1 //===- DebugTypes.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 #ifndef LLD_COFF_DEBUGTYPES_H
10 #define LLD_COFF_DEBUGTYPES_H
11 
12 #include "llvm/Support/Error.h"
13 #include "llvm/Support/MemoryBuffer.h"
14 
15 namespace llvm {
16 namespace codeview {
17 class PrecompRecord;
18 class TypeServer2Record;
19 } // namespace codeview
20 namespace pdb {
21 class NativeSession;
22 }
23 } // namespace llvm
24 
25 namespace lld {
26 namespace coff {
27 
28 class ObjFile;
29 class PDBInputFile;
30 struct CVIndexMap;
31 class TypeMerger;
32 
33 class TpiSource {
34 public:
35   enum TpiKind { Regular, PCH, UsingPCH, PDB, UsingPDB };
36 
37   TpiSource(TpiKind k, ObjFile *f);
38   virtual ~TpiSource();
39 
40   /// Produce a mapping from the type and item indices used in the object
41   /// file to those in the destination PDB.
42   ///
43   /// If the object file uses a type server PDB (compiled with /Zi), merge TPI
44   /// and IPI from the type server PDB and return a map for it. Each unique type
45   /// server PDB is merged at most once, so this may return an existing index
46   /// mapping.
47   ///
48   /// If the object does not use a type server PDB (compiled with /Z7), we merge
49   /// all the type and item records from the .debug$S stream and fill in the
50   /// caller-provided ObjectIndexMap.
51   virtual llvm::Expected<const CVIndexMap *> mergeDebugT(TypeMerger *m,
52                                                          CVIndexMap *indexMap);
53   /// Is this a dependent file that needs to be processed first, before other
54   /// OBJs?
55   virtual bool isDependency() const { return false; }
56 
57   static void forEachSource(llvm::function_ref<void(TpiSource *)> fn);
58 
59   static uint32_t countTypeServerPDBs();
60   static uint32_t countPrecompObjs();
61 
62   /// Clear global data structures for TpiSources.
63   static void clear();
64 
65   const TpiKind kind;
66   ObjFile *file;
67 };
68 
69 TpiSource *makeTpiSource(ObjFile *file);
70 TpiSource *makeTypeServerSource(PDBInputFile *pdbInputFile);
71 TpiSource *makeUseTypeServerSource(ObjFile *file,
72                                    llvm::codeview::TypeServer2Record ts);
73 TpiSource *makePrecompSource(ObjFile *file);
74 TpiSource *makeUsePrecompSource(ObjFile *file,
75                                 llvm::codeview::PrecompRecord ts);
76 
77 } // namespace coff
78 } // namespace lld
79 
80 #endif
81