gdbserver静态编译-调试失败的原来

为了调试Android系统的Zygote进程,由于Android使用非glibc库,需要静态编译gdbserver。通过`CFLAGS=-static ./configure --host=arm-none-linux-gnueabi`进行配置,成功生成静态gdbserver。但在尝试调试时遇到问题,通过Google Issue #15894找到解决方案,涉及follow-fork-mode的设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

打算调试,zyote。众所周知,android的lib不是glibc.所以要个静态编译的gdbserver.

./configure --help

CFLAGS=-static ./configure --host=arm-none-linux-gnueabi
然后make当前目录下就gdbserver出来了。readelf -d结果为静态文件。

 

用自己编译的gdbserver+arm-none-linux-gnueabi-gdb调度时。follow-fork-mode和detach-on-fork死都不管用. info inferiors只显示一个进程。

 

人品很好,在下面的地方找到了答案。(http://code.google.com/p/android/issues/detail?id=15894)

The 'gdbserver' that comes in NDK r5b is stripped of symbols, so I cannot confirm that what I'm about to say is absolutely the cause of this particular segfault, but I do have an interesting data-point to share:

Back in early February I discovered that the AOSP's prebuilt 'gdbserver' for Gingerbread had been statically linked against a libc from Cupcake.  This caused an impedance mismatch between libc and the kernel, causing segfaults.  (During this time I was unaware of the 'ndk-build' and 'ndk-gdb' scripts, and was doing things "the hard way".)

My solution was to rebuild my own gdbserver (from 7.2 gdb,) applying Google's 7.1.x libthread_db patches.  The result was a usable gdbserver.    I now find that I can also work around this new segfault (with NDK r5b's "ndk-gdb script") by again using that self-built gdbserver.

See below for details captured in February.

This brings up an interesting point:  It makes sense for gdbserver to be statically linked to libc, for the purpose of minimizing gdbserver's dependence on the system being debugged.  But at the same time, I think maybe it makes it a little risky to use the same gdbserver binary for all Android OS versions, particularly when there are kernel differences?  If my concern has merit, then perhaps the NDK should come supplied with multiple copies of gdbserver, and then the appropriate one should get used for a given target device.

   rbissell@rvb-android-dev0:~/src/android$ nm -a ./gdbserver | grep fork
   0003c460 T fork
   00000000 a fork.c
   rbissell@rvb-android-dev0:~/src/android$ addr2line -e ./gdbserver 0003c460
   /opt/digit/android/main/cupcake/android/bionic/libc/bionic/fork.c:34 

(Again, the was the gdbserver taken from the Gingerbread AOSP tree, back in early February 2011.)

Hope that helps in some way.


gdb调试多进程
http://sourceware.org/gdb/onlinedocs/gdb/Forks.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值