1 //===- DWARFDebugLineTest.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 "DwarfGenerator.h" 11 #include "DwarfUtils.h" 12 #include "llvm/DebugInfo/DWARF/DWARFContext.h" 13 #include "llvm/DebugInfo/DWARF/DWARFDebugLine.h" 14 #include "llvm/Object/ObjectFile.h" 15 #include "llvm/Testing/Support/Error.h" 16 #include "gtest/gtest.h" 17 18 using namespace llvm; 19 using namespace dwarf; 20 using namespace object; 21 using namespace utils; 22 23 namespace { 24 25 struct DebugLineGenerator { 26 bool init() { 27 Triple T = getHostTripleForAddrSize(8); 28 if (!isConfigurationSupported(T)) 29 return false; 30 auto ExpectedGenerator = dwarfgen::Generator::create(T, 4); 31 if (ExpectedGenerator) 32 Generator.reset(ExpectedGenerator->release()); 33 return true; 34 } 35 36 std::unique_ptr<DWARFContext> createContext() { 37 if (!Generator) 38 return nullptr; 39 StringRef FileBytes = Generator->generate(); 40 MemoryBufferRef FileBuffer(FileBytes, "dwarf"); 41 auto Obj = object::ObjectFile::createObjectFile(FileBuffer); 42 if (Obj) 43 return DWARFContext::create(**Obj); 44 return nullptr; 45 } 46 47 std::unique_ptr<dwarfgen::Generator> Generator; 48 }; 49 50 TEST(DWARFDebugLine, GetLineTableAtInvalidOffset) { 51 DebugLineGenerator LineGen; 52 if (!LineGen.init()) 53 return; 54 55 DWARFDebugLine Line; 56 std::unique_ptr<DWARFContext> Context = LineGen.createContext(); 57 ASSERT_TRUE(Context != nullptr); 58 const DWARFObject &Obj = Context->getDWARFObj(); 59 DWARFDataExtractor LineData(Obj, Obj.getLineSection(), true, 8); 60 61 EXPECT_EQ(Line.getOrParseLineTable(LineData, 0, *Context, nullptr), nullptr); 62 } 63 64 } // end anonymous namespace 65