Loading debuggerd/tombstone.cpp +3 −9 Original line number Original line Diff line number Diff line Loading @@ -625,12 +625,9 @@ static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, uintptr_t a dump_fault_addr(log, tid, signal); dump_fault_addr(log, tid, signal); } } BacktraceMap* map = NULL; UniquePtr<BacktraceMap> map(BacktraceMap::Create(pid)); UniquePtr<Backtrace> backtrace(Backtrace::Create(pid, tid)); UniquePtr<Backtrace> backtrace(Backtrace::Create(pid, tid, map.get())); if (backtrace->Unwind(0)) { if (backtrace->Unwind(0)) { // Grab the map that was created and share it with the siblings. map = backtrace->TakeMapOwnership(); dump_abort_message(backtrace.get(), log, abort_msg_address); dump_abort_message(backtrace.get(), log, abort_msg_address); dump_thread(backtrace.get(), log, SCOPE_AT_FAULT, total_sleep_time_usec); dump_thread(backtrace.get(), log, SCOPE_AT_FAULT, total_sleep_time_usec); } } Loading @@ -641,12 +638,9 @@ static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, uintptr_t a bool detach_failed = false; bool detach_failed = false; if (dump_sibling_threads) { if (dump_sibling_threads) { detach_failed = dump_sibling_thread_report(log, pid, tid, total_sleep_time_usec, map); detach_failed = dump_sibling_thread_report(log, pid, tid, total_sleep_time_usec, map.get()); } } // Destroy the BacktraceMap object. delete map; if (want_logs) { if (want_logs) { dump_logs(log, pid, 0); dump_logs(log, pid, 0); } } Loading include/backtrace/Backtrace.h +0 −4 Original line number Original line Diff line number Diff line Loading @@ -64,10 +64,6 @@ public: // Find the map associated with the given pc. // Find the map associated with the given pc. virtual const backtrace_map_t* FindMap(uintptr_t pc); virtual const backtrace_map_t* FindMap(uintptr_t pc); // Take ownership of the BacktraceMap object associated with the backtrace. // If this is called, the caller must handle deleting the object themselves. virtual BacktraceMap* TakeMapOwnership(); // Read the data at a specific address. // Read the data at a specific address. virtual bool ReadWord(uintptr_t ptr, uint32_t* out_value) = 0; virtual bool ReadWord(uintptr_t ptr, uint32_t* out_value) = 0; Loading include/backtrace/BacktraceMap.h +8 −5 Original line number Original line Diff line number Diff line Loading @@ -28,8 +28,8 @@ #include <sys/mman.h> #include <sys/mman.h> #endif #endif #include <deque> #include <string> #include <string> #include <vector> struct backtrace_map_t { struct backtrace_map_t { uintptr_t start; uintptr_t start; Loading @@ -40,7 +40,8 @@ struct backtrace_map_t { class BacktraceMap { class BacktraceMap { public: public: BacktraceMap(pid_t pid); static BacktraceMap* Create(pid_t pid); virtual ~BacktraceMap(); virtual ~BacktraceMap(); // Get the map data structure for the given address. // Get the map data structure for the given address. Loading @@ -60,20 +61,22 @@ public: bool IsWritable(uintptr_t pc) { return GetFlags(pc) & PROT_WRITE; } bool IsWritable(uintptr_t pc) { return GetFlags(pc) & PROT_WRITE; } bool IsExecutable(uintptr_t pc) { return GetFlags(pc) & PROT_EXEC; } bool IsExecutable(uintptr_t pc) { return GetFlags(pc) & PROT_EXEC; } typedef std::vector<backtrace_map_t>::iterator iterator; typedef std::deque<backtrace_map_t>::iterator iterator; iterator begin() { return maps_.begin(); } iterator begin() { return maps_.begin(); } iterator end() { return maps_.end(); } iterator end() { return maps_.end(); } typedef std::vector<backtrace_map_t>::const_iterator const_iterator; typedef std::deque<backtrace_map_t>::const_iterator const_iterator; const_iterator begin() const { return maps_.begin(); } const_iterator begin() const { return maps_.begin(); } const_iterator end() const { return maps_.end(); } const_iterator end() const { return maps_.end(); } virtual bool Build(); virtual bool Build(); protected: protected: BacktraceMap(pid_t pid); virtual bool ParseLine(const char* line, backtrace_map_t* map); virtual bool ParseLine(const char* line, backtrace_map_t* map); std::vector<backtrace_map_t> maps_; std::deque<backtrace_map_t> maps_; pid_t pid_; pid_t pid_; }; }; Loading libbacktrace/Android.mk +3 −2 Original line number Original line Diff line number Diff line LOCAL_PATH:= $(call my-dir) LOCAL_PATH:= $(call my-dir) common_src := \ common_src := \ Backtrace.cpp \ BacktraceImpl.cpp \ BacktraceMap.cpp \ BacktraceMap.cpp \ BacktraceThread.cpp \ BacktraceThread.cpp \ thread_utils.c \ thread_utils.c \ Loading @@ -23,7 +23,7 @@ common_shared_libs := \ liblog \ liblog \ # To enable using libunwind on each arch, add it to this list. # To enable using libunwind on each arch, add it to this list. libunwind_architectures := arm64 libunwind_architectures := arm arm64 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),$(libunwind_architectures))) ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),$(libunwind_architectures))) Loading @@ -35,6 +35,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ LOCAL_SRC_FILES:= \ $(common_src) \ $(common_src) \ UnwindCurrent.cpp \ UnwindCurrent.cpp \ UnwindMap.cpp \ UnwindPtrace.cpp \ UnwindPtrace.cpp \ LOCAL_CFLAGS := \ LOCAL_CFLAGS := \ Loading libbacktrace/Backtrace.cpp→libbacktrace/BacktraceImpl.cpp +7 −27 Original line number Original line Diff line number Diff line Loading @@ -29,7 +29,7 @@ #include <backtrace/Backtrace.h> #include <backtrace/Backtrace.h> #include <backtrace/BacktraceMap.h> #include <backtrace/BacktraceMap.h> #include "Backtrace.h" #include "BacktraceImpl.h" #include "thread_utils.h" #include "thread_utils.h" //------------------------------------------------------------------------- //------------------------------------------------------------------------- Loading @@ -40,21 +40,21 @@ Backtrace::Backtrace(BacktraceImpl* impl, pid_t pid, BacktraceMap* map) impl_->SetParent(this); impl_->SetParent(this); if (map_ == NULL) { if (map_ == NULL) { // The map will be created when needed. map_ = BacktraceMap::Create(pid); map_shared_ = false; map_shared_ = false; } } } } Backtrace::~Backtrace() { Backtrace::~Backtrace() { if (map_ && !map_shared_) { delete map_; map_ = NULL; } if (impl_) { if (impl_) { delete impl_; delete impl_; impl_ = NULL; impl_ = NULL; } } if (map_ && !map_shared_) { delete map_; map_ = NULL; } } } bool Backtrace::Unwind(size_t num_ignore_frames) { bool Backtrace::Unwind(size_t num_ignore_frames) { Loading Loading @@ -129,30 +129,10 @@ std::string Backtrace::FormatFrameData(const backtrace_frame_data_t* frame) { return buf; return buf; } } bool Backtrace::BuildMap() { map_ = impl_->CreateBacktraceMap(pid_); if (!map_->Build()) { BACK_LOGW("Failed to build map for process %d", pid_); return false; } return true; } const backtrace_map_t* Backtrace::FindMap(uintptr_t pc) { const backtrace_map_t* Backtrace::FindMap(uintptr_t pc) { if (map_ == NULL) { // Lazy eval, time to build the map. if (!BuildMap()) { return NULL; } } return map_->Find(pc); return map_->Find(pc); } } BacktraceMap* Backtrace::TakeMapOwnership() { map_shared_ = true; return map_; } //------------------------------------------------------------------------- //------------------------------------------------------------------------- // BacktraceCurrent functions. // BacktraceCurrent functions. //------------------------------------------------------------------------- //------------------------------------------------------------------------- Loading Loading
debuggerd/tombstone.cpp +3 −9 Original line number Original line Diff line number Diff line Loading @@ -625,12 +625,9 @@ static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, uintptr_t a dump_fault_addr(log, tid, signal); dump_fault_addr(log, tid, signal); } } BacktraceMap* map = NULL; UniquePtr<BacktraceMap> map(BacktraceMap::Create(pid)); UniquePtr<Backtrace> backtrace(Backtrace::Create(pid, tid)); UniquePtr<Backtrace> backtrace(Backtrace::Create(pid, tid, map.get())); if (backtrace->Unwind(0)) { if (backtrace->Unwind(0)) { // Grab the map that was created and share it with the siblings. map = backtrace->TakeMapOwnership(); dump_abort_message(backtrace.get(), log, abort_msg_address); dump_abort_message(backtrace.get(), log, abort_msg_address); dump_thread(backtrace.get(), log, SCOPE_AT_FAULT, total_sleep_time_usec); dump_thread(backtrace.get(), log, SCOPE_AT_FAULT, total_sleep_time_usec); } } Loading @@ -641,12 +638,9 @@ static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, uintptr_t a bool detach_failed = false; bool detach_failed = false; if (dump_sibling_threads) { if (dump_sibling_threads) { detach_failed = dump_sibling_thread_report(log, pid, tid, total_sleep_time_usec, map); detach_failed = dump_sibling_thread_report(log, pid, tid, total_sleep_time_usec, map.get()); } } // Destroy the BacktraceMap object. delete map; if (want_logs) { if (want_logs) { dump_logs(log, pid, 0); dump_logs(log, pid, 0); } } Loading
include/backtrace/Backtrace.h +0 −4 Original line number Original line Diff line number Diff line Loading @@ -64,10 +64,6 @@ public: // Find the map associated with the given pc. // Find the map associated with the given pc. virtual const backtrace_map_t* FindMap(uintptr_t pc); virtual const backtrace_map_t* FindMap(uintptr_t pc); // Take ownership of the BacktraceMap object associated with the backtrace. // If this is called, the caller must handle deleting the object themselves. virtual BacktraceMap* TakeMapOwnership(); // Read the data at a specific address. // Read the data at a specific address. virtual bool ReadWord(uintptr_t ptr, uint32_t* out_value) = 0; virtual bool ReadWord(uintptr_t ptr, uint32_t* out_value) = 0; Loading
include/backtrace/BacktraceMap.h +8 −5 Original line number Original line Diff line number Diff line Loading @@ -28,8 +28,8 @@ #include <sys/mman.h> #include <sys/mman.h> #endif #endif #include <deque> #include <string> #include <string> #include <vector> struct backtrace_map_t { struct backtrace_map_t { uintptr_t start; uintptr_t start; Loading @@ -40,7 +40,8 @@ struct backtrace_map_t { class BacktraceMap { class BacktraceMap { public: public: BacktraceMap(pid_t pid); static BacktraceMap* Create(pid_t pid); virtual ~BacktraceMap(); virtual ~BacktraceMap(); // Get the map data structure for the given address. // Get the map data structure for the given address. Loading @@ -60,20 +61,22 @@ public: bool IsWritable(uintptr_t pc) { return GetFlags(pc) & PROT_WRITE; } bool IsWritable(uintptr_t pc) { return GetFlags(pc) & PROT_WRITE; } bool IsExecutable(uintptr_t pc) { return GetFlags(pc) & PROT_EXEC; } bool IsExecutable(uintptr_t pc) { return GetFlags(pc) & PROT_EXEC; } typedef std::vector<backtrace_map_t>::iterator iterator; typedef std::deque<backtrace_map_t>::iterator iterator; iterator begin() { return maps_.begin(); } iterator begin() { return maps_.begin(); } iterator end() { return maps_.end(); } iterator end() { return maps_.end(); } typedef std::vector<backtrace_map_t>::const_iterator const_iterator; typedef std::deque<backtrace_map_t>::const_iterator const_iterator; const_iterator begin() const { return maps_.begin(); } const_iterator begin() const { return maps_.begin(); } const_iterator end() const { return maps_.end(); } const_iterator end() const { return maps_.end(); } virtual bool Build(); virtual bool Build(); protected: protected: BacktraceMap(pid_t pid); virtual bool ParseLine(const char* line, backtrace_map_t* map); virtual bool ParseLine(const char* line, backtrace_map_t* map); std::vector<backtrace_map_t> maps_; std::deque<backtrace_map_t> maps_; pid_t pid_; pid_t pid_; }; }; Loading
libbacktrace/Android.mk +3 −2 Original line number Original line Diff line number Diff line LOCAL_PATH:= $(call my-dir) LOCAL_PATH:= $(call my-dir) common_src := \ common_src := \ Backtrace.cpp \ BacktraceImpl.cpp \ BacktraceMap.cpp \ BacktraceMap.cpp \ BacktraceThread.cpp \ BacktraceThread.cpp \ thread_utils.c \ thread_utils.c \ Loading @@ -23,7 +23,7 @@ common_shared_libs := \ liblog \ liblog \ # To enable using libunwind on each arch, add it to this list. # To enable using libunwind on each arch, add it to this list. libunwind_architectures := arm64 libunwind_architectures := arm arm64 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),$(libunwind_architectures))) ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),$(libunwind_architectures))) Loading @@ -35,6 +35,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ LOCAL_SRC_FILES:= \ $(common_src) \ $(common_src) \ UnwindCurrent.cpp \ UnwindCurrent.cpp \ UnwindMap.cpp \ UnwindPtrace.cpp \ UnwindPtrace.cpp \ LOCAL_CFLAGS := \ LOCAL_CFLAGS := \ Loading
libbacktrace/Backtrace.cpp→libbacktrace/BacktraceImpl.cpp +7 −27 Original line number Original line Diff line number Diff line Loading @@ -29,7 +29,7 @@ #include <backtrace/Backtrace.h> #include <backtrace/Backtrace.h> #include <backtrace/BacktraceMap.h> #include <backtrace/BacktraceMap.h> #include "Backtrace.h" #include "BacktraceImpl.h" #include "thread_utils.h" #include "thread_utils.h" //------------------------------------------------------------------------- //------------------------------------------------------------------------- Loading @@ -40,21 +40,21 @@ Backtrace::Backtrace(BacktraceImpl* impl, pid_t pid, BacktraceMap* map) impl_->SetParent(this); impl_->SetParent(this); if (map_ == NULL) { if (map_ == NULL) { // The map will be created when needed. map_ = BacktraceMap::Create(pid); map_shared_ = false; map_shared_ = false; } } } } Backtrace::~Backtrace() { Backtrace::~Backtrace() { if (map_ && !map_shared_) { delete map_; map_ = NULL; } if (impl_) { if (impl_) { delete impl_; delete impl_; impl_ = NULL; impl_ = NULL; } } if (map_ && !map_shared_) { delete map_; map_ = NULL; } } } bool Backtrace::Unwind(size_t num_ignore_frames) { bool Backtrace::Unwind(size_t num_ignore_frames) { Loading Loading @@ -129,30 +129,10 @@ std::string Backtrace::FormatFrameData(const backtrace_frame_data_t* frame) { return buf; return buf; } } bool Backtrace::BuildMap() { map_ = impl_->CreateBacktraceMap(pid_); if (!map_->Build()) { BACK_LOGW("Failed to build map for process %d", pid_); return false; } return true; } const backtrace_map_t* Backtrace::FindMap(uintptr_t pc) { const backtrace_map_t* Backtrace::FindMap(uintptr_t pc) { if (map_ == NULL) { // Lazy eval, time to build the map. if (!BuildMap()) { return NULL; } } return map_->Find(pc); return map_->Find(pc); } } BacktraceMap* Backtrace::TakeMapOwnership() { map_shared_ = true; return map_; } //------------------------------------------------------------------------- //------------------------------------------------------------------------- // BacktraceCurrent functions. // BacktraceCurrent functions. //------------------------------------------------------------------------- //------------------------------------------------------------------------- Loading