#include "CodeViewDebug.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/LexicalScopes.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/TargetFrameLowering.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
#include "llvm/DebugInfo/CodeView/CodeViewRecordIO.h"
#include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h"
#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
#include "llvm/DebugInfo/CodeView/EnumTables.h"
#include "llvm/DebugInfo/CodeView/Line.h"
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
#include "llvm/DebugInfo/CodeView/TypeTableCollection.h"
#include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCSectionCOFF.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/BinaryStreamWriter.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/SMLoc.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/TargetParser/Triple.h"
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstddef>
#include <iterator>
#include <limits>
usingnamespacellvm;
usingnamespacellvm::codeview;
namespace {
class CVMCAdapter : public CodeViewRecordStreamer { … };
}
static CPUType mapArchToCVCPUType(Triple::ArchType Type) { … }
CodeViewDebug::CodeViewDebug(AsmPrinter *AP)
: … { … }
StringRef CodeViewDebug::getFullFilepath(const DIFile *File) { … }
unsigned CodeViewDebug::maybeRecordFile(const DIFile *F) { … }
CodeViewDebug::InlineSite &
CodeViewDebug::getInlineSite(const DILocation *InlinedAt,
const DISubprogram *Inlinee) { … }
static StringRef getPrettyScopeName(const DIScope *Scope) { … }
const DISubprogram *CodeViewDebug::collectParentScopeNames(
const DIScope *Scope, SmallVectorImpl<StringRef> &QualifiedNameComponents) { … }
static std::string formatNestedName(ArrayRef<StringRef> QualifiedNameComponents,
StringRef TypeName) { … }
struct CodeViewDebug::TypeLoweringScope { … };
std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Scope,
StringRef Name) { … }
std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Ty) { … }
TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) { … }
static StringRef removeTemplateArgs(StringRef Name) { … }
TypeIndex CodeViewDebug::getFuncIdForSubprogram(const DISubprogram *SP) { … }
static bool isNonTrivial(const DICompositeType *DCTy) { … }
static FunctionOptions
getFunctionOptions(const DISubroutineType *Ty,
const DICompositeType *ClassTy = nullptr,
StringRef SPName = StringRef("")) { … }
TypeIndex CodeViewDebug::getMemberFunctionType(const DISubprogram *SP,
const DICompositeType *Class) { … }
TypeIndex CodeViewDebug::recordTypeIndexForDINode(const DINode *Node,
TypeIndex TI,
const DIType *ClassTy) { … }
unsigned CodeViewDebug::getPointerSizeInBytes() { … }
void CodeViewDebug::recordLocalVariable(LocalVariable &&Var,
const LexicalScope *LS) { … }
static void addLocIfNotPresent(SmallVectorImpl<const DILocation *> &Locs,
const DILocation *Loc) { … }
void CodeViewDebug::maybeRecordLocation(const DebugLoc &DL,
const MachineFunction *MF) { … }
void CodeViewDebug::emitCodeViewMagicVersion() { … }
static SourceLanguage MapDWLangToCVLang(unsigned DWLang) { … }
void CodeViewDebug::beginModule(Module *M) { … }
void CodeViewDebug::endModule() { … }
static void
emitNullTerminatedSymbolName(MCStreamer &OS, StringRef S,
unsigned MaxFixedRecordLength = 0xF00) { … }
void CodeViewDebug::emitTypeInformation() { … }
void CodeViewDebug::emitTypeGlobalHashes() { … }
void CodeViewDebug::emitObjName() { … }
namespace {
struct Version { … };
}
static Version parseVersion(StringRef Name) { … }
void CodeViewDebug::emitCompilerInformation() { … }
static TypeIndex getStringIdTypeIdx(GlobalTypeTableBuilder &TypeTable,
StringRef S) { … }
void CodeViewDebug::emitBuildInfo() { … }
void CodeViewDebug::emitInlineeLinesSubsection() { … }
void CodeViewDebug::emitInlinedCallSite(const FunctionInfo &FI,
const DILocation *InlinedAt,
const InlineSite &Site) { … }
void CodeViewDebug::switchToDebugSectionForSymbol(const MCSymbol *GVSym) { … }
void CodeViewDebug::emitDebugInfoForThunk(const Function *GV,
FunctionInfo &FI,
const MCSymbol *Fn) { … }
void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
FunctionInfo &FI) { … }
CodeViewDebug::LocalVarDef
CodeViewDebug::createDefRangeMem(uint16_t CVRegister, int Offset) { … }
void CodeViewDebug::collectVariableInfoFromMFTable(
DenseSet<InlinedEntity> &Processed) { … }
static bool canUseReferenceType(const DbgVariableLocation &Loc) { … }
static bool needsReferenceType(const DbgVariableLocation &Loc) { … }
void CodeViewDebug::calculateRanges(
LocalVariable &Var, const DbgValueHistoryMap::Entries &Entries) { … }
void CodeViewDebug::collectVariableInfo(const DISubprogram *SP) { … }
void CodeViewDebug::beginFunctionImpl(const MachineFunction *MF) { … }
static bool shouldEmitUdt(const DIType *T) { … }
void CodeViewDebug::addToUDTs(const DIType *Ty) { … }
TypeIndex CodeViewDebug::lowerType(const DIType *Ty, const DIType *ClassTy) { … }
TypeIndex CodeViewDebug::lowerTypeAlias(const DIDerivedType *Ty) { … }
TypeIndex CodeViewDebug::lowerTypeArray(const DICompositeType *Ty) { … }
TypeIndex CodeViewDebug::lowerTypeString(const DIStringType *Ty) { … }
TypeIndex CodeViewDebug::lowerTypeBasic(const DIBasicType *Ty) { … }
TypeIndex CodeViewDebug::lowerTypePointer(const DIDerivedType *Ty,
PointerOptions PO) { … }
static PointerToMemberRepresentation
translatePtrToMemberRep(unsigned SizeInBytes, bool IsPMF, unsigned Flags) { … }
TypeIndex CodeViewDebug::lowerTypeMemberPointer(const DIDerivedType *Ty,
PointerOptions PO) { … }
static CallingConvention dwarfCCToCodeView(unsigned DwarfCC) { … }
TypeIndex CodeViewDebug::lowerTypeModifier(const DIDerivedType *Ty) { … }
TypeIndex CodeViewDebug::lowerTypeFunction(const DISubroutineType *Ty) { … }
TypeIndex CodeViewDebug::lowerTypeMemberFunction(const DISubroutineType *Ty,
const DIType *ClassTy,
int ThisAdjustment,
bool IsStaticMethod,
FunctionOptions FO) { … }
TypeIndex CodeViewDebug::lowerTypeVFTableShape(const DIDerivedType *Ty) { … }
static MemberAccess translateAccessFlags(unsigned RecordTag, unsigned Flags) { … }
static MethodOptions translateMethodOptionFlags(const DISubprogram *SP) { … }
static MethodKind translateMethodKindFlags(const DISubprogram *SP,
bool Introduced) { … }
static TypeRecordKind getRecordKind(const DICompositeType *Ty) { … }
static ClassOptions getCommonClassOptions(const DICompositeType *Ty) { … }
void CodeViewDebug::addUDTSrcLine(const DIType *Ty, TypeIndex TI) { … }
TypeIndex CodeViewDebug::lowerTypeEnum(const DICompositeType *Ty) { … }
struct llvm::ClassInfo { … };
void CodeViewDebug::clear() { … }
void CodeViewDebug::collectMemberInfo(ClassInfo &Info,
const DIDerivedType *DDTy) { … }
ClassInfo CodeViewDebug::collectClassInfo(const DICompositeType *Ty) { … }
static bool shouldAlwaysEmitCompleteClassType(const DICompositeType *Ty) { … }
TypeIndex CodeViewDebug::lowerTypeClass(const DICompositeType *Ty) { … }
TypeIndex CodeViewDebug::lowerCompleteTypeClass(const DICompositeType *Ty) { … }
TypeIndex CodeViewDebug::lowerTypeUnion(const DICompositeType *Ty) { … }
TypeIndex CodeViewDebug::lowerCompleteTypeUnion(const DICompositeType *Ty) { … }
std::tuple<TypeIndex, TypeIndex, unsigned, bool>
CodeViewDebug::lowerRecordFieldList(const DICompositeType *Ty) { … }
TypeIndex CodeViewDebug::getVBPTypeIndex() { … }
TypeIndex CodeViewDebug::getTypeIndex(const DIType *Ty, const DIType *ClassTy) { … }
codeview::TypeIndex
CodeViewDebug::getTypeIndexForThisPtr(const DIDerivedType *PtrTy,
const DISubroutineType *SubroutineTy) { … }
TypeIndex CodeViewDebug::getTypeIndexForReferenceTo(const DIType *Ty) { … }
TypeIndex CodeViewDebug::getCompleteTypeIndex(const DIType *Ty) { … }
void CodeViewDebug::emitDeferredCompleteTypes() { … }
void CodeViewDebug::emitLocalVariableList(const FunctionInfo &FI,
ArrayRef<LocalVariable> Locals) { … }
void CodeViewDebug::emitLocalVariable(const FunctionInfo &FI,
const LocalVariable &Var) { … }
void CodeViewDebug::emitLexicalBlockList(ArrayRef<LexicalBlock *> Blocks,
const FunctionInfo& FI) { … }
void CodeViewDebug::emitLexicalBlock(const LexicalBlock &Block,
const FunctionInfo& FI) { … }
void CodeViewDebug::collectLexicalBlockInfo(
SmallVectorImpl<LexicalScope *> &Scopes,
SmallVectorImpl<LexicalBlock *> &Blocks,
SmallVectorImpl<LocalVariable> &Locals,
SmallVectorImpl<CVGlobalVariable> &Globals) { … }
void CodeViewDebug::collectLexicalBlockInfo(
LexicalScope &Scope,
SmallVectorImpl<LexicalBlock *> &ParentBlocks,
SmallVectorImpl<LocalVariable> &ParentLocals,
SmallVectorImpl<CVGlobalVariable> &ParentGlobals) { … }
void CodeViewDebug::endFunctionImpl(const MachineFunction *MF) { … }
static bool isUsableDebugLoc(DebugLoc DL) { … }
void CodeViewDebug::beginInstruction(const MachineInstr *MI) { … }
MCSymbol *CodeViewDebug::beginCVSubsection(DebugSubsectionKind Kind) { … }
void CodeViewDebug::endCVSubsection(MCSymbol *EndLabel) { … }
static StringRef getSymbolName(SymbolKind SymKind) { … }
MCSymbol *CodeViewDebug::beginSymbolRecord(SymbolKind SymKind) { … }
void CodeViewDebug::endSymbolRecord(MCSymbol *SymEnd) { … }
void CodeViewDebug::emitEndSymbolRecord(SymbolKind EndKind) { … }
void CodeViewDebug::emitDebugInfoForUDTs(
const std::vector<std::pair<std::string, const DIType *>> &UDTs) { … }
void CodeViewDebug::collectGlobalVariableInfo() { … }
void CodeViewDebug::collectDebugInfoForGlobals() { … }
void CodeViewDebug::emitDebugInfoForGlobals() { … }
void CodeViewDebug::emitDebugInfoForRetainedTypes() { … }
void CodeViewDebug::emitGlobalVariableList(ArrayRef<CVGlobalVariable> Globals) { … }
void CodeViewDebug::emitConstantSymbolRecord(const DIType *DTy, APSInt &Value,
const std::string &QualifiedName) { … }
void CodeViewDebug::emitStaticConstMemberList() { … }
static bool isFloatDIType(const DIType *Ty) { … }
void CodeViewDebug::emitDebugInfoForGlobal(const CVGlobalVariable &CVGV) { … }
void forEachJumpTableBranch(
const MachineFunction *MF, bool isThumb,
const std::function<void(const MachineJumpTableInfo &, const MachineInstr &,
int64_t)> &Callback) { … }
void CodeViewDebug::discoverJumpTableBranches(const MachineFunction *MF,
bool isThumb) { … }
void CodeViewDebug::collectDebugInfoForJumpTables(const MachineFunction *MF,
bool isThumb) { … }
void CodeViewDebug::emitDebugInfoForJumpTables(const FunctionInfo &FI) { … }
void CodeViewDebug::emitInlinees(
const SmallSet<codeview::TypeIndex, 1> &Inlinees) { … }