Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Breakpad format #477

Merged
merged 8 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
rust: stable
profile: dev
args: "--lib --no-default-features --features=apk"
- runs-on: ubuntu-latest
rust: stable
profile: dev
args: "--lib --no-default-features --features=breakpad"
- runs-on: ubuntu-latest
rust: stable
profile: dev
Expand Down Expand Up @@ -153,8 +157,11 @@ jobs:
cat Cargo.toml
- name: cargo test -Zsanitizer=${{ matrix.sanitizer }}
env:
CFLAGS: "-fsanitize=${{ matrix.sanitizer }}"
CXXFLAGS: "-fsanitize=${{ matrix.sanitizer }}"
# TODO: Ideally we'd set CFLAGS and CXXFLAGS as well, but some
# of our transitive dependencies don't play nice with
# ASAN.
#CFLAGS: "-fsanitize=${{ matrix.sanitizer }}"
#CXXFLAGS: "-fsanitize=${{ matrix.sanitizer }}"
RUSTFLAGS: "-Zsanitizer=${{ matrix.sanitizer }}"
ASAN_OPTIONS: "detect_odr_violation=0:detect_leaks=0"
LSAN_OPTIONS: ""
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/data/*.bin
/data/*.gsym
/data/*.so
/data/*.sym
/data/*.zip
/data/kallsyms
/data/vmlinux-5.17.12-100.fc34.x86_64*
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Unreleased
----------
- Added support for Breakpad format behind `breakpad` feature (disabled
by default)


0.2.0-alpha.10
--------------
- Introduced `symbolize::Reason` enum to provide best guess at why symbolization
Expand Down
13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ apk = []
# Note that by default backtraces will not be collected unless opted in with
# environment variables.
backtrace = []
# Enable this feature to enable Breakpad support.
breakpad = ["circular", "nom"]
# Enable this feature to get transparent symbol demangling.
demangle = ["cpp_demangle", "rustc-demangle"]
# Enable this feature to enable DWARF support.
Expand All @@ -59,10 +61,10 @@ gsym = []

# Enable this feature to opt in to the generation of unit test files.
# Having these test files created is necessary for running tests.
generate-unit-test-files = ["xz2", "zip"]
generate-unit-test-files = ["dump_syms", "xz2", "zip"]
# Enable this feature to opt in to the generation of large benchmark
# files (also used for regression testing).
generate-large-test-files = ["reqwest", "xz2"]
generate-large-test-files = ["dump_syms", "reqwest", "xz2"]
# Disable generation of test files. This feature takes preference over
# `generate-unit-test-files`.
dont-generate-unit-test-files = []
Expand All @@ -82,9 +84,11 @@ lto = true
codegen-units = 1

[dependencies]
circular = {version = "0.3", optional = true}
cpp_demangle = {version = "0.4", optional = true}
gimli = {version = "0.28", optional = true}
libc = "0.2.137"
nom = {version = "7", optional = true}
rustc-demangle = {version = "0.1.4", optional = true}
tracing = {version = "0.1.27", default-features = false, features = ["attributes"], optional = true}

Expand All @@ -93,7 +97,7 @@ tracing = {version = "0.1.27", default-features = false, features = ["attributes
# APIs.
addr2line = "=0.21.0"
anyhow = "1.0.71"
blazesym = {path = ".", features = ["generate-unit-test-files", "apk", "gsym", "tracing"]}
blazesym = {path = ".", features = ["generate-unit-test-files", "apk", "breakpad", "gsym", "tracing"]}
criterion = {version = "0.5.1", default-features = false, features = ["rayon", "cargo_bench_support"]}
env_logger = "0.10"
scopeguard = "1.2"
Expand All @@ -102,13 +106,14 @@ test-log = {version = "0.2", default-features = false, features = ["trace"]}
tracing-subscriber = {version = "0.3", default-features = false, features = ["env-filter", "fmt"]}

[build-dependencies]
dump_syms = {version = "2.2", optional = true, default-features = false}
libc = "0.2.137"
reqwest = {version = "0.11.18", optional = true, features = ["blocking"]}
xz2 = {version = "0.1.7", optional = true}
zip = {version = "0.6.4", optional = true, default-features = false}

# https://docs.rs/about/metadata
[package.metadata.docs.rs]
features = ["apk", "backtrace", "demangle", "dwarf", "gsym"]
features = ["apk", "backtrace", "breakpad", "demangle", "dwarf", "gsym"]
# defines the configuration attribute `docsrs`
rustdoc-args = ["--cfg", "docsrs"]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ format supports and whether **blazesym** can currently use this feature:

| Format | Feature | Supported by format? | Supported by blazesym? |
| ------------- | -------------------------------- | ------------------------ | ------------------------ |
| Breakpad | symbol size | :heavy_check_mark: | :heavy_check_mark: |
| | source code location information | :heavy_check_mark: | :heavy_check_mark: |
| | inlined function information | :heavy_check_mark: | :heavy_check_mark: |
| ELF | symbol size | :heavy_check_mark: | :heavy_check_mark: |
| | source code location information | :heavy_multiplication_x: | :heavy_multiplication_x: |
| | inlined function information | :heavy_multiplication_x: | :heavy_multiplication_x: |
Expand Down
21 changes: 21 additions & 0 deletions benches/symbolize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::hint::black_box;
use std::path::Path;

use blazesym::symbolize::Breakpad;
use blazesym::symbolize::Elf;
use blazesym::symbolize::GsymFile;
use blazesym::symbolize::Input;
Expand Down Expand Up @@ -35,6 +36,25 @@ fn symbolize_process() {
assert_eq!(results.len(), addrs.len());
}

/// Symbolize an address in a Breakpad (*.sym) file, end-to-end, i.e.,
/// including all necessary setup.
fn symbolize_breakpad() {
let sym_vmlinux = Path::new(&env!("CARGO_MANIFEST_DIR"))
.join("data")
.join("vmlinux-5.17.12-100.fc34.x86_64.sym");
let src = Source::from(Breakpad::new(sym_vmlinux));
let symbolizer = Symbolizer::new();

let result = symbolizer
.symbolize_single(black_box(&src), black_box(Input::FileOffset(0x10ecb0)))
.unwrap()
.into_sym()
.unwrap();

assert_eq!(result.name, "abort_creds");
assert_eq!(result.code_info.as_ref().unwrap().line, Some(534));
}

/// Symbolize an address in an ELF file, end-to-end, i.e., including all
/// necessary setup.
fn symbolize_elf() {
Expand Down Expand Up @@ -161,6 +181,7 @@ where
M: Measurement,
{
bench_fn!(group, symbolize_process);
bench_fn!(group, symbolize_breakpad);
bench_fn!(group, symbolize_elf);
bench_fn!(group, symbolize_dwarf_no_lines);
bench_fn!(group, symbolize_dwarf);
Expand Down
45 changes: 44 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,41 @@ fn dwarf(src: &Path, dst: impl AsRef<OsStr>) {
strip(src, dst, &["--keep-section=.debug_*"])
}

/// Generate a Breakpad .sym file for the given source.
#[cfg(feature = "dump_syms")]
fn syms(src: &Path, dst: impl AsRef<OsStr>) {
use std::env::consts::ARCH;

use dump_syms::dumper;
use dump_syms::dumper::Config;
use dump_syms::dumper::FileOutput;
use dump_syms::dumper::Output;

let dst = src.with_file_name(dst);

let config = Config {
output: Output::File(FileOutput::Path(dst)),
symbol_server: None,
debug_id: None,
code_id: None,
arch: ARCH,
num_jobs: 1,
check_cfi: false,
emit_inlines: true,
mapping_var: None,
mapping_src: None,
mapping_dest: None,
mapping_file: None,
};
let path = src.to_str().unwrap();
let () = dumper::single_file(&config, path).unwrap();
}

#[cfg(not(feature = "dump_syms"))]
fn syms(_src: &Path, _dst: impl AsRef<OsStr>) {
unimplemented!()
}

/// Unpack an xz compressed file.
#[cfg(feature = "xz2")]
fn unpack_xz(src: &Path, dst: &Path) {
Expand Down Expand Up @@ -382,6 +417,9 @@ fn prepare_test_files(crate_root: &Path) {
gsym(&src, "test-stable-addresses.gsym");
dwarf(&src, "test-stable-addresses-dwarf-only.bin");
strip(&src, "test-stable-addresses-stripped.bin", &[]);
if cfg!(feature = "dump_syms") {
syms(&src, "test-stable-addresses.sym");
}

let src = crate_root.join("data").join("kallsyms.xz");
let mut dst = src.clone();
Expand Down Expand Up @@ -474,10 +512,15 @@ fn prepare_bench_files(crate_root: &Path) {
let dst = dst.file_name().unwrap();
gsym(&vmlinux, dst);

let mut dst = vmlinux_xz;
let mut dst = vmlinux_xz.clone();
assert!(dst.set_extension("dwarf"));
let dst = dst.file_name().unwrap();
dwarf(&vmlinux, dst);

let mut dst = vmlinux_xz;
assert!(dst.set_extension("sym"));
let dst = dst.file_name().unwrap();
syms(&vmlinux, dst);
}

fn main() {
Expand Down
5 changes: 5 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Unreleased
----------
- Added support for symbolization using Breakpad (`*.sym`) files


0.1.2
-----
- Bumped `blazesym` dependency to `0.2.0-alpha.10`
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ grev = "0.1.3"

[dependencies]
anyhow = "1.0.68"
blazesym = {version = "=0.2.0-alpha.10", path = "../", features = ["apk", "demangle", "dwarf", "gsym", "tracing"]}
blazesym = {version = "=0.2.0-alpha.10", path = "../", features = ["apk", "breakpad", "demangle", "dwarf", "gsym", "tracing"]}
clap = {version = "4.1.7", features = ["derive"]}
clap_complete = {version = "4.1.1", optional = true}
tracing = "0.1"
Expand Down
14 changes: 14 additions & 0 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,25 @@ pub struct User {
/// A type representing the `symbolize` command.
#[derive(Debug, Subcommand)]
pub enum Symbolize {
Breakpad(Breakpad),
Elf(Elf),
Gsym(Gsym),
Process(Process),
}

#[derive(Debug, Arguments)]
pub struct Breakpad {
/// The path to the Breakpad (*.sym) file.
#[clap(short, long)]
pub path: PathBuf,
/// The addresses to symbolize.
///
/// Addresses are assumed to be file offsets as they would be used on the
/// original (ELF/DWARF/...) source file.
#[arg(value_parser = parse_addr)]
pub addrs: Vec<Addr>,
}

#[derive(Debug, Arguments)]
pub struct Elf {
/// The path to the ELF file.
Expand Down
6 changes: 6 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ fn print_frame(
fn symbolize(symbolize: args::Symbolize) -> Result<()> {
let symbolizer = Symbolizer::new();
let (src, input, addrs) = match symbolize {
args::Symbolize::Breakpad(args::Breakpad { path, ref addrs }) => {
let src = symbolize::Source::from(symbolize::Breakpad::new(path));
let addrs = addrs.as_slice();
let input = symbolize::Input::FileOffset(addrs);
(src, input, addrs)
}
args::Symbolize::Elf(args::Elf { path, ref addrs }) => {
let src = symbolize::Source::from(symbolize::Elf::new(path));
let addrs = addrs.as_slice();
Expand Down
Loading