Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print backtrace upon panic #1395

Open
jounathaen opened this issue Sep 20, 2024 · 2 comments
Open

Print backtrace upon panic #1395

jounathaen opened this issue Sep 20, 2024 · 2 comments
Assignees

Comments

@jounathaen
Copy link
Member

This is not an easy one, but it would make debugging hermit way more easy, if we had a RUST_BACKTRACE=1 like backtrace in the panic message.
We would probably need to analyze the stack manually for this and somehow map back the function names from the debug info to the frame pointers.

Could help e.g., in cases like:

@jounathaen
Copy link
Member Author

This crate could be something: https://github.com/Amanieu/mini-backtrace
Unfortunately, it can't resolve the addresses by itself, but might be a first step.

@jounathaen
Copy link
Member Author

I tried to implement this, but it didn't work.

Steps to reproduce:

  1. Add -fPIE to libunwinds compile flags in the build script of mini-backtrace
  2. compile a kernel - Note that the llvm linker has a different syntax for the linker script:
    RUSTFLAGS="-Cforce-unwind-tables -Clink-arg=-T/absolute/path/to/mini-backtrace/eh_frame.ld"  cargo build -Zbuild-std=std,panic_abort --target x86_64-unknown-hermit
  3. Enjoy the General Protection Fault that occurs on let bt = Backtrace::<16>::capture();:
    [0][ERROR] General Protection (#GP) Exception: InterruptStackFrame {
       instruction_pointer: VirtAddr(
           0x8d5551,
       ),
       code_segment: SegmentSelector {
           index: 1,
           rpl: Ring0,
       },
       cpu_flags: RFlags(
           RESUME_FLAG | INTERRUPT_FLAG | AUXILIARY_CARRY_FLAG | PARITY_FLAG | 0x2,
       ),
       stack_pointer: VirtAddr(
           0x3fe588,
       ),
       stack_segment: SegmentSelector {
           index: 2,
           rpl: Ring0,
       },
    }, error 0x0
    
    

@mkroening mkroening self-assigned this Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants