How to print panic backtraces? #1394
-
Idk how panic backtraces work, but it seems like part of printing a nice looking backtrace is resolving symbols. I can do that because I have a user space program in an Also would this be possible in the kernel itself by parsing the elf of the kernel itself inside the kernel's code? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
To get a backtrace, you can either compile with frame pointers enabled (
Yes. Basically you did have to parse the entire kernel image as ELF file, look up it's symbol table and then for each address you got from the previous step to get a backtrace you have to find the symbol with the highest address lower than or equal to this address in the backtrace. The name of the symbol should then match the name of the function that corresponds to the stack frame. If your kernel can be relocated (PIC/PIE) then you will have to add the actual offset by which the kernel is relocated to the addresses you get from the symbol table. |
Beta Was this translation helpful? Give feedback.
-
Seems like This will give you something like If you want filenames and line numbers, you'll have to dive into DWARF parsing. You could look at the |
Beta Was this translation helpful? Give feedback.
Seems like
unwinding
is overkill after all. If you just want to print backtraces, look at https://github.com/tsatke/devos/blob/935889f66944201bb70986bb753b96cac99ad66d/kernel/src/main.rs#L79 . Basically jump base-pointers until that's0
and resolve the addresses to symbols (like @bjorn3 said). You'll need a mapping of your elf file in virtual memory, which limine conveniently provides.This will give you something like
If you want filenames and line numbers, you'll have to dive into DWARF parsing. You could look at the
addr2line
crate together withgimli
for that.