llvm.org GIT mirror llvm / 61e059d
Revert r306512 "[ELF] - Add ability for DWARFContextInMemory to exit early when any error happen." It broke BB: [13/106] 13 0.022 Generating VCSRevision.h [25/106] 24 1.209 Building CXX object unittests/DebugInfo/DWARF/CMakeFiles/DebugInfoDWARFTests.dir/DWARFDebugInfoTest.cpp.o FAILED: unittests/DebugInfo/DWARF/CMakeFiles/DebugInfoDWARFTests.dir/DWARFDebugInfoTest.cpp.o /home/bb/bin/g++ -DGTEST_HAS_RTTI=0 -DLLVM_BUILD_GLOBAL_ISEL -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iunittests/DebugInfo/DWARF -I../llvm-project/llvm/unittests/DebugInfo/DWARF -Iinclude -I../llvm-project/llvm/include -I../llvm-project/llvm/utils/unittest/googletest/include -I../llvm-project/llvm/utils/unittest/googlemock/include -fPIC -fvisibility-inlines-hidden -m32 -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O3 -UNDEBUG -Wno-variadic-macros -fno-exceptions -fno-rtti -MD -MT unittests/DebugInfo/DWARF/CMakeFiles/DebugInfoDWARFTests.dir/DWARFDebugInfoTest.cpp.o -MF unittests/DebugInfo/DWARF/CMakeFiles/DebugInfoDWARFTests.dir/DWARFDebugInfoTest.cpp.o.d -o unittests/DebugInfo/DWARF/CMakeFiles/DebugInfoDWARFTests.dir/DWARFDebugInfoTest.cpp.o -c ../llvm-project/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp ../llvm-project/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp:18:37: fatal error: llvm/Codegen/AsmPrinter.h: No such file or directory #include "llvm/Codegen/AsmPrinter.h" ^ compilation terminated. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306513 91177308-0d34-0410-b5e6-96231b3b80d8 George Rimar 2 years ago
4 changed file(s) with 11 addition(s) and 81 deletion(s). Raw diff Collapse all Expand all
288288 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
289289 };
290290
291 /// Used as a return value for a error callback passed to DWARF context.
292 /// Callback should return Halt if client application wants to stop
293 /// object parsing, or should return Continue otherwise.
294 enum class ErrorPolicy { Halt, Continue };
295
296291 /// DWARFContextInMemory is the simplest possible implementation of a
297292 /// DWARFContext. It assumes all content is available in memory and stores
298293 /// pointers to it.
350345 Error maybeDecompress(const object::SectionRef &Sec, StringRef Name,
351346 StringRef &Data);
352347
353 /// Function used to handle default error reporting policy. Prints a error
354 /// message and returns Continue, so DWARF context ignores the error.
355 static ErrorPolicy defaultErrorHandler(Error E);
356
357348 public:
358 DWARFContextInMemory(
359 const object::ObjectFile &Obj, const LoadedObjectInfo *L = nullptr,
360 function_ref HandleError = defaultErrorHandler);
349 DWARFContextInMemory(const object::ObjectFile &Obj,
350 const LoadedObjectInfo *L = nullptr);
361351
362352 DWARFContextInMemory(const StringMap> &Sections,
363353 uint8_t AddrSize,
869869
870870 Expected SymAddrOrErr = Sym->getAddress();
871871 if (!SymAddrOrErr)
872 return createError("failed to compute symbol address: ",
872 return createError("error: failed to compute symbol address: ",
873873 SymAddrOrErr.takeError());
874874
875875 // Also remember what section this symbol is in for later
876876 auto SectOrErr = Sym->getSection();
877877 if (!SectOrErr)
878 return createError("failed to get symbol section: ",
878 return createError("error: failed to get symbol section: ",
879879 SectOrErr.takeError());
880880
881881 RSec = *SectOrErr;
936936 return Error::success();
937937 }
938938
939 ErrorPolicy DWARFContextInMemory::defaultErrorHandler(Error E) {
940 errs() << "error: " + toString(std::move(E)) << '\n';
941 return ErrorPolicy::Continue;
942 }
943
944 DWARFContextInMemory::DWARFContextInMemory(
945 const object::ObjectFile &Obj, const LoadedObjectInfo *L,
946 function_ref HandleError)
939 DWARFContextInMemory::DWARFContextInMemory(const object::ObjectFile &Obj,
940 const LoadedObjectInfo *L)
947941 : FileName(Obj.getFileName()), IsLittleEndian(Obj.isLittleEndian()),
948942 AddressSize(Obj.getBytesInAddress()) {
949943 for (const SectionRef &Section : Obj.sections()) {
966960 Section.getContents(data);
967961
968962 if (auto Err = maybeDecompress(Section, name, data)) {
969 ErrorPolicy EP = HandleError(
970 createError("failed to decompress '" + name + "', ", std::move(Err)));
971 if (EP == ErrorPolicy::Halt)
972 return;
963 errs() << "error: failed to decompress '" + name + "', " +
964 toString(std::move(Err))
965 << '\n';
973966 continue;
974967 }
975968
10611054
10621055 Expected SymInfoOrErr = getSymbolInfo(Obj, Reloc, L, AddrCache);
10631056 if (!SymInfoOrErr) {
1064 if (HandleError(SymInfoOrErr.takeError()) == ErrorPolicy::Halt)
1065 return;
1057 errs() << toString(SymInfoOrErr.takeError()) << '\n';
10661058 continue;
10671059 }
10681060
10711063 if (V.error()) {
10721064 SmallString<32> Name;
10731065 Reloc.getTypeName(Name);
1074 ErrorPolicy EP = HandleError(
1075 createError("failed to compute relocation: " + name + ", ",
1076 errorCodeToError(object_error::parse_failed)));
1077 if (EP == ErrorPolicy::Halt)
1078 return;
1066 errs() << "error: failed to compute relocation: " << Name << "\n";
10791067 continue;
10801068 }
10811069 RelocAddrEntry Rel = {SymInfoOrErr->SectionIndex, Val};
1414 #include "llvm/ADT/Triple.h"
1515 #include "llvm/BinaryFormat/Dwarf.h"
1616 #include "llvm/Config/llvm-config.h"
17 #include "llvm/Codegen/AsmPrinter.h"
1817 #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
1918 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
2019 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
2120 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
22 #include "llvm/MC/MCContext.h"
23 #include "llvm/MC/MCSectionELF.h"
24 #include "llvm/MC/MCStreamer.h"
2521 #include "llvm/Object/ObjectFile.h"
2622 #include "llvm/ObjectYAML/DWARFEmitter.h"
2723 #include "llvm/ObjectYAML/DWARFYAML.h"
21492145 "offset:");
21502146 }
21512147
2152 TEST(DWARFDebugInfo, TestErrorReportingPolicy) {
2153 initLLVMIfNeeded();
2154 auto ExpectedDG = dwarfgen::Generator::create(Triple("x86_64-pc-linux"),
2155 4 /*DwarfVersion*/);
2156 if (HandleExpectedError(ExpectedDG))
2157 return;
2158 dwarfgen::Generator *DG = ExpectedDG.get().get();
2159 AsmPrinter *AP = DG->getAsmPrinter();
2160 MCContext *MC = DG->getMCContext();
2161
2162 // Emit two compressed sections with broken headers.
2163 AP->OutStreamer->SwitchSection(
2164 MC->getELFSection(".zdebug_foo", 0 /*Type*/, 0 /*Flags*/));
2165 AP->OutStreamer->EmitBytes("0");
2166 AP->OutStreamer->SwitchSection(
2167 MC->getELFSection(".zdebug_bar", 0 /*Type*/, 0 /*Flags*/));
2168 AP->OutStreamer->EmitBytes("0");
2169
2170 MemoryBufferRef FileBuffer(DG->generate(), "dwarf");
2171 auto Obj = object::ObjectFile::createObjectFile(FileBuffer);
2172 EXPECT_TRUE((bool)Obj);
2173
2174 // Case 1: error handler handles all errors. That allows
2175 // DWARFContextInMemory
2176 // to parse whole file and find both two errors we know about.
2177 int Errors = 0;
2178 DWARFContextInMemory Ctx1(*Obj.get(), nullptr, [&](Error E) {
2179 ++Errors;
2180 consumeError(std::move(E));
2181 return ErrorPolicy::Continue;
2182 });
2183 EXPECT_TRUE(Errors == 2);
2184
2185 // Case 2: error handler stops parsing of object after first error.
2186 Errors = 0;
2187 DWARFContextInMemory Ctx2(*Obj.get(), nullptr, [&](Error E) {
2188 ++Errors;
2189 consumeError(std::move(E));
2190 return ErrorPolicy::Halt;
2191 });
2192 EXPECT_TRUE(Errors == 1);
2193 }
2194
21952148 } // end anonymous namespace
214214
215215 BumpPtrAllocator &getAllocator() { return Allocator; }
216216 AsmPrinter *getAsmPrinter() const { return Asm.get(); }
217 MCContext *getMCContext() const { return MC.get(); }
218217 DIEAbbrevSet &getAbbrevSet() { return Abbreviations; }
219218 DwarfStringPool &getStringPool() { return *StringPool; }
220219