[gdb/exp] Interpret size of vla with unknown size as <optimized out>
authorTom de Vries <tdevries@suse.de>
Wed, 18 Jul 2018 11:38:35 +0000 (13:38 +0200)
committerTom de Vries <tdevries@suse.de>
Sat, 28 Jul 2018 08:16:30 +0000 (10:16 +0200)
commit37cc0caeca4c9a8552370040f4cfeaeceaa03369
tree90e1faa39ff376464a5ae52516b5e1009564c387
parent5842d7025f1307a2fb37ae5c4f25fdacfb827d35
[gdb/exp] Interpret size of vla with unknown size as <optimized out>

At -O3 -g -gstrict-dwarf, gcc generates for an optimized out vla 'a' a
DW_TAG_variable with type DW_TAG_array_type containing one
DW_TAG_subrange_type, but without DW_AT_upper_bound or DW_AT_count, which
makes the upper bound value 'unknown':
...
.uleb128 0x15   # (DIE (0x161) DW_TAG_variable)
        .long   0xec    # DW_AT_abstract_origin
        .long   0x170   # DW_AT_type
...
        .uleb128 0xa    # (DIE (0x170) DW_TAG_array_type)
        .long   0x110   # DW_AT_type
        .long   0x17f   # DW_AT_sibling
        .uleb128 0x17   # (DIE (0x179) DW_TAG_subrange_type)
        .long   0xc6    # DW_AT_type
        .byte   0       # end of children of DIE 0x170
...

But gdb prints '0' for the size of 'a':
...
/gdb ./vla-1.exe -batch -ex "b f1" -ex "run" -ex "p sizeof(a)"
Breakpoint 1 at 0x4004c0: f1. (2 locations)

Breakpoint 1, f1 (i=<optimized out>) at vla-1.c:18
18      }
$1 = 0
...
while <optimized out> would be more appropriate.

This patch fixes that in evaluate_subexp_for_sizeof.

Build and reg-tested on x86_64-linux.

2018-07-28  Tom de Vries  <tdevries@suse.de>

* eval.c (evaluate_subexp_for_sizeof): Interpret size of dynamic type
with undefined upper bound as <optimized out>.

* gdb.base/vla-optimized-out-o3-strict.exp: New file.
gdb/ChangeLog
gdb/eval.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/vla-optimized-out-o3-strict.exp [new file with mode: 0644]