2017-08-18 05:26:39 +08:00
|
|
|
//===- llvm/CodeGen/DwarfDebug.cpp - Dwarf Debug Framework ----------------===//
|
2009-05-15 17:23:25 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-05-15 17:23:25 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "DebugLocStream.h"
|
2015-01-14 19:23:27 +08:00
|
|
|
#include "DwarfCompileUnit.h"
|
|
|
|
#include "DwarfExpression.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "DwarfFile.h"
|
2013-12-03 03:33:15 +08:00
|
|
|
#include "DwarfUnit.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/ADT/APInt.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/DenseSet.h"
|
|
|
|
#include "llvm/ADT/MapVector.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
2018-01-29 22:52:41 +08:00
|
|
|
#include "llvm/CodeGen/AccelTable.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2015-01-06 05:29:41 +08:00
|
|
|
#include "llvm/CodeGen/DIE.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/CodeGen/LexicalScopes.h"
|
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
2018-10-06 04:37:17 +08:00
|
|
|
#include "llvm/CodeGen/TargetInstrInfo.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.h"
|
|
|
|
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
2019-03-19 21:16:28 +08:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
|
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
|
|
|
#include "llvm/IR/DebugLoc.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/GlobalVariable.h"
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2010-03-09 09:58:53 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2015-08-07 23:14:08 +08:00
|
|
|
#include "llvm/MC/MCDwarf.h"
|
2009-08-01 02:48:30 +08:00
|
|
|
#include "llvm/MC/MCSection.h"
|
2009-08-19 13:49:37 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2010-03-09 09:58:53 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/MC/MCTargetOptions.h"
|
|
|
|
#include "llvm/MC/MachineLocation.h"
|
|
|
|
#include "llvm/MC/SectionKind.h"
|
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/Support/Casting.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"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2013-07-27 01:02:41 +08:00
|
|
|
#include "llvm/Support/MD5.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include "llvm/Support/MathExtras.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"
|
2018-03-24 07:58:19 +08:00
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2017-08-18 05:26:39 +08:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <iterator>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2016-02-03 02:20:45 +08:00
|
|
|
|
2009-05-15 17:23:25 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:02:50 +08:00
|
|
|
#define DEBUG_TYPE "dwarfdebug"
|
|
|
|
|
2013-07-24 06:16:41 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
DisableDebugInfoPrinting("disable-debug-info-print", cl::Hidden,
|
|
|
|
cl::desc("Disable debug info printing"));
|
2010-04-28 03:46:33 +08:00
|
|
|
|
2017-08-01 05:48:42 +08:00
|
|
|
static cl::opt<bool> UseDwarfRangesBaseAddressSpecifier(
|
|
|
|
"use-dwarf-ranges-base-address-specifier", cl::Hidden,
|
2017-08-01 22:50:50 +08:00
|
|
|
cl::desc("Use base address specifiers in debug_ranges"), cl::init(false));
|
2017-08-01 05:48:42 +08:00
|
|
|
|
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));
|
|
|
|
|
[DebugInfo] Generate .debug_names section when it makes sense
Summary:
This patch makes us generate the debug_names section in response to some
user-facing commands (previously it was only generated if explicitly
selected via the -accel-tables option).
My goal was to make this work for DWARF>=5 (as it's an official part of
that standard), and also, as an extension, for DWARF<5 if one is
explicitly tuning for lldb as a debugger (because it brings a large
performance improvement there).
This is slightly complicated by the fact that the debug_names tables are
incompatible with the DWARF v4 type units (they assume that the type
units are in the debug_info section), and unfortunately, right now we
generate DWARF v4-style type units even for -gdwarf-5. For this reason,
I disable all accelerator tables if the user requested type unit
generation. I do this even for apple tables, as they have the same
problem (in fact generating type units for apple targets makes us crash
even before we get around to emitting the accelerator tables).
Reviewers: JDevlieghere, aprantl, dblaikie, echristo, probinson
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D49420
llvm-svn: 337544
2018-07-20 20:59:05 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
GenerateDwarfTypeUnits("generate-type-units", cl::Hidden,
|
|
|
|
cl::desc("Generate DWARF4 type units."),
|
|
|
|
cl::init(false));
|
|
|
|
|
2017-05-12 09:13:45 +08:00
|
|
|
static cl::opt<bool> SplitDwarfCrossCuReferences(
|
|
|
|
"split-dwarf-cross-cu-references", cl::Hidden,
|
|
|
|
cl::desc("Enable cross-cu references in DWO files"), cl::init(false));
|
|
|
|
|
2014-01-28 07:50:03 +08:00
|
|
|
enum DefaultOnOff { Default, Enable, Disable };
|
2011-11-07 17:24:32 +08:00
|
|
|
|
2016-12-13 04:49:11 +08:00
|
|
|
static cl::opt<DefaultOnOff> UnknownLocations(
|
|
|
|
"use-unknown-locations", cl::Hidden,
|
|
|
|
cl::desc("Make an absence of debug location information explicit."),
|
|
|
|
cl::values(clEnumVal(Default, "At top of block or after label"),
|
|
|
|
clEnumVal(Enable, "In all cases"), clEnumVal(Disable, "Never")),
|
|
|
|
cl::init(Default));
|
|
|
|
|
2018-04-04 22:42:14 +08:00
|
|
|
static cl::opt<AccelTableKind> AccelTables(
|
|
|
|
"accel-tables", cl::Hidden, cl::desc("Output dwarf accelerator tables."),
|
|
|
|
cl::values(clEnumValN(AccelTableKind::Default, "Default",
|
|
|
|
"Default for platform"),
|
|
|
|
clEnumValN(AccelTableKind::None, "Disable", "Disabled."),
|
|
|
|
clEnumValN(AccelTableKind::Apple, "Apple", "Apple"),
|
|
|
|
clEnumValN(AccelTableKind::Dwarf, "Dwarf", "DWARF")),
|
|
|
|
cl::init(AccelTableKind::Default));
|
2012-08-24 06:36:40 +08:00
|
|
|
|
2018-02-20 23:28:08 +08:00
|
|
|
static cl::opt<DefaultOnOff>
|
|
|
|
DwarfInlinedStrings("dwarf-inlined-strings", cl::Hidden,
|
|
|
|
cl::desc("Use inlined strings rather than string section."),
|
|
|
|
cl::values(clEnumVal(Default, "Default for platform"),
|
|
|
|
clEnumVal(Enable, "Enabled"),
|
|
|
|
clEnumVal(Disable, "Disabled")),
|
|
|
|
cl::init(Default));
|
|
|
|
|
2018-03-21 04:21:38 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
NoDwarfRangesSection("no-dwarf-ranges-section", cl::Hidden,
|
|
|
|
cl::desc("Disable emission .debug_ranges section."),
|
|
|
|
cl::init(false));
|
|
|
|
|
2018-03-23 21:35:54 +08:00
|
|
|
static cl::opt<DefaultOnOff> DwarfSectionsAsReferences(
|
|
|
|
"dwarf-sections-as-references", cl::Hidden,
|
|
|
|
cl::desc("Use sections+offset as references rather than labels."),
|
|
|
|
cl::values(clEnumVal(Default, "Default for platform"),
|
|
|
|
clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")),
|
|
|
|
cl::init(Default));
|
|
|
|
|
2016-04-19 06:41:41 +08:00
|
|
|
enum LinkageNameOption {
|
|
|
|
DefaultLinkageNames,
|
|
|
|
AllLinkageNames,
|
|
|
|
AbstractLinkageNames
|
|
|
|
};
|
2017-08-18 05:26:39 +08:00
|
|
|
|
2016-04-19 06:41:41 +08:00
|
|
|
static cl::opt<LinkageNameOption>
|
|
|
|
DwarfLinkageNames("dwarf-linkage-names", cl::Hidden,
|
|
|
|
cl::desc("Which DWARF linkage-name attributes to emit."),
|
|
|
|
cl::values(clEnumValN(DefaultLinkageNames, "Default",
|
|
|
|
"Default for platform"),
|
|
|
|
clEnumValN(AllLinkageNames, "All", "All"),
|
|
|
|
clEnumValN(AbstractLinkageNames, "Abstract",
|
2016-10-09 03:41:06 +08:00
|
|
|
"Abstract subprograms")),
|
2016-04-19 06:41:41 +08:00
|
|
|
cl::init(DefaultLinkageNames));
|
2015-08-12 05:36:45 +08:00
|
|
|
|
2016-11-19 03:43:18 +08:00
|
|
|
static const char *const DWARFGroupName = "dwarf";
|
|
|
|
static const char *const DWARFGroupDescription = "DWARF Emission";
|
|
|
|
static const char *const DbgTimerName = "writer";
|
|
|
|
static const char *const DbgTimerDescription = "DWARF Debug Writer";
|
2019-03-19 21:16:28 +08:00
|
|
|
static constexpr unsigned ULEB128PadSize = 4;
|
2010-04-07 17:28:04 +08:00
|
|
|
|
2017-03-17 01:42:45 +08:00
|
|
|
void DebugLocDwarfExpression::emitOp(uint8_t Op, const char *Comment) {
|
2015-03-03 06:02:33 +08:00
|
|
|
BS.EmitInt8(
|
|
|
|
Op, Comment ? Twine(Comment) + " " + dwarf::OperationEncodingString(Op)
|
|
|
|
: dwarf::OperationEncodingString(Op));
|
|
|
|
}
|
|
|
|
|
2017-03-17 01:42:45 +08:00
|
|
|
void DebugLocDwarfExpression::emitSigned(int64_t Value) {
|
2015-03-03 06:02:33 +08:00
|
|
|
BS.EmitSLEB128(Value, Twine(Value));
|
|
|
|
}
|
|
|
|
|
2017-03-17 01:42:45 +08:00
|
|
|
void DebugLocDwarfExpression::emitUnsigned(uint64_t Value) {
|
2015-03-03 06:02:33 +08:00
|
|
|
BS.EmitULEB128(Value, Twine(Value));
|
|
|
|
}
|
|
|
|
|
2019-03-19 21:16:28 +08:00
|
|
|
void DebugLocDwarfExpression::emitBaseTypeRef(uint64_t Idx) {
|
|
|
|
assert(Idx < (1ULL << (ULEB128PadSize * 7)) && "Idx wont fit");
|
|
|
|
BS.EmitULEB128(Idx, Twine(Idx), ULEB128PadSize);
|
|
|
|
}
|
|
|
|
|
2016-05-21 03:35:17 +08:00
|
|
|
bool DebugLocDwarfExpression::isFrameRegister(const TargetRegisterInfo &TRI,
|
|
|
|
unsigned MachineReg) {
|
2015-03-03 06:02:33 +08:00
|
|
|
// This information is not available while emitting .debug_loc entries.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-18 10:34:58 +08:00
|
|
|
bool DbgVariable::isBlockByrefVariable() const {
|
2018-08-17 23:22:04 +08:00
|
|
|
assert(getVariable() && "Invalid complex DbgVariable!");
|
|
|
|
return getVariable()->getType().resolve()->isBlockByrefStruct();
|
2014-03-18 10:34:58 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
const DIType *DbgVariable::getType() const {
|
2018-08-17 23:22:04 +08:00
|
|
|
DIType *Ty = getVariable()->getType().resolve();
|
2011-04-13 06:53:02 +08:00
|
|
|
// FIXME: isBlockByrefVariable should be reformulated in terms of complex
|
|
|
|
// addresses instead.
|
2015-04-14 09:59:58 +08:00
|
|
|
if (Ty->isBlockByrefStruct()) {
|
2011-04-13 06:53:02 +08:00
|
|
|
/* Byref variables, in Blocks, are declared by the programmer as
|
|
|
|
"SomeType VarName;", but the compiler creates a
|
|
|
|
__Block_byref_x_VarName struct, and gives the variable VarName
|
|
|
|
either the struct, or a pointer to the struct, as its type. This
|
|
|
|
is necessary for various behind-the-scenes things the compiler
|
|
|
|
needs to do with by-reference variables in blocks.
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2011-04-13 06:53:02 +08:00
|
|
|
However, as far as the original *programmer* is concerned, the
|
|
|
|
variable should still have type 'SomeType', as originally declared.
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2011-04-13 06:53:02 +08:00
|
|
|
The following function dives into the __Block_byref_x_VarName
|
|
|
|
struct to find the original type of the variable. This will be
|
|
|
|
passed back to the code generating the type for the Debug
|
|
|
|
Information Entry for the variable 'VarName'. 'VarName' will then
|
|
|
|
have the original type 'SomeType' in its debug information.
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2011-04-13 06:53:02 +08:00
|
|
|
The original type 'SomeType' will be the type of the field named
|
|
|
|
'VarName' inside the __Block_byref_x_VarName struct.
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2011-04-13 06:53:02 +08:00
|
|
|
NOTE: In order for this to not completely fail on the debugger
|
|
|
|
side, the Debug Information Entry for the variable VarName needs to
|
|
|
|
have a DW_AT_location that tells the debugger how to unwind through
|
|
|
|
the pointers and __Block_byref_x_VarName struct to find the actual
|
|
|
|
value of the variable. The function addBlockByrefType does this. */
|
2015-04-30 00:38:44 +08:00
|
|
|
DIType *subType = Ty;
|
2015-04-16 09:01:28 +08:00
|
|
|
uint16_t tag = Ty->getTag();
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2013-09-05 03:53:21 +08:00
|
|
|
if (tag == dwarf::DW_TAG_pointer_type)
|
2015-04-30 00:38:44 +08:00
|
|
|
subType = resolve(cast<DIDerivedType>(Ty)->getBaseType());
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2015-07-25 02:17:17 +08:00
|
|
|
auto Elements = cast<DICompositeType>(subType)->getElements();
|
2015-04-07 12:14:33 +08:00
|
|
|
for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
|
2015-07-25 02:58:32 +08:00
|
|
|
auto *DT = cast<DIDerivedType>(Elements[i]);
|
2015-04-16 09:01:28 +08:00
|
|
|
if (getName() == DT->getName())
|
2015-04-21 02:20:03 +08:00
|
|
|
return resolve(DT->getBaseType());
|
2010-08-10 05:01:39 +08:00
|
|
|
}
|
|
|
|
}
|
2011-04-13 06:53:02 +08:00
|
|
|
return Ty;
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2017-02-18 03:42:32 +08:00
|
|
|
ArrayRef<DbgVariable::FrameIndexExpr> DbgVariable::getFrameIndexExprs() const {
|
2017-03-23 00:50:16 +08:00
|
|
|
if (FrameIndexExprs.size() == 1)
|
|
|
|
return FrameIndexExprs;
|
|
|
|
|
2017-08-18 05:26:39 +08:00
|
|
|
assert(llvm::all_of(FrameIndexExprs,
|
|
|
|
[](const FrameIndexExpr &A) {
|
|
|
|
return A.Expr->isFragment();
|
|
|
|
}) &&
|
2017-03-23 00:50:16 +08:00
|
|
|
"multiple FI expressions without DW_OP_LLVM_fragment");
|
llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)
Summary: The convenience wrapper in STLExtras is available since rL342102.
Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb
Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits
Differential Revision: https://reviews.llvm.org/D52573
llvm-svn: 343163
2018-09-27 10:13:45 +08:00
|
|
|
llvm::sort(FrameIndexExprs,
|
2018-04-07 02:08:42 +08:00
|
|
|
[](const FrameIndexExpr &A, const FrameIndexExpr &B) -> bool {
|
|
|
|
return A.Expr->getFragmentInfo()->OffsetInBits <
|
|
|
|
B.Expr->getFragmentInfo()->OffsetInBits;
|
|
|
|
});
|
2017-10-10 15:46:17 +08:00
|
|
|
|
2017-02-18 03:42:32 +08:00
|
|
|
return FrameIndexExprs;
|
|
|
|
}
|
|
|
|
|
2017-10-10 15:46:17 +08:00
|
|
|
void DbgVariable::addMMIEntry(const DbgVariable &V) {
|
|
|
|
assert(DebugLocListIndex == ~0U && !MInsn && "not an MMI entry");
|
|
|
|
assert(V.DebugLocListIndex == ~0U && !V.MInsn && "not an MMI entry");
|
2018-08-17 23:22:04 +08:00
|
|
|
assert(V.getVariable() == getVariable() && "conflicting variable");
|
|
|
|
assert(V.getInlinedAt() == getInlinedAt() && "conflicting inlined-at location");
|
2017-10-10 15:46:17 +08:00
|
|
|
|
|
|
|
assert(!FrameIndexExprs.empty() && "Expected an MMI entry");
|
|
|
|
assert(!V.FrameIndexExprs.empty() && "Expected an MMI entry");
|
|
|
|
|
2017-10-12 21:25:05 +08:00
|
|
|
// FIXME: This logic should not be necessary anymore, as we now have proper
|
|
|
|
// deduplication. However, without it, we currently run into the assertion
|
|
|
|
// below, which means that we are likely dealing with broken input, i.e. two
|
|
|
|
// non-fragment entries for the same variable at different frame indices.
|
|
|
|
if (FrameIndexExprs.size()) {
|
|
|
|
auto *Expr = FrameIndexExprs.back().Expr;
|
|
|
|
if (!Expr || !Expr->isFragment())
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-10 15:46:17 +08:00
|
|
|
for (const auto &FIE : V.FrameIndexExprs)
|
|
|
|
// Ignore duplicate entries.
|
|
|
|
if (llvm::none_of(FrameIndexExprs, [&](const FrameIndexExpr &Other) {
|
|
|
|
return FIE.FI == Other.FI && FIE.Expr == Other.Expr;
|
|
|
|
}))
|
|
|
|
FrameIndexExprs.push_back(FIE);
|
|
|
|
|
|
|
|
assert((FrameIndexExprs.size() == 1 ||
|
|
|
|
llvm::all_of(FrameIndexExprs,
|
|
|
|
[](FrameIndexExpr &FIE) {
|
|
|
|
return FIE.Expr && FIE.Expr->isFragment();
|
|
|
|
})) &&
|
|
|
|
"conflicting locations for variable");
|
|
|
|
}
|
|
|
|
|
[DebugInfo] Generate .debug_names section when it makes sense
Summary:
This patch makes us generate the debug_names section in response to some
user-facing commands (previously it was only generated if explicitly
selected via the -accel-tables option).
My goal was to make this work for DWARF>=5 (as it's an official part of
that standard), and also, as an extension, for DWARF<5 if one is
explicitly tuning for lldb as a debugger (because it brings a large
performance improvement there).
This is slightly complicated by the fact that the debug_names tables are
incompatible with the DWARF v4 type units (they assume that the type
units are in the debug_info section), and unfortunately, right now we
generate DWARF v4-style type units even for -gdwarf-5. For this reason,
I disable all accelerator tables if the user requested type unit
generation. I do this even for apple tables, as they have the same
problem (in fact generating type units for apple targets makes us crash
even before we get around to emitting the accelerator tables).
Reviewers: JDevlieghere, aprantl, dblaikie, echristo, probinson
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D49420
llvm-svn: 337544
2018-07-20 20:59:05 +08:00
|
|
|
static AccelTableKind computeAccelTableKind(unsigned DwarfVersion,
|
|
|
|
bool GenerateTypeUnits,
|
|
|
|
DebuggerKind Tuning,
|
|
|
|
const Triple &TT) {
|
|
|
|
// Honor an explicit request.
|
|
|
|
if (AccelTables != AccelTableKind::Default)
|
|
|
|
return AccelTables;
|
|
|
|
|
|
|
|
// Accelerator tables with type units are currently not supported.
|
|
|
|
if (GenerateTypeUnits)
|
|
|
|
return AccelTableKind::None;
|
|
|
|
|
|
|
|
// Accelerator tables get emitted if targetting DWARF v5 or LLDB. DWARF v5
|
|
|
|
// always implies debug_names. For lower standard versions we use apple
|
|
|
|
// accelerator tables on apple platforms and debug_names elsewhere.
|
|
|
|
if (DwarfVersion >= 5)
|
|
|
|
return AccelTableKind::Dwarf;
|
|
|
|
if (Tuning == DebuggerKind::LLDB)
|
|
|
|
return TT.isOSBinFormatMachO() ? AccelTableKind::Apple
|
|
|
|
: AccelTableKind::Dwarf;
|
|
|
|
return AccelTableKind::None;
|
|
|
|
}
|
|
|
|
|
2010-04-05 13:11:15 +08:00
|
|
|
DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
|
2016-02-11 04:55:49 +08:00
|
|
|
: DebugHandlerBase(A), DebugLocs(A->OutStreamer->isVerboseAsm()),
|
|
|
|
InfoHolder(A, "info_string", DIEValueAllocator),
|
2015-03-04 10:30:17 +08:00
|
|
|
SkeletonHolder(A, "skel_string", DIEValueAllocator),
|
[CodeGen] Refactor AppleAccelTable
Summary:
This commit separates the abstract accelerator table data structure
from the code for writing out an on-disk representation of a specific
accelerator table format. The idea is that former (now called
AccelTable<T>) can be reused for the DWARF v5 accelerator tables
as-is, without any further customizations.
Some bits of the emission code (now living in the EmissionContext class)
can be reused for DWARF v5 as well, but the subtle differences in the
layout of various subtables mean the sharing is not always possible.
(Also, the individual emit*** functions are fairly simple so there's a
tradeoff between making a bigger general-purpose function, and two
smaller targeted functions.)
Another advantage of this setup is that more of the serialization logic
can be hidden in the .cpp file -- I have moved declarations of the
header and all the emission functions there.
Reviewers: JDevlieghere, aprantl, probinson, dblaikie
Subscribers: echristo, clayborg, vleschuk, llvm-commits
Differential Revision: https://reviews.llvm.org/D43285
llvm-svn: 325516
2018-02-20 00:12:20 +08:00
|
|
|
IsDarwin(A->TM.getTargetTriple().isOSDarwin()) {
|
2016-10-01 09:50:29 +08:00
|
|
|
const Triple &TT = Asm->TM.getTargetTriple();
|
2015-07-16 06:04:54 +08:00
|
|
|
|
2019-01-26 00:29:35 +08:00
|
|
|
// Make sure we know our "debugger tuning". The target option takes
|
2015-07-16 06:04:54 +08:00
|
|
|
// precedence; fall back to triple-based defaults.
|
2015-12-17 03:58:30 +08:00
|
|
|
if (Asm->TM.Options.DebuggerTuning != DebuggerKind::Default)
|
|
|
|
DebuggerTuning = Asm->TM.Options.DebuggerTuning;
|
Turn off lldb debug tuning by default for FreeBSD
Summary:
In rL242338, debugger tuning was introduced, and the tuning for FreeBSD
was set to lldb by default. However, for the foreseeable future we
still need to default to gdb tuning, since lldb is not ready for all of
FreeBSD's architectures, and some system tools (like objcopy, etc) have
not yet been adapted to cope with the lldb tuned format, which has
.apple sections.
Therefore, let FreeBSD use gdb by default for now.
Reviewers: emaste, probinson
Subscribers: llvm-commits, emaste
Differential Revision: http://reviews.llvm.org/D15966
llvm-svn: 257103
2016-01-08 06:09:12 +08:00
|
|
|
else if (IsDarwin)
|
2015-07-16 06:04:54 +08:00
|
|
|
DebuggerTuning = DebuggerKind::LLDB;
|
|
|
|
else if (TT.isPS4CPU())
|
|
|
|
DebuggerTuning = DebuggerKind::SCE;
|
|
|
|
else
|
|
|
|
DebuggerTuning = DebuggerKind::GDB;
|
2012-04-03 01:58:52 +08:00
|
|
|
|
2018-05-18 11:13:08 +08:00
|
|
|
if (DwarfInlinedStrings == Default)
|
|
|
|
UseInlineStrings = TT.isNVPTX();
|
|
|
|
else
|
|
|
|
UseInlineStrings = DwarfInlinedStrings == Enable;
|
|
|
|
|
2018-06-29 22:23:28 +08:00
|
|
|
UseLocSection = !TT.isNVPTX();
|
|
|
|
|
2016-05-25 05:19:28 +08:00
|
|
|
HasAppleExtensionAttributes = tuneForLLDB();
|
|
|
|
|
2017-04-22 07:35:26 +08:00
|
|
|
// Handle split DWARF.
|
|
|
|
HasSplitDwarf = !Asm->TM.Options.MCOptions.SplitDwarfFile.empty();
|
2013-08-20 05:41:38 +08:00
|
|
|
|
2016-04-19 06:41:41 +08:00
|
|
|
// SCE defaults to linkage names only for abstract subprograms.
|
|
|
|
if (DwarfLinkageNames == DefaultLinkageNames)
|
|
|
|
UseAllLinkageNames = !tuneForSCE();
|
2015-08-12 05:36:45 +08:00
|
|
|
else
|
2016-04-19 06:41:41 +08:00
|
|
|
UseAllLinkageNames = DwarfLinkageNames == AllLinkageNames;
|
2015-08-12 05:36:45 +08:00
|
|
|
|
2014-06-19 14:22:08 +08:00
|
|
|
unsigned DwarfVersionNumber = Asm->TM.Options.MCOptions.DwarfVersion;
|
2016-11-24 07:30:37 +08:00
|
|
|
unsigned DwarfVersion = DwarfVersionNumber ? DwarfVersionNumber
|
2014-04-29 04:42:22 +08:00
|
|
|
: MMI->getModule()->getDwarfVersion();
|
2018-05-18 11:13:08 +08:00
|
|
|
// Use dwarf 4 by default if nothing is requested. For NVPTX, use dwarf 2.
|
|
|
|
DwarfVersion =
|
|
|
|
TT.isNVPTX() ? 2 : (DwarfVersion ? DwarfVersion : dwarf::DWARF_VERSION);
|
2013-07-03 07:40:10 +08:00
|
|
|
|
2018-05-18 11:13:08 +08:00
|
|
|
UseRangesSection = !NoDwarfRangesSection && !TT.isNVPTX();
|
2018-03-21 00:04:40 +08:00
|
|
|
|
2018-05-18 11:13:08 +08:00
|
|
|
// Use sections as references. Force for NVPTX.
|
|
|
|
if (DwarfSectionsAsReferences == Default)
|
|
|
|
UseSectionsAsReferences = TT.isNVPTX();
|
|
|
|
else
|
|
|
|
UseSectionsAsReferences = DwarfSectionsAsReferences == Enable;
|
2018-03-23 21:35:54 +08:00
|
|
|
|
2018-08-01 20:53:06 +08:00
|
|
|
// Don't generate type units for unsupported object file formats.
|
|
|
|
GenerateTypeUnits =
|
|
|
|
A->TM.getTargetTriple().isOSBinFormatELF() && GenerateDwarfTypeUnits;
|
[DebugInfo] Generate .debug_names section when it makes sense
Summary:
This patch makes us generate the debug_names section in response to some
user-facing commands (previously it was only generated if explicitly
selected via the -accel-tables option).
My goal was to make this work for DWARF>=5 (as it's an official part of
that standard), and also, as an extension, for DWARF<5 if one is
explicitly tuning for lldb as a debugger (because it brings a large
performance improvement there).
This is slightly complicated by the fact that the debug_names tables are
incompatible with the DWARF v4 type units (they assume that the type
units are in the debug_info section), and unfortunately, right now we
generate DWARF v4-style type units even for -gdwarf-5. For this reason,
I disable all accelerator tables if the user requested type unit
generation. I do this even for apple tables, as they have the same
problem (in fact generating type units for apple targets makes us crash
even before we get around to emitting the accelerator tables).
Reviewers: JDevlieghere, aprantl, dblaikie, echristo, probinson
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D49420
llvm-svn: 337544
2018-07-20 20:59:05 +08:00
|
|
|
|
|
|
|
TheAccelTableKind = computeAccelTableKind(
|
|
|
|
DwarfVersion, GenerateTypeUnits, DebuggerTuning, A->TM.getTargetTriple());
|
|
|
|
|
2015-07-16 06:04:54 +08:00
|
|
|
// Work around a GDB bug. GDB doesn't support the standard opcode;
|
|
|
|
// SCE doesn't support GNU's; LLDB prefers the standard opcode, which
|
|
|
|
// is defined as of DWARF 3.
|
|
|
|
// See GDB bug 11616 - DW_OP_form_tls_address is unimplemented
|
|
|
|
// https://sourceware.org/bugzilla/show_bug.cgi?id=11616
|
|
|
|
UseGNUTLSOpcode = tuneForGDB() || DwarfVersion < 3;
|
2015-03-05 04:55:11 +08:00
|
|
|
|
2016-05-18 05:07:16 +08:00
|
|
|
// GDB does not fully support the DWARF 4 representation for bitfields.
|
|
|
|
UseDWARF2Bitfields = (DwarfVersion < 4) || tuneForGDB();
|
|
|
|
|
2018-01-27 02:52:58 +08:00
|
|
|
// The DWARF v5 string offsets table has - possibly shared - contributions
|
|
|
|
// from each compile and type unit each preceded by a header. The string
|
|
|
|
// offsets table used by the pre-DWARF v5 split-DWARF implementation uses
|
|
|
|
// a monolithic string offsets table without any header.
|
|
|
|
UseSegmentedStringOffsetsTable = DwarfVersion >= 5;
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->getContext().setDwarfVersion(DwarfVersion);
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2014-05-01 04:34:31 +08:00
|
|
|
// Define out of line so we don't have to include DwarfUnit.h in DwarfDebug.h.
|
2017-08-18 05:26:39 +08:00
|
|
|
DwarfDebug::~DwarfDebug() = default;
|
2014-05-01 04:34:31 +08:00
|
|
|
|
2011-11-11 03:25:34 +08:00
|
|
|
static bool isObjCClass(StringRef Name) {
|
|
|
|
return Name.startswith("+") || Name.startswith("-");
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool hasObjCCategory(StringRef Name) {
|
2013-11-19 17:04:36 +08:00
|
|
|
if (!isObjCClass(Name))
|
|
|
|
return false;
|
2011-11-11 03:25:34 +08:00
|
|
|
|
2013-08-24 20:15:54 +08:00
|
|
|
return Name.find(") ") != StringRef::npos;
|
2011-11-11 03:25:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void getObjCClassCategory(StringRef In, StringRef &Class,
|
|
|
|
StringRef &Category) {
|
|
|
|
if (!hasObjCCategory(In)) {
|
|
|
|
Class = In.slice(In.find('[') + 1, In.find(' '));
|
|
|
|
Category = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Class = In.slice(In.find('[') + 1, In.find('('));
|
|
|
|
Category = In.slice(In.find('[') + 1, In.find(' '));
|
|
|
|
}
|
|
|
|
|
|
|
|
static StringRef getObjCMethodName(StringRef In) {
|
|
|
|
return In.slice(In.find(' ') + 1, In.find(']'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the various names to the Dwarf accelerator table names.
|
2018-08-17 05:29:55 +08:00
|
|
|
void DwarfDebug::addSubprogramNames(const DICompileUnit &CU,
|
|
|
|
const DISubprogram *SP, DIE &Die) {
|
|
|
|
if (getAccelTableKind() != AccelTableKind::Apple &&
|
|
|
|
CU.getNameTableKind() == DICompileUnit::DebugNameTableKind::None)
|
|
|
|
return;
|
|
|
|
|
2015-04-14 11:40:37 +08:00
|
|
|
if (!SP->isDefinition())
|
2013-11-19 17:04:36 +08:00
|
|
|
return;
|
[CodeGen/AccelTable]: Don't emit accelerator entries for functions with no names
Summary:
We were emitting accelerator entries for functions with no name, which
is contrary to the DWARF v5 spec: "All other (i.e., *not*
DW_TAG_namespace) debugging information entries without a DW_AT_name
attribute are excluded." Besides that, a name table entry with an empty
string as a key is fairly useless.
We can sometimes end up with functions which have a DW_AT_linkage_name but no
DW_AT_name. One such example is the global-constructor-initialization functions,
which C++ compilers synthesize for each compilation unit with global
constructors.
A very strict reading of the DWARF v5 spec would suggest that we should not even
emit the accelerator entry for the linkage name in this case, but I don't think
we should go that far.
I found this when running the dwarf verifier over llvm codebase compiled
with DWARF v5 accelerator tables.
Reviewers: JDevlieghere, aprantl, dblaikie
Subscribers: vleschuk, clayborg, echristo, probinson, llvm-commits
Differential Revision: https://reviews.llvm.org/D45367
llvm-svn: 329552
2018-04-09 16:41:57 +08:00
|
|
|
|
|
|
|
if (SP->getName() != "")
|
2018-08-17 05:29:55 +08:00
|
|
|
addAccelName(CU, SP->getName(), Die);
|
2011-11-11 03:25:34 +08:00
|
|
|
|
2018-05-14 22:13:20 +08:00
|
|
|
// If the linkage name is different than the name, go ahead and output that as
|
|
|
|
// well into the name table. Only do that if we are going to actually emit
|
|
|
|
// that name.
|
|
|
|
if (SP->getLinkageName() != "" && SP->getName() != SP->getLinkageName() &&
|
|
|
|
(useAllLinkageNames() || InfoHolder.getAbstractSPDies().lookup(SP)))
|
2018-08-17 05:29:55 +08:00
|
|
|
addAccelName(CU, 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);
|
2018-08-17 05:29:55 +08:00
|
|
|
addAccelObjC(CU, Class, Die);
|
2011-11-11 03:25:34 +08:00
|
|
|
if (Category != "")
|
2018-08-17 05:29:55 +08:00
|
|
|
addAccelObjC(CU, Category, Die);
|
2011-11-11 03:25:34 +08:00
|
|
|
// Also add the base method name to the name table.
|
2018-08-17 05:29:55 +08:00
|
|
|
addAccelName(CU, getObjCMethodName(SP->getName()), Die);
|
2011-11-11 03:25:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-12 03:40:28 +08:00
|
|
|
/// Check whether we should create a DIE for the given Scope, return true
|
|
|
|
/// if we don't create a DIE (the corresponding DIE is null).
|
2013-09-11 02:40:41 +08:00
|
|
|
bool DwarfDebug::isLexicalScopeDIENull(LexicalScope *Scope) {
|
|
|
|
if (Scope->isAbstractScope())
|
|
|
|
return false;
|
|
|
|
|
2013-09-12 03:40:28 +08:00
|
|
|
// We don't create a DIE if there is no Range.
|
2013-09-11 02:40:41 +08:00
|
|
|
const SmallVectorImpl<InsnRange> &Ranges = Scope->getRanges();
|
|
|
|
if (Ranges.empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (Ranges.size() > 1)
|
|
|
|
return false;
|
|
|
|
|
2013-09-12 03:40:28 +08:00
|
|
|
// We don't create a DIE if we have a single Range and the end label
|
|
|
|
// is null.
|
2014-08-31 10:14:26 +08:00
|
|
|
return !getLabelAfterInsn(Ranges.front().second);
|
2013-09-11 02:40:41 +08:00
|
|
|
}
|
|
|
|
|
2016-08-06 19:13:10 +08:00
|
|
|
template <typename Func> static void forBothCUs(DwarfCompileUnit &CU, Func F) {
|
Provide gmlt-like inline scope information in the skeleton CU to facilitate symbolication without needing the .dwo files
Clang -gsplit-dwarf self-host -O0, binary increases by 0.0005%, -O2,
binary increases by 25%.
A large binary inside Google, split-dwarf, -O0, and other internal flags
(GDB index, etc) increases by 1.8%, optimized build is 35%.
The size impact may be somewhat greater in .o files (I haven't measured
that much - since the linked executable -O0 numbers seemed low enough)
due to relocations. These relocations could be removed if we taught the
llvm-symbolizer to handle indexed addressing in the .o file (GDB can't
cope with this just yet, but GDB won't be reading this info anyway).
Also debug_ranges could be shared between .o and .dwo, though ideally
debug_ranges would get a schema that could used index(+offset)
addressing, and move to the .dwo file, then we'd be back to sharing
addresses in the address pool again.
But for now, these sizes seem small enough to go ahead with this.
Verified that no other DW_TAGs are produced into the .o file other than
subprograms and inlined_subroutines.
llvm-svn: 221306
2014-11-05 06:12:25 +08:00
|
|
|
F(CU);
|
|
|
|
if (auto *SkelCU = CU.getSkeleton())
|
2016-08-25 02:29:49 +08:00
|
|
|
if (CU.getCUNode()->getSplitDebugInlining())
|
|
|
|
F(*SkelCU);
|
Provide gmlt-like inline scope information in the skeleton CU to facilitate symbolication without needing the .dwo files
Clang -gsplit-dwarf self-host -O0, binary increases by 0.0005%, -O2,
binary increases by 25%.
A large binary inside Google, split-dwarf, -O0, and other internal flags
(GDB index, etc) increases by 1.8%, optimized build is 35%.
The size impact may be somewhat greater in .o files (I haven't measured
that much - since the linked executable -O0 numbers seemed low enough)
due to relocations. These relocations could be removed if we taught the
llvm-symbolizer to handle indexed addressing in the .o file (GDB can't
cope with this just yet, but GDB won't be reading this info anyway).
Also debug_ranges could be shared between .o and .dwo, though ideally
debug_ranges would get a schema that could used index(+offset)
addressing, and move to the .dwo file, then we'd be back to sharing
addresses in the address pool again.
But for now, these sizes seem small enough to go ahead with this.
Verified that no other DW_TAGs are produced into the .o file other than
subprograms and inlined_subroutines.
llvm-svn: 221306
2014-11-05 06:12:25 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 09:13:45 +08:00
|
|
|
bool DwarfDebug::shareAcrossDWOCUs() const {
|
|
|
|
return SplitDwarfCrossCuReferences;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DwarfDebug::constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU,
|
|
|
|
LexicalScope *Scope) {
|
2014-04-29 04:27:02 +08:00
|
|
|
assert(Scope && Scope->getScopeNode());
|
2014-04-29 23:58:35 +08:00
|
|
|
assert(Scope->isAbstractScope());
|
|
|
|
assert(!Scope->getInlinedAt());
|
2014-04-29 04:27:02 +08:00
|
|
|
|
2016-12-15 03:38:39 +08:00
|
|
|
auto *SP = cast<DISubprogram>(Scope->getScopeNode());
|
2014-04-29 23:58:35 +08:00
|
|
|
|
2014-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.
|
2017-05-29 14:25:30 +08:00
|
|
|
if (useSplitDwarf() && !shareAcrossDWOCUs() && !SP->getUnit()->getSplitDebugInlining())
|
|
|
|
// Avoid building the original CU if it won't be used
|
|
|
|
SrcCU.constructAbstractSubprogramScopeDIE(Scope);
|
|
|
|
else {
|
|
|
|
auto &CU = getOrCreateDwarfCompileUnit(SP->getUnit());
|
|
|
|
if (auto *SkelCU = CU.getSkeleton()) {
|
|
|
|
(shareAcrossDWOCUs() ? CU : SrcCU)
|
|
|
|
.constructAbstractSubprogramScopeDIE(Scope);
|
|
|
|
if (CU.getCUNode()->getSplitDebugInlining())
|
|
|
|
SkelCU->constructAbstractSubprogramScopeDIE(Scope);
|
|
|
|
} else
|
|
|
|
CU.constructAbstractSubprogramScopeDIE(Scope);
|
2017-05-12 09:13:45 +08:00
|
|
|
}
|
2014-04-29 23:58:35 +08:00
|
|
|
}
|
2014-04-29 04:27:02 +08:00
|
|
|
|
2018-10-06 04:37:17 +08:00
|
|
|
void DwarfDebug::constructCallSiteEntryDIEs(const DISubprogram &SP,
|
|
|
|
DwarfCompileUnit &CU, DIE &ScopeDIE,
|
|
|
|
const MachineFunction &MF) {
|
|
|
|
// Add a call site-related attribute (DWARF5, Sec. 3.3.1.3). Do this only if
|
|
|
|
// the subprogram is required to have one.
|
|
|
|
if (!SP.areAllCallsDescribed() || !SP.isDefinition())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Use DW_AT_call_all_calls to express that call site entries are present
|
|
|
|
// for both tail and non-tail calls. Don't use DW_AT_call_all_source_calls
|
|
|
|
// because one of its requirements is not met: call site entries for
|
|
|
|
// optimized-out calls are elided.
|
|
|
|
CU.addFlag(ScopeDIE, dwarf::DW_AT_call_all_calls);
|
|
|
|
|
|
|
|
const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
|
|
|
|
assert(TII && "TargetInstrInfo not found: cannot label tail calls");
|
|
|
|
|
|
|
|
// Emit call site entries for each call or tail call in the function.
|
|
|
|
for (const MachineBasicBlock &MBB : MF) {
|
|
|
|
for (const MachineInstr &MI : MBB.instrs()) {
|
|
|
|
// Skip instructions which aren't calls. Both calls and tail-calling jump
|
|
|
|
// instructions (e.g TAILJMPd64) are classified correctly here.
|
|
|
|
if (!MI.isCall())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// TODO: Add support for targets with delay slots (see: beginInstruction).
|
|
|
|
if (MI.hasDelaySlot())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If this is a direct call, find the callee's subprogram.
|
|
|
|
const MachineOperand &CalleeOp = MI.getOperand(0);
|
|
|
|
if (!CalleeOp.isGlobal())
|
|
|
|
continue;
|
|
|
|
const Function *CalleeDecl = dyn_cast<Function>(CalleeOp.getGlobal());
|
|
|
|
if (!CalleeDecl || !CalleeDecl->getSubprogram())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// TODO: Omit call site entries for runtime calls (objc_msgSend, etc).
|
|
|
|
// TODO: Add support for indirect calls.
|
|
|
|
|
|
|
|
bool IsTail = TII->isTailCall(MI);
|
|
|
|
|
|
|
|
// For tail calls, no return PC information is needed. For regular calls,
|
|
|
|
// the return PC is needed to disambiguate paths in the call graph which
|
|
|
|
// could lead to some target function.
|
2018-10-23 05:44:21 +08:00
|
|
|
const MCExpr *PCOffset =
|
|
|
|
IsTail ? nullptr : getFunctionLocalOffsetAfterInsn(&MI);
|
2018-10-06 04:37:17 +08:00
|
|
|
|
2018-10-23 05:44:21 +08:00
|
|
|
assert((IsTail || PCOffset) && "Call without return PC information");
|
2018-10-06 04:37:17 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "CallSiteEntry: " << MF.getName() << " -> "
|
|
|
|
<< CalleeDecl->getName() << (IsTail ? " [tail]" : "")
|
|
|
|
<< "\n");
|
|
|
|
CU.constructCallSiteEntryDIE(ScopeDIE, *CalleeDecl->getSubprogram(),
|
2018-10-23 05:44:21 +08:00
|
|
|
IsTail, PCOffset);
|
2018-10-06 04:37:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-26 02:50:28 +08:00
|
|
|
void DwarfDebug::addGnuPubAttributes(DwarfCompileUnit &U, DIE &D) const {
|
2017-09-13 05:50:41 +08:00
|
|
|
if (!U.hasDwarfPubSections())
|
2013-12-05 05:31:26 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-12-15 06:44:46 +08:00
|
|
|
void DwarfDebug::finishUnitAttributes(const DICompileUnit *DIUnit,
|
|
|
|
DwarfCompileUnit &NewCU) {
|
2014-04-29 05:04:29 +08:00
|
|
|
DIE &Die = NewCU.getUnitDie();
|
2018-12-15 06:44:46 +08:00
|
|
|
StringRef FN = DIUnit->getFilename();
|
2014-04-23 06:39:41 +08:00
|
|
|
|
2017-03-30 07:34:27 +08:00
|
|
|
StringRef Producer = DIUnit->getProducer();
|
|
|
|
StringRef Flags = DIUnit->getFlags();
|
2018-08-09 00:33:22 +08:00
|
|
|
if (!Flags.empty() && !useAppleExtensionAttributes()) {
|
2017-03-30 07:34:27 +08:00
|
|
|
std::string ProducerWithFlags = Producer.str() + " " + Flags.str();
|
|
|
|
NewCU.addString(Die, dwarf::DW_AT_producer, ProducerWithFlags);
|
|
|
|
} else
|
|
|
|
NewCU.addString(Die, dwarf::DW_AT_producer, Producer);
|
|
|
|
|
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
|
|
|
|
2018-01-27 02:52:58 +08:00
|
|
|
// Add DW_str_offsets_base to the unit DIE, except for split units.
|
|
|
|
if (useSegmentedStringOffsetsTable() && !useSplitDwarf())
|
|
|
|
NewCU.addStringOffsetsStart();
|
|
|
|
|
2013-04-10 03:23:15 +08:00
|
|
|
if (!useSplitDwarf()) {
|
2015-03-11 00:58:10 +08:00
|
|
|
NewCU.initStmtList();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2013-09-28 06:50:48 +08:00
|
|
|
// If we're using split dwarf the compilation dir is going to be in the
|
|
|
|
// skeleton CU and so we don't need to duplicate it here.
|
|
|
|
if (!CompilationDir.empty())
|
2014-04-29 05:04:29 +08:00
|
|
|
NewCU.addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
|
2013-09-13 08:35:05 +08:00
|
|
|
|
2014-04-29 05:04:29 +08:00
|
|
|
addGnuPubAttributes(NewCU, Die);
|
2013-09-28 06:50:48 +08:00
|
|
|
}
|
2013-09-13 08:35:05 +08:00
|
|
|
|
2016-05-25 05:19:28 +08:00
|
|
|
if (useAppleExtensionAttributes()) {
|
|
|
|
if (DIUnit->isOptimized())
|
|
|
|
NewCU.addFlag(Die, dwarf::DW_AT_APPLE_optimized);
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2016-05-25 05:19:28 +08:00
|
|
|
StringRef Flags = DIUnit->getFlags();
|
|
|
|
if (!Flags.empty())
|
|
|
|
NewCU.addString(Die, dwarf::DW_AT_APPLE_flags, Flags);
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2016-05-25 05:19:28 +08:00
|
|
|
if (unsigned RVer = DIUnit->getRuntimeVersion())
|
|
|
|
NewCU.addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
|
|
|
|
dwarf::DW_FORM_data1, RVer);
|
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2015-09-15 06:10:22 +08:00
|
|
|
if (DIUnit->getDWOId()) {
|
2015-09-23 07:21:00 +08:00
|
|
|
// This CU is either a clang module DWO or a skeleton CU.
|
2015-09-15 06:10:22 +08:00
|
|
|
NewCU.addUInt(Die, dwarf::DW_AT_GNU_dwo_id, dwarf::DW_FORM_data8,
|
|
|
|
DIUnit->getDWOId());
|
2015-09-23 07:21:00 +08:00
|
|
|
if (!DIUnit->getSplitDebugFilename().empty())
|
|
|
|
// This is a prefabricated skeleton CU.
|
|
|
|
NewCU.addString(Die, dwarf::DW_AT_GNU_dwo_name,
|
|
|
|
DIUnit->getSplitDebugFilename());
|
2015-09-15 06:10:22 +08:00
|
|
|
}
|
2018-12-15 06:44:46 +08:00
|
|
|
}
|
|
|
|
// Create new DwarfCompileUnit for the given metadata node with tag
|
|
|
|
// DW_TAG_compile_unit.
|
|
|
|
DwarfCompileUnit &
|
|
|
|
DwarfDebug::getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit) {
|
|
|
|
if (auto *CU = CUMap.lookup(DIUnit))
|
|
|
|
return *CU;
|
|
|
|
|
|
|
|
CompilationDir = DIUnit->getDirectory();
|
|
|
|
|
|
|
|
auto OwnedUnit = llvm::make_unique<DwarfCompileUnit>(
|
|
|
|
InfoHolder.getUnits().size(), DIUnit, Asm, this, &InfoHolder);
|
|
|
|
DwarfCompileUnit &NewCU = *OwnedUnit;
|
|
|
|
InfoHolder.addUnit(std::move(OwnedUnit));
|
|
|
|
|
2018-12-19 03:40:22 +08:00
|
|
|
for (auto *IE : DIUnit->getImportedEntities())
|
|
|
|
NewCU.addImportedEntity(IE);
|
|
|
|
|
2018-12-21 04:46:55 +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.
|
|
|
|
if (!Asm->OutStreamer->hasRawTextSupport() || SingleCU)
|
|
|
|
Asm->OutStreamer->emitDwarfFile0Directive(
|
|
|
|
CompilationDir, DIUnit->getFilename(),
|
|
|
|
NewCU.getMD5AsBytes(DIUnit->getFile()), DIUnit->getSource(),
|
|
|
|
NewCU.getUniqueID());
|
|
|
|
|
2018-12-15 06:44:46 +08:00
|
|
|
if (useSplitDwarf()) {
|
|
|
|
NewCU.setSkeleton(constructSkeletonCU(NewCU));
|
|
|
|
NewCU.setSection(Asm->getObjFileLowering().getDwarfInfoDWOSection());
|
|
|
|
} else {
|
|
|
|
finishUnitAttributes(DIUnit, NewCU);
|
|
|
|
NewCU.setSection(Asm->getObjFileLowering().getDwarfInfoSection());
|
|
|
|
}
|
2015-09-15 06:10:22 +08:00
|
|
|
|
2016-08-12 05:15:00 +08:00
|
|
|
CUMap.insert({DIUnit, &NewCU});
|
2018-12-15 06:44:46 +08:00
|
|
|
CUDieMap.insert({&NewCU.getUnitDie(), &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) {
|
2017-07-27 08:06:53 +08:00
|
|
|
if (isa<DILocalScope>(N->getScope()))
|
|
|
|
return;
|
2015-04-22 02:44:06 +08:00
|
|
|
if (DIE *D = TheCU.getOrCreateContextDIE(N->getScope()))
|
|
|
|
D->addChild(TheCU.constructImportedEntityDIE(N));
|
2013-04-22 14:12:31 +08:00
|
|
|
}
|
|
|
|
|
2016-12-20 10:09:43 +08:00
|
|
|
/// Sort and unique GVEs by comparing their fragment offset.
|
|
|
|
static SmallVectorImpl<DwarfCompileUnit::GlobalExpr> &
|
|
|
|
sortGlobalExprs(SmallVectorImpl<DwarfCompileUnit::GlobalExpr> &GVEs) {
|
llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)
Summary: The convenience wrapper in STLExtras is available since rL342102.
Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb
Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits
Differential Revision: https://reviews.llvm.org/D52573
llvm-svn: 343163
2018-09-27 10:13:45 +08:00
|
|
|
llvm::sort(
|
|
|
|
GVEs, [](DwarfCompileUnit::GlobalExpr A, DwarfCompileUnit::GlobalExpr B) {
|
|
|
|
// Sort order: first null exprs, then exprs without fragment
|
|
|
|
// info, then sort by fragment offset in bits.
|
|
|
|
// FIXME: Come up with a more comprehensive comparator so
|
|
|
|
// the sorting isn't non-deterministic, and so the following
|
|
|
|
// std::unique call works correctly.
|
|
|
|
if (!A.Expr || !B.Expr)
|
|
|
|
return !!B.Expr;
|
|
|
|
auto FragmentA = A.Expr->getFragmentInfo();
|
|
|
|
auto FragmentB = B.Expr->getFragmentInfo();
|
|
|
|
if (!FragmentA || !FragmentB)
|
|
|
|
return !!FragmentB;
|
|
|
|
return FragmentA->OffsetInBits < FragmentB->OffsetInBits;
|
|
|
|
});
|
2016-12-20 10:09:43 +08:00
|
|
|
GVEs.erase(std::unique(GVEs.begin(), GVEs.end(),
|
|
|
|
[](DwarfCompileUnit::GlobalExpr A,
|
|
|
|
DwarfCompileUnit::GlobalExpr B) {
|
|
|
|
return A.Expr == B.Expr;
|
|
|
|
}),
|
|
|
|
GVEs.end());
|
|
|
|
return GVEs;
|
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Emit all Dwarf sections that should come prior to the content. Create
|
|
|
|
// global DIEs and emit initial debug info sections. This is invoked by
|
|
|
|
// the target AsmPrinter.
|
2012-11-20 06:42:15 +08:00
|
|
|
void DwarfDebug::beginModule() {
|
2016-11-19 03:43:18 +08:00
|
|
|
NamedRegionTimer T(DbgTimerName, DbgTimerDescription, DWARFGroupName,
|
|
|
|
DWARFGroupDescription, TimePassesIsEnabled);
|
2018-11-01 01:18:41 +08:00
|
|
|
if (DisableDebugInfoPrinting) {
|
|
|
|
MMI->setDebugInfoAvailability(false);
|
2010-04-28 03:46:33 +08:00
|
|
|
return;
|
2018-11-01 01:18:41 +08:00
|
|
|
}
|
2010-04-28 03:46:33 +08:00
|
|
|
|
2012-11-20 06:42:15 +08:00
|
|
|
const Module *M = MMI->getModule();
|
|
|
|
|
2016-06-01 10:58:40 +08:00
|
|
|
unsigned NumDebugCUs = std::distance(M->debug_compile_units_begin(),
|
|
|
|
M->debug_compile_units_end());
|
2016-04-09 06:43:03 +08:00
|
|
|
// Tell MMI whether we have debug info.
|
2018-11-01 01:18:41 +08:00
|
|
|
assert(MMI->hasDebugInfo() == (NumDebugCUs > 0) &&
|
|
|
|
"DebugInfoAvailabilty initialized unexpectedly");
|
2016-04-09 06:43:03 +08:00
|
|
|
SingleCU = NumDebugCUs == 1;
|
2016-12-20 10:09:43 +08:00
|
|
|
DenseMap<DIGlobalVariable *, SmallVector<DwarfCompileUnit::GlobalExpr, 1>>
|
|
|
|
GVMap;
|
2016-09-13 09:12:59 +08:00
|
|
|
for (const GlobalVariable &Global : M->globals()) {
|
2016-12-20 10:09:43 +08:00
|
|
|
SmallVector<DIGlobalVariableExpression *, 1> GVs;
|
2016-09-13 09:12:59 +08:00
|
|
|
Global.getDebugInfo(GVs);
|
2016-12-20 10:09:43 +08:00
|
|
|
for (auto *GVE : GVs)
|
|
|
|
GVMap[GVE->getVariable()].push_back({&Global, GVE->getExpression()});
|
2016-09-13 09:12:59 +08:00
|
|
|
}
|
|
|
|
|
2018-01-27 02:52:58 +08:00
|
|
|
// Create the symbol that designates the start of the unit's contribution
|
|
|
|
// to the string offsets table. In a split DWARF scenario, only the skeleton
|
|
|
|
// unit has the DW_AT_str_offsets_base attribute (and hence needs the symbol).
|
|
|
|
if (useSegmentedStringOffsetsTable())
|
|
|
|
(useSplitDwarf() ? SkeletonHolder : InfoHolder)
|
|
|
|
.setStringOffsetsStartSym(Asm->createTempSymbol("str_offsets_base"));
|
|
|
|
|
2018-10-26 19:25:12 +08:00
|
|
|
|
|
|
|
// Create the symbols that designates the start of the DWARF v5 range list
|
|
|
|
// and locations list tables. They are located past the table headers.
|
2018-10-20 15:36:39 +08:00
|
|
|
if (getDwarfVersion() >= 5) {
|
2018-10-26 19:25:12 +08:00
|
|
|
DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
|
|
|
|
Holder.setRnglistsTableBaseSym(
|
|
|
|
Asm->createTempSymbol("rnglists_table_base"));
|
|
|
|
Holder.setLoclistsTableBaseSym(
|
|
|
|
Asm->createTempSymbol("loclists_table_base"));
|
|
|
|
|
2018-10-20 15:36:39 +08:00
|
|
|
if (useSplitDwarf())
|
|
|
|
InfoHolder.setRnglistsTableBaseSym(
|
|
|
|
Asm->createTempSymbol("rnglists_dwo_table_base"));
|
|
|
|
}
|
2018-07-13 02:18:21 +08:00
|
|
|
|
2018-09-20 17:17:36 +08:00
|
|
|
// Create the symbol that points to the first entry following the debug
|
|
|
|
// address table (.debug_addr) header.
|
|
|
|
AddrPool.setLabel(Asm->createTempSymbol("addr_table_base"));
|
|
|
|
|
2016-04-09 06:43:03 +08:00
|
|
|
for (DICompileUnit *CUNode : M->debug_compile_units()) {
|
2017-07-28 11:06:25 +08:00
|
|
|
// FIXME: Move local imported entities into a list attached to the
|
|
|
|
// subprogram, then this search won't be needed and a
|
|
|
|
// getImportedEntities().empty() test should go below with the rest.
|
|
|
|
bool HasNonLocalImportedEntities = llvm::any_of(
|
|
|
|
CUNode->getImportedEntities(), [](const DIImportedEntity *IE) {
|
|
|
|
return !isa<DILocalScope>(IE->getScope());
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!HasNonLocalImportedEntities && CUNode->getEnumTypes().empty() &&
|
|
|
|
CUNode->getRetainedTypes().empty() &&
|
|
|
|
CUNode->getGlobalVariables().empty() && CUNode->getMacros().empty())
|
2017-05-27 02:52:56 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
DwarfCompileUnit &CU = getOrCreateDwarfCompileUnit(CUNode);
|
2016-12-20 10:09:43 +08:00
|
|
|
|
|
|
|
// Global Variables.
|
2017-08-19 09:15:06 +08:00
|
|
|
for (auto *GVE : CUNode->getGlobalVariables()) {
|
|
|
|
// Don't bother adding DIGlobalVariableExpressions listed in the CU if we
|
|
|
|
// already know about the variable and it isn't adding a constant
|
|
|
|
// expression.
|
|
|
|
auto &GVMapEntry = GVMap[GVE->getVariable()];
|
|
|
|
auto *Expr = GVE->getExpression();
|
|
|
|
if (!GVMapEntry.size() || (Expr && Expr->isConstant()))
|
|
|
|
GVMapEntry.push_back({nullptr, Expr});
|
|
|
|
}
|
2016-12-20 10:09:43 +08:00
|
|
|
DenseSet<DIGlobalVariable *> Processed;
|
|
|
|
for (auto *GVE : CUNode->getGlobalVariables()) {
|
|
|
|
DIGlobalVariable *GV = GVE->getVariable();
|
|
|
|
if (Processed.insert(GV).second)
|
|
|
|
CU.getOrCreateGlobalVariableDIE(GV, sortGlobalExprs(GVMap[GV]));
|
|
|
|
}
|
|
|
|
|
2015-04-21 02:52:06 +08:00
|
|
|
for (auto *Ty : CUNode->getEnumTypes()) {
|
2014-07-29 07:04:20 +08:00
|
|
|
// The enum types array by design contains pointers to
|
|
|
|
// MDNodes rather than DIRefs. Unique them here.
|
2016-04-24 05:08:00 +08:00
|
|
|
CU.getOrCreateTypeDIE(cast<DIType>(Ty));
|
2014-07-29 07:04:20 +08:00
|
|
|
}
|
2015-04-21 02:52:06 +08:00
|
|
|
for (auto *Ty : CUNode->getRetainedTypes()) {
|
2014-03-18 10:35:03 +08:00
|
|
|
// The retained types array by design contains pointers to
|
|
|
|
// MDNodes rather than DIRefs. Unique them here.
|
2016-04-30 09:44:07 +08:00
|
|
|
if (DIType *RT = dyn_cast<DIType>(Ty))
|
2016-04-15 23:57:41 +08:00
|
|
|
// There is no point in force-emitting a forward declaration.
|
|
|
|
CU.getOrCreateTypeDIE(RT);
|
2014-03-18 10:35:03 +08:00
|
|
|
}
|
2013-04-22 14:12:31 +08:00
|
|
|
// Emit imported_modules last so that the relevant context is already
|
|
|
|
// available.
|
2015-04-07 12:14:33 +08:00
|
|
|
for (auto *IE : CUNode->getImportedEntities())
|
2016-04-30 09:44:07 +08:00
|
|
|
constructAndAddImportedEntityDIE(CU, IE);
|
2013-03-12 07:39:23 +08:00
|
|
|
}
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2018-08-17 23:22:04 +08:00
|
|
|
void DwarfDebug::finishEntityDefinitions() {
|
|
|
|
for (const auto &Entity : ConcreteEntities) {
|
|
|
|
DIE *Die = Entity->getDIE();
|
|
|
|
assert(Die);
|
2014-06-14 06:18:23 +08:00
|
|
|
// FIXME: Consider the time-space tradeoff of just storing the unit pointer
|
2018-08-17 23:22:04 +08:00
|
|
|
// in the ConcreteEntities list, rather than looking it up again here.
|
2014-06-14 06:18:23 +08:00
|
|
|
// DIE::getUnit isn't simple - it walks parent pointers, etc.
|
2018-08-17 23:22:04 +08:00
|
|
|
DwarfCompileUnit *Unit = CUDieMap.lookup(Die->getUnitDie());
|
2014-06-14 06:18:23 +08:00
|
|
|
assert(Unit);
|
2018-08-17 23:22:04 +08:00
|
|
|
Unit->finishEntityDefinition(Entity.get());
|
2014-06-14 06:18:23 +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
|
|
|
void DwarfDebug::finishSubprogramDefinitions() {
|
2017-05-27 02:52:56 +08:00
|
|
|
for (const DISubprogram *SP : ProcessedSPNodes) {
|
|
|
|
assert(SP->getUnit()->getEmissionKind() != DICompileUnit::NoDebug);
|
|
|
|
forBothCUs(
|
|
|
|
getOrCreateDwarfCompileUnit(SP->getUnit()),
|
|
|
|
[&](DwarfCompileUnit &CU) { CU.finishSubprogramDefinition(SP); });
|
|
|
|
}
|
2012-11-22 08:59:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DwarfDebug::finalizeModuleInfo() {
|
2015-03-11 00:58:10 +08:00
|
|
|
const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
|
|
|
|
|
2014-05-28 02:37:48 +08:00
|
|
|
finishSubprogramDefinitions();
|
|
|
|
|
2018-08-17 23:22:04 +08:00
|
|
|
finishEntityDefinitions();
|
2014-06-14 06:18:23 +08:00
|
|
|
|
2017-05-29 14:32:34 +08:00
|
|
|
// Include the DWO file name in the hash if there's more than one CU.
|
|
|
|
// This handles ThinLTO's situation where imported CUs may very easily be
|
|
|
|
// duplicate with the same CU partially imported into another ThinLTO unit.
|
|
|
|
StringRef DWOName;
|
|
|
|
if (CUMap.size() > 1)
|
|
|
|
DWOName = Asm->TM.Options.MCOptions.SplitDwarfFile;
|
|
|
|
|
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;
|
2018-08-02 03:38:20 +08:00
|
|
|
if (TheCU.getCUNode()->isDebugDirectivesOnly())
|
|
|
|
continue;
|
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();
|
2018-12-15 06:44:46 +08:00
|
|
|
if (useSplitDwarf() && !empty(TheCU.getUnitDie().children())) {
|
|
|
|
finishUnitAttributes(TheCU.getCUNode(), TheCU);
|
|
|
|
TheCU.addString(TheCU.getUnitDie(), dwarf::DW_AT_GNU_dwo_name,
|
|
|
|
Asm->TM.Options.MCOptions.SplitDwarfFile);
|
|
|
|
SkCU->addString(SkCU->getUnitDie(), dwarf::DW_AT_GNU_dwo_name,
|
|
|
|
Asm->TM.Options.MCOptions.SplitDwarfFile);
|
2014-11-01 09:11:19 +08:00
|
|
|
// Emit a unique identifier for this CU.
|
2017-05-29 14:32:34 +08:00
|
|
|
uint64_t ID =
|
|
|
|
DIEHash(Asm).computeCUSignature(DWOName, TheCU.getUnitDie());
|
2018-05-23 01:27:31 +08:00
|
|
|
if (getDwarfVersion() >= 5) {
|
|
|
|
TheCU.setDWOId(ID);
|
|
|
|
SkCU->setDWOId(ID);
|
|
|
|
} else {
|
|
|
|
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);
|
|
|
|
}
|
2018-09-20 17:17:36 +08:00
|
|
|
|
2018-10-20 15:36:39 +08:00
|
|
|
if (getDwarfVersion() < 5 && !SkeletonHolder.getRangeLists().empty()) {
|
2015-03-11 00:58:10 +08:00
|
|
|
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);
|
|
|
|
}
|
2018-12-15 06:44:46 +08:00
|
|
|
} else if (SkCU) {
|
|
|
|
finishUnitAttributes(SkCU->getCUNode(), *SkCU);
|
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;
|
2018-10-20 14:02:15 +08:00
|
|
|
|
|
|
|
// We don't keep track of which addresses are used in which CU so this
|
|
|
|
// is a bit pessimistic under LTO.
|
2018-12-15 06:44:46 +08:00
|
|
|
if (!AddrPool.isEmpty() &&
|
|
|
|
(getDwarfVersion() >= 5 ||
|
|
|
|
(SkCU && !empty(TheCU.getUnitDie().children()))))
|
2018-10-20 14:02:15 +08:00
|
|
|
U.addAddrTableBase();
|
|
|
|
|
2014-11-04 07:10:59 +08:00
|
|
|
if (unsigned NumRanges = TheCU.getRanges().size()) {
|
2018-03-21 04:21:38 +08:00
|
|
|
if (NumRanges > 1 && useRangesSection())
|
2014-11-01 09:11:19 +08:00
|
|
|
// A DW_AT_low_pc attribute may also be specified in combination with
|
|
|
|
// DW_AT_ranges to specify the default base address for use in
|
|
|
|
// location lists (see Section 2.6.2) and range lists (see Section
|
|
|
|
// 2.17.3).
|
|
|
|
U.addUInt(U.getUnitDie(), dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, 0);
|
2014-11-04 07:10:59 +08:00
|
|
|
else
|
2015-05-02 10:31:49 +08:00
|
|
|
U.setBaseAddress(TheCU.getRanges().front().getStart());
|
2014-11-04 07:10:59 +08:00
|
|
|
U.attachRangesOrLowHighPC(U.getUnitDie(), TheCU.takeRanges());
|
2013-08-13 04:27:48 +08:00
|
|
|
}
|
2016-01-07 22:28:20 +08:00
|
|
|
|
2018-10-26 19:25:12 +08:00
|
|
|
if (getDwarfVersion() >= 5) {
|
|
|
|
if (U.hasRangeLists())
|
|
|
|
U.addRnglistsBase();
|
|
|
|
|
|
|
|
if (!DebugLocs.getLists().empty() && !useSplitDwarf())
|
|
|
|
U.addLoclistsBase();
|
|
|
|
}
|
2018-07-27 06:48:52 +08:00
|
|
|
|
2016-01-07 22:28:20 +08:00
|
|
|
auto *CUNode = cast<DICompileUnit>(P.first);
|
2016-02-01 22:09:41 +08:00
|
|
|
// If compile Unit has macros, emit "DW_AT_macro_info" attribute.
|
|
|
|
if (CUNode->getMacros())
|
|
|
|
U.addSectionLabel(U.getUnitDie(), dwarf::DW_AT_macro_info,
|
|
|
|
U.getMacroLabelBegin(),
|
|
|
|
TLOF.getDwarfMacinfoSection()->getBeginSymbol());
|
2013-08-13 04:27:48 +08:00
|
|
|
}
|
|
|
|
|
2017-07-27 02:48:32 +08:00
|
|
|
// Emit all frontend-produced Skeleton CUs, i.e., Clang modules.
|
|
|
|
for (auto *CUNode : MMI->getModule()->debug_compile_units())
|
2017-07-27 23:24:20 +08:00
|
|
|
if (CUNode->getDWOId())
|
2017-07-27 02:48:32 +08:00
|
|
|
getOrCreateDwarfCompileUnit(CUNode);
|
|
|
|
|
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
|
|
|
|
2019-03-19 21:16:28 +08:00
|
|
|
for (const auto &P : CUMap) {
|
|
|
|
auto &CU = *P.second;
|
|
|
|
CU.createBaseTypeDIEs();
|
|
|
|
}
|
|
|
|
|
2014-10-25 01:53:38 +08:00
|
|
|
// If we aren't actually generating debug info (check beginModule -
|
|
|
|
// conditionalized on !DisableDebugInfoPrinting and the presence of the
|
|
|
|
// llvm.dbg.cu metadata node)
|
2015-03-11 08:51:37 +08:00
|
|
|
if (!MMI->hasDebugInfo())
|
2013-11-19 17:04:36 +08:00
|
|
|
return;
|
2012-11-22 08:59:49 +08:00
|
|
|
|
|
|
|
// Finalize the debug info for the module.
|
|
|
|
finalizeModuleInfo();
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2013-11-19 17:04:50 +08:00
|
|
|
emitDebugStr();
|
2013-09-21 07:22:52 +08:00
|
|
|
|
2015-03-11 00:58:10 +08:00
|
|
|
if (useSplitDwarf())
|
|
|
|
emitDebugLocDWO();
|
|
|
|
else
|
|
|
|
// Emit info into a debug loc section.
|
|
|
|
emitDebugLoc();
|
|
|
|
|
2013-11-19 17:04:50 +08:00
|
|
|
// Corresponding abbreviations into a abbrev section.
|
|
|
|
emitAbbreviations();
|
2012-11-28 06:43:42 +08:00
|
|
|
|
2015-03-11 08:51:37 +08:00
|
|
|
// Emit all the DIEs into a debug info section.
|
|
|
|
emitDebugInfo();
|
|
|
|
|
2013-11-19 17:04:50 +08:00
|
|
|
// Emit info into a debug aranges section.
|
2014-02-14 09:26:55 +08:00
|
|
|
if (GenerateARangeSection)
|
|
|
|
emitDebugARanges();
|
2012-11-28 06:43:42 +08:00
|
|
|
|
2013-11-19 17:04:50 +08:00
|
|
|
// Emit info into a debug ranges section.
|
|
|
|
emitDebugRanges();
|
2012-11-28 06:43:42 +08:00
|
|
|
|
2016-01-07 22:28:20 +08:00
|
|
|
// Emit info into a debug macinfo section.
|
|
|
|
emitDebugMacinfo();
|
|
|
|
|
2013-11-19 17:04:50 +08:00
|
|
|
if (useSplitDwarf()) {
|
|
|
|
emitDebugStrDWO();
|
2012-12-01 07:59:06 +08:00
|
|
|
emitDebugInfoDWO();
|
2012-12-20 06:02:53 +08:00
|
|
|
emitDebugAbbrevDWO();
|
2014-03-18 09:17:26 +08:00
|
|
|
emitDebugLineDWO();
|
2018-10-20 16:12:36 +08:00
|
|
|
emitDebugRangesDWO();
|
2015-03-11 00:58:10 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2018-10-20 14:02:15 +08:00
|
|
|
emitDebugAddr();
|
|
|
|
|
2012-08-23 15:32:06 +08:00
|
|
|
// Emit info into the dwarf accelerator table sections.
|
2018-04-04 22:42:14 +08:00
|
|
|
switch (getAccelTableKind()) {
|
|
|
|
case AccelTableKind::Apple:
|
2011-11-07 17:24:32 +08:00
|
|
|
emitAccelNames();
|
|
|
|
emitAccelObjC();
|
|
|
|
emitAccelNamespaces();
|
|
|
|
emitAccelTypes();
|
2018-04-04 22:42:14 +08:00
|
|
|
break;
|
|
|
|
case AccelTableKind::Dwarf:
|
|
|
|
emitAccelDebugNames();
|
|
|
|
break;
|
|
|
|
case AccelTableKind::None:
|
|
|
|
break;
|
|
|
|
case AccelTableKind::Default:
|
|
|
|
llvm_unreachable("Default should have already been resolved.");
|
2011-11-07 17:24:32 +08:00
|
|
|
}
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2013-08-30 08:40:17 +08:00
|
|
|
// Emit the pubnames and pubtypes sections if requested.
|
2017-09-13 05:50:41 +08:00
|
|
|
emitDebugPubSections();
|
2009-11-24 09:14:22 +08:00
|
|
|
|
2010-08-03 01:32:15 +08:00
|
|
|
// clean up.
|
2017-05-12 09:13:45 +08:00
|
|
|
// FIXME: AbstractVariables.clear();
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2018-08-17 23:22:04 +08:00
|
|
|
void DwarfDebug::ensureAbstractEntityIsCreated(DwarfCompileUnit &CU,
|
|
|
|
const DINode *Node,
|
|
|
|
const MDNode *ScopeNode) {
|
|
|
|
if (CU.getExistingAbstractEntity(Node))
|
2014-06-14 07:52:55 +08:00
|
|
|
return;
|
2014-06-05 07:50:52 +08:00
|
|
|
|
2018-08-17 23:22:04 +08:00
|
|
|
CU.createAbstractEntity(Node, LScopes.getOrCreateAbstractScope(
|
2015-04-30 00:38:44 +08:00
|
|
|
cast<DILocalScope>(ScopeNode)));
|
2014-06-05 07:50:52 +08:00
|
|
|
}
|
|
|
|
|
2018-08-17 23:22:04 +08:00
|
|
|
void DwarfDebug::ensureAbstractEntityIsCreatedIfScoped(DwarfCompileUnit &CU,
|
|
|
|
const DINode *Node, const MDNode *ScopeNode) {
|
|
|
|
if (CU.getExistingAbstractEntity(Node))
|
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)))
|
2018-08-17 23:22:04 +08:00
|
|
|
CU.createAbstractEntity(Node, Scope);
|
2014-06-05 07:50:52 +08:00
|
|
|
}
|
2017-08-18 05:26:39 +08:00
|
|
|
|
2016-12-01 07:48:50 +08:00
|
|
|
// Collect variable information from side table maintained by MF.
|
|
|
|
void DwarfDebug::collectVariableInfoFromMFTable(
|
2018-09-06 10:22:06 +08:00
|
|
|
DwarfCompileUnit &TheCU, DenseSet<InlinedEntity> &Processed) {
|
|
|
|
SmallDenseMap<InlinedEntity, DbgVariable *> MFVars;
|
2016-12-01 07:48:50 +08:00
|
|
|
for (const auto &VI : Asm->MF->getVariableDbgInfo()) {
|
2014-03-09 23:44:39 +08:00
|
|
|
if (!VI.Var)
|
2013-11-19 17:04:36 +08:00
|
|
|
continue;
|
2015-04-17 06:12:59 +08:00
|
|
|
assert(VI.Var->isValidLocationForIntrinsic(VI.Loc) &&
|
|
|
|
"Expected inlined-at fields to agree");
|
|
|
|
|
2018-09-06 10:22:06 +08:00
|
|
|
InlinedEntity 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
|
|
|
|
2018-08-17 23:22:04 +08:00
|
|
|
ensureAbstractEntityIsCreatedIfScoped(TheCU, Var.first, Scope->getScopeNode());
|
2018-09-06 10:22:06 +08:00
|
|
|
auto RegVar = llvm::make_unique<DbgVariable>(
|
|
|
|
cast<DILocalVariable>(Var.first), Var.second);
|
AsmPrinter: Rewrite initialization of DbgVariable, NFC
There are three types of `DbgVariable`:
- alloca variables, created based on the MMI table,
- register variables, created based on DBG_VALUE instructions, and
- optimized-out variables.
This commit reconfigures `DbgVariable` to make it easier to tell which
kind we have, and make initialization a little clearer.
For MMI/alloca variables, `FrameIndex.size()` must always equal
`Expr.size()`, and there shouldn't be an `MInsn`. For register
variables (with a `MInsn`), `FrameIndex` must be empty, and `Expr`
should have 0 or 1 element depending on whether it has a complex
expression (registers with multiple locations use `DebugLocListIndex`).
Optimized-out variables shouldn't have any of these fields.
Moreover, this separates DBG_VALUE initialization until after the
variable is created, simplifying logic in a future commit that changes
`collectVariableInfo()` to stop creating empty .debug_loc entries/lists.
llvm-svn: 240243
2015-06-22 00:50:43 +08:00
|
|
|
RegVar->initializeMMI(VI.Expr, VI.Slot);
|
2017-07-26 07:32:59 +08:00
|
|
|
if (DbgVariable *DbgVar = MFVars.lookup(Var))
|
|
|
|
DbgVar->addMMIEntry(*RegVar);
|
|
|
|
else if (InfoHolder.addScopeVariable(Scope, RegVar.get())) {
|
|
|
|
MFVars.insert({Var, RegVar.get()});
|
2018-08-17 23:22:04 +08:00
|
|
|
ConcreteEntities.push_back(std::move(RegVar));
|
2017-07-26 07:32:59 +08:00
|
|
|
}
|
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();
|
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()) {
|
2017-08-03 01:19:13 +08:00
|
|
|
auto RegOp = MI->getOperand(0);
|
|
|
|
auto Op1 = MI->getOperand(1);
|
2013-07-10 04:28:37 +08:00
|
|
|
// If the second operand is an immediate, this is a
|
|
|
|
// register-indirect address.
|
2017-08-03 01:19:13 +08:00
|
|
|
assert((!Op1.isImm() || (Op1.getImm() == 0)) && "unexpected offset");
|
|
|
|
MachineLocation MLoc(RegOp.getReg(), Op1.isImm());
|
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
|
|
|
}
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// If this and Next are describing different fragments of the same
|
2016-01-16 09:11:33 +08:00
|
|
|
/// variable, merge them by appending Next's values to the current
|
|
|
|
/// list of values.
|
|
|
|
/// Return true if the merge was successful.
|
|
|
|
bool DebugLocEntry::MergeValues(const DebugLocEntry &Next) {
|
|
|
|
if (Begin == Next.Begin) {
|
2016-02-04 05:13:33 +08:00
|
|
|
auto *FirstExpr = cast<DIExpression>(Values[0].Expression);
|
|
|
|
auto *FirstNextExpr = cast<DIExpression>(Next.Values[0].Expression);
|
2016-12-06 02:04:47 +08:00
|
|
|
if (!FirstExpr->isFragment() || !FirstNextExpr->isFragment())
|
2016-02-04 05:13:33 +08:00
|
|
|
return false;
|
|
|
|
|
2016-12-06 02:04:47 +08:00
|
|
|
// We can only merge entries if none of the fragments overlap any others.
|
2016-02-04 05:13:33 +08:00
|
|
|
// In doing so, we can take advantage of the fact that both lists are
|
|
|
|
// sorted.
|
|
|
|
for (unsigned i = 0, j = 0; i < Values.size(); ++i) {
|
|
|
|
for (; j < Next.Values.size(); ++j) {
|
2018-03-13 02:02:39 +08:00
|
|
|
int res = cast<DIExpression>(Values[i].Expression)->fragmentCmp(
|
2016-02-11 04:55:49 +08:00
|
|
|
cast<DIExpression>(Next.Values[j].Expression));
|
2016-02-04 05:13:33 +08:00
|
|
|
if (res == 0) // The two expressions overlap, we can't merge.
|
|
|
|
return false;
|
|
|
|
// Values[i] is entirely before Next.Values[j],
|
|
|
|
// so go back to the next entry of Values.
|
|
|
|
else if (res == -1)
|
|
|
|
break;
|
|
|
|
// Next.Values[j] is entirely before Values[i], so go on to the
|
|
|
|
// next entry of Next.Values.
|
|
|
|
}
|
2016-01-16 09:11:33 +08:00
|
|
|
}
|
2016-02-04 05:13:33 +08:00
|
|
|
|
|
|
|
addValues(Next.Values);
|
|
|
|
End = Next.End;
|
|
|
|
return true;
|
2016-01-16 09:11:33 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-02 06:11:58 +08:00
|
|
|
/// Build the location list for all DBG_VALUEs in the function that
|
|
|
|
/// describe the same variable. If the ranges of several independent
|
2016-12-06 02:04:47 +08:00
|
|
|
/// fragments of the same variable overlap partially, split them up and
|
2014-08-02 06:11:58 +08:00
|
|
|
/// combine the ranges. The resulting DebugLocEntries are will have
|
|
|
|
/// strict monotonically increasing begin addresses and will never
|
|
|
|
/// overlap.
|
|
|
|
//
|
|
|
|
// Input:
|
|
|
|
//
|
2016-12-06 02:04:47 +08:00
|
|
|
// Ranges History [var, loc, fragment ofs size]
|
|
|
|
// 0 | [x, (reg0, fragment 0, 32)]
|
|
|
|
// 1 | | [x, (reg1, fragment 32, 32)] <- IsFragmentOfPrevEntry
|
2014-08-02 06:11:58 +08:00
|
|
|
// 2 | | ...
|
|
|
|
// 3 | [clobber reg0]
|
2016-12-06 02:04:47 +08:00
|
|
|
// 4 [x, (mem, fragment 0, 64)] <- overlapping with both previous fragments of
|
2015-02-18 04:02:28 +08:00
|
|
|
// x.
|
2014-08-02 06:11:58 +08:00
|
|
|
//
|
|
|
|
// Output:
|
|
|
|
//
|
2016-12-06 02:04:47 +08:00
|
|
|
// [0-1] [x, (reg0, fragment 0, 32)]
|
|
|
|
// [1-3] [x, (reg0, fragment 0, 32), (reg1, fragment 32, 32)]
|
|
|
|
// [3-4] [x, (reg1, fragment 32, 32)]
|
|
|
|
// [4- ] [x, (mem, fragment 0, 64)]
|
2014-08-06 07:14:16 +08:00
|
|
|
void
|
|
|
|
DwarfDebug::buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
|
|
|
|
const DbgValueHistoryMap::InstrRanges &Ranges) {
|
2014-08-12 05:05:57 +08:00
|
|
|
SmallVector<DebugLocEntry::Value, 4> OpenRanges;
|
2014-08-02 06:11:58 +08:00
|
|
|
|
|
|
|
for (auto I = Ranges.begin(), E = Ranges.end(); I != E; ++I) {
|
|
|
|
const MachineInstr *Begin = I->first;
|
|
|
|
const MachineInstr *End = I->second;
|
|
|
|
assert(Begin->isDebugValue() && "Invalid History entry");
|
|
|
|
|
|
|
|
// Check if a variable is inaccessible in this range.
|
2014-08-13 05:55:58 +08:00
|
|
|
if (Begin->getNumOperands() > 1 &&
|
|
|
|
Begin->getOperand(0).isReg() && !Begin->getOperand(0).getReg()) {
|
2014-08-02 06:11:58 +08:00
|
|
|
OpenRanges.clear();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-06 02:04:47 +08:00
|
|
|
// If this fragment overlaps with any open ranges, truncate them.
|
2015-04-30 00:38:44 +08:00
|
|
|
const DIExpression *DIExpr = Begin->getDebugExpression();
|
2016-08-12 05:15:00 +08:00
|
|
|
auto Last = remove_if(OpenRanges, [&](DebugLocEntry::Value R) {
|
2018-03-13 02:02:39 +08:00
|
|
|
return DIExpr->fragmentsOverlap(R.getExpression());
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
});
|
2014-08-02 06:11:58 +08:00
|
|
|
OpenRanges.erase(Last, OpenRanges.end());
|
|
|
|
|
|
|
|
const MCSymbol *StartLabel = getLabelBeforeInsn(Begin);
|
|
|
|
assert(StartLabel && "Forgot label before DBG_VALUE starting a range!");
|
|
|
|
|
|
|
|
const MCSymbol *EndLabel;
|
|
|
|
if (End != nullptr)
|
|
|
|
EndLabel = getLabelAfterInsn(End);
|
|
|
|
else if (std::next(I) == Ranges.end())
|
2015-03-05 10:05:42 +08:00
|
|
|
EndLabel = Asm->getFunctionEnd();
|
2014-08-02 06:11:58 +08:00
|
|
|
else
|
|
|
|
EndLabel = getLabelBeforeInsn(std::next(I)->first);
|
|
|
|
assert(EndLabel && "Forgot label after instruction ending a range!");
|
|
|
|
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "DotDebugLoc: " << *Begin << "\n");
|
2014-08-02 06:11:58 +08:00
|
|
|
|
|
|
|
auto Value = getDebugLocValue(Begin);
|
[DebugInfo] Omit location list entries with empty ranges
Summary:
This fixes PR39710. In that case we emitted a location list looking like
this:
.Ldebug_loc0:
.quad .Lfunc_begin0-.Lfunc_begin0
.quad .Lfunc_begin0-.Lfunc_begin0
.short 1 # Loc expr size
.byte 85 # DW_OP_reg5
.quad .Lfunc_begin0-.Lfunc_begin0
.quad .Lfunc_end0-.Lfunc_begin0
.short 1 # Loc expr size
.byte 85 # super-register DW_OP_reg5
.quad 0
.quad 0
As seen, the first entry's beginning and ending addresses evalute to 0,
which meant that the entry inadvertently became an "end of list" entry,
resulting in the location list ending sooner than expected.
To fix this, omit all entries with empty ranges. Location list entries
with empty ranges do not have any effect, as specified by DWARF, so we
might as well drop them:
"A location list entry (but not a base address selection or end of list
entry) whose beginning and ending addresses are equal has no effect
because the size of the range covered by such an entry is zero."
Reviewers: davide, aprantl, dblaikie
Reviewed By: aprantl
Subscribers: javed.absar, JDevlieghere, llvm-commits
Tags: #debug-info
Differential Revision: https://reviews.llvm.org/D55919
llvm-svn: 350698
2019-01-09 17:58:59 +08:00
|
|
|
|
|
|
|
// Omit entries with empty ranges as they do not have any effect in DWARF.
|
|
|
|
if (StartLabel == EndLabel) {
|
|
|
|
// If this is a fragment, we must still add the value to the list of
|
|
|
|
// open ranges, since it may describe non-overlapping parts of the
|
|
|
|
// variable.
|
|
|
|
if (DIExpr->isFragment())
|
|
|
|
OpenRanges.push_back(Value);
|
|
|
|
LLVM_DEBUG(dbgs() << "Omitting location list entry with empty range.\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-08-06 07:14:16 +08:00
|
|
|
DebugLocEntry Loc(StartLabel, EndLabel, Value);
|
2014-08-12 04:59:28 +08:00
|
|
|
bool couldMerge = false;
|
|
|
|
|
2016-12-06 02:04:47 +08:00
|
|
|
// If this is a fragment, it may belong to the current DebugLocEntry.
|
|
|
|
if (DIExpr->isFragment()) {
|
2014-08-12 04:59:28 +08:00
|
|
|
// Add this value to the list of open ranges.
|
2014-08-12 05:05:57 +08:00
|
|
|
OpenRanges.push_back(Value);
|
2014-08-12 04:59:28 +08:00
|
|
|
|
2016-12-06 02:04:47 +08:00
|
|
|
// Attempt to add the fragment to the last entry.
|
2014-08-12 04:59:28 +08:00
|
|
|
if (!DebugLoc.empty())
|
|
|
|
if (DebugLoc.back().MergeValues(Loc))
|
|
|
|
couldMerge = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!couldMerge) {
|
|
|
|
// Need to add a new DebugLocEntry. Add all values from still
|
2016-12-06 02:04:47 +08:00
|
|
|
// valid non-overlapping fragments.
|
2014-08-12 05:06:00 +08:00
|
|
|
if (OpenRanges.size())
|
|
|
|
Loc.addValues(OpenRanges);
|
|
|
|
|
2014-08-02 06:11:58 +08:00
|
|
|
DebugLoc.push_back(std::move(Loc));
|
|
|
|
}
|
2014-08-12 04:59:28 +08:00
|
|
|
|
|
|
|
// Attempt to coalesce the ranges of two otherwise identical
|
|
|
|
// DebugLocEntries.
|
|
|
|
auto CurEntry = DebugLoc.rbegin();
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG({
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
dbgs() << CurEntry->getValues().size() << " Values:\n";
|
2015-05-27 04:06:51 +08:00
|
|
|
for (auto &Value : CurEntry->getValues())
|
2016-03-01 06:28:22 +08:00
|
|
|
Value.dump();
|
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
|
|
|
dbgs() << "-----\n";
|
|
|
|
});
|
2015-05-27 04:06:48 +08:00
|
|
|
|
|
|
|
auto PrevEntry = std::next(CurEntry);
|
|
|
|
if (PrevEntry != DebugLoc.rend() && PrevEntry->MergeRanges(*CurEntry))
|
|
|
|
DebugLoc.pop_back();
|
2014-08-02 06:11:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-17 23:22:04 +08:00
|
|
|
DbgEntity *DwarfDebug::createConcreteEntity(DwarfCompileUnit &TheCU,
|
|
|
|
LexicalScope &Scope,
|
|
|
|
const DINode *Node,
|
|
|
|
const DILocation *Location,
|
|
|
|
const MCSymbol *Sym) {
|
|
|
|
ensureAbstractEntityIsCreatedIfScoped(TheCU, Node, Scope.getScopeNode());
|
|
|
|
if (isa<const DILocalVariable>(Node)) {
|
|
|
|
ConcreteEntities.push_back(
|
|
|
|
llvm::make_unique<DbgVariable>(cast<const DILocalVariable>(Node),
|
|
|
|
Location));
|
|
|
|
InfoHolder.addScopeVariable(&Scope,
|
|
|
|
cast<DbgVariable>(ConcreteEntities.back().get()));
|
|
|
|
} else if (isa<const DILabel>(Node)) {
|
|
|
|
ConcreteEntities.push_back(
|
|
|
|
llvm::make_unique<DbgLabel>(cast<const DILabel>(Node),
|
|
|
|
Location, Sym));
|
|
|
|
InfoHolder.addScopeLabel(&Scope,
|
|
|
|
cast<DbgLabel>(ConcreteEntities.back().get()));
|
|
|
|
}
|
|
|
|
return ConcreteEntities.back().get();
|
AsmPrinter: Rewrite initialization of DbgVariable, NFC
There are three types of `DbgVariable`:
- alloca variables, created based on the MMI table,
- register variables, created based on DBG_VALUE instructions, and
- optimized-out variables.
This commit reconfigures `DbgVariable` to make it easier to tell which
kind we have, and make initialization a little clearer.
For MMI/alloca variables, `FrameIndex.size()` must always equal
`Expr.size()`, and there shouldn't be an `MInsn`. For register
variables (with a `MInsn`), `FrameIndex` must be empty, and `Expr`
should have 0 or 1 element depending on whether it has a complex
expression (registers with multiple locations use `DebugLocListIndex`).
Optimized-out variables shouldn't have any of these fields.
Moreover, this separates DBG_VALUE initialization until after the
variable is created, simplifying logic in a future commit that changes
`collectVariableInfo()` to stop creating empty .debug_loc entries/lists.
llvm-svn: 240243
2015-06-22 00:50:43 +08:00
|
|
|
}
|
2014-08-02 06:11:58 +08:00
|
|
|
|
2017-06-17 06:40:04 +08:00
|
|
|
/// Determine whether a *singular* DBG_VALUE is valid for the entirety of its
|
|
|
|
/// enclosing lexical scope. The check ensures there are no other instructions
|
|
|
|
/// in the same lexical scope preceding the DBG_VALUE and that its range is
|
|
|
|
/// either open or otherwise rolls off the end of the scope.
|
|
|
|
static bool validThroughout(LexicalScopes &LScopes,
|
|
|
|
const MachineInstr *DbgValue,
|
|
|
|
const MachineInstr *RangeEnd) {
|
|
|
|
assert(DbgValue->getDebugLoc() && "DBG_VALUE without a debug location");
|
|
|
|
auto MBB = DbgValue->getParent();
|
|
|
|
auto DL = DbgValue->getDebugLoc();
|
|
|
|
auto *LScope = LScopes.findLexicalScope(DL);
|
|
|
|
// Scope doesn't exist; this is a dead DBG_VALUE.
|
|
|
|
if (!LScope)
|
2016-03-01 03:49:46 +08:00
|
|
|
return false;
|
2017-06-17 06:40:04 +08:00
|
|
|
auto &LSRange = LScope->getRanges();
|
|
|
|
if (LSRange.size() == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Determine if the DBG_VALUE is valid at the beginning of its lexical block.
|
|
|
|
const MachineInstr *LScopeBegin = LSRange.front().first;
|
|
|
|
// Early exit if the lexical scope begins outside of the current block.
|
|
|
|
if (LScopeBegin->getParent() != MBB)
|
|
|
|
return false;
|
|
|
|
MachineBasicBlock::const_reverse_iterator Pred(DbgValue);
|
|
|
|
for (++Pred; Pred != MBB->rend(); ++Pred) {
|
|
|
|
if (Pred->getFlag(MachineInstr::FrameSetup))
|
|
|
|
break;
|
|
|
|
auto PredDL = Pred->getDebugLoc();
|
2017-06-21 05:08:52 +08:00
|
|
|
if (!PredDL || Pred->isMetaInstruction())
|
2017-06-17 06:40:04 +08:00
|
|
|
continue;
|
|
|
|
// Check whether the instruction preceding the DBG_VALUE is in the same
|
|
|
|
// (sub)scope as the DBG_VALUE.
|
2017-06-21 05:08:52 +08:00
|
|
|
if (DL->getScope() == PredDL->getScope())
|
|
|
|
return false;
|
|
|
|
auto *PredScope = LScopes.findLexicalScope(PredDL);
|
|
|
|
if (!PredScope || LScope->dominates(PredScope))
|
2016-03-01 03:49:46 +08:00
|
|
|
return false;
|
2017-06-17 06:40:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the range of the DBG_VALUE is open-ended, report success.
|
|
|
|
if (!RangeEnd)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Fail if there are instructions belonging to our scope in another block.
|
|
|
|
const MachineInstr *LScopeEnd = LSRange.back().second;
|
|
|
|
if (LScopeEnd->getParent() != MBB)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Single, constant DBG_VALUEs in the prologue are promoted to be live
|
|
|
|
// throughout the function. This is a hack, presumably for DWARF v2 and not
|
|
|
|
// necessarily correct. It would be much better to use a dbg.declare instead
|
|
|
|
// if we know the constant is live throughout the scope.
|
|
|
|
if (DbgValue->getOperand(0).isImm() && MBB->pred_empty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2016-03-01 03:49:46 +08:00
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Find variables for each lexical scope.
|
2018-08-17 23:22:04 +08:00
|
|
|
void DwarfDebug::collectEntityInfo(DwarfCompileUnit &TheCU,
|
|
|
|
const DISubprogram *SP,
|
2018-09-06 10:22:06 +08:00
|
|
|
DenseSet<InlinedEntity> &Processed) {
|
2013-07-04 05:37:03 +08:00
|
|
|
// Grab the variable info that was squirreled away in the MMI side-table.
|
2017-05-12 09:13:45 +08:00
|
|
|
collectVariableInfoFromMFTable(TheCU, Processed);
|
2010-03-16 02:33:46 +08:00
|
|
|
|
2014-05-01 07:02:40 +08:00
|
|
|
for (const auto &I : DbgValues) {
|
2018-09-06 10:22:06 +08:00
|
|
|
InlinedEntity IV = I.first;
|
2015-04-16 06:29:27 +08:00
|
|
|
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;
|
2018-09-06 10:22:06 +08:00
|
|
|
const DILocalVariable *LocalVar = cast<DILocalVariable>(IV.first);
|
2015-04-30 00:38:44 +08:00
|
|
|
if (const DILocation *IA = IV.second)
|
2018-09-06 10:22:06 +08:00
|
|
|
Scope = LScopes.findInlinedScope(LocalVar->getScope(), IA);
|
2015-02-17 08:02:27 +08:00
|
|
|
else
|
2018-09-06 10:22:06 +08:00
|
|
|
Scope = LScopes.findLexicalScope(LocalVar->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);
|
2018-08-17 23:22:04 +08:00
|
|
|
DbgVariable *RegVar = cast<DbgVariable>(createConcreteEntity(TheCU,
|
2018-09-06 10:22:06 +08:00
|
|
|
*Scope, LocalVar, IV.second));
|
AsmPrinter: Rewrite initialization of DbgVariable, NFC
There are three types of `DbgVariable`:
- alloca variables, created based on the MMI table,
- register variables, created based on DBG_VALUE instructions, and
- optimized-out variables.
This commit reconfigures `DbgVariable` to make it easier to tell which
kind we have, and make initialization a little clearer.
For MMI/alloca variables, `FrameIndex.size()` must always equal
`Expr.size()`, and there shouldn't be an `MInsn`. For register
variables (with a `MInsn`), `FrameIndex` must be empty, and `Expr`
should have 0 or 1 element depending on whether it has a complex
expression (registers with multiple locations use `DebugLocListIndex`).
Optimized-out variables shouldn't have any of these fields.
Moreover, this separates DBG_VALUE initialization until after the
variable is created, simplifying logic in a future commit that changes
`collectVariableInfo()` to stop creating empty .debug_loc entries/lists.
llvm-svn: 240243
2015-06-22 00:50:43 +08:00
|
|
|
|
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");
|
|
|
|
|
2017-06-17 06:40:04 +08:00
|
|
|
// Check if there is a single DBG_VALUE, valid throughout the var's scope.
|
2016-03-01 03:49:46 +08:00
|
|
|
if (Ranges.size() == 1 &&
|
2017-06-17 06:40:04 +08:00
|
|
|
validThroughout(LScopes, MInsn, Ranges.front().second)) {
|
2015-06-22 00:54:56 +08:00
|
|
|
RegVar->initializeDbgValue(MInsn);
|
2010-05-26 07:40:22 +08:00
|
|
|
continue;
|
2015-06-22 00:54:56 +08:00
|
|
|
}
|
2018-06-29 22:23:28 +08:00
|
|
|
// Do not emit location lists if .debug_loc secton is disabled.
|
|
|
|
if (!useLocSection())
|
|
|
|
continue;
|
2010-05-26 07:40:22 +08:00
|
|
|
|
2013-01-29 01:33:26 +08:00
|
|
|
// Handle multiple DBG_VALUE instructions describing one variable.
|
2015-06-22 00:54:56 +08:00
|
|
|
DebugLocStream::ListBuilder List(DebugLocs, TheCU, *Asm, *RegVar, *MInsn);
|
2014-08-02 06:11:58 +08:00
|
|
|
|
|
|
|
// Build the location list for this variable.
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
SmallVector<DebugLocEntry, 8> Entries;
|
|
|
|
buildLocationList(Entries, Ranges);
|
2015-04-18 00:28:58 +08:00
|
|
|
|
2016-03-01 01:06:46 +08:00
|
|
|
// If the variable has a DIBasicType, extract it. Basic types cannot have
|
2015-04-18 00:28:58 +08:00
|
|
|
// unique identifiers, so don't bother resolving the type with the
|
|
|
|
// identifier map.
|
2015-04-30 00:38:44 +08:00
|
|
|
const DIBasicType *BT = dyn_cast<DIBasicType>(
|
2018-09-06 10:22:06 +08:00
|
|
|
static_cast<const Metadata *>(LocalVar->getType()));
|
2015-04-18 00:28:58 +08:00
|
|
|
|
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)
|
2019-03-19 21:16:28 +08:00
|
|
|
Entry.finalize(*Asm, List, BT, TheCU);
|
2010-03-16 02:33:46 +08:00
|
|
|
}
|
2010-05-15 05:01:35 +08:00
|
|
|
|
2018-09-06 10:22:06 +08:00
|
|
|
// For each InlinedEntity collected from DBG_LABEL instructions, convert to
|
2018-08-17 23:22:04 +08:00
|
|
|
// DWARF-related DbgLabel.
|
|
|
|
for (const auto &I : DbgLabels) {
|
2018-09-06 10:22:06 +08:00
|
|
|
InlinedEntity IL = I.first;
|
2018-08-17 23:22:04 +08:00
|
|
|
const MachineInstr *MI = I.second;
|
|
|
|
if (MI == nullptr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
LexicalScope *Scope = nullptr;
|
2018-09-06 10:22:06 +08:00
|
|
|
const DILabel *Label = cast<DILabel>(IL.first);
|
2018-08-17 23:22:04 +08:00
|
|
|
// Get inlined DILocation if it is inlined label.
|
|
|
|
if (const DILocation *IA = IL.second)
|
2018-09-06 10:22:06 +08:00
|
|
|
Scope = LScopes.findInlinedScope(Label->getScope(), IA);
|
2018-08-17 23:22:04 +08:00
|
|
|
else
|
2018-09-06 10:22:06 +08:00
|
|
|
Scope = LScopes.findLexicalScope(Label->getScope());
|
2018-08-17 23:22:04 +08:00
|
|
|
// If label scope is not found then skip this label.
|
|
|
|
if (!Scope)
|
|
|
|
continue;
|
|
|
|
|
2018-09-06 10:22:06 +08:00
|
|
|
Processed.insert(IL);
|
2018-08-17 23:22:04 +08:00
|
|
|
/// At this point, the temporary label is created.
|
|
|
|
/// Save the temporary label to DbgLabel entity to get the
|
|
|
|
/// actually address when generating Dwarf DIE.
|
|
|
|
MCSymbol *Sym = getLabelBeforeInsn(MI);
|
2018-09-06 10:22:06 +08:00
|
|
|
createConcreteEntity(TheCU, *Scope, Label, IL.second, Sym);
|
2018-08-17 23:22:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Collect info for variables/labels that were optimized out.
|
[DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label.
In order to set breakpoints on labels and list source code around
labels, we need collect debug information for labels, i.e., label
name, the function label belong, line number in the file, and the
address label located. In order to keep these information in LLVM
IR and to allow backend to generate debug information correctly.
We create a new kind of metadata for labels, DILabel. The format
of DILabel is
!DILabel(scope: !1, name: "foo", file: !2, line: 3)
We hope to keep debug information as much as possible even the
code is optimized. So, we create a new kind of intrinsic for label
metadata to avoid the metadata is eliminated with basic block.
The intrinsic will keep existing if we keep it from optimized out.
The format of the intrinsic is
llvm.dbg.label(metadata !1)
It has only one argument, that is the DILabel metadata. The
intrinsic will follow the label immediately. Backend could get the
label metadata through the intrinsic's parameter.
We also create DIBuilder API for labels to be used by Frontend.
Frontend could use createLabel() to allocate DILabel objects, and use
insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR.
Differential Revision: https://reviews.llvm.org/D45024
Patch by Hsiangkai Wang.
llvm-svn: 331841
2018-05-09 10:40:45 +08:00
|
|
|
for (const DINode *DN : SP->getRetainedNodes()) {
|
2018-09-06 10:22:06 +08:00
|
|
|
if (!Processed.insert(InlinedEntity(DN, nullptr)).second)
|
|
|
|
continue;
|
2018-08-17 23:22:04 +08:00
|
|
|
LexicalScope *Scope = nullptr;
|
[DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label.
In order to set breakpoints on labels and list source code around
labels, we need collect debug information for labels, i.e., label
name, the function label belong, line number in the file, and the
address label located. In order to keep these information in LLVM
IR and to allow backend to generate debug information correctly.
We create a new kind of metadata for labels, DILabel. The format
of DILabel is
!DILabel(scope: !1, name: "foo", file: !2, line: 3)
We hope to keep debug information as much as possible even the
code is optimized. So, we create a new kind of intrinsic for label
metadata to avoid the metadata is eliminated with basic block.
The intrinsic will keep existing if we keep it from optimized out.
The format of the intrinsic is
llvm.dbg.label(metadata !1)
It has only one argument, that is the DILabel metadata. The
intrinsic will follow the label immediately. Backend could get the
label metadata through the intrinsic's parameter.
We also create DIBuilder API for labels to be used by Frontend.
Frontend could use createLabel() to allocate DILabel objects, and use
insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR.
Differential Revision: https://reviews.llvm.org/D45024
Patch by Hsiangkai Wang.
llvm-svn: 331841
2018-05-09 10:40:45 +08:00
|
|
|
if (auto *DV = dyn_cast<DILocalVariable>(DN)) {
|
2018-08-17 23:22:04 +08:00
|
|
|
Scope = LScopes.findLexicalScope(DV->getScope());
|
|
|
|
} else if (auto *DL = dyn_cast<DILabel>(DN)) {
|
|
|
|
Scope = LScopes.findLexicalScope(DL->getScope());
|
[DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label.
In order to set breakpoints on labels and list source code around
labels, we need collect debug information for labels, i.e., label
name, the function label belong, line number in the file, and the
address label located. In order to keep these information in LLVM
IR and to allow backend to generate debug information correctly.
We create a new kind of metadata for labels, DILabel. The format
of DILabel is
!DILabel(scope: !1, name: "foo", file: !2, line: 3)
We hope to keep debug information as much as possible even the
code is optimized. So, we create a new kind of intrinsic for label
metadata to avoid the metadata is eliminated with basic block.
The intrinsic will keep existing if we keep it from optimized out.
The format of the intrinsic is
llvm.dbg.label(metadata !1)
It has only one argument, that is the DILabel metadata. The
intrinsic will follow the label immediately. Backend could get the
label metadata through the intrinsic's parameter.
We also create DIBuilder API for labels to be used by Frontend.
Frontend could use createLabel() to allocate DILabel objects, and use
insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR.
Differential Revision: https://reviews.llvm.org/D45024
Patch by Hsiangkai Wang.
llvm-svn: 331841
2018-05-09 10:40:45 +08:00
|
|
|
}
|
2018-08-17 23:22:04 +08:00
|
|
|
|
|
|
|
if (Scope)
|
|
|
|
createConcreteEntity(TheCU, *Scope, DN, nullptr);
|
2010-05-15 05:01:35 +08:00
|
|
|
}
|
2010-05-26 07:40:22 +08:00
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Process beginning of an instruction.
|
2010-10-27 01:49:02 +08:00
|
|
|
void DwarfDebug::beginInstruction(const MachineInstr *MI) {
|
2016-02-11 04:55:49 +08:00
|
|
|
DebugHandlerBase::beginInstruction(MI);
|
|
|
|
assert(CurMI);
|
|
|
|
|
2017-12-16 06:22:58 +08:00
|
|
|
const auto *SP = MI->getMF()->getFunction().getSubprogram();
|
2017-05-27 01:05:15 +08:00
|
|
|
if (!SP || SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug)
|
|
|
|
return;
|
|
|
|
|
2016-12-10 03:15:32 +08:00
|
|
|
// Check if source location changes, but ignore DBG_VALUE and CFI locations.
|
2018-02-15 01:35:52 +08:00
|
|
|
// If the instruction is part of the function frame setup code, do not emit
|
|
|
|
// any line record, as there is no correspondence with any user code.
|
|
|
|
if (MI->isMetaInstruction() || MI->getFlag(MachineInstr::FrameSetup))
|
2016-11-23 03:46:51 +08:00
|
|
|
return;
|
|
|
|
const DebugLoc &DL = MI->getDebugLoc();
|
2016-12-13 04:49:11 +08:00
|
|
|
// When we emit a line-0 record, we don't update PrevInstLoc; so look at
|
|
|
|
// the last line number actually emitted, to see if it was line 0.
|
|
|
|
unsigned LastAsmLine =
|
|
|
|
Asm->OutStreamer->getContext().getCurrentDwarfLoc().getLine();
|
|
|
|
|
2018-10-06 04:37:17 +08:00
|
|
|
// Request a label after the call in order to emit AT_return_pc information
|
|
|
|
// in call site entries. TODO: Add support for targets with delay slots.
|
|
|
|
if (SP->areAllCallsDescribed() && MI->isCall() && !MI->hasDelaySlot())
|
|
|
|
requestLabelAfterInsn(MI);
|
|
|
|
|
2016-12-13 04:49:11 +08:00
|
|
|
if (DL == PrevInstLoc) {
|
|
|
|
// If we have an ongoing unspecified location, nothing to do here.
|
|
|
|
if (!DL)
|
|
|
|
return;
|
|
|
|
// We have an explicit location, same as the previous location.
|
|
|
|
// But we might be coming back to it after a line 0 record.
|
|
|
|
if (LastAsmLine == 0 && DL.getLine() != 0) {
|
|
|
|
// Reinstate the source location but not marked as a statement.
|
|
|
|
const MDNode *Scope = DL.getScope();
|
|
|
|
recordSourceLine(DL.getLine(), DL.getCol(), Scope, /*Flags=*/0);
|
|
|
|
}
|
2016-11-23 03:46:51 +08:00
|
|
|
return;
|
2016-12-13 04:49:11 +08:00
|
|
|
}
|
2016-11-23 03:46:51 +08:00
|
|
|
|
|
|
|
if (!DL) {
|
|
|
|
// We have an unspecified location, which might want to be line 0.
|
2016-12-13 04:49:11 +08:00
|
|
|
// If we have already emitted a line-0 record, don't repeat it.
|
|
|
|
if (LastAsmLine == 0)
|
|
|
|
return;
|
|
|
|
// If user said Don't Do That, don't do that.
|
|
|
|
if (UnknownLocations == Disable)
|
|
|
|
return;
|
2018-10-12 07:37:58 +08:00
|
|
|
// See if we have a reason to emit a line-0 record now.
|
|
|
|
// Reasons to emit a line-0 record include:
|
|
|
|
// - User asked for it (UnknownLocations).
|
|
|
|
// - Instruction has a label, so it's referenced from somewhere else,
|
|
|
|
// possibly debug information; we want it to have a source location.
|
|
|
|
// - Instruction is at the top of a block; we don't want to inherit the
|
|
|
|
// location from the physically previous (maybe unrelated) block.
|
|
|
|
if (UnknownLocations == Enable || PrevLabel ||
|
|
|
|
(PrevInstBB && PrevInstBB != MI->getParent())) {
|
|
|
|
// Preserve the file and column numbers, if we can, to save space in
|
|
|
|
// the encoded line table.
|
|
|
|
// Do not update PrevInstLoc, it remembers the last non-0 line.
|
|
|
|
const MDNode *Scope = nullptr;
|
|
|
|
unsigned Column = 0;
|
|
|
|
if (PrevInstLoc) {
|
|
|
|
Scope = PrevInstLoc.getScope();
|
|
|
|
Column = PrevInstLoc.getCol();
|
|
|
|
}
|
|
|
|
recordSourceLine(/*Line=*/0, Column, Scope, /*Flags=*/0);
|
2011-03-26 01:20:59 +08:00
|
|
|
}
|
2016-11-23 03:46:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-12 07:37:58 +08:00
|
|
|
// We have an explicit location, different from the previous location.
|
|
|
|
// Don't repeat a line-0 record, but otherwise emit the new location.
|
|
|
|
// (The new location might be an explicit line 0, which we do emit.)
|
2019-01-17 07:26:29 +08:00
|
|
|
if (DL.getLine() == 0 && LastAsmLine == 0)
|
2018-10-12 07:37:58 +08:00
|
|
|
return;
|
|
|
|
unsigned Flags = 0;
|
|
|
|
if (DL == PrologEndLoc) {
|
|
|
|
Flags |= DWARF2_FLAG_PROLOGUE_END | DWARF2_FLAG_IS_STMT;
|
|
|
|
PrologEndLoc = DebugLoc();
|
|
|
|
}
|
|
|
|
// If the line changed, we call that a new statement; unless we went to
|
|
|
|
// line 0 and came back, in which case it is not a new statement.
|
|
|
|
unsigned OldLine = PrevInstLoc ? PrevInstLoc.getLine() : LastAsmLine;
|
|
|
|
if (DL.getLine() && DL.getLine() != OldLine)
|
|
|
|
Flags |= DWARF2_FLAG_IS_STMT;
|
|
|
|
|
|
|
|
const MDNode *Scope = DL.getScope();
|
|
|
|
recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags);
|
|
|
|
|
|
|
|
// If we're not at line 0, remember this location.
|
|
|
|
if (DL.getLine())
|
|
|
|
PrevInstLoc = DL;
|
2009-10-02 04:31:14 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 06:47:41 +08:00
|
|
|
static DebugLoc findPrologueEndLoc(const MachineFunction *MF) {
|
|
|
|
// First known non-DBG_VALUE and non-frame setup location marks
|
|
|
|
// the beginning of the function body.
|
|
|
|
for (const auto &MBB : *MF)
|
|
|
|
for (const auto &MI : MBB)
|
2017-05-23 04:47:09 +08:00
|
|
|
if (!MI.isMetaInstruction() && !MI.getFlag(MachineInstr::FrameSetup) &&
|
2015-10-08 15:48:49 +08:00
|
|
|
MI.getDebugLoc())
|
2014-05-28 06:47:41 +08:00
|
|
|
return MI.getDebugLoc();
|
|
|
|
return DebugLoc();
|
|
|
|
}
|
|
|
|
|
2019-01-23 01:24:16 +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.
|
|
|
|
static void recordSourceLine(AsmPrinter &Asm, unsigned Line, unsigned Col,
|
|
|
|
const MDNode *S, unsigned Flags, unsigned CUID,
|
|
|
|
uint16_t DwarfVersion,
|
|
|
|
ArrayRef<std::unique_ptr<DwarfCompileUnit>> DCUs) {
|
|
|
|
StringRef Fn;
|
|
|
|
unsigned FileNo = 1;
|
|
|
|
unsigned Discriminator = 0;
|
|
|
|
if (auto *Scope = cast_or_null<DIScope>(S)) {
|
|
|
|
Fn = Scope->getFilename();
|
|
|
|
if (Line != 0 && DwarfVersion >= 4)
|
|
|
|
if (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope))
|
|
|
|
Discriminator = LBF->getDiscriminator();
|
|
|
|
|
|
|
|
FileNo = static_cast<DwarfCompileUnit &>(*DCUs[CUID])
|
|
|
|
.getOrCreateSourceID(Scope->getFile());
|
|
|
|
}
|
|
|
|
Asm.OutStreamer->EmitDwarfLocDirective(FileNo, Line, Col, Flags, 0,
|
|
|
|
Discriminator, Fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
DebugLoc DwarfDebug::emitInitialLocDirective(const MachineFunction &MF,
|
|
|
|
unsigned CUID) {
|
|
|
|
// Get beginning of function.
|
|
|
|
if (DebugLoc PrologEndLoc = findPrologueEndLoc(&MF)) {
|
|
|
|
// Ensure the compile unit is created if the function is called before
|
|
|
|
// beginFunction().
|
|
|
|
(void)getOrCreateDwarfCompileUnit(
|
|
|
|
MF.getFunction().getSubprogram()->getUnit());
|
|
|
|
// 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.
|
|
|
|
const DISubprogram *SP = PrologEndLoc->getInlinedAtScope()->getSubprogram();
|
|
|
|
::recordSourceLine(*Asm, SP->getScopeLine(), 0, SP, DWARF2_FLAG_IS_STMT,
|
|
|
|
CUID, getDwarfVersion(), getUnits());
|
|
|
|
return PrologEndLoc;
|
|
|
|
}
|
|
|
|
return DebugLoc();
|
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Gather pre-function debug information. Assumes being called immediately
|
|
|
|
// after the function entry point has been emitted.
|
2017-02-17 02:48:33 +08:00
|
|
|
void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
|
2013-12-03 23:10:23 +08:00
|
|
|
CurFn = MF;
|
2013-11-02 07:14:17 +08:00
|
|
|
|
2017-12-16 06:22:58 +08:00
|
|
|
auto *SP = MF->getFunction().getSubprogram();
|
2017-05-26 07:11:28 +08:00
|
|
|
assert(LScopes.empty() || SP == LScopes.getCurrentFunctionScope()->getScopeNode());
|
2017-05-27 02:52:56 +08:00
|
|
|
if (SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug)
|
2016-04-09 06:43:03 +08:00
|
|
|
return;
|
2017-05-27 02:52:56 +08:00
|
|
|
|
|
|
|
DwarfCompileUnit &CU = getOrCreateDwarfCompileUnit(SP->getUnit());
|
2017-05-26 07:11:28 +08:00
|
|
|
|
|
|
|
// Set DwarfDwarfCompileUnitID in MCContext to the Compile Unit this function
|
|
|
|
// belongs to so that we add to the correct per-cu line table in the
|
|
|
|
// non-asm case.
|
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
|
2017-05-27 02:52:56 +08:00
|
|
|
Asm->OutStreamer->getContext().setDwarfCompileUnitID(CU.getUniqueID());
|
2013-02-06 05:52:47 +08:00
|
|
|
|
2011-05-12 03:22:19 +08:00
|
|
|
// Record beginning of function.
|
2019-01-23 01:24:16 +08:00
|
|
|
PrologEndLoc = emitInitialLocDirective(
|
|
|
|
*MF, Asm->OutStreamer->getContext().getDwarfCompileUnitID());
|
2009-05-15 17:23:25 +08:00
|
|
|
}
|
|
|
|
|
2017-02-17 02:48:33 +08:00
|
|
|
void DwarfDebug::skippedNonDebugFunction() {
|
|
|
|
// If we don't have a subprogram for this function then there will be a hole
|
|
|
|
// in the range information. Keep note of this by setting the previously used
|
|
|
|
// section to nullptr.
|
|
|
|
PrevCU = nullptr;
|
|
|
|
CurFn = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Gather and emit post-function debug information.
|
2017-02-17 02:48:33 +08:00
|
|
|
void DwarfDebug::endFunctionImpl(const MachineFunction *MF) {
|
2017-12-16 06:22:58 +08:00
|
|
|
const DISubprogram *SP = MF->getFunction().getSubprogram();
|
2017-02-17 02:48:33 +08:00
|
|
|
|
2014-10-15 01:12:02 +08:00
|
|
|
assert(CurFn == MF &&
|
|
|
|
"endFunction should be called with the same function as beginFunction");
|
2013-12-03 23:10:23 +08:00
|
|
|
|
2013-12-10 07:57:44 +08:00
|
|
|
// Set DwarfDwarfCompileUnitID in MCContext to default value.
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->getContext().setDwarfCompileUnitID(0);
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2011-08-16 06:04:40 +08:00
|
|
|
LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
|
2016-12-16 07:17:52 +08:00
|
|
|
assert(!FnScope || SP == FnScope->getScopeNode());
|
2016-04-15 23:57:41 +08:00
|
|
|
DwarfCompileUnit &TheCU = *CUMap.lookup(SP->getUnit());
|
2018-08-02 03:38:20 +08:00
|
|
|
if (TheCU.getCUNode()->isDebugDirectivesOnly()) {
|
|
|
|
PrevLabel = nullptr;
|
|
|
|
CurFn = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
2014-10-23 08:06:27 +08:00
|
|
|
|
2018-09-06 10:22:06 +08:00
|
|
|
DenseSet<InlinedEntity> Processed;
|
|
|
|
collectEntityInfo(TheCU, SP, Processed);
|
2011-08-16 06:04:40 +08:00
|
|
|
|
2014-09-20 01:03:16 +08:00
|
|
|
// Add the range of this function to the list of ranges for the CU.
|
2015-03-05 10:05:42 +08:00
|
|
|
TheCU.addRange(RangeSpan(Asm->getFunctionBegin(), Asm->getFunctionEnd()));
|
2014-09-20 01:03:16 +08:00
|
|
|
|
|
|
|
// Under -gmlt, skip building the subprogram if there are no inlined
|
2017-01-19 08:44:11 +08:00
|
|
|
// subroutines inside it. But with -fdebug-info-for-profiling, the subprogram
|
|
|
|
// is still needed as we need its source location.
|
Change debug-info-for-profiling from a TargetOption to a function attribute.
Summary: LTO requires the debug-info-for-profiling to be a function attribute.
Reviewers: echristo, mehdi_amini, dblaikie, probinson, aprantl
Reviewed By: mehdi_amini, dblaikie, aprantl
Subscribers: aprantl, probinson, ahatanak, llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D29203
llvm-svn: 293833
2017-02-02 06:45:09 +08:00
|
|
|
if (!TheCU.getCUNode()->getDebugInfoForProfiling() &&
|
2017-01-19 08:44:11 +08:00
|
|
|
TheCU.getCUNode()->getEmissionKind() == DICompileUnit::LineTablesOnly &&
|
Disable the -gmlt optimization implemented in r218129 under Darwin due to issues with dsymutil.
r218129 omits DW_TAG_subprograms which have no inlined subroutines when
emitting -gmlt data. This makes -gmlt very low cost for -O0 builds.
Darwin's dsymutil reasonably considers a CU empty if it has no
subprograms (which occurs with the above optimization in -O0 programs
without any force_inline function calls) and drops the line table, CU,
and everything in this situation, making backtraces impossible.
Until dsymutil is modified to account for this, disable this
optimization on Darwin to preserve the desired functionality.
(see r218545, which should be reverted after this patch, for other
discussion/details)
Footnote:
In the long term, it doesn't look like this scheme (of simplified debug
info to describe inlining to enable backtracing) is tenable, it is far
too size inefficient for optimized code (the DW_TAG_inlined_subprograms,
even once compressed, are nearly twice as large as the line table
itself (also compressed)) and we'll be considering things like Cary's
two level line table proposal to encode all this information directly in
the line table.
llvm-svn: 218702
2014-10-01 05:28:32 +08:00
|
|
|
LScopes.getAbstractScopesList().empty() && !IsDarwin) {
|
2014-10-25 01:57:34 +08:00
|
|
|
assert(InfoHolder.getScopeVariables().empty());
|
2014-09-20 01:03:16 +08:00
|
|
|
PrevLabel = nullptr;
|
|
|
|
CurFn = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-14 04:44:58 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
size_t NumAbstractScopes = LScopes.getAbstractScopesList().size();
|
|
|
|
#endif
|
2011-08-11 04:55:27 +08:00
|
|
|
// Construct abstract scopes.
|
2014-03-08 03:09:39 +08:00
|
|
|
for (LexicalScope *AScope : LScopes.getAbstractScopesList()) {
|
2015-04-30 00:38:44 +08:00
|
|
|
auto *SP = cast<DISubprogram>(AScope->getScopeNode());
|
[DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label.
In order to set breakpoints on labels and list source code around
labels, we need collect debug information for labels, i.e., label
name, the function label belong, line number in the file, and the
address label located. In order to keep these information in LLVM
IR and to allow backend to generate debug information correctly.
We create a new kind of metadata for labels, DILabel. The format
of DILabel is
!DILabel(scope: !1, name: "foo", file: !2, line: 3)
We hope to keep debug information as much as possible even the
code is optimized. So, we create a new kind of intrinsic for label
metadata to avoid the metadata is eliminated with basic block.
The intrinsic will keep existing if we keep it from optimized out.
The format of the intrinsic is
llvm.dbg.label(metadata !1)
It has only one argument, that is the DILabel metadata. The
intrinsic will follow the label immediately. Backend could get the
label metadata through the intrinsic's parameter.
We also create DIBuilder API for labels to be used by Frontend.
Frontend could use createLabel() to allocate DILabel objects, and use
insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR.
Differential Revision: https://reviews.llvm.org/D45024
Patch by Hsiangkai Wang.
llvm-svn: 331841
2018-05-09 10:40:45 +08:00
|
|
|
for (const DINode *DN : SP->getRetainedNodes()) {
|
2018-09-06 10:22:06 +08:00
|
|
|
if (!Processed.insert(InlinedEntity(DN, nullptr)).second)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const MDNode *Scope = nullptr;
|
|
|
|
if (auto *DV = dyn_cast<DILocalVariable>(DN))
|
|
|
|
Scope = DV->getScope();
|
|
|
|
else if (auto *DL = dyn_cast<DILabel>(DN))
|
|
|
|
Scope = DL->getScope();
|
|
|
|
else
|
|
|
|
llvm_unreachable("Unexpected DI type!");
|
|
|
|
|
|
|
|
// Collect info for variables/labels that were optimized out.
|
|
|
|
ensureAbstractEntityIsCreated(TheCU, DN, Scope);
|
|
|
|
assert(LScopes.getAbstractScopesList().size() == NumAbstractScopes
|
|
|
|
&& "ensureAbstractEntityIsCreated inserted abstract scopes");
|
2010-06-26 06:07:34 +08:00
|
|
|
}
|
2017-05-12 09:13:45 +08:00
|
|
|
constructAbstractSubprogramScopeDIE(TheCU, AScope);
|
2011-08-11 04:55:27 +08:00
|
|
|
}
|
2012-11-20 06:42:10 +08:00
|
|
|
|
2016-12-16 07:37:38 +08:00
|
|
|
ProcessedSPNodes.insert(SP);
|
2018-10-06 04:37:17 +08:00
|
|
|
DIE &ScopeDIE = TheCU.constructSubprogramScopeDIE(SP, FnScope);
|
Provide gmlt-like inline scope information in the skeleton CU to facilitate symbolication without needing the .dwo files
Clang -gsplit-dwarf self-host -O0, binary increases by 0.0005%, -O2,
binary increases by 25%.
A large binary inside Google, split-dwarf, -O0, and other internal flags
(GDB index, etc) increases by 1.8%, optimized build is 35%.
The size impact may be somewhat greater in .o files (I haven't measured
that much - since the linked executable -O0 numbers seemed low enough)
due to relocations. These relocations could be removed if we taught the
llvm-symbolizer to handle indexed addressing in the .o file (GDB can't
cope with this just yet, but GDB won't be reading this info anyway).
Also debug_ranges could be shared between .o and .dwo, though ideally
debug_ranges would get a schema that could used index(+offset)
addressing, and move to the .dwo file, then we'd be back to sharing
addresses in the address pool again.
But for now, these sizes seem small enough to go ahead with this.
Verified that no other DW_TAGs are produced into the .o file other than
subprograms and inlined_subroutines.
llvm-svn: 221306
2014-11-05 06:12:25 +08:00
|
|
|
if (auto *SkelCU = TheCU.getSkeleton())
|
2016-08-25 02:29:49 +08:00
|
|
|
if (!LScopes.getAbstractScopesList().empty() &&
|
|
|
|
TheCU.getCUNode()->getSplitDebugInlining())
|
2016-12-16 07:17:52 +08:00
|
|
|
SkelCU->constructSubprogramScopeDIE(SP, FnScope);
|
2011-08-16 06:04:40 +08:00
|
|
|
|
2018-10-06 04:37:17 +08:00
|
|
|
// Construct call site entries.
|
|
|
|
constructCallSiteEntryDIEs(*SP, TheCU, ScopeDIE, *MF);
|
|
|
|
|
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();
|
2018-08-17 23:22:04 +08:00
|
|
|
InfoHolder.getScopeLabels().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) {
|
2019-01-23 01:24:16 +08:00
|
|
|
::recordSourceLine(*Asm, Line, Col, S, Flags,
|
|
|
|
Asm->OutStreamer->getContext().getDwarfCompileUnitID(),
|
|
|
|
getDwarfVersion(), getUnits());
|
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
|
|
|
}
|
|
|
|
|
2018-01-27 02:52:58 +08:00
|
|
|
void DwarfDebug::emitStringOffsetsTableHeader() {
|
|
|
|
DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
|
2018-07-26 22:36:07 +08:00
|
|
|
Holder.getStringPool().emitStringOffsetsTableHeader(
|
|
|
|
*Asm, Asm->getObjFileLowering().getDwarfStrOffSection(),
|
|
|
|
Holder.getStringOffsetsStartSym());
|
2018-01-27 02:52:58 +08:00
|
|
|
}
|
|
|
|
|
2018-01-29 22:52:34 +08:00
|
|
|
template <typename AccelTableT>
|
|
|
|
void DwarfDebug::emitAccel(AccelTableT &Accel, MCSection *Section,
|
2015-03-11 06:00:25 +08:00
|
|
|
StringRef 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.
|
[CodeGen] Refactor AppleAccelTable
Summary:
This commit separates the abstract accelerator table data structure
from the code for writing out an on-disk representation of a specific
accelerator table format. The idea is that former (now called
AccelTable<T>) can be reused for the DWARF v5 accelerator tables
as-is, without any further customizations.
Some bits of the emission code (now living in the EmissionContext class)
can be reused for DWARF v5 as well, but the subtle differences in the
layout of various subtables mean the sharing is not always possible.
(Also, the individual emit*** functions are fairly simple so there's a
tradeoff between making a bigger general-purpose function, and two
smaller targeted functions.)
Another advantage of this setup is that more of the serialization logic
can be hidden in the .cpp file -- I have moved declarations of the
header and all the emission functions there.
Reviewers: JDevlieghere, aprantl, probinson, dblaikie
Subscribers: echristo, clayborg, vleschuk, llvm-commits
Differential Revision: https://reviews.llvm.org/D43285
llvm-svn: 325516
2018-02-20 00:12:20 +08:00
|
|
|
emitAppleAccelTable(Asm, Accel, TableName, Section->getBeginSymbol());
|
2014-09-12 05:12:48 +08:00
|
|
|
}
|
|
|
|
|
2018-04-04 22:42:14 +08:00
|
|
|
void DwarfDebug::emitAccelDebugNames() {
|
2018-04-09 22:38:53 +08:00
|
|
|
// Don't emit anything if we have no compilation units to index.
|
|
|
|
if (getUnits().empty())
|
|
|
|
return;
|
|
|
|
|
2018-04-04 22:42:14 +08:00
|
|
|
emitDWARF5AccelTable(Asm, AccelDebugNames, *this, getUnits());
|
|
|
|
}
|
|
|
|
|
2014-09-12 05:12:48 +08:00
|
|
|
// Emit visible names into a hashed accelerator table section.
|
|
|
|
void DwarfDebug::emitAccelNames() {
|
|
|
|
emitAccel(AccelNames, Asm->getObjFileLowering().getDwarfAccelNamesSection(),
|
2015-03-11 06:00:25 +08:00
|
|
|
"Names");
|
2011-11-07 17:24:32 +08:00
|
|
|
}
|
|
|
|
|
2012-12-21 05:58:40 +08:00
|
|
|
// Emit objective C classes and categories into a hashed accelerator table
|
|
|
|
// section.
|
2011-11-07 17:24:32 +08:00
|
|
|
void DwarfDebug::emitAccelObjC() {
|
2014-09-12 05:12:48 +08:00
|
|
|
emitAccel(AccelObjC, Asm->getObjFileLowering().getDwarfAccelObjCSection(),
|
2015-03-11 06:00:25 +08:00
|
|
|
"ObjC");
|
2011-11-07 17:24:32 +08:00
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Emit namespace dies into a hashed accelerator table.
|
2011-11-07 17:24:32 +08:00
|
|
|
void DwarfDebug::emitAccelNamespaces() {
|
2014-09-12 05:12:48 +08:00
|
|
|
emitAccel(AccelNamespace,
|
|
|
|
Asm->getObjFileLowering().getDwarfAccelNamespaceSection(),
|
2015-03-11 06:00:25 +08:00
|
|
|
"namespac");
|
2011-11-07 17:24:32 +08:00
|
|
|
}
|
|
|
|
|
2012-11-28 06:43:45 +08:00
|
|
|
// Emit type dies into a hashed accelerator table.
|
2011-11-07 17:24:32 +08:00
|
|
|
void DwarfDebug::emitAccelTypes() {
|
2014-09-12 05:12:48 +08:00
|
|
|
emitAccel(AccelTypes, Asm->getObjFileLowering().getDwarfAccelTypesSection(),
|
2015-03-11 06:00:25 +08:00
|
|
|
"types");
|
2011-11-07 17:24:32 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 08:35:05 +08:00
|
|
|
// Public name handling.
|
|
|
|
// The format for the various pubnames:
|
|
|
|
//
|
|
|
|
// dwarf pubnames - offset/name pairs where the offset is the offset into the CU
|
|
|
|
// for the DIE that is named.
|
|
|
|
//
|
|
|
|
// gnu pubnames - offset/index value/name tuples where the offset is the offset
|
|
|
|
// into the CU and the index value is computed according to the type of value
|
|
|
|
// for the DIE that is named.
|
|
|
|
//
|
|
|
|
// For type units the offset is the offset of the skeleton DIE. For split dwarf
|
|
|
|
// it's the offset within the debug_info/debug_types dwo section, however, the
|
|
|
|
// reference in the pubname header doesn't change.
|
|
|
|
|
|
|
|
/// computeIndexValue - Compute the gdb index value for the DIE and CU.
|
2013-12-10 07:32:48 +08:00
|
|
|
static dwarf::PubIndexEntryDescriptor computeIndexValue(DwarfUnit *CU,
|
2013-11-21 08:48:22 +08:00
|
|
|
const DIE *Die) {
|
2017-02-03 08:44:18 +08:00
|
|
|
// Entities that ended up only in a Type Unit reference the CU instead (since
|
|
|
|
// the pub entry has offsets within the CU there's no real offset that can be
|
|
|
|
// provided anyway). As it happens all such entities (namespaces and types,
|
|
|
|
// types only in C++ at that) are rendered as TYPE+EXTERNAL. If this turns out
|
|
|
|
// not to be true it would be necessary to persist this information from the
|
|
|
|
// point at which the entry is added to the index data structure - since by
|
|
|
|
// the time the index is built from that, the original type/namespace DIE in a
|
|
|
|
// type unit has already been destroyed so it can't be queried for properties
|
|
|
|
// like tag, etc.
|
|
|
|
if (Die->getTag() == dwarf::DW_TAG_compile_unit)
|
|
|
|
return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_TYPE,
|
|
|
|
dwarf::GIEL_EXTERNAL);
|
2013-10-16 09:37:49 +08:00
|
|
|
dwarf::GDBIndexEntryLinkage Linkage = dwarf::GIEL_STATIC;
|
|
|
|
|
|
|
|
// We could have a specification DIE that has our most of our knowledge,
|
|
|
|
// look for that now.
|
Reapply "AsmPrinter: Change DIEValue to be stored by value"
This reverts commit r238350, effectively reapplying r238349 after fixing
(all?) the problems, all somehow related to how I was using
`AlignedArrayCharUnion<>` inside `DIEValue`:
- MSVC can only handle `sizeof()` on types, not values. Change the
assert.
- GCC doesn't know the `is_trivially_copyable` type trait. Instead of
asserting it, add destructors.
- Call placement new even when constructing POD (i.e., the pointers).
- Instead of copying the char buffer, copy the casted classes.
I've left in a couple of `static_assert`s that I think both MSVC and GCC
know how to handle. If the bots disagree with me, I'll remove them.
- Check that the constructed type is either standard layout or a
pointer. This protects against a programming error: we really want
the "small" `DIEValue`s to be small and simple, so don't
accidentally change them not to be.
- Similarly, check that the size of the buffer is no bigger than a
`uint64_t` or a pointer. (I thought checking against
`sizeof(uint64_t)` would be good enough, but Chandler suggested that
pointers might sometimes be bigger than that in the context of
sanitizers.)
I've also committed r238359 in the meantime, which introduces a
DIEValue.def to simplify dispatching between the various types (thanks
to a review comment by David Blaikie). Without that, this commit would
be almost unintelligible.
Here's the original commit message:
--
Change `DIEValue` to be stored/passed/etc. by value, instead of
reference. It's now a discriminated union, with a `Val` field storing
the actual type. The classes that used to inherit from `DIEValue` no
longer do. There are two categories of these:
- Small values fit in a single pointer and are stored by value.
- Large values require auxiliary storage, and are stored by reference.
The only non-mechanical change is to tools/dsymutil/DwarfLinker.cpp. It
was relying on `DIEInteger`s being passed around by reference, so I
replaced that assumption with a `PatchLocation` type that stores a safe
reference to where the `DIEInteger` lives instead.
This commit causes a temporary regression in memory usage, since I've
left merging `DIEAbbrevData` into `DIEValue` for a follow-up commit. I
measured an increase from 845 MB to 879 MB, around 3.9%. The follow-up
drops it lower than the starting point, and I've only recently brought
the memory this low anyway, so I'm committing these changes separately
to keep them incremental. (I also considered swapping the commits, but
the other one first would cause a lot more code churn.)
(I'm looking at `llc` memory usage on `verify-uselistorder.lto.opt.bc`;
see r236629 for details.)
--
llvm-svn: 238362
2015-05-28 06:14:58 +08:00
|
|
|
if (DIEValue SpecVal = Die->findAttribute(dwarf::DW_AT_specification)) {
|
|
|
|
DIE &SpecDIE = SpecVal.getDIEEntry().getEntry();
|
2014-04-26 03:33:43 +08:00
|
|
|
if (SpecDIE.findAttribute(dwarf::DW_AT_external))
|
2013-10-16 09:37:49 +08:00
|
|
|
Linkage = dwarf::GIEL_EXTERNAL;
|
|
|
|
} else if (Die->findAttribute(dwarf::DW_AT_external))
|
|
|
|
Linkage = dwarf::GIEL_EXTERNAL;
|
2013-09-13 08:35:05 +08:00
|
|
|
|
|
|
|
switch (Die->getTag()) {
|
|
|
|
case dwarf::DW_TAG_class_type:
|
|
|
|
case dwarf::DW_TAG_structure_type:
|
|
|
|
case dwarf::DW_TAG_union_type:
|
|
|
|
case dwarf::DW_TAG_enumeration_type:
|
2013-09-24 04:55:35 +08:00
|
|
|
return dwarf::PubIndexEntryDescriptor(
|
|
|
|
dwarf::GIEK_TYPE, CU->getLanguage() != dwarf::DW_LANG_C_plus_plus
|
|
|
|
? dwarf::GIEL_STATIC
|
|
|
|
: dwarf::GIEL_EXTERNAL);
|
2013-09-13 08:35:05 +08:00
|
|
|
case dwarf::DW_TAG_typedef:
|
|
|
|
case dwarf::DW_TAG_base_type:
|
|
|
|
case dwarf::DW_TAG_subrange_type:
|
2013-09-20 04:40:26 +08:00
|
|
|
return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_TYPE, dwarf::GIEL_STATIC);
|
2013-09-13 08:35:05 +08:00
|
|
|
case dwarf::DW_TAG_namespace:
|
2013-09-20 04:40:26 +08:00
|
|
|
return dwarf::GIEK_TYPE;
|
2013-09-13 08:35:05 +08:00
|
|
|
case dwarf::DW_TAG_subprogram:
|
2013-09-24 06:59:14 +08:00
|
|
|
return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_FUNCTION, Linkage);
|
2013-09-13 08:35:05 +08:00
|
|
|
case dwarf::DW_TAG_variable:
|
2013-09-24 06:59:14 +08:00
|
|
|
return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_VARIABLE, Linkage);
|
2013-09-13 08:35:05 +08:00
|
|
|
case dwarf::DW_TAG_enumerator:
|
2013-09-20 04:40:26 +08:00
|
|
|
return dwarf::PubIndexEntryDescriptor(dwarf::GIEK_VARIABLE,
|
|
|
|
dwarf::GIEL_STATIC);
|
2013-09-13 08:35:05 +08:00
|
|
|
default:
|
2013-09-20 04:40:26 +08:00
|
|
|
return dwarf::GIEK_NONE;
|
2013-09-13 08:35:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-13 05:50:41 +08:00
|
|
|
/// emitDebugPubSections - Emit visible names and types into debug pubnames and
|
|
|
|
/// pubtypes sections.
|
|
|
|
void DwarfDebug::emitDebugPubSections() {
|
2014-03-06 09:42:00 +08:00
|
|
|
for (const auto &NU : CUMap) {
|
|
|
|
DwarfCompileUnit *TheU = NU.second;
|
2017-09-13 05:50:41 +08:00
|
|
|
if (!TheU->hasDwarfPubSections())
|
2014-03-12 07:35:06 +08:00
|
|
|
continue;
|
|
|
|
|
2018-08-17 05:29:55 +08:00
|
|
|
bool GnuStyle = TheU->getCUNode()->getNameTableKind() ==
|
|
|
|
DICompileUnit::DebugNameTableKind::GNU;
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2017-09-13 05:50:41 +08:00
|
|
|
Asm->OutStreamer->SwitchSection(
|
|
|
|
GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubNamesSection()
|
|
|
|
: Asm->getObjFileLowering().getDwarfPubNamesSection());
|
|
|
|
emitDebugPubSection(GnuStyle, "Names", TheU, TheU->getGlobalNames());
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2017-09-13 05:50:41 +08:00
|
|
|
Asm->OutStreamer->SwitchSection(
|
|
|
|
GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubTypesSection()
|
|
|
|
: Asm->getObjFileLowering().getDwarfPubTypesSection());
|
|
|
|
emitDebugPubSection(GnuStyle, "Types", TheU, TheU->getGlobalTypes());
|
|
|
|
}
|
|
|
|
}
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2018-03-23 21:35:54 +08:00
|
|
|
void DwarfDebug::emitSectionReference(const DwarfCompileUnit &CU) {
|
|
|
|
if (useSectionsAsReferences())
|
|
|
|
Asm->EmitDwarfOffset(CU.getSection()->getBeginSymbol(),
|
|
|
|
CU.getDebugSectionOffset());
|
|
|
|
else
|
|
|
|
Asm->emitDwarfSymbolReference(CU.getLabelBegin());
|
|
|
|
}
|
|
|
|
|
2017-09-13 05:50:41 +08:00
|
|
|
void DwarfDebug::emitDebugPubSection(bool GnuStyle, StringRef Name,
|
|
|
|
DwarfCompileUnit *TheU,
|
|
|
|
const StringMap<const DIE *> &Globals) {
|
|
|
|
if (auto *Skeleton = TheU->getSkeleton())
|
|
|
|
TheU = Skeleton;
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2017-09-13 05:50:41 +08:00
|
|
|
// Emit the header.
|
|
|
|
Asm->OutStreamer->AddComment("Length of Public " + Name + " Info");
|
|
|
|
MCSymbol *BeginLabel = Asm->createTempSymbol("pub" + Name + "_begin");
|
|
|
|
MCSymbol *EndLabel = Asm->createTempSymbol("pub" + Name + "_end");
|
|
|
|
Asm->EmitLabelDifference(EndLabel, BeginLabel, 4);
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2017-09-13 05:50:41 +08:00
|
|
|
Asm->OutStreamer->EmitLabel(BeginLabel);
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2017-09-13 05:50:41 +08:00
|
|
|
Asm->OutStreamer->AddComment("DWARF Version");
|
2018-03-30 07:32:54 +08:00
|
|
|
Asm->emitInt16(dwarf::DW_PUBNAMES_VERSION);
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2017-09-13 05:50:41 +08:00
|
|
|
Asm->OutStreamer->AddComment("Offset of Compilation Unit Info");
|
2018-03-23 21:35:54 +08:00
|
|
|
emitSectionReference(*TheU);
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2017-09-13 05:50:41 +08:00
|
|
|
Asm->OutStreamer->AddComment("Compilation Unit Length");
|
2018-03-30 07:32:54 +08:00
|
|
|
Asm->emitInt32(TheU->getLength());
|
2013-02-13 02:00:14 +08:00
|
|
|
|
2017-09-13 05:50:41 +08:00
|
|
|
// Emit the pubnames for this compilation unit.
|
|
|
|
for (const auto &GI : Globals) {
|
|
|
|
const char *Name = GI.getKeyData();
|
|
|
|
const DIE *Entity = GI.second;
|
2013-09-13 08:35:05 +08:00
|
|
|
|
2017-09-13 05:50:41 +08:00
|
|
|
Asm->OutStreamer->AddComment("DIE offset");
|
2018-03-30 07:32:54 +08:00
|
|
|
Asm->emitInt32(Entity->getOffset());
|
2017-09-13 05:50:41 +08:00
|
|
|
|
|
|
|
if (GnuStyle) {
|
|
|
|
dwarf::PubIndexEntryDescriptor Desc = computeIndexValue(TheU, Entity);
|
|
|
|
Asm->OutStreamer->AddComment(
|
2018-11-14 04:18:08 +08:00
|
|
|
Twine("Attributes: ") + dwarf::GDBIndexEntryKindString(Desc.Kind) +
|
|
|
|
", " + dwarf::GDBIndexEntryLinkageString(Desc.Linkage));
|
2018-03-30 07:32:54 +08:00
|
|
|
Asm->emitInt8(Desc.toBits());
|
2013-02-13 02:00:14 +08:00
|
|
|
}
|
|
|
|
|
2017-09-13 05:50:41 +08:00
|
|
|
Asm->OutStreamer->AddComment("External Name");
|
|
|
|
Asm->OutStreamer->EmitBytes(StringRef(Name, GI.getKeyLength() + 1));
|
2013-02-13 02:00:14 +08:00
|
|
|
}
|
2013-09-13 08:34:58 +08:00
|
|
|
|
2017-09-13 05:50:41 +08:00
|
|
|
Asm->OutStreamer->AddComment("End Mark");
|
2018-03-30 07:32:54 +08:00
|
|
|
Asm->emitInt32(0);
|
2017-09-13 05:50:41 +08:00
|
|
|
Asm->OutStreamer->EmitLabel(EndLabel);
|
2009-11-24 09:14:22 +08:00
|
|
|
}
|
|
|
|
|
2016-01-24 16:18:55 +08:00
|
|
|
/// Emit null-terminated strings into a debug str section.
|
2012-12-27 10:14:01 +08:00
|
|
|
void DwarfDebug::emitDebugStr() {
|
2018-01-27 02:52:58 +08:00
|
|
|
MCSection *StringOffsetsSection = nullptr;
|
|
|
|
if (useSegmentedStringOffsetsTable()) {
|
|
|
|
emitStringOffsetsTableHeader();
|
|
|
|
StringOffsetsSection = Asm->getObjFileLowering().getDwarfStrOffSection();
|
|
|
|
}
|
2013-12-06 02:06:10 +08:00
|
|
|
DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
|
2018-01-27 02:52:58 +08:00
|
|
|
Holder.emitStrings(Asm->getObjFileLowering().getDwarfStrSection(),
|
|
|
|
StringOffsetsSection, /* UseRelativeOffsets = */ true);
|
2012-12-27 10:14:01 +08:00
|
|
|
}
|
|
|
|
|
2019-03-19 21:16:28 +08:00
|
|
|
void DwarfDebug::emitDebugLocEntry(ByteStreamer &Streamer, const
|
|
|
|
DebugLocStream::Entry &Entry,
|
|
|
|
const DwarfCompileUnit *CU) {
|
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
|
|
|
auto &&Comments = DebugLocs.getComments(Entry);
|
|
|
|
auto Comment = Comments.begin();
|
|
|
|
auto End = Comments.end();
|
2019-03-19 21:16:28 +08:00
|
|
|
|
|
|
|
// The expressions are inserted into a byte stream rather early (see
|
|
|
|
// DwarfExpression::addExpression) so for those ops (e.g. DW_OP_convert) that
|
|
|
|
// need to reference a base_type DIE the offset of that DIE is not yet known.
|
|
|
|
// To deal with this we instead insert a placeholder early and then extract
|
|
|
|
// it here and replace it with the real reference.
|
|
|
|
unsigned PtrSize = Asm->MAI->getCodePointerSize();
|
|
|
|
DWARFDataExtractor Data(StringRef(DebugLocs.getBytes(Entry).data(),
|
|
|
|
DebugLocs.getBytes(Entry).size()),
|
|
|
|
Asm->getDataLayout().isLittleEndian(), PtrSize);
|
|
|
|
DWARFExpression Expr(Data, getDwarfVersion(), PtrSize);
|
|
|
|
|
|
|
|
using Encoding = DWARFExpression::Operation::Encoding;
|
|
|
|
uint32_t Offset = 0;
|
|
|
|
for (auto &Op : Expr) {
|
|
|
|
assert(Op.getCode() != dwarf::DW_OP_const_type &&
|
|
|
|
"3 operand ops not yet supported");
|
|
|
|
Streamer.EmitInt8(Op.getCode(), Comment != End ? *(Comment++) : "");
|
|
|
|
Offset++;
|
|
|
|
for (unsigned I = 0; I < 2; ++I) {
|
|
|
|
if (Op.getDescription().Op[I] == Encoding::SizeNA)
|
|
|
|
continue;
|
|
|
|
if (Op.getDescription().Op[I] == Encoding::BaseTypeRef) {
|
|
|
|
if (CU) {
|
|
|
|
uint64_t Offset = CU->ExprRefedBaseTypes[Op.getRawOperand(I)].Die->getOffset();
|
|
|
|
assert(Offset < (1ULL << (ULEB128PadSize * 7)) && "Offset wont fit");
|
|
|
|
Asm->EmitULEB128(Offset, nullptr, ULEB128PadSize);
|
|
|
|
} else {
|
|
|
|
// Emit a reference to the 'generic type'.
|
|
|
|
Asm->EmitULEB128(0, nullptr, ULEB128PadSize);
|
|
|
|
}
|
|
|
|
// Make sure comments stay aligned.
|
|
|
|
for (unsigned J = 0; J < ULEB128PadSize; ++J)
|
|
|
|
if (Comment != End)
|
|
|
|
Comment++;
|
|
|
|
} else {
|
|
|
|
for (uint32_t J = Offset; J < Op.getOperandEndOffset(I); ++J)
|
|
|
|
Streamer.EmitInt8(Data.getData()[J], Comment != End ? *(Comment++) : "");
|
|
|
|
}
|
|
|
|
Offset = Op.getOperandEndOffset(I);
|
|
|
|
}
|
|
|
|
assert(Offset == Op.getEndOffset());
|
|
|
|
}
|
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
|
|
|
const DebugLocEntry::Value &Value,
|
2016-12-10 04:43:40 +08:00
|
|
|
DwarfExpression &DwarfExpr) {
|
2017-03-21 05:35:09 +08:00
|
|
|
auto *DIExpr = Value.getExpression();
|
|
|
|
DIExpressionCursor ExprCursor(DIExpr);
|
|
|
|
DwarfExpr.addFragmentOffset(DIExpr);
|
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))
|
2017-03-17 01:42:45 +08:00
|
|
|
DwarfExpr.addSignedConstant(Value.getInt());
|
2015-01-13 08:04:06 +08:00
|
|
|
else
|
2017-03-17 01:42:45 +08:00
|
|
|
DwarfExpr.addUnsignedConstant(Value.getInt());
|
2014-04-28 02:25:40 +08:00
|
|
|
} else if (Value.isLocation()) {
|
2017-03-21 05:35:09 +08:00
|
|
|
MachineLocation Location = Value.getLoc();
|
2017-04-20 07:42:25 +08:00
|
|
|
if (Location.isIndirect())
|
|
|
|
DwarfExpr.setMemoryLocationKind();
|
2017-08-02 23:22:17 +08:00
|
|
|
DIExpressionCursor Cursor(DIExpr);
|
2016-12-10 04:43:40 +08:00
|
|
|
const TargetRegisterInfo &TRI = *AP.MF->getSubtarget().getRegisterInfo();
|
2017-04-20 07:42:25 +08:00
|
|
|
if (!DwarfExpr.addMachineRegExpression(TRI, Cursor, Location.getReg()))
|
2017-03-21 05:35:09 +08:00
|
|
|
return;
|
|
|
|
return DwarfExpr.addExpression(std::move(Cursor));
|
2016-04-08 08:38:37 +08:00
|
|
|
} else if (Value.isConstantFP()) {
|
|
|
|
APInt RawBytes = Value.getConstantFP()->getValueAPF().bitcastToAPInt();
|
2017-03-17 01:42:45 +08:00
|
|
|
DwarfExpr.addUnsignedConstant(RawBytes);
|
2014-03-08 06:40:37 +08:00
|
|
|
}
|
2017-03-17 01:42:45 +08:00
|
|
|
DwarfExpr.addExpression(std::move(ExprCursor));
|
2014-03-08 06:40:37 +08:00
|
|
|
}
|
|
|
|
|
2015-06-22 00:54:56 +08:00
|
|
|
void DebugLocEntry::finalize(const AsmPrinter &AP,
|
|
|
|
DebugLocStream::ListBuilder &List,
|
2019-03-19 21:16:28 +08:00
|
|
|
const DIBasicType *BT,
|
|
|
|
DwarfCompileUnit &TheCU) {
|
[DebugInfo] Omit location list entries with empty ranges
Summary:
This fixes PR39710. In that case we emitted a location list looking like
this:
.Ldebug_loc0:
.quad .Lfunc_begin0-.Lfunc_begin0
.quad .Lfunc_begin0-.Lfunc_begin0
.short 1 # Loc expr size
.byte 85 # DW_OP_reg5
.quad .Lfunc_begin0-.Lfunc_begin0
.quad .Lfunc_end0-.Lfunc_begin0
.short 1 # Loc expr size
.byte 85 # super-register DW_OP_reg5
.quad 0
.quad 0
As seen, the first entry's beginning and ending addresses evalute to 0,
which meant that the entry inadvertently became an "end of list" entry,
resulting in the location list ending sooner than expected.
To fix this, omit all entries with empty ranges. Location list entries
with empty ranges do not have any effect, as specified by DWARF, so we
might as well drop them:
"A location list entry (but not a base address selection or end of list
entry) whose beginning and ending addresses are equal has no effect
because the size of the range covered by such an entry is zero."
Reviewers: davide, aprantl, dblaikie
Reviewed By: aprantl
Subscribers: javed.absar, JDevlieghere, llvm-commits
Tags: #debug-info
Differential Revision: https://reviews.llvm.org/D55919
llvm-svn: 350698
2019-01-09 17:58:59 +08:00
|
|
|
assert(Begin != End && "unexpected location list entry with empty range");
|
2015-06-22 00:54:56 +08:00
|
|
|
DebugLocStream::EntryBuilder Entry(List, Begin, End);
|
|
|
|
BufferByteStreamer Streamer = Entry.getStreamer();
|
2019-03-19 21:16:28 +08:00
|
|
|
DebugLocDwarfExpression DwarfExpr(AP.getDwarfVersion(), Streamer, TheCU);
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
const DebugLocEntry::Value &Value = Values[0];
|
2016-12-06 02:04:47 +08:00
|
|
|
if (Value.isFragment()) {
|
|
|
|
// Emit all fragments that belong to the same variable and range.
|
2017-08-18 05:26:39 +08:00
|
|
|
assert(llvm::all_of(Values, [](DebugLocEntry::Value P) {
|
2016-12-06 02:04:47 +08:00
|
|
|
return P.isFragment();
|
|
|
|
}) && "all values are expected to be fragments");
|
2015-03-03 06:02:33 +08:00
|
|
|
assert(std::is_sorted(Values.begin(), Values.end()) &&
|
2016-12-06 02:04:47 +08:00
|
|
|
"fragments are expected to be sorted");
|
2015-04-14 02:53:11 +08:00
|
|
|
|
2016-12-10 04:43:40 +08:00
|
|
|
for (auto Fragment : Values)
|
2018-06-28 12:50:40 +08:00
|
|
|
emitDebugLocValue(AP, BT, Fragment, DwarfExpr);
|
2016-12-10 04:43:40 +08:00
|
|
|
|
2015-03-03 06:02:33 +08:00
|
|
|
} else {
|
2016-12-06 02:04:47 +08:00
|
|
|
assert(Values.size() == 1 && "only fragments may have >1 value");
|
2018-06-28 12:50:40 +08:00
|
|
|
emitDebugLocValue(AP, BT, Value, DwarfExpr);
|
2015-03-03 06:02:33 +08:00
|
|
|
}
|
2016-12-10 04:43:40 +08:00
|
|
|
DwarfExpr.finalize();
|
2015-03-03 06:02:33 +08:00
|
|
|
}
|
|
|
|
|
2019-03-19 21:16:28 +08:00
|
|
|
void DwarfDebug::emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry,
|
|
|
|
const DwarfCompileUnit *CU) {
|
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");
|
2019-02-02 01:11:58 +08:00
|
|
|
if (getDwarfVersion() >= 5)
|
|
|
|
Asm->EmitULEB128(DebugLocs.getBytes(Entry).size());
|
2019-03-20 04:37:06 +08:00
|
|
|
else if (DebugLocs.getBytes(Entry).size() <= std::numeric_limits<uint16_t>::max())
|
2019-02-02 01:11:58 +08:00
|
|
|
Asm->emitInt16(DebugLocs.getBytes(Entry).size());
|
2019-03-20 04:37:06 +08:00
|
|
|
else {
|
|
|
|
// The entry is too big to fit into 16 bit, drop it as there is nothing we
|
|
|
|
// can do.
|
|
|
|
Asm->emitInt16(0);
|
|
|
|
return;
|
|
|
|
}
|
2014-04-02 00:17:41 +08:00
|
|
|
// Emit the entry.
|
|
|
|
APByteStreamer Streamer(*Asm);
|
2019-03-19 21:16:28 +08:00
|
|
|
emitDebugLocEntry(Streamer, Entry, CU);
|
2014-04-02 00:17:41 +08:00
|
|
|
}
|
|
|
|
|
2018-10-26 19:25:12 +08:00
|
|
|
// Emit the common part of the DWARF 5 range/locations list tables header.
|
|
|
|
static void emitListsTableHeaderStart(AsmPrinter *Asm, const DwarfFile &Holder,
|
|
|
|
MCSymbol *TableStart,
|
|
|
|
MCSymbol *TableEnd) {
|
|
|
|
// Build the table header, which starts with the length field.
|
|
|
|
Asm->OutStreamer->AddComment("Length");
|
|
|
|
Asm->EmitLabelDifference(TableEnd, TableStart, 4);
|
|
|
|
Asm->OutStreamer->EmitLabel(TableStart);
|
|
|
|
// Version number (DWARF v5 and later).
|
|
|
|
Asm->OutStreamer->AddComment("Version");
|
|
|
|
Asm->emitInt16(Asm->OutStreamer->getContext().getDwarfVersion());
|
|
|
|
// Address size.
|
|
|
|
Asm->OutStreamer->AddComment("Address size");
|
|
|
|
Asm->emitInt8(Asm->MAI->getCodePointerSize());
|
|
|
|
// Segment selector size.
|
|
|
|
Asm->OutStreamer->AddComment("Segment selector size");
|
|
|
|
Asm->emitInt8(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the header of a DWARF 5 range list table list table. Returns the symbol
|
|
|
|
// that designates the end of the table for the caller to emit when the table is
|
|
|
|
// complete.
|
|
|
|
static MCSymbol *emitRnglistsTableHeader(AsmPrinter *Asm,
|
|
|
|
const DwarfFile &Holder) {
|
|
|
|
MCSymbol *TableStart = Asm->createTempSymbol("debug_rnglist_table_start");
|
|
|
|
MCSymbol *TableEnd = Asm->createTempSymbol("debug_rnglist_table_end");
|
|
|
|
emitListsTableHeaderStart(Asm, Holder, TableStart, TableEnd);
|
|
|
|
|
|
|
|
Asm->OutStreamer->AddComment("Offset entry count");
|
|
|
|
Asm->emitInt32(Holder.getRangeLists().size());
|
|
|
|
Asm->OutStreamer->EmitLabel(Holder.getRnglistsTableBaseSym());
|
|
|
|
|
|
|
|
for (const RangeSpanList &List : Holder.getRangeLists())
|
|
|
|
Asm->EmitLabelDifference(List.getSym(), Holder.getRnglistsTableBaseSym(),
|
|
|
|
4);
|
|
|
|
|
|
|
|
return TableEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the header of a DWARF 5 locations list table. Returns the symbol that
|
|
|
|
// designates the end of the table for the caller to emit when the table is
|
|
|
|
// complete.
|
|
|
|
static MCSymbol *emitLoclistsTableHeader(AsmPrinter *Asm,
|
|
|
|
const DwarfFile &Holder) {
|
|
|
|
MCSymbol *TableStart = Asm->createTempSymbol("debug_loclist_table_start");
|
|
|
|
MCSymbol *TableEnd = Asm->createTempSymbol("debug_loclist_table_end");
|
|
|
|
emitListsTableHeaderStart(Asm, Holder, TableStart, TableEnd);
|
|
|
|
|
|
|
|
// FIXME: Generate the offsets table and use DW_FORM_loclistx with the
|
|
|
|
// DW_AT_loclists_base attribute. Until then set the number of offsets to 0.
|
|
|
|
Asm->OutStreamer->AddComment("Offset entry count");
|
|
|
|
Asm->emitInt32(0);
|
|
|
|
Asm->OutStreamer->EmitLabel(Holder.getLoclistsTableBaseSym());
|
|
|
|
|
|
|
|
return TableEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit locations into the .debug_loc/.debug_rnglists section.
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::emitDebugLoc() {
|
2017-05-27 02:52:56 +08:00
|
|
|
if (DebugLocs.getLists().empty())
|
|
|
|
return;
|
|
|
|
|
2018-10-26 19:25:12 +08:00
|
|
|
bool IsLocLists = getDwarfVersion() >= 5;
|
|
|
|
MCSymbol *TableEnd = nullptr;
|
|
|
|
if (IsLocLists) {
|
|
|
|
Asm->OutStreamer->SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfLoclistsSection());
|
|
|
|
TableEnd = emitLoclistsTableHeader(Asm, useSplitDwarf() ? SkeletonHolder
|
|
|
|
: InfoHolder);
|
|
|
|
} else {
|
|
|
|
Asm->OutStreamer->SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfLocSection());
|
|
|
|
}
|
|
|
|
|
2017-04-18 01:41:25 +08:00
|
|
|
unsigned char Size = Asm->MAI->getCodePointerSize();
|
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);
|
2018-10-26 19:25:12 +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
|
|
|
const DwarfCompileUnit *CU = List.CU;
|
2018-10-26 19:25:12 +08:00
|
|
|
const MCSymbol *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
|
|
|
for (const auto &Entry : DebugLocs.getEntries(List)) {
|
2018-10-26 19:25:12 +08:00
|
|
|
if (Base) {
|
|
|
|
// 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.
|
|
|
|
if (IsLocLists) {
|
|
|
|
Asm->OutStreamer->AddComment("DW_LLE_offset_pair");
|
|
|
|
Asm->OutStreamer->EmitIntValue(dwarf::DW_LLE_offset_pair, 1);
|
|
|
|
Asm->OutStreamer->AddComment(" starting offset");
|
|
|
|
Asm->EmitLabelDifferenceAsULEB128(Entry.BeginSym, Base);
|
|
|
|
Asm->OutStreamer->AddComment(" ending offset");
|
|
|
|
Asm->EmitLabelDifferenceAsULEB128(Entry.EndSym, Base);
|
|
|
|
} else {
|
|
|
|
Asm->EmitLabelDifference(Entry.BeginSym, Base, Size);
|
|
|
|
Asm->EmitLabelDifference(Entry.EndSym, Base, Size);
|
|
|
|
}
|
|
|
|
|
2019-03-19 21:16:28 +08:00
|
|
|
emitDebugLocEntryLocation(Entry, CU);
|
2018-10-26 19:25:12 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have no base address.
|
|
|
|
if (IsLocLists) {
|
|
|
|
// TODO: Use DW_LLE_base_addressx + DW_LLE_offset_pair, or
|
|
|
|
// DW_LLE_startx_length in case if there is only a single range.
|
|
|
|
// That should reduce the size of the debug data emited.
|
|
|
|
// For now just use the DW_LLE_startx_length for all cases.
|
|
|
|
Asm->OutStreamer->AddComment("DW_LLE_startx_length");
|
|
|
|
Asm->emitInt8(dwarf::DW_LLE_startx_length);
|
|
|
|
Asm->OutStreamer->AddComment(" start idx");
|
|
|
|
Asm->EmitULEB128(AddrPool.getIndex(Entry.BeginSym));
|
|
|
|
Asm->OutStreamer->AddComment(" length");
|
|
|
|
Asm->EmitLabelDifferenceAsULEB128(Entry.EndSym, Entry.BeginSym);
|
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
|
|
|
|
2019-03-19 21:16:28 +08:00
|
|
|
emitDebugLocEntryLocation(Entry, CU);
|
2010-05-26 07:40:22 +08:00
|
|
|
}
|
2018-10-26 19:25:12 +08:00
|
|
|
|
|
|
|
if (IsLocLists) {
|
|
|
|
// .debug_loclists section ends with DW_LLE_end_of_list.
|
|
|
|
Asm->OutStreamer->AddComment("DW_LLE_end_of_list");
|
|
|
|
Asm->OutStreamer->EmitIntValue(dwarf::DW_LLE_end_of_list, 1);
|
|
|
|
} else {
|
|
|
|
// Terminate the .debug_loc list with two 0 values.
|
|
|
|
Asm->OutStreamer->EmitIntValue(0, Size);
|
|
|
|
Asm->OutStreamer->EmitIntValue(0, Size);
|
|
|
|
}
|
2014-04-02 09:50:20 +08:00
|
|
|
}
|
2018-10-26 19:25:12 +08:00
|
|
|
|
|
|
|
if (TableEnd)
|
|
|
|
Asm->OutStreamer->EmitLabel(TableEnd);
|
2014-04-02 09:50:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DwarfDebug::emitDebugLocDWO() {
|
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()) {
|
2019-02-12 08:00:38 +08:00
|
|
|
Asm->OutStreamer->SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfLocDWOSection());
|
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)) {
|
2018-10-26 06:26:25 +08:00
|
|
|
// GDB only supports startx_length in pre-standard split-DWARF.
|
|
|
|
// (in v5 standard loclists, it currently* /only/ supports base_address +
|
|
|
|
// offset_pair, so the implementations can't really share much since they
|
|
|
|
// need to use different representations)
|
|
|
|
// * as of October 2018, at least
|
|
|
|
// Ideally/in v5, this could use SectionLabels to reuse existing addresses
|
|
|
|
// in the address pool to minimize object size/relocations.
|
2018-03-30 07:32:54 +08:00
|
|
|
Asm->emitInt8(dwarf::DW_LLE_startx_length);
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
unsigned idx = AddrPool.getIndex(Entry.BeginSym);
|
2014-04-02 09:50:20 +08:00
|
|
|
Asm->EmitULEB128(idx);
|
AsmPrinter: Create a unified .debug_loc stream
This commit removes `DebugLocList` and replaces it with
`DebugLocStream`.
- `DebugLocEntry` no longer contains its byte/comment streams.
- The `DebugLocEntry` list for a variable/inlined-at pair is allocated
on the stack, and released right after `DebugLocEntry::finalize()`
(possible because of the refactoring in r231023). Now, only one
list is in memory at a time now.
- There's a single unified stream for the `.debug_loc` section that
persists, stored in the new `DebugLocStream` data structure.
The last point is important: this collapses the nested `SmallVector<>`s
from `DebugLocList` into unified streams. We previously had something
like the following:
vec<tuple<Label, CU,
vec<tuple<BeginSym, EndSym,
vec<Value>,
vec<char>,
vec<string>>>>>
A `SmallVector` can avoid allocations, but is statically fairly large
for a vector: three pointers plus the size of the small storage, which
is the number of elements in small mode times the element size).
Nesting these is expensive, since an inner vector's size contributes to
the element size of an outer one. (Nesting any vector is expensive...)
In the old data structure, the outer vector's *element* size was 632B,
excluding allocation costs for when the middle and inner vectors
exceeded their small sizes. 312B of this was for the "three" pointers
in the vector-tree beneath it. If you assume 1M functions with an
average of 10 variable/inlined-at pairs each (in an LTO scenario),
that's almost 6GB (besides inner allocations), with almost 3GB for the
"three" pointers.
This came up in a heap profile a little while ago of a `clang -flto -g`
bootstrap, with `DwarfDebug::collectVariableInfo()` using something like
10-15% of the total memory.
With this commit, we have:
tuple<vec<tuple<Label, CU, Offset>>,
vec<tuple<BeginSym, EndSym, Offset, Offset>>,
vec<char>,
vec<string>>
The offsets are used to create `ArrayRef` slices of adjacent
`SmallVector`s. This reduces the number of vectors to four (unrelated
to the number of variable/inlined-at pairs), and caps the number of
allocations at the same number.
Besides saving memory and limiting allocations, this is NFC.
I don't know my way around this code very well yet, but I wonder if we
could go further: why stream to a side-table, instead of directly to the
output stream?
llvm-svn: 235229
2015-04-18 05:34:47 +08:00
|
|
|
Asm->EmitLabelDifference(Entry.EndSym, Entry.BeginSym, 4);
|
2014-04-02 09:50:20 +08:00
|
|
|
|
2019-03-19 21:16:28 +08:00
|
|
|
emitDebugLocEntryLocation(Entry, List.CU);
|
2014-03-25 09:44:02 +08:00
|
|
|
}
|
2018-03-30 07:32:54 +08:00
|
|
|
Asm->emitInt8(dwarf::DW_LLE_end_of_list);
|
2010-05-26 07:40:22 +08:00
|
|
|
}
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
2009-05-15 17:23:25 +08:00
|
|
|
|
2013-09-20 07:21:01 +08:00
|
|
|
struct ArangeSpan {
|
|
|
|
const MCSymbol *Start, *End;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Emit a debug aranges section, containing a CU lookup for any
|
|
|
|
// address we can tie back to a CU.
|
2012-11-21 08:34:35 +08:00
|
|
|
void DwarfDebug::emitDebugARanges() {
|
2015-02-27 06:02:02 +08:00
|
|
|
// Provides a unique id per text section.
|
2015-05-22 03:20:38 +08:00
|
|
|
MapVector<MCSection *, SmallVector<SymbolCU, 8>> SectionMap;
|
2013-09-20 07:21:01 +08:00
|
|
|
|
2015-02-27 06:02:02 +08:00
|
|
|
// Filter labels by section.
|
|
|
|
for (const SymbolCU &SCU : ArangeLabels) {
|
|
|
|
if (SCU.Sym->isInSection()) {
|
|
|
|
// Make a note of this symbol and it's section.
|
2015-05-22 03:20:38 +08:00
|
|
|
MCSection *Section = &SCU.Sym->getSection();
|
2015-02-27 06:02:02 +08:00
|
|
|
if (!Section->getKind().isMetadata())
|
|
|
|
SectionMap[Section].push_back(SCU);
|
|
|
|
} else {
|
|
|
|
// Some symbols (e.g. common/bss on mach-o) can have no section but still
|
|
|
|
// appear in the output. This sucks as we rely on sections to build
|
|
|
|
// arange spans. We can do it without, but it's icky.
|
|
|
|
SectionMap[nullptr].push_back(SCU);
|
|
|
|
}
|
|
|
|
}
|
2013-09-20 07:21:01 +08:00
|
|
|
|
2015-02-27 06:02:02 +08:00
|
|
|
DenseMap<DwarfCompileUnit *, std::vector<ArangeSpan>> Spans;
|
|
|
|
|
2015-03-10 06:08:37 +08:00
|
|
|
for (auto &I : SectionMap) {
|
2016-05-20 08:38:28 +08:00
|
|
|
MCSection *Section = I.first;
|
2015-03-10 06:08:37 +08:00
|
|
|
SmallVector<SymbolCU, 8> &List = I.second;
|
2016-05-20 08:38:28 +08:00
|
|
|
if (List.size() < 1)
|
2013-09-20 07:21:01 +08:00
|
|
|
continue;
|
|
|
|
|
2015-02-03 03:22:51 +08:00
|
|
|
// If we have no section (e.g. common), just write out
|
|
|
|
// individual spans for each symbol.
|
|
|
|
if (!Section) {
|
|
|
|
for (const SymbolCU &Cur : List) {
|
|
|
|
ArangeSpan Span;
|
|
|
|
Span.Start = Cur.Sym;
|
|
|
|
Span.End = nullptr;
|
2016-05-20 08:38:28 +08:00
|
|
|
assert(Cur.CU);
|
|
|
|
Spans[Cur.CU].push_back(Span);
|
2015-02-03 03:22:51 +08:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-09-20 07:21:01 +08:00
|
|
|
// Sort the symbols by offset within the section.
|
2018-02-26 03:52:34 +08:00
|
|
|
std::stable_sort(
|
2016-05-20 07:17:37 +08:00
|
|
|
List.begin(), List.end(), [&](const SymbolCU &A, const SymbolCU &B) {
|
|
|
|
unsigned IA = A.Sym ? Asm->OutStreamer->GetSymbolOrder(A.Sym) : 0;
|
|
|
|
unsigned IB = B.Sym ? Asm->OutStreamer->GetSymbolOrder(B.Sym) : 0;
|
|
|
|
|
|
|
|
// Symbols with no order assigned should be placed at the end.
|
|
|
|
// (e.g. section end labels)
|
|
|
|
if (IA == 0)
|
|
|
|
return false;
|
|
|
|
if (IB == 0)
|
|
|
|
return true;
|
|
|
|
return IA < IB;
|
|
|
|
});
|
2013-09-20 07:21:01 +08:00
|
|
|
|
2016-05-20 08:38:28 +08:00
|
|
|
// Insert a final terminator.
|
|
|
|
List.push_back(SymbolCU(nullptr, Asm->OutStreamer->endSection(Section)));
|
|
|
|
|
2015-02-03 03:22:51 +08:00
|
|
|
// Build spans between each label.
|
|
|
|
const MCSymbol *StartSym = List[0].Sym;
|
|
|
|
for (size_t n = 1, e = List.size(); n < e; n++) {
|
|
|
|
const SymbolCU &Prev = List[n - 1];
|
|
|
|
const SymbolCU &Cur = List[n];
|
|
|
|
|
|
|
|
// Try and build the longest span we can within the same CU.
|
|
|
|
if (Cur.CU != Prev.CU) {
|
2013-09-20 07:21:01 +08:00
|
|
|
ArangeSpan Span;
|
2015-02-03 03:22:51 +08:00
|
|
|
Span.Start = StartSym;
|
|
|
|
Span.End = Cur.Sym;
|
2016-05-20 08:38:28 +08:00
|
|
|
assert(Prev.CU);
|
2015-02-03 03:22:51 +08:00
|
|
|
Spans[Prev.CU].push_back(Span);
|
|
|
|
StartSym = Cur.Sym;
|
2013-09-20 07:21:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-27 06:02:02 +08:00
|
|
|
// Start the dwarf aranges section.
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->SwitchSection(
|
2015-02-27 06:02:02 +08:00
|
|
|
Asm->getObjFileLowering().getDwarfARangesSection());
|
|
|
|
|
2017-04-18 01:41:25 +08:00
|
|
|
unsigned PtrSize = Asm->MAI->getCodePointerSize();
|
2013-09-20 07:21:01 +08:00
|
|
|
|
|
|
|
// 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).
|
llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)
Summary: The convenience wrapper in STLExtras is available since rL342102.
Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb
Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits
Differential Revision: https://reviews.llvm.org/D52573
llvm-svn: 343163
2018-09-27 10:13:45 +08:00
|
|
|
llvm::sort(CUs, [](const DwarfCompileUnit *A, const DwarfCompileUnit *B) {
|
|
|
|
return A->getUniqueID() < B->getUniqueID();
|
|
|
|
});
|
2013-09-20 07:21:01 +08:00
|
|
|
|
|
|
|
// Emit an arange table for each CU we used.
|
2014-03-08 03:09:39 +08:00
|
|
|
for (DwarfCompileUnit *CU : CUs) {
|
2013-09-20 07:21:01 +08:00
|
|
|
std::vector<ArangeSpan> &List = Spans[CU];
|
|
|
|
|
2014-11-02 09:21:43 +08:00
|
|
|
// Describe the skeleton CU's offset and length, not the dwo file's.
|
|
|
|
if (auto *Skel = CU->getSkeleton())
|
|
|
|
CU = Skel;
|
|
|
|
|
2013-09-20 07:21:01 +08:00
|
|
|
// Emit size of content not including length itself.
|
2013-11-19 17:04:36 +08:00
|
|
|
unsigned ContentSize =
|
|
|
|
sizeof(int16_t) + // DWARF ARange version number
|
|
|
|
sizeof(int32_t) + // Offset of CU in the .debug_info section
|
|
|
|
sizeof(int8_t) + // Pointer Size (in bytes)
|
|
|
|
sizeof(int8_t); // Segment Size (in bytes)
|
2013-09-20 07:21:01 +08:00
|
|
|
|
|
|
|
unsigned TupleSize = PtrSize * 2;
|
|
|
|
|
|
|
|
// 7.20 in the Dwarf specs requires the table to be aligned to a tuple.
|
2014-01-08 03:28:14 +08:00
|
|
|
unsigned Padding =
|
|
|
|
OffsetToAlignment(sizeof(int32_t) + ContentSize, TupleSize);
|
2013-09-20 07:21:01 +08:00
|
|
|
|
|
|
|
ContentSize += Padding;
|
|
|
|
ContentSize += (List.size() + 1) * TupleSize;
|
|
|
|
|
|
|
|
// For each compile unit, write the list of spans it covers.
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("Length of ARange Set");
|
2018-03-30 07:32:54 +08:00
|
|
|
Asm->emitInt32(ContentSize);
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("DWARF Arange version number");
|
2018-03-30 07:32:54 +08:00
|
|
|
Asm->emitInt16(dwarf::DW_ARANGES_VERSION);
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("Offset Into Debug Info Section");
|
2018-03-23 21:35:54 +08:00
|
|
|
emitSectionReference(*CU);
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("Address Size (in bytes)");
|
2018-03-30 07:32:54 +08:00
|
|
|
Asm->emitInt8(PtrSize);
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("Segment Size (in bytes)");
|
2018-03-30 07:32:54 +08:00
|
|
|
Asm->emitInt8(0);
|
2013-09-20 07:21:01 +08:00
|
|
|
|
2016-06-01 09:59:58 +08:00
|
|
|
Asm->OutStreamer->emitFill(Padding, 0xff);
|
2013-09-20 07:21:01 +08:00
|
|
|
|
2014-03-08 03:09:39 +08:00
|
|
|
for (const ArangeSpan &Span : List) {
|
2013-09-20 07:21:01 +08:00
|
|
|
Asm->EmitLabelReference(Span.Start, PtrSize);
|
|
|
|
|
|
|
|
// Calculate the size as being from the span start to it's end.
|
2013-09-24 01:56:20 +08:00
|
|
|
if (Span.End) {
|
2013-09-20 07:21:01 +08:00
|
|
|
Asm->EmitLabelDifference(Span.End, Span.Start, PtrSize);
|
2013-09-24 01:56:20 +08:00
|
|
|
} else {
|
|
|
|
// For symbols without an end marker (e.g. common), we
|
|
|
|
// write a single arange entry containing just that one symbol.
|
|
|
|
uint64_t Size = SymSize[Span.Start];
|
|
|
|
if (Size == 0)
|
|
|
|
Size = 1;
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->EmitIntValue(Size, PtrSize);
|
2013-09-24 01:56:20 +08:00
|
|
|
}
|
2013-09-20 07:21:01 +08:00
|
|
|
}
|
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm->OutStreamer->AddComment("ARange terminator");
|
|
|
|
Asm->OutStreamer->EmitIntValue(0, PtrSize);
|
|
|
|
Asm->OutStreamer->EmitIntValue(0, PtrSize);
|
2013-09-20 07:21:01 +08:00
|
|
|
}
|
2009-05-21 07:04:56 +08:00
|
|
|
}
|
|
|
|
|
2018-07-13 02:18:21 +08:00
|
|
|
/// Emit a single range list. We handle both DWARF v5 and earlier.
|
2018-10-20 15:36:39 +08:00
|
|
|
static void emitRangeList(DwarfDebug &DD, AsmPrinter *Asm,
|
2018-07-10 08:10:11 +08:00
|
|
|
const RangeSpanList &List) {
|
2018-07-13 02:18:21 +08:00
|
|
|
|
2018-10-20 15:36:39 +08:00
|
|
|
auto DwarfVersion = DD.getDwarfVersion();
|
2018-07-10 08:10:11 +08:00
|
|
|
// Emit our symbol so we can find the beginning of the range.
|
|
|
|
Asm->OutStreamer->EmitLabel(List.getSym());
|
|
|
|
// Gather all the ranges that apply to the same section so they can share
|
|
|
|
// a base address entry.
|
|
|
|
MapVector<const MCSection *, std::vector<const RangeSpan *>> SectionRanges;
|
|
|
|
// Size for our labels.
|
|
|
|
auto Size = Asm->MAI->getCodePointerSize();
|
|
|
|
|
|
|
|
for (const RangeSpan &Range : List.getRanges())
|
|
|
|
SectionRanges[&Range.getStart()->getSection()].push_back(&Range);
|
|
|
|
|
2018-11-08 08:35:54 +08:00
|
|
|
const DwarfCompileUnit &CU = List.getCU();
|
|
|
|
const MCSymbol *CUBase = CU.getBaseAddress();
|
2018-07-10 08:10:11 +08:00
|
|
|
bool BaseIsSet = false;
|
|
|
|
for (const auto &P : SectionRanges) {
|
|
|
|
// Don't bother with a base address entry if there's only one range in
|
|
|
|
// this section in this range list - for example ranges for a CU will
|
|
|
|
// usually consist of single regions from each of many sections
|
|
|
|
// (-ffunction-sections, or just C++ inline functions) except under LTO
|
|
|
|
// or optnone where there may be holes in a single CU's section
|
2018-07-13 02:18:21 +08:00
|
|
|
// contributions.
|
2018-07-10 08:10:11 +08:00
|
|
|
auto *Base = CUBase;
|
2018-10-20 17:16:49 +08:00
|
|
|
if (!Base && (P.second.size() > 1 || DwarfVersion < 5) &&
|
2018-11-14 04:08:10 +08:00
|
|
|
(CU.getCUNode()->getRangesBaseAddress() || DwarfVersion >= 5)) {
|
2018-07-10 08:10:11 +08:00
|
|
|
BaseIsSet = true;
|
|
|
|
// FIXME/use care: This may not be a useful base address if it's not
|
|
|
|
// the lowest address/range in this object.
|
|
|
|
Base = P.second.front()->getStart();
|
2018-07-19 02:04:42 +08:00
|
|
|
if (DwarfVersion >= 5) {
|
2018-10-25 07:36:29 +08:00
|
|
|
Base = DD.getSectionLabel(&Base->getSection());
|
2018-10-20 15:36:39 +08:00
|
|
|
Asm->OutStreamer->AddComment("DW_RLE_base_addressx");
|
|
|
|
Asm->OutStreamer->EmitIntValue(dwarf::DW_RLE_base_addressx, 1);
|
|
|
|
Asm->OutStreamer->AddComment(" base address index");
|
|
|
|
Asm->EmitULEB128(DD.getAddressPool().getIndex(Base));
|
|
|
|
} else {
|
2018-07-13 02:18:21 +08:00
|
|
|
Asm->OutStreamer->EmitIntValue(-1, Size);
|
2018-10-20 15:36:39 +08:00
|
|
|
Asm->OutStreamer->AddComment(" base address");
|
|
|
|
Asm->OutStreamer->EmitSymbolValue(Base, Size);
|
|
|
|
}
|
2018-07-19 02:04:42 +08:00
|
|
|
} else if (BaseIsSet && DwarfVersion < 5) {
|
2018-07-10 08:10:11 +08:00
|
|
|
BaseIsSet = false;
|
2018-07-19 02:04:42 +08:00
|
|
|
assert(!Base);
|
|
|
|
Asm->OutStreamer->EmitIntValue(-1, Size);
|
2018-07-10 08:10:11 +08:00
|
|
|
Asm->OutStreamer->EmitIntValue(0, Size);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto *RS : P.second) {
|
|
|
|
const MCSymbol *Begin = RS->getStart();
|
|
|
|
const MCSymbol *End = RS->getEnd();
|
|
|
|
assert(Begin && "Range without a begin symbol?");
|
|
|
|
assert(End && "Range without an end symbol?");
|
|
|
|
if (Base) {
|
2018-07-13 02:18:21 +08:00
|
|
|
if (DwarfVersion >= 5) {
|
|
|
|
// Emit DW_RLE_offset_pair when we have a base.
|
2018-07-19 02:04:42 +08:00
|
|
|
Asm->OutStreamer->AddComment("DW_RLE_offset_pair");
|
2018-07-13 02:18:21 +08:00
|
|
|
Asm->OutStreamer->EmitIntValue(dwarf::DW_RLE_offset_pair, 1);
|
2018-07-19 02:04:42 +08:00
|
|
|
Asm->OutStreamer->AddComment(" starting offset");
|
2018-07-13 02:18:21 +08:00
|
|
|
Asm->EmitLabelDifferenceAsULEB128(Begin, Base);
|
2018-07-19 02:04:42 +08:00
|
|
|
Asm->OutStreamer->AddComment(" ending offset");
|
2018-07-13 02:18:21 +08:00
|
|
|
Asm->EmitLabelDifferenceAsULEB128(End, Base);
|
|
|
|
} else {
|
|
|
|
Asm->EmitLabelDifference(Begin, Base, Size);
|
|
|
|
Asm->EmitLabelDifference(End, Base, Size);
|
|
|
|
}
|
|
|
|
} else if (DwarfVersion >= 5) {
|
2018-10-20 15:36:39 +08:00
|
|
|
Asm->OutStreamer->AddComment("DW_RLE_startx_length");
|
|
|
|
Asm->OutStreamer->EmitIntValue(dwarf::DW_RLE_startx_length, 1);
|
|
|
|
Asm->OutStreamer->AddComment(" start index");
|
|
|
|
Asm->EmitULEB128(DD.getAddressPool().getIndex(Begin));
|
2018-07-19 02:04:42 +08:00
|
|
|
Asm->OutStreamer->AddComment(" length");
|
2018-07-13 02:18:21 +08:00
|
|
|
Asm->EmitLabelDifferenceAsULEB128(End, Begin);
|
2018-07-10 08:10:11 +08:00
|
|
|
} else {
|
|
|
|
Asm->OutStreamer->EmitSymbolValue(Begin, Size);
|
|
|
|
Asm->OutStreamer->EmitSymbolValue(End, Size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-19 02:04:42 +08:00
|
|
|
if (DwarfVersion >= 5) {
|
|
|
|
Asm->OutStreamer->AddComment("DW_RLE_end_of_list");
|
2018-07-13 02:18:21 +08:00
|
|
|
Asm->OutStreamer->EmitIntValue(dwarf::DW_RLE_end_of_list, 1);
|
2018-07-19 02:04:42 +08:00
|
|
|
} else {
|
2018-07-13 02:18:21 +08:00
|
|
|
// Terminate the list with two 0 values.
|
|
|
|
Asm->OutStreamer->EmitIntValue(0, Size);
|
|
|
|
Asm->OutStreamer->EmitIntValue(0, Size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 02:36:22 +08:00
|
|
|
static void emitDebugRangesImpl(DwarfDebug &DD, AsmPrinter *Asm,
|
|
|
|
const DwarfFile &Holder, MCSymbol *TableEnd) {
|
2018-10-20 15:36:39 +08:00
|
|
|
for (const RangeSpanList &List : Holder.getRangeLists())
|
|
|
|
emitRangeList(DD, Asm, List);
|
|
|
|
|
|
|
|
if (TableEnd)
|
|
|
|
Asm->OutStreamer->EmitLabel(TableEnd);
|
|
|
|
}
|
|
|
|
|
2018-07-27 06:48:52 +08:00
|
|
|
/// Emit address ranges into the .debug_ranges section or into the DWARF v5
|
|
|
|
/// .debug_rnglists section.
|
2009-11-21 10:48:08 +08:00
|
|
|
void DwarfDebug::emitDebugRanges() {
|
2017-05-27 02:52:56 +08:00
|
|
|
if (CUMap.empty())
|
|
|
|
return;
|
|
|
|
|
2018-10-20 15:36:39 +08:00
|
|
|
const auto &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
|
2018-08-02 03:38:20 +08:00
|
|
|
|
2018-10-20 15:36:39 +08:00
|
|
|
if (Holder.getRangeLists().empty())
|
2018-03-21 04:21:38 +08:00
|
|
|
return;
|
|
|
|
|
2018-10-20 15:36:39 +08:00
|
|
|
assert(useRangesSection());
|
|
|
|
assert(llvm::none_of(CUMap, [](const decltype(CUMap)::value_type &Pair) {
|
|
|
|
return Pair.second->getCUNode()->isDebugDirectivesOnly();
|
|
|
|
}));
|
2018-07-13 02:18:21 +08:00
|
|
|
|
2009-05-21 07:21:38 +08:00
|
|
|
// Start the dwarf ranges section.
|
2018-07-27 06:48:52 +08:00
|
|
|
MCSymbol *TableEnd = nullptr;
|
|
|
|
if (getDwarfVersion() >= 5) {
|
|
|
|
Asm->OutStreamer->SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfRnglistsSection());
|
2018-10-20 15:36:39 +08:00
|
|
|
TableEnd = emitRnglistsTableHeader(Asm, Holder);
|
2018-07-27 06:48:52 +08:00
|
|
|
} else
|
|
|
|
Asm->OutStreamer->SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfRangesSection());
|
2013-12-03 08:45:45 +08:00
|
|
|
|
2018-10-20 15:36:39 +08:00
|
|
|
emitDebugRangesImpl(*this, Asm, Holder, TableEnd);
|
2009-05-21 07:21:38 +08:00
|
|
|
}
|
|
|
|
|
2018-10-20 16:12:36 +08:00
|
|
|
void DwarfDebug::emitDebugRangesDWO() {
|
|
|
|
assert(useSplitDwarf());
|
|
|
|
|
|
|
|
if (CUMap.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto &Holder = InfoHolder;
|
|
|
|
|
|
|
|
if (Holder.getRangeLists().empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert(getDwarfVersion() >= 5);
|
|
|
|
assert(useRangesSection());
|
|
|
|
assert(llvm::none_of(CUMap, [](const decltype(CUMap)::value_type &Pair) {
|
|
|
|
return Pair.second->getCUNode()->isDebugDirectivesOnly();
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Start the dwarf ranges section.
|
|
|
|
Asm->OutStreamer->SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfRnglistsDWOSection());
|
|
|
|
MCSymbol *TableEnd = emitRnglistsTableHeader(Asm, Holder);
|
|
|
|
|
|
|
|
emitDebugRangesImpl(*this, Asm, Holder, TableEnd);
|
|
|
|
}
|
|
|
|
|
2016-02-01 22:09:41 +08:00
|
|
|
void DwarfDebug::handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U) {
|
2016-01-07 22:28:20 +08:00
|
|
|
for (auto *MN : Nodes) {
|
|
|
|
if (auto *M = dyn_cast<DIMacro>(MN))
|
2016-02-01 22:09:41 +08:00
|
|
|
emitMacro(*M);
|
2016-01-07 22:28:20 +08:00
|
|
|
else if (auto *F = dyn_cast<DIMacroFile>(MN))
|
2016-02-01 22:09:41 +08:00
|
|
|
emitMacroFile(*F, U);
|
2016-01-07 22:28:20 +08:00
|
|
|
else
|
|
|
|
llvm_unreachable("Unexpected DI type!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-01 22:09:41 +08:00
|
|
|
void DwarfDebug::emitMacro(DIMacro &M) {
|
|
|
|
Asm->EmitULEB128(M.getMacinfoType());
|
|
|
|
Asm->EmitULEB128(M.getLine());
|
2016-01-07 22:28:20 +08:00
|
|
|
StringRef Name = M.getName();
|
|
|
|
StringRef Value = M.getValue();
|
2016-02-01 22:09:41 +08:00
|
|
|
Asm->OutStreamer->EmitBytes(Name);
|
2016-01-07 22:28:20 +08:00
|
|
|
if (!Value.empty()) {
|
|
|
|
// There should be one space between macro name and macro value.
|
2018-03-30 07:32:54 +08:00
|
|
|
Asm->emitInt8(' ');
|
2016-02-01 22:09:41 +08:00
|
|
|
Asm->OutStreamer->EmitBytes(Value);
|
2016-01-07 22:28:20 +08:00
|
|
|
}
|
2018-03-30 07:32:54 +08:00
|
|
|
Asm->emitInt8('\0');
|
2016-01-07 22:28:20 +08:00
|
|
|
}
|
|
|
|
|
2016-02-01 22:09:41 +08:00
|
|
|
void DwarfDebug::emitMacroFile(DIMacroFile &F, DwarfCompileUnit &U) {
|
2016-01-07 22:28:20 +08:00
|
|
|
assert(F.getMacinfoType() == dwarf::DW_MACINFO_start_file);
|
2016-02-01 22:09:41 +08:00
|
|
|
Asm->EmitULEB128(dwarf::DW_MACINFO_start_file);
|
|
|
|
Asm->EmitULEB128(F.getLine());
|
2018-01-13 03:17:50 +08:00
|
|
|
Asm->EmitULEB128(U.getOrCreateSourceID(F.getFile()));
|
2016-02-01 22:09:41 +08:00
|
|
|
handleMacroNodes(F.getElements(), U);
|
|
|
|
Asm->EmitULEB128(dwarf::DW_MACINFO_end_file);
|
2016-01-07 22:28:20 +08:00
|
|
|
}
|
|
|
|
|
2016-01-24 16:18:55 +08:00
|
|
|
/// Emit macros into a debug macinfo section.
|
2016-01-07 22:28:20 +08:00
|
|
|
void DwarfDebug::emitDebugMacinfo() {
|
2017-05-27 02:52:56 +08:00
|
|
|
if (CUMap.empty())
|
|
|
|
return;
|
|
|
|
|
2018-08-02 03:38:20 +08:00
|
|
|
if (llvm::all_of(CUMap, [](const decltype(CUMap)::value_type &Pair) {
|
|
|
|
return Pair.second->getCUNode()->isDebugDirectivesOnly();
|
|
|
|
}))
|
|
|
|
return;
|
|
|
|
|
2016-02-01 22:09:41 +08:00
|
|
|
// Start the dwarf macinfo section.
|
|
|
|
Asm->OutStreamer->SwitchSection(
|
|
|
|
Asm->getObjFileLowering().getDwarfMacinfoSection());
|
|
|
|
|
2016-01-07 22:28:20 +08:00
|
|
|
for (const auto &P : CUMap) {
|
|
|
|
auto &TheCU = *P.second;
|
2018-08-02 03:38:20 +08:00
|
|
|
if (TheCU.getCUNode()->isDebugDirectivesOnly())
|
|
|
|
continue;
|
2016-01-07 22:28:20 +08:00
|
|
|
auto *SkCU = TheCU.getSkeleton();
|
|
|
|
DwarfCompileUnit &U = SkCU ? *SkCU : TheCU;
|
|
|
|
auto *CUNode = cast<DICompileUnit>(P.first);
|
2018-02-23 00:20:30 +08:00
|
|
|
DIMacroNodeArray Macros = CUNode->getMacros();
|
|
|
|
if (!Macros.empty()) {
|
|
|
|
Asm->OutStreamer->EmitLabel(U.getMacroLabelBegin());
|
|
|
|
handleMacroNodes(Macros, U);
|
|
|
|
}
|
2016-01-07 22:28:20 +08:00
|
|
|
}
|
|
|
|
Asm->OutStreamer->AddComment("End Of Macro List Mark");
|
2018-03-30 07:32:54 +08:00
|
|
|
Asm->emitInt8(0);
|
2016-01-07 22:28:20 +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,
|
2016-02-12 03:57:46 +08:00
|
|
|
std::unique_ptr<DwarfCompileUnit> NewU) {
|
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
|
|
|
}
|
|
|
|
|
2014-04-23 06:39:41 +08:00
|
|
|
DwarfCompileUnit &DwarfDebug::constructSkeletonCU(const DwarfCompileUnit &CU) {
|
2012-12-01 07:59:06 +08:00
|
|
|
|
2017-08-18 05:26:39 +08:00
|
|
|
auto OwnedUnit = llvm::make_unique<DwarfCompileUnit>(
|
2014-04-29 05:14:27 +08:00
|
|
|
CU.getUniqueID(), CU.getCUNode(), Asm, this, &SkeletonHolder);
|
2014-04-23 06:39:41 +08:00
|
|
|
DwarfCompileUnit &NewCU = *OwnedUnit;
|
2016-12-02 02:56:29 +08:00
|
|
|
NewCU.setSection(Asm->getObjFileLowering().getDwarfInfoSection());
|
2013-01-17 11:00:04 +08:00
|
|
|
|
2015-03-11 00:58:10 +08:00
|
|
|
NewCU.initStmtList();
|
2012-12-01 07:59:06 +08:00
|
|
|
|
2018-01-27 02:52:58 +08:00
|
|
|
if (useSegmentedStringOffsetsTable())
|
|
|
|
NewCU.addStringOffsetsStart();
|
|
|
|
|
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?");
|
2018-03-28 05:28:59 +08:00
|
|
|
SplitTypeUnitFileTable.Emit(
|
|
|
|
*Asm->OutStreamer, MCDwarfLineTableParams(),
|
2014-03-18 09:17:26 +08:00
|
|
|
Asm->getObjFileLowering().getDwarfLineDWOSection());
|
|
|
|
}
|
|
|
|
|
2018-01-27 02:52:58 +08:00
|
|
|
void DwarfDebug::emitStringOffsetsTableHeaderDWO() {
|
|
|
|
assert(useSplitDwarf() && "No split dwarf?");
|
2018-07-26 22:36:07 +08:00
|
|
|
InfoHolder.getStringPool().emitStringOffsetsTableHeader(
|
|
|
|
*Asm, Asm->getObjFileLowering().getDwarfStrOffDWOSection(),
|
|
|
|
InfoHolder.getStringOffsetsStartSym());
|
2018-01-27 02:52:58 +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() {
|
2018-01-27 02:52:58 +08:00
|
|
|
if (useSegmentedStringOffsetsTable())
|
|
|
|
emitStringOffsetsTableHeaderDWO();
|
2012-12-27 10:14:01 +08:00
|
|
|
assert(useSplitDwarf() && "No split dwarf?");
|
2015-05-22 03:20:38 +08:00
|
|
|
MCSection *OffSec = Asm->getObjFileLowering().getDwarfStrOffDWOSection();
|
2013-01-08 03:32:41 +08:00
|
|
|
InfoHolder.emitStrings(Asm->getObjFileLowering().getDwarfStrDWOSection(),
|
2018-01-27 02:52:58 +08:00
|
|
|
OffSec, /* UseRelativeOffsets = */ false);
|
2012-12-27 10:14:01 +08:00
|
|
|
}
|
2013-11-20 07:08:21 +08:00
|
|
|
|
2018-10-20 14:02:15 +08:00
|
|
|
// Emit address pool.
|
2018-08-01 13:48:06 +08:00
|
|
|
void DwarfDebug::emitDebugAddr() {
|
|
|
|
AddrPool.emit(*Asm, Asm->getObjFileLowering().getDwarfAddrSection());
|
|
|
|
}
|
|
|
|
|
2014-03-19 08:11:28 +08:00
|
|
|
MCDwarfDwoLineTable *DwarfDebug::getDwoLineTable(const DwarfCompileUnit &CU) {
|
|
|
|
if (!useSplitDwarf())
|
|
|
|
return nullptr;
|
2018-03-30 01:16:41 +08:00
|
|
|
const DICompileUnit *DIUnit = CU.getCUNode();
|
|
|
|
SplitTypeUnitFileTable.maybeSetRootFile(
|
|
|
|
DIUnit->getDirectory(), DIUnit->getFilename(),
|
|
|
|
CU.getMD5AsBytes(DIUnit->getFile()), DIUnit->getSource());
|
2014-03-19 08:11:28 +08:00
|
|
|
return &SplitTypeUnitFileTable;
|
|
|
|
}
|
|
|
|
|
2015-07-16 01:01:41 +08:00
|
|
|
uint64_t DwarfDebug::makeTypeSignature(StringRef Identifier) {
|
2014-04-27 00:26:41 +08:00
|
|
|
MD5 Hash;
|
|
|
|
Hash.update(Identifier);
|
|
|
|
// ... take the least significant 8 bytes and return those. Our MD5
|
2017-03-21 07:33:18 +08:00
|
|
|
// implementation always returns its results in little endian, so we actually
|
|
|
|
// need the "high" word.
|
2014-04-27 00:26:41 +08:00
|
|
|
MD5::MD5Result Result;
|
|
|
|
Hash.final(Result);
|
2017-03-21 07:33:18 +08:00
|
|
|
return Result.high();
|
2014-04-27 00:26:41 +08:00
|
|
|
}
|
|
|
|
|
2014-02-12 08:31:30 +08:00
|
|
|
void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
|
2014-04-26 02:26:14 +08:00
|
|
|
StringRef Identifier, DIE &RefDie,
|
2015-04-30 00:38:44 +08:00
|
|
|
const DICompositeType *CTy) {
|
2014-04-27 01:27:38 +08:00
|
|
|
// Fast path if we're building some type units and one has already used the
|
|
|
|
// address pool we know we're going to throw away all this work anyway, so
|
|
|
|
// don't bother building dependent types.
|
|
|
|
if (!TypeUnitsUnderConstruction.empty() && AddrPool.hasBeenUsed())
|
|
|
|
return;
|
|
|
|
|
2016-02-12 03:57:46 +08:00
|
|
|
auto Ins = TypeSignatures.insert(std::make_pair(CTy, 0));
|
|
|
|
if (!Ins.second) {
|
|
|
|
CU.addDIETypeSignature(RefDie, Ins.first->second);
|
2014-01-20 16:07:07 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-27 01:27:38 +08:00
|
|
|
bool TopLevelType = TypeUnitsUnderConstruction.empty();
|
|
|
|
AddrPool.resetUsedFlag();
|
|
|
|
|
2017-08-18 05:26:39 +08:00
|
|
|
auto OwnedUnit = llvm::make_unique<DwarfTypeUnit>(CU, Asm, this, &InfoHolder,
|
|
|
|
getDwoLineTable(CU));
|
2014-04-23 06:39:41 +08:00
|
|
|
DwarfTypeUnit &NewTU = *OwnedUnit;
|
2014-04-29 05:04:29 +08:00
|
|
|
DIE &UnitDie = NewTU.getUnitDie();
|
2016-08-12 05:15:00 +08:00
|
|
|
TypeUnitsUnderConstruction.emplace_back(std::move(OwnedUnit), CTy);
|
2014-04-23 06:39:41 +08:00
|
|
|
|
2014-04-29 05:04:29 +08:00
|
|
|
NewTU.addUInt(UnitDie, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
|
2014-04-23 07:09:36 +08:00
|
|
|
CU.getLanguage());
|
2014-01-20 16:07:07 +08:00
|
|
|
|
2014-04-27 00:26:41 +08:00
|
|
|
uint64_t Signature = makeTypeSignature(Identifier);
|
2014-04-23 06:39:41 +08:00
|
|
|
NewTU.setTypeSignature(Signature);
|
2016-02-12 03:57:46 +08:00
|
|
|
Ins.first->second = Signature;
|
2014-04-27 00:26:41 +08:00
|
|
|
|
2018-11-13 00:55:11 +08:00
|
|
|
if (useSplitDwarf()) {
|
|
|
|
MCSection *Section =
|
|
|
|
getDwarfVersion() <= 4
|
|
|
|
? Asm->getObjFileLowering().getDwarfTypesDWOSection()
|
|
|
|
: Asm->getObjFileLowering().getDwarfInfoDWOSection();
|
|
|
|
NewTU.setSection(Section);
|
|
|
|
} else {
|
2018-11-10 03:06:09 +08:00
|
|
|
MCSection *Section =
|
|
|
|
getDwarfVersion() <= 4
|
|
|
|
? Asm->getObjFileLowering().getDwarfTypesSection(Signature)
|
|
|
|
: Asm->getObjFileLowering().getDwarfInfoSection(Signature);
|
|
|
|
NewTU.setSection(Section);
|
2018-03-28 05:28:59 +08:00
|
|
|
// Non-split type units reuse the compile unit's line table.
|
|
|
|
CU.applyStmtList(UnitDie);
|
2014-07-26 01:11:58 +08:00
|
|
|
}
|
2014-01-20 16:07:07 +08:00
|
|
|
|
2018-01-27 02:52:58 +08:00
|
|
|
// Add DW_AT_str_offsets_base to the type unit DIE, but not for split type
|
|
|
|
// units.
|
|
|
|
if (useSegmentedStringOffsetsTable() && !useSplitDwarf())
|
|
|
|
NewTU.addStringOffsetsStart();
|
|
|
|
|
2014-04-27 00:26:41 +08:00
|
|
|
NewTU.setType(NewTU.createTypeDIE(CTy));
|
|
|
|
|
2014-04-27 01:27:38 +08:00
|
|
|
if (TopLevelType) {
|
|
|
|
auto TypeUnitsToAdd = std::move(TypeUnitsUnderConstruction);
|
|
|
|
TypeUnitsUnderConstruction.clear();
|
|
|
|
|
|
|
|
// Types referencing entries in the address table cannot be placed in type
|
|
|
|
// units.
|
|
|
|
if (AddrPool.hasBeenUsed()) {
|
|
|
|
|
|
|
|
// Remove all the types built while building this type.
|
|
|
|
// This is pessimistic as some of these types might not be dependent on
|
|
|
|
// the type that used an address.
|
|
|
|
for (const auto &TU : TypeUnitsToAdd)
|
2016-02-12 03:57:46 +08:00
|
|
|
TypeSignatures.erase(TU.second);
|
2014-04-27 01:27:38 +08:00
|
|
|
|
|
|
|
// Construct this type in the CU directly.
|
|
|
|
// This is inefficient because all the dependent types will be rebuilt
|
|
|
|
// from scratch, including building them in type units, discovering that
|
|
|
|
// they depend on addresses, throwing them out and rebuilding them.
|
2015-04-30 00:38:44 +08:00
|
|
|
CU.constructTypeDIE(RefDie, cast<DICompositeType>(CTy));
|
2014-04-27 01:27:38 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the type wasn't dependent on fission addresses, finish adding the type
|
|
|
|
// and all its dependent types.
|
2016-02-12 03:57:46 +08:00
|
|
|
for (auto &TU : TypeUnitsToAdd) {
|
|
|
|
InfoHolder.computeSizeAndOffsetsForUnit(TU.first.get());
|
|
|
|
InfoHolder.emitUnit(TU.first.get(), useSplitDwarf());
|
|
|
|
}
|
2014-04-27 01:27:38 +08:00
|
|
|
}
|
2016-02-12 03:57:46 +08:00
|
|
|
CU.addDIETypeSignature(RefDie, Signature);
|
2013-11-20 07:08:21 +08:00
|
|
|
}
|
2014-03-08 02:49:45 +08:00
|
|
|
|
2018-07-20 23:24:13 +08:00
|
|
|
// Add the Name along with its companion DIE to the appropriate accelerator
|
|
|
|
// table (for AccelTableKind::Dwarf it's always AccelDebugNames, for
|
|
|
|
// AccelTableKind::Apple, we use the table we got as an argument). If
|
|
|
|
// accelerator tables are disabled, this function does nothing.
|
|
|
|
template <typename DataT>
|
2018-08-17 05:29:55 +08:00
|
|
|
void DwarfDebug::addAccelNameImpl(const DICompileUnit &CU,
|
|
|
|
AccelTable<DataT> &AppleAccel, StringRef Name,
|
2018-07-20 23:24:13 +08:00
|
|
|
const DIE &Die) {
|
|
|
|
if (getAccelTableKind() == AccelTableKind::None)
|
|
|
|
return;
|
2018-04-18 20:11:59 +08:00
|
|
|
|
2018-08-17 05:29:55 +08:00
|
|
|
if (getAccelTableKind() != AccelTableKind::Apple &&
|
|
|
|
CU.getNameTableKind() == DICompileUnit::DebugNameTableKind::None)
|
|
|
|
return;
|
|
|
|
|
2018-04-18 20:11:59 +08:00
|
|
|
DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
|
[DebugInfo] Reduce debug_str_offsets section size
Summary:
The accelerator tables use the debug_str section to store their strings.
However, they do not support the indirect method of access that is
available for the debug_info section (DW_FORM_strx et al.).
Currently our code is assuming that all strings can/will be referenced
indirectly, and puts all of them into the debug_str_offsets section.
This is generally true for regular (unsplit) dwarf, but in the DWO case,
most of the strings in the debug_str section will only be used from the
accelerator tables. Therefore the contents of the debug_str_offsets
section will be largely unused and bloating the main executable.
This patch rectifies this by teaching the DwarfStringPool to
differentiate between strings accessed directly and indirectly. When a
user inserts a string into the pool it has to declare whether that
string will be referenced directly or not. If at least one user requsts
indirect access, that string will be assigned an index ID and put into
debug_str_offsets table. Otherwise, the offset table is skipped.
This approach reduces the overall binary size (when compiled with
-gdwarf-5 -gsplit-dwarf) in my tests by about 2% (debug_str_offsets is
shrunk by 99%).
Reviewers: probinson, dblaikie, JDevlieghere
Subscribers: aprantl, mgrang, llvm-commits
Differential Revision: https://reviews.llvm.org/D49493
llvm-svn: 339122
2018-08-07 17:54:52 +08:00
|
|
|
DwarfStringPoolEntryRef Ref = Holder.getStringPool().getEntry(*Asm, Name);
|
2018-04-18 20:11:59 +08:00
|
|
|
|
2018-04-04 22:42:14 +08:00
|
|
|
switch (getAccelTableKind()) {
|
|
|
|
case AccelTableKind::Apple:
|
2018-07-20 23:24:13 +08:00
|
|
|
AppleAccel.addName(Ref, Die);
|
2018-04-04 22:42:14 +08:00
|
|
|
break;
|
|
|
|
case AccelTableKind::Dwarf:
|
2018-07-20 23:24:13 +08:00
|
|
|
AccelDebugNames.addName(Ref, Die);
|
2018-04-04 22:42:14 +08:00
|
|
|
break;
|
|
|
|
case AccelTableKind::Default:
|
|
|
|
llvm_unreachable("Default should have already been resolved.");
|
2018-07-20 23:24:13 +08:00
|
|
|
case AccelTableKind::None:
|
|
|
|
llvm_unreachable("None handled above");
|
2018-04-04 22:42:14 +08:00
|
|
|
}
|
2014-04-24 07:37:35 +08:00
|
|
|
}
|
2014-04-24 08:53:32 +08:00
|
|
|
|
2018-08-17 05:29:55 +08:00
|
|
|
void DwarfDebug::addAccelName(const DICompileUnit &CU, StringRef Name,
|
|
|
|
const DIE &Die) {
|
|
|
|
addAccelNameImpl(CU, AccelNames, Name, Die);
|
2018-07-20 23:24:13 +08:00
|
|
|
}
|
|
|
|
|
2018-08-17 05:29:55 +08:00
|
|
|
void DwarfDebug::addAccelObjC(const DICompileUnit &CU, StringRef Name,
|
|
|
|
const DIE &Die) {
|
2018-07-20 23:24:13 +08:00
|
|
|
// ObjC names go only into the Apple accelerator tables.
|
|
|
|
if (getAccelTableKind() == AccelTableKind::Apple)
|
2018-08-17 05:29:55 +08:00
|
|
|
addAccelNameImpl(CU, AccelObjC, Name, Die);
|
2014-04-24 08:53:32 +08:00
|
|
|
}
|
2014-04-24 09:02:42 +08:00
|
|
|
|
2018-08-17 05:29:55 +08:00
|
|
|
void DwarfDebug::addAccelNamespace(const DICompileUnit &CU, StringRef Name,
|
|
|
|
const DIE &Die) {
|
|
|
|
addAccelNameImpl(CU, AccelNamespace, Name, Die);
|
2014-04-24 09:02:42 +08:00
|
|
|
}
|
2014-04-24 09:23:49 +08:00
|
|
|
|
2018-08-17 05:29:55 +08:00
|
|
|
void DwarfDebug::addAccelType(const DICompileUnit &CU, StringRef Name,
|
|
|
|
const DIE &Die, char Flags) {
|
|
|
|
addAccelNameImpl(CU, AccelTypes, Name, Die);
|
2014-04-24 09:23:49 +08:00
|
|
|
}
|
2016-11-24 07:30:37 +08:00
|
|
|
|
|
|
|
uint16_t DwarfDebug::getDwarfVersion() const {
|
|
|
|
return Asm->OutStreamer->getContext().getDwarfVersion();
|
|
|
|
}
|
2018-10-25 07:36:29 +08:00
|
|
|
|
|
|
|
void DwarfDebug::addSectionLabel(const MCSymbol *Sym) {
|
|
|
|
SectionLabels.insert(std::make_pair(&Sym->getSection(), Sym));
|
|
|
|
}
|
|
|
|
|
|
|
|
const MCSymbol *DwarfDebug::getSectionLabel(const MCSection *S) {
|
|
|
|
return SectionLabels.find(S)->second;
|
|
|
|
}
|