Skip to content

Commit

Permalink
Fix code snippets in README
Browse files Browse the repository at this point in the history
The code snippets in the README are outdated. The SymSrcCfg type
mentioned there, for example, seems to have been renamed in the library
to SymbolSrcCfg eons ago. Update the README accordingly. Not all
snippets can (or are intended to) compile, but those that can are fully
fixed up now and checked as part of CI.

Closes: #32

Signed-off-by: Daniel Müller <deso@posteo.net>
  • Loading branch information
d-e-s-o committed Dec 8, 2022
1 parent b8b0ada commit 80c4063
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ jobs:
with:
toolchain: stable
override: true
- run: cargo test
- run: |
cargo test
cargo test --doc
bench:
name: Benchmark
runs-on: ubuntu-latest
Expand Down
41 changes: 20 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,21 @@ functions and various types of BlazeSym.
The following code makes use of BlazeSym to access symbol names, filenames of
sources, and line numbers of addresses involved in a process.

```rust,ignore
use blazesym::{BlazeSymbolizer, SymbolSrcCfg, SymbolizedResult};
```ignore,compile_fail
use blazesym::{BlazeSymbolizer, SymSrcCfg, SymbolizedResult};
let process_id: u32 = <process id>;
let process_id: u32 = std::process::id(); // <some process id>
// load all symbols of loaded files of the given process.
let sym_srcs = [SymSrcCfg::Process { pid: process_id }];
let sym_srcs = [SymbolSrcCfg::Process { pid: Some(process_id) }];
let symbolizer = BlazeSymbolizer::new().unwrap();
let stack: [u64] = [0xff023, 0x17ff93b]; // Addresses of instructions
let stack: [u64; 2] = [0xff023, 0x17ff93b]; // Addresses of instructions
let symlist = symbolizer.symbolize(&sym_srcs, // Pass this configuration every time
&stack);
for i in 0..stack.len() {
let address = stack[i];
if symlist.len() <= i or symlist[i].len() == 0 { // Unknown address
if symlist.len() <= i || symlist[i].len() == 0 { // Unknown address
println!("0x{:016x}", address);
continue;
}
Expand All @@ -71,11 +70,11 @@ sources, and line numbers of addresses involved in a process.
```

`sym_srcs` is a list of symbol sources in a process.
However, there is only one `SymSrcCfg::Process {}` here.
`SymSrcCfg::Process {}` is a convenient variant for loading all objects,
However, there is only one `SymbolSrcCfg::Process {}` here.
`SymbolSrcCfg::Process {}` is a convenient variant for loading all objects,
i.e., binaries and shared libraries, mapped in a process. Therefore, developers
do not have to specify each object and its base address with
`SymSrcCfg::Process {}`.
`SymbolSrcCfg::Process {}`.

`symlist` is a list of lists of `SymbolizedResult`. The instruction provided
at an address can result from several lines of code from multiple
Expand All @@ -86,10 +85,10 @@ argument passed to [`BlazeSymbolizer::symbolize()`].

### With Linux Kernel

`SymSrcCfg::Kernel {}` is a variant to load symbols of the Linux Kernel.
`SymbolSrcCfg::Kernel {}` is a variant to load symbols of the Linux Kernel.

```ignore,compile_fail
let sym_srcs = [SymSrcCfg::Kernel {
```rust,ignore,compile_fail
let sym_srcs = [SymbolSrcCfg::Kernel {
kallsyms: Some("/proc/kallsyms".to_string()),
kernel_image: Some("/boot/vmlinux-xxxxx".to_string()),
}];
Expand All @@ -104,19 +103,19 @@ paths for you, if possible. It will use `"/proc/kallsyms"` for
kallsyms and find the kernel image of the running kernel from several
potential directories; for instance, `"/boot/"` and `"/usr/lib/debug/boot/"`.

```ignore,compile_fail
let sym_srcs = [SymSrcCfg::Kernel { kallsyms: None, kernel_image: None }];
```rust,ignore,compile_fail
let sym_srcs = [SymbolSrcCfg::Kernel { kallsyms: None, kernel_image: None }];
```

### A list of ELF files

You can still provide a list of ELF files and their base addresses if necessary.

```ignore,compile_fail
let sym_srcs = [SymSrcCfg::Elf { file_name: String::from("/lib/libc.so.xxx"),
base_address: 0x1f005d },
SymSrcCfg::Elf { fie_name: String::from("/path/to/my/binary"),
base_address: 0x77777 },
```rust,ignore,compile_fail
let sym_srcs = [SymbolSrcCfg::Elf { file_name: String::from("/lib/libc.so.xxx"),
base_address: 0x1f005d },
SymbolSrcCfg::Elf { fie_name: String::from("/path/to/my/binary"),
base_address: 0x77777 },
......
];
```
Expand Down Expand Up @@ -169,7 +168,7 @@ shows the addresses, symbol names, source filenames and line numbers.
/* sym_srcs should be passed every time doing symbolization */
result = blazesym_symbolize(symbolizer,
sym_srcs, 1,
stack, stack_sz);
stack, stack_sz);

for (i = 0; i < stack_sz; i++) {
addr = stack[i];
Expand Down

0 comments on commit 80c4063

Please sign in to comment.