123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- #ifndef BASE_DEBUG_STACK_TRACE_H_
- #define BASE_DEBUG_STACK_TRACE_H_
- #include <stddef.h>
- #include <iosfwd>
- #include <string>
- #include "base/base_export.h"
- #include "base/debug/debugging_buildflags.h"
- #include "base/macros.h"
- #include "build/build_config.h"
- #if defined(OS_POSIX)
- #if !defined(OS_NACL)
- #include <signal.h>
- #endif
- #include <unistd.h>
- #endif
- #if defined(OS_WIN)
- struct _EXCEPTION_POINTERS;
- struct _CONTEXT;
- #endif
- namespace base {
- namespace debug {
- BASE_EXPORT bool EnableInProcessStackDumping();
- #if defined(OS_POSIX) && !defined(OS_NACL)
- BASE_EXPORT bool SetStackDumpFirstChanceCallback(bool (*handler)(int,
- siginfo_t*,
- void*));
- #endif
- #if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
- BASE_EXPORT uintptr_t GetStackEnd();
- #endif
- class BASE_EXPORT StackTrace {
- public:
-
- StackTrace();
-
-
- explicit StackTrace(size_t count);
-
-
-
- StackTrace(const void* const* trace, size_t count);
- #if defined(OS_WIN)
-
-
-
- StackTrace(_EXCEPTION_POINTERS* exception_pointers);
- StackTrace(const _CONTEXT* context);
- #endif
-
-
-
-
-
- const void* const* Addresses(size_t* count) const;
-
- void Print() const;
-
-
- void PrintWithPrefix(const char* prefix_string) const;
- #if !defined(__UCLIBC__) & !defined(_AIX)
-
- void OutputToStream(std::ostream* os) const;
-
-
- void OutputToStreamWithPrefix(std::ostream* os,
- const char* prefix_string) const;
- #endif
-
- std::string ToString() const;
-
-
- std::string ToStringWithPrefix(const char* prefix_string) const;
- private:
- #if defined(OS_WIN)
- void InitTrace(const _CONTEXT* context_record);
- #endif
- #if defined(OS_ANDROID)
-
-
- static constexpr int kMaxTraces = 62;
- #else
-
-
- static constexpr int kMaxTraces = 250;
- #endif
- void* trace_[kMaxTraces];
-
- size_t count_;
- };
- BASE_EXPORT std::ostream& operator<<(std::ostream& os, const StackTrace& s);
- BASE_EXPORT size_t CollectStackTrace(void** trace, size_t count);
- #if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
- #if defined(OS_LINUX)
- constexpr bool kEnableScanningByDefault = true;
- #else
- constexpr bool kEnableScanningByDefault = false;
- #endif
- BASE_EXPORT size_t
- TraceStackFramePointers(const void** out_trace,
- size_t max_depth,
- size_t skip_initial,
- bool enable_scanning = kEnableScanningByDefault);
- BASE_EXPORT size_t TraceStackFramePointersFromBuffer(
- uintptr_t fp,
- uintptr_t stack_end,
- const void** out_trace,
- size_t max_depth,
- size_t skip_initial,
- bool enable_scanning = kEnableScanningByDefault);
- class BASE_EXPORT ScopedStackFrameLinker {
- public:
- ScopedStackFrameLinker(void* fp, void* parent_fp);
- ~ScopedStackFrameLinker();
- private:
- void* fp_;
- void* parent_fp_;
- void* original_parent_fp_;
- DISALLOW_COPY_AND_ASSIGN(ScopedStackFrameLinker);
- };
- #endif
- namespace internal {
- #if defined(OS_POSIX) && !defined(OS_ANDROID)
- BASE_EXPORT char *itoa_r(intptr_t i,
- char *buf,
- size_t sz,
- int base,
- size_t padding);
- #endif
- }
- }
- }
- #endif
|