aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm16/include/llvm/DebugInfo/LogicalView/LVReaderHandler.h
blob: 2b3dea1370f5ed16a6bc61a5e2f95cbc54086ae2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#pragma once

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif

//===-- LVReaderHandler.h ---------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This class implements the Reader handler.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVREADERHANDLER_H
#define LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVREADERHANDLER_H

#include "llvm/ADT/PointerUnion.h"
#include "llvm/DebugInfo/LogicalView/Core/LVReader.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/MachOUniversal.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/ScopedPrinter.h"
#include <string>
#include <vector>

namespace llvm {
namespace logicalview {

using LVReaders = std::vector<LVReader *>;
using ArgVector = std::vector<std::string>;
using PdbOrObj = PointerUnion<object::ObjectFile *, pdb::PDBFile *>;

// This class performs the following tasks:
// - Creates a logical reader for every binary file in the command line,
//   that parses the debug information and creates a high level logical
//   view representation containing scopes, symbols, types and lines.
// - Prints and compares the logical views.
//
// The supported binary formats are: ELF, Mach-O and CodeView.
class LVReaderHandler {
  ArgVector &Objects;
  ScopedPrinter &W;
  raw_ostream &OS;
  LVReaders TheReaders;

  Error createReaders();
  void destroyReaders();
  Error printReaders();
  Error compareReaders();

  Error handleArchive(LVReaders &Readers, StringRef Filename,
                      object::Archive &Arch);
  Error handleBuffer(LVReaders &Readers, StringRef Filename,
                     MemoryBufferRef Buffer, StringRef ExePath = {});
  Error handleFile(LVReaders &Readers, StringRef Filename,
                   StringRef ExePath = {});
  Error handleMach(LVReaders &Readers, StringRef Filename,
                   object::MachOUniversalBinary &Mach);
  Error handleObject(LVReaders &Readers, StringRef Filename,
                     object::Binary &Binary);

  Error createReader(StringRef Filename, LVReaders &Readers, PdbOrObj &Input,
                     StringRef FileFormatName, StringRef ExePath = {});

public:
  LVReaderHandler() = delete;
  LVReaderHandler(ArgVector &Objects, ScopedPrinter &W,
                  LVOptions &ReaderOptions)
      : Objects(Objects), W(W), OS(W.getOStream()) {
    setOptions(&ReaderOptions);
  }
  LVReaderHandler(const LVReaderHandler &) = delete;
  LVReaderHandler &operator=(const LVReaderHandler &) = delete;
  ~LVReaderHandler() { destroyReaders(); }

  Error createReader(StringRef Filename, LVReaders &Readers) {
    return handleFile(Readers, Filename);
  }
  Error process();

  Expected<LVReader *> createReader(StringRef Pathname) {
    LVReaders Readers;
    if (Error Err = createReader(Pathname, Readers))
      return std::move(Err);
    return Readers[0];
  }
  void deleteReader(LVReader *Reader) { delete Reader; }

  void print(raw_ostream &OS) const;

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  void dump() const { print(dbgs()); }
#endif
};

} // end namespace logicalview
} // namespace llvm

#endif // LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVREADERHANDLER_H

#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif