GDB调试opencore源码

花了一天的时间终于用GDB实现了对opencore的调试,虽然网上高人写的相关文章很详细,但是自己对GDB知之甚少,理解很慢,现在自己再写一个,希望给对像我这样刚接触GDB的人一些帮助:

1 首先在终端执行:

emulator –avd emulatorname

打开模拟器

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

adb shell

进入模拟器shell,

3 在模拟器shell中执行

ps mediaserver

查看进程mediaserver的PID

4 查看PID后,接着执行:

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

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

adb forward tcp:4800 tcp:4800

6 启动arm-eabi-gdb,

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

命令格式:

arm-eabi-gdb 可执行文件(在此是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.

8 在执行

(gdb) target remote :4800

9 进行GDB调试

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

(gdb) b createPlayer

(gdb) c

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

播放会在断点处卡住,

(gdb) l

就可以显示断点出的源码

参考文献:

http://blog.chinaunix.net/u2/61880/showart_2393482.html

http://blog.wjmjimmie.cn/2010/08/02/Android系统中调试动态链接库so文件的步骤

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