LLVM  6.0.0svn
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 
15 #include "llvm/Support/Format.h"
17 #include <cinttypes>
18 
19 using namespace llvm;
20 
22  uint32_t *offset_ptr) {
23  if (!DWARFUnit::extractImpl(debug_info, offset_ptr))
24  return false;
25  TypeHash = debug_info.getU64(offset_ptr);
26  TypeOffset = debug_info.getU32(offset_ptr);
27  // TypeOffset is relative to the beginning of the header,
28  // so we have to account for the leading length field.
29  // FIXME: The size of the length field is 12 in DWARF64.
30  unsigned SizeOfLength = 4;
31  return TypeOffset < getLength() + SizeOfLength;
32 }
33 
35  DWARFDie TD = getDIEForOffset(TypeOffset + getOffset());
36  const char *Name = TD.getName(DINameKind::ShortName);
37 
38  if (DumpOpts.SummarizeTypes) {
39  OS << "name = '" << Name << "'"
40  << " type_signature = " << format("0x%016" PRIx64, TypeHash)
41  << " length = " << format("0x%08x", getLength()) << '\n';
42  return;
43  }
44 
45  OS << format("0x%08x", getOffset()) << ": Type Unit:"
46  << " length = " << format("0x%08x", getLength())
47  << " version = " << format("0x%04x", getVersion());
48  if (getVersion() >= 5)
49  OS << " unit_type = " << dwarf::UnitTypeString(getUnitType());
50  OS << " abbr_offset = " << format("0x%04x", getAbbreviations()->getOffset())
51  << " addr_size = " << format("0x%02x", getAddressByteSize())
52  << " name = '" << Name << "'"
53  << " type_signature = " << format("0x%016" PRIx64, TypeHash)
54  << " type_offset = " << format("0x%04x", TypeOffset)
55  << " (next unit at " << format("0x%08x", getNextUnitOffset()) << ")\n";
56 
57  if (DWARFDie TU = getUnitDIE(false))
58  TU.dump(OS, 0, DumpOpts);
59  else
60  OS << "<type unit can't be parsed!>\n\n";
61 }
const DWARFAbbreviationDeclarationSet * getAbbreviations() const
Definition: DWARFUnit.cpp:464
void dump(raw_ostream &OS, DIDumpOptions DumpOpts={})
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
uint32_t getNextUnitOffset() const
Definition: DWARFUnit.h:272
uint32_t getU32(uint32_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
uint8_t getAddressByteSize() const
Definition: DWARFUnit.h:278
uint16_t getVersion() const
Definition: DWARFUnit.h:276
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:153
Utility class that carries the DWARF compile/type unit and the debug info entry in an object...
Definition: DWARFDie.h:43
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:329
const char * getName(DINameKind Kind) const
Return the DIE name resolving DW_AT_sepcification or DW_AT_abstract_origin references if necessary...
Definition: DWARFDie.cpp:402
StringRef UnitTypeString(unsigned)
Definition: Dwarf.cpp:479
uint32_t getLength() const
Definition: DWARFUnit.h:273
virtual bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr)
Definition: DWARFUnit.cpp:92
uint32_t getOffset() const
Definition: DWARFUnit.h:271
uint8_t getUnitType() const
Definition: DWARFUnit.h:286
DWARFDie getDIEForOffset(uint32_t Offset)
Return the DIE object for a given offset inside the unit&#39;s DIE vector.
Definition: DWARFUnit.h:386
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44