LLVM  4.0.0
DWARFDebugLoc.cpp
Go to the documentation of this file.
1 //===-- DWARFDebugLoc.cpp -------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "llvm/Support/Dwarf.h"
12 #include "llvm/Support/Format.h"
14 
15 using namespace llvm;
16 
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())
23  OS.indent(Indent);
24  OS << "Beginning address offset: " << format("0x%016" PRIx64, E.Begin)
25  << '\n';
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);
31  }
32  OS << "\n\n";
33  }
34  }
35 }
36 
37 void DWARFDebugLoc::parse(DataExtractor data, unsigned AddressSize) {
38  uint32_t Offset = 0;
39  while (data.isValidOffset(Offset+AddressSize-1)) {
40  Locations.resize(Locations.size() + 1);
41  LocationList &Loc = Locations.back();
42  Loc.Offset = Offset;
43  // 2.6.2 Location Lists
44  // A location list entry consists of:
45  while (true) {
46  Entry E;
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;
52 
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;
58 
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)
63  break;
64 
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);
68  Offset += Bytes;
69  E.Loc.append(str.begin(), str.end());
70  Loc.Entries.push_back(std::move(E));
71  }
72  }
73  if (data.isValidOffset(Offset))
74  llvm::errs() << "error: failed to consume entire .debug_loc section\n";
75 }
76 
78  uint32_t Offset = 0;
79  while (data.isValidOffset(Offset)) {
80  Locations.resize(Locations.size() + 1);
81  LocationList &Loc = Locations.back();
82  Loc.Offset = Offset;
84  while ((Kind = static_cast<dwarf::LocationListEntry>(
85  data.getU8(&Offset))) != dwarf::DW_LLE_end_of_list) {
86 
87  if (Kind != dwarf::DW_LLE_startx_length) {
88  llvm::errs() << "error: dumping support for LLE of kind " << (int)Kind
89  << " not implemented\n";
90  return;
91  }
92 
93  Entry E;
94 
95  E.Start = data.getULEB128(&Offset);
96  E.Length = data.getU32(&Offset);
97 
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);
101  Offset += Bytes;
102  E.Loc.resize(str.size());
103  std::copy(str.begin(), str.end(), E.Loc.begin());
104 
105  Loc.Entries.push_back(std::move(E));
106  }
107  }
108 }
109 
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())
116  OS.indent(Indent);
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);
122  OS << "\n\n";
123  }
124  }
125 }
126 
MachineLoop * L
StringRef getData() const
Get the data pointed to by this extractor.
Definition: DataExtractor.h:31
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void dump(raw_ostream &OS) const
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
void parse(DataExtractor data, unsigned AddressSize)
Parse the debug_loc section accessible via the 'data' parameter using the specified address size to i...
bool isValidOffset(uint32_t offset) const
Test the validity of offset.
uint32_t getU32(uint32_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:135
void parse(DataExtractor data)
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
iterator begin() const
Definition: StringRef.h:103
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
iterator begin() const
Definition: LoopInfo.h:132
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
uint8_t getU8(uint32_t *offset_ptr) const
Extract a uint8_t value from *offset_ptr.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:587
uint32_t Offset
uint64_t getULEB128(uint32_t *offset_ptr) const
Extract a unsigned LEB128 value from *offset_ptr.
LocationListEntry
Constants for location lists in DWARF v5.
Definition: Dwarf.h:289
uint16_t getU16(uint32_t *offset_ptr) const
Extract a uint16_t value from *offset_ptr.
void dump(raw_ostream &OS) const
Print the location lists found within the debug_loc section.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
iterator end()
Definition: DenseMap.h:69
iterator find(const KeyT &Val)
Definition: DenseMap.h:127
const unsigned Kind
iterator end() const
Definition: StringRef.h:105
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
uint64_t getUnsigned(uint32_t *offset_ptr, uint32_t byte_size) const
Extract an unsigned integer of size byte_size from *offset_ptr.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
void resize(size_type N)
Definition: SmallVector.h:352