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

deps: update blazesym submodule to v0.2.0-alpha.7 #222

Merged
merged 1 commit into from
Oct 11, 2023
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
2 changes: 1 addition & 1 deletion blazesym
Submodule blazesym updated 52 files
+18 −0 .github/dependabot.yml
+1 −1 .github/workflows/build.yml
+2 −2 .github/workflows/publish.yml
+12 −12 .github/workflows/test.yml
+25 −0 CHANGELOG.md
+6 −6 Cargo.toml
+26 −3 README.md
+20 −32 benches/symbolize.rs
+30 −0 build.rs
+1 −0 cli/Cargo.toml
+3 −3 cli/README.md
+23 −1 cli/src/args.rs
+120 −37 cli/src/main.rs
+17 −0 data/test-stable-addresses.c
+2 −0 data/test-stable-addresses.ld
+40 −0 data/test.rs
+59 −33 examples/addr2ln.rs
+57 −31 examples/addr2ln_pid.rs
+65 −33 examples/backtrace.rs
+83 −40 include/blazesym.h
+6 −0 src/c_api/inspect.rs
+42 −16 src/c_api/normalize.rs
+176 −114 src/c_api/symbolize.rs
+315 −0 src/dwarf/function.rs
+1 −0 src/dwarf/location.rs
+82 −25 src/dwarf/resolver.rs
+30 −8 src/dwarf/unit.rs
+134 −13 src/dwarf/units.rs
+2 −2 src/elf/cache.rs
+43 −34 src/elf/parser.rs
+15 −9 src/elf/resolver.rs
+19 −7 src/error.rs
+152 −0 src/gsym/inline.rs
+9 −9 src/gsym/linetab.rs
+1 −0 src/gsym/mod.rs
+1 −3 src/gsym/parser.rs
+218 −90 src/gsym/resolver.rs
+6 −6 src/kernel.rs
+42 −138 src/ksym.rs
+6 −1 src/lib.rs
+13 −0 src/normalize/buildid.rs
+3 −0 src/normalize/meta.rs
+1 −0 src/normalize/mod.rs
+48 −17 src/normalize/normalizer.rs
+18 −16 src/normalize/user.rs
+13 −6 src/resolver.rs
+220 −38 src/symbolize/mod.rs
+1 −0 src/symbolize/source.rs
+200 −121 src/symbolize/symbolizer.rs
+11 −11 src/util.rs
+210 −105 tests/blazesym.rs
+139 −22 tests/c_api.rs
60 changes: 32 additions & 28 deletions examples/c/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,33 @@ static long perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu

static struct blaze_symbolizer *symbolizer;

static void print_frame(const char *name, uintptr_t input_addr, uintptr_t addr, uint64_t offset, const blaze_symbolize_code_info* code_info)
{
// If we have an input address we have a new symbol.
if (input_addr != 0) {
printf("%016lx: %s @ 0x%lx+0x%lx", input_addr, name, addr, offset);
if (code_info != NULL && code_info->dir != NULL && code_info->file != NULL) {
printf(" %s/%s:%u\n", code_info->dir, code_info->file, code_info->line);
} else if (code_info != NULL && code_info->file != NULL) {
printf(" %s:%u\n", code_info->file, code_info->line);
} else {
printf("\n");
}
} else {
printf("%016s %s", "", name);
if (code_info != NULL && code_info->dir != NULL && code_info->file != NULL) {
printf("@ %s/%s:%u [inlined]\n", code_info->dir, code_info->file, code_info->line);
} else if (code_info != NULL && code_info->file != NULL) {
printf("@ %s:%u [inlined]\n", code_info->file, code_info->line);
} else {
printf("[inlined]\n");
}
}
}

static void show_stack_trace(__u64 *stack, int stack_sz, pid_t pid)
{
const struct blaze_symbolize_inlined_fn* inlined;
const struct blaze_result *result;
const struct blaze_sym *sym;
int i, j;
Expand All @@ -54,39 +79,18 @@ static void show_stack_trace(__u64 *stack, int stack_sz, pid_t pid)


for (i = 0; i < stack_sz; i++) {
if (!result || result->size <= i || !result->entries[i].size) {
if (!result || result->cnt <= i || result->syms[i].name == NULL) {
printf(" %2d [<%016llx>]\n", i, stack[i]);
continue;
}

if (result->entries[i].size == 1) {
sym = &result->entries[i].syms[0];

if (sym->dir && sym->dir[0] != '\0' && sym->file && sym->file[0] != '\0') {
printf(" %2d [<%016llx>] %s+0x%lx %s/%s:%u\n", i, stack[i],
sym->name, sym->offset, sym->dir, sym->file, sym->line);
} else if (sym->file && sym->file[0] != '\0') {
printf(" %2d [<%016llx>] %s+0x%lx %s:%u\n", i, stack[i],
sym->name, sym->offset, sym->file, sym->line);
} else {
printf(" %2d [<%016llx>] %s+0x%lx\n", i, stack[i], sym->name, sym->offset);
}
continue;
}
sym = &result->syms[i];
print_frame(sym->name, stack[i], sym->addr, sym->offset, &sym->code_info);

printf(" %2d [<%016llx>]\n", i, stack[i]);
for (j = 0; j < result->entries[i].size; j++) {
sym = &result->entries[i].syms[j];
if (sym->dir && sym->dir[0] != '\0' && sym->file && sym->file[0] != '\0') {
printf(" %s+0x%lx %s/%s:%u\n", sym->name,
sym->offset, sym->dir, sym->file, sym->line);
} else if (sym->file && sym->file[0] != '\0') {
printf(" %s+0x%lx %s:%u\n", sym->name,
sym->offset, sym->file, sym->line);
} else {
printf(" %s+0x%lx\n", sym->name, sym->offset);
}
}
for (j = 0; j < sym->inlined_cnt; j++) {
inlined = &sym->inlined[j];
print_frame(sym->name, 0, 0, 0, &inlined->code_info);
}
}

blaze_result_free(result);
Expand Down
47 changes: 35 additions & 12 deletions examples/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 50 additions & 30 deletions examples/rust/profile/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::io::Error;
use std::mem;
use std::path::PathBuf;
use std::time::Duration;

use blazesym::symbolize;
Expand All @@ -24,6 +23,7 @@ use profile::*;

const MAX_STACK_DEPTH: usize = 128;
const TASK_COMM_LEN: usize = 16;
const ADDR_WIDTH: usize = 16;

// A Rust version of stacktrace_event in profile.h
#[repr(C)]
Expand Down Expand Up @@ -69,6 +69,39 @@ fn attach_perf_event(
.collect()
}

fn print_frame(name: &str, addr_info: Option<(blazesym::Addr, blazesym::Addr, usize)>, code_info: &Option<symbolize::CodeInfo>) {
let code_info = code_info.as_ref().map(|code_info| {
let path = code_info.to_path();
let path = path.display();

match (code_info.line, code_info.column) {
(Some(line), Some(col)) => format!(" {path}:{line}:{col}"),
(Some(line), None) => format!(" {path}:{line}"),
(None, _) => format!(" {path}"),
}
});

if let Some((input_addr, addr, offset)) = addr_info {
// If we have various address information bits we have a new symbol.
println!(
"{input_addr:#0width$x}: {name} @ {addr:#x}+{offset:#x}{code_info}",
code_info = code_info.as_deref().unwrap_or(""),
width = ADDR_WIDTH
)
} else {
// Otherwise we are dealing with an inlined call.
println!(
"{:width$} {name}{code_info} [inlined]",
" ",
code_info = code_info
.map(|info| format!(" @{info}"))
.as_deref()
.unwrap_or(""),
width = ADDR_WIDTH
)
}
}

// Pid 0 means a kernel space stack.
fn show_stack_trace(stack: &[u64], symbolizer: &symbolize::Symbolizer, pid: u32) {
let converted_stack;
Expand Down Expand Up @@ -101,36 +134,23 @@ fn show_stack_trace(stack: &[u64], symbolizer: &symbolize::Symbolizer, pid: u32)
}
};

for (i, (addr, syms)) in stack.iter().zip(syms).enumerate() {
let mut addr_fmt = format!(" {i:2} [<{addr:016x}>]");
if syms.is_empty() {
println!("{addr_fmt}")
} else {
for (i, sym) in syms.into_iter().enumerate() {
if i == 1 {
addr_fmt = addr_fmt.replace(|_c| true, " ");
for (input_addr, sym) in stack.iter().copied().zip(syms) {
match sym {
symbolize::Symbolized::Sym(symbolize::Sym {
name,
addr,
offset,
code_info,
inlined,
..
}) => {
print_frame(&name, Some((input_addr, addr, offset)), &code_info);
for frame in inlined.iter() {
print_frame(&frame.name, None, &frame.code_info);
}

let path = match (sym.dir, sym.file) {
(Some(dir), Some(file)) => Some(dir.join(file)),
(dir, file) => dir.or_else(|| file.map(PathBuf::from)),
};

let src_loc = if let (Some(path), Some(line)) = (path, sym.line) {
if let Some(col) = sym.column {
format!(" {}:{line}:{col}", path.display())
} else {
format!(" {}:{line}", path.display())
}
} else {
String::new()
};

let symbolize::Sym {
name, addr, offset, ..
} = sym;

println!("{addr_fmt} {name} @ {addr:#x}+{offset:#x}{src_loc}");
}
symbolize::Symbolized::Unknown => {
println!("{input_addr:#0width$x}: <no-symbol>", width = ADDR_WIDTH)
}
}
}
Expand Down
Loading