#vex #v5 #unwind #no-alloc #stack-frame #libunwind

sys no-std vex-libunwind-sys

FFI bindings to LLVM libunwind for VEX V5 robots

1 unstable release

0.1.0 Sep 19, 2024

#216 in Robotics

Download history 103/week @ 2024-09-16 12/week @ 2024-09-23 40/week @ 2024-09-30 27/week @ 2024-10-07 36/week @ 2024-10-14 56/week @ 2024-10-21 12/week @ 2024-10-28 15/week @ 2024-11-04 34/week @ 2024-11-11 23/week @ 2024-11-18 43/week @ 2024-11-25 62/week @ 2024-12-02 113/week @ 2024-12-09

247 downloads per month
Used in 4 crates (via vex-libunwind)

MIT license

61KB
199 lines

Contains (static library, 48KB) link/libunwind.a

vex-libunwind

Idiomatic Rust bindings for LLVM libunwind on VEX V5 robots

Install

cargo add vex-libunwind

Usage

To unwind from the current execution point, also known as "local" unwinding, capture the current CPU state with UnwindContext and then step through each stack frame with an UnwindCursor.

let context = UnwindContext::new().unwrap();
let mut cursor = UnwindCursor::new(&context);

loop {
    // Print instruction pointer (i.e. "program counter")
    println!("{:?}", cursor.register(registers::UNW_REG_IP));

    if !cursor.step().unwrap() {
        // End of stack reached
        break;
    }
}

Prerequisites

Libunwind will not find stack frames unless you add unwind tables to your program and show it where to find them.

Add unwind tables by updating your target file or using the -Cforce-unwind-tables=on rust flag:

{
    ...,
    "default-uwtable": true
}

Then update your target file to include the unwind tables and the symbols libunwind uses to find them:

SECTIONS {
    /* ... */

    .eh_frame : {
        __eh_frame_start = .;
       *(.eh_frame)
        __eh_frame_end = .;
    } > RAM

    .eh_framehdr : {
       __eh_frame_hdr_start = .;
       *(.eh_framehdr)
       __eh_frame_hdr_end = .;
    } > RAM

    .ARM.exidx : {
        __exidx_start = .;
        *(.ARM.exidx*)
        *(.gnu.linkonce.armexidix.*.*)
        __exidx_end = .;
    } > RAM

    /* ... */
}

Further Reading

Documentation for LLVM-flavored libunwind: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst

Documentation for similar but distinct libunwind/libunwind project:


lib.rs:

Bindings to the low-level unw_* LLVM libunwind APIs which are an interface defined by the HP libunwind project.

No runtime deps