android NDK: gdb crashes when connecting - android
As a followup to this (I got gdbserver starting properly): Android NDK debugging: armeabi-v7a not working
NDK 8c, Eclipse & Cygwin, NativeActivity.
I set a breakpoint in the while loop here:
void android_main( android_app* state )
{
int stop = 0;
int x = 5;
while( stop == 0 )
{
x++;
}
... but gdb crashes when connecting! It does "stuff" for about 10 seconds, then crashes. There is some output.
Here's the gdbserver output:
Android NDK installation path: /cygdrive/e/uppercut/sdks/android-ndk
Using default adb command: /cygdrive/e/uppercut/sdks/android-sdk/platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.31
Using ADB flags:
Using auto-detected project path: .
Found package name: com.example.radgame
ABIs targetted by application: armeabi-v7a
Device API Level: 15
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi-v7a
Using gdb setup init: ./libs/armeabi-v7a/gdb.setup
Using toolchain prefix: /cygdrive/e/uppercut/sdks/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi-
Using app out directory: ./obj/local/armeabi-v7a
Found debuggable flag: true
Found device gdbserver: /data/data/com.example.radgame/lib/gdbserver
Found data directory: '/data/data/com.example.radgame'
Found running PID: 3218
Launched gdbserver succesfully.
Setup network redirection
## COMMAND: adb_cmd shell run-as com.example.radgame lib/gdbserver +debug-socket --attach 3218
## COMMAND: adb_cmd forward tcp:5039 localfilesystem:/data/data/com.example.radgame/debug-socket
Attached; pid = 3218
Listening on Unix socket debug-socket
## COMMAND: adb_cmd pull /system/bin/app_process obj/local/armeabi-v7a/app_process
3204 KB/s (9848 bytes in 0.003s)
Pulled app_process from device/emulator.
## COMMAND: adb_cmd pull /system/bin/linker obj/local/armeabi-v7a/linker
7732 KB/s (39592 bytes in 0.005s)
Pulled linker from device/emulator.
## COMMAND: adb_cmd pull /system/lib/libc.so obj/local/armeabi-v7a/libc.so
6994 KB/s (286536 bytes in 0.040s)
Pulled libc.so from device/emulator.
<waits while gdb connects...>
Remote debugging from host 0.0.0.0
libthread_db:td_ta_new: Probing system for platform bug.
<lots of repetitive lines...>
libthread_db:td_ta_new: Victory: We can debug theads!
readchar: Got EOF
Remote side has terminated connection. GDBserver will reopen the connection.
Listening on Unix socket debug-socket
The last several lines are its response to gdb connecting and crashing.
Here's the gdb output:
Reading symbols from E:\uppercut\prototype\build\code\androidp4\radgame\obj\local\armeabi-v7a\app_process...done.
WARNING: no debugging symbols found in E:\uppercut\prototype\build\code\androidp4\radgame\obj\local\armeabi-v7a\app_process.
Either the binary was compiled without debugging information
or the debugging information was removed (e.g., with strip or strip -g).
Debugger capabilities will be very limited.
For further information: http://wiki/Main/GdbFaq#No_debugging_symbols_found
89-gdb-set confirm off
(gdb)
89^done
(gdb)
90-gdb-set width 0
90^done
(gdb)
91-gdb-set height 0
91^done
(gdb)
92-interpreter-exec console echo
92^done
(gdb)
93-gdb-show prompt
93^done,value="(gdb) "
(gdb)
94-gdb-set target-async 0
94^done
(gdb)
95-gdb-set auto-solib-add on
95^done
(gdb)
96-gdb-set stop-on-solib-events 0
96^done
(gdb)
97-gdb-set stop-on-solib-events 1
97^done
(gdb)
98-target-select remote localhost:5039
=thread-group-started,id="i1",pid="42000"
=thread-created,id="1",group-id="i1"
&"warning: while parsing target library list (at line 2): No segment defined for com.example.radgame\n"
warning: while parsing target library list (at line 2): No segment defined for com.example.radgame
=library-loaded,id="/system/bin/linker",target-name="/system/bin/linker",host-name="E:\\uppercut\\prototype\\build\\code\\androidp4\\radgame/./obj/local/armeabi-v7a/linker",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libc.so",target-name="libc.so",host-name="E:\\uppercut\\prototype\\build\\code\\androidp4\\radgame/./obj/local/armeabi-v7a/libc.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libstdc++.so",target-name="libstdc++.so",host-name="libstdc++.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libm.so",target-name="libm.so",host-name="libm.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="liblog.so",target-name="liblog.so",host-name="liblog.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libcutils.so",target-name="libcutils.so",host-name="libcutils.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libz.so",target-name="libz.so",host-name="libz.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libtime_genoff.so",target-name="libtime_genoff.so",host-name="libtime_genoff.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libutils.so",target-name="libutils.so",host-name="libutils.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libbinder.so",target-name="libbinder.so",host-name="libbinder.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libexpat.so",target-name="libexpat.so",host-name="libexpat.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libcrypto.so",target-name="libcrypto.so",host-name="libcrypto.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libgabi++.so",target-name="libgabi++.so",host-name="libgabi++.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libicuuc.so",target-name="libicuuc.so",host-name="libicuuc.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libicui18n.so",target-name="libicui18n.so",host-name="libicui18n.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libssl.so",target-name="libssl.so",host-name="libssl.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libstlport.so",target-name="libstlport.so",host-name="libstlport.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libnativehelper.so",target-name="libnativehelper.so",host-name="libnativehelper.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libnetutils.so",target-name="libnetutils.so",host-name="libnetutils.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libGLESv2_dbg.so",target-name="libGLESv2_dbg.so",host-name="libGLESv2_dbg.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libEGL.so",target-name="libEGL.so",host-name="libEGL.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libwpa_client.so",target-name="libwpa_client.so",host-name="libwpa_client.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libhardware_legacy.so",target-name="libhardware_legacy.so",host-name="libhardware_legacy.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libpixelflinger.so",target-name="libpixelflinger.so",host-name="libpixelflinger.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libhardware.so",target-name="libhardware.so",host-name="libhardware.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libemoji.so",target-name="libemoji.so",host-name="libemoji.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libjpeg.so",target-name="libjpeg.so",host-name="libjpeg.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libsecnativefeature.so",target-name="libsecnativefeature.so",host-name="libsecnativefeature.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libharfbuzz.so",target-name="libharfbuzz.so",host-name="libharfbuzz.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libquramimagecodec.so",target-name="libquramimagecodec.so",host-name="libquramimagecodec.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libskia.so",target-name="libskia.so",host-name="libskia.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libui.so",target-name="libui.so",host-name="libui.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libGLESv2.so",target-name="libGLESv2.so",host-name="libGLESv2.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libmemalloc.so",target-name="libmemalloc.so",host-name="libmemalloc.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libQcomUI.so",target-name="libQcomUI.so",host-name="libQcomUI.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libremotedesktop_client.so",target-name="libremotedesktop_client.so",host-name="libremotedesktop_client.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libgui.so",target-name="libgui.so",host-name="libgui.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libcamera_client.so",target-name="libcamera_client.so",host-name="libcamera_client.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libsqlite.so",target-name="libsqlite.so",host-name="libsqlite.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libqc-opt.so",target-name="libqc-opt.so",host-name="libqc-opt.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libdvm.so",target-name="libdvm.so",host-name="libdvm.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libGLESv1_CM.so",target-name="libGLESv1_CM.so",host-name="libGLESv1_CM.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libETC1.so",target-name="libETC1.so",host-name="libETC1.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libsisodrm.so",target-name="libsisodrm.so",host-name="libsisodrm.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libsonivox.so",target-name="libsonivox.so",host-name="libsonivox.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libstagefright_foundation.so",target-name="libstagefright_foundation.so",host-name="libstagefright_foundation.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libmedia.so",target-name="libmedia.so",host-name="libmedia.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libQmageDecoder.so",target-name="libQmageDecoder.so",host-name="libQmageDecoder.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libnfc_ndef.so",target-name="libnfc_ndef.so",host-name="libnfc_ndef.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libusbhost.so",target-name="libusbhost.so",host-name="libusbhost.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libhwui.so",target-name="libhwui.so",host-name="libhwui.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libtilerenderer.so",target-name="libtilerenderer.so",host-name="libtilerenderer.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libbluedroid.so",target-name="libbluedroid.so",host-name="libbluedroid.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libdbus.so",target-name="libdbus.so",host-name="libdbus.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libandroid_runtime.so",target-name="libandroid_runtime.so",host-name="libandroid_runtime.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libvorbisidec.so",target-name="libvorbisidec.so",host-name="libvorbisidec.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libstagefright_yuv.so",target-name="libstagefright_yuv.so",host-name="libstagefright_yuv.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libdrmframework.so",target-name="libdrmframework.so",host-name="libdrmframework.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libpowermanager.so",target-name="libpowermanager.so",host-name="libpowermanager.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libdiag.so",target-name="libdiag.so",host-name="libdiag.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libaudcal.so",target-name="libaudcal.so",host-name="libaudcal.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libacdbloader.so",target-name="libacdbloader.so",host-name="libacdbloader.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libalsa-intf.so",target-name="libalsa-intf.so",host-name="libalsa-intf.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libchromium_net.so",target-name="libchromium_net.so",host-name="libchromium_net.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libstagefright_amrnb_common.so",target-name="libstagefright_amrnb_common.so",host-name="libstagefright_amrnb_common.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libstagefright_enc_common.so",target-name="libstagefright_enc_common.so",host-name="libstagefright_enc_common.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libstagefright_avc_common.so",target-name="libstagefright_avc_common.so",host-name="libstagefright_avc_common.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libsavscmn.so",target-name="libsavscmn.so",host-name="libsavscmn.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libsavsff.so",target-name="libsavsff.so",host-name="libsavsff.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libsurfaceflinger_client.so",target-name="libsurfaceflinger_client.so",host-name="libsurfaceflinger_client.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libtvoutinterface.so",target-name="libtvoutinterface.so",host-name="libtvoutinterface.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libtvoutservice.so",target-name="libtvoutservice.so",host-name="libtvoutservice.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libmm-abl-oem.so",target-name="libmm-abl-oem.so",host-name="libmm-abl-oem.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libmm-abl.so",target-name="libmm-abl.so",host-name="libmm-abl.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libstagefright.so",target-name="libstagefright.so",host-name="libstagefright.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libmtp.so",target-name="libmtp.so",host-name="libmtp.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libexif.so",target-name="libexif.so",host-name="libexif.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libmedia_jni.so",target-name="libmedia_jni.so",host-name="libmedia_jni.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libbcc.so",target-name="libbcc.so",host-name="libbcc.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libbcinfo.so",target-name="libbcinfo.so",host-name="libbcinfo.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libRS.so",target-name="libRS.so",host-name="libRS.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="librs_jni.so",target-name="librs_jni.so",host-name="librs_jni.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libandroid.so",target-name="libandroid.so",host-name="libandroid.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libv8.so",target-name="libv8.so",host-name="libv8.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libwebcore.so",target-name="libwebcore.so",host-name="libwebcore.so",symbols-loaded="0",thread-group="i1"
=library-loaded,id="libradgame.so",target-name="libradgame.so",host-name="E:\\uppercut\\prototype\\build\\code\\androidp4\\radgame/./obj/local/armeabi-v7a/libradgame.so",symbols-loaded="0",thread-group="i1"
&"warning: Could not load shared library symbols for 83 libraries, e.g. libstdc++.so.\nUse the \"info sharedlibrary\" command to see the complete listing.\nDo you need \"set solib-search-path\" or \"set sysroot\"?"
&"\n"
warning: Could not load shared library symbols for 83 libraries, e.g. libstdc++.so.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
&"warning: Breakpoint address adjusted from 0xb00056f5 to 0xb00056f4.\n"
warning: Breakpoint address adjusted from 0xb00056f5 to 0xb00056f4.
*stopped,frame={addr="0x4004d738",func="__futex_syscall3",args=[],from="E:\\uppercut\\prototype\\build\\code\\androidp4\\radgame/./obj/local/armeabi-v7a/libc.so"},thread-id="1",stopped-threads="all",core="0"
98^connected
(gdb)
99 info proc
&"info proc\n"
&"Undefined info command: \"proc\". Try \"help info\".\n"
99^error,msg="Undefined info command: \"proc\". Try \"help info\"."
(gdb)
100-environment-cd E:\\uppercut\\prototype\\build\\code\\androidp4\\radgame
100^done
(gdb)
101 info program
&"info program\n"
~"Debugging a target over a serial line.\n"
~"Program stopped at 0x4004d738.\n"
~"It stopped with signal SIGTRAP, Trace/breakpoint trap.\n"
~"Type \"info stack\" or \"info registers\" for more information.\n"
101^done
(gdb)
102 info threads
&"info threads\n"
=thread-created,id="2",group-id="i1"
~"[New Thread 3219]\n"
=thread-created,id="3",group-id="i1"
~"[New Thread 3223]\n"
=thread-created,id="4",group-id="i1"
~"[New Thread 3224]\n"
=thread-created,id="5",group-id="i1"
~"[New Thread 3225]\n"
=thread-created,id="6",group-id="i1"
~"[New Thread 3226]\n"
=thread-created,id="7",group-id="i1"
~"[New Thread 3229]\n"
=thread-created,id="8",group-id="i1"
~"[New Thread 3230]\n"
=thread-created,id="9",group-id="i1"
~"[New Thread 3231]\n"
=thread-created,id="10",group-id="i1"
~"[New Thread 3233]\n"
=thread-created,id="11",group-id="i1"
~"[New Thread 3317]\n"
=thread-created,id="12",group-id="i1"
~"[New Thread 3320]\n"
~" Id Target Id Frame \n"
~" 12 Thread 3320 0x4004c7fc in __ioctl () from E:\\uppercut\\prototype\\build\\code\\androidp4\\radgame/./obj/local/armeabi-v7a/libc.so\n"
I have had debugging working before with gdb, with a Java entry point and 'armeabi'. After switching to C++ entry point (android_main) and 'armeabi-v7a', gdb crashes. I don't know if either is related...
For what it's worth, gdb also crashes any other time I connect (I remove the infinite while loop on startup). For example I'm having thread issues, so my app hangs for no apparent reason. If I connect when it's hung, then gdb crashes in the same way.
This was due to one or both of these GCC compiler flags, which I had added while switching to armeabi-v7a, and then forgot about.
-gstabs+ -g
The version of gdb that comes with the NDK must not like those flags.
Related
Android: building a static aarch64 gdb
I am having a lot of trouble using gdbserver and gdbserver64 on Android and the companion aarch64 gdb on my host. For example, I run into issues like this, where gdb is outputting what seems to be nonsense: (gdb) target remote :5039 Remote debugging using :5039 warning: Could not load vsyscall page because no executable was specified try using the "file" command first. 0x0000007fa7921d2c in ?? () (gdb) bt Python Exception <type 'exceptions.ImportError'> No module named gdb.frames: #0 0x0000007fa7921d2c in ?? () #1 0x0000000040000600 in ?? () Backtrace stopped: Cannot access memory at address 0x22eee199476794f4 (gdb) c Continuing. Program received signal SIGSEGV, Segmentation fault. 0x0000007f87c249b4 in ?? () (gdb) x/4i $pc => 0x7f87c249b4: ldrb w8, [x0,#432] 0x7f87c249b8: cbz w8, 0x7f87c249ec 0x7f87c249bc: ldr x8, [x19,#3632] 0x7f87c249c0: ldr x9, [x8,#24] (gdb) bt Python Exception <type 'exceptions.ImportError'> No module named gdb.frames: #0 0x0000007f87c249b4 in ?? () #1 0x0000007fa4b4fb25 in ?? () #2 0x0000000000000001 in ?? () Backtrace stopped: previous frame identical to this frame (corrupt stack?) (gdb) c Continuing. [New Thread 22374] [New Thread 22375] Program received signal SIGSEGV, Segmentation fault. 0x0000007f87c249b4 in ?? () (gdb) c Continuing. Program received signal SIGSEGV, Segmentation fault. 0x0000007f87c249b4 in ?? () This is almost impossible to use, with everything being totally unhelpful. No symbols are loaded and no backtraces are even remotely reasonable. The app is also repeatedly signaled in places that it is not signaled at when being straced or traced using a static gdb (just to name one specific problem with it). However, I was able to use a prebuilt armv7a statically linked gdb binary to debug some 32-bit applications in an Android emulator with relative ease. I ran the static gdb in a device shell without issue. I had no trouble loading symbols and had no odd signaling problems. I couldn't find a statically linked aarch64 gdb binary anywhere, so I tried to build one inside my aarch64 chroot. I did manage to build gdb for aarch64, and I used these configure flags: LDFLAGS="-static" ../configure --prefix=/noprefix --enable-static --disable-shared --disable-interprocess-agent --disable-libcc1 But it is dynamically linked, which is not what I wanted. root#gram:/opt/gdb-aarch64/noprefix/bin# file gdb gdb: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=f1a630e569467794c45b4389f510720c4342704b, not stripped How do I build a statically linked linux aarch64 gdb?
Next step error when debugging Android kernel
I am researching Linux kernel source code on Android. So I built a debugging environment on Android emulator (the emulator based on qemu). But, when I debug the kernel using gdb, the next command always jump to error code. Here is the example: (gdb) b vfs_write Breakpoint 3 at 0xffffffff80383ec8: file fs/read_write.c, line 527. (gdb) c Continuing. [Switching to Thread 3] Thread 3 hit Breakpoint 3, vfs_write (file=0xffff88003aa7a600, buf=0x72f8f6490f9f "*\032_\f\220\250\364\275\345\310\023\320\022", count=1, pos=0xffff88000b7c7f18) at fs/read_write.c:527 527 if (!(file->f_mode & FMODE_WRITE)) (gdb) list 522 523 ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_t *pos) 524 { 525 ssize_t ret; 526 527 if (!(file->f_mode & FMODE_WRITE)) 528 return -EBADF; 529 if (!(file->f_mode & FMODE_CAN_WRITE)) 530 return -EINVAL; 531 if (unlikely(!access_ok(VERIFY_READ, buf, count))) (gdb) n ioread8 (addr=0xffffc90000040000) at lib/iomap.c:73 73 IO_COND(addr, return inb(port), return readb(addr)); (gdb) The breakpoint at fs/read_write.c:527. When next (n), the debugger should stop at fs/read_write.c:528 or fs/read_write.c:529. But unexpected, it jumped to lib/iomap.c:73. Why does this problem happen? I get the Android kernel source from https://android.googlesource.com/kernel/goldfish And, I checkout branch android-goldfish-4.4-dev I built the kernel with some configs: CONFIG_DEBUG_KERNEL=y CONFIG_DEBUG_INFO=y CONFIG_KGDB=y CONFIG_FRAME_POINTER=y \# CONFIG_DEBUG_RODATA is not set \# CONFIG_RANDOMIZE_BASE is not set I launched the emulator like this: emulator -avd Pixel2XL-x86_64 -show-kernel -verbose -wipe-data -netfast -kernel arch/x86/boot/bzImage -qemu -s The avd Pixel2XL-x86_64 is x86_64 arch, and I built the kernel as x86_64. Someone said this is caused by GCC O2 optimize. I referenced kernel hacking: GCC optimization for better debug experience (-Og) But, it was useless.
NDK r11b: help needed using the ndk-gdb.py debugger
Platform is Mac, Using NDK r11b, my application consists of around 8 c/c++ so files. In the past I've used ndk-gdb (sh) script via NDK r10e. the shell script is now deprecated and ndk-gdb.py is now the only option. Problem is I can't get it to work. I'm running it from my project folder as I've always done. I've tried multiple command line options with no luck. It feels like it isn't finding my source files. It launches the application with the "Waiting for Debugger". I get to the (gdb) prompt. I've tried adding breakpoints with no luck breaking at reliable interrupt points. I need some pointers as to how to configure and use the python version for ndk-gdb. Google has removed the documentation files and I can't find anything anywhere that suffices as a guide. Some command lines I've tried. ndk-gdb --launch --verbose This launches the application but blocks on Waiting for debugger ndk-gdb will attach to a running process. ctr-c will pause the execution but a back trace bt lists a corrupt stack. ndk-gdb --launch -t -v -p $ProjectDir I get a new interface I'm not familiar with and it states [ No Source Available ] Any help or insight would be appreciated
Same story for me - I was able to get past "Waiting for Debugger" message for a new debugging session by issuing ndk-gdb --launch --force --nowait but still ndk-gdb doesn't work well even with Google's NDK samples. Only info thread command produces the actual result except of stack traces - bt, info stack and others complaints on the corrupt stack. My target device is Nexus 5 running API 23 with latest updates. The same binaries compiled by NDK r11b could be successfully debugged by GDB 7.7 from a previous NDK r10e. On Windows, ndk-gdb.py fails with the following error message: Traceback (most recent call last): File "F:\work\android-ndk-r11b\prebuilt\windows\bin\ndk-gdb.py", line 704, in <module> main() File "F:\work\android-ndk-r11b\prebuilt\windows\bin\ndk-gdb.py", line 583, in main args.props = device.get_props() File "F:\work\android-ndk-r11b\python-packages\adb\device.py", line 459, in get_props raise RuntimeError('invalid getprop line: "{}"'.format(line)) RuntimeError: invalid getprop line: "" Actually, it looks like ndk-gdb.py from NDK r11b only works on Linux: vagrant#vagrant:/vagrant/native_activity$ $ANDROID_NDK_ROOT/ndk-gdb --launch --force WARNING: Failed to find jdb on your path, defaulting to --nowait Redirecting gdbclient output to /tmp/gdbclient-9150 GNU gdb (GDB) 7.10 ... This GDB was configured as "x86_64-linux-gnu". ... warning: Could not load shared library symbols for 110 libraries, e.g. /system/lib/libcutils.so. Use the "info sharedlibrary" command to see the complete listing. Do you need "set solib-search-path" or "set sysroot"? 0xb6c93894 in __epoll_pwait () from /vagrant/native_activity/obj/local/armeabi-v7a/system/lib/libc.so (gdb) info sources Source files for which symbols have been read in: Source files for which symbols will be read in on demand: /Volumes/Android/buildbot/tmp/build/toolchain/gcc-4.9/gcc/include/unwind-arm-common.h, /Volumes/Android/buildbot/src/android/gcc/toolchain/build/../gcc/gcc-4.9/libgcc/config/arm/pr-support.c, /Volumes/Android/buildbot/src/android/gcc/toolchain/build/../gcc/gcc-4.9/libgcc/config/arm/libunwind.S, /Volumes/Android/buildbot/tmp/build/toolchain/gcc-4.9/arm-linux-androideabi/armv7-a/libgcc/./unwind.h, /Volumes/Android/buildbot/src/android/gcc/toolchain/build/../gcc/gcc-4.9/libgcc/unwind-arm-common.inc, /Volumes/Android/buildbot/src/android/gcc/toolchain/build/../gcc/gcc-4.9/libgcc/config/arm/unwind-arm.c, /Users/mike/android-ndk-r11b/sources/android/native_app_glue/android_native_app_glue.c, /vagrant/native_activity/jni/main.c Basic commands is working correctly: (gdb) bt #0 0xb6c93894 in __epoll_pwait () from /vagrant/native_activity/obj/local/armeabi-v7a/system/lib/libc.so #1 0xb6c6ce72 in epoll_pwait () from /vagrant/native_activity/obj/local/armeabi-v7a/system/lib/libc.so #2 0xb6c6ce80 in epoll_wait () from /vagrant/native_activity/obj/local/armeabi-v7a/system/lib/libc.so #3 0xb6ebfc5a in ?? () Backtrace stopped: previous frame identical to this frame (corrupt stack?) (gdb) info thread Id Target Id Frame 11 Thread 28735 0xb6c6a5e4 in syscall () from /vagrant/native_activity/obj/local/armeabi-v7a/system/lib/libc.so 10 Thread 28733 0xb6c93894 in __epoll_pwait () from /vagrant/native_activity/obj/local/armeabi-v7a/system/lib/libc.so 9 Thread 28721 0xb6c939bc in __ioctl () from /vagrant/native_activity/obj/local/armeabi-v7a/system/lib/libc.so 8 Thread 28720 0xb6c939bc in __ioctl () from /vagrant/native_activity/obj/local/armeabi-v7a/system/lib/libc.so 7 Thread 28719 0xb6c6a5e4 in syscall () from /vagrant/native_activity/obj/local/armeabi-v7a/system/lib/libc.so 6 Thread 28718 0xb6c6a5e4 in syscall () from /vagrant/native_activity/obj/local/armeabi-v7a/system/lib/libc.so 5 Thread 28717 0xb6c6a5e4 in syscall () from /vagrant/native_activity/obj/local/armeabi-v7a/system/lib/libc.so 4 Thread 28716 0xb6c6a5e4 in syscall () from /vagrant/native_activity/obj/local/armeabi-v7a/system/lib/libc.so 3 Thread 28715 0xb6c94948 in recvmsg () from /vagrant/native_activity/obj/local/armeabi-v7a/system/lib/libc.so 2 Thread 28714 0xb6c93b68 in __rt_sigtimedwait () from /vagrant/native_activity/obj/local/armeabi-v7a/system/lib/libc.so * 1 Thread 28709 0xb6c93894 in __epoll_pwait () from /vagrant/native_activity/obj/local/armeabi-v7a/system/lib/libc.so
This issue was posted to the https://github.com/android-ndk/ndk/issues site that Mikhail provided. The issue was assigned and claimed fixed: Resolution will be propagated in NDK r11c; https://github.com/android-ndk/ndk/issues/51 additionally I updated to R11c. everything is now working
How to Debug native code using ndk-gdb
This is what I am getting after running ndk-gdb according to many tutorials when it links to you to (gdb) server you have to type continue but what after that how to debug the code there after. In my case it displays Continuing and remain like this. WHat i have to do further I am totally clueless. Arathore#chd-arathore-AND /cygdrive/d/All_Work/All_ARathore/All_Workspace_Practice/ndkfoo $ /cygdrive/d/All_Required_Stuff/Android/android-ndk-r8e/ndk-gdb --verbose --adb=/cygdrive/D/All_Required_Stuff/Android/android-sdk-windows/platform-tools/adb.exe Android NDK installation path: /cygdrive/d/All_Required_Stuff/Android/android-ndk-r8e Using specific adb command: /cygdrive/D/All_Required_Stuff/Android/android-sdk-windows/platform-tools/adb.exe ADB version found: Android Debug Bridge version 1.0.31 Using ADB flags: Using auto-detected project path: . Found package name: com.example.ndkfoo /cygdrive/d/All_Required_Stuff/Android/android-ndk-r8e/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in /cygdrive/d/All_Work/All_ARathore/All_Workspace_Practice/ndkfoo/AndroidManifest.xml ABIs targetted by application: armeabi Device API Level: 17 Device CPU ABIs: armeabi-v7a armeabi Compatible device ABI: armeabi /cygdrive/d/All_Required_Stuff/Android/android-ndk-r8e/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in /cygdrive/d/All_Work/All_ARathore/All_Workspace_Practice/ndkfoo/AndroidManifest.xml Using gdb setup init: /cygdrive/d/All_Work/All_ARathore/All_Workspace_Practice/ndkfoo/libs/armeabi/gdb.setup /cygdrive/d/All_Required_Stuff/Android/android-ndk-r8e/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in /cygdrive/d/All_Work/All_ARathore/All_Workspace_Practice/ndkfoo/AndroidManifest.xml Using toolchain prefix: /cygdrive/d/All_Required_Stuff/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/arm-linux-androideabi- /cygdrive/d/All_Required_Stuff/Android/android-ndk-r8e/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in /cygdrive/d/All_Work/All_ARathore/All_Workspace_Practice/ndkfoo/AndroidManifest.xml Using app out directory: ./obj/local/armeabi Found debuggable flag: true Found device gdbserver: /data/data/com.example.ndkfoo/lib/gdbserver Found data directory: '/data/data/com.example.ndkfoo' Found running PID: 1106 Launched gdbserver succesfully. Setup network redirection ## COMMAND: adb_cmd shell run-as com.example.ndkfoo lib/gdbserver +debug-socket --attach 1106 ## COMMAND: adb_cmd forward tcp:5039 localfilesystem:/data/data/com.example.ndkfoo/debug-socket ## COMMAND: adb_cmd pull /system/bin/app_process obj/local/armeabi/app_process Attached; pid = 1106 Listening on Unix socket debug-socket 99 KB/s (9592 bytes in 0.093s) Pulled app_process from device/emulator. ## COMMAND: adb_cmd pull /system/bin/linker obj/local/armeabi/linker 54 KB/s (63240 bytes in 1.140s) Pulled linker from device/emulator. ## COMMAND: adb_cmd pull /system/lib/libc.so obj/local/armeabi/libc.so 75 KB/s (297604 bytes in 3.828s) Pulled libc.so from device/emulator. GNU gdb (GDB) 7.3.1-gg2 Copyright (C) 2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=i586-pc-mingw32msvc --target=arm-linux-android". For bug reporting instructions, please see: <http://source.android.com/source/report-bugs.html>. Remote debugging from host 0.0.0.0 libthread_db:td_ta_new: Probing system for platform bug. libthread_db:_get_task_permitted_caps: Found CapPerm of 0 in /proc/1147/task/1147/status libthread_db:_get_task_permitted_caps: Found CapPerm of 0 in /proc/1106/task/1106/status libthread_db:_get_task_permitted_caps: Found CapPerm of 0 in /proc/1106/task/1109/status libthread_db:_get_task_permitted_caps: Found CapPerm of 0 in /proc/1106/task/1111/status libthread_db:_get_task_permitted_caps: Found CapPerm of 0 in /proc/1106/task/1112/status libthread_db:_get_task_permitted_caps: Found CapPerm of 0 in /proc/1106/task/1113/status libthread_db:_get_task_permitted_caps: Found CapPerm of 0 in /proc/1106/task/1114/status libthread_db:_get_task_permitted_caps: Found CapPerm of 0 in /proc/1106/task/1115/status libthread_db:_get_task_permitted_caps: Found CapPerm of 0 in /proc/1106/task/1116/status libthread_db:_get_task_permitted_caps: Found CapPerm of 0 in /proc/1106/task/1117/status libthread_db:_get_task_permitted_caps: Found CapPerm of 0 in /proc/1106/task/1118/status libthread_db:td_ta_new: Victory: We can debug theads! 0x40037ebc in epoll_wait () from D:/All_Work/All_ARathore/All_Workspace_Practice/ndkfoo/obj/local/armeabi/libc.so warning: Could not load shared library symbols for 72 libraries, e.g. libstdc++.so. Use the "info sharedlibrary" command to see the complete listing. Do you need "set solib-search-path" or "set sysroot"? warning: Breakpoint address adjusted from 0x40005a53 to 0x40005a52. (gdb) continue Continuing. How to debug? According to the ndk-Docs You can set breakpoints with 'b <location>' and resume execution with 'c' (for 'continue'). See the GDB manual for a list of commands. How to make this happen.
The commands are the same as in gdb. A basic primer: Set a breakpoint by entering b <function name> or b <file>:<line number> step into functions by typing s go to next line by typing n continue execution with c print a variable or expression value with print <exp> repeat the last typed command by just hitting enter You can find much more comprehensive gdb tutorials online. I personally have a gdb cheatsheet printed out and posted on my wall. This should be enough to get you started.
this tutorial will show you exactly how to debugging with ndk-gdb in eclipse.
Not able to hit the break point in ndk-gdb in Android
Development Environment: NDK: r7 SDK & Tools: r15 AVD: GB2.3.3, API Level 10 I wrote a test application in which thread will be launched in the native. I Kept a break point in the thread. (Intially when i tried on Galaxy S2 i was getting an error, "Thread debugging not supported in this Platform". So i created an AVD 2.3.3 Level 10). After this i was getting an error like this #0 0xafd0c51c in epoll_wait () from /Volumes/SecureCode/webos/rta/android/obj/local/armeabi/libc.so #1 0xa81216a6 in ?? () I googled and found this Solution (Link Here). I followed the guide lines there $ adb pull /system/lib lib $ ndk-gdb ... (gdb) set solib-search-path lib But after this also I am not able to hit the break point. I am still getting stuck at this poll_wait() and not moving forward. D:\EclipseTestWorkspace\CallbackJava>sh sh-4.1$ ndk-gdb --force --start --verbose Android NDK installation path: /cygdrive/c/Android/android-ndk Using default adb command: /cygdrive/c/Android/android-sdk-windows/platform-tools/adb ADB version found: Android Debug Bridge version 1.0.29 Using final ADB command: '/cygdrive/c/Android/android-sdk-windows/platform-tools/adb' Using auto-detected project path: . Found package name: com.callback ABIs targetted by application: armeabi Device API Level: 10 Device CPU ABI: armeabi Compatible device ABI: armeabi Found debuggable flag: true Found device gdbserver: /data/data/com.callback/lib/gdbserver Using gdb setup init: ./libs/armeabi/gdb.setup Using toolchain prefix: /cygdrive/c/Android/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi- Using app out directory: ./obj/local/armeabi Found data directory: '/data/data/com.callback' Found first launchable activity: .CallbackJavaActivity Launching activity: com.callback/.CallbackJavaActivity ## COMMAND: /cygdrive/c/Android/android-sdk-windows/platform-tools/adb shell am start -n com.callback/.CallbackJavaActivity Starting: Intent { cmp=com.callback/.CallbackJavaActivity } ## COMMAND: /cygdrive/c/Android/android-sdk-windows/platform-tools/adb shell sleep 2 Found running PID: 352 Launched gdbserver succesfully. ## COMMAND: /cygdrive/c/Android/android-sdk-windows/platform-tools/adb shell run-as com.callback lib/gdbserver +debug-socket --attach 352 Setup network redirection ## COMMAND: /cygdrive/c/Android/android-sdk-windows/platform-tools/adb forward tcp:5039 localfilesystem:/data/data/com.callback/debug-socket ## COMMAND: /cygdrive/c/Android/android-sdk-windows/platform-tools/adb pull /system/bin/app_process obj/local/armeabi/app_process Attached; pid = 352 Listening on sockaddr socket debug-socket 19 KB/s (5660 bytes in 0.281s) Pulled app_process from device/emulator. ## COMMAND: /cygdrive/c/Android/android-sdk-windows/platform-tools/adb pull /system/lib/libc.so obj/local/armeabi/libc.so 80 KB/s (273868 bytes in 3.325s) Pulled libc.so from device/emulator. GNU gdb 6.6 Copyright (C) 2006 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "--host=i586-mingw32msvc --target=arm-elf-linux". (no debugging symbols found) Error while mapping shared library sections: /system/bin/linker: No such file or directory. ----- So many similar errors ----- Error while mapping shared library sections: gralloc.default.so: No such file or directory. (no debugging symbols found) warning: Unable to find dynamic linker breakpoint function. GDB will be unable to debug shared library initializers and track explicitly loaded dynamic code. warning: shared library handler failed to enable breakpoint 0xafd0c51c in epoll_wait () from D:/EclipseTestWorkspace/CallbackJava/obj/local/armeabi/libc.so (gdb) set solib-search-path lib Error while mapping shared library sections: /system/bin/linker: No such file or directory. Error while mapping shared library sections: gralloc.default.so: No such file or directory. Symbol file not found for /system/bin/linker Reading symbols from D:\EclipseTestWorkspace\CallbackJava/lib/libc.so...(no debugging symbols found)...done. Loaded symbols for D:\EclipseTestWorkspace\CallbackJava/lib/libc.so ----- So many similar errors ----- Loaded symbols for D:\EclipseTestWorkspace\CallbackJava/lib/libwebcore.so Symbol file not found for gralloc.default.so (gdb) file ./libs/armeabi/libcallbacks.so A program is being debugged already. Are you sure you want to change the file? (y or n) y Reading symbols from D:\EclipseTestWorkspace\CallbackJava/./libs/armeabi/libcallbacks.so...(no debugging symbols found)...done. (gdb) file ./obj/local/armeabi/libcallbacks.so A program is being debugged already. Are you sure you want to change the file? (y or n) y Reading symbols from D:\EclipseTestWorkspace\CallbackJava/./obj/local/armeabi/libcallbacks.so...done. (gdb) break callbacks_java.cpp:appcallback_register Breakpoint 1 at 0x1a64: file D:/EclipseTestWorkspace/CallbackJava/jni/callbacks_java.cpp, line 419. (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y 0x00001a64 in appcallback_register at D:/EclipseTestWorkspace/CallbackJava/jni/callbacks_java.cpp:419 (gdb) where #0 0xafd0c51c in epoll_wait () from D:\EclipseTestWorkspace\CallbackJava/lib/libc.so #1 0xa81211b4 in android::Looper::pollInner () from D:\EclipseTestWorkspace\CallbackJava/lib/libutils.so #2 0x00000000 in ?? () (gdb) where #0 0xafd0c51c in epoll_wait () from D:\EclipseTestWorkspace\CallbackJava/lib/libc.so #1 0xa81211b4 in android::Looper::pollInner () from D:\EclipseTestWorkspace\CallbackJava/lib/libutils.so #2 0x00000000 in ?? () (gdb) c Continuing. Warning: Cannot insert breakpoint 1. Error accessing memory address 0x1a64: Input/output error. (gdb) Which i would like to concentrate on main part as (gdb) file ./libs/armeabi/libcallbacks.so A program is being debugged already. Are you sure you want to change the file? (y or n) y Reading symbols from D:\EclipseTestWorkspace\CallbackJava/./libs/armeabi/libcallbacks.so...(no debugging symbols found)...done. (gdb) file ./obj/local/armeabi/libcallbacks.so A program is being debugged already. Are you sure you want to change the file? (y or n) y Reading symbols from D:\EclipseTestWorkspace\CallbackJava/./obj/local/armeabi/libcallbacks.so...done. (gdb) break callbacks_java.cpp:appcallback_register Breakpoint 1 at 0x1a64: file D:/EclipseTestWorkspace/CallbackJava/jni/callbacks_java.cpp, line 419. (gdb) info breakpoints Num Type Disp Enb Address What 1 breakpoint keep y 0x00001a64 in appcallback_register at D:/EclipseTestWorkspace/CallbackJava/jni/callbacks_java.cpp:419 (gdb) where #0 0xafd0c51c in epoll_wait () from D:\EclipseTestWorkspace\CallbackJava/lib/libc.so #1 0xa81211b4 in android::Looper::pollInner () from D:\EclipseTestWorkspace\CallbackJava/lib/libutils.so #2 0x00000000 in ?? () (gdb) where #0 0xafd0c51c in epoll_wait () from D:\EclipseTestWorkspace\CallbackJava/lib/libc.so #1 0xa81211b4 in android::Looper::pollInner () from D:\EclipseTestWorkspace\CallbackJava/lib/libutils.so #2 0x00000000 in ?? () (gdb) c Continuing. Warning: Cannot insert breakpoint 1. Error accessing memory address 0x1a64: Input/output error. (gdb) So from the last error what i understand is its considering the absolute address 0x1a64. Its not considering the relative address (runtime address), so not able to hit the break point. and also its getting stuck at the epoll_wait () , not moving further. Will any one please help me how can I proceed further? Thanks & Regards, SSuman185
You could try debugging in Eclipse with DS-5 CE plugin. Tutorial how to install and setup it you can find here http://forums.arm.com/index.php?/topic/15575-arm-ds-5-tutorial-for-android/ (last post is how to make it work on SGS2). I know that is not an exact answer to your question, but if you need NDK debugging on SGS2 you might want to try it, also it's for Eclipse, not a command line gdb (but who could ever prefer command-line debugging instead of debugging in IDE??) PS. DS-5 CE is a first NDK debugging tool that worked for me with SGS2 (it's not perfect - possibly because of bugs/limitations in SGS2 - but at least works).