2017-06-07 06:22:41 +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
|
|
|
|
2018-08-17 23:22:04 +08:00
|
|
|
#include "DbgEntityHistoryCalculator.h"
|
2016-02-11 04:55:49 +08:00
|
|
|
#include "DebugHandlerBase.h"
|
2017-06-07 06:22:41 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2014-01-30 09:39:17 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2017-06-07 06:22:41 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
|
|
|
#include "llvm/ADT/MapVector.h"
|
|
|
|
#include "llvm/ADT/SetVector.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/DebugInfo/CodeView/CodeView.h"
|
2017-12-14 06:33:58 +08:00
|
|
|
#include "llvm/DebugInfo/CodeView/GlobalTypeTableBuilder.h"
|
2016-01-30 02:16:43 +08:00
|
|
|
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
|
2014-03-05 18:30:38 +08:00
|
|
|
#include "llvm/IR/DebugLoc.h"
|
2017-06-07 06:22:41 +08:00
|
|
|
#include "llvm/Support/Allocator.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include <cstdint>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <tuple>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2014-01-30 09:39:17 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2016-02-11 04:55:49 +08:00
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
struct ClassInfo;
|
2017-06-07 06:22:41 +08:00
|
|
|
class StringRef;
|
|
|
|
class AsmPrinter;
|
|
|
|
class Function;
|
|
|
|
class GlobalVariable;
|
|
|
|
class MCSectionCOFF;
|
|
|
|
class MCStreamer;
|
|
|
|
class MCSymbol;
|
|
|
|
class MachineFunction;
|
2016-02-11 04:55:49 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// 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;
|
2017-06-07 06:22:41 +08:00
|
|
|
BumpPtrAllocator Allocator;
|
2017-12-14 06:33:58 +08:00
|
|
|
codeview::GlobalTypeTableBuilder TypeTable;
|
2016-02-11 04:55:49 +08:00
|
|
|
|
2018-11-17 02:47:41 +08:00
|
|
|
/// Whether to emit type record hashes into .debug$H.
|
|
|
|
bool EmitDebugGlobalHashes = false;
|
|
|
|
|
[codeview] Emit S_FRAMEPROC and use S_DEFRANGE_FRAMEPOINTER_REL
Summary:
Before this change, LLVM would always describe locals on the stack as
being relative to some specific register, RSP, ESP, EBP, ESI, etc.
Variables in stack memory are pretty common, so there is a special
S_DEFRANGE_FRAMEPOINTER_REL symbol for them. This change uses it to
reduce the size of our debug info.
On top of the size savings, there are cases on 32-bit x86 where local
variables are addressed from ESP, but ESP changes across the function.
Unlike in DWARF, there is no FPO data to describe the stack adjustments
made to push arguments onto the stack and pop them off after the call,
which makes it hard for the debugger to find the local variables in
frames further up the stack.
To handle this, CodeView has a special VFRAME register, which
corresponds to the $T0 variable set by our FPO data in 32-bit. Offsets
to local variables are instead relative to this value.
This is part of PR38857.
Reviewers: hans, zturner, javed.absar
Subscribers: aprantl, hiraditya, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D52217
llvm-svn: 343543
2018-10-02 05:59:45 +08:00
|
|
|
/// The codeview CPU type used by the translation unit.
|
|
|
|
codeview::CPUType TheCPU;
|
|
|
|
|
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;
|
|
|
|
|
2016-10-06 05:21:33 +08:00
|
|
|
/// Non-zero if this is a piece of an aggregate.
|
|
|
|
uint16_t IsSubfield : 1;
|
|
|
|
|
|
|
|
/// Offset into aggregate.
|
|
|
|
uint16_t StructOffset : 15;
|
2016-02-13 05:48:30 +08:00
|
|
|
|
|
|
|
/// 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 ||
|
2016-10-06 05:21:33 +08:00
|
|
|
IsSubfield != O.IsSubfield || StructOffset != O.StructOffset ||
|
|
|
|
CVRegister != O.CVRegister;
|
2016-02-13 05:48:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SmallVector<std::pair<const MCSymbol *, const MCSymbol *>, 1> Ranges;
|
|
|
|
};
|
|
|
|
|
|
|
|
static LocalVarDefRange createDefRangeMem(uint16_t CVRegister, int Offset);
|
|
|
|
|
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;
|
2017-08-31 23:56:49 +08:00
|
|
|
bool UseReferenceType = false;
|
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;
|
2016-07-15 07:47:15 +08:00
|
|
|
|
|
|
|
/// The ID of the inline site or function used with .cv_loc. Not a type
|
|
|
|
/// index.
|
2016-01-30 02:16:43 +08:00
|
|
|
unsigned SiteFuncId = 0;
|
|
|
|
};
|
|
|
|
|
2018-03-16 05:24:04 +08:00
|
|
|
// Combines information from DILexicalBlock and LexicalScope.
|
|
|
|
struct LexicalBlock {
|
|
|
|
SmallVector<LocalVariable, 1> Locals;
|
|
|
|
SmallVector<LexicalBlock *, 1> Children;
|
|
|
|
const MCSymbol *Begin;
|
|
|
|
const MCSymbol *End;
|
|
|
|
StringRef Name;
|
|
|
|
};
|
|
|
|
|
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 {
|
2018-03-16 05:12:21 +08:00
|
|
|
FunctionInfo() = default;
|
|
|
|
|
|
|
|
// Uncopyable.
|
|
|
|
FunctionInfo(const FunctionInfo &FI) = delete;
|
|
|
|
|
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
|
|
|
|
2018-03-16 05:24:04 +08:00
|
|
|
std::unordered_map<const DILexicalBlockBase*, LexicalBlock> LexicalBlocks;
|
|
|
|
|
|
|
|
// Lexical blocks containing local variables.
|
|
|
|
SmallVector<LexicalBlock *, 1> ChildBlocks;
|
|
|
|
|
2017-09-06 04:14:58 +08:00
|
|
|
std::vector<std::pair<MCSymbol *, MDNode *>> Annotations;
|
|
|
|
|
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;
|
[codeview] Emit S_FRAMEPROC and use S_DEFRANGE_FRAMEPOINTER_REL
Summary:
Before this change, LLVM would always describe locals on the stack as
being relative to some specific register, RSP, ESP, EBP, ESI, etc.
Variables in stack memory are pretty common, so there is a special
S_DEFRANGE_FRAMEPOINTER_REL symbol for them. This change uses it to
reduce the size of our debug info.
On top of the size savings, there are cases on 32-bit x86 where local
variables are addressed from ESP, but ESP changes across the function.
Unlike in DWARF, there is no FPO data to describe the stack adjustments
made to push arguments onto the stack and pop them off after the call,
which makes it hard for the debugger to find the local variables in
frames further up the stack.
To handle this, CodeView has a special VFRAME register, which
corresponds to the $T0 variable set by our FPO data in 32-bit. Offsets
to local variables are instead relative to this value.
This is part of PR38857.
Reviewers: hans, zturner, javed.absar
Subscribers: aprantl, hiraditya, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D52217
llvm-svn: 343543
2018-10-02 05:59:45 +08:00
|
|
|
|
|
|
|
/// Number of bytes allocated in the prologue for all local stack objects.
|
|
|
|
unsigned FrameSize = 0;
|
|
|
|
|
|
|
|
/// Number of bytes of parameters on the stack.
|
|
|
|
unsigned ParamSize = 0;
|
|
|
|
|
|
|
|
/// Number of bytes pushed to save CSRs.
|
|
|
|
unsigned CSRSize = 0;
|
|
|
|
|
2018-11-03 08:41:52 +08:00
|
|
|
/// Adjustment to apply on x86 when using the VFRAME frame pointer.
|
|
|
|
int OffsetAdjustment = 0;
|
|
|
|
|
[codeview] Emit S_FRAMEPROC and use S_DEFRANGE_FRAMEPOINTER_REL
Summary:
Before this change, LLVM would always describe locals on the stack as
being relative to some specific register, RSP, ESP, EBP, ESI, etc.
Variables in stack memory are pretty common, so there is a special
S_DEFRANGE_FRAMEPOINTER_REL symbol for them. This change uses it to
reduce the size of our debug info.
On top of the size savings, there are cases on 32-bit x86 where local
variables are addressed from ESP, but ESP changes across the function.
Unlike in DWARF, there is no FPO data to describe the stack adjustments
made to push arguments onto the stack and pop them off after the call,
which makes it hard for the debugger to find the local variables in
frames further up the stack.
To handle this, CodeView has a special VFRAME register, which
corresponds to the $T0 variable set by our FPO data in 32-bit. Offsets
to local variables are instead relative to this value.
This is part of PR38857.
Reviewers: hans, zturner, javed.absar
Subscribers: aprantl, hiraditya, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D52217
llvm-svn: 343543
2018-10-02 05:59:45 +08:00
|
|
|
/// Two-bit value indicating which register is the designated frame pointer
|
|
|
|
/// register for local variables. Included in S_FRAMEPROC.
|
|
|
|
codeview::EncodedFramePtrReg EncodedLocalFramePtrReg =
|
|
|
|
codeview::EncodedFramePtrReg::None;
|
|
|
|
|
|
|
|
/// Two-bit value indicating which register is the designated frame pointer
|
|
|
|
/// register for stack parameters. Included in S_FRAMEPROC.
|
|
|
|
codeview::EncodedFramePtrReg EncodedParamFramePtrReg =
|
|
|
|
codeview::EncodedFramePtrReg::None;
|
|
|
|
|
|
|
|
codeview::FrameProcedureOptions FrameProcOpts;
|
|
|
|
|
2018-10-03 00:43:52 +08:00
|
|
|
bool HasStackRealignment = false;
|
|
|
|
|
2016-01-29 08:49:42 +08:00
|
|
|
bool HaveLineInfo = false;
|
2016-01-16 08:09:09 +08:00
|
|
|
};
|
2017-06-07 06:22:41 +08:00
|
|
|
FunctionInfo *CurFn = nullptr;
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2018-03-16 05:24:04 +08:00
|
|
|
// Map used to seperate variables according to the lexical scope they belong
|
|
|
|
// in. This is populated by recordLocalVariable() before
|
|
|
|
// collectLexicalBlocks() separates the variables between the FunctionInfo
|
|
|
|
// and LexicalBlocks.
|
|
|
|
DenseMap<const LexicalScope *, SmallVector<LocalVariable, 1>> ScopeVariables;
|
|
|
|
|
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
|
|
|
|
2017-08-30 04:59:25 +08:00
|
|
|
void calculateRanges(LocalVariable &Var,
|
|
|
|
const DbgValueHistoryMap::InstrRanges &Ranges);
|
|
|
|
|
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.
|
2018-03-16 05:12:21 +08:00
|
|
|
MapVector<const Function *, std::unique_ptr<FunctionInfo>> FnDebugInfo;
|
2016-01-29 08:49:42 +08:00
|
|
|
|
2017-11-01 05:52:15 +08:00
|
|
|
/// Map from full file path to .cv_file id. Full paths are built from DIFiles
|
|
|
|
/// and are stored in FileToFilepathMap;
|
|
|
|
DenseMap<StringRef, 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;
|
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
/// Map from a pair of DI metadata nodes and its DI type (or scope) that can
|
|
|
|
/// be nullptr, to CodeView type indices. Primarily indexed by
|
|
|
|
/// {DIType*, DIType*} and {DISubprogram*, DIType*}.
|
|
|
|
///
|
|
|
|
/// The second entry in the key is needed for methods as DISubroutineType
|
|
|
|
/// representing static method type are shared with non-method function type.
|
|
|
|
DenseMap<std::pair<const DINode *, const DIType *>, 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-06-23 01:15:28 +08:00
|
|
|
/// Complete record types to emit after all active type lowerings are
|
|
|
|
/// finished.
|
|
|
|
SmallVector<const DICompositeType *, 4> DeferredCompleteTypes;
|
|
|
|
|
|
|
|
/// Number of type lowering frames active on the stack.
|
|
|
|
unsigned TypeEmissionLevel = 0;
|
|
|
|
|
2016-06-25 00:24:24 +08:00
|
|
|
codeview::TypeIndex VBPType;
|
|
|
|
|
2016-06-16 02:00:01 +08:00
|
|
|
const DISubprogram *CurrentSubprogram = nullptr;
|
|
|
|
|
|
|
|
// The UDTs we have seen while processing types; each entry is a pair of type
|
|
|
|
// index and type name.
|
[CodeView] Don't output S_UDT symbols for forward decls.
S_UDT symbols are the debugger's "index" for all the structs,
typedefs, classes, and enums in a program. If any of those
structs/classes don't have a complete declaration, or if there
is a typedef to something that doesn't have a complete definition,
then emitting the S_UDT is unhelpful because it doesn't give
the debugger enough information to do anything useful. On the
other hand, it results in a huge size blow-up in the resulting
PDB, which is exacerbated by an order of magnitude when linking
with /DEBUG:FASTLINK.
With this patch, we drop S_UDT records for types that refer either
directly or indirectly (e.g. through a typedef, pointer, etc) to
a class/struct/union/enum without a complete definition. This
brings us about 50% of the way towards parity with /DEBUG:FASTLINK
PDBs generated from cl-compiled object files.
Differential Revision: https://reviews.llvm.org/D37162
llvm-svn: 311904
2017-08-29 02:49:04 +08:00
|
|
|
std::vector<std::pair<std::string, const DIType *>> LocalUDTs;
|
|
|
|
std::vector<std::pair<std::string, const DIType *>> GlobalUDTs;
|
2016-06-16 02:00:01 +08:00
|
|
|
|
2017-06-07 06:22:41 +08:00
|
|
|
using FileToFilepathMapTy = std::map<const DIFile *, std::string>;
|
2016-01-16 08:09:09 +08:00
|
|
|
FileToFilepathMapTy FileToFilepathMap;
|
2017-06-07 06:22:41 +08:00
|
|
|
|
2018-07-17 02:51:40 +08:00
|
|
|
StringRef getFullFilepath(const DIFile *File);
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2016-01-29 08:49:42 +08:00
|
|
|
unsigned maybeRecordFile(const DIFile *F);
|
|
|
|
|
2016-06-12 23:39:02 +08:00
|
|
|
void maybeRecordLocation(const DebugLoc &DL, const MachineFunction *MF);
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
void clear();
|
2016-06-16 02:00:01 +08:00
|
|
|
|
|
|
|
void setCurrentSubprogram(const DISubprogram *SP) {
|
|
|
|
CurrentSubprogram = SP;
|
|
|
|
LocalUDTs.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
|
2018-04-10 04:17:56 +08:00
|
|
|
/// section. Appears at the front of every .debug$S or .debug$T or .debug$P
|
|
|
|
/// section.
|
2016-05-26 07:16:12 +08:00
|
|
|
void emitCodeViewMagicVersion();
|
|
|
|
|
2016-01-30 02:16:43 +08:00
|
|
|
void emitTypeInformation();
|
|
|
|
|
2017-12-14 06:33:58 +08:00
|
|
|
void emitTypeGlobalHashes();
|
|
|
|
|
2016-09-21 01:20:51 +08:00
|
|
|
void emitCompilerInformation();
|
|
|
|
|
2018-10-13 02:19:06 +08:00
|
|
|
void emitBuildInfo();
|
|
|
|
|
2016-05-26 07:16:12 +08:00
|
|
|
void emitInlineeLinesSubsection();
|
2016-02-03 01:41:18 +08:00
|
|
|
|
2018-04-17 00:53:57 +08:00
|
|
|
void emitDebugInfoForThunk(const Function *GV,
|
|
|
|
FunctionInfo &FI,
|
|
|
|
const MCSymbol *Fn);
|
|
|
|
|
2016-01-29 08:49:42 +08:00
|
|
|
void emitDebugInfoForFunction(const Function *GV, FunctionInfo &FI);
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2016-06-07 08:02:03 +08:00
|
|
|
void emitDebugInfoForGlobals();
|
|
|
|
|
2016-06-24 00:33:53 +08:00
|
|
|
void emitDebugInfoForRetainedTypes();
|
|
|
|
|
[CodeView] Don't output S_UDT symbols for forward decls.
S_UDT symbols are the debugger's "index" for all the structs,
typedefs, classes, and enums in a program. If any of those
structs/classes don't have a complete declaration, or if there
is a typedef to something that doesn't have a complete definition,
then emitting the S_UDT is unhelpful because it doesn't give
the debugger enough information to do anything useful. On the
other hand, it results in a huge size blow-up in the resulting
PDB, which is exacerbated by an order of magnitude when linking
with /DEBUG:FASTLINK.
With this patch, we drop S_UDT records for types that refer either
directly or indirectly (e.g. through a typedef, pointer, etc) to
a class/struct/union/enum without a complete definition. This
brings us about 50% of the way towards parity with /DEBUG:FASTLINK
PDBs generated from cl-compiled object files.
Differential Revision: https://reviews.llvm.org/D37162
llvm-svn: 311904
2017-08-29 02:49:04 +08:00
|
|
|
void
|
|
|
|
emitDebugInfoForUDTs(ArrayRef<std::pair<std::string, const DIType *>> UDTs);
|
2016-06-16 02:00:01 +08:00
|
|
|
|
2016-09-13 09:12:59 +08:00
|
|
|
void emitDebugInfoForGlobal(const DIGlobalVariable *DIGV,
|
|
|
|
const GlobalVariable *GV, MCSymbol *GVSym);
|
2016-06-07 08:02:03 +08:00
|
|
|
|
|
|
|
/// Opens a subsection of the given kind in a .debug$S codeview section.
|
|
|
|
/// Returns an end label for use with endCVSubsection when the subsection is
|
|
|
|
/// finished.
|
2017-05-31 00:36:15 +08:00
|
|
|
MCSymbol *beginCVSubsection(codeview::DebugSubsectionKind Kind);
|
2016-06-07 08:02:03 +08:00
|
|
|
|
|
|
|
void endCVSubsection(MCSymbol *EndLabel);
|
|
|
|
|
2016-01-30 02:16:43 +08:00
|
|
|
void emitInlinedCallSite(const FunctionInfo &FI, const DILocation *InlinedAt,
|
|
|
|
const InlineSite &Site);
|
|
|
|
|
2018-09-06 10:22:06 +08:00
|
|
|
using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
|
2016-02-13 05:48:30 +08:00
|
|
|
|
|
|
|
void collectVariableInfo(const DISubprogram *SP);
|
|
|
|
|
2018-09-06 10:22:06 +08:00
|
|
|
void collectVariableInfoFromMFTable(DenseSet<InlinedEntity> &Processed);
|
2016-02-13 05:48:30 +08:00
|
|
|
|
2018-03-16 05:24:04 +08:00
|
|
|
// Construct the lexical block tree for a routine, pruning emptpy lexical
|
|
|
|
// scopes, and populate it with local variables.
|
|
|
|
void collectLexicalBlockInfo(SmallVectorImpl<LexicalScope *> &Scopes,
|
|
|
|
SmallVectorImpl<LexicalBlock *> &Blocks,
|
|
|
|
SmallVectorImpl<LocalVariable> &Locals);
|
|
|
|
void collectLexicalBlockInfo(LexicalScope &Scope,
|
|
|
|
SmallVectorImpl<LexicalBlock *> &ParentBlocks,
|
|
|
|
SmallVectorImpl<LocalVariable> &ParentLocals);
|
|
|
|
|
2016-02-13 05:48:30 +08:00
|
|
|
/// Records information about a local variable in the appropriate scope. In
|
|
|
|
/// particular, locals from inlined code live inside the inlining site.
|
2018-03-16 05:24:04 +08:00
|
|
|
void recordLocalVariable(LocalVariable &&Var, const LexicalScope *LS);
|
2016-02-11 04:55:49 +08:00
|
|
|
|
2016-06-25 01:55:40 +08:00
|
|
|
/// Emits local variables in the appropriate order.
|
[codeview] Emit S_FRAMEPROC and use S_DEFRANGE_FRAMEPOINTER_REL
Summary:
Before this change, LLVM would always describe locals on the stack as
being relative to some specific register, RSP, ESP, EBP, ESI, etc.
Variables in stack memory are pretty common, so there is a special
S_DEFRANGE_FRAMEPOINTER_REL symbol for them. This change uses it to
reduce the size of our debug info.
On top of the size savings, there are cases on 32-bit x86 where local
variables are addressed from ESP, but ESP changes across the function.
Unlike in DWARF, there is no FPO data to describe the stack adjustments
made to push arguments onto the stack and pop them off after the call,
which makes it hard for the debugger to find the local variables in
frames further up the stack.
To handle this, CodeView has a special VFRAME register, which
corresponds to the $T0 variable set by our FPO data in 32-bit. Offsets
to local variables are instead relative to this value.
This is part of PR38857.
Reviewers: hans, zturner, javed.absar
Subscribers: aprantl, hiraditya, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D52217
llvm-svn: 343543
2018-10-02 05:59:45 +08:00
|
|
|
void emitLocalVariableList(const FunctionInfo &FI,
|
|
|
|
ArrayRef<LocalVariable> Locals);
|
2016-06-25 01:55:40 +08:00
|
|
|
|
|
|
|
/// Emits an S_LOCAL record and its associated defined ranges.
|
[codeview] Emit S_FRAMEPROC and use S_DEFRANGE_FRAMEPOINTER_REL
Summary:
Before this change, LLVM would always describe locals on the stack as
being relative to some specific register, RSP, ESP, EBP, ESI, etc.
Variables in stack memory are pretty common, so there is a special
S_DEFRANGE_FRAMEPOINTER_REL symbol for them. This change uses it to
reduce the size of our debug info.
On top of the size savings, there are cases on 32-bit x86 where local
variables are addressed from ESP, but ESP changes across the function.
Unlike in DWARF, there is no FPO data to describe the stack adjustments
made to push arguments onto the stack and pop them off after the call,
which makes it hard for the debugger to find the local variables in
frames further up the stack.
To handle this, CodeView has a special VFRAME register, which
corresponds to the $T0 variable set by our FPO data in 32-bit. Offsets
to local variables are instead relative to this value.
This is part of PR38857.
Reviewers: hans, zturner, javed.absar
Subscribers: aprantl, hiraditya, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D52217
llvm-svn: 343543
2018-10-02 05:59:45 +08:00
|
|
|
void emitLocalVariable(const FunctionInfo &FI, const LocalVariable &Var);
|
2016-02-11 04:55:49 +08:00
|
|
|
|
2018-03-16 05:24:04 +08:00
|
|
|
/// Emits a sequence of lexical block scopes and their children.
|
|
|
|
void emitLexicalBlockList(ArrayRef<LexicalBlock *> Blocks,
|
|
|
|
const FunctionInfo& FI);
|
|
|
|
|
|
|
|
/// Emit a lexical block scope and its children.
|
|
|
|
void emitLexicalBlock(const LexicalBlock &Block, const FunctionInfo& FI);
|
|
|
|
|
2016-06-02 01:05:51 +08:00
|
|
|
/// Translates the DIType to codeview if necessary and returns a type index
|
|
|
|
/// for it.
|
2016-06-18 18:25:07 +08:00
|
|
|
codeview::TypeIndex getTypeIndex(DITypeRef TypeRef,
|
|
|
|
DITypeRef ClassTyRef = DITypeRef());
|
2016-06-02 01:05:51 +08:00
|
|
|
|
2018-11-21 06:13:43 +08:00
|
|
|
codeview::TypeIndex
|
|
|
|
getTypeIndexForThisPtr(DITypeRef TypeRef,
|
|
|
|
const DISubroutineType *SubroutineTy);
|
|
|
|
|
2017-08-30 04:59:25 +08:00
|
|
|
codeview::TypeIndex getTypeIndexForReferenceTo(DITypeRef TypeRef);
|
|
|
|
|
2016-06-22 09:32:56 +08:00
|
|
|
codeview::TypeIndex getMemberFunctionType(const DISubprogram *SP,
|
|
|
|
const DICompositeType *Class);
|
|
|
|
|
|
|
|
codeview::TypeIndex getScopeIndex(const DIScope *Scope);
|
|
|
|
|
2016-06-25 00:24:24 +08:00
|
|
|
codeview::TypeIndex getVBPTypeIndex();
|
|
|
|
|
[CodeView] Don't output S_UDT symbols for forward decls.
S_UDT symbols are the debugger's "index" for all the structs,
typedefs, classes, and enums in a program. If any of those
structs/classes don't have a complete declaration, or if there
is a typedef to something that doesn't have a complete definition,
then emitting the S_UDT is unhelpful because it doesn't give
the debugger enough information to do anything useful. On the
other hand, it results in a huge size blow-up in the resulting
PDB, which is exacerbated by an order of magnitude when linking
with /DEBUG:FASTLINK.
With this patch, we drop S_UDT records for types that refer either
directly or indirectly (e.g. through a typedef, pointer, etc) to
a class/struct/union/enum without a complete definition. This
brings us about 50% of the way towards parity with /DEBUG:FASTLINK
PDBs generated from cl-compiled object files.
Differential Revision: https://reviews.llvm.org/D37162
llvm-svn: 311904
2017-08-29 02:49:04 +08:00
|
|
|
void addToUDTs(const DIType *Ty);
|
2016-06-24 06:57:25 +08:00
|
|
|
|
2018-03-07 02:20:22 +08:00
|
|
|
void addUDTSrcLine(const DIType *Ty, codeview::TypeIndex TI);
|
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
codeview::TypeIndex lowerType(const DIType *Ty, const DIType *ClassTy);
|
2016-06-02 14:21:37 +08:00
|
|
|
codeview::TypeIndex lowerTypeAlias(const DIDerivedType *Ty);
|
2016-06-09 02:22:59 +08:00
|
|
|
codeview::TypeIndex lowerTypeArray(const DICompositeType *Ty);
|
2016-06-02 01:05:51 +08:00
|
|
|
codeview::TypeIndex lowerTypeBasic(const DIBasicType *Ty);
|
[CodeView] Lower __restrict and other pointer qualifiers correctly
Qualifiers on a pointer or reference type may apply to either the
pointee or the pointer itself. Consider 'const char *' and 'char *
const'. In the first example, the pointee data may not be modified
without casts, and in the second example, the pointer may not be updated
to point to new data.
In the general case, qualifiers are applied to types with LF_MODIFIER
records, which support the usual const and volatile qualifiers as well
as the __unaligned extension qualifier.
However, LF_POINTER records, which are used for pointers, references,
and member pointers, have flags for qualifiers applying to the
*pointer*. In fact, this is the only way to represent the restrict
qualifier, which can only apply to pointers, and cannot qualify regular
data types.
This patch causes LLVM to correctly fold 'const' and 'volatile' pointer
qualifiers into the pointer record, as well as adding support for
'__restrict' qualifiers in the same place.
Based on a patch from Aaron Smith
Differential Revision: https://reviews.llvm.org/D43060
llvm-svn: 326260
2018-02-28 06:08:15 +08:00
|
|
|
codeview::TypeIndex lowerTypePointer(
|
|
|
|
const DIDerivedType *Ty,
|
|
|
|
codeview::PointerOptions PO = codeview::PointerOptions::None);
|
|
|
|
codeview::TypeIndex lowerTypeMemberPointer(
|
|
|
|
const DIDerivedType *Ty,
|
|
|
|
codeview::PointerOptions PO = codeview::PointerOptions::None);
|
2016-06-02 01:05:51 +08:00
|
|
|
codeview::TypeIndex lowerTypeModifier(const DIDerivedType *Ty);
|
2016-06-03 01:13:53 +08:00
|
|
|
codeview::TypeIndex lowerTypeFunction(const DISubroutineType *Ty);
|
2016-08-31 23:59:30 +08:00
|
|
|
codeview::TypeIndex lowerTypeVFTableShape(const DIDerivedType *Ty);
|
2018-10-03 04:21:05 +08:00
|
|
|
codeview::TypeIndex lowerTypeMemberFunction(
|
|
|
|
const DISubroutineType *Ty, const DIType *ClassTy, int ThisAdjustment,
|
|
|
|
bool IsStaticMethod,
|
|
|
|
codeview::FunctionOptions FO = codeview::FunctionOptions::None);
|
2016-06-17 05:32:16 +08:00
|
|
|
codeview::TypeIndex lowerTypeEnum(const DICompositeType *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);
|
|
|
|
|
2016-06-23 01:15:28 +08:00
|
|
|
struct TypeLoweringScope;
|
|
|
|
|
|
|
|
void emitDeferredCompleteTypes();
|
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
void collectMemberInfo(ClassInfo &Info, const DIDerivedType *DDTy);
|
2016-06-23 00:06:42 +08:00
|
|
|
ClassInfo collectClassInfo(const DICompositeType *Ty);
|
2016-06-18 18:25:07 +08:00
|
|
|
|
2016-06-03 23:58:20 +08:00
|
|
|
/// Common record member lowering functionality for record types, which are
|
|
|
|
/// structs, classes, and unions. Returns the field list index and the member
|
|
|
|
/// count.
|
2016-07-07 03:49:51 +08:00
|
|
|
std::tuple<codeview::TypeIndex, codeview::TypeIndex, unsigned, bool>
|
2016-06-03 23:58:20 +08:00
|
|
|
lowerRecordFieldList(const DICompositeType *Ty);
|
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
/// Inserts {{Node, ClassTy}, TI} into TypeIndices and checks for duplicates.
|
2016-06-22 09:32:56 +08:00
|
|
|
codeview::TypeIndex recordTypeIndexForDINode(const DINode *Node,
|
|
|
|
codeview::TypeIndex TI,
|
|
|
|
const DIType *ClassTy = nullptr);
|
2016-06-18 18:25:07 +08:00
|
|
|
|
|
|
|
unsigned getPointerSizeInBytes();
|
2016-06-02 01:05:51 +08:00
|
|
|
|
2017-02-17 02:48:33 +08:00
|
|
|
protected:
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Gather pre-function debug information.
|
2017-02-17 02:48:33 +08:00
|
|
|
void beginFunctionImpl(const MachineFunction *MF) override;
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Gather post-function debug information.
|
2017-02-17 02:48:33 +08:00
|
|
|
void endFunctionImpl(const MachineFunction *) override;
|
|
|
|
|
2014-01-30 09:39:17 +08:00
|
|
|
public:
|
2018-07-17 02:51:40 +08:00
|
|
|
CodeViewDebug(AsmPrinter *AP);
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2017-06-07 06:22:41 +08:00
|
|
|
void setSymbolSize(const MCSymbol *, uint64_t) override {}
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// 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
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// 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
|
|
|
};
|
|
|
|
|
2017-06-07 06:22:41 +08:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H
|