-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Dump regs fbsd fix #99676
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
Merged
Merged
Dump regs fbsd fix #99676
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2121,7 +2121,8 @@ bool SignalContext::IsTrueFaultingAddress() const { | |
UNUSED | ||
static const char *RegNumToRegName(int reg) { | ||
switch (reg) { | ||
# if defined(__x86_64__) | ||
# if SANITIZER_LINUX | ||
# if defined(__x86_64__) | ||
case REG_RAX: | ||
return "rax"; | ||
case REG_RBX: | ||
|
@@ -2154,7 +2155,7 @@ static const char *RegNumToRegName(int reg) { | |
return "r14"; | ||
case REG_R15: | ||
return "r15"; | ||
# elif defined(__i386__) | ||
# elif defined(__i386__) | ||
case REG_EAX: | ||
return "eax"; | ||
case REG_EBX: | ||
|
@@ -2171,29 +2172,32 @@ static const char *RegNumToRegName(int reg) { | |
return "ebp"; | ||
case REG_ESP: | ||
return "esp"; | ||
# endif | ||
# endif | ||
default: | ||
return NULL; | ||
} | ||
return NULL; | ||
} | ||
|
||
# if SANITIZER_LINUX | ||
UNUSED | ||
static void DumpSingleReg(ucontext_t *ctx, int RegNum) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can probably # if SANITIZER_LINUX both functions with one block |
||
const char *RegName = RegNumToRegName(RegNum); | ||
# if defined(__x86_64__) | ||
# if defined(__x86_64__) | ||
Printf("%s%s = 0x%016llx ", internal_strlen(RegName) == 2 ? " " : "", | ||
RegName, ctx->uc_mcontext.gregs[RegNum]); | ||
# elif defined(__i386__) | ||
# elif defined(__i386__) | ||
Printf("%s = 0x%08x ", RegName, ctx->uc_mcontext.gregs[RegNum]); | ||
# else | ||
# else | ||
(void)RegName; | ||
# endif | ||
# endif | ||
} | ||
# endif | ||
|
||
void SignalContext::DumpAllRegisters(void *context) { | ||
# if SANITIZER_LINUX | ||
ucontext_t *ucontext = (ucontext_t *)context; | ||
# if SANITIZER_LINUX | ||
# if defined(__x86_64__) | ||
Report("Register values:\n"); | ||
DumpSingleReg(ucontext, REG_RAX); | ||
|
@@ -2232,8 +2236,35 @@ void SignalContext::DumpAllRegisters(void *context) { | |
DumpSingleReg(ucontext, REG_EBP); | ||
DumpSingleReg(ucontext, REG_ESP); | ||
Printf("\n"); | ||
# else | ||
(void)ucontext; | ||
# endif | ||
# elif SANITIZER_FREEBSD | ||
# if defined(__x86_64__) | ||
Report("Register values:\n"); | ||
Printf("rax = 0x%016llx ", ucontext->uc_mcontext.mc_rax); | ||
Printf("rbx = 0x%016llx ", ucontext->uc_mcontext.mc_rbx); | ||
Printf("rcx = 0x%016llx ", ucontext->uc_mcontext.mc_rcx); | ||
Printf("rdx = 0x%016llx ", ucontext->uc_mcontext.mc_rdx); | ||
Printf("\n"); | ||
Printf("rdi = 0x%016llx ", ucontext->uc_mcontext.mc_rdi); | ||
Printf("rsi = 0x%016llx ", ucontext->uc_mcontext.mc_rsi); | ||
Printf("rbp = 0x%016llx ", ucontext->uc_mcontext.mc_rbp); | ||
Printf("rsp = 0x%016llx ", ucontext->uc_mcontext.mc_rsp); | ||
Printf("\n"); | ||
Printf(" r8 = 0x%016llx ", ucontext->uc_mcontext.mc_r8); | ||
Printf(" r9 = 0x%016llx ", ucontext->uc_mcontext.mc_r9); | ||
Printf("r10 = 0x%016llx ", ucontext->uc_mcontext.mc_r10); | ||
Printf("r11 = 0x%016llx ", ucontext->uc_mcontext.mc_r11); | ||
Printf("\n"); | ||
Printf("r12 = 0x%016llx ", ucontext->uc_mcontext.mc_r12); | ||
Printf("r13 = 0x%016llx ", ucontext->uc_mcontext.mc_r13); | ||
Printf("r14 = 0x%016llx ", ucontext->uc_mcontext.mc_r14); | ||
Printf("r15 = 0x%016llx ", ucontext->uc_mcontext.mc_r15); | ||
Printf("\n"); | ||
# else | ||
(void)ucontext; | ||
# endif | ||
# endif | ||
// FIXME: Implement this for other OSes and architectures. | ||
} | ||
|
19 changes: 19 additions & 0 deletions
19
compiler-rt/test/sanitizer_common/TestCases/FreeBSD/dump_registers_x86_64.cpp
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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: x86_64-target-arch | ||
|
||
#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; | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is this related to regs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not thus I put in separate commit.