Stack Traces Stop Before Getting To My Code (on Android Using Ndk)
Solution 1:
Is there any way at all to get better stack traces than this?
As far as I know, you must build and write the Android image by yourself. It enables you to have the whole complete symbols of the Android (executable files and shared libraries) except proprietary shared libraries.
Also it provides to use the symbols using gdb.
$ adb shell setprop debug.db.uid 32767
$ adb forward tcp:5039 tcp:5039
/*
program terminated and debuggerd caught exception like the following.
Use the PID number for gdbclient 3rd parameter.
I/DEBUG ( 2154): ********************************************************
I/DEBUG ( 2154): * Process 2508 has been suspended while crashing. To
I/DEBUG ( 2154): * attach gdbserver for a gdb connection on port 5039:
I/DEBUG ( 2154): *
I/DEBUG ( 2154): * adb shell gdbserver :5039 --attach 2508 &
I/DEBUG ( 2154): *
I/DEBUG ( 2154): * Press HOME key to let the process continue crashing.
I/DEBUG ( 2154): ********************************************************)
*/
$ gdbclient "" "" 2508
EDITED:
You can still use ndk-gdb instead of gdbclient command. Please specify the symbol files for shared libraries.
(gdb) set solib-search-path (ANDROID_SOURCE_PATH)/out/target/product/(PRODUCT_NAME)/symbols/system/lib
EDITED 2:
If you don't need the symbols of the Android system shared libraries, just adb pull shared libraries and set sollib-search-path to it.
$ adb pull /system/lib lib
$ ndk-gdb
...
(gdb) set solib-search-path lib
Solution 2:
Couple of notes:
- In some cases, your stack trace may be damaged because your stack has been partially trashed. Unlikely though.
- What OS are you using? Gingerbread (Android 2.3) is much better in terms of stack traces. If you're not running Android 2.3, find an Android 2.3 ROM for your phone somewhere, or get a cheap development phone that runs 2.3.
- Have you seen Onur's script? It's been working very well for me, even on Android 2.2 phones.
- Hope that fadden is reading this, I'm sure he has an answer that is much more helpful than mine.
Solution 3:
Check out the following question: How to generate a stacktrace when my gcc C++ app crashes
We did the same with our Android app.: we wrote our own signal handler, handled signals 7 (sigbus) and 11 (sigsegv) and printed out the stack tace from the handler. We didn't use the backtrace() function though, but unwinded the stack manually...
Combining the first two answers you should be able to write your own signal handler to dump the stack trace. This article may help you also: http://www.ibm.com/developerworks/power/library/l-sigdebug/index.html. Only keep in mind, that extracting register content is architecture dependent, so you must substitute the structures used in the above codes with the ones on android (ARM processor dependent). For example I had to dig into the Android source for 'struct ucontext'.
When you have the stack trace, run a script on the output, which will resolve the symbols using addr2line and your unstripped executable.
Solution 4:
Sorry to flood my own question with answers, but I did discover that integrating Google Breakpad was an excellent way to get good stack traces/crash reports. It's easy to write a signal handler that calls Breakpad, and that takes care of everything; we just have to upload the reports to our server. We also integrated the process of calling stackwalk.sh
into our build system. It took some work, but all in all it's perfect for getting good native crash reports on Android.
This answer has some details on writing a signal handler; the rest of the code you need is on the Google Breakpad site under the wiki.
Solution 5:
I did get an answer to this question for some stack traces. (From the looks of this question that may be all I get.) These are the ones that terminate with an lr
(link register) address. See my other question/answer.
Post a Comment for "Stack Traces Stop Before Getting To My Code (on Android Using Ndk)"