[gdb/exp] Fix printing of type of optimized out vla
Consider this snippet from gcc/testsuite/gcc.dg/guality/vla-1.c: ... int __attribute__((noinline)) f1 (int i) { char a[i + 1]; a[0] = 5; /* { dg-final { gdb-test .+1 "i" "5" } } */ return a[0]; /* { dg-final { gdb-test . "sizeof (a)" "6" } } */ } ... When we compile the test-case with -O1 -g, and query the size of optimized out vla 'a', we get: ... $ ./gdb -batch -ex "b f1" -ex "r" -ex "p sizeof (a)" vla-1.exe Breakpoint 1 at 0x4004a8: file vla-1.c, line 17. Breakpoint 1, f1 (i=i@entry=5) at vla-1.c:17 17 return a[0]; $1 = 0 ... while we expect a size of '6'. The problem is that default_read_var_value does not resolve the dynamic type of a variable if the variable is optimized out. This patch fixes that, and consequently gdb prints '6', as expected. Tested on x86_64-linux. 2018-07-18 Tom de Vries <tdevries@suse.de> * findvar.c (default_read_var_value): Also resolve dynamic type for LOC_OPTIMIZED_OUT vars. * gdb.base/vla-optimized-out.c: New test. * gdb.base/vla-optimized-out.exp: New file.
This commit is contained in:
parent
6592ceed48
commit
42dc7699a2
|
@ -1,3 +1,8 @@
|
||||||
|
2018-07-18 Tom de Vries <tdevries@suse.de>
|
||||||
|
|
||||||
|
* findvar.c (default_read_var_value): Also resolve dynamic type for
|
||||||
|
LOC_OPTIMIZED_OUT vars.
|
||||||
|
|
||||||
2018-07-18 Maciej W. Rozycki <macro@mips.com>
|
2018-07-18 Maciej W. Rozycki <macro@mips.com>
|
||||||
|
|
||||||
* mips-tdep.c (micromips_next_pc): Add SYSCALL instruction
|
* mips-tdep.c (micromips_next_pc): Add SYSCALL instruction
|
||||||
|
|
|
@ -789,6 +789,8 @@ default_read_var_value (struct symbol *var, const struct block *var_block,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LOC_OPTIMIZED_OUT:
|
case LOC_OPTIMIZED_OUT:
|
||||||
|
if (is_dynamic_type (type))
|
||||||
|
type = resolve_dynamic_type (type, NULL, /* Unused address. */ 0);
|
||||||
return allocate_optimized_out_value (type);
|
return allocate_optimized_out_value (type);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
2018-07-18 Tom de Vries <tdevries@suse.de>
|
||||||
|
|
||||||
|
* gdb.base/vla-optimized-out.c: New test.
|
||||||
|
* gdb.base/vla-optimized-out.exp: New file.
|
||||||
|
|
||||||
2018-07-13 Sergio Durigan Junior <sergiodj@redhat.com>
|
2018-07-13 Sergio Durigan Junior <sergiodj@redhat.com>
|
||||||
|
|
||||||
* lib/gdbserver-support.exp (gdbserver_start): Expect for the
|
* lib/gdbserver-support.exp (gdbserver_start): Expect for the
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* This testcase is part of GDB, the GNU debugger.
|
||||||
|
|
||||||
|
Copyright 2018 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
int __attribute__((noinline, noclone))
|
||||||
|
f1 (int i)
|
||||||
|
{
|
||||||
|
char a[i + 1];
|
||||||
|
a[0] = 5;
|
||||||
|
return a[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (void)
|
||||||
|
{
|
||||||
|
volatile int j;
|
||||||
|
int i = 5;
|
||||||
|
asm volatile ("" : "=r" (i) : "0" (i));
|
||||||
|
j = f1 (i);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
# Copyright 2018 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Check whether we can determine the size of an optimized-out vla.
|
||||||
|
|
||||||
|
standard_testfile
|
||||||
|
|
||||||
|
if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
|
||||||
|
{debug optimize=-O1}] } {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
proc vla_optimized_out { } {
|
||||||
|
if ![runto f1] {
|
||||||
|
fail "can't run to f1"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
gdb_test "p a" \
|
||||||
|
{ = <optimized out>} \
|
||||||
|
"printed optimized out vla"
|
||||||
|
|
||||||
|
gdb_test "p sizeof (a)" \
|
||||||
|
{ = 6} \
|
||||||
|
"printed size of optimized out vla"
|
||||||
|
}
|
||||||
|
|
||||||
|
vla_optimized_out
|
Loading…
Reference in New Issue