Author: Gary
Date: 2019-2-21
转载整理自:
https://wladimir-tm4pda.github.io/porting/debugging_gdb.html
https://www.cnblogs.com/liumce/p/8027559.html
1.环境安装与配置
编译安卓,具体步骤见:
安卓版本为android-6.0.1_r1,机型为Nexus 5。
2.手机启动监听
- 进入adb shell:
$ adb shell
- 在shell中查询要监听的App的PID,以相机为例,可以看到camara进程的pid是1834:
# ps | grep camera
camera 389 1 205556 8224 poll_sched b6d47a84 S /system/bin/mm-qcamera-daemon
u0_a25 1834 383 1926660 260764 SyS_epoll_ b6d48894 S com.android.camera2
- adb中设置监听
# gdbserver :5039 --attach 1834
Attached; pid = 1834
Listening on port 5039
Remote debugging from host 127.0.0.1
3.主机启动gdb调试
-
设置端口转发:
$ adb forward tcp:5039 tcp:5039
-
启动Android源码中内置的定制版gdb:
$ prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-gdb
-
在启动的gdb中,设置共享库位置:
(gdb) set solib-absolute-prefix /home/cc/bin/android-6.0.1_r1/out/target/product/product-name/symbols
(gdb) set solib-search-path /home/cc/bin/android-6.0.1_r1/out/target/product/product-name/symbols/system/lib
-
连接设备:
(gdb) target remote :5039
此时可以在adb shell中看到如下提示:
Remote debugging from host 127.0.0.1
-
开始调试,设置断点:
(gdb) b frameworks/base/libs/hwui/renderthread/DrawFrameTask.cpp:71
No symbol table is loaded. Use the "file" command.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (frameworks/base/libs/hwui/renderthread/DrawFrameTask.cpp:71) pending.
- 等待运行到断点处:
(gdb) c
Continuing.
Cannot access memory at address 0x1c
然后终端就阻塞在该处,但是在app中进行操作都没有触发断点,原因目前未知。