Skip to content
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
12 changes: 6 additions & 6 deletions src/bin/wasm-tools/addr2line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ line numbers.
# Print filename and line number information for two addresses (specified as decimals),
# interpreting the addresses relative to the beginning of the code section.
$ target/debug/wasm-tools addr2line --generate-dwarf lines --code-section-relative foo.wasm 255 512
0xff: main foo.c:21:9
0x200: main foo.c:25:9
255: main foo.c:21:9
512: main foo.c:25:9

The output shows how the addresses correspond to different source locations
if interpreted relative to the beginning of the code section.
Expand Down Expand Up @@ -118,13 +118,13 @@ impl Opts {
) -> Result<()> {
// Support either `0x` or `@` prefixes for hex addresses since 0x is
// standard and @ is used by wasmprinter (and web browsers I think?)
let addr = if let Some(hex) = addr.strip_prefix("0x").or_else(|| addr.strip_prefix("@")) {
let parsed = if let Some(hex) = addr.strip_prefix("0x").or_else(|| addr.strip_prefix("@")) {
u64::from_str_radix(hex, 16)?
} else {
addr.parse()?
};

let (cx, text_relative_addr) = match modules.context(addr, self.code_section_relative)? {
let (cx, text_relative_addr) = match modules.context(parsed, self.code_section_relative)? {
Some(pair) => pair,
None => bail!("no module found which contains this address"),
};
Expand All @@ -139,7 +139,7 @@ impl Opts {
let mut first = true;
while let Some(frame) = frames.next()? {
if first {
write!(out, "{addr:#x}: ")?;
write!(out, "{addr}: ")?;
} else {
write!(out, "\t")?;
}
Expand All @@ -165,7 +165,7 @@ impl Opts {
writeln!(out, "")?;
}
if first {
writeln!(out, "{addr:#x}: no dwarf frames found for this address")?;
writeln!(out, "{addr}: no dwarf frames found for this address")?;
}
Ok(())
}
Expand Down
13 changes: 13 additions & 0 deletions tests/cli/dwarf-into-addr2line-decimal.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
;; RUN: addr2line --generate-dwarf lines % 24 26 30 32

(module
(func $"dwarf(name)"
(;@18;) i32.const 0
(;@1a;) drop
)

(func $another-function
(;@1e;) i32.const 0
(;@20;) drop
)
)
4 changes: 4 additions & 0 deletions tests/cli/dwarf-into-addr2line-decimal.wat.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
24: dwarf(name) tests/cli/dwarf-into-addr2line-decimal.wat:5:10
26: dwarf(name) tests/cli/dwarf-into-addr2line-decimal.wat:6:10
30: another-function tests/cli/dwarf-into-addr2line-decimal.wat:10:10
32: another-function tests/cli/dwarf-into-addr2line-decimal.wat:11:10
4 changes: 2 additions & 2 deletions tests/cli/help-addr2line-short.wat.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ line numbers.
# interpreting the addresses relative to the beginning of the code section.
$ target/debug/wasm-tools addr2line --generate-dwarf lines
--code-section-relative foo.wasm 255 512
0xff: main foo.c:21:9
0x200: main foo.c:25:9
255: main foo.c:21:9
512: main foo.c:25:9

The output shows how the addresses correspond to different source locations
if interpreted relative to the beginning of the code section.
4 changes: 2 additions & 2 deletions tests/cli/help-addr2line.wat.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ line numbers.
# interpreting the addresses relative to the beginning of the code section.
$ target/debug/wasm-tools addr2line --generate-dwarf lines
--code-section-relative foo.wasm 255 512
0xff: main foo.c:21:9
0x200: main foo.c:25:9
255: main foo.c:21:9
512: main foo.c:25:9

The output shows how the addresses correspond to different source locations
if interpreted relative to the beginning of the code section.
Loading