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/DebugInfo/DWARF/DWARFDebugLoc.h"
11 #include "llvm/Support/Dwarf.h"
12 #include "llvm/Support/Format.h"
13 #include "llvm/Support/raw_ostream.h"
17 void DWARFDebugLoc::dump(raw_ostream &OS) const {
18 for (const LocationList &L : Locations) {
19 OS << format("0x%8.8x: ", L.Offset);
20 const unsigned Indent = 12;
21 for (const Entry &E : L.Entries) {
22 if (&E != L.Entries.begin())
24 OS << "Beginning address offset: " << format("0x%016" PRIx64, E.Begin)
26 OS.indent(Indent) << " Ending address offset: "
27 << format("0x%016" PRIx64, E.End) << '\n';
28 OS.indent(Indent) << " Location description: ";
29 for (unsigned char Loc : E.Loc) {
30 OS << format("%2.2x ", Loc);
37 void DWARFDebugLoc::parse(DataExtractor data, unsigned AddressSize) {
39 while (data.isValidOffset(Offset+AddressSize-1)) {
40 Locations.resize(Locations.size() + 1);
41 LocationList &Loc = Locations.back();
43 // 2.6.2 Location Lists
44 // A location list entry consists of:
47 RelocAddrMap::const_iterator AI = RelocMap.find(Offset);
48 // 1. A beginning address offset. ...
49 E.Begin = data.getUnsigned(&Offset, AddressSize);
50 if (AI != RelocMap.end())
51 E.Begin += AI->second.second;
53 AI = RelocMap.find(Offset);
54 // 2. An ending address offset. ...
55 E.End = data.getUnsigned(&Offset, AddressSize);
56 if (AI != RelocMap.end())
57 E.End += AI->second.second;
59 // The end of any given location list is marked by an end of list entry,
60 // which consists of a 0 for the beginning address offset and a 0 for the
61 // ending address offset.
62 if (E.Begin == 0 && E.End == 0)
65 unsigned Bytes = data.getU16(&Offset);
66 // A single location description describing the location of the object...
67 StringRef str = data.getData().substr(Offset, Bytes);
69 E.Loc.append(str.begin(), str.end());
70 Loc.Entries.push_back(std::move(E));
73 if (data.isValidOffset(Offset))
74 llvm::errs() << "error: failed to consume entire .debug_loc section\n";
77 void DWARFDebugLocDWO::parse(DataExtractor data) {
79 while (data.isValidOffset(Offset)) {
80 Locations.resize(Locations.size() + 1);
81 LocationList &Loc = Locations.back();
83 dwarf::LocationListEntry Kind;
84 while ((Kind = static_cast<dwarf::LocationListEntry>(
85 data.getU8(&Offset))) != dwarf::DW_LLE_end_of_list) {
87 if (Kind != dwarf::DW_LLE_startx_length) {
88 llvm::errs() << "error: dumping support for LLE of kind " << (int)Kind
89 << " not implemented\n";
95 E.Start = data.getULEB128(&Offset);
96 E.Length = data.getU32(&Offset);
98 unsigned Bytes = data.getU16(&Offset);
99 // A single location description describing the location of the object...
100 StringRef str = data.getData().substr(Offset, Bytes);
102 E.Loc.resize(str.size());
103 std::copy(str.begin(), str.end(), E.Loc.begin());
105 Loc.Entries.push_back(std::move(E));
110 void DWARFDebugLocDWO::dump(raw_ostream &OS) const {
111 for (const LocationList &L : Locations) {
112 OS << format("0x%8.8x: ", L.Offset);
113 const unsigned Indent = 12;
114 for (const Entry &E : L.Entries) {
115 if (&E != L.Entries.begin())
117 OS << "Beginning address index: " << E.Start << '\n';
118 OS.indent(Indent) << " Length: " << E.Length << '\n';
119 OS.indent(Indent) << " Location description: ";
120 for (unsigned char Loc : E.Loc)
121 OS << format("%2.2x ", Loc);