Rust Debugging Skill
This skill provides commands and workflows for inspecting binaries and debugging the OS components on Linux.
Prerequisites
- •LLVM Tools: Ensure
llvm-tools-previewis installed:bashrustup component add llvm-tools-preview
- •Rust Object Tools: Recommended usage via
rust-objdump,rust-nm, or standardllvm-*tools found in your Rust toolchain. - •GDB: Ensure
gdborrust-gdbis installed (sudo apt install gdb).
1. User Space Debugging (Static Musl Binaries)
For user space programs compiled with x86_64-unknown-linux-musl and crt-static.
List Symbols (nm)
To see all symbols in a binary (with Rust demangling):
rust-nm <BINARY> # Or using standard nm (demangle with rustfilt if installed) nm <BINARY> | rustfilt
Disassemble (objdump)
To view the assembly instructions. rust-objdump automatically demangles names:
rust-objdump -d <BINARY>
Look for _start or main to verify the entry point.
Check ELF Headers (readobj)
To verify if it's a valid statically linked ELF:
rust-readobj -h <BINARY>
2. Kernel & Bootloader Debugging
Inspect Initial RAM Disk / UEFI Payload
Use llvm-objdump to check the kernel binary structure before it gets packed.
rust-objdump -h target/x86_64-unknown-none/release/kernel
QEMU + GDB Debugging
To debug the running kernel with GDB:
- •
Launch QEMU with GDB Stub: Add
-s -Sto your QEMU command.- •
-s: Shorthand for-gdb tcp::1234 - •
-S: Freeze CPU at startup (wait for debugger)
- •
- •
Attach GDB: Open a new terminal and run:
bashrust-gdb target/x86_64-unknown-none/debug/kernel
(Ensure you point to the compiled kernel binary to load symbols)
- •
Connect to QEMU: Inside GDB:
gdbtarget remote :1234 break _start continue
QEMU Monitor
When QEMU is running:
- •Press
Ctrl+Alt+2to switch to the QEMU Monitor. - •Type
info registersto see CPU state. - •Type
info memto see memory mappings (if supported). - •Press
Ctrl+Alt+1to return to the display.
3. Common Cargo Commands
- •Check Code:
cargo check - •Clippy:
cargo clippy - •Macro Expansion:
cargo expand(requirescargo-expandcrate)