Skip to content

Commit eab6e94

Browse files
committed
[DebugInfo] Add a TargetFuncName field in DISubprogram for
specifying DW_AT_trampoline as a string. Also update the signature of DIBuilder::createFunction to reflect this addition. Differential Revision: https://reviews.llvm.org/D123697
1 parent 39a68cc commit eab6e94

File tree

14 files changed

+206
-49
lines changed

14 files changed

+206
-49
lines changed

llvm/docs/SourceLevelDebugging.rst

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,8 @@ a Fortran front-end would generate the following descriptors:
10861086
10871087
!DILocalVariable(name: "string", arg: 1, scope: !10, file: !3, line: 4, type: !15)
10881088
!DIStringType(name: "character(*)!2", stringLength: !16, stringLengthExpression: !DIExpression(), size: 32)
1089-
1090-
A fortran deferred-length character can also contain the information of raw storage of the characters in addition to the length of the string. This information is encoded in the stringLocationExpression field. Based on this information, DW_AT_data_location attribute is emitted in a DW_TAG_string_type debug info.
1089+
1090+
A fortran deferred-length character can also contain the information of raw storage of the characters in addition to the length of the string. This information is encoded in the stringLocationExpression field. Based on this information, DW_AT_data_location attribute is emitted in a DW_TAG_string_type debug info.
10911091

10921092
!DIStringType(name: "character(*)!2", stringLengthExpression: !DIExpression(), stringLocationExpression: !DIExpression(DW_OP_push_object_address, DW_OP_deref), size: 32)
10931093

@@ -1105,6 +1105,25 @@ and this will materialize in DWARF tags as:
11051105
...
11061106
DW_AT_artificial (true)
11071107
1108+
A Fortran front-end may need to generate a *trampoline* function to call a
1109+
function defined in a different compilation unit. In this case, the front-end
1110+
can emit the following descriptor for the trampoline function:
1111+
1112+
.. code-block:: text
1113+
1114+
!DISubprogram(name: "sub1_.t0p", linkageName: "sub1_.t0p", scope: !4, file: !4, type: !5, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !7, retainedNodes: !24, targetFuncName: "sub1_")
1115+
1116+
The targetFuncName field is the name of the function that the trampoline
1117+
calls. This descriptor results in the following DWARF tag:
1118+
1119+
.. code-block:: text
1120+
1121+
DW_TAG_subprogram
1122+
...
1123+
DW_AT_linkage_name ("sub1_.t0p")
1124+
DW_AT_name ("sub1_.t0p")
1125+
DW_AT_trampoline ("sub1_")
1126+
11081127
Debugging information format
11091128
============================
11101129

llvm/include/llvm/IR/DIBuilder.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,8 @@ namespace llvm {
752752
/// \param TParams Function template parameters.
753753
/// \param ThrownTypes Exception types this function may throw.
754754
/// \param Annotations Attribute Annotations.
755+
/// \param TargetFuncName The name of the target function if this is
756+
/// a trampoline.
755757
DISubprogram *
756758
createFunction(DIScope *Scope, StringRef Name, StringRef LinkageName,
757759
DIFile *File, unsigned LineNo, DISubroutineType *Ty,
@@ -760,7 +762,8 @@ namespace llvm {
760762
DITemplateParameterArray TParams = nullptr,
761763
DISubprogram *Decl = nullptr,
762764
DITypeArray ThrownTypes = nullptr,
763-
DINodeArray Annotations = nullptr);
765+
DINodeArray Annotations = nullptr,
766+
StringRef TargetFuncName = "");
764767

765768
/// Identical to createFunction,
766769
/// except that the resulting DbgNode is meant to be RAUWed.

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,13 +1851,14 @@ class DISubprogram : public DILocalScope {
18511851
DISPFlags SPFlags, DICompileUnit *Unit,
18521852
DITemplateParameterArray TemplateParams, DISubprogram *Declaration,
18531853
DINodeArray RetainedNodes, DITypeArray ThrownTypes,
1854-
DINodeArray Annotations, StorageType Storage,
1855-
bool ShouldCreate = true) {
1854+
DINodeArray Annotations, StringRef TargetFuncName,
1855+
StorageType Storage, bool ShouldCreate = true) {
18561856
return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
18571857
getCanonicalMDString(Context, LinkageName), File, Line, Type,
18581858
ScopeLine, ContainingType, VirtualIndex, ThisAdjustment,
18591859
Flags, SPFlags, Unit, TemplateParams.get(), Declaration,
18601860
RetainedNodes.get(), ThrownTypes.get(), Annotations.get(),
1861+
getCanonicalMDString(Context, TargetFuncName),
18611862
Storage, ShouldCreate);
18621863
}
18631864
static DISubprogram *
@@ -1867,15 +1868,17 @@ class DISubprogram : public DILocalScope {
18671868
int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
18681869
Metadata *TemplateParams, Metadata *Declaration,
18691870
Metadata *RetainedNodes, Metadata *ThrownTypes, Metadata *Annotations,
1870-
StorageType Storage, bool ShouldCreate = true);
1871+
MDString *TargetFuncName, StorageType Storage,
1872+
bool ShouldCreate = true);
18711873

18721874
TempDISubprogram cloneImpl() const {
18731875
return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
18741876
getFile(), getLine(), getType(), getScopeLine(),
18751877
getContainingType(), getVirtualIndex(),
18761878
getThisAdjustment(), getFlags(), getSPFlags(),
18771879
getUnit(), getTemplateParams(), getDeclaration(),
1878-
getRetainedNodes(), getThrownTypes(), getAnnotations());
1880+
getRetainedNodes(), getThrownTypes(), getAnnotations(),
1881+
getTargetFuncName());
18791882
}
18801883

18811884
public:
@@ -1887,10 +1890,11 @@ class DISubprogram : public DILocalScope {
18871890
DIFlags Flags, DISPFlags SPFlags, DICompileUnit *Unit,
18881891
DITemplateParameterArray TemplateParams = nullptr,
18891892
DISubprogram *Declaration = nullptr, DINodeArray RetainedNodes = nullptr,
1890-
DITypeArray ThrownTypes = nullptr, DINodeArray Annotations = nullptr),
1893+
DITypeArray ThrownTypes = nullptr, DINodeArray Annotations = nullptr,
1894+
StringRef TargetFuncName = ""),
18911895
(Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
18921896
VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
1893-
Declaration, RetainedNodes, ThrownTypes, Annotations))
1897+
Declaration, RetainedNodes, ThrownTypes, Annotations, TargetFuncName))
18941898

18951899
DEFINE_MDNODE_GET(
18961900
DISubprogram,
@@ -1900,10 +1904,10 @@ class DISubprogram : public DILocalScope {
19001904
DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
19011905
Metadata *TemplateParams = nullptr, Metadata *Declaration = nullptr,
19021906
Metadata *RetainedNodes = nullptr, Metadata *ThrownTypes = nullptr,
1903-
Metadata *Annotations = nullptr),
1907+
Metadata *Annotations = nullptr, MDString *TargetFuncName = nullptr),
19041908
(Scope, Name, LinkageName, File, Line, Type, ScopeLine, ContainingType,
19051909
VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit, TemplateParams,
1906-
Declaration, RetainedNodes, ThrownTypes, Annotations))
1910+
Declaration, RetainedNodes, ThrownTypes, Annotations, TargetFuncName))
19071911

19081912
TempDISubprogram clone() const { return cloneImpl(); }
19091913

@@ -2012,6 +2016,9 @@ class DISubprogram : public DILocalScope {
20122016
DINodeArray getAnnotations() const {
20132017
return cast_or_null<MDTuple>(getRawAnnotations());
20142018
}
2019+
StringRef getTargetFuncName() const {
2020+
return (getRawTargetFuncName()) ? getStringOperand(12) : StringRef();
2021+
}
20152022

20162023
Metadata *getRawScope() const { return getOperand(1); }
20172024
MDString *getRawName() const { return getOperandAs<MDString>(2); }
@@ -2032,6 +2039,9 @@ class DISubprogram : public DILocalScope {
20322039
Metadata *getRawAnnotations() const {
20332040
return getNumOperands() > 11 ? getOperandAs<Metadata>(11) : nullptr;
20342041
}
2042+
MDString *getRawTargetFuncName() const {
2043+
return getNumOperands() > 12 ? getOperandAs<MDString>(12) : nullptr;
2044+
}
20352045

20362046
void replaceRawLinkageName(MDString *LinkageName) {
20372047
replaceOperandWith(3, LinkageName);

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4822,7 +4822,8 @@ bool LLParser::parseDISubprogram(MDNode *&Result, bool IsDistinct) {
48224822
OPTIONAL(declaration, MDField, ); \
48234823
OPTIONAL(retainedNodes, MDField, ); \
48244824
OPTIONAL(thrownTypes, MDField, ); \
4825-
OPTIONAL(annotations, MDField, );
4825+
OPTIONAL(annotations, MDField, ); \
4826+
OPTIONAL(targetFuncName, MDStringField, );
48264827
PARSE_MD_FIELDS();
48274828
#undef VISIT_MD_FIELDS
48284829

@@ -4841,7 +4842,8 @@ bool LLParser::parseDISubprogram(MDNode *&Result, bool IsDistinct) {
48414842
(Context, scope.Val, name.Val, linkageName.Val, file.Val, line.Val,
48424843
type.Val, scopeLine.Val, containingType.Val, virtualIndex.Val,
48434844
thisAdjustment.Val, flags.Val, SPFlags, unit.Val, templateParams.Val,
4844-
declaration.Val, retainedNodes.Val, thrownTypes.Val, annotations.Val));
4845+
declaration.Val, retainedNodes.Val, thrownTypes.Val, annotations.Val,
4846+
targetFuncName.Val));
48454847
return false;
48464848
}
48474849

llvm/lib/Bitcode/Reader/MetadataLoader.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
16981698
bool HasThisAdj = true;
16991699
bool HasThrownTypes = true;
17001700
bool HasAnnotations = false;
1701+
bool HasTargetFuncName = false;
17011702
unsigned OffsetA = 0;
17021703
unsigned OffsetB = 0;
17031704
if (!HasSPFlags) {
@@ -1711,6 +1712,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
17111712
HasThrownTypes = Record.size() >= 21;
17121713
} else {
17131714
HasAnnotations = Record.size() >= 19;
1715+
HasTargetFuncName = Record.size() >= 20;
17141716
}
17151717
Metadata *CUorFn = getMDOrNull(Record[12 + OffsetB]);
17161718
DISubprogram *SP = GET_OR_DISTINCT(
@@ -1735,7 +1737,9 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata(
17351737
HasThrownTypes ? getMDOrNull(Record[17 + OffsetB])
17361738
: nullptr, // thrownTypes
17371739
HasAnnotations ? getMDOrNull(Record[18 + OffsetB])
1738-
: nullptr // annotations
1740+
: nullptr, // annotations
1741+
HasTargetFuncName ? getMDString(Record[19 + OffsetB])
1742+
: nullptr // targetFuncName
17391743
));
17401744
MetadataList.assignValue(SP, NextMetadataNo);
17411745
NextMetadataNo++;

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,6 +1822,7 @@ void ModuleBitcodeWriter::writeDISubprogram(const DISubprogram *N,
18221822
Record.push_back(N->getThisAdjustment());
18231823
Record.push_back(VE.getMetadataOrNullID(N->getThrownTypes().get()));
18241824
Record.push_back(VE.getMetadataOrNullID(N->getAnnotations().get()));
1825+
Record.push_back(VE.getMetadataOrNullID(N->getRawTargetFuncName()));
18251826

18261827
Stream.EmitRecord(bitc::METADATA_SUBPROGRAM, Record, Abbrev);
18271828
Record.clear();

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,9 @@ void DwarfUnit::applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie,
13441344
if (SP->isRecursive())
13451345
addFlag(SPDie, dwarf::DW_AT_recursive);
13461346

1347+
if (!SP->getTargetFuncName().empty())
1348+
addString(SPDie, dwarf::DW_AT_trampoline, SP->getTargetFuncName());
1349+
13471350
if (DD->getDwarfVersion() >= 5 && SP->isDeleted())
13481351
addFlag(SPDie, dwarf::DW_AT_deleted);
13491352
}

llvm/lib/IR/AsmWriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,6 +2131,7 @@ static void writeDISubprogram(raw_ostream &Out, const DISubprogram *N,
21312131
Printer.printMetadata("retainedNodes", N->getRawRetainedNodes());
21322132
Printer.printMetadata("thrownTypes", N->getRawThrownTypes());
21332133
Printer.printMetadata("annotations", N->getRawAnnotations());
2134+
Printer.printString("targetFuncName", N->getTargetFuncName());
21342135
Out << ")";
21352136
}
21362137

llvm/lib/IR/DIBuilder.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,14 +846,15 @@ DISubprogram *DIBuilder::createFunction(
846846
unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine,
847847
DINode::DIFlags Flags, DISubprogram::DISPFlags SPFlags,
848848
DITemplateParameterArray TParams, DISubprogram *Decl,
849-
DITypeArray ThrownTypes, DINodeArray Annotations) {
849+
DITypeArray ThrownTypes, DINodeArray Annotations,
850+
StringRef TargetFuncName) {
850851
bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition;
851852
auto *Node = getSubprogram(
852853
/*IsDistinct=*/IsDefinition, VMContext, getNonCompileUnitScope(Context),
853854
Name, LinkageName, File, LineNo, Ty, ScopeLine, nullptr, 0, 0, Flags,
854855
SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl,
855856
MDTuple::getTemporary(VMContext, None).release(), ThrownTypes,
856-
Annotations);
857+
Annotations, TargetFuncName);
857858

858859
if (IsDefinition)
859860
AllSubprograms.push_back(Node);

llvm/lib/IR/DebugInfoMetadata.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -978,27 +978,33 @@ DISubprogram *DISubprogram::getImpl(
978978
unsigned ScopeLine, Metadata *ContainingType, unsigned VirtualIndex,
979979
int ThisAdjustment, DIFlags Flags, DISPFlags SPFlags, Metadata *Unit,
980980
Metadata *TemplateParams, Metadata *Declaration, Metadata *RetainedNodes,
981-
Metadata *ThrownTypes, Metadata *Annotations, StorageType Storage,
982-
bool ShouldCreate) {
981+
Metadata *ThrownTypes, Metadata *Annotations, MDString *TargetFuncName,
982+
StorageType Storage, bool ShouldCreate) {
983983
assert(isCanonical(Name) && "Expected canonical MDString");
984984
assert(isCanonical(LinkageName) && "Expected canonical MDString");
985+
assert(isCanonical(TargetFuncName) && "Expected canonical MDString");
985986
DEFINE_GETIMPL_LOOKUP(DISubprogram,
986987
(Scope, Name, LinkageName, File, Line, Type, ScopeLine,
987988
ContainingType, VirtualIndex, ThisAdjustment, Flags,
988989
SPFlags, Unit, TemplateParams, Declaration,
989-
RetainedNodes, ThrownTypes, Annotations));
990-
SmallVector<Metadata *, 12> Ops = {
990+
RetainedNodes, ThrownTypes, Annotations,
991+
TargetFuncName));
992+
SmallVector<Metadata *, 13> Ops = {
991993
File, Scope, Name, LinkageName,
992994
Type, Unit, Declaration, RetainedNodes,
993-
ContainingType, TemplateParams, ThrownTypes, Annotations};
994-
if (!Annotations) {
995+
ContainingType, TemplateParams, ThrownTypes, Annotations,
996+
TargetFuncName};
997+
if (!TargetFuncName) {
995998
Ops.pop_back();
996-
if (!ThrownTypes) {
999+
if (!Annotations) {
9971000
Ops.pop_back();
998-
if (!TemplateParams) {
1001+
if (!ThrownTypes) {
9991002
Ops.pop_back();
1000-
if (!ContainingType)
1003+
if (!TemplateParams) {
10011004
Ops.pop_back();
1005+
if (!ContainingType)
1006+
Ops.pop_back();
1007+
}
10021008
}
10031009
}
10041010
}

0 commit comments

Comments
 (0)