Android NDK应用程序无法打到任何断点
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Android NDK应用程序无法打到任何断点,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含10467字,纯文字阅读大概需要15分钟。
内容图文
![Android NDK应用程序无法打到任何断点](/upload/InfoBanner/zyjiaocheng/794/f9bdc9b710ed402685063c7b5469e35d.jpg)
我正在使用https://www.youtube.com/watch?v=kjsC-lKUgM8教程尝试调试一个简单的NDK应用程序.我已完成视频中的所有操作,但以下情况除外:
>我使用的是OS X 10.9.3而不是Windows.
>我没有在AndroidManifest.xml中使用android:debuggable = true(因为eclipse认为它是错误的)而是我已经从Preferences-> Android-> NDK和Project Properties中设置了NDK路径 – > C/C++ Build unchecked使用默认构建命令并在那里设置ndk-build NDK_DEBUG = 1 APP_OPTIM = debug.
>我不使用x86模拟器,而是使用Android 4.0.4的Samsung Duos S设备
但在我的情况下,视频中使用的breakpoiin没有被击中.我试图在第4天调试一个简单的NDK测试项目.调查了很多材料:
> Android Native Development Kit Cookbook
>一堆论坛和教程
>视频
但不能打一个该死的断点.如果你能这样做,请帮忙.
解决方法:
以下是我为内部Android开发团队编写的教程的摘录.其中大部分来自此博客:http://mhandroid.wordpress.com/
重要笔记:
>我使用Linux(Ubuntu 12.04)环境进行Android工作.
>我使用ADT Bundle for Linux,Build:v22.2.1-833290(Eclipse IDE Extras)
>这些步骤用于从Java Activity调试到JNI共享对象.
>我为本教程创建了测试项目,这些测试项目将不会在此处发布,尽管下面的说明中提供了对这些项目的引用.您需要一个现有的Android应用程序项目以及Java代码调用的JNI共享对象.
项目设置
>启用调试.
Open AndroidManifest.xml, select the Application tab, and set Debuggable=true. This will make the application debuggable even when it’s running on a device that’s running in user mode.
>构建本机源.在终端中,输入项目目录并输入:
ndk-build -B
您应该看到以下输出:
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile++ thumb : DebuggingTestJNI <= com_sample_test_DebuggingTestActivity.cpp
StaticLibrary : libstdc++.a
SharedLibrary : libDebuggingTestJNI.so
Install : libDebuggingTestJNI.so => libs/armeabi/libDebuggingTestJNI.so
>清理项目.在Eclipse菜单条中,选择Project→Clean.无论何时更改/构建本机源,都可以执行此步骤.此步骤确保Eclipse将重建您的.apk.
本机调试设置
>创建Java调试配置.我们需要创建一个调试配置来进入Java源代码.
- In the Eclipse toolbar, you’ll see a green bug. Click the little arrow next to the bug and select “Debug Configurations…”.
- Double-click “Android Application” in the tree structure on the left. This will create a template for a new Android Application Debug Configuration.
- In the “Name:” field, name it “DebuggingTest Java Debug” to make sure you know this Configuration applies specifically to the DebuggingTest project, and targets your Java source.
- Under “Project:”, click the “Browse…” button and select DebuggingTest.
- Click “Apply” to save your changes.
- Click “Close”.
- In the Eclipse toolbar, click the little arrow next to the bug and select “Organize Favorites…”.
- Click “Add…”
- Select “DebuggingTest Java Debug” and click “OK”.
Your new debug configuration has now been created and added to your favorites. You can access your favorites by clicking the little arrow next to the bug in the toolbar. “DebuggingTest Java Debug” should be at the top of the list.
>运行ndk-gdb.
- In the Eclipse toolbar, click the little arrow next to the bug and select “DebuggingTest Java Debug”. This will deploy and install the DebuggingTest.apk to your connected Android device and start the debugger.
Navigate to the DebuggingTest project directory in your Terminal and type the following:
ndk-gdb
If the command succeeds, you should see the following:
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB. Type “show warranty” for details.
This GDB was configured as “–host=x86_64-linux-gnu –target=arm-elf-linux”.
(no debugging symbols found)
…
如果您在此步骤之前忘记开始调试应用程序,则会得到以下内容:
ERROR: Could not extract PID of application on device/emulator.
Are you sure the application is already started?
Consider using –start or –launch= if not.
If your Android.mk file is malformed or contains $(info) blocks, you get the following:
cp: target./obj/local/armeabi/gdb.setup' is not a directory
start –help’ for more information.
/home/Dev/NDK/ndk-gdb: 639: cannot create start DebuggingTest/jni/Android.mk
end DebuggingTest/jni/Android.mk
./obj/local/armeabi/gdb.setup: Directory nonexistent
/home/Dev/NDK/ndk-gdb: 640: cannot create start DebuggingTest/jni/Android.mk
end DebuggingTest/jni/Android.mk
./obj/local/armeabi/gdb.setup: Directory nonexistent
start: invalid option: -x
Try
如果ndk-gdb已在运行,您将获得以下内容:
ERROR: Another debug session running, Use –force to kill it.
在继续之前解决您的错误. ndk-gdb必须成功运行.
运行ndk-gdb不仅可以确保我们目前正在做的一切,还可以在项目的obj / local / armeabi /子目录中创建app_process,gdb.setup和libc.so文件.稍后的步骤将需要这些文件.
>停止调试.
- In your Terminal, type CTRL+Z to stop ndk-gdb.
- In Eclipse, select Run–>Terminate.
>创建C/C++调试配置.我们需要创建一个调试配置来进入C/C++源代码.
- In Eclipse, click the little arrow next to the bug and select “Debug Configurations…”.
- Double-click “C/C++ Application” in the tree structure on the left. This will create a template for a new C/C++ Application Debug Configuration.
- In the “Name:” field, name it “DebuggingTest C and CPP Debug” to make sure you know this Configuration applies specifically to the DebuggingTest project, and targets your C/C++ source.
- In the “Main” tab:
- Click “Browse…” on the “C/C++ Application:” field.
Navigate to “/home/Test/testing/DebuggingTest/obj/local/armeabi/app_process” and click “OK”.- Click “Browse…” on the “Project:” field.
- Select “DebuggingTest” and click “OK”.
- Check the “Disable auto build” box.
- At the bottom of the form, you’ll see “Using GDB (DSF) … – Select other…”. Press the “Select other…” button.
- In the pop-up, check the “Use configuration specific settings” box.
- Select “Standard Create Process Launcher” in the list and press “OK”.
- In the “Debugger” tab:
- Click the combo-box on the “Debugger:” field and select “gdbserver”.
- Uncheck the “Stop on startup at:” box.
- In the “Main” sub-tab:
- Click “Browse…” on the “GDB debugger:” field.
- Navigate to “/home/Dev/ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gdb” and click “OK”. This debugger is distributed with the Android NDK.
- In the “GDB command file:” field, type “/home/Test/testing/DebuggingTest/obj/local/armeabi/gdb2.setup”. The gdb2.setup file does not exist yet, but we’ll create it shortly.
- Check the “Use full file path to set breakpoints” box.
- In the “Connection” sub-tab:
- Set “Type:” to TCP
- Set “Port number:” to 5039
- Click “Apply” to save your changes.
- Click “Close”
- In the Eclipse toolbar, click the little arrow next to the bug and select “Organize Favorites…”.
- Click “Add…”
- Select “DebuggingTest C and CPP Debug” and click “OK”.
您的新调试配置现已创建并添加到您的收藏夹中.您可以通过单击工具栏中的错误旁边的小箭头来访问您的收藏夹. “DebuggingTest C和CPP Debug”应位于列表的顶部.
>创建gdb2.setup. Eclipse不喜欢gdb安装文件中的“target remote:5039”行,因为它想在内部输入此命令(这就是您在上一步中配置端口5039的原因).因为gdb.setup文件是由NDK脚本重新创建的,所以必须将它复制到gdb2.setup并将Eclipse指向gdb2.setup文件(我们在上一步中做过).
- In your File Explorer, navigate to “/home/Test/testing/DebuggingTest/obj/local/armeabi/”.
- Copy the “gdb.setup” file and then paste it into the same folder. The result should be a file named “gdb (copy).setup”.
- Rename “gdb (copy).setup” to “gdb2.setup”.
- Open gdb2.setup by double-clicking the file.
- Replace “set solib-search-path ./obj/local/armeabi” with “set solib-search-path /home/Test/testing/DebuggingTest/obj/local/armeabi”.
- Replace “file ./obj/local/armeabi/app_process” with “file /home/Test/testing/DebuggingTest/obj/local/armeabi/app_process”.
- Remove the line that reads “target remote :5039”.
- Save and Close the file.
>创建ndk-gdb-eclipse.最后一个Eclipse家务项目. Eclipse将自己运行gdb二进制文件,因此我们必须从ndk-gdb中删除gdb的执行.我们将通过执行另一次复制粘贴重命名来保存原始内容.
- In your File Explorer, navigate to “/home/Dev/NDK”.
- Copy the “ndk-gdb” file and then paste it into the same folder. The result should be a file named “ndk-gdb (copy)”.
- Rename “ndk-gdb (copy)” to “ndk-gdb-eclipse”.
- Open ndk-gdb-eclipse by doing a right-click–>Open With Other Application…
- Select Text Editor from the list of applications
- In the file, locate the line that reads “$GDBCLIENT -x
native_path $GDBSETUP
” (probably at the very bottom) and comment it out by prefixing it with a “#” character.- Save and Close the file.
在Eclipse IDE中调试本机源时,我们将使用ndk-gdb-eclipse而不是ndk-gdb.
调试/步入代码
>进入Java代码!
- Put a breakpoint in the DebuggingTestActivity.java file at line 20 (System.out.println(“hello world!”)).
- Insert a breakpoint in your main Activity BEFORE any calls into native code are made. onCreate() is generally the best place for this.
- Start the DebuggingTest application in Debug mode by clicking on the little arrow next to the bug and selecting “DebuggingTest Java Debug”.
- You’ll see a pop-up on the screen labeled “Confirm Perspective Switch”. Press “Yes” if you’d like it to switch to your Debug Perspective. I would recommend doing so.
- At this point, you should have hit the breakpoint you set.
警告:我们刚刚命中的断点位于onCreate函数内部.在完成所有静态loadLibrary调用之后,将调用此函数.请注意,在onCreate函数之外,静态块内部有一个System.loadLibrary(“DebuggingTestJNI”).这个loadLibrary调用将在我们进入onCreate函数之前执行,确保在我们达到初始断点时加载我们的本机符号.在继续之前我们必须在断点处停下来!
>进入C/C++代码!
- In your Terminal, navigate to the DebuggingTest directory and type the following command:
ndk-gdb-eclipse <– Remember that we created this file back in step 6
>如果成功,该命令应该完成而不做任何响应.
>通过单击错误旁边的小箭头并选择“DebuggingTest C和CPP Debug”,返回Eclipse并运行C/C++调试器
>注意:当我这样做时,我在Eclipse控制台中看到了几十个错误,但事情似乎仍在起作用……
>切换回Java Perspective.
>单击Eclipse窗口右上角的双箭头,然后选择Java.
>打开DebuggingTest / jni / com_sample_test_DebuggingTestActivity.cpp
>在主活动将调用的第一个JNI函数中设置断点.
>点击运行 – >恢复(F8)
>您将再次获得Perspective Switch消息,因此可以随意切换回Debug Perspective.
你应该刚刚点击我们在本机代码中设置的断点!
恭喜!
此时,您应该能够学习所学知识并使其适应您可能拥有的现有项目.
内容总结
以上是互联网集市为您收集整理的Android NDK应用程序无法打到任何断点全部内容,希望文章能够帮你解决Android NDK应用程序无法打到任何断点所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。