diff options
author | Christopher Ferris <cferris@google.com> | 2017-12-11 17:44:33 -0800 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2018-01-29 10:41:11 -0800 |
commit | 7b8258328f105491ad51a7543b66d6dc65564890 (patch) | |
tree | 086644d59f88c8166cd131ce434d5c7ae97215f9 /libbacktrace/include/backtrace | |
parent | a7524f6165c1598dc23ea95350dd81102c9d91c8 (diff) | |
download | unwinding-7b8258328f105491ad51a7543b66d6dc65564890.tar.gz |
Use new unwinder for offline in libbacktrace.
libbbacktrace changes:
- Completely rewrite the BacktraceOffline class to use the new unwinder.
- Modify the test data to save ucontext_t data instead of unw_context data.
- Convert the previous tests from unw_context data to ucontext_t data.
Bug: 65682279
Test: New unit tests pass in libunwindstack.
Test: All offline tests continue to pass.
Change-Id: I540345c304b20199d46deeb0349a0638a0f3ab2f
Diffstat (limited to 'libbacktrace/include/backtrace')
-rw-r--r-- | libbacktrace/include/backtrace/Backtrace.h | 39 | ||||
-rw-r--r-- | libbacktrace/include/backtrace/BacktraceMap.h | 6 |
2 files changed, 32 insertions, 13 deletions
diff --git a/libbacktrace/include/backtrace/Backtrace.h b/libbacktrace/include/backtrace/Backtrace.h index 18e9f61..7a37015 100644 --- a/libbacktrace/include/backtrace/Backtrace.h +++ b/libbacktrace/include/backtrace/Backtrace.h @@ -60,6 +60,10 @@ enum BacktraceUnwindErrorCode : uint32_t { BACKTRACE_UNWIND_ERROR_FIND_PROC_INFO_FAILED, // Failed to execute dwarf instructions in debug sections. BACKTRACE_UNWIND_ERROR_EXECUTE_DWARF_INSTRUCTION_FAILED, + // Unwind information is incorrect. + BACKTRACE_UNWIND_ERROR_UNWIND_INFO, + // Unwind information stopped due to sp/pc repeating. + BACKTRACE_UNWIND_ERROR_REPEATED_FRAME, }; struct BacktraceUnwindError { @@ -87,14 +91,6 @@ struct backtrace_frame_data_t { // NULL. }; -#if defined(__APPLE__) -struct __darwin_ucontext; -typedef __darwin_ucontext ucontext_t; -#else -struct ucontext; -typedef ucontext ucontext_t; -#endif - struct backtrace_stackinfo_t { uint64_t start; uint64_t end; @@ -106,7 +102,16 @@ class Regs; } class Backtrace { -public: + public: + enum ArchEnum : uint8_t { + ARCH_ARM, + ARCH_ARM64, + ARCH_X86, + ARCH_X86_64, + }; + + static void SetGlobalElfCache(bool enable); + // Create the correct Backtrace object based on what is to be unwound. // If pid < 0 or equals the current pid, then the Backtrace object // corresponds to the current process. @@ -120,6 +125,16 @@ public: static Backtrace* Create(pid_t pid, pid_t tid, BacktraceMap* map = NULL); // Create an offline Backtrace object that can be used to do an unwind without a process + // that is still running. By default, information is only cached in the map + // file. If the calling code creates the map, data can be cached between + // unwinds. If not, all cached data will be destroyed when the Backtrace + // object is destroyed. + static Backtrace* CreateOffline(ArchEnum arch, pid_t pid, pid_t tid, + const std::vector<backtrace_map_t>& maps, + const backtrace_stackinfo_t& stack); + static Backtrace* CreateOffline(ArchEnum arch, pid_t pid, pid_t tid, BacktraceMap* map); + + // Create an offline Backtrace object that can be used to do an unwind without a process // that is still running. If cache_file is set to true, then elf information will be cached // for this call. The cached information survives until the calling process ends. This means // that subsequent calls to create offline Backtrace objects will continue to use the same @@ -130,11 +145,11 @@ 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) = 0; + virtual bool Unwind(size_t num_ignore_frames, void* context = NULL) = 0; static bool Unwind(unwindstack::Regs* regs, BacktraceMap* back_map, std::vector<backtrace_frame_data_t>* frames, size_t num_ignore_frames, - std::vector<std::string>* skip_names); + std::vector<std::string>* skip_names, BacktraceUnwindError* error = nullptr); // Get the function name and offset into the function given the pc. // If the string is empty, then no valid function name was found, @@ -184,7 +199,7 @@ public: std::string GetErrorString(BacktraceUnwindError error); -protected: + protected: Backtrace(pid_t pid, pid_t tid, BacktraceMap* map); // The name returned is not demangled, GetFunctionName() takes care of diff --git a/libbacktrace/include/backtrace/BacktraceMap.h b/libbacktrace/include/backtrace/BacktraceMap.h index 4d020e6..e19c413 100644 --- a/libbacktrace/include/backtrace/BacktraceMap.h +++ b/libbacktrace/include/backtrace/BacktraceMap.h @@ -34,6 +34,9 @@ #include <string> #include <vector> +// Forward declaration. +struct backtrace_stackinfo_t; + // Special flag to indicate a map is in /dev/. However, a map in // /dev/ashmem/... does not set this flag. static constexpr int PROT_DEVICE_MAP = 0x8000; @@ -58,7 +61,8 @@ public: // is unsupported. static BacktraceMap* Create(pid_t pid, bool uncached = false); - static BacktraceMap* Create(pid_t pid, const std::vector<backtrace_map_t>& maps); + static BacktraceMap* CreateOffline(pid_t pid, const std::vector<backtrace_map_t>& maps, + const backtrace_stackinfo_t& stack); virtual ~BacktraceMap(); |