Skip to content

Conversation

@devnexen
Copy link
Member

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Jul 19, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: David CARLIER (devnexen)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/99702.diff

2 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp (+12)
  • (added) compiler-rt/test/sanitizer_common/TestCases/FreeBSD/dump_registers_i386.cpp (+17)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 40c46a8949636..6691a814f82c5 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -2262,6 +2262,18 @@ void SignalContext::DumpAllRegisters(void *context) {
   Printf("r14 = 0x%016llx  ", ucontext->uc_mcontext.mc_r14);
   Printf("r15 = 0x%016llx  ", ucontext->uc_mcontext.mc_r15);
   Printf("\n");
+#    elif defined(__i386__)
+  Report("Register values:\n");
+  Printf("eax = 0x%016llx  ", ucontext->uc_mcontext.mc_eax);
+  Printf("ebx = 0x%016llx  ", ucontext->uc_mcontext.mc_ebx);
+  Printf("ecx = 0x%016llx  ", ucontext->uc_mcontext.mc_ecx);
+  Printf("edx = 0x%016llx  ", ucontext->uc_mcontext.mc_edx);
+  Printf("\n");
+  Printf("edi = 0x%016llx  ", ucontext->uc_mcontext.mc_edi);
+  Printf("esi = 0x%016llx  ", ucontext->uc_mcontext.mc_esi);
+  Printf("ebp = 0x%016llx  ", ucontext->uc_mcontext.mc_ebp);
+  Printf("esp = 0x%016llx  ", ucontext->uc_mcontext.mc_esp);
+  Printf("\n");
 #    else
   (void)ucontext;
 #    endif
diff --git a/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/dump_registers_i386.cpp b/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/dump_registers_i386.cpp
new file mode 100644
index 0000000000000..74aea4d8b360a
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/FreeBSD/dump_registers_i386.cpp
@@ -0,0 +1,17 @@
+// Check that sanitizer prints registers dump_registers on dump_registers=1
+// RUN: %clangxx  %s -o %t
+// RUN: %env_tool_opts=dump_registers=0 not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-NODUMP --strict-whitespace
+// RUN: not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-DUMP --strict-whitespace
+//
+// REQUIRES: i386-target-arch
+
+#include <signal.h>
+
+int main() {
+  raise(SIGSEGV);
+  // CHECK-DUMP: Register values
+  // CHECK-DUMP-NEXT: eax = {{0x[0-9a-f]+}}  ebx = {{0x[0-9a-f]+}}  ecx = {{0x[0-9a-f]+}}  edx = {{0x[0-9a-f]+}}
+  // CHECK-DUMP-NEXT: edi = {{0x[0-9a-f]+}}  esi = {{0x[0-9a-f]+}}  ebp = {{0x[0-9a-f]+}}  esp = {{0x[0-9a-f]+}}
+  // CHECK-NODUMP-NOT: Register values
+  return 0;
+}

@devnexen devnexen requested a review from vitalybuka July 19, 2024 20:52
Printf("\n");
# elif defined(__i386__)
Report("Register values:\n");
Printf("eax = 0x%016llx ", ucontext->uc_mcontext.mc_eax);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for 32bit it should be 8char aligned

Copy link
Collaborator

@vitalybuka vitalybuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix format to use 8 char

@devnexen devnexen force-pushed the dump_regs_fbsd_i386 branch from 059ec3e to b1b65ad Compare July 19, 2024 21:20
@devnexen devnexen merged commit 9e74f66 into llvm:main Jul 19, 2024
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary: 

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants