[compiler-rt] [compiler-rt] SignalContext, attempt to implement ::DumpAllRegisters (PR #84413)

David CARLIER via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 7 16:58:11 PST 2024


https://github.com/devnexen created https://github.com/llvm/llvm-project/pull/84413

None

>From 65b4f60bfb95cd86866dc06acee96d153765745a Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Fri, 8 Mar 2024 00:57:04 +0000
Subject: [PATCH] [compiler-rt]  SignalContext, attempt to implement
 ::DumpAllRegisters

---
 .../lib/sanitizer_common/sanitizer_linux.cpp  | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 5d2dd3a7a658fe..3c0e9248b9a66b 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -2106,7 +2106,24 @@ bool SignalContext::IsTrueFaultingAddress() const {
 }
 
 void SignalContext::DumpAllRegisters(void *context) {
-  // FIXME: Implement this.
+#  if SANITIZER_LINUX
+#    if defined(__x86_64__)
+   ucontext_t *uc = static_cast<ucontext_t *>(context);
+   mcontext_t *mc = &uc->uc_mcontext;
+   
+   Report(
+       "rax: %016lx rbx: %016lx rbp: %016lx rsp: %016lx\n"
+       "rdi: %016lx rsi: %016lx rdx: %016lx rcx: %016lx\n"
+       "r8: %016lx  r9: %016lx  r10: %016lx r11: %016lx\n"
+       "r12: %016lx r13: %016lx r14: %016lx r15: %016lx\n",
+       mc->gregs[REG_RAX], mc->gregs[REG_RBX], mc->gregs[REG_RBP], mc->gregs[REG_RSP],
+       mc->gregs[REG_RDI], mc->gregs[REG_RSI], mc->gregs[REG_RDX], mc->gregs[REG_RCX],
+       mc->gregs[REG_R8], mc->gregs[REG_R9], mc->gregs[REG_R10], mc->gregs[REG_R11],
+       mc->gregs[REG_R12], mc->gregs[REG_R13], mc->gregs[REG_R14], mc->gregs[REG_R15]
+   );
+#    endif
+#  endif
+  // FIXME: Implement for other platforms/archs.
 }
 
 static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {



More information about the llvm-commits mailing list