LLVM  3.7.0
DWARFFormValue.h
Go to the documentation of this file.
1 //===-- DWARFFormValue.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_DWARFFORMVALUE_H
11 #define LLVM_DEBUGINFO_DWARFFORMVALUE_H
12 
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/Optional.h"
16 
17 namespace llvm {
18 
19 class DWARFUnit;
20 class raw_ostream;
21 
23 public:
24  enum FormClass {
35  };
36 
37 private:
38  struct ValueType {
39  ValueType() : data(nullptr) {
40  uval = 0;
41  }
42 
43  union {
44  uint64_t uval;
45  int64_t sval;
46  const char* cstr;
47  };
48  const uint8_t* data;
49  };
50 
51  uint16_t Form; // Form for this value.
52  ValueType Value; // Contains all data for the form.
53 
54 public:
55  DWARFFormValue(uint16_t Form = 0) : Form(Form) {}
56  uint16_t getForm() const { return Form; }
57  bool isFormClass(FormClass FC) const;
58 
59  void dump(raw_ostream &OS, const DWARFUnit *U) const;
60 
61  /// \brief extracts a value in data at offset *offset_ptr.
62  ///
63  /// The passed DWARFUnit is allowed to be nullptr, in which
64  /// case no relocation processing will be performed and some
65  /// kind of forms that depend on Unit information are disallowed.
66  /// \returns whether the extraction succeeded.
67  bool extractValue(DataExtractor data, uint32_t *offset_ptr,
68  const DWARFUnit *u);
69  bool isInlinedCStr() const {
70  return Value.data != nullptr && Value.data == (const uint8_t*)Value.cstr;
71  }
72 
73  /// getAsFoo functions below return the extracted value as Foo if only
74  /// DWARFFormValue has form class is suitable for representing Foo.
82 
83  bool skipValue(DataExtractor debug_info_data, uint32_t *offset_ptr,
84  const DWARFUnit *u) const;
85  static bool skipValue(uint16_t form, DataExtractor debug_info_data,
86  uint32_t *offset_ptr, const DWARFUnit *u);
87 
88  static ArrayRef<uint8_t> getFixedFormSizes(uint8_t AddrSize,
89  uint16_t Version);
90 private:
91  void dumpString(raw_ostream &OS, const DWARFUnit *U) const;
92 };
93 
94 }
95 
96 #endif
Optional< const char * > getAsCString(const DWARFUnit *U) const
DWARFFormValue(uint16_t Form=0)
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
static ArrayRef< uint8_t > getFixedFormSizes(uint8_t AddrSize, uint16_t Version)
void dump(raw_ostream &OS, const DWARFUnit *U) const
bool skipValue(DataExtractor debug_info_data, uint32_t *offset_ptr, const DWARFUnit *u) const
Optional< ArrayRef< uint8_t > > getAsBlock() const
bool extractValue(DataExtractor data, uint32_t *offset_ptr, const DWARFUnit *u)
extracts a value in data at offset *offset_ptr.
uint16_t getForm() const
Optional< uint64_t > getAsReference(const DWARFUnit *U) const
getAsFoo functions below return the extracted value as Foo if only DWARFFormValue has form class is s...
bool isInlinedCStr() const
Optional< uint64_t > getAsUnsignedConstant() const
bool isFormClass(FormClass FC) const
Optional< int64_t > getAsSignedConstant() const
Optional< uint64_t > getAsSectionOffset() const
LLVM Value Representation.
Definition: Value.h:69
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
Optional< uint64_t > getAsAddress(const DWARFUnit *U) const