(wasm, options)
| 397 | |
| 398 | |
| 399 | def read_dwarf_info(wasm, options): |
| 400 | if options.dwarfdump_output: |
| 401 | output = utils.read_file(options.dwarfdump_output) |
| 402 | elif options.dwarfdump: |
| 403 | logger.debug('Reading DWARF information from %s' % wasm) |
| 404 | if not os.path.exists(options.dwarfdump): |
| 405 | utils.exit_with_error('llvm-dwarfdump not found: ' + options.dwarfdump) |
| 406 | dwarfdump_cmd = [options.dwarfdump, '-debug-info', '-debug-line', wasm] |
| 407 | if generate_scopes: |
| 408 | # We need only three tags in the debug info: DW_TAG_compile_unit for |
| 409 | # source location, and DW_TAG_subprogram and DW_TAG_inlined_subroutine |
| 410 | # for the function ranges. |
| 411 | dwarfdump_cmd += ['-t', 'DW_TAG_compile_unit', '-t', 'DW_TAG_subprogram', |
| 412 | '-t', 'DW_TAG_inlined_subroutine'] |
| 413 | else: |
| 414 | # We only need the top-level DW_TAG_compile_unit tags when not generating |
| 415 | # the names field |
| 416 | dwarfdump_cmd += ['--recurse-depth=0'] |
| 417 | proc = shared.check_call(dwarfdump_cmd, stdout=shared.PIPE) |
| 418 | output = proc.stdout |
| 419 | else: |
| 420 | utils.exit_with_error('Please specify either --dwarfdump or --dwarfdump-output') |
| 421 | |
| 422 | debug_line_pattern = re.compile(r"debug_line\[(0x[0-9a-f]*)\]") |
| 423 | include_dir_pattern = re.compile(r"include_directories\[\s*(\d+)\] = \"([^\"]*)") |
| 424 | file_pattern = re.compile(r"file_names\[\s*(\d+)\]:\s+name: \"([^\"]*)\"\s+dir_index: (\d+)") |
| 425 | line_pattern = re.compile(r"\n0x([0-9a-f]+)\s+(\d+)\s+(\d+)\s+(\d+)(.*?end_sequence)?") |
| 426 | |
| 427 | entries = [] |
| 428 | iterator = debug_line_pattern.finditer(output) |
| 429 | current_match = None |
| 430 | try: |
| 431 | current_match = next(iterator) |
| 432 | debug_info_end = current_match.start() # end of .debug_info contents |
| 433 | except StopIteration: |
| 434 | debug_info_end = len(output) |
| 435 | |
| 436 | debug_info = output[:debug_info_end] # .debug_info contents |
| 437 | map_stmt_list_to_comp_dir = extract_comp_dir_map(debug_info) |
| 438 | |
| 439 | while current_match: |
| 440 | next_match = next(iterator, None) |
| 441 | |
| 442 | stmt_list = current_match.group(1) |
| 443 | start = current_match.end() |
| 444 | end = next_match.start() if next_match else len(output) |
| 445 | |
| 446 | comp_dir = map_stmt_list_to_comp_dir.get(stmt_list, '') |
| 447 | |
| 448 | # include_directories[ 1] = "/Users/yury/Work/junk/sqlite-playground/src" |
| 449 | # file_names[ 1]: |
| 450 | # name: "playground.c" |
| 451 | # dir_index: 1 |
| 452 | # mod_time: 0x00000000 |
| 453 | # length: 0x00000000 |
| 454 | # |
| 455 | # Address Line Column File ISA Discriminator Flags |
| 456 | # ------------------ ------ ------ ------ --- ------------- ------------- |
no test coverage detected