diff --git a/.cargo/config.toml b/.cargo/config.toml index daa85e1..b9d643f 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -17,8 +17,8 @@ runner = "scripts/run_debug.sh" [target.'cfg(all(target_arch = "x86_64", target_os = "none", not(debug_assertions)))'] runner = "scripts/run_release.sh" -# [registry] -# default = "gitea" +[target.x86_64-kernel] +rustflags = ["-C", "force-unwind-tables"] [registries.gitea] index = "sparse+https://git.zxq5.dev/api/packages/OsDev/cargo/" # Sparse index diff --git a/kernel/src/std/elf/mod.rs b/kernel/src/std/elf/mod.rs index 021f0c7..92956b5 100644 --- a/kernel/src/std/elf/mod.rs +++ b/kernel/src/std/elf/mod.rs @@ -18,6 +18,7 @@ use elf::{ parse::{ParseAt, ParsingTable}, section::{SectionHeader, SectionHeaderTable}, string_table::StringTable, + symbol::SymbolTable, }; use limine::request::KernelFileRequest; @@ -83,6 +84,17 @@ impl ElfReader { Ok(Self { elf }) } + #[warn(clippy::unwrap_used)] + pub fn get_symbol_table( + &self, + ) -> Result< + Option<(SymbolTable<'static, LittleEndian>, StringTable<'static>)>, + ElfError, + > { + // TODO: Remove .unwrap(). + Ok(self.elf.symbol_table().unwrap()) + } + /// Gets the section size of `section_name` in bytes. pub fn get_section_size( &self, diff --git a/kernel/src/std/unwind/panic.rs b/kernel/src/std/unwind/panic.rs index 7dca632..203c41a 100644 --- a/kernel/src/std/unwind/panic.rs +++ b/kernel/src/std/unwind/panic.rs @@ -45,7 +45,19 @@ pub fn panic_handler(info: &PanicInfo<'_>) -> ! { eprintln!("{:?}", err); hcf() }) { - eprintln!("Frame: {:x?}", call_frame); + serial_println!("Got frame: {:x?}", call_frame); + let Some((symtab, strtab)) = + ELF.get_symbol_table().unwrap_or_else(|e| { + serial_println!("{:?}", e); + hcf() + }) + else { + // TODO: Omit symbol names but just print addresses. + serial_println!("Didn't find symtab and strtab!"); + hcf() + }; + + // let sym_name = symtab.get(call_frame.pc as usize).unwrap(); } crate::hcf() diff --git a/kernel/src/std/unwind/unwinder.rs b/kernel/src/std/unwind/unwinder.rs index 5f1eb51..4811b1f 100644 --- a/kernel/src/std/unwind/unwinder.rs +++ b/kernel/src/std/unwind/unwinder.rs @@ -50,7 +50,7 @@ impl FallibleIterator for Unwinder { if self.is_first { self.is_first = false; - return Ok(Some(CallFrame { pc })); + return Ok(Some(CallFrame { pc, symbol: 0 })); } // This is a row in the virtual unwind table AKA the CFI which will help @@ -121,7 +121,7 @@ impl FallibleIterator for Unwinder { // the caller function). self.regs.set_stack_ptr(self.cfa); - Ok(Some(CallFrame { pc })) + Ok(Some(CallFrame { pc, symbol: 0 })) } // fn next(&mut self) -> Option, UnwinderError>> {} } @@ -209,6 +209,8 @@ impl RegisterSet { pub struct CallFrame { /// The current instruction pointer. pub pc: u64, + /// The symbol of the function. + pub symbol: usize, } #[derive(Debug)]