How to Debug native code using ndk-gdb

DeltaCap019 picture DeltaCap019 · Jul 11, 2013 · Viewed 13.5k times · Source

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.

Answer

krsteeve picture krsteeve · Aug 16, 2013

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.