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/unwind-arm.c b/debuggerd/unwind-arm.c
index 9642d2e..b081161 100644
--- a/debuggerd/unwind-arm.c
+++ b/debuggerd/unwind-arm.c
@@ -37,6 +37,8 @@
#include <unwind.h>
#include "utility.h"
+#include "symbol_table.h"
+
typedef struct _ZSt9type_info type_info; /* This names C++ type_info type */
void __attribute__((weak)) __cxa_call_unexpected(_Unwind_Control_Block *ucbp);
@@ -393,6 +395,7 @@
phase2_vrs *vrs = (phase2_vrs*) context;
const mapinfo *mi;
bool only_in_tombstone = !at_fault;
+ const struct symbol* sym = 0;
if (stack_level < STACK_CONTENT_DEPTH) {
sp_list[stack_level] = vrs->core.r[R_SP];
@@ -451,9 +454,20 @@
rel_pc = pc;
mi = pc_to_mapinfo(map, pc, &rel_pc);
- _LOG(tfd, only_in_tombstone,
- " #%02d pc %08x %s\n", stack_level, rel_pc,
- mi ? mi->name : "");
+ /* See if we can determine what symbol this stack frame resides in */
+ if (mi != 0 && mi->symbols != 0) {
+ sym = symbol_table_lookup(mi->symbols, rel_pc);
+ }
+
+ if (sym) {
+ _LOG(tfd, only_in_tombstone,
+ " #%02d pc %08x %s (%s)\n", stack_level, rel_pc,
+ mi ? mi->name : "", sym->name);
+ } else {
+ _LOG(tfd, only_in_tombstone,
+ " #%02d pc %08x %s\n", stack_level, rel_pc,
+ mi ? mi->name : "");
+ }
return _URC_NO_REASON;
}