1 //===- DWARFDebugLoc.cpp --------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/StringRef.h"
11 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
12 #include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
13 #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
14 #include "llvm/Support/Dwarf.h"
15 #include "llvm/Support/Format.h"
16 #include "llvm/Support/raw_ostream.h"
23 void DWARFDebugLoc::dump(raw_ostream &OS) const {
24 for (const LocationList &L : Locations) {
25 OS << format("0x%8.8x: ", L.Offset);
26 const unsigned Indent = 12;
27 for (const Entry &E : L.Entries) {
28 if (&E != L.Entries.begin())
30 OS << "Beginning address offset: " << format("0x%016" PRIx64, E.Begin)
32 OS.indent(Indent) << " Ending address offset: "
33 << format("0x%016" PRIx64, E.End) << '\n';
34 OS.indent(Indent) << " Location description: ";
35 for (unsigned char Loc : E.Loc) {
36 OS << format("%2.2x ", Loc);
43 void DWARFDebugLoc::parse(DataExtractor data, unsigned AddressSize) {
45 while (data.isValidOffset(Offset+AddressSize-1)) {
46 Locations.resize(Locations.size() + 1);
47 LocationList &Loc = Locations.back();
49 // 2.6.2 Location Lists
50 // A location list entry consists of:
52 // A beginning and ending address offsets.
54 E.Begin = getRelocatedValue(data, AddressSize, &Offset, &RelocMap);
55 E.End = getRelocatedValue(data, AddressSize, &Offset, &RelocMap);
57 // The end of any given location list is marked by an end of list entry,
58 // which consists of a 0 for the beginning address offset and a 0 for the
59 // ending address offset.
60 if (E.Begin == 0 && E.End == 0)
63 unsigned Bytes = data.getU16(&Offset);
64 // A single location description describing the location of the object...
65 StringRef str = data.getData().substr(Offset, Bytes);
67 E.Loc.append(str.begin(), str.end());
68 Loc.Entries.push_back(std::move(E));
71 if (data.isValidOffset(Offset))
72 errs() << "error: failed to consume entire .debug_loc section\n";
75 void DWARFDebugLocDWO::parse(DataExtractor data) {
77 while (data.isValidOffset(Offset)) {
78 Locations.resize(Locations.size() + 1);
79 LocationList &Loc = Locations.back();
81 dwarf::LocationListEntry Kind;
82 while ((Kind = static_cast<dwarf::LocationListEntry>(
83 data.getU8(&Offset))) != dwarf::DW_LLE_end_of_list) {
85 if (Kind != dwarf::DW_LLE_startx_length) {
86 errs() << "error: dumping support for LLE of kind " << (int)Kind
87 << " not implemented\n";
93 E.Start = data.getULEB128(&Offset);
94 E.Length = data.getU32(&Offset);
96 unsigned Bytes = data.getU16(&Offset);
97 // A single location description describing the location of the object...
98 StringRef str = data.getData().substr(Offset, Bytes);
100 E.Loc.resize(str.size());
101 std::copy(str.begin(), str.end(), E.Loc.begin());
103 Loc.Entries.push_back(std::move(E));
108 void DWARFDebugLocDWO::dump(raw_ostream &OS) const {
109 for (const LocationList &L : Locations) {
110 OS << format("0x%8.8x: ", L.Offset);
111 const unsigned Indent = 12;
112 for (const Entry &E : L.Entries) {
113 if (&E != L.Entries.begin())
115 OS << "Beginning address index: " << E.Start << '\n';
116 OS.indent(Indent) << " Length: " << E.Length << '\n';
117 OS.indent(Indent) << " Location description: ";
118 for (unsigned char Loc : E.Loc)
119 OS << format("%2.2x ", Loc);