Add convenience functions to print the stack trace directly
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0d437cfcca
commit
c8302a4fef
@ -22,5 +22,7 @@ namespace CPU
|
||||
void wait_for_interrupt();
|
||||
|
||||
void get_stack_trace(void (*callback)(u64, void*), void* arg);
|
||||
void print_stack_trace();
|
||||
void get_stack_trace_at(Registers* regs, void (*callback)(u64, void*), void* arg);
|
||||
void print_stack_trace_at(Registers* regs);
|
||||
}
|
@ -303,15 +303,7 @@ static void setup_idt()
|
||||
asm volatile("mov %%cr2, %0" : "=r"(cr2));
|
||||
kerrorln("Page fault at RIP %lx while accessing %lx!", regs->rip, cr2);
|
||||
|
||||
int frame_index = 0;
|
||||
CPU::get_stack_trace_at(
|
||||
regs,
|
||||
[](u64 instruction, void* arg) {
|
||||
int* ptr = (int*)arg;
|
||||
kinfoln("#%d at %p", *ptr, (void*)instruction);
|
||||
(*ptr)++;
|
||||
},
|
||||
&frame_index);
|
||||
CPU::print_stack_trace_at(regs);
|
||||
|
||||
CPU::efficient_halt();
|
||||
}
|
||||
@ -476,6 +468,20 @@ namespace CPU
|
||||
}
|
||||
}
|
||||
|
||||
void print_stack_trace()
|
||||
{
|
||||
u64 rbp;
|
||||
int frame_index = 0;
|
||||
asm volatile("mov %%rbp, %0" : "=r"(rbp));
|
||||
StackFrame* current_frame = (StackFrame*)rbp;
|
||||
// FIXME: Validate that the frame itself is readable, might span across multiple pages
|
||||
while (current_frame && MemoryManager::validate_readable_page((u64)current_frame))
|
||||
{
|
||||
kinfoln("#%d at %p", frame_index++, (void*)current_frame->instruction);
|
||||
current_frame = current_frame->next;
|
||||
}
|
||||
}
|
||||
|
||||
void get_stack_trace_at(Registers* regs, void (*callback)(u64, void*), void* arg)
|
||||
{
|
||||
callback(regs->rip, arg);
|
||||
@ -487,6 +493,19 @@ namespace CPU
|
||||
current_frame = current_frame->next;
|
||||
}
|
||||
}
|
||||
|
||||
void print_stack_trace_at(Registers* regs)
|
||||
{
|
||||
int frame_index = 0;
|
||||
get_stack_trace_at(
|
||||
regs,
|
||||
[](u64 instruction, void* arg) {
|
||||
int* ptr = (int*)arg;
|
||||
kinfoln("#%d at %p", *ptr, (void*)instruction);
|
||||
(*ptr)++;
|
||||
},
|
||||
&frame_index);
|
||||
}
|
||||
}
|
||||
|
||||
// called by kernel_yield
|
||||
|
Loading…
Reference in New Issue
Block a user