#producer #dwarf #compiler #dw-at-producer

bin+lib dwprod

在共享库或可执行文件中查找所有编译单元的 DW_AT_producer

1 个不稳定版本

使用旧的 Rust 2015

0.1.0 2017 年 9 月 28 日

#23#producer

Apache-2.0/MIT

18KB
191

dwprod

查找共享库或可执行文件中所有编译单元的 DW_AT_producer

Unix Build Status

什么是 DW_AT_producer

DW_AT_producer 是 DWARF 调试信息中的一个属性,它说明了用于创建给定共享库或可执行文件中每个编译单元的编译器。

用法

作为库

首先,将以下内容添加到您的 Cargo.toml

[dependencies.dwprod]
version = "0.1.0"
# Do not build the command line `dwprod` executable.
default-features = false

然后,导入 dwprod crate 并使用它遍历 DW_AT_producer

extern crate dwprod;

fn try_main() -> dwprod::Result<()> {
    let opts = dwprod::Options::new("path/to/some/executable");

    opts.producers(|producers| {
        while let Some(producer) = producers.next()? {
            println!("Found DW_AT_producer = {}", producer);
        }

        Ok(())
    })?
}

fn main() {
    if let Err(e) = try_main() {
        eprintln!("Uh oh! {}", e);
        ::std::process::exit(1);
    }
}

也可以使用 fallible-iterator crate 来利用迭代器组合器,如 mapfilter

extern crate dwprod;
extern crate fallible_iterator;

use fallible_iterator::FallibleIterator;
use std::path::Path;

fn each_rustc_producer<F>(
    shared_lib_or_exe: &Path,
    mut callback: F
) -> dwprod::Result<()>
where
    F: FnMut(String)
{
    let opts = dwprod::Options::new(shared_lib_or_exe);
    opts.producers(|producers| {
        producers
            // Filter down to only the producers with "rustc" in their name.
            .filter(|p| p.contains("rustc"))
            // Then map the given callback over each producer.
            .map(&mut callback)
            // Finally, use `count` to force iteration.
            .count()?;

        Ok(())
    })?
}
作为命令行工具

首先,通过 cargo 进行安装

$ cargo install dwprod

然后,运行 dwprod 路径//共享///可执行文件 以获取给定共享库或可执行文件中每个编译单元的所有 DW_AT_producer 值的转储。

这是对自身运行 dwprod 的结果

$ dwprod $(which dwprod)
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
clang LLVM (rustc version 1.22.0-nightly (088216fb9 2017-09-04))
GNU C 4.8.5 -m64 -mtune=generic -march=x86-64 -g3 -O3 -O2 -O2 -std=gnu11 -fvisibility=hidden -funroll-loops -ffunction-sections -fdata-sections -fPIC
GNU C 4.8.5 -m64 -mtune=generic -march=x86-64 -g3 -O3 -O2 -O2 -std=gnu11 -fvisibility=hidden -funroll-loops -ffunction-sections -fdata-sections -fPIC
GNU C 4.8.5 -m64 -mtune=generic -march=x86-64 -g3 -O3 -O2 -O2 -std=gnu11 -fvisibility=hidden -funroll-loops -ffunction-sections -fdata-sections -fPIC
GNU C 4.8.5 -m64 -mtune=generic -march=x86-64 -g3 -O3 -O2 -O2 -std=gnu11 -fvisibility=hidden -funroll-loops -ffunction-sections -fdata-sections -fPIC
<truncated>

有关 dwprod 命令行工具的更多详细信息,请运行 dwprod --help

许可证:Apache-2.0/MIT

依赖关系

~5MB
~96K SLoC