如何使用 Eclipse 调试 JNI 代码(Java & C/C++)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2762916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 12:34:27  来源:igfitidea点击:

How to Use Eclipse to Debug JNI code (Java & C/C++)

javaeclipsedebuggingjava-native-interfaceandroid-ndk

提问by Tim Kryger

While I can debug my application with the Eclipse JDT debugger for Java code and GDB for C code, I would prefer to use a single tool for all my debugging. I found several projects that enable "mixed-mode" debugging in Eclipse and include support for single stepping between Java and native code.

虽然我可以使用用于 Java 代码的 Eclipse JDT 调试器和用于 C 代码的 GDB 来调试我的应用程序,但我更愿意使用单个工具进行所有调试。我发现了几个在 Eclipse 中启用“混合模式”调试的项目,包括对 Java 和本机代码之间的单步执行的支持。

Unfortunately, one claims to be pre-release quality and the other is currently unmaintained. Are there any plug-ins that bring mixed mode debugging functionality to Eclipse in a reliable way or should I continue to use two separate debuggers?

不幸的是,一个声称是预发布质量,另一个目前没有维护。 是否有任何插件以可靠的方式将混合模式调试功能引入 Eclipse,还是我应该继续使用两个单独的调试器?

采纳答案by JesperE

I don't think there is anything available today which will fix it, but I know that Doug Schaefer has this pretty high on his list of things he wants to get done. Keep an eye on his blogfor updates on that.

我认为今天没有任何可用的东西可以解决它,但我知道 Doug Schaefer 在他想要完成的事情清单上非常高。请密切关注他的博客以获取有关更新的信息。

回答by Fred Grott

Eclipse Sequoyah 1.0 has android ndk features..Eclipse 3.6 release train and 3.5 release early June.

Eclipse Sequoyah 1.0 具有 android ndk 功能。Eclipse 3.6 发行版和 6 月初 3.5 发行版。

回答by Seva Alekseyev

ARM itself seems to have a toolkit: http://ds.arm.com/ds-5-community-edition/

ARM 本身似乎有一个工具包:http: //ds.arm.com/ds-5-community-edition/

Requires Eclipse 4.4 ("Luna").

需要 Eclipse 4.4(“Luna”)。

回答by R Schultz

For those looking to debug NDK/JNI code in the Eclipse Juno release, it is essentially built into the software after installing the Android plugins and CDT plugins. You may have issues though since there is a problem that was introduced with the C/C++ Development tools (CDT 8.1) that as of 7/24/12 has not been fixed. For details on the issue see the following link. If you just want to debug, keep reading.

对于那些希望在 Eclipse Juno 版本中调试 NDK/JNI 代码的人来说,它基本上是在安装 Android 插件和 CDT 插件后内置到软件中的。您可能会遇到问题,因为 C/C++ 开发工具 (CDT 8.1) 引入了一个问题,该问题截至 2012 年 7 月 24 日尚未修复。有关该问题的详细信息,请参阅以下链接。如果您只是想调试,请继续阅读。

http://code.google.com/p/android/issues/detail?id=33788

http://code.google.com/p/android/issues/detail?id=33788

If it is working correctly, you simply set your breakpoints in the C and Debug As -> Android Native Application. Unfortunately, you can not debug the java and C at the same time. If the problem is in the Java and you want to debug you do so by clicking Debug As -> Android Application.

如果它工作正常,您只需在 C 和Debug As -> Android Native Application 中设置断点。不幸的是,您不能同时调试 java 和 C。如果问题出在 Java 中并且您想进行调试,请单击Debug As -> Android Application 进行调试

If it is not working correctly, and you want to figure out how to get it correctly, the following packages worked for me.

如果它不能正常工作,并且您想弄清楚如何正确获取它,以下软件包对我有用。

  Android DDMS  20.0.1.v201207132230-403220
  Android Development Tools 20.0.1.v201207132230-403220 
  Android Hierarchy Viewer  20.0.1.v201207132230-403220 
  Android Native Development Tools  20.0.1.v201207132230-403220 
  Android Traceview 20.0.1.v201207132230-403220 
  Autotools support for CDT (Incubation)    3.0.1.201202152032  
  C/C++ Development Tools   8.0.2.201202111925  
  C/C++ Development Tools SDK   8.0.2.201202111925
  C/C++ Library API Documentation Hover Help (Incubation)   
  Eclipse SDK   4.2.0.I20120608-1400    
  Tracer for OpenGL ES  20.0.1.v201207132230-403220

The android packages came from setting Work With:option on the Eclipse Help->Install New Software...dialog to

android 包来自设置Work With:Eclipse Help->Install New Software...对话框中的选项

dl-ssl.google.com/android/eclipse/

The older 8.02... CDT packages came from setting the Work With:option to the Indigo release packages.

较旧的 8.02... CDT 包来自将Work With:选项设置为 Indigo 发布包。

download.eclipse.org/releases/indigo

If installed, you will need to remove the Android tools, and the new version of the CDT prior to installing the old version of the CDT. Once the 8.02... version of CDT is installed, you can install the Android tools and commence debugging.

如果已安装,您将需要在安装旧版 CDT 之前删除 Android 工具和新版 CDT。一旦安装了 8.02... 版本的 CDT,您就可以安装 Android 工具并开始调试。

Ensure you use the Build command "ndk-build NDK_DEBUG=1"

确保您使用构建命令“ndk-build NDK_DEBUG=1”

Autotools may not be required but since it is installed I have it listed.

Autotools 可能不是必需的,但由于它已安装,因此我将其列出。

Note that stepping through the code can be quirky sometimes.

请注意,单步执行代码有时可能很古怪。

回答by R Schultz

With the new Android ADT bundle (as of 05/12/2013), there is no longer a need for the older 8.02 software package. If you find yourself editing text files to get the debugging working, you are following old directions that no longer apply. Use the android ADT and Debug As-> Android Native Application. You may still need to set NDK_DEBUG=1 if its not already done in the setup.

使用新的 Android ADT 捆绑包(截至 2013 年 5 月 12 日),不再需要旧的 8.02 软件包。如果您发现自己正在编辑文本文件以使调试正常工作,那么您正在遵循不再适用的旧指示。使用 android ADT 和 Debug As-> Android Native Application。如果尚未在设置中完成,您可能仍需要设置 NDK_DEBUG=1。