Save failed stack trace code for future reference.

This commit is contained in:
2025-03-08 18:39:27 +00:00
parent 4b8388c66d
commit da6690fd8b
14 changed files with 335 additions and 122 deletions
+73 -10
View File
@@ -3,9 +3,18 @@
extern crate alloc;
use foundry_os::arch::x86_64::processing::async_io::task::{Executor, Task};
use foundry_os::prelude::*;
use foundry_os::util::shell::shell;
use core::arch::asm;
use foundry_os::{
// arch::x86_64::processing::async_io::task::{Executor, Task},
prelude::*,
// std::unwind::UNWINDER,
// util::shell::shell,
};
// use framehop::{
// x86_64::{CacheX86_64, UnwindRegsX86_64},
// *,
// };
#[unsafe(no_mangle)]
extern "C" fn kmain() -> ! {
@@ -24,15 +33,69 @@ extern "C" fn kmain() -> ! {
test1();
let mut executor = Executor::new();
executor.spawn(Task::new(shell()));
executor.run()
// let mut executor = Executor::new();
// executor.spawn(Task::new(shell()));
// executor.run()
loop {}
}
fn test1() {
test2()
#[inline(never)]
pub fn test1() {
test2();
}
fn test2() {
panic!("Test");
#[inline(never)]
pub fn test2() {
test3();
}
const fn read_stack(addr: u64) -> Result<u64, ()> {
Ok(unsafe { *(addr as *const u64) })
}
#[inline(never)]
pub fn test3() {
// let mut cache = CacheX86_64::new();
// let unwinder = &*UNWINDER;
// let mut rip: u64;
// let mut rsp: u64;
// let mut rbp: u64;
// let mut read_stack_fn = read_stack;
// unsafe {
// asm!("lea {0}, [rip]",
// "mov {1}, rsp",
// "mov {2}, rbp",
// out(reg) rip,
// out(reg) rsp,
// out(reg) rbp);
// }
// let regs = UnwindRegsX86_64::new(rip, rsp, rbp);
// let mut frame_iter =
// unwinder.iter_frames(rip, regs, &mut cache, &mut read_stack_fn);
// // This is just me testing the unwinding. It seems to not return any
// stack // frames for some odd reason.
// loop {
// match frame_iter.next() {
// Ok(Some(frame)) => {
// debugln!("Got function with {:x?}",
// frame.address_for_lookup()); // match frame {
// // FrameAddress::InstructionPointer(rip) => (),
// // FrameAddress::ReturnAddress(ra) => {}
// // }
// }
// Ok(None) => {
// debugln!("Hit end of stack.");
// break;
// }
// Err(why) => {
// debugln!("{}", why);
// break;
// }
// }
// }
}