ktrace: don't unwind past ISR entry points
parent
7f92690f84
commit
36d53093d4
@ -1,18 +1,29 @@
|
||||
/* Copyright (C) 2021 fef <owo@fef.moe>. All rights reserved. */
|
||||
|
||||
#include <arch/vmparam.h>
|
||||
|
||||
#include <gay/kprintf.h>
|
||||
#include <gay/ktrace.h>
|
||||
#include <gay/linker.h>
|
||||
|
||||
void ktrace_print(void)
|
||||
__naked void ktrace_print(void)
|
||||
{
|
||||
void **rbp;
|
||||
__asm__ volatile("movq (%%rbp), %0" : "=r"(rbp));
|
||||
__asm__ volatile(
|
||||
" movq %rbp, %rdi \n"
|
||||
" jmp ktrace_print_from \n"
|
||||
);
|
||||
}
|
||||
|
||||
void ktrace_print_from(void *frame)
|
||||
{
|
||||
void **rbp = (void **)frame;
|
||||
kprintf("Stack trace:\n");
|
||||
while (rbp >= (void **)KERNBASE) {
|
||||
|
||||
/* XXX Rather than spitting out raw addresses, parse the kernel image's
|
||||
* ELF sections to figure out what the address actually belongs to */
|
||||
while (rbp >= (void **)image_start && rbp < (void **)image_end) {
|
||||
/* caller return address is immediately above the stack frame */
|
||||
kprintf(" %p\n", rbp[1]);
|
||||
if (rbp[1] >= isr_start && rbp[1] < isr_end)
|
||||
break;
|
||||
rbp = *rbp;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
/* Copyright (C) 2021 fef <owo@fef.moe>. All rights reserved. */
|
||||
|
||||
#include <gay/kprintf.h>
|
||||
#include <gay/ktrace.h>
|
||||
#include <gay/linker.h>
|
||||
|
||||
__naked void ktrace_print(void)
|
||||
{
|
||||
__asm__ volatile(
|
||||
" pushl %ebp \n"
|
||||
" call ktrace_print_from \n"
|
||||
" ret \n"
|
||||
);
|
||||
}
|
||||
|
||||
void ktrace_print_from(void *frame)
|
||||
{
|
||||
void **ebp = (void **)frame;
|
||||
kprintf("Stack trace:\n");
|
||||
|
||||
/* XXX Rather than spitting out raw addresses, parse the kernel image's
|
||||
* ELF sections to figure out what the address actually belongs to */
|
||||
while (ebp >= (void **)image_start && ebp < (void **)image_end) {
|
||||
/* caller return address is immediately above the stack frame */
|
||||
kprintf(" %p\n", ebp[1]);
|
||||
if (rbp[1] >= isr_start && rbp[1] < isr_end)
|
||||
break;
|
||||
rbp = *rbp;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue