blob: 22ac0116646ef8c8257f1e9c0c18b969d7cc398e [file] [log] [blame]
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +00001//===-- 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/Support/DataExtractor.h"
14
15namespace llvm {
16
17class DWARFCompileUnit;
18class raw_ostream;
19
20class DWARFFormValue {
21public:
22 struct ValueType {
23 ValueType() : data(NULL) {
24 uval = 0;
25 }
26
27 union {
28 uint64_t uval;
29 int64_t sval;
30 const char* cstr;
31 };
32 const uint8_t* data;
33 };
34
35 enum {
36 eValueTypeInvalid = 0,
37 eValueTypeUnsigned,
38 eValueTypeSigned,
39 eValueTypeCStr,
40 eValueTypeBlock
41 };
42
43private:
44 uint16_t Form; // Form for this value.
45 ValueType Value; // Contains all data for the form.
46
47public:
48 DWARFFormValue(uint16_t form = 0) : Form(form) {}
49 uint16_t getForm() const { return Form; }
50 const ValueType& value() const { return Value; }
Benjamin Kramer34f864f2011-09-15 16:57:13 +000051 void dump(raw_ostream &OS, const DWARFCompileUnit* cu) const;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000052 bool extractValue(DataExtractor data, uint32_t *offset_ptr,
Benjamin Kramer4aa3fea2011-09-13 21:47:32 +000053 const DWARFCompileUnit *cu);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000054 bool isInlinedCStr() const {
55 return Value.data != NULL && Value.data == (uint8_t*)Value.cstr;
56 }
57 const uint8_t *BlockData() const;
58 uint64_t getReference(const DWARFCompileUnit* cu) const;
59
60 /// Resolve any compile unit specific references so that we don't need
61 /// the compile unit at a later time in order to work with the form
62 /// value.
63 bool resolveCompileUnitReferences(const DWARFCompileUnit* cu);
64 uint64_t getUnsigned() const { return Value.uval; }
65 int64_t getSigned() const { return Value.sval; }
66 const char *getAsCString(const DataExtractor *debug_str_data_ptr) const;
67 bool skipValue(DataExtractor debug_info_data, uint32_t *offset_ptr,
68 const DWARFCompileUnit *cu) const;
69 static bool skipValue(uint16_t form, DataExtractor debug_info_data,
70 uint32_t *offset_ptr, const DWARFCompileUnit *cu);
71 static bool isBlockForm(uint16_t form);
72 static bool isDataForm(uint16_t form);
73 static const uint8_t *getFixedFormSizesForAddressSize(uint8_t addr_size);
74};
75
76}
77
78#endif