Skip to content
Advertisement

How do I debug Android native code into kernel?

I compiled goldfish kernel with:

 [ ] Optimize for size,
 [*] Kernel hacking 
     [*] Compile the kernel with debug info 
     [*] KGDB: kernel debugging with remote gdb —>      
     [*] Enable dynamic printk() call support 

I started the AVD with the compiled kernel.

emulator -kernel goldfish/arch/arm/boot/zImage -avd TestAVD

I pushed a compiled c program onto AVD.

And I downloaded the libs (I’m not sure if it’s the proper way)

adb pull /system/lib ./debuginfo/lib
adb pull /system/bin/linker ./debuginfo/lib

run gdbserver:

gdbserver 127.0.0.1:7777 ./a

forward port:

adb forward tcp:7777 tcp:7777

run gdb

gdb-multiarch ./a

specify the search directory:

set solib-search-path ./debuginfo/lib

connect to device

target remote :7777

I breaked at, for example, close.

0xaf0ae228 in close () from /home/wuyihao/android_sec/debuginfo/lib/libc.so
1: x/i $pc
=> 0xaf0ae228 <close+8>:        svc     0x00000000
(gdb) list
No symbol table is loaded.  Use the "file" command.

I couln’d get the source. So I tried to recompile the kernel with variable CFLAG=”-g”

Nothing different.

Thank you!

ps: I noticed the downloaded libs are all stripped.

Advertisement

Answer

libc.so is not the Linux kernel. It is C standard library.

It is extremely unlikely you’ll need to look for a problem there. If your close() call doesn’t work, it’s almost certain something is wrong with you using it, not its implementation.

Advertisement