diff options
author | Elliott Hughes <enh@google.com> | 2014-05-17 03:34:38 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-05-17 03:34:38 +0000 |
commit | 9cb0b5719c0ac5fefc043f0c61b1640e058b7793 (patch) | |
tree | 65aae3ce73bec2761cc804c2afaf3c1692424ce5 | |
parent | 770cd7c7e7c18a657f233d86aeecb1d9f3091449 (diff) | |
parent | d9bf2b21370faeda4ef57932a42a14c05557e71a (diff) | |
download | system_core-9cb0b5719c0ac5fefc043f0c61b1640e058b7793.zip system_core-9cb0b5719c0ac5fefc043f0c61b1640e058b7793.tar.gz system_core-9cb0b5719c0ac5fefc043f0c61b1640e058b7793.tar.bz2 |
Merge "Output correct gdbserver instructions from debuggerd."
-rw-r--r-- | debuggerd/debuggerd.cpp | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/debuggerd/debuggerd.cpp b/debuggerd/debuggerd.cpp index 94232cf..0a1f5ef 100644 --- a/debuggerd/debuggerd.cpp +++ b/debuggerd/debuggerd.cpp @@ -92,20 +92,43 @@ static void disable_debug_led() { } static void wait_for_user_action(pid_t pid) { - // First log a helpful message + // Find out the name of the process that crashed. + char path[64]; + snprintf(path, sizeof(path), "/proc/%d/exe", pid); + + char exe[PATH_MAX]; + int count; + if ((count = readlink(path, exe, sizeof(exe) - 1)) == -1) { + LOG("readlink('%s') failed: %s", path, strerror(errno)); + strlcpy(exe, "unknown", sizeof(exe)); + } else { + exe[count] = '\0'; + } + + // Turn "/system/bin/app_process" into "app_process". + // gdbserver doesn't cope with full paths (though we should fix that + // and remove this). + char* name = strrchr(exe, '/'); + if (name == NULL) { + name = exe; // No '/' found. + } else { + ++name; // Skip the '/'. + } + + // Explain how to attach the debugger. LOG( "********************************************************\n" - "* Process %d has been suspended while crashing. To\n" - "* attach gdbserver for a gdb connection on port 5039\n" + "* Process %d has been suspended while crashing.\n" + "* To attach gdbserver for a gdb connection on port 5039\n" "* and start gdbclient:\n" "*\n" - "* gdbclient app_process :5039 %d\n" + "* gdbclient %s :5039 %d\n" "*\n" - "* Wait for gdb to start, then press HOME or VOLUME DOWN key\n" + "* Wait for gdb to start, then press the VOLUME DOWN key\n" "* to let the process continue crashing.\n" "********************************************************\n", - pid, pid); + pid, name, pid); - // wait for HOME or VOLUME DOWN key + // Wait for VOLUME DOWN. if (init_getevent() == 0) { int ms = 1200 / 10; int dit = 1; @@ -118,17 +141,14 @@ static void wait_for_user_action(pid_t pid) { }; size_t s = 0; input_event e; - bool done = false; init_debug_led(); enable_debug_led(); - do { + while (true) { int timeout = abs(codes[s]) * ms; int res = get_event(&e, timeout); if (res == 0) { - if (e.type == EV_KEY - && (e.code == KEY_HOME || e.code == KEY_VOLUMEDOWN) - && e.value == 0) { - done = true; + if (e.type == EV_KEY && e.code == KEY_VOLUMEDOWN && e.value == 0) { + break; } } else if (res == 1) { if (++s >= sizeof(codes)/sizeof(*codes)) @@ -139,7 +159,7 @@ static void wait_for_user_action(pid_t pid) { disable_debug_led(); } } - } while (!done); + } uninit_getevent(); } |