2014-01-30 09:39:17 +08:00
|
|
|
//===-- llvm/lib/CodeGen/AsmPrinter/WinCodeViewLineTables.h ----*- C++ -*--===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains support for writing line tables info into COFF files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_WINCODEVIEWLINETABLES_H
|
|
|
|
#define LLVM_LIB_CODEGEN_ASMPRINTER_WINCODEVIEWLINETABLES_H
|
2014-01-30 09:39:17 +08:00
|
|
|
|
|
|
|
#include "AsmPrinterHandler.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2014-03-04 18:07:28 +08:00
|
|
|
#include "llvm/CodeGen/LexicalScopes.h"
|
2014-01-30 09:39:17 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2014-03-06 08:46:21 +08:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
2014-03-05 18:30:38 +08:00
|
|
|
#include "llvm/IR/DebugLoc.h"
|
2014-01-30 09:39:17 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
/// \brief Collects and handles line tables information in a CodeView format.
|
2015-07-02 00:18:16 +08:00
|
|
|
class LLVM_LIBRARY_VISIBILITY WinCodeViewLineTables : public AsmPrinterHandler {
|
2014-01-30 09:39:17 +08:00
|
|
|
AsmPrinter *Asm;
|
|
|
|
DebugLoc PrevInstLoc;
|
|
|
|
|
|
|
|
// For each function, store a vector of labels to its instructions, as well as
|
|
|
|
// to the end of the function.
|
|
|
|
struct FunctionInfo {
|
|
|
|
SmallVector<MCSymbol *, 10> Instrs;
|
|
|
|
MCSymbol *End;
|
2014-04-28 12:05:08 +08:00
|
|
|
FunctionInfo() : End(nullptr) {}
|
2014-01-30 09:39:17 +08:00
|
|
|
} *CurFn;
|
|
|
|
|
|
|
|
typedef DenseMap<const Function *, FunctionInfo> FnDebugInfoTy;
|
|
|
|
FnDebugInfoTy FnDebugInfo;
|
|
|
|
// Store the functions we've visited in a vector so we can maintain a stable
|
|
|
|
// order while emitting subsections.
|
|
|
|
SmallVector<const Function *, 10> VisitedFunctions;
|
|
|
|
|
|
|
|
// InstrInfoTy - Holds the Filename:LineNumber information for every
|
|
|
|
// instruction with a unique debug location.
|
|
|
|
struct InstrInfoTy {
|
|
|
|
StringRef Filename;
|
|
|
|
unsigned LineNumber;
|
2015-07-09 08:19:51 +08:00
|
|
|
unsigned ColumnNumber;
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2015-07-09 08:19:51 +08:00
|
|
|
InstrInfoTy() : LineNumber(0), ColumnNumber(0) {}
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2015-07-09 08:19:51 +08:00
|
|
|
InstrInfoTy(StringRef Filename, unsigned LineNumber, unsigned ColumnNumber)
|
|
|
|
: Filename(Filename), LineNumber(LineNumber),
|
|
|
|
ColumnNumber(ColumnNumber) {}
|
2014-01-30 09:39:17 +08:00
|
|
|
};
|
|
|
|
DenseMap<MCSymbol *, InstrInfoTy> InstrInfo;
|
|
|
|
|
|
|
|
// FileNameRegistry - Manages filenames observed while generating debug info
|
|
|
|
// by filtering out duplicates and bookkeeping the offsets in the string
|
|
|
|
// table to be generated.
|
|
|
|
struct FileNameRegistryTy {
|
|
|
|
SmallVector<StringRef, 10> Filenames;
|
|
|
|
struct PerFileInfo {
|
|
|
|
size_t FilenameID, StartOffset;
|
|
|
|
};
|
|
|
|
StringMap<PerFileInfo> Infos;
|
|
|
|
|
|
|
|
// The offset in the string table where we'll write the next unique
|
|
|
|
// filename.
|
|
|
|
size_t LastOffset;
|
|
|
|
|
|
|
|
FileNameRegistryTy() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add Filename to the registry, if it was not observed before.
|
|
|
|
void add(StringRef Filename) {
|
|
|
|
if (Infos.count(Filename))
|
|
|
|
return;
|
|
|
|
size_t OldSize = Infos.size();
|
|
|
|
Infos[Filename].FilenameID = OldSize;
|
|
|
|
Infos[Filename].StartOffset = LastOffset;
|
|
|
|
LastOffset += Filename.size() + 1;
|
|
|
|
Filenames.push_back(Filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear() {
|
|
|
|
LastOffset = 1;
|
|
|
|
Infos.clear();
|
|
|
|
Filenames.clear();
|
|
|
|
}
|
|
|
|
} FileNameRegistry;
|
|
|
|
|
|
|
|
typedef std::map<std::pair<StringRef, StringRef>, char *>
|
|
|
|
DirAndFilenameToFilepathMapTy;
|
|
|
|
DirAndFilenameToFilepathMapTy DirAndFilenameToFilepathMap;
|
|
|
|
StringRef getFullFilepath(const MDNode *S);
|
|
|
|
|
|
|
|
void maybeRecordLocation(DebugLoc DL, const MachineFunction *MF);
|
|
|
|
|
|
|
|
void clear() {
|
2014-04-28 12:05:08 +08:00
|
|
|
assert(CurFn == nullptr);
|
2014-01-30 09:39:17 +08:00
|
|
|
FileNameRegistry.clear();
|
|
|
|
InstrInfo.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void emitDebugInfoForFunction(const Function *GV);
|
|
|
|
|
|
|
|
public:
|
|
|
|
WinCodeViewLineTables(AsmPrinter *Asm);
|
|
|
|
|
2015-04-11 10:11:45 +08:00
|
|
|
~WinCodeViewLineTables() override {
|
2014-01-30 09:39:17 +08:00
|
|
|
for (DirAndFilenameToFilepathMapTy::iterator
|
|
|
|
I = DirAndFilenameToFilepathMap.begin(),
|
|
|
|
E = DirAndFilenameToFilepathMap.end();
|
|
|
|
I != E; ++I)
|
|
|
|
free(I->second);
|
|
|
|
}
|
|
|
|
|
2014-03-08 14:31:39 +08:00
|
|
|
void setSymbolSize(const llvm::MCSymbol *, uint64_t) override {}
|
2014-01-30 09:39:17 +08:00
|
|
|
|
|
|
|
/// \brief Emit the COFF section that holds the line table information.
|
2014-03-08 14:31:39 +08:00
|
|
|
void endModule() override;
|
2014-01-30 09:39:17 +08:00
|
|
|
|
|
|
|
/// \brief Gather pre-function debug information.
|
2014-03-08 14:31:39 +08:00
|
|
|
void beginFunction(const MachineFunction *MF) override;
|
2014-01-30 09:39:17 +08:00
|
|
|
|
|
|
|
/// \brief Gather post-function debug information.
|
2014-03-08 14:31:39 +08:00
|
|
|
void endFunction(const MachineFunction *) override;
|
2014-01-30 09:39:17 +08:00
|
|
|
|
|
|
|
/// \brief Process beginning of an instruction.
|
2014-03-08 14:31:39 +08:00
|
|
|
void beginInstruction(const MachineInstr *MI) override;
|
2014-01-30 09:39:17 +08:00
|
|
|
|
|
|
|
/// \brief Process end of an instruction.
|
2014-03-08 14:31:39 +08:00
|
|
|
void endInstruction() override {}
|
2014-01-30 09:39:17 +08:00
|
|
|
};
|
|
|
|
} // End of namespace llvm
|
|
|
|
|
|
|
|
#endif
|