llvm.org GIT mirror llvm / cd61455
Create a stub for DWARF parser unittests Moves one DWARF-specific header to include/llvm/DebugInfo from lib/. Add a short unittest for r179095. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179678 91177308-0d34-0410-b5e6-96231b3b80d8 Alexey Samsonov 6 years ago
10 changed file(s) with 148 addition(s) and 86 deletion(s). Raw diff Collapse all Expand all
0 //===-- DWARFFormValue.h ----------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_DEBUGINFO_DWARFFORMVALUE_H
10 #define LLVM_DEBUGINFO_DWARFFORMVALUE_H
11
12 #include "llvm/Support/DataExtractor.h"
13
14 namespace llvm {
15
16 class DWARFCompileUnit;
17 class raw_ostream;
18
19 class DWARFFormValue {
20 public:
21 struct ValueType {
22 ValueType() : data(NULL) {
23 uval = 0;
24 }
25
26 union {
27 uint64_t uval;
28 int64_t sval;
29 const char* cstr;
30 };
31 const uint8_t* data;
32 };
33
34 enum {
35 eValueTypeInvalid = 0,
36 eValueTypeUnsigned,
37 eValueTypeSigned,
38 eValueTypeCStr,
39 eValueTypeBlock
40 };
41
42 private:
43 uint16_t Form; // Form for this value.
44 ValueType Value; // Contains all data for the form.
45
46 public:
47 DWARFFormValue(uint16_t form = 0) : Form(form) {}
48 uint16_t getForm() const { return Form; }
49 const ValueType& value() const { return Value; }
50 void dump(raw_ostream &OS, const DWARFCompileUnit* cu) const;
51 bool extractValue(DataExtractor data, uint32_t *offset_ptr,
52 const DWARFCompileUnit *cu);
53 bool isInlinedCStr() const {
54 return Value.data != NULL && Value.data == (const uint8_t*)Value.cstr;
55 }
56 const uint8_t *BlockData() const;
57 uint64_t getReference(const DWARFCompileUnit* cu) const;
58
59 /// Resolve any compile unit specific references so that we don't need
60 /// the compile unit at a later time in order to work with the form
61 /// value.
62 bool resolveCompileUnitReferences(const DWARFCompileUnit* cu);
63 uint64_t getUnsigned() const { return Value.uval; }
64 int64_t getSigned() const { return Value.sval; }
65 const char *getAsCString(const DataExtractor *debug_str_data_ptr) const;
66 const char *getIndirectCString(const DataExtractor *,
67 const DataExtractor *) const;
68 uint64_t getIndirectAddress(const DataExtractor *,
69 const DWARFCompileUnit *) const;
70 bool skipValue(DataExtractor debug_info_data, uint32_t *offset_ptr,
71 const DWARFCompileUnit *cu) const;
72 static bool skipValue(uint16_t form, DataExtractor debug_info_data,
73 uint32_t *offset_ptr, const DWARFCompileUnit *cu);
74 static bool isBlockForm(uint16_t form);
75 static bool isDataForm(uint16_t form);
76 static const uint8_t *getFixedFormSizes(uint8_t AddrSize, uint16_t Version);
77 };
78
79 }
80
81 #endif
88
99 #include "DWARFCompileUnit.h"
1010 #include "DWARFContext.h"
11 #include "DWARFFormValue.h"
11 #include "llvm/DebugInfo/DWARFFormValue.h"
1212 #include "llvm/Support/Dwarf.h"
1313 #include "llvm/Support/Format.h"
1414 #include "llvm/Support/raw_ostream.h"
1010 #include "DWARFCompileUnit.h"
1111 #include "DWARFContext.h"
1212 #include "DWARFDebugAbbrev.h"
13 #include "DWARFFormValue.h"
13 #include "llvm/DebugInfo/DWARFFormValue.h"
1414 #include "llvm/Support/Debug.h"
1515 #include "llvm/Support/Dwarf.h"
1616 #include "llvm/Support/Format.h"
66 //
77 //===----------------------------------------------------------------------===//
88
9 #include "DWARFFormValue.h"
9 #include "llvm/DebugInfo/DWARFFormValue.h"
1010 #include "DWARFCompileUnit.h"
1111 #include "DWARFContext.h"
1212 #include "llvm/Support/Debug.h"
+0
-82
lib/DebugInfo/DWARFFormValue.h less more
None //===-- DWARFFormValue.h ----------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_DEBUGINFO_DWARFFORMVALUE_H
10 #define LLVM_DEBUGINFO_DWARFFORMVALUE_H
11
12 #include "llvm/Support/DataExtractor.h"
13
14 namespace llvm {
15
16 class DWARFCompileUnit;
17 class raw_ostream;
18
19 class DWARFFormValue {
20 public:
21 struct ValueType {
22 ValueType() : data(NULL) {
23 uval = 0;
24 }
25
26 union {
27 uint64_t uval;
28 int64_t sval;
29 const char* cstr;
30 };
31 const uint8_t* data;
32 };
33
34 enum {
35 eValueTypeInvalid = 0,
36 eValueTypeUnsigned,
37 eValueTypeSigned,
38 eValueTypeCStr,
39 eValueTypeBlock
40 };
41
42 private:
43 uint16_t Form; // Form for this value.
44 ValueType Value; // Contains all data for the form.
45
46 public:
47 DWARFFormValue(uint16_t form = 0) : Form(form) {}
48 uint16_t getForm() const { return Form; }
49 const ValueType& value() const { return Value; }
50 void dump(raw_ostream &OS, const DWARFCompileUnit* cu) const;
51 bool extractValue(DataExtractor data, uint32_t *offset_ptr,
52 const DWARFCompileUnit *cu);
53 bool isInlinedCStr() const {
54 return Value.data != NULL && Value.data == (const uint8_t*)Value.cstr;
55 }
56 const uint8_t *BlockData() const;
57 uint64_t getReference(const DWARFCompileUnit* cu) const;
58
59 /// Resolve any compile unit specific references so that we don't need
60 /// the compile unit at a later time in order to work with the form
61 /// value.
62 bool resolveCompileUnitReferences(const DWARFCompileUnit* cu);
63 uint64_t getUnsigned() const { return Value.uval; }
64 int64_t getSigned() const { return Value.sval; }
65 const char *getAsCString(const DataExtractor *debug_str_data_ptr) const;
66 const char *getIndirectCString(const DataExtractor *,
67 const DataExtractor *) const;
68 uint64_t getIndirectAddress(const DataExtractor *,
69 const DWARFCompileUnit *) const;
70 bool skipValue(DataExtractor debug_info_data, uint32_t *offset_ptr,
71 const DWARFCompileUnit *cu) const;
72 static bool skipValue(uint16_t form, DataExtractor debug_info_data,
73 uint32_t *offset_ptr, const DWARFCompileUnit *cu);
74 static bool isBlockForm(uint16_t form);
75 static bool isDataForm(uint16_t form);
76 static const uint8_t *getFixedFormSizes(uint8_t AddrSize, uint16_t Version);
77 };
78
79 }
80
81 #endif
1212 add_subdirectory(Support)
1313 add_subdirectory(Transforms)
1414 add_subdirectory(IR)
15 add_subdirectory(DebugInfo)
0 set(LLVM_LINK_COMPONENTS
1 debuginfo
2 object
3 support
4 )
5
6 set(DebugInfoSources
7 DWARFFormValueTest.cpp
8 )
9
10 add_llvm_unittest(DebugInfoTests
11 ${DebugInfoSources}
12 )
0 //===- llvm/unittest/DebugInfo/DWARFFormValueTest.cpp ---------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/DebugInfo/DWARFFormValue.h"
10 #include "llvm/Support/Dwarf.h"
11 #include "gtest/gtest.h"
12 using namespace llvm;
13 using namespace dwarf;
14
15 namespace {
16
17 TEST(DWARFFormValue, FixedFormSizes) {
18 // Size of DW_FORM_addr and DW_FORM_ref_addr are equal in DWARF2,
19 // DW_FORM_ref_addr is always 4 bytes in DWARF32 starting from DWARF3.
20 const uint8_t *sizes = DWARFFormValue::getFixedFormSizes(4, 2);
21 EXPECT_EQ(sizes[DW_FORM_addr], sizes[DW_FORM_ref_addr]);
22 sizes = DWARFFormValue::getFixedFormSizes(8, 2);
23 EXPECT_EQ(sizes[DW_FORM_addr], sizes[DW_FORM_ref_addr]);
24 sizes = DWARFFormValue::getFixedFormSizes(8, 3);
25 EXPECT_EQ(4, sizes[DW_FORM_ref_addr]);
26 // Check that we don't have fixed form sizes for weird address sizes.
27 EXPECT_EQ(0, DWARFFormValue::getFixedFormSizes(16, 2));
28 }
29
30 } // end anonymous namespace
0 ##===- unittests/DebugInfo/Makefile ------------------------*- Makefile -*-===##
1 #
2 # The LLVM Compiler Infrastructure
3 #
4 # This file is distributed under the University of Illinois Open Source
5 # License. See LICENSE.TXT for details.
6 #
7 ##===----------------------------------------------------------------------===##
8
9 LEVEL = ../..
10 TESTNAME = DebugInfo
11 LINK_COMPONENTS := debuginfo object support
12
13 include $(LEVEL)/Makefile.config
14
15 include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
88
99 LEVEL = ..
1010
11 PARALLEL_DIRS = ADT ExecutionEngine Support Transforms IR Analysis Bitcode
11 PARALLEL_DIRS = ADT ExecutionEngine Support Transforms IR Analysis Bitcode \
12 DebugInfo
1213
1314 include $(LEVEL)/Makefile.common
1415