This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
Re: PATCH: printing elements of typedef'ed arrays
- To: Andrew Cagney <ac131313 at cygnus dot com>
- Subject: Re: PATCH: printing elements of typedef'ed arrays
- From: Elena Zannoni <ezannoni at cygnus dot com>
- Date: Tue, 14 Mar 2000 12:01:20 -0500 (EST)
- Cc: Elena Zannoni <ezannoni at cygnus dot com>, gdb-patches at sourceware dot cygnus dot com
- References: <14535.62150.908914.943283@kwikemart.cygnus.com><38CDED0E.2FBE16B6@cygnus.com>
Andrew Cagney writes:
> Elena Zannoni wrote:
> >
> > [Sorry, wrong list...]
> >
> > When an array is typedeffed, like in this example:
> >
> > typedef long ArrayLong [10];
> > ArrayLong a1;
> >
> > typedef struct s
> > {
> > int a;
> > int b;
> > } structure;
> >
> > long a2 [10];
> > structure s1;
> >
> > int main (void)
> > {
> > return 0;
> > }
> >
> > Gdb cannot print individual elements of the array a1:
> >
> > (gdb) p a1
> > $1 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
> > (gdb) p a1[0]
> > $2 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} <<<< is incorrect
> > (gdb) p a2
> > $3 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
> > (gdb) p a2[0]
> > $4 = 0
> > (gdb)
> >
> > The following patch takes care of this.
> > I tested it on solaris and showed no regressions.
> > OK to check in?
> >
> > Elena
>
> Just two cross checks:
>
> o the existing testsuite
> checks that the printing of
> character strings doesn't change
> and the patch didn't change the
> behavour
>
> (I've a foggy memory about a great
> debate where the printing of strings
> was made special in some way)
Correct. I saw no regressions.
>
> o you've sneekered in a testsuite
> change (to printcmd.exp?) :-)
>
Yes, I added some tests.
> Andrew
>
> PS: I guess I'm the defacto maintainer.
Here is the full patch. I just committed it.
Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.130
diff -c -u -r1.130 ChangeLog
--- ChangeLog 2000/03/14 02:37:24 1.130
+++ ChangeLog 2000/03/14 16:56:48
@@ -1,3 +1,8 @@
+2000-03-14 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
+
+ * eval.c (evaluate_subexp_with_coercion): Add call to
+ check_typedef, to handle typedeffed vars correctly.
+
Mon Mar 13 21:21:41 2000 Andrew Cagney <cagney@b1.cygnus.com>
* defs.h (STREQ, STRCMP, STREQN): Document that these macros are
Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.1.1.7
diff -c -u -r1.1.1.7 eval.c
--- eval.c 1999/12/14 01:05:30 1.1.1.7
+++ eval.c 2000/03/14 16:56:49
@@ -1875,7 +1875,7 @@
val =
locate_var_value
(var, block_innermost_frame (exp->elts[pc + 1].block));
- return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (SYMBOL_TYPE (var))),
+ return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (check_typedef (SYMBOL_TYPE (var)))),
val);
}
/* FALLTHROUGH */
Index: testsuite/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/ChangeLog,v
retrieving revision 1.7
diff -c -u -r1.7 ChangeLog
--- ChangeLog 2000/03/14 06:14:07 1.7
+++ ChangeLog 2000/03/14 16:56:52
@@ -1,3 +1,10 @@
+2000-03-14 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
+
+ * gdb.base/printcmds.c: Add typedeffed arrays.
+
+ * gdb.base/printcmds.exp (test_print_typedef_arrays): New
+ procedure to test arrays that are typedef'd.
+
2000-03-13 James Ingham <jingham@leda.cygnus.com>
* lib/gdb.exp: Fix the gdbtk_start routine to correctly find all
Index: testsuite/gdb.base/printcmds.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/printcmds.c,v
retrieving revision 1.1.1.2
diff -c -u -r1.1.1.2 printcmds.c
--- printcmds.c 1999/06/28 16:03:41 1.1.1.2
+++ printcmds.c 2000/03/14 16:56:52
@@ -59,6 +59,12 @@
/* Single and multidimensional arrays to test access and printing of array
members. */
+typedef int ArrayInt [10];
+ArrayInt a1 = {2,4,6,8,10,12,14,16,18,20};
+
+typedef char ArrayChar [5];
+ArrayChar a2 = {'a','b','c','d','\0'};
+
int int1dim[12] = {0,1,2,3,4,5,6,7,8,9,10,11};
int int2dim[3][4] = {{0,1,2,3},{4,5,6,7},{8,9,10,11}};
int int3dim[2][3][2] = {{{0,1},{2,3},{4,5}},{{6,7},{8,9},{10,11}}};
@@ -97,5 +103,5 @@
/* Prevent AIX linker from removing variables. */
return ctable1[0] + ctable2[0] + int1dim[0] + int2dim[0][0]
+ int3dim[0][0][0] + int4dim[0][0][0][0] + teststring[0] +
- *parrays -> array1;
+ *parrays -> array1 + a1[0] + a2[0];
}
Index: testsuite/gdb.base/printcmds.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/printcmds.exp,v
retrieving revision 1.1.1.3
diff -c -u -r1.1.1.3 printcmds.exp
--- printcmds.exp 1999/08/02 23:46:51 1.1.1.3
+++ printcmds.exp 2000/03/14 16:56:52
@@ -552,6 +552,22 @@
" = {{{{0, 1}, {2, 3}, {4, 5}}, {{6, 7}, {8, 9}, {10, 11}}}}"
}
+proc test_print_typedef_arrays {} {
+ global gdb_prompt
+
+ gdb_test "set print elements 24" ""
+
+ gdb_test "p a1" \
+ " = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}"
+ gdb_test "p a1\[0\]" " = 2"
+ gdb_test "p a1\[9\]" " = 20"
+
+ gdb_test "p a2" \
+ " = \"abcd\""
+ gdb_test "p a2\[0\]" " = 97 'a'"
+ gdb_test "p a2\[3\]" " = 100 'd'"
+}
+
proc test_artificial_arrays {} {
# Send \026@ instead of just @ in case the kill character is @.
gdb_test "p int1dim\[0\]\026@2" " = {0, 1}" {p int1dim[0]@2}
@@ -691,6 +707,7 @@
test_print_repeats_10
test_print_strings
test_print_int_arrays
+ test_print_typedef_arrays
test_artificial_arrays
test_print_char_arrays
# We used to do the runto main here.