From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Cc: Joel Brobecker <brobecker@adacore.com>
Subject: [commit/Ada] fix warning when printing empty array
Date: Wed, 03 Nov 2010 23:22:00 -0000 [thread overview]
Message-ID: <1288826552-17869-1-git-send-email-brobecker@adacore.com> (raw)
In-Reply-To: <20101103211550.GC2445@adacore.com>
This patch should fix the following regression:
(gdb) print my_table
-$1 = ()
-(gdb) PASS: gdb.ada/null_array.exp: print my_table
+$1 = (warning: unable to get bounds of array, assuming null array
+)
+(gdb) FAIL: gdb.ada/null_array.exp: print my_table
The problem was introduced by a change in val_print_array_elements
which removed a check for the case where the array's high bound
is smaller than the array's low bound (empty array).
This change restores the check and forces the len to zero in that case.
Looking at the patch that caused the regression, I suspect that we may
have other parts that might have been broken (non-zero array low bound?).
gdb/ChangeLog:
* valprint.c (val_print_array_elements): Put back handling of
empty arrays.
Tested on x86_64-linux. Checked in.
---
gdb/ChangeLog | 5 +++++
gdb/valprint.c | 12 +++++++++++-
2 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 719582b..221868b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2010-11-03 Joel Brobecker <brobecker@adacore.com>
+
+ * valprint.c (val_print_array_elements): Put back handling of
+ empty arrays.
+
2010-11-03 Ken Werner <ken.werner@de.ibm.com>
* dwarf2read.c (read_array_type): Read the DW_AT_byte_size from the
diff --git a/gdb/valprint.c b/gdb/valprint.c
index dba528b..ddb16e4 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1118,7 +1118,17 @@ val_print_array_elements (struct type *type, const gdb_byte *valaddr,
index_type = TYPE_INDEX_TYPE (type);
if (get_array_bounds (type, &low_bound, &high_bound))
- len = high_bound - low_bound + 1;
+ {
+ /* The array length should normally be HIGH_BOUND - LOW_BOUND + 1.
+ But we have to be a little extra careful, because some languages
+ such as Ada allow LOW_BOUND to be greater than HIGH_BOUND for
+ empty arrays. In that situation, the array length is just zero,
+ not negative! */
+ if (low_bound > high_bound)
+ len = 0;
+ else
+ len = high_bound - low_bound + 1;
+ }
else
{
warning (_("unable to get bounds of array, assuming null array"));
--
1.7.1
next prev parent reply other threads:[~2010-11-03 23:22 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-19 11:24 [patch] DW_AT_byte_size for array type entries Ken Werner
2010-10-19 18:16 ` Ken Werner
2010-11-02 8:23 ` Ken Werner
2010-11-02 22:45 ` Tom Tromey
2010-11-03 14:23 ` Ken Werner
2010-11-03 19:09 ` Regression on gdb.ada/null_array.exp [Re: [patch] DW_AT_byte_size for array type entries] Jan Kratochvil
2010-11-03 21:16 ` Joel Brobecker
2010-11-03 23:22 ` Joel Brobecker [this message]
2010-11-03 23:24 ` Joel Brobecker
2010-11-04 0:31 ` Jan Kratochvil
2010-11-04 1:57 ` Joel Brobecker
2010-11-04 3:26 ` Jan Kratochvil
2010-11-04 18:01 ` Joel Brobecker
2010-11-04 18:10 ` Jan Kratochvil
2010-11-04 18:23 ` Joel Brobecker
2010-11-04 18:54 ` Jan Kratochvil
2010-11-04 22:11 ` Joel Brobecker
2010-12-13 20:03 ` [patch] DW_AT_byte_size for array type entries Ken Werner
2010-12-14 5:42 ` Joel Brobecker
2010-12-14 10:27 ` Ken Werner
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=1288826552-17869-1-git-send-email-brobecker@adacore.com \
--to=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
/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