summaryrefslogtreecommitdiffstats
path: root/libbacktrace
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2017-09-06 22:16:09 -0700
committerJosh Gao <jmgao@google.com>2017-10-20 13:52:56 -0700
commit358de18b2747828720e7f9dc538e724a66f02cba (patch)
tree60788722a9ace559fd55cc9e7a46b3fc59b10bfd /libbacktrace
parent45c4a56f1d484ce60390bf48ab55076d4d601c9d (diff)
downloadcore-358de18b2747828720e7f9dc538e724a66f02cba.tar.gz
core-358de18b2747828720e7f9dc538e724a66f02cba.tar.bz2
core-358de18b2747828720e7f9dc538e724a66f02cba.zip
libunwindstack: expose UnwindStackMap::GetFunctionName.
Test: mma Change-Id: I8736ff5c2ed7c5e64eb68df5f4eccfed614612c7
Diffstat (limited to 'libbacktrace')
-rw-r--r--libbacktrace/UnwindStack.cpp26
-rw-r--r--libbacktrace/UnwindStackMap.cpp21
-rw-r--r--libbacktrace/UnwindStackMap.h2
-rw-r--r--libbacktrace/include/backtrace/BacktraceMap.h3
4 files changed, 28 insertions, 24 deletions
diff --git a/libbacktrace/UnwindStack.cpp b/libbacktrace/UnwindStack.cpp
index 0f6730c8b..dcd3d09cf 100644
--- a/libbacktrace/UnwindStack.cpp
+++ b/libbacktrace/UnwindStack.cpp
@@ -44,28 +44,6 @@
#include "UnwindStack.h"
#include "UnwindStackMap.h"
-static std::string GetFunctionName(BacktraceMap* back_map, uintptr_t pc, uintptr_t* offset) {
- *offset = 0;
- unwindstack::Maps* maps = reinterpret_cast<UnwindStackMap*>(back_map)->stack_maps();
-
- // Get the map for this
- unwindstack::MapInfo* map_info = maps->Find(pc);
- if (map_info == nullptr || map_info->flags & PROT_DEVICE_MAP) {
- return "";
- }
-
- UnwindStackMap* stack_map = reinterpret_cast<UnwindStackMap*>(back_map);
- unwindstack::Elf* elf = map_info->GetElf(stack_map->process_memory(), true);
-
- std::string name;
- uint64_t func_offset;
- if (!elf->GetFunctionName(elf->GetRelPc(pc, map_info), &name, &func_offset)) {
- return "";
- }
- *offset = func_offset;
- return name;
-}
-
bool Backtrace::Unwind(unwindstack::Regs* regs, BacktraceMap* back_map,
std::vector<backtrace_frame_data_t>* frames, size_t num_ignore_frames) {
static std::set<std::string> skip_names{"libunwindstack.so", "libbacktrace.so"};
@@ -111,7 +89,7 @@ UnwindStackCurrent::UnwindStackCurrent(pid_t pid, pid_t tid, BacktraceMap* map)
: BacktraceCurrent(pid, tid, map) {}
std::string UnwindStackCurrent::GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset) {
- return ::GetFunctionName(GetMap(), pc, offset);
+ return GetMap()->GetFunctionName(pc, offset);
}
bool UnwindStackCurrent::UnwindFromContext(size_t num_ignore_frames, ucontext_t* ucontext) {
@@ -134,7 +112,7 @@ UnwindStackPtrace::UnwindStackPtrace(pid_t pid, pid_t tid, BacktraceMap* map)
: BacktracePtrace(pid, tid, map) {}
std::string UnwindStackPtrace::GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset) {
- return ::GetFunctionName(GetMap(), pc, offset);
+ return GetMap()->GetFunctionName(pc, offset);
}
bool UnwindStackPtrace::Unwind(size_t num_ignore_frames, ucontext_t* context) {
diff --git a/libbacktrace/UnwindStackMap.cpp b/libbacktrace/UnwindStackMap.cpp
index d4a2444dc..a9121a800 100644
--- a/libbacktrace/UnwindStackMap.cpp
+++ b/libbacktrace/UnwindStackMap.cpp
@@ -75,6 +75,27 @@ void UnwindStackMap::FillIn(uintptr_t addr, backtrace_map_t* map) {
map->load_bias = elf->GetLoadBias();
}
+std::string UnwindStackMap::GetFunctionName(uintptr_t pc, uintptr_t* offset) {
+ *offset = 0;
+ unwindstack::Maps* maps = stack_maps();
+
+ // Get the map for this
+ unwindstack::MapInfo* map_info = maps->Find(pc);
+ if (map_info == nullptr || map_info->flags & PROT_DEVICE_MAP) {
+ return "";
+ }
+
+ unwindstack::Elf* elf = map_info->GetElf(process_memory(), true);
+
+ std::string name;
+ uint64_t func_offset;
+ if (!elf->GetFunctionName(elf->GetRelPc(pc, map_info), &name, &func_offset)) {
+ return "";
+ }
+ *offset = func_offset;
+ return name;
+}
+
//-------------------------------------------------------------------------
// BacktraceMap create function.
//-------------------------------------------------------------------------
diff --git a/libbacktrace/UnwindStackMap.h b/libbacktrace/UnwindStackMap.h
index b93b3403c..2a8af839d 100644
--- a/libbacktrace/UnwindStackMap.h
+++ b/libbacktrace/UnwindStackMap.h
@@ -34,6 +34,8 @@ class UnwindStackMap : public BacktraceMap {
void FillIn(uintptr_t addr, backtrace_map_t* map) override;
+ virtual std::string GetFunctionName(uintptr_t pc, uintptr_t* offset) override;
+
unwindstack::Maps* stack_maps() { return stack_maps_.get(); }
const std::shared_ptr<unwindstack::Memory>& process_memory() { return process_memory_; }
diff --git a/libbacktrace/include/backtrace/BacktraceMap.h b/libbacktrace/include/backtrace/BacktraceMap.h
index 6cf8b3fca..104479d71 100644
--- a/libbacktrace/include/backtrace/BacktraceMap.h
+++ b/libbacktrace/include/backtrace/BacktraceMap.h
@@ -62,6 +62,9 @@ public:
// Fill in the map data structure for the given address.
virtual void FillIn(uintptr_t addr, backtrace_map_t* map);
+ // Only supported with the new unwinder.
+ virtual std::string GetFunctionName(uintptr_t /*pc*/, uintptr_t* /*offset*/) { return ""; }
+
// The flags returned are the same flags as used by the mmap call.
// The values are PROT_*.
int GetFlags(uintptr_t pc) {