blob: 77b5ed39c1f82d75e708a56a379c80e69577e5bd [file] [log] [blame]
Reid Kleckner70f5bc92016-01-14 19:25:04 +00001//===-- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h ----*- C++ -*--===//
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +00002//
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//
Reid Kleckner70f5bc92016-01-14 19:25:04 +000010// This file contains support for writing Microsoft CodeView debug info.
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000011//
12//===----------------------------------------------------------------------===//
13
Reid Kleckner70f5bc92016-01-14 19:25:04 +000014#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H
15#define LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000016
17#include "AsmPrinterHandler.h"
18#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/StringMap.h"
20#include "llvm/ADT/StringRef.h"
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000021#include "llvm/CodeGen/AsmPrinter.h"
Chandler Carruth442f7842014-03-04 10:07:28 +000022#include "llvm/CodeGen/LexicalScopes.h"
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000023#include "llvm/CodeGen/MachineFunction.h"
24#include "llvm/CodeGen/MachineModuleInfo.h"
Chandler Carruth9a4c9e52014-03-06 00:46:21 +000025#include "llvm/IR/DebugInfo.h"
Chandler Carruth92051402014-03-05 10:30:38 +000026#include "llvm/IR/DebugLoc.h"
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000027#include "llvm/MC/MCStreamer.h"
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000028#include "llvm/Target/TargetLoweringObjectFile.h"
29
30namespace llvm {
31/// \brief Collects and handles line tables information in a CodeView format.
Reid Kleckner70f5bc92016-01-14 19:25:04 +000032class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public AsmPrinterHandler {
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000033 AsmPrinter *Asm;
34 DebugLoc PrevInstLoc;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000035
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 {
Reid Kleckner9533af42016-01-16 00:09:09 +000039 DebugLoc LastLoc;
Reid Kleckner2214ed82016-01-29 00:49:42 +000040 MCSymbol *End = nullptr;
41 unsigned FuncId = 0;
42 unsigned LastFileId;
43 bool HaveLineInfo = false;
Reid Kleckner9533af42016-01-16 00:09:09 +000044 };
45 FunctionInfo *CurFn;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000046
Reid Kleckner2214ed82016-01-29 00:49:42 +000047 unsigned NextFuncId = 0;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000048
Reid Kleckner2214ed82016-01-29 00:49:42 +000049 /// Remember some debug info about each function. Keep it in a stable order to
50 /// emit at the end of the TU.
51 MapVector<const Function *, FunctionInfo> FnDebugInfo;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000052
Reid Kleckner2214ed82016-01-29 00:49:42 +000053 /// Map from DIFile to .cv_file id.
54 DenseMap<const DIFile *, unsigned> FileIdMap;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000055
Reid Kleckner9533af42016-01-16 00:09:09 +000056 typedef std::map<const DIFile *, std::string> FileToFilepathMapTy;
57 FileToFilepathMapTy FileToFilepathMap;
58 StringRef getFullFilepath(const DIFile *S);
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000059
Reid Kleckner2214ed82016-01-29 00:49:42 +000060 unsigned maybeRecordFile(const DIFile *F);
61
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000062 void maybeRecordLocation(DebugLoc DL, const MachineFunction *MF);
63
64 void clear() {
Craig Toppere73658d2014-04-28 04:05:08 +000065 assert(CurFn == nullptr);
Reid Kleckner2214ed82016-01-29 00:49:42 +000066 FileIdMap.clear();
67 FnDebugInfo.clear();
68 FileToFilepathMap.clear();
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000069 }
70
Reid Kleckner2214ed82016-01-29 00:49:42 +000071 void emitDebugInfoForFunction(const Function *GV, FunctionInfo &FI);
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000072
73public:
Reid Kleckner70f5bc92016-01-14 19:25:04 +000074 CodeViewDebug(AsmPrinter *Asm);
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000075
Craig Topper7b883b32014-03-08 06:31:39 +000076 void setSymbolSize(const llvm::MCSymbol *, uint64_t) override {}
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000077
78 /// \brief Emit the COFF section that holds the line table information.
Craig Topper7b883b32014-03-08 06:31:39 +000079 void endModule() override;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000080
81 /// \brief Gather pre-function debug information.
Craig Topper7b883b32014-03-08 06:31:39 +000082 void beginFunction(const MachineFunction *MF) override;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000083
84 /// \brief Gather post-function debug information.
Craig Topper7b883b32014-03-08 06:31:39 +000085 void endFunction(const MachineFunction *) override;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000086
87 /// \brief Process beginning of an instruction.
Craig Topper7b883b32014-03-08 06:31:39 +000088 void beginInstruction(const MachineInstr *MI) override;
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000089
90 /// \brief Process end of an instruction.
Craig Topper7b883b32014-03-08 06:31:39 +000091 void endInstruction() override {}
Timur Iskhodzhanovf166f6c2014-01-30 01:39:17 +000092};
93} // End of namespace llvm
94
95#endif