diff options
-rw-r--r-- | src/kernel/mem/alloc.c | 10 | ||||
-rw-r--r-- | tools/stacktrace_resolve.awk | 11 |
2 files changed, 16 insertions, 5 deletions
diff --git a/src/kernel/mem/alloc.c b/src/kernel/mem/alloc.c index 9067fb8..d099a31 100644 --- a/src/kernel/mem/alloc.c +++ b/src/kernel/mem/alloc.c @@ -12,6 +12,7 @@ struct malloc_hdr { uint32_t magic; uint32_t page_amt; struct malloc_hdr *next, *prev; + void *stacktrace[4]; }; struct malloc_hdr *malloc_last = NULL; @@ -49,7 +50,10 @@ void mem_debugprint(void) { kprintf("current kmallocs:\n"); kprintf("addr pages\n"); for (struct malloc_hdr *iter = malloc_last; iter; iter = iter->prev) { - kprintf("%08x %05x\n", iter, iter->page_amt); + kprintf("%08x %05x", iter, iter->page_amt); + for (size_t i = 0; i < 4; i++) + kprintf(" k/%08x", iter->stacktrace[i]); + kprintf("\n"); total++; } kprintf(" total 0x%x\n", total); @@ -124,6 +128,10 @@ void *kmalloc(size_t len) { assert(!addr->prev->next); addr->prev->next = addr; } + + for (size_t i = 0; i < 4; i++) + addr->stacktrace[i] = debug_caller(i); + malloc_last = addr; kmalloc_sanity(addr); diff --git a/tools/stacktrace_resolve.awk b/tools/stacktrace_resolve.awk index a8254a7..1b4742d 100644 --- a/tools/stacktrace_resolve.awk +++ b/tools/stacktrace_resolve.awk @@ -1,9 +1,12 @@ /k\/[0-9A-Fa-f]{8}/ { print; - addr = substr($0, match($0, /k\/[0-9A-Fa-f]{8}/) + 2, RLENGTH - 2); - if (addr != "00000000") { - printf " "; - system("addr2line -psfe out/fs/boot/kernel.bin 0x" addr); + while (match($0, /k\/[0-9A-Fa-f]{8}/)) { + addr = substr($0, RSTART + 2, RLENGTH - 2); + if (addr != "00000000") { + printf " "; + system("addr2line -psfe out/fs/boot/kernel.bin 0x" addr); + } + $0 = substr($0, RSTART + RLENGTH); } next; } |