mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[kernel] Improve debugcon & panic display
Several minor changes related to debug output. - Colorize the debugcon logger like the userspace one. - Display the process and thread for each cpu in the panic display - Skip the panic() frame in panic back traces - Don't try to follow obviously bad (non-canonical) stack frame pointers
This commit is contained in:
@@ -13,9 +13,6 @@ install(uintptr_t entrypoint, util::const_buffer symbol_data)
|
||||
symbol_table = symbol_data.pointer;
|
||||
}
|
||||
|
||||
extern uint32_t *apic_icr;
|
||||
extern void const *symbol_table;
|
||||
|
||||
[[ noreturn ]]
|
||||
void panic(
|
||||
const char *message,
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
namespace debugcon {
|
||||
|
||||
namespace {
|
||||
static const uint8_t level_colors[] = {0x00, 0x09, 0x01, 0x0b, 0x0f, 0x07, 0x08};
|
||||
const char *level_names[] = {"", "fatal", "error", "warn", "info", "verbose", "spam"};
|
||||
const char *area_names[] = {
|
||||
#define LOG(name, lvl) #name ,
|
||||
@@ -19,9 +20,9 @@ namespace {
|
||||
asm ( "rep outsb;" :: "c"(size), "d"(port), "S"(msg) );
|
||||
}
|
||||
|
||||
inline void debug_newline() {
|
||||
static const char *newline = "\r\n";
|
||||
asm ( "rep outsb;" :: "c"(2), "d"(port), "S"(newline) );
|
||||
inline void debug_endline() {
|
||||
static const char *newline = "\e[38;5;0m\r\n";
|
||||
asm ( "rep outsb;" :: "c"(11), "d"(port), "S"(newline) );
|
||||
}
|
||||
} // anon namespace
|
||||
|
||||
@@ -29,12 +30,16 @@ void
|
||||
output(j6_log_entry *entry)
|
||||
{
|
||||
char buffer [256];
|
||||
size_t dlen = util::format({buffer, sizeof(buffer)}, "%7s %7s| ",
|
||||
area_names[entry->area], level_names[entry->severity]);
|
||||
size_t dlen = util::format({buffer, sizeof(buffer)}, "\e[38;5;%dm%7s %7s\e[38;5;14m|\e[38;5;%dm ",
|
||||
level_colors[entry->severity],
|
||||
area_names[entry->area],
|
||||
level_names[entry->severity],
|
||||
level_colors[entry->severity]);
|
||||
|
||||
debug_out(buffer, dlen);
|
||||
|
||||
debug_out(entry->message, entry->bytes - sizeof(j6_log_entry));
|
||||
debug_newline();
|
||||
debug_endline();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "cpu.h"
|
||||
#include "display.h"
|
||||
#include "objects/process.h"
|
||||
#include "objects/thread.h"
|
||||
#include "serial.h"
|
||||
#include "symbol_table.h"
|
||||
|
||||
@@ -36,11 +38,25 @@ print_header(
|
||||
void
|
||||
print_cpu(serial_port &out, cpu_data &cpu)
|
||||
{
|
||||
uint32_t process = cpu.process ? cpu.process->obj_id() : 0;
|
||||
uint32_t thread = cpu.thread ? cpu.thread->obj_id() : 0;
|
||||
|
||||
out.write("\n \e[0;31m==[ CPU: ");
|
||||
char cpuid[7];
|
||||
util::format({cpuid, sizeof(cpuid)}, "%4d", cpu.id + 1); // gdb uses 1-based CPU indices
|
||||
out.write(cpuid);
|
||||
out.write(" ]====================================================================\n");
|
||||
|
||||
char buffer[64];
|
||||
util::format({buffer, sizeof(buffer)}, "%4d <%02lx:%02lx>",
|
||||
cpu.id + 1, process, thread);
|
||||
out.write(buffer);
|
||||
|
||||
out.write(" ]=============================================================\n");
|
||||
}
|
||||
|
||||
template <typename T> inline bool
|
||||
canonical(T p)
|
||||
{
|
||||
static constexpr uintptr_t mask = 0xffff800000000000;
|
||||
uintptr_t addr = reinterpret_cast<uintptr_t>(p);
|
||||
return (addr & mask) == mask || (addr & mask) == 0;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -49,10 +65,10 @@ print_callstack(serial_port &out, symbol_table &syms, frame const *fp)
|
||||
char message[512];
|
||||
unsigned count = 0;
|
||||
|
||||
while (fp && fp->return_addr) {
|
||||
while (canonical(fp) && fp && fp->return_addr) {
|
||||
char const *name = syms.find_symbol(fp->return_addr);
|
||||
if (!name)
|
||||
name = "<unknown>";
|
||||
name = canonical(fp->return_addr) ? "<unknown>" : "<corrupt>";
|
||||
|
||||
util::format({message, sizeof(message)},
|
||||
" \e[0;33mframe %2d: <0x%016lx> \e[1;33m%s\n",
|
||||
|
||||
@@ -19,7 +19,7 @@ panicking::serial_port &com1 = __com1_storage.value;
|
||||
util::no_construct<panicking::symbol_table> __syms_storage;
|
||||
panicking::symbol_table &syms = __syms_storage.value;
|
||||
|
||||
constexpr int order = __ATOMIC_ACQ_REL;
|
||||
static constexpr int order = __ATOMIC_ACQ_REL;
|
||||
|
||||
extern "C"
|
||||
void panic_handler(const cpu_state *regs)
|
||||
@@ -41,7 +41,7 @@ void panic_handler(const cpu_state *regs)
|
||||
asm ("pause");
|
||||
|
||||
panicking::frame const *fp = nullptr;
|
||||
asm ( "mov %%rbp, %0" : "=r" (fp) );
|
||||
asm ( "movq (%%rbp), %0" : "=r" (fp) );
|
||||
|
||||
if (panic)
|
||||
print_header(com1, panic->message, panic->function,
|
||||
|
||||
Reference in New Issue
Block a user