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"
|
2014-03-06 08:22:06 +08:00
|
|
|
#include "llvm/IR/DIBuilder.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#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"
|
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"
|
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-07-24 06:16:41 +08:00
|
|
|
static cl::opt<bool> UnknownLocations(
|
|
|
|
"use-unknown-locations", cl::Hidden,
|
|
|
|
cl::desc("Make an absence of debug location information explicit."),
|
|
|
|
cl::init(false));
|
2010-05-07 09:08:53 +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
|
|
|
|
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"),
|
|
|
|
clEnumVal(Disable, "Disabled"), clEnumValEnd),
|
|
|
|
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"),
|
|
|
|
clEnumVal(Disable, "Disabled"), clEnumValEnd),
|
|
|
|
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"),
|
|
|
|
clEnumVal(Disable, "Disabled"), clEnumValEnd),
|
|
|
|
cl::init(Default));
|
2013-08-20 05:07:38 +08:00
|
|
|
|
2013-08-24 20:54:27 +08:00
|
|
|
static const char *const DWARFGroupName = "DWARF Emission";
|
|
|
|
static const char *const DbgTimerName = "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));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DebugLocDwarfExpression::isFrameRegister(unsigned MachineReg) {
|
|
|
|
// This information is not available while emitting .debug_loc entries.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-05-15 17:23:25 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-10-09 03:07:44 +08:00
|
|
|
/// resolve - Look in the DwarfDebug map for the MDNode that
|
|
|
|
/// corresponds to the reference.
|
2015-04-30 00:38:44 +08:00
|
|
|
template <typename T> T *DbgVariable::resolve(TypedDINodeRef<T> Ref) const {
|
2013-10-09 03:07:44 +08:00
|
|
|
return DD->resolve(Ref);
|
|
|
|
}
|
|
|
|
|
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!");
|
2015-04-14 09:59:58 +08:00
|
|
|
return Var->getType()
|
|
|
|
.resolve(DD->getTypeIdentifierMap())
|
|
|
|
->isBlockByrefStruct();
|
2014-03-18 10:34:58 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
const DIType *DbgVariable::getType() const {
|
|
|
|
DIType *Ty = Var->getType().resolve(DD->getTypeIdentifierMap());
|
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-04-30 00:38:44 +08:00
|
|
|
auto Elements = cast<DICompositeTypeBase>(subType)->getElements();
|
2015-04-07 12:14:33 +08:00
|
|
|
for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
|
2015-04-30 00:38:44 +08:00
|
|
|
auto *DT = cast<DIDerivedTypeBase>(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
|
|
|
|
2014-04-24 09:23:49 +08:00
|
|
|
static LLVM_CONSTEXPR DwarfAccelTable::Atom TypeAtoms[] = {
|
|
|
|
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)
|
2015-03-18 04:07:06 +08:00
|
|
|
: Asm(A), MMI(Asm->MMI), PrevLabel(nullptr),
|
2015-03-04 10:30:17 +08:00
|
|
|
InfoHolder(A, "info_string", DIEValueAllocator),
|
2014-01-28 08:49:26 +08:00
|
|
|
UsedNonDefaultText(false),
|
2015-03-04 10:30:17 +08:00
|
|
|
SkeletonHolder(A, "skel_string", DIEValueAllocator),
|
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
|
|
|
IsDarwin(Triple(A->getTargetTriple()).isOSDarwin()),
|
2015-03-05 04:55:11 +08:00
|
|
|
IsPS4(Triple(A->getTargetTriple()).isPS4()),
|
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)),
|
|
|
|
AccelTypes(TypeAtoms) {
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2014-04-24 14:44:33 +08:00
|
|
|
CurFn = nullptr;
|
|
|
|
CurMI = nullptr;
|
2012-04-03 01:58:52 +08:00
|
|
|
|
2013-10-16 04:26:37 +08:00
|
|
|
// Turn on accelerator tables for Darwin by default, pubnames by
|
2015-03-05 08:08:27 +08:00
|
|
|
// default for non-Darwin/PS4, and handle split dwarf.
|
2013-08-20 05:41:38 +08:00
|
|
|
if (DwarfAccelTables == Default)
|
|
|
|
HasDwarfAccelTables = IsDarwin;
|
|
|
|
else
|
2013-08-27 04:58:35 +08:00
|
|
|
HasDwarfAccelTables = DwarfAccelTables == Enable;
|
2012-08-24 06:36:36 +08:00
|
|
|
|
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;
|
|
|
|
|
2013-08-27 07:24:35 +08:00
|
|
|
if (DwarfPubSections == Default)
|
2015-03-05 08:08:27 +08:00
|
|
|
HasDwarfPubSections = !IsDarwin && !IsPS4;
|
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
|
|
|
|
2014-06-19 14:22:08 +08:00
|
|
|
unsigned DwarfVersionNumber = Asm->TM.Options.MCOptions.DwarfVersion;
|
2014-04-29 04:42:22 +08:00
|
|
|
DwarfVersion = DwarfVersionNumber ? DwarfVersionNumber
|
|
|
|
: MMI->getModule()->getDwarfVersion();
|
2013-07-03 07:40:10 +08:00
|
|
|
|
2015-03-05 04:55:11 +08:00
|
|
|
// Darwin and PS4 use the standard TLS opcode (defined in DWARF 3).
|
|
|
|
// Everybody else uses GNU's.
|
|
|
|
UseGNUTLSOpcode = !(IsDarwin || IsPS4) || DwarfVersion < 3;
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->getContext().setDwarfVersion(DwarfVersion);
|
2014-06-19 23:39:33 +08:00
|
|
|
|
2010-06-18 23:56:31 +08:00
|
|
|
{
|
|
|
|
NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
|
2012-11-20 06:42:15 +08:00
|
|
|
beginModule();
|
2010-04-07 18:44:46 +08:00
|
|
|
}
|
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(' '));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-10 03:05:21 +08:00
|
|
|
/// isSubprogramContext - Return true if Context is either a subprogram
|
|
|
|
/// or another context nested inside a subprogram.
|
|
|
|
bool DwarfDebug::isSubprogramContext(const MDNode *Context) {
|
|
|
|
if (!Context)
|
|
|
|
return false;
|
2015-04-30 00:38:44 +08:00
|
|
|
if (isa<DISubprogram>(Context))
|
2013-09-10 03:05:21 +08:00
|
|
|
return true;
|
2015-04-30 00:38:44 +08:00
|
|
|
if (auto *T = dyn_cast<DIType>(Context))
|
2015-04-16 09:01:28 +08:00
|
|
|
return isSubprogramContext(resolve(T->getScope()));
|
2013-09-10 03:05:21 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
template <typename Func> void forBothCUs(DwarfCompileUnit &CU, Func F) {
|
|
|
|
F(CU);
|
|
|
|
if (auto *SkelCU = CU.getSkeleton())
|
|
|
|
F(*SkelCU);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-10-10 14:39:26 +08:00
|
|
|
const MDNode *SP = 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.
|
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
|
|
|
auto &CU = SPMap[SP];
|
|
|
|
forBothCUs(*CU, [&](DwarfCompileUnit &CU) {
|
|
|
|
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));
|
2014-11-02 16:51:37 +08:00
|
|
|
if (useSplitDwarf())
|
|
|
|
NewCU.setSkeleton(constructSkeletonCU(NewCU));
|
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
|
|
|
|
2015-04-16 07:19:27 +08:00
|
|
|
if (DIUnit->isOptimized())
|
2014-04-29 05:04:29 +08:00
|
|
|
NewCU.addFlag(Die, dwarf::DW_AT_APPLE_optimized);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2015-04-16 07:19:27 +08:00
|
|
|
StringRef Flags = DIUnit->getFlags();
|
2009-11-26 01:36:49 +08:00
|
|
|
if (!Flags.empty())
|
2014-04-29 05:04:29 +08:00
|
|
|
NewCU.addString(Die, dwarf::DW_AT_APPLE_flags, Flags);
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2015-04-16 07:19:27 +08:00
|
|
|
if (unsigned RVer = DIUnit->getRuntimeVersion())
|
2014-04-29 05:04:29 +08:00
|
|
|
NewCU.addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
|
2014-04-23 07:09:36 +08:00
|
|
|
dwarf::DW_FORM_data1, RVer);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2014-11-02 16:51:37 +08:00
|
|
|
if (useSplitDwarf())
|
2015-03-11 00:58:10 +08:00
|
|
|
NewCU.initSection(Asm->getObjFileLowering().getDwarfInfoDWOSection());
|
2014-11-02 16:51:37 +08:00
|
|
|
else
|
2015-03-11 00:58:10 +08:00
|
|
|
NewCU.initSection(Asm->getObjFileLowering().getDwarfInfoSection());
|
2013-12-30 11:40:32 +08:00
|
|
|
|
2014-04-23 06:39:41 +08:00
|
|
|
CUMap.insert(std::make_pair(DIUnit, &NewCU));
|
2014-04-29 05:04:29 +08:00
|
|
|
CUDieMap.insert(std::make_pair(&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
|
|
|
}
|
|
|
|
|
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() {
|
2010-04-28 03:46:33 +08:00
|
|
|
if (DisableDebugInfoPrinting)
|
|
|
|
return;
|
|
|
|
|
2012-11-20 06:42:15 +08:00
|
|
|
const Module *M = MMI->getModule();
|
|
|
|
|
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
|
|
|
FunctionDIs = makeSubprogramMap(*M);
|
|
|
|
|
2011-05-04 00:45:22 +08:00
|
|
|
NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu");
|
2013-03-12 07:39:23 +08:00
|
|
|
if (!CU_Nodes)
|
2011-08-16 07:47:24 +08:00
|
|
|
return;
|
2013-09-06 02:48:31 +08:00
|
|
|
TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes);
|
2010-04-05 10:19:28 +08:00
|
|
|
|
2014-03-19 08:11:28 +08:00
|
|
|
SingleCU = CU_Nodes->getNumOperands() == 1;
|
2014-03-18 08:11:48 +08:00
|
|
|
|
2014-11-12 05:30:22 +08:00
|
|
|
for (MDNode *N : CU_Nodes->operands()) {
|
2015-04-30 00:38:44 +08:00
|
|
|
auto *CUNode = cast<DICompileUnit>(N);
|
2014-04-23 06:39:41 +08:00
|
|
|
DwarfCompileUnit &CU = constructDwarfCompileUnit(CUNode);
|
2015-04-07 12:14:33 +08:00
|
|
|
for (auto *IE : CUNode->getImportedEntities())
|
|
|
|
ScopesWithImportedEntities.push_back(std::make_pair(IE->getScope(), IE));
|
2015-03-04 02:40:53 +08:00
|
|
|
// Stable sort to preserve the order of appearance of imported entities.
|
|
|
|
// This is to avoid out-of-order processing of interdependent declarations
|
|
|
|
// within the same scope, e.g. { namespace A = base; namespace B = A; }
|
|
|
|
std::stable_sort(ScopesWithImportedEntities.begin(),
|
|
|
|
ScopesWithImportedEntities.end(), less_first());
|
2015-04-07 12:14:33 +08:00
|
|
|
for (auto *GV : CUNode->getGlobalVariables())
|
|
|
|
CU.getOrCreateGlobalVariableDIE(GV);
|
|
|
|
for (auto *SP : CUNode->getSubprograms())
|
|
|
|
SPMap.insert(std::make_pair(SP, &CU));
|
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.
|
2015-04-30 00:38:44 +08:00
|
|
|
CU.getOrCreateTypeDIE(cast<DIType>(resolve(Ty->getRef())));
|
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.
|
2015-04-30 00:38:44 +08:00
|
|
|
CU.getOrCreateTypeDIE(cast<DIType>(resolve(Ty->getRef())));
|
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())
|
|
|
|
constructAndAddImportedEntityDIE(CU, IE);
|
2013-03-12 07:39:23 +08:00
|
|
|
}
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2010-04-05 10:19:28 +08:00
|
|
|
// Tell MMI that we have debug info.
|
|
|
|
MMI->setDebugInfoAvailability(true);
|
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.
|
|
|
|
DwarfCompileUnit *Unit = lookupUnit(VariableDie->getUnit());
|
|
|
|
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() {
|
2014-10-11 00:59:52 +08:00
|
|
|
for (const auto &P : SPMap)
|
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
|
|
|
forBothCUs(*P.second, [&](DwarfCompileUnit &CU) {
|
2015-04-30 00:38:44 +08:00
|
|
|
CU.finishSubprogramDefinition(cast<DISubprogram>(P.first));
|
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
|
|
|
});
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-22 08:59:49 +08:00
|
|
|
// Collect info for variables that were optimized out.
|
|
|
|
void DwarfDebug::collectDeadVariables() {
|
2010-06-29 02:25:03 +08:00
|
|
|
const Module *M = MMI->getModule();
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2011-08-17 06:09:43 +08:00
|
|
|
if (NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu")) {
|
2014-11-12 05:30:22 +08:00
|
|
|
for (MDNode *N : CU_Nodes->operands()) {
|
2015-04-30 00:38:44 +08:00
|
|
|
auto *TheCU = cast<DICompileUnit>(N);
|
2014-05-15 05:52:46 +08:00
|
|
|
// Construct subprogram DIE and add variables DIEs.
|
|
|
|
DwarfCompileUnit *SPCU =
|
|
|
|
static_cast<DwarfCompileUnit *>(CUMap.lookup(TheCU));
|
|
|
|
assert(SPCU && "Unable to find Compile Unit!");
|
2015-04-07 12:14:33 +08:00
|
|
|
for (auto *SP : TheCU->getSubprograms()) {
|
2013-10-16 07:31:38 +08:00
|
|
|
if (ProcessedSPNodes.count(SP) != 0)
|
|
|
|
continue;
|
2014-11-01 06:30:30 +08:00
|
|
|
SPCU->collectDeadVariables(SP);
|
2010-06-29 02:25:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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();
|
|
|
|
|
2012-11-22 08:59:49 +08:00
|
|
|
// Collect info for variables that were optimized out.
|
|
|
|
collectDeadVariables();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
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.
|
2011-08-17 06:09:43 +08:00
|
|
|
SPMap.clear();
|
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) {
|
2015-04-16 06:29:27 +08:00
|
|
|
auto AbsDbgVariable =
|
2015-04-22 02:44:06 +08:00
|
|
|
make_unique<DbgVariable>(Var, /* IA */ nullptr, /* Expr */ nullptr, this);
|
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
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Collect variable information from side table maintained by MMI.
|
2013-11-19 17:04:36 +08:00
|
|
|
void DwarfDebug::collectVariableInfoFromMMITable(
|
2015-04-16 06:29:27 +08:00
|
|
|
DenseSet<InlinedVariable> &Processed) {
|
2014-03-08 03:09:39 +08:00
|
|
|
for (const auto &VI : MMI->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-30 00:38:44 +08:00
|
|
|
const DIExpression *Expr = cast_or_null<DIExpression>(VI.Expr);
|
2015-04-16 06:29:27 +08:00
|
|
|
ensureAbstractVariableIsCreatedIfScoped(Var, Scope->getScopeNode());
|
|
|
|
auto RegVar =
|
|
|
|
make_unique<DbgVariable>(Var.first, Var.second, Expr, this, 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
|
|
|
}
|
|
|
|
|
2014-08-02 06:11:58 +08:00
|
|
|
/// Determine whether two variable pieces overlap.
|
2015-04-30 00:38:44 +08:00
|
|
|
static bool piecesOverlap(const DIExpression *P1, const DIExpression *P2) {
|
2015-04-14 09:12:42 +08:00
|
|
|
if (!P1->isBitPiece() || !P2->isBitPiece())
|
2014-08-02 06:11:58 +08:00
|
|
|
return true;
|
2015-04-14 09:12:42 +08:00
|
|
|
unsigned l1 = P1->getBitPieceOffset();
|
|
|
|
unsigned l2 = P2->getBitPieceOffset();
|
|
|
|
unsigned r1 = l1 + P1->getBitPieceSize();
|
|
|
|
unsigned r2 = l2 + P2->getBitPieceSize();
|
2014-08-02 06:11:58 +08:00
|
|
|
// True where [l1,r1[ and [r1,r2[ overlap.
|
|
|
|
return (l1 < r2) && (l2 < r1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Build the location list for all DBG_VALUEs in the function that
|
|
|
|
/// describe the same variable. If the ranges of several independent
|
|
|
|
/// pieces of the same variable overlap partially, split them up and
|
|
|
|
/// combine the ranges. The resulting DebugLocEntries are will have
|
|
|
|
/// strict monotonically increasing begin addresses and will never
|
|
|
|
/// overlap.
|
|
|
|
//
|
|
|
|
// Input:
|
|
|
|
//
|
|
|
|
// Ranges History [var, loc, piece ofs size]
|
|
|
|
// 0 | [x, (reg0, piece 0, 32)]
|
|
|
|
// 1 | | [x, (reg1, piece 32, 32)] <- IsPieceOfPrevEntry
|
|
|
|
// 2 | | ...
|
|
|
|
// 3 | [clobber reg0]
|
2015-02-18 04:02:28 +08:00
|
|
|
// 4 [x, (mem, piece 0, 64)] <- overlapping with both previous pieces of
|
|
|
|
// x.
|
2014-08-02 06:11:58 +08:00
|
|
|
//
|
|
|
|
// Output:
|
|
|
|
//
|
|
|
|
// [0-1] [x, (reg0, piece 0, 32)]
|
|
|
|
// [1-3] [x, (reg0, piece 0, 32), (reg1, piece 32, 32)]
|
|
|
|
// [3-4] [x, (reg1, piece 32, 32)]
|
|
|
|
// [4- ] [x, (mem, piece 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this piece overlaps with any open ranges, truncate them.
|
2015-04-30 00:38:44 +08:00
|
|
|
const DIExpression *DIExpr = Begin->getDebugExpression();
|
2014-08-12 05:05:57 +08:00
|
|
|
auto Last = std::remove_if(OpenRanges.begin(), OpenRanges.end(),
|
2014-08-12 07:22:59 +08:00
|
|
|
[&](DebugLocEntry::Value R) {
|
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
|
|
|
return piecesOverlap(DIExpr, R.getExpression());
|
|
|
|
});
|
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;
|
|
|
|
|
|
|
|
// If this is a piece, it may belong to the current DebugLocEntry.
|
2015-04-14 09:12:42 +08:00
|
|
|
if (DIExpr->isBitPiece()) {
|
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
|
|
|
|
|
|
|
// Attempt to add the piece to the last entry.
|
|
|
|
if (!DebugLoc.empty())
|
|
|
|
if (DebugLoc.back().MergeValues(Loc))
|
|
|
|
couldMerge = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!couldMerge) {
|
|
|
|
// Need to add a new DebugLocEntry. Add all values from still
|
|
|
|
// valid non-overlapping pieces.
|
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();
|
|
|
|
auto PrevEntry = std::next(CurEntry);
|
|
|
|
if (PrevEntry != DebugLoc.rend() && PrevEntry->MergeRanges(*CurEntry))
|
|
|
|
DebugLoc.pop_back();
|
2014-08-02 06:11:58 +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
|
|
|
DEBUG({
|
|
|
|
dbgs() << CurEntry->getValues().size() << " Values:\n";
|
|
|
|
for (auto Value : CurEntry->getValues()) {
|
|
|
|
Value.getExpression()->dump();
|
|
|
|
}
|
|
|
|
dbgs() << "-----\n";
|
|
|
|
});
|
2014-08-02 06:11:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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.
|
2013-12-03 23:10:23 +08:00
|
|
|
collectVariableInfoFromMMITable(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);
|
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");
|
2015-04-16 06:29:27 +08:00
|
|
|
ensureAbstractVariableIsCreatedIfScoped(IV, Scope->getScopeNode());
|
2014-06-14 07:52:55 +08:00
|
|
|
ConcreteVariables.push_back(make_unique<DbgVariable>(MInsn, this));
|
2014-06-14 06:18:23 +08:00
|
|
|
DbgVariable *RegVar = ConcreteVariables.back().get();
|
2014-10-24 08:43:47 +08:00
|
|
|
InfoHolder.addScopeVariable(Scope, RegVar);
|
2011-03-26 10:19:36 +08:00
|
|
|
|
2014-05-28 07:09:50 +08:00
|
|
|
// Check if the first DBG_VALUE is valid for the rest of the function.
|
2014-05-31 05:10:13 +08:00
|
|
|
if (Ranges.size() == 1 && Ranges.front().second == nullptr)
|
2010-05-26 07:40:22 +08:00
|
|
|
continue;
|
|
|
|
|
2013-01-29 01:33:26 +08:00
|
|
|
// Handle multiple DBG_VALUE instructions describing one 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
|
|
|
RegVar->setDebugLocListIndex(
|
|
|
|
DebugLocs.startList(&TheCU, Asm->createTempSymbol("debug_loc")));
|
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
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
// If the variable has an 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)
|
|
|
|
Entry.finalize(*Asm, DebugLocs, 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()) {
|
2015-04-16 06:29:27 +08:00
|
|
|
if (!Processed.insert(InlinedVariable(DV, nullptr)).second)
|
2011-08-20 07:28:12 +08:00
|
|
|
continue;
|
2015-04-14 10:22:36 +08:00
|
|
|
if (LexicalScope *Scope = LScopes.findLexicalScope(DV->getScope())) {
|
2015-04-16 06:29:27 +08:00
|
|
|
ensureAbstractVariableIsCreatedIfScoped(InlinedVariable(DV, nullptr),
|
|
|
|
Scope->getScopeNode());
|
2015-04-22 02:44:06 +08:00
|
|
|
ConcreteVariables.push_back(make_unique<DbgVariable>(
|
|
|
|
DV, /* IA */ nullptr, /* Expr */ nullptr, this));
|
2014-10-24 08:43:47 +08:00
|
|
|
InfoHolder.addScopeVariable(Scope, ConcreteVariables.back().get());
|
PR19388: DebugInfo: Emit dead arguments in their originally declared order.
Unused arguments were not being added to the argument list, but instead
treated as arbitrary scope variables. This meant they weren't carefully
added in the original argument order.
In this particular example, though, it turns out the argument is only
/mostly/ unused (well, actually it's entirely used, but in a specific
way). It's a struct that, due to ABI reasons, is decomposed into chunks
(exactly one chunk, since it has one member) and then passed. Since only
one of those chunks is used (SROA, etc, kill the original reconstitution
code) we don't have a location to describe the whole variable.
In this particular case, since the struct consists of just the one int,
once we have partial location information, this should have a location
that describes the entire variable (since the piece is the entirety of
the object).
And at some point we'll need to describe the location of even /entirely/
unused arguments so that they can at least be printed on function entry.
llvm-svn: 210231
2014-06-05 08:51:35 +08:00
|
|
|
}
|
2010-05-15 05:01:35 +08:00
|
|
|
}
|
2010-05-26 07:40:22 +08:00
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Return Label preceding the instruction.
|
2013-01-16 07:56:56 +08:00
|
|
|
MCSymbol *DwarfDebug::getLabelBeforeInsn(const MachineInstr *MI) {
|
2011-03-26 10:19:36 +08:00
|
|
|
MCSymbol *Label = LabelsBeforeInsn.lookup(MI);
|
|
|
|
assert(Label && "Didn't insert label before instruction");
|
|
|
|
return Label;
|
2010-05-26 07:40:22 +08:00
|
|
|
}
|
2010-05-15 05:01:35 +08:00
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Return Label immediately following the instruction.
|
2013-01-16 07:56:56 +08:00
|
|
|
MCSymbol *DwarfDebug::getLabelAfterInsn(const MachineInstr *MI) {
|
2011-03-26 10:19:36 +08:00
|
|
|
return LabelsAfterInsn.lookup(MI);
|
2009-10-06 09:26:37 +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) {
|
2014-04-28 12:05:08 +08:00
|
|
|
assert(CurMI == nullptr);
|
2013-12-03 23:10:23 +08:00
|
|
|
CurMI = MI;
|
2011-03-26 01:20:59 +08:00
|
|
|
// Check if source location changes, but ignore DBG_VALUE locations.
|
|
|
|
if (!MI->isDebugValue()) {
|
|
|
|
DebugLoc DL = MI->getDebugLoc();
|
2015-03-21 03:37:03 +08:00
|
|
|
if (DL != PrevInstLoc) {
|
2015-03-31 03:14:47 +08:00
|
|
|
if (DL) {
|
2015-03-21 03:37:03 +08:00
|
|
|
unsigned Flags = 0;
|
|
|
|
PrevInstLoc = DL;
|
|
|
|
if (DL == PrologEndLoc) {
|
|
|
|
Flags |= DWARF2_FLAG_PROLOGUE_END;
|
|
|
|
PrologEndLoc = DebugLoc();
|
|
|
|
Flags |= DWARF2_FLAG_IS_STMT;
|
|
|
|
}
|
|
|
|
if (DL.getLine() !=
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->getContext().getCurrentDwarfLoc().getLine())
|
2015-03-21 03:37:03 +08:00
|
|
|
Flags |= DWARF2_FLAG_IS_STMT;
|
|
|
|
|
2015-03-31 03:14:47 +08:00
|
|
|
const MDNode *Scope = DL.getScope();
|
2011-05-12 03:22:19 +08:00
|
|
|
recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags);
|
2015-03-21 03:37:03 +08:00
|
|
|
} else if (UnknownLocations) {
|
|
|
|
PrevInstLoc = DL;
|
2014-04-24 14:44:33 +08:00
|
|
|
recordSourceLine(0, 0, nullptr, 0);
|
2015-03-21 03:37:03 +08:00
|
|
|
}
|
2011-03-26 01:20:59 +08:00
|
|
|
}
|
2010-05-27 03:37:24 +08:00
|
|
|
}
|
|
|
|
|
2011-03-26 01:20:59 +08:00
|
|
|
// Insert labels where requested.
|
2013-11-19 17:04:36 +08:00
|
|
|
DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
|
|
|
|
LabelsBeforeInsn.find(MI);
|
2011-03-26 10:19:36 +08:00
|
|
|
|
|
|
|
// No label needed.
|
|
|
|
if (I == LabelsBeforeInsn.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Label already assigned.
|
|
|
|
if (I->second)
|
2010-03-30 01:20:31 +08:00
|
|
|
return;
|
2010-05-27 03:37:24 +08:00
|
|
|
|
2011-03-26 01:20:59 +08:00
|
|
|
if (!PrevLabel) {
|
2015-05-19 02:43:14 +08:00
|
|
|
PrevLabel = MMI->getContext().createTempSymbol();
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->EmitLabel(PrevLabel);
|
2010-04-28 03:46:33 +08:00
|
|
|
}
|
2011-03-26 10:19:36 +08:00
|
|
|
I->second = PrevLabel;
|
2009-10-06 09:50:42 +08:00
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Process end of an instruction.
|
2013-12-03 23:10:23 +08:00
|
|
|
void DwarfDebug::endInstruction() {
|
2014-04-28 12:05:08 +08:00
|
|
|
assert(CurMI != nullptr);
|
2011-03-26 01:20:59 +08:00
|
|
|
// Don't create a new label after DBG_VALUE instructions.
|
|
|
|
// They don't generate code.
|
2013-12-03 23:10:23 +08:00
|
|
|
if (!CurMI->isDebugValue())
|
2014-04-24 14:44:33 +08:00
|
|
|
PrevLabel = nullptr;
|
2011-03-26 01:20:59 +08:00
|
|
|
|
2013-11-19 17:04:36 +08:00
|
|
|
DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
|
2013-12-03 23:10:23 +08:00
|
|
|
LabelsAfterInsn.find(CurMI);
|
2014-04-24 14:44:33 +08:00
|
|
|
CurMI = nullptr;
|
2011-03-26 10:19:36 +08:00
|
|
|
|
|
|
|
// No label needed.
|
|
|
|
if (I == LabelsAfterInsn.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Label already assigned.
|
|
|
|
if (I->second)
|
2011-03-26 01:20:59 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// We need a label after this instruction.
|
|
|
|
if (!PrevLabel) {
|
2015-05-19 02:43:14 +08:00
|
|
|
PrevLabel = MMI->getContext().createTempSymbol();
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->EmitLabel(PrevLabel);
|
2010-04-09 00:50:29 +08:00
|
|
|
}
|
2011-03-26 10:19:36 +08:00
|
|
|
I->second = PrevLabel;
|
2009-11-11 07:06:00 +08:00
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Each LexicalScope has first instruction and last instruction to mark
|
|
|
|
// beginning and end of a scope respectively. Create an inverse map that list
|
|
|
|
// scopes starts (and ends) with an instruction. One instruction may start (or
|
|
|
|
// end) multiple scopes. Ignore scopes that are not reachable.
|
2010-04-09 02:43:56 +08:00
|
|
|
void DwarfDebug::identifyScopeMarkers() {
|
2011-08-11 04:55:27 +08:00
|
|
|
SmallVector<LexicalScope *, 4> WorkList;
|
|
|
|
WorkList.push_back(LScopes.getCurrentFunctionScope());
|
2010-01-20 10:05:23 +08:00
|
|
|
while (!WorkList.empty()) {
|
2011-08-11 04:55:27 +08:00
|
|
|
LexicalScope *S = WorkList.pop_back_val();
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2013-07-03 12:24:43 +08:00
|
|
|
const SmallVectorImpl<LexicalScope *> &Children = S->getChildren();
|
2010-07-22 05:21:52 +08:00
|
|
|
if (!Children.empty())
|
2014-03-08 03:09:39 +08:00
|
|
|
WorkList.append(Children.begin(), Children.end());
|
2010-01-20 10:05:23 +08:00
|
|
|
|
2009-11-11 07:06:00 +08:00
|
|
|
if (S->isAbstractScope())
|
|
|
|
continue;
|
2010-07-22 05:21:52 +08:00
|
|
|
|
2014-03-08 03:09:39 +08:00
|
|
|
for (const InsnRange &R : S->getRanges()) {
|
|
|
|
assert(R.first && "InsnRange does not have first instruction!");
|
|
|
|
assert(R.second && "InsnRange does not have second instruction!");
|
|
|
|
requestLabelBeforeInsn(R.first);
|
|
|
|
requestLabelAfterInsn(R.second);
|
2010-04-28 03:46:33 +08:00
|
|
|
}
|
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-03-31 03:14:47 +08:00
|
|
|
MI.getDebugLoc()) {
|
2014-12-16 08:20:49 +08:00
|
|
|
// Did the target forget to set the FrameSetup flag for CFI insns?
|
|
|
|
assert(!MI.isCFIInstruction() &&
|
|
|
|
"First non-frame-setup instruction is a CFI instruction.");
|
2014-05-28 06:47:41 +08:00
|
|
|
return MI.getDebugLoc();
|
2014-12-16 08:20:49 +08:00
|
|
|
}
|
2014-05-28 06:47:41 +08:00
|
|
|
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.
|
2010-01-27 07:18:02 +08:00
|
|
|
void DwarfDebug::beginFunction(const MachineFunction *MF) {
|
2013-12-03 23:10:23 +08:00
|
|
|
CurFn = MF;
|
2013-11-02 07:14:17 +08:00
|
|
|
|
|
|
|
// If there's no debug info for the function we're not going to do anything.
|
|
|
|
if (!MMI->hasDebugInfo())
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
auto DI = FunctionDIs.find(MF->getFunction());
|
|
|
|
if (DI == FunctionDIs.end())
|
|
|
|
return;
|
|
|
|
|
2013-11-02 07:14:17 +08:00
|
|
|
// Grab the lexical scopes for the function, if we don't have any of those
|
|
|
|
// then we're not going to be able to do anything.
|
2011-08-11 04:55:27 +08:00
|
|
|
LScopes.initialize(*MF);
|
2014-03-21 03:16:16 +08:00
|
|
|
if (LScopes.empty())
|
2013-11-02 07:14:17 +08:00
|
|
|
return;
|
|
|
|
|
2014-05-01 07:02:40 +08:00
|
|
|
assert(DbgValues.empty() && "DbgValues map wasn't cleaned!");
|
2013-11-02 07:14:17 +08:00
|
|
|
|
|
|
|
// Make sure that each lexical scope will have a begin/end label.
|
2011-08-11 04:55:27 +08:00
|
|
|
identifyScopeMarkers();
|
2009-10-07 02:37:31 +08:00
|
|
|
|
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)))
|
2013-12-10 07:57:44 +08:00
|
|
|
DwarfCompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode());
|
2013-02-06 05:52:47 +08:00
|
|
|
assert(TheCU && "Unable to find compile unit!");
|
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
|
|
|
|
2014-05-01 05:34:11 +08:00
|
|
|
// Calculate history for local variables.
|
2015-02-21 06:36:11 +08:00
|
|
|
calculateDbgValueHistory(MF, Asm->MF->getSubtarget().getRegisterInfo(),
|
2014-08-05 05:25:23 +08:00
|
|
|
DbgValues);
|
2014-05-01 05:34:11 +08:00
|
|
|
|
|
|
|
// Request labels for the full history.
|
2014-05-28 07:09:50 +08:00
|
|
|
for (const auto &I : DbgValues) {
|
|
|
|
const auto &Ranges = I.second;
|
|
|
|
if (Ranges.empty())
|
2011-03-26 10:19:36 +08:00
|
|
|
continue;
|
|
|
|
|
2015-03-05 10:05:42 +08:00
|
|
|
// The first mention of a function argument gets the CurrentFnBegin
|
2014-05-01 05:34:11 +08:00
|
|
|
// label, so arguments are visible when breaking at function entry.
|
2015-04-30 00:38:44 +08:00
|
|
|
const DILocalVariable *DIVar = Ranges.front().first->getDebugVariable();
|
2015-04-14 10:22:36 +08:00
|
|
|
if (DIVar->getTag() == dwarf::DW_TAG_arg_variable &&
|
2015-04-14 11:40:37 +08:00
|
|
|
getDISubprogram(DIVar->getScope())->describes(MF->getFunction())) {
|
2015-03-05 10:05:42 +08:00
|
|
|
LabelsBeforeInsn[Ranges.front().first] = Asm->getFunctionBegin();
|
2015-04-14 09:12:42 +08:00
|
|
|
if (Ranges.front().first->getDebugExpression()->isBitPiece()) {
|
2014-08-02 06:11:58 +08:00
|
|
|
// Mark all non-overlapping initial pieces.
|
|
|
|
for (auto I = Ranges.begin(); I != Ranges.end(); ++I) {
|
2015-04-30 00:38:44 +08:00
|
|
|
const DIExpression *Piece = I->first->getDebugExpression();
|
2014-08-02 06:11:58 +08:00
|
|
|
if (std::all_of(Ranges.begin(), I,
|
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
|
|
|
[&](DbgValueHistoryMap::InstrRange Pred) {
|
|
|
|
return !piecesOverlap(Piece, Pred.first->getDebugExpression());
|
2014-08-02 06:11:58 +08:00
|
|
|
}))
|
2015-03-05 10:05:42 +08:00
|
|
|
LabelsBeforeInsn[I->first] = Asm->getFunctionBegin();
|
2014-08-02 06:11:58 +08:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-01 05:34:11 +08:00
|
|
|
|
2014-05-28 07:09:50 +08:00
|
|
|
for (const auto &Range : Ranges) {
|
|
|
|
requestLabelBeforeInsn(Range.first);
|
|
|
|
if (Range.second)
|
|
|
|
requestLabelAfterInsn(Range.second);
|
2011-03-26 10:19:36 +08:00
|
|
|
}
|
|
|
|
}
|
2010-05-27 03:37:24 +08:00
|
|
|
|
2011-03-26 01:20:59 +08:00
|
|
|
PrevInstLoc = DebugLoc();
|
2015-03-05 10:05:42 +08:00
|
|
|
PrevLabel = Asm->getFunctionBegin();
|
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
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Gather and emit post-function debug information.
|
2013-12-03 21:15:54 +08:00
|
|
|
void DwarfDebug::endFunction(const MachineFunction *MF) {
|
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
|
|
|
|
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
|
|
|
if (!MMI->hasDebugInfo() || LScopes.empty() ||
|
|
|
|
!FunctionDIs.count(MF->getFunction())) {
|
2014-03-21 03:16:16 +08:00
|
|
|
// If we don't have a lexical scope 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;
|
2014-04-24 14:44:33 +08:00
|
|
|
CurFn = nullptr;
|
2013-11-19 17:04:36 +08:00
|
|
|
return;
|
2013-12-03 23:10:23 +08:00
|
|
|
}
|
2010-05-22 08:04:14 +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();
|
2015-04-30 00:38:44 +08:00
|
|
|
auto *SP = cast<DISubprogram>(FnScope->getScopeNode());
|
2014-10-23 08:06:27 +08:00
|
|
|
DwarfCompileUnit &TheCU = *SPMap.lookup(SP);
|
|
|
|
|
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
|
|
|
|
// subroutines inside it.
|
2015-04-16 07:19:27 +08:00
|
|
|
if (TheCU.getCUNode()->getEmissionKind() == DIBuilder::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
|
|
|
assert(DbgValues.empty());
|
2014-10-10 02:24:28 +08:00
|
|
|
// FIXME: This wouldn't be true in LTO with a -g (with inlining) CU followed
|
|
|
|
// by a -gmlt CU. Add a test and remove this assertion.
|
2014-09-20 01:03:16 +08:00
|
|
|
assert(AbstractVariables.empty());
|
|
|
|
LabelsBeforeInsn.clear();
|
|
|
|
LabelsAfterInsn.clear();
|
|
|
|
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
|
|
|
|
2014-10-10 04:21:36 +08:00
|
|
|
TheCU.constructSubprogramScopeDIE(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())
|
|
|
|
if (!LScopes.getAbstractScopesList().empty())
|
|
|
|
SkelCU->constructSubprogramScopeDIE(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();
|
2011-03-26 10:19:36 +08:00
|
|
|
DbgValues.clear();
|
2010-04-28 03:46:33 +08:00
|
|
|
LabelsBeforeInsn.clear();
|
|
|
|
LabelsAfterInsn.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))
|
2015-04-14 11:40:37 +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
|
|
|
}
|
|
|
|
|
2014-09-12 05:12:48 +08:00
|
|
|
void DwarfDebug::emitAccel(DwarfAccelTable &Accel, const 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) {
|
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.
|
|
|
|
DIEValue *SpecVal = Die->findAttribute(dwarf::DW_AT_specification);
|
|
|
|
if (SpecVal) {
|
2014-04-26 03:33:43 +08:00
|
|
|
DIE &SpecDIE = cast<DIEEntry>(SpecVal)->getEntry();
|
|
|
|
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) {
|
|
|
|
const 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(
|
|
|
|
bool GnuStyle, const 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-03-11 00:58:10 +08:00
|
|
|
Asm->emitSectionOffset(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) {
|
2013-09-24 04:55:35 +08:00
|
|
|
const 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
|
|
|
}
|
|
|
|
|
2012-12-27 10:14:01 +08:00
|
|
|
// Emit visible names into a debug str section.
|
|
|
|
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,
|
|
|
|
unsigned PieceOffsetInBits) {
|
2015-03-13 08:38:19 +08:00
|
|
|
DebugLocDwarfExpression DwarfExpr(*AP.MF->getSubtarget().getRegisterInfo(),
|
|
|
|
AP.getDwarfDebug()->getDwarfVersion(),
|
|
|
|
Streamer);
|
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();
|
2015-04-30 00:38:44 +08:00
|
|
|
const DIExpression *Expr = Value.getExpression();
|
2015-04-14 09:12:42 +08:00
|
|
|
if (!Expr || !Expr->getNumElements())
|
2014-03-08 06:40:37 +08:00
|
|
|
// Regular entry.
|
2015-03-03 06:02:33 +08:00
|
|
|
AP.EmitDwarfRegOp(Streamer, Loc);
|
2014-03-08 06:40:37 +08:00
|
|
|
else {
|
|
|
|
// Complex address entry.
|
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
|
|
|
if (Loc.getOffset()) {
|
|
|
|
DwarfExpr.AddMachineRegIndirect(Loc.getReg(), Loc.getOffset());
|
2015-04-07 11:45:57 +08:00
|
|
|
DwarfExpr.AddExpression(Expr->expr_op_begin(), Expr->expr_op_end(),
|
|
|
|
PieceOffsetInBits);
|
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
|
|
|
} else
|
|
|
|
DwarfExpr.AddMachineRegExpression(Expr, Loc.getReg(),
|
|
|
|
PieceOffsetInBits);
|
2014-03-08 06:40:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// else ... ignore constant fp. There is not any good way to
|
|
|
|
// to represent them here in dwarf.
|
|
|
|
// FIXME: ^
|
|
|
|
}
|
|
|
|
|
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 DebugLocEntry::finalize(const AsmPrinter &AP, DebugLocStream &Locs,
|
2015-04-30 00:38:44 +08:00
|
|
|
const DIBasicType *BT) {
|
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
|
|
|
Locs.startEntry(Begin, End);
|
|
|
|
BufferByteStreamer Streamer = Locs.getStreamer();
|
|
|
|
const DebugLocEntry::Value &Value = Values[0];
|
2015-03-03 06:02:33 +08:00
|
|
|
if (Value.isBitPiece()) {
|
|
|
|
// Emit all pieces that belong to the same variable and range.
|
|
|
|
assert(std::all_of(Values.begin(), Values.end(), [](DebugLocEntry::Value P) {
|
|
|
|
return P.isBitPiece();
|
|
|
|
}) && "all values are expected to be pieces");
|
|
|
|
assert(std::is_sorted(Values.begin(), Values.end()) &&
|
|
|
|
"pieces are expected to be sorted");
|
|
|
|
|
|
|
|
unsigned Offset = 0;
|
|
|
|
for (auto Piece : Values) {
|
2015-04-30 00:38:44 +08:00
|
|
|
const DIExpression *Expr = Piece.getExpression();
|
2015-04-14 09:12:42 +08:00
|
|
|
unsigned PieceOffset = Expr->getBitPieceOffset();
|
|
|
|
unsigned PieceSize = Expr->getBitPieceSize();
|
2015-03-03 06:02:33 +08:00
|
|
|
assert(Offset <= PieceOffset && "overlapping or duplicate pieces");
|
|
|
|
if (Offset < PieceOffset) {
|
|
|
|
// The DWARF spec seriously mandates pieces with no locations for gaps.
|
2015-03-13 08:38:19 +08:00
|
|
|
DebugLocDwarfExpression Expr(*AP.MF->getSubtarget().getRegisterInfo(),
|
|
|
|
AP.getDwarfDebug()->getDwarfVersion(),
|
|
|
|
Streamer);
|
2015-03-03 06:02:33 +08:00
|
|
|
Expr.AddOpPiece(PieceOffset-Offset, 0);
|
|
|
|
Offset += PieceOffset-Offset;
|
|
|
|
}
|
|
|
|
Offset += PieceSize;
|
2015-04-14 02:53:11 +08:00
|
|
|
|
2015-04-18 00:28:58 +08:00
|
|
|
emitDebugLocValue(AP, BT, Streamer, Piece, PieceOffset);
|
2015-03-03 06:02:33 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
assert(Values.size() == 1 && "only pieces may have >1 value");
|
2015-04-18 00:28:58 +08:00
|
|
|
emitDebugLocValue(AP, BT, Streamer, Value, 0);
|
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?)
|
|
|
|
Asm->EmitInt8(dwarf::DW_LLE_start_length_entry);
|
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
|
|
|
}
|
2014-04-02 09:50:20 +08:00
|
|
|
Asm->EmitInt8(dwarf::DW_LLE_end_of_list_entry);
|
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-03-10 06:08:37 +08:00
|
|
|
MapVector<const 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.
|
|
|
|
const MCSection *Section = &SCU.Sym->getSection();
|
|
|
|
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
|
|
|
// Add terminating symbols for each section.
|
2015-03-10 06:08:37 +08:00
|
|
|
for (const auto &I : SectionMap) {
|
|
|
|
const MCSection *Section = I.first;
|
2015-02-27 06:02:02 +08:00
|
|
|
MCSymbol *Sym = nullptr;
|
|
|
|
|
2015-03-24 05:22:04 +08:00
|
|
|
if (Section)
|
2015-04-25 03:11:51 +08:00
|
|
|
Sym = Asm->OutStreamer->endSection(Section);
|
2015-02-27 06:02:02 +08:00
|
|
|
|
|
|
|
// Insert a final terminator.
|
|
|
|
SectionMap[Section].push_back(SymbolCU(nullptr, Sym));
|
|
|
|
}
|
|
|
|
|
|
|
|
DenseMap<DwarfCompileUnit *, std::vector<ArangeSpan>> Spans;
|
|
|
|
|
2015-03-10 06:08:37 +08:00
|
|
|
for (auto &I : SectionMap) {
|
|
|
|
const MCSection *Section = I.first;
|
|
|
|
SmallVector<SymbolCU, 8> &List = I.second;
|
2013-09-20 07:21:01 +08:00
|
|
|
if (List.size() < 2)
|
|
|
|
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;
|
|
|
|
if (Cur.CU)
|
|
|
|
Spans[Cur.CU].push_back(Span);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-09-20 07:21:01 +08:00
|
|
|
// Sort the symbols by offset within the section.
|
2014-03-08 03:41:22 +08:00
|
|
|
std::sort(List.begin(), List.end(),
|
|
|
|
[&](const SymbolCU &A, const SymbolCU &B) {
|
2015-04-25 03:11:51 +08:00
|
|
|
unsigned IA = A.Sym ? Asm->OutStreamer->GetSymbolOrder(A.Sym) : 0;
|
|
|
|
unsigned IB = B.Sym ? Asm->OutStreamer->GetSymbolOrder(B.Sym) : 0;
|
2014-03-08 03:41:22 +08:00
|
|
|
|
|
|
|
// 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
|
|
|
|
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;
|
|
|
|
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).
|
2014-03-08 03:41:22 +08:00
|
|
|
std::sort(CUs.begin(), CUs.end(), [](const DwarfUnit *A, const DwarfUnit *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-03-11 00:58:10 +08:00
|
|
|
Asm->emitSectionOffset(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);
|
|
|
|
|
2015-04-25 03:11:51 +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
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Emit visible names 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
|
|
|
}
|
|
|
|
|
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,
|
2014-04-23 06:39:41 +08:00
|
|
|
std::unique_ptr<DwarfUnit> 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;
|
2015-03-11 00:58:10 +08:00
|
|
|
NewCU.initSection(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-04-25 03:11:51 +08:00
|
|
|
SplitTypeUnitFileTable.Emit(*Asm->OutStreamer);
|
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?");
|
2013-11-19 17:04:36 +08:00
|
|
|
const 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;
|
|
|
|
}
|
|
|
|
|
2014-04-27 00:26:41 +08:00
|
|
|
static uint64_t makeTypeSignature(StringRef Identifier) {
|
|
|
|
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;
|
|
|
|
|
2013-12-18 07:32:35 +08:00
|
|
|
const DwarfTypeUnit *&TU = DwarfTypeUnits[CTy];
|
2014-01-20 16:07:07 +08:00
|
|
|
if (TU) {
|
2014-02-12 08:31:30 +08:00
|
|
|
CU.addDIETypeSignature(RefDie, *TU);
|
2014-01-20 16:07:07 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-27 01:27:38 +08:00
|
|
|
bool TopLevelType = TypeUnitsUnderConstruction.empty();
|
|
|
|
AddrPool.resetUsedFlag();
|
|
|
|
|
2014-07-26 01:11:58 +08:00
|
|
|
auto OwnedUnit = make_unique<DwarfTypeUnit>(
|
|
|
|
InfoHolder.getUnits().size() + TypeUnitsUnderConstruction.size(), 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();
|
2014-04-23 06:39:41 +08:00
|
|
|
TU = &NewTU;
|
2014-04-29 04:42:22 +08:00
|
|
|
TypeUnitsUnderConstruction.push_back(
|
|
|
|
std::make_pair(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);
|
2014-04-27 00:26:41 +08:00
|
|
|
|
2014-07-26 01:11:58 +08:00
|
|
|
if (useSplitDwarf())
|
2014-11-02 04:06:28 +08:00
|
|
|
NewTU.initSection(Asm->getObjFileLowering().getDwarfTypesDWOSection());
|
2014-07-26 01:11:58 +08:00
|
|
|
else {
|
2014-04-29 05:04:29 +08:00
|
|
|
CU.applyStmtList(UnitDie);
|
2014-07-26 01:11:58 +08:00
|
|
|
NewTU.initSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfTypesSection(Signature));
|
|
|
|
}
|
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)
|
|
|
|
DwarfTypeUnits.erase(TU.second);
|
|
|
|
|
|
|
|
// 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.
|
2014-08-27 13:04:14 +08:00
|
|
|
for (auto &TU : TypeUnitsToAdd)
|
2014-04-27 01:27:38 +08:00
|
|
|
InfoHolder.addUnit(std::move(TU.first));
|
|
|
|
}
|
2014-04-23 06:39:41 +08:00
|
|
|
CU.addDIETypeSignature(RefDie, NewTU);
|
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;
|
2014-04-26 06:21:35 +08:00
|
|
|
AccelNames.AddName(Name, InfoHolder.getStringPool().getSymbol(*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;
|
2014-04-26 06:21:35 +08:00
|
|
|
AccelObjC.AddName(Name, InfoHolder.getStringPool().getSymbol(*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;
|
2014-04-26 06:21:35 +08:00
|
|
|
AccelNamespace.AddName(Name, InfoHolder.getStringPool().getSymbol(*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;
|
2014-04-26 06:21:35 +08:00
|
|
|
AccelTypes.AddName(Name, InfoHolder.getStringPool().getSymbol(*Asm, Name),
|
|
|
|
&Die);
|
2014-04-24 09:23:49 +08:00
|
|
|
}
|