11
11
# If there is an emscripten symbol map, we can use that to get the symbol name
12
12
# If there is a name section or symbol table, llvm-symbolizer can show the
13
13
# symbol name.
14
- # Separate DWARF and emscripten symbol maps are not supported yet.
14
+ # Separate DWARF is not supported yet.
15
15
16
16
import argparse
17
17
import json
22
22
from tools import shared
23
23
from tools import webassembly
24
24
25
+
25
26
LLVM_SYMBOLIZER = os .path .expanduser (
26
27
shared .build_llvm_tool_path (shared .exe_suffix ('llvm-symbolizer' )))
27
28
@@ -70,6 +71,8 @@ def symbolize_address_symbolizer(module, address, is_dwarf):
70
71
vma_adjust = 0
71
72
cmd = [LLVM_SYMBOLIZER , '-e' , module .filename , f'--adjust-vma={ vma_adjust } ' ,
72
73
str (address )]
74
+ if shared .DEBUG :
75
+ print (f'Running { " " .join (cmd )} ' )
73
76
out = shared .run_process (cmd , stdout = subprocess .PIPE ).stdout .strip ()
74
77
out_lines = out .splitlines ()
75
78
@@ -215,6 +218,31 @@ def symbolize_address_sourcemap(module, address, force_file):
215
218
sm .lookup (address ).print ()
216
219
217
220
221
+ def symbolize_address_symbolmap (module , address , symbol_map_file ):
222
+ """Symbolize using a symbol map file."""
223
+ func_names = {}
224
+
225
+ with open (symbol_map_file ) as f :
226
+ lines = f .read ().splitlines ()
227
+ for line in lines :
228
+ index , name = line .split (':' )
229
+ func_names [int (index )] = name
230
+
231
+ func_index = - 1
232
+ for i , func in module .iter_functions_by_index ():
233
+ if shared .DEBUG :
234
+ print (f'Func { i } : { hex (func .offset )} , { func_names [i ]} ' )
235
+ if func .offset > address :
236
+ if i > 0 :
237
+ func_index = i - 1
238
+ break
239
+ else :
240
+ print ("Address is before the first function" )
241
+ return
242
+
243
+ LocationInfo (func = func_names [func_index ]).print ()
244
+
245
+
218
246
def main (args ):
219
247
with webassembly .Module (args .wasm_file ) as module :
220
248
base = 16 if args .address .lower ().startswith ('0x' ) else 10
@@ -235,6 +263,8 @@ def main(args):
235
263
elif ((has_linking_section (module ) and not args .source ) or
236
264
'symtab' in args .source ):
237
265
symbolize_address_symbolizer (module , address , is_dwarf = False )
266
+ elif (args .source == 'symbolmap' ):
267
+ symbolize_address_symbolmap (module , address , args .file )
238
268
else :
239
269
raise Error ('No .debug_line or sourceMappingURL section found in '
240
270
f'{ module .filename } .'
@@ -244,7 +274,7 @@ def main(args):
244
274
def get_args ():
245
275
parser = argparse .ArgumentParser ()
246
276
parser .add_argument ('-s' , '--source' , choices = ['dwarf' , 'sourcemap' ,
247
- 'names' , 'symtab' ],
277
+ 'names' , 'symtab' , 'symbolmap' ],
248
278
help = 'Force debug info source type' , default = ())
249
279
parser .add_argument ('-f' , '--file' , action = 'store' ,
250
280
help = 'Force debug info source file' )
0 commit comments