Commit dca2b36b authored by Pavel Labath's avatar Pavel Labath
Browse files

Re-commit "DWARF location lists: Add section index dumping"

This reapplies c0f6ad7d with an
additional fix in test/DebugInfo/X86/constant-loclist.ll, which had a
slightly different output on windows targets. The test now accounts for
this difference.

The original commit message follows.

Summary:
As discussed in D70081, this adds the ability to dump section
names/indices to the location list dumper. It does this by moving the
range specific logic from DWARFDie.cpp:dumpRanges into the
DWARFAddressRange class.

The trickiest part of this patch is the backflip in the meanings of the
two dump flags for the location list sections.

The dumping of "raw" location list data is now controlled by
"DisplayRawContents" flag. This frees up the "Verbose" flag to be used
to control whether we print the section index. Additionally, the
DisplayRawContents flag is set for section-based dumps whenever the
--verbose option is passed, but this is not done for the "inline" dumps.

Also note that the index dumping currently does not work for the DWARF
v5 location lists, as the parser does not fill out the appropriate
fields. This will be done in a separate patch.

Reviewers: dblaikie, probinson, JDevlieghere, SouraVX

Subscribers: sdardis, hiraditya, jrtc27, atanasyan, arphaman, aprantl, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D70227
parent edd9f701
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
namespace llvm {

class raw_ostream;
class DWARFObject;

struct DWARFAddressRange {
  uint64_t LowPC;
@@ -26,7 +27,9 @@ struct DWARFAddressRange {
  DWARFAddressRange() = default;

  /// Used for unit testing.
  DWARFAddressRange(uint64_t LowPC, uint64_t HighPC, uint64_t SectionIndex = 0)
  DWARFAddressRange(
      uint64_t LowPC, uint64_t HighPC,
      uint64_t SectionIndex = object::SectionedAddress::UndefSection)
      : LowPC(LowPC), HighPC(HighPC), SectionIndex(SectionIndex) {}

  /// Returns true if LowPC is smaller or equal to HighPC. This accounts for
@@ -42,8 +45,8 @@ struct DWARFAddressRange {
    return LowPC < RHS.HighPC && RHS.LowPC < HighPC;
  }

  void dump(raw_ostream &OS, uint32_t AddressSize,
            DIDumpOptions DumpOpts = {}) const;
  void dump(raw_ostream &OS, uint32_t AddressSize, DIDumpOptions DumpOpts = {},
            const DWARFObject *Obj = nullptr) const;
};

static inline bool operator<(const DWARFAddressRange &LHS,
+6 −2
Original line number Diff line number Diff line
@@ -7,19 +7,23 @@
//===----------------------------------------------------------------------===//

#include "llvm/DebugInfo/DWARF/DWARFAddressRange.h"

#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

void DWARFAddressRange::dump(raw_ostream &OS, uint32_t AddressSize,
                             DIDumpOptions DumpOpts) const {
                             DIDumpOptions DumpOpts,
                             const DWARFObject *Obj) const {

  OS << (DumpOpts.DisplayRawContents ? " " : "[");
  OS << format("0x%*.*" PRIx64 ", ", AddressSize * 2, AddressSize * 2, LowPC)
     << format("0x%*.*" PRIx64, AddressSize * 2, AddressSize * 2, HighPC);
  OS << (DumpOpts.DisplayRawContents ? "" : ")");

  if (Obj)
    DWARFFormValue::dumpAddressSection(*Obj, OS, DumpOpts, SectionIndex);
}

raw_ostream &llvm::operator<<(raw_ostream &OS, const DWARFAddressRange &R) {
+9 −4
Original line number Diff line number Diff line
@@ -388,16 +388,20 @@ void DWARFContext::dump(
      dumpDebugType(".debug_types.dwo", dwo_types_section_units());
  }

  DIDumpOptions LLDumpOpts = DumpOpts;
  if (LLDumpOpts.Verbose)
    LLDumpOpts.DisplayRawContents = true;

  if (const auto *Off = shouldDump(Explicit, ".debug_loc", DIDT_ID_DebugLoc,
                                   DObj->getLocSection().Data)) {
    getDebugLoc()->dump(OS, getRegisterInfo(), DumpOpts, *Off);
    getDebugLoc()->dump(OS, getRegisterInfo(), LLDumpOpts, *Off);
  }
  if (const auto *Off =
          shouldDump(Explicit, ".debug_loclists", DIDT_ID_DebugLoclists,
                     DObj->getLoclistsSection().Data)) {
    DWARFDataExtractor Data(*DObj, DObj->getLoclistsSection(), isLittleEndian(),
                            0);
    dumpLoclistsSection(OS, DumpOpts, Data, getRegisterInfo(), *Off);
    dumpLoclistsSection(OS, LLDumpOpts, Data, getRegisterInfo(), *Off);
  }
  if (const auto *Off =
          shouldDump(ExplicitDWO, ".debug_loc.dwo", DIDT_ID_DebugLoc,
@@ -409,10 +413,11 @@ void DWARFContext::dump(
      uint64_t Offset = **Off;
      Loc.dumpLocationList(&Offset, OS,
                           /*BaseAddr=*/None, getRegisterInfo(), nullptr,
                           DumpOpts, /*Indent=*/0);
                           LLDumpOpts, /*Indent=*/0);
      OS << "\n";
    } else {
      Loc.dumpRange(0, Data.getData().size(), OS, getRegisterInfo(), DumpOpts);
      Loc.dumpRange(0, Data.getData().size(), OS, getRegisterInfo(),
                    LLDumpOpts);
    }
  }

+9 −3
Original line number Diff line number Diff line
@@ -115,14 +115,20 @@ bool DWARFLocationTable::dumpLocationList(uint64_t *Offset, raw_ostream &OS,
  OS << format("0x%8.8" PRIx64 ": ", *Offset);
  Error E = visitLocationList(Offset, [&](const DWARFLocationEntry &E) {
    Expected<Optional<DWARFLocationExpression>> Loc = Interp.Interpret(E);
    if (!Loc || DumpOpts.Verbose)
    if (!Loc || DumpOpts.DisplayRawContents)
      dumpRawEntry(E, OS, Indent);
    if (Loc && *Loc) {
      OS << "\n";
      OS.indent(Indent);
      if (DumpOpts.Verbose)
      if (DumpOpts.DisplayRawContents)
        OS << "          => ";
      Loc.get()->Range->dump(OS, Data.getAddressSize(), DumpOpts);

      DIDumpOptions RangeDumpOpts(DumpOpts);
      RangeDumpOpts.DisplayRawContents = false;
      const DWARFObject *Obj = nullptr;
      if (U)
        Obj = &U->getContext().getDWARFObj();
      Loc.get()->Range->dump(OS, Data.getAddressSize(), RangeDumpOpts, Obj);
    }
    if (!Loc)
      consumeError(Loc.takeError());
+2 −11
Original line number Diff line number Diff line
@@ -62,16 +62,10 @@ static void dumpRanges(const DWARFObject &Obj, raw_ostream &OS,
  if (!DumpOpts.ShowAddresses)
    return;

  ArrayRef<SectionName> SectionNames;
  if (DumpOpts.Verbose)
    SectionNames = Obj.getSectionNames();

  for (const DWARFAddressRange &R : Ranges) {
    OS << '\n';
    OS.indent(Indent);
    R.dump(OS, AddressSize);

    DWARFFormValue::dumpAddressSection(Obj, OS, DumpOpts, R.SectionIndex);
    R.dump(OS, AddressSize, DumpOpts, &Obj);
  }
}

@@ -91,9 +85,6 @@ static void dumpLocation(raw_ostream &OS, DWARFFormValue &FormValue,
  }

  if (FormValue.isFormClass(DWARFFormValue::FC_SectionOffset)) {
    auto LLDumpOpts = DumpOpts;
    LLDumpOpts.Verbose = false;

    uint64_t Offset = *FormValue.getAsSectionOffset();

    if (FormValue.getForm() == DW_FORM_loclistx) {
@@ -104,7 +95,7 @@ static void dumpLocation(raw_ostream &OS, DWARFFormValue &FormValue,
        return;
    }
    U->getLocationTable().dumpLocationList(&Offset, OS, U->getBaseAddress(),
                                           MRI, U, LLDumpOpts, Indent);
                                           MRI, U, DumpOpts, Indent);
    return;
  }

Loading