rust-lang / rust-lang/backtrace-rs

Need to be able to reliably get symbol addrs

Open
#520 16 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
628
Forks
291
PR merge metrics
No merged PRs in 30d

Description

The documentation for Frame::symbol_address warns:

This will attempt to rewind the instruction pointer returned by ip to the start of the function, returning that value. In some cases, however, backends will just return ip from this function.

Consequently, the following code 'works' on x86_64-unknown-linux-gnu, but not on aarch64-apple-darwin:

use backtrace;
use std::{hint::black_box, ptr, ffi::c_void};

fn main() {
    black_box(function());
}

#[inline(never)]
fn function() {
    let function = function as *const c_void;
    println!("searching for symbol_address={:?}", function);

    backtrace::trace(|frame| {
        println!("unwound to {:?}", frame);
        if ptr::eq(frame.symbol_address(), function) {
            println!("found it!"); // not reached on aarch64-apple-darwin :(
            return false;
        }
        true
    });
}

Is this expected behavior on this platform? If so, is there any way to work around this discrepancy?

In the scoped-trace crate, I use symbol address equality to capture backtraces with limited upper and lower unwinding bounds. I'm hoping to get this crate working on aarch64-apple-darwin.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the Frame::symbol_address documentation and the backtrace::trace example in this issue, comparing behavior on x86_64-unknown-linux-gnu and aarch64-apple-darwin. Investigate whether the platform-specific result is expected and whether a reliable workaround can support scoped-trace's symbol-address bounds.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.