summaryrefslogtreecommitdiff
path: root/libbacktrace
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2017-09-01 11:17:16 -0700
committerChristopher Ferris <cferris@google.com>2017-09-05 14:30:22 -0700
commitf5a78904010773faedc8ea9d8684672d03e67fa4 (patch)
tree977e12ffbe7abe506d9e68cc716eb8803cfe6ece /libbacktrace
parent5e035738e693f22dcff5cf0b08ed2c63472523d9 (diff)
downloadunwinding-f5a78904010773faedc8ea9d8684672d03e67fa4.tar.gz
Add a method to share the process memory object.
New function to create the process memory object. This allows for a future where different remote process memory objects could be created depending on the way remote memory can be created. Even different local memory objects that access memory without doing any checks. It also allows MemoryRange objects to share one single process memory object and could help if the process memory object caches data. Small changes to MapInfo::CreateMemory to when some errors are detected. - Always check if the map is a device map, instead of only if the name is not empty. - Check if a memory map is readable before creating the memory from process memory. Bug: 23762183 Test: Ran unit tests, unwound on device using the new code. Change-Id: I12a93c2dc19639689a528ec41c67bfac74d431b3
Diffstat (limited to 'libbacktrace')
-rw-r--r--libbacktrace/UnwindStack.cpp30
-rw-r--r--libbacktrace/UnwindStack.h6
-rw-r--r--libbacktrace/UnwindStackMap.cpp5
-rw-r--r--libbacktrace/UnwindStackMap.h5
4 files changed, 24 insertions, 22 deletions
diff --git a/libbacktrace/UnwindStack.cpp b/libbacktrace/UnwindStack.cpp
index 3b2f38e..61812ab 100644
--- a/libbacktrace/UnwindStack.cpp
+++ b/libbacktrace/UnwindStack.cpp
@@ -41,8 +41,7 @@
#include "UnwindStack.h"
#include "UnwindStackMap.h"
-static std::string GetFunctionName(pid_t pid, BacktraceMap* back_map, uintptr_t pc,
- uintptr_t* offset) {
+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();
@@ -52,7 +51,8 @@ static std::string GetFunctionName(pid_t pid, BacktraceMap* back_map, uintptr_t
return "";
}
- unwindstack::Elf* elf = map_info->GetElf(pid, true);
+ 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;
@@ -68,10 +68,10 @@ static bool IsUnwindLibrary(const std::string& map_name) {
return library == "libunwindstack.so" || library == "libbacktrace.so";
}
-static bool Unwind(pid_t pid, unwindstack::Memory* memory, unwindstack::Regs* regs,
- BacktraceMap* back_map, std::vector<backtrace_frame_data_t>* frames,
- size_t num_ignore_frames) {
- unwindstack::Maps* maps = reinterpret_cast<UnwindStackMap*>(back_map)->stack_maps();
+static bool Unwind(unwindstack::Regs* regs, BacktraceMap* back_map,
+ std::vector<backtrace_frame_data_t>* frames, size_t num_ignore_frames) {
+ UnwindStackMap* stack_map = reinterpret_cast<UnwindStackMap*>(back_map);
+ unwindstack::Maps* maps = stack_map->stack_maps();
bool adjust_rel_pc = false;
size_t num_frames = 0;
frames->clear();
@@ -84,7 +84,7 @@ static bool Unwind(pid_t pid, unwindstack::Memory* memory, unwindstack::Regs* re
break;
}
- unwindstack::Elf* elf = map_info->GetElf(pid, true);
+ unwindstack::Elf* elf = map_info->GetElf(stack_map->process_memory(), true);
uint64_t rel_pc = elf->GetRelPc(regs->pc(), map_info);
bool skip_frame = num_frames == 0 && IsUnwindLibrary(map_info->name);
@@ -137,7 +137,7 @@ static bool Unwind(pid_t pid, unwindstack::Memory* memory, unwindstack::Regs* re
break;
}
- if (!elf->Step(rel_pc + map_info->elf_offset, regs, memory)) {
+ if (!elf->Step(rel_pc + map_info->elf_offset, regs, stack_map->process_memory().get())) {
break;
}
}
@@ -146,10 +146,10 @@ static bool Unwind(pid_t pid, unwindstack::Memory* memory, unwindstack::Regs* re
}
UnwindStackCurrent::UnwindStackCurrent(pid_t pid, pid_t tid, BacktraceMap* map)
- : BacktraceCurrent(pid, tid, map), memory_(new unwindstack::MemoryLocal) {}
+ : BacktraceCurrent(pid, tid, map) {}
std::string UnwindStackCurrent::GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset) {
- return ::GetFunctionName(Pid(), GetMap(), pc, offset);
+ return ::GetFunctionName(GetMap(), pc, offset);
}
bool UnwindStackCurrent::UnwindFromContext(size_t num_ignore_frames, ucontext_t* ucontext) {
@@ -165,14 +165,14 @@ bool UnwindStackCurrent::UnwindFromContext(size_t num_ignore_frames, ucontext_t*
}
error_ = BACKTRACE_UNWIND_NO_ERROR;
- return ::Unwind(getpid(), memory_.get(), regs.get(), GetMap(), &frames_, num_ignore_frames);
+ return ::Unwind(regs.get(), GetMap(), &frames_, num_ignore_frames);
}
UnwindStackPtrace::UnwindStackPtrace(pid_t pid, pid_t tid, BacktraceMap* map)
- : BacktracePtrace(pid, tid, map), memory_(new unwindstack::MemoryRemote(pid)) {}
+ : BacktracePtrace(pid, tid, map) {}
std::string UnwindStackPtrace::GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset) {
- return ::GetFunctionName(Pid(), GetMap(), pc, offset);
+ return ::GetFunctionName(GetMap(), pc, offset);
}
bool UnwindStackPtrace::Unwind(size_t num_ignore_frames, ucontext_t* context) {
@@ -185,7 +185,7 @@ bool UnwindStackPtrace::Unwind(size_t num_ignore_frames, ucontext_t* context) {
}
error_ = BACKTRACE_UNWIND_NO_ERROR;
- return ::Unwind(Pid(), memory_.get(), regs.get(), GetMap(), &frames_, num_ignore_frames);
+ return ::Unwind(regs.get(), GetMap(), &frames_, num_ignore_frames);
}
Backtrace* Backtrace::CreateNew(pid_t pid, pid_t tid, BacktraceMap* map) {
diff --git a/libbacktrace/UnwindStack.h b/libbacktrace/UnwindStack.h
index 32d1f51..be9ef63 100644
--- a/libbacktrace/UnwindStack.h
+++ b/libbacktrace/UnwindStack.h
@@ -35,9 +35,6 @@ class UnwindStackCurrent : public BacktraceCurrent {
std::string GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset) override;
bool UnwindFromContext(size_t num_ignore_frames, ucontext_t* ucontext) override;
-
- private:
- std::unique_ptr<unwindstack::Memory> memory_;
};
class UnwindStackPtrace : public BacktracePtrace {
@@ -48,9 +45,6 @@ class UnwindStackPtrace : public BacktracePtrace {
bool Unwind(size_t num_ignore_frames, ucontext_t* context) override;
std::string GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset);
-
- private:
- std::unique_ptr<unwindstack::Memory> memory_;
};
#endif // _LIBBACKTRACE_UNWIND_STACK_H
diff --git a/libbacktrace/UnwindStackMap.cpp b/libbacktrace/UnwindStackMap.cpp
index ba9fd87..d4a2444 100644
--- a/libbacktrace/UnwindStackMap.cpp
+++ b/libbacktrace/UnwindStackMap.cpp
@@ -36,6 +36,9 @@ bool UnwindStackMap::Build() {
stack_maps_.reset(new unwindstack::RemoteMaps(pid_));
}
+ // Create the process memory object.
+ process_memory_ = unwindstack::Memory::CreateProcessMemory(pid_);
+
if (!stack_maps_->Parse()) {
return false;
}
@@ -68,7 +71,7 @@ void UnwindStackMap::FillIn(uintptr_t addr, backtrace_map_t* map) {
if (map_info == nullptr) {
return;
}
- unwindstack::Elf* elf = map_info->GetElf(pid_, true);
+ unwindstack::Elf* elf = map_info->GetElf(process_memory_, true);
map->load_bias = elf->GetLoadBias();
}
diff --git a/libbacktrace/UnwindStackMap.h b/libbacktrace/UnwindStackMap.h
index 7885b74..b93b340 100644
--- a/libbacktrace/UnwindStackMap.h
+++ b/libbacktrace/UnwindStackMap.h
@@ -20,6 +20,8 @@
#include <stdint.h>
#include <sys/types.h>
+#include <memory>
+
#include <backtrace/BacktraceMap.h>
#include <unwindstack/Maps.h>
@@ -34,8 +36,11 @@ class UnwindStackMap : public BacktraceMap {
unwindstack::Maps* stack_maps() { return stack_maps_.get(); }
+ const std::shared_ptr<unwindstack::Memory>& process_memory() { return process_memory_; }
+
protected:
std::unique_ptr<unwindstack::Maps> stack_maps_;
+ std::shared_ptr<unwindstack::Memory> process_memory_;
};
#endif // _LIBBACKTRACE_UNWINDSTACK_MAP_H