LLVM  6.0.0svn
DWARFAcceleratorTable.h
Go to the documentation of this file.
1 //===- DWARFAcceleratorTable.h ----------------------------------*- C++ -*-===//
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 #ifndef LLVM_DEBUGINFO_DWARFACCELERATORTABLE_H
11 #define LLVM_DEBUGINFO_DWARFACCELERATORTABLE_H
12 
13 #include "llvm/ADT/SmallVector.h"
17 #include <cstdint>
18 #include <utility>
19 
20 namespace llvm {
21 
22 class raw_ostream;
23 
24 /// This implements the Apple accelerator table format, a precursor of the
25 /// DWARF 5 accelerator table format.
26 /// TODO: Factor out a common base class for both formats.
28  struct Header {
30  uint16_t Version;
31  uint16_t HashFunction;
32  uint32_t NumBuckets;
33  uint32_t NumHashes;
34  uint32_t HeaderDataLength;
35  };
36 
37  struct HeaderData {
38  using AtomType = uint16_t;
39  using Form = dwarf::Form;
40 
41  uint32_t DIEOffsetBase;
43  };
44 
45  struct Header Hdr;
46  struct HeaderData HdrData;
47  DWARFDataExtractor AccelSection;
48  DataExtractor StringSection;
49  bool IsValid = false;
50 
51 public:
52  /// An iterator for the entries associated with one key. Each entry can have
53  /// multiple DWARFFormValues.
54  class ValueIterator : public std::iterator<std::input_iterator_tag,
55  ArrayRef<DWARFFormValue>> {
56  const DWARFAcceleratorTable *AccelTable = nullptr;
57  SmallVector<DWARFFormValue, 3> AtomForms; ///< The decoded data entry.
58 
59  unsigned DataOffset = 0; ///< Offset into the section.
60  unsigned Data = 0; ///< Current data entry.
61  unsigned NumData = 0; ///< Number of data entries.
62 
63  /// Advance the iterator.
64  void Next();
65  public:
66  /// Construct a new iterator for the entries at \p DataOffset.
67  ValueIterator(const DWARFAcceleratorTable &AccelTable, unsigned DataOffset);
68  /// End marker.
69  ValueIterator() = default;
70 
72  return AtomForms;
73  }
74  ValueIterator &operator++() { Next(); return *this; }
76  ValueIterator I = *this;
77  Next();
78  return I;
79  }
80  friend bool operator==(const ValueIterator &A, const ValueIterator &B) {
81  return A.NumData == B.NumData && A.DataOffset == B.DataOffset;
82  }
83  friend bool operator!=(const ValueIterator &A, const ValueIterator &B) {
84  return !(A == B);
85  }
86  };
87 
88 
90  DataExtractor StringSection)
91  : AccelSection(AccelSection), StringSection(StringSection) {}
92 
93  bool extract();
99  bool validateForms();
100 
101  /// Return information related to the DWARF DIE we're looking for when
102  /// performing a lookup by name.
103  ///
104  /// \param HashDataOffset an offset into the hash data table
105  /// \returns <DieOffset, DieTag>
106  /// DieOffset is the offset into the .debug_info section for the DIE
107  /// related to the input hash data offset.
108  /// DieTag is the tag of the DIE
109  std::pair<uint32_t, dwarf::Tag> readAtoms(uint32_t &HashDataOffset);
110  void dump(raw_ostream &OS) const;
111 
112  /// Look up all entries in the accelerator table matching \c Key.
114 };
115 
116 } // end namespace llvm
117 
118 #endif // LLVM_DEBUGINFO_DWARFACCELERATORTABLE_H
This implements the Apple accelerator table format, a precursor of the DWARF 5 accelerator table form...
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
std::pair< uint32_t, dwarf::Tag > readAtoms(uint32_t &HashDataOffset)
Return information related to the DWARF DIE we&#39;re looking for when performing a lookup by name...
friend bool operator==(const ValueIterator &A, const ValueIterator &B)
Key
PAL metadata keys.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
DWARFAcceleratorTable(const DWARFDataExtractor &AccelSection, DataExtractor StringSection)
iterator_range< ValueIterator > equal_range(StringRef Key) const
Look up all entries in the accelerator table matching Key.
static const char *const Magic
Definition: Archive.cpp:42
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
ArrayRef< std::pair< HeaderData::AtomType, HeaderData::Form > > getAtomsDesc()
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:864
A range adaptor for a pair of iterators.
This file contains constants used for implementing Dwarf debug support.
const ArrayRef< DWARFFormValue > operator*() const
friend bool operator!=(const ValueIterator &A, const ValueIterator &B)
void dump(raw_ostream &OS) const
#define I(x, y, z)
Definition: MD5.cpp:58
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
An iterator for the entries associated with one key.
const uint64_t Version
Definition: InstrProf.h:867