From a74e9cd840e70cf6350b0c0d971a4316e7c3ee9e Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 23 Jan 2020 14:11:15 -0800 Subject: DWARF: Update .debug_loc (#2616) Add support for that section to the YAML layer, and add code to update it. The updating is slightly tricky - unlike .debug_ranges, the size of entries is not fixed. So we can't just skip entries, as the end marker is smaller than a normal entry. Instead, replace now-invalid segments with (1, 1) which is of size 0 and so should be ignored by the debugger (we can't use (0, 0) as that would be an end marker, and (-1, *) is the special base marker). In the future we probably do want to do this in a more sophisticated manner, completely rewriting the indexes into the section as well. For now though this should be enough for when binaryen does not optimize (as we don't move/reorder anything). Note that this doesn't update the location description (like where on the wasm expression stack the value is). Again, that is correct for when binaryen doesn't optimize, but for fully optimized builds we would need to track things (which would be hard!). Also clean up some code that uses "Extra" instead of "Delimiter" that was missed before, and shorten some unnecessarily long names. --- third_party/llvm-project/dwarf2yaml.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'third_party/llvm-project/dwarf2yaml.cpp') diff --git a/third_party/llvm-project/dwarf2yaml.cpp b/third_party/llvm-project/dwarf2yaml.cpp index 7d5f2e048..994be5511 100644 --- a/third_party/llvm-project/dwarf2yaml.cpp +++ b/third_party/llvm-project/dwarf2yaml.cpp @@ -105,6 +105,34 @@ void dumpDebugRanges(DWARFContext &DCtx, DWARFYAML::Data &Y) { // XXX BINARYEN } } +void dumpDebugLoc(DWARFContext &DCtx, DWARFYAML::Data &Y) { // XXX BINARYEN + uint8_t savedAddressByteSize = 4; + DWARFDataExtractor locsData(DCtx.getDWARFObj(), DCtx.getDWARFObj().getLocSection(), + DCtx.isLittleEndian(), savedAddressByteSize); + uint64_t offset = 0; + DWARFDebugLoc locList; + while (locsData.isValidOffset(offset)) { + auto list = locList.parseOneLocationList(locsData, &offset); + if (!list) { + errs() << "debug_loc error\n"; + break; + } + for (auto& entry : list.get().Entries) { + DWARFYAML::Loc loc; + loc.Start = entry.Begin; + loc.End = entry.End; + for (auto x : entry.Loc) { + loc.Location.push_back(x); + } + Y.Locs.push_back(loc); + } + DWARFYAML::Loc loc; + loc.Start = 0; + loc.End = 0; + Y.Locs.push_back(loc); + } +} + void dumpPubSection(DWARFContext &DCtx, DWARFYAML::PubSection &Y, DWARFSection Section) { DWARFDataExtractor PubSectionData(DCtx.getDWARFObj(), Section, @@ -380,6 +408,7 @@ std::error_code dwarf2yaml(DWARFContext &DCtx, DWARFYAML::Data &Y) { dumpDebugStrings(DCtx, Y); dumpDebugARanges(DCtx, Y); dumpDebugRanges(DCtx, Y); // XXX BINARYEN + dumpDebugLoc(DCtx, Y); // XXX BINARYEN dumpDebugPubSections(DCtx, Y); dumpDebugInfo(DCtx, Y); dumpDebugLines(DCtx, Y); -- cgit v1.2.3