1 //===- DWARFAcceleratorTableTest.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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h" 10 #include "llvm/DebugInfo/DWARF/DWARFContext.h" 11 #include "gtest/gtest.h" 12 13 using namespace llvm; 14 15 namespace { 16 17 void ExpectDebugNamesExtractError(StringRef NamesSecData, StringRef StrSecData, 18 const char *ErrorMessage) { 19 DWARFSection NamesDWARFSection; 20 NamesDWARFSection.Data = NamesSecData; 21 StringMap<std::unique_ptr<MemoryBuffer>> Sections; 22 auto Context = DWARFContext::create(Sections, /* AddrSize = */ 4, 23 /* isLittleEndian = */ true); 24 DWARFDataExtractor NamesExtractor(Context->getDWARFObj(), NamesDWARFSection, 25 /* isLittleEndian = */ true, 26 /* AddrSize = */ 4); 27 DataExtractor StrExtractor(StrSecData, 28 /* isLittleEndian = */ true, 29 /* AddrSize = */ 4); 30 DWARFDebugNames Table(NamesExtractor, StrExtractor); 31 Error E = Table.extract(); 32 ASSERT_TRUE(E.operator bool()); 33 EXPECT_STREQ(ErrorMessage, toString(std::move(E)).c_str()); 34 } 35 36 TEST(DWARFDebugNames, ReservedUnitLength) { 37 static const char NamesSecData[64] = 38 "\xf0\xff\xff\xff"; // Reserved unit length value 39 ExpectDebugNamesExtractError(StringRef(NamesSecData, sizeof(NamesSecData)), 40 StringRef(), 41 "Unsupported reserved unit length value"); 42 } 43 44 TEST(DWARFDebugNames, TooSmallForDWARF64) { 45 // DWARF64 header takes at least 44 bytes. 46 static const char NamesSecData[43] = "\xff\xff\xff\xff"; // DWARF64 mark 47 ExpectDebugNamesExtractError( 48 StringRef(NamesSecData, sizeof(NamesSecData)), StringRef(), 49 "Section too small: cannot read header."); 50 } 51 52 } // end anonymous namespace 53