From 0b6be3c9d158b1bae4386297c2b405108b5f4042 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 19 Jul 2024 11:01:11 +0300 Subject: [PATCH 1/8] [compiler-rt] Add `DumpAllRegister` impl for arm and aarch64 --- .../lib/sanitizer_common/sanitizer_linux.cpp | 146 +++++++++++++++++- 1 file changed, 142 insertions(+), 4 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp index 483a1042a6238..3b44a056e5b2f 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp @@ -2172,7 +2172,70 @@ static const char *RegNumToRegName(int reg) { return "ebp"; case REG_ESP: return "esp"; -# endif +# elif defined(__arm__) +# define REG_STR(reg) #reg +# define MAKE_CASE(N) \ + case REG_R##N: \ + return REG_STR(r##N) + MAKE_CASE(0); + MAKE_CASE(1); + MAKE_CASE(2); + MAKE_CASE(3); + MAKE_CASE(4); + MAKE_CASE(5); + MAKE_CASE(6); + MAKE_CASE(7); + MAKE_CASE(8); + MAKE_CASE(9); + MAKE_CASE(10); + MAKE_CASE(11); + MAKE_CASE(12); + case REG_R13: + return "sp"; + case REG_R14: + return "lr"; + case REG_R15: + return "pc"; +# elif defined(__aarch64__) +# define REG_STR(reg) #reg +# define MAKE_CASE(N) \ + case N: \ + return REG_STR(x##N) + MAKE_CASE(0); + MAKE_CASE(1); + MAKE_CASE(2); + MAKE_CASE(3); + MAKE_CASE(4); + MAKE_CASE(5); + MAKE_CASE(6); + MAKE_CASE(7); + MAKE_CASE(8); + MAKE_CASE(9); + MAKE_CASE(10); + MAKE_CASE(11); + MAKE_CASE(12); + MAKE_CASE(13); + MAKE_CASE(14); + MAKE_CASE(15); + MAKE_CASE(16); + MAKE_CASE(17); + MAKE_CASE(18); + MAKE_CASE(19); + MAKE_CASE(20); + MAKE_CASE(21); + MAKE_CASE(22); + MAKE_CASE(23); + MAKE_CASE(24); + MAKE_CASE(25); + MAKE_CASE(26); + MAKE_CASE(27); + MAKE_CASE(28); + case 29: + return "fp"; + case 30: + return "lr"; + case 31: + return "sp"; # endif default: return NULL; @@ -2180,7 +2243,47 @@ static const char *RegNumToRegName(int reg) { return NULL; } -# if SANITIZER_LINUX +# if SANITIZER_LINUX && (defined(__arm__) || defined(__aarch64__)) +static unsigned long GetArmRegister(ucontext_t *ctx, int RegNum) { + switch (RegNum) { +# if defined(__arm__) +# define MAKE_CASE(N) \ + case REG_R##N: \ + return ctx->uc_mcontext.arm_r##N + MAKE_CASE(0); + MAKE_CASE(1); + MAKE_CASE(2); + MAKE_CASE(3); + MAKE_CASE(4); + MAKE_CASE(5); + MAKE_CASE(6); + MAKE_CASE(7); + MAKE_CASE(8); + MAKE_CASE(9); + MAKE_CASE(10); + case REG_R11: + return ctx->uc_mcontext.arm_fp; + case REG_R12: + return ctx->uc_mcontext.arm_ip; + case REG_R13: + return ctx->uc_mcontext.arm_sp; + case REG_R14: + return ctx->uc_mcontext.arm_lr; + case REG_R15: + return ctx->uc_mcontext.arm_pc; +# elif defined(__aarch64__) + case 0 ... 30: + return ctx->uc_mcontext.regs[RegNum]; + case 31: + return ctx->uc_mcontext.sp; +# endif + default: + return 0UL; + } + return 0UL; +} +# endif // SANITIZER_LINUX && (defined(__arm__) || defined(__aarch64__)) + UNUSED static void DumpSingleReg(ucontext_t *ctx, int RegNum) { const char *RegName = RegNumToRegName(RegNum); @@ -2189,7 +2292,13 @@ static void DumpSingleReg(ucontext_t *ctx, int RegNum) { RegName, ctx->uc_mcontext.gregs[RegNum]); # elif defined(__i386__) Printf("%s = 0x%08x ", RegName, ctx->uc_mcontext.gregs[RegNum]); -# else +# elif defined(__arm__) + Printf("%s%s = 0x%08lx ", internal_strlen(RegName) == 2 ? " " : "", RegName, + GetArmRegister(ctx, RegNum)); +# elif defined(__aarch64__) + Printf("%s%s = 0x%016llx ", internal_strlen(RegName) == 2 ? " " : "", + RegName, GetArmRegister(ctx, RegNum)); +# else (void)RegName; # endif } @@ -2236,7 +2345,36 @@ void SignalContext::DumpAllRegisters(void *context) { DumpSingleReg(ucontext, REG_EBP); DumpSingleReg(ucontext, REG_ESP); Printf("\n"); -# else +# elif defined(__arm__) + Report("Register values:\n"); + DumpSingleReg(ucontext, REG_R0); + DumpSingleReg(ucontext, REG_R1); + DumpSingleReg(ucontext, REG_R2); + DumpSingleReg(ucontext, REG_R3); + Printf("\n"); + DumpSingleReg(ucontext, REG_R4); + DumpSingleReg(ucontext, REG_R5); + DumpSingleReg(ucontext, REG_R6); + DumpSingleReg(ucontext, REG_R7); + Printf("\n"); + DumpSingleReg(ucontext, REG_R8); + DumpSingleReg(ucontext, REG_R9); + DumpSingleReg(ucontext, REG_R10); + DumpSingleReg(ucontext, REG_R11); + Printf("\n"); + DumpSingleReg(ucontext, REG_R12); + DumpSingleReg(ucontext, REG_R13); + DumpSingleReg(ucontext, REG_R14); + DumpSingleReg(ucontext, REG_R15); + Printf("\n"); +# elif defined(__aarch64__) + Report("Register values:\n"); + for (int i = 0; i <= 31; ++i) { + DumpSingleReg(ucontext, i); + if (i % 4 == 3) + Printf("\n"); + } +# endif (void)ucontext; # endif # elif SANITIZER_FREEBSD From 9af8fb2959b3b8537f477cd9d649436529e61aae Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Fri, 19 Jul 2024 11:06:04 +0300 Subject: [PATCH 2/8] [compiler-rt][test] Add tests to `DumpAllRegisters` - Add tests to check `DumpAllRegisters` output on ARM and AArch64 --- .../Linux/dump_registers_aarch64.cpp | 23 +++++++++++++++++++ .../TestCases/Linux/dump_registers_arm.cpp | 19 +++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 compiler-rt/test/sanitizer_common/TestCases/Linux/dump_registers_aarch64.cpp create mode 100644 compiler-rt/test/sanitizer_common/TestCases/Linux/dump_registers_arm.cpp diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/dump_registers_aarch64.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/dump_registers_aarch64.cpp new file mode 100644 index 0000000000000..e73de49b5c84e --- /dev/null +++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/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 --check-prefix=CHECK-DUMP +// +// REQUIRES: aarch64-target-arch + +#include + +int main() { + raise(SIGSEGV); + // 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; +} diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/dump_registers_arm.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/dump_registers_arm.cpp new file mode 100644 index 0000000000000..4b322ce2564eb --- /dev/null +++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/dump_registers_arm.cpp @@ -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-prefix=CHECK-NODUMP +// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-DUMP +// +// REQUIRES: arm-target-arch + +#include + +int main() { + raise(SIGSEGV); + // CHECK-DUMP: Register values + // CHECK-DUMP-NEXT: r0 = {{0x[0-9a-f]+}} r1 = {{0x[0-9a-f]+}} r2 = {{0x[0-9a-f]+}} r3 = {{0x[0-9a-f]+}} + // CHECK-DUMP-NEXT: r4 = {{0x[0-9a-f]+}} r5 = {{0x[0-9a-f]+}} r6 = {{0x[0-9a-f]+}} r7 = {{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]+}} sp = {{0x[0-9a-f]+}} lr = {{0x[0-9a-f]+}} pc = {{0x[0-9a-f]+}} + // CHECK-NODUMP-NOT: Register values + return 0; +} From 9fb4f89da0b7baf41e7314a200c7a9f895c3ba16 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Sun, 21 Jul 2024 08:40:55 +0300 Subject: [PATCH 3/8] [compiler-rt] Fix wrong PP directive --- compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp index 3b44a056e5b2f..a90be0dbd1df7 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp @@ -2374,7 +2374,7 @@ void SignalContext::DumpAllRegisters(void *context) { if (i % 4 == 3) Printf("\n"); } -# endif +# else (void)ucontext; # endif # elif SANITIZER_FREEBSD From bbb4a60ba01e0530e56a22655a607ad46bc7c870 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Sun, 21 Jul 2024 08:45:52 +0300 Subject: [PATCH 4/8] [compiler-rt] Correct codestyle --- .../lib/sanitizer_common/sanitizer_linux.cpp | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp index a90be0dbd1df7..8291512c1d644 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp @@ -2172,11 +2172,11 @@ static const char *RegNumToRegName(int reg) { return "ebp"; case REG_ESP: return "esp"; -# elif defined(__arm__) -# define REG_STR(reg) #reg -# define MAKE_CASE(N) \ - case REG_R##N: \ - return REG_STR(r##N) +# elif defined(__arm__) +# define REG_STR(reg) #reg +# define MAKE_CASE(N) \ + case REG_R##N: \ + return REG_STR(r##N) MAKE_CASE(0); MAKE_CASE(1); MAKE_CASE(2); @@ -2196,11 +2196,11 @@ static const char *RegNumToRegName(int reg) { return "lr"; case REG_R15: return "pc"; -# elif defined(__aarch64__) -# define REG_STR(reg) #reg -# define MAKE_CASE(N) \ - case N: \ - return REG_STR(x##N) +# elif defined(__aarch64__) +# define REG_STR(reg) #reg +# define MAKE_CASE(N) \ + case N: \ + return REG_STR(x##N) MAKE_CASE(0); MAKE_CASE(1); MAKE_CASE(2); @@ -2236,20 +2236,20 @@ static const char *RegNumToRegName(int reg) { return "lr"; case 31: return "sp"; -# endif +# endif default: return NULL; } return NULL; } -# if SANITIZER_LINUX && (defined(__arm__) || defined(__aarch64__)) +# if SANITIZER_LINUX && (defined(__arm__) || defined(__aarch64__)) static unsigned long GetArmRegister(ucontext_t *ctx, int RegNum) { switch (RegNum) { -# if defined(__arm__) -# define MAKE_CASE(N) \ - case REG_R##N: \ - return ctx->uc_mcontext.arm_r##N +# if defined(__arm__) +# define MAKE_CASE(N) \ + case REG_R##N: \ + return ctx->uc_mcontext.arm_r##N MAKE_CASE(0); MAKE_CASE(1); MAKE_CASE(2); @@ -2271,18 +2271,18 @@ static unsigned long GetArmRegister(ucontext_t *ctx, int RegNum) { return ctx->uc_mcontext.arm_lr; case REG_R15: return ctx->uc_mcontext.arm_pc; -# elif defined(__aarch64__) +# elif defined(__aarch64__) case 0 ... 30: return ctx->uc_mcontext.regs[RegNum]; case 31: return ctx->uc_mcontext.sp; -# endif +# endif default: return 0UL; } return 0UL; } -# endif // SANITIZER_LINUX && (defined(__arm__) || defined(__aarch64__)) +# endif // SANITIZER_LINUX && (defined(__arm__) || defined(__aarch64__)) UNUSED static void DumpSingleReg(ucontext_t *ctx, int RegNum) { @@ -2292,13 +2292,13 @@ static void DumpSingleReg(ucontext_t *ctx, int RegNum) { RegName, ctx->uc_mcontext.gregs[RegNum]); # elif defined(__i386__) Printf("%s = 0x%08x ", RegName, ctx->uc_mcontext.gregs[RegNum]); -# elif defined(__arm__) +# elif defined(__arm__) Printf("%s%s = 0x%08lx ", internal_strlen(RegName) == 2 ? " " : "", RegName, GetArmRegister(ctx, RegNum)); -# elif defined(__aarch64__) +# elif defined(__aarch64__) Printf("%s%s = 0x%016llx ", internal_strlen(RegName) == 2 ? " " : "", RegName, GetArmRegister(ctx, RegNum)); -# else +# else (void)RegName; # endif } From 67abe942b9d76478b7a2c18ca3892bdbc5883009 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Wed, 24 Jul 2024 09:39:43 +0300 Subject: [PATCH 5/8] [compiler-rt] Change return type to uptr --- compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp index 8291512c1d644..95f7061b8bad8 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp @@ -2244,7 +2244,7 @@ static const char *RegNumToRegName(int reg) { } # if SANITIZER_LINUX && (defined(__arm__) || defined(__aarch64__)) -static unsigned long GetArmRegister(ucontext_t *ctx, int RegNum) { +static uptr GetArmRegister(ucontext_t *ctx, int RegNum) { switch (RegNum) { # if defined(__arm__) # define MAKE_CASE(N) \ @@ -2278,9 +2278,9 @@ static unsigned long GetArmRegister(ucontext_t *ctx, int RegNum) { return ctx->uc_mcontext.sp; # endif default: - return 0UL; + return 0; } - return 0UL; + return 0; } # endif // SANITIZER_LINUX && (defined(__arm__) || defined(__aarch64__)) @@ -2293,10 +2293,10 @@ static void DumpSingleReg(ucontext_t *ctx, int RegNum) { # elif defined(__i386__) Printf("%s = 0x%08x ", RegName, ctx->uc_mcontext.gregs[RegNum]); # elif defined(__arm__) - Printf("%s%s = 0x%08lx ", internal_strlen(RegName) == 2 ? " " : "", RegName, + Printf("%s%s = 0xzx ", internal_strlen(RegName) == 2 ? " " : "", RegName, GetArmRegister(ctx, RegNum)); # elif defined(__aarch64__) - Printf("%s%s = 0x%016llx ", internal_strlen(RegName) == 2 ? " " : "", + Printf("%s%s = 0xzx ", internal_strlen(RegName) == 2 ? " " : "", RegName, GetArmRegister(ctx, RegNum)); # else (void)RegName; From 3e6fe27f9cd66630d3bbdbaa1c8216388fda5f68 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Wed, 24 Jul 2024 09:40:09 +0300 Subject: [PATCH 6/8] [compiler-rt][test] Use `--strict-whitespace` --- .../TestCases/Linux/dump_registers_aarch64.cpp | 18 +++++++++--------- .../TestCases/Linux/dump_registers_arm.cpp | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/dump_registers_aarch64.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/dump_registers_aarch64.cpp index e73de49b5c84e..e01b826c86b8a 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Linux/dump_registers_aarch64.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/dump_registers_aarch64.cpp @@ -1,7 +1,7 @@ // 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 --check-prefix=CHECK-DUMP +// RUN: not %run %t 2>&1 | FileCheck %s --strict-whitespace --check-prefix=CHECK-DUMP // // REQUIRES: aarch64-target-arch @@ -10,14 +10,14 @@ int main() { raise(SIGSEGV); // 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-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; } diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/dump_registers_arm.cpp b/compiler-rt/test/sanitizer_common/TestCases/Linux/dump_registers_arm.cpp index 4b322ce2564eb..e17dbf196227b 100644 --- a/compiler-rt/test/sanitizer_common/TestCases/Linux/dump_registers_arm.cpp +++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/dump_registers_arm.cpp @@ -1,7 +1,7 @@ // 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 --check-prefix=CHECK-DUMP +// RUN: not %run %t 2>&1 | FileCheck %s --strict-whitespace --check-prefix=CHECK-DUMP // // REQUIRES: arm-target-arch @@ -10,10 +10,10 @@ int main() { raise(SIGSEGV); // CHECK-DUMP: Register values - // CHECK-DUMP-NEXT: r0 = {{0x[0-9a-f]+}} r1 = {{0x[0-9a-f]+}} r2 = {{0x[0-9a-f]+}} r3 = {{0x[0-9a-f]+}} - // CHECK-DUMP-NEXT: r4 = {{0x[0-9a-f]+}} r5 = {{0x[0-9a-f]+}} r6 = {{0x[0-9a-f]+}} r7 = {{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]+}} sp = {{0x[0-9a-f]+}} lr = {{0x[0-9a-f]+}} pc = {{0x[0-9a-f]+}} + // CHECK-DUMP-NEXT: r0 = {{0x[0-9a-f]+}} r1 = {{0x[0-9a-f]+}} r2 = {{0x[0-9a-f]+}} r3 = {{0x[0-9a-f]+}} + // CHECK-DUMP-NEXT: r4 = {{0x[0-9a-f]+}} r5 = {{0x[0-9a-f]+}} r6 = {{0x[0-9a-f]+}} r7 = {{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]+}} sp = {{0x[0-9a-f]+}} lr = {{0x[0-9a-f]+}} pc = {{0x[0-9a-f]+}} // CHECK-NODUMP-NOT: Register values return 0; } From 57c0b90b62059201cb792518c483772ff889e75e Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Wed, 24 Jul 2024 09:41:07 +0300 Subject: [PATCH 7/8] [compiler-rt] Adjust code style --- compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp index 95f7061b8bad8..128bf84b534ee 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp @@ -2296,8 +2296,8 @@ static void DumpSingleReg(ucontext_t *ctx, int RegNum) { Printf("%s%s = 0xzx ", internal_strlen(RegName) == 2 ? " " : "", RegName, GetArmRegister(ctx, RegNum)); # elif defined(__aarch64__) - Printf("%s%s = 0xzx ", internal_strlen(RegName) == 2 ? " " : "", - RegName, GetArmRegister(ctx, RegNum)); + Printf("%s%s = 0xzx ", internal_strlen(RegName) == 2 ? " " : "", RegName, + GetArmRegister(ctx, RegNum)); # else (void)RegName; # endif From 0cb1157f70cc9c4bb8c7c8fdff66d26ecef52937 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh Date: Wed, 24 Jul 2024 09:42:09 +0300 Subject: [PATCH 8/8] [compiler-rt] Add missing printf qualifiers --- compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp index 128bf84b534ee..bc2cb247f2a8a 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp @@ -2293,10 +2293,10 @@ static void DumpSingleReg(ucontext_t *ctx, int RegNum) { # elif defined(__i386__) Printf("%s = 0x%08x ", RegName, ctx->uc_mcontext.gregs[RegNum]); # elif defined(__arm__) - Printf("%s%s = 0xzx ", internal_strlen(RegName) == 2 ? " " : "", RegName, + Printf("%s%s = 0x%08zx ", internal_strlen(RegName) == 2 ? " " : "", RegName, GetArmRegister(ctx, RegNum)); # elif defined(__aarch64__) - Printf("%s%s = 0xzx ", internal_strlen(RegName) == 2 ? " " : "", RegName, + Printf("%s%s = 0x%016zx ", internal_strlen(RegName) == 2 ? " " : "", RegName, GetArmRegister(ctx, RegNum)); # else (void)RegName;