Skip to content

Commit

Permalink
Fix bug decode DWARF backtraces on Linux without --decode
Browse files Browse the repository at this point in the history
  • Loading branch information
markbenvenuto committed Apr 10, 2020
1 parent 1fbb212 commit 97367ce
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mrlog"
version = "0.2.0"
version = "0.2.1"
authors = ["Mark Benvenuto <[email protected]>"]
edition = "2018"

Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

Converts MongoDB 4.4 log format to MongoDB 4.2 and prior style text logs

## Features
* Converts JSON to text
* Optional output coloring
* Subprocess execution
* Demangles C++ names automatically
* Optional decoding of stacktraces using DWARF to give line numbers (Linux only)

## Run

To read from standard in:
Expand All @@ -14,12 +21,19 @@ To convert a file:

File is printed to standard out

**Advanced Features:**

To run a command and colorize its output:

```mrlog -c -e python -- buildscripts/resmoke.py ...```

Separate the command executable from its arguments with `--`.

To decode stacktraces using DWARF fromm mongod (Linux only).

```mrlog --decode=mongod <optional file>```


## Options

```
Expand All @@ -45,7 +59,11 @@ ARGS:
```

## Build
```cargo build```
Get Rust from https://rustup.rs/.

```cargo build --release```

**Note**: Release builds are needed for good performance for decoding DWARF.

## License

Expand Down
26 changes: 20 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,21 @@ impl LogFormatter {
let ret = self.objs.contains_key(path);

if !ret {
let file = File::open(path).with_context(|| format!("Failed to open file '{}' for dwarf and symbols", path) )?;

let m1 = unsafe { memmap2::Mmap::map(&file).with_context(|| format!("Failed to mmap file '{}' for dwarf and symbols", path))? };
let file = File::open(path)
.with_context(|| format!("Failed to open file '{}' for dwarf and symbols", path))?;

let m1 = unsafe {
memmap2::Mmap::map(&file).with_context(|| {
format!("Failed to mmap file '{}' for dwarf and symbols", path)
})?
};
let r1 = rent_object::RentObject::new(
Rc::new(m1),
|m3| Rc::new(object::File::parse(m3).expect(&format!("Failed to parse file '{}'", path))) ,
|m3| {
Rc::new(
object::File::parse(m3).expect(&format!("Failed to parse file '{}'", path)),
)
},
|a1, _| Rc::new(a1.symbol_map()),
);

Expand Down Expand Up @@ -590,8 +599,13 @@ impl LogFormatter {
// Only mac and linux have processInfo
// Note: decoding only works on Linux for now since gimli::Object does not support multi-arch binaries on Mac
// TODO - use goblin instead
if cfg!(target_os = "linux") && msg.starts_with("BACKTRACE") && attr["bt"].has_key("processInfo")
&& attr["bt"]["processInfo"]["somap"][0].has_key("elfType") {
// See https://github.com/rust-lang/backtrace-rs/blob/ac175e25d15e7bd2c870cd4d06e141bc62bbf59e/src/symbolize/gimli.rs#L38-L61
if cfg!(target_os = "linux")
&& self.decode.is_some()
&& msg.starts_with("BACKTRACE")
&& attr["bt"].has_key("processInfo")
&& attr["bt"]["processInfo"]["somap"][0].has_key("elfType")
{
return self.demangle_backtrace(
&attr["bt"],
s,
Expand Down

0 comments on commit 97367ce

Please sign in to comment.