1

In my android project I use a c++ lib that I've implemented. My lib has some crashes, but I can only retrieve the stack traces of the exceptions raised, but not of the signals like SIGSEGV (the stack trace is empty).

To retrieve the stack trace, I've used this code : https://stackoverflow.com/a/28858941/5120292

To handle the signals :

struct sigaction psa, oldPsa;

void Utils::registerSignalHandlers() {

    psa.sa_sigaction = Utils::handleSignal;
    psa.sa_flags = SA_SIGINFO;
    sigemptyset( &psa.sa_mask );

    sigaction(SIGSEGV, &psa, &oldPsa);
}

void Utils::handleSignal(int signalNumber, siginfo_t *sigInfo, void *context) {
    std::string message = get_stacktrace();
    throw std::runtime_error(message); // this will create a java.lang.RuntimeException
}

By the way I can't modify the JNI bridges since they are auto-generated by a tool.

My project has this architecture :

  • android_project
    • ...
    • main_module
    • c++_library_module
      • ...
      • jni
      • libs
        • armeabi-v7a
          • c++_lib.so

I saw that there is a tool called ndk-stack, but I could not understand how to make it work with my project. Also, it would be preferable to retrieve the log inside the program, and not using an external tool.. Any help would be appreciated !

Community
  • 1
  • 1
Xys
  • 8,486
  • 2
  • 38
  • 56
  • In your case it would be something like this (from a Terminal in your android_project folder): `adb logcat | ndk-stack -sym ./c++_library_module/libs/armeabi-v7a` – Daniel Nugent May 17 '16 at 17:51
  • Thank you, since it wrote "waiting for device", I guess it should be working. However when I plug in the device nothing happens. I've made the app crash but nothing is displayed in the terminal, even if I relaunch the command. – Xys May 17 '16 at 18:09
  • Ok so I managed to make ndk-stack work (needed to remove signal handlers to have the native log). But unfortunately it does not help me since it does not display the whole stack : It can't reach the function where I added the SIGSEGV on purpose (stops at first function ?). Anyway not using ndk-stack would be better for me since I would prefer to retrieve the stack trace in the code, if it's possible.. – Xys May 17 '16 at 18:23
  • Actually ndk-stack works fine, but it seems you need to wait a bit before the app starts to have full logs. If the crash happens at the start, ndk-stack will not provide full stack trace – Xys May 25 '16 at 14:38

0 Answers0