用GDB调试Android中C/C++程序(命令行)
2012-02-10 20:16
627 查看
一、编译Android gdbserver(非必须)
因手头Android 2.3源码编译后的版本执行gdbserver时报错:Segmentation fault,不得不重新编译gdbserver。
1、编译gdbserver
编译过程参考博文:自己编译Android
gdbserver(解决运行 gdbserver时 Segmentation fault 问题)。
2、使用新编译的gdbserver替换原有版本gdbserver
simba@simba-Vostro-3400:~/neptune/android_2.3$ adb push ~/gdb_build/install/gdbserver /system/bin
二、使用带调试符号表的C/C++程序替换原有程序
simba@simba-Vostro-3400:~/neptune/android_2.3$ adb push out/target/product/xxxx/symbols/system/bin/debug_demo /system/bin
三、使用gdbserver调试android C/C++程序
1、 [b]gdbserver attach被调试程序
[/b]
方法一:adb shell中以gdbserver参数的形式执行被调试程序
simba@simba-Vostro-3400:~/neptune/android_2.3$ adb shell gdbserver :5039 /system/bin/debug_demo &
[3] 17600
simba@simba-Vostro-3400:~/neptune/android_2.3$ Process /system/bin/debug_demo created; pid = 3323
Listening on port 5039
方法二:adb shell中执行被调试的程序,ps命令查看其PID并gdbserver attach
simba@simba-Vostro-3400:~/neptune/android_2.3$ adb shell /system/bin/debug_demo &
[3] 22614
simba@simba-Vostro-3400:~/neptune/android_2.3$ adb shell ps | grep /system/bin/debug_demo
root 3353 3352 1048 412 800cc220 6fd0bdac S /system/bin/debug_demo
simba@simba-Vostro-3400:~/neptune/android_2.3$ adb shell gdbserver :5039 --attach 3353 &
[4] 26856
simba@simba-Vostro-3400:~/neptune/android_2.3$ Attached; pid = 3353
Listening on port 5039
2、[b]调试端口映射,把设备的5039端口映射到PC的5039[/b]
simba@simba-Vostro-3400:~/neptune/android_2.3$ adb forward tcp:5039 tcp:5039
设定之后用netstat -na命令可看到PC的5039端口已处于listen状态
simba@simba-Vostro-3400:~/neptune/android_2.3$ netstat -na | grep 5039
tcp 0 0 127.0.0.1:5039 0.0.0.0:* LISTEN
3、gdb客户端命令行调试
simba@simba-Vostro-3400:~/neptune/android_2.3$ /home/simba/neptune/android_2.3/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gdb ./out/target/product/xxxx/symbols/system/bin/debug_demo
(gdb) set solib-absolute-prefix ./out/target/product/xxxx/symbols/system/bin/
(gdb) set solib-search-path ./out/target/product/xxxx/symbols/system/bin
这里的gdb的版本一定要正确。这时已经进入了gdb调试模式,还需要进行与远程的gdbserver进行连接,在gdb模式下输入:
(gdb) target remote :5039
4.开始愉悦的调试吧
四、后记
用命令行调试比较繁琐,习惯使用Eclipse参考:用 Eclipse +
GDB调试Android中C/C++程序
--
参考文章:
GDB 命令详细解释
用Eclipse开发与调试纯粹的Android C++程序,非ndk-build、ndk-gdb
GDB: The GNU Project Debugger
因手头Android 2.3源码编译后的版本执行gdbserver时报错:Segmentation fault,不得不重新编译gdbserver。
1、编译gdbserver
编译过程参考博文:自己编译Android
gdbserver(解决运行 gdbserver时 Segmentation fault 问题)。
2、使用新编译的gdbserver替换原有版本gdbserver
simba@simba-Vostro-3400:~/neptune/android_2.3$ adb push ~/gdb_build/install/gdbserver /system/bin
二、使用带调试符号表的C/C++程序替换原有程序
simba@simba-Vostro-3400:~/neptune/android_2.3$ adb push out/target/product/xxxx/symbols/system/bin/debug_demo /system/bin
三、使用gdbserver调试android C/C++程序
1、 [b]gdbserver attach被调试程序
[/b]
方法一:adb shell中以gdbserver参数的形式执行被调试程序
simba@simba-Vostro-3400:~/neptune/android_2.3$ adb shell gdbserver :5039 /system/bin/debug_demo &
[3] 17600
simba@simba-Vostro-3400:~/neptune/android_2.3$ Process /system/bin/debug_demo created; pid = 3323
Listening on port 5039
方法二:adb shell中执行被调试的程序,ps命令查看其PID并gdbserver attach
simba@simba-Vostro-3400:~/neptune/android_2.3$ adb shell /system/bin/debug_demo &
[3] 22614
simba@simba-Vostro-3400:~/neptune/android_2.3$ adb shell ps | grep /system/bin/debug_demo
root 3353 3352 1048 412 800cc220 6fd0bdac S /system/bin/debug_demo
simba@simba-Vostro-3400:~/neptune/android_2.3$ adb shell gdbserver :5039 --attach 3353 &
[4] 26856
simba@simba-Vostro-3400:~/neptune/android_2.3$ Attached; pid = 3353
Listening on port 5039
2、[b]调试端口映射,把设备的5039端口映射到PC的5039[/b]
simba@simba-Vostro-3400:~/neptune/android_2.3$ adb forward tcp:5039 tcp:5039
设定之后用netstat -na命令可看到PC的5039端口已处于listen状态
simba@simba-Vostro-3400:~/neptune/android_2.3$ netstat -na | grep 5039
tcp 0 0 127.0.0.1:5039 0.0.0.0:* LISTEN
3、gdb客户端命令行调试
simba@simba-Vostro-3400:~/neptune/android_2.3$ /home/simba/neptune/android_2.3/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gdb ./out/target/product/xxxx/symbols/system/bin/debug_demo
(gdb) set solib-absolute-prefix ./out/target/product/xxxx/symbols/system/bin/
(gdb) set solib-search-path ./out/target/product/xxxx/symbols/system/bin
这里的gdb的版本一定要正确。这时已经进入了gdb调试模式,还需要进行与远程的gdbserver进行连接,在gdb模式下输入:
(gdb) target remote :5039
4.开始愉悦的调试吧
四、后记
用命令行调试比较繁琐,习惯使用Eclipse参考:用 Eclipse +
GDB调试Android中C/C++程序
--
参考文章:
GDB 命令详细解释
用Eclipse开发与调试纯粹的Android C++程序,非ndk-build、ndk-gdb
GDB: The GNU Project Debugger
相关文章推荐
- 如何使用arm-eabi-gdb调试android c/c++程序
- adb gdb 调试android C/C++程序
- 如何使用arm-eabi-gdb调试android c/c++程序
- 使用gdb和gdbserver调试Android C/C++程序
- 使用GDB命令行调试器调试C/C++程序
- 用 Eclipse + GDB调试Android中C/C++程序
- 使用GDB命令行调试器调试C/C++程序
- 使用GDB命令行调试器调试C/C++程序
- 用android自带的gdb与gdbserver调试native C/C++程序
- GDB 调试 android 本地 c/c++ 程序
- 使用GDB调试Android中的C/C++程序
- 如何使用arm-eabi-gdb调试android c/c++程序
- 使用GDB命令行调试器调试C/C++程序
- 使用GDB命令行调试器调试C/C++程序
- 使用GDB命令行调试器调试C/C++程序
- 如何使用arm-eabi-gdb调试android c/c++程序
- 使用GDB命令行调试器调试C/C++程序
- 使用GDB命令行调试器调试C/C++程序【转】
- 使用GDB命令行调试器调试C/C++程序
- Ubuntu下使用gdb远程调试android native程序笔记