Android NDK + GDB

Help me use ndk-gdb!

I searched through StackOverflow and other internets =), but was still doing something wrong.

Configuration: MacOSX 64 + last SDK + last NDK + last IDEA + Nexus 7 + project with huge C ++.

I made all the general agreement:

  • -g -ggdb -O0 to LOCAL_CFLAGS (also tried only -g )
  • APP_OPTIM := debug
  • debuggable=ยซtrueยป in the manifest
  • ndk-build NDK_DEBUG=1

I get the expected gdb.setup and gdbserver files, BUT nm gives me zero output in my * .so files.

I run ndk-gdb in the root folder of the project and get a working GDB - for example. I can pause the application and resume it, get the ASM code at address, etc. Even when I install brakepoints using break Class::method , gdb will tell me the correct file name and line number.

But breakpoints do not fall at 99%. The back panel is always clearly erroneous (incorrect method names). It seems like all the symbolic names and addresses are mapped incorrectly.

What did I miss?

UPD gdb at the beginning with two info sharedlibrary and C commands.

 :ndk-gdb /android-ndk-macosx/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than >android:minSdkVersion 8 in ./AndroidManifest.xml /android-ndk-macosx/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than >android:minSdkVersion 8 in ./AndroidManifest.xml /android-ndk-macosx/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than >android:minSdkVersion 8 in ./AndroidManifest.xml /android-ndk-macosx/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than >android:minSdkVersion 8 in ./AndroidManifest.xml 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=x86_64-apple-darwin --target=arm-linux-android". For bug reporting instructions, please see: <http://source.android.com/source/report-bugs.html>. warning: .dynamic section for "/Users/<...>/android/obj/local/armeabi/lib1.so" is not at the expected address (wrong library or version >mismatch?) warning: Could not load shared library symbols for 73 libraries, eg 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 0x400aca53 to 0x400aca52. 0x401a7ee4 in epoll_wait () from /Users/<...>/android/obj/local/armeabi/libc.so (gdb) info sharedlibrary From To Syms Read Shared Object Library 0x400aa220 0x400b2978 Yes (*) /Users/<...>/android/obj/local/armeabi/linker 0x4019c860 0x401cc184 Yes (*) /Users/<...>/android/obj/local/armeabi/libc.so No libstdc++.so No libm.so <...dozens of system libs with "no"...> No libjnigraphics.so 0x6749c160 0x67527844 Yes (*) /Users/<...>/android/obj/local/armeabi/lib1.so 0x65c487f8 0x65c6634c Yes (*) /Users/<...>/android/obj/local/armeabi/lib2.so 0x693e62e8 0x699dcd90 Yes /Users/<...>/android/obj/local/armeabi/lib3.so (*): Shared library is missing debugging information. (gdb) C Continuing.> 

You can see that

  • lib3.so (main lib) loaded the most correctly (or not?)
  • breakpoint address is adjusted (what does this mean?)
+4
source share
1 answer

Well, finally, I have earned. The point was on the line APP_ABI in Application.mk . There were two ABIs and somehow this confusing GDB. Now it works with one abi (I chose armeabi-v7a ).

And something that I would also like to notice

  • you have nothing to do to get GDB to work. Just don't bother him =)
  • each variable (cflag or manifest tag, etc.) has a default value suitable for debugging, but this is not important, and I recommend that you explicitly set APP_OPTIM := debug and APP_CFLAG := -g -ggdb -O0 in Application.mk ; android:debuggable="true" in the manifest and NDK_DEBUG=1 for ndk-build . I did not understand that they somehow help GDB work better. Some of them are duplicates of each other. And, of course, not one of them will be worse.
  • This is normal when Breakpoint address adjusted
  • NM . I also didnโ€™t understand this very well, but he continues to give me zero output for every file I guessed to check. What is really important is the output of the info sharedlibrary to working GDB. Make sure there are characters for your library (e.g. my lib3.so in the example above). It is necessary, but not enough.
+6
source

All Articles