Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. //===-- LVReaderHandler.h ---------------------------------------*- C++ -*-===//
  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. // This class implements the Reader handler.
  10. //
  11. //===----------------------------------------------------------------------===//
  12.  
  13. #ifndef LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVREADERHANDLER_H
  14. #define LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVREADERHANDLER_H
  15.  
  16. #include "llvm/ADT/PointerUnion.h"
  17. #include "llvm/DebugInfo/LogicalView/Core/LVReader.h"
  18. #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
  19. #include "llvm/Object/Archive.h"
  20. #include "llvm/Object/MachOUniversal.h"
  21. #include "llvm/Object/ObjectFile.h"
  22. #include "llvm/Support/MemoryBuffer.h"
  23. #include "llvm/Support/ScopedPrinter.h"
  24. #include <string>
  25. #include <vector>
  26.  
  27. namespace llvm {
  28. namespace logicalview {
  29.  
  30. using LVReaders = std::vector<LVReader *>;
  31. using ArgVector = std::vector<std::string>;
  32. using PdbOrObj = PointerUnion<object::ObjectFile *, pdb::PDBFile *>;
  33.  
  34. // This class performs the following tasks:
  35. // - Creates a logical reader for every binary file in the command line,
  36. //   that parses the debug information and creates a high level logical
  37. //   view representation containing scopes, symbols, types and lines.
  38. // - Prints and compares the logical views.
  39. //
  40. // The supported binary formats are: ELF, Mach-O and CodeView.
  41. class LVReaderHandler {
  42.   ArgVector &Objects;
  43.   ScopedPrinter &W;
  44.   raw_ostream &OS;
  45.   LVReaders TheReaders;
  46.  
  47.   Error createReaders();
  48.   void destroyReaders();
  49.   Error printReaders();
  50.   Error compareReaders();
  51.  
  52.   Error handleArchive(LVReaders &Readers, StringRef Filename,
  53.                       object::Archive &Arch);
  54.   Error handleBuffer(LVReaders &Readers, StringRef Filename,
  55.                      MemoryBufferRef Buffer, StringRef ExePath = {});
  56.   Error handleFile(LVReaders &Readers, StringRef Filename,
  57.                    StringRef ExePath = {});
  58.   Error handleMach(LVReaders &Readers, StringRef Filename,
  59.                    object::MachOUniversalBinary &Mach);
  60.   Error handleObject(LVReaders &Readers, StringRef Filename,
  61.                      object::Binary &Binary);
  62.  
  63.   Error createReader(StringRef Filename, LVReaders &Readers, PdbOrObj &Input,
  64.                      StringRef FileFormatName, StringRef ExePath = {});
  65.  
  66. public:
  67.   LVReaderHandler() = delete;
  68.   LVReaderHandler(ArgVector &Objects, ScopedPrinter &W,
  69.                   LVOptions &ReaderOptions)
  70.       : Objects(Objects), W(W), OS(W.getOStream()) {
  71.     setOptions(&ReaderOptions);
  72.   }
  73.   LVReaderHandler(const LVReaderHandler &) = delete;
  74.   LVReaderHandler &operator=(const LVReaderHandler &) = delete;
  75.   ~LVReaderHandler() { destroyReaders(); }
  76.  
  77.   Error createReader(StringRef Filename, LVReaders &Readers) {
  78.     return handleFile(Readers, Filename);
  79.   }
  80.   Error process();
  81.  
  82.   Expected<LVReader *> createReader(StringRef Pathname) {
  83.     LVReaders Readers;
  84.     if (Error Err = createReader(Pathname, Readers))
  85.       return std::move(Err);
  86.     return Readers[0];
  87.   }
  88.   void deleteReader(LVReader *Reader) { delete Reader; }
  89.  
  90.   void print(raw_ostream &OS) const;
  91.  
  92. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  93.   void dump() const { print(dbgs()); }
  94. #endif
  95. };
  96.  
  97. } // end namespace logicalview
  98. } // namespace llvm
  99.  
  100. #endif // LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVREADERHANDLER_H
  101.