summaryrefslogtreecommitdiffstats
path: root/library/backtrace/crates/debuglink/src/main.rs
blob: 99265ae9a565fc901ce63c5917f7c09b616c7370 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Test that the debuginfo is being found by checking that the
// backtrace contains `main` and that the source filename uses
// the path given in the command line arguments.
//
// For dwz tests, this assumes that the path string will be moved into
// the dwz file.
fn main() {
    let crate_dir = std::env::args().skip(1).next().unwrap();
    let expect = std::path::Path::new(&crate_dir).join("src/main.rs");

    let bt = backtrace::Backtrace::new();
    println!("{:?}", bt);

    let mut found_main = false;

    for frame in bt.frames() {
        let symbols = frame.symbols();
        if symbols.is_empty() {
            continue;
        }

        if let Some(name) = symbols[0].name() {
            let name = format!("{:#}", name);
            if name == "debuglink::main" {
                found_main = true;
                let filename = symbols[0].filename().unwrap();
                assert_eq!(filename, expect);
                break;
            }
        }
    }

    assert!(found_main);
}