【转】GDB调试opencore源码

1 首先在终端执行:

emulator –show-kernel -memory 1024
打开模拟器

2 开启另一个终端,执行:

adb shell

进入模拟器shell,

3 在模拟器shell中执行

ps mediaserver

查看进程mediaserver的PID

4 查看PID后,接着执行:

gdbserver :5039 –attach PID(上面查看的mediaserver的PID)

5 再开启一个终端,设置模拟器端口转发:

adb forward tcp:5039 tcp:5039

6 启动arm-eabi-gdb,

arm-eabi-gdb位于androidsrc/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin下,此文件夹下存放着android的编译器等工具

命令格式:

arm-eabi-gdb 可执行文件(在此是mediaserver,别忘了指定路径)

例: arm-eabi-gdb /androidsrc/out/target/product/generic/symbols/system/bin/mediaserver


这样就会进入GDB环境

7 设置gdb中的来那个坏境变量:

(gdb) set solib-absolute-prefix /androidsrc/out/target/product/generic/symbols/
(gdb) set solib-search-path /androidsrc/out/target/product/generic/symbols/system/lib/

关于这两个变量:

solib-absolute-prefix :设置查找共享库的前缀,作为查找so库路径的前缀;

If this variable is set, path will be used as a prefix for any absolute shared library paths; many runtime loaders store the absolute paths to the shared library in the target program's memory. If you use `solib-absolute-prefix' to find shared libraries, they need to be laid out in the same way that they are on the target, with e.g. a `/usr/lib' hierarchy under path. You can set the default value of `solib-absolute-prefix' by using the configure-time `--with-sysroot' option.

solib-search-path :设置so库的查找路径,它是在根据solib-absolute-prefix 查找库失败后使用

If this variable is set, path is a colon-separated list of directories to search for shared libraries. `solib-search-path' is used after `solib-absolute-prefix' fails to locate the library, or if the path to the library is relative instead of absolute. If you want to use `solib-search-path' instead of `solib-absolute-prefix', be sure to set `solib-absolute-prefix' to a nonexistant directory to prevent GDB from finding your host's libraries.

 

Connect to the device by issuing the gdb command:

(gdb)target remote :5039


8 进行GDB调试

此时就可以使用GDB来调试源码了,首先设置断点:

(gdb) b createPlayer

(gdb) c

然后再到模拟器播放文件可以了

播放会在断点处卡住,

(gdb) l

就可以显示断点出的源码

你可能感兴趣的:(shell,command,Path,library,hierarchy,终端)