-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[compiler-rt] Add DumpAllRegisters
impl
#99049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add implementation for x86_64 and linux - Add test The output is like ` ==XXYYZZ==Register values: rax = 0x... rbx = 0x... rcx = 0x... rdx = 0x... rdi = 0x... rsi = 0x... rbp = 0x... rsp = 0x... r8 = 0x... r9 = 0x... r10 = 0x... r11 = 0x... r12 = 0x... r13 = 0x... r14 = 0x... r15 = 0x... `
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Dmitriy Chestnykh (chestnykh) Changes
The output is like ==XXYYZZ==Register values: Full diff: https://github.com/llvm/llvm-project/pull/99049.diff 2 Files Affected:
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 7935c88204a05..58233a3c0f607 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -2118,8 +2118,89 @@ bool SignalContext::IsTrueFaultingAddress() const {
return si->si_signo == SIGSEGV && si->si_code != 128;
}
+static const char *RegNumToRegName(int reg) {
+# if defined(__x86_64__)
+ switch (reg) {
+ case REG_RAX:
+ return "rax";
+ case REG_RBX:
+ return "rbx";
+ case REG_RCX:
+ return "rcx";
+ case REG_RDX:
+ return "rdx";
+ case REG_RDI:
+ return "rdi";
+ case REG_RSI:
+ return "rsi";
+ case REG_RBP:
+ return "rbp";
+ case REG_RSP:
+ return "rsp";
+ case REG_R8:
+ return "r8";
+ case REG_R9:
+ return "r9";
+ case REG_R10:
+ return "r10";
+ case REG_R11:
+ return "r11";
+ case REG_R12:
+ return "r12";
+ case REG_R13:
+ return "r13";
+ case REG_R14:
+ return "r14";
+ case REG_R15:
+ return "r15";
+ default:
+ return NULL;
+ }
+# endif
+ return NULL;
+}
+
void SignalContext::DumpAllRegisters(void *context) {
- // FIXME: Implement this.
+# if SANITIZER_LINUX
+ ucontext_t *ucontext = (ucontext_t *)context;
+# define DUMPREG64(r) \
+ Printf("%s = 0x%016llx ", RegNumToRegName(r), \
+ ucontext->uc_mcontext.gregs[r]);
+# define DUMPREG_(r) \
+ Printf(" "); \
+ DUMPREG(r);
+# define DUMPREG__(r) \
+ Printf(" "); \
+ DUMPREG(r);
+# define DUMPREG___(r) \
+ Printf(" "); \
+ DUMPREG(r);
+# if defined(__x86_64__)
+# define DUMPREG(r) DUMPREG64(r)
+ Report("Register values:\n");
+ DUMPREG(REG_RAX);
+ DUMPREG(REG_RBX);
+ DUMPREG(REG_RCX);
+ DUMPREG(REG_RDX);
+ Printf("\n");
+ DUMPREG(REG_RDI);
+ DUMPREG(REG_RSI);
+ DUMPREG(REG_RBP);
+ DUMPREG(REG_RSP);
+ Printf("\n");
+ DUMPREG_(REG_R8);
+ DUMPREG_(REG_R9);
+ DUMPREG(REG_R10);
+ DUMPREG(REG_R11);
+ Printf("\n");
+ DUMPREG(REG_R12);
+ DUMPREG(REG_R13);
+ DUMPREG(REG_R14);
+ DUMPREG(REG_R15);
+ Printf("\n");
+# endif
+# endif
+ // FIXME: Implement this for other OSes and architectures.
}
static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/dump_registers.cpp b/compiler-rt/test/sanitizer_common/TestCases/Posix/dump_registers.cpp
index f09b2bf4447cc..2cbd40e924263 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Posix/dump_registers.cpp
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/dump_registers.cpp
@@ -1,16 +1,20 @@
// Check that sanitizer prints registers dump_registers on dump_registers=1
// RUN: %clangxx %s -o %t
-// RUN: %env_tool_opts=dump_registers=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NODUMP
-// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-DUMP
+// RUN: %env_tool_opts=dump_registers=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NODUMP
+// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-DUMP
//
-// FIXME: Implement.
-// XFAIL: *
+// FIXME: Implement for other OSes and architectures.
+// REQUIRES: x86_64-target-arch, linux
#include <signal.h>
int main() {
raise(SIGSEGV);
// CHECK-DUMP: Register values
+ // CHECK-DUMP-NEXT: rax = {{0x[0-9a-f]+}} rbx = {{0x[0-9a-f]+}} rcx = {{0x[0-9a-f]+}} rdx = {{0x[0-9a-f]+}}
+ // CHECK-DUMP-NEXT: rdi = {{0x[0-9a-f]+}} rsi = {{0x[0-9a-f]+}} rbp = {{0x[0-9a-f]+}} rsp = {{0x[0-9a-f]+}}
+ // CHECK-DUMP-NEXT: r8 = {{0x[0-9a-f]+}} r9 = {{0x[0-9a-f]+}} r10 = {{0x[0-9a-f]+}} r11 = {{0x[0-9a-f]+}}
+ // CHECK-DUMP-NEXT: r12 = {{0x[0-9a-f]+}} r13 = {{0x[0-9a-f]+}} r14 = {{0x[0-9a-f]+}} r15 = {{0x[0-9a-f]+}}
// CHECK-NODUMP-NOT: Register values
return 0;
}
|
Fox example gcc warns about `RegNumToRegName` is unused and about `ucontext` is unused
compiler-rt/test/sanitizer_common/TestCases/Posix/dump_registers.cpp
Outdated
Show resolved
Hide resolved
- Restore dump_registers.cpp test in Posix/ dir - Add linux-specifix tests inside Linux/ directory Mac uses single dump_registers.cpp test inside Darwin/ directory though checks in this test are partially 'restricted' For linux we provide one test per each supported architecture with checks for each part of `DumpAllRegisters` output
@vitalybuka i've covered i386 arch and described in the third commit message why i restored common dump_register.cpp test and made two separate dump_register_.cpp tests instead |
✅ With the latest revision this PR passed the C/C++ code formatter. |
A couple of previous commits leaded to wrong endif placement inside the source that caused build problem in https://lab.llvm.org/buildbot/#/builders/13/builds/1020 See llvm#99613 llvm#99049
A couple of previous commits leaded to wrong endif placement inside the source that caused build problem in https://lab.llvm.org/buildbot/#/builders/13/builds/1020 See #99613 #99049
Summary: - Add implementation for x86_64 and linux - Add test The output is like ==XXYYZZ==Register values: rax = 0x... rbx = 0x... rcx = 0x... rdx = 0x... rdi = 0x... rsi = 0x... rbp = 0x... rsp = 0x... r8 = 0x... r9 = 0x... r10 = 0x... r11 = 0x... r12 = 0x... r13 = 0x... r14 = 0x... r15 = 0x... Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251400
Summary: A couple of previous commits leaded to wrong endif placement inside the source that caused build problem in https://lab.llvm.org/buildbot/#/builders/13/builds/1020 See #99613 #99049 Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250654
The output is like
==XXYYZZ==Register values:
rax = 0x... rbx = 0x... rcx = 0x... rdx = 0x...
rdi = 0x... rsi = 0x... rbp = 0x... rsp = 0x...
r8 = 0x... r9 = 0x... r10 = 0x... r11 = 0x...
r12 = 0x... r13 = 0x... r14 = 0x... r15 = 0x...