public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [gdb/tdep] Fix nr array elements in ppc64_aggregate_candidate
@ 2023-11-01  7:49 Tom de Vries
  2023-11-02 17:41 ` Ulrich Weigand
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2023-11-01  7:49 UTC (permalink / raw)
  To: gdb-patches; +Cc: Ulrich Weigand

On AlmaLinux 9.2 powerpc64le I run into:
...
(gdb) PASS: gdb.ada/array_return.exp: continuing to Create_Small_Float_Vector
finish^M
Run till exit from #0  pck.create_small_float_vector () at pck.adb:30^M
0x00000000100022d4 in p () at p.adb:25^M
25         Vector := Create_Small_Float_Vector;^M
Value returned is $3 = (2.80259693e-45, 2.80259693e-45)^M
(gdb) FAIL: gdb.ada/array_return.exp: value printed by finish of Create_Small_Float_Vector
...
while this is expected:
...
Value returned is $3 = (4.25, 4.25)^M
...

The problem is here in ppc64_aggregate_candidate:
...
		  if (!get_array_bounds (type, &low_bound, &high_bound))
		    return -1;
		  count *= high_bound - low_bound
...

The array type (containing 2 elements) is:
...
   type Small_Float_Vector is array (1 .. 2) of Float;
...
so we have:
...
(gdb) p	low_bound
$1 = 1
(gdb) p	high_bound
$2 = 2
...
but we calculate the number of elements in the array using
"high_bound - low_bound", which is 1.

Consequently, gdb fails to correctly classify the type as a ELFv2 homogeneous
aggregate.

Fix this by calculating the number of elements in the array by using
"high_bound - low_bound + 1" instead.

Furthermore, high_bound can (in general, though perhaps not here) be also be
smaller than low_bound, so to be safe take that into account as well:
...
	  LONGEST nr_array_elements = (low_bound > high_bound
				       ? 0
				       : (high_bound - low_bound + 1));
	  count *= nr_array_elements;
...

Tested on powerpc64le-linux.

PR tdep/31015
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31015
---
 gdb/ppc-sysv-tdep.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
index 20e732ff162..dd6f44c07ac 100644
--- a/gdb/ppc-sysv-tdep.c
+++ b/gdb/ppc-sysv-tdep.c
@@ -1127,7 +1127,11 @@ ppc64_aggregate_candidate (struct type *type,
 
 	  if (!get_array_bounds (type, &low_bound, &high_bound))
 	    return -1;
-	  count *= high_bound - low_bound;
+
+	  LONGEST nr_array_elements = (low_bound > high_bound
+				       ? 0
+				       : (high_bound - low_bound + 1));
+	  count *= nr_array_elements;
 
 	  /* There must be no padding.  */
 	  if (count == 0)

base-commit: f514e6e48061661cacfc980cd5272fd99887d38b
-- 
2.35.3


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

* Re: [PATCH] [gdb/tdep] Fix nr array elements in ppc64_aggregate_candidate
  2023-11-01  7:49 [PATCH] [gdb/tdep] Fix nr array elements in ppc64_aggregate_candidate Tom de Vries
@ 2023-11-02 17:41 ` Ulrich Weigand
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Weigand @ 2023-11-02 17:41 UTC (permalink / raw)
  To: gdb-patches, tdevries

Tom de Vries <tdevries@suse.de> wrote:

>Fix this by calculating the number of elements in the array by using
>"high_bound - low_bound + 1" instead.
>
>Furthermore, high_bound can (in general, though perhaps not here) be also be
>smaller than low_bound, so to be safe take that into account as well:
>...
>	  LONGEST nr_array_elements = (low_bound > high_bound
>				       ? 0
>				       : (high_bound - low_bound + 1));
>	  count *= nr_array_elements;
>...

I see.  This does appear to be a bug, indeed.

The patch looks good to me.


Bye,
Ulrich


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

end of thread, other threads:[~2023-11-02 17:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-01  7:49 [PATCH] [gdb/tdep] Fix nr array elements in ppc64_aggregate_candidate Tom de Vries
2023-11-02 17:41 ` Ulrich Weigand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).