LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
10 #include "DWARFDebugLoc.h"
11 #include "llvm/Support/Compiler.h"
12 #include "llvm/Support/Format.h"
14 
15 using namespace llvm;
16 
18  for (LocationLists::const_iterator I = Locations.begin(), E = Locations.end(); I != E; ++I) {
19  OS << format("0x%8.8x: ", I->Offset);
20  const unsigned Indent = 12;
21  for (SmallVectorImpl<Entry>::const_iterator I2 = I->Entries.begin(), E2 = I->Entries.end(); I2 != E2; ++I2) {
22  if (I2 != I->Entries.begin())
23  OS.indent(Indent);
24  OS << "Beginning address offset: " << format("0x%016" PRIx64, I2->Begin)
25  << '\n';
26  OS.indent(Indent) << " Ending address offset: "
27  << format("0x%016" PRIx64, I2->End) << '\n';
28  OS.indent(Indent) << " Location description: ";
29  for (SmallVectorImpl<unsigned char>::const_iterator I3 = I2->Loc.begin(), E3 = I2->Loc.end(); I3 != E3; ++I3) {
30  OS << format("%2.2x ", *I3);
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)) {
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.reserve(str.size());
70  std::copy(str.begin(), str.end(), std::back_inserter(E.Loc));
71  Loc.Entries.push_back(llvm_move(E));
72  }
73  }
74 }
StringRef getData() const
Get the data pointed to by this extractor.
Definition: DataExtractor.h:32
size_t size() const
size - Get the string size.
Definition: StringRef.h:113
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
StringRef substr(size_t Start, size_t N=npos) const
Definition: StringRef.h:392
void parse(DataExtractor data, unsigned AddressSize)
bool isValidOffset(uint32_t offset) const
#define llvm_move(value)
Definition: Compiler.h:108
format_object1< T > format(const char *Fmt, const T &Val)
Definition: Format.h:180
iterator begin() const
Definition: StringRef.h:97
* if(!EatIfPresent(lltok::kw_thread_local)) return false
iterator end()
Definition: DenseMap.h:57
uint16_t getU16(uint32_t *offset_ptr) const
void dump(raw_ostream &OS) const
Print the location lists found within the debug_loc section.
#define I(x, y, z)
Definition: MD5.cpp:54
void resize(unsigned N)
Definition: SmallVector.h:401
iterator end() const
Definition: StringRef.h:99
uint64_t getUnsigned(uint32_t *offset_ptr, uint32_t byte_size) const
iterator find(const KeyT &Val)
Definition: DenseMap.h:108