Skip to content

Commit e866e6b

Browse files
authored
[compiler-rt] Implements DumpAllRegisters for windows intel archs. (#108688)
1 parent ec42778 commit e866e6b

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_win.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,45 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
10331033
}
10341034

10351035
void SignalContext::DumpAllRegisters(void *context) {
1036-
// FIXME: Implement this.
1036+
CONTEXT *ctx = (CONTEXT *)context;
1037+
# if defined(__M_X64)
1038+
Report("Register values:\n");
1039+
Printf("rax = %llx ", ctx->Rax);
1040+
Printf("rbx = %llx ", ctx->Rbx);
1041+
Printf("rcx = %llx ", ctx->Rcx);
1042+
Printf("rdx = %llx ", ctx->Rdx);
1043+
Printf("\n");
1044+
Printf("rdi = %llx ", ctx->Rdi);
1045+
Printf("rsi = %llx ", ctx->Rsi);
1046+
Printf("rbp = %llx ", ctx->Rbp);
1047+
Printf("rsp = %llx ", ctx->Rsp);
1048+
Printf("\n");
1049+
Printf("r8 = %llx ", ctx->R8);
1050+
Printf("r9 = %llx ", ctx->R9);
1051+
Printf("r10 = %llx ", ctx->R10);
1052+
Printf("r11 = %llx ", ctx->R11);
1053+
Printf("\n");
1054+
Printf("r12 = %llx ", ctx->R12);
1055+
Printf("r13 = %llx ", ctx->R13);
1056+
Printf("r14 = %llx ", ctx->R14);
1057+
Printf("r15 = %llx ", ctx->R15);
1058+
Printf("\n");
1059+
# elif defined(_M_IX86)
1060+
Report("Register values:\n");
1061+
Printf("eax = %lx ", ctx->Eax);
1062+
Printf("ebx = %lx ", ctx->Ebx);
1063+
Printf("ecx = %lx ", ctx->Ecx);
1064+
Printf("edx = %lx ", ctx->Edx);
1065+
Printf("\n");
1066+
Printf("edi = %lx ", ctx->Edi);
1067+
Printf("esi = %lx ", ctx->Esi);
1068+
Printf("ebp = %lx ", ctx->Ebp);
1069+
Printf("esp = %lx ", ctx->Esp);
1070+
Printf("\n");
1071+
# else
1072+
// TODO
1073+
(void)ctx;
1074+
# endif
10371075
}
10381076

10391077
int SignalContext::GetType() const {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Check that sanitizer prints registers dump_registers on dump_registers=1
2+
// RUN: %clangxx %s -o %t
3+
// RUN: %env_tool_opts=dump_registers=0 not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-NODUMP --strict-whitespace
4+
// RUN: not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-DUMP --strict-whitespace
5+
//
6+
// REQUIRES: i386-pc-windows-msvc
7+
8+
#include <windows.h>
9+
10+
int main() {
11+
RaiseException(EXCEPTION_ACCESS_VIOLATION, 0, 0, NULL);
12+
// CHECK-DUMP: Register values
13+
// CHECK-DUMP-NEXT: eax = {{0x[0-9a-f]+}} ebx = {{0x[0-9a-f]+}} ecx = {{0x[0-9a-f]+}} edx = {{0x[0-9a-f]+}}
14+
// CHECK-DUMP-NEXT: edi = {{0x[0-9a-f]+}} esi = {{0x[0-9a-f]+}} ebp = {{0x[0-9a-f]+}} esp = {{0x[0-9a-f]+}}
15+
// CHECK-NODUMP-NOT: Register values
16+
return 0;
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Check that sanitizer prints registers dump_registers on dump_registers=1
2+
// RUN: %clangxx %s -o %t
3+
// RUN: %env_tool_opts=dump_registers=0 not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-NODUMP --strict-whitespace
4+
// RUN: not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK-DUMP --strict-whitespace
5+
//
6+
// REQUIRES: x86_64-pc-windows-msvc
7+
8+
#include <windows.h>
9+
10+
int main() {
11+
RaiseException(EXCEPTION_ACCESS_VIOLATION, 0, 0, NULL);
12+
// CHECK-DUMP: Register values
13+
// CHECK-DUMP-NEXT: rax = {{0x[0-9a-f]+}} rbx = {{0x[0-9a-f]+}} rcx = {{0x[0-9a-f]+}} rdx = {{0x[0-9a-f]+}}
14+
// CHECK-DUMP-NEXT: rdi = {{0x[0-9a-f]+}} rsi = {{0x[0-9a-f]+}} rbp = {{0x[0-9a-f]+}} rsp = {{0x[0-9a-f]+}}
15+
// CHECK-DUMP-NEXT: r8 = {{0x[0-9a-f]+}} r9 = {{0x[0-9a-f]+}} r10 = {{0x[0-9a-f]+}} r11 = {{0x[0-9a-f]+}}
16+
// CHECK-DUMP-NEXT: r12 = {{0x[0-9a-f]+}} r13 = {{0x[0-9a-f]+}} r14 = {{0x[0-9a-f]+}} r15 = {{0x[0-9a-f]+}}
17+
// CHECK-NODUMP-NOT: Register values
18+
return 0;
19+
}

0 commit comments

Comments
 (0)