Improve stack tracing

This commit is contained in:
Justin C. Miller
2018-05-11 01:25:40 -07:00
parent 0a231f2e0e
commit 045bede481
3 changed files with 45 additions and 15 deletions

View File

@@ -20,6 +20,9 @@ _start:
mov rsp, stack_end
push 0 ; signal end of stack with 0 return address
push 0 ; and a few extra entries in case of stack
push 0 ; problems
push 0
mov rbp, rsp
extern kernel_main

View File

@@ -206,10 +206,22 @@ struct registers
uint64_t rip, cs, eflags, user_esp, ss;
};
#define print_reg(name, value) cons->printf(" %s: %lx\n", name, (value));
#define print_reg(name, value) cons->printf(" %s: %016lx\n", name, (value));
extern "C" uint64_t get_frame(int frame);
void
print_stacktrace(int skip = 0)
{
console *cons = console::get();
int frame = 0;
uint64_t bp = get_frame(skip);
while (bp) {
cons->printf(" frame %2d: %lx\n", frame, bp);
bp = get_frame(++frame + skip);
}
}
void
isr_handler(registers regs)
{
@@ -243,17 +255,38 @@ isr_handler(registers regs)
*/
break;
case isr::isrPageFault: {
cons->set_color(11);
cons->puts("\nPage Fault:\n");
cons->set_color();
cons->puts(" flags:");
if (regs.errorcode & 0x01) cons->puts(" present");
if (regs.errorcode & 0x02) cons->puts(" write");
if (regs.errorcode & 0x04) cons->puts(" user");
if (regs.errorcode & 0x08) cons->puts(" reserved");
if (regs.errorcode & 0x10) cons->puts(" ip");
cons->puts("\n");
uint64_t cr2 = 0;
__asm__ __volatile__ ("mov %%cr2, %0" : "=r"(cr2));
print_reg("cr2", cr2);
print_reg("rip", regs.rip);
cons->puts("\n");
print_stacktrace(2);
}
while(1) asm("hlt");
break;
default:
cons->set_color(9);
cons->puts("\nReceived ISR interrupt:\n");
cons->set_color();
uint64_t cr2 = 0;
__asm__ __volatile__ ("mov %%cr2, %0" : "=r"(cr2));
print_reg("ISR", regs.interrupt);
print_reg("ERR", regs.errorcode);
print_reg("CR2", cr2);
cons->printf(" ISR: %02lx\n", regs.interrupt);
cons->printf(" ERR: %lx\n", regs.errorcode);
cons->puts("\n");
print_reg(" ds", regs.ds);
@@ -274,13 +307,7 @@ isr_handler(registers regs)
print_reg(" ss", regs.ss);
cons->puts("\n");
int frame = 0;
uint64_t bp = get_frame(0);
while (bp) {
cons->printf(" frame %2d: %lx\n", frame, bp);
bp = get_frame(++frame);
}
print_stacktrace(2);
while(1) asm("hlt");
}

View File

@@ -29,7 +29,7 @@ def build(bld):
return node.path_from(node.ctx.launch_node())
def run(self):
from subprocess import check_output
args = self.env.objdump + ["-D", self.inputs[0].abspath()]
args = self.env.objdump + ["--source", "-D", self.inputs[0].abspath()]
with file(self.outputs[0].abspath(), 'w') as output:
output.write(check_output(args))