This is in continuation with the patch posted earlier for bug-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)
Nit: The LLVM coding style wants all comments to be full sentences, including a trailing .