LLVM  4.0.0
DWARFTypeUnit.cpp
Go to the documentation of this file.
1 //===-- DWARFTypeUnit.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 
12 #include "llvm/Support/Dwarf.h"
13 #include "llvm/Support/Format.h"
15 
16 using namespace llvm;
17 
19  uint32_t *offset_ptr) {
20  if (!DWARFUnit::extractImpl(debug_info, offset_ptr))
21  return false;
22  TypeHash = debug_info.getU64(offset_ptr);
23  TypeOffset = debug_info.getU32(offset_ptr);
24  return TypeOffset < getLength();
25 }
26 
27 void DWARFTypeUnit::dump(raw_ostream &OS, bool SummarizeTypes) {
28  DWARFDie TD = getDIEForOffset(TypeOffset + getOffset());
29  const char *Name = TD.getAttributeValueAsString(llvm::dwarf::DW_AT_name, "");
30 
31  if (SummarizeTypes) {
32  OS << "name = '" << Name << "'"
33  << " type_signature = " << format("0x%16" PRIx64, TypeHash)
34  << " length = " << format("0x%08x", getLength()) << '\n';
35  return;
36  }
37 
38  OS << format("0x%08x", getOffset()) << ": Type Unit:"
39  << " length = " << format("0x%08x", getLength())
40  << " version = " << format("0x%04x", getVersion())
41  << " abbr_offset = " << format("0x%04x", getAbbreviations()->getOffset())
42  << " addr_size = " << format("0x%02x", getAddressByteSize())
43  << " name = '" << Name << "'"
44  << " type_signature = " << format("0x%16" PRIx64, TypeHash)
45  << " type_offset = " << format("0x%04x", TypeOffset)
46  << " (next unit at " << format("0x%08x", getNextUnitOffset()) << ")\n";
47 
48  if (DWARFDie TU = getUnitDIE(false))
49  TU.dump(OS, -1U);
50  else
51  OS << "<type unit can't be parsed!>\n\n";
52 }
uint32_t getNextUnitOffset() const
Definition: DWARFUnit.h:202
virtual bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr)
Definition: DWARFUnit.cpp:87
const DWARFAbbreviationDeclarationSet * getAbbreviations() const
Definition: DWARFUnit.h:208
uint32_t getLength() const
Definition: DWARFUnit.h:203
uint32_t getU32(uint32_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
const char * getAttributeValueAsString(dwarf::Attribute Attr, const char *FailValue) const
Extract the specified attribute from this DIE as a C string.
Definition: DWARFDie.cpp:146
uint16_t getVersion() const
Definition: DWARFUnit.h:204
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
Utility class that carries the DWARF compile/type unit and the debug info entry in an object...
Definition: DWARFDie.h:36
bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr) override
uint64_t getU64(uint32_t *offset_ptr) const
Extract a uint64_t value from *offset_ptr.
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
Definition: DWARFUnit.h:228
void dump(raw_ostream &OS, bool Brief=false)
uint32_t getOffset() const
Definition: DWARFUnit.h:201
uint8_t getAddressByteSize() const
Definition: DWARFUnit.h:211
DWARFDie getDIEForOffset(uint32_t Offset)
Return the DIE object for a given offset inside the unit's DIE vector.
Definition: DWARFUnit.h:279
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44