• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- llvm/unittest/DebugInfo/DWARFFormValueTest.cpp ---------------------===//
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 #include "llvm/DebugInfo/DWARFFormValue.h"
11 #include "llvm/Support/Dwarf.h"
12 #include "gtest/gtest.h"
13 using namespace llvm;
14 using namespace dwarf;
15 
16 namespace {
17 
TEST(DWARFFormValue,FixedFormSizes)18 TEST(DWARFFormValue, FixedFormSizes) {
19   // Size of DW_FORM_addr and DW_FORM_ref_addr are equal in DWARF2,
20   // DW_FORM_ref_addr is always 4 bytes in DWARF32 starting from DWARF3.
21   ArrayRef<uint8_t> sizes = DWARFFormValue::getFixedFormSizes(4, 2);
22   EXPECT_EQ(sizes[DW_FORM_addr], sizes[DW_FORM_ref_addr]);
23   sizes = DWARFFormValue::getFixedFormSizes(8, 2);
24   EXPECT_EQ(sizes[DW_FORM_addr], sizes[DW_FORM_ref_addr]);
25   sizes = DWARFFormValue::getFixedFormSizes(8, 3);
26   EXPECT_EQ(4, sizes[DW_FORM_ref_addr]);
27   // Check that we don't have fixed form sizes for weird address sizes.
28   EXPECT_EQ(0U, DWARFFormValue::getFixedFormSizes(16, 2).size());
29 }
30 
isFormClass(uint16_t Form,DWARFFormValue::FormClass FC)31 bool isFormClass(uint16_t Form, DWARFFormValue::FormClass FC) {
32   return DWARFFormValue(Form).isFormClass(FC);
33 }
34 
TEST(DWARFFormValue,FormClass)35 TEST(DWARFFormValue, FormClass) {
36   EXPECT_TRUE(isFormClass(DW_FORM_addr, DWARFFormValue::FC_Address));
37   EXPECT_FALSE(isFormClass(DW_FORM_data8, DWARFFormValue::FC_Address));
38   EXPECT_TRUE(isFormClass(DW_FORM_data8, DWARFFormValue::FC_Constant));
39   EXPECT_TRUE(isFormClass(DW_FORM_data8, DWARFFormValue::FC_SectionOffset));
40   EXPECT_TRUE(
41       isFormClass(DW_FORM_sec_offset, DWARFFormValue::FC_SectionOffset));
42   EXPECT_TRUE(isFormClass(DW_FORM_GNU_str_index, DWARFFormValue::FC_String));
43   EXPECT_TRUE(isFormClass(DW_FORM_GNU_addr_index, DWARFFormValue::FC_Address));
44   EXPECT_FALSE(isFormClass(DW_FORM_ref_addr, DWARFFormValue::FC_Address));
45   EXPECT_TRUE(isFormClass(DW_FORM_ref_addr, DWARFFormValue::FC_Reference));
46   EXPECT_TRUE(isFormClass(DW_FORM_ref_sig8, DWARFFormValue::FC_Reference));
47 }
48 
49 } // end anonymous namespace
50