crates.io page docs.rs page

macho-unwind-info

A zero-copy parser for the contents of the __unwind_info section of a mach-O binary.

Quickly look up the unwinding opcode for an address.

This crate is intended to be fast enough to be used in a sampling profiler. Re-parsing from scratch is cheap and can be done on every sample.

Example

```rust use machounwindinfo::{UnwindInfo, OpcodeX86_64};

let unwindinfo = UnwindInfo::parse(data)?; if let Some(function) = unwindinfo.lookup(0x1234)? { match OpcodeX8664::parse(function.opcode) { OpcodeX8664::Null => println!("Null"), OpcodeX8664::FrameBased { .. } => println!("FrameBased"), OpcodeX8664::FramelessImmediate { .. } => println!("FramelessImmediate"), OpcodeX8664::FramelessIndirect => println!("FramelessIndirect"), OpcodeX8664::Dwarf { .. } => println!("Dwarf"), } } ```

Command-line usage

This repository also contains two CLI executables. You can install them like so:

% cargo install --examples macho-unwind-info

Credits

Thanks a ton to @Gankra for documenting this format at https://gankra.github.io/blah/compact-unwinding/.

License

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.