Index: unittests/DebugInfo/DWARF/CMakeLists.txt =================================================================== --- unittests/DebugInfo/DWARF/CMakeLists.txt +++ unittests/DebugInfo/DWARF/CMakeLists.txt @@ -6,6 +6,7 @@ Object ObjectYAML Support + TestingSupport ) set(DebugInfoSources Index: unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp =================================================================== --- unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp +++ unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp @@ -29,6 +29,8 @@ #include "llvm/Support/Error.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/TargetSelect.h" +#include "llvm/Support/TargetRegistry.h" +#include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" #include #include @@ -61,28 +63,19 @@ return PT; } -/// Take any llvm::Expected and check and handle any errors. -/// -/// \param Expected a llvm::Excepted instance to check. -/// \returns true if there were errors, false otherwise. -template -static bool HandleExpectedError(T &Expected) { - std::string ErrorMsg; - handleAllErrors(Expected.takeError(), [&](const ErrorInfoBase &EI) { - ErrorMsg = EI.message(); - }); - if (!ErrorMsg.empty()) { - ::testing::AssertionFailure() << "error: " << ErrorMsg; - return true; - } - return false; +static bool isConfigurationSupported(Triple &T) { + initLLVMIfNeeded(); + std::string Err; + return TargetRegistry::lookupTarget(T.getTriple(), Err); } template void TestAllForms() { - // Test that we can decode all DW_FORM values correctly. + Triple Triple = getHostTripleForAddrSize(sizeof(AddrType)); + if (!isConfigurationSupported(Triple)) + return; - const uint8_t AddrSize = sizeof(AddrType); + // Test that we can decode all DW_FORM values correctly. const AddrType AddrValue = (AddrType)0x0123456789abcdefULL; const uint8_t BlockData[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; const uint32_t BlockSize = sizeof(BlockData); @@ -101,11 +94,9 @@ const uint32_t Dwarf32Values[] = {1, 2, 3, 4, 5, 6, 7, 8}; const char *StringValue = "Hello"; const char *StrpValue = "World"; - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); + auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); dwarfgen::DIE CUDie = CU.getUnitDIE(); @@ -431,16 +422,16 @@ } template void TestChildren() { + Triple Triple = getHostTripleForAddrSize(sizeof(AddrType)); + if (!isConfigurationSupported(Triple)) + return; + // Test that we can decode DW_FORM_ref_addr values correctly in DWARF 2 with // 4 byte addresses. DW_FORM_ref_addr values should be 4 bytes when using // 8 byte addresses. - const uint8_t AddrSize = sizeof(AddrType); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); dwarfgen::DIE CUDie = CU.getUnitDIE(); @@ -555,14 +546,13 @@ } template void TestReferences() { - // Test that we can decode DW_FORM_refXXX values correctly in DWARF. + Triple Triple = getHostTripleForAddrSize(sizeof(AddrType)); + if (!isConfigurationSupported(Triple)) + return; - const uint8_t AddrSize = sizeof(AddrType); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); + // Test that we can decode DW_FORM_refXXX values correctly in DWARF. auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU1 = DG->addCompileUnit(); dwarfgen::CompileUnit &CU2 = DG->addCompileUnit(); @@ -804,15 +794,15 @@ } template void TestAddresses() { + Triple Triple = getHostTripleForAddrSize(sizeof(AddrType)); + if (!isConfigurationSupported(Triple)) + return; + // Test the DWARF APIs related to accessing the DW_AT_low_pc and // DW_AT_high_pc. - const uint8_t AddrSize = sizeof(AddrType); const bool SupportsHighPCAsOffset = Version >= 4; - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); dwarfgen::DIE CUDie = CU.getUnitDIE(); @@ -975,16 +965,15 @@ } TEST(DWARFDebugInfo, TestRelations) { + Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + if (!isConfigurationSupported(Triple)) + return; + // Test the DWARF APIs related to accessing the DW_AT_low_pc and // DW_AT_high_pc. uint16_t Version = 4; - - const uint8_t AddrSize = sizeof(void *); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); @@ -1106,16 +1095,15 @@ } TEST(DWARFDebugInfo, TestChildIterators) { + Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + if (!isConfigurationSupported(Triple)) + return; + // Test the DWARF APIs related to iterating across the children of a DIE using // the DWARFDie::iterator class. uint16_t Version = 4; - - const uint8_t AddrSize = sizeof(void *); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); @@ -1218,16 +1206,15 @@ } TEST(DWARFDebugInfo, TestAttributeIterators) { + Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + if (!isConfigurationSupported(Triple)) + return; + // Test the DWARF APIs related to iterating across all attribute values in a // a DWARFDie. uint16_t Version = 4; - - const uint8_t AddrSize = sizeof(void *); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); const uint64_t CULowPC = 0x1000; @@ -1280,14 +1267,13 @@ } TEST(DWARFDebugInfo, TestFindRecurse) { - uint16_t Version = 4; + Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + if (!isConfigurationSupported(Triple)) + return; - const uint8_t AddrSize = sizeof(void *); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); + uint16_t Version = 4; auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); @@ -1494,16 +1480,15 @@ } TEST(DWARFDebugInfo, TestFindAttrs) { + Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + if (!isConfigurationSupported(Triple)) + return; + // Test the DWARFDie::find() and DWARFDie::findRecursively() that take an // ArrayRef value to make sure they work correctly. uint16_t Version = 4; - - const uint8_t AddrSize = sizeof(void *); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); @@ -1557,14 +1542,13 @@ } TEST(DWARFDebugInfo, TestImplicitConstAbbrevs) { - uint16_t Version = 5; + Triple Triple = getHostTripleForAddrSize(sizeof(void *)); + if (!isConfigurationSupported(Triple)) + return; - const uint8_t AddrSize = sizeof(void *); - initLLVMIfNeeded(); - Triple Triple = getHostTripleForAddrSize(AddrSize); + uint16_t Version = 5; auto ExpectedDG = dwarfgen::Generator::create(Triple, Version); - if (HandleExpectedError(ExpectedDG)) - return; + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); dwarfgen::CompileUnit &CU = DG->addCompileUnit(); dwarfgen::DIE CUDie = CU.getUnitDIE(); @@ -2151,11 +2135,12 @@ } TEST(DWARFDebugInfo, TestErrorReportingPolicy) { - initLLVMIfNeeded(); - auto ExpectedDG = dwarfgen::Generator::create(Triple("x86_64-pc-linux"), - 4 /*DwarfVersion*/); - if (HandleExpectedError(ExpectedDG)) - return; + Triple Triple("x86_64-pc-linux"); + if (!isConfigurationSupported(Triple)) + return; + + auto ExpectedDG = dwarfgen::Generator::create(Triple, 4 /*DwarfVersion*/); + ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded()); dwarfgen::Generator *DG = ExpectedDG.get().get(); AsmPrinter *AP = DG->getAsmPrinter(); MCContext *MC = DG->getMCContext();