LLVM API Documentation
00001 //===-- DWARFFormValue.h ----------------------------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef LLVM_DEBUGINFO_DWARFFORMVALUE_H 00011 #define LLVM_DEBUGINFO_DWARFFORMVALUE_H 00012 00013 #include "llvm/ADT/ArrayRef.h" 00014 #include "llvm/ADT/Optional.h" 00015 #include "llvm/Support/DataExtractor.h" 00016 00017 namespace llvm { 00018 00019 class DWARFUnit; 00020 class raw_ostream; 00021 00022 class DWARFFormValue { 00023 public: 00024 enum FormClass { 00025 FC_Unknown, 00026 FC_Address, 00027 FC_Block, 00028 FC_Constant, 00029 FC_String, 00030 FC_Flag, 00031 FC_Reference, 00032 FC_Indirect, 00033 FC_SectionOffset, 00034 FC_Exprloc 00035 }; 00036 00037 private: 00038 struct ValueType { 00039 ValueType() : data(nullptr) { 00040 uval = 0; 00041 } 00042 00043 union { 00044 uint64_t uval; 00045 int64_t sval; 00046 const char* cstr; 00047 }; 00048 const uint8_t* data; 00049 }; 00050 00051 uint16_t Form; // Form for this value. 00052 ValueType Value; // Contains all data for the form. 00053 00054 public: 00055 DWARFFormValue(uint16_t Form = 0) : Form(Form) {} 00056 uint16_t getForm() const { return Form; } 00057 bool isFormClass(FormClass FC) const; 00058 00059 void dump(raw_ostream &OS, const DWARFUnit *U) const; 00060 bool extractValue(DataExtractor data, uint32_t *offset_ptr, 00061 const DWARFUnit *u); 00062 bool isInlinedCStr() const { 00063 return Value.data != nullptr && Value.data == (const uint8_t*)Value.cstr; 00064 } 00065 00066 /// getAsFoo functions below return the extracted value as Foo if only 00067 /// DWARFFormValue has form class is suitable for representing Foo. 00068 Optional<uint64_t> getAsReference(const DWARFUnit *U) const; 00069 Optional<uint64_t> getAsUnsignedConstant() const; 00070 Optional<const char *> getAsCString(const DWARFUnit *U) const; 00071 Optional<uint64_t> getAsAddress(const DWARFUnit *U) const; 00072 Optional<uint64_t> getAsSectionOffset() const; 00073 Optional<ArrayRef<uint8_t>> getAsBlock() const; 00074 00075 bool skipValue(DataExtractor debug_info_data, uint32_t *offset_ptr, 00076 const DWARFUnit *u) const; 00077 static bool skipValue(uint16_t form, DataExtractor debug_info_data, 00078 uint32_t *offset_ptr, const DWARFUnit *u); 00079 00080 static ArrayRef<uint8_t> getFixedFormSizes(uint8_t AddrSize, 00081 uint16_t Version); 00082 }; 00083 00084 } 00085 00086 #endif