mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
Improve stack tracing
This commit is contained in:
@@ -20,6 +20,9 @@ _start:
|
|||||||
|
|
||||||
mov rsp, stack_end
|
mov rsp, stack_end
|
||||||
push 0 ; signal end of stack with 0 return address
|
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
|
mov rbp, rsp
|
||||||
extern kernel_main
|
extern kernel_main
|
||||||
|
|||||||
@@ -206,10 +206,22 @@ struct registers
|
|||||||
uint64_t rip, cs, eflags, user_esp, ss;
|
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);
|
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
|
void
|
||||||
isr_handler(registers regs)
|
isr_handler(registers regs)
|
||||||
{
|
{
|
||||||
@@ -243,17 +255,38 @@ isr_handler(registers regs)
|
|||||||
*/
|
*/
|
||||||
break;
|
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:
|
default:
|
||||||
cons->set_color(9);
|
cons->set_color(9);
|
||||||
cons->puts("\nReceived ISR interrupt:\n");
|
cons->puts("\nReceived ISR interrupt:\n");
|
||||||
cons->set_color();
|
cons->set_color();
|
||||||
|
|
||||||
uint64_t cr2 = 0;
|
cons->printf(" ISR: %02lx\n", regs.interrupt);
|
||||||
__asm__ __volatile__ ("mov %%cr2, %0" : "=r"(cr2));
|
cons->printf(" ERR: %lx\n", regs.errorcode);
|
||||||
|
|
||||||
print_reg("ISR", regs.interrupt);
|
|
||||||
print_reg("ERR", regs.errorcode);
|
|
||||||
print_reg("CR2", cr2);
|
|
||||||
cons->puts("\n");
|
cons->puts("\n");
|
||||||
|
|
||||||
print_reg(" ds", regs.ds);
|
print_reg(" ds", regs.ds);
|
||||||
@@ -274,13 +307,7 @@ isr_handler(registers regs)
|
|||||||
print_reg(" ss", regs.ss);
|
print_reg(" ss", regs.ss);
|
||||||
|
|
||||||
cons->puts("\n");
|
cons->puts("\n");
|
||||||
|
print_stacktrace(2);
|
||||||
int frame = 0;
|
|
||||||
uint64_t bp = get_frame(0);
|
|
||||||
while (bp) {
|
|
||||||
cons->printf(" frame %2d: %lx\n", frame, bp);
|
|
||||||
bp = get_frame(++frame);
|
|
||||||
}
|
|
||||||
while(1) asm("hlt");
|
while(1) asm("hlt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ def build(bld):
|
|||||||
return node.path_from(node.ctx.launch_node())
|
return node.path_from(node.ctx.launch_node())
|
||||||
def run(self):
|
def run(self):
|
||||||
from subprocess import check_output
|
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:
|
with file(self.outputs[0].abspath(), 'w') as output:
|
||||||
output.write(check_output(args))
|
output.write(check_output(args))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user