RFA: tolerate unavailable struct return values

Jim Blandy jimb@zwingli.cygnus.com
Fri Nov 23 13:51:00 GMT 2001


Daniel Jacobowitz <drow@mvista.com> writes:
> On Thu, Nov 29, 2001 at 05:09:13PM -0500, Jim Blandy wrote:
> > 
> > On some architectures, it's impossible for GDB to find structs
> > returned by value.  These shouldn't be failures.  Should they be
> > passes?
> 
> Out of curiousity, which architectures?  And to be pedantic, I suspect
> that it might be "not always possible" rather than actually
> impossible.

The one I have in mind is the S/390, although I'm pretty sure there
are others.  I've included the bug report I sent to the S/390 GCC
maintainers below.

One approach would be to hope that the return buffer's address was
still there in the register it was passed in.  But there's no way to
tell when you're wrong.  GDB will just print garbage, and the user
will think their program is wrong.  Better to simply say, "I can't
find this information reliably", and let the user, who knows their
program, find another way to get the info --- setting a breakpoint on
the return statement, or looking at where the caller put the
structure.


------- Start of forwarded message -------
From: Jim Blandy <jimb@zwingli.cygnus.com>
To: Hartmut Penner <hpenner@de.ibm.com>,
	Ulrich Weigand <uweigand@de.ibm.com>
Cc: Chris Moller <cmoller@redhat.com>,
	Matt Hiller <hiller@cygnus.com>
Subject: GDB unable to find structs returned by value using S/390 ABI 
Message-Id: <20011129190712.6AA5D5E9DB@zwingli.cygnus.com>
Date: Thu, 29 Nov 2001 14:07:12 -0500 (EST)


Given the way the S/390 Linux ABI specifies functions should return
structures by value, it is sometimes impossible for GDB to find
functions' return values.  There is a simple fix for this which is
backwards binary compatible with existing code; I don't think it will
have much impact on performance.

According to the ABI, structures which are one, two, four, or eight
bytes long must be returned by value in registers r2 and r3.  These
structures pose no problem for GDB.  However, the ABI specifies that
all other structures should be written to a buffer allocated by the
caller, whose address is passed to the callee as an "invisible" first
argument, in r2.  GDB is unable to find structs returned this way.

Suppose the user is running their program under GDB, and stops
execution in the middle of a function which will return a structure by
value.  The user then types the 'finish' command, which runs the
current function call to completion, and prints the value it returns.

By the time the function has returned to its caller, it will have
stored the returned struct in the caller's buffer.  Unfortunately, GDB
has no way at this point to find out where this buffer is.  The caller
passed it to the callee in r2, but the callee is free to do whatever
it pleases with that address; r2's value is unspecified upon return.

I suggest that we amend the ABI to require the callee to return the
address of the buffer holding the returned struct in r2.  This will
allow GDB to reliably find the buffer.  Since the pointer to the
buffer is live until the return value has been computed anyway, this
requirement shouldn't significantly increase register pressure in the
callee.

------- End of forwarded message -------



More information about the Gdb-patches mailing list