From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25985 invoked by alias); 4 Dec 2002 23:29:06 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 25977 invoked from network); 4 Dec 2002 23:29:04 -0000 Received: from unknown (HELO touchme.toronto.redhat.com) (216.138.202.10) by sources.redhat.com with SMTP; 4 Dec 2002 23:29:04 -0000 Received: from redhat.com (totem.toronto.redhat.com [172.16.14.242]) by touchme.toronto.redhat.com (Postfix) with ESMTP id 58F7B80023F; Wed, 4 Dec 2002 18:29:04 -0500 (EST) Message-ID: <3DEE8FC0.5090808@redhat.com> Date: Wed, 04 Dec 2002 15:29:00 -0000 From: Fernando Nasser Organization: Red Hat , Inc. - Toronto User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.1) Gecko/20020827 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Andrew Cagney Cc: gdb-patches@sources.redhat.com Subject: Re: [rfa/testsuite] Test GDB's ability to store values in registers References: <3DE51731.9040508@redhat.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2002-12/txt/msg00126.txt.bz2 Andrew Cagney wrote:> Hello, > > This patch got lost in an earlier thread. It adds a testcase to check > that GDB can store values in register variables. It required a number > of fixes, but they are already in. > > Fernando, ok? > Andrew > Sure. Thanks for the new test. > > ------------------------------------------------------------------------ > > 2002-11-02 Andrew Cagney > > * gdb.base/store.exp, gdb.base/store.c: New files. > > Index: gdb.base/store.c > =================================================================== > RCS file: gdb.base/store.c > diff -N gdb.base/store.c > --- /dev/null 1 Jan 1970 00:00:00 -0000 > +++ gdb.base/store.c 27 Nov 2002 19:01:51 -0000 > @@ -0,0 +1,250 @@ > +/* Check that GDB can correctly update a value, living in a register, > + in the target. This pretty much relies on the compiler taking heed > + of requests for values to be stored in registers. */ > + > +static char > +add_char (register char u, register char v) > +{ > + return u + v; > +} > + > +static short > +add_short (register short u, register short v) > +{ > + return u + v; > +} > + > +static int > +add_int (register int u, register int v) > +{ > + return u + v; > +} > + > +static long > +add_long (register long u, register long v) > +{ > + return u + v; > +} > + > +static float > +add_float (register float u, register float v) > +{ > + return u + v; > +} > + > +static double > +add_double (register double u, register double v) > +{ > + return u + v; > +} > + > +/* */ > + > +static char > +wack_char (register char u, register char v) > +{ > + register char l = u; > + l = add_char (l, v); > + return l; > +} > + > +static short > +wack_short (register short u, register short v) > +{ > + register short l = u; > + l = add_short (l, v); > + return l; > +} > + > +static int > +wack_int (register int u, register int v) > +{ > + register int l = u; > + l = add_int (l, v); > + return l; > +} > + > +static long > +wack_long (register long u, register long v) > +{ > + register long l = u; > + l = add_long (l, v); > + return l; > +} > + > +static float > +wack_float (register float u, register float v) > +{ > + register float l = u; > + l = add_float (l, v); > + return l; > +} > + > +static double > +wack_double (register double u, register double v) > +{ > + register double l = u; > + l = add_double (l, v); > + return l; > +} > + > +struct s_1 { short s[1]; } z_1, s_1; > +struct s_2 { short s[2]; } z_2, s_2; > +struct s_3 { short s[3]; } z_3, s_3; > +struct s_4 { short s[4]; } z_4, s_4; > + > +static struct s_1 > +add_struct_1 (struct s_1 s) > +{ > + int i; > + for (i = 0; i < sizeof (s) / sizeof (s.s[0]); i++) > + { > + s.s[i] = s.s[i] + s.s[i]; > + } > + return s; > +} > + > +static struct s_2 > +add_struct_2 (struct s_2 s) > +{ > + int i; > + for (i = 0; i < sizeof (s) / sizeof (s.s[0]); i++) > + { > + s.s[i] = s.s[i] + s.s[i]; > + } > + return s; > +} > + > +static struct s_3 > +add_struct_3 (struct s_3 s) > +{ > + int i; > + for (i = 0; i < sizeof (s) / sizeof (s.s[0]); i++) > + { > + s.s[i] = s.s[i] + s.s[i]; > + } > + return s; > +} > + > +static struct s_4 > +add_struct_4 (struct s_4 s) > +{ > + int i; > + for (i = 0; i < sizeof (s) / sizeof (s.s[0]); i++) > + { > + s.s[i] = s.s[i] + s.s[i]; > + } > + return s; > +} > + > +static struct s_1 > +wack_struct_1 (void) > +{ > + int i; register struct s_1 u = z_1; > + for (i = 0; i < sizeof (s_1) / sizeof (s_1.s[0]); i++) { s_1.s[i] = i + 1; } > + u = add_struct_1 (u); > + return u; > +} > + > +static struct s_2 > +wack_struct_2 (void) > +{ > + int i; register struct s_2 u = z_2; > + for (i = 0; i < sizeof (s_2) / sizeof (s_2.s[0]); i++) { s_2.s[i] = i + 1; } > + u = add_struct_2 (u); > + return u; > +} > + > +static struct s_3 > +wack_struct_3 (void) > +{ > + int i; register struct s_3 u = z_3; > + for (i = 0; i < sizeof (s_3) / sizeof (s_3.s[0]); i++) { s_3.s[i] = i + 1; } > + u = add_struct_3 (u); > + return u; > +} > + > +static struct s_4 > +wack_struct_4 (void) > +{ > + int i; register struct s_4 u = z_4; > + for (i = 0; i < sizeof (s_4) / sizeof (s_4.s[0]); i++) { s_4.s[i] = i + 1; } > + u = add_struct_4 (u); > + return u; > +} > + > +/* */ > + > +struct f_1 {unsigned i:1;unsigned j:1;unsigned k:1; } f_1 = {1,1,1}, F_1; > +struct f_2 {unsigned i:2;unsigned j:2;unsigned k:2; } f_2 = {1,1,1}, F_2; > +struct f_3 {unsigned i:3;unsigned j:3;unsigned k:3; } f_3 = {1,1,1}, F_3; > +struct f_4 {unsigned i:4;unsigned j:4;unsigned k:4; } f_4 = {1,1,1}, F_4; > + > +static struct f_1 > +wack_field_1 (void) > +{ > + register struct f_1 u = f_1; > + return u; > +} > + > +static struct f_2 > +wack_field_2 (void) > +{ > + register struct f_2 u = f_2; > + return u; > +} > + > +static struct f_3 > +wack_field_3 (void) > +{ > + register struct f_3 u = f_3; > + return u; > +} > + > +static struct f_4 > +wack_field_4 (void) > +{ > + register struct f_4 u = f_4; > + return u; > +} > + > +/* */ > + > +int > +main () > +{ > + /* These calls are for current frame test. */ > + wack_char (1, 2); > + wack_short (1, 2); > + wack_int (1, 2); > + wack_long (1, 2); > + wack_float (1, 2); > + wack_double (1, 2); > + > + /* These calls are for up frame. */ > + wack_char (1, 2); > + wack_short (1, 2); > + wack_int (1, 2); > + wack_long (1, 2); > + wack_float (1, 2); > + wack_double (1, 2); > + > + /* These calls are for current frame test. */ > + wack_struct_1 (); > + wack_struct_2 (); > + wack_struct_3 (); > + wack_struct_4 (); > + > + /* These calls are for up frame. */ > + wack_struct_1 (); > + wack_struct_2 (); > + wack_struct_3 (); > + wack_struct_4 (); > + > + wack_field_1 (); > + wack_field_2 (); > + wack_field_3 (); > + wack_field_4 (); > + > + return 0; > +} > Index: gdb.base/store.exp > =================================================================== > RCS file: gdb.base/store.exp > diff -N gdb.base/store.exp > --- /dev/null 1 Jan 1970 00:00:00 -0000 > +++ gdb.base/store.exp 27 Nov 2002 19:01:51 -0000 > @@ -0,0 +1,171 @@ > +# Copyright 2002 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 2 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, write to the Free Software > +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. > + > +# Please email any bugs, comments, and/or additions to this file to: > +# bug-gdb@gnu.org > + > +if $tracelevel { > + strace $tracelevel > +} > + > +# > +# test running programs > +# > +set prms_id 0 > +set bug_id 0 > + > +set testfile "store" > +set srcfile ${testfile}.c > +set binfile ${objdir}/${subdir}/${testfile} > +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { > + gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." > +} > + > +if [get_compiler_info ${binfile}] { > + return -1; > +} > + > +gdb_exit > +gdb_start > +gdb_reinitialize_dir $srcdir/$subdir > +gdb_load ${binfile} > + > +# > +# set it up at a breakpoint so we can play with the variable values > +# > + > +if ![runto_main] then { > + perror "couldn't run to breakpoint" > + continue > +} > + > +# > + > +proc check_set { t old new add } { > + global gdb_prompt > + gdb_test "tbreak wack_${t}" > + gdb_test "continue" "register ${t} l = u;" "continue set ${t}" > + gdb_test "next" "l = add_${t} .l, v.;" "next ${t}" > + gdb_test "print l" " = ${old}" "print old ${t}" > + gdb_test "set variable l = 4" > + gdb_test "print l" " = ${new}" "print new ${t}" > + gdb_test "next" "return l;" > + gdb_test "print l" " = ${add}" "print add ${t}" > +} > + > +check_set "char" "1 ..001." "4 ..004." "6 ..006." > +check_set "short" "1" "4" "6" > +check_set "int" "1" "4" "6" > +check_set "long" "1" "4" "6" > +check_set "float" "1" "4" "6" > +check_set "double" "1" "4" "6" > + > +# > + > +proc up_set { t old new } { > + global gdb_prompt > + gdb_test "tbreak add_${t}" > + gdb_test "continue" "return u . v;" "continue up ${t}" > + gdb_test "up" "l = add_${t} .l, v.;" "up ${t}" > + gdb_test "print l" " = ${old}" "print old up ${t}" > + gdb_test "set variable l = 4" > + gdb_test "print l" " = ${new}" "print new up ${t}" > +} > + > +up_set "char" "1 ..001." "4 ..004." > +up_set "short" "1" "4" > +up_set "int" "1" "4" > +up_set "long" "1" "4" > +up_set "float" "1" "4" > +up_set "double" "1" "4" > + > +# > + > +proc check_struct { t old new } { > + global gdb_prompt > + gdb_test "tbreak wack_struct_${t}" > + gdb_test "continue" "int i; register struct s_${t} u = z_${t};" \ > + "continue set struct ${t}" > + gdb_test "next 2" "add_struct_${t} .u.;" > + gdb_test "print u" " = ${old}" "old check struct ${t}" > + gdb_test "set variable u = s_${t}" > + gdb_test "print u" " = ${new}" "new check struct ${t}" > +} > + > +check_struct "1" "{s = {0}}" "{s = {1}}" > +check_struct "2" "{s = {0, 0}}" "{s = {1, 2}}" > +check_struct "3" "{s = {0, 0, 0}}" "{s = {1, 2, 3}}" > +check_struct "4" "{s = {0, 0, 0, 0}}" "{s = {1, 2, 3, 4}}" > + > +proc up_struct { t old new } { > + global gdb_prompt > + gdb_test "tbreak add_struct_${t}" > + gdb_test "continue" "for .i = 0; i < sizeof .s. / sizeof .s.s.0..; i..." \ > + "continue up struct ${t}" > + gdb_test "up" "u = add_struct_${t} .u.;" "up struct ${t}" > + gdb_test "print u" " = ${old}" "old up struct ${t}" > + gdb_test "set variable u = s_${t}" > + gdb_test "print u" " = ${new}" "new up struct ${t}" > +} > + > +up_struct "1" "{s = {0}}" "{s = {1}}" > +up_struct "2" "{s = {0, 0}}" "{s = {1, 2}}" > +up_struct "3" "{s = {0, 0, 0}}" "{s = {1, 2, 3}}" > +up_struct "4" "{s = {0, 0, 0, 0}}" "{s = {1, 2, 3, 4}}" > + > +# > + > +proc check_field { t } { > + global gdb_prompt > + gdb_test "tbreak wack_field_${t}" > + gdb_test "continue" "register struct f_${t} u = f_${t};" \ > + "continue field ${t}" > + gdb_test "next" "return u;" "next field ${t}" > + > + gdb_test "print u" " = {i = 1, j = 1, k = 1}" "old field ${t}" > + gdb_test "set variable u = F_${t}" > + gdb_test "print u" " = {i = 0, j = 0, k = 0}" "new field ${t}" > + > + gdb_test "set variable u = F_${t}, u.i = f_${t}.i" > + gdb_test "print u" " = {i = 1, j = 0, k = 0}" "f_${t}.i" > + > + gdb_test "set variable u = F_${t}, u.j = f_${t}.j" > + gdb_test "print u" " = {i = 0, j = 1, k = 0}" "f_${t}.j" > + > + gdb_test "set variable u = F_${t}, u.k = f_${t}.k" > + gdb_test "print u" " = {i = 0, j = 0, k = 1}" "f_${t}.k" > + > + gdb_test "set variable u = f_${t}, u.i = F_${t}.i" > + gdb_test "print u" " = {i = 0, j = 1, k = 1}" "F_${t}.i" > + > + gdb_test "set variable u = f_${t}, u.j = F_${t}.j" > + gdb_test "print u" " = {i = 1, j = 0, k = 1}" "F_${t}.j" > + > + gdb_test "set variable u = f_${t}, u.k = F_${t}.k" > + gdb_test "print u" " = {i = 1, j = 1, k = 0}" "F_${t}.k" > + > +} > + > +check_field 1 > +check_field 2 > +check_field 3 > +check_field 4 > + > +# > + > +# WANTED: A fairly portable way of convincing the compiler to split a > +# value across memory and registers. > + -- Fernando Nasser Red Hat - Toronto E-Mail: fnasser@redhat.com 2323 Yonge Street, Suite #300 Toronto, Ontario M4P 2C9