2016-01-15 03:25:04 +08:00
|
|
|
//===-- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h ----*- C++ -*--===//
|
2014-01-30 09:39:17 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2016-01-15 03:25:04 +08:00
|
|
|
// This file contains support for writing Microsoft CodeView debug info.
|
2014-01-30 09:39:17 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-01-15 03:25:04 +08:00
|
|
|
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H
|
|
|
|
#define LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2016-02-11 04:55:49 +08:00
|
|
|
#include "DebugHandlerBase.h"
|
2014-01-30 09:39:17 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2016-05-24 04:23:46 +08:00
|
|
|
#include "llvm/DebugInfo/CodeView/MemoryTypeTableBuilder.h"
|
2016-01-30 02:16:43 +08:00
|
|
|
#include "llvm/DebugInfo/CodeView/TypeIndex.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 {
|
2016-02-11 04:55:49 +08:00
|
|
|
|
2016-04-18 17:17:29 +08:00
|
|
|
class StringRef;
|
2016-02-11 04:55:49 +08:00
|
|
|
class LexicalScope;
|
|
|
|
|
2014-01-30 09:39:17 +08:00
|
|
|
/// \brief Collects and handles line tables information in a CodeView format.
|
2016-02-11 04:55:49 +08:00
|
|
|
class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
|
2016-02-04 05:15:48 +08:00
|
|
|
MCStreamer &OS;
|
2016-05-24 04:23:46 +08:00
|
|
|
codeview::MemoryTypeTableBuilder TypeTable;
|
2016-02-11 04:55:49 +08:00
|
|
|
|
2016-02-13 05:48:30 +08:00
|
|
|
/// Represents the most general definition range.
|
|
|
|
struct LocalVarDefRange {
|
|
|
|
/// Indicates that variable data is stored in memory relative to the
|
|
|
|
/// specified register.
|
|
|
|
int InMemory : 1;
|
|
|
|
|
|
|
|
/// Offset of variable data in memory.
|
|
|
|
int DataOffset : 31;
|
|
|
|
|
|
|
|
/// Offset of the data into the user level struct. If zero, no splitting
|
|
|
|
/// occurred.
|
|
|
|
uint16_t StructOffset;
|
|
|
|
|
|
|
|
/// Register containing the data or the register base of the memory
|
|
|
|
/// location containing the data.
|
|
|
|
uint16_t CVRegister;
|
|
|
|
|
|
|
|
/// Compares all location fields. This includes all fields except the label
|
|
|
|
/// ranges.
|
|
|
|
bool isDifferentLocation(LocalVarDefRange &O) {
|
|
|
|
return InMemory != O.InMemory || DataOffset != O.DataOffset ||
|
|
|
|
StructOffset != O.StructOffset || CVRegister != O.CVRegister;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallVector<std::pair<const MCSymbol *, const MCSymbol *>, 1> Ranges;
|
|
|
|
};
|
|
|
|
|
|
|
|
static LocalVarDefRange createDefRangeMem(uint16_t CVRegister, int Offset);
|
|
|
|
static LocalVarDefRange createDefRangeReg(uint16_t CVRegister);
|
|
|
|
|
2016-02-11 04:55:49 +08:00
|
|
|
/// Similar to DbgVariable in DwarfDebug, but not dwarf-specific.
|
|
|
|
struct LocalVariable {
|
|
|
|
const DILocalVariable *DIVar = nullptr;
|
2016-02-13 05:48:30 +08:00
|
|
|
SmallVector<LocalVarDefRange, 1> DefRanges;
|
2016-02-11 04:55:49 +08:00
|
|
|
};
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2016-01-30 02:16:43 +08:00
|
|
|
struct InlineSite {
|
2016-02-11 04:55:49 +08:00
|
|
|
SmallVector<LocalVariable, 1> InlinedLocals;
|
|
|
|
SmallVector<const DILocation *, 1> ChildSites;
|
2016-01-30 02:16:43 +08:00
|
|
|
const DISubprogram *Inlinee = nullptr;
|
|
|
|
unsigned SiteFuncId = 0;
|
|
|
|
};
|
|
|
|
|
2014-01-30 09:39:17 +08:00
|
|
|
// For each function, store a vector of labels to its instructions, as well as
|
|
|
|
// to the end of the function.
|
|
|
|
struct FunctionInfo {
|
2016-01-30 02:16:43 +08:00
|
|
|
/// Map from inlined call site to inlined instructions and child inlined
|
|
|
|
/// call sites. Listed in program order.
|
2016-02-11 04:55:49 +08:00
|
|
|
std::unordered_map<const DILocation *, InlineSite> InlineSites;
|
|
|
|
|
|
|
|
/// Ordered list of top-level inlined call sites.
|
|
|
|
SmallVector<const DILocation *, 1> ChildSites;
|
|
|
|
|
|
|
|
SmallVector<LocalVariable, 1> Locals;
|
2016-01-30 02:16:43 +08:00
|
|
|
|
2016-01-16 08:09:09 +08:00
|
|
|
DebugLoc LastLoc;
|
2016-02-03 01:41:18 +08:00
|
|
|
const MCSymbol *Begin = nullptr;
|
|
|
|
const MCSymbol *End = nullptr;
|
2016-01-29 08:49:42 +08:00
|
|
|
unsigned FuncId = 0;
|
2016-01-30 02:16:43 +08:00
|
|
|
unsigned LastFileId = 0;
|
2016-01-29 08:49:42 +08:00
|
|
|
bool HaveLineInfo = false;
|
2016-01-16 08:09:09 +08:00
|
|
|
};
|
|
|
|
FunctionInfo *CurFn;
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2016-05-26 07:16:12 +08:00
|
|
|
/// The set of comdat .debug$S sections that we've seen so far. Each section
|
|
|
|
/// must start with a magic version number that must only be emitted once.
|
|
|
|
/// This set tracks which sections we've already opened.
|
|
|
|
DenseSet<MCSectionCOFF *> ComdatDebugSections;
|
|
|
|
|
|
|
|
/// Switch to the appropriate .debug$S section for GVSym. If GVSym, the symbol
|
|
|
|
/// of an emitted global value, is in a comdat COFF section, this will switch
|
|
|
|
/// to a new .debug$S section in that comdat. This method ensures that the
|
|
|
|
/// section starts with the magic version number on first use. If GVSym is
|
|
|
|
/// null, uses the main .debug$S section.
|
|
|
|
void switchToDebugSectionForSymbol(const MCSymbol *GVSym);
|
|
|
|
|
2016-03-19 02:54:32 +08:00
|
|
|
/// The next available function index for use with our .cv_* directives. Not
|
|
|
|
/// to be confused with type indices for LF_FUNC_ID records.
|
2016-01-29 08:49:42 +08:00
|
|
|
unsigned NextFuncId = 0;
|
|
|
|
|
2016-02-13 05:48:30 +08:00
|
|
|
InlineSite &getInlineSite(const DILocation *InlinedAt,
|
|
|
|
const DISubprogram *Inlinee);
|
2016-01-30 02:16:43 +08:00
|
|
|
|
2016-06-03 01:13:53 +08:00
|
|
|
codeview::TypeIndex getFuncIdForSubprogram(const DISubprogram *SP);
|
2016-05-24 04:23:46 +08:00
|
|
|
|
2016-02-03 01:41:18 +08:00
|
|
|
static void collectInlineSiteChildren(SmallVectorImpl<unsigned> &Children,
|
|
|
|
const FunctionInfo &FI,
|
|
|
|
const InlineSite &Site);
|
|
|
|
|
2016-01-29 08:49:42 +08:00
|
|
|
/// Remember some debug info about each function. Keep it in a stable order to
|
|
|
|
/// emit at the end of the TU.
|
|
|
|
MapVector<const Function *, FunctionInfo> FnDebugInfo;
|
|
|
|
|
|
|
|
/// Map from DIFile to .cv_file id.
|
|
|
|
DenseMap<const DIFile *, unsigned> FileIdMap;
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2016-03-19 02:54:32 +08:00
|
|
|
/// All inlined subprograms in the order they should be emitted.
|
2016-05-24 04:23:46 +08:00
|
|
|
SmallSetVector<const DISubprogram *, 4> InlinedSubprograms;
|
|
|
|
|
|
|
|
/// Map from DI metadata nodes to CodeView type indices. Primarily indexed by
|
|
|
|
/// DIType* and DISubprogram*.
|
|
|
|
DenseMap<const DINode *, codeview::TypeIndex> TypeIndices;
|
2016-01-30 02:16:43 +08:00
|
|
|
|
2016-06-03 23:58:20 +08:00
|
|
|
/// Map from DICompositeType* to complete type index. Non-record types are
|
|
|
|
/// always looked up in the normal TypeIndices map.
|
|
|
|
DenseMap<const DICompositeType *, codeview::TypeIndex> CompleteTypeIndices;
|
|
|
|
|
2016-01-16 08:09:09 +08:00
|
|
|
typedef std::map<const DIFile *, std::string> FileToFilepathMapTy;
|
|
|
|
FileToFilepathMapTy FileToFilepathMap;
|
|
|
|
StringRef getFullFilepath(const DIFile *S);
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2016-01-29 08:49:42 +08:00
|
|
|
unsigned maybeRecordFile(const DIFile *F);
|
|
|
|
|
2014-01-30 09:39:17 +08:00
|
|
|
void maybeRecordLocation(DebugLoc DL, const MachineFunction *MF);
|
|
|
|
|
|
|
|
void clear() {
|
2014-04-28 12:05:08 +08:00
|
|
|
assert(CurFn == nullptr);
|
2016-01-29 08:49:42 +08:00
|
|
|
FileIdMap.clear();
|
|
|
|
FnDebugInfo.clear();
|
|
|
|
FileToFilepathMap.clear();
|
2014-01-30 09:39:17 +08:00
|
|
|
}
|
|
|
|
|
2016-05-26 07:16:12 +08:00
|
|
|
/// Emit the magic version number at the start of a CodeView type or symbol
|
|
|
|
/// section. Appears at the front of every .debug$S or .debug$T section.
|
|
|
|
void emitCodeViewMagicVersion();
|
|
|
|
|
2016-01-30 02:16:43 +08:00
|
|
|
void emitTypeInformation();
|
|
|
|
|
2016-05-26 07:16:12 +08:00
|
|
|
void emitInlineeLinesSubsection();
|
2016-02-03 01:41:18 +08:00
|
|
|
|
2016-01-29 08:49:42 +08:00
|
|
|
void emitDebugInfoForFunction(const Function *GV, FunctionInfo &FI);
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2016-01-30 02:16:43 +08:00
|
|
|
void emitInlinedCallSite(const FunctionInfo &FI, const DILocation *InlinedAt,
|
|
|
|
const InlineSite &Site);
|
|
|
|
|
2016-02-13 05:48:30 +08:00
|
|
|
typedef DbgValueHistoryMap::InlinedVariable InlinedVariable;
|
|
|
|
|
|
|
|
void collectVariableInfo(const DISubprogram *SP);
|
|
|
|
|
|
|
|
void collectVariableInfoFromMMITable(DenseSet<InlinedVariable> &Processed);
|
|
|
|
|
|
|
|
/// Records information about a local variable in the appropriate scope. In
|
|
|
|
/// particular, locals from inlined code live inside the inlining site.
|
|
|
|
void recordLocalVariable(LocalVariable &&Var, const DILocation *Loc);
|
2016-02-11 04:55:49 +08:00
|
|
|
|
|
|
|
void emitLocalVariable(const LocalVariable &Var);
|
|
|
|
|
2016-06-02 01:05:51 +08:00
|
|
|
/// Translates the DIType to codeview if necessary and returns a type index
|
|
|
|
/// for it.
|
2016-06-03 23:58:20 +08:00
|
|
|
codeview::TypeIndex getTypeIndex(DITypeRef TypeRef);
|
2016-06-02 01:05:51 +08:00
|
|
|
|
|
|
|
codeview::TypeIndex lowerType(const DIType *Ty);
|
2016-06-02 14:21:37 +08:00
|
|
|
codeview::TypeIndex lowerTypeAlias(const DIDerivedType *Ty);
|
2016-06-02 01:05:51 +08:00
|
|
|
codeview::TypeIndex lowerTypeBasic(const DIBasicType *Ty);
|
|
|
|
codeview::TypeIndex lowerTypePointer(const DIDerivedType *Ty);
|
|
|
|
codeview::TypeIndex lowerTypeMemberPointer(const DIDerivedType *Ty);
|
|
|
|
codeview::TypeIndex lowerTypeModifier(const DIDerivedType *Ty);
|
2016-06-03 01:13:53 +08:00
|
|
|
codeview::TypeIndex lowerTypeFunction(const DISubroutineType *Ty);
|
2016-06-03 23:58:20 +08:00
|
|
|
codeview::TypeIndex lowerTypeClass(const DICompositeType *Ty);
|
|
|
|
codeview::TypeIndex lowerTypeUnion(const DICompositeType *Ty);
|
|
|
|
|
|
|
|
/// Symbol records should point to complete types, but type records should
|
|
|
|
/// always point to incomplete types to avoid cycles in the type graph. Only
|
|
|
|
/// use this entry point when generating symbol records. The complete and
|
|
|
|
/// incomplete type indices only differ for record types. All other types use
|
|
|
|
/// the same index.
|
|
|
|
codeview::TypeIndex getCompleteTypeIndex(DITypeRef TypeRef);
|
|
|
|
|
|
|
|
codeview::TypeIndex lowerCompleteTypeClass(const DICompositeType *Ty);
|
|
|
|
codeview::TypeIndex lowerCompleteTypeUnion(const DICompositeType *Ty);
|
|
|
|
|
|
|
|
/// Common record member lowering functionality for record types, which are
|
|
|
|
/// structs, classes, and unions. Returns the field list index and the member
|
|
|
|
/// count.
|
|
|
|
std::pair<codeview::TypeIndex, unsigned>
|
|
|
|
lowerRecordFieldList(const DICompositeType *Ty);
|
|
|
|
|
|
|
|
/// Inserts {Node, TI} into TypeIndices and checks for duplicates.
|
|
|
|
void recordTypeIndexForDINode(const DINode *Node, codeview::TypeIndex TI);
|
2016-06-02 01:05:51 +08:00
|
|
|
|
2014-01-30 09:39:17 +08:00
|
|
|
public:
|
2016-01-15 03:25:04 +08:00
|
|
|
CodeViewDebug(AsmPrinter *Asm);
|
2014-01-30 09:39:17 +08:00
|
|
|
|
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
|
|
|
};
|
|
|
|
} // End of namespace llvm
|
|
|
|
|
|
|
|
#endif
|