31
31
- run the following command to transfer the address to line info:
32
32
```
33
33
$ cd test-tools/addr2line
34
- $ python3 addr2line.py --wasi-sdk <wasi-sdk installation> --wabt <wabt installation> -- wasm-file <wasm file path> call_stack.txt
34
+ $ python3 addr2line.py --wasi-sdk <wasi-sdk installation> --wasm-file <wasm file path> call_stack.txt
35
35
```
36
- - the script will use *wasm-objdump* in wabt to transform address, then use *llvm-dwarfdump* to lookup the line info for each address
37
- in the call-stack dump.
36
+ - the script will use *llvm-dwarfdump* to lookup the line info for each address in the call-stack dump.
38
37
- the output will be:
39
38
```
40
39
#00: 0x0a04 - $f18
46
45
"""
47
46
48
47
49
- def get_code_section_start (wasm_objdump : Path , wasm_file : Path ) -> int :
50
- """
51
- Find the start offset of Code section in a wasm file.
52
-
53
- if the code section header likes:
54
- Code start=0x0000017c end=0x00004382 (size=0x00004206) count: 47
55
-
56
- the start offset is 0x0000017c
57
- """
58
- cmd = f"{ wasm_objdump } -h { wasm_file } "
59
- p = subprocess .run (
60
- shlex .split (cmd ),
61
- check = True ,
62
- capture_output = True ,
63
- text = True ,
64
- universal_newlines = True ,
65
- )
66
- outputs = p .stdout .split (os .linesep )
67
-
68
- # if there is no .debug section, return -1
69
- for line in outputs :
70
- line = line .strip ()
71
- if ".debug_info" in line :
72
- break
73
- else :
74
- print (f"No .debug_info section found { wasm_file } " )
75
- return - 1
76
-
77
- for line in outputs :
78
- line = line .strip ()
79
- if "Code" in line :
80
- return int (line .split ()[1 ].split ("=" )[1 ], 16 )
81
-
82
- return - 1
83
-
84
-
85
48
def get_line_info (dwarf_dump : Path , wasm_file : Path , offset : int ) -> str :
86
49
"""
87
50
Find the location info of a given offset in a wasm file.
@@ -142,21 +105,13 @@ def parse_call_stack_line(line: str) -> ():
142
105
def main ():
143
106
parser = argparse .ArgumentParser (description = "addr2line for wasm" )
144
107
parser .add_argument ("--wasi-sdk" , type = Path , help = "path to wasi-sdk" )
145
- parser .add_argument ("--wabt" , type = Path , help = "path to wabt" )
146
108
parser .add_argument ("--wasm-file" , type = Path , help = "path to wasm file" )
147
109
parser .add_argument ("call_stack_file" , type = Path , help = "path to a call stack file" )
148
110
args = parser .parse_args ()
149
111
150
- wasm_objdump = args .wabt .joinpath ("bin/wasm-objdump" )
151
- assert wasm_objdump .exists ()
152
-
153
112
llvm_dwarf_dump = args .wasi_sdk .joinpath ("bin/llvm-dwarfdump" )
154
113
assert llvm_dwarf_dump .exists ()
155
114
156
- code_section_start = get_code_section_start (wasm_objdump , args .wasm_file )
157
- if code_section_start == - 1 :
158
- return - 1
159
-
160
115
assert args .call_stack_file .exists ()
161
116
with open (args .call_stack_file , "rt" , encoding = "ascii" ) as f :
162
117
for line in f :
@@ -173,7 +128,6 @@ def main():
173
128
_ , offset , _ = splitted
174
129
175
130
offset = int (offset , 16 )
176
- offset = offset - code_section_start
177
131
line_info = get_line_info (llvm_dwarf_dump , args .wasm_file , offset )
178
132
if not line_info :
179
133
print (line )
0 commit comments