#include "base/debug/stack_trace.h"
#include <string.h>
#include <algorithm>
#include <sstream>
#include <utility>
#include "base/check_op.h"
#include "base/debug/debugging_buildflags.h"
#include "build/build_config.h"
#include "build/config/compiler/compiler_buildflags.h"
#if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
#include <optional>
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
#include <pthread.h>
#include "base/process/process_handle.h"
#include "base/threading/platform_thread.h"
#endif
#if BUILDFLAG(IS_APPLE)
#include <pthread.h>
#endif
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && defined(__GLIBC__)
extern "C" void* __libc_stack_end;
#endif
#endif
namespace base {
namespace debug {
namespace {
#if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
#if defined(__arm__) && defined(__GNUC__) && !defined(__clang__)
constexpr size_t kStackFrameAdjustment = sizeof(uintptr_t);
#else
constexpr size_t kStackFrameAdjustment = …;
#endif
static uintptr_t StripPointerAuthenticationBits(uintptr_t ptr) { … }
uintptr_t GetNextStackFrame(uintptr_t fp) { … }
uintptr_t GetStackFramePC(uintptr_t fp) { … }
bool IsStackFrameValid(uintptr_t fp, uintptr_t prev_fp, uintptr_t stack_end) { … }
uintptr_t ScanStackForNextFrame(uintptr_t fp, uintptr_t stack_end) { … }
void* LinkStackFrames(void* fpp, void* parent_fp) { … }
#endif
std::string* g_stack_trace_message = …;
OverrideStackTraceOutputForTesting::Mode g_override_suppression = …;
}
#if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
uintptr_t GetStackEnd() { … }
#endif
StackTrace::StackTrace() : … { … }
StackTrace::StackTrace(size_t count)
: … { … }
StackTrace::StackTrace(span<const void* const> trace)
: … { … }
bool StackTrace::WillSymbolizeToStreamForTesting() { … }
void StackTrace::Print() const { … }
void StackTrace::PrintWithPrefix(cstring_view prefix_string) const { … }
void StackTrace::OutputToStream(std::ostream* os) const { … }
void StackTrace::OutputToStreamWithPrefix(std::ostream* os,
cstring_view prefix_string) const { … }
std::string StackTrace::ToString() const { … }
std::string StackTrace::ToStringWithPrefix(cstring_view prefix_string) const { … }
void StackTrace::SuppressStackTracesWithMessageForTesting(std::string message) { … }
bool StackTrace::ShouldSuppressOutput() { … }
std::ostream& operator<<(std::ostream& os, const StackTrace& s) { … }
OverrideStackTraceOutputForTesting::OverrideStackTraceOutputForTesting(
Mode mode) { … }
OverrideStackTraceOutputForTesting::~OverrideStackTraceOutputForTesting() { … }
#if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
struct AddressRange { … };
bool IsWithinRange(uintptr_t address, const AddressRange& range) { … }
NOINLINE size_t TraceStackFramePointers(span<const void*> out_trace,
size_t skip_initial,
bool enable_scanning) { … }
ScopedStackFrameLinker::ScopedStackFrameLinker(void* fp, void* parent_fp)
: … { … }
ScopedStackFrameLinker::~ScopedStackFrameLinker() { … }
#endif
}
}