brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.9 KiB · 702bd8c Raw
184 lines · cpp
1//===-- DWARF64UnitTest.cpp------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h"10#include "Plugins/SymbolFile/DWARF/DWARFUnit.h"11#include "TestingSupport/Symbol/YAMLModuleTester.h"12 13using namespace lldb_private;14using namespace lldb_private::plugin::dwarf;15using namespace llvm::dwarf;16 17TEST(DWARF64UnitTest, DWARF64DebugInfoAndCU) {18  const char *yamldata = R"(19--- !ELF20FileHeader:21  Class:   ELFCLASS6422  Data:    ELFDATA2LSB23  Type:    ET_EXEC24  Machine: EM_PPC6425DWARF:26  debug_str:27    - 'clang version 18.1.8 (clang-18.1.8-1)'28    - 'main'29  debug_abbrev:30    - Table:31        - Code:            0x132          Tag:             DW_TAG_compile_unit33          Children:        DW_CHILDREN_yes34          Attributes:35            - Attribute:       DW_AT_producer36              Form:            DW_FORM_strp37            - Attribute:       DW_AT_language38              Form:            DW_FORM_data239            - Attribute:       DW_AT_stmt_list 40              Form:            DW_FORM_sec_offset 41        - Code:            0x0242          Tag:             DW_TAG_subprogram 43          Children:        DW_CHILDREN_no44          Attributes:45            - Attribute:       DW_AT_name 46              Form:            DW_FORM_strp47  debug_info:48    - Format:          DWARF6449      Version:         450      AbbrOffset:      0x051      AddrSize:        852      Entries:53        - AbbrCode:        0x154          Values:55            - Value:           0x056            - Value:           0x0457            - Value:           0x058        - AbbrCode:        0x259          Values:60            - Value:           0x161        - AbbrCode:	   0x062)";63 64  YAMLModuleTester t(yamldata);65  auto *symbol_file =66      llvm::cast<SymbolFileDWARF>(t.GetModule()->GetSymbolFile());67  DWARFUnit *unit = symbol_file->DebugInfo().GetUnitAtIndex(0);68  ASSERT_TRUE(unit);69  ASSERT_EQ(unit->GetFormParams().Format, DwarfFormat::DWARF64);70  ASSERT_EQ(unit->GetVersion(), 4);71  ASSERT_EQ(unit->GetAddressByteSize(), 8);72 73  DWARFFormValue form_value;74  const DWARFDebugInfoEntry *cu_entry = unit->DIE().GetDIE();75  ASSERT_EQ(cu_entry->Tag(), DW_TAG_compile_unit);76  ASSERT_EQ(unit->GetProducer(), eProducerClang);77  ASSERT_EQ(unit->GetDWARFLanguageType(), DW_LANG_C_plus_plus);78  auto attrs = cu_entry->GetAttributes(unit, DWARFDebugInfoEntry::Recurse::yes);79  attrs.ExtractFormValueAtIndex(2, form_value); // Validate DW_AT_stmt_list80  ASSERT_EQ(form_value.Unsigned(), 0UL);81 82  DWARFDIE cu_die(unit, cu_entry);83  auto declaration = cu_die.GetFirstChild();84  ASSERT_TRUE(declaration.IsValid());85  ASSERT_EQ(declaration.Tag(), DW_TAG_subprogram);86}87 88TEST(DWARF64UnitTest, DWARF5StrTable) {89  const char *yamldata = R"(90--- !ELF91FileHeader:92  Class:   ELFCLASS6493  Data:    ELFDATA2MSB94  Type:    ET_EXEC95  Machine: EM_PPC6496DWARF:97  debug_str:98    - 'clang version 18.1.8 (clang-18.1.8-1)'99    - 'main.c'100    - 'foo'101    - 'main'102  debug_abbrev:103    - Table:104        - Code:            0x1105          Tag:             DW_TAG_compile_unit106          Children:        DW_CHILDREN_yes107          Attributes:108            - Attribute:       DW_AT_producer109              Form:            DW_FORM_strx1110            - Attribute:       DW_AT_language111              Form:            DW_FORM_data2112            - Attribute:       DW_AT_name113              Form:            DW_FORM_strx1114            - Attribute:       DW_AT_str_offsets_base115              Form:            DW_FORM_sec_offset116        - Code:            0x2117          Tag:             DW_TAG_subprogram118          Children:        DW_CHILDREN_no119          Attributes:120            - Attribute:       DW_AT_name121              Form:            DW_FORM_strx1122  debug_info:123    - Format:          DWARF64124      Version:         0x05125      UnitType:        DW_UT_compile126      AbbrOffset:      0x0127      AddrSize:        0x08128      Entries:129        - AbbrCode:        0x1130          Values:131            - Value:           0x0132            - Value:           0x04133            - Value:           0x1134            - Value:           0x00000010135        - AbbrCode:        0x2136          Values:137            - Value:           0x2138        - AbbrCode:        0x2139          Values:140            - Value:           0x3141        - AbbrCode:	   0x0142 143  debug_str_offsets:144    - Format:           DWARF64145      Version:          "0x05"146      Offsets:147          - 0x00000000148          - 0x00000026149          - 0x0000002d150          - 0x00000031151)";152 153  YAMLModuleTester t(yamldata);154  auto *symbol_file =155      llvm::cast<SymbolFileDWARF>(t.GetModule()->GetSymbolFile());156  DWARFUnit *unit = symbol_file->DebugInfo().GetUnitAtIndex(0);157  ASSERT_TRUE(unit);158  ASSERT_EQ(unit->GetFormParams().Format, DwarfFormat::DWARF64);159  ASSERT_EQ(unit->GetVersion(), 5);160  ASSERT_EQ(unit->GetAddressByteSize(), 8);161 162  DWARFFormValue form_value;163  const DWARFDebugInfoEntry *cu_entry = unit->DIE().GetDIE();164  ASSERT_EQ(cu_entry->Tag(), DW_TAG_compile_unit);165  ASSERT_EQ(unit->GetProducer(), eProducerClang);166  ASSERT_EQ(unit->GetDWARFLanguageType(), DW_LANG_C_plus_plus);167  auto attrs = cu_entry->GetAttributes(unit, DWARFDebugInfoEntry::Recurse::yes);168  attrs.ExtractFormValueAtIndex(3,169                                form_value); // Validate DW_AT_str_offsets_bae170  ASSERT_EQ(form_value.Unsigned(), 0x00000010UL);171  DWARFDIE cu_die(unit, cu_entry);172  ASSERT_EQ(ConstString(cu_die.GetName()), "main.c");173 174  auto func_foo = cu_die.GetFirstChild();175  ASSERT_TRUE(func_foo.IsValid());176  ASSERT_EQ(func_foo.Tag(), DW_TAG_subprogram);177  ASSERT_EQ(ConstString(func_foo.GetName()), "foo");178 179  auto func_main = func_foo.GetSibling();180  ASSERT_TRUE(func_main.IsValid());181  ASSERT_EQ(func_main.Tag(), DW_TAG_subprogram);182  ASSERT_EQ(ConstString(func_main.GetName()), "main");183}184