Skip to content

Debug info generated for arrays is not what GDB expects (not as good as GCC's) #29901

Open
@cmtice

Description

@cmtice
Bugzilla Link 30553
Version trunk
OS Linux
Blocks #24719
CC @adrian-prantl,@Theodor,@fhahn,@fredriss,@hfinkel,@CarlosAlbertoEnciso,@pogo59,@sdesmalen-arm,@vedantk
Fixed by commit(s) 323952

Extended Description

There is a very annoying difference in the way GCC & LLVM generate debug information for arrays. The symptom is that when GDB is asked to print an array-type variable that was compiled with GCC, it shows the array and it's contents, while when asked to print the same variable for the same program, compiled by LLVM, all you get is a pointer:

GCC version:
(gdb) print vla
$1 = {5, 7, 9}
(gdb) print vlaref
$2 = (int (&)[3]) @​0x7fffffffdc30: {5, 7, 9}
(gdb) print vlaref2
$3 = (const vlareftypedef) @​0x7fffffffdc30: {5, 7, 9}

LLVM version:
(gdb) print vla
$1 = 0x7fffffffdc20
(gdb) print vlaref
$2 = (int (&)[]) @​0x7fffffffdc20: 0x7fffffffdc20
(gdb) print vlaref2
$3 = (vlareftypedef) @​0x7fffffffdc20: 0x7fffffffdc20

LLVM can't even tell gdb the length of the array, much less its contents!

In discussing this with Eric Christopher, he said:

A simple testcase is:

int foo(int a) {
int vla[a];
int sum = 0;

for (int i = 0; i < a; ++i)
vla[i] = i;
for (int j = 0; j < a; ++j)
sum += vla[j];

return sum;
}

int main (void) {
return foo(4);
}

What's happening is that we're not adding a DW_AT_upper_bound of type DW_FORM_expr/exprloc with the upper bound of the array.

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzillaclangClang issues not falling into any other category

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions