[PATCH] D120989: Support debug info for alias variable

Kavitha Natarajan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 4 04:29:21 PST 2022


kavitha-natarajan created this revision.
kavitha-natarajan added reviewers: kamleshbhalui, umesh.kalappa0, probinson, dblaikie.
kavitha-natarajan added a project: debug-info.
Herald added a subscriber: jeroen.dobbelaere.
Herald added a project: All.
kavitha-natarajan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is in continuation with the patch posted earlier for bug-50052 <https://bugs.llvm.org/show_bug.cgi?id=50052>:

https://reviews.llvm.org/D103131

For the below testcase, when compiled with clang compiler, debugger is not able to print alias variable type or value. 
$ cat test.c
int oldname = 1;
extern int newname attribute((alias("oldname")));

int main ()
{

  return 0;

}

$ clang -g -O0 test.c

$ gdb a.out
(gdb) ptype oldname
type = int
(gdb) ptype newname
type = <data variable, no debug info>
(gdb) p oldname
$1 = 1
(gdb) p newname
'newname' has unknown type; cast it to its declared type

This is because clang is not emitting dwarf information for alias variable. The above mentioned patch supports clang to emit debug info for alias variable as imported entity (DW_TAG_imported_declaration). However, gdb cannot handle the imported declaration for alias variables. GCC emits debug info for alias variables as DW_TAG_variable which gdb can handle. The discussions in the above bug report and patch review links talk about why it is appropriate to emit alias variable as DW_TAG_imported_declaration rather than DW_TAG_variable. Refer section "3.2.3 Imported (or Renamed) Declaration Entries" in DWARF 5 specification.

In the clang patch, CGDebugInfo.cpp:EmitGlobalAlias() function is rewritten to handle nested (recursive) imported declaration and developed a testcase as well. A corresponding gdb patch that can handle DW_TAG_imported_declaration as alias variables is also developed and will be posted to gdb community for review in parallel.

After clang and gdb fixes:

$ gdb a.out
(gdb) ptype oldname
type = int
(gdb) ptype newname
type = int
(gdb) p oldname
$1 = 1
(gdb) p newname
$2 = 1
(gdb)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120989

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/debug-info-alias.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120989.412961.patch
Type: text/x-patch
Size: 6242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220304/9b7cadaf/attachment.bin>


More information about the cfe-commits mailing list