LLVM  3.7.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/Compiler.h"
12 #include "llvm/Support/Dwarf.h"
13 #include "llvm/Support/Format.h"
15 
16 using namespace llvm;
17 
19  for (const LocationList &L : Locations) {
20  OS << format("0x%8.8x: ", L.Offset);
21  const unsigned Indent = 12;
22  for (const Entry &E : L.Entries) {
23  if (&E != L.Entries.begin())
24  OS.indent(Indent);
25  OS << "Beginning address offset: " << format("0x%016" PRIx64, E.Begin)
26  << '\n';
27  OS.indent(Indent) << " Ending address offset: "
28  << format("0x%016" PRIx64, E.End) << '\n';
29  OS.indent(Indent) << " Location description: ";
30  for (unsigned char Loc : E.Loc) {
31  OS << format("%2.2x ", Loc);
32  }
33  OS << "\n\n";
34  }
35  }
36 }
37 
38 void DWARFDebugLoc::parse(DataExtractor data, unsigned AddressSize) {
39  uint32_t Offset = 0;
40  while (data.isValidOffset(Offset+AddressSize-1)) {
41  Locations.resize(Locations.size() + 1);
42  LocationList &Loc = Locations.back();
43  Loc.Offset = Offset;
44  // 2.6.2 Location Lists
45  // A location list entry consists of:
46  while (true) {
47  Entry E;
48  RelocAddrMap::const_iterator AI = RelocMap.find(Offset);
49  // 1. A beginning address offset. ...
50  E.Begin = data.getUnsigned(&Offset, AddressSize);
51  if (AI != RelocMap.end())
52  E.Begin += AI->second.second;
53 
54  AI = RelocMap.find(Offset);
55  // 2. An ending address offset. ...
56  E.End = data.getUnsigned(&Offset, AddressSize);
57  if (AI != RelocMap.end())
58  E.End += AI->second.second;
59 
60  // The end of any given location list is marked by an end of list entry,
61  // which consists of a 0 for the beginning address offset and a 0 for the
62  // ending address offset.
63  if (E.Begin == 0 && E.End == 0)
64  break;
65 
66  unsigned Bytes = data.getU16(&Offset);
67  // A single location description describing the location of the object...
68  StringRef str = data.getData().substr(Offset, Bytes);
69  Offset += Bytes;
70  E.Loc.append(str.begin(), str.end());
71  Loc.Entries.push_back(std::move(E));
72  }
73  }
74  if (data.isValidOffset(Offset))
75  llvm::errs() << "error: failed to consume entire .debug_loc section\n";
76 }
77 
79  uint32_t Offset = 0;
80  while (data.isValidOffset(Offset)) {
81  Locations.resize(Locations.size() + 1);
82  LocationList &Loc = Locations.back();
83  Loc.Offset = Offset;
85  while ((Kind = static_cast<dwarf::LocationListEntry>(
86  data.getU8(&Offset))) != dwarf::DW_LLE_end_of_list_entry) {
87 
89  llvm::errs() << "error: dumping support for LLE of kind " << (int)Kind
90  << " not implemented\n";
91  return;
92  }
93 
94  Entry E;
95 
96  E.Start = data.getULEB128(&Offset);
97  E.Length = data.getU32(&Offset);
98 
99  unsigned Bytes = data.getU16(&Offset);
100  // A single location description describing the location of the object...
101  StringRef str = data.getData().substr(Offset, Bytes);
102  Offset += Bytes;
103  E.Loc.resize(str.size());
104  std::copy(str.begin(), str.end(), E.Loc.begin());
105 
106  Loc.Entries.push_back(std::move(E));
107  }
108  }
109 }
110 
112  for (const LocationList &L : Locations) {
113  OS << format("0x%8.8x: ", L.Offset);
114  const unsigned Indent = 12;
115  for (const Entry &E : L.Entries) {
116  if (&E != L.Entries.begin())
117  OS.indent(Indent);
118  OS << "Beginning address index: " << E.Start << '\n';
119  OS.indent(Indent) << " Length: " << E.Length << '\n';
120  OS.indent(Indent) << " Location description: ";
121  for (unsigned char Loc : E.Loc)
122  OS << format("%2.2x ", Loc);
123  OS << "\n\n";
124  }
125  }
126 }
127 
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.
size_t size() const
size - Get the string size.
Definition: StringRef.h:113
void dump(raw_ostream &OS) const
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:405
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.
void parse(DataExtractor data)
iterator begin() const
Definition: StringRef.h:90
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:111
* 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.
uint64_t getULEB128(uint32_t *offset_ptr) const
Extract a unsigned LEB128 value from *offset_ptr.
LocationListEntry
Definition: Dwarf.h:493
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.
iterator end()
Definition: DenseMap.h:68
iterator find(const KeyT &Val)
Definition: DenseMap.h:124
const ARM::ArchExtKind Kind
iterator end() const
Definition: StringRef.h:92
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
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:40
void resize(size_type N)
Definition: SmallVector.h:376