[compiler-rt] Add DumpAllRegisters impl#99049
Merged
vitalybuka merged 5 commits intollvm:mainfrom Jul 18, 2024
Merged
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... `
Member
|
@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
Contributor
Author
vitalybuka
reviewed
Jul 17, 2024
vitalybuka
reviewed
Jul 17, 2024
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
Contributor
Author
|
@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. |
vitalybuka
approved these changes
Jul 18, 2024
chestnykh
added a commit
to chestnykh/llvm-project
that referenced
this pull request
Jul 24, 2024
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
chestnykh
added a commit
that referenced
this pull request
Jul 24, 2024
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
yuxuanchen1997
pushed a commit
that referenced
this pull request
Jul 25, 2024
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
yuxuanchen1997
pushed a commit
that referenced
this pull request
Jul 25, 2024
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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...