Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 2 | // 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] | f01ae981 | 2011-08-30 19:33:04 | [diff] [blame] | 7 | #include <string.h> |
8 | |||||
9 | #include <algorithm> | ||||
[email protected] | d4114ba | 2011-10-12 16:13:40 | [diff] [blame] | 10 | #include <sstream> |
Greg Thompson | c82cbc9 | 2024-04-10 07:36:06 | [diff] [blame] | 11 | #include <utility> |
[email protected] | f01ae981 | 2011-08-30 19:33:04 | [diff] [blame] | 12 | |
Hans Wennborg | c3cffa6 | 2020-04-27 10:09:12 | [diff] [blame] | 13 | #include "base/check_op.h" |
Daniel Cheng | 8d764e57 | 2024-06-07 00:12:55 | [diff] [blame] | 14 | #include "base/debug/debugging_buildflags.h" |
Xiaohan Wang | 131aa4d | 2022-01-15 19:39:41 | [diff] [blame] | 15 | #include "build/build_config.h" |
Gabriel Charette | be4ecb1 | 2021-05-14 15:47:47 | [diff] [blame] | 16 | #include "build/config/compiler/compiler_buildflags.h" |
avi | ebe805c | 2015-12-24 08:20:28 | [diff] [blame] | 17 | |
erikchen | f7c8a0d | 2017-04-06 21:15:27 | [diff] [blame] | 18 | #if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) |
Arthur Sonzogni | e5fff99c | 2024-02-21 15:58:24 | [diff] [blame] | 19 | #include <optional> |
dskiba | 2ff5458 | 2016-08-30 03:57:43 | [diff] [blame] | 20 | |
Xiaohan Wang | 131aa4d | 2022-01-15 19:39:41 | [diff] [blame] | 21 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) |
dskiba | 0bed5150 | 2016-06-06 21:37:57 | [diff] [blame] | 22 | #include <pthread.h> |
Lei Zhang | b7f2622 | 2021-06-15 18:45:47 | [diff] [blame] | 23 | |
dskiba | 0bed5150 | 2016-06-06 21:37:57 | [diff] [blame] | 24 | #include "base/process/process_handle.h" |
25 | #include "base/threading/platform_thread.h" | ||||
26 | #endif | ||||
27 | |||||
Xiaohan Wang | 131aa4d | 2022-01-15 19:39:41 | [diff] [blame] | 28 | #if BUILDFLAG(IS_APPLE) |
erikchen | d6b2b82 | 2017-02-22 21:10:31 | [diff] [blame] | 29 | #include <pthread.h> |
30 | #endif | ||||
31 | |||||
Xiaohan Wang | 131aa4d | 2022-01-15 19:39:41 | [diff] [blame] | 32 | #if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && defined(__GLIBC__) |
dskiba | 2ff5458 | 2016-08-30 03:57:43 | [diff] [blame] | 33 | extern "C" void* __libc_stack_end; |
34 | #endif | ||||
35 | |||||
erikchen | f7c8a0d | 2017-04-06 21:15:27 | [diff] [blame] | 36 | #endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) |
dskiba | 2ff5458 | 2016-08-30 03:57:43 | [diff] [blame] | 37 | |
Peter Kasting | 811504a7 | 2025-01-09 03:18:50 | [diff] [blame] | 38 | namespace base::debug { |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 39 | |
dskiba | 678c7c2 | 2016-09-08 18:23:01 | [diff] [blame] | 40 | namespace { |
[email protected] | d4114ba | 2011-10-12 16:13:40 | [diff] [blame] | 41 | |
wez | 460b124 | 2017-04-10 21:55:36 | [diff] [blame] | 42 | #if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) |
dskiba | 79080da0 | 2016-04-23 00:10:27 | [diff] [blame] | 43 | |
dskiba | 678c7c2 | 2016-09-08 18:23:01 | [diff] [blame] | 44 | #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. | ||||
48 | constexpr size_t kStackFrameAdjustment = sizeof(uintptr_t); | ||||
49 | #else | ||||