MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / test_dwarf

Method test_dwarf

test/test_core.py:8009–8140  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

8007 @no_wasm2js('TODO: source maps in wasm2js')
8008 @no_esm_integration('WASM_ESM_INTEGRATION is not compatible with dwarf output')
8009 def test_dwarf(self):
8010 self.cflags.append('-g')
8011
8012 copy_asset('core/test_dwarf.c')
8013
8014 self.emcc('test_dwarf.c')
8015
8016 out = self.run_process([shared.LLVM_DWARFDUMP, 'a.out.wasm', '-all'], stdout=PIPE).stdout
8017
8018 # parse the sections
8019 sections = {}
8020
8021 lines = out.splitlines()
8022 # Add a sentinel to ensure the last section gets flushed properly
8023 lines += [' dummy contents:']
8024
8025 curr_section_name = ''
8026 curr_section_start = -1
8027 for i, line in enumerate(lines):
8028 if ' contents:' in line:
8029 if curr_section_start >= 0:
8030 # a new section, a line like ".debug_str contents:"
8031 sections[curr_section_name] = '\n'.join(lines[curr_section_start:i])
8032 curr_section_name = line.split(' ')[0]
8033 curr_section_start = i + 1
8034
8035 # make sure the right sections exist
8036 self.assertIn('.debug_abbrev', sections)
8037 self.assertIn('.debug_info', sections)
8038 self.assertIn('.debug_line', sections)
8039 self.assertIn('.debug_str', sections)
8040 self.assertIn('.debug_ranges', sections)
8041
8042 # verify some content in the sections
8043 self.assertIn('"test_dwarf.c"', sections['.debug_info'])
8044 # the line section looks like this:
8045 # Address Line Column File ISA Discriminator Flags
8046 # ------------------ ------ ------ ------ --- ------------- -------------
8047 # 0x000000000000000b 5 0 3 0 0 is_stmt
8048 src_to_addr = {}
8049 found_dwarf_c = False
8050 for line in sections['.debug_line'].splitlines():
8051 if 'name: "test_dwarf.c"' in line:
8052 found_dwarf_c = True
8053 if not found_dwarf_c:
8054 continue
8055 if 'debug_line' in line:
8056 break
8057 if line.startswith('0x'):
8058 while ' ' in line:
8059 line = line.replace(' ', ' ')
8060 addr, line, col = line.split(' ')[:3]
8061 key = (int(line), int(col))
8062 src_to_addr.setdefault(key, []).append(addr)
8063
8064 # each of the calls must remain in the binary, and be mapped
8065 self.assertIn((6, 3), src_to_addr)
8066 self.assertIn((7, 3), src_to_addr)

Callers

nothing calls this directly

Calls 8

is_optimizingMethod · 0.95
copy_assetFunction · 0.90
appendMethod · 0.80
emccMethod · 0.80
run_processMethod · 0.80
splitMethod · 0.80
rangeFunction · 0.50
joinMethod · 0.45

Tested by

no test coverage detected