Skip to content

Commit 3d53e00

Browse files
authored
Expand --help output for addr2line command (#2329)
Add example usage section.
1 parent 3d0e9f4 commit 3d53e00

File tree

5 files changed

+254
-0
lines changed

5 files changed

+254
-0
lines changed

src/bin/wasm-tools/addr2line.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,55 @@ use wasm_tools::addr2line::Addr2lineModules;
1919
/// address is an inlined function into another function. Frames are printed
2020
/// innermost or youngest first.
2121
#[derive(clap::Parser)]
22+
#[clap(after_help = "\
23+
Examples:
24+
25+
Suppose foo.wat is as follows:
26+
27+
(module
28+
(func $\"dwarf(name)\"
29+
(;@18;) i32.const 0
30+
(;@1a;) drop
31+
)
32+
33+
(func $another-function
34+
(;@1e;) i32.const 0
35+
(;@20;) drop
36+
)
37+
)
38+
39+
# Parse foo.wat to binary form and then print filename
40+
# and line number information for four addresses in the binary
41+
# (that is, byte offsets).
42+
# Each line of output shows the requested address, then the name of
43+
# the function enclosing this address, then the source filename and
44+
# beginning and endling line numbers.
45+
$ wasm-tools addr2line --generate-dwarf lines foo.wat 0x18 0x1a 0x1e 0x20
46+
0x18: dwarf(name) foo.wat:3:10
47+
0x1a: dwarf(name) foo.wat:4:10
48+
0x1e: another-function foo.wat:8:10
49+
0x20: another-function foo.wat:9:10
50+
51+
Suppose foo.c was compiled to a .wasm file called foo.wasm. (foo.c not shown.)
52+
53+
# Print filename and line number information for two addresses.
54+
$ target/debug/wasm-tools addr2line --generate-dwarf lines foo.wasm 0xff 0x200
55+
0xff: main foo.c:14:0
56+
0x200: main foo.c:22:9
57+
58+
The output shows that both offsets are in the `main()` function, but at different
59+
line numbers.
60+
61+
# Print filename and line number information for two addresses (specified as decimals),
62+
# interpreting the addresses relative to the beginning of the code section.
63+
$ target/debug/wasm-tools addr2line --generate-dwarf lines --code-section-relative foo.wasm 255 512
64+
0xff: main foo.c:21:9
65+
0x200: main foo.c:25:9
66+
67+
The output shows how the addresses correspond to different source locations
68+
if interpreted relative to the beginning of the code section.
69+
70+
")]
2271
pub struct Opts {
2372
#[clap(flatten)]
2473
generate_dwarf: wasm_tools::GenerateDwarfArg,

tests/cli/help-addr2line-short.wat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
;; RUN: addr2line -h
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
Translate a WebAssembly address to a filename and line number using DWARF
2+
debugging information
3+
4+
Usage: wasm-tools addr2line [OPTIONS] [INPUT] [ADDRESSES]...
5+
6+
Arguments:
7+
[INPUT] Input file to process
8+
[ADDRESSES]... Addresses to convert to filenames and line numbers
9+
10+
Options:
11+
--generate-dwarf <lines|full>
12+
Optionally generate DWARF debugging information from WebAssembly text
13+
files
14+
-g
15+
Shorthand for `--generate-dwarf full`
16+
-o, --output <OUTPUT>
17+
Where to place output
18+
-v, --verbose...
19+
Use verbose output (-v info, -vv debug, -vvv trace)
20+
--color <COLOR>
21+
Configuration over whether terminal colors are used in output
22+
[default: auto]
23+
--code-section-relative
24+
Indicates that addresses are code-section-relative instead of offsets
25+
from the beginning of the module
26+
-h, --help
27+
Print help (see more with '--help')
28+
29+
Examples:
30+
31+
Suppose foo.wat is as follows:
32+
33+
(module
34+
(func $"dwarf(name)"
35+
(;@18;) i32.const 0
36+
(;@1a;) drop
37+
)
38+
39+
(func $another-function
40+
(;@1e;) i32.const 0
41+
(;@20;) drop
42+
)
43+
)
44+
45+
# Parse foo.wat to binary form and then print filename
46+
# and line number information for four addresses in the binary
47+
# (that is, byte offsets).
48+
# Each line of output shows the requested address, then the name of
49+
# the function enclosing this address, then the source filename and
50+
# beginning and endling line numbers.
51+
$ wasm-tools addr2line --generate-dwarf lines foo.wat 0x18 0x1a 0x1e 0x20
52+
0x18: dwarf(name) foo.wat:3:10
53+
0x1a: dwarf(name) foo.wat:4:10
54+
0x1e: another-function foo.wat:8:10
55+
0x20: another-function foo.wat:9:10
56+
57+
Suppose foo.c was compiled to a .wasm file called foo.wasm. (foo.c not shown.)
58+
59+
# Print filename and line number information for two addresses.
60+
$ target/debug/wasm-tools addr2line --generate-dwarf lines foo.wasm 0xff
61+
0x200
62+
0xff: main foo.c:14:0
63+
0x200: main foo.c:22:9
64+
65+
The output shows that both offsets are in the `main()` function, but at
66+
different
67+
line numbers.
68+
69+
# Print filename and line number information for two addresses (specified as
70+
decimals),
71+
# interpreting the addresses relative to the beginning of the code section.
72+
$ target/debug/wasm-tools addr2line --generate-dwarf lines
73+
--code-section-relative foo.wasm 255 512
74+
0xff: main foo.c:21:9
75+
0x200: main foo.c:25:9
76+
77+
The output shows how the addresses correspond to different source locations
78+
if interpreted relative to the beginning of the code section.

tests/cli/help-addr2line.wat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
;; RUN: addr2line --help
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
Translate a WebAssembly address to a filename and line number using DWARF
2+
debugging information.
3+
4+
WebAssembly binaries compiled with Clang can have DWARF debug information
5+
inserted into them to map from WebAssembly instruction offsets to original
6+
filenames and line numbers. For example when compiling C the `-g` argument can
7+
be used or when compiling Rust the `-Cdebuginfo=1` argument can be used (or the
8+
default `dev` profile for Cargo). This subcommand will parse the DWARF debugging
9+
information and translate a list of addresses to their original filenames and
10+
line numbers.
11+
12+
Each address may have multiple lines printed for it indicating that the address
13+
is an inlined function into another function. Frames are printed innermost or
14+
youngest first.
15+
16+
Usage: wasm-tools addr2line [OPTIONS] [INPUT] [ADDRESSES]...
17+
18+
Arguments:
19+
[INPUT]
20+
Input file to process.
21+
22+
If not provided or if this is `-` then stdin is read entirely and
23+
processed. Note that for most subcommands this input can either be a
24+
binary `*.wasm` file or a textual format `*.wat` file.
25+
26+
[ADDRESSES]...
27+
Addresses to convert to filenames and line numbers.
28+
29+
Arguments can be specified as either `0x...` or `@...` in hexadecimal
30+
or are otherwise parsed as a base-10 address. Addresses should be
31+
relative to the beginning of the module unless
32+
`--code-section-relative` is passed in which case they should be
33+
relative to the beginning of the contents of the code section.
34+
35+
Options:
36+
--generate-dwarf <lines|full>
37+
Optionally generate DWARF debugging information from WebAssembly text
38+
files.
39+
40+
When the input to this command is a WebAssembly text file, such as
41+
`*.wat`, then this option will instruct the text parser to insert
42+
DWARF debugging information to map binary locations back to the
43+
original source locations in the input `*.wat` file. This option has
44+
no effect if the `INPUT` argument is already a WebAssembly binary or
45+
if the text format uses `(module binary ...)`.
46+
47+
-g
48+
Shorthand for `--generate-dwarf full`
49+
50+
-o, --output <OUTPUT>
51+
Where to place output.
52+
53+
Required when printing WebAssembly binary output.
54+
55+
If not provided, then stdout is used.
56+
57+
-v, --verbose...
58+
Use verbose output (-v info, -vv debug, -vvv trace)
59+
60+
--color <COLOR>
61+
Configuration over whether terminal colors are used in output.
62+
63+
Supports one of `auto|never|always|always-ansi`. The default is to
64+
detect what to do based on the terminal environment, for example by
65+
using `isatty`.
66+
67+
[default: auto]
68+
69+
--code-section-relative
70+
Indicates that addresses are code-section-relative instead of offsets
71+
from the beginning of the module
72+
73+
-h, --help
74+
Print help (see a summary with '-h')
75+
76+
Examples:
77+
78+
Suppose foo.wat is as follows:
79+
80+
(module
81+
(func $"dwarf(name)"
82+
(;@18;) i32.const 0
83+
(;@1a;) drop
84+
)
85+
86+
(func $another-function
87+
(;@1e;) i32.const 0
88+
(;@20;) drop
89+
)
90+
)
91+
92+
# Parse foo.wat to binary form and then print filename
93+
# and line number information for four addresses in the binary
94+
# (that is, byte offsets).
95+
# Each line of output shows the requested address, then the name of
96+
# the function enclosing this address, then the source filename and
97+
# beginning and endling line numbers.
98+
$ wasm-tools addr2line --generate-dwarf lines foo.wat 0x18 0x1a 0x1e 0x20
99+
0x18: dwarf(name) foo.wat:3:10
100+
0x1a: dwarf(name) foo.wat:4:10
101+
0x1e: another-function foo.wat:8:10
102+
0x20: another-function foo.wat:9:10
103+
104+
Suppose foo.c was compiled to a .wasm file called foo.wasm. (foo.c not shown.)
105+
106+
# Print filename and line number information for two addresses.
107+
$ target/debug/wasm-tools addr2line --generate-dwarf lines foo.wasm 0xff
108+
0x200
109+
0xff: main foo.c:14:0
110+
0x200: main foo.c:22:9
111+
112+
The output shows that both offsets are in the `main()` function, but at
113+
different
114+
line numbers.
115+
116+
# Print filename and line number information for two addresses (specified as
117+
decimals),
118+
# interpreting the addresses relative to the beginning of the code section.
119+
$ target/debug/wasm-tools addr2line --generate-dwarf lines
120+
--code-section-relative foo.wasm 255 512
121+
0xff: main foo.c:21:9
122+
0x200: main foo.c:25:9
123+
124+
The output shows how the addresses correspond to different source locations
125+
if interpreted relative to the beginning of the code section.

0 commit comments

Comments
 (0)