1 //===- llvm/unittest/DebugInfo/DWARFDebugArangeSetTest.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/DWARFDebugArangeSet.h" 10 #include "gtest/gtest.h" 11 12 using namespace llvm; 13 14 namespace { 15 16 template <size_t SecSize> 17 void ExpectExtractError(const char (&SecDataRaw)[SecSize], 18 const char *ErrorMessage) { 19 DataExtractor Extractor(StringRef(SecDataRaw, SecSize - 1), 20 /* IsLittleEndian = */ true, 21 /* AddressSize = */ 4); 22 DWARFDebugArangeSet Set; 23 uint64_t Offset = 0; 24 Error E = Set.extract(Extractor, &Offset); 25 ASSERT_TRUE(E.operator bool()); 26 EXPECT_STREQ(ErrorMessage, toString(std::move(E)).c_str()); 27 } 28 29 TEST(DWARFDebugArangeSet, LengthExceedsSectionSize) { 30 static const char DebugArangesSecRaw[] = 31 "\x15\x00\x00\x00" // The length exceeds the section boundaries 32 "\x02\x00" // Version 33 "\x00\x00\x00\x00" // Debug Info Offset 34 "\x04" // Address Size 35 "\x00" // Segment Selector Size 36 "\x00\x00\x00\x00" // Padding 37 "\x00\x00\x00\x00" // Termination tuple 38 "\x00\x00\x00\x00"; 39 ExpectExtractError( 40 DebugArangesSecRaw, 41 "the length of address range table at offset 0x0 exceeds section size"); 42 } 43 44 TEST(DWARFDebugArangeSet, UnsupportedAddressSize) { 45 static const char DebugArangesSecRaw[] = 46 "\x0c\x00\x00\x00" // Length 47 "\x02\x00" // Version 48 "\x00\x00\x00\x00" // Debug Info Offset 49 "\x02" // Address Size (not supported) 50 "\x00" // Segment Selector Size 51 // No padding 52 "\x00\x00\x00\x00"; // Termination tuple 53 ExpectExtractError( 54 DebugArangesSecRaw, 55 "address range table at offset 0x0 has unsupported address size: 2 " 56 "(4 and 8 supported)"); 57 } 58 59 TEST(DWARFDebugArangeSet, NoTerminationEntry) { 60 static const char DebugArangesSecRaw[] = 61 "\x14\x00\x00\x00" // Length 62 "\x02\x00" // Version 63 "\x00\x00\x00\x00" // Debug Info Offset 64 "\x04" // Address Size 65 "\x00" // Segment Selector Size 66 "\x00\x00\x00\x00" // Padding 67 "\x00\x00\x00\x00" // Entry: Address 68 "\x01\x00\x00\x00" // Length 69 ; // No termination tuple 70 ExpectExtractError( 71 DebugArangesSecRaw, 72 "address range table at offset 0x0 is not terminated by null entry"); 73 } 74 75 } // end anonymous namespace 76