Debug info: Support variadic functions.

Variadic functions have an unspecified parameter tag after the last
argument. In IR this is represented as an unspecified parameter in the
subroutine type.

Paired commit with CFE r202185.

rdar://problem/13690847

This re-applies r202184 + a bugfix in DwarfDebug's argument handling.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202188 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Adrian Prantl
2014-02-25 19:57:42 +00:00
parent 9791b3f9ae
commit dbaa6ab8b5
5 changed files with 141 additions and 29 deletions

View File

@@ -403,15 +403,21 @@ DIE *DwarfDebug::updateSubprogramScopeDIE(DwarfCompileUnit *SPCU,
DIArray Args = SPTy.getTypeArray();
uint16_t SPTag = SPTy.getTag();
if (SPTag == dwarf::DW_TAG_subroutine_type)
// FIXME: Use DwarfUnit::constructSubprogramArguments() here.
for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
DIE *Arg =
SPCU->createAndAddDIE(dwarf::DW_TAG_formal_parameter, *SPDie);
DIType ATy(Args.getElement(i));
SPCU->addType(Arg, ATy);
if (ATy.isArtificial())
SPCU->addFlag(Arg, dwarf::DW_AT_artificial);
if (ATy.isObjectPointer())
SPCU->addDIEEntry(SPDie, dwarf::DW_AT_object_pointer, Arg);
if (ATy.isUnspecifiedParameter()) {
assert(i == N-1 && "ellipsis must be the last argument");
SPCU->createAndAddDIE(dwarf::DW_TAG_unspecified_parameters, *SPDie);
} else {
DIE *Arg =
SPCU->createAndAddDIE(dwarf::DW_TAG_formal_parameter, *SPDie);
SPCU->addType(Arg, ATy);
if (ATy.isArtificial())
SPCU->addFlag(Arg, dwarf::DW_AT_artificial);
if (ATy.isObjectPointer())
SPCU->addDIEEntry(SPDie, dwarf::DW_AT_object_pointer, Arg);
}
}
DIE *SPDeclDie = SPDie;
SPDie = SPCU->createAndAddDIE(dwarf::DW_TAG_subprogram,
@@ -582,7 +588,7 @@ DIE *DwarfDebug::createScopeChildrenDIE(DwarfCompileUnit *TheCU,
DIE *ObjectPointer = NULL;
// Collect arguments for current function.
if (LScopes.isCurrentFunctionScope(Scope))
if (LScopes.isCurrentFunctionScope(Scope)) {
for (unsigned i = 0, N = CurrentFnArguments.size(); i < N; ++i)
if (DbgVariable *ArgDV = CurrentFnArguments[i])
if (DIE *Arg =
@@ -592,6 +598,16 @@ DIE *DwarfDebug::createScopeChildrenDIE(DwarfCompileUnit *TheCU,
ObjectPointer = Arg;
}
// Create the unspecified parameter that marks a function as variadic.
DISubprogram SP(Scope->getScopeNode());
assert(SP.Verify());
DIArray FnArgs = SP.getType().getTypeArray();
if (FnArgs.getElement(FnArgs.getNumElements()-1).isUnspecifiedParameter()) {
DIE *Ellipsis = new DIE(dwarf::DW_TAG_unspecified_parameters);
Children.push_back(Ellipsis);
}
}
// Collect lexical scope children first.
const SmallVectorImpl<DbgVariable *> &Variables =
ScopeVariables.lookup(Scope);