How to get ndk-gdb working on Android?
You don't need to use -O0 or -g switches.
You need to do one of following:
- put
android:debuggable="true"
to the<application>
tag inAndroidManifest.xml
file - use
NDK_DEBUG=1
after ndk-build - put
APP_OPTIM := debug
in Application.mk file
Doing anyone of these three things will automatically use -O0 and -g switches.
Can you try running gdb manually, without gdb script?
It involves following steps:
- pushing
gdbserver
file to/data/local
folder on device - running your application & invoking in
adb shell
following commandgdbserver :5055 --attach PID
, where PID is your application process id. - running
adb forward tcp:5055 tcp:5055
on host - running
arm-linux-androideabi-gdb.exe
from your app folder - entering following commands in gdb
set solib-search-path obj/local/armeabi
file obj/local/armeabi/libMySharedLib.so
target remote :5055
And see if you can debug then.
If you want see symbols for other shared libraries your library is using like libc.so
, then pull them from device (from /system/lib
folder) to your obj/local/armeabi
folder.
Android NDK + GDB
Ok, finally I made it work. The point was in APP_ABI
line in Application.mk
. There was two ABI's and somehow this confused GDB. Now it works with one abi (I chose armeabi-v7a
).
And something, that i also would like to notice
- there is nothing you really need to do, to make GDB work. Just dont disturb him =)
- every variable (cflag or manifest tag or etc.) has default value suitable for debugging, but thats no matter and i'll recommend you to explicitly set
APP_OPTIM := debug
andAPP_CFLAG := -g -ggdb -O0
inApplication.mk
;android:debuggable="true"
in manifest andNDK_DEBUG=1
forndk-build
. I have not figured out if they somehow helps GDB to work better. Some of them are duplicates of each other. And certainly none of them will not do worse. - It is normal, when
Breakpoint address adjusted
NM
command. I also did not understand it well, but it keeps giving me zero output on every file that I guessed to check. What is really important - output ofinfo sharedlibrary
command in working GDB. Check that for your library has symbols (like mylib3.so
in example above). This is necessary, but not sufficient.
ndk-gdb unable to find gdb.setup
I just answered in the post: https://stackoverflow.com/a/32972182/1617066
I ran into the same problem. It seems something changed in recent version of Android Build tools.
The trick is:
ERROR: Could not find gdb.setup under ./libs/
It expects gdb.setup is in the directory libs but NOT libs/armeabi
so the simple workground is to copy gdb.setup and gdbserver from "libs/cpu" to "libs" and it works like a magic!
NDK r11b: help needed using the ndk-gdb.py debugger
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
Related Topics
Custom Format Edit Text Input Android to Accept Credit Card Number
Android Sdk Cut/Trim Video File
Avoiding Content Type Issues When Downloading a File via Browser on Android
How to Capture an Image in Background Without Using the Camera Application
Recycler View Showing Single Item
Enabling Wifi on Android Emulator
Make a Hyperlink Textview in Android
How to Put the Text on the Left of a Radio Button in Android
Multiple Dex Files Define Lorg/Apache/Cordova/Buildhelper
Android Studio 3.1 Cannot Resolve Symbol (Themes, Widget, Attr, etc.)
Android: Making a Fullscreen Application
Android Seekbar with Two Thumbs
How to Use Recyclerview.Scrolltoposition() to Move the Position to the Top of Current View