I have set up debugging in Eclipse for native code using the Android NDK (on Windows XP, with Cygwin) to the stage where I can set breakpoints in both Java and native code and the debugger will break at them correctly. My issue is that when stepping through the native code, I will often get segmentation faults/SIGILLs that do not occur when continuing past the breakpoint instead.
- My application is debuggable as defined in AndroidManifest.xml
- I have altered the (NDK)/build/core/build-binary.mk to prevent it from stripping out debug symbols when
APP_OPTIM
is defined as debug, which it is in the Application.mk file in my jni directory - I have defined
LOCAL_CFLAGS := -g -O0
in the Android.mk file, and I have also tried each of these flags individually
I have read that this problem is to do with the optimised code generated, but turning optimisation off with -O0
has no impact on my issue. I have also come across using the NDK_BUILD=1
flag when building, but defining debuggable=true
in AndroidManifest.xml apparently has the same effect.
I have tried this both on an emulator (running 2.3.3) and on a device (running 2.2 - which surprisingly didn't have the thread issues I expected), with similar results (although if I remember correctly, 开发者_JAVA技巧the failures happened at different points in code).
Does anyone have any insight into possible fixes/steps I could try, and/or have been able to successfully step through native code with no issues?
Thanks very much
Edit: This was never really solved, but for anyone who wants to take a look at my guide for NDK debugging, you can find it here.
Edit 2: The answers I got to this question came once new versions of the NDK had come out, and this question may now be redundant. My guide may still work, but I haven't been using the NDK for a while so I cannot vouch for its continued correctness. I have accepted the answer I have as all three basically say the same thing, and that was the first one to be submitted.
If it works for armeabi and not for armeabi-v7a, this should be a build issue. Unzip the apk file in the bin directory and check the library files in both the armeabi and armeabi-v7a are the same.
One thing that I've noticed is that armeabi-v7a doesn't work well for debugging native code on certain devices. Try building for only armeabi and see if that helps.
compile the c++ source files with -march=armv4
In build/core/combo/arm/yourarch.mk put -march=armv4 and then do mm -B showcommands to check if it was used.
Then gdbserver can handle it.
精彩评论