blob: 595b6c1fd88285e10268c389eaa3aadf06823ee3 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2012 The Chromium Authors
[email protected]58580352010-10-26 04:07:502// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/debug/stack_trace.h"
6
[email protected]f01ae9812011-08-30 19:33:047#include <string.h>
8
9#include <algorithm>
[email protected]d4114ba2011-10-12 16:13:4010#include <sstream>
Greg Thompsonc82cbc92024-04-10 07:36:0611#include <utility>
[email protected]f01ae9812011-08-30 19:33:0412
Hans Wennborgc3cffa62020-04-27 10:09:1213#include "base/check_op.h"
Daniel Cheng8d764e572024-06-07 00:12:5514#include "base/debug/debugging_buildflags.h"
Xiaohan Wang131aa4d2022-01-15 19:39:4115#include "build/build_config.h"
Gabriel Charettebe4ecb12021-05-14 15:47:4716#include "build/config/compiler/compiler_buildflags.h"
aviebe805c2015-12-24 08:20:2817
erikchenf7c8a0d2017-04-06 21:15:2718#if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
Arthur Sonzognie5fff99c2024-02-21 15:58:2419#include <optional>
dskiba2ff54582016-08-30 03:57:4320
Xiaohan Wang131aa4d2022-01-15 19:39:4121#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
dskiba0bed51502016-06-06 21:37:5722#include <pthread.h>
Lei Zhangb7f26222021-06-15 18:45:4723
dskiba0bed51502016-06-06 21:37:5724#include "base/process/process_handle.h"
25#include "base/threading/platform_thread.h"
26#endif
27
Xiaohan Wang131aa4d2022-01-15 19:39:4128#if BUILDFLAG(IS_APPLE)
erikchend6b2b822017-02-22 21:10:3129#include <pthread.h>
30#endif
31
Xiaohan Wang131aa4d2022-01-15 19:39:4132#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && defined(__GLIBC__)
dskiba2ff54582016-08-30 03:57:4333extern "C" void* __libc_stack_end;
34#endif
35
erikchenf7c8a0d2017-04-06 21:15:2736#endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
dskiba2ff54582016-08-30 03:57:4337
Peter Kasting811504a72025-01-09 03:18:5038namespace base::debug {
[email protected]58580352010-10-26 04:07:5039
dskiba678c7c22016-09-08 18:23:0140namespace {
[email protected]d4114ba2011-10-12 16:13:4041
wez460b1242017-04-10 21:55:3642#if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
dskiba79080da02016-04-23 00:10:2743
dskiba678c7c22016-09-08 18:23:0144#if defined(__arm__) && defined(__GNUC__) && !defined(__clang__)
45// GCC and LLVM generate slightly different frames on ARM, see
46// https://llvm.org/bugs/show_bug.cgi?id=18505 - LLVM generates
47// x86-compatible frame, while GCC needs adjustment.
48constexpr size_t kStackFrameAdjustment = sizeof(uintptr_t);
49#else