Add tips on debugging/disassembling kernel sources

This commit is contained in:
2025-02-27 23:32:05 +00:00
parent 9852cb14eb
commit 2915d0c879
2 changed files with 20 additions and 0 deletions
+4
View File
@@ -45,4 +45,8 @@ Alternatively, you may disable using a UEFI firmware with qemu like so:
USE_LEGACY_BIOS=1 cargo run USE_LEGACY_BIOS=1 cargo run
``` ```
## Debugging
See [debugging](docs/Debugging/DEBUGGING.md) for some help with this, including commands to help with disassembly.
If you have any other issues, feel free to create an issue or a PR. If you have any other issues, feel free to create an issue or a PR.
+16
View File
@@ -0,0 +1,16 @@
# Debugging the Kernel
Here we will add some helpful tips on debugging the kernel.
## Disassembling a public function
To disassemble a public function, first we need a symbol in the public symbol table, so start by making the function fully public (including any parent modules). Do this as though you are trying to make a public function for a library crate (this includes the `kernel` crate). Simply mark the function and any parent modules as public, up until the point of [lib.rs (kernel link)](../../kernel/src/lib.rs).
Then, we need to find the specific demangled symbol to disassemble, because the default objdump output can be very verbose.
```sh
# Change as required, I pipe to less and /SEARCH FOR FUNCTION HERE.
nm --demangle ./build/target/x86_64-kernel/debug/kernel | less
# Now just paste the symbol where it says YOUR_SYMBOL_HERE and profit. Use -Mintel for Intel assembly syntax.
objdump -Matt --source --line-numbers --visualize-jumps ./build/target/x86_64-kernel/debug/kernel --demangle=rust --disassemble="YOUR_SYMBOL_HERE"
```