Skip to content

Debugging

Bobby Galli edited this page Feb 21, 2021 · 6 revisions

Notes

  • Use adb root shell to attempt to execute libcrashpad_handler.so directly to see if it is compatible with the device
  • Cmake build output is found at ${PROJECT_DIR}/app/.cxx/cmake/${debug|release}/${ABI}
  • Enable debugging of the Crashpad source by adding a symbols path in project configuration, add paths to ${CRASHPAD_DIR}/crashpad and $CRASHPAD_DIR}/crashpad/third_party/mini_chromium/mini_chromium
  • To debug Crashpad at crash time, set a breakpoint in client/crashpad_client_linux.cpp where HandleCrashImpl calls fork(), this will yield the pid of the spawned process

Logs

  • Unfortunately Crashpad sends all log statements to stdout which on Android ultimately ends up getting piped to /dev/null. We found the following code snippet was incredibly valuable as it allows you to pipe stdout to Logcat (reference):
static int pfd[2];
static pthread_t thr;
static const char *tag = "myapp";

int start_logger(const char *app_name)
{
    tag = app_name;

    /* make stdout line-buffered and stderr unbuffered */
    setvbuf(stdout, 0, _IOLBF, 0);
    setvbuf(stderr, 0, _IONBF, 0);

    /* create the pipe and redirect stdout and stderr */
    pipe(pfd);
    dup2(pfd[1], 1);
    dup2(pfd[1], 2);

    /* spawn the logging thread */
    if(pthread_create(&thr, 0, thread_func, 0) == -1)
        return -1;
    pthread_detach(thr);
    return 0;
}

static void *thread_func(void*)
{
    ssize_t rdsz;
    char buf[128];
    while((rdsz = read(pfd[0], buf, sizeof buf - 1)) > 0) {
        if(buf[rdsz - 1] == '\n') --rdsz;
        buf[rdsz] = 0;  /* add null-terminator */
        __android_log_write(ANDROID_LOG_DEBUG, tag, buf);
    }
    return 0;
}
Clone this wiki locally