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