aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Unix/Signals.inc
diff options
context:
space:
mode:
authorStephen Tozer <stephen.tozer@sony.com>2025-07-02 12:01:17 +0100
committerGitHub <noreply@github.com>2025-07-02 12:01:17 +0100
commit35626e97d886dcb5f335af8abcfadb5f6bbcc64a (patch)
tree345df4728dd484a8fe840ffefa2874dbb4c43dc4 /llvm/lib/Support/Unix/Signals.inc
parenta2c9f7dbcc8beef2befce5a3cd786ac320b5449d (diff)
downloadllvm-35626e97d886dcb5f335af8abcfadb5f6bbcc64a.zip
llvm-35626e97d886dcb5f335af8abcfadb5f6bbcc64a.tar.gz
llvm-35626e97d886dcb5f335af8abcfadb5f6bbcc64a.tar.bz2
[DLCov] Origin-Tracking: Enable collecting and symbolizing stack traces (#143591)
This patch is part of a series that adds origin-tracking to the debugify source location coverage checks, allowing us to report symbolized stack traces of the point where missing source locations appear. This patch adds a pair of new functions in `signals.h` that can be used to collect and symbolize stack traces respectively. This has major implementation overlap with the existing stack trace collection/symbolizing methods, but the existing functions are specialized for dumping a stack trace to stderr when LLVM crashes, while these new functions are meant to be called repeatedly during the execution of the program, and therefore we need a separate set of functions.
Diffstat (limited to 'llvm/lib/Support/Unix/Signals.inc')
-rw-r--r--llvm/lib/Support/Unix/Signals.inc15
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc
index 6668a29..a4525a5 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -507,6 +507,21 @@ static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {
return 0;
}
+#if LLVM_ENABLE_DEBUGLOC_TRACKING_ORIGIN
+#if !defined(HAVE_BACKTRACE)
+#error DebugLoc origin-tracking currently requires `backtrace()`.
+#endif
+namespace llvm {
+namespace sys {
+template <unsigned long MaxDepth>
+int getStackTrace(std::array<void *, MaxDepth> &StackTrace) {
+ return backtrace(StackTrace.data(), MaxDepth);
+}
+template int getStackTrace<16ul>(std::array<void *, 16ul> &);
+} // namespace sys
+} // namespace llvm
+#endif
+
/// If this is an ELF platform, we can find all loaded modules and their virtual
/// addresses with dl_iterate_phdr.
static bool findModulesAndOffsets(void **StackTrace, int Depth,