forked from OSchip/llvm-project
Debug Info: Using declarations/DW_TAG_imported_declaration of variables, types, and functions.
Basic support is implemented here - it still doesn't account for declared-but-not-defined variables or functions. It cannot handle out of order (declared, 'using', then defined) cases for variables, but can handle that for functions (& can handle declared, 'using'd, and not defined at all cases for types). llvm-svn: 181393
This commit is contained in:
parent
3b6038b6f3
commit
b0b645cad1
|
@ -2097,6 +2097,17 @@ llvm::DIType CGDebugInfo::CreateMemberType(llvm::DIFile Unit, QualType FType,
|
||||||
return Ty;
|
return Ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
llvm::DIDescriptor CGDebugInfo::getDeclarationOrDefinition(const Decl *D) {
|
||||||
|
if (const TypeDecl *RD = dyn_cast<TypeDecl>(D))
|
||||||
|
return CreatePointeeType(QualType(RD->getTypeForDecl(), 0), llvm::DIFile());
|
||||||
|
llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator I =
|
||||||
|
DeclCache.find(D->getCanonicalDecl());
|
||||||
|
if (I == DeclCache.end())
|
||||||
|
return llvm::DIDescriptor();
|
||||||
|
llvm::Value *V = I->second;
|
||||||
|
return llvm::DIDescriptor(dyn_cast_or_null<llvm::MDNode>(V));
|
||||||
|
}
|
||||||
|
|
||||||
/// getFunctionDeclaration - Return debug info descriptor to describe method
|
/// getFunctionDeclaration - Return debug info descriptor to describe method
|
||||||
/// declaration for the given method definition.
|
/// declaration for the given method definition.
|
||||||
llvm::DISubprogram CGDebugInfo::getFunctionDeclaration(const Decl *D) {
|
llvm::DISubprogram CGDebugInfo::getFunctionDeclaration(const Decl *D) {
|
||||||
|
@ -2265,6 +2276,8 @@ void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType,
|
||||||
getLineNumber(CurLoc), Flags,
|
getLineNumber(CurLoc), Flags,
|
||||||
CGM.getLangOpts().Optimize,
|
CGM.getLangOpts().Optimize,
|
||||||
Fn, TParamsArray, SPDecl);
|
Fn, TParamsArray, SPDecl);
|
||||||
|
if (HasDecl)
|
||||||
|
DeclCache.insert(std::make_pair(D->getCanonicalDecl(), llvm::WeakVH(SP)));
|
||||||
|
|
||||||
// Push function on region stack.
|
// Push function on region stack.
|
||||||
llvm::MDNode *SPN = SP;
|
llvm::MDNode *SPN = SP;
|
||||||
|
@ -2875,10 +2888,11 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
|
||||||
LinkageName = StringRef();
|
LinkageName = StringRef();
|
||||||
llvm::DIDescriptor DContext =
|
llvm::DIDescriptor DContext =
|
||||||
getContextDescriptor(dyn_cast<Decl>(D->getDeclContext()));
|
getContextDescriptor(dyn_cast<Decl>(D->getDeclContext()));
|
||||||
DBuilder.createStaticVariable(DContext, DeclName, LinkageName,
|
llvm::DIGlobalVariable GV = DBuilder.createStaticVariable(DContext, DeclName, LinkageName,
|
||||||
Unit, LineNo, getOrCreateType(T, Unit),
|
Unit, LineNo, getOrCreateType(T, Unit),
|
||||||
Var->hasInternalLinkage(), Var,
|
Var->hasInternalLinkage(), Var,
|
||||||
getStaticDataMemberDeclaration(D));
|
getStaticDataMemberDeclaration(D));
|
||||||
|
DeclCache.insert(std::make_pair(D->getCanonicalDecl(), llvm::WeakVH(GV)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitGlobalVariable - Emit information about an objective-c interface.
|
/// EmitGlobalVariable - Emit information about an objective-c interface.
|
||||||
|
@ -2923,22 +2937,38 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD,
|
||||||
// Do not use DIGlobalVariable for enums.
|
// Do not use DIGlobalVariable for enums.
|
||||||
if (Ty.getTag() == llvm::dwarf::DW_TAG_enumeration_type)
|
if (Ty.getTag() == llvm::dwarf::DW_TAG_enumeration_type)
|
||||||
return;
|
return;
|
||||||
DBuilder.createStaticVariable(Unit, Name, Name, Unit,
|
llvm::DIGlobalVariable GV = DBuilder.createStaticVariable(Unit, Name, Name, Unit,
|
||||||
getLineNumber(VD->getLocation()),
|
getLineNumber(VD->getLocation()),
|
||||||
Ty, true, Init,
|
Ty, true, Init,
|
||||||
getStaticDataMemberDeclaration(VD));
|
getStaticDataMemberDeclaration(VD));
|
||||||
|
DeclCache.insert(std::make_pair(VD->getCanonicalDecl(), llvm::WeakVH(GV)));
|
||||||
|
}
|
||||||
|
|
||||||
|
llvm::DIScope CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
|
||||||
|
if (!LexicalBlockStack.empty())
|
||||||
|
return llvm::DIScope(LexicalBlockStack.back());
|
||||||
|
return getContextDescriptor(D);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGDebugInfo::EmitUsingDirective(const UsingDirectiveDecl &UD) {
|
void CGDebugInfo::EmitUsingDirective(const UsingDirectiveDecl &UD) {
|
||||||
llvm::DIScope Scope =
|
|
||||||
LexicalBlockStack.empty()
|
|
||||||
? getContextDescriptor(cast<Decl>(UD.getDeclContext()))
|
|
||||||
: llvm::DIScope(LexicalBlockStack.back());
|
|
||||||
DBuilder.createImportedModule(
|
DBuilder.createImportedModule(
|
||||||
Scope, getOrCreateNameSpace(UD.getNominatedNamespace()),
|
getCurrentContextDescriptor(cast<Decl>(UD.getDeclContext())),
|
||||||
|
getOrCreateNameSpace(UD.getNominatedNamespace()),
|
||||||
getLineNumber(UD.getLocation()));
|
getLineNumber(UD.getLocation()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CGDebugInfo::EmitUsingDecl(const UsingDecl &UD) {
|
||||||
|
assert(UD.shadow_size() &&
|
||||||
|
"We shouldn't be codegening an invalid UsingDecl containing no decls");
|
||||||
|
// Emitting one decl is sufficient - debuggers can detect that this is an
|
||||||
|
// overloaded name & provide lookup for all the overloads.
|
||||||
|
const UsingShadowDecl &USD = **UD.shadow_begin();
|
||||||
|
if (llvm::DIDescriptor Target = getDeclarationOrDefinition(USD.getUnderlyingDecl()))
|
||||||
|
DBuilder.createImportedDeclaration(
|
||||||
|
getCurrentContextDescriptor(cast<Decl>(USD.getDeclContext())), Target,
|
||||||
|
getLineNumber(USD.getLocation()));
|
||||||
|
}
|
||||||
|
|
||||||
/// getOrCreateNamesSpace - Return namespace descriptor for the given
|
/// getOrCreateNamesSpace - Return namespace descriptor for the given
|
||||||
/// namespace decl.
|
/// namespace decl.
|
||||||
llvm::DINameSpace
|
llvm::DINameSpace
|
||||||
|
|
|
@ -35,6 +35,7 @@ namespace clang {
|
||||||
class ObjCIvarDecl;
|
class ObjCIvarDecl;
|
||||||
class ClassTemplateSpecializationDecl;
|
class ClassTemplateSpecializationDecl;
|
||||||
class GlobalDecl;
|
class GlobalDecl;
|
||||||
|
class UsingDecl;
|
||||||
|
|
||||||
namespace CodeGen {
|
namespace CodeGen {
|
||||||
class CodeGenModule;
|
class CodeGenModule;
|
||||||
|
@ -94,6 +95,7 @@ class CGDebugInfo {
|
||||||
|
|
||||||
llvm::DenseMap<const char *, llvm::WeakVH> DIFileCache;
|
llvm::DenseMap<const char *, llvm::WeakVH> DIFileCache;
|
||||||
llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache;
|
llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache;
|
||||||
|
llvm::DenseMap<const Decl *, llvm::WeakVH> DeclCache;
|
||||||
llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache;
|
llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache;
|
||||||
llvm::DenseMap<const Decl *, llvm::WeakVH> StaticDataMemberCache;
|
llvm::DenseMap<const Decl *, llvm::WeakVH> StaticDataMemberCache;
|
||||||
|
|
||||||
|
@ -265,6 +267,9 @@ public:
|
||||||
/// \brief - Emit C++ using directive.
|
/// \brief - Emit C++ using directive.
|
||||||
void EmitUsingDirective(const UsingDirectiveDecl &UD);
|
void EmitUsingDirective(const UsingDirectiveDecl &UD);
|
||||||
|
|
||||||
|
/// \brief - Emit C++ using declaration.
|
||||||
|
void EmitUsingDecl(const UsingDecl &UD);
|
||||||
|
|
||||||
/// getOrCreateRecordType - Emit record type's standalone debug info.
|
/// getOrCreateRecordType - Emit record type's standalone debug info.
|
||||||
llvm::DIType getOrCreateRecordType(QualType Ty, SourceLocation L);
|
llvm::DIType getOrCreateRecordType(QualType Ty, SourceLocation L);
|
||||||
|
|
||||||
|
@ -286,6 +291,8 @@ private:
|
||||||
/// getContextDescriptor - Get context info for the decl.
|
/// getContextDescriptor - Get context info for the decl.
|
||||||
llvm::DIScope getContextDescriptor(const Decl *Decl);
|
llvm::DIScope getContextDescriptor(const Decl *Decl);
|
||||||
|
|
||||||
|
llvm::DIScope getCurrentContextDescriptor(const Decl *Decl);
|
||||||
|
|
||||||
/// createRecordFwdDecl - Create a forward decl for a RecordType in a given
|
/// createRecordFwdDecl - Create a forward decl for a RecordType in a given
|
||||||
/// context.
|
/// context.
|
||||||
llvm::DIType createRecordFwdDecl(const RecordDecl *, llvm::DIDescriptor);
|
llvm::DIType createRecordFwdDecl(const RecordDecl *, llvm::DIDescriptor);
|
||||||
|
@ -329,6 +336,10 @@ private:
|
||||||
llvm::DIType CreateMemberType(llvm::DIFile Unit, QualType FType,
|
llvm::DIType CreateMemberType(llvm::DIFile Unit, QualType FType,
|
||||||
StringRef Name, uint64_t *Offset);
|
StringRef Name, uint64_t *Offset);
|
||||||
|
|
||||||
|
/// \brief Retrieve the DIDescriptor, if any, for the canonical form of this
|
||||||
|
/// declaration.
|
||||||
|
llvm::DIDescriptor getDeclarationOrDefinition(const Decl *D);
|
||||||
|
|
||||||
/// getFunctionDeclaration - Return debug info descriptor to describe method
|
/// getFunctionDeclaration - Return debug info descriptor to describe method
|
||||||
/// declaration for the given method definition.
|
/// declaration for the given method definition.
|
||||||
llvm::DISubprogram getFunctionDeclaration(const Decl *D);
|
llvm::DISubprogram getFunctionDeclaration(const Decl *D);
|
||||||
|
|
|
@ -72,14 +72,13 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
|
||||||
case Decl::Block:
|
case Decl::Block:
|
||||||
case Decl::Captured:
|
case Decl::Captured:
|
||||||
case Decl::ClassScopeFunctionSpecialization:
|
case Decl::ClassScopeFunctionSpecialization:
|
||||||
|
case Decl::UsingShadow:
|
||||||
llvm_unreachable("Declaration should not be in declstmts!");
|
llvm_unreachable("Declaration should not be in declstmts!");
|
||||||
case Decl::Function: // void X();
|
case Decl::Function: // void X();
|
||||||
case Decl::Record: // struct/union/class X;
|
case Decl::Record: // struct/union/class X;
|
||||||
case Decl::Enum: // enum X;
|
case Decl::Enum: // enum X;
|
||||||
case Decl::EnumConstant: // enum ? { X = ? }
|
case Decl::EnumConstant: // enum ? { X = ? }
|
||||||
case Decl::CXXRecord: // struct/union/class X; [C++]
|
case Decl::CXXRecord: // struct/union/class X; [C++]
|
||||||
case Decl::Using: // using X; [C++]
|
|
||||||
case Decl::UsingShadow:
|
|
||||||
case Decl::NamespaceAlias:
|
case Decl::NamespaceAlias:
|
||||||
case Decl::StaticAssert: // static_assert(X, ""); [C++0x]
|
case Decl::StaticAssert: // static_assert(X, ""); [C++0x]
|
||||||
case Decl::Label: // __label__ x;
|
case Decl::Label: // __label__ x;
|
||||||
|
@ -89,6 +88,10 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
|
||||||
// None of these decls require codegen support.
|
// None of these decls require codegen support.
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
case Decl::Using: // using X; [C++]
|
||||||
|
if (CGDebugInfo *DI = getDebugInfo())
|
||||||
|
DI->EmitUsingDecl(cast<UsingDecl>(D));
|
||||||
|
return;
|
||||||
case Decl::UsingDirective: // using namespace X; [C++]
|
case Decl::UsingDirective: // using namespace X; [C++]
|
||||||
if (CGDebugInfo *DI = getDebugInfo())
|
if (CGDebugInfo *DI = getDebugInfo())
|
||||||
DI->EmitUsingDirective(cast<UsingDirectiveDecl>(D));
|
DI->EmitUsingDirective(cast<UsingDirectiveDecl>(D));
|
||||||
|
|
|
@ -4,6 +4,10 @@ namespace A {
|
||||||
#line 1 "foo.cpp"
|
#line 1 "foo.cpp"
|
||||||
namespace B {
|
namespace B {
|
||||||
int i;
|
int i;
|
||||||
|
void f1() { }
|
||||||
|
void f1(int) { }
|
||||||
|
struct foo;
|
||||||
|
struct bar { };
|
||||||
}
|
}
|
||||||
using namespace B;
|
using namespace B;
|
||||||
}
|
}
|
||||||
|
@ -16,22 +20,37 @@ int func(bool b) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
using namespace A;
|
using namespace A;
|
||||||
return B::i;
|
using B::foo;
|
||||||
|
using B::bar;
|
||||||
|
using B::f1;
|
||||||
|
using B::i;
|
||||||
|
bar x;
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This should work even if 'i' and 'func' were declarations & not definitions,
|
||||||
|
// but it doesn't yet.
|
||||||
|
|
||||||
// CHECK: [[CU:![0-9]*]] = {{.*}}[[MODULES:![0-9]*]], metadata !""} ; [ DW_TAG_compile_unit ]
|
// CHECK: [[CU:![0-9]*]] = {{.*}}[[MODULES:![0-9]*]], metadata !""} ; [ DW_TAG_compile_unit ]
|
||||||
// CHECK: [[FILE:![0-9]*]] {{.*}}debug-info-namespace.cpp"
|
// CHECK: [[FILE:![0-9]*]] {{.*}}debug-info-namespace.cpp"
|
||||||
// CHECK: [[FUNC:![0-9]*]] {{.*}} ; [ DW_TAG_subprogram ] [line 9] [def] [func]
|
// CHECK: [[NS:![0-9]*]] = {{.*}}, metadata [[FILE2:![0-9]*]], metadata [[CTXT:![0-9]*]], {{.*}} ; [ DW_TAG_namespace ] [B] [line 1]
|
||||||
// CHECK: [[FILE2:![0-9]*]]} ; [ DW_TAG_file_type ] [{{.*}}foo.cpp]
|
|
||||||
// CHECK: [[VAR:![0-9]*]] = {{.*}}, metadata [[NS:![0-9]*]], metadata !"i", {{.*}} ; [ DW_TAG_variable ] [i]
|
|
||||||
// CHECK: [[NS]] = {{.*}}, metadata [[FILE2]], metadata [[CTXT:![0-9]*]], {{.*}} ; [ DW_TAG_namespace ] [B] [line 1]
|
|
||||||
// CHECK: [[CTXT]] = {{.*}}, metadata [[FILE]], null, {{.*}} ; [ DW_TAG_namespace ] [A] [line 3]
|
// CHECK: [[CTXT]] = {{.*}}, metadata [[FILE]], null, {{.*}} ; [ DW_TAG_namespace ] [A] [line 3]
|
||||||
// CHECK: [[MODULES]] = metadata !{metadata [[M1:![0-9]*]], metadata [[M2:![0-9]*]], metadata [[M3:![0-9]*]], metadata [[M4:![0-9]*]]}
|
// CHECK: [[F1:![0-9]*]] {{.*}} ; [ DW_TAG_subprogram ] [line 4] [def] [f1]
|
||||||
// CHECK: [[M1]] = metadata !{i32 {{[0-9]*}}, metadata [[CTXT]], metadata [[NS]], i32 4} ; [ DW_TAG_imported_module ]
|
// CHECK: [[FUNC:![0-9]*]] {{.*}} ; [ DW_TAG_subprogram ] [line 13] [def] [func]
|
||||||
// CHECK: [[M2]] = metadata !{i32 {{[0-9]*}}, metadata [[CU]], metadata [[CTXT]], i32 7} ; [ DW_TAG_imported_module ]
|
// CHECK: [[FILE2]]} ; [ DW_TAG_file_type ] [{{.*}}foo.cpp]
|
||||||
// CHECK: [[M3]] = metadata !{i32 {{[0-9]*}}, metadata [[LEX:![0-9]*]], metadata [[NS]], i32 11} ; [ DW_TAG_imported_module ]
|
// CHECK: [[I:![0-9]*]] = {{.*}}, metadata [[NS]], metadata !"i", {{.*}} ; [ DW_TAG_variable ] [i]
|
||||||
// CHECK: [[LEX]] = metadata !{i32 {{[0-9]*}}, metadata [[FILE2]], metadata [[FUNC]], i32 10, i32 0, i32 0} ; [ DW_TAG_lexical_block ]
|
// CHECK: [[MODULES]] = metadata !{metadata [[M1:![0-9]*]], metadata [[M2:![0-9]*]], metadata [[M3:![0-9]*]], metadata [[M4:![0-9]*]], metadata [[M5:![0-9]*]], metadata [[M6:![0-9]*]], metadata [[M7:![0-9]*]], metadata [[M8:![0-9]*]]}
|
||||||
// CHECK: [[M4]] = metadata !{i32 {{[0-9]*}}, metadata [[FUNC]], metadata [[CTXT]], i32 14} ; [ DW_TAG_imported_module ]
|
// CHECK: [[M1]] = metadata !{i32 {{[0-9]*}}, metadata [[CTXT]], metadata [[NS]], i32 8} ; [ DW_TAG_imported_module ]
|
||||||
|
// CHECK: [[M2]] = metadata !{i32 {{[0-9]*}}, metadata [[CU]], metadata [[CTXT]], i32 11} ; [ DW_TAG_imported_module ]
|
||||||
|
// CHECK: [[M3]] = metadata !{i32 {{[0-9]*}}, metadata [[LEX:![0-9]*]], metadata [[NS]], i32 15} ; [ DW_TAG_imported_module ]
|
||||||
|
// CHECK: [[LEX]] = metadata !{i32 {{[0-9]*}}, metadata [[FILE2]], metadata [[FUNC]], i32 14, i32 0, i32 0} ; [ DW_TAG_lexical_block ]
|
||||||
|
// CHECK: [[M4]] = metadata !{i32 {{[0-9]*}}, metadata [[FUNC]], metadata [[CTXT]], i32 18} ; [ DW_TAG_imported_module ]
|
||||||
|
// CHECK: [[M5]] = metadata !{i32 {{[0-9]*}}, metadata [[FUNC]], metadata [[FOO:![0-9]*]], i32 19} ; [ DW_TAG_imported_declaration ]
|
||||||
|
// CHECK: [[FOO]] {{.*}} ; [ DW_TAG_structure_type ] [foo] [line 5, size 0, align 0, offset 0] [fwd] [from ]
|
||||||
|
// CHECK: [[M6]] = metadata !{i32 {{[0-9]*}}, metadata [[FUNC]], metadata [[BAR:![0-9]*]], i32 20} ; [ DW_TAG_imported_declaration ]
|
||||||
|
// CHECK: [[BAR]] {{.*}} ; [ DW_TAG_structure_type ] [bar] [line 6, {{.*}}] [from ]
|
||||||
|
// CHECK: [[M7]] = metadata !{i32 {{[0-9]*}}, metadata [[FUNC]], metadata [[F1]], i32 21} ; [ DW_TAG_imported_declaration ]
|
||||||
|
// CHECK: [[M8]] = metadata !{i32 {{[0-9]*}}, metadata [[FUNC]], metadata [[I]], i32 22} ; [ DW_TAG_imported_declaration ]
|
||||||
|
|
||||||
// FIXME: It is confused on win32 to generate file entry when dosish filename is given.
|
// FIXME: It is confused on win32 to generate file entry when dosish filename is given.
|
||||||
// REQUIRES: shell
|
// REQUIRES: shell
|
||||||
|
|
Loading…
Reference in New Issue