This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
pp.rs
74 lines (58 loc) · 2.42 KB
/
pp.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Pretty printing the backtrace
use std::borrow::Cow;
use colored::Colorize as _;
use crate::dep;
use super::{symbolicate::Frame, Settings};
/// Pretty prints processed backtrace frames up to `backtrace_limit`
pub(crate) fn backtrace(frames: &[Frame], settings: &Settings) {
println!("{}", "stack backtrace:".dimmed());
let mut frame_index = 0;
for frame in frames {
match frame {
Frame::Exception => {
println!(" <exception entry>");
}
Frame::Subroutine(subroutine) => {
let name = match &subroutine.name_or_pc {
either::Either::Left(name) => Cow::Borrowed(name),
either::Either::Right(pc) => Cow::Owned(format!("??? (PC={:#010x})", pc)),
};
let is_local_function = subroutine
.location
.as_ref()
.map(|location| location.path_is_relative)
.unwrap_or(false);
let line = format!("{:>4}: {}", frame_index, name);
let colorized_line = if is_local_function {
line.bold()
} else {
line.normal()
};
println!("{}", colorized_line);
if let Some(location) = &subroutine.location {
let dep_path = dep::Path::from_std_path(&location.path);
let path = if settings.shorten_paths {
dep_path.format_short()
} else {
dep_path.format_highlight()
};
let line = location.line;
let column = location
.column
.map(|column| Cow::Owned(format!(":{}", column)))
.unwrap_or(Cow::Borrowed(""));
println!(" at {}:{}{}", path, line, column);
}
frame_index += 1;
if frame_index >= settings.backtrace_limit {
log::warn!(
"maximum backtrace length of {} reached; cutting off the rest.const ",
settings.backtrace_limit
);
log::warn!("note: re-run with `--max-backtrace-len=<your maximum>` to extend this limit");
break;
}
}
}
}
}