Skip to content

[compiler-rt]: DumpAllRegs on NetBSD arm64. #102826

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 1 commit into from
Aug 26, 2024

Conversation

devnexen
Copy link
Member

all 35 registers are stored in one unique array. for simplicity sake, we do not bother using _REG_X* constants.

@llvmbot
Copy link
Member

llvmbot commented Aug 11, 2024

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

Author: David CARLIER (devnexen)

Changes

all 35 registers are stored in one unique array. for simplicity sake, we do not bother using _REG_X* constants.


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

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp (+8-3)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 73f07c7b22dc5a..16d06c69a38f32 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -2312,11 +2312,11 @@ static const char *RegNumToRegName(int reg) {
   return NULL;
 }
 
-#  if SANITIZER_LINUX && SANITIZER_GLIBC && \
+#  if ((SANITIZER_LINUX && SANITIZER_GLIBC) || SANITIZER_NETBSD) && \
       (defined(__arm__) || defined(__aarch64__))
 static uptr GetArmRegister(ucontext_t *ctx, int RegNum) {
   switch (RegNum) {
-#    if defined(__arm__)
+#    if defined(__arm__) && !SANITIZER_NETBSD
 #      ifdef MAKE_CASE
 #        undef MAKE_CASE
 #      endif
@@ -2345,10 +2345,15 @@ static uptr GetArmRegister(ucontext_t *ctx, int RegNum) {
     case REG_R15:
       return ctx->uc_mcontext.arm_pc;
 #    elif defined(__aarch64__)
+#      if SANITIZER_LINUX
     case 0 ... 30:
       return ctx->uc_mcontext.regs[RegNum];
     case 31:
       return ctx->uc_mcontext.sp;
+#      elif SANITIZER_NETBSD
+    case 0 ... 31:
+      return ctx->uc_mcontext.__gregs[RegNum];
+#      endif
 #    endif
     default:
       return 0;
@@ -2456,7 +2461,7 @@ void SignalContext::DumpAllRegisters(void *context) {
   DumpSingleReg(ucontext, REG_R14);
   DumpSingleReg(ucontext, REG_R15);
   Printf("\n");
-#    elif defined(__aarch64__) && !SANITIZER_NETBSD
+#    elif defined(__aarch64__)
   Report("Register values:\n");
   for (int i = 0; i <= 31; ++i) {
     DumpSingleReg(ucontext, i);

all 35 registers are stored in one unique array. for simplicity
sake, we do not bother using _REG_X* constants.
@devnexen devnexen force-pushed the netbsd_dump_reg_arm64 branch from 525bfa5 to dc4835c Compare August 20, 2024 21:15
@devnexen devnexen requested a review from chestnykh August 20, 2024 21:15
Copy link
Contributor

@chestnykh chestnykh left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@devnexen devnexen merged commit b0fbfbb into llvm:main Aug 26, 2024
7 checks passed
@fmayer
Copy link
Contributor

fmayer commented Aug 26, 2024

Huh, why do we have a NetBSD branch in sanitizer_linux.cpp

@devnexen
Copy link
Member Author

I guess it is easier to share common code with linux

@fmayer
Copy link
Contributor

fmayer commented Aug 26, 2024

There is sanitizer_netbsd.cpp, it should go into that. IMO it is hard to navigate code otherwise.

EDIT: I guess it's not your fault, the file is already littered with BSD ifdefs

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.

4 participants