This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch/rfc] Rewrite "structs" testcase


Hello,

The attached rewrites the "structs" testcase, greatly increasing its coverage of struct return inferior function call edge cases. Of note the patch:

- hacks structs.c so that it can be built to test almost any scalar struct return construct

- rewrites structs.exp to build structs.c / test structs.c with several combinations of char, short, int, long, long long, float, double, and long double.

- since the bug that stopped GDB finding inferior function call struct return values has been fixed, it expects all tests to pass

Look ok? Tested on PPC.

Andrew
2003-11-05  Andrew Cagney  <cagney@redhat.com>

	* gdb.base/structs.exp: Update copyright.  Rewrite.
	* gdb.base/structs.c: Update copyright.  Rewrite.

Index: gdb.base/structs.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/structs.c,v
retrieving revision 1.2
diff -u -r1.2 structs.c
--- gdb.base/structs.c	6 Mar 2001 08:21:51 -0000	1.2
+++ gdb.base/structs.c	5 Nov 2003 22:02:58 -0000
@@ -1,4 +1,6 @@
-/* Copyright 1996, 1999 Free Software Foundation, Inc.
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 1996, 1999, 2003 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
@@ -17,37 +19,105 @@
    Please email any bugs, comments, and/or additions to this file to:
    bug-gdb@prep.ai.mit.edu  */
 
-struct struct1 { char a;};
-struct struct2 { char a, b;};
-struct struct3 { char a, b, c; };
-struct struct4 { char a, b, c, d; };
-struct struct5 { char a, b, c, d, e; };
-struct struct6 { char a, b, c, d, e, f; };
-struct struct7 { char a, b, c, d, e, f, g; };
-struct struct8 { char a, b, c, d, e, f, g, h; };
-struct struct9 { char a, b, c, d, e, f, g, h, i; };
-struct struct10 { char a, b, c, d, e, f, g, h, i, j; };
-struct struct11 { char a, b, c, d, e, f, g, h, i, j, k; };
-struct struct12 { char a, b, c, d, e, f, g, h, i, j, k, l; };
-struct struct16 { char a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p; };
-
-struct struct1 foo1 = {'1'},  L1;
-struct struct2 foo2 = { 'a', 'b'},  L2;
-struct struct3 foo3 = { 'A', 'B', 'C'},  L3;
-struct struct4 foo4 = {'1', '2', '3', '4'},  L4;
-struct struct5 foo5 = {'a', 'b', 'c', 'd', 'e'},  L5;
-struct struct6 foo6 = {'A', 'B', 'C', 'D', 'E', 'F'},  L6;
-struct struct7 foo7 = {'1', '2', '3', '4', '5', '6', '7'},  L7;
-struct struct8 foo8 = {'1', '2', '3', '4', '5', '6', '7', '8'},  L8;
-struct struct9 foo9 = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'},  L9;
-struct struct10 foo10 = {
-  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'},  L10;
-struct struct11 foo11 = {
-  '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B'}, L11;
-struct struct12 foo12 = {
-  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'}, L12;
-struct struct16 foo16 = {
-  'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'}, L16;
+/* Useful abreviations.  */
+typedef void t;
+typedef char tc;
+typedef short ts;
+typedef int ti;
+typedef long tl;
+typedef long long tll;
+typedef float tf;
+typedef double td;
+typedef long double tld;
+
+/* Force the type of each field.  */
+#ifndef tA
+typedef t tA;
+#endif
+#ifndef tB
+typedef tA tB;
+#endif
+#ifndef tC
+typedef tB tC;
+#endif
+#ifndef tD
+typedef tC tD;
+#endif
+#ifndef tE
+typedef tD tE;
+#endif
+#ifndef tF
+typedef tE tF;
+#endif
+#ifndef tG
+typedef tF tG;
+#endif
+#ifndef tH
+typedef tG tH;
+#endif
+#ifndef tI
+typedef tH tI;
+#endif
+#ifndef tJ
+typedef tI tJ;
+#endif
+#ifndef tK
+typedef tJ tK;
+#endif
+#ifndef tL
+typedef tK tL;
+#endif
+#ifndef tM
+typedef tL tM;
+#endif
+#ifndef tN
+typedef tM tN;
+#endif
+#ifndef tO
+typedef tN tO;
+#endif
+#ifndef tP
+typedef tO tP;
+#endif
+#ifndef tQ
+typedef tP tQ;
+#endif
+
+struct  struct1 {tA a;};
+struct  struct2 {tA a; tB b;};
+struct  struct3 {tA a; tB b; tC c; };
+struct  struct4 {tA a; tB b; tC c; tD D; };
+struct  struct5 {tA a; tB b; tC c; tD D; tE e; };
+struct  struct6 {tA a; tB b; tC c; tD D; tE e; tF f; };
+struct  struct7 {tA a; tB b; tC c; tD D; tE e; tF f; tG g; };
+struct  struct8 {tA a; tB b; tC c; tD D; tE e; tF f; tG g; tH h; };
+struct  struct9 {tA a; tB b; tC c; tD D; tE e; tF f; tG g; tH h; tI i; };
+struct struct10 {tA a; tB b; tC c; tD D; tE e; tF f; tG g; tH h; tI i; tJ j; };
+struct struct11 {tA a; tB b; tC c; tD D; tE e; tF f; tG g; tH h; tI i; tJ j; tK k; };
+struct struct12 {tA a; tB b; tC c; tD D; tE e; tF f; tG g; tH h; tI i; tJ j; tK k; tL l; };
+struct struct13 {tA a; tB b; tC c; tD D; tE e; tF f; tG g; tH h; tI i; tJ j; tK k; tL l; tM m; };
+struct struct14 {tA a; tB b; tC c; tD D; tE e; tF f; tG g; tH h; tI i; tJ j; tK k; tL l; tM m; tN n; };
+struct struct15 {tA a; tB b; tC c; tD D; tE e; tF f; tG g; tH h; tI i; tJ j; tK k; tL l; tM m; tN n; tO o; };
+struct struct16 {tA a; tB b; tC c; tD D; tE e; tF f; tG g; tH h; tI i; tJ j; tK k; tL l; tM m; tN n; tO o; tP p; };
+struct struct17 {tA a; tB b; tC c; tD D; tE e; tF f; tG g; tH h; tI i; tJ j; tK k; tL l; tM m; tN n; tO o; tP p; tQ q; };
+
+struct  struct1  foo1 = {'1'}, L1;
+struct  struct2  foo2 = {'a','2'}, L2;
+struct  struct3  foo3 = {'1','b','3'}, L3;
+struct  struct4  foo4 = {'a','2','c','4'}, L4;
+struct  struct5  foo5 = {'1','b','3','d','5'}, L5;
+struct  struct6  foo6 = {'a','2','c','4','e','6'}, L6;
+struct  struct7  foo7 = {'1','b','3','d','5','f','7'}, L7;
+struct  struct8  foo8 = {'a','2','c','4','e','6','g','8'}, L8;
+struct  struct9  foo9 = {'1','b','3','d','5','f','7','h','9'}, L9;
+struct struct10 foo10 = {'a','2','c','4','e','6','g','8','i','A'}, L10;
+struct struct11 foo11 = {'1','b','3','d','5','f','7','h','9','j','B'}, L11;
+struct struct12 foo12 = {'a','2','c','4','e','6','g','8','i','A','k','C'}, L12;
+struct struct13 foo13 = {'1','b','3','d','5','f','7','h','9','j','B','l','D'}, L13;
+struct struct14 foo14 = {'a','2','c','4','e','6','g','8','i','A','k','C','m','E'}, L14;
+struct struct15 foo15 = {'1','b','3','d','5','f','7','h','9','j','B','l','D','n','F'}, L15;
+struct struct16 foo16 = {'a','2','c','4','e','6','g','8','i','A','k','C','m','E','o','G'}, L16;
+struct struct17 foo17 = {'1','b','3','d','5','f','7','h','9','j','B','l','D','n','F','p','H'}, L17;
 
 struct struct1  fun1()
 {
@@ -97,10 +167,26 @@
 {
   return foo12; 
 }
+struct struct13 fun13()
+{
+  return foo13; 
+}
+struct struct14 fun14()
+{
+  return foo14; 
+}
+struct struct15 fun15()
+{
+  return foo15; 
+}
 struct struct16 fun16()
 {
   return foo16; 
 }
+struct struct17 fun17()
+{
+  return foo17; 
+}
 
 #ifdef PROTOTYPES
 void Fun1(struct struct1 foo1)
@@ -211,6 +297,33 @@
   L12 = foo12; 
 }
 #ifdef PROTOTYPES
+void Fun13(struct struct13 foo13)
+#else
+void Fun13(foo13)
+     struct struct13 foo13;
+#endif
+{
+  L13 = foo13; 
+}
+#ifdef PROTOTYPES
+void Fun14(struct struct14 foo14)
+#else
+void Fun14(foo14)
+     struct struct14 foo14;
+#endif
+{
+  L14 = foo14; 
+}
+#ifdef PROTOTYPES
+void Fun15(struct struct15 foo15)
+#else
+void Fun15(foo15)
+     struct struct15 foo15;
+#endif
+{
+  L15 = foo15; 
+}
+#ifdef PROTOTYPES
 void Fun16(struct struct16 foo16)
 #else
 void Fun16(foo16)
@@ -219,6 +332,15 @@
 {
   L16 = foo16; 
 }
+#ifdef PROTOTYPES
+void Fun17(struct struct17 foo17)
+#else
+void Fun17(foo17)
+     struct struct17 foo17;
+#endif
+{
+  L17 = foo17; 
+}
 
 int main()
 {
@@ -240,10 +362,15 @@
   L10 = fun10();
   L11 = fun11();
   L12 = fun12();
+  L13 = fun13();
+  L14 = fun14();
+  L15 = fun15();
   L16 = fun16();
+  L17 = fun17();
 
   foo1.a = foo2.a = foo3.a = foo4.a = foo5.a = foo6.a = foo7.a = foo8.a =
-    foo9.a = foo10.a = foo11.a = foo12.a = foo16.a = '$';
+    foo9.a = foo10.a = foo11.a = foo12.a = foo13.a = foo14.a = foo15.a =
+    foo16.a = foo17.a = '$';
 
   Fun1(foo1);	
   Fun2(foo2);	
@@ -257,7 +384,11 @@
   Fun10(foo10);
   Fun11(foo11);
   Fun12(foo12);
+  Fun13(foo13);
+  Fun14(foo14);
+  Fun15(foo15);
   Fun16(foo16);
+  Fun17(foo17);
 
   return 0;
 }
Index: gdb.base/structs.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/structs.exp,v
retrieving revision 1.5
diff -u -r1.5 structs.exp
--- gdb.base/structs.exp	7 Jan 2002 19:20:09 -0000	1.5
+++ gdb.base/structs.exp	5 Nov 2003 22:02:58 -0000
@@ -1,4 +1,6 @@
-# Copyright 1996, 1997, 1999 Free Software Foundation, Inc.
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 1996, 1997, 1999, 2003 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
@@ -26,142 +28,241 @@
 set prms_id 0
 set bug_id 0
 
-set prototypes 1
+# Some targets can't call functions, so don't even bother with this
+# test.
+
+if [target_info exists gdb,cannot_call_functions] {
+    setup_xfail "*-*-*" 2416
+    fail "This target can not call functions"
+    continue
+}
+
+# Build a variant of the testcase.
+
 set testfile "structs"
 set srcfile ${testfile}.c
 set binfile ${objdir}/${subdir}/${testfile}
 
-# build the first test case
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
-    # built the second test case since we can't use prototypes
-    warning "Prototypes not supported, rebuilding with -DNO_PROTOTYPES"
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DNO_PROTOTYPES}] != "" } {
-     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+proc start_structs_test { suffix defs } {
+    global testfile
+    global srcfile
+    global binfile
+    global objdir
+    global subdir
+    global srcdir
+    set binfile ${objdir}/${subdir}/${testfile}-${suffix}
+    if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "debug ${defs}"] != "" } {
+	# built the second test case since we can't use prototypes
+	warning "Prototypes not supported, rebuilding with -DNO_PROTOTYPES"
+	if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "debug ${defs} additional_flags=-DNO_PROTOTYPES"] != "" } {
+	    gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+	}
     }
-    set prototypes 0
-}
 
-# Create and source the file that provides information about the compiler
-# used to compile the test case.
-if [get_compiler_info ${binfile}] {
-    return -1;
+    # Start with a fresh gdb.
+    gdb_start
+    gdb_reinitialize_dir $srcdir/$subdir
+    gdb_load ${binfile}
+
+    # Make certain that the output is consistent
+    gdb_test "set print sevenbit-strings" "" "set print sevenbit-strings for ${suffix}"
+    gdb_test "set print address off" ""      "set print address off for ${suffix}"
+    gdb_test "set width 0" ""                "set width 0 for ${suffix}"
 }
 
 
-# Some targets can't call functions, so don't even bother with this
-# test.
-if [target_info exists gdb,cannot_call_functions] {
-    setup_xfail "*-*-*" 2416
-    fail "This target can not call functions"
-    continue
-}
+# Create and source the file that provides information about the
+# compiler used to compile the test case.
 
+if [get_compiler_info ${binfile}] {
+    return -1;
+}
 
 # Call FUNC with no arguments, and expect to see the regexp RESULT in
-# the output.  If we get back the error message "Function return value
-# unknown", call that an unsupported test; on some architectures, it's
-# impossible to find structs returned by value reliably.
-proc call_struct_func { func result } {
+# the output.  Since GDB called the function, GDB always knows where
+# the return value is.  These tests should never fail.  Use a char
+# formatted print so that, regardless of the type of each struct
+# element, the printed value are always the same.
+
+proc call_struct_func { name n result } {
     global gdb_prompt
     
-    set command "p ${func}()"
+    set command "p/c fun${n}()"
     send_gdb "${command}\n"
     gdb_expect {
         -re "$result\[\r\n\]+$gdb_prompt $" {
-            pass "$command"
-        }
-        -re "Function return value unknown.\[\r\n\]+$gdb_prompt $" {
-            unsupported "$command"
+            pass "$command for ${name}"
         }
         -re "$gdb_prompt $" {
-            fail "$command"
+            fail "$command for ${name}"
         }
         timeout {
-            fail "$command (timeout)"
+            fail "$command for ${name} (timeout)"
         }
     }
 }
 
-# FIXME:  Before calling this proc, we should probably verify that
-# we can call inferior functions and get a valid integral value
-# returned.
+proc call_void_func { name n } {
+    set command  "p Fun${n}(foo${n})"
+    gdb_test "${command}" " = (void|0)" "${command} for ${n}"
+}
+
+proc print_struct { name n result } {
+    set command  "p/c L${n}"
+    gdb_test "${command}" ${result} "${command} for ${name}"
+}
+
 # Note that it is OK to check for 0 or 1 as the returned values, because C
 # specifies that the numeric value of a relational or logical expression
 # (computed in the inferior) is 1 for true and 0 for false.
 
-proc do_function_calls {} {
+proc do_function_calls { name } {
     global prototypes
     global gcc_compiled
     global gdb_prompt
 
-    # First, call the "fun" functions and examine the value they return.
-    call_struct_func "fun1" " = {a = 49 '1'}"
-    call_struct_func "fun2" " = {a = 97 'a', b = 98 'b'}"
-    call_struct_func "fun3" " = {a = 65 'A', b = 66 'B', c = 67 'C'}"
-    call_struct_func "fun4" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4'}"
-    call_struct_func "fun5" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e'}"
-    call_struct_func "fun6" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F'}"
-    call_struct_func "fun7" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4', e = 53 '5', f = 54 '6', g = 55 '7'}"
-    call_struct_func "fun8" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4', e = 53 '5', f = 54 '6', g = 55 '7', h = 56 '8'}"
-    call_struct_func "fun9" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e', f = 102 'f', g = 103 'g', h = 104 'h', i = 105 'i'}"
-    call_struct_func "fun10" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F', g = 71 'G', h = 72 'H', i = 73 'I', j = 74 'J'}"
-    call_struct_func "fun11" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4', e = 53 '5', f = 54 '6', g = 55 '7', h = 56 '8', i = 57 '9', j = 65 'A', k = 66 'B'}"
-    call_struct_func "fun12" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F', g = 71 'G', h = 72 'H', i = 73 'I', j = 74 'J', k = 75 'K', l = 76 'L'}"
-    call_struct_func "fun16" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e', f = 102 'f', g = 103 'g', h = 104 'h', i = 105 'i', j = 106 'j', k = 107 'k', l = 108 'l', m = 109 'm', n = 110 'n', o = 111 'o', p = 112 'p'}"
+    # First, call the "fun" functions and examine the value they
+    # return.  This checks that GDB can correctly, and always, extract
+    # the return value from an inferior function call.
+
+    call_struct_func ${name} 1 " = {a = 49 '1'}"
+    call_struct_func ${name} 2 " = {a = 97 'a', b = 50 '2'}"
+    call_struct_func ${name} 3 " = {a = 49 '1', b = 98 'b', c = 51 '3'}"
+    call_struct_func ${name} 4 " = {a = 97 'a', b = 50 '2', c = 99 'c', D = 52 '4'}"
+    call_struct_func ${name} 5 " = {a = 49 '1', b = 98 'b', c = 51 '3', D = 100 'd', e = 53 '5'}"
+    call_struct_func ${name} 6 " = {a = 97 'a', b = 50 '2', c = 99 'c', D = 52 '4', e = 101 'e', f = 54 '6'}"
+    call_struct_func ${name} 7 " = {a = 49 '1', b = 98 'b', c = 51 '3', D = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7'}"
+    call_struct_func ${name} 8 " = {a = 97 'a', b = 50 '2', c = 99 'c', D = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8'}"
+    call_struct_func ${name} 9 " = {a = 49 '1', b = 98 'b', c = 51 '3', D = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9'}"
+    call_struct_func ${name} 10 " = {a = 97 'a', b = 50 '2', c = 99 'c', D = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A'}"
+    call_struct_func ${name} 11 " = {a = 49 '1', b = 98 'b', c = 51 '3', D = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B'}"
+    call_struct_func ${name} 12 " = {a = 97 'a', b = 50 '2', c = 99 'c', D = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A', k = 107 'k', l = 67 'C'}"
+    call_struct_func ${name} 13 " = {a = 49 '1', b = 98 'b', c = 51 '3', D = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B', l = 108 'l', m = 68 'D'}"
+    call_struct_func ${name} 14 " = {a = 97 'a', b = 50 '2', c = 99 'c', D = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A', k = 107 'k', l = 67 'C', m = 109 'm', n = 69 'E'}"
+    call_struct_func ${name} 15 " = {a = 49 '1', b = 98 'b', c = 51 '3', D = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B', l = 108 'l', m = 68 'D', n = 110 'n', o = 70 'F'}"
+    call_struct_func ${name} 16 " = {a = 97 'a', b = 50 '2', c = 99 'c', D = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A', k = 107 'k', l = 67 'C', m = 109 'm', n = 69 'E', o = 111 'o', p = 71 'G'}"
+    call_struct_func ${name} 17 " = {a = 49 '1', b = 98 'b', c = 51 '3', D = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B', l = 108 'l', m = 68 'D', n = 110 'n', o = 70 'F', p = 112 'p', q = 72 'H'}"
 
     # Now call the Fun functions to set the L* variables.  This
     # tests that gdb properly passes structures to functions.
-    gdb_test "p Fun1(foo1)" " = (void|0)"
-    gdb_test "p Fun2(foo2)" " = (void|0)"
-    gdb_test "p Fun3(foo3)" " = (void|0)"
-    gdb_test "p Fun4(foo4)" " = (void|0)"
-    gdb_test "p Fun5(foo5)" " = (void|0)"
-    gdb_test "p Fun6(foo6)" " = (void|0)"
-    gdb_test "p Fun7(foo7)" " = (void|0)"
-    gdb_test "p Fun8(foo8)" " = (void|0)"
-    gdb_test "p Fun9(foo9)" " = (void|0)"
-    gdb_test "p Fun10(foo10)" " = (void|0)"
-    gdb_test "p Fun11(foo11)" " = (void|0)"
-    gdb_test "p Fun12(foo12)" " = (void|0)"
-    gdb_test "p Fun16(foo16)" " = (void|0)"
+
+    call_void_func ${name} 1
+    call_void_func ${name} 2
+    call_void_func ${name} 3
+    call_void_func ${name} 4
+    call_void_func ${name} 5
+    call_void_func ${name} 6
+    call_void_func ${name} 7
+    call_void_func ${name} 8
+    call_void_func ${name} 9
+    call_void_func ${name} 10
+    call_void_func ${name} 11
+    call_void_func ${name} 12
+    call_void_func ${name} 13
+    call_void_func ${name} 14
+    call_void_func ${name} 15
+    call_void_func ${name} 16
+    call_void_func ${name} 17
 
     # Now print the L* variables and examine their values.
-    gdb_test "p L1" " = {a = 49 '1'}"
-    gdb_test "p L2" " = {a = 97 'a', b = 98 'b'}"
-    gdb_test "p L3" " = {a = 65 'A', b = 66 'B', c = 67 'C'}"
-    gdb_test "p L4" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4'}"
-    gdb_test "p L5" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e'}"
-    gdb_test "p L6" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F'}"
-    gdb_test "p L7" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4', e = 53 '5', f = 54 '6', g = 55 '7'}"
-    gdb_test "p L8" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4', e = 53 '5', f = 54 '6', g = 55 '7', h = 56 '8'}"
-    gdb_test "p L9" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e', f = 102 'f', g = 103 'g', h = 104 'h', i = 105 'i'}"
-    gdb_test "p L10" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F', g = 71 'G', h = 72 'H', i = 73 'I', j = 74 'J'}"
-    gdb_test "p L11" " = {a = 49 '1', b = 50 '2', c = 51 '3', d = 52 '4', e = 53 '5', f = 54 '6', g = 55 '7', h = 56 '8', i = 57 '9', j = 65 'A', k = 66 'B'}"
-    gdb_test "p L12" " = {a = 65 'A', b = 66 'B', c = 67 'C', d = 68 'D', e = 69 'E', f = 70 'F', g = 71 'G', h = 72 'H', i = 73 'I', j = 74 'J', k = 75 'K', l = 76 'L'}"
-    gdb_test "p L16" " = {a = 97 'a', b = 98 'b', c = 99 'c', d = 100 'd', e = 101 'e', f = 102 'f', g = 103 'g', h = 104 'h', i = 105 'i', j = 106 'j', k = 107 'k', l = 108 'l', m = 109 'm', n = 110 'n', o = 111 'o', p = 112 'p'}"
-}
-# Start with a fresh gdb.
-
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
-
-gdb_test "set print sevenbit-strings" ""
-gdb_test "set print address off" ""
-gdb_test "set width 0" ""
+    print_struct ${name} 1 " = {a = 49 '1'}"
+    print_struct ${name} 2 " = {a = 97 'a', b = 50 '2'}"
+    print_struct ${name} 3 " = {a = 49 '1', b = 98 'b', c = 51 '3'}"
+    print_struct ${name} 4 " = {a = 97 'a', b = 50 '2', c = 99 'c', D = 52 '4'}"
+    print_struct ${name} 5 " = {a = 49 '1', b = 98 'b', c = 51 '3', D = 100 'd', e = 53 '5'}"
+    print_struct ${name} 6 " = {a = 97 'a', b = 50 '2', c = 99 'c', D = 52 '4', e = 101 'e', f = 54 '6'}"
+    print_struct ${name} 7 " = {a = 49 '1', b = 98 'b', c = 51 '3', D = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7'}"
+    print_struct ${name} 8 " = {a = 97 'a', b = 50 '2', c = 99 'c', D = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8'}"
+    print_struct ${name} 9 " = {a = 49 '1', b = 98 'b', c = 51 '3', D = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9'}"
+    print_struct ${name} 10 " = {a = 97 'a', b = 50 '2', c = 99 'c', D = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A'}"
+    print_struct ${name} 11 " = {a = 49 '1', b = 98 'b', c = 51 '3', D = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B'}"
+    print_struct ${name} 12 " = {a = 97 'a', b = 50 '2', c = 99 'c', D = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A', k = 107 'k', l = 67 'C'}"
+    print_struct ${name} 13 " = {a = 49 '1', b = 98 'b', c = 51 '3', D = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B', l = 108 'l', m = 68 'D'}"
+    print_struct ${name} 14 " = {a = 97 'a', b = 50 '2', c = 99 'c', D = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A', k = 107 'k', l = 67 'C', m = 109 'm', n = 69 'E'}"
+    print_struct ${name} 15 " = {a = 49 '1', b = 98 'b', c = 51 '3', D = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B', l = 108 'l', m = 68 'D', n = 110 'n', o = 70 'F'}"
+    print_struct ${name} 16 " = {a = 97 'a', b = 50 '2', c = 99 'c', D = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A', k = 107 'k', l = 67 'C', m = 109 'm', n = 69 'E', o = 111 'o', p = 71 'G'}"
+    print_struct ${name} 17 " = {a = 49 '1', b = 98 'b', c = 51 '3', D = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B', l = 108 'l', m = 68 'D', n = 110 'n', o = 70 'F', p = 112 'p', q = 72 'H'}"
+}
 
-if [target_info exists gdb,cannot_call_functions] {
-    setup_xfail "*-*-*" 2416
-    fail "This target can not call functions"
-    return 0
+# Simple test - all elements are the same size
+
+proc run_struct1_test { suffix type } {
+    global ws
+    start_structs_test 1${suffix} "additional_flags=-DtA=${suffix}"
+
+    if { ![runto_main] } then {
+	gdb_suppress_tests;
+    }
+
+    # check that the type is correct
+    gdb_test "ptype foo1.a" "type = ${type}" "ptype foo1.a for 1${suffix}"
+
+    do_function_calls 2${suffix};
+
+    gdb_stop_suppressing_tests;
 }
 
-if { ![runto_main] } then {
-    gdb_suppress_tests;
+run_struct1_test  tc "char"
+run_struct1_test  ts "short int"
+run_struct1_test  ti "int"
+run_struct1_test  tl "long int"
+run_struct1_test  tll "long long int"
+run_struct1_test  tf "float"
+run_struct1_test  td "double"
+run_struct1_test  tld "long double"
+
+# First element is something strange, rest are char
+
+proc run_struct2_test { suffix type } {
+    global ws
+    start_structs_test 2${suffix} "additional_flags=-DtA=${suffix} additional_flags=-DtB=tc"
+
+    if { ![runto_main] } then {
+	gdb_suppress_tests;
+    }
+
+    # check that the types are correct
+    gdb_test "ptype foo2.a" "type = ${type}" "ptype foo2.a for 2${suffix}"
+    gdb_test "ptype foo2.b" "type = char" "ptype foo2.b for 2${suffix}"
+
+    do_function_calls 2${suffix};
+
+    gdb_stop_suppressing_tests;
 }
 
-do_function_calls;
+run_struct2_test  ts "short int"
+run_struct2_test  ti "int"
+run_struct2_test  tl "long int"
+run_struct2_test  tll "long long int"
+run_struct2_test  tf "float"
+run_struct2_test  td "double"
+run_struct2_test  tld "long double"
+
+# First element is char, rest are something strange
+
+proc run_struct3_test { suffix type } {
+    global ws
+    start_structs_test 3${suffix} "additional_flags=-DtA=tc additional_flags=-DtB=${suffix}"
+
+    if { ![runto_main] } then {
+	gdb_suppress_tests;
+    }
+
+    # check that the types are correct
+    gdb_test "ptype foo3.a" "type = char" "ptype foo2.a for 3${suffix}"
+    gdb_test "ptype foo3.b" "type = ${type}" "ptype foo2.b for 3${suffix}"
+
+    do_function_calls 3${suffix};
+
+    gdb_stop_suppressing_tests;
+}
 
-gdb_stop_suppressing_tests;
+run_struct2_test  ts "short int"
+run_struct2_test  ti "int"
+run_struct2_test  tl "long int"
+run_struct2_test  tll "long long int"
+run_struct2_test  tf "float"
+run_struct2_test  td "double"
+run_struct2_test  tld "long double"
 
 return 0

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]