Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Remove unexpected warning when printing empty array
@ 2005-10-05 22:09 Joel Brobecker
  2005-10-09 20:33 ` Daniel Jacobowitz
  0 siblings, 1 reply; 3+ messages in thread
From: Joel Brobecker @ 2005-10-05 22:09 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1043 bytes --]

This is to fix a small warning introduced after checking in this patch:

        http://sources.redhat.com/ml/gdb-patches/2005-10/msg00028.htm

This fixes two FAILs for a testcase I just submitted:

        http://sources.redhat.com/ml/gdb-patches/2005-10/msg00046.html

FAIL: gdb.ada/arrayidx.exp: print empty, indexes off
FAIL: gdb.ada/arrayidx.exp: print empty

The problem is that we were trying to get the lower bound of an
empty array. To do that, we called get_array_low_bound(), which
assumes that the array is not empty. So this routine determines
that there is something abnormal about the array, and returns
an error, causing us to then issue a warning to the user.

By shifting slightly the code a bit, we can avoid the warnings
in all situations.

2005-10-05  Joel Brobecker  <brobecker@adacore.com>

        * valprint.c (val_print_array_elements): Check array size before
        computing its low bound. If zero, then use a default bound of zero.

Tested on x86-linux, fixes the two FAILs above.
OK to apply?

Thanks,
-- 
Joel

[-- Attachment #2: valprint.c.diff --]
[-- Type: text/plain, Size: 1225 bytes --]

Index: valprint.c
===================================================================
RCS file: /cvs/src/src/gdb/valprint.c,v
retrieving revision 1.55
diff -u -p -r1.55 valprint.c
--- valprint.c	3 Oct 2005 21:21:20 -0000	1.55
+++ valprint.c	5 Oct 2005 22:00:29 -0000
@@ -959,19 +959,21 @@ val_print_array_elements (struct type *t
   unsigned int rep1;
   /* Number of repetitions we have detected so far.  */
   unsigned int reps;
-  long low_bound_index;
-
-  if (!get_array_low_bound (type, &low_bound_index))
-    {
-      warning ("unable to get low bound of array, using zero as default");
-      low_bound_index = 0;
-    }
+  long low_bound_index = 0;
 
   elttype = TYPE_TARGET_TYPE (type);
   eltlen = TYPE_LENGTH (check_typedef (elttype));
   len = TYPE_LENGTH (type) / eltlen;
   index_type = TYPE_INDEX_TYPE (type);
 
+  /* Get the array low bound.  This only makes sense if the array
+     has one or more element in it.  */
+  if (len > 0 && !get_array_low_bound (type, &low_bound_index))
+    {
+      warning ("unable to get low bound of array, using zero as default");
+      low_bound_index = 0;
+    }
+
   annotate_array_section_begin (i, elttype);
 
   for (; i < len && things_printed < print_max; i++)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFA] Remove unexpected warning when printing empty array
  2005-10-05 22:09 [RFA] Remove unexpected warning when printing empty array Joel Brobecker
@ 2005-10-09 20:33 ` Daniel Jacobowitz
  2005-10-10  1:15   ` Joel Brobecker
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Jacobowitz @ 2005-10-09 20:33 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

On Wed, Oct 05, 2005 at 03:09:35PM -0700, Joel Brobecker wrote:
> 2005-10-05  Joel Brobecker  <brobecker@adacore.com>
> 
>         * valprint.c (val_print_array_elements): Check array size before
>         computing its low bound. If zero, then use a default bound of zero.
> 
> Tested on x86-linux, fixes the two FAILs above.
> OK to apply?

OK.

-- 
Daniel Jacobowitz
CodeSourcery, LLC


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFA] Remove unexpected warning when printing empty array
  2005-10-09 20:33 ` Daniel Jacobowitz
@ 2005-10-10  1:15   ` Joel Brobecker
  0 siblings, 0 replies; 3+ messages in thread
From: Joel Brobecker @ 2005-10-10  1:15 UTC (permalink / raw)
  To: gdb-patches

> > 2005-10-05  Joel Brobecker  <brobecker@adacore.com>
> > 
> >         * valprint.c (val_print_array_elements): Check array size before
> >         computing its low bound. If zero, then use a default bound of zero.
> > 
> > Tested on x86-linux, fixes the two FAILs above.
> > OK to apply?
> 
> OK.

Thank you, checked in.

-- 
Joel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-10-10  1:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-05 22:09 [RFA] Remove unexpected warning when printing empty array Joel Brobecker
2005-10-09 20:33 ` Daniel Jacobowitz
2005-10-10  1:15   ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox