summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-05-16 19:16:22 -0700
committerElliott Hughes <enh@google.com>2014-05-16 19:51:41 -0700
commitd9bf2b21370faeda4ef57932a42a14c05557e71a (patch)
tree65aae3ce73bec2761cc804c2afaf3c1692424ce5
parent770cd7c7e7c18a657f233d86aeecb1d9f3091449 (diff)
downloadsystem_core-d9bf2b21370faeda4ef57932a42a14c05557e71a.zip
system_core-d9bf2b21370faeda4ef57932a42a14c05557e71a.tar.gz
system_core-d9bf2b21370faeda4ef57932a42a14c05557e71a.tar.bz2
Output correct gdbserver instructions from debuggerd.
Bug: 15021938 Change-Id: I2df433d939f5f83ed2a2a30af357b83e4d8e5331
-rw-r--r--debuggerd/debuggerd.cpp48
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();
}