2017-06-07 06:22:41 +08:00
|
|
|
//===- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp ----------------------===//
|
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
|
|
|
#include "CodeViewDebug.h"
|
2017-08-02 05:45:24 +08:00
|
|
|
#include "DwarfExpression.h"
|
2017-06-07 06:22:41 +08:00
|
|
|
#include "llvm/ADT/APSInt.h"
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/DenseSet.h"
|
|
|
|
#include "llvm/ADT/MapVector.h"
|
|
|
|
#include "llvm/ADT/None.h"
|
|
|
|
#include "llvm/ADT/Optional.h"
|
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2016-06-23 02:31:14 +08:00
|
|
|
#include "llvm/ADT/TinyPtrVector.h"
|
2017-06-07 06:22:41 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
|
|
|
#include "llvm/ADT/Twine.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/COFF.h"
|
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
2017-06-07 06:22:41 +08:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
|
|
|
#include "llvm/CodeGen/LexicalScopes.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
|
|
|
#include "llvm/Config/llvm-config.h"
|
2016-07-02 02:05:56 +08:00
|
|
|
#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
|
2016-01-14 07:44:57 +08:00
|
|
|
#include "llvm/DebugInfo/CodeView/CodeView.h"
|
2017-05-31 00:36:15 +08:00
|
|
|
#include "llvm/DebugInfo/CodeView/DebugInlineeLinesSubsection.h"
|
2016-01-29 08:49:42 +08:00
|
|
|
#include "llvm/DebugInfo/CodeView/Line.h"
|
2016-01-14 07:44:57 +08:00
|
|
|
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
|
[CodeView] Finish decoupling TypeDatabase from TypeDumper.
Previously the type dumper itself was passed around to a lot of different
places and manipulated in ways that were more appropriate on the type
database. For example, the entire TypeDumper was passed into the symbol
dumper, when all the symbol dumper wanted to do was lookup the name of a
TypeIndex so it could print it. That's what the TypeDatabase is for --
mapping type indices to names.
Another example is how if the user runs llvm-pdbdump with the option to
dump symbols but not types, we still have to visit all types so that we
can print minimal information about the type of a symbol, but just without
dumping full symbol records. The way we did this before is by hacking it
up so that we run everything through the type dumper with a null printer,
so that the output goes to /dev/null. But really, we don't need to dump
anything, all we want to do is build the type database. Since
TypeDatabaseVisitor now exists independently of TypeDumper, we can do
this. We just build a custom visitor callback pipeline that includes a
database visitor but not a dumper.
All the hackery around printers etc goes away. After this patch, we could
probably even delete the entire CVTypeDumper class since really all it is
at this point is a thin wrapper that hides the details of how to build a
useful visitation pipeline. It's not a priority though, so CVTypeDumper
remains for now.
After this patch we will be able to easily plug in a different style of
type dumper by only implementing the proper visitation methods to dump
one-line output and then sticking it on the pipeline.
Differential Revision: https://reviews.llvm.org/D28524
llvm-svn: 291724
2017-01-12 07:24:22 +08:00
|
|
|
#include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h"
|
2016-01-30 02:16:43 +08:00
|
|
|
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
|
|
|
|
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
|
2017-05-20 03:26:58 +08:00
|
|
|
#include "llvm/DebugInfo/CodeView/TypeTableCollection.h"
|
2016-06-30 11:00:20 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
2017-06-07 06:22:41 +08:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
|
|
|
#include "llvm/IR/DebugLoc.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"
|
2016-07-28 00:03:57 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2017-06-07 06:22:41 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2016-05-26 07:16:12 +08:00
|
|
|
#include "llvm/MC/MCSectionCOFF.h"
|
2017-06-07 06:22:41 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2014-01-30 09:39:17 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/Support/BinaryByteStream.h"
|
|
|
|
#include "llvm/Support/BinaryStreamReader.h"
|
2017-06-07 06:22:41 +08:00
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/Endian.h"
|
|
|
|
#include "llvm/Support/Error.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
[codeview] Improve readability of type record assembly
Adds the method MCStreamer::EmitBinaryData, which is usually an alias
for EmitBytes. In the MCAsmStreamer case, it is overridden to emit hex
dump output like this:
.byte 0x0e, 0x00, 0x08, 0x10
.byte 0x03, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x10, 0x00, 0x00
Also, when verbose asm comments are enabled, this patch prints the dump
output for each comment before its record, like this:
# ArgList (0x1000) {
# TypeLeafKind: LF_ARGLIST (0x1201)
# NumArgs: 0
# Arguments [
# ]
# }
.byte 0x06, 0x00, 0x01, 0x12
.byte 0x00, 0x00, 0x00, 0x00
This should make debugging easier and testing more convenient.
Reviewers: aaboud
Subscribers: majnemer, zturner, amccarth, aaboud, llvm-commits
Differential Revision: http://reviews.llvm.org/D20711
llvm-svn: 271313
2016-06-01 02:45:36 +08:00
|
|
|
#include "llvm/Support/ScopedPrinter.h"
|
2017-06-07 06:22:41 +08:00
|
|
|
#include "llvm/Support/SMLoc.h"
|
2016-02-11 04:55:49 +08:00
|
|
|
#include "llvm/Target/TargetFrameLowering.h"
|
2017-06-07 06:22:41 +08:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2016-06-18 18:25:07 +08:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
|
|
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
2017-06-07 06:22:41 +08:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cctype>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <iterator>
|
|
|
|
#include <limits>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2016-02-11 04:55:49 +08:00
|
|
|
using namespace llvm;
|
2016-01-14 07:44:57 +08:00
|
|
|
using namespace llvm::codeview;
|
|
|
|
|
2016-02-11 04:55:49 +08:00
|
|
|
CodeViewDebug::CodeViewDebug(AsmPrinter *AP)
|
2017-06-07 06:22:41 +08:00
|
|
|
: DebugHandlerBase(AP), OS(*Asm->OutStreamer), TypeTable(Allocator) {
|
2016-02-11 04:55:49 +08:00
|
|
|
// If module doesn't have named metadata anchors or COFF debug section
|
|
|
|
// is not available, skip any debug info related stuff.
|
|
|
|
if (!MMI->getModule()->getNamedMetadata("llvm.dbg.cu") ||
|
|
|
|
!AP->getObjFileLowering().getCOFFDebugSymbolsSection()) {
|
|
|
|
Asm = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell MMI that we have debug info.
|
|
|
|
MMI->setDebugInfoAvailability(true);
|
|
|
|
}
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2016-01-16 08:09:09 +08:00
|
|
|
StringRef CodeViewDebug::getFullFilepath(const DIFile *File) {
|
|
|
|
std::string &Filepath = FileToFilepathMap[File];
|
2015-12-03 06:34:30 +08:00
|
|
|
if (!Filepath.empty())
|
|
|
|
return Filepath;
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2016-01-16 08:09:09 +08:00
|
|
|
StringRef Dir = File->getDirectory(), Filename = File->getFilename();
|
|
|
|
|
2014-01-30 09:39:17 +08:00
|
|
|
// Clang emits directory and relative filename info into the IR, but CodeView
|
|
|
|
// operates on full paths. We could change Clang to emit full paths too, but
|
|
|
|
// that would increase the IR size and probably not needed for other users.
|
|
|
|
// For now, just concatenate and canonicalize the path here.
|
|
|
|
if (Filename.find(':') == 1)
|
|
|
|
Filepath = Filename;
|
|
|
|
else
|
2015-03-28 01:51:30 +08:00
|
|
|
Filepath = (Dir + "\\" + Filename).str();
|
2014-01-30 09:39:17 +08:00
|
|
|
|
|
|
|
// Canonicalize the path. We have to do it textually because we may no longer
|
|
|
|
// have access the file in the filesystem.
|
|
|
|
// First, replace all slashes with backslashes.
|
|
|
|
std::replace(Filepath.begin(), Filepath.end(), '/', '\\');
|
|
|
|
|
|
|
|
// Remove all "\.\" with "\".
|
|
|
|
size_t Cursor = 0;
|
|
|
|
while ((Cursor = Filepath.find("\\.\\", Cursor)) != std::string::npos)
|
|
|
|
Filepath.erase(Cursor, 2);
|
|
|
|
|
|
|
|
// Replace all "\XXX\..\" with "\". Don't try too hard though as the original
|
|
|
|
// path should be well-formatted, e.g. start with a drive letter, etc.
|
|
|
|
Cursor = 0;
|
|
|
|
while ((Cursor = Filepath.find("\\..\\", Cursor)) != std::string::npos) {
|
|
|
|
// Something's wrong if the path starts with "\..\", abort.
|
|
|
|
if (Cursor == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
size_t PrevSlash = Filepath.rfind('\\', Cursor - 1);
|
|
|
|
if (PrevSlash == std::string::npos)
|
|
|
|
// Something's wrong, abort.
|
|
|
|
break;
|
|
|
|
|
|
|
|
Filepath.erase(PrevSlash, Cursor + 3 - PrevSlash);
|
|
|
|
// The next ".." might be following the one we've just erased.
|
|
|
|
Cursor = PrevSlash;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove all duplicate backslashes.
|
|
|
|
Cursor = 0;
|
|
|
|
while ((Cursor = Filepath.find("\\\\", Cursor)) != std::string::npos)
|
|
|
|
Filepath.erase(Cursor, 1);
|
|
|
|
|
2015-12-03 06:34:30 +08:00
|
|
|
return Filepath;
|
2014-01-30 09:39:17 +08:00
|
|
|
}
|
|
|
|
|
2016-01-29 08:49:42 +08:00
|
|
|
unsigned CodeViewDebug::maybeRecordFile(const DIFile *F) {
|
|
|
|
unsigned NextId = FileIdMap.size() + 1;
|
|
|
|
auto Insertion = FileIdMap.insert(std::make_pair(F, NextId));
|
|
|
|
if (Insertion.second) {
|
|
|
|
// We have to compute the full filepath and emit a .cv_file directive.
|
|
|
|
StringRef FullPath = getFullFilepath(F);
|
2016-08-27 01:58:37 +08:00
|
|
|
bool Success = OS.EmitCVFileDirective(NextId, FullPath);
|
|
|
|
(void)Success;
|
|
|
|
assert(Success && ".cv_file directive failed");
|
2016-01-29 08:49:42 +08:00
|
|
|
}
|
|
|
|
return Insertion.first->second;
|
|
|
|
}
|
|
|
|
|
2016-02-13 05:48:30 +08:00
|
|
|
CodeViewDebug::InlineSite &
|
|
|
|
CodeViewDebug::getInlineSite(const DILocation *InlinedAt,
|
|
|
|
const DISubprogram *Inlinee) {
|
2016-03-19 02:54:32 +08:00
|
|
|
auto SiteInsertion = CurFn->InlineSites.insert({InlinedAt, InlineSite()});
|
|
|
|
InlineSite *Site = &SiteInsertion.first->second;
|
|
|
|
if (SiteInsertion.second) {
|
2016-09-08 00:15:31 +08:00
|
|
|
unsigned ParentFuncId = CurFn->FuncId;
|
|
|
|
if (const DILocation *OuterIA = InlinedAt->getInlinedAt())
|
|
|
|
ParentFuncId =
|
|
|
|
getInlineSite(OuterIA, InlinedAt->getScope()->getSubprogram())
|
|
|
|
.SiteFuncId;
|
|
|
|
|
2016-02-11 04:55:49 +08:00
|
|
|
Site->SiteFuncId = NextFuncId++;
|
2016-09-08 00:15:31 +08:00
|
|
|
OS.EmitCVInlineSiteIdDirective(
|
|
|
|
Site->SiteFuncId, ParentFuncId, maybeRecordFile(InlinedAt->getFile()),
|
|
|
|
InlinedAt->getLine(), InlinedAt->getColumn(), SMLoc());
|
2016-02-13 05:48:30 +08:00
|
|
|
Site->Inlinee = Inlinee;
|
2016-05-24 04:23:46 +08:00
|
|
|
InlinedSubprograms.insert(Inlinee);
|
2016-06-03 01:13:53 +08:00
|
|
|
getFuncIdForSubprogram(Inlinee);
|
2016-01-30 02:16:43 +08:00
|
|
|
}
|
2016-02-11 04:55:49 +08:00
|
|
|
return *Site;
|
2016-01-30 02:16:43 +08:00
|
|
|
}
|
|
|
|
|
2016-07-02 07:12:45 +08:00
|
|
|
static StringRef getPrettyScopeName(const DIScope *Scope) {
|
|
|
|
StringRef ScopeName = Scope->getName();
|
|
|
|
if (!ScopeName.empty())
|
|
|
|
return ScopeName;
|
|
|
|
|
|
|
|
switch (Scope->getTag()) {
|
|
|
|
case dwarf::DW_TAG_enumeration_type:
|
|
|
|
case dwarf::DW_TAG_class_type:
|
|
|
|
case dwarf::DW_TAG_structure_type:
|
|
|
|
case dwarf::DW_TAG_union_type:
|
|
|
|
return "<unnamed-tag>";
|
|
|
|
case dwarf::DW_TAG_namespace:
|
|
|
|
return "`anonymous namespace'";
|
|
|
|
}
|
|
|
|
|
|
|
|
return StringRef();
|
|
|
|
}
|
|
|
|
|
2016-06-22 09:32:56 +08:00
|
|
|
static const DISubprogram *getQualifiedNameComponents(
|
|
|
|
const DIScope *Scope, SmallVectorImpl<StringRef> &QualifiedNameComponents) {
|
|
|
|
const DISubprogram *ClosestSubprogram = nullptr;
|
|
|
|
while (Scope != nullptr) {
|
|
|
|
if (ClosestSubprogram == nullptr)
|
|
|
|
ClosestSubprogram = dyn_cast<DISubprogram>(Scope);
|
2016-07-02 07:12:45 +08:00
|
|
|
StringRef ScopeName = getPrettyScopeName(Scope);
|
2016-06-22 09:32:56 +08:00
|
|
|
if (!ScopeName.empty())
|
|
|
|
QualifiedNameComponents.push_back(ScopeName);
|
|
|
|
Scope = Scope->getScope().resolve();
|
|
|
|
}
|
|
|
|
return ClosestSubprogram;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string getQualifiedName(ArrayRef<StringRef> QualifiedNameComponents,
|
|
|
|
StringRef TypeName) {
|
|
|
|
std::string FullyQualifiedName;
|
2017-06-07 06:22:41 +08:00
|
|
|
for (StringRef QualifiedNameComponent :
|
|
|
|
llvm::reverse(QualifiedNameComponents)) {
|
2016-06-22 09:32:56 +08:00
|
|
|
FullyQualifiedName.append(QualifiedNameComponent);
|
|
|
|
FullyQualifiedName.append("::");
|
|
|
|
}
|
|
|
|
FullyQualifiedName.append(TypeName);
|
|
|
|
return FullyQualifiedName;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string getFullyQualifiedName(const DIScope *Scope, StringRef Name) {
|
|
|
|
SmallVector<StringRef, 5> QualifiedNameComponents;
|
|
|
|
getQualifiedNameComponents(Scope, QualifiedNameComponents);
|
|
|
|
return getQualifiedName(QualifiedNameComponents, Name);
|
|
|
|
}
|
|
|
|
|
2016-07-01 10:41:21 +08:00
|
|
|
struct CodeViewDebug::TypeLoweringScope {
|
|
|
|
TypeLoweringScope(CodeViewDebug &CVD) : CVD(CVD) { ++CVD.TypeEmissionLevel; }
|
|
|
|
~TypeLoweringScope() {
|
|
|
|
// Don't decrement TypeEmissionLevel until after emitting deferred types, so
|
|
|
|
// inner TypeLoweringScopes don't attempt to emit deferred types.
|
|
|
|
if (CVD.TypeEmissionLevel == 1)
|
|
|
|
CVD.emitDeferredCompleteTypes();
|
|
|
|
--CVD.TypeEmissionLevel;
|
|
|
|
}
|
|
|
|
CodeViewDebug &CVD;
|
|
|
|
};
|
|
|
|
|
2016-07-02 07:12:45 +08:00
|
|
|
static std::string getFullyQualifiedName(const DIScope *Ty) {
|
|
|
|
const DIScope *Scope = Ty->getScope().resolve();
|
|
|
|
return getFullyQualifiedName(Scope, getPrettyScopeName(Ty));
|
|
|
|
}
|
|
|
|
|
2016-06-22 09:32:56 +08:00
|
|
|
TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) {
|
|
|
|
// No scope means global scope and that uses the zero index.
|
|
|
|
if (!Scope || isa<DIFile>(Scope))
|
|
|
|
return TypeIndex();
|
|
|
|
|
|
|
|
assert(!isa<DIType>(Scope) && "shouldn't make a namespace scope for a type");
|
|
|
|
|
|
|
|
// Check if we've already translated this scope.
|
|
|
|
auto I = TypeIndices.find({Scope, nullptr});
|
|
|
|
if (I != TypeIndices.end())
|
|
|
|
return I->second;
|
|
|
|
|
|
|
|
// Build the fully qualified name of the scope.
|
2016-07-02 07:12:45 +08:00
|
|
|
std::string ScopeName = getFullyQualifiedName(Scope);
|
2016-11-09 06:24:53 +08:00
|
|
|
StringIdRecord SID(TypeIndex(), ScopeName);
|
|
|
|
auto TI = TypeTable.writeKnownType(SID);
|
2016-06-22 09:32:56 +08:00
|
|
|
return recordTypeIndexForDINode(Scope, TI);
|
|
|
|
}
|
|
|
|
|
2016-06-03 01:13:53 +08:00
|
|
|
TypeIndex CodeViewDebug::getFuncIdForSubprogram(const DISubprogram *SP) {
|
2016-07-28 13:03:22 +08:00
|
|
|
assert(SP);
|
2016-05-24 04:23:46 +08:00
|
|
|
|
2016-06-03 01:13:53 +08:00
|
|
|
// Check if we've already translated this subprogram.
|
2016-06-18 18:25:07 +08:00
|
|
|
auto I = TypeIndices.find({SP, nullptr});
|
2016-06-03 01:13:53 +08:00
|
|
|
if (I != TypeIndices.end())
|
|
|
|
return I->second;
|
2016-05-24 04:23:46 +08:00
|
|
|
|
2016-06-18 00:11:20 +08:00
|
|
|
// The display name includes function template arguments. Drop them to match
|
|
|
|
// MSVC.
|
2017-04-27 07:59:52 +08:00
|
|
|
StringRef DisplayName = SP->getName().split('<').first;
|
2016-06-03 01:13:53 +08:00
|
|
|
|
2016-06-22 09:32:56 +08:00
|
|
|
const DIScope *Scope = SP->getScope().resolve();
|
|
|
|
TypeIndex TI;
|
|
|
|
if (const auto *Class = dyn_cast_or_null<DICompositeType>(Scope)) {
|
|
|
|
// If the scope is a DICompositeType, then this must be a method. Member
|
|
|
|
// function types take some special handling, and require access to the
|
|
|
|
// subprogram.
|
|
|
|
TypeIndex ClassType = getTypeIndex(Class);
|
|
|
|
MemberFuncIdRecord MFuncId(ClassType, getMemberFunctionType(SP, Class),
|
|
|
|
DisplayName);
|
[CodeView] Decouple record deserialization from visitor dispatch.
Until now, our use case for the visitor has been to take a stream of bytes
representing a type stream, deserialize the records in sequence, and do
something with them, where "something" is determined by how the user
implements a particular set of callbacks on an abstract class.
For actually writing PDBs, however, we want to do the reverse. We have
some kind of description of the list of records in their in-memory format,
and we want to process each one. Perhaps by serializing them to a byte
stream, or perhaps by converting them from one description format (Yaml)
to another (in-memory representation).
This was difficult in the current model because deserialization and
invoking the callbacks were tightly coupled.
With this patch we change this so that TypeDeserializer is itself an
implementation of the particular set of callbacks. This decouples
deserialization from the iteration over a list of records and invocation
of the callbacks. TypeDeserializer is initialized with another
implementation of the callback interface, so that upon deserialization it
can pass the deserialized record through to the next set of callbacks. In
a sense this is like an implementation of the Decorator design pattern,
where the Deserializer is a decorator.
This will be useful for writing Pdbs from yaml, where we have a
description of the type records in Yaml format. In this case, the visitor
implementation would have each visitation callback method implemented in
such a way as to extract the proper set of fields from the Yaml, and it
could maintain state that builds up a list of these records. Finally at
the end we can pass this information through to another set of callbacks
which serializes them into a byte stream.
Reviewed By: majnemer, ruiu, rnk
Differential Revision: https://reviews.llvm.org/D23177
llvm-svn: 277871
2016-08-06 05:45:34 +08:00
|
|
|
TI = TypeTable.writeKnownType(MFuncId);
|
2016-06-22 09:32:56 +08:00
|
|
|
} else {
|
|
|
|
// Otherwise, this must be a free function.
|
|
|
|
TypeIndex ParentScope = getScopeIndex(Scope);
|
|
|
|
FuncIdRecord FuncId(ParentScope, getTypeIndex(SP->getType()), DisplayName);
|
[CodeView] Decouple record deserialization from visitor dispatch.
Until now, our use case for the visitor has been to take a stream of bytes
representing a type stream, deserialize the records in sequence, and do
something with them, where "something" is determined by how the user
implements a particular set of callbacks on an abstract class.
For actually writing PDBs, however, we want to do the reverse. We have
some kind of description of the list of records in their in-memory format,
and we want to process each one. Perhaps by serializing them to a byte
stream, or perhaps by converting them from one description format (Yaml)
to another (in-memory representation).
This was difficult in the current model because deserialization and
invoking the callbacks were tightly coupled.
With this patch we change this so that TypeDeserializer is itself an
implementation of the particular set of callbacks. This decouples
deserialization from the iteration over a list of records and invocation
of the callbacks. TypeDeserializer is initialized with another
implementation of the callback interface, so that upon deserialization it
can pass the deserialized record through to the next set of callbacks. In
a sense this is like an implementation of the Decorator design pattern,
where the Deserializer is a decorator.
This will be useful for writing Pdbs from yaml, where we have a
description of the type records in Yaml format. In this case, the visitor
implementation would have each visitation callback method implemented in
such a way as to extract the proper set of fields from the Yaml, and it
could maintain state that builds up a list of these records. Finally at
the end we can pass this information through to another set of callbacks
which serializes them into a byte stream.
Reviewed By: majnemer, ruiu, rnk
Differential Revision: https://reviews.llvm.org/D23177
llvm-svn: 277871
2016-08-06 05:45:34 +08:00
|
|
|
TI = TypeTable.writeKnownType(FuncId);
|
2016-06-22 09:32:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return recordTypeIndexForDINode(SP, TI);
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeIndex CodeViewDebug::getMemberFunctionType(const DISubprogram *SP,
|
|
|
|
const DICompositeType *Class) {
|
2016-07-01 10:41:21 +08:00
|
|
|
// Always use the method declaration as the key for the function type. The
|
|
|
|
// method declaration contains the this adjustment.
|
|
|
|
if (SP->getDeclaration())
|
|
|
|
SP = SP->getDeclaration();
|
|
|
|
assert(!SP->getDeclaration() && "should use declaration as key");
|
|
|
|
|
2016-06-22 09:32:56 +08:00
|
|
|
// Key the MemberFunctionRecord into the map as {SP, Class}. It won't collide
|
|
|
|
// with the MemberFuncIdRecord, which is keyed in as {SP, nullptr}.
|
2016-07-01 10:41:21 +08:00
|
|
|
auto I = TypeIndices.find({SP, Class});
|
2016-06-22 09:32:56 +08:00
|
|
|
if (I != TypeIndices.end())
|
|
|
|
return I->second;
|
|
|
|
|
2016-07-01 10:41:21 +08:00
|
|
|
// Make sure complete type info for the class is emitted *after* the member
|
|
|
|
// function type, as the complete class type is likely to reference this
|
|
|
|
// member function type.
|
|
|
|
TypeLoweringScope S(*this);
|
2016-06-22 09:32:56 +08:00
|
|
|
TypeIndex TI =
|
2016-07-01 10:41:21 +08:00
|
|
|
lowerTypeMemberFunction(SP->getType(), Class, SP->getThisAdjustment());
|
2016-06-22 09:32:56 +08:00
|
|
|
return recordTypeIndexForDINode(SP, TI, Class);
|
2016-05-24 04:23:46 +08:00
|
|
|
}
|
|
|
|
|
2016-07-12 20:06:34 +08:00
|
|
|
TypeIndex CodeViewDebug::recordTypeIndexForDINode(const DINode *Node,
|
|
|
|
TypeIndex TI,
|
|
|
|
const DIType *ClassTy) {
|
2016-06-18 18:25:07 +08:00
|
|
|
auto InsertResult = TypeIndices.insert({{Node, ClassTy}, TI});
|
2016-06-03 23:58:20 +08:00
|
|
|
(void)InsertResult;
|
|
|
|
assert(InsertResult.second && "DINode was already assigned a type index");
|
2016-06-22 09:32:56 +08:00
|
|
|
return TI;
|
2016-06-03 23:58:20 +08:00
|
|
|
}
|
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
unsigned CodeViewDebug::getPointerSizeInBytes() {
|
|
|
|
return MMI->getModule()->getDataLayout().getPointerSizeInBits() / 8;
|
|
|
|
}
|
|
|
|
|
2016-02-13 05:48:30 +08:00
|
|
|
void CodeViewDebug::recordLocalVariable(LocalVariable &&Var,
|
|
|
|
const DILocation *InlinedAt) {
|
|
|
|
if (InlinedAt) {
|
|
|
|
// This variable was inlined. Associate it with the InlineSite.
|
|
|
|
const DISubprogram *Inlinee = Var.DIVar->getScope()->getSubprogram();
|
|
|
|
InlineSite &Site = getInlineSite(InlinedAt, Inlinee);
|
|
|
|
Site.InlinedLocals.emplace_back(Var);
|
|
|
|
} else {
|
|
|
|
// This variable goes in the main ProcSym.
|
|
|
|
CurFn->Locals.emplace_back(Var);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-12 03:41:47 +08:00
|
|
|
static void addLocIfNotPresent(SmallVectorImpl<const DILocation *> &Locs,
|
|
|
|
const DILocation *Loc) {
|
|
|
|
auto B = Locs.begin(), E = Locs.end();
|
|
|
|
if (std::find(B, E, Loc) == E)
|
|
|
|
Locs.push_back(Loc);
|
|
|
|
}
|
|
|
|
|
2016-06-12 23:39:02 +08:00
|
|
|
void CodeViewDebug::maybeRecordLocation(const DebugLoc &DL,
|
2016-01-16 08:09:09 +08:00
|
|
|
const MachineFunction *MF) {
|
|
|
|
// Skip this instruction if it has the same location as the previous one.
|
2017-07-01 05:33:44 +08:00
|
|
|
if (!DL || DL == PrevInstLoc)
|
2016-01-16 08:09:09 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
const DIScope *Scope = DL.get()->getScope();
|
2014-01-30 09:39:17 +08:00
|
|
|
if (!Scope)
|
|
|
|
return;
|
2016-01-16 08:09:09 +08:00
|
|
|
|
2016-01-13 09:05:23 +08:00
|
|
|
// Skip this line if it is longer than the maximum we can record.
|
2016-01-29 08:49:42 +08:00
|
|
|
LineInfo LI(DL.getLine(), DL.getLine(), /*IsStatement=*/true);
|
|
|
|
if (LI.getStartLine() != DL.getLine() || LI.isAlwaysStepInto() ||
|
|
|
|
LI.isNeverStepInto())
|
2016-01-13 09:05:23 +08:00
|
|
|
return;
|
|
|
|
|
2016-01-29 08:49:42 +08:00
|
|
|
ColumnInfo CI(DL.getCol(), /*EndColumn=*/0);
|
|
|
|
if (CI.getStartColumn() != DL.getCol())
|
|
|
|
return;
|
2016-01-29 08:13:28 +08:00
|
|
|
|
2016-01-29 08:49:42 +08:00
|
|
|
if (!CurFn->HaveLineInfo)
|
|
|
|
CurFn->HaveLineInfo = true;
|
|
|
|
unsigned FileId = 0;
|
2017-07-01 05:33:44 +08:00
|
|
|
if (PrevInstLoc.get() && PrevInstLoc->getFile() == DL->getFile())
|
2016-01-29 08:49:42 +08:00
|
|
|
FileId = CurFn->LastFileId;
|
|
|
|
else
|
|
|
|
FileId = CurFn->LastFileId = maybeRecordFile(DL->getFile());
|
2017-07-01 05:33:44 +08:00
|
|
|
PrevInstLoc = DL;
|
2016-01-30 02:16:43 +08:00
|
|
|
|
|
|
|
unsigned FuncId = CurFn->FuncId;
|
2016-02-13 05:48:30 +08:00
|
|
|
if (const DILocation *SiteLoc = DL->getInlinedAt()) {
|
2016-02-12 03:41:47 +08:00
|
|
|
const DILocation *Loc = DL.get();
|
|
|
|
|
2016-01-30 02:16:43 +08:00
|
|
|
// If this location was actually inlined from somewhere else, give it the ID
|
|
|
|
// of the inline call site.
|
2016-02-13 05:48:30 +08:00
|
|
|
FuncId =
|
|
|
|
getInlineSite(SiteLoc, Loc->getScope()->getSubprogram()).SiteFuncId;
|
2016-02-12 03:41:47 +08:00
|
|
|
|
2016-01-30 02:16:43 +08:00
|
|
|
// Ensure we have links in the tree of inline call sites.
|
2016-02-12 03:41:47 +08:00
|
|
|
bool FirstLoc = true;
|
|
|
|
while ((SiteLoc = Loc->getInlinedAt())) {
|
2016-02-13 05:48:30 +08:00
|
|
|
InlineSite &Site =
|
|
|
|
getInlineSite(SiteLoc, Loc->getScope()->getSubprogram());
|
2016-02-12 03:41:47 +08:00
|
|
|
if (!FirstLoc)
|
|
|
|
addLocIfNotPresent(Site.ChildSites, Loc);
|
|
|
|
FirstLoc = false;
|
|
|
|
Loc = SiteLoc;
|
2016-01-30 02:16:43 +08:00
|
|
|
}
|
2016-02-12 03:41:47 +08:00
|
|
|
addLocIfNotPresent(CurFn->ChildSites, Loc);
|
2016-01-30 02:16:43 +08:00
|
|
|
}
|
|
|
|
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.EmitCVLocDirective(FuncId, FileId, DL.getLine(), DL.getCol(),
|
2016-09-08 00:15:31 +08:00
|
|
|
/*PrologueEnd=*/false, /*IsStmt=*/false,
|
|
|
|
DL->getFilename(), SMLoc());
|
2014-01-30 09:39:17 +08:00
|
|
|
}
|
|
|
|
|
2016-05-26 07:16:12 +08:00
|
|
|
void CodeViewDebug::emitCodeViewMagicVersion() {
|
|
|
|
OS.EmitValueToAlignment(4);
|
|
|
|
OS.AddComment("Debug section magic");
|
|
|
|
OS.EmitIntValue(COFF::DEBUG_SECTION_MAGIC, 4);
|
|
|
|
}
|
|
|
|
|
2016-01-15 03:25:04 +08:00
|
|
|
void CodeViewDebug::endModule() {
|
2016-06-07 08:02:03 +08:00
|
|
|
if (!Asm || !MMI->hasDebugInfo())
|
2014-10-11 00:05:32 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
assert(Asm != nullptr);
|
|
|
|
|
|
|
|
// The COFF .debug$S section consists of several subsections, each starting
|
|
|
|
// with a 4-byte control code (e.g. 0xF1, 0xF2, etc) and then a 4-byte length
|
|
|
|
// of the payload followed by the payload itself. The subsections are 4-byte
|
|
|
|
// aligned.
|
|
|
|
|
2016-06-07 08:02:03 +08:00
|
|
|
// Use the generic .debug$S section, and make a subsection for all the inlined
|
|
|
|
// subprograms.
|
|
|
|
switchToDebugSectionForSymbol(nullptr);
|
2016-11-03 05:30:35 +08:00
|
|
|
|
2017-05-31 00:36:15 +08:00
|
|
|
MCSymbol *CompilerInfo = beginCVSubsection(DebugSubsectionKind::Symbols);
|
2016-11-03 05:30:35 +08:00
|
|
|
emitCompilerInformation();
|
|
|
|
endCVSubsection(CompilerInfo);
|
|
|
|
|
2016-05-26 07:16:12 +08:00
|
|
|
emitInlineeLinesSubsection();
|
2016-02-03 01:41:18 +08:00
|
|
|
|
2016-01-29 08:49:42 +08:00
|
|
|
// Emit per-function debug information.
|
|
|
|
for (auto &P : FnDebugInfo)
|
2016-06-15 08:19:52 +08:00
|
|
|
if (!P.first->isDeclarationForLinker())
|
|
|
|
emitDebugInfoForFunction(P.first, P.second);
|
2014-10-11 00:05:32 +08:00
|
|
|
|
2016-06-07 08:02:03 +08:00
|
|
|
// Emit global variable debug information.
|
2016-06-16 02:00:01 +08:00
|
|
|
setCurrentSubprogram(nullptr);
|
2016-06-07 08:02:03 +08:00
|
|
|
emitDebugInfoForGlobals();
|
|
|
|
|
2016-06-24 00:33:53 +08:00
|
|
|
// Emit retained types.
|
|
|
|
emitDebugInfoForRetainedTypes();
|
|
|
|
|
2016-05-26 07:16:12 +08:00
|
|
|
// Switch back to the generic .debug$S section after potentially processing
|
|
|
|
// comdat symbol sections.
|
|
|
|
switchToDebugSectionForSymbol(nullptr);
|
|
|
|
|
2016-06-16 02:00:01 +08:00
|
|
|
// Emit UDT records for any types used by global variables.
|
|
|
|
if (!GlobalUDTs.empty()) {
|
2017-05-31 00:36:15 +08:00
|
|
|
MCSymbol *SymbolsEnd = beginCVSubsection(DebugSubsectionKind::Symbols);
|
2016-06-16 02:00:01 +08:00
|
|
|
emitDebugInfoForUDTs(GlobalUDTs);
|
|
|
|
endCVSubsection(SymbolsEnd);
|
|
|
|
}
|
|
|
|
|
2014-10-11 00:05:32 +08:00
|
|
|
// This subsection holds a file index to offset in string table table.
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.AddComment("File index to string table offset subsection");
|
|
|
|
OS.EmitCVFileChecksumsDirective();
|
2014-10-11 00:05:32 +08:00
|
|
|
|
|
|
|
// This subsection holds the string table.
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.AddComment("String table");
|
|
|
|
OS.EmitCVStringTableDirective();
|
2014-10-11 00:05:32 +08:00
|
|
|
|
2016-06-02 01:05:51 +08:00
|
|
|
// Emit type information last, so that any types we translate while emitting
|
|
|
|
// function info are included.
|
|
|
|
emitTypeInformation();
|
|
|
|
|
2014-10-11 00:05:32 +08:00
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2016-03-14 13:15:09 +08:00
|
|
|
static void emitNullTerminatedSymbolName(MCStreamer &OS, StringRef S) {
|
2016-10-06 06:36:07 +08:00
|
|
|
// The maximum CV record length is 0xFF00. Most of the strings we emit appear
|
|
|
|
// after a fixed length portion of the record. The fixed length portion should
|
|
|
|
// always be less than 0xF00 (3840) bytes, so truncate the string so that the
|
|
|
|
// overall record size is less than the maximum allowed.
|
|
|
|
unsigned MaxFixedRecordLength = 0xF00;
|
|
|
|
SmallString<32> NullTerminatedString(
|
|
|
|
S.take_front(MaxRecordLength - MaxFixedRecordLength - 1));
|
2016-03-14 13:15:09 +08:00
|
|
|
NullTerminatedString.push_back('\0');
|
|
|
|
OS.EmitBytes(NullTerminatedString);
|
|
|
|
}
|
|
|
|
|
2016-01-30 02:16:43 +08:00
|
|
|
void CodeViewDebug::emitTypeInformation() {
|
2016-05-24 04:23:46 +08:00
|
|
|
// Do nothing if we have no debug info or if no non-trivial types were emitted
|
|
|
|
// to TypeTable during codegen.
|
2016-06-18 18:25:07 +08:00
|
|
|
NamedMDNode *CU_Nodes = MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
|
2016-01-30 02:16:43 +08:00
|
|
|
if (!CU_Nodes)
|
|
|
|
return;
|
2016-05-24 04:23:46 +08:00
|
|
|
if (TypeTable.empty())
|
2016-03-19 02:54:32 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Start the .debug$T section with 0x4.
|
|
|
|
OS.SwitchSection(Asm->getObjFileLowering().getCOFFDebugTypesSection());
|
2016-05-26 07:16:12 +08:00
|
|
|
emitCodeViewMagicVersion();
|
2016-01-30 02:16:43 +08:00
|
|
|
|
[codeview] Improve readability of type record assembly
Adds the method MCStreamer::EmitBinaryData, which is usually an alias
for EmitBytes. In the MCAsmStreamer case, it is overridden to emit hex
dump output like this:
.byte 0x0e, 0x00, 0x08, 0x10
.byte 0x03, 0x00, 0x00, 0x00
.byte 0x00, 0x00, 0x00, 0x00
.byte 0x00, 0x10, 0x00, 0x00
Also, when verbose asm comments are enabled, this patch prints the dump
output for each comment before its record, like this:
# ArgList (0x1000) {
# TypeLeafKind: LF_ARGLIST (0x1201)
# NumArgs: 0
# Arguments [
# ]
# }
.byte 0x06, 0x00, 0x01, 0x12
.byte 0x00, 0x00, 0x00, 0x00
This should make debugging easier and testing more convenient.
Reviewers: aaboud
Subscribers: majnemer, zturner, amccarth, aaboud, llvm-commits
Differential Revision: http://reviews.llvm.org/D20711
llvm-svn: 271313
2016-06-01 02:45:36 +08:00
|
|
|
SmallString<8> CommentPrefix;
|
|
|
|
if (OS.isVerboseAsm()) {
|
|
|
|
CommentPrefix += '\t';
|
|
|
|
CommentPrefix += Asm->MAI->getCommentString();
|
|
|
|
CommentPrefix += ' ';
|
|
|
|
}
|
|
|
|
|
2017-05-20 03:26:58 +08:00
|
|
|
TypeTableCollection Table(TypeTable.records());
|
|
|
|
Optional<TypeIndex> B = Table.getFirst();
|
|
|
|
while (B) {
|
|
|
|
// This will fail if the record data is invalid.
|
|
|
|
CVType Record = Table.getType(*B);
|
|
|
|
|
2016-11-09 06:24:53 +08:00
|
|
|
if (OS.isVerboseAsm()) {
|
|
|
|
// Emit a block comment describing the type record for readability.
|
|
|
|
SmallString<512> CommentBlock;
|
|
|
|
raw_svector_ostream CommentOS(CommentBlock);
|
|
|
|
ScopedPrinter SP(CommentOS);
|
|
|
|
SP.setPrefix(CommentPrefix);
|
2017-05-20 03:26:58 +08:00
|
|
|
TypeDumpVisitor TDV(Table, &SP, false);
|
|
|
|
|
|
|
|
Error E = codeview::visitTypeRecord(Record, *B, TDV);
|
2016-11-09 06:24:53 +08:00
|
|
|
if (E) {
|
|
|
|
logAllUnhandledErrors(std::move(E), errs(), "error: ");
|
|
|
|
llvm_unreachable("produced malformed type record");
|
|
|
|
}
|
|
|
|
// emitRawComment will insert its own tab and comment string before
|
|
|
|
// the first line, so strip off our first one. It also prints its own
|
|
|
|
// newline.
|
|
|
|
OS.emitRawComment(
|
|
|
|
CommentOS.str().drop_front(CommentPrefix.size() - 1).rtrim());
|
|
|
|
}
|
2017-05-20 03:26:58 +08:00
|
|
|
OS.EmitBinaryData(Record.str_data());
|
|
|
|
B = Table.getNext(*B);
|
|
|
|
}
|
2016-01-30 02:16:43 +08:00
|
|
|
}
|
|
|
|
|
2016-09-21 01:20:51 +08:00
|
|
|
static SourceLanguage MapDWLangToCVLang(unsigned DWLang) {
|
|
|
|
switch (DWLang) {
|
|
|
|
case dwarf::DW_LANG_C:
|
|
|
|
case dwarf::DW_LANG_C89:
|
|
|
|
case dwarf::DW_LANG_C99:
|
|
|
|
case dwarf::DW_LANG_C11:
|
|
|
|
case dwarf::DW_LANG_ObjC:
|
|
|
|
return SourceLanguage::C;
|
|
|
|
case dwarf::DW_LANG_C_plus_plus:
|
|
|
|
case dwarf::DW_LANG_C_plus_plus_03:
|
|
|
|
case dwarf::DW_LANG_C_plus_plus_11:
|
|
|
|
case dwarf::DW_LANG_C_plus_plus_14:
|
|
|
|
return SourceLanguage::Cpp;
|
|
|
|
case dwarf::DW_LANG_Fortran77:
|
|
|
|
case dwarf::DW_LANG_Fortran90:
|
|
|
|
case dwarf::DW_LANG_Fortran03:
|
|
|
|
case dwarf::DW_LANG_Fortran08:
|
|
|
|
return SourceLanguage::Fortran;
|
|
|
|
case dwarf::DW_LANG_Pascal83:
|
|
|
|
return SourceLanguage::Pascal;
|
|
|
|
case dwarf::DW_LANG_Cobol74:
|
|
|
|
case dwarf::DW_LANG_Cobol85:
|
|
|
|
return SourceLanguage::Cobol;
|
|
|
|
case dwarf::DW_LANG_Java:
|
|
|
|
return SourceLanguage::Java;
|
2017-07-25 00:16:42 +08:00
|
|
|
case dwarf::DW_LANG_D:
|
|
|
|
return SourceLanguage::D;
|
2016-09-21 01:20:51 +08:00
|
|
|
default:
|
|
|
|
// There's no CodeView representation for this language, and CV doesn't
|
|
|
|
// have an "unknown" option for the language field, so we'll use MASM,
|
|
|
|
// as it's very low level.
|
|
|
|
return SourceLanguage::Masm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 00:16:17 +08:00
|
|
|
namespace {
|
2016-09-21 01:20:51 +08:00
|
|
|
struct Version {
|
|
|
|
int Part[4];
|
|
|
|
};
|
2017-07-25 00:16:17 +08:00
|
|
|
} // end anonymous namespace
|
2016-09-21 01:20:51 +08:00
|
|
|
|
|
|
|
// Takes a StringRef like "clang 4.0.0.0 (other nonsense 123)" and parses out
|
|
|
|
// the version number.
|
|
|
|
static Version parseVersion(StringRef Name) {
|
2016-09-21 01:42:13 +08:00
|
|
|
Version V = {{0}};
|
2016-09-21 01:20:51 +08:00
|
|
|
int N = 0;
|
|
|
|
for (const char C : Name) {
|
|
|
|
if (isdigit(C)) {
|
|
|
|
V.Part[N] *= 10;
|
|
|
|
V.Part[N] += C - '0';
|
|
|
|
} else if (C == '.') {
|
|
|
|
++N;
|
|
|
|
if (N >= 4)
|
|
|
|
return V;
|
|
|
|
} else if (N > 0)
|
|
|
|
return V;
|
|
|
|
}
|
|
|
|
return V;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CPUType mapArchToCVCPUType(Triple::ArchType Type) {
|
|
|
|
switch (Type) {
|
2017-07-25 00:16:17 +08:00
|
|
|
case Triple::ArchType::x86:
|
|
|
|
return CPUType::Pentium3;
|
|
|
|
case Triple::ArchType::x86_64:
|
|
|
|
return CPUType::X64;
|
|
|
|
case Triple::ArchType::thumb:
|
|
|
|
return CPUType::Thumb;
|
|
|
|
case Triple::ArchType::aarch64:
|
|
|
|
return CPUType::ARM64;
|
|
|
|
default:
|
|
|
|
report_fatal_error("target architecture doesn't map to a CodeView CPUType");
|
2016-09-21 01:20:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewDebug::emitCompilerInformation() {
|
|
|
|
MCContext &Context = MMI->getContext();
|
|
|
|
MCSymbol *CompilerBegin = Context.createTempSymbol(),
|
|
|
|
*CompilerEnd = Context.createTempSymbol();
|
|
|
|
OS.AddComment("Record length");
|
|
|
|
OS.emitAbsoluteSymbolDiff(CompilerEnd, CompilerBegin, 2);
|
|
|
|
OS.EmitLabel(CompilerBegin);
|
|
|
|
OS.AddComment("Record kind: S_COMPILE3");
|
|
|
|
OS.EmitIntValue(SymbolKind::S_COMPILE3, 2);
|
|
|
|
uint32_t Flags = 0;
|
|
|
|
|
|
|
|
NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
|
|
|
|
const MDNode *Node = *CUs->operands().begin();
|
|
|
|
const auto *CU = cast<DICompileUnit>(Node);
|
|
|
|
|
|
|
|
// The low byte of the flags indicates the source language.
|
|
|
|
Flags = MapDWLangToCVLang(CU->getSourceLanguage());
|
|
|
|
// TODO: Figure out which other flags need to be set.
|
|
|
|
|
|
|
|
OS.AddComment("Flags and language");
|
|
|
|
OS.EmitIntValue(Flags, 4);
|
|
|
|
|
|
|
|
OS.AddComment("CPUType");
|
|
|
|
CPUType CPU =
|
|
|
|
mapArchToCVCPUType(Triple(MMI->getModule()->getTargetTriple()).getArch());
|
|
|
|
OS.EmitIntValue(static_cast<uint64_t>(CPU), 2);
|
|
|
|
|
|
|
|
StringRef CompilerVersion = CU->getProducer();
|
|
|
|
Version FrontVer = parseVersion(CompilerVersion);
|
|
|
|
OS.AddComment("Frontend version");
|
|
|
|
for (int N = 0; N < 4; ++N)
|
|
|
|
OS.EmitIntValue(FrontVer.Part[N], 2);
|
|
|
|
|
|
|
|
// Some Microsoft tools, like Binscope, expect a backend version number of at
|
|
|
|
// least 8.something, so we'll coerce the LLVM version into a form that
|
|
|
|
// guarantees it'll be big enough without really lying about the version.
|
2016-09-30 04:28:25 +08:00
|
|
|
int Major = 1000 * LLVM_VERSION_MAJOR +
|
|
|
|
10 * LLVM_VERSION_MINOR +
|
|
|
|
LLVM_VERSION_PATCH;
|
|
|
|
// Clamp it for builds that use unusually large version numbers.
|
|
|
|
Major = std::min<int>(Major, std::numeric_limits<uint16_t>::max());
|
|
|
|
Version BackVer = {{ Major, 0, 0, 0 }};
|
2016-09-21 01:20:51 +08:00
|
|
|
OS.AddComment("Backend version");
|
|
|
|
for (int N = 0; N < 4; ++N)
|
|
|
|
OS.EmitIntValue(BackVer.Part[N], 2);
|
|
|
|
|
|
|
|
OS.AddComment("Null-terminated compiler version string");
|
|
|
|
emitNullTerminatedSymbolName(OS, CompilerVersion);
|
|
|
|
|
|
|
|
OS.EmitLabel(CompilerEnd);
|
|
|
|
}
|
|
|
|
|
2016-05-26 07:16:12 +08:00
|
|
|
void CodeViewDebug::emitInlineeLinesSubsection() {
|
2016-02-03 01:41:18 +08:00
|
|
|
if (InlinedSubprograms.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
OS.AddComment("Inlinee lines subsection");
|
2017-05-31 00:36:15 +08:00
|
|
|
MCSymbol *InlineEnd = beginCVSubsection(DebugSubsectionKind::InlineeLines);
|
2016-02-03 01:41:18 +08:00
|
|
|
|
|
|
|
// We don't provide any extra file info.
|
|
|
|
// FIXME: Find out if debuggers use this info.
|
2016-02-03 07:18:23 +08:00
|
|
|
OS.AddComment("Inlinee lines signature");
|
2016-02-03 01:41:18 +08:00
|
|
|
OS.EmitIntValue(unsigned(InlineeLinesSignature::Normal), 4);
|
|
|
|
|
|
|
|
for (const DISubprogram *SP : InlinedSubprograms) {
|
2016-06-18 18:25:07 +08:00
|
|
|
assert(TypeIndices.count({SP, nullptr}));
|
|
|
|
TypeIndex InlineeIdx = TypeIndices[{SP, nullptr}];
|
2016-05-24 04:23:46 +08:00
|
|
|
|
2016-02-03 07:18:23 +08:00
|
|
|
OS.AddBlankLine();
|
2016-02-03 01:41:18 +08:00
|
|
|
unsigned FileId = maybeRecordFile(SP->getFile());
|
2017-04-27 07:59:52 +08:00
|
|
|
OS.AddComment("Inlined function " + SP->getName() + " starts at " +
|
2016-02-03 01:41:18 +08:00
|
|
|
SP->getFilename() + Twine(':') + Twine(SP->getLine()));
|
2016-02-03 07:18:23 +08:00
|
|
|
OS.AddBlankLine();
|
2016-02-03 01:41:18 +08:00
|
|
|
// The filechecksum table uses 8 byte entries for now, and file ids start at
|
|
|
|
// 1.
|
|
|
|
unsigned FileOffset = (FileId - 1) * 8;
|
2016-02-03 07:18:23 +08:00
|
|
|
OS.AddComment("Type index of inlined function");
|
2016-05-24 04:23:46 +08:00
|
|
|
OS.EmitIntValue(InlineeIdx.getIndex(), 4);
|
2016-02-03 07:18:23 +08:00
|
|
|
OS.AddComment("Offset into filechecksum table");
|
2016-02-03 01:41:18 +08:00
|
|
|
OS.EmitIntValue(FileOffset, 4);
|
2016-02-03 07:18:23 +08:00
|
|
|
OS.AddComment("Starting line number");
|
2016-02-03 01:41:18 +08:00
|
|
|
OS.EmitIntValue(SP->getLine(), 4);
|
|
|
|
}
|
|
|
|
|
2016-06-07 08:02:03 +08:00
|
|
|
endCVSubsection(InlineEnd);
|
2016-02-03 01:41:18 +08:00
|
|
|
}
|
|
|
|
|
2016-01-30 02:16:43 +08:00
|
|
|
void CodeViewDebug::emitInlinedCallSite(const FunctionInfo &FI,
|
|
|
|
const DILocation *InlinedAt,
|
|
|
|
const InlineSite &Site) {
|
2016-02-11 04:55:49 +08:00
|
|
|
MCSymbol *InlineBegin = MMI->getContext().createTempSymbol(),
|
|
|
|
*InlineEnd = MMI->getContext().createTempSymbol();
|
2016-01-30 02:16:43 +08:00
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
assert(TypeIndices.count({Site.Inlinee, nullptr}));
|
|
|
|
TypeIndex InlineeIdx = TypeIndices[{Site.Inlinee, nullptr}];
|
2016-01-30 02:16:43 +08:00
|
|
|
|
|
|
|
// SymbolRecord
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.AddComment("Record length");
|
2016-02-04 05:24:42 +08:00
|
|
|
OS.emitAbsoluteSymbolDiff(InlineEnd, InlineBegin, 2); // RecordLength
|
2016-01-30 02:16:43 +08:00
|
|
|
OS.EmitLabel(InlineBegin);
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.AddComment("Record kind: S_INLINESITE");
|
2016-05-18 07:50:21 +08:00
|
|
|
OS.EmitIntValue(SymbolKind::S_INLINESITE, 2); // RecordKind
|
2016-01-30 02:16:43 +08:00
|
|
|
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.AddComment("PtrParent");
|
|
|
|
OS.EmitIntValue(0, 4);
|
|
|
|
OS.AddComment("PtrEnd");
|
|
|
|
OS.EmitIntValue(0, 4);
|
|
|
|
OS.AddComment("Inlinee type index");
|
2016-05-24 04:23:46 +08:00
|
|
|
OS.EmitIntValue(InlineeIdx.getIndex(), 4);
|
2016-01-30 02:16:43 +08:00
|
|
|
|
2016-02-03 01:41:18 +08:00
|
|
|
unsigned FileId = maybeRecordFile(Site.Inlinee->getFile());
|
|
|
|
unsigned StartLineNum = Site.Inlinee->getLine();
|
|
|
|
|
|
|
|
OS.EmitCVInlineLinetableDirective(Site.SiteFuncId, FileId, StartLineNum,
|
2016-09-08 00:15:31 +08:00
|
|
|
FI.Begin, FI.End);
|
2016-01-30 02:16:43 +08:00
|
|
|
|
|
|
|
OS.EmitLabel(InlineEnd);
|
|
|
|
|
2016-06-25 01:55:40 +08:00
|
|
|
emitLocalVariableList(Site.InlinedLocals);
|
2016-02-11 04:55:49 +08:00
|
|
|
|
2016-01-30 02:16:43 +08:00
|
|
|
// Recurse on child inlined call sites before closing the scope.
|
|
|
|
for (const DILocation *ChildSite : Site.ChildSites) {
|
|
|
|
auto I = FI.InlineSites.find(ChildSite);
|
|
|
|
assert(I != FI.InlineSites.end() &&
|
|
|
|
"child site not in function inline site map");
|
|
|
|
emitInlinedCallSite(FI, ChildSite, I->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close the scope.
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.AddComment("Record length");
|
|
|
|
OS.EmitIntValue(2, 2); // RecordLength
|
|
|
|
OS.AddComment("Record kind: S_INLINESITE_END");
|
2016-05-18 07:50:21 +08:00
|
|
|
OS.EmitIntValue(SymbolKind::S_INLINESITE_END, 2); // RecordKind
|
2016-01-30 02:16:43 +08:00
|
|
|
}
|
|
|
|
|
2016-05-26 07:16:12 +08:00
|
|
|
void CodeViewDebug::switchToDebugSectionForSymbol(const MCSymbol *GVSym) {
|
|
|
|
// If we have a symbol, it may be in a section that is COMDAT. If so, find the
|
|
|
|
// comdat key. A section may be comdat because of -ffunction-sections or
|
|
|
|
// because it is comdat in the IR.
|
|
|
|
MCSectionCOFF *GVSec =
|
|
|
|
GVSym ? dyn_cast<MCSectionCOFF>(&GVSym->getSection()) : nullptr;
|
|
|
|
const MCSymbol *KeySym = GVSec ? GVSec->getCOMDATSymbol() : nullptr;
|
|
|
|
|
|
|
|
MCSectionCOFF *DebugSec = cast<MCSectionCOFF>(
|
|
|
|
Asm->getObjFileLowering().getCOFFDebugSymbolsSection());
|
|
|
|
DebugSec = OS.getContext().getAssociativeCOFFSection(DebugSec, KeySym);
|
|
|
|
|
|
|
|
OS.SwitchSection(DebugSec);
|
|
|
|
|
|
|
|
// Emit the magic version number if this is the first time we've switched to
|
|
|
|
// this section.
|
|
|
|
if (ComdatDebugSections.insert(DebugSec).second)
|
|
|
|
emitCodeViewMagicVersion();
|
|
|
|
}
|
|
|
|
|
2016-01-29 08:49:42 +08:00
|
|
|
void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
|
|
|
|
FunctionInfo &FI) {
|
2014-01-30 09:39:17 +08:00
|
|
|
// For each function there is a separate subsection
|
|
|
|
// which holds the PC to file:line table.
|
|
|
|
const MCSymbol *Fn = Asm->getSymbol(GV);
|
|
|
|
assert(Fn);
|
2014-03-26 17:50:36 +08:00
|
|
|
|
2016-05-26 07:16:12 +08:00
|
|
|
// Switch to the to a comdat section, if appropriate.
|
|
|
|
switchToDebugSectionForSymbol(Fn);
|
|
|
|
|
2016-06-18 00:11:20 +08:00
|
|
|
std::string FuncName;
|
2016-06-16 02:00:01 +08:00
|
|
|
auto *SP = GV->getSubprogram();
|
2016-07-28 13:03:22 +08:00
|
|
|
assert(SP);
|
2016-06-16 02:00:01 +08:00
|
|
|
setCurrentSubprogram(SP);
|
2016-06-18 00:11:20 +08:00
|
|
|
|
|
|
|
// If we have a display name, build the fully qualified name by walking the
|
|
|
|
// chain of scopes.
|
2017-04-27 07:59:52 +08:00
|
|
|
if (!SP->getName().empty())
|
2016-06-22 09:32:56 +08:00
|
|
|
FuncName =
|
2017-04-27 07:59:52 +08:00
|
|
|
getFullyQualifiedName(SP->getScope().resolve(), SP->getName());
|
2015-03-21 03:50:00 +08:00
|
|
|
|
2016-01-14 08:12:54 +08:00
|
|
|
// If our DISubprogram name is empty, use the mangled name.
|
2016-01-14 03:32:35 +08:00
|
|
|
if (FuncName.empty())
|
2017-05-16 08:39:01 +08:00
|
|
|
FuncName = GlobalValue::dropLLVMManglingEscape(GV->getName());
|
2016-01-14 08:12:54 +08:00
|
|
|
|
2014-10-24 09:27:45 +08:00
|
|
|
// Emit a symbol subsection, required by VS2012+ to find function boundaries.
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.AddComment("Symbol subsection for " + Twine(FuncName));
|
2017-05-31 00:36:15 +08:00
|
|
|
MCSymbol *SymbolsEnd = beginCVSubsection(DebugSubsectionKind::Symbols);
|
2014-10-24 09:27:45 +08:00
|
|
|
{
|
2016-02-11 04:55:49 +08:00
|
|
|
MCSymbol *ProcRecordBegin = MMI->getContext().createTempSymbol(),
|
|
|
|
*ProcRecordEnd = MMI->getContext().createTempSymbol();
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.AddComment("Record length");
|
2016-02-04 05:24:42 +08:00
|
|
|
OS.emitAbsoluteSymbolDiff(ProcRecordEnd, ProcRecordBegin, 2);
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.EmitLabel(ProcRecordBegin);
|
2014-10-24 09:27:45 +08:00
|
|
|
|
2016-09-15 05:49:21 +08:00
|
|
|
if (GV->hasLocalLinkage()) {
|
|
|
|
OS.AddComment("Record kind: S_LPROC32_ID");
|
|
|
|
OS.EmitIntValue(unsigned(SymbolKind::S_LPROC32_ID), 2);
|
|
|
|
} else {
|
|
|
|
OS.AddComment("Record kind: S_GPROC32_ID");
|
|
|
|
OS.EmitIntValue(unsigned(SymbolKind::S_GPROC32_ID), 2);
|
|
|
|
}
|
2016-01-14 07:44:57 +08:00
|
|
|
|
2016-02-03 07:18:23 +08:00
|
|
|
// These fields are filled in by tools like CVPACK which run after the fact.
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.AddComment("PtrParent");
|
|
|
|
OS.EmitIntValue(0, 4);
|
|
|
|
OS.AddComment("PtrEnd");
|
|
|
|
OS.EmitIntValue(0, 4);
|
|
|
|
OS.AddComment("PtrNext");
|
|
|
|
OS.EmitIntValue(0, 4);
|
2014-10-24 09:27:45 +08:00
|
|
|
// This is the important bit that tells the debugger where the function
|
|
|
|
// code is located and what's its size:
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.AddComment("Code size");
|
2016-02-04 05:24:42 +08:00
|
|
|
OS.emitAbsoluteSymbolDiff(FI.End, Fn, 4);
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.AddComment("Offset after prologue");
|
|
|
|
OS.EmitIntValue(0, 4);
|
|
|
|
OS.AddComment("Offset before epilogue");
|
|
|
|
OS.EmitIntValue(0, 4);
|
|
|
|
OS.AddComment("Function type index");
|
2016-06-03 01:13:53 +08:00
|
|
|
OS.EmitIntValue(getFuncIdForSubprogram(GV->getSubprogram()).getIndex(), 4);
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.AddComment("Function section relative address");
|
2017-01-02 11:00:19 +08:00
|
|
|
OS.EmitCOFFSecRel32(Fn, /*Offset=*/0);
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.AddComment("Function section index");
|
|
|
|
OS.EmitCOFFSectionIndex(Fn);
|
|
|
|
OS.AddComment("Flags");
|
|
|
|
OS.EmitIntValue(0, 1);
|
2014-11-13 04:10:09 +08:00
|
|
|
// Emit the function display name as a null-terminated string.
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.AddComment("Function name");
|
2016-03-13 18:53:30 +08:00
|
|
|
// Truncate the name so we won't overflow the record length field.
|
2016-03-14 13:15:09 +08:00
|
|
|
emitNullTerminatedSymbolName(OS, FuncName);
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.EmitLabel(ProcRecordEnd);
|
2014-10-24 09:27:45 +08:00
|
|
|
|
2016-06-25 01:55:40 +08:00
|
|
|
emitLocalVariableList(FI.Locals);
|
2016-02-11 04:55:49 +08:00
|
|
|
|
2016-01-30 02:16:43 +08:00
|
|
|
// Emit inlined call site information. Only emit functions inlined directly
|
|
|
|
// into the parent function. We'll emit the other sites recursively as part
|
|
|
|
// of their parent inline site.
|
2016-02-11 04:55:49 +08:00
|
|
|
for (const DILocation *InlinedAt : FI.ChildSites) {
|
|
|
|
auto I = FI.InlineSites.find(InlinedAt);
|
|
|
|
assert(I != FI.InlineSites.end() &&
|
|
|
|
"child site not in function inline site map");
|
|
|
|
emitInlinedCallSite(FI, InlinedAt, I->second);
|
2016-01-30 02:16:43 +08:00
|
|
|
}
|
|
|
|
|
2017-09-06 04:14:58 +08:00
|
|
|
for (auto Annot : FI.Annotations) {
|
|
|
|
MCSymbol *Label = Annot.first;
|
|
|
|
MDTuple *Strs = cast<MDTuple>(Annot.second);
|
|
|
|
MCSymbol *AnnotBegin = MMI->getContext().createTempSymbol(),
|
|
|
|
*AnnotEnd = MMI->getContext().createTempSymbol();
|
|
|
|
OS.AddComment("Record length");
|
|
|
|
OS.emitAbsoluteSymbolDiff(AnnotEnd, AnnotBegin, 2);
|
|
|
|
OS.EmitLabel(AnnotBegin);
|
|
|
|
OS.AddComment("Record kind: S_ANNOTATION");
|
|
|
|
OS.EmitIntValue(SymbolKind::S_ANNOTATION, 2);
|
|
|
|
OS.EmitCOFFSecRel32(Label, /*Offset=*/0);
|
|
|
|
// FIXME: Make sure we don't overflow the max record size.
|
|
|
|
OS.EmitCOFFSectionIndex(Label);
|
|
|
|
OS.EmitIntValue(Strs->getNumOperands(), 2);
|
|
|
|
for (Metadata *MD : Strs->operands()) {
|
|
|
|
// MDStrings are null terminated, so we can do EmitBytes and get the
|
|
|
|
// nice .asciz directive.
|
|
|
|
StringRef Str = cast<MDString>(MD)->getString();
|
|
|
|
assert(Str.data()[Str.size()] == '\0' && "non-nullterminated MDString");
|
|
|
|
OS.EmitBytes(StringRef(Str.data(), Str.size() + 1));
|
|
|
|
}
|
|
|
|
OS.EmitLabel(AnnotEnd);
|
|
|
|
}
|
|
|
|
|
2016-06-16 02:00:01 +08:00
|
|
|
if (SP != nullptr)
|
|
|
|
emitDebugInfoForUDTs(LocalUDTs);
|
|
|
|
|
2014-10-24 09:27:45 +08:00
|
|
|
// We're done with this function.
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.AddComment("Record length");
|
|
|
|
OS.EmitIntValue(0x0002, 2);
|
|
|
|
OS.AddComment("Record kind: S_PROC_ID_END");
|
2016-05-18 07:50:21 +08:00
|
|
|
OS.EmitIntValue(unsigned(SymbolKind::S_PROC_ID_END), 2);
|
2014-10-24 09:27:45 +08:00
|
|
|
}
|
2016-06-07 08:02:03 +08:00
|
|
|
endCVSubsection(SymbolsEnd);
|
2014-10-24 09:27:45 +08:00
|
|
|
|
2016-01-29 08:49:42 +08:00
|
|
|
// We have an assembler directive that takes care of the whole line table.
|
2016-02-04 05:15:48 +08:00
|
|
|
OS.EmitCVLinetableDirective(FI.FuncId, Fn, FI.End);
|
2014-01-30 09:39:17 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 05:48:30 +08:00
|
|
|
CodeViewDebug::LocalVarDefRange
|
|
|
|
CodeViewDebug::createDefRangeMem(uint16_t CVRegister, int Offset) {
|
|
|
|
LocalVarDefRange DR;
|
2016-02-16 23:35:51 +08:00
|
|
|
DR.InMemory = -1;
|
2016-02-13 05:48:30 +08:00
|
|
|
DR.DataOffset = Offset;
|
|
|
|
assert(DR.DataOffset == Offset && "truncation");
|
2016-10-06 05:21:33 +08:00
|
|
|
DR.IsSubfield = 0;
|
2016-02-13 05:48:30 +08:00
|
|
|
DR.StructOffset = 0;
|
|
|
|
DR.CVRegister = CVRegister;
|
|
|
|
return DR;
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeViewDebug::LocalVarDefRange
|
2016-10-06 05:21:33 +08:00
|
|
|
CodeViewDebug::createDefRangeGeneral(uint16_t CVRegister, bool InMemory,
|
|
|
|
int Offset, bool IsSubfield,
|
|
|
|
uint16_t StructOffset) {
|
2016-02-13 05:48:30 +08:00
|
|
|
LocalVarDefRange DR;
|
2016-10-06 05:21:33 +08:00
|
|
|
DR.InMemory = InMemory;
|
|
|
|
DR.DataOffset = Offset;
|
|
|
|
DR.IsSubfield = IsSubfield;
|
|
|
|
DR.StructOffset = StructOffset;
|
2016-02-13 05:48:30 +08:00
|
|
|
DR.CVRegister = CVRegister;
|
|
|
|
return DR;
|
|
|
|
}
|
|
|
|
|
2016-12-01 07:48:50 +08:00
|
|
|
void CodeViewDebug::collectVariableInfoFromMFTable(
|
2016-02-13 05:48:30 +08:00
|
|
|
DenseSet<InlinedVariable> &Processed) {
|
2016-12-01 07:48:50 +08:00
|
|
|
const MachineFunction &MF = *Asm->MF;
|
|
|
|
const TargetSubtargetInfo &TSI = MF.getSubtarget();
|
2016-02-13 05:48:30 +08:00
|
|
|
const TargetFrameLowering *TFI = TSI.getFrameLowering();
|
|
|
|
const TargetRegisterInfo *TRI = TSI.getRegisterInfo();
|
|
|
|
|
2016-12-01 07:48:50 +08:00
|
|
|
for (const MachineFunction::VariableDbgInfo &VI : MF.getVariableDbgInfo()) {
|
2016-02-11 04:55:49 +08:00
|
|
|
if (!VI.Var)
|
|
|
|
continue;
|
|
|
|
assert(VI.Var->isValidLocationForIntrinsic(VI.Loc) &&
|
|
|
|
"Expected inlined-at fields to agree");
|
|
|
|
|
2016-02-13 05:48:30 +08:00
|
|
|
Processed.insert(InlinedVariable(VI.Var, VI.Loc->getInlinedAt()));
|
2016-02-11 04:55:49 +08:00
|
|
|
LexicalScope *Scope = LScopes.findLexicalScope(VI.Loc);
|
|
|
|
|
|
|
|
// If variable scope is not found then skip this variable.
|
|
|
|
if (!Scope)
|
|
|
|
continue;
|
|
|
|
|
2017-05-10 03:59:29 +08:00
|
|
|
// If the variable has an attached offset expression, extract it.
|
|
|
|
// FIXME: Try to handle DW_OP_deref as well.
|
|
|
|
int64_t ExprOffset = 0;
|
|
|
|
if (VI.Expr)
|
|
|
|
if (!VI.Expr->extractIfOffset(ExprOffset))
|
|
|
|
continue;
|
|
|
|
|
2016-02-11 04:55:49 +08:00
|
|
|
// Get the frame register used and the offset.
|
|
|
|
unsigned FrameReg = 0;
|
2016-02-13 05:48:30 +08:00
|
|
|
int FrameOffset = TFI->getFrameIndexReference(*Asm->MF, VI.Slot, FrameReg);
|
|
|
|
uint16_t CVReg = TRI->getCodeViewRegNum(FrameReg);
|
2016-02-11 04:55:49 +08:00
|
|
|
|
|
|
|
// Calculate the label ranges.
|
2017-05-10 03:59:29 +08:00
|
|
|
LocalVarDefRange DefRange =
|
|
|
|
createDefRangeMem(CVReg, FrameOffset + ExprOffset);
|
2016-02-11 04:55:49 +08:00
|
|
|
for (const InsnRange &Range : Scope->getRanges()) {
|
|
|
|
const MCSymbol *Begin = getLabelBeforeInsn(Range.first);
|
|
|
|
const MCSymbol *End = getLabelAfterInsn(Range.second);
|
2016-02-13 05:48:30 +08:00
|
|
|
End = End ? End : Asm->getFunctionEnd();
|
|
|
|
DefRange.Ranges.emplace_back(Begin, End);
|
2016-02-11 04:55:49 +08:00
|
|
|
}
|
|
|
|
|
2016-02-13 05:48:30 +08:00
|
|
|
LocalVariable Var;
|
|
|
|
Var.DIVar = VI.Var;
|
|
|
|
Var.DefRanges.emplace_back(std::move(DefRange));
|
|
|
|
recordLocalVariable(std::move(Var), VI.Loc->getInlinedAt());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-31 23:56:49 +08:00
|
|
|
static bool canUseReferenceType(const DbgVariableLocation &Loc) {
|
|
|
|
return !Loc.LoadChain.empty() && Loc.LoadChain.back() == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool needsReferenceType(const DbgVariableLocation &Loc) {
|
|
|
|
return Loc.LoadChain.size() == 2 && Loc.LoadChain.back() == 0;
|
|
|
|
}
|
|
|
|
|
2017-08-30 04:59:25 +08:00
|
|
|
void CodeViewDebug::calculateRanges(
|
|
|
|
LocalVariable &Var, const DbgValueHistoryMap::InstrRanges &Ranges) {
|
|
|
|
const TargetRegisterInfo *TRI = Asm->MF->getSubtarget().getRegisterInfo();
|
|
|
|
|
2017-08-31 23:56:49 +08:00
|
|
|
// Calculate the definition ranges.
|
2017-08-30 04:59:25 +08:00
|
|
|
for (auto I = Ranges.begin(), E = Ranges.end(); I != E; ++I) {
|
|
|
|
const InsnRange &Range = *I;
|
|
|
|
const MachineInstr *DVInst = Range.first;
|
|
|
|
assert(DVInst->isDebugValue() && "Invalid History entry");
|
|
|
|
// FIXME: Find a way to represent constant variables, since they are
|
|
|
|
// relatively common.
|
2017-08-31 01:50:21 +08:00
|
|
|
Optional<DbgVariableLocation> Location =
|
|
|
|
DbgVariableLocation::extractFromMachineInstruction(*DVInst);
|
|
|
|
if (!Location)
|
2017-08-30 05:01:55 +08:00
|
|
|
continue;
|
2017-08-30 04:59:25 +08:00
|
|
|
|
2017-08-31 23:56:49 +08:00
|
|
|
// CodeView can only express variables in register and variables in memory
|
|
|
|
// at a constant offset from a register. However, for variables passed
|
|
|
|
// indirectly by pointer, it is common for that pointer to be spilled to a
|
|
|
|
// stack location. For the special case of one offseted load followed by a
|
|
|
|
// zero offset load (a pointer spilled to the stack), we change the type of
|
|
|
|
// the local variable from a value type to a reference type. This tricks the
|
|
|
|
// debugger into doing the load for us.
|
|
|
|
if (Var.UseReferenceType) {
|
|
|
|
// We're using a reference type. Drop the last zero offset load.
|
|
|
|
if (canUseReferenceType(*Location))
|
|
|
|
Location->LoadChain.pop_back();
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
} else if (needsReferenceType(*Location)) {
|
|
|
|
// This location can't be expressed without switching to a reference type.
|
|
|
|
// Start over using that.
|
|
|
|
Var.UseReferenceType = true;
|
2017-08-30 04:59:25 +08:00
|
|
|
Var.DefRanges.clear();
|
|
|
|
calculateRanges(Var, Ranges);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-31 23:56:49 +08:00
|
|
|
// We can only handle a register or an offseted load of a register.
|
|
|
|
if (Location->Register == 0 || Location->LoadChain.size() > 1)
|
2017-08-30 04:59:25 +08:00
|
|
|
continue;
|
|
|
|
{
|
|
|
|
LocalVarDefRange DR;
|
2017-08-31 01:50:21 +08:00
|
|
|
DR.CVRegister = TRI->getCodeViewRegNum(Location->Register);
|
2017-08-31 23:56:49 +08:00
|
|
|
DR.InMemory = !Location->LoadChain.empty();
|
|
|
|
DR.DataOffset =
|
|
|
|
!Location->LoadChain.empty() ? Location->LoadChain.back() : 0;
|
2017-08-31 01:50:21 +08:00
|
|
|
if (Location->FragmentInfo) {
|
2017-08-30 04:59:25 +08:00
|
|
|
DR.IsSubfield = true;
|
2017-08-31 01:50:21 +08:00
|
|
|
DR.StructOffset = Location->FragmentInfo->OffsetInBits / 8;
|
2017-08-30 04:59:25 +08:00
|
|
|
} else {
|
|
|
|
DR.IsSubfield = false;
|
|
|
|
DR.StructOffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Var.DefRanges.empty() ||
|
|
|
|
Var.DefRanges.back().isDifferentLocation(DR)) {
|
|
|
|
Var.DefRanges.emplace_back(std::move(DR));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the label range.
|
|
|
|
const MCSymbol *Begin = getLabelBeforeInsn(Range.first);
|
|
|
|
const MCSymbol *End = getLabelAfterInsn(Range.second);
|
|
|
|
if (!End) {
|
|
|
|
// This range is valid until the next overlapping bitpiece. In the
|
|
|
|
// common case, ranges will not be bitpieces, so they will overlap.
|
|
|
|
auto J = std::next(I);
|
|
|
|
const DIExpression *DIExpr = DVInst->getDebugExpression();
|
|
|
|
while (J != E &&
|
|
|
|
!fragmentsOverlap(DIExpr, J->first->getDebugExpression()))
|
|
|
|
++J;
|
|
|
|
if (J != E)
|
|
|
|
End = getLabelBeforeInsn(J->first);
|
|
|
|
else
|
|
|
|
End = Asm->getFunctionEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the last range end is our begin, just extend the last range.
|
|
|
|
// Otherwise make a new range.
|
|
|
|
SmallVectorImpl<std::pair<const MCSymbol *, const MCSymbol *>> &R =
|
|
|
|
Var.DefRanges.back().Ranges;
|
|
|
|
if (!R.empty() && R.back().second == Begin)
|
|
|
|
R.back().second = End;
|
|
|
|
else
|
|
|
|
R.emplace_back(Begin, End);
|
|
|
|
|
|
|
|
// FIXME: Do more range combining.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-13 05:48:30 +08:00
|
|
|
void CodeViewDebug::collectVariableInfo(const DISubprogram *SP) {
|
|
|
|
DenseSet<InlinedVariable> Processed;
|
|
|
|
// Grab the variable info that was squirreled away in the MMI side-table.
|
2016-12-01 07:48:50 +08:00
|
|
|
collectVariableInfoFromMFTable(Processed);
|
2016-02-13 05:48:30 +08:00
|
|
|
|
|
|
|
for (const auto &I : DbgValues) {
|
|
|
|
InlinedVariable IV = I.first;
|
|
|
|
if (Processed.count(IV))
|
|
|
|
continue;
|
|
|
|
const DILocalVariable *DIVar = IV.first;
|
|
|
|
const DILocation *InlinedAt = IV.second;
|
|
|
|
|
|
|
|
// Instruction ranges, specifying where IV is accessible.
|
|
|
|
const auto &Ranges = I.second;
|
|
|
|
|
|
|
|
LexicalScope *Scope = nullptr;
|
|
|
|
if (InlinedAt)
|
|
|
|
Scope = LScopes.findInlinedScope(DIVar->getScope(), InlinedAt);
|
|
|
|
else
|
|
|
|
Scope = LScopes.findLexicalScope(DIVar->getScope());
|
|
|
|
// If variable scope is not found then skip this variable.
|
|
|
|
if (!Scope)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
LocalVariable Var;
|
|
|
|
Var.DIVar = DIVar;
|
|
|
|
|
2017-08-30 04:59:25 +08:00
|
|
|
calculateRanges(Var, Ranges);
|
2016-02-13 05:48:30 +08:00
|
|
|
recordLocalVariable(std::move(Var), InlinedAt);
|
2016-02-11 04:55:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-17 02:48:33 +08:00
|
|
|
void CodeViewDebug::beginFunctionImpl(const MachineFunction *MF) {
|
2014-01-30 09:39:17 +08:00
|
|
|
const Function *GV = MF->getFunction();
|
|
|
|
assert(FnDebugInfo.count(GV) == false);
|
|
|
|
CurFn = &FnDebugInfo[GV];
|
2016-01-29 08:49:42 +08:00
|
|
|
CurFn->FuncId = NextFuncId++;
|
2016-02-03 01:41:18 +08:00
|
|
|
CurFn->Begin = Asm->getFunctionBegin();
|
2014-01-30 09:39:17 +08:00
|
|
|
|
2016-09-08 00:15:31 +08:00
|
|
|
OS.EmitCVFuncIdDirective(CurFn->FuncId);
|
|
|
|
|
2016-02-11 04:55:49 +08:00
|
|
|
// Find the end of the function prolog. First known non-DBG_VALUE and
|
|
|
|
// non-frame setup location marks the beginning of the function body.
|
2014-01-30 09:39:17 +08:00
|
|
|
// FIXME: is there a simpler a way to do this? Can we just search
|
|
|
|
// for the first instruction of the function, not the last of the prolog?
|
|
|
|
DebugLoc PrologEndLoc;
|
|
|
|
bool EmptyPrologue = true;
|
2014-05-01 06:17:38 +08:00
|
|
|
for (const auto &MBB : *MF) {
|
|
|
|
for (const auto &MI : MBB) {
|
2017-05-23 04:47:09 +08:00
|
|
|
if (!MI.isMetaInstruction() && !MI.getFlag(MachineInstr::FrameSetup) &&
|
2016-02-11 04:55:49 +08:00
|
|
|
MI.getDebugLoc()) {
|
2014-05-01 06:17:38 +08:00
|
|
|
PrologEndLoc = MI.getDebugLoc();
|
2014-01-30 09:39:17 +08:00
|
|
|
break;
|
2017-05-23 04:47:09 +08:00
|
|
|
} else if (!MI.isMetaInstruction()) {
|
2016-02-11 04:55:49 +08:00
|
|
|
EmptyPrologue = false;
|
2014-01-30 09:39:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-11 04:55:49 +08:00
|
|
|
|
2014-01-30 09:39:17 +08:00
|
|
|
// Record beginning of function if we have a non-empty prologue.
|
2015-03-31 03:14:47 +08:00
|
|
|
if (PrologEndLoc && !EmptyPrologue) {
|
|
|
|
DebugLoc FnStartDL = PrologEndLoc.getFnDebugLoc();
|
2014-01-30 09:39:17 +08:00
|
|
|
maybeRecordLocation(FnStartDL, MF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[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
|
|
|
static bool shouldEmitUdt(const DIType *T) {
|
|
|
|
while (true) {
|
|
|
|
if (!T || T->isForwardDecl())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const DIDerivedType *DT = dyn_cast<DIDerivedType>(T);
|
|
|
|
if (!DT)
|
|
|
|
return true;
|
|
|
|
T = DT->getBaseType().resolve();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewDebug::addToUDTs(const DIType *Ty) {
|
2016-07-02 06:24:51 +08:00
|
|
|
// Don't record empty UDTs.
|
|
|
|
if (Ty->getName().empty())
|
|
|
|
return;
|
[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
|
|
|
if (!shouldEmitUdt(Ty))
|
|
|
|
return;
|
2016-07-02 06:24:51 +08:00
|
|
|
|
2016-06-24 06:57:25 +08:00
|
|
|
SmallVector<StringRef, 5> QualifiedNameComponents;
|
|
|
|
const DISubprogram *ClosestSubprogram = getQualifiedNameComponents(
|
|
|
|
Ty->getScope().resolve(), QualifiedNameComponents);
|
|
|
|
|
|
|
|
std::string FullyQualifiedName =
|
2016-07-02 07:12:45 +08:00
|
|
|
getQualifiedName(QualifiedNameComponents, getPrettyScopeName(Ty));
|
2016-06-24 06:57:25 +08:00
|
|
|
|
[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
|
|
|
if (ClosestSubprogram == nullptr) {
|
|
|
|
GlobalUDTs.emplace_back(std::move(FullyQualifiedName), Ty);
|
|
|
|
} else if (ClosestSubprogram == CurrentSubprogram) {
|
|
|
|
LocalUDTs.emplace_back(std::move(FullyQualifiedName), Ty);
|
|
|
|
}
|
2016-06-24 06:57:25 +08:00
|
|
|
|
|
|
|
// TODO: What if the ClosestSubprogram is neither null or the current
|
|
|
|
// subprogram? Currently, the UDT just gets dropped on the floor.
|
|
|
|
//
|
|
|
|
// The current behavior is not desirable. To get maximal fidelity, we would
|
|
|
|
// need to perform all type translation before beginning emission of .debug$S
|
|
|
|
// and then make LocalUDTs a member of FunctionInfo
|
|
|
|
}
|
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
TypeIndex CodeViewDebug::lowerType(const DIType *Ty, const DIType *ClassTy) {
|
2016-06-02 01:05:51 +08:00
|
|
|
// Generic dispatch for lowering an unknown type.
|
|
|
|
switch (Ty->getTag()) {
|
2016-06-09 02:22:59 +08:00
|
|
|
case dwarf::DW_TAG_array_type:
|
|
|
|
return lowerTypeArray(cast<DICompositeType>(Ty));
|
2016-06-02 14:21:37 +08:00
|
|
|
case dwarf::DW_TAG_typedef:
|
|
|
|
return lowerTypeAlias(cast<DIDerivedType>(Ty));
|
2016-06-02 01:05:51 +08:00
|
|
|
case dwarf::DW_TAG_base_type:
|
|
|
|
return lowerTypeBasic(cast<DIBasicType>(Ty));
|
|
|
|
case dwarf::DW_TAG_pointer_type:
|
2016-08-31 23:59:30 +08:00
|
|
|
if (cast<DIDerivedType>(Ty)->getName() == "__vtbl_ptr_type")
|
|
|
|
return lowerTypeVFTableShape(cast<DIDerivedType>(Ty));
|
|
|
|
LLVM_FALLTHROUGH;
|
2016-06-02 01:05:51 +08:00
|
|
|
case dwarf::DW_TAG_reference_type:
|
|
|
|
case dwarf::DW_TAG_rvalue_reference_type:
|
|
|
|
return lowerTypePointer(cast<DIDerivedType>(Ty));
|
|
|
|
case dwarf::DW_TAG_ptr_to_member_type:
|
|
|
|
return lowerTypeMemberPointer(cast<DIDerivedType>(Ty));
|
|
|
|
case dwarf::DW_TAG_const_type:
|
|
|
|
case dwarf::DW_TAG_volatile_type:
|
2016-11-01 03:09:38 +08:00
|
|
|
// TODO: add support for DW_TAG_atomic_type here
|
2016-06-02 01:05:51 +08:00
|
|
|
return lowerTypeModifier(cast<DIDerivedType>(Ty));
|
2016-06-03 01:13:53 +08:00
|
|
|
case dwarf::DW_TAG_subroutine_type:
|
2016-06-22 09:32:56 +08:00
|
|
|
if (ClassTy) {
|
|
|
|
// The member function type of a member function pointer has no
|
|
|
|
// ThisAdjustment.
|
|
|
|
return lowerTypeMemberFunction(cast<DISubroutineType>(Ty), ClassTy,
|
|
|
|
/*ThisAdjustment=*/0);
|
|
|
|
}
|
2016-06-03 01:13:53 +08:00
|
|
|
return lowerTypeFunction(cast<DISubroutineType>(Ty));
|
2016-06-17 05:32:16 +08:00
|
|
|
case dwarf::DW_TAG_enumeration_type:
|
|
|
|
return lowerTypeEnum(cast<DICompositeType>(Ty));
|
2016-06-03 23:58:20 +08:00
|
|
|
case dwarf::DW_TAG_class_type:
|
|
|
|
case dwarf::DW_TAG_structure_type:
|
|
|
|
return lowerTypeClass(cast<DICompositeType>(Ty));
|
|
|
|
case dwarf::DW_TAG_union_type:
|
|
|
|
return lowerTypeUnion(cast<DICompositeType>(Ty));
|
2016-06-02 01:05:51 +08:00
|
|
|
default:
|
|
|
|
// Use the null type index.
|
|
|
|
return TypeIndex();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-02 14:21:37 +08:00
|
|
|
TypeIndex CodeViewDebug::lowerTypeAlias(const DIDerivedType *Ty) {
|
|
|
|
DITypeRef UnderlyingTypeRef = Ty->getBaseType();
|
|
|
|
TypeIndex UnderlyingTypeIndex = getTypeIndex(UnderlyingTypeRef);
|
2016-06-16 02:00:01 +08:00
|
|
|
StringRef TypeName = Ty->getName();
|
|
|
|
|
[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
|
|
|
addToUDTs(Ty);
|
2016-06-16 02:00:01 +08:00
|
|
|
|
2016-06-02 14:21:37 +08:00
|
|
|
if (UnderlyingTypeIndex == TypeIndex(SimpleTypeKind::Int32Long) &&
|
2016-06-16 02:00:01 +08:00
|
|
|
TypeName == "HRESULT")
|
2016-06-02 14:21:37 +08:00
|
|
|
return TypeIndex(SimpleTypeKind::HResult);
|
2016-06-04 23:40:33 +08:00
|
|
|
if (UnderlyingTypeIndex == TypeIndex(SimpleTypeKind::UInt16Short) &&
|
2016-06-16 02:00:01 +08:00
|
|
|
TypeName == "wchar_t")
|
2016-06-04 23:40:33 +08:00
|
|
|
return TypeIndex(SimpleTypeKind::WideCharacter);
|
2016-06-24 06:57:25 +08:00
|
|
|
|
2016-06-02 14:21:37 +08:00
|
|
|
return UnderlyingTypeIndex;
|
|
|
|
}
|
|
|
|
|
2016-06-09 02:22:59 +08:00
|
|
|
TypeIndex CodeViewDebug::lowerTypeArray(const DICompositeType *Ty) {
|
|
|
|
DITypeRef ElementTypeRef = Ty->getBaseType();
|
|
|
|
TypeIndex ElementTypeIndex = getTypeIndex(ElementTypeRef);
|
|
|
|
// IndexType is size_t, which depends on the bitness of the target.
|
2017-04-18 01:41:25 +08:00
|
|
|
TypeIndex IndexType = Asm->TM.getPointerSize() == 8
|
2016-06-09 02:22:59 +08:00
|
|
|
? TypeIndex(SimpleTypeKind::UInt64Quad)
|
|
|
|
: TypeIndex(SimpleTypeKind::UInt32Long);
|
2016-07-12 20:06:34 +08:00
|
|
|
|
|
|
|
uint64_t ElementSize = getBaseTypeSize(ElementTypeRef) / 8;
|
|
|
|
|
|
|
|
// Add subranges to array type.
|
|
|
|
DINodeArray Elements = Ty->getElements();
|
|
|
|
for (int i = Elements.size() - 1; i >= 0; --i) {
|
|
|
|
const DINode *Element = Elements[i];
|
|
|
|
assert(Element->getTag() == dwarf::DW_TAG_subrange_type);
|
|
|
|
|
|
|
|
const DISubrange *Subrange = cast<DISubrange>(Element);
|
|
|
|
assert(Subrange->getLowerBound() == 0 &&
|
|
|
|
"codeview doesn't support subranges with lower bounds");
|
|
|
|
int64_t Count = Subrange->getCount();
|
|
|
|
|
|
|
|
// Variable Length Array (VLA) has Count equal to '-1'.
|
|
|
|
// Replace with Count '1', assume it is the minimum VLA length.
|
|
|
|
// FIXME: Make front-end support VLA subrange and emit LF_DIMVARLU.
|
2017-03-25 07:28:42 +08:00
|
|
|
if (Count == -1)
|
2016-07-12 20:06:34 +08:00
|
|
|
Count = 1;
|
|
|
|
|
|
|
|
// Update the element size and element type index for subsequent subranges.
|
|
|
|
ElementSize *= Count;
|
2016-09-10 01:29:36 +08:00
|
|
|
|
|
|
|
// If this is the outermost array, use the size from the array. It will be
|
2017-03-25 07:28:42 +08:00
|
|
|
// more accurate if we had a VLA or an incomplete element type size.
|
2016-09-10 01:29:36 +08:00
|
|
|
uint64_t ArraySize =
|
|
|
|
(i == 0 && ElementSize == 0) ? Ty->getSizeInBits() / 8 : ElementSize;
|
|
|
|
|
|
|
|
StringRef Name = (i == 0) ? Ty->getName() : "";
|
2016-11-09 06:24:53 +08:00
|
|
|
ArrayRecord AR(ElementTypeIndex, IndexType, ArraySize, Name);
|
|
|
|
ElementTypeIndex = TypeTable.writeKnownType(AR);
|
2016-07-12 20:06:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ElementTypeIndex;
|
2016-06-09 02:22:59 +08:00
|
|
|
}
|
|
|
|
|
2016-06-02 01:05:51 +08:00
|
|
|
TypeIndex CodeViewDebug::lowerTypeBasic(const DIBasicType *Ty) {
|
|
|
|
TypeIndex Index;
|
|
|
|
dwarf::TypeKind Kind;
|
|
|
|
uint32_t ByteSize;
|
|
|
|
|
|
|
|
Kind = static_cast<dwarf::TypeKind>(Ty->getEncoding());
|
2016-06-02 14:21:42 +08:00
|
|
|
ByteSize = Ty->getSizeInBits() / 8;
|
2016-06-02 01:05:51 +08:00
|
|
|
|
|
|
|
SimpleTypeKind STK = SimpleTypeKind::None;
|
|
|
|
switch (Kind) {
|
|
|
|
case dwarf::DW_ATE_address:
|
|
|
|
// FIXME: Translate
|
|
|
|
break;
|
|
|
|
case dwarf::DW_ATE_boolean:
|
|
|
|
switch (ByteSize) {
|
2016-06-02 15:02:32 +08:00
|
|
|
case 1: STK = SimpleTypeKind::Boolean8; break;
|
|
|
|
case 2: STK = SimpleTypeKind::Boolean16; break;
|
|
|
|
case 4: STK = SimpleTypeKind::Boolean32; break;
|
|
|
|
case 8: STK = SimpleTypeKind::Boolean64; break;
|
|
|
|
case 16: STK = SimpleTypeKind::Boolean128; break;
|
2016-06-02 01:05:51 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dwarf::DW_ATE_complex_float:
|
|
|
|
switch (ByteSize) {
|
2016-06-02 15:02:32 +08:00
|
|
|
case 2: STK = SimpleTypeKind::Complex16; break;
|
2016-06-02 01:05:51 +08:00
|
|
|
case 4: STK = SimpleTypeKind::Complex32; break;
|
|
|
|
case 8: STK = SimpleTypeKind::Complex64; break;
|
|
|
|
case 10: STK = SimpleTypeKind::Complex80; break;
|
|
|
|
case 16: STK = SimpleTypeKind::Complex128; break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dwarf::DW_ATE_float:
|
|
|
|
switch (ByteSize) {
|
2016-06-02 15:02:32 +08:00
|
|
|
case 2: STK = SimpleTypeKind::Float16; break;
|
2016-06-02 01:05:51 +08:00
|
|
|
case 4: STK = SimpleTypeKind::Float32; break;
|
|
|
|
case 6: STK = SimpleTypeKind::Float48; break;
|
|
|
|
case 8: STK = SimpleTypeKind::Float64; break;
|
|
|
|
case 10: STK = SimpleTypeKind::Float80; break;
|
|
|
|
case 16: STK = SimpleTypeKind::Float128; break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dwarf::DW_ATE_signed:
|
|
|
|
switch (ByteSize) {
|
2016-09-30 01:55:01 +08:00
|
|
|
case 1: STK = SimpleTypeKind::SignedCharacter; break;
|
|
|
|
case 2: STK = SimpleTypeKind::Int16Short; break;
|
|
|
|
case 4: STK = SimpleTypeKind::Int32; break;
|
|
|
|
case 8: STK = SimpleTypeKind::Int64Quad; break;
|
|
|
|
case 16: STK = SimpleTypeKind::Int128Oct; break;
|
2016-06-02 01:05:51 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dwarf::DW_ATE_unsigned:
|
|
|
|
switch (ByteSize) {
|
2016-09-30 01:55:01 +08:00
|
|
|
case 1: STK = SimpleTypeKind::UnsignedCharacter; break;
|
|
|
|
case 2: STK = SimpleTypeKind::UInt16Short; break;
|
|
|
|
case 4: STK = SimpleTypeKind::UInt32; break;
|
|
|
|
case 8: STK = SimpleTypeKind::UInt64Quad; break;
|
|
|
|
case 16: STK = SimpleTypeKind::UInt128Oct; break;
|
2016-06-02 01:05:51 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dwarf::DW_ATE_UTF:
|
|
|
|
switch (ByteSize) {
|
|
|
|
case 2: STK = SimpleTypeKind::Character16; break;
|
|
|
|
case 4: STK = SimpleTypeKind::Character32; break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case dwarf::DW_ATE_signed_char:
|
|
|
|
if (ByteSize == 1)
|
|
|
|
STK = SimpleTypeKind::SignedCharacter;
|
|
|
|
break;
|
|
|
|
case dwarf::DW_ATE_unsigned_char:
|
|
|
|
if (ByteSize == 1)
|
|
|
|
STK = SimpleTypeKind::UnsignedCharacter;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply some fixups based on the source-level type name.
|
|
|
|
if (STK == SimpleTypeKind::Int32 && Ty->getName() == "long int")
|
|
|
|
STK = SimpleTypeKind::Int32Long;
|
|
|
|
if (STK == SimpleTypeKind::UInt32 && Ty->getName() == "long unsigned int")
|
|
|
|
STK = SimpleTypeKind::UInt32Long;
|
2016-06-04 23:40:33 +08:00
|
|
|
if (STK == SimpleTypeKind::UInt16Short &&
|
|
|
|
(Ty->getName() == "wchar_t" || Ty->getName() == "__wchar_t"))
|
2016-06-02 01:05:51 +08:00
|
|
|
STK = SimpleTypeKind::WideCharacter;
|
|
|
|
if ((STK == SimpleTypeKind::SignedCharacter ||
|
|
|
|
STK == SimpleTypeKind::UnsignedCharacter) &&
|
|
|
|
Ty->getName() == "char")
|
|
|
|
STK = SimpleTypeKind::NarrowCharacter;
|
|
|
|
|
|
|
|
return TypeIndex(STK);
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeIndex CodeViewDebug::lowerTypePointer(const DIDerivedType *Ty) {
|
|
|
|
TypeIndex PointeeTI = getTypeIndex(Ty->getBaseType());
|
|
|
|
|
|
|
|
// Pointers to simple types can use SimpleTypeMode, rather than having a
|
|
|
|
// dedicated pointer type record.
|
|
|
|
if (PointeeTI.isSimple() &&
|
|
|
|
PointeeTI.getSimpleMode() == SimpleTypeMode::Direct &&
|
|
|
|
Ty->getTag() == dwarf::DW_TAG_pointer_type) {
|
|
|
|
SimpleTypeMode Mode = Ty->getSizeInBits() == 64
|
|
|
|
? SimpleTypeMode::NearPointer64
|
|
|
|
: SimpleTypeMode::NearPointer32;
|
|
|
|
return TypeIndex(PointeeTI.getSimpleKind(), Mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
PointerKind PK =
|
|
|
|
Ty->getSizeInBits() == 64 ? PointerKind::Near64 : PointerKind::Near32;
|
|
|
|
PointerMode PM = PointerMode::Pointer;
|
|
|
|
switch (Ty->getTag()) {
|
|
|
|
default: llvm_unreachable("not a pointer tag type");
|
|
|
|
case dwarf::DW_TAG_pointer_type:
|
|
|
|
PM = PointerMode::Pointer;
|
|
|
|
break;
|
|
|
|
case dwarf::DW_TAG_reference_type:
|
|
|
|
PM = PointerMode::LValueReference;
|
|
|
|
break;
|
|
|
|
case dwarf::DW_TAG_rvalue_reference_type:
|
|
|
|
PM = PointerMode::RValueReference;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FIXME: MSVC folds qualifiers into PointerOptions in the context of a method
|
|
|
|
// 'this' pointer, but not normal contexts. Figure out what we're supposed to
|
|
|
|
// do.
|
|
|
|
PointerOptions PO = PointerOptions::None;
|
|
|
|
PointerRecord PR(PointeeTI, PK, PM, PO, Ty->getSizeInBits() / 8);
|
[CodeView] Decouple record deserialization from visitor dispatch.
Until now, our use case for the visitor has been to take a stream of bytes
representing a type stream, deserialize the records in sequence, and do
something with them, where "something" is determined by how the user
implements a particular set of callbacks on an abstract class.
For actually writing PDBs, however, we want to do the reverse. We have
some kind of description of the list of records in their in-memory format,
and we want to process each one. Perhaps by serializing them to a byte
stream, or perhaps by converting them from one description format (Yaml)
to another (in-memory representation).
This was difficult in the current model because deserialization and
invoking the callbacks were tightly coupled.
With this patch we change this so that TypeDeserializer is itself an
implementation of the particular set of callbacks. This decouples
deserialization from the iteration over a list of records and invocation
of the callbacks. TypeDeserializer is initialized with another
implementation of the callback interface, so that upon deserialization it
can pass the deserialized record through to the next set of callbacks. In
a sense this is like an implementation of the Decorator design pattern,
where the Deserializer is a decorator.
This will be useful for writing Pdbs from yaml, where we have a
description of the type records in Yaml format. In this case, the visitor
implementation would have each visitation callback method implemented in
such a way as to extract the proper set of fields from the Yaml, and it
could maintain state that builds up a list of these records. Finally at
the end we can pass this information through to another set of callbacks
which serializes them into a byte stream.
Reviewed By: majnemer, ruiu, rnk
Differential Revision: https://reviews.llvm.org/D23177
llvm-svn: 277871
2016-08-06 05:45:34 +08:00
|
|
|
return TypeTable.writeKnownType(PR);
|
2016-06-02 01:05:51 +08:00
|
|
|
}
|
|
|
|
|
2016-06-18 06:14:39 +08:00
|
|
|
static PointerToMemberRepresentation
|
|
|
|
translatePtrToMemberRep(unsigned SizeInBytes, bool IsPMF, unsigned Flags) {
|
|
|
|
// SizeInBytes being zero generally implies that the member pointer type was
|
|
|
|
// incomplete, which can happen if it is part of a function prototype. In this
|
|
|
|
// case, use the unknown model instead of the general model.
|
2016-06-18 05:31:33 +08:00
|
|
|
if (IsPMF) {
|
|
|
|
switch (Flags & DINode::FlagPtrToMemberRep) {
|
|
|
|
case 0:
|
2016-06-18 06:14:39 +08:00
|
|
|
return SizeInBytes == 0 ? PointerToMemberRepresentation::Unknown
|
|
|
|
: PointerToMemberRepresentation::GeneralFunction;
|
2016-06-18 05:31:33 +08:00
|
|
|
case DINode::FlagSingleInheritance:
|
|
|
|
return PointerToMemberRepresentation::SingleInheritanceFunction;
|
|
|
|
case DINode::FlagMultipleInheritance:
|
|
|
|
return PointerToMemberRepresentation::MultipleInheritanceFunction;
|
|
|
|
case DINode::FlagVirtualInheritance:
|
|
|
|
return PointerToMemberRepresentation::VirtualInheritanceFunction;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (Flags & DINode::FlagPtrToMemberRep) {
|
|
|
|
case 0:
|
2016-06-18 06:14:39 +08:00
|
|
|
return SizeInBytes == 0 ? PointerToMemberRepresentation::Unknown
|
|
|
|
: PointerToMemberRepresentation::GeneralData;
|
2016-06-18 05:31:33 +08:00
|
|
|
case DINode::FlagSingleInheritance:
|
|
|
|
return PointerToMemberRepresentation::SingleInheritanceData;
|
|
|
|
case DINode::FlagMultipleInheritance:
|
|
|
|
return PointerToMemberRepresentation::MultipleInheritanceData;
|
|
|
|
case DINode::FlagVirtualInheritance:
|
|
|
|
return PointerToMemberRepresentation::VirtualInheritanceData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
llvm_unreachable("invalid ptr to member representation");
|
|
|
|
}
|
|
|
|
|
2016-06-02 01:05:51 +08:00
|
|
|
TypeIndex CodeViewDebug::lowerTypeMemberPointer(const DIDerivedType *Ty) {
|
|
|
|
assert(Ty->getTag() == dwarf::DW_TAG_ptr_to_member_type);
|
|
|
|
TypeIndex ClassTI = getTypeIndex(Ty->getClassType());
|
2016-06-18 18:25:07 +08:00
|
|
|
TypeIndex PointeeTI = getTypeIndex(Ty->getBaseType(), Ty->getClassType());
|
2017-04-18 01:41:25 +08:00
|
|
|
PointerKind PK = Asm->TM.getPointerSize() == 8 ? PointerKind::Near64
|
|
|
|
: PointerKind::Near32;
|
2016-06-18 05:31:33 +08:00
|
|
|
bool IsPMF = isa<DISubroutineType>(Ty->getBaseType());
|
|
|
|
PointerMode PM = IsPMF ? PointerMode::PointerToMemberFunction
|
|
|
|
: PointerMode::PointerToDataMember;
|
2016-06-02 01:05:51 +08:00
|
|
|
PointerOptions PO = PointerOptions::None; // FIXME
|
2016-06-18 06:14:39 +08:00
|
|
|
assert(Ty->getSizeInBits() / 8 <= 0xff && "pointer size too big");
|
|
|
|
uint8_t SizeInBytes = Ty->getSizeInBits() / 8;
|
|
|
|
MemberPointerInfo MPI(
|
|
|
|
ClassTI, translatePtrToMemberRep(SizeInBytes, IsPMF, Ty->getFlags()));
|
2016-06-18 05:31:33 +08:00
|
|
|
PointerRecord PR(PointeeTI, PK, PM, PO, SizeInBytes, MPI);
|
[CodeView] Decouple record deserialization from visitor dispatch.
Until now, our use case for the visitor has been to take a stream of bytes
representing a type stream, deserialize the records in sequence, and do
something with them, where "something" is determined by how the user
implements a particular set of callbacks on an abstract class.
For actually writing PDBs, however, we want to do the reverse. We have
some kind of description of the list of records in their in-memory format,
and we want to process each one. Perhaps by serializing them to a byte
stream, or perhaps by converting them from one description format (Yaml)
to another (in-memory representation).
This was difficult in the current model because deserialization and
invoking the callbacks were tightly coupled.
With this patch we change this so that TypeDeserializer is itself an
implementation of the particular set of callbacks. This decouples
deserialization from the iteration over a list of records and invocation
of the callbacks. TypeDeserializer is initialized with another
implementation of the callback interface, so that upon deserialization it
can pass the deserialized record through to the next set of callbacks. In
a sense this is like an implementation of the Decorator design pattern,
where the Deserializer is a decorator.
This will be useful for writing Pdbs from yaml, where we have a
description of the type records in Yaml format. In this case, the visitor
implementation would have each visitation callback method implemented in
such a way as to extract the proper set of fields from the Yaml, and it
could maintain state that builds up a list of these records. Finally at
the end we can pass this information through to another set of callbacks
which serializes them into a byte stream.
Reviewed By: majnemer, ruiu, rnk
Differential Revision: https://reviews.llvm.org/D23177
llvm-svn: 277871
2016-08-06 05:45:34 +08:00
|
|
|
return TypeTable.writeKnownType(PR);
|
2016-06-02 01:05:51 +08:00
|
|
|
}
|
|
|
|
|
2016-06-09 04:34:29 +08:00
|
|
|
/// Given a DWARF calling convention, get the CodeView equivalent. If we don't
|
|
|
|
/// have a translation, use the NearC convention.
|
|
|
|
static CallingConvention dwarfCCToCodeView(unsigned DwarfCC) {
|
|
|
|
switch (DwarfCC) {
|
|
|
|
case dwarf::DW_CC_normal: return CallingConvention::NearC;
|
|
|
|
case dwarf::DW_CC_BORLAND_msfastcall: return CallingConvention::NearFast;
|
|
|
|
case dwarf::DW_CC_BORLAND_thiscall: return CallingConvention::ThisCall;
|
|
|
|
case dwarf::DW_CC_BORLAND_stdcall: return CallingConvention::NearStdCall;
|
|
|
|
case dwarf::DW_CC_BORLAND_pascal: return CallingConvention::NearPascal;
|
|
|
|
case dwarf::DW_CC_LLVM_vectorcall: return CallingConvention::NearVector;
|
|
|
|
}
|
|
|
|
return CallingConvention::NearC;
|
|
|
|
}
|
|
|
|
|
2016-06-02 01:05:51 +08:00
|
|
|
TypeIndex CodeViewDebug::lowerTypeModifier(const DIDerivedType *Ty) {
|
|
|
|
ModifierOptions Mods = ModifierOptions::None;
|
|
|
|
bool IsModifier = true;
|
|
|
|
const DIType *BaseTy = Ty;
|
2016-06-03 01:40:51 +08:00
|
|
|
while (IsModifier && BaseTy) {
|
2016-11-01 03:09:38 +08:00
|
|
|
// FIXME: Need to add DWARF tags for __unaligned and _Atomic
|
2016-06-02 01:05:51 +08:00
|
|
|
switch (BaseTy->getTag()) {
|
|
|
|
case dwarf::DW_TAG_const_type:
|
|
|
|
Mods |= ModifierOptions::Const;
|
|
|
|
break;
|
|
|
|
case dwarf::DW_TAG_volatile_type:
|
|
|
|
Mods |= ModifierOptions::Volatile;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
IsModifier = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (IsModifier)
|
|
|
|
BaseTy = cast<DIDerivedType>(BaseTy)->getBaseType().resolve();
|
|
|
|
}
|
|
|
|
TypeIndex ModifiedTI = getTypeIndex(BaseTy);
|
2016-11-09 06:24:53 +08:00
|
|
|
ModifierRecord MR(ModifiedTI, Mods);
|
|
|
|
return TypeTable.writeKnownType(MR);
|
2016-06-02 01:05:51 +08:00
|
|
|
}
|
|
|
|
|
2016-06-03 01:13:53 +08:00
|
|
|
TypeIndex CodeViewDebug::lowerTypeFunction(const DISubroutineType *Ty) {
|
|
|
|
SmallVector<TypeIndex, 8> ReturnAndArgTypeIndices;
|
|
|
|
for (DITypeRef ArgTypeRef : Ty->getTypeArray())
|
|
|
|
ReturnAndArgTypeIndices.push_back(getTypeIndex(ArgTypeRef));
|
|
|
|
|
|
|
|
TypeIndex ReturnTypeIndex = TypeIndex::Void();
|
|
|
|
ArrayRef<TypeIndex> ArgTypeIndices = None;
|
|
|
|
if (!ReturnAndArgTypeIndices.empty()) {
|
|
|
|
auto ReturnAndArgTypesRef = makeArrayRef(ReturnAndArgTypeIndices);
|
|
|
|
ReturnTypeIndex = ReturnAndArgTypesRef.front();
|
|
|
|
ArgTypeIndices = ReturnAndArgTypesRef.drop_front();
|
|
|
|
}
|
|
|
|
|
|
|
|
ArgListRecord ArgListRec(TypeRecordKind::ArgList, ArgTypeIndices);
|
[CodeView] Decouple record deserialization from visitor dispatch.
Until now, our use case for the visitor has been to take a stream of bytes
representing a type stream, deserialize the records in sequence, and do
something with them, where "something" is determined by how the user
implements a particular set of callbacks on an abstract class.
For actually writing PDBs, however, we want to do the reverse. We have
some kind of description of the list of records in their in-memory format,
and we want to process each one. Perhaps by serializing them to a byte
stream, or perhaps by converting them from one description format (Yaml)
to another (in-memory representation).
This was difficult in the current model because deserialization and
invoking the callbacks were tightly coupled.
With this patch we change this so that TypeDeserializer is itself an
implementation of the particular set of callbacks. This decouples
deserialization from the iteration over a list of records and invocation
of the callbacks. TypeDeserializer is initialized with another
implementation of the callback interface, so that upon deserialization it
can pass the deserialized record through to the next set of callbacks. In
a sense this is like an implementation of the Decorator design pattern,
where the Deserializer is a decorator.
This will be useful for writing Pdbs from yaml, where we have a
description of the type records in Yaml format. In this case, the visitor
implementation would have each visitation callback method implemented in
such a way as to extract the proper set of fields from the Yaml, and it
could maintain state that builds up a list of these records. Finally at
the end we can pass this information through to another set of callbacks
which serializes them into a byte stream.
Reviewed By: majnemer, ruiu, rnk
Differential Revision: https://reviews.llvm.org/D23177
llvm-svn: 277871
2016-08-06 05:45:34 +08:00
|
|
|
TypeIndex ArgListIndex = TypeTable.writeKnownType(ArgListRec);
|
2016-06-03 01:13:53 +08:00
|
|
|
|
2016-06-09 04:34:29 +08:00
|
|
|
CallingConvention CC = dwarfCCToCodeView(Ty->getCC());
|
|
|
|
|
|
|
|
ProcedureRecord Procedure(ReturnTypeIndex, CC, FunctionOptions::None,
|
|
|
|
ArgTypeIndices.size(), ArgListIndex);
|
[CodeView] Decouple record deserialization from visitor dispatch.
Until now, our use case for the visitor has been to take a stream of bytes
representing a type stream, deserialize the records in sequence, and do
something with them, where "something" is determined by how the user
implements a particular set of callbacks on an abstract class.
For actually writing PDBs, however, we want to do the reverse. We have
some kind of description of the list of records in their in-memory format,
and we want to process each one. Perhaps by serializing them to a byte
stream, or perhaps by converting them from one description format (Yaml)
to another (in-memory representation).
This was difficult in the current model because deserialization and
invoking the callbacks were tightly coupled.
With this patch we change this so that TypeDeserializer is itself an
implementation of the particular set of callbacks. This decouples
deserialization from the iteration over a list of records and invocation
of the callbacks. TypeDeserializer is initialized with another
implementation of the callback interface, so that upon deserialization it
can pass the deserialized record through to the next set of callbacks. In
a sense this is like an implementation of the Decorator design pattern,
where the Deserializer is a decorator.
This will be useful for writing Pdbs from yaml, where we have a
description of the type records in Yaml format. In this case, the visitor
implementation would have each visitation callback method implemented in
such a way as to extract the proper set of fields from the Yaml, and it
could maintain state that builds up a list of these records. Finally at
the end we can pass this information through to another set of callbacks
which serializes them into a byte stream.
Reviewed By: majnemer, ruiu, rnk
Differential Revision: https://reviews.llvm.org/D23177
llvm-svn: 277871
2016-08-06 05:45:34 +08:00
|
|
|
return TypeTable.writeKnownType(Procedure);
|
2016-06-03 01:13:53 +08:00
|
|
|
}
|
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
TypeIndex CodeViewDebug::lowerTypeMemberFunction(const DISubroutineType *Ty,
|
2016-06-22 09:32:56 +08:00
|
|
|
const DIType *ClassTy,
|
|
|
|
int ThisAdjustment) {
|
2016-06-18 18:25:07 +08:00
|
|
|
// Lower the containing class type.
|
|
|
|
TypeIndex ClassType = getTypeIndex(ClassTy);
|
|
|
|
|
|
|
|
SmallVector<TypeIndex, 8> ReturnAndArgTypeIndices;
|
|
|
|
for (DITypeRef ArgTypeRef : Ty->getTypeArray())
|
|
|
|
ReturnAndArgTypeIndices.push_back(getTypeIndex(ArgTypeRef));
|
|
|
|
|
|
|
|
TypeIndex ReturnTypeIndex = TypeIndex::Void();
|
|
|
|
ArrayRef<TypeIndex> ArgTypeIndices = None;
|
|
|
|
if (!ReturnAndArgTypeIndices.empty()) {
|
|
|
|
auto ReturnAndArgTypesRef = makeArrayRef(ReturnAndArgTypeIndices);
|
|
|
|
ReturnTypeIndex = ReturnAndArgTypesRef.front();
|
|
|
|
ArgTypeIndices = ReturnAndArgTypesRef.drop_front();
|
|
|
|
}
|
|
|
|
TypeIndex ThisTypeIndex = TypeIndex::Void();
|
|
|
|
if (!ArgTypeIndices.empty()) {
|
|
|
|
ThisTypeIndex = ArgTypeIndices.front();
|
|
|
|
ArgTypeIndices = ArgTypeIndices.drop_front();
|
|
|
|
}
|
|
|
|
|
|
|
|
ArgListRecord ArgListRec(TypeRecordKind::ArgList, ArgTypeIndices);
|
[CodeView] Decouple record deserialization from visitor dispatch.
Until now, our use case for the visitor has been to take a stream of bytes
representing a type stream, deserialize the records in sequence, and do
something with them, where "something" is determined by how the user
implements a particular set of callbacks on an abstract class.
For actually writing PDBs, however, we want to do the reverse. We have
some kind of description of the list of records in their in-memory format,
and we want to process each one. Perhaps by serializing them to a byte
stream, or perhaps by converting them from one description format (Yaml)
to another (in-memory representation).
This was difficult in the current model because deserialization and
invoking the callbacks were tightly coupled.
With this patch we change this so that TypeDeserializer is itself an
implementation of the particular set of callbacks. This decouples
deserialization from the iteration over a list of records and invocation
of the callbacks. TypeDeserializer is initialized with another
implementation of the callback interface, so that upon deserialization it
can pass the deserialized record through to the next set of callbacks. In
a sense this is like an implementation of the Decorator design pattern,
where the Deserializer is a decorator.
This will be useful for writing Pdbs from yaml, where we have a
description of the type records in Yaml format. In this case, the visitor
implementation would have each visitation callback method implemented in
such a way as to extract the proper set of fields from the Yaml, and it
could maintain state that builds up a list of these records. Finally at
the end we can pass this information through to another set of callbacks
which serializes them into a byte stream.
Reviewed By: majnemer, ruiu, rnk
Differential Revision: https://reviews.llvm.org/D23177
llvm-svn: 277871
2016-08-06 05:45:34 +08:00
|
|
|
TypeIndex ArgListIndex = TypeTable.writeKnownType(ArgListRec);
|
2016-06-18 18:25:07 +08:00
|
|
|
|
|
|
|
CallingConvention CC = dwarfCCToCodeView(Ty->getCC());
|
|
|
|
|
|
|
|
// TODO: Need to use the correct values for:
|
|
|
|
// FunctionOptions
|
|
|
|
// ThisPointerAdjustment.
|
2016-11-09 06:24:53 +08:00
|
|
|
MemberFunctionRecord MFR(ReturnTypeIndex, ClassType, ThisTypeIndex, CC,
|
|
|
|
FunctionOptions::None, ArgTypeIndices.size(),
|
|
|
|
ArgListIndex, ThisAdjustment);
|
|
|
|
TypeIndex TI = TypeTable.writeKnownType(MFR);
|
2016-06-18 18:25:07 +08:00
|
|
|
|
|
|
|
return TI;
|
|
|
|
}
|
|
|
|
|
2016-08-31 23:59:30 +08:00
|
|
|
TypeIndex CodeViewDebug::lowerTypeVFTableShape(const DIDerivedType *Ty) {
|
2017-04-18 01:41:25 +08:00
|
|
|
unsigned VSlotCount =
|
|
|
|
Ty->getSizeInBits() / (8 * Asm->MAI->getCodePointerSize());
|
2016-08-31 23:59:30 +08:00
|
|
|
SmallVector<VFTableSlotKind, 4> Slots(VSlotCount, VFTableSlotKind::Near);
|
2016-11-09 06:24:53 +08:00
|
|
|
|
|
|
|
VFTableShapeRecord VFTSR(Slots);
|
|
|
|
return TypeTable.writeKnownType(VFTSR);
|
2016-08-31 23:59:30 +08:00
|
|
|
}
|
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
static MemberAccess translateAccessFlags(unsigned RecordTag, unsigned Flags) {
|
|
|
|
switch (Flags & DINode::FlagAccessibility) {
|
2016-06-03 23:58:20 +08:00
|
|
|
case DINode::FlagPrivate: return MemberAccess::Private;
|
|
|
|
case DINode::FlagPublic: return MemberAccess::Public;
|
|
|
|
case DINode::FlagProtected: return MemberAccess::Protected;
|
|
|
|
case 0:
|
|
|
|
// If there was no explicit access control, provide the default for the tag.
|
|
|
|
return RecordTag == dwarf::DW_TAG_class_type ? MemberAccess::Private
|
|
|
|
: MemberAccess::Public;
|
|
|
|
}
|
|
|
|
llvm_unreachable("access flags are exclusive");
|
|
|
|
}
|
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
static MethodOptions translateMethodOptionFlags(const DISubprogram *SP) {
|
|
|
|
if (SP->isArtificial())
|
|
|
|
return MethodOptions::CompilerGenerated;
|
|
|
|
|
|
|
|
// FIXME: Handle other MethodOptions.
|
|
|
|
|
|
|
|
return MethodOptions::None;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MethodKind translateMethodKindFlags(const DISubprogram *SP,
|
|
|
|
bool Introduced) {
|
|
|
|
switch (SP->getVirtuality()) {
|
|
|
|
case dwarf::DW_VIRTUALITY_none:
|
|
|
|
break;
|
|
|
|
case dwarf::DW_VIRTUALITY_virtual:
|
|
|
|
return Introduced ? MethodKind::IntroducingVirtual : MethodKind::Virtual;
|
|
|
|
case dwarf::DW_VIRTUALITY_pure_virtual:
|
|
|
|
return Introduced ? MethodKind::PureIntroducingVirtual
|
|
|
|
: MethodKind::PureVirtual;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("unhandled virtuality case");
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Get Clang to mark DISubprogram as static and do something with it.
|
|
|
|
|
|
|
|
return MethodKind::Vanilla;
|
|
|
|
}
|
|
|
|
|
2016-06-03 23:58:20 +08:00
|
|
|
static TypeRecordKind getRecordKind(const DICompositeType *Ty) {
|
|
|
|
switch (Ty->getTag()) {
|
|
|
|
case dwarf::DW_TAG_class_type: return TypeRecordKind::Class;
|
|
|
|
case dwarf::DW_TAG_structure_type: return TypeRecordKind::Struct;
|
|
|
|
}
|
|
|
|
llvm_unreachable("unexpected tag");
|
|
|
|
}
|
|
|
|
|
2016-07-02 08:11:07 +08:00
|
|
|
/// Return ClassOptions that should be present on both the forward declaration
|
|
|
|
/// and the defintion of a tag type.
|
|
|
|
static ClassOptions getCommonClassOptions(const DICompositeType *Ty) {
|
|
|
|
ClassOptions CO = ClassOptions::None;
|
|
|
|
|
|
|
|
// MSVC always sets this flag, even for local types. Clang doesn't always
|
2016-06-03 23:58:20 +08:00
|
|
|
// appear to give every type a linkage name, which may be problematic for us.
|
|
|
|
// FIXME: Investigate the consequences of not following them here.
|
2016-07-02 08:11:07 +08:00
|
|
|
if (!Ty->getIdentifier().empty())
|
|
|
|
CO |= ClassOptions::HasUniqueName;
|
|
|
|
|
|
|
|
// Put the Nested flag on a type if it appears immediately inside a tag type.
|
|
|
|
// Do not walk the scope chain. Do not attempt to compute ContainsNestedClass
|
|
|
|
// here. That flag is only set on definitions, and not forward declarations.
|
|
|
|
const DIScope *ImmediateScope = Ty->getScope().resolve();
|
|
|
|
if (ImmediateScope && isa<DICompositeType>(ImmediateScope))
|
|
|
|
CO |= ClassOptions::Nested;
|
|
|
|
|
|
|
|
// Put the Scoped flag on function-local types.
|
|
|
|
for (const DIScope *Scope = ImmediateScope; Scope != nullptr;
|
|
|
|
Scope = Scope->getScope().resolve()) {
|
|
|
|
if (isa<DISubprogram>(Scope)) {
|
|
|
|
CO |= ClassOptions::Scoped;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CO;
|
2016-06-03 23:58:20 +08:00
|
|
|
}
|
|
|
|
|
2016-06-17 05:32:16 +08:00
|
|
|
TypeIndex CodeViewDebug::lowerTypeEnum(const DICompositeType *Ty) {
|
2016-07-02 08:11:07 +08:00
|
|
|
ClassOptions CO = getCommonClassOptions(Ty);
|
2016-06-17 05:32:16 +08:00
|
|
|
TypeIndex FTI;
|
2016-06-18 00:13:21 +08:00
|
|
|
unsigned EnumeratorCount = 0;
|
2016-06-17 05:32:16 +08:00
|
|
|
|
2016-06-18 00:13:21 +08:00
|
|
|
if (Ty->isForwardDecl()) {
|
2016-06-17 05:32:16 +08:00
|
|
|
CO |= ClassOptions::ForwardReference;
|
2016-06-18 00:13:21 +08:00
|
|
|
} else {
|
2016-11-09 06:24:53 +08:00
|
|
|
FieldListRecordBuilder FLRB(TypeTable);
|
|
|
|
|
|
|
|
FLRB.begin();
|
2016-06-18 00:13:21 +08:00
|
|
|
for (const DINode *Element : Ty->getElements()) {
|
|
|
|
// We assume that the frontend provides all members in source declaration
|
|
|
|
// order, which is what MSVC does.
|
|
|
|
if (auto *Enumerator = dyn_cast_or_null<DIEnumerator>(Element)) {
|
2016-11-09 06:24:53 +08:00
|
|
|
EnumeratorRecord ER(MemberAccess::Public,
|
|
|
|
APSInt::getUnsigned(Enumerator->getValue()),
|
|
|
|
Enumerator->getName());
|
|
|
|
FLRB.writeMemberType(ER);
|
2016-06-18 00:13:21 +08:00
|
|
|
EnumeratorCount++;
|
|
|
|
}
|
|
|
|
}
|
2017-05-26 05:15:37 +08:00
|
|
|
FTI = FLRB.end(true);
|
2016-06-18 00:13:21 +08:00
|
|
|
}
|
2016-06-17 05:32:16 +08:00
|
|
|
|
2016-07-02 07:12:45 +08:00
|
|
|
std::string FullName = getFullyQualifiedName(Ty);
|
2016-06-22 09:32:56 +08:00
|
|
|
|
2016-11-09 06:24:53 +08:00
|
|
|
EnumRecord ER(EnumeratorCount, CO, FTI, FullName, Ty->getIdentifier(),
|
|
|
|
getTypeIndex(Ty->getBaseType()));
|
|
|
|
return TypeTable.writeKnownType(ER);
|
2016-06-17 05:32:16 +08:00
|
|
|
}
|
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ClassInfo
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
struct llvm::ClassInfo {
|
|
|
|
struct MemberInfo {
|
|
|
|
const DIDerivedType *MemberTypeNode;
|
2016-07-02 07:12:48 +08:00
|
|
|
uint64_t BaseOffset;
|
2016-06-18 18:25:07 +08:00
|
|
|
};
|
|
|
|
// [MemberInfo]
|
2017-06-07 06:22:41 +08:00
|
|
|
using MemberList = std::vector<MemberInfo>;
|
2016-06-18 18:25:07 +08:00
|
|
|
|
2017-06-07 06:22:41 +08:00
|
|
|
using MethodsList = TinyPtrVector<const DISubprogram *>;
|
2016-06-18 18:25:07 +08:00
|
|
|
// MethodName -> MethodsList
|
2017-06-07 06:22:41 +08:00
|
|
|
using MethodsMap = MapVector<MDString *, MethodsList>;
|
2016-06-18 18:25:07 +08:00
|
|
|
|
2016-06-25 00:24:24 +08:00
|
|
|
/// Base classes.
|
|
|
|
std::vector<const DIDerivedType *> Inheritance;
|
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
/// Direct members.
|
|
|
|
MemberList Members;
|
|
|
|
// Direct overloaded methods gathered by name.
|
|
|
|
MethodsMap Methods;
|
2016-07-07 03:49:51 +08:00
|
|
|
|
2016-08-31 23:59:30 +08:00
|
|
|
TypeIndex VShapeTI;
|
|
|
|
|
2017-08-09 04:30:14 +08:00
|
|
|
std::vector<const DIType *> NestedTypes;
|
2016-06-18 18:25:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void CodeViewDebug::clear() {
|
|
|
|
assert(CurFn == nullptr);
|
|
|
|
FileIdMap.clear();
|
|
|
|
FnDebugInfo.clear();
|
|
|
|
FileToFilepathMap.clear();
|
|
|
|
LocalUDTs.clear();
|
|
|
|
GlobalUDTs.clear();
|
|
|
|
TypeIndices.clear();
|
|
|
|
CompleteTypeIndices.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewDebug::collectMemberInfo(ClassInfo &Info,
|
|
|
|
const DIDerivedType *DDTy) {
|
|
|
|
if (!DDTy->getName().empty()) {
|
|
|
|
Info.Members.push_back({DDTy, 0});
|
|
|
|
return;
|
|
|
|
}
|
2016-06-23 00:06:42 +08:00
|
|
|
// An unnamed member must represent a nested struct or union. Add all the
|
|
|
|
// indirect fields to the current record.
|
2016-06-18 18:25:07 +08:00
|
|
|
assert((DDTy->getOffsetInBits() % 8) == 0 && "Unnamed bitfield member!");
|
2016-07-02 07:12:48 +08:00
|
|
|
uint64_t Offset = DDTy->getOffsetInBits();
|
2016-06-18 18:25:07 +08:00
|
|
|
const DIType *Ty = DDTy->getBaseType().resolve();
|
2016-06-21 22:56:24 +08:00
|
|
|
const DICompositeType *DCTy = cast<DICompositeType>(Ty);
|
2016-06-23 00:06:42 +08:00
|
|
|
ClassInfo NestedInfo = collectClassInfo(DCTy);
|
|
|
|
for (const ClassInfo::MemberInfo &IndirectField : NestedInfo.Members)
|
2016-06-18 18:25:07 +08:00
|
|
|
Info.Members.push_back(
|
2016-06-23 00:06:42 +08:00
|
|
|
{IndirectField.MemberTypeNode, IndirectField.BaseOffset + Offset});
|
2016-06-18 18:25:07 +08:00
|
|
|
}
|
|
|
|
|
2016-06-23 00:06:42 +08:00
|
|
|
ClassInfo CodeViewDebug::collectClassInfo(const DICompositeType *Ty) {
|
|
|
|
ClassInfo Info;
|
2016-06-18 18:25:07 +08:00
|
|
|
// Add elements to structure type.
|
|
|
|
DINodeArray Elements = Ty->getElements();
|
|
|
|
for (auto *Element : Elements) {
|
|
|
|
// We assume that the frontend provides all members in source declaration
|
|
|
|
// order, which is what MSVC does.
|
|
|
|
if (!Element)
|
|
|
|
continue;
|
|
|
|
if (auto *SP = dyn_cast<DISubprogram>(Element)) {
|
2016-06-23 02:31:14 +08:00
|
|
|
Info.Methods[SP->getRawName()].push_back(SP);
|
2016-06-18 18:25:07 +08:00
|
|
|
} else if (auto *DDTy = dyn_cast<DIDerivedType>(Element)) {
|
2016-06-25 00:24:24 +08:00
|
|
|
if (DDTy->getTag() == dwarf::DW_TAG_member) {
|
2016-06-23 00:06:42 +08:00
|
|
|
collectMemberInfo(Info, DDTy);
|
2016-06-25 00:24:24 +08:00
|
|
|
} else if (DDTy->getTag() == dwarf::DW_TAG_inheritance) {
|
|
|
|
Info.Inheritance.push_back(DDTy);
|
2016-08-31 23:59:30 +08:00
|
|
|
} else if (DDTy->getTag() == dwarf::DW_TAG_pointer_type &&
|
|
|
|
DDTy->getName() == "__vtbl_ptr_type") {
|
|
|
|
Info.VShapeTI = getTypeIndex(DDTy);
|
2017-08-09 04:30:14 +08:00
|
|
|
} else if (DDTy->getTag() == dwarf::DW_TAG_typedef) {
|
|
|
|
Info.NestedTypes.push_back(DDTy);
|
2016-06-18 18:25:07 +08:00
|
|
|
} else if (DDTy->getTag() == dwarf::DW_TAG_friend) {
|
|
|
|
// Ignore friend members. It appears that MSVC emitted info about
|
|
|
|
// friends in the past, but modern versions do not.
|
|
|
|
}
|
2016-07-07 03:49:51 +08:00
|
|
|
} else if (auto *Composite = dyn_cast<DICompositeType>(Element)) {
|
2017-08-09 04:30:14 +08:00
|
|
|
Info.NestedTypes.push_back(Composite);
|
2016-06-18 18:25:07 +08:00
|
|
|
}
|
|
|
|
// Skip other unrecognized kinds of elements.
|
|
|
|
}
|
2016-06-23 00:06:42 +08:00
|
|
|
return Info;
|
2016-06-18 18:25:07 +08:00
|
|
|
}
|
|
|
|
|
2016-06-03 23:58:20 +08:00
|
|
|
TypeIndex CodeViewDebug::lowerTypeClass(const DICompositeType *Ty) {
|
|
|
|
// First, construct the forward decl. Don't look into Ty to compute the
|
|
|
|
// forward decl options, since it might not be available in all TUs.
|
|
|
|
TypeRecordKind Kind = getRecordKind(Ty);
|
|
|
|
ClassOptions CO =
|
2016-07-02 08:11:07 +08:00
|
|
|
ClassOptions::ForwardReference | getCommonClassOptions(Ty);
|
2016-07-02 07:12:45 +08:00
|
|
|
std::string FullName = getFullyQualifiedName(Ty);
|
2016-11-09 06:24:53 +08:00
|
|
|
ClassRecord CR(Kind, 0, CO, TypeIndex(), TypeIndex(), TypeIndex(), 0,
|
|
|
|
FullName, Ty->getIdentifier());
|
|
|
|
TypeIndex FwdDeclTI = TypeTable.writeKnownType(CR);
|
2016-06-23 01:15:28 +08:00
|
|
|
if (!Ty->isForwardDecl())
|
|
|
|
DeferredCompleteTypes.push_back(Ty);
|
2016-06-03 23:58:20 +08:00
|
|
|
return FwdDeclTI;
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeIndex CodeViewDebug::lowerCompleteTypeClass(const DICompositeType *Ty) {
|
|
|
|
// Construct the field list and complete type record.
|
|
|
|
TypeRecordKind Kind = getRecordKind(Ty);
|
2016-07-02 08:11:07 +08:00
|
|
|
ClassOptions CO = getCommonClassOptions(Ty);
|
2016-06-18 18:25:07 +08:00
|
|
|
TypeIndex FieldTI;
|
|
|
|
TypeIndex VShapeTI;
|
2016-06-03 23:58:20 +08:00
|
|
|
unsigned FieldCount;
|
2016-07-07 03:49:51 +08:00
|
|
|
bool ContainsNestedClass;
|
|
|
|
std::tie(FieldTI, VShapeTI, FieldCount, ContainsNestedClass) =
|
|
|
|
lowerRecordFieldList(Ty);
|
|
|
|
|
|
|
|
if (ContainsNestedClass)
|
|
|
|
CO |= ClassOptions::ContainsNestedClass;
|
2016-06-03 23:58:20 +08:00
|
|
|
|
2016-07-02 07:12:45 +08:00
|
|
|
std::string FullName = getFullyQualifiedName(Ty);
|
2016-06-22 09:32:56 +08:00
|
|
|
|
2016-06-03 23:58:20 +08:00
|
|
|
uint64_t SizeInBytes = Ty->getSizeInBits() / 8;
|
2016-06-23 05:22:13 +08:00
|
|
|
|
2016-11-09 06:24:53 +08:00
|
|
|
ClassRecord CR(Kind, FieldCount, CO, FieldTI, TypeIndex(), VShapeTI,
|
|
|
|
SizeInBytes, FullName, Ty->getIdentifier());
|
|
|
|
TypeIndex ClassTI = TypeTable.writeKnownType(CR);
|
2016-06-23 05:22:13 +08:00
|
|
|
|
2017-05-04 05:39:01 +08:00
|
|
|
if (const auto *File = Ty->getFile()) {
|
|
|
|
StringIdRecord SIDR(TypeIndex(0x0), getFullFilepath(File));
|
|
|
|
TypeIndex SIDI = TypeTable.writeKnownType(SIDR);
|
|
|
|
UdtSourceLineRecord USLR(ClassTI, SIDI, Ty->getLine());
|
|
|
|
TypeTable.writeKnownType(USLR);
|
|
|
|
}
|
2016-06-23 05:22:13 +08:00
|
|
|
|
[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
|
|
|
addToUDTs(Ty);
|
2016-06-24 06:57:25 +08:00
|
|
|
|
2016-06-23 05:22:13 +08:00
|
|
|
return ClassTI;
|
2016-06-03 23:58:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TypeIndex CodeViewDebug::lowerTypeUnion(const DICompositeType *Ty) {
|
|
|
|
ClassOptions CO =
|
2016-07-02 08:11:07 +08:00
|
|
|
ClassOptions::ForwardReference | getCommonClassOptions(Ty);
|
2016-07-02 07:12:45 +08:00
|
|
|
std::string FullName = getFullyQualifiedName(Ty);
|
2016-11-09 06:24:53 +08:00
|
|
|
UnionRecord UR(0, CO, TypeIndex(), 0, FullName, Ty->getIdentifier());
|
|
|
|
TypeIndex FwdDeclTI = TypeTable.writeKnownType(UR);
|
2016-06-23 01:15:28 +08:00
|
|
|
if (!Ty->isForwardDecl())
|
|
|
|
DeferredCompleteTypes.push_back(Ty);
|
2016-06-03 23:58:20 +08:00
|
|
|
return FwdDeclTI;
|
|
|
|
}
|
|
|
|
|
|
|
|
TypeIndex CodeViewDebug::lowerCompleteTypeUnion(const DICompositeType *Ty) {
|
2016-07-07 05:07:42 +08:00
|
|
|
ClassOptions CO = ClassOptions::Sealed | getCommonClassOptions(Ty);
|
2016-06-18 18:25:07 +08:00
|
|
|
TypeIndex FieldTI;
|
2016-06-03 23:58:20 +08:00
|
|
|
unsigned FieldCount;
|
2016-07-07 03:49:51 +08:00
|
|
|
bool ContainsNestedClass;
|
|
|
|
std::tie(FieldTI, std::ignore, FieldCount, ContainsNestedClass) =
|
|
|
|
lowerRecordFieldList(Ty);
|
|
|
|
|
|
|
|
if (ContainsNestedClass)
|
|
|
|
CO |= ClassOptions::ContainsNestedClass;
|
|
|
|
|
2016-06-03 23:58:20 +08:00
|
|
|
uint64_t SizeInBytes = Ty->getSizeInBits() / 8;
|
2016-07-02 07:12:45 +08:00
|
|
|
std::string FullName = getFullyQualifiedName(Ty);
|
2016-06-23 05:22:13 +08:00
|
|
|
|
2016-11-09 06:24:53 +08:00
|
|
|
UnionRecord UR(FieldCount, CO, FieldTI, SizeInBytes, FullName,
|
|
|
|
Ty->getIdentifier());
|
|
|
|
TypeIndex UnionTI = TypeTable.writeKnownType(UR);
|
2016-06-23 05:22:13 +08:00
|
|
|
|
2016-11-09 06:24:53 +08:00
|
|
|
StringIdRecord SIR(TypeIndex(0x0), getFullFilepath(Ty->getFile()));
|
|
|
|
TypeIndex SIRI = TypeTable.writeKnownType(SIR);
|
|
|
|
UdtSourceLineRecord USLR(UnionTI, SIRI, Ty->getLine());
|
|
|
|
TypeTable.writeKnownType(USLR);
|
2016-06-23 05:22:13 +08:00
|
|
|
|
[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
|
|
|
addToUDTs(Ty);
|
2016-06-24 06:57:25 +08:00
|
|
|
|
2016-06-23 05:22:13 +08:00
|
|
|
return UnionTI;
|
2016-06-03 23:58:20 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 03:49:51 +08:00
|
|
|
std::tuple<TypeIndex, TypeIndex, unsigned, bool>
|
2016-06-03 23:58:20 +08:00
|
|
|
CodeViewDebug::lowerRecordFieldList(const DICompositeType *Ty) {
|
|
|
|
// Manually count members. MSVC appears to count everything that generates a
|
|
|
|
// field list record. Each individual overload in a method overload group
|
|
|
|
// contributes to this count, even though the overload group is a single field
|
|
|
|
// list record.
|
|
|
|
unsigned MemberCount = 0;
|
2016-06-23 00:06:42 +08:00
|
|
|
ClassInfo Info = collectClassInfo(Ty);
|
2016-11-09 06:24:53 +08:00
|
|
|
FieldListRecordBuilder FLBR(TypeTable);
|
|
|
|
FLBR.begin();
|
2016-06-18 18:25:07 +08:00
|
|
|
|
2016-06-25 00:24:24 +08:00
|
|
|
// Create base classes.
|
|
|
|
for (const DIDerivedType *I : Info.Inheritance) {
|
|
|
|
if (I->getFlags() & DINode::FlagVirtual) {
|
|
|
|
// Virtual base.
|
|
|
|
// FIXME: Emit VBPtrOffset when the frontend provides it.
|
|
|
|
unsigned VBPtrOffset = 0;
|
|
|
|
// FIXME: Despite the accessor name, the offset is really in bytes.
|
|
|
|
unsigned VBTableIndex = I->getOffsetInBits() / 4;
|
2016-10-26 06:11:52 +08:00
|
|
|
auto RecordKind = (I->getFlags() & DINode::FlagIndirectVirtualBase) == DINode::FlagIndirectVirtualBase
|
|
|
|
? TypeRecordKind::IndirectVirtualBaseClass
|
|
|
|
: TypeRecordKind::VirtualBaseClass;
|
2016-11-09 06:24:53 +08:00
|
|
|
VirtualBaseClassRecord VBCR(
|
2016-10-26 06:11:52 +08:00
|
|
|
RecordKind, translateAccessFlags(Ty->getTag(), I->getFlags()),
|
2016-06-25 00:24:24 +08:00
|
|
|
getTypeIndex(I->getBaseType()), getVBPTypeIndex(), VBPtrOffset,
|
2016-11-09 06:24:53 +08:00
|
|
|
VBTableIndex);
|
|
|
|
|
|
|
|
FLBR.writeMemberType(VBCR);
|
2016-06-25 00:24:24 +08:00
|
|
|
} else {
|
|
|
|
assert(I->getOffsetInBits() % 8 == 0 &&
|
|
|
|
"bases must be on byte boundaries");
|
2016-11-09 06:24:53 +08:00
|
|
|
BaseClassRecord BCR(translateAccessFlags(Ty->getTag(), I->getFlags()),
|
|
|
|
getTypeIndex(I->getBaseType()),
|
|
|
|
I->getOffsetInBits() / 8);
|
|
|
|
FLBR.writeMemberType(BCR);
|
2016-06-25 00:24:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
// Create members.
|
|
|
|
for (ClassInfo::MemberInfo &MemberInfo : Info.Members) {
|
|
|
|
const DIDerivedType *Member = MemberInfo.MemberTypeNode;
|
|
|
|
TypeIndex MemberBaseType = getTypeIndex(Member->getBaseType());
|
2016-06-30 11:00:20 +08:00
|
|
|
StringRef MemberName = Member->getName();
|
|
|
|
MemberAccess Access =
|
|
|
|
translateAccessFlags(Ty->getTag(), Member->getFlags());
|
2016-06-18 18:25:07 +08:00
|
|
|
|
|
|
|
if (Member->isStaticMember()) {
|
2016-11-09 06:24:53 +08:00
|
|
|
StaticDataMemberRecord SDMR(Access, MemberBaseType, MemberName);
|
|
|
|
FLBR.writeMemberType(SDMR);
|
2016-06-18 18:25:07 +08:00
|
|
|
MemberCount++;
|
2016-06-03 23:58:20 +08:00
|
|
|
continue;
|
|
|
|
}
|
2016-06-18 18:25:07 +08:00
|
|
|
|
2016-08-31 23:59:30 +08:00
|
|
|
// Virtual function pointer member.
|
|
|
|
if ((Member->getFlags() & DINode::FlagArtificial) &&
|
|
|
|
Member->getName().startswith("_vptr$")) {
|
2016-11-09 06:24:53 +08:00
|
|
|
VFPtrRecord VFPR(getTypeIndex(Member->getBaseType()));
|
|
|
|
FLBR.writeMemberType(VFPR);
|
2016-08-31 23:59:30 +08:00
|
|
|
MemberCount++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-06-30 11:00:20 +08:00
|
|
|
// Data member.
|
2016-07-02 07:12:48 +08:00
|
|
|
uint64_t MemberOffsetInBits =
|
|
|
|
Member->getOffsetInBits() + MemberInfo.BaseOffset;
|
2016-06-30 11:00:20 +08:00
|
|
|
if (Member->isBitField()) {
|
|
|
|
uint64_t StartBitOffset = MemberOffsetInBits;
|
|
|
|
if (const auto *CI =
|
|
|
|
dyn_cast_or_null<ConstantInt>(Member->getStorageOffsetInBits())) {
|
2016-07-02 07:12:48 +08:00
|
|
|
MemberOffsetInBits = CI->getZExtValue() + MemberInfo.BaseOffset;
|
2016-06-30 11:00:20 +08:00
|
|
|
}
|
|
|
|
StartBitOffset -= MemberOffsetInBits;
|
2016-11-09 06:24:53 +08:00
|
|
|
BitFieldRecord BFR(MemberBaseType, Member->getSizeInBits(),
|
|
|
|
StartBitOffset);
|
|
|
|
MemberBaseType = TypeTable.writeKnownType(BFR);
|
2016-06-30 11:00:20 +08:00
|
|
|
}
|
|
|
|
uint64_t MemberOffsetInBytes = MemberOffsetInBits / 8;
|
2016-11-09 06:24:53 +08:00
|
|
|
DataMemberRecord DMR(Access, MemberBaseType, MemberOffsetInBytes,
|
|
|
|
MemberName);
|
|
|
|
FLBR.writeMemberType(DMR);
|
2016-06-18 18:25:07 +08:00
|
|
|
MemberCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create methods
|
|
|
|
for (auto &MethodItr : Info.Methods) {
|
|
|
|
StringRef Name = MethodItr.first->getString();
|
|
|
|
|
|
|
|
std::vector<OneMethodRecord> Methods;
|
2016-06-23 02:31:14 +08:00
|
|
|
for (const DISubprogram *SP : MethodItr.second) {
|
|
|
|
TypeIndex MethodType = getMemberFunctionType(SP, Ty);
|
|
|
|
bool Introduced = SP->getFlags() & DINode::FlagIntroducedVirtual;
|
2016-06-18 18:25:07 +08:00
|
|
|
|
|
|
|
unsigned VFTableOffset = -1;
|
|
|
|
if (Introduced)
|
|
|
|
VFTableOffset = SP->getVirtualIndex() * getPointerSizeInBytes();
|
|
|
|
|
2016-11-03 01:05:19 +08:00
|
|
|
Methods.push_back(OneMethodRecord(
|
|
|
|
MethodType, translateAccessFlags(Ty->getTag(), SP->getFlags()),
|
|
|
|
translateMethodKindFlags(SP, Introduced),
|
|
|
|
translateMethodOptionFlags(SP), VFTableOffset, Name));
|
2016-06-18 18:25:07 +08:00
|
|
|
MemberCount++;
|
|
|
|
}
|
2017-06-07 06:22:41 +08:00
|
|
|
assert(!Methods.empty() && "Empty methods map entry");
|
2016-06-18 18:25:07 +08:00
|
|
|
if (Methods.size() == 1)
|
2016-11-09 06:24:53 +08:00
|
|
|
FLBR.writeMemberType(Methods[0]);
|
2016-06-18 18:25:07 +08:00
|
|
|
else {
|
2016-11-09 06:24:53 +08:00
|
|
|
MethodOverloadListRecord MOLR(Methods);
|
|
|
|
TypeIndex MethodList = TypeTable.writeKnownType(MOLR);
|
|
|
|
OverloadedMethodRecord OMR(Methods.size(), MethodList, Name);
|
|
|
|
FLBR.writeMemberType(OMR);
|
2016-06-18 18:25:07 +08:00
|
|
|
}
|
2016-06-03 23:58:20 +08:00
|
|
|
}
|
2016-07-07 03:49:51 +08:00
|
|
|
|
|
|
|
// Create nested classes.
|
2017-08-09 04:30:14 +08:00
|
|
|
for (const DIType *Nested : Info.NestedTypes) {
|
2016-07-07 03:49:51 +08:00
|
|
|
NestedTypeRecord R(getTypeIndex(DITypeRef(Nested)), Nested->getName());
|
2016-11-09 06:24:53 +08:00
|
|
|
FLBR.writeMemberType(R);
|
2016-07-07 03:49:51 +08:00
|
|
|
MemberCount++;
|
|
|
|
}
|
|
|
|
|
2017-05-26 05:15:37 +08:00
|
|
|
TypeIndex FieldTI = FLBR.end(true);
|
2016-08-31 23:59:30 +08:00
|
|
|
return std::make_tuple(FieldTI, Info.VShapeTI, MemberCount,
|
2017-08-09 04:30:14 +08:00
|
|
|
!Info.NestedTypes.empty());
|
2016-06-03 23:58:20 +08:00
|
|
|
}
|
|
|
|
|
2016-06-25 00:24:24 +08:00
|
|
|
TypeIndex CodeViewDebug::getVBPTypeIndex() {
|
|
|
|
if (!VBPType.getIndex()) {
|
|
|
|
// Make a 'const int *' type.
|
|
|
|
ModifierRecord MR(TypeIndex::Int32(), ModifierOptions::Const);
|
[CodeView] Decouple record deserialization from visitor dispatch.
Until now, our use case for the visitor has been to take a stream of bytes
representing a type stream, deserialize the records in sequence, and do
something with them, where "something" is determined by how the user
implements a particular set of callbacks on an abstract class.
For actually writing PDBs, however, we want to do the reverse. We have
some kind of description of the list of records in their in-memory format,
and we want to process each one. Perhaps by serializing them to a byte
stream, or perhaps by converting them from one description format (Yaml)
to another (in-memory representation).
This was difficult in the current model because deserialization and
invoking the callbacks were tightly coupled.
With this patch we change this so that TypeDeserializer is itself an
implementation of the particular set of callbacks. This decouples
deserialization from the iteration over a list of records and invocation
of the callbacks. TypeDeserializer is initialized with another
implementation of the callback interface, so that upon deserialization it
can pass the deserialized record through to the next set of callbacks. In
a sense this is like an implementation of the Decorator design pattern,
where the Deserializer is a decorator.
This will be useful for writing Pdbs from yaml, where we have a
description of the type records in Yaml format. In this case, the visitor
implementation would have each visitation callback method implemented in
such a way as to extract the proper set of fields from the Yaml, and it
could maintain state that builds up a list of these records. Finally at
the end we can pass this information through to another set of callbacks
which serializes them into a byte stream.
Reviewed By: majnemer, ruiu, rnk
Differential Revision: https://reviews.llvm.org/D23177
llvm-svn: 277871
2016-08-06 05:45:34 +08:00
|
|
|
TypeIndex ModifiedTI = TypeTable.writeKnownType(MR);
|
2016-06-25 00:24:24 +08:00
|
|
|
|
|
|
|
PointerKind PK = getPointerSizeInBytes() == 8 ? PointerKind::Near64
|
|
|
|
: PointerKind::Near32;
|
|
|
|
PointerMode PM = PointerMode::Pointer;
|
|
|
|
PointerOptions PO = PointerOptions::None;
|
|
|
|
PointerRecord PR(ModifiedTI, PK, PM, PO, getPointerSizeInBytes());
|
|
|
|
|
[CodeView] Decouple record deserialization from visitor dispatch.
Until now, our use case for the visitor has been to take a stream of bytes
representing a type stream, deserialize the records in sequence, and do
something with them, where "something" is determined by how the user
implements a particular set of callbacks on an abstract class.
For actually writing PDBs, however, we want to do the reverse. We have
some kind of description of the list of records in their in-memory format,
and we want to process each one. Perhaps by serializing them to a byte
stream, or perhaps by converting them from one description format (Yaml)
to another (in-memory representation).
This was difficult in the current model because deserialization and
invoking the callbacks were tightly coupled.
With this patch we change this so that TypeDeserializer is itself an
implementation of the particular set of callbacks. This decouples
deserialization from the iteration over a list of records and invocation
of the callbacks. TypeDeserializer is initialized with another
implementation of the callback interface, so that upon deserialization it
can pass the deserialized record through to the next set of callbacks. In
a sense this is like an implementation of the Decorator design pattern,
where the Deserializer is a decorator.
This will be useful for writing Pdbs from yaml, where we have a
description of the type records in Yaml format. In this case, the visitor
implementation would have each visitation callback method implemented in
such a way as to extract the proper set of fields from the Yaml, and it
could maintain state that builds up a list of these records. Finally at
the end we can pass this information through to another set of callbacks
which serializes them into a byte stream.
Reviewed By: majnemer, ruiu, rnk
Differential Revision: https://reviews.llvm.org/D23177
llvm-svn: 277871
2016-08-06 05:45:34 +08:00
|
|
|
VBPType = TypeTable.writeKnownType(PR);
|
2016-06-25 00:24:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return VBPType;
|
|
|
|
}
|
|
|
|
|
2016-06-18 18:25:07 +08:00
|
|
|
TypeIndex CodeViewDebug::getTypeIndex(DITypeRef TypeRef, DITypeRef ClassTyRef) {
|
2016-06-02 01:05:51 +08:00
|
|
|
const DIType *Ty = TypeRef.resolve();
|
2016-06-18 18:25:07 +08:00
|
|
|
const DIType *ClassTy = ClassTyRef.resolve();
|
2016-06-02 01:05:51 +08:00
|
|
|
|
|
|
|
// The null DIType is the void type. Don't try to hash it.
|
|
|
|
if (!Ty)
|
|
|
|
return TypeIndex::Void();
|
|
|
|
|
2016-06-03 23:58:20 +08:00
|
|
|
// Check if we've already translated this type. Don't try to do a
|
|
|
|
// get-or-create style insertion that caches the hash lookup across the
|
|
|
|
// lowerType call. It will update the TypeIndices map.
|
2016-06-18 18:25:07 +08:00
|
|
|
auto I = TypeIndices.find({Ty, ClassTy});
|
2016-06-02 01:05:51 +08:00
|
|
|
if (I != TypeIndices.end())
|
|
|
|
return I->second;
|
|
|
|
|
2016-07-01 10:41:21 +08:00
|
|
|
TypeLoweringScope S(*this);
|
|
|
|
TypeIndex TI = lowerType(Ty, ClassTy);
|
|
|
|
return recordTypeIndexForDINode(Ty, TI, ClassTy);
|
2016-06-03 23:58:20 +08:00
|
|
|
}
|
|
|
|
|
2017-08-30 04:59:25 +08:00
|
|
|
TypeIndex CodeViewDebug::getTypeIndexForReferenceTo(DITypeRef TypeRef) {
|
|
|
|
DIType *Ty = TypeRef.resolve();
|
|
|
|
PointerRecord PR(getTypeIndex(Ty),
|
|
|
|
getPointerSizeInBytes() == 8 ? PointerKind::Near64
|
|
|
|
: PointerKind::Near32,
|
|
|
|
PointerMode::LValueReference, PointerOptions::None,
|
|
|
|
Ty->getSizeInBits() / 8);
|
|
|
|
return TypeTable.writeKnownType(PR);
|
|
|
|
}
|
|
|
|
|
2016-06-03 23:58:20 +08:00
|
|
|
TypeIndex CodeViewDebug::getCompleteTypeIndex(DITypeRef TypeRef) {
|
|
|
|
const DIType *Ty = TypeRef.resolve();
|
|
|
|
|
|
|
|
// The null DIType is the void type. Don't try to hash it.
|
|
|
|
if (!Ty)
|
|
|
|
return TypeIndex::Void();
|
|
|
|
|
|
|
|
// If this is a non-record type, the complete type index is the same as the
|
|
|
|
// normal type index. Just call getTypeIndex.
|
|
|
|
switch (Ty->getTag()) {
|
|
|
|
case dwarf::DW_TAG_class_type:
|
|
|
|
case dwarf::DW_TAG_structure_type:
|
|
|
|
case dwarf::DW_TAG_union_type:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return getTypeIndex(Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we've already translated the complete record type. Lowering a
|
|
|
|
// complete type should never trigger lowering another complete type, so we
|
|
|
|
// can reuse the hash table lookup result.
|
|
|
|
const auto *CTy = cast<DICompositeType>(Ty);
|
|
|
|
auto InsertResult = CompleteTypeIndices.insert({CTy, TypeIndex()});
|
|
|
|
if (!InsertResult.second)
|
|
|
|
return InsertResult.first->second;
|
|
|
|
|
2016-06-23 01:15:28 +08:00
|
|
|
TypeLoweringScope S(*this);
|
|
|
|
|
2016-06-03 23:58:20 +08:00
|
|
|
// Make sure the forward declaration is emitted first. It's unclear if this
|
|
|
|
// is necessary, but MSVC does it, and we should follow suit until we can show
|
|
|
|
// otherwise.
|
|
|
|
TypeIndex FwdDeclTI = getTypeIndex(CTy);
|
|
|
|
|
|
|
|
// Just use the forward decl if we don't have complete type info. This might
|
|
|
|
// happen if the frontend is using modules and expects the complete definition
|
|
|
|
// to be emitted elsewhere.
|
|
|
|
if (CTy->isForwardDecl())
|
|
|
|
return FwdDeclTI;
|
|
|
|
|
|
|
|
TypeIndex TI;
|
|
|
|
switch (CTy->getTag()) {
|
|
|
|
case dwarf::DW_TAG_class_type:
|
|
|
|
case dwarf::DW_TAG_structure_type:
|
|
|
|
TI = lowerCompleteTypeClass(CTy);
|
|
|
|
break;
|
|
|
|
case dwarf::DW_TAG_union_type:
|
|
|
|
TI = lowerCompleteTypeUnion(CTy);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("not a record");
|
|
|
|
}
|
|
|
|
|
|
|
|
InsertResult.first->second = TI;
|
2016-06-02 01:05:51 +08:00
|
|
|
return TI;
|
|
|
|
}
|
|
|
|
|
2016-06-23 01:15:28 +08:00
|
|
|
/// Emit all the deferred complete record types. Try to do this in FIFO order,
|
2016-07-12 20:06:34 +08:00
|
|
|
/// and do this until fixpoint, as each complete record type typically
|
|
|
|
/// references
|
2016-06-23 01:15:28 +08:00
|
|
|
/// many other record types.
|
|
|
|
void CodeViewDebug::emitDeferredCompleteTypes() {
|
|
|
|
SmallVector<const DICompositeType *, 4> TypesToEmit;
|
|
|
|
while (!DeferredCompleteTypes.empty()) {
|
|
|
|
std::swap(DeferredCompleteTypes, TypesToEmit);
|
|
|
|
for (const DICompositeType *RecordTy : TypesToEmit)
|
|
|
|
getCompleteTypeIndex(RecordTy);
|
|
|
|
TypesToEmit.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-25 01:55:40 +08:00
|
|
|
void CodeViewDebug::emitLocalVariableList(ArrayRef<LocalVariable> Locals) {
|
|
|
|
// Get the sorted list of parameters and emit them first.
|
|
|
|
SmallVector<const LocalVariable *, 6> Params;
|
|
|
|
for (const LocalVariable &L : Locals)
|
|
|
|
if (L.DIVar->isParameter())
|
|
|
|
Params.push_back(&L);
|
|
|
|
std::sort(Params.begin(), Params.end(),
|
|
|
|
[](const LocalVariable *L, const LocalVariable *R) {
|
|
|
|
return L->DIVar->getArg() < R->DIVar->getArg();
|
|
|
|
});
|
|
|
|
for (const LocalVariable *L : Params)
|
|
|
|
emitLocalVariable(*L);
|
|
|
|
|
|
|
|
// Next emit all non-parameters in the order that we found them.
|
|
|
|
for (const LocalVariable &L : Locals)
|
|
|
|
if (!L.DIVar->isParameter())
|
|
|
|
emitLocalVariable(L);
|
|
|
|
}
|
|
|
|
|
2016-02-11 04:55:49 +08:00
|
|
|
void CodeViewDebug::emitLocalVariable(const LocalVariable &Var) {
|
|
|
|
// LocalSym record, see SymbolRecord.h for more info.
|
|
|
|
MCSymbol *LocalBegin = MMI->getContext().createTempSymbol(),
|
|
|
|
*LocalEnd = MMI->getContext().createTempSymbol();
|
|
|
|
OS.AddComment("Record length");
|
|
|
|
OS.emitAbsoluteSymbolDiff(LocalEnd, LocalBegin, 2);
|
|
|
|
OS.EmitLabel(LocalBegin);
|
|
|
|
|
|
|
|
OS.AddComment("Record kind: S_LOCAL");
|
2016-05-18 07:50:21 +08:00
|
|
|
OS.EmitIntValue(unsigned(SymbolKind::S_LOCAL), 2);
|
2016-02-11 04:55:49 +08:00
|
|
|
|
2016-05-18 07:50:21 +08:00
|
|
|
LocalSymFlags Flags = LocalSymFlags::None;
|
2016-02-11 04:55:49 +08:00
|
|
|
if (Var.DIVar->isParameter())
|
2016-05-18 07:50:21 +08:00
|
|
|
Flags |= LocalSymFlags::IsParameter;
|
2016-02-13 05:48:30 +08:00
|
|
|
if (Var.DefRanges.empty())
|
2016-05-18 07:50:21 +08:00
|
|
|
Flags |= LocalSymFlags::IsOptimizedOut;
|
2016-02-11 04:55:49 +08:00
|
|
|
|
|
|
|
OS.AddComment("TypeIndex");
|
2017-08-31 23:56:49 +08:00
|
|
|
TypeIndex TI = Var.UseReferenceType
|
|
|
|
? getTypeIndexForReferenceTo(Var.DIVar->getType())
|
|
|
|
: getCompleteTypeIndex(Var.DIVar->getType());
|
2016-06-02 01:05:51 +08:00
|
|
|
OS.EmitIntValue(TI.getIndex(), 4);
|
2016-02-11 04:55:49 +08:00
|
|
|
OS.AddComment("Flags");
|
2016-05-18 07:50:21 +08:00
|
|
|
OS.EmitIntValue(static_cast<uint16_t>(Flags), 2);
|
2016-03-13 18:53:30 +08:00
|
|
|
// Truncate the name so we won't overflow the record length field.
|
2016-03-14 13:15:09 +08:00
|
|
|
emitNullTerminatedSymbolName(OS, Var.DIVar->getName());
|
2016-02-11 04:55:49 +08:00
|
|
|
OS.EmitLabel(LocalEnd);
|
|
|
|
|
2016-02-13 05:48:30 +08:00
|
|
|
// Calculate the on disk prefix of the appropriate def range record. The
|
|
|
|
// records and on disk formats are described in SymbolRecords.h. BytePrefix
|
|
|
|
// should be big enough to hold all forms without memory allocation.
|
|
|
|
SmallString<20> BytePrefix;
|
|
|
|
for (const LocalVarDefRange &DefRange : Var.DefRanges) {
|
|
|
|
BytePrefix.clear();
|
|
|
|
if (DefRange.InMemory) {
|
2016-10-06 05:21:33 +08:00
|
|
|
uint16_t RegRelFlags = 0;
|
|
|
|
if (DefRange.IsSubfield) {
|
|
|
|
RegRelFlags = DefRangeRegisterRelSym::IsSubfieldFlag |
|
|
|
|
(DefRange.StructOffset
|
|
|
|
<< DefRangeRegisterRelSym::OffsetInParentShift);
|
|
|
|
}
|
2016-12-17 06:48:14 +08:00
|
|
|
DefRangeRegisterRelSym Sym(S_DEFRANGE_REGISTER_REL);
|
|
|
|
Sym.Hdr.Register = DefRange.CVRegister;
|
|
|
|
Sym.Hdr.Flags = RegRelFlags;
|
|
|
|
Sym.Hdr.BasePointerOffset = DefRange.DataOffset;
|
2016-02-13 05:48:30 +08:00
|
|
|
ulittle16_t SymKind = ulittle16_t(S_DEFRANGE_REGISTER_REL);
|
|
|
|
BytePrefix +=
|
|
|
|
StringRef(reinterpret_cast<const char *>(&SymKind), sizeof(SymKind));
|
2016-05-24 02:49:06 +08:00
|
|
|
BytePrefix +=
|
2016-12-17 06:48:14 +08:00
|
|
|
StringRef(reinterpret_cast<const char *>(&Sym.Hdr), sizeof(Sym.Hdr));
|
2016-02-13 05:48:30 +08:00
|
|
|
} else {
|
|
|
|
assert(DefRange.DataOffset == 0 && "unexpected offset into register");
|
2016-10-06 05:21:33 +08:00
|
|
|
if (DefRange.IsSubfield) {
|
|
|
|
// Unclear what matters here.
|
2016-12-17 06:48:14 +08:00
|
|
|
DefRangeSubfieldRegisterSym Sym(S_DEFRANGE_SUBFIELD_REGISTER);
|
|
|
|
Sym.Hdr.Register = DefRange.CVRegister;
|
|
|
|
Sym.Hdr.MayHaveNoName = 0;
|
|
|
|
Sym.Hdr.OffsetInParent = DefRange.StructOffset;
|
|
|
|
|
2016-10-06 05:21:33 +08:00
|
|
|
ulittle16_t SymKind = ulittle16_t(S_DEFRANGE_SUBFIELD_REGISTER);
|
|
|
|
BytePrefix += StringRef(reinterpret_cast<const char *>(&SymKind),
|
|
|
|
sizeof(SymKind));
|
2016-12-17 06:48:14 +08:00
|
|
|
BytePrefix += StringRef(reinterpret_cast<const char *>(&Sym.Hdr),
|
|
|
|
sizeof(Sym.Hdr));
|
2016-10-06 05:21:33 +08:00
|
|
|
} else {
|
|
|
|
// Unclear what matters here.
|
2016-12-17 06:48:14 +08:00
|
|
|
DefRangeRegisterSym Sym(S_DEFRANGE_REGISTER);
|
|
|
|
Sym.Hdr.Register = DefRange.CVRegister;
|
|
|
|
Sym.Hdr.MayHaveNoName = 0;
|
2016-10-06 05:21:33 +08:00
|
|
|
ulittle16_t SymKind = ulittle16_t(S_DEFRANGE_REGISTER);
|
|
|
|
BytePrefix += StringRef(reinterpret_cast<const char *>(&SymKind),
|
|
|
|
sizeof(SymKind));
|
2016-12-17 06:48:14 +08:00
|
|
|
BytePrefix += StringRef(reinterpret_cast<const char *>(&Sym.Hdr),
|
|
|
|
sizeof(Sym.Hdr));
|
2016-10-06 05:21:33 +08:00
|
|
|
}
|
2016-02-13 05:48:30 +08:00
|
|
|
}
|
|
|
|
OS.EmitCVDefRangeDirective(DefRange.Ranges, BytePrefix);
|
|
|
|
}
|
2016-02-11 04:55:49 +08:00
|
|
|
}
|
|
|
|
|
2017-02-17 02:48:33 +08:00
|
|
|
void CodeViewDebug::endFunctionImpl(const MachineFunction *MF) {
|
2014-03-26 19:24:36 +08:00
|
|
|
const Function *GV = MF->getFunction();
|
2014-06-20 18:26:56 +08:00
|
|
|
assert(FnDebugInfo.count(GV));
|
2014-03-26 19:24:36 +08:00
|
|
|
assert(CurFn == &FnDebugInfo[GV]);
|
|
|
|
|
2016-03-11 10:14:16 +08:00
|
|
|
collectVariableInfo(GV->getSubprogram());
|
2016-02-13 05:48:30 +08:00
|
|
|
|
2016-01-29 08:49:42 +08:00
|
|
|
// Don't emit anything if we don't have any line tables.
|
|
|
|
if (!CurFn->HaveLineInfo) {
|
2014-03-26 19:24:36 +08:00
|
|
|
FnDebugInfo.erase(GV);
|
2016-02-11 04:55:49 +08:00
|
|
|
CurFn = nullptr;
|
|
|
|
return;
|
2014-03-26 17:50:36 +08:00
|
|
|
}
|
2016-02-11 04:55:49 +08:00
|
|
|
|
2017-09-06 04:14:58 +08:00
|
|
|
CurFn->Annotations = MF->getCodeViewAnnotations();
|
|
|
|
|
2016-02-11 04:55:49 +08:00
|
|
|
CurFn->End = Asm->getFunctionEnd();
|
|
|
|
|
2014-04-24 14:44:33 +08:00
|
|
|
CurFn = nullptr;
|
2014-01-30 09:39:17 +08:00
|
|
|
}
|
|
|
|
|
2016-01-15 03:25:04 +08:00
|
|
|
void CodeViewDebug::beginInstruction(const MachineInstr *MI) {
|
2016-02-11 04:55:49 +08:00
|
|
|
DebugHandlerBase::beginInstruction(MI);
|
|
|
|
|
2014-01-30 09:39:17 +08:00
|
|
|
// Ignore DBG_VALUE locations and function prologue.
|
2016-07-28 13:03:22 +08:00
|
|
|
if (!Asm || !CurFn || MI->isDebugValue() ||
|
|
|
|
MI->getFlag(MachineInstr::FrameSetup))
|
2014-01-30 09:39:17 +08:00
|
|
|
return;
|
2017-07-01 05:33:44 +08:00
|
|
|
|
|
|
|
// If the first instruction of a new MBB has no location, find the first
|
|
|
|
// instruction with a location and use that.
|
2014-01-30 09:39:17 +08:00
|
|
|
DebugLoc DL = MI->getDebugLoc();
|
2017-07-01 05:33:44 +08:00
|
|
|
if (!DL && MI->getParent() != PrevInstBB) {
|
|
|
|
for (const auto &NextMI : *MI->getParent()) {
|
2017-08-01 05:03:08 +08:00
|
|
|
if (NextMI.isDebugValue())
|
|
|
|
continue;
|
2017-07-01 05:33:44 +08:00
|
|
|
DL = NextMI.getDebugLoc();
|
|
|
|
if (DL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PrevInstBB = MI->getParent();
|
|
|
|
|
|
|
|
// If we still don't have a debug location, don't record a location.
|
|
|
|
if (!DL)
|
2014-01-30 09:39:17 +08:00
|
|
|
return;
|
2017-07-01 05:33:44 +08:00
|
|
|
|
2014-01-30 09:39:17 +08:00
|
|
|
maybeRecordLocation(DL, Asm->MF);
|
|
|
|
}
|
2016-06-07 08:02:03 +08:00
|
|
|
|
2017-05-31 00:36:15 +08:00
|
|
|
MCSymbol *CodeViewDebug::beginCVSubsection(DebugSubsectionKind Kind) {
|
2016-06-07 08:02:03 +08:00
|
|
|
MCSymbol *BeginLabel = MMI->getContext().createTempSymbol(),
|
|
|
|
*EndLabel = MMI->getContext().createTempSymbol();
|
|
|
|
OS.EmitIntValue(unsigned(Kind), 4);
|
|
|
|
OS.AddComment("Subsection size");
|
|
|
|
OS.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 4);
|
|
|
|
OS.EmitLabel(BeginLabel);
|
|
|
|
return EndLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CodeViewDebug::endCVSubsection(MCSymbol *EndLabel) {
|
|
|
|
OS.EmitLabel(EndLabel);
|
|
|
|
// Every subsection must be aligned to a 4-byte boundary.
|
|
|
|
OS.EmitValueToAlignment(4);
|
|
|
|
}
|
|
|
|
|
2016-06-16 02:00:01 +08:00
|
|
|
void CodeViewDebug::emitDebugInfoForUDTs(
|
[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
|
|
|
ArrayRef<std::pair<std::string, const DIType *>> UDTs) {
|
|
|
|
for (const auto &UDT : UDTs) {
|
|
|
|
const DIType *T = UDT.second;
|
|
|
|
assert(shouldEmitUdt(T));
|
|
|
|
|
2016-06-16 02:00:01 +08:00
|
|
|
MCSymbol *UDTRecordBegin = MMI->getContext().createTempSymbol(),
|
|
|
|
*UDTRecordEnd = MMI->getContext().createTempSymbol();
|
|
|
|
OS.AddComment("Record length");
|
|
|
|
OS.emitAbsoluteSymbolDiff(UDTRecordEnd, UDTRecordBegin, 2);
|
|
|
|
OS.EmitLabel(UDTRecordBegin);
|
|
|
|
|
|
|
|
OS.AddComment("Record kind: S_UDT");
|
|
|
|
OS.EmitIntValue(unsigned(SymbolKind::S_UDT), 2);
|
|
|
|
|
|
|
|
OS.AddComment("Type");
|
[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
|
|
|
OS.EmitIntValue(getCompleteTypeIndex(T).getIndex(), 4);
|
2016-06-16 02:00:01 +08:00
|
|
|
|
|
|
|
emitNullTerminatedSymbolName(OS, UDT.first);
|
|
|
|
OS.EmitLabel(UDTRecordEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 08:02:03 +08:00
|
|
|
void CodeViewDebug::emitDebugInfoForGlobals() {
|
2016-12-20 10:09:43 +08:00
|
|
|
DenseMap<const DIGlobalVariableExpression *, const GlobalVariable *>
|
|
|
|
GlobalMap;
|
2016-09-13 09:12:59 +08:00
|
|
|
for (const GlobalVariable &GV : MMI->getModule()->globals()) {
|
2016-12-20 10:09:43 +08:00
|
|
|
SmallVector<DIGlobalVariableExpression *, 1> GVEs;
|
|
|
|
GV.getDebugInfo(GVEs);
|
|
|
|
for (const auto *GVE : GVEs)
|
|
|
|
GlobalMap[GVE] = &GV;
|
2016-09-13 09:12:59 +08:00
|
|
|
}
|
|
|
|
|
2016-06-07 08:02:03 +08:00
|
|
|
NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
|
|
|
|
for (const MDNode *Node : CUs->operands()) {
|
|
|
|
const auto *CU = cast<DICompileUnit>(Node);
|
|
|
|
|
|
|
|
// First, emit all globals that are not in a comdat in a single symbol
|
|
|
|
// substream. MSVC doesn't like it if the substream is empty, so only open
|
|
|
|
// it if we have at least one global to emit.
|
|
|
|
switchToDebugSectionForSymbol(nullptr);
|
|
|
|
MCSymbol *EndLabel = nullptr;
|
2016-12-20 10:09:43 +08:00
|
|
|
for (const auto *GVE : CU->getGlobalVariables()) {
|
|
|
|
if (const auto *GV = GlobalMap.lookup(GVE))
|
2016-06-15 08:19:52 +08:00
|
|
|
if (!GV->hasComdat() && !GV->isDeclarationForLinker()) {
|
2016-06-07 08:02:03 +08:00
|
|
|
if (!EndLabel) {
|
|
|
|
OS.AddComment("Symbol subsection for globals");
|
2017-05-31 00:36:15 +08:00
|
|
|
EndLabel = beginCVSubsection(DebugSubsectionKind::Symbols);
|
2016-06-07 08:02:03 +08:00
|
|
|
}
|
2016-12-20 10:09:43 +08:00
|
|
|
// FIXME: emitDebugInfoForGlobal() doesn't handle DIExpressions.
|
|
|
|
emitDebugInfoForGlobal(GVE->getVariable(), GV, Asm->getSymbol(GV));
|
2016-06-07 08:02:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (EndLabel)
|
|
|
|
endCVSubsection(EndLabel);
|
|
|
|
|
|
|
|
// Second, emit each global that is in a comdat into its own .debug$S
|
|
|
|
// section along with its own symbol substream.
|
2016-12-20 10:09:43 +08:00
|
|
|
for (const auto *GVE : CU->getGlobalVariables()) {
|
|
|
|
if (const auto *GV = GlobalMap.lookup(GVE)) {
|
2016-06-07 08:02:03 +08:00
|
|
|
if (GV->hasComdat()) {
|
|
|
|
MCSymbol *GVSym = Asm->getSymbol(GV);
|
|
|
|
OS.AddComment("Symbol subsection for " +
|
2017-05-16 08:39:01 +08:00
|
|
|
Twine(GlobalValue::dropLLVMManglingEscape(GV->getName())));
|
2016-06-07 08:02:03 +08:00
|
|
|
switchToDebugSectionForSymbol(GVSym);
|
2017-05-31 00:36:15 +08:00
|
|
|
EndLabel = beginCVSubsection(DebugSubsectionKind::Symbols);
|
2016-12-20 10:09:43 +08:00
|
|
|
// FIXME: emitDebugInfoForGlobal() doesn't handle DIExpressions.
|
|
|
|
emitDebugInfoForGlobal(GVE->getVariable(), GV, GVSym);
|
2016-06-07 08:02:03 +08:00
|
|
|
endCVSubsection(EndLabel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-24 00:33:53 +08:00
|
|
|
void CodeViewDebug::emitDebugInfoForRetainedTypes() {
|
|
|
|
NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu");
|
|
|
|
for (const MDNode *Node : CUs->operands()) {
|
|
|
|
for (auto *Ty : cast<DICompileUnit>(Node)->getRetainedTypes()) {
|
|
|
|
if (DIType *RT = dyn_cast<DIType>(Ty)) {
|
|
|
|
getTypeIndex(RT);
|
|
|
|
// FIXME: Add to global/local DTU list.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 08:02:03 +08:00
|
|
|
void CodeViewDebug::emitDebugInfoForGlobal(const DIGlobalVariable *DIGV,
|
2016-09-13 09:12:59 +08:00
|
|
|
const GlobalVariable *GV,
|
2016-06-07 08:02:03 +08:00
|
|
|
MCSymbol *GVSym) {
|
|
|
|
// DataSym record, see SymbolRecord.h for more info.
|
|
|
|
// FIXME: Thread local data, etc
|
|
|
|
MCSymbol *DataBegin = MMI->getContext().createTempSymbol(),
|
|
|
|
*DataEnd = MMI->getContext().createTempSymbol();
|
|
|
|
OS.AddComment("Record length");
|
|
|
|
OS.emitAbsoluteSymbolDiff(DataEnd, DataBegin, 2);
|
|
|
|
OS.EmitLabel(DataBegin);
|
2016-07-07 05:07:47 +08:00
|
|
|
if (DIGV->isLocalToUnit()) {
|
2016-07-07 13:14:21 +08:00
|
|
|
if (GV->isThreadLocal()) {
|
|
|
|
OS.AddComment("Record kind: S_LTHREAD32");
|
|
|
|
OS.EmitIntValue(unsigned(SymbolKind::S_LTHREAD32), 2);
|
|
|
|
} else {
|
|
|
|
OS.AddComment("Record kind: S_LDATA32");
|
|
|
|
OS.EmitIntValue(unsigned(SymbolKind::S_LDATA32), 2);
|
|
|
|
}
|
2016-07-07 05:07:47 +08:00
|
|
|
} else {
|
2016-07-07 13:14:21 +08:00
|
|
|
if (GV->isThreadLocal()) {
|
|
|
|
OS.AddComment("Record kind: S_GTHREAD32");
|
|
|
|
OS.EmitIntValue(unsigned(SymbolKind::S_GTHREAD32), 2);
|
|
|
|
} else {
|
|
|
|
OS.AddComment("Record kind: S_GDATA32");
|
|
|
|
OS.EmitIntValue(unsigned(SymbolKind::S_GDATA32), 2);
|
|
|
|
}
|
2016-07-07 05:07:47 +08:00
|
|
|
}
|
2016-06-07 08:02:03 +08:00
|
|
|
OS.AddComment("Type");
|
|
|
|
OS.EmitIntValue(getCompleteTypeIndex(DIGV->getType()).getIndex(), 4);
|
|
|
|
OS.AddComment("DataOffset");
|
2017-01-02 11:00:19 +08:00
|
|
|
OS.EmitCOFFSecRel32(GVSym, /*Offset=*/0);
|
2016-06-07 08:02:03 +08:00
|
|
|
OS.AddComment("Segment");
|
|
|
|
OS.EmitCOFFSectionIndex(GVSym);
|
|
|
|
OS.AddComment("Name");
|
|
|
|
emitNullTerminatedSymbolName(OS, DIGV->getName());
|
|
|
|
OS.EmitLabel(DataEnd);
|
|
|
|
}
|