From 27e829d0372c529518abf58c384aa80936677a95 Mon Sep 17 00:00:00 2001 From: Andrew Cagney Date: Thu, 5 Dec 2002 01:48:19 +0000 Subject: [PATCH] 2002-12-04 Andrew Cagney * gdb.base/store.exp, gdb.base/store.c: New files. --- gdb/testsuite/ChangeLog | 4 + gdb/testsuite/gdb.base/store.c | 250 +++++++++++++++++++++++++++++++++++++++ gdb/testsuite/gdb.base/store.exp | 171 ++++++++++++++++++++++++++ 3 files changed, 425 insertions(+) create mode 100644 gdb/testsuite/gdb.base/store.c create mode 100644 gdb/testsuite/gdb.base/store.exp diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 86ea376..e915ae5 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2002-12-04 Andrew Cagney + + * gdb.base/store.exp, gdb.base/store.c: New files. + 2002-12-03 Daniel Jacobowitz * gdb.base/selftest.exp: Update for current gdb. diff --git a/gdb/testsuite/gdb.base/store.c b/gdb/testsuite/gdb.base/store.c new file mode 100644 index 0000000..3a69641 --- /dev/null +++ b/gdb/testsuite/gdb.base/store.c @@ -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; +} diff --git a/gdb/testsuite/gdb.base/store.exp b/gdb/testsuite/gdb.base/store.exp new file mode 100644 index 0000000..64a8749 --- /dev/null +++ b/gdb/testsuite/gdb.base/store.exp @@ -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. + -- 2.7.4