From 2915d0c87947f90282640aef514c2639bb1dc323 Mon Sep 17 00:00:00 2001 From: Jacob Hinchliffe Date: Thu, 27 Feb 2025 23:32:05 +0000 Subject: [PATCH] Add tips on debugging/disassembling kernel sources --- README.md | 4 ++++ docs/Debugging/DEBUGGING.md | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 docs/Debugging/DEBUGGING.md diff --git a/README.md b/README.md index fe03e6b..0b89a8a 100644 --- a/README.md +++ b/README.md @@ -45,4 +45,8 @@ Alternatively, you may disable using a UEFI firmware with qemu like so: 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. \ No newline at end of file diff --git a/docs/Debugging/DEBUGGING.md b/docs/Debugging/DEBUGGING.md new file mode 100644 index 0000000..06cd260 --- /dev/null +++ b/docs/Debugging/DEBUGGING.md @@ -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" +```