X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/b9f4a7b7475e62dbff22da6dd768222f03889c00..9eed27f6f2f002145667fb4abfc5e476b53630e5:/lunaix-os/kernel/debug/trace.c?ds=sidebyside diff --git a/lunaix-os/kernel/debug/trace.c b/lunaix-os/kernel/debug/trace.c index a3553f1..1cf9ae3 100644 --- a/lunaix-os/kernel/debug/trace.c +++ b/lunaix-os/kernel/debug/trace.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include #include @@ -23,13 +23,14 @@ trace_modksyms_init(struct boot_handoff* bhctx) for (size_t i = 0; i < bhctx->mods.mods_num; i++) { struct boot_modent* mod = &bhctx->mods.entries[i]; if (streq(mod->str, "modksyms")) { - // In case boot loader does not place our ksyms on page boundary - ptr_t start = PG_ALIGN(mod->start); + assert(PG_ALIGNED(mod->start)); + ptr_t end = ROUNDUP(mod->end, PG_SIZE); - ptr_t ksym_va = (ptr_t)ioremap(start, (end - start)); + ptr_t ksym_va = + (ptr_t)vmap(mod->start, (end - mod->start), PG_PREM_R, 0); - trace_ctx.ksym_table = - (struct ksyms*)(ksym_va + (mod->start - start)); + assert(ksym_va); + trace_ctx.ksym_table = (struct ksyms*)ksym_va; } } } @@ -90,8 +91,10 @@ trace_walkback(struct trace_record* tb_buffer, ptr_t pc = *(frame + 1); current = trace_sym_lookup(pc); - tb_buffer[i] = (struct trace_record){ .pc = current ? current->pc : pc, - .symbol = ksym_getstr(current) }; + tb_buffer[i] = + (struct trace_record){ .pc = pc, + .sym_pc = current ? current->pc : 0, + .symbol = ksym_getstr(current) }; frame = (ptr_t*)*frame; i++; @@ -104,19 +107,27 @@ trace_walkback(struct trace_record* tb_buffer, return i; } +static inline void +trace_print_code_entry(ptr_t sym_pc, ptr_t inst_pc, char* sym) +{ + DEBUG("%p+%p: %s", sym_pc, inst_pc - sym_pc, sym); +} + void trace_printstack_of(ptr_t fp) { struct trace_record tbs[NB_TRACEBACK]; + // Let's get our Stackwalker does his job ;) int n = trace_walkback(tbs, fp, NB_TRACEBACK, &fp); if (fp) { - kprintf(KDEBUG "...\n"); + DEBUG("..."); } for (int i = 0; i < n; i++) { - kprintf(KDEBUG "%p: %s\n", tbs[i].pc, tbs[i].symbol); + struct trace_record* tb = &tbs[i]; + trace_print_code_entry(tb->sym_pc, tb->pc, tb->symbol); } } @@ -126,15 +137,19 @@ trace_printstack() trace_printstack_of(cpu_get_fp()); } -void +static void trace_printswctx(const isr_param* p, char* direction) { struct ksym_entry* sym = trace_sym_lookup(p->execp->eip); - kprintf( - KDEBUG ">> (sw:%s) iv:%d, errno:%p <<\n", direction, p->execp->vector); - kprintf(KDEBUG "%p:%s\n", p->execp->eip, ksym_getstr(sym)); + DEBUG(">> (sw:%s) iv:%d, errno:%p <<", + direction, + p->execp->vector, + p->execp->err_code); + + ptr_t sym_pc = sym ? sym->pc : p->execp->eip; + trace_print_code_entry(sym_pc, p->execp->eip, ksym_getstr(sym)); } void @@ -142,10 +157,9 @@ trace_printstack_isr(const isr_param* isrm) { isr_param* p = isrm; ptr_t fp = cpu_get_fp(); - int prev_fromusr = uspace_context(p); + int prev_fromusr = 0; - kprintf(KDEBUG "\n"); - kprintf(KDEBUG "stack trace (pid=%d)\n", __current->pid); + DEBUG("stack trace (pid=%d)\n", __current->pid); trace_printstack_of(fp); @@ -167,5 +181,4 @@ trace_printstack_isr(const isr_param* isrm) p = p->execp->saved_prev_ctx; } - kprintf(KDEBUG "\n"); } \ No newline at end of file