[PATCH] D103131: support debug info for alias variable
kamlesh kumar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 25 17:51:06 PDT 2021
kamleshbhalui created this revision.
kamleshbhalui added reviewers: dblaikie, aprantl, probinson.
kamleshbhalui added a project: LLVM.
Herald added a subscriber: jeroen.dobbelaere.
kamleshbhalui requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
consider below test demonstration
$cat test.c
int oldname = 1;
extern int newname __attribute__((alias("oldname")));
$clang -g -O0 test.c
$gdb a.out
(gdb) pt oldname
type = int
(gdb) pt newname
type = <data variable, no debug info>
(gdb) p newname
'newname' has unknown type; cast it to its declared type
debugger is unable to print newname types and value because clang does not emit debug info for newname.
This patch supports having debug info for alias variable as imported entity.
Fixes PR50052.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D103131
Files:
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/debug-info-alias.c
Index: clang/test/CodeGen/debug-info-alias.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/debug-info-alias.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-linux-unknown %s -o - | FileCheck %s
+
+// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope:{{.*}}, entity: ![[VAR:[0-9]+]]
+// CHECK: ![[VAR]] = !DIGlobalVariable(name: "newname"
+
+int oldname = 1;
+extern int newname __attribute__((alias("oldname")));
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4922,6 +4922,13 @@
setTLSMode(GA, *VD);
SetCommonAttributes(GD, GA);
+
+ // Emit global alias debug information.
+ if (const auto *VD = dyn_cast<VarDecl>(D)) {
+ if (CGDebugInfo *DI = getModuleDebugInfo())
+ if (getCodeGenOpts().hasReducedDebugInfo())
+ DI->EmitGlobalAlias(GA, VD);
+ }
}
void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
Index: clang/lib/CodeGen/CGDebugInfo.h
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -493,6 +493,9 @@
/// Emit information about an external variable.
void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
+ /// Emit information about global alias.
+ void EmitGlobalAlias(llvm::GlobalAlias *GA, const VarDecl *Decl);
+
/// Emit C++ using directive.
void EmitUsingDirective(const UsingDirectiveDecl &UD);
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4945,6 +4945,19 @@
Var->addDebugInfo(GVE);
}
+void CGDebugInfo::EmitGlobalAlias(llvm::GlobalAlias *Var, const VarDecl *D) {
+ if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
+ return;
+
+ llvm::DIFile *Unit = getOrCreateFile(D->getLocation());
+ llvm::DIScope *DContext = getDeclContextDescriptor(D);
+ if (llvm::DINode *Target = getDeclarationOrDefinition(D)) {
+ auto Loc = D->getLocation();
+ DBuilder.createImportedDeclaration(DContext, Target, Unit,
+ getLineNumber(Loc));
+ }
+}
+
llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
if (!LexicalBlockStack.empty())
return LexicalBlockStack.back();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103131.347831.patch
Type: text/x-patch
Size: 2522 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210526/353131b0/attachment.bin>
More information about the cfe-commits
mailing list