summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2012-05-18 16:53:22 -0700
committerElliott Hughes <enh@google.com>2012-05-18 16:53:22 -0700
commit04607b8aa91051bb43cd652dca1cef1579ed5dad (patch)
tree1da7a49e665de47fbe9430e6c77cd780e9364f82
parent71363a8075e7916c2166cbdd8a0bf5a180ed4d54 (diff)
downloadcore-04607b8aa91051bb43cd652dca1cef1579ed5dad.tar.gz
core-04607b8aa91051bb43cd652dca1cef1579ed5dad.tar.bz2
core-04607b8aa91051bb43cd652dca1cef1579ed5dad.zip
Test libcorkscrew's ELF symbol table decoder too.
Change-Id: I3180ffe07b44245c698dd03a789a3b337f32872a
-rw-r--r--libcorkscrew/test.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/libcorkscrew/test.c b/libcorkscrew/test.c
index 2d1ba7cc9..1d6c3cb9c 100644
--- a/libcorkscrew/test.c
+++ b/libcorkscrew/test.c
@@ -1,4 +1,5 @@
#include <corkscrew/backtrace.h>
+#include <corkscrew/symbol_table.h>
#include <stdio.h>
#include <stdlib.h>
@@ -15,7 +16,28 @@ void do_backtrace() {
char line[MAX_BACKTRACE_LINE_LENGTH];
format_backtrace_line(i, &frames[i], &backtrace_symbols[i],
line, MAX_BACKTRACE_LINE_LENGTH);
- fprintf(stderr, " %s\n", line);
+ if (backtrace_symbols[i].symbol_name != NULL) {
+ // get_backtrace_symbols found the symbol's name with dladdr(3).
+ fprintf(stderr, " %s\n", line);
+ } else {
+ // We don't have a symbol. Maybe this is a static symbol, and
+ // we can look it up?
+ symbol_table_t* symbols = NULL;
+ if (backtrace_symbols[i].map_name != NULL) {
+ symbols = load_symbol_table(backtrace_symbols[i].map_name);
+ }
+ const symbol_t* symbol = NULL;
+ if (symbols != NULL) {
+ symbol = find_symbol(symbols, frames[i].absolute_pc);
+ }
+ if (symbol != NULL) {
+ uintptr_t offset = frames[i].absolute_pc - symbol->start;
+ fprintf(stderr, " %s (%s%+d)\n", line, symbol->name, offset);
+ } else {
+ fprintf(stderr, " %s (\?\?\?)\n", line);
+ }
+ free(symbols);
+ }
}
free_backtrace_symbols(backtrace_symbols, frame_count);