Skip to content

Commit 8d2f079

Browse files
committed
implement dump registers for freebsd amd64/fix build
1 parent 2f8b64d commit 8d2f079

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,7 +2121,8 @@ bool SignalContext::IsTrueFaultingAddress() const {
21212121
UNUSED
21222122
static const char *RegNumToRegName(int reg) {
21232123
switch (reg) {
2124-
# if defined(__x86_64__)
2124+
# if SANITIZER_LINUX
2125+
# if defined(__x86_64__)
21252126
case REG_RAX:
21262127
return "rax";
21272128
case REG_RBX:
@@ -2154,7 +2155,7 @@ static const char *RegNumToRegName(int reg) {
21542155
return "r14";
21552156
case REG_R15:
21562157
return "r15";
2157-
# elif defined(__i386__)
2158+
# elif defined(__i386__)
21582159
case REG_EAX:
21592160
return "eax";
21602161
case REG_EBX:
@@ -2171,13 +2172,15 @@ static const char *RegNumToRegName(int reg) {
21712172
return "ebp";
21722173
case REG_ESP:
21732174
return "esp";
2175+
# endif
21742176
# endif
21752177
default:
21762178
return NULL;
21772179
}
21782180
return NULL;
21792181
}
21802182

2183+
#if SANITIZER_LINUX
21812184
UNUSED
21822185
static void DumpSingleReg(ucontext_t *ctx, int RegNum) {
21832186
const char *RegName = RegNumToRegName(RegNum);
@@ -2190,10 +2193,11 @@ static void DumpSingleReg(ucontext_t *ctx, int RegNum) {
21902193
(void)RegName;
21912194
# endif
21922195
}
2196+
#endif
21932197

21942198
void SignalContext::DumpAllRegisters(void *context) {
2195-
# if SANITIZER_LINUX
21962199
ucontext_t *ucontext = (ucontext_t *)context;
2200+
# if SANITIZER_LINUX
21972201
# if defined(__x86_64__)
21982202
Report("Register values:\n");
21992203
DumpSingleReg(ucontext, REG_RAX);
@@ -2232,8 +2236,35 @@ void SignalContext::DumpAllRegisters(void *context) {
22322236
DumpSingleReg(ucontext, REG_EBP);
22332237
DumpSingleReg(ucontext, REG_ESP);
22342238
Printf("\n");
2239+
# else
2240+
(void)ucontext;
22352241
# endif
2242+
# elif SANITIZER_FREEBSD
2243+
# if defined(__x86_64__)
2244+
Report("Register values:\n");
2245+
Printf("RAX = 0x%016llx ", ucontext->uc_mcontext.mc_rax);
2246+
Printf("RBX = 0x%016llx ", ucontext->uc_mcontext.mc_rbx);
2247+
Printf("RCX = 0x%016llx ", ucontext->uc_mcontext.mc_rcx);
2248+
Printf("RDX = 0x%016llx ", ucontext->uc_mcontext.mc_rdx);
2249+
Printf("\n");
2250+
Printf("RDI = 0x%016llx ", ucontext->uc_mcontext.mc_rdi);
2251+
Printf("RSI = 0x%016llx ", ucontext->uc_mcontext.mc_rsi);
2252+
Printf("RBP = 0x%016llx ", ucontext->uc_mcontext.mc_rbp);
2253+
Printf("RSP = 0x%016llx ", ucontext->uc_mcontext.mc_rsp);
2254+
Printf("\n");
2255+
Printf(" R8 = 0x%016llx ", ucontext->uc_mcontext.mc_r8);
2256+
Printf(" R9 = 0x%016llx ", ucontext->uc_mcontext.mc_r9);
2257+
Printf("R10 = 0x%016llx ", ucontext->uc_mcontext.mc_r10);
2258+
Printf("R11 = 0x%016llx ", ucontext->uc_mcontext.mc_r11);
2259+
Printf("\n");
2260+
Printf("R12 = 0x%016llx ", ucontext->uc_mcontext.mc_r12);
2261+
Printf("R13 = 0x%016llx ", ucontext->uc_mcontext.mc_r13);
2262+
Printf("R14 = 0x%016llx ", ucontext->uc_mcontext.mc_r14);
2263+
Printf("R15 = 0x%016llx ", ucontext->uc_mcontext.mc_r15);
2264+
Printf("\n");
2265+
# else
22362266
(void)ucontext;
2267+
# endif
22372268
# endif
22382269
// FIXME: Implement this for other OSes and architectures.
22392270
}

0 commit comments

Comments
 (0)