debuggerd: Show function names in tombstone backtraces
This change enables debuggerd to provide backtraces with function
names in tombstone files and log messages. It does this by reading
the image file that the address is found in, and parsing the dynamic
symbol table to try to extract the symbol corresponding to the given
address.
This works best when "-Wl,-export-dynamic" is added to the LDFLAGS
of each library and executable, because this will cause all symbols
to be added to the dynamic symbol table. If this flag is not present,
it will still work, but it will only be able to identify functions
which are part of the external API of the library/executable.
Change-Id: I618baaff9ed9143b7d1a1f302224e9f21d2b0626
diff --git a/debuggerd/debuggerd.c b/debuggerd/debuggerd.c
index 996e6c2..02bab2c 100644
--- a/debuggerd/debuggerd.c
+++ b/debuggerd/debuggerd.c
@@ -55,7 +55,7 @@
/* Log information onto the tombstone */
void _LOG(int tfd, bool in_tombstone_only, const char *fmt, ...)
{
- char buf[128];
+ char buf[512];
va_list ap;
va_start(ap, fmt);
@@ -98,10 +98,11 @@
mi->start = strtoul(line, 0, 16);
mi->end = strtoul(line + 9, 0, 16);
- /* To be filled in parse_exidx_info if the mapped section starts with
+ /* To be filled in parse_elf_info if the mapped section starts with
* elf_header
*/
mi->exidx_start = mi->exidx_end = 0;
+ mi->symbols = 0;
mi->next = 0;
strcpy(mi->name, line + 49);
@@ -335,7 +336,7 @@
if(sig) dump_fault_addr(tfd, tid, sig);
}
-static void parse_exidx_info(mapinfo *milist, pid_t pid)
+static void parse_elf_info(mapinfo *milist, pid_t pid)
{
mapinfo *mi;
for (mi = milist; mi != NULL; mi = mi->next) {
@@ -365,6 +366,9 @@
break;
}
}
+
+ /* Try to load symbols from this file */
+ mi->symbols = symbol_table_create(mi->name);
}
}
}
@@ -402,7 +406,7 @@
fclose(fp);
}
- parse_exidx_info(milist, tid);
+ parse_elf_info(milist, tid);
/* If stack unwinder fails, use the default solution to dump the stack
* content.
@@ -422,6 +426,7 @@
while(milist) {
mapinfo *next = milist->next;
+ symbol_table_free(milist->symbols);
free(milist);
milist = next;
}