public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug tdep/32152] New: [gdb/tdep, riscv64] FAIL: gdb.cp/non-trivial-retval.exp: finish from f1
@ 2024-09-08 7:28 vries at gcc dot gnu.org
2024-09-08 8:42 ` [Bug tdep/32152] " schwab@linux-m68k.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2024-09-08 7:28 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=32152
Bug ID: 32152
Summary: [gdb/tdep, riscv64] FAIL:
gdb.cp/non-trivial-retval.exp: finish from f1
Product: gdb
Version: HEAD
Status: NEW
Severity: normal
Priority: P2
Component: tdep
Assignee: unassigned at sourceware dot org
Reporter: vries at gcc dot gnu.org
Target Milestone: ---
On riscv64-linux, I ran into:
...
(gdb) finish^M
Run till exit from #0 f1 (i1=i1@entry=23, i2=i2@entry=100) at
non-trivial-retval.cc:34^M
main () at non-trivial-retval.cc:163^M
163 B b = f2 (i1, i2);^M
Value returned is $6 = {a = -5856}^M
(gdb) FAIL: gdb.cp/non-trivial-retval.exp: finish from f1
...
The problem is that gdb thinks that the return value is in $a0:
...
$ gdb -q -batch non-trivial-retval \
-ex "b f1" \
-ex run \
-ex "set debug riscv infcall on" \
-ex finish
Breakpoint 1 at 0x80a: file non-trivial-retval.cc, line 34.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/riscv64-linux-gnu/libthread_db.so.1".
Breakpoint 1, f1 (i1=i1@entry=23, i2=i2@entry=100) at non-trivial-retval.cc:34
34 {
[riscv-infcall] riscv_return_value: [R] type: 'A', length: 0x4, alignment: 0x4,
register a0
[riscv-infcall] riscv_return_value: [R] type: 'A', length: 0x4, alignment: 0x4,
register a0
[riscv-infcall] riscv_return_value: [R] type: 'A', length: 0x4, alignment: 0x4,
register a0
main () at non-trivial-retval.cc:163
163 B b = f2 (i1, i2);
Value returned is $1 = {a = -3568}
...
while $a0 actually contains a pointer to the returned value 123:
...
(gdb) p /x $a0
$3 = 0x3ffffff210
(gdb) p *((unsigned int *)$a0)
$5 = 123
...
which is instead interpreted as an int:
...
(gdb) p (int) $a0
$6 = -3568
...
The system gcc compiler is configured with --with-abi=lp64d.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tdep/32152] [gdb/tdep, riscv64] FAIL: gdb.cp/non-trivial-retval.exp: finish from f1
2024-09-08 7:28 [Bug tdep/32152] New: [gdb/tdep, riscv64] FAIL: gdb.cp/non-trivial-retval.exp: finish from f1 vries at gcc dot gnu.org
@ 2024-09-08 8:42 ` schwab@linux-m68k.org
2024-09-08 11:02 ` vries at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: schwab@linux-m68k.org @ 2024-09-08 8:42 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=32152
--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
I don't understand why the values are returned through memory, they are all
word-sized aggregates.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tdep/32152] [gdb/tdep, riscv64] FAIL: gdb.cp/non-trivial-retval.exp: finish from f1
2024-09-08 7:28 [Bug tdep/32152] New: [gdb/tdep, riscv64] FAIL: gdb.cp/non-trivial-retval.exp: finish from f1 vries at gcc dot gnu.org
2024-09-08 8:42 ` [Bug tdep/32152] " schwab@linux-m68k.org
@ 2024-09-08 11:02 ` vries at gcc dot gnu.org
2024-09-09 3:40 ` vries at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2024-09-08 11:02 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=32152
--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Andreas Schwab from comment #1)
> I don't understand why the values are returned through memory, they are all
> word-sized aggregates.
Here (
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc
) I found:
...
Aggregates larger than 2×XLEN bits are passed by reference and are replaced in
the argument list with the address, as are C++ aggregates with nontrivial copy
constructors, destructors, or vtables.
...
So, I think it's the case of "C++ aggregates with nontrivial copy constructors,
destructors, or vtables".
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tdep/32152] [gdb/tdep, riscv64] FAIL: gdb.cp/non-trivial-retval.exp: finish from f1
2024-09-08 7:28 [Bug tdep/32152] New: [gdb/tdep, riscv64] FAIL: gdb.cp/non-trivial-retval.exp: finish from f1 vries at gcc dot gnu.org
2024-09-08 8:42 ` [Bug tdep/32152] " schwab@linux-m68k.org
2024-09-08 11:02 ` vries at gcc dot gnu.org
@ 2024-09-09 3:40 ` vries at gcc dot gnu.org
2025-01-09 12:58 ` vries at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2024-09-09 3:40 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=32152
--- Comment #3 from Tom de Vries <vries at gcc dot gnu.org> ---
Fixed by:
...
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 932708ca4e9..bfb3b350b1d 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -2857,8 +2857,11 @@ static void
riscv_call_arg_scalar_int (struct riscv_arg_info *ainfo,
struct riscv_call_info *cinfo)
{
+ auto lang_req = language_pass_by_reference (ainfo->type);
if (TYPE_HAS_DYNAMIC_LENGTH (ainfo->type)
- || ainfo->length > (2 * cinfo->xlen))
+ || ainfo->length > (2 * cinfo->xlen)
+ || !lang_req.trivially_copy_constructible
+ || !lang_req.trivially_destructible)
{
/* Argument is going to be passed by reference. */
ainfo->argloc[0].loc_type
...
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tdep/32152] [gdb/tdep, riscv64] FAIL: gdb.cp/non-trivial-retval.exp: finish from f1
2024-09-08 7:28 [Bug tdep/32152] New: [gdb/tdep, riscv64] FAIL: gdb.cp/non-trivial-retval.exp: finish from f1 vries at gcc dot gnu.org
` (2 preceding siblings ...)
2024-09-09 3:40 ` vries at gcc dot gnu.org
@ 2025-01-09 12:58 ` vries at gcc dot gnu.org
2025-01-10 9:32 ` cvs-commit at gcc dot gnu.org
2025-01-10 9:33 ` vries at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2025-01-09 12:58 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=32152
--- Comment #4 from Tom de Vries <vries at gcc dot gnu.org> ---
https://sourceware.org/pipermail/gdb-patches/2025-January/214582.html
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tdep/32152] [gdb/tdep, riscv64] FAIL: gdb.cp/non-trivial-retval.exp: finish from f1
2024-09-08 7:28 [Bug tdep/32152] New: [gdb/tdep, riscv64] FAIL: gdb.cp/non-trivial-retval.exp: finish from f1 vries at gcc dot gnu.org
` (3 preceding siblings ...)
2025-01-09 12:58 ` vries at gcc dot gnu.org
@ 2025-01-10 9:32 ` cvs-commit at gcc dot gnu.org
2025-01-10 9:33 ` vries at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2025-01-10 9:32 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=32152
--- Comment #5 from Sourceware Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <vries@sourceware.org>:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=84067a55fcbb15f903c7298adc3a708c6a431e12
commit 84067a55fcbb15f903c7298adc3a708c6a431e12
Author: Tom de Vries <tdevries@suse.de>
Date: Fri Jan 10 10:32:00 2025 +0100
[gdb/tdep] Fix gdb.cp/non-trivial-retval.exp on riscv64-linux
With test-case gdb.cp/non-trivial-retval.exp on riscv64-linux, I ran into:
...
(gdb) finish^M
Run till exit from #0 f1 (i1=i1@entry=23, i2=i2@entry=100) \
at non-trivial-retval.cc:34^M
main () at non-trivial-retval.cc:163^M
163 B b = f2 (i1, i2);^M
Value returned is $6 = {a = -5856}^M
(gdb) FAIL: $exp: finish from f1
...
where "Value returned is $6 = {a = 123}" is expected.
The problem is that gdb thinks that the return value is in $a0:
...
$ gdb -q -batch non-trivial-retval \
-ex "b f1" \
-ex run \
-ex "set debug riscv infcall on" \
-ex finish
Breakpoint 1 at 0x80a: file non-trivial-retval.cc, line 34.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/riscv64-linux-gnu/libthread_db.so.1".
Breakpoint 1, f1 (i1=i1@entry=23, i2=i2@entry=100) at
non-trivial-retval.cc:34
34 {
[riscv-infcall] riscv_return_value: \
[R] type: 'A', length: 0x4, alignment: 0x4, register a0
[riscv-infcall] riscv_return_value: \
[R] type: 'A', length: 0x4, alignment: 0x4, register a0
[riscv-infcall] riscv_return_value: \
[R] type: 'A', length: 0x4, alignment: 0x4, register a0
main () at non-trivial-retval.cc:163
163 B b = f2 (i1, i2);
Value returned is $1 = {a = -3568}
...
while $a0 actually contains a pointer to the returned value 123:
...
(gdb) p /x $a0
$3 = 0x3ffffff210
(gdb) p *((unsigned int *)$a0)
$5 = 123
...
The returned type is:
...
class A
{
public:
A () {}
A (A &obj);
int a;
};
...
which is a C++ aggregate with a nontrivial (because it's user-defined) copy
constructor:
According to the ABI [1], indeed this is returned by reference:
...
Values are returned in the same manner as a first named argument of the
same
type would be passed. If such an argument would have been passed by
reference, the caller allocates memory for the return value, and passes the
address as an implicit first parameter.
...
Aggregates larger than 2×XLEN bits are passed by reference and are replaced
in
the argument list with the address, as are C++ aggregates with nontrivial
copy
constructors, destructors, or vtables.
...
Fix this in riscv_call_arg_scalar_int by checking for
language_pass_by_reference ().trivially_copy_constructible.
The vtable case is explictly mentioned in the ABI, but AFAIU already
covered
by the nontrivial copy constructor case.
The nontrivial destructor case is also not supported, but the testsuite
doesn't seem to trigger this.
Fix this by:
- extending the test-case to cover this scenario, and
- fixing it in riscv_call_arg_scalar_int by checking for
language_pass_by_reference ().trivially_destructible.
Tested on riscv64-linux.
PR tdep/32152
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32152
Approved-By: Andrew Burgess <aburgess@redhat.com>
[1]
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug tdep/32152] [gdb/tdep, riscv64] FAIL: gdb.cp/non-trivial-retval.exp: finish from f1
2024-09-08 7:28 [Bug tdep/32152] New: [gdb/tdep, riscv64] FAIL: gdb.cp/non-trivial-retval.exp: finish from f1 vries at gcc dot gnu.org
` (4 preceding siblings ...)
2025-01-10 9:32 ` cvs-commit at gcc dot gnu.org
@ 2025-01-10 9:33 ` vries at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: vries at gcc dot gnu.org @ 2025-01-10 9:33 UTC (permalink / raw)
To: gdb-prs
https://sourceware.org/bugzilla/show_bug.cgi?id=32152
Tom de Vries <vries at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Target Milestone|--- |17.1
Resolution|--- |FIXED
--- Comment #6 from Tom de Vries <vries at gcc dot gnu.org> ---
Fixed.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-01-10 9:33 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-08 7:28 [Bug tdep/32152] New: [gdb/tdep, riscv64] FAIL: gdb.cp/non-trivial-retval.exp: finish from f1 vries at gcc dot gnu.org
2024-09-08 8:42 ` [Bug tdep/32152] " schwab@linux-m68k.org
2024-09-08 11:02 ` vries at gcc dot gnu.org
2024-09-09 3:40 ` vries at gcc dot gnu.org
2025-01-09 12:58 ` vries at gcc dot gnu.org
2025-01-10 9:32 ` cvs-commit at gcc dot gnu.org
2025-01-10 9:33 ` vries at gcc dot gnu.org
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).