From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sources.redhat.com
Subject: [RFA] Remove unexpected warning when printing empty array
Date: Wed, 05 Oct 2005 22:09:00 -0000 [thread overview]
Message-ID: <20051005220935.GO1591@adacore.com> (raw)
[-- 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++)
next reply other threads:[~2005-10-05 22:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-05 22:09 Joel Brobecker [this message]
2005-10-09 20:33 ` Daniel Jacobowitz
2005-10-10 1:15 ` Joel Brobecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20051005220935.GO1591@adacore.com \
--to=brobecker@adacore.com \
--cc=gdb-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox