diff options
author | Christopher Ferris <cferris@google.com> | 2013-11-05 10:31:45 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-11-05 10:31:45 -0800 |
commit | 4ddea7f44c6362e7c34939302729e4508aa665c5 (patch) | |
tree | 72d49aa886b6d6cfb3f313e30694d1f484c96fba | |
parent | eb0eb4f79fca083009aa7a6b6e28ddcdbcbd1214 (diff) | |
parent | d5a7c371d22ea327be03bfa10944e5f0f2d51a24 (diff) | |
download | core-4ddea7f44c6362e7c34939302729e4508aa665c5.tar.gz core-4ddea7f44c6362e7c34939302729e4508aa665c5.tar.bz2 core-4ddea7f44c6362e7c34939302729e4508aa665c5.zip |
am d5a7c371: am 408b3acf: Merge "Add corkscrew support for finding static symbols."
* commit 'd5a7c371d22ea327be03bfa10944e5f0f2d51a24':
Add corkscrew support for finding static symbols.
-rw-r--r-- | libbacktrace/Corkscrew.cpp | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/libbacktrace/Corkscrew.cpp b/libbacktrace/Corkscrew.cpp index 9daa75221..2be5930f6 100644 --- a/libbacktrace/Corkscrew.cpp +++ b/libbacktrace/Corkscrew.cpp @@ -86,15 +86,33 @@ bool CorkscrewCurrent::Unwind(size_t num_ignore_frames) { std::string CorkscrewCurrent::GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset) { *offset = 0; - // Get information about the current thread. Dl_info info; const backtrace_map_info_t* map_info = backtrace_obj_->FindMapInfo(pc); - const char* symbol_name = NULL; - if (map_info && dladdr((const void*)pc, &info) && info.dli_sname) { - *offset = pc - map_info->start - (uintptr_t)info.dli_saddr + (uintptr_t)info.dli_fbase; - symbol_name = info.dli_sname; - - return symbol_name; + if (map_info) { + if (dladdr((const void*)pc, &info)) { + if (info.dli_sname) { + *offset = pc - map_info->start - (uintptr_t)info.dli_saddr + (uintptr_t)info.dli_fbase; + return info.dli_sname; + } + } else { + // dladdr(3) didn't find a symbol; maybe it's static? Look in the ELF file... + symbol_table_t* symbol_table = load_symbol_table(map_info->name); + if (symbol_table) { + // First check if we can find the symbol using a relative pc. + std::string name; + const symbol_t* elf_symbol = find_symbol(symbol_table, pc - map_info->start); + if (elf_symbol) { + name = elf_symbol->name; + *offset = pc - map_info->start - elf_symbol->start; + } else if ((elf_symbol = find_symbol(symbol_table, pc)) != NULL) { + // Found the symbol using the absolute pc. + name = elf_symbol->name; + *offset = pc - elf_symbol->start; + } + free_symbol_table(symbol_table); + return name; + } + } } return ""; } |