Skip to content

Commit 565570b

Browse files
committed
Improve wholesym-addr2line.
1 parent 4594a0e commit 565570b

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

wholesym-addr2line/src/main.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use clap::parser::ValuesRef;
66
use clap::{value_parser, Arg, ArgAction, Command};
77
use wholesym::LookupAddress;
88

9-
fn parse_uint_from_hex_string(string: &str) -> u32 {
9+
fn parse_uint_from_hex_string(string: &str) -> u64 {
1010
if string.len() > 2 && string.starts_with("0x") {
11-
u32::from_str_radix(&string[2..], 16).expect("Failed to parse address")
11+
u64::from_str_radix(&string[2..], 16).expect("Failed to parse address")
1212
} else {
13-
u32::from_str_radix(string, 16).expect("Failed to parse address")
13+
u64::from_str_radix(string, 16).expect("Failed to parse address")
1414
}
1515
}
1616

@@ -20,9 +20,9 @@ enum Addrs<'a> {
2020
}
2121

2222
impl<'a> Iterator for Addrs<'a> {
23-
type Item = u32;
23+
type Item = u64;
2424

25-
fn next(&mut self) -> Option<u32> {
25+
fn next(&mut self) -> Option<u64> {
2626
let text = match *self {
2727
Addrs::Args(ref mut vals) => vals.next().map(Cow::from),
2828
Addrs::Stdin(ref mut lines) => lines.next().map(Result::unwrap).map(Cow::from),
@@ -64,9 +64,9 @@ fn print_loc(
6464

6565
#[tokio::main]
6666
async fn main() -> Result<(), Box<dyn std::error::Error>> {
67-
let matches = Command::new("pdb-addr2line")
67+
let matches = Command::new("wholesym-addr2line")
6868
.version("0.1")
69-
.about("A fast addr2line port for PDBs")
69+
.about("A fast addr2line equivalent which supports lots of platforms.")
7070
.args(&[
7171
Arg::new("exe")
7272
.short('e')
@@ -77,10 +77,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
7777
"Specify the name of the executable for which addresses should be translated.",
7878
)
7979
.required(true),
80-
Arg::new("sup")
81-
.long("sup")
82-
.value_name("filename")
83-
.help("Path to supplementary object file."),
8480
Arg::new("functions")
8581
.action(ArgAction::SetTrue)
8682
.short('f')
@@ -122,9 +118,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
122118
.long("demangle")
123119
.help(
124120
"Demangle function names. \
125-
Specifying a specific demangling style (like GNU addr2line) \
126-
is not supported. (TODO)",
121+
We are currently demangling all function names even if this flag is not set.",
127122
),
123+
Arg::new("relative")
124+
.action(ArgAction::SetTrue)
125+
.long("relative")
126+
.conflicts_with("file-offsets")
127+
.help("Interpret the passed addresses as being relative to the image base address"),
128+
Arg::new("file-offsets")
129+
.action(ArgAction::SetTrue)
130+
.long("file-offsets")
131+
.conflicts_with("relative")
132+
.help("Interpret the passed addresses as being raw file offsets"),
128133
Arg::new("llvm")
129134
.action(ArgAction::SetTrue)
130135
.long("llvm")
@@ -141,6 +146,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
141146
let print_addrs = matches.get_flag("addresses");
142147
let basenames = matches.get_flag("basenames");
143148
let _demangle = matches.get_flag("demangle");
149+
let relative = matches.get_flag("relative");
150+
let file_offsets = matches.get_flag("file-offsets");
144151
let llvm = matches.get_flag("llvm");
145152
let path = matches.get_one::<PathBuf>("exe").unwrap();
146153

@@ -174,7 +181,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
174181
}
175182

176183
let mut printed_anything = false;
177-
if let Some(address_info) = symbol_map.lookup(LookupAddress::Relative(probe)).await {
184+
let address = if relative {
185+
LookupAddress::Relative(probe as u32)
186+
} else if file_offsets {
187+
LookupAddress::FileOffset(probe)
188+
} else {
189+
LookupAddress::Svma(probe)
190+
};
191+
if let Some(address_info) = symbol_map.lookup(address).await {
178192
if let Some(frames) = address_info.frames {
179193
if do_functions || do_inlines {
180194
for (i, frame) in frames.iter().enumerate() {

0 commit comments

Comments
 (0)