LLVM  3.7.0
WinCodeViewLineTables.h
Go to the documentation of this file.
1 //===-- llvm/lib/CodeGen/AsmPrinter/WinCodeViewLineTables.h ----*- C++ -*--===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains support for writing line tables info into COFF files.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_WINCODEVIEWLINETABLES_H
15 #define LLVM_LIB_CODEGEN_ASMPRINTER_WINCODEVIEWLINETABLES_H
16 
17 #include "AsmPrinterHandler.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/ADT/StringRef.h"
25 #include "llvm/IR/DebugInfo.h"
26 #include "llvm/IR/DebugLoc.h"
27 #include "llvm/MC/MCStreamer.h"
29 
30 namespace llvm {
31 /// \brief Collects and handles line tables information in a CodeView format.
33  AsmPrinter *Asm;
34  DebugLoc PrevInstLoc;
35 
36  // For each function, store a vector of labels to its instructions, as well as
37  // to the end of the function.
38  struct FunctionInfo {
40  MCSymbol *End;
41  FunctionInfo() : End(nullptr) {}
42  } *CurFn;
43 
45  FnDebugInfoTy FnDebugInfo;
46  // Store the functions we've visited in a vector so we can maintain a stable
47  // order while emitting subsections.
48  SmallVector<const Function *, 10> VisitedFunctions;
49 
50  // InstrInfoTy - Holds the Filename:LineNumber information for every
51  // instruction with a unique debug location.
52  struct InstrInfoTy {
53  StringRef Filename;
54  unsigned LineNumber;
55  unsigned ColumnNumber;
56 
57  InstrInfoTy() : LineNumber(0), ColumnNumber(0) {}
58 
59  InstrInfoTy(StringRef Filename, unsigned LineNumber, unsigned ColumnNumber)
60  : Filename(Filename), LineNumber(LineNumber),
61  ColumnNumber(ColumnNumber) {}
62  };
64 
65  // FileNameRegistry - Manages filenames observed while generating debug info
66  // by filtering out duplicates and bookkeeping the offsets in the string
67  // table to be generated.
68  struct FileNameRegistryTy {
70  struct PerFileInfo {
71  size_t FilenameID, StartOffset;
72  };
74 
75  // The offset in the string table where we'll write the next unique
76  // filename.
77  size_t LastOffset;
78 
79  FileNameRegistryTy() {
80  clear();
81  }
82 
83  // Add Filename to the registry, if it was not observed before.
84  void add(StringRef Filename) {
85  if (Infos.count(Filename))
86  return;
87  size_t OldSize = Infos.size();
88  Infos[Filename].FilenameID = OldSize;
89  Infos[Filename].StartOffset = LastOffset;
90  LastOffset += Filename.size() + 1;
91  Filenames.push_back(Filename);
92  }
93 
94  void clear() {
95  LastOffset = 1;
96  Infos.clear();
97  Filenames.clear();
98  }
99  } FileNameRegistry;
100 
101  typedef std::map<std::pair<StringRef, StringRef>, char *>
102  DirAndFilenameToFilepathMapTy;
103  DirAndFilenameToFilepathMapTy DirAndFilenameToFilepathMap;
104  StringRef getFullFilepath(const MDNode *S);
105 
106  void maybeRecordLocation(DebugLoc DL, const MachineFunction *MF);
107 
108  void clear() {
109  assert(CurFn == nullptr);
110  FileNameRegistry.clear();
111  InstrInfo.clear();
112  }
113 
114  void emitDebugInfoForFunction(const Function *GV);
115 
116 public:
117  WinCodeViewLineTables(AsmPrinter *Asm);
118 
120  for (DirAndFilenameToFilepathMapTy::iterator
121  I = DirAndFilenameToFilepathMap.begin(),
122  E = DirAndFilenameToFilepathMap.end();
123  I != E; ++I)
124  free(I->second);
125  }
126 
127  void setSymbolSize(const llvm::MCSymbol *, uint64_t) override {}
128 
129  /// \brief Emit the COFF section that holds the line table information.
130  void endModule() override;
131 
132  /// \brief Gather pre-function debug information.
133  void beginFunction(const MachineFunction *MF) override;
134 
135  /// \brief Gather post-function debug information.
136  void endFunction(const MachineFunction *) override;
137 
138  /// \brief Process beginning of an instruction.
139  void beginInstruction(const MachineInstr *MI) override;
140 
141  /// \brief Process end of an instruction.
142  void endInstruction() override {}
143 };
144 } // End of namespace llvm
145 
146 #endif
size_t size() const
size - Get the string size.
Definition: StringRef.h:113
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
Collects and handles AsmPrinter objects required to build debug or EH information.
A debug info location.
Definition: DebugLoc.h:34
static bool add(uint64_t *dest, const uint64_t *x, const uint64_t *y, unsigned len)
This function adds the integer array x to the integer array Y and places the result in dest...
Definition: APInt.cpp:238
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:66
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library...
Definition: Compiler.h:110
void endInstruction() override
Process end of an instruction.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:214
Representation of each machine instruction.
Definition: MachineInstr.h:51
void setSymbolSize(const llvm::MCSymbol *, uint64_t) override
For symbols that have a size designated (e.g.
#define I(x, y, z)
Definition: MD5.cpp:54
Collects and handles line tables information in a CodeView format.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40