From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9616 invoked by alias); 13 Jul 2018 06:16:54 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 9583 invoked by uid 89); 13 Jul 2018 06:16:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,SPF_PASS autolearn=ham version=3.3.2 spammy=20180703 X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Jul 2018 06:16:47 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 4AFD9AD45 for ; Fri, 13 Jul 2018 06:16:45 +0000 (UTC) Subject: [PING][PATCH][gdb/exp] Fix printing of type of optimized out vla From: Tom de Vries To: gdb-patches@sourceware.org References: <20180703141821.wzcayjt4ykepdotg@delia> Message-ID: <0b65bc01-38c9-d982-9f59-faae87a90c08@suse.de> Date: Fri, 13 Jul 2018 06:16:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180703141821.wzcayjt4ykepdotg@delia> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2018-07/txt/msg00375.txt.bz2 On 07/03/2018 04:18 PM, Tom de Vries wrote: > Hi, > > 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. > > OK for trunk? > > Thanks, > - Tom > > [gdb/exp] Fix printing of type of optimized out vla > > 2018-07-03 Tom de Vries > > * 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. > > --- > gdb/findvar.c | 2 ++ > gdb/testsuite/gdb.base/vla-optimized-out.c | 34 +++++++++++++++++++++++ > gdb/testsuite/gdb.base/vla-optimized-out.exp | 40 ++++++++++++++++++++++++++++ > 3 files changed, 76 insertions(+) > > diff --git a/gdb/findvar.c b/gdb/findvar.c > index 8ad5e25cb2..ebaff923a1 100644 > --- a/gdb/findvar.c > +++ b/gdb/findvar.c > @@ -789,6 +789,8 @@ default_read_var_value (struct symbol *var, const struct block *var_block, > break; > > case LOC_OPTIMIZED_OUT: > + if (is_dynamic_type (type)) > + type = resolve_dynamic_type (type, NULL, /* Unused address. */ 0); > return allocate_optimized_out_value (type); > > default: > diff --git a/gdb/testsuite/gdb.base/vla-optimized-out.c b/gdb/testsuite/gdb.base/vla-optimized-out.c > new file mode 100644 > index 0000000000..913e8ea867 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/vla-optimized-out.c > @@ -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 . */ > + > +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; > +} > diff --git a/gdb/testsuite/gdb.base/vla-optimized-out.exp b/gdb/testsuite/gdb.base/vla-optimized-out.exp > new file mode 100644 > index 0000000000..39abb795c8 > --- /dev/null > +++ b/gdb/testsuite/gdb.base/vla-optimized-out.exp > @@ -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 . > + > +# 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" \ > + { = } \ > + "printed optimized out vla" > + > + gdb_test "p sizeof (a)" \ > + { = 6} \ > + "printed size of optimized out vla" > +} > + > +vla_optimized_out >