|
| 1 | +//===--- Backtrace.cpp - Swift crash catching and backtracing support ---- ===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2022 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | +// |
| 13 | +// Definitions relating to backtracing. |
| 14 | +// |
| 15 | +//===----------------------------------------------------------------------===// |
| 16 | + |
| 17 | +#ifndef SWIFT_RUNTIME_BACKTRACE_H |
| 18 | +#define SWIFT_RUNTIME_BACKTRACE_H |
| 19 | + |
| 20 | +#include "swift/Runtime/Config.h" |
| 21 | + |
| 22 | +#include "swift/shims/Visibility.h" |
| 23 | +#include "swift/shims/_SwiftBacktracing.h" |
| 24 | + |
| 25 | +#include <inttypes.h> |
| 26 | + |
| 27 | +#ifdef __cplusplus |
| 28 | +namespace swift { |
| 29 | +namespace runtime { |
| 30 | +namespace backtrace { |
| 31 | +#endif |
| 32 | + |
| 33 | +#ifdef _WIN32 |
| 34 | +typedef wchar_t ArgChar; |
| 35 | +typedef DWORD ErrorCode; |
| 36 | +#else |
| 37 | +typedef char ArgChar; |
| 38 | +typedef int ErrorCode; |
| 39 | +#endif |
| 40 | + |
| 41 | +SWIFT_RUNTIME_STDLIB_INTERNAL ErrorCode _swift_installCrashHandler(); |
| 42 | + |
| 43 | +SWIFT_RUNTIME_STDLIB_INTERNAL bool _swift_spawnBacktracer(const ArgChar * const *argv); |
| 44 | + |
| 45 | +enum class UnwindAlgorithm { |
| 46 | + Auto = 0, |
| 47 | + Fast = 1, |
| 48 | + Precise = 2 |
| 49 | +}; |
| 50 | + |
| 51 | +enum class OnOffTty { |
| 52 | + Off = 0, |
| 53 | + On = 1, |
| 54 | + TTY = 2 |
| 55 | +}; |
| 56 | + |
| 57 | +enum class Preset { |
| 58 | + Auto = -1, |
| 59 | + Friendly = 0, |
| 60 | + Medium = 1, |
| 61 | + Full = 2 |
| 62 | +}; |
| 63 | + |
| 64 | +enum class ThreadsToShow { |
| 65 | + Preset = -1, |
| 66 | + All = 0, |
| 67 | + Crashed = 1 |
| 68 | +}; |
| 69 | + |
| 70 | +enum class RegistersToShow { |
| 71 | + Preset = -1, |
| 72 | + None = 0, |
| 73 | + All = 1, |
| 74 | + Crashed = 2 |
| 75 | +}; |
| 76 | + |
| 77 | +enum class ImagesToShow { |
| 78 | + Preset = -1, |
| 79 | + None = 0, |
| 80 | + All = 1, |
| 81 | + Mentioned = 2 |
| 82 | +}; |
| 83 | + |
| 84 | +enum class SanitizePaths { |
| 85 | + Preset = -1, |
| 86 | + Off = 0, |
| 87 | + On = 1 |
| 88 | +}; |
| 89 | + |
| 90 | +struct BacktraceSettings { |
| 91 | + UnwindAlgorithm algorithm; |
| 92 | + OnOffTty enabled; |
| 93 | + bool demangle; |
| 94 | + OnOffTty interactive; |
| 95 | + OnOffTty color; |
| 96 | + unsigned timeout; |
| 97 | + ThreadsToShow threads; |
| 98 | + RegistersToShow registers; |
| 99 | + ImagesToShow images; |
| 100 | + unsigned limit; |
| 101 | + unsigned top; |
| 102 | + SanitizePaths sanitize; |
| 103 | + Preset preset; |
| 104 | + const char *swiftBacktracePath; |
| 105 | +}; |
| 106 | + |
| 107 | +SWIFT_RUNTIME_STDLIB_INTERNAL BacktraceSettings _swift_backtraceSettings; |
| 108 | + |
| 109 | +SWIFT_RUNTIME_STDLIB_SPI SWIFT_CC(swift) bool _swift_isThunkFunction(const char *mangledName); |
| 110 | + |
| 111 | +#ifdef __cplusplus |
| 112 | +} // namespace backtrace |
| 113 | +} // namespace runtime |
| 114 | +} // namespace swift |
| 115 | +#endif |
| 116 | + |
| 117 | +#endif // SWIFT_RUNTIME_BACKTRACE_H |
0 commit comments