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

 打算调试,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

你可能感兴趣的:(gdbserver,静态编译,调试失败)