Loading libbacktrace/UnwindStack.cpp +15 −15 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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; Loading @@ -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(); Loading @@ -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); Loading Loading @@ -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; } } Loading @@ -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) { Loading @@ -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) { Loading @@ -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) { Loading libbacktrace/UnwindStack.h +0 −6 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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 libbacktrace/UnwindStackMap.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -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; } Loading Loading @@ -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(); } Loading libbacktrace/UnwindStackMap.h +5 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ #include <stdint.h> #include <sys/types.h> #include <memory> #include <backtrace/BacktraceMap.h> #include <unwindstack/Maps.h> Loading @@ -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 libunwindstack/Android.bp +7 −1 Original line number Diff line number Diff line Loading @@ -61,6 +61,13 @@ cc_library { "Symbols.cpp", ], target: { // Always disable optimizations for host to make it easier to debug. linux: { cflags: ["-O0", "-g"], }, }, arch: { x86: { srcs: ["AsmGetRegsX86.S"], Loading Loading @@ -101,7 +108,6 @@ cc_test { "tests/ElfTest.cpp", "tests/ElfTestUtils.cpp", "tests/LogFake.cpp", "tests/MapInfoCreateMemoryTest.cpp", "tests/MapInfoGetElfTest.cpp", "tests/MapsTest.cpp", "tests/MemoryBufferTest.cpp", Loading Loading
libbacktrace/UnwindStack.cpp +15 −15 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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; Loading @@ -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(); Loading @@ -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); Loading Loading @@ -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; } } Loading @@ -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) { Loading @@ -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) { Loading @@ -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) { Loading
libbacktrace/UnwindStack.h +0 −6 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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
libbacktrace/UnwindStackMap.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -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; } Loading Loading @@ -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(); } Loading
libbacktrace/UnwindStackMap.h +5 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ #include <stdint.h> #include <sys/types.h> #include <memory> #include <backtrace/BacktraceMap.h> #include <unwindstack/Maps.h> Loading @@ -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
libunwindstack/Android.bp +7 −1 Original line number Diff line number Diff line Loading @@ -61,6 +61,13 @@ cc_library { "Symbols.cpp", ], target: { // Always disable optimizations for host to make it easier to debug. linux: { cflags: ["-O0", "-g"], }, }, arch: { x86: { srcs: ["AsmGetRegsX86.S"], Loading Loading @@ -101,7 +108,6 @@ cc_test { "tests/ElfTest.cpp", "tests/ElfTestUtils.cpp", "tests/LogFake.cpp", "tests/MapInfoCreateMemoryTest.cpp", "tests/MapInfoGetElfTest.cpp", "tests/MapsTest.cpp", "tests/MemoryBufferTest.cpp", Loading