diff options
Diffstat (limited to 'include/backtrace')
-rw-r--r-- | include/backtrace/Backtrace.h | 33 | ||||
-rw-r--r-- | include/backtrace/BacktraceMap.h | 17 |
2 files changed, 30 insertions, 20 deletions
diff --git a/include/backtrace/Backtrace.h b/include/backtrace/Backtrace.h index e07d322..290682a 100644 --- a/include/backtrace/Backtrace.h +++ b/include/backtrace/Backtrace.h @@ -39,14 +39,11 @@ struct backtrace_frame_data_t { uintptr_t pc; // The absolute pc. uintptr_t sp; // The top of the stack. size_t stack_size; // The size of the stack, zero indicate an unknown stack size. - const backtrace_map_t* map; // The map associated with the given pc. + backtrace_map_t map; // The map associated with the given pc. std::string func_name; // The function name associated with this pc, NULL if not found. uintptr_t func_offset; // pc relative to the start of the function, only valid if func_name is not NULL. }; -// Forward declarations. -class BacktraceImpl; - #if defined(__APPLE__) struct __darwin_ucontext; typedef __darwin_ucontext ucontext_t; @@ -72,26 +69,32 @@ public: virtual ~Backtrace(); // Get the current stack trace and store in the backtrace_ structure. - virtual bool Unwind(size_t num_ignore_frames, ucontext_t* context = NULL); + virtual bool Unwind(size_t num_ignore_frames, ucontext_t* context = NULL) = 0; // Get the function name and offset into the function given the pc. // If the string is empty, then no valid function name was found. virtual std::string GetFunctionName(uintptr_t pc, uintptr_t* offset); - // Find the map associated with the given pc. - virtual const backtrace_map_t* FindMap(uintptr_t pc); + // Fill in the map data associated with the given pc. + virtual void FillInMap(uintptr_t pc, backtrace_map_t* map); // Read the data at a specific address. virtual bool ReadWord(uintptr_t ptr, word_t* out_value) = 0; + // Read arbitrary data from a specific address. If a read request would + // span from one map to another, this call only reads up until the end + // of the current map. + // Returns the total number of bytes actually read. + virtual size_t Read(uintptr_t addr, uint8_t* buffer, size_t bytes) = 0; + // Create a string representing the formatted line of backtrace information // for a single frame. virtual std::string FormatFrameData(size_t frame_num); virtual std::string FormatFrameData(const backtrace_frame_data_t* frame); - pid_t Pid() { return pid_; } - pid_t Tid() { return tid_; } - size_t NumFrames() { return frames_.size(); } + pid_t Pid() const { return pid_; } + pid_t Tid() const { return tid_; } + size_t NumFrames() const { return frames_.size(); } const backtrace_frame_data_t* GetFrame(size_t frame_num) { if (frame_num >= frames_.size()) { @@ -111,7 +114,11 @@ public: BacktraceMap* GetMap() { return map_; } protected: - Backtrace(BacktraceImpl* impl, pid_t pid, BacktraceMap* map); + Backtrace(pid_t pid, pid_t tid, BacktraceMap* map); + + // The name returned is not demangled, GetFunctionName() takes care of + // demangling the name. + virtual std::string GetFunctionNameRaw(uintptr_t pc, uintptr_t* offset) = 0; virtual bool VerifyReadWordArgs(uintptr_t ptr, word_t* out_value); @@ -124,10 +131,6 @@ protected: bool map_shared_; std::vector<backtrace_frame_data_t> frames_; - - BacktraceImpl* impl_; - - friend class BacktraceImpl; }; #endif // _BACKTRACE_BACKTRACE_H diff --git a/include/backtrace/BacktraceMap.h b/include/backtrace/BacktraceMap.h index 4ed23a8..da96307 100644 --- a/include/backtrace/BacktraceMap.h +++ b/include/backtrace/BacktraceMap.h @@ -33,6 +33,8 @@ #include <string> struct backtrace_map_t { + backtrace_map_t(): start(0), end(0), flags(0) {} + uintptr_t start; uintptr_t end; int flags; @@ -48,15 +50,16 @@ public: virtual ~BacktraceMap(); - // Get the map data structure for the given address. - virtual const backtrace_map_t* Find(uintptr_t addr); + // Fill in the map data structure for the given address. + virtual void FillIn(uintptr_t addr, backtrace_map_t* map); // The flags returned are the same flags as used by the mmap call. // The values are PROT_*. int GetFlags(uintptr_t pc) { - const backtrace_map_t* map = Find(pc); - if (map) { - return map->flags; + backtrace_map_t map; + FillIn(pc, &map); + if (IsValid(map)) { + return map.flags; } return PROT_NONE; } @@ -75,6 +78,10 @@ public: virtual bool Build(); + static inline bool IsValid(const backtrace_map_t& map) { + return map.end > 0; + } + protected: BacktraceMap(pid_t pid); |