|
| 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