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<std::unique_ptr<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 | Error printReaders(); |
49 | Error compareReaders(); |
50 | |
51 | Error handleArchive(LVReaders &Readers, StringRef Filename, |
52 | object::Archive &Arch); |
53 | Error handleBuffer(LVReaders &Readers, StringRef Filename, |
54 | MemoryBufferRef Buffer, StringRef ExePath = {}); |
55 | Error handleFile(LVReaders &Readers, StringRef Filename, |
56 | StringRef ExePath = {}); |
57 | Error handleMach(LVReaders &Readers, StringRef Filename, |
58 | object::MachOUniversalBinary &Mach); |
59 | Error handleObject(LVReaders &Readers, StringRef Filename, |
60 | object::Binary &Binary); |
61 | Error handleObject(LVReaders &Readers, StringRef Filename, StringRef Buffer, |
62 | StringRef ExePath); |
63 | |
64 | Error createReader(StringRef Filename, LVReaders &Readers, PdbOrObj &Input, |
65 | StringRef FileFormatName, StringRef ExePath = {}); |
66 | |
67 | public: |
68 | LVReaderHandler() = delete; |
69 | LVReaderHandler(ArgVector &Objects, ScopedPrinter &W, |
70 | LVOptions &ReaderOptions) |
71 | : Objects(Objects), W(W), OS(W.getOStream()) { |
72 | setOptions(&ReaderOptions); |
73 | } |
74 | LVReaderHandler(const LVReaderHandler &) = delete; |
75 | LVReaderHandler &operator=(const LVReaderHandler &) = delete; |
76 | |
77 | Error createReader(StringRef Filename, LVReaders &Readers) { |
78 | return handleFile(Readers, Filename); |
79 | } |
80 | Error process(); |
81 | |
82 | Expected<std::unique_ptr<LVReader>> createReader(StringRef Pathname) { |
83 | LVReaders Readers; |
84 | if (Error Err = createReader(Filename: Pathname, Readers)) |
85 | return std::move(Err); |
86 | return std::move(Readers[0]); |
87 | } |
88 | |
89 | void print(raw_ostream &OS) const; |
90 | |
91 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
92 | void dump() const { print(OS&: dbgs()); } |
93 | #endif |
94 | }; |
95 | |
96 | } // end namespace logicalview |
97 | } // namespace llvm |
98 | |
99 | #endif // LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVREADERHANDLER_H |
100 | |