2009-05-15 17:23:25 +08:00
|
|
|
//===-- llvm/CodeGen/DwarfDebug.cpp - Dwarf Debug Framework ---------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains support for writing dwarf debug info into asm files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2010-03-09 08:39:24 +08:00
|
|
|
|
2009-05-15 17:23:25 +08:00
|
|
|
#include "DwarfDebug.h"
|
2014-10-04 23:49:50 +08:00
|
|
|
#include "ByteStreamer.h"
|
2013-08-09 07:45:55 +08:00
|
|
|
#include "DIEHash.h"
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
#include "DebugLocEntry.h"
|
2015-01-14 19:23:27 +08:00
|
|
|
#include "DwarfCompileUnit.h"
|
|
|
|
#include "DwarfExpression.h"
|
2013-12-03 03:33:15 +08:00
|
|
|
#include "DwarfUnit.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/ADT/Triple.h"
|
2015-01-06 05:29:41 +08:00
|
|
|
#include "llvm/CodeGen/DIE.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
2014-03-06 08:46:21 +08:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2014-03-04 19:17:44 +08:00
|
|
|
#include "llvm/IR/ValueHandle.h"
|
2010-03-09 09:58:53 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2015-08-07 23:14:08 +08:00
|
|
|
#include "llvm/MC/MCDwarf.h"
|
2009-08-01 02:48:30 +08:00
|
|
|
#include "llvm/MC/MCSection.h"
|
2009-08-19 13:49:37 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2010-03-09 09:58:53 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2010-04-28 03:46:33 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2009-10-13 14:47:08 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2013-08-21 14:13:34 +08:00
|
|
|
#include "llvm/Support/Dwarf.h"
|
2014-07-15 00:28:09 +08:00
|
|
|
#include "llvm/Support/Endian.h"
|
2009-10-13 14:47:08 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-01-23 06:09:00 +08:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2014-02-22 22:00:39 +08:00
|
|
|
#include "llvm/Support/LEB128.h"
|
2013-07-27 01:02:41 +08:00
|
|
|
#include "llvm/Support/MD5.h"
|
2010-11-30 02:16:10 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/Timer.h"
|
2015-03-24 03:32:43 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Target/TargetFrameLowering.h"
|
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2014-08-05 05:25:23 +08:00
|
|
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
2016-02-03 02:20:45 +08:00
|
|
|
|
2009-05-15 17:23:25 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:02:50 +08:00
|
|
|
#define DEBUG_TYPE "dwarfdebug"
|
|
|
|
|
2013-07-24 06:16:41 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
DisableDebugInfoPrinting("disable-debug-info-print", cl::Hidden,
|
|
|
|
cl::desc("Disable debug info printing"));
|
2010-04-28 03:46:33 +08:00
|
|
|
|
2013-09-13 08:35:05 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
GenerateGnuPubSections("generate-gnu-dwarf-pub-sections", cl::Hidden,
|
|
|
|
cl::desc("Generate GNU-style pubnames and pubtypes"),
|
|
|
|
cl::init(false));
|
|
|
|
|
2014-02-14 09:26:55 +08:00
|
|
|
static cl::opt<bool> GenerateARangeSection("generate-arange-section",
|
|
|
|
cl::Hidden,
|
|
|
|
cl::desc("Generate dwarf aranges"),
|
|
|
|
cl::init(false));
|
|
|
|
|
2012-08-24 06:36:40 +08:00
|
|
|
namespace {
|
2014-01-28 07:50:03 +08:00
|
|
|
enum DefaultOnOff { Default, Enable, Disable };
|
2012-08-24 06:36:40 +08:00
|
|
|
}
|
2011-11-07 17:24:32 +08:00
|
|
|
|
2016-12-13 04:49:11 +08:00
|
|
|
static cl::opt<DefaultOnOff> UnknownLocations(
|
|
|
|
"use-unknown-locations", cl::Hidden,
|
|
|
|
cl::desc("Make an absence of debug location information explicit."),
|
|
|
|
cl::values(clEnumVal(Default, "At top of block or after label"),
|
|
|
|
clEnumVal(Enable, "In all cases"), clEnumVal(Disable, "Never")),
|
|
|
|
cl::init(Default));
|
|
|
|
|
2013-07-24 06:16:41 +08:00
|
|
|
static cl::opt<DefaultOnOff>
|
|
|
|
DwarfAccelTables("dwarf-accel-tables", cl::Hidden,
|
|
|
|
cl::desc("Output prototype dwarf accelerator tables."),
|
|
|
|
cl::values(clEnumVal(Default, "Default for platform"),
|
|
|
|
clEnumVal(Enable, "Enabled"),
|
2016-10-09 03:41:06 +08:00
|
|
|
clEnumVal(Disable, "Disabled")),
|
2013-07-24 06:16:41 +08:00
|
|
|
cl::init(Default));
|
2012-08-24 06:36:40 +08:00
|
|
|
|
2013-07-24 06:16:41 +08:00
|
|
|
static cl::opt<DefaultOnOff>
|
|
|
|
SplitDwarf("split-dwarf", cl::Hidden,
|
2013-12-05 07:24:28 +08:00
|
|
|
cl::desc("Output DWARF5 split debug info."),
|
2013-07-24 06:16:41 +08:00
|
|
|
cl::values(clEnumVal(Default, "Default for platform"),
|
|
|
|
clEnumVal(Enable, "Enabled"),
|
2016-10-09 03:41:06 +08:00
|
|
|
clEnumVal(Disable, "Disabled")),
|
2013-07-24 06:16:41 +08:00
|
|
|
cl::init(Default));
|
2012-11-13 06:22:20 +08:00
|
|
|
|
2013-08-20 05:07:38 +08:00
|
|
|
static cl::opt<DefaultOnOff>
|
2013-08-27 07:24:35 +08:00
|
|
|
DwarfPubSections("generate-dwarf-pub-sections", cl::Hidden,
|
|
|
|
cl::desc("Generate DWARF pubnames and pubtypes sections"),
|
|
|
|
cl::values(clEnumVal(Default, "Default for platform"),
|
|
|
|
clEnumVal(Enable, "Enabled"),
|
2016-10-09 03:41:06 +08:00
|
|
|
clEnumVal(Disable, "Disabled")),
|
2013-08-27 07:24:35 +08:00
|
|
|
cl::init(Default));
|
2013-08-20 05:07:38 +08:00
|
|
|
|
2016-04-19 06:41:41 +08:00
|
|
|
enum LinkageNameOption {
|
|
|
|
DefaultLinkageNames,
|
|
|
|
AllLinkageNames,
|
|
|
|
AbstractLinkageNames
|
|
|
|
};
|
|
|
|
static cl::opt<LinkageNameOption>
|
|
|
|
DwarfLinkageNames("dwarf-linkage-names", cl::Hidden,
|
|
|
|
cl::desc("Which DWARF linkage-name attributes to emit."),
|
|
|
|
cl::values(clEnumValN(DefaultLinkageNames, "Default",
|
|
|
|
"Default for platform"),
|
|
|
|
clEnumValN(AllLinkageNames, "All", "All"),
|
|
|
|
clEnumValN(AbstractLinkageNames, "Abstract",
|
2016-10-09 03:41:06 +08:00
|
|
|
"Abstract subprograms")),
|
2016-04-19 06:41:41 +08:00
|
|
|
cl::init(DefaultLinkageNames));
|
2015-08-12 05:36:45 +08:00
|
|
|
|
2016-11-19 03:43:18 +08:00
|
|
|
static const char *const DWARFGroupName = "dwarf";
|
|
|
|
static const char *const DWARFGroupDescription = "DWARF Emission";
|
|
|
|
static const char *const DbgTimerName = "writer";
|
|
|
|
static const char *const DbgTimerDescription = "DWARF Debug Writer";
|
2010-04-07 17:28:04 +08:00
|
|
|
|
2015-03-03 06:02:33 +08:00
|
|
|
void DebugLocDwarfExpression::EmitOp(uint8_t Op, const char *Comment) {
|
|
|
|
BS.EmitInt8(
|
|
|
|
Op, Comment ? Twine(Comment) + " " + dwarf::OperationEncodingString(Op)
|
|
|
|
: dwarf::OperationEncodingString(Op));
|
|
|
|
}
|
|
|
|
|
2015-03-11 03:23:37 +08:00
|
|
|
void DebugLocDwarfExpression::EmitSigned(int64_t Value) {
|
2015-03-03 06:02:33 +08:00
|
|
|
BS.EmitSLEB128(Value, Twine(Value));
|
|
|
|
}
|
|
|
|
|
2015-03-11 03:23:37 +08:00
|
|
|
void DebugLocDwarfExpression::EmitUnsigned(uint64_t Value) {
|
2015-03-03 06:02:33 +08:00
|
|
|
BS.EmitULEB128(Value, Twine(Value));
|
|
|
|
}
|
|
|
|
|
2016-05-21 03:35:17 +08:00
|
|
|
bool DebugLocDwarfExpression::isFrameRegister(const TargetRegisterInfo &TRI,
|
|
|
|
unsigned MachineReg) {
|
2015-03-03 06:02:33 +08:00
|
|
|
// This information is not available while emitting .debug_loc entries.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-05-15 17:23:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-03-18 10:34:58 +08:00
|
|
|
bool DbgVariable::isBlockByrefVariable() const {
|
2015-04-07 07:27:40 +08:00
|
|
|
assert(Var && "Invalid complex DbgVariable!");
|
2016-04-24 05:08:00 +08:00
|
|
|
return Var->getType().resolve()->isBlockByrefStruct();
|
2014-03-18 10:34:58 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
const DIType *DbgVariable::getType() const {
|
2016-04-24 05:08:00 +08:00
|
|
|
DIType *Ty = Var->getType().resolve();
|
2011-04-13 06:53:02 +08:00
|
|
|
// FIXME: isBlockByrefVariable should be reformulated in terms of complex
|
|
|
|
// addresses instead.
|
2015-04-14 09:59:58 +08:00
|
|
|
if (Ty->isBlockByrefStruct()) {
|
2011-04-13 06:53:02 +08:00
|
|
|
/* Byref variables, in Blocks, are declared by the programmer as
|
|
|
|
"SomeType VarName;", but the compiler creates a
|
|
|
|
__Block_byref_x_VarName struct, and gives the variable VarName
|
|
|
|
either the struct, or a pointer to the struct, as its type. This
|
|
|
|
is necessary for various behind-the-scenes things the compiler
|
|
|
|
needs to do with by-reference variables in blocks.
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2011-04-13 06:53:02 +08:00
|
|
|
However, as far as the original *programmer* is concerned, the
|
|
|
|
variable should still have type 'SomeType', as originally declared.
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2011-04-13 06:53:02 +08:00
|
|
|
The following function dives into the __Block_byref_x_VarName
|
|
|
|
struct to find the original type of the variable. This will be
|
|
|
|
passed back to the code generating the type for the Debug
|
|
|
|
Information Entry for the variable 'VarName'. 'VarName' will then
|
|
|
|
have the original type 'SomeType' in its debug information.
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2011-04-13 06:53:02 +08:00
|
|
|
The original type 'SomeType' will be the type of the field named
|
|
|
|
'VarName' inside the __Block_byref_x_VarName struct.
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2011-04-13 06:53:02 +08:00
|
|
|
NOTE: In order for this to not completely fail on the debugger
|
|
|
|
side, the Debug Information Entry for the variable VarName needs to
|
|
|
|
have a DW_AT_location that tells the debugger how to unwind through
|
|
|
|
the pointers and __Block_byref_x_VarName struct to find the actual
|
|
|
|
value of the variable. The function addBlockByrefType does this. */
|
2015-04-30 00:38:44 +08:00
|
|
|
DIType *subType = Ty;
|
2015-04-16 09:01:28 +08:00
|
|
|
uint16_t tag = Ty->getTag();
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2013-09-05 03:53:21 +08:00
|
|
|
if (tag == dwarf::DW_TAG_pointer_type)
|
2015-04-30 00:38:44 +08:00
|
|
|
subType = resolve(cast<DIDerivedType>(Ty)->getBaseType());
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2015-07-25 02:17:17 +08:00
|
|
|
auto Elements = cast<DICompositeType>(subType)->getElements();
|
2015-04-07 12:14:33 +08:00
|
|
|
for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
|
2015-07-25 02:58:32 +08:00
|
|
|
auto *DT = cast<DIDerivedType>(Elements[i]);
|
2015-04-16 09:01:28 +08:00
|
|
|
if (getName() == DT->getName())
|
2015-04-21 02:20:03 +08:00
|
|
|
return resolve(DT->getBaseType());
|
2010-08-10 05:01:39 +08:00
|
|
|
}
|
|
|
|
}
|
2011-04-13 06:53:02 +08:00
|
|
|
return Ty;
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2017-02-18 03:42:32 +08:00
|
|
|
ArrayRef<DbgVariable::FrameIndexExpr> DbgVariable::getFrameIndexExprs() const {
|
|
|
|
std::sort(FrameIndexExprs.begin(), FrameIndexExprs.end(),
|
|
|
|
[](const FrameIndexExpr &A, const FrameIndexExpr &B) -> bool {
|
|
|
|
return A.Expr->getFragmentInfo()->OffsetInBits <
|
|
|
|
B.Expr->getFragmentInfo()->OffsetInBits;
|
|
|
|
});
|
|
|
|
return FrameIndexExprs;
|
|
|
|
}
|
|
|
|
|
2016-08-25 09:05:08 +08:00
|
|
|
static const DwarfAccelTable::Atom TypeAtoms[] = {
|
2014-04-24 09:23:49 +08:00
|
|
|
DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4),
|
|
|
|
DwarfAccelTable::Atom(dwarf::DW_ATOM_die_tag, dwarf::DW_FORM_data2),
|
|
|
|
DwarfAccelTable::Atom(dwarf::DW_ATOM_type_flags, dwarf::DW_FORM_data1)};
|
|
|
|
|
2010-04-05 13:11:15 +08:00
|
|
|
DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
|
2016-02-11 04:55:49 +08:00
|
|
|
: DebugHandlerBase(A), DebugLocs(A->OutStreamer->isVerboseAsm()),
|
|
|
|
InfoHolder(A, "info_string", DIEValueAllocator),
|
2015-03-04 10:30:17 +08:00
|
|
|
SkeletonHolder(A, "skel_string", DIEValueAllocator),
|
2016-10-01 09:50:29 +08:00
|
|
|
IsDarwin(A->TM.getTargetTriple().isOSDarwin()),
|
2014-04-24 07:37:35 +08:00
|
|
|
AccelNames(DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset,
|
2014-04-24 08:53:32 +08:00
|
|
|
dwarf::DW_FORM_data4)),
|
|
|
|
AccelObjC(DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset,
|
2014-04-24 09:02:42 +08:00
|
|
|
dwarf::DW_FORM_data4)),
|
|
|
|
AccelNamespace(DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset,
|
2014-04-24 09:23:49 +08:00
|
|
|
dwarf::DW_FORM_data4)),
|
2015-07-16 06:04:54 +08:00
|
|
|
AccelTypes(TypeAtoms), DebuggerTuning(DebuggerKind::Default) {
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2014-04-24 14:44:33 +08:00
|
|
|
CurFn = nullptr;
|
2016-10-01 09:50:29 +08:00
|
|
|
const Triple &TT = Asm->TM.getTargetTriple();
|
2015-07-16 06:04:54 +08:00
|
|
|
|
2015-12-17 03:58:30 +08:00
|
|
|
// Make sure we know our "debugger tuning." The target option takes
|
2015-07-16 06:04:54 +08:00
|
|
|
// precedence; fall back to triple-based defaults.
|
2015-12-17 03:58:30 +08:00
|
|
|
if (Asm->TM.Options.DebuggerTuning != DebuggerKind::Default)
|
|
|
|
DebuggerTuning = Asm->TM.Options.DebuggerTuning;
|
Turn off lldb debug tuning by default for FreeBSD
Summary:
In rL242338, debugger tuning was introduced, and the tuning for FreeBSD
was set to lldb by default. However, for the foreseeable future we
still need to default to gdb tuning, since lldb is not ready for all of
FreeBSD's architectures, and some system tools (like objcopy, etc) have
not yet been adapted to cope with the lldb tuned format, which has
.apple sections.
Therefore, let FreeBSD use gdb by default for now.
Reviewers: emaste, probinson
Subscribers: llvm-commits, emaste
Differential Revision: http://reviews.llvm.org/D15966
llvm-svn: 257103
2016-01-08 06:09:12 +08:00
|
|
|
else if (IsDarwin)
|
2015-07-16 06:04:54 +08:00
|
|
|
DebuggerTuning = DebuggerKind::LLDB;
|
|
|
|
else if (TT.isPS4CPU())
|
|
|
|
DebuggerTuning = DebuggerKind::SCE;
|
|
|
|
else
|
|
|
|
DebuggerTuning = DebuggerKind::GDB;
|
2012-04-03 01:58:52 +08:00
|
|
|
|
2015-07-16 06:04:54 +08:00
|
|
|
// Turn on accelerator tables for LLDB by default.
|
2013-08-20 05:41:38 +08:00
|
|
|
if (DwarfAccelTables == Default)
|
2015-07-16 06:04:54 +08:00
|
|
|
HasDwarfAccelTables = tuneForLLDB();
|
2013-08-20 05:41:38 +08:00
|
|
|
else
|
2013-08-27 04:58:35 +08:00
|
|
|
HasDwarfAccelTables = DwarfAccelTables == Enable;
|
2012-08-24 06:36:36 +08:00
|
|
|
|
2016-05-25 05:19:28 +08:00
|
|
|
HasAppleExtensionAttributes = tuneForLLDB();
|
|
|
|
|
2015-07-16 06:04:54 +08:00
|
|
|
// Handle split DWARF. Off by default for now.
|
2012-12-11 03:51:21 +08:00
|
|
|
if (SplitDwarf == Default)
|
|
|
|
HasSplitDwarf = false;
|
2012-11-13 06:22:20 +08:00
|
|
|
else
|
2013-08-20 05:41:38 +08:00
|
|
|
HasSplitDwarf = SplitDwarf == Enable;
|
|
|
|
|
2015-07-16 06:04:54 +08:00
|
|
|
// Pubnames/pubtypes on by default for GDB.
|
2013-08-27 07:24:35 +08:00
|
|
|
if (DwarfPubSections == Default)
|
2015-07-16 06:04:54 +08:00
|
|
|
HasDwarfPubSections = tuneForGDB();
|
2013-08-20 05:41:38 +08:00
|
|
|
else
|
2013-08-27 07:24:35 +08:00
|
|
|
HasDwarfPubSections = DwarfPubSections == Enable;
|
2013-08-20 05:07:38 +08:00
|
|
|
|
2016-04-19 06:41:41 +08:00
|
|
|
// SCE defaults to linkage names only for abstract subprograms.
|
|
|
|
if (DwarfLinkageNames == DefaultLinkageNames)
|
|
|
|
UseAllLinkageNames = !tuneForSCE();
|
2015-08-12 05:36:45 +08:00
|
|
|
else
|
2016-04-19 06:41:41 +08:00
|
|
|
UseAllLinkageNames = DwarfLinkageNames == AllLinkageNames;
|
2015-08-12 05:36:45 +08:00
|
|
|
|
2014-06-19 14:22:08 +08:00
|
|
|
unsigned DwarfVersionNumber = Asm->TM.Options.MCOptions.DwarfVersion;
|
2016-11-24 07:30:37 +08:00
|
|
|
unsigned DwarfVersion = DwarfVersionNumber ? DwarfVersionNumber
|
2014-04-29 04:42:22 +08:00
|
|
|
: MMI->getModule()->getDwarfVersion();
|
2015-08-06 06:26:20 +08:00
|
|
|
// Use dwarf 4 by default if nothing is requested.
|
|
|
|
DwarfVersion = DwarfVersion ? DwarfVersion : dwarf::DWARF_VERSION;
|
2013-07-03 07:40:10 +08:00
|
|
|
|
2015-07-16 06:04:54 +08:00
|
|
|
// Work around a GDB bug. GDB doesn't support the standard opcode;
|
|
|
|
// SCE doesn't support GNU's; LLDB prefers the standard opcode, which
|
|
|
|
// is defined as of DWARF 3.
|
|
|
|
// See GDB bug 11616 - DW_OP_form_tls_address is unimplemented
|
|
|
|
// https://sourceware.org/bugzilla/show_bug.cgi?id=11616
|
|
|
|
UseGNUTLSOpcode = tuneForGDB() || DwarfVersion < 3;
|
2015-03-05 04:55:11 +08:00
|
|
|
|
2016-05-18 05:07:16 +08:00
|
|
|
// GDB does not fully support the DWARF 4 representation for bitfields.
|
|
|
|
UseDWARF2Bitfields = (DwarfVersion < 4) || tuneForGDB();
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->getContext().setDwarfVersion(DwarfVersion);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2014-05-01 04:34:31 +08:00
|
|
|
// Define out of line so we don't have to include DwarfUnit.h in DwarfDebug.h.
|
|
|
|
DwarfDebug::~DwarfDebug() { }
|
|
|
|
|
2011-11-11 03:25:34 +08:00
|
|
|
static bool isObjCClass(StringRef Name) {
|
|
|
|
return Name.startswith("+") || Name.startswith("-");
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool hasObjCCategory(StringRef Name) {
|
2013-11-19 17:04:36 +08:00
|
|
|
if (!isObjCClass(Name))
|
|
|
|
return false;
|
2011-11-11 03:25:34 +08:00
|
|
|
|
2013-08-24 20:15:54 +08:00
|
|
|
return Name.find(") ") != StringRef::npos;
|
2011-11-11 03:25:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void getObjCClassCategory(StringRef In, StringRef &Class,
|
|
|
|
StringRef &Category) {
|
|
|
|
if (!hasObjCCategory(In)) {
|
|
|
|
Class = In.slice(In.find('[') + 1, In.find(' '));
|
|
|
|
Category = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Class = In.slice(In.find('[') + 1, In.find('('));
|
|
|
|
Category = In.slice(In.find('[') + 1, In.find(' '));
|
|
|
|
}
|
|
|
|
|
|
|
|
static StringRef getObjCMethodName(StringRef In) {
|
|
|
|
return In.slice(In.find(' ') + 1, In.find(']'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the various names to the Dwarf accelerator table names.
|
2013-09-21 07:22:52 +08:00
|
|
|
// TODO: Determine whether or not we should add names for programs
|
|
|
|
// that do not have a DW_AT_name or DW_AT_linkage_name field - this
|
|
|
|
// is only slightly different than the lookup of non-standard ObjC names.
|
2015-04-30 00:38:44 +08:00
|
|
|
void DwarfDebug::addSubprogramNames(const DISubprogram *SP, DIE &Die) {
|
2015-04-14 11:40:37 +08:00
|
|
|
if (!SP->isDefinition())
|
2013-11-19 17:04:36 +08:00
|
|
|
return;
|
2015-04-14 11:40:37 +08:00
|
|
|
addAccelName(SP->getName(), Die);
|
2011-11-11 03:25:34 +08:00
|
|
|
|
|
|
|
// If the linkage name is different than the name, go ahead and output
|
|
|
|
// that as well into the name table.
|
2015-04-14 11:40:37 +08:00
|
|
|
if (SP->getLinkageName() != "" && SP->getName() != SP->getLinkageName())
|
|
|
|
addAccelName(SP->getLinkageName(), Die);
|
2011-11-11 03:25:34 +08:00
|
|
|
|
|
|
|
// If this is an Objective-C selector name add it to the ObjC accelerator
|
|
|
|
// too.
|
2015-04-14 11:40:37 +08:00
|
|
|
if (isObjCClass(SP->getName())) {
|
2011-11-11 03:25:34 +08:00
|
|
|
StringRef Class, Category;
|
2015-04-14 11:40:37 +08:00
|
|
|
getObjCClassCategory(SP->getName(), Class, Category);
|
2014-04-24 08:53:32 +08:00
|
|
|
addAccelObjC(Class, Die);
|
2011-11-11 03:25:34 +08:00
|
|
|
if (Category != "")
|
2014-04-24 08:53:32 +08:00
|
|
|
addAccelObjC(Category, Die);
|
2011-11-11 03:25:34 +08:00
|
|
|
// Also add the base method name to the name table.
|
2015-04-14 11:40:37 +08:00
|
|
|
addAccelName(getObjCMethodName(SP->getName()), Die);
|
2011-11-11 03:25:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-12 03:40:28 +08:00
|
|
|
/// Check whether we should create a DIE for the given Scope, return true
|
|
|
|
/// if we don't create a DIE (the corresponding DIE is null).
|
2013-09-11 02:40:41 +08:00
|
|
|
bool DwarfDebug::isLexicalScopeDIENull(LexicalScope *Scope) {
|
|
|
|
if (Scope->isAbstractScope())
|
|
|
|
return false;
|
|
|
|
|
2013-09-12 03:40:28 +08:00
|
|
|
// We don't create a DIE if there is no Range.
|
2013-09-11 02:40:41 +08:00
|
|
|
const SmallVectorImpl<InsnRange> &Ranges = Scope->getRanges();
|
|
|
|
if (Ranges.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Ranges.size() > 1)
|
|
|
|
return false;
|
|
|
|
|
2013-09-12 03:40:28 +08:00
|
|
|
// We don't create a DIE if we have a single Range and the end label
|
|
|
|
// is null.
|
2014-08-31 10:14:26 +08:00
|
|
|
return !getLabelAfterInsn(Ranges.front().second);
|
2013-09-11 02:40:41 +08:00
|
|
|
}
|
|
|
|
|
2016-08-06 19:13:10 +08:00
|
|
|
template <typename Func> static void forBothCUs(DwarfCompileUnit &CU, Func F) {
|
Provide gmlt-like inline scope information in the skeleton CU to facilitate symbolication without needing the .dwo files
Clang -gsplit-dwarf self-host -O0, binary increases by 0.0005%, -O2,
binary increases by 25%.
A large binary inside Google, split-dwarf, -O0, and other internal flags
(GDB index, etc) increases by 1.8%, optimized build is 35%.
The size impact may be somewhat greater in .o files (I haven't measured
that much - since the linked executable -O0 numbers seemed low enough)
due to relocations. These relocations could be removed if we taught the
llvm-symbolizer to handle indexed addressing in the .o file (GDB can't
cope with this just yet, but GDB won't be reading this info anyway).
Also debug_ranges could be shared between .o and .dwo, though ideally
debug_ranges would get a schema that could used index(+offset)
addressing, and move to the .dwo file, then we'd be back to sharing
addresses in the address pool again.
But for now, these sizes seem small enough to go ahead with this.
Verified that no other DW_TAGs are produced into the .o file other than
subprograms and inlined_subroutines.
llvm-svn: 221306
2014-11-05 06:12:25 +08:00
|
|
|
F(CU);
|
|
|
|
if (auto *SkelCU = CU.getSkeleton())
|
2016-08-25 02:29:49 +08:00
|
|
|
if (CU.getCUNode()->getSplitDebugInlining())
|
|
|
|
F(*SkelCU);
|
Provide gmlt-like inline scope information in the skeleton CU to facilitate symbolication without needing the .dwo files
Clang -gsplit-dwarf self-host -O0, binary increases by 0.0005%, -O2,
binary increases by 25%.
A large binary inside Google, split-dwarf, -O0, and other internal flags
(GDB index, etc) increases by 1.8%, optimized build is 35%.
The size impact may be somewhat greater in .o files (I haven't measured
that much - since the linked executable -O0 numbers seemed low enough)
due to relocations. These relocations could be removed if we taught the
llvm-symbolizer to handle indexed addressing in the .o file (GDB can't
cope with this just yet, but GDB won't be reading this info anyway).
Also debug_ranges could be shared between .o and .dwo, though ideally
debug_ranges would get a schema that could used index(+offset)
addressing, and move to the .dwo file, then we'd be back to sharing
addresses in the address pool again.
But for now, these sizes seem small enough to go ahead with this.
Verified that no other DW_TAGs are produced into the .o file other than
subprograms and inlined_subroutines.
llvm-svn: 221306
2014-11-05 06:12:25 +08:00
|
|
|
}
|
|
|
|
|
2014-10-10 04:36:27 +08:00
|
|
|
void DwarfDebug::constructAbstractSubprogramScopeDIE(LexicalScope *Scope) {
|
2014-04-29 04:27:02 +08:00
|
|
|
assert(Scope && Scope->getScopeNode());
|
2014-04-29 23:58:35 +08:00
|
|
|
assert(Scope->isAbstractScope());
|
|
|
|
assert(!Scope->getInlinedAt());
|
2014-04-29 04:27:02 +08:00
|
|
|
|
2016-12-15 03:38:39 +08:00
|
|
|
auto *SP = cast<DISubprogram>(Scope->getScopeNode());
|
2014-04-29 23:58:35 +08:00
|
|
|
|
2014-10-10 11:09:38 +08:00
|
|
|
ProcessedSPNodes.insert(SP);
|
|
|
|
|
2014-05-22 07:14:12 +08:00
|
|
|
// Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
|
|
|
|
// was inlined from another compile unit.
|
2016-12-15 03:38:39 +08:00
|
|
|
auto &CU = *CUMap.lookup(SP->getUnit());
|
2016-04-15 23:57:41 +08:00
|
|
|
forBothCUs(CU, [&](DwarfCompileUnit &CU) {
|
Provide gmlt-like inline scope information in the skeleton CU to facilitate symbolication without needing the .dwo files
Clang -gsplit-dwarf self-host -O0, binary increases by 0.0005%, -O2,
binary increases by 25%.
A large binary inside Google, split-dwarf, -O0, and other internal flags
(GDB index, etc) increases by 1.8%, optimized build is 35%.
The size impact may be somewhat greater in .o files (I haven't measured
that much - since the linked executable -O0 numbers seemed low enough)
due to relocations. These relocations could be removed if we taught the
llvm-symbolizer to handle indexed addressing in the .o file (GDB can't
cope with this just yet, but GDB won't be reading this info anyway).
Also debug_ranges could be shared between .o and .dwo, though ideally
debug_ranges would get a schema that could used index(+offset)
addressing, and move to the .dwo file, then we'd be back to sharing
addresses in the address pool again.
But for now, these sizes seem small enough to go ahead with this.
Verified that no other DW_TAGs are produced into the .o file other than
subprograms and inlined_subroutines.
llvm-svn: 221306
2014-11-05 06:12:25 +08:00
|
|
|
CU.constructAbstractSubprogramScopeDIE(Scope);
|
|
|
|
});
|
2014-04-29 23:58:35 +08:00
|
|
|
}
|
2014-04-29 04:27:02 +08:00
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfDebug::addGnuPubAttributes(DwarfUnit &U, DIE &D) const {
|
2013-12-05 05:31:26 +08:00
|
|
|
if (!GenerateGnuPubSections)
|
|
|
|
return;
|
|
|
|
|
2014-04-23 06:39:41 +08:00
|
|
|
U.addFlag(D, dwarf::DW_AT_GNU_pubnames);
|
2013-12-05 05:31:26 +08:00
|
|
|
}
|
|
|
|
|
2013-12-10 07:57:44 +08:00
|
|
|
// Create new DwarfCompileUnit for the given metadata node with tag
|
2012-12-21 05:58:40 +08:00
|
|
|
// DW_TAG_compile_unit.
|
2015-04-21 06:10:08 +08:00
|
|
|
DwarfCompileUnit &
|
2015-04-30 00:38:44 +08:00
|
|
|
DwarfDebug::constructDwarfCompileUnit(const DICompileUnit *DIUnit) {
|
2015-04-16 07:19:27 +08:00
|
|
|
StringRef FN = DIUnit->getFilename();
|
|
|
|
CompilationDir = DIUnit->getDirectory();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2014-04-23 06:39:41 +08:00
|
|
|
auto OwnedUnit = make_unique<DwarfCompileUnit>(
|
2014-04-29 05:14:27 +08:00
|
|
|
InfoHolder.getUnits().size(), DIUnit, Asm, this, &InfoHolder);
|
2014-04-23 06:39:41 +08:00
|
|
|
DwarfCompileUnit &NewCU = *OwnedUnit;
|
2014-04-29 05:04:29 +08:00
|
|
|
DIE &Die = NewCU.getUnitDie();
|
2014-04-23 06:39:41 +08:00
|
|
|
InfoHolder.addUnit(std::move(OwnedUnit));
|
2016-03-25 02:37:08 +08:00
|
|
|
if (useSplitDwarf()) {
|
2014-11-02 16:51:37 +08:00
|
|
|
NewCU.setSkeleton(constructSkeletonCU(NewCU));
|
2016-03-25 02:37:08 +08:00
|
|
|
NewCU.addString(Die, dwarf::DW_AT_GNU_dwo_name,
|
|
|
|
DIUnit->getSplitDebugFilename());
|
|
|
|
}
|
2014-04-23 06:39:41 +08:00
|
|
|
|
2014-03-21 01:05:45 +08:00
|
|
|
// LTO with assembly output shares a single line table amongst multiple CUs.
|
|
|
|
// To avoid the compilation directory being ambiguous, let the line table
|
|
|
|
// explicitly describe the directory of all files, never relying on the
|
|
|
|
// compilation directory.
|
2015-04-25 03:11:51 +08:00
|
|
|
if (!Asm->OutStreamer->hasRawTextSupport() || SingleCU)
|
|
|
|
Asm->OutStreamer->getContext().setMCLineTableCompilationDir(
|
2014-04-23 06:39:41 +08:00
|
|
|
NewCU.getUniqueID(), CompilationDir);
|
2013-12-07 03:38:46 +08:00
|
|
|
|
2015-04-16 07:19:27 +08:00
|
|
|
NewCU.addString(Die, dwarf::DW_AT_producer, DIUnit->getProducer());
|
2014-04-29 05:04:29 +08:00
|
|
|
NewCU.addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
|
2015-04-16 07:19:27 +08:00
|
|
|
DIUnit->getSourceLanguage());
|
2014-04-29 05:04:29 +08:00
|
|
|
NewCU.addString(Die, dwarf::DW_AT_name, FN);
|
2013-04-10 03:23:15 +08:00
|
|
|
|
|
|
|
if (!useSplitDwarf()) {
|
2015-03-11 00:58:10 +08:00
|
|
|
NewCU.initStmtList();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2013-09-28 06:50:48 +08:00
|
|
|
// If we're using split dwarf the compilation dir is going to be in the
|
|
|
|
// skeleton CU and so we don't need to duplicate it here.
|
|
|
|
if (!CompilationDir.empty())
|
2014-04-29 05:04:29 +08:00
|
|
|
NewCU.addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
|
2013-09-13 08:35:05 +08:00
|
|
|
|
2014-04-29 05:04:29 +08:00
|
|
|
addGnuPubAttributes(NewCU, Die);
|
2013-09-28 06:50:48 +08:00
|
|
|
}
|
2013-09-13 08:35:05 +08:00
|
|
|
|
2016-05-25 05:19:28 +08:00
|
|
|
if (useAppleExtensionAttributes()) {
|
|
|
|
if (DIUnit->isOptimized())
|
|
|
|
NewCU.addFlag(Die, dwarf::DW_AT_APPLE_optimized);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2016-05-25 05:19:28 +08:00
|
|
|
StringRef Flags = DIUnit->getFlags();
|
|
|
|
if (!Flags.empty())
|
|
|
|
NewCU.addString(Die, dwarf::DW_AT_APPLE_flags, Flags);
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2016-05-25 05:19:28 +08:00
|
|
|
if (unsigned RVer = DIUnit->getRuntimeVersion())
|
|
|
|
NewCU.addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
|
|
|
|
dwarf::DW_FORM_data1, RVer);
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2014-11-02 16:51:37 +08:00
|
|
|
if (useSplitDwarf())
|
2016-12-02 02:56:29 +08:00
|
|
|
NewCU.setSection(Asm->getObjFileLowering().getDwarfInfoDWOSection());
|
2014-11-02 16:51:37 +08:00
|
|
|
else
|
2016-12-02 02:56:29 +08:00
|
|
|
NewCU.setSection(Asm->getObjFileLowering().getDwarfInfoSection());
|
2013-12-30 11:40:32 +08:00
|
|
|
|
2015-09-15 06:10:22 +08:00
|
|
|
if (DIUnit->getDWOId()) {
|
2015-09-23 07:21:00 +08:00
|
|
|
// This CU is either a clang module DWO or a skeleton CU.
|
2015-09-15 06:10:22 +08:00
|
|
|
NewCU.addUInt(Die, dwarf::DW_AT_GNU_dwo_id, dwarf::DW_FORM_data8,
|
|
|
|
DIUnit->getDWOId());
|
2015-09-23 07:21:00 +08:00
|
|
|
if (!DIUnit->getSplitDebugFilename().empty())
|
|
|
|
// This is a prefabricated skeleton CU.
|
|
|
|
NewCU.addString(Die, dwarf::DW_AT_GNU_dwo_name,
|
|
|
|
DIUnit->getSplitDebugFilename());
|
2015-09-15 06:10:22 +08:00
|
|
|
}
|
|
|
|
|
2016-08-12 05:15:00 +08:00
|
|
|
CUMap.insert({DIUnit, &NewCU});
|
|
|
|
CUDieMap.insert({&Die, &NewCU});
|
2011-08-17 06:09:43 +08:00
|
|
|
return NewCU;
|
2009-05-21 07:19:06 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2014-08-31 13:41:15 +08:00
|
|
|
void DwarfDebug::constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
|
2015-04-30 00:38:44 +08:00
|
|
|
const DIImportedEntity *N) {
|
2015-04-22 02:44:06 +08:00
|
|
|
if (DIE *D = TheCU.getOrCreateContextDIE(N->getScope()))
|
|
|
|
D->addChild(TheCU.constructImportedEntityDIE(N));
|
2013-04-22 14:12:31 +08:00
|
|
|
}
|
|
|
|
|
2016-12-20 10:09:43 +08:00
|
|
|
/// Sort and unique GVEs by comparing their fragment offset.
|
|
|
|
static SmallVectorImpl<DwarfCompileUnit::GlobalExpr> &
|
|
|
|
sortGlobalExprs(SmallVectorImpl<DwarfCompileUnit::GlobalExpr> &GVEs) {
|
|
|
|
std::sort(GVEs.begin(), GVEs.end(),
|
|
|
|
[](DwarfCompileUnit::GlobalExpr A, DwarfCompileUnit::GlobalExpr B) {
|
2016-12-22 13:27:12 +08:00
|
|
|
if (A.Expr != B.Expr && A.Expr && B.Expr) {
|
|
|
|
auto FragmentA = A.Expr->getFragmentInfo();
|
|
|
|
auto FragmentB = B.Expr->getFragmentInfo();
|
|
|
|
if (FragmentA && FragmentB)
|
|
|
|
return FragmentA->OffsetInBits < FragmentB->OffsetInBits;
|
|
|
|
}
|
2016-12-20 10:09:43 +08:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
GVEs.erase(std::unique(GVEs.begin(), GVEs.end(),
|
|
|
|
[](DwarfCompileUnit::GlobalExpr A,
|
|
|
|
DwarfCompileUnit::GlobalExpr B) {
|
|
|
|
return A.Expr == B.Expr;
|
|
|
|
}),
|
|
|
|
GVEs.end());
|
|
|
|
return GVEs;
|
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Emit all Dwarf sections that should come prior to the content. Create
|
|
|
|
// global DIEs and emit initial debug info sections. This is invoked by
|
|
|
|
// the target AsmPrinter.
|
2012-11-20 06:42:15 +08:00
|
|
|
void DwarfDebug::beginModule() {
|
2016-11-19 03:43:18 +08:00
|
|
|
NamedRegionTimer T(DbgTimerName, DbgTimerDescription, DWARFGroupName,
|
|
|
|
DWARFGroupDescription, TimePassesIsEnabled);
|
2010-04-28 03:46:33 +08:00
|
|
|
if (DisableDebugInfoPrinting)
|
|
|
|
return;
|
|
|
|
|
2012-11-20 06:42:15 +08:00
|
|
|
const Module *M = MMI->getModule();
|
|
|
|
|
2016-06-01 10:58:40 +08:00
|
|
|
unsigned NumDebugCUs = std::distance(M->debug_compile_units_begin(),
|
|
|
|
M->debug_compile_units_end());
|
2016-04-09 06:43:03 +08:00
|
|
|
// Tell MMI whether we have debug info.
|
|
|
|
MMI->setDebugInfoAvailability(NumDebugCUs > 0);
|
|
|
|
SingleCU = NumDebugCUs == 1;
|
2016-12-20 10:09:43 +08:00
|
|
|
DenseMap<DIGlobalVariable *, SmallVector<DwarfCompileUnit::GlobalExpr, 1>>
|
|
|
|
GVMap;
|
2016-09-13 09:12:59 +08:00
|
|
|
for (const GlobalVariable &Global : M->globals()) {
|
2016-12-20 10:09:43 +08:00
|
|
|
SmallVector<DIGlobalVariableExpression *, 1> GVs;
|
2016-09-13 09:12:59 +08:00
|
|
|
Global.getDebugInfo(GVs);
|
2016-12-20 10:09:43 +08:00
|
|
|
for (auto *GVE : GVs)
|
|
|
|
GVMap[GVE->getVariable()].push_back({&Global, GVE->getExpression()});
|
2016-09-13 09:12:59 +08:00
|
|
|
}
|
|
|
|
|
2016-04-09 06:43:03 +08:00
|
|
|
for (DICompileUnit *CUNode : M->debug_compile_units()) {
|
2014-04-23 06:39:41 +08:00
|
|
|
DwarfCompileUnit &CU = constructDwarfCompileUnit(CUNode);
|
2016-04-30 09:44:07 +08:00
|
|
|
for (auto *IE : CUNode->getImportedEntities())
|
|
|
|
CU.addImportedEntity(IE);
|
2016-12-20 10:09:43 +08:00
|
|
|
|
|
|
|
// Global Variables.
|
|
|
|
for (auto *GVE : CUNode->getGlobalVariables())
|
|
|
|
GVMap[GVE->getVariable()].push_back({nullptr, GVE->getExpression()});
|
|
|
|
DenseSet<DIGlobalVariable *> Processed;
|
|
|
|
for (auto *GVE : CUNode->getGlobalVariables()) {
|
|
|
|
DIGlobalVariable *GV = GVE->getVariable();
|
|
|
|
if (Processed.insert(GV).second)
|
|
|
|
CU.getOrCreateGlobalVariableDIE(GV, sortGlobalExprs(GVMap[GV]));
|
|
|
|
}
|
|
|
|
|
2015-04-21 02:52:06 +08:00
|
|
|
for (auto *Ty : CUNode->getEnumTypes()) {
|
2014-07-29 07:04:20 +08:00
|
|
|
// The enum types array by design contains pointers to
|
|
|
|
// MDNodes rather than DIRefs. Unique them here.
|
2016-04-24 05:08:00 +08:00
|
|
|
CU.getOrCreateTypeDIE(cast<DIType>(Ty));
|
2014-07-29 07:04:20 +08:00
|
|
|
}
|
2015-04-21 02:52:06 +08:00
|
|
|
for (auto *Ty : CUNode->getRetainedTypes()) {
|
2014-03-18 10:35:03 +08:00
|
|
|
// The retained types array by design contains pointers to
|
|
|
|
// MDNodes rather than DIRefs. Unique them here.
|
2016-04-30 09:44:07 +08:00
|
|
|
if (DIType *RT = dyn_cast<DIType>(Ty))
|
|
|
|
if (!RT->isExternalTypeRef())
|
2016-04-15 23:57:41 +08:00
|
|
|
// There is no point in force-emitting a forward declaration.
|
|
|
|
CU.getOrCreateTypeDIE(RT);
|
2014-03-18 10:35:03 +08:00
|
|
|
}
|
2013-04-22 14:12:31 +08:00
|
|
|
// Emit imported_modules last so that the relevant context is already
|
|
|
|
// available.
|
2015-04-07 12:14:33 +08:00
|
|
|
for (auto *IE : CUNode->getImportedEntities())
|
2016-04-30 09:44:07 +08:00
|
|
|
constructAndAddImportedEntityDIE(CU, IE);
|
2013-03-12 07:39:23 +08:00
|
|
|
}
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2014-06-14 06:18:23 +08:00
|
|
|
void DwarfDebug::finishVariableDefinitions() {
|
|
|
|
for (const auto &Var : ConcreteVariables) {
|
|
|
|
DIE *VariableDie = Var->getDIE();
|
2014-08-12 08:00:31 +08:00
|
|
|
assert(VariableDie);
|
2014-06-14 06:18:23 +08:00
|
|
|
// FIXME: Consider the time-space tradeoff of just storing the unit pointer
|
|
|
|
// in the ConcreteVariables list, rather than looking it up again here.
|
|
|
|
// DIE::getUnit isn't simple - it walks parent pointers, etc.
|
2016-12-02 02:56:29 +08:00
|
|
|
DwarfCompileUnit *Unit = CUDieMap.lookup(VariableDie->getUnitDie());
|
2014-06-14 06:18:23 +08:00
|
|
|
assert(Unit);
|
2015-04-16 06:29:27 +08:00
|
|
|
DbgVariable *AbsVar = getExistingAbstractVariable(
|
|
|
|
InlinedVariable(Var->getVariable(), Var->getInlinedAt()));
|
2014-06-14 06:18:23 +08:00
|
|
|
if (AbsVar && AbsVar->getDIE()) {
|
|
|
|
Unit->addDIEEntry(*VariableDie, dwarf::DW_AT_abstract_origin,
|
|
|
|
*AbsVar->getDIE());
|
|
|
|
} else
|
|
|
|
Unit->applyVariableAttributes(*Var, *VariableDie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
DebugInfo: Lazily attach definition attributes to definitions.
This is a precursor to fixing inlined debug info where the concrete,
out-of-line definition may preceed any inlined usage. To cope with this,
the attributes that may appear on the concrete definition or the
abstract definition are delayed until the end of the module. Then, if an
abstract definition was created, it is referenced (and no other
attributes are added to the out-of-line definition), otherwise the
attributes are added directly to the out-of-line definition.
In a couple of cases this causes not just reordering of attributes, but
reordering of types. When the creation of the attribute is delayed, if
that creation would create a type (such as for a DW_AT_type attribute)
then other top level DIEs may've been constructed during the delay,
causing the referenced type to be created and added after those
intervening DIEs. In the extreme case, in cross-cu-inlining.ll, this
actually causes the DW_TAG_basic_type for "int" to move from one CU to
another.
llvm-svn: 209674
2014-05-28 02:37:43 +08:00
|
|
|
void DwarfDebug::finishSubprogramDefinitions() {
|
2016-12-15 03:38:39 +08:00
|
|
|
for (const DISubprogram *SP : ProcessedSPNodes)
|
|
|
|
if (SP->getUnit()->getEmissionKind() != DICompileUnit::NoDebug)
|
|
|
|
forBothCUs(*CUMap.lookup(SP->getUnit()), [&](DwarfCompileUnit &CU) {
|
|
|
|
CU.finishSubprogramDefinition(SP);
|
|
|
|
});
|
2012-11-22 08:59:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DwarfDebug::finalizeModuleInfo() {
|
2015-03-11 00:58:10 +08:00
|
|
|
const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
|
|
|
|
|
2014-05-28 02:37:48 +08:00
|
|
|
finishSubprogramDefinitions();
|
|
|
|
|
2014-06-14 06:18:23 +08:00
|
|
|
finishVariableDefinitions();
|
|
|
|
|
2013-12-05 07:24:38 +08:00
|
|
|
// Handle anything that needs to be done on a per-unit basis after
|
|
|
|
// all other generation.
|
2014-11-01 09:11:19 +08:00
|
|
|
for (const auto &P : CUMap) {
|
|
|
|
auto &TheCU = *P.second;
|
2013-08-13 04:27:48 +08:00
|
|
|
// Emit DW_AT_containing_type attribute to connect types with their
|
|
|
|
// vtable holding type.
|
2014-11-01 09:11:19 +08:00
|
|
|
TheCU.constructContainingTypeDIEs();
|
2013-08-13 04:27:48 +08:00
|
|
|
|
2013-12-20 12:16:18 +08:00
|
|
|
// Add CU specific attributes if we need to add any.
|
2014-11-01 09:11:19 +08:00
|
|
|
// If we're splitting the dwarf out now that we've got the entire
|
|
|
|
// CU then add the dwo id to it.
|
|
|
|
auto *SkCU = TheCU.getSkeleton();
|
|
|
|
if (useSplitDwarf()) {
|
|
|
|
// Emit a unique identifier for this CU.
|
|
|
|
uint64_t ID = DIEHash(Asm).computeCUSignature(TheCU.getUnitDie());
|
|
|
|
TheCU.addUInt(TheCU.getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
|
|
|
|
dwarf::DW_FORM_data8, ID);
|
|
|
|
SkCU->addUInt(SkCU->getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
|
|
|
|
dwarf::DW_FORM_data8, ID);
|
|
|
|
|
|
|
|
// We don't keep track of which addresses are used in which CU so this
|
|
|
|
// is a bit pessimistic under LTO.
|
2015-03-11 00:58:10 +08:00
|
|
|
if (!AddrPool.isEmpty()) {
|
|
|
|
const MCSymbol *Sym = TLOF.getDwarfAddrSection()->getBeginSymbol();
|
2014-11-01 09:11:19 +08:00
|
|
|
SkCU->addSectionLabel(SkCU->getUnitDie(), dwarf::DW_AT_GNU_addr_base,
|
2015-03-11 00:58:10 +08:00
|
|
|
Sym, Sym);
|
|
|
|
}
|
|
|
|
if (!SkCU->getRangeLists().empty()) {
|
|
|
|
const MCSymbol *Sym = TLOF.getDwarfRangesSection()->getBeginSymbol();
|
2014-11-01 09:11:19 +08:00
|
|
|
SkCU->addSectionLabel(SkCU->getUnitDie(), dwarf::DW_AT_GNU_ranges_base,
|
2015-03-11 00:58:10 +08:00
|
|
|
Sym, Sym);
|
|
|
|
}
|
2014-11-01 09:11:19 +08:00
|
|
|
}
|
2013-12-31 01:22:27 +08:00
|
|
|
|
2014-11-01 09:11:19 +08:00
|
|
|
// If we have code split among multiple sections or non-contiguous
|
|
|
|
// ranges of code then emit a DW_AT_ranges attribute on the unit that will
|
|
|
|
// remain in the .o file, otherwise add a DW_AT_low_pc.
|
|
|
|
// FIXME: We should use ranges allow reordering of code ala
|
|
|
|
// .subsections_via_symbols in mach-o. This would mean turning on
|
|
|
|
// ranges for all subprogram DIEs for mach-o.
|
2014-11-01 09:15:24 +08:00
|
|
|
DwarfCompileUnit &U = SkCU ? *SkCU : TheCU;
|
2014-11-04 07:10:59 +08:00
|
|
|
if (unsigned NumRanges = TheCU.getRanges().size()) {
|
|
|
|
if (NumRanges > 1)
|
2014-11-01 09:11:19 +08:00
|
|
|
// A DW_AT_low_pc attribute may also be specified in combination with
|
|
|
|
// DW_AT_ranges to specify the default base address for use in
|
|
|
|
// location lists (see Section 2.6.2) and range lists (see Section
|
|
|
|
// 2.17.3).
|
|
|
|
U.addUInt(U.getUnitDie(), dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, 0);
|
2014-11-04 07:10:59 +08:00
|
|
|
else
|
2015-05-02 10:31:49 +08:00
|
|
|
U.setBaseAddress(TheCU.getRanges().front().getStart());
|
2014-11-04 07:10:59 +08:00
|
|
|
U.attachRangesOrLowHighPC(U.getUnitDie(), TheCU.takeRanges());
|
2013-08-13 04:27:48 +08:00
|
|
|
}
|
2016-01-07 22:28:20 +08:00
|
|
|
|
|
|
|
auto *CUNode = cast<DICompileUnit>(P.first);
|
2016-02-01 22:09:41 +08:00
|
|
|
// If compile Unit has macros, emit "DW_AT_macro_info" attribute.
|
|
|
|
if (CUNode->getMacros())
|
|
|
|
U.addSectionLabel(U.getUnitDie(), dwarf::DW_AT_macro_info,
|
|
|
|
U.getMacroLabelBegin(),
|
|
|
|
TLOF.getDwarfMacinfoSection()->getBeginSymbol());
|
2013-08-13 04:27:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compute DIE offsets and sizes.
|
2012-12-11 07:34:43 +08:00
|
|
|
InfoHolder.computeSizeAndOffsets();
|
|
|
|
if (useSplitDwarf())
|
|
|
|
SkeletonHolder.computeSizeAndOffsets();
|
2012-11-22 08:59:49 +08:00
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Emit all Dwarf sections that should come after the content.
|
2012-11-22 08:59:49 +08:00
|
|
|
void DwarfDebug::endModule() {
|
2014-04-28 12:05:08 +08:00
|
|
|
assert(CurFn == nullptr);
|
|
|
|
assert(CurMI == nullptr);
|
2012-11-22 08:59:49 +08:00
|
|
|
|
2014-10-25 01:53:38 +08:00
|
|
|
// If we aren't actually generating debug info (check beginModule -
|
|
|
|
// conditionalized on !DisableDebugInfoPrinting and the presence of the
|
|
|
|
// llvm.dbg.cu metadata node)
|
2015-03-11 08:51:37 +08:00
|
|
|
if (!MMI->hasDebugInfo())
|
2013-11-19 17:04:36 +08:00
|
|
|
return;
|
2012-11-22 08:59:49 +08:00
|
|
|
|
|
|
|
// Finalize the debug info for the module.
|
|
|
|
finalizeModuleInfo();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2013-11-19 17:04:50 +08:00
|
|
|
emitDebugStr();
|
2013-09-21 07:22:52 +08:00
|
|
|
|
2015-03-11 00:58:10 +08:00
|
|
|
if (useSplitDwarf())
|
|
|
|
emitDebugLocDWO();
|
|
|
|
else
|
|
|
|
// Emit info into a debug loc section.
|
|
|
|
emitDebugLoc();
|
|
|
|
|
2013-11-19 17:04:50 +08:00
|
|
|
// Corresponding abbreviations into a abbrev section.
|
|
|
|
emitAbbreviations();
|
2012-11-28 06:43:42 +08:00
|
|
|
|
2015-03-11 08:51:37 +08:00
|
|
|
// Emit all the DIEs into a debug info section.
|
|
|
|
emitDebugInfo();
|
|
|
|
|
2013-11-19 17:04:50 +08:00
|
|
|
// Emit info into a debug aranges section.
|
2014-02-14 09:26:55 +08:00
|
|
|
if (GenerateARangeSection)
|
|
|
|
emitDebugARanges();
|
2012-11-28 06:43:42 +08:00
|
|
|
|
2013-11-19 17:04:50 +08:00
|
|
|
// Emit info into a debug ranges section.
|
|
|
|
emitDebugRanges();
|
2012-11-28 06:43:42 +08:00
|
|
|
|
2016-01-07 22:28:20 +08:00
|
|
|
// Emit info into a debug macinfo section.
|
|
|
|
emitDebugMacinfo();
|
|
|
|
|
2013-11-19 17:04:50 +08:00
|
|
|
if (useSplitDwarf()) {
|
|
|
|
emitDebugStrDWO();
|
2012-12-01 07:59:06 +08:00
|
|
|
emitDebugInfoDWO();
|
2012-12-20 06:02:53 +08:00
|
|
|
emitDebugAbbrevDWO();
|
2014-03-18 09:17:26 +08:00
|
|
|
emitDebugLineDWO();
|
2013-01-16 07:56:56 +08:00
|
|
|
// Emit DWO addresses.
|
2014-04-24 05:20:10 +08:00
|
|
|
AddrPool.emit(*Asm, Asm->getObjFileLowering().getDwarfAddrSection());
|
2015-03-11 00:58:10 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2012-08-23 15:32:06 +08:00
|
|
|
// Emit info into the dwarf accelerator table sections.
|
2012-08-24 06:36:40 +08:00
|
|
|
if (useDwarfAccelTables()) {
|
2011-11-07 17:24:32 +08:00
|
|
|
emitAccelNames();
|
|
|
|
emitAccelObjC();
|
|
|
|
emitAccelNamespaces();
|
|
|
|
emitAccelTypes();
|
|
|
|
}
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2013-08-30 08:40:17 +08:00
|
|
|
// Emit the pubnames and pubtypes sections if requested.
|
|
|
|
if (HasDwarfPubSections) {
|
2013-09-20 01:33:35 +08:00
|
|
|
emitDebugPubNames(GenerateGnuPubSections);
|
|
|
|
emitDebugPubTypes(GenerateGnuPubSections);
|
2013-08-30 08:40:17 +08:00
|
|
|
}
|
2009-11-24 09:14:22 +08:00
|
|
|
|
2010-08-03 01:32:15 +08:00
|
|
|
// clean up.
|
2014-05-22 06:41:17 +08:00
|
|
|
AbstractVariables.clear();
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Find abstract variable, if any, associated with Var.
|
2015-04-22 02:44:06 +08:00
|
|
|
DbgVariable *
|
|
|
|
DwarfDebug::getExistingAbstractVariable(InlinedVariable IV,
|
2015-04-30 00:38:44 +08:00
|
|
|
const DILocalVariable *&Cleansed) {
|
2011-08-11 05:50:54 +08:00
|
|
|
// More then one inlined variable corresponds to one abstract variable.
|
2015-04-16 06:29:27 +08:00
|
|
|
Cleansed = IV.first;
|
2014-06-05 07:50:52 +08:00
|
|
|
auto I = AbstractVariables.find(Cleansed);
|
2014-05-22 06:41:17 +08:00
|
|
|
if (I != AbstractVariables.end())
|
|
|
|
return I->second.get();
|
2014-06-05 07:50:52 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
2010-03-16 02:33:46 +08:00
|
|
|
|
2015-04-16 06:29:27 +08:00
|
|
|
DbgVariable *DwarfDebug::getExistingAbstractVariable(InlinedVariable IV) {
|
2015-04-30 00:38:44 +08:00
|
|
|
const DILocalVariable *Cleansed;
|
2015-04-16 06:29:27 +08:00
|
|
|
return getExistingAbstractVariable(IV, Cleansed);
|
2014-06-14 06:35:44 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
void DwarfDebug::createAbstractVariable(const DILocalVariable *Var,
|
2014-06-14 07:52:55 +08:00
|
|
|
LexicalScope *Scope) {
|
2017-02-02 07:51:56 +08:00
|
|
|
assert(Scope && Scope->isAbstractScope());
|
2016-04-24 05:08:00 +08:00
|
|
|
auto AbsDbgVariable = make_unique<DbgVariable>(Var, /* IA */ nullptr);
|
2014-10-24 08:43:47 +08:00
|
|
|
InfoHolder.addScopeVariable(Scope, AbsDbgVariable.get());
|
2014-06-14 07:52:55 +08:00
|
|
|
AbstractVariables[Var] = std::move(AbsDbgVariable);
|
2010-03-16 02:33:46 +08:00
|
|
|
}
|
|
|
|
|
2015-04-16 06:29:27 +08:00
|
|
|
void DwarfDebug::ensureAbstractVariableIsCreated(InlinedVariable IV,
|
2014-06-14 07:52:55 +08:00
|
|
|
const MDNode *ScopeNode) {
|
2015-04-30 00:38:44 +08:00
|
|
|
const DILocalVariable *Cleansed = nullptr;
|
2015-04-16 06:29:27 +08:00
|
|
|
if (getExistingAbstractVariable(IV, Cleansed))
|
2014-06-14 07:52:55 +08:00
|
|
|
return;
|
2014-06-05 07:50:52 +08:00
|
|
|
|
2015-03-31 07:21:21 +08:00
|
|
|
createAbstractVariable(Cleansed, LScopes.getOrCreateAbstractScope(
|
2015-04-30 00:38:44 +08:00
|
|
|
cast<DILocalScope>(ScopeNode)));
|
2014-06-05 07:50:52 +08:00
|
|
|
}
|
|
|
|
|
2015-04-16 06:29:27 +08:00
|
|
|
void DwarfDebug::ensureAbstractVariableIsCreatedIfScoped(
|
|
|
|
InlinedVariable IV, const MDNode *ScopeNode) {
|
2015-04-30 00:38:44 +08:00
|
|
|
const DILocalVariable *Cleansed = nullptr;
|
2015-04-16 06:29:27 +08:00
|
|
|
if (getExistingAbstractVariable(IV, Cleansed))
|
2014-06-14 07:52:55 +08:00
|
|
|
return;
|
2014-06-05 07:50:52 +08:00
|
|
|
|
2015-03-31 07:21:21 +08:00
|
|
|
if (LexicalScope *Scope =
|
2015-04-30 00:38:44 +08:00
|
|
|
LScopes.findAbstractScope(cast_or_null<DILocalScope>(ScopeNode)))
|
2014-06-14 07:52:55 +08:00
|
|
|
createAbstractVariable(Cleansed, Scope);
|
2014-06-05 07:50:52 +08:00
|
|
|
}
|
|
|
|
|
2016-12-01 07:48:50 +08:00
|
|
|
// Collect variable information from side table maintained by MF.
|
|
|
|
void DwarfDebug::collectVariableInfoFromMFTable(
|
2015-04-16 06:29:27 +08:00
|
|
|
DenseSet<InlinedVariable> &Processed) {
|
2016-12-01 07:48:50 +08:00
|
|
|
for (const auto &VI : Asm->MF->getVariableDbgInfo()) {
|
2014-03-09 23:44:39 +08:00
|
|
|
if (!VI.Var)
|
2013-11-19 17:04:36 +08:00
|
|
|
continue;
|
2015-04-17 06:12:59 +08:00
|
|
|
assert(VI.Var->isValidLocationForIntrinsic(VI.Loc) &&
|
|
|
|
"Expected inlined-at fields to agree");
|
|
|
|
|
|
|
|
InlinedVariable Var(VI.Var, VI.Loc->getInlinedAt());
|
2015-04-16 06:29:27 +08:00
|
|
|
Processed.insert(Var);
|
2014-03-09 23:44:39 +08:00
|
|
|
LexicalScope *Scope = LScopes.findLexicalScope(VI.Loc);
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2009-11-11 07:20:04 +08:00
|
|
|
// If variable scope is not found then skip this variable.
|
2014-04-24 14:44:33 +08:00
|
|
|
if (!Scope)
|
2009-11-11 07:20:04 +08:00
|
|
|
continue;
|
2009-11-11 07:06:00 +08:00
|
|
|
|
2015-04-16 06:29:27 +08:00
|
|
|
ensureAbstractVariableIsCreatedIfScoped(Var, Scope->getScopeNode());
|
2016-04-24 05:08:00 +08:00
|
|
|
auto RegVar = make_unique<DbgVariable>(Var.first, Var.second);
|
AsmPrinter: Rewrite initialization of DbgVariable, NFC
There are three types of `DbgVariable`:
- alloca variables, created based on the MMI table,
- register variables, created based on DBG_VALUE instructions, and
- optimized-out variables.
This commit reconfigures `DbgVariable` to make it easier to tell which
kind we have, and make initialization a little clearer.
For MMI/alloca variables, `FrameIndex.size()` must always equal
`Expr.size()`, and there shouldn't be an `MInsn`. For register
variables (with a `MInsn`), `FrameIndex` must be empty, and `Expr`
should have 0 or 1 element depending on whether it has a complex
expression (registers with multiple locations use `DebugLocListIndex`).
Optimized-out variables shouldn't have any of these fields.
Moreover, this separates DBG_VALUE initialization until after the
variable is created, simplifying logic in a future commit that changes
`collectVariableInfo()` to stop creating empty .debug_loc entries/lists.
llvm-svn: 240243
2015-06-22 00:50:43 +08:00
|
|
|
RegVar->initializeMMI(VI.Expr, VI.Slot);
|
2015-02-11 07:18:28 +08:00
|
|
|
if (InfoHolder.addScopeVariable(Scope, RegVar.get()))
|
|
|
|
ConcreteVariables.push_back(std::move(RegVar));
|
2009-10-06 09:26:37 +08:00
|
|
|
}
|
2010-05-21 03:57:06 +08:00
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Get .debug_loc entry for the instruction range starting at MI.
|
2014-04-28 02:25:40 +08:00
|
|
|
static DebugLocEntry::Value getDebugLocValue(const MachineInstr *MI) {
|
2015-04-30 00:38:44 +08:00
|
|
|
const DIExpression *Expr = MI->getDebugExpression();
|
2011-07-09 01:09:57 +08:00
|
|
|
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
assert(MI->getNumOperands() == 4);
|
2013-07-10 04:28:37 +08:00
|
|
|
if (MI->getOperand(0).isReg()) {
|
2011-07-09 01:09:57 +08:00
|
|
|
MachineLocation MLoc;
|
2013-07-10 04:28:37 +08:00
|
|
|
// If the second operand is an immediate, this is a
|
|
|
|
// register-indirect address.
|
|
|
|
if (!MI->getOperand(1).isImm())
|
2013-04-27 05:57:17 +08:00
|
|
|
MLoc.set(MI->getOperand(0).getReg());
|
|
|
|
else
|
|
|
|
MLoc.set(MI->getOperand(0).getReg(), MI->getOperand(1).getImm());
|
2015-04-18 00:33:37 +08:00
|
|
|
return DebugLocEntry::Value(Expr, MLoc);
|
2011-07-09 01:09:57 +08:00
|
|
|
}
|
|
|
|
if (MI->getOperand(0).isImm())
|
2015-04-18 00:33:37 +08:00
|
|
|
return DebugLocEntry::Value(Expr, MI->getOperand(0).getImm());
|
2011-07-09 01:09:57 +08:00
|
|
|
if (MI->getOperand(0).isFPImm())
|
2015-04-18 00:33:37 +08:00
|
|
|
return DebugLocEntry::Value(Expr, MI->getOperand(0).getFPImm());
|
2011-07-09 01:09:57 +08:00
|
|
|
if (MI->getOperand(0).isCImm())
|
2015-04-18 00:33:37 +08:00
|
|
|
return DebugLocEntry::Value(Expr, MI->getOperand(0).getCImm());
|
2011-07-09 01:09:57 +08:00
|
|
|
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
llvm_unreachable("Unexpected 4-operand DBG_VALUE instruction!");
|
2011-07-09 01:09:57 +08:00
|
|
|
}
|
|
|
|
|
2016-12-06 02:04:47 +08:00
|
|
|
/// \brief If this and Next are describing different fragments of the same
|
2016-01-16 09:11:33 +08:00
|
|
|
/// variable, merge them by appending Next's values to the current
|
|
|
|
/// list of values.
|
|
|
|
/// Return true if the merge was successful.
|
|
|
|
bool DebugLocEntry::MergeValues(const DebugLocEntry &Next) {
|
|
|
|
if (Begin == Next.Begin) {
|
2016-02-04 05:13:33 +08:00
|
|
|
auto *FirstExpr = cast<DIExpression>(Values[0].Expression);
|
|
|
|
auto *FirstNextExpr = cast<DIExpression>(Next.Values[0].Expression);
|
2016-12-06 02:04:47 +08:00
|
|
|
if (!FirstExpr->isFragment() || !FirstNextExpr->isFragment())
|
2016-02-04 05:13:33 +08:00
|
|
|
return false;
|
|
|
|
|
2016-12-06 02:04:47 +08:00
|
|
|
// We can only merge entries if none of the fragments overlap any others.
|
2016-02-04 05:13:33 +08:00
|
|
|
// In doing so, we can take advantage of the fact that both lists are
|
|
|
|
// sorted.
|
|
|
|
for (unsigned i = 0, j = 0; i < Values.size(); ++i) {
|
|
|
|
for (; j < Next.Values.size(); ++j) {
|
2016-12-06 02:04:47 +08:00
|
|
|
int res = DebugHandlerBase::fragmentCmp(
|
2016-02-11 04:55:49 +08:00
|
|
|
cast<DIExpression>(Values[i].Expression),
|
|
|
|
cast<DIExpression>(Next.Values[j].Expression));
|
2016-02-04 05:13:33 +08:00
|
|
|
if (res == 0) // The two expressions overlap, we can't merge.
|
|
|
|
return false;
|
|
|
|
// Values[i] is entirely before Next.Values[j],
|
|
|
|
// so go back to the next entry of Values.
|
|
|
|
else if (res == -1)
|
|
|
|
break;
|
|
|
|
// Next.Values[j] is entirely before Values[i], so go on to the
|
|
|
|
// next entry of Next.Values.
|
|
|
|
}
|
2016-01-16 09:11:33 +08:00
|
|
|
}
|
2016-02-04 05:13:33 +08:00
|
|
|
|
|
|
|
addValues(Next.Values);
|
|
|
|
End = Next.End;
|
|
|
|
return true;
|
2016-01-16 09:11:33 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-02 06:11:58 +08:00
|
|
|
/// Build the location list for all DBG_VALUEs in the function that
|
|
|
|
/// describe the same variable. If the ranges of several independent
|
2016-12-06 02:04:47 +08:00
|
|
|
/// fragments of the same variable overlap partially, split them up and
|
2014-08-02 06:11:58 +08:00
|
|
|
/// combine the ranges. The resulting DebugLocEntries are will have
|
|
|
|
/// strict monotonically increasing begin addresses and will never
|
|
|
|
/// overlap.
|
|
|
|
//
|
|
|
|
// Input:
|
|
|
|
//
|
2016-12-06 02:04:47 +08:00
|
|
|
// Ranges History [var, loc, fragment ofs size]
|
|
|
|
// 0 | [x, (reg0, fragment 0, 32)]
|
|
|
|
// 1 | | [x, (reg1, fragment 32, 32)] <- IsFragmentOfPrevEntry
|
2014-08-02 06:11:58 +08:00
|
|
|
// 2 | | ...
|
|
|
|
// 3 | [clobber reg0]
|
2016-12-06 02:04:47 +08:00
|
|
|
// 4 [x, (mem, fragment 0, 64)] <- overlapping with both previous fragments of
|
2015-02-18 04:02:28 +08:00
|
|
|
// x.
|
2014-08-02 06:11:58 +08:00
|
|
|
//
|
|
|
|
// Output:
|
|
|
|
//
|
2016-12-06 02:04:47 +08:00
|
|
|
// [0-1] [x, (reg0, fragment 0, 32)]
|
|
|
|
// [1-3] [x, (reg0, fragment 0, 32), (reg1, fragment 32, 32)]
|
|
|
|
// [3-4] [x, (reg1, fragment 32, 32)]
|
|
|
|
// [4- ] [x, (mem, fragment 0, 64)]
|
2014-08-06 07:14:16 +08:00
|
|
|
void
|
|
|
|
DwarfDebug::buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
|
|
|
|
const DbgValueHistoryMap::InstrRanges &Ranges) {
|
2014-08-12 05:05:57 +08:00
|
|
|
SmallVector<DebugLocEntry::Value, 4> OpenRanges;
|
2014-08-02 06:11:58 +08:00
|
|
|
|
|
|
|
for (auto I = Ranges.begin(), E = Ranges.end(); I != E; ++I) {
|
|
|
|
const MachineInstr *Begin = I->first;
|
|
|
|
const MachineInstr *End = I->second;
|
|
|
|
assert(Begin->isDebugValue() && "Invalid History entry");
|
|
|
|
|
|
|
|
// Check if a variable is inaccessible in this range.
|
2014-08-13 05:55:58 +08:00
|
|
|
if (Begin->getNumOperands() > 1 &&
|
|
|
|
Begin->getOperand(0).isReg() && !Begin->getOperand(0).getReg()) {
|
2014-08-02 06:11:58 +08:00
|
|
|
OpenRanges.clear();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-06 02:04:47 +08:00
|
|
|
// If this fragment overlaps with any open ranges, truncate them.
|
2015-04-30 00:38:44 +08:00
|
|
|
const DIExpression *DIExpr = Begin->getDebugExpression();
|
2016-08-12 05:15:00 +08:00
|
|
|
auto Last = remove_if(OpenRanges, [&](DebugLocEntry::Value R) {
|
2016-12-06 02:04:47 +08:00
|
|
|
return fragmentsOverlap(DIExpr, R.getExpression());
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
});
|
2014-08-02 06:11:58 +08:00
|
|
|
OpenRanges.erase(Last, OpenRanges.end());
|
|
|
|
|
|
|
|
const MCSymbol *StartLabel = getLabelBeforeInsn(Begin);
|
|
|
|
assert(StartLabel && "Forgot label before DBG_VALUE starting a range!");
|
|
|
|
|
|
|
|
const MCSymbol *EndLabel;
|
|
|
|
if (End != nullptr)
|
|
|
|
EndLabel = getLabelAfterInsn(End);
|
|
|
|
else if (std::next(I) == Ranges.end())
|
2015-03-05 10:05:42 +08:00
|
|
|
EndLabel = Asm->getFunctionEnd();
|
2014-08-02 06:11:58 +08:00
|
|
|
else
|
|
|
|
EndLabel = getLabelBeforeInsn(std::next(I)->first);
|
|
|
|
assert(EndLabel && "Forgot label after instruction ending a range!");
|
|
|
|
|
|
|
|
DEBUG(dbgs() << "DotDebugLoc: " << *Begin << "\n");
|
|
|
|
|
|
|
|
auto Value = getDebugLocValue(Begin);
|
2014-08-06 07:14:16 +08:00
|
|
|
DebugLocEntry Loc(StartLabel, EndLabel, Value);
|
2014-08-12 04:59:28 +08:00
|
|
|
bool couldMerge = false;
|
|
|
|
|
2016-12-06 02:04:47 +08:00
|
|
|
// If this is a fragment, it may belong to the current DebugLocEntry.
|
|
|
|
if (DIExpr->isFragment()) {
|
2014-08-12 04:59:28 +08:00
|
|
|
// Add this value to the list of open ranges.
|
2014-08-12 05:05:57 +08:00
|
|
|
OpenRanges.push_back(Value);
|
2014-08-12 04:59:28 +08:00
|
|
|
|
2016-12-06 02:04:47 +08:00
|
|
|
// Attempt to add the fragment to the last entry.
|
2014-08-12 04:59:28 +08:00
|
|
|
if (!DebugLoc.empty())
|
|
|
|
if (DebugLoc.back().MergeValues(Loc))
|
|
|
|
couldMerge = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!couldMerge) {
|
|
|
|
// Need to add a new DebugLocEntry. Add all values from still
|
2016-12-06 02:04:47 +08:00
|
|
|
// valid non-overlapping fragments.
|
2014-08-12 05:06:00 +08:00
|
|
|
if (OpenRanges.size())
|
|
|
|
Loc.addValues(OpenRanges);
|
|
|
|
|
2014-08-02 06:11:58 +08:00
|
|
|
DebugLoc.push_back(std::move(Loc));
|
|
|
|
}
|
2014-08-12 04:59:28 +08:00
|
|
|
|
|
|
|
// Attempt to coalesce the ranges of two otherwise identical
|
|
|
|
// DebugLocEntries.
|
|
|
|
auto CurEntry = DebugLoc.rbegin();
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
DEBUG({
|
|
|
|
dbgs() << CurEntry->getValues().size() << " Values:\n";
|
2015-05-27 04:06:51 +08:00
|
|
|
for (auto &Value : CurEntry->getValues())
|
2016-03-01 06:28:22 +08:00
|
|
|
Value.dump();
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
dbgs() << "-----\n";
|
|
|
|
});
|
2015-05-27 04:06:48 +08:00
|
|
|
|
|
|
|
auto PrevEntry = std::next(CurEntry);
|
|
|
|
if (PrevEntry != DebugLoc.rend() && PrevEntry->MergeRanges(*CurEntry))
|
|
|
|
DebugLoc.pop_back();
|
2014-08-02 06:11:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
AsmPrinter: Rewrite initialization of DbgVariable, NFC
There are three types of `DbgVariable`:
- alloca variables, created based on the MMI table,
- register variables, created based on DBG_VALUE instructions, and
- optimized-out variables.
This commit reconfigures `DbgVariable` to make it easier to tell which
kind we have, and make initialization a little clearer.
For MMI/alloca variables, `FrameIndex.size()` must always equal
`Expr.size()`, and there shouldn't be an `MInsn`. For register
variables (with a `MInsn`), `FrameIndex` must be empty, and `Expr`
should have 0 or 1 element depending on whether it has a complex
expression (registers with multiple locations use `DebugLocListIndex`).
Optimized-out variables shouldn't have any of these fields.
Moreover, this separates DBG_VALUE initialization until after the
variable is created, simplifying logic in a future commit that changes
`collectVariableInfo()` to stop creating empty .debug_loc entries/lists.
llvm-svn: 240243
2015-06-22 00:50:43 +08:00
|
|
|
DbgVariable *DwarfDebug::createConcreteVariable(LexicalScope &Scope,
|
|
|
|
InlinedVariable IV) {
|
|
|
|
ensureAbstractVariableIsCreatedIfScoped(IV, Scope.getScopeNode());
|
2016-04-24 05:08:00 +08:00
|
|
|
ConcreteVariables.push_back(make_unique<DbgVariable>(IV.first, IV.second));
|
AsmPrinter: Rewrite initialization of DbgVariable, NFC
There are three types of `DbgVariable`:
- alloca variables, created based on the MMI table,
- register variables, created based on DBG_VALUE instructions, and
- optimized-out variables.
This commit reconfigures `DbgVariable` to make it easier to tell which
kind we have, and make initialization a little clearer.
For MMI/alloca variables, `FrameIndex.size()` must always equal
`Expr.size()`, and there shouldn't be an `MInsn`. For register
variables (with a `MInsn`), `FrameIndex` must be empty, and `Expr`
should have 0 or 1 element depending on whether it has a complex
expression (registers with multiple locations use `DebugLocListIndex`).
Optimized-out variables shouldn't have any of these fields.
Moreover, this separates DBG_VALUE initialization until after the
variable is created, simplifying logic in a future commit that changes
`collectVariableInfo()` to stop creating empty .debug_loc entries/lists.
llvm-svn: 240243
2015-06-22 00:50:43 +08:00
|
|
|
InfoHolder.addScopeVariable(&Scope, ConcreteVariables.back().get());
|
|
|
|
return ConcreteVariables.back().get();
|
|
|
|
}
|
2014-08-02 06:11:58 +08:00
|
|
|
|
2016-03-01 03:49:46 +08:00
|
|
|
// Determine whether this DBG_VALUE is valid at the beginning of the function.
|
|
|
|
static bool validAtEntry(const MachineInstr *MInsn) {
|
|
|
|
auto MBB = MInsn->getParent();
|
|
|
|
// Is it in the entry basic block?
|
|
|
|
if (!MBB->pred_empty())
|
|
|
|
return false;
|
|
|
|
for (MachineBasicBlock::const_reverse_iterator I(MInsn); I != MBB->rend(); ++I)
|
|
|
|
if (!(I->isDebugValue() || I->getFlag(MachineInstr::FrameSetup)))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Find variables for each lexical scope.
|
2015-04-21 06:10:08 +08:00
|
|
|
void DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU,
|
2015-04-30 00:38:44 +08:00
|
|
|
const DISubprogram *SP,
|
2015-04-16 06:29:27 +08:00
|
|
|
DenseSet<InlinedVariable> &Processed) {
|
2013-07-04 05:37:03 +08:00
|
|
|
// Grab the variable info that was squirreled away in the MMI side-table.
|
2016-12-01 07:48:50 +08:00
|
|
|
collectVariableInfoFromMFTable(Processed);
|
2010-03-16 02:33:46 +08:00
|
|
|
|
2014-05-01 07:02:40 +08:00
|
|
|
for (const auto &I : DbgValues) {
|
2015-04-16 06:29:27 +08:00
|
|
|
InlinedVariable IV = I.first;
|
|
|
|
if (Processed.count(IV))
|
2010-05-21 03:57:06 +08:00
|
|
|
continue;
|
2010-03-16 02:33:46 +08:00
|
|
|
|
2015-04-16 06:29:27 +08:00
|
|
|
// Instruction ranges, specifying where IV is accessible.
|
2014-05-28 07:09:50 +08:00
|
|
|
const auto &Ranges = I.second;
|
|
|
|
if (Ranges.empty())
|
2011-03-26 10:19:36 +08:00
|
|
|
continue;
|
2010-05-26 07:40:22 +08:00
|
|
|
|
2014-04-24 14:44:33 +08:00
|
|
|
LexicalScope *Scope = nullptr;
|
2015-04-30 00:38:44 +08:00
|
|
|
if (const DILocation *IA = IV.second)
|
2015-04-16 06:29:27 +08:00
|
|
|
Scope = LScopes.findInlinedScope(IV.first->getScope(), IA);
|
2015-02-17 08:02:27 +08:00
|
|
|
else
|
2015-04-16 06:29:27 +08:00
|
|
|
Scope = LScopes.findLexicalScope(IV.first->getScope());
|
2010-05-21 03:57:06 +08:00
|
|
|
// If variable scope is not found then skip this variable.
|
2010-05-21 08:10:20 +08:00
|
|
|
if (!Scope)
|
2010-05-21 03:57:06 +08:00
|
|
|
continue;
|
|
|
|
|
2015-04-16 06:29:27 +08:00
|
|
|
Processed.insert(IV);
|
AsmPrinter: Rewrite initialization of DbgVariable, NFC
There are three types of `DbgVariable`:
- alloca variables, created based on the MMI table,
- register variables, created based on DBG_VALUE instructions, and
- optimized-out variables.
This commit reconfigures `DbgVariable` to make it easier to tell which
kind we have, and make initialization a little clearer.
For MMI/alloca variables, `FrameIndex.size()` must always equal
`Expr.size()`, and there shouldn't be an `MInsn`. For register
variables (with a `MInsn`), `FrameIndex` must be empty, and `Expr`
should have 0 or 1 element depending on whether it has a complex
expression (registers with multiple locations use `DebugLocListIndex`).
Optimized-out variables shouldn't have any of these fields.
Moreover, this separates DBG_VALUE initialization until after the
variable is created, simplifying logic in a future commit that changes
`collectVariableInfo()` to stop creating empty .debug_loc entries/lists.
llvm-svn: 240243
2015-06-22 00:50:43 +08:00
|
|
|
DbgVariable *RegVar = createConcreteVariable(*Scope, IV);
|
|
|
|
|
2014-05-28 07:09:50 +08:00
|
|
|
const MachineInstr *MInsn = Ranges.front().first;
|
2011-03-26 10:19:36 +08:00
|
|
|
assert(MInsn->isDebugValue() && "History must begin with debug value");
|
|
|
|
|
2016-03-01 03:49:46 +08:00
|
|
|
// Check if there is a single DBG_VALUE, valid throughout the function.
|
|
|
|
// A single constant is also considered valid for the entire function.
|
|
|
|
if (Ranges.size() == 1 &&
|
|
|
|
(MInsn->getOperand(0).isImm() ||
|
|
|
|
(validAtEntry(MInsn) && Ranges.front().second == nullptr))) {
|
2015-06-22 00:54:56 +08:00
|
|
|
RegVar->initializeDbgValue(MInsn);
|
2010-05-26 07:40:22 +08:00
|
|
|
continue;
|
2015-06-22 00:54:56 +08:00
|
|
|
}
|
2010-05-26 07:40:22 +08:00
|
|
|
|
2013-01-29 01:33:26 +08:00
|
|
|
// Handle multiple DBG_VALUE instructions describing one variable.
|
2015-06-22 00:54:56 +08:00
|
|
|
DebugLocStream::ListBuilder List(DebugLocs, TheCU, *Asm, *RegVar, *MInsn);
|
2014-08-02 06:11:58 +08:00
|
|
|
|
|
|
|
// Build the location list for this variable.
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
SmallVector<DebugLocEntry, 8> Entries;
|
|
|
|
buildLocationList(Entries, Ranges);
|
2015-04-18 00:28:58 +08:00
|
|
|
|
2016-03-01 01:06:46 +08:00
|
|
|
// If the variable has a DIBasicType, extract it. Basic types cannot have
|
2015-04-18 00:28:58 +08:00
|
|
|
// unique identifiers, so don't bother resolving the type with the
|
|
|
|
// identifier map.
|
2015-04-30 00:38:44 +08:00
|
|
|
const DIBasicType *BT = dyn_cast<DIBasicType>(
|
2015-04-18 00:28:58 +08:00
|
|
|
static_cast<const Metadata *>(IV.first->getType()));
|
|
|
|
|
2015-03-03 06:02:33 +08:00
|
|
|
// Finalize the entry by lowering it into a DWARF bytestream.
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
for (auto &Entry : Entries)
|
2015-06-22 00:54:56 +08:00
|
|
|
Entry.finalize(*Asm, List, BT);
|
2010-03-16 02:33:46 +08:00
|
|
|
}
|
2010-05-15 05:01:35 +08:00
|
|
|
|
|
|
|
// Collect info for variables that were optimized out.
|
2015-04-30 00:38:44 +08:00
|
|
|
for (const DILocalVariable *DV : SP->getVariables()) {
|
AsmPrinter: Rewrite initialization of DbgVariable, NFC
There are three types of `DbgVariable`:
- alloca variables, created based on the MMI table,
- register variables, created based on DBG_VALUE instructions, and
- optimized-out variables.
This commit reconfigures `DbgVariable` to make it easier to tell which
kind we have, and make initialization a little clearer.
For MMI/alloca variables, `FrameIndex.size()` must always equal
`Expr.size()`, and there shouldn't be an `MInsn`. For register
variables (with a `MInsn`), `FrameIndex` must be empty, and `Expr`
should have 0 or 1 element depending on whether it has a complex
expression (registers with multiple locations use `DebugLocListIndex`).
Optimized-out variables shouldn't have any of these fields.
Moreover, this separates DBG_VALUE initialization until after the
variable is created, simplifying logic in a future commit that changes
`collectVariableInfo()` to stop creating empty .debug_loc entries/lists.
llvm-svn: 240243
2015-06-22 00:50:43 +08:00
|
|
|
if (Processed.insert(InlinedVariable(DV, nullptr)).second)
|
|
|
|
if (LexicalScope *Scope = LScopes.findLexicalScope(DV->getScope()))
|
|
|
|
createConcreteVariable(*Scope, InlinedVariable(DV, nullptr));
|
2010-05-15 05:01:35 +08:00
|
|
|
}
|
2010-05-26 07:40:22 +08:00
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Process beginning of an instruction.
|
2010-10-27 01:49:02 +08:00
|
|
|
void DwarfDebug::beginInstruction(const MachineInstr *MI) {
|
2016-02-11 04:55:49 +08:00
|
|
|
DebugHandlerBase::beginInstruction(MI);
|
|
|
|
assert(CurMI);
|
|
|
|
|
2016-12-10 03:15:32 +08:00
|
|
|
// Check if source location changes, but ignore DBG_VALUE and CFI locations.
|
|
|
|
if (MI->isDebugValue() || MI->isCFIInstruction())
|
2016-11-23 03:46:51 +08:00
|
|
|
return;
|
|
|
|
const DebugLoc &DL = MI->getDebugLoc();
|
2016-12-13 04:49:11 +08:00
|
|
|
// When we emit a line-0 record, we don't update PrevInstLoc; so look at
|
|
|
|
// the last line number actually emitted, to see if it was line 0.
|
|
|
|
unsigned LastAsmLine =
|
|
|
|
Asm->OutStreamer->getContext().getCurrentDwarfLoc().getLine();
|
|
|
|
|
|
|
|
if (DL == PrevInstLoc) {
|
|
|
|
// If we have an ongoing unspecified location, nothing to do here.
|
|
|
|
if (!DL)
|
|
|
|
return;
|
|
|
|
// We have an explicit location, same as the previous location.
|
|
|
|
// But we might be coming back to it after a line 0 record.
|
|
|
|
if (LastAsmLine == 0 && DL.getLine() != 0) {
|
|
|
|
// Reinstate the source location but not marked as a statement.
|
|
|
|
const MDNode *Scope = DL.getScope();
|
|
|
|
recordSourceLine(DL.getLine(), DL.getCol(), Scope, /*Flags=*/0);
|
|
|
|
}
|
2016-11-23 03:46:51 +08:00
|
|
|
return;
|
2016-12-13 04:49:11 +08:00
|
|
|
}
|
2016-11-23 03:46:51 +08:00
|
|
|
|
|
|
|
if (!DL) {
|
|
|
|
// We have an unspecified location, which might want to be line 0.
|
2016-12-13 04:49:11 +08:00
|
|
|
// If we have already emitted a line-0 record, don't repeat it.
|
|
|
|
if (LastAsmLine == 0)
|
|
|
|
return;
|
|
|
|
// If user said Don't Do That, don't do that.
|
|
|
|
if (UnknownLocations == Disable)
|
|
|
|
return;
|
|
|
|
// See if we have a reason to emit a line-0 record now.
|
|
|
|
// Reasons to emit a line-0 record include:
|
|
|
|
// - User asked for it (UnknownLocations).
|
|
|
|
// - Instruction has a label, so it's referenced from somewhere else,
|
|
|
|
// possibly debug information; we want it to have a source location.
|
|
|
|
// - Instruction is at the top of a block; we don't want to inherit the
|
|
|
|
// location from the physically previous (maybe unrelated) block.
|
|
|
|
if (UnknownLocations == Enable || PrevLabel ||
|
|
|
|
(PrevInstBB && PrevInstBB != MI->getParent())) {
|
2016-12-14 08:27:35 +08:00
|
|
|
// Preserve the file and column numbers, if we can, to save space in
|
|
|
|
// the encoded line table.
|
2016-12-13 04:49:11 +08:00
|
|
|
// Do not update PrevInstLoc, it remembers the last non-0 line.
|
2016-12-14 08:27:35 +08:00
|
|
|
const MDNode *Scope = nullptr;
|
|
|
|
unsigned Column = 0;
|
|
|
|
if (PrevInstLoc) {
|
|
|
|
Scope = PrevInstLoc.getScope();
|
|
|
|
Column = PrevInstLoc.getCol();
|
|
|
|
}
|
|
|
|
recordSourceLine(/*Line=*/0, Column, Scope, /*Flags=*/0);
|
2011-03-26 01:20:59 +08:00
|
|
|
}
|
2016-11-23 03:46:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-13 04:49:11 +08:00
|
|
|
// We have an explicit location, different from the previous location.
|
|
|
|
// Don't repeat a line-0 record, but otherwise emit the new location.
|
|
|
|
// (The new location might be an explicit line 0, which we do emit.)
|
2016-12-17 07:54:33 +08:00
|
|
|
if (PrevInstLoc && DL.getLine() == 0 && LastAsmLine == 0)
|
2016-12-13 04:49:11 +08:00
|
|
|
return;
|
2016-11-23 03:46:51 +08:00
|
|
|
unsigned Flags = 0;
|
|
|
|
if (DL == PrologEndLoc) {
|
|
|
|
Flags |= DWARF2_FLAG_PROLOGUE_END | DWARF2_FLAG_IS_STMT;
|
|
|
|
PrologEndLoc = DebugLoc();
|
2010-05-27 03:37:24 +08:00
|
|
|
}
|
2016-12-13 04:49:11 +08:00
|
|
|
// If the line changed, we call that a new statement; unless we went to
|
|
|
|
// line 0 and came back, in which case it is not a new statement.
|
|
|
|
unsigned OldLine = PrevInstLoc ? PrevInstLoc.getLine() : LastAsmLine;
|
|
|
|
if (DL.getLine() && DL.getLine() != OldLine)
|
2016-11-23 03:46:51 +08:00
|
|
|
Flags |= DWARF2_FLAG_IS_STMT;
|
|
|
|
|
|
|
|
const MDNode *Scope = DL.getScope();
|
|
|
|
recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags);
|
2016-12-13 04:49:11 +08:00
|
|
|
|
|
|
|
// If we're not at line 0, remember this location.
|
|
|
|
if (DL.getLine())
|
|
|
|
PrevInstLoc = DL;
|
2009-10-02 04:31:14 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 06:47:41 +08:00
|
|
|
static DebugLoc findPrologueEndLoc(const MachineFunction *MF) {
|
|
|
|
// First known non-DBG_VALUE and non-frame setup location marks
|
|
|
|
// the beginning of the function body.
|
|
|
|
for (const auto &MBB : *MF)
|
|
|
|
for (const auto &MI : MBB)
|
|
|
|
if (!MI.isDebugValue() && !MI.getFlag(MachineInstr::FrameSetup) &&
|
2015-10-08 15:48:49 +08:00
|
|
|
MI.getDebugLoc())
|
2014-05-28 06:47:41 +08:00
|
|
|
return MI.getDebugLoc();
|
|
|
|
return DebugLoc();
|
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Gather pre-function debug information. Assumes being called immediately
|
|
|
|
// after the function entry point has been emitted.
|
2017-02-17 02:48:33 +08:00
|
|
|
void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
|
2013-12-03 23:10:23 +08:00
|
|
|
CurFn = MF;
|
2013-11-02 07:14:17 +08:00
|
|
|
|
2014-03-21 03:16:16 +08:00
|
|
|
if (LScopes.empty())
|
2013-11-02 07:14:17 +08:00
|
|
|
return;
|
|
|
|
|
2013-12-10 07:57:44 +08:00
|
|
|
// Set DwarfDwarfCompileUnitID in MCContext to the Compile Unit this function
|
2013-11-02 07:14:17 +08:00
|
|
|
// belongs to so that we add to the correct per-cu line table in the
|
|
|
|
// non-asm case.
|
2013-02-06 05:52:47 +08:00
|
|
|
LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
|
Recommit r212203: Don't try to construct debug LexicalScopes hierarchy for functions that do not have top level debug information.
Reverted by Eric Christopher (Thanks!) in r212203 after Bob Wilson
reported LTO issues. Duncan Exon Smith and Aditya Nandakumar helped
provide a reduced reproduction, though the failure wasn't too hard to
guess, and even easier with the example to confirm.
The assertion that the subprogram metadata associated with an
llvm::Function matches the scope data referenced by the DbgLocs on the
instructions in that function is not valid under LTO. In LTO, a C++
inline function might exist in multiple CUs and the subprogram metadata
nodes will refer to the same llvm::Function. In this case, depending on
the order of the CUs, the first intance of the subprogram metadata may
not be the one referenced by the instructions in that function and the
assertion will fail.
A test case (test/DebugInfo/cross-cu-linkonce-distinct.ll) is added, the
assertion removed and a comment added to explain this situation.
This was then reverted again in r213581 as it caused PR20367. The root
cause of this was the early exit in LiveDebugVariables meant that
spurious DBG_VALUE intrinsics that referenced dead variables were not
removed, causing an assertion/crash later on. The fix is to have
LiveDebugVariables strip all DBG_VALUE intrinsics in functions without
debug info as they're not needed anyway. Test case added to cover this
situation (that occurs when a debug-having function is inlined into a
nodebug function) in test/DebugInfo/X86/nodebug_with_debug_loc.ll
Original commit message:
If a function isn't actually in a CU's subprogram list in the debug info
metadata, ignore all the DebugLocs and don't try to build scopes, track
variables, etc.
While this is possibly a minor optimization, it's also a correctness fix
for an incoming patch that will add assertions to LexicalScopes and the
debug info verifier to ensure that all scope chains lead to debug info
for the current function.
Fix up a few test cases that had broken/incomplete debug info that could
violate this constraint.
Add a test case where this occurs by design (inlining a
debug-info-having function in an attribute nodebug function - we want
this to work because /if/ the nodebug function is then inlined into a
debug-info-having function, it should be fine (and will work fine - we
just stitch the scopes up as usual), but should the inlining not happen
we need to not assert fail either).
llvm-svn: 213952
2014-07-26 00:10:16 +08:00
|
|
|
// FnScope->getScopeNode() and DI->second should represent the same function,
|
|
|
|
// though they may not be the same MDNode due to inline functions merged in
|
|
|
|
// LTO where the debug info metadata still differs (either due to distinct
|
|
|
|
// written differences - two versions of a linkonce_odr function
|
|
|
|
// written/copied into two separate files, or some sub-optimal metadata that
|
|
|
|
// isn't structurally identical (see: file path/name info from clang, which
|
|
|
|
// includes the directory of the cpp file being built, even when the file name
|
|
|
|
// is absolute (such as an <> lookup header)))
|
2016-04-15 23:57:41 +08:00
|
|
|
auto *SP = cast<DISubprogram>(FnScope->getScopeNode());
|
|
|
|
DwarfCompileUnit *TheCU = CUMap.lookup(SP->getUnit());
|
|
|
|
if (!TheCU) {
|
|
|
|
assert(SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug &&
|
|
|
|
"DICompileUnit missing from llvm.dbg.cu?");
|
2016-04-09 06:43:03 +08:00
|
|
|
return;
|
2016-04-15 23:57:41 +08:00
|
|
|
}
|
2015-04-25 03:11:51 +08:00
|
|
|
if (Asm->OutStreamer->hasRawTextSupport())
|
2014-02-06 02:00:21 +08:00
|
|
|
// Use a single line table if we are generating assembly.
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->getContext().setDwarfCompileUnitID(0);
|
2013-05-21 08:57:22 +08:00
|
|
|
else
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->getContext().setDwarfCompileUnitID(TheCU->getUniqueID());
|
2013-02-06 05:52:47 +08:00
|
|
|
|
2011-05-12 03:22:19 +08:00
|
|
|
// Record beginning of function.
|
2014-05-28 06:47:41 +08:00
|
|
|
PrologEndLoc = findPrologueEndLoc(MF);
|
2015-04-30 00:38:44 +08:00
|
|
|
if (DILocation *L = PrologEndLoc) {
|
2015-01-25 04:19:45 +08:00
|
|
|
// We'd like to list the prologue as "not statements" but GDB behaves
|
|
|
|
// poorly if we do that. Revisit this with caution/GDB (7.5+) testing.
|
2015-03-31 05:32:28 +08:00
|
|
|
auto *SP = L->getInlinedAtScope()->getSubprogram();
|
|
|
|
recordSourceLine(SP->getScopeLine(), 0, SP, DWARF2_FLAG_IS_STMT);
|
2011-05-12 03:22:19 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2017-02-17 02:48:33 +08:00
|
|
|
void DwarfDebug::skippedNonDebugFunction() {
|
|
|
|
// If we don't have a subprogram for this function then there will be a hole
|
|
|
|
// in the range information. Keep note of this by setting the previously used
|
|
|
|
// section to nullptr.
|
|
|
|
PrevCU = nullptr;
|
|
|
|
CurFn = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Gather and emit post-function debug information.
|
2017-02-17 02:48:33 +08:00
|
|
|
void DwarfDebug::endFunctionImpl(const MachineFunction *MF) {
|
|
|
|
const DISubprogram *SP = MF->getFunction()->getSubprogram();
|
|
|
|
|
2014-10-15 01:12:02 +08:00
|
|
|
assert(CurFn == MF &&
|
|
|
|
"endFunction should be called with the same function as beginFunction");
|
2013-12-03 23:10:23 +08:00
|
|
|
|
2013-12-10 07:57:44 +08:00
|
|
|
// Set DwarfDwarfCompileUnitID in MCContext to default value.
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->getContext().setDwarfCompileUnitID(0);
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2011-08-16 06:04:40 +08:00
|
|
|
LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
|
2016-12-16 07:17:52 +08:00
|
|
|
assert(!FnScope || SP == FnScope->getScopeNode());
|
2016-04-15 23:57:41 +08:00
|
|
|
DwarfCompileUnit &TheCU = *CUMap.lookup(SP->getUnit());
|
2014-10-23 08:06:27 +08:00
|
|
|
|
2015-04-16 06:29:27 +08:00
|
|
|
DenseSet<InlinedVariable> ProcessedVars;
|
2014-10-23 08:06:27 +08:00
|
|
|
collectVariableInfo(TheCU, SP, ProcessedVars);
|
2011-08-16 06:04:40 +08:00
|
|
|
|
2014-09-20 01:03:16 +08:00
|
|
|
// Add the range of this function to the list of ranges for the CU.
|
2015-03-05 10:05:42 +08:00
|
|
|
TheCU.addRange(RangeSpan(Asm->getFunctionBegin(), Asm->getFunctionEnd()));
|
2014-09-20 01:03:16 +08:00
|
|
|
|
|
|
|
// Under -gmlt, skip building the subprogram if there are no inlined
|
2017-01-19 08:44:11 +08:00
|
|
|
// subroutines inside it. But with -fdebug-info-for-profiling, the subprogram
|
|
|
|
// is still needed as we need its source location.
|
Change debug-info-for-profiling from a TargetOption to a function attribute.
Summary: LTO requires the debug-info-for-profiling to be a function attribute.
Reviewers: echristo, mehdi_amini, dblaikie, probinson, aprantl
Reviewed By: mehdi_amini, dblaikie, aprantl
Subscribers: aprantl, probinson, ahatanak, llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D29203
llvm-svn: 293833
2017-02-02 06:45:09 +08:00
|
|
|
if (!TheCU.getCUNode()->getDebugInfoForProfiling() &&
|
2017-01-19 08:44:11 +08:00
|
|
|
TheCU.getCUNode()->getEmissionKind() == DICompileUnit::LineTablesOnly &&
|
Disable the -gmlt optimization implemented in r218129 under Darwin due to issues with dsymutil.
r218129 omits DW_TAG_subprograms which have no inlined subroutines when
emitting -gmlt data. This makes -gmlt very low cost for -O0 builds.
Darwin's dsymutil reasonably considers a CU empty if it has no
subprograms (which occurs with the above optimization in -O0 programs
without any force_inline function calls) and drops the line table, CU,
and everything in this situation, making backtraces impossible.
Until dsymutil is modified to account for this, disable this
optimization on Darwin to preserve the desired functionality.
(see r218545, which should be reverted after this patch, for other
discussion/details)
Footnote:
In the long term, it doesn't look like this scheme (of simplified debug
info to describe inlining to enable backtracing) is tenable, it is far
too size inefficient for optimized code (the DW_TAG_inlined_subprograms,
even once compressed, are nearly twice as large as the line table
itself (also compressed)) and we'll be considering things like Cary's
two level line table proposal to encode all this information directly in
the line table.
llvm-svn: 218702
2014-10-01 05:28:32 +08:00
|
|
|
LScopes.getAbstractScopesList().empty() && !IsDarwin) {
|
2014-10-25 01:57:34 +08:00
|
|
|
assert(InfoHolder.getScopeVariables().empty());
|
2014-09-20 01:03:16 +08:00
|
|
|
PrevLabel = nullptr;
|
|
|
|
CurFn = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-14 04:44:58 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
size_t NumAbstractScopes = LScopes.getAbstractScopesList().size();
|
|
|
|
#endif
|
2011-08-11 04:55:27 +08:00
|
|
|
// Construct abstract scopes.
|
2014-03-08 03:09:39 +08:00
|
|
|
for (LexicalScope *AScope : LScopes.getAbstractScopesList()) {
|
2015-04-30 00:38:44 +08:00
|
|
|
auto *SP = cast<DISubprogram>(AScope->getScopeNode());
|
2014-05-13 02:23:35 +08:00
|
|
|
// Collect info for variables that were optimized out.
|
2015-04-30 00:38:44 +08:00
|
|
|
for (const DILocalVariable *DV : SP->getVariables()) {
|
2015-04-16 06:29:27 +08:00
|
|
|
if (!ProcessedVars.insert(InlinedVariable(DV, nullptr)).second)
|
2014-05-13 02:23:35 +08:00
|
|
|
continue;
|
2015-04-16 06:29:27 +08:00
|
|
|
ensureAbstractVariableIsCreated(InlinedVariable(DV, nullptr),
|
|
|
|
DV->getScope());
|
2014-10-14 04:44:58 +08:00
|
|
|
assert(LScopes.getAbstractScopesList().size() == NumAbstractScopes
|
|
|
|
&& "ensureAbstractVariableIsCreated inserted abstract scopes");
|
2010-06-26 06:07:34 +08:00
|
|
|
}
|
2014-10-10 04:36:27 +08:00
|
|
|
constructAbstractSubprogramScopeDIE(AScope);
|
2011-08-11 04:55:27 +08:00
|
|
|
}
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2016-12-16 07:37:38 +08:00
|
|
|
ProcessedSPNodes.insert(SP);
|
2016-12-16 07:17:52 +08:00
|
|
|
TheCU.constructSubprogramScopeDIE(SP, FnScope);
|
Provide gmlt-like inline scope information in the skeleton CU to facilitate symbolication without needing the .dwo files
Clang -gsplit-dwarf self-host -O0, binary increases by 0.0005%, -O2,
binary increases by 25%.
A large binary inside Google, split-dwarf, -O0, and other internal flags
(GDB index, etc) increases by 1.8%, optimized build is 35%.
The size impact may be somewhat greater in .o files (I haven't measured
that much - since the linked executable -O0 numbers seemed low enough)
due to relocations. These relocations could be removed if we taught the
llvm-symbolizer to handle indexed addressing in the .o file (GDB can't
cope with this just yet, but GDB won't be reading this info anyway).
Also debug_ranges could be shared between .o and .dwo, though ideally
debug_ranges would get a schema that could used index(+offset)
addressing, and move to the .dwo file, then we'd be back to sharing
addresses in the address pool again.
But for now, these sizes seem small enough to go ahead with this.
Verified that no other DW_TAGs are produced into the .o file other than
subprograms and inlined_subroutines.
llvm-svn: 221306
2014-11-05 06:12:25 +08:00
|
|
|
if (auto *SkelCU = TheCU.getSkeleton())
|
2016-08-25 02:29:49 +08:00
|
|
|
if (!LScopes.getAbstractScopesList().empty() &&
|
|
|
|
TheCU.getCUNode()->getSplitDebugInlining())
|
2016-12-16 07:17:52 +08:00
|
|
|
SkelCU->constructSubprogramScopeDIE(SP, FnScope);
|
2011-08-16 06:04:40 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Clear debug info
|
2014-05-22 06:41:17 +08:00
|
|
|
// Ownership of DbgVariables is a bit subtle - ScopeVariables owns all the
|
|
|
|
// DbgVariables except those that are also in AbstractVariables (since they
|
|
|
|
// can be used cross-function)
|
2014-10-25 01:57:34 +08:00
|
|
|
InfoHolder.getScopeVariables().clear();
|
2014-04-24 14:44:33 +08:00
|
|
|
PrevLabel = nullptr;
|
|
|
|
CurFn = nullptr;
|
2009-05-21 07:19:06 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Register a source line with debug info. Returns the unique label that was
|
|
|
|
// emitted and which provides correspondence to the source line list.
|
2011-05-12 03:22:19 +08:00
|
|
|
void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
|
|
|
|
unsigned Flags) {
|
2009-11-26 01:36:49 +08:00
|
|
|
StringRef Fn;
|
2011-03-25 04:30:50 +08:00
|
|
|
StringRef Dir;
|
2010-05-06 07:41:32 +08:00
|
|
|
unsigned Src = 1;
|
2014-03-04 02:53:17 +08:00
|
|
|
unsigned Discriminator = 0;
|
2015-04-30 00:38:44 +08:00
|
|
|
if (auto *Scope = cast_or_null<DIScope>(S)) {
|
2015-04-16 09:37:00 +08:00
|
|
|
Fn = Scope->getFilename();
|
|
|
|
Dir = Scope->getDirectory();
|
2015-04-30 00:38:44 +08:00
|
|
|
if (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope))
|
2016-11-24 07:30:37 +08:00
|
|
|
if (getDwarfVersion() >= 4)
|
2016-10-07 23:21:31 +08:00
|
|
|
Discriminator = LBF->getDiscriminator();
|
2010-05-06 07:41:32 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
unsigned CUID = Asm->OutStreamer->getContext().getDwarfCompileUnitID();
|
2014-04-23 05:27:37 +08:00
|
|
|
Src = static_cast<DwarfCompileUnit &>(*InfoHolder.getUnits()[CUID])
|
|
|
|
.getOrCreateSourceID(Fn, Dir);
|
2010-05-06 07:41:32 +08:00
|
|
|
}
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->EmitDwarfLocDirective(Src, Line, Col, Flags, 0,
|
|
|
|
Discriminator, Fn);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2009-05-21 07:22:40 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Emit Methods
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-01 07:59:06 +08:00
|
|
|
// Emit the debug info section.
|
|
|
|
void DwarfDebug::emitDebugInfo() {
|
2013-12-06 02:06:10 +08:00
|
|
|
DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
|
2015-03-11 00:58:10 +08:00
|
|
|
Holder.emitUnits(/* UseOffsets */ false);
|
2012-12-01 07:59:06 +08:00
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Emit the abbreviation section.
|
2012-11-21 07:30:11 +08:00
|
|
|
void DwarfDebug::emitAbbreviations() {
|
2013-12-06 02:06:10 +08:00
|
|
|
DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
|
2013-12-05 15:43:55 +08:00
|
|
|
|
|
|
|
Holder.emitAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevSection());
|
2012-12-20 06:02:53 +08:00
|
|
|
}
|
|
|
|
|
2015-05-22 03:20:38 +08:00
|
|
|
void DwarfDebug::emitAccel(DwarfAccelTable &Accel, MCSection *Section,
|
2015-03-11 06:00:25 +08:00
|
|
|
StringRef TableName) {
|
2014-09-12 05:12:48 +08:00
|
|
|
Accel.FinalizeTable(Asm, TableName);
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->SwitchSection(Section);
|
2011-11-07 17:24:32 +08:00
|
|
|
|
|
|
|
// Emit the full data.
|
2015-03-11 00:58:10 +08:00
|
|
|
Accel.emit(Asm, Section->getBeginSymbol(), this);
|
2014-09-12 05:12:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Emit visible names into a hashed accelerator table section.
|
|
|
|
void DwarfDebug::emitAccelNames() {
|
|
|
|
emitAccel(AccelNames, Asm->getObjFileLowering().getDwarfAccelNamesSection(),
|
2015-03-11 06:00:25 +08:00
|
|
|
"Names");
|
2011-11-07 17:24:32 +08:00
|
|
|
}
|
|
|
|
|
2012-12-21 05:58:40 +08:00
|
|
|
// Emit objective C classes and categories into a hashed accelerator table
|
|
|
|
// section.
|
2011-11-07 17:24:32 +08:00
|
|
|
void DwarfDebug::emitAccelObjC() {
|
2014-09-12 05:12:48 +08:00
|
|
|
emitAccel(AccelObjC, Asm->getObjFileLowering().getDwarfAccelObjCSection(),
|
2015-03-11 06:00:25 +08:00
|
|
|
"ObjC");
|
2011-11-07 17:24:32 +08:00
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Emit namespace dies into a hashed accelerator table.
|
2011-11-07 17:24:32 +08:00
|
|
|
void DwarfDebug::emitAccelNamespaces() {
|
2014-09-12 05:12:48 +08:00
|
|
|
emitAccel(AccelNamespace,
|
|
|
|
Asm->getObjFileLowering().getDwarfAccelNamespaceSection(),
|
2015-03-11 06:00:25 +08:00
|
|
|
"namespac");
|
2011-11-07 17:24:32 +08:00
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Emit type dies into a hashed accelerator table.
|
2011-11-07 17:24:32 +08:00
|
|
|
void DwarfDebug::emitAccelTypes() {
|
2014-09-12 05:12:48 +08:00
|
|
|
emitAccel(AccelTypes, Asm->getObjFileLowering().getDwarfAccelTypesSection(),
|
2015-03-11 06:00:25 +08:00
|
|
|
"types");
|
2011-11-07 17:24:32 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 08:35:05 +08:00
|
|
|
// Public name handling.
|
|
|
|
// The format for the various pubnames:
|
|
|
|
//
|
|
|
|
// dwarf pubnames - offset/name pairs where the offset is the offset into the CU
|
|
|
|
// for the DIE that is named.
|
|
|
|
//
|
|
|
|
// gnu pubnames - offset/index value/name tuples where the offset is the offset
|
|
|
|
// into the CU and the index value is computed according to the type of value
|
|
|
|
// for the DIE that is named.
|
|
|
|
//
|
|
|
|
// For type units the offset is the offset of the skeleton DIE. For split dwarf
|
|
|
|
// it's the offset within the debug_info/debug_types dwo section, however, the
|
|
|
|
// reference in the pubname header doesn't change.
|
|
|
|
|
|
|
|
/// computeIndexValue - Compute the gdb index value for the DIE and CU.
|
2013-12-10 07:32:48 +08:00
|
|
|
static dwarf::PubIndexEntryDescriptor computeIndexValue(DwarfUnit *CU,
|
2013-11-21 08:48:22 +08:00
|
|
|
const DIE *Die) {
|
2017-02-03 08:44:18 +08:00
|
|
|
// Entities that ended up only in a Type Unit reference the CU instead (since
|
|
|
|
// the pub entry has offsets within the CU there's no real offset that can be
|
|
|
|
// provided anyway). As it happens all such entities (namespaces and types,
|
|
|
|
// types only in C++ at that) are rendered as TYPE+EXTERNAL. If this turns out
|
|
|
|
// not to be true it would be necessary to persist this information from the
|
|
|
|
// point at which the entry is added to the index data structure - since by
|
|
|
|
// the time the index is built from that, the original type/namespace DIE in a
|
|
|
|
// type unit has already been destroyed so it can't be queried for properties
|
|
|
|
// like tag, etc.
|
|
|
|
if (Die->getTag() == dwarf::DW_TAG_compile_unit)
|
|
|
|
return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_TYPE,
|
|
|
|
dwarf::GIEL_EXTERNAL);
|
2013-10-16 09:37:49 +08:00
|
|
|
dwarf::GDBIndexEntryLinkage Linkage = dwarf::GIEL_STATIC;
|
|
|
|
|
|
|
|
// We could have a specification DIE that has our most of our knowledge,
|
|
|
|
// look for that now.
|
Reapply "AsmPrinter: Change DIEValue to be stored by value"
This reverts commit r238350, effectively reapplying r238349 after fixing
(all?) the problems, all somehow related to how I was using
`AlignedArrayCharUnion<>` inside `DIEValue`:
- MSVC can only handle `sizeof()` on types, not values. Change the
assert.
- GCC doesn't know the `is_trivially_copyable` type trait. Instead of
asserting it, add destructors.
- Call placement new even when constructing POD (i.e., the pointers).
- Instead of copying the char buffer, copy the casted classes.
I've left in a couple of `static_assert`s that I think both MSVC and GCC
know how to handle. If the bots disagree with me, I'll remove them.
- Check that the constructed type is either standard layout or a
pointer. This protects against a programming error: we really want
the "small" `DIEValue`s to be small and simple, so don't
accidentally change them not to be.
- Similarly, check that the size of the buffer is no bigger than a
`uint64_t` or a pointer. (I thought checking against
`sizeof(uint64_t)` would be good enough, but Chandler suggested that
pointers might sometimes be bigger than that in the context of
sanitizers.)
I've also committed r238359 in the meantime, which introduces a
DIEValue.def to simplify dispatching between the various types (thanks
to a review comment by David Blaikie). Without that, this commit would
be almost unintelligible.
Here's the original commit message:
--
Change `DIEValue` to be stored/passed/etc. by value, instead of
reference. It's now a discriminated union, with a `Val` field storing
the actual type. The classes that used to inherit from `DIEValue` no
longer do. There are two categories of these:
- Small values fit in a single pointer and are stored by value.
- Large values require auxiliary storage, and are stored by reference.
The only non-mechanical change is to tools/dsymutil/DwarfLinker.cpp. It
was relying on `DIEInteger`s being passed around by reference, so I
replaced that assumption with a `PatchLocation` type that stores a safe
reference to where the `DIEInteger` lives instead.
This commit causes a temporary regression in memory usage, since I've
left merging `DIEAbbrevData` into `DIEValue` for a follow-up commit. I
measured an increase from 845 MB to 879 MB, around 3.9%. The follow-up
drops it lower than the starting point, and I've only recently brought
the memory this low anyway, so I'm committing these changes separately
to keep them incremental. (I also considered swapping the commits, but
the other one first would cause a lot more code churn.)
(I'm looking at `llc` memory usage on `verify-uselistorder.lto.opt.bc`;
see r236629 for details.)
--
llvm-svn: 238362
2015-05-28 06:14:58 +08:00
|
|
|
if (DIEValue SpecVal = Die->findAttribute(dwarf::DW_AT_specification)) {
|
|
|
|
DIE &SpecDIE = SpecVal.getDIEEntry().getEntry();
|
2014-04-26 03:33:43 +08:00
|
|
|
if (SpecDIE.findAttribute(dwarf::DW_AT_external))
|
2013-10-16 09:37:49 +08:00
|
|
|
Linkage = dwarf::GIEL_EXTERNAL;
|
|
|
|
} else if (Die->findAttribute(dwarf::DW_AT_external))
|
|
|
|
Linkage = dwarf::GIEL_EXTERNAL;
|
2013-09-13 08:35:05 +08:00
|
|
|
|
|
|
|
switch (Die->getTag()) {
|
|
|
|
case dwarf::DW_TAG_class_type:
|
|
|
|
case dwarf::DW_TAG_structure_type:
|
|
|
|
case dwarf::DW_TAG_union_type:
|
|
|
|
case dwarf::DW_TAG_enumeration_type:
|
2013-09-24 04:55:35 +08:00
|
|
|
return dwarf::PubIndexEntryDescriptor(
|
|
|
|
dwarf::GIEK_TYPE, CU->getLanguage() != dwarf::DW_LANG_C_plus_plus
|
|
|
|
? dwarf::GIEL_STATIC
|
|
|
|
: dwarf::GIEL_EXTERNAL);
|
2013-09-13 08:35:05 +08:00
|
|
|
case dwarf::DW_TAG_typedef:
|
|
|
|
case dwarf::DW_TAG_base_type:
|
|
|
|
case dwarf::DW_TAG_subrange_type:
|
2013-09-20 04:40:26 +08:00
|
|
|
return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_TYPE, dwarf::GIEL_STATIC);
|
2013-09-13 08:35:05 +08:00
|
|
|
case dwarf::DW_TAG_namespace:
|
2013-09-20 04:40:26 +08:00
|
|
|
return dwarf::GIEK_TYPE;
|
2013-09-13 08:35:05 +08:00
|
|
|
case dwarf::DW_TAG_subprogram:
|
2013-09-24 06:59:14 +08:00
|
|
|
return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_FUNCTION, Linkage);
|
2013-09-13 08:35:05 +08:00
|
|
|
case dwarf::DW_TAG_variable:
|
2013-09-24 06:59:14 +08:00
|
|
|
return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_VARIABLE, Linkage);
|
2013-09-13 08:35:05 +08:00
|
|
|
case dwarf::DW_TAG_enumerator:
|
2013-09-20 04:40:26 +08:00
|
|
|
return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_VARIABLE,
|
|
|
|
dwarf::GIEL_STATIC);
|
2013-09-13 08:35:05 +08:00
|
|
|
default:
|
2013-09-20 04:40:26 +08:00
|
|
|
return dwarf::GIEK_NONE;
|
2013-09-13 08:35:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-10 04:03:17 +08:00
|
|
|
/// emitDebugPubNames - Emit visible names into a debug pubnames section.
|
2013-02-13 02:00:14 +08:00
|
|
|
///
|
2013-09-13 08:35:05 +08:00
|
|
|
void DwarfDebug::emitDebugPubNames(bool GnuStyle) {
|
2015-05-22 03:20:38 +08:00
|
|
|
MCSection *PSec = GnuStyle
|
|
|
|
? Asm->getObjFileLowering().getDwarfGnuPubNamesSection()
|
|
|
|
: Asm->getObjFileLowering().getDwarfPubNamesSection();
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2014-11-02 14:16:39 +08:00
|
|
|
emitDebugPubSection(GnuStyle, PSec, "Names",
|
|
|
|
&DwarfCompileUnit::getGlobalNames);
|
2014-03-12 07:18:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DwarfDebug::emitDebugPubSection(
|
2015-05-22 03:20:38 +08:00
|
|
|
bool GnuStyle, MCSection *PSec, StringRef Name,
|
2014-11-02 14:16:39 +08:00
|
|
|
const StringMap<const DIE *> &(DwarfCompileUnit::*Accessor)() const) {
|
2014-03-06 09:42:00 +08:00
|
|
|
for (const auto &NU : CUMap) {
|
|
|
|
DwarfCompileUnit *TheU = NU.second;
|
2014-03-12 07:23:39 +08:00
|
|
|
|
|
|
|
const auto &Globals = (TheU->*Accessor)();
|
|
|
|
|
2014-03-12 07:35:06 +08:00
|
|
|
if (Globals.empty())
|
|
|
|
continue;
|
|
|
|
|
2014-11-01 09:03:39 +08:00
|
|
|
if (auto *Skeleton = TheU->getSkeleton())
|
2014-03-06 09:42:00 +08:00
|
|
|
TheU = Skeleton;
|
2013-02-13 02:00:14 +08:00
|
|
|
|
|
|
|
// Start the dwarf pubnames section.
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->SwitchSection(PSec);
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2013-09-13 08:35:05 +08:00
|
|
|
// Emit the header.
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("Length of Public " + Name + " Info");
|
2015-03-18 04:07:06 +08:00
|
|
|
MCSymbol *BeginLabel = Asm->createTempSymbol("pub" + Name + "_begin");
|
|
|
|
MCSymbol *EndLabel = Asm->createTempSymbol("pub" + Name + "_end");
|
2013-12-05 01:55:41 +08:00
|
|
|
Asm->EmitLabelDifference(EndLabel, BeginLabel, 4);
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->EmitLabel(BeginLabel);
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("DWARF Version");
|
2013-08-21 14:13:34 +08:00
|
|
|
Asm->EmitInt16(dwarf::DW_PUBNAMES_VERSION);
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("Offset of Compilation Unit Info");
|
2015-06-17 07:22:02 +08:00
|
|
|
Asm->emitDwarfSymbolReference(TheU->getLabelBegin());
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("Compilation Unit Length");
|
2014-11-02 07:07:14 +08:00
|
|
|
Asm->EmitInt32(TheU->getLength());
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2013-09-13 08:35:05 +08:00
|
|
|
// Emit the pubnames for this compilation unit.
|
2014-03-12 07:23:39 +08:00
|
|
|
for (const auto &GI : Globals) {
|
2014-03-08 03:09:39 +08:00
|
|
|
const char *Name = GI.getKeyData();
|
|
|
|
const DIE *Entity = GI.second;
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("DIE offset");
|
2013-02-13 02:00:14 +08:00
|
|
|
Asm->EmitInt32(Entity->getOffset());
|
|
|
|
|
2013-09-13 08:35:05 +08:00
|
|
|
if (GnuStyle) {
|
2013-12-03 06:09:48 +08:00
|
|
|
dwarf::PubIndexEntryDescriptor Desc = computeIndexValue(TheU, Entity);
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment(
|
2013-09-20 08:33:15 +08:00
|
|
|
Twine("Kind: ") + dwarf::GDBIndexEntryKindString(Desc.Kind) + ", " +
|
2013-09-20 07:01:29 +08:00
|
|
|
dwarf::GDBIndexEntryLinkageString(Desc.Linkage));
|
2013-09-20 06:19:37 +08:00
|
|
|
Asm->EmitInt8(Desc.toBits());
|
2013-09-13 08:35:05 +08:00
|
|
|
}
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("External Name");
|
|
|
|
Asm->OutStreamer->EmitBytes(StringRef(Name, GI.getKeyLength() + 1));
|
2013-02-13 02:00:14 +08:00
|
|
|
}
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("End Mark");
|
2013-02-13 02:00:14 +08:00
|
|
|
Asm->EmitInt32(0);
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->EmitLabel(EndLabel);
|
2013-02-13 02:00:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-13 08:35:05 +08:00
|
|
|
void DwarfDebug::emitDebugPubTypes(bool GnuStyle) {
|
2015-05-22 03:20:38 +08:00
|
|
|
MCSection *PSec = GnuStyle
|
|
|
|
? Asm->getObjFileLowering().getDwarfGnuPubTypesSection()
|
|
|
|
: Asm->getObjFileLowering().getDwarfPubTypesSection();
|
2013-09-13 08:34:58 +08:00
|
|
|
|
2014-11-02 14:16:39 +08:00
|
|
|
emitDebugPubSection(GnuStyle, PSec, "Types",
|
|
|
|
&DwarfCompileUnit::getGlobalTypes);
|
2009-11-24 09:14:22 +08:00
|
|
|
}
|
|
|
|
|
2016-01-24 16:18:55 +08:00
|
|
|
/// Emit null-terminated strings into a debug str section.
|
2012-12-27 10:14:01 +08:00
|
|
|
void DwarfDebug::emitDebugStr() {
|
2013-12-06 02:06:10 +08:00
|
|
|
DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
|
2012-12-27 10:14:01 +08:00
|
|
|
Holder.emitStrings(Asm->getObjFileLowering().getDwarfStrSection());
|
|
|
|
}
|
|
|
|
|
2014-03-08 06:40:37 +08:00
|
|
|
void DwarfDebug::emitDebugLocEntry(ByteStreamer &Streamer,
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
const DebugLocStream::Entry &Entry) {
|
|
|
|
auto &&Comments = DebugLocs.getComments(Entry);
|
|
|
|
auto Comment = Comments.begin();
|
|
|
|
auto End = Comments.end();
|
|
|
|
for (uint8_t Byte : DebugLocs.getBytes(Entry))
|
2015-03-03 06:02:33 +08:00
|
|
|
Streamer.EmitInt8(Byte, Comment != End ? *(Comment++) : "");
|
2014-08-02 06:11:58 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
static void emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT,
|
2015-03-03 06:02:33 +08:00
|
|
|
ByteStreamer &Streamer,
|
|
|
|
const DebugLocEntry::Value &Value,
|
2016-12-10 04:43:40 +08:00
|
|
|
DwarfExpression &DwarfExpr) {
|
2016-11-03 00:12:20 +08:00
|
|
|
DIExpressionCursor ExprCursor(Value.getExpression());
|
2016-12-10 04:43:40 +08:00
|
|
|
DwarfExpr.addFragmentOffset(Value.getExpression());
|
2014-08-02 06:11:58 +08:00
|
|
|
// Regular entry.
|
2014-04-28 02:25:40 +08:00
|
|
|
if (Value.isInt()) {
|
2015-04-18 00:28:58 +08:00
|
|
|
if (BT && (BT->getEncoding() == dwarf::DW_ATE_signed ||
|
|
|
|
BT->getEncoding() == dwarf::DW_ATE_signed_char))
|
Debug Info: Move the complex expression handling (=the remainder) of
emitDebugLocValue() into DwarfExpression.
Ought to be NFC, but it actually uncovered a bug in the debug-loc-asan.ll
testcase. The testcase checks that the address of variable "y" is stored
at [RSP+16], which also lines up with the comment.
It also check(ed) that the *value* of "y" is stored in RDI before that,
but that is actually incorrect, since RDI is the very value that is
stored in [RSP+16]. Here's the assembler output:
movb 2147450880(%rcx), %r8b
#DEBUG_VALUE: bar:y <- RDI
cmpb $0, %r8b
movq %rax, 32(%rsp) # 8-byte Spill
movq %rsi, 24(%rsp) # 8-byte Spill
movq %rdi, 16(%rsp) # 8-byte Spill
.Ltmp3:
#DEBUG_VALUE: bar:y <- [RSP+16]
Fixed the comment to spell out the correct register and the check to
expect an address rather than a value.
Note that the range that is emitted for the RDI location was and is still
wrong, it claims to begin at the function prologue, but really it should
start where RDI is first assigned.
llvm-svn: 225851
2015-01-14 07:39:11 +08:00
|
|
|
DwarfExpr.AddSignedConstant(Value.getInt());
|
2015-01-13 08:04:06 +08:00
|
|
|
else
|
Debug Info: Move the complex expression handling (=the remainder) of
emitDebugLocValue() into DwarfExpression.
Ought to be NFC, but it actually uncovered a bug in the debug-loc-asan.ll
testcase. The testcase checks that the address of variable "y" is stored
at [RSP+16], which also lines up with the comment.
It also check(ed) that the *value* of "y" is stored in RDI before that,
but that is actually incorrect, since RDI is the very value that is
stored in [RSP+16]. Here's the assembler output:
movb 2147450880(%rcx), %r8b
#DEBUG_VALUE: bar:y <- RDI
cmpb $0, %r8b
movq %rax, 32(%rsp) # 8-byte Spill
movq %rsi, 24(%rsp) # 8-byte Spill
movq %rdi, 16(%rsp) # 8-byte Spill
.Ltmp3:
#DEBUG_VALUE: bar:y <- [RSP+16]
Fixed the comment to spell out the correct register and the check to
expect an address rather than a value.
Note that the range that is emitted for the RDI location was and is still
wrong, it claims to begin at the function prologue, but really it should
start where RDI is first assigned.
llvm-svn: 225851
2015-01-14 07:39:11 +08:00
|
|
|
DwarfExpr.AddUnsignedConstant(Value.getInt());
|
2014-04-28 02:25:40 +08:00
|
|
|
} else if (Value.isLocation()) {
|
|
|
|
MachineLocation Loc = Value.getLoc();
|
2016-12-10 04:43:40 +08:00
|
|
|
const TargetRegisterInfo &TRI = *AP.MF->getSubtarget().getRegisterInfo();
|
|
|
|
if (Loc.getOffset())
|
|
|
|
DwarfExpr.AddMachineRegIndirect(TRI, Loc.getReg(), Loc.getOffset());
|
|
|
|
else
|
|
|
|
DwarfExpr.AddMachineRegExpression(TRI, ExprCursor, Loc.getReg());
|
2016-04-08 08:38:37 +08:00
|
|
|
} else if (Value.isConstantFP()) {
|
|
|
|
APInt RawBytes = Value.getConstantFP()->getValueAPF().bitcastToAPInt();
|
|
|
|
DwarfExpr.AddUnsignedConstant(RawBytes);
|
2014-03-08 06:40:37 +08:00
|
|
|
}
|
2016-12-10 04:43:40 +08:00
|
|
|
DwarfExpr.AddExpression(std::move(ExprCursor));
|
2014-03-08 06:40:37 +08:00
|
|
|
}
|
|
|
|
|
2015-06-22 00:54:56 +08:00
|
|
|
void DebugLocEntry::finalize(const AsmPrinter &AP,
|
|
|
|
DebugLocStream::ListBuilder &List,
|
2015-04-30 00:38:44 +08:00
|
|
|
const DIBasicType *BT) {
|
2015-06-22 00:54:56 +08:00
|
|
|
DebugLocStream::EntryBuilder Entry(List, Begin, End);
|
|
|
|
BufferByteStreamer Streamer = Entry.getStreamer();
|
2016-12-10 04:43:40 +08:00
|
|
|
DebugLocDwarfExpression DwarfExpr(AP.getDwarfVersion(), Streamer);
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
const DebugLocEntry::Value &Value = Values[0];
|
2016-12-06 02:04:47 +08:00
|
|
|
if (Value.isFragment()) {
|
|
|
|
// Emit all fragments that belong to the same variable and range.
|
2016-08-12 05:15:00 +08:00
|
|
|
assert(all_of(Values, [](DebugLocEntry::Value P) {
|
2016-12-06 02:04:47 +08:00
|
|
|
return P.isFragment();
|
|
|
|
}) && "all values are expected to be fragments");
|
2015-03-03 06:02:33 +08:00
|
|
|
assert(std::is_sorted(Values.begin(), Values.end()) &&
|
2016-12-06 02:04:47 +08:00
|
|
|
"fragments are expected to be sorted");
|
2015-04-14 02:53:11 +08:00
|
|
|
|
2016-12-10 04:43:40 +08:00
|
|
|
for (auto Fragment : Values)
|
|
|
|
emitDebugLocValue(AP, BT, Streamer, Fragment, DwarfExpr);
|
|
|
|
|
2015-03-03 06:02:33 +08:00
|
|
|
} else {
|
2016-12-06 02:04:47 +08:00
|
|
|
assert(Values.size() == 1 && "only fragments may have >1 value");
|
2016-12-10 04:43:40 +08:00
|
|
|
emitDebugLocValue(AP, BT, Streamer, Value, DwarfExpr);
|
2015-03-03 06:02:33 +08:00
|
|
|
}
|
2016-12-10 04:43:40 +08:00
|
|
|
DwarfExpr.finalize();
|
2015-03-03 06:02:33 +08:00
|
|
|
}
|
|
|
|
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
void DwarfDebug::emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry) {
|
2015-05-07 03:11:20 +08:00
|
|
|
// Emit the size.
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("Loc expr size");
|
2015-05-07 03:11:20 +08:00
|
|
|
Asm->EmitInt16(DebugLocs.getBytes(Entry).size());
|
|
|
|
|
2014-04-02 00:17:41 +08:00
|
|
|
// Emit the entry.
|
|
|
|
APByteStreamer Streamer(*Asm);
|
|
|
|
emitDebugLocEntry(Streamer, Entry);
|
|
|
|
}
|
|
|
|
|
2013-07-03 05:36:07 +08:00
|
|
|
// Emit locations into the debug loc section.
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::emitDebugLoc() {
|
2011-03-17 06:16:39 +08:00
|
|
|
// Start the dwarf loc section.
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->SwitchSection(
|
2014-04-02 09:50:20 +08:00
|
|
|
Asm->getObjFileLowering().getDwarfLocSection());
|
Revert the majority of the next patch in the address space series:
r165941: Resubmit the changes to llvm core to update the functions to
support different pointer sizes on a per address space basis.
Despite this commit log, this change primarily changed stuff outside of
VMCore, and those changes do not carry any tests for correctness (or
even plausibility), and we have consistently found questionable or flat
out incorrect cases in these changes. Most of them are probably correct,
but we need to devise a system that makes it more clear when we have
handled the address space concerns correctly, and ideally each pass that
gets updated would receive an accompanying test case that exercises that
pass specificaly w.r.t. alternate address spaces.
However, from this commit, I have retained the new C API entry points.
Those were an orthogonal change that probably should have been split
apart, but they seem entirely good.
In several places the changes were very obvious cleanups with no actual
multiple address space code added; these I have not reverted when
I spotted them.
In a few other places there were merge conflicts due to a cleaner
solution being implemented later, often not using address spaces at all.
In those cases, I've preserved the new code which isn't address space
dependent.
This is part of my ongoing effort to clean out the partial address space
code which carries high risk and low test coverage, and not likely to be
finished before the 3.2 release looms closer. Duncan and I would both
like to see the above issues addressed before we return to these
changes.
llvm-svn: 167222
2012-11-01 17:14:31 +08:00
|
|
|
unsigned char Size = Asm->getDataLayout().getPointerSize();
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
for (const auto &List : DebugLocs.getLists()) {
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->EmitLabel(List.Label);
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
const DwarfCompileUnit *CU = List.CU;
|
|
|
|
for (const auto &Entry : DebugLocs.getEntries(List)) {
|
2014-03-21 03:16:16 +08:00
|
|
|
// Set up the range. This range is relative to the entry point of the
|
|
|
|
// compile unit. This is a hard coded 0 for low_pc when we're emitting
|
|
|
|
// ranges, or the DW_AT_low_pc on the compile unit otherwise.
|
2014-11-04 05:15:30 +08:00
|
|
|
if (auto *Base = CU->getBaseAddress()) {
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
Asm->EmitLabelDifference(Entry.BeginSym, Base, Size);
|
|
|
|
Asm->EmitLabelDifference(Entry.EndSym, Base, Size);
|
2014-03-21 03:16:16 +08:00
|
|
|
} else {
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->EmitSymbolValue(Entry.BeginSym, Size);
|
|
|
|
Asm->OutStreamer->EmitSymbolValue(Entry.EndSym, Size);
|
2014-03-21 03:16:16 +08:00
|
|
|
}
|
2014-04-02 09:50:20 +08:00
|
|
|
|
2014-04-02 00:17:41 +08:00
|
|
|
emitDebugLocEntryLocation(Entry);
|
2010-05-26 07:40:22 +08:00
|
|
|
}
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->EmitIntValue(0, Size);
|
|
|
|
Asm->OutStreamer->EmitIntValue(0, Size);
|
2014-04-02 09:50:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DwarfDebug::emitDebugLocDWO() {
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->SwitchSection(
|
2014-04-02 09:50:20 +08:00
|
|
|
Asm->getObjFileLowering().getDwarfLocDWOSection());
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
for (const auto &List : DebugLocs.getLists()) {
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->EmitLabel(List.Label);
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
for (const auto &Entry : DebugLocs.getEntries(List)) {
|
2014-04-02 09:50:20 +08:00
|
|
|
// Just always use start_length for now - at least that's one address
|
|
|
|
// rather than two. We could get fancier and try to, say, reuse an
|
|
|
|
// address we know we've emitted elsewhere (the start of the function?
|
|
|
|
// The start of the CU or CU subrange that encloses this range?)
|
2016-10-29 01:59:50 +08:00
|
|
|
Asm->EmitInt8(dwarf::DW_LLE_startx_length);
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
unsigned idx = AddrPool.getIndex(Entry.BeginSym);
|
2014-04-02 09:50:20 +08:00
|
|
|
Asm->EmitULEB128(idx);
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
Asm->EmitLabelDifference(Entry.EndSym, Entry.BeginSym, 4);
|
2014-04-02 09:50:20 +08:00
|
|
|
|
|
|
|
emitDebugLocEntryLocation(Entry);
|
2014-03-25 09:44:02 +08:00
|
|
|
}
|
2016-10-29 01:59:50 +08:00
|
|
|
Asm->EmitInt8(dwarf::DW_LLE_end_of_list);
|
2010-05-26 07:40:22 +08:00
|
|
|
}
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2013-09-20 07:21:01 +08:00
|
|
|
struct ArangeSpan {
|
|
|
|
const MCSymbol *Start, *End;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Emit a debug aranges section, containing a CU lookup for any
|
|
|
|
// address we can tie back to a CU.
|
2012-11-21 08:34:35 +08:00
|
|
|
void DwarfDebug::emitDebugARanges() {
|
2015-02-27 06:02:02 +08:00
|
|
|
// Provides a unique id per text section.
|
2015-05-22 03:20:38 +08:00
|
|
|
MapVector<MCSection *, SmallVector<SymbolCU, 8>> SectionMap;
|
2013-09-20 07:21:01 +08:00
|
|
|
|
2015-02-27 06:02:02 +08:00
|
|
|
// Filter labels by section.
|
|
|
|
for (const SymbolCU &SCU : ArangeLabels) {
|
|
|
|
if (SCU.Sym->isInSection()) {
|
|
|
|
// Make a note of this symbol and it's section.
|
2015-05-22 03:20:38 +08:00
|
|
|
MCSection *Section = &SCU.Sym->getSection();
|
2015-02-27 06:02:02 +08:00
|
|
|
if (!Section->getKind().isMetadata())
|
|
|
|
SectionMap[Section].push_back(SCU);
|
|
|
|
} else {
|
|
|
|
// Some symbols (e.g. common/bss on mach-o) can have no section but still
|
|
|
|
// appear in the output. This sucks as we rely on sections to build
|
|
|
|
// arange spans. We can do it without, but it's icky.
|
|
|
|
SectionMap[nullptr].push_back(SCU);
|
|
|
|
}
|
|
|
|
}
|
2013-09-20 07:21:01 +08:00
|
|
|
|
2015-02-27 06:02:02 +08:00
|
|
|
DenseMap<DwarfCompileUnit *, std::vector<ArangeSpan>> Spans;
|
|
|
|
|
2015-03-10 06:08:37 +08:00
|
|
|
for (auto &I : SectionMap) {
|
2016-05-20 08:38:28 +08:00
|
|
|
MCSection *Section = I.first;
|
2015-03-10 06:08:37 +08:00
|
|
|
SmallVector<SymbolCU, 8> &List = I.second;
|
2016-05-20 08:38:28 +08:00
|
|
|
if (List.size() < 1)
|
2013-09-20 07:21:01 +08:00
|
|
|
continue;
|
|
|
|
|
2015-02-03 03:22:51 +08:00
|
|
|
// If we have no section (e.g. common), just write out
|
|
|
|
// individual spans for each symbol.
|
|
|
|
if (!Section) {
|
|
|
|
for (const SymbolCU &Cur : List) {
|
|
|
|
ArangeSpan Span;
|
|
|
|
Span.Start = Cur.Sym;
|
|
|
|
Span.End = nullptr;
|
2016-05-20 08:38:28 +08:00
|
|
|
assert(Cur.CU);
|
|
|
|
Spans[Cur.CU].push_back(Span);
|
2015-02-03 03:22:51 +08:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-09-20 07:21:01 +08:00
|
|
|
// Sort the symbols by offset within the section.
|
2016-05-20 07:17:37 +08:00
|
|
|
std::sort(
|
|
|
|
List.begin(), List.end(), [&](const SymbolCU &A, const SymbolCU &B) {
|
|
|
|
unsigned IA = A.Sym ? Asm->OutStreamer->GetSymbolOrder(A.Sym) : 0;
|
|
|
|
unsigned IB = B.Sym ? Asm->OutStreamer->GetSymbolOrder(B.Sym) : 0;
|
|
|
|
|
|
|
|
// Symbols with no order assigned should be placed at the end.
|
|
|
|
// (e.g. section end labels)
|
|
|
|
if (IA == 0)
|
|
|
|
return false;
|
|
|
|
if (IB == 0)
|
|
|
|
return true;
|
|
|
|
return IA < IB;
|
|
|
|
});
|
2013-09-20 07:21:01 +08:00
|
|
|
|
2016-05-20 08:38:28 +08:00
|
|
|
// Insert a final terminator.
|
|
|
|
List.push_back(SymbolCU(nullptr, Asm->OutStreamer->endSection(Section)));
|
|
|
|
|
2015-02-03 03:22:51 +08:00
|
|
|
// Build spans between each label.
|
|
|
|
const MCSymbol *StartSym = List[0].Sym;
|
|
|
|
for (size_t n = 1, e = List.size(); n < e; n++) {
|
|
|
|
const SymbolCU &Prev = List[n - 1];
|
|
|
|
const SymbolCU &Cur = List[n];
|
|
|
|
|
|
|
|
// Try and build the longest span we can within the same CU.
|
|
|
|
if (Cur.CU != Prev.CU) {
|
2013-09-20 07:21:01 +08:00
|
|
|
ArangeSpan Span;
|
2015-02-03 03:22:51 +08:00
|
|
|
Span.Start = StartSym;
|
|
|
|
Span.End = Cur.Sym;
|
2016-05-20 08:38:28 +08:00
|
|
|
assert(Prev.CU);
|
2015-02-03 03:22:51 +08:00
|
|
|
Spans[Prev.CU].push_back(Span);
|
|
|
|
StartSym = Cur.Sym;
|
2013-09-20 07:21:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-27 06:02:02 +08:00
|
|
|
// Start the dwarf aranges section.
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->SwitchSection(
|
2015-02-27 06:02:02 +08:00
|
|
|
Asm->getObjFileLowering().getDwarfARangesSection());
|
|
|
|
|
2013-09-20 07:21:01 +08:00
|
|
|
unsigned PtrSize = Asm->getDataLayout().getPointerSize();
|
|
|
|
|
|
|
|
// Build a list of CUs used.
|
2013-12-10 07:57:44 +08:00
|
|
|
std::vector<DwarfCompileUnit *> CUs;
|
2014-03-08 03:09:39 +08:00
|
|
|
for (const auto &it : Spans) {
|
|
|
|
DwarfCompileUnit *CU = it.first;
|
2013-09-20 07:21:01 +08:00
|
|
|
CUs.push_back(CU);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the CU list (again, to ensure consistent output order).
|
2016-02-12 03:57:46 +08:00
|
|
|
std::sort(CUs.begin(), CUs.end(),
|
|
|
|
[](const DwarfCompileUnit *A, const DwarfCompileUnit *B) {
|
|
|
|
return A->getUniqueID() < B->getUniqueID();
|
|
|
|
});
|
2013-09-20 07:21:01 +08:00
|
|
|
|
|
|
|
// Emit an arange table for each CU we used.
|
2014-03-08 03:09:39 +08:00
|
|
|
for (DwarfCompileUnit *CU : CUs) {
|
2013-09-20 07:21:01 +08:00
|
|
|
std::vector<ArangeSpan> &List = Spans[CU];
|
|
|
|
|
2014-11-02 09:21:43 +08:00
|
|
|
// Describe the skeleton CU's offset and length, not the dwo file's.
|
|
|
|
if (auto *Skel = CU->getSkeleton())
|
|
|
|
CU = Skel;
|
|
|
|
|
2013-09-20 07:21:01 +08:00
|
|
|
// Emit size of content not including length itself.
|
2013-11-19 17:04:36 +08:00
|
|
|
unsigned ContentSize =
|
|
|
|
sizeof(int16_t) + // DWARF ARange version number
|
|
|
|
sizeof(int32_t) + // Offset of CU in the .debug_info section
|
|
|
|
sizeof(int8_t) + // Pointer Size (in bytes)
|
|
|
|
sizeof(int8_t); // Segment Size (in bytes)
|
2013-09-20 07:21:01 +08:00
|
|
|
|
|
|
|
unsigned TupleSize = PtrSize * 2;
|
|
|
|
|
|
|
|
// 7.20 in the Dwarf specs requires the table to be aligned to a tuple.
|
2014-01-08 03:28:14 +08:00
|
|
|
unsigned Padding =
|
|
|
|
OffsetToAlignment(sizeof(int32_t) + ContentSize, TupleSize);
|
2013-09-20 07:21:01 +08:00
|
|
|
|
|
|
|
ContentSize += Padding;
|
|
|
|
ContentSize += (List.size() + 1) * TupleSize;
|
|
|
|
|
|
|
|
// For each compile unit, write the list of spans it covers.
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("Length of ARange Set");
|
2013-09-20 07:21:01 +08:00
|
|
|
Asm->EmitInt32(ContentSize);
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("DWARF Arange version number");
|
2013-09-20 07:21:01 +08:00
|
|
|
Asm->EmitInt16(dwarf::DW_ARANGES_VERSION);
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("Offset Into Debug Info Section");
|
2015-06-17 07:22:02 +08:00
|
|
|
Asm->emitDwarfSymbolReference(CU->getLabelBegin());
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("Address Size (in bytes)");
|
2013-09-20 07:21:01 +08:00
|
|
|
Asm->EmitInt8(PtrSize);
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("Segment Size (in bytes)");
|
2013-09-20 07:21:01 +08:00
|
|
|
Asm->EmitInt8(0);
|
|
|
|
|
2016-06-01 09:59:58 +08:00
|
|
|
Asm->OutStreamer->emitFill(Padding, 0xff);
|
2013-09-20 07:21:01 +08:00
|
|
|
|
2014-03-08 03:09:39 +08:00
|
|
|
for (const ArangeSpan &Span : List) {
|
2013-09-20 07:21:01 +08:00
|
|
|
Asm->EmitLabelReference(Span.Start, PtrSize);
|
|
|
|
|
|
|
|
// Calculate the size as being from the span start to it's end.
|
2013-09-24 01:56:20 +08:00
|
|
|
if (Span.End) {
|
2013-09-20 07:21:01 +08:00
|
|
|
Asm->EmitLabelDifference(Span.End, Span.Start, PtrSize);
|
2013-09-24 01:56:20 +08:00
|
|
|
} else {
|
|
|
|
// For symbols without an end marker (e.g. common), we
|
|
|
|
// write a single arange entry containing just that one symbol.
|
|
|
|
uint64_t Size = SymSize[Span.Start];
|
|
|
|
if (Size == 0)
|
|
|
|
Size = 1;
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->EmitIntValue(Size, PtrSize);
|
2013-09-24 01:56:20 +08:00
|
|
|
}
|
2013-09-20 07:21:01 +08:00
|
|
|
}
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("ARange terminator");
|
|
|
|
Asm->OutStreamer->EmitIntValue(0, PtrSize);
|
|
|
|
Asm->OutStreamer->EmitIntValue(0, PtrSize);
|
2013-09-20 07:21:01 +08:00
|
|
|
}
|
2009-05-21 07:04:56 +08:00
|
|
|
}
|
|
|
|
|
2016-01-24 16:18:55 +08:00
|
|
|
/// Emit address ranges into a debug ranges section.
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::emitDebugRanges() {
|
2009-05-21 07:21:38 +08:00
|
|
|
// Start the dwarf ranges section.
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->SwitchSection(
|
2013-11-19 17:04:36 +08:00
|
|
|
Asm->getObjFileLowering().getDwarfRangesSection());
|
2013-12-03 08:45:45 +08:00
|
|
|
|
|
|
|
// Size for our labels.
|
Revert the majority of the next patch in the address space series:
r165941: Resubmit the changes to llvm core to update the functions to
support different pointer sizes on a per address space basis.
Despite this commit log, this change primarily changed stuff outside of
VMCore, and those changes do not carry any tests for correctness (or
even plausibility), and we have consistently found questionable or flat
out incorrect cases in these changes. Most of them are probably correct,
but we need to devise a system that makes it more clear when we have
handled the address space concerns correctly, and ideally each pass that
gets updated would receive an accompanying test case that exercises that
pass specificaly w.r.t. alternate address spaces.
However, from this commit, I have retained the new C API entry points.
Those were an orthogonal change that probably should have been split
apart, but they seem entirely good.
In several places the changes were very obvious cleanups with no actual
multiple address space code added; these I have not reverted when
I spotted them.
In a few other places there were merge conflicts due to a cleaner
solution being implemented later, often not using address spaces at all.
In those cases, I've preserved the new code which isn't address space
dependent.
This is part of my ongoing effort to clean out the partial address space
code which carries high risk and low test coverage, and not likely to be
finished before the 3.2 release looms closer. Duncan and I would both
like to see the above issues addressed before we return to these
changes.
llvm-svn: 167222
2012-11-01 17:14:31 +08:00
|
|
|
unsigned char Size = Asm->getDataLayout().getPointerSize();
|
2013-12-03 08:45:45 +08:00
|
|
|
|
|
|
|
// Grab the specific ranges for the compile units in the module.
|
2014-03-08 03:09:39 +08:00
|
|
|
for (const auto &I : CUMap) {
|
|
|
|
DwarfCompileUnit *TheCU = I.second;
|
2013-12-03 08:45:45 +08:00
|
|
|
|
Provide gmlt-like inline scope information in the skeleton CU to facilitate symbolication without needing the .dwo files
Clang -gsplit-dwarf self-host -O0, binary increases by 0.0005%, -O2,
binary increases by 25%.
A large binary inside Google, split-dwarf, -O0, and other internal flags
(GDB index, etc) increases by 1.8%, optimized build is 35%.
The size impact may be somewhat greater in .o files (I haven't measured
that much - since the linked executable -O0 numbers seemed low enough)
due to relocations. These relocations could be removed if we taught the
llvm-symbolizer to handle indexed addressing in the .o file (GDB can't
cope with this just yet, but GDB won't be reading this info anyway).
Also debug_ranges could be shared between .o and .dwo, though ideally
debug_ranges would get a schema that could used index(+offset)
addressing, and move to the .dwo file, then we'd be back to sharing
addresses in the address pool again.
But for now, these sizes seem small enough to go ahead with this.
Verified that no other DW_TAGs are produced into the .o file other than
subprograms and inlined_subroutines.
llvm-svn: 221306
2014-11-05 06:12:25 +08:00
|
|
|
if (auto *Skel = TheCU->getSkeleton())
|
|
|
|
TheCU = Skel;
|
|
|
|
|
2013-12-03 08:45:45 +08:00
|
|
|
// Iterate over the misc ranges for the compile units in the module.
|
2014-03-08 03:09:39 +08:00
|
|
|
for (const RangeSpanList &List : TheCU->getRangeLists()) {
|
2013-12-05 06:04:50 +08:00
|
|
|
// Emit our symbol so we can find the beginning of the range.
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->EmitLabel(List.getSym());
|
2013-12-03 08:45:45 +08:00
|
|
|
|
2014-03-08 03:09:39 +08:00
|
|
|
for (const RangeSpan &Range : List.getRanges()) {
|
2013-12-03 08:45:45 +08:00
|
|
|
const MCSymbol *Begin = Range.getStart();
|
|
|
|
const MCSymbol *End = Range.getEnd();
|
2013-12-20 12:34:22 +08:00
|
|
|
assert(Begin && "Range without a begin symbol?");
|
|
|
|
assert(End && "Range without an end symbol?");
|
2014-11-04 05:15:30 +08:00
|
|
|
if (auto *Base = TheCU->getBaseAddress()) {
|
2014-04-26 06:23:54 +08:00
|
|
|
Asm->EmitLabelDifference(Begin, Base, Size);
|
|
|
|
Asm->EmitLabelDifference(End, Base, Size);
|
|
|
|
} else {
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->EmitSymbolValue(Begin, Size);
|
|
|
|
Asm->OutStreamer->EmitSymbolValue(End, Size);
|
2014-04-26 06:23:54 +08:00
|
|
|
}
|
2013-12-03 08:45:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// And terminate the list with two 0 values.
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->EmitIntValue(0, Size);
|
|
|
|
Asm->OutStreamer->EmitIntValue(0, Size);
|
2013-12-03 08:45:45 +08:00
|
|
|
}
|
2010-04-17 07:33:45 +08:00
|
|
|
}
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
|
|
|
|
2016-02-01 22:09:41 +08:00
|
|
|
void DwarfDebug::handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U) {
|
2016-01-07 22:28:20 +08:00
|
|
|
for (auto *MN : Nodes) {
|
|
|
|
if (auto *M = dyn_cast<DIMacro>(MN))
|
2016-02-01 22:09:41 +08:00
|
|
|
emitMacro(*M);
|
2016-01-07 22:28:20 +08:00
|
|
|
else if (auto *F = dyn_cast<DIMacroFile>(MN))
|
2016-02-01 22:09:41 +08:00
|
|
|
emitMacroFile(*F, U);
|
2016-01-07 22:28:20 +08:00
|
|
|
else
|
|
|
|
llvm_unreachable("Unexpected DI type!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-01 22:09:41 +08:00
|
|
|
void DwarfDebug::emitMacro(DIMacro &M) {
|
|
|
|
Asm->EmitULEB128(M.getMacinfoType());
|
|
|
|
Asm->EmitULEB128(M.getLine());
|
2016-01-07 22:28:20 +08:00
|
|
|
StringRef Name = M.getName();
|
|
|
|
StringRef Value = M.getValue();
|
2016-02-01 22:09:41 +08:00
|
|
|
Asm->OutStreamer->EmitBytes(Name);
|
2016-01-07 22:28:20 +08:00
|
|
|
if (!Value.empty()) {
|
|
|
|
// There should be one space between macro name and macro value.
|
2016-02-01 22:09:41 +08:00
|
|
|
Asm->EmitInt8(' ');
|
|
|
|
Asm->OutStreamer->EmitBytes(Value);
|
2016-01-07 22:28:20 +08:00
|
|
|
}
|
2016-02-01 22:09:41 +08:00
|
|
|
Asm->EmitInt8('\0');
|
2016-01-07 22:28:20 +08:00
|
|
|
}
|
|
|
|
|
2016-02-01 22:09:41 +08:00
|
|
|
void DwarfDebug::emitMacroFile(DIMacroFile &F, DwarfCompileUnit &U) {
|
2016-01-07 22:28:20 +08:00
|
|
|
assert(F.getMacinfoType() == dwarf::DW_MACINFO_start_file);
|
2016-02-01 22:09:41 +08:00
|
|
|
Asm->EmitULEB128(dwarf::DW_MACINFO_start_file);
|
|
|
|
Asm->EmitULEB128(F.getLine());
|
2016-01-07 22:28:20 +08:00
|
|
|
DIFile *File = F.getFile();
|
|
|
|
unsigned FID =
|
|
|
|
U.getOrCreateSourceID(File->getFilename(), File->getDirectory());
|
2016-02-01 22:09:41 +08:00
|
|
|
Asm->EmitULEB128(FID);
|
|
|
|
handleMacroNodes(F.getElements(), U);
|
|
|
|
Asm->EmitULEB128(dwarf::DW_MACINFO_end_file);
|
2016-01-07 22:28:20 +08:00
|
|
|
}
|
|
|
|
|
2016-01-24 16:18:55 +08:00
|
|
|
/// Emit macros into a debug macinfo section.
|
2016-01-07 22:28:20 +08:00
|
|
|
void DwarfDebug::emitDebugMacinfo() {
|
2016-02-01 22:09:41 +08:00
|
|
|
// Start the dwarf macinfo section.
|
|
|
|
Asm->OutStreamer->SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfMacinfoSection());
|
|
|
|
|
2016-01-07 22:28:20 +08:00
|
|
|
for (const auto &P : CUMap) {
|
|
|
|
auto &TheCU = *P.second;
|
|
|
|
auto *SkCU = TheCU.getSkeleton();
|
|
|
|
DwarfCompileUnit &U = SkCU ? *SkCU : TheCU;
|
|
|
|
auto *CUNode = cast<DICompileUnit>(P.first);
|
2016-02-01 22:09:41 +08:00
|
|
|
Asm->OutStreamer->EmitLabel(U.getMacroLabelBegin());
|
|
|
|
handleMacroNodes(CUNode->getMacros(), U);
|
2016-01-07 22:28:20 +08:00
|
|
|
}
|
|
|
|
Asm->OutStreamer->AddComment("End Of Macro List Mark");
|
|
|
|
Asm->EmitInt8(0);
|
|
|
|
}
|
|
|
|
|
2012-12-12 03:42:09 +08:00
|
|
|
// DWARF5 Experimental Separate Dwarf emitters.
|
2012-12-01 07:59:06 +08:00
|
|
|
|
2014-04-26 02:26:14 +08:00
|
|
|
void DwarfDebug::initSkeletonUnit(const DwarfUnit &U, DIE &Die,
|
2016-02-12 03:57:46 +08:00
|
|
|
std::unique_ptr<DwarfCompileUnit> NewU) {
|
2014-11-02 16:51:37 +08:00
|
|
|
NewU->addString(Die, dwarf::DW_AT_GNU_dwo_name,
|
2015-04-16 07:19:27 +08:00
|
|
|
U.getCUNode()->getSplitDebugFilename());
|
2014-01-09 12:28:46 +08:00
|
|
|
|
|
|
|
if (!CompilationDir.empty())
|
2014-11-02 16:51:37 +08:00
|
|
|
NewU->addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
|
2014-01-09 12:28:46 +08:00
|
|
|
|
2014-04-23 06:39:41 +08:00
|
|
|
addGnuPubAttributes(*NewU, Die);
|
2014-01-09 12:28:46 +08:00
|
|
|
|
2014-04-23 06:39:41 +08:00
|
|
|
SkeletonHolder.addUnit(std::move(NewU));
|
2014-01-09 12:28:46 +08:00
|
|
|
}
|
|
|
|
|
2012-12-01 07:59:06 +08:00
|
|
|
// This DIE has the following attributes: DW_AT_comp_dir, DW_AT_stmt_list,
|
|
|
|
// DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_dwo_name, DW_AT_dwo_id,
|
2014-03-25 05:31:35 +08:00
|
|
|
// DW_AT_addr_base, DW_AT_ranges_base.
|
2014-04-23 06:39:41 +08:00
|
|
|
DwarfCompileUnit &DwarfDebug::constructSkeletonCU(const DwarfCompileUnit &CU) {
|
2012-12-01 07:59:06 +08:00
|
|
|
|
2014-04-23 06:39:41 +08:00
|
|
|
auto OwnedUnit = make_unique<DwarfCompileUnit>(
|
2014-04-29 05:14:27 +08:00
|
|
|
CU.getUniqueID(), CU.getCUNode(), Asm, this, &SkeletonHolder);
|
2014-04-23 06:39:41 +08:00
|
|
|
DwarfCompileUnit &NewCU = *OwnedUnit;
|
2016-12-02 02:56:29 +08:00
|
|
|
NewCU.setSection(Asm->getObjFileLowering().getDwarfInfoSection());
|
2013-01-17 11:00:04 +08:00
|
|
|
|
2015-03-11 00:58:10 +08:00
|
|
|
NewCU.initStmtList();
|
2012-12-01 07:59:06 +08:00
|
|
|
|
2014-04-29 05:04:29 +08:00
|
|
|
initSkeletonUnit(CU, NewCU.getUnitDie(), std::move(OwnedUnit));
|
2012-12-11 07:34:43 +08:00
|
|
|
|
2012-12-01 07:59:06 +08:00
|
|
|
return NewCU;
|
|
|
|
}
|
|
|
|
|
2012-12-12 03:42:09 +08:00
|
|
|
// Emit the .debug_info.dwo section for separated dwarf. This contains the
|
|
|
|
// compile units that would normally be in debug_info.
|
2012-12-01 07:59:06 +08:00
|
|
|
void DwarfDebug::emitDebugInfoDWO() {
|
2012-12-11 03:51:21 +08:00
|
|
|
assert(useSplitDwarf() && "No split dwarf debug info?");
|
2015-03-11 00:58:10 +08:00
|
|
|
// Don't emit relocations into the dwo file.
|
|
|
|
InfoHolder.emitUnits(/* UseOffsets */ true);
|
2012-12-20 06:02:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the .debug_abbrev.dwo section for separated dwarf. This contains the
|
|
|
|
// abbreviations for the .debug_info.dwo section.
|
|
|
|
void DwarfDebug::emitDebugAbbrevDWO() {
|
|
|
|
assert(useSplitDwarf() && "No split dwarf?");
|
2013-12-05 15:43:55 +08:00
|
|
|
InfoHolder.emitAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevDWOSection());
|
2012-12-01 07:59:06 +08:00
|
|
|
}
|
2012-12-27 10:14:01 +08:00
|
|
|
|
2014-03-18 09:17:26 +08:00
|
|
|
void DwarfDebug::emitDebugLineDWO() {
|
|
|
|
assert(useSplitDwarf() && "No split dwarf?");
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->SwitchSection(
|
2014-03-18 09:17:26 +08:00
|
|
|
Asm->getObjFileLowering().getDwarfLineDWOSection());
|
2015-08-07 23:14:08 +08:00
|
|
|
SplitTypeUnitFileTable.Emit(*Asm->OutStreamer, MCDwarfLineTableParams());
|
2014-03-18 09:17:26 +08:00
|
|
|
}
|
|
|
|
|
2012-12-27 10:14:01 +08:00
|
|
|
// Emit the .debug_str.dwo section for separated dwarf. This contains the
|
|
|
|
// string section and is identical in format to traditional .debug_str
|
|
|
|
// sections.
|
|
|
|
void DwarfDebug::emitDebugStrDWO() {
|
|
|
|
assert(useSplitDwarf() && "No split dwarf?");
|
2015-05-22 03:20:38 +08:00
|
|
|
MCSection *OffSec = Asm->getObjFileLowering().getDwarfStrOffDWOSection();
|
2013-01-08 03:32:41 +08:00
|
|
|
InfoHolder.emitStrings(Asm->getObjFileLowering().getDwarfStrDWOSection(),
|
2014-09-12 05:12:48 +08:00
|
|
|
OffSec);
|
2012-12-27 10:14:01 +08:00
|
|
|
}
|
2013-11-20 07:08:21 +08:00
|
|
|
|
2014-03-19 08:11:28 +08:00
|
|
|
MCDwarfDwoLineTable *DwarfDebug::getDwoLineTable(const DwarfCompileUnit &CU) {
|
|
|
|
if (!useSplitDwarf())
|
|
|
|
return nullptr;
|
|
|
|
if (SingleCU)
|
2015-04-16 07:19:27 +08:00
|
|
|
SplitTypeUnitFileTable.setCompilationDir(CU.getCUNode()->getDirectory());
|
2014-03-19 08:11:28 +08:00
|
|
|
return &SplitTypeUnitFileTable;
|
|
|
|
}
|
|
|
|
|
2015-07-16 01:01:41 +08:00
|
|
|
uint64_t DwarfDebug::makeTypeSignature(StringRef Identifier) {
|
2014-04-27 00:26:41 +08:00
|
|
|
MD5 Hash;
|
|
|
|
Hash.update(Identifier);
|
|
|
|
// ... take the least significant 8 bytes and return those. Our MD5
|
|
|
|
// implementation always returns its results in little endian, swap bytes
|
|
|
|
// appropriately.
|
|
|
|
MD5::MD5Result Result;
|
|
|
|
Hash.final(Result);
|
2015-03-03 05:19:12 +08:00
|
|
|
return support::endian::read64le(Result + 8);
|
2014-04-27 00:26:41 +08:00
|
|
|
}
|
|
|
|
|
2014-02-12 08:31:30 +08:00
|
|
|
void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
|
2014-04-26 02:26:14 +08:00
|
|
|
StringRef Identifier, DIE &RefDie,
|
2015-04-30 00:38:44 +08:00
|
|
|
const DICompositeType *CTy) {
|
2014-04-27 01:27:38 +08:00
|
|
|
// Fast path if we're building some type units and one has already used the
|
|
|
|
// address pool we know we're going to throw away all this work anyway, so
|
|
|
|
// don't bother building dependent types.
|
|
|
|
if (!TypeUnitsUnderConstruction.empty() && AddrPool.hasBeenUsed())
|
|
|
|
return;
|
|
|
|
|
2016-02-12 03:57:46 +08:00
|
|
|
auto Ins = TypeSignatures.insert(std::make_pair(CTy, 0));
|
|
|
|
if (!Ins.second) {
|
|
|
|
CU.addDIETypeSignature(RefDie, Ins.first->second);
|
2014-01-20 16:07:07 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-27 01:27:38 +08:00
|
|
|
bool TopLevelType = TypeUnitsUnderConstruction.empty();
|
|
|
|
AddrPool.resetUsedFlag();
|
|
|
|
|
2016-02-12 03:57:46 +08:00
|
|
|
auto OwnedUnit = make_unique<DwarfTypeUnit>(CU, Asm, this, &InfoHolder,
|
|
|
|
getDwoLineTable(CU));
|
2014-04-23 06:39:41 +08:00
|
|
|
DwarfTypeUnit &NewTU = *OwnedUnit;
|
2014-04-29 05:04:29 +08:00
|
|
|
DIE &UnitDie = NewTU.getUnitDie();
|
2016-08-12 05:15:00 +08:00
|
|
|
TypeUnitsUnderConstruction.emplace_back(std::move(OwnedUnit), CTy);
|
2014-04-23 06:39:41 +08:00
|
|
|
|
2014-04-29 05:04:29 +08:00
|
|
|
NewTU.addUInt(UnitDie, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
|
2014-04-23 07:09:36 +08:00
|
|
|
CU.getLanguage());
|
2014-01-20 16:07:07 +08:00
|
|
|
|
2014-04-27 00:26:41 +08:00
|
|
|
uint64_t Signature = makeTypeSignature(Identifier);
|
2014-04-23 06:39:41 +08:00
|
|
|
NewTU.setTypeSignature(Signature);
|
2016-02-12 03:57:46 +08:00
|
|
|
Ins.first->second = Signature;
|
2014-04-27 00:26:41 +08:00
|
|
|
|
2014-07-26 01:11:58 +08:00
|
|
|
if (useSplitDwarf())
|
2016-12-02 02:56:29 +08:00
|
|
|
NewTU.setSection(Asm->getObjFileLowering().getDwarfTypesDWOSection());
|
2014-07-26 01:11:58 +08:00
|
|
|
else {
|
2014-04-29 05:04:29 +08:00
|
|
|
CU.applyStmtList(UnitDie);
|
2016-12-02 02:56:29 +08:00
|
|
|
NewTU.setSection(Asm->getObjFileLowering().getDwarfTypesSection(Signature));
|
2014-07-26 01:11:58 +08:00
|
|
|
}
|
2014-01-20 16:07:07 +08:00
|
|
|
|
2014-04-27 00:26:41 +08:00
|
|
|
NewTU.setType(NewTU.createTypeDIE(CTy));
|
|
|
|
|
2014-04-27 01:27:38 +08:00
|
|
|
if (TopLevelType) {
|
|
|
|
auto TypeUnitsToAdd = std::move(TypeUnitsUnderConstruction);
|
|
|
|
TypeUnitsUnderConstruction.clear();
|
|
|
|
|
|
|
|
// Types referencing entries in the address table cannot be placed in type
|
|
|
|
// units.
|
|
|
|
if (AddrPool.hasBeenUsed()) {
|
|
|
|
|
|
|
|
// Remove all the types built while building this type.
|
|
|
|
// This is pessimistic as some of these types might not be dependent on
|
|
|
|
// the type that used an address.
|
|
|
|
for (const auto &TU : TypeUnitsToAdd)
|
2016-02-12 03:57:46 +08:00
|
|
|
TypeSignatures.erase(TU.second);
|
2014-04-27 01:27:38 +08:00
|
|
|
|
|
|
|
// Construct this type in the CU directly.
|
|
|
|
// This is inefficient because all the dependent types will be rebuilt
|
|
|
|
// from scratch, including building them in type units, discovering that
|
|
|
|
// they depend on addresses, throwing them out and rebuilding them.
|
2015-04-30 00:38:44 +08:00
|
|
|
CU.constructTypeDIE(RefDie, cast<DICompositeType>(CTy));
|
2014-04-27 01:27:38 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the type wasn't dependent on fission addresses, finish adding the type
|
|
|
|
// and all its dependent types.
|
2016-02-12 03:57:46 +08:00
|
|
|
for (auto &TU : TypeUnitsToAdd) {
|
|
|
|
InfoHolder.computeSizeAndOffsetsForUnit(TU.first.get());
|
|
|
|
InfoHolder.emitUnit(TU.first.get(), useSplitDwarf());
|
|
|
|
}
|
2014-04-27 01:27:38 +08:00
|
|
|
}
|
2016-02-12 03:57:46 +08:00
|
|
|
CU.addDIETypeSignature(RefDie, Signature);
|
2013-11-20 07:08:21 +08:00
|
|
|
}
|
2014-03-08 02:49:45 +08:00
|
|
|
|
2014-04-24 07:37:35 +08:00
|
|
|
// Accelerator table mutators - add each name along with its companion
|
|
|
|
// DIE to the proper table while ensuring that the name that we're going
|
|
|
|
// to reference is in the string table. We do this since the names we
|
|
|
|
// add may not only be identical to the names in the DIE.
|
2014-04-26 02:52:29 +08:00
|
|
|
void DwarfDebug::addAccelName(StringRef Name, const DIE &Die) {
|
2014-04-24 07:37:35 +08:00
|
|
|
if (!useDwarfAccelTables())
|
|
|
|
return;
|
2015-05-25 00:44:32 +08:00
|
|
|
AccelNames.AddName(InfoHolder.getStringPool().getEntry(*Asm, Name), &Die);
|
2014-04-24 07:37:35 +08:00
|
|
|
}
|
2014-04-24 08:53:32 +08:00
|
|
|
|
2014-04-26 02:52:29 +08:00
|
|
|
void DwarfDebug::addAccelObjC(StringRef Name, const DIE &Die) {
|
2014-04-24 08:53:32 +08:00
|
|
|
if (!useDwarfAccelTables())
|
|
|
|
return;
|
2015-05-25 00:44:32 +08:00
|
|
|
AccelObjC.AddName(InfoHolder.getStringPool().getEntry(*Asm, Name), &Die);
|
2014-04-24 08:53:32 +08:00
|
|
|
}
|
2014-04-24 09:02:42 +08:00
|
|
|
|
2014-04-26 02:52:29 +08:00
|
|
|
void DwarfDebug::addAccelNamespace(StringRef Name, const DIE &Die) {
|
2014-04-24 09:02:42 +08:00
|
|
|
if (!useDwarfAccelTables())
|
|
|
|
return;
|
2015-05-25 00:44:32 +08:00
|
|
|
AccelNamespace.AddName(InfoHolder.getStringPool().getEntry(*Asm, Name), &Die);
|
2014-04-24 09:02:42 +08:00
|
|
|
}
|
2014-04-24 09:23:49 +08:00
|
|
|
|
2014-04-26 02:52:29 +08:00
|
|
|
void DwarfDebug::addAccelType(StringRef Name, const DIE &Die, char Flags) {
|
2014-04-24 09:23:49 +08:00
|
|
|
if (!useDwarfAccelTables())
|
|
|
|
return;
|
2015-05-25 00:44:32 +08:00
|
|
|
AccelTypes.AddName(InfoHolder.getStringPool().getEntry(*Asm, Name), &Die);
|
2014-04-24 09:23:49 +08:00
|
|
|
}
|
2016-11-24 07:30:37 +08:00
|
|
|
|
|
|
|
uint16_t DwarfDebug::getDwarfVersion() const {
|
|
|
|
return Asm->OutStreamer->getContext().getDwarfVersion();
|
|
|
|
}
|