Skip to content
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

[compiler-rt] DumpAllRegisters implementation for windows arm64. #112254

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

devnexen
Copy link
Member

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Oct 14, 2024

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

Author: David CARLIER (devnexen)

Changes

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

2 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_win.cpp (+36-1)
  • (added) compiler-rt/test/sanitizer_common/TestCases/Windows/dump_registers_aarch64.cpp (+23)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
index 832682772950e9..838b14d3cc559d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
@@ -1034,7 +1034,7 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
 
 void SignalContext::DumpAllRegisters(void *context) {
   CONTEXT *ctx = (CONTEXT *)context;
-#  if defined(__M_X64)
+#  if defined(_M_X64)
   Report("Register values:\n");
   Printf("rax = %llx  ", ctx->Rax);
   Printf("rbx = %llx  ", ctx->Rbx);
@@ -1068,6 +1068,41 @@ void SignalContext::DumpAllRegisters(void *context) {
   Printf("ebp = %lx  ", ctx->Ebp);
   Printf("esp = %lx  ", ctx->Esp);
   Printf("\n");
+#  elif defined(_M_ARM64)
+  Report("Register values:\n");
+  Printf("x0  = %llx  ", ctx->X0);
+  Printf("x1  = %llx  ", ctx->X1);
+  Printf("x2  = %llx  ", ctx->X2);
+  Printf("x3  = %llx  ", ctx->X3);
+  Printf("x4  = %llx  ", ctx->X4);
+  Printf("x5  = %llx  ", ctx->X5);
+  Printf("x6  = %llx  ", ctx->X6);
+  Printf("x7  = %llx  ", ctx->X7);
+  Printf("x8  = %llx  ", ctx->X8);
+  Printf("x9  = %llx  ", ctx->X9);
+  Printf("x10 = %llx  ", ctx->X10);
+  Printf("x11 = %llx  ", ctx->X11);
+  Printf("x12 = %llx  ", ctx->X12);
+  Printf("x13 = %llx  ", ctx->X13);
+  Printf("x14 = %llx  ", ctx->X14);
+  Printf("x15 = %llx  ", ctx->X15);
+  Printf("x16 = %llx  ", ctx->X16);
+  Printf("x17 = %llx  ", ctx->X17);
+  Printf("x18 = %llx  ", ctx->X18);
+  Printf("x19 = %llx  ", ctx->X19);
+  Printf("x20 = %llx  ", ctx->X20);
+  Printf("x21 = %llx  ", ctx->X21);
+  Printf("x22 = %llx  ", ctx->X22);
+  Printf("x23 = %llx  ", ctx->X23);
+  Printf("x24 = %llx  ", ctx->X24);
+  Printf("x25 = %llx  ", ctx->X25);
+  Printf("x26 = %llx  ", ctx->X26);
+  Printf("x27 = %llx  ", ctx->X27);
+  Printf("x28 = %llx  ", ctx->X28);
+  Printf("x29 = %llx  ", ctx->X29);
+  Printf("x30 = %llx  ", ctx->X30);
+  Printf("x31 = %llx  ", ctx->X31);
+  Printf("\n");
 #  else
   // TODO
   (void)ctx;
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Windows/dump_registers_aarch64.cpp b/compiler-rt/test/sanitizer_common/TestCases/Windows/dump_registers_aarch64.cpp
new file mode 100644
index 00000000000000..f4805640d682b0
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Windows/dump_registers_aarch64.cpp
@@ -0,0 +1,23 @@
+// 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-prefix=CHECK-NODUMP
+// RUN: not %run %t 2>&1 | FileCheck %s --strict-whitespace --check-prefix=CHECK-DUMP
+//
+// REQUIRES: aarch64-pc-windows-msvc
+
+#include <windows.h>
+
+int main() {
+  RaiseException(EXCEPTION_ACCESS_VIOLATION, 0, 0, NULL);
+  // CHECK-DUMP: Register values
+  // CHECK-DUMP-NEXT: x0 = {{0x[0-9a-f]+}}   x1 = {{0x[0-9a-f]+}}   x2 = {{0x[0-9a-f]+}}   x3 = {{0x[0-9a-f]+}}
+  // CHECK-DUMP-NEXT: x4 = {{0x[0-9a-f]+}}   x5 = {{0x[0-9a-f]+}}   x6 = {{0x[0-9a-f]+}}   x7 = {{0x[0-9a-f]+}}
+  // CHECK-DUMP-NEXT: x8 = {{0x[0-9a-f]+}}   x9 = {{0x[0-9a-f]+}}  x10 = {{0x[0-9a-f]+}}  x11 = {{0x[0-9a-f]+}}
+  // CHECK-DUMP-NEXT:x12 = {{0x[0-9a-f]+}}  x13 = {{0x[0-9a-f]+}}  x14 = {{0x[0-9a-f]+}}  x15 = {{0x[0-9a-f]+}}
+  // CHECK-DUMP-NEXT:x16 = {{0x[0-9a-f]+}}  x17 = {{0x[0-9a-f]+}}  x18 = {{0x[0-9a-f]+}}  x19 = {{0x[0-9a-f]+}}
+  // CHECK-DUMP-NEXT:x20 = {{0x[0-9a-f]+}}  x21 = {{0x[0-9a-f]+}}  x22 = {{0x[0-9a-f]+}}  x23 = {{0x[0-9a-f]+}}
+  // CHECK-DUMP-NEXT:x24 = {{0x[0-9a-f]+}}  x25 = {{0x[0-9a-f]+}}  x26 = {{0x[0-9a-f]+}}  x27 = {{0x[0-9a-f]+}}
+  // CHECK-DUMP-NEXT:x28 = {{0x[0-9a-f]+}}   fp = {{0x[0-9a-f]+}}   lr = {{0x[0-9a-f]+}}   sp = {{0x[0-9a-f]+}}
+  // CHECK-NODUMP-NOT: Register values
+  return 0;
+}

@devnexen devnexen merged commit b8ee0aa into llvm:main Oct 14, 2024
8 of 9 checks passed
@glandium
Copy link
Contributor

This fails to build on downstream builders:

/builds/worker/fetches/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp(1103,31):
error: no member named 'X29' in '_CONTEXT'
 1103 |   Printf("x29 = %llx  ", ctx->X29);
      |                          ~~~  ^
/builds/worker/fetches/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp(1104,31):
error: no member named 'X30' in '_CONTEXT'
 1104 |   Printf("x30 = %llx  ", ctx->X30);
      |                          ~~~  ^
/builds/worker/fetches/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_win.cpp(1105,31):
error: no member named 'X31' in '_CONTEXT'
 1105 |   Printf("x31 = %llx  ", ctx->X31);
      |                          ~~~  ^
3 errors generated.

@glandium
Copy link
Contributor

The winnt.h header in the windows 10 SDK 10.0.22621 has this:

    /* +0x008 */ union {
                    struct {
                        ...
                        DWORD64 X28;
    /* +0x0f0 */        DWORD64 Fp;
    /* +0x0f8 */        DWORD64 Lr;
                    } DUMMYSTRUCTNAME;
                    DWORD64 X[31];
                 } DUMMYUNIONNAME;
    /* +0x100 */ DWORD64 Sp;
    /* +0x108 */ DWORD64 Pc;

@devnexen
Copy link
Member Author

Looking at it. thanks

devnexen added a commit to devnexen/llvm-project that referenced this pull request Oct 15, 2024
devnexen added a commit to devnexen/llvm-project that referenced this pull request Oct 15, 2024
devnexen added a commit to devnexen/llvm-project that referenced this pull request Oct 15, 2024
// CHECK-DUMP-NEXT:x16 = {{0x[0-9a-f]+}} x17 = {{0x[0-9a-f]+}} x18 = {{0x[0-9a-f]+}} x19 = {{0x[0-9a-f]+}}
// CHECK-DUMP-NEXT:x20 = {{0x[0-9a-f]+}} x21 = {{0x[0-9a-f]+}} x22 = {{0x[0-9a-f]+}} x23 = {{0x[0-9a-f]+}}
// CHECK-DUMP-NEXT:x24 = {{0x[0-9a-f]+}} x25 = {{0x[0-9a-f]+}} x26 = {{0x[0-9a-f]+}} x27 = {{0x[0-9a-f]+}}
// CHECK-DUMP-NEXT:x28 = {{0x[0-9a-f]+}} fp = {{0x[0-9a-f]+}} lr = {{0x[0-9a-f]+}} sp = {{0x[0-9a-f]+}}
Copy link
Member

Choose a reason for hiding this comment

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

This test can't possibly succeed - as you're printing x29 etc above, while looking for the string fp here?

Also even with #112305 when the code actually does compile, it still won't match this test.

Please make sure that you test compile code contributions, and for test additions, that you actually have tested running them and verified that they succeed. If you did try to run the test, was it executed, or was the REQUIRES line not really matched?

Copy link
Member Author

Choose a reason for hiding this comment

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

In fact I do not have windows for arm64 just x86_64 but have access to the CONTEXT struct definitions

Copy link
Member Author

Choose a reason for hiding this comment

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

going to fix the test..

DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
bricknerb pushed a commit to bricknerb/llvm-project that referenced this pull request Oct 17, 2024
bricknerb pushed a commit to bricknerb/llvm-project that referenced this pull request Oct 17, 2024
EricWF pushed a commit to efcs/llvm-project that referenced this pull request Oct 22, 2024
EricWF pushed a commit to efcs/llvm-project that referenced this pull request Oct 22, 2024
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.

5 participants