mirror of
https://github.com/justinian/jsix.git
synced 2025-12-09 16:04:32 -08:00
[panic.serial] Display memory around the user rip
When displaying a set of user regs, also display memory around the current rip from those user regs. This helps find or rule out memory corruption errors causing invalid code to run.
This commit is contained in:
@@ -113,11 +113,34 @@ print_cpu_state(serial_port &out, const cpu_state ®s)
|
||||
out.write(clear);
|
||||
}
|
||||
|
||||
static void
|
||||
print_rip(serial_port &out, uintptr_t addr)
|
||||
{
|
||||
constexpr size_t per_line = 16;
|
||||
addr -= per_line;
|
||||
uint8_t *data = reinterpret_cast<uint8_t*>(addr);
|
||||
|
||||
char bit[100];
|
||||
|
||||
out.write("\n");
|
||||
for (unsigned i = 0; i < per_line*3; i += per_line) {
|
||||
snprintf(bit, sizeof(bit), "\e[0;33m%20lx: \e[0m", addr + i);
|
||||
out.write(bit);
|
||||
|
||||
for (unsigned j = 0; j < per_line; ++j) {
|
||||
snprintf(bit, sizeof(bit), "%02x ", data[i+j]);
|
||||
out.write(bit);
|
||||
}
|
||||
out.write("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
print_user_state(serial_port &out, const cpu_state ®s)
|
||||
{
|
||||
out.write("\n\e[1;35m USER:\e[0 ");
|
||||
print_cpu_state(out, regs);
|
||||
print_rip(out, regs.rip);
|
||||
}
|
||||
|
||||
} // namespace panicking
|
||||
|
||||
Reference in New Issue
Block a user