From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jim Blandy To: Daniel Jacobowitz Cc: gdb-patches@sources.redhat.com Subject: Re: RFA: tolerate unavailable struct return values Date: Fri, 30 Nov 2001 12:48:00 -0000 Message-id: References: <20011129220913.2D72A5E9D8@zwingli.cygnus.com> <20011129173644.A15429@nevyn.them.org> X-SW-Source: 2001-11/msg00629.html Daniel Jacobowitz 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 To: Hartmut Penner , Ulrich Weigand Cc: Chris Moller , Matt Hiller 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 ------- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32070 invoked by alias); 30 Nov 2001 20:48:39 -0000 Mailing-List: contact gdb-patches-help@sourceware.cygnus.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 31824 invoked from network); 30 Nov 2001 20:48:37 -0000 Received: from unknown (HELO zwingli.cygnus.com) (208.245.165.35) by hostedprojects.ges.redhat.com with SMTP; 30 Nov 2001 20:48:37 -0000 Received: by zwingli.cygnus.com (Postfix, from userid 442) id AD9A65E9D8; Fri, 30 Nov 2001 15:49:52 -0500 (EST) To: Daniel Jacobowitz Cc: gdb-patches@sources.redhat.com Subject: Re: RFA: tolerate unavailable struct return values References: <20011129220913.2D72A5E9D8@zwingli.cygnus.com> <20011129173644.A15429@nevyn.them.org> From: Jim Blandy Date: Fri, 23 Nov 2001 13:51:00 -0000 In-Reply-To: Daniel Jacobowitz's message of Thu, 29 Nov 2001 17:36:44 -0500 Message-ID: X-Mailer: Gnus v5.3/Emacs 19.34 X-SW-Source: 2001-11/txt/msg00414.txt.bz2 Message-ID: <20011123135100.KTx5lcXu2BumcW2Od8Zi6fr8PV0K639k1bLQ8satLOo@z> Daniel Jacobowitz 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 To: Hartmut Penner , Ulrich Weigand Cc: Chris Moller , Matt Hiller 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 -------