public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: Carl Love <cel@us.ibm.com>
Cc: gdb-patches@sourceware.org, Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
Subject: Re: [PATCH 2/2] PowerPC, fix support for printing the function return value for non-trivial values.
Date: Mon, 17 Oct 2022 18:06:57 -0700	[thread overview]
Message-ID: <20221017180657.54a9aeec@f35-zws-1> (raw)
In-Reply-To: <41e8f94ed30fb22c94a05a0823de2f5ae2250334.camel@us.ibm.com>

On Fri, 14 Oct 2022 16:23:58 -0700
Carl Love <cel@us.ibm.com> wrote:

> > 2) Whitespace complaints:
> > 
> > Applying: PowerPC, fix support for printing the function return value
> > for non-trivial values.
> > ...patch:161: indent with spaces.
> >                       "gdbarch_dump: get_return_buf_addr = <%s>\n",
> > ...patch:162: indent with spaces.
> >                       host_address_to_string (gdbarch-  
> > >get_return_buf_addr));  
> > ...patch:182: indent with spaces.
> >                                  gdbarch_get_return_buf_addr_ftype
> > get_return_buf_addr)
> > warning: 3 lines add whitespace errors.
> > 
> > (I substituted some long paths local to my machines w/ '...'.)  
> 
> Yes, I have seen the complaints about the white spaces.  The whitespace
> complaints come from file gdb/gdbarch.c which is a generated file.  As
> I assume you know, the file was regenerated by the gdb/gdbarch.py based
> on the changes to gdb/gdbarch-components.py.  The regenerated file is
> set to read only.  Not sure what I can do to rectify the white spaces? 
> Any ideas?

If the unwanted white space is generated by gdbarch.py,maybe fix that
script?

That said, if those files already have this problem, I'm okay with
it going in with the whitespace complaints.  (It can be fixed in
a later patch addressing just that problem.)

> > I already mentioned this last week, but...
> > 
> > s/GDB ABI/gdbarch method/
> > 
> > I guess you could also refer to it as an API which you did later on
> > in your commit remarks.  (What I really object to is calling it an
> > "ABI", which it definitely is not - that said it's easy to mis-type
> > API
> > as ABI, so I do understand this mistake.)  
> 
> Yea, I think referring to it as a new gdbarch method is probably better
> than GDB API/ABI.  I have changed the GDB API/ABI references to gdbarch
> method.  I will need to update that in the message to the GDB
> maintainers as well when I send the next version of the patch.

Sounds good.

> > > value of r3 on entry to the function.  This requires the use of the
> > > -fvar-tracking compiler option to compile the user application thus
> > > generating the DW_OP_entry_value in the binary.  The DW_OP_entries
> > > in the  
> > 
> > I don't think that "DW_OP_entries" is correct here.  Maybe
> > "DW_OP_entry_value
> > entries"?  
> 
> > > binary file enables GDB can resolve the DW_TAG_call_sites.  This
> > > new API  
> > 
> > Maybe instead of "enables GDB can resolve the DW_TAG_call_sites", say
> > "allow GDB to resolve the DW_TAG_call_site entries".
> > 
> >   
> > > is used to get the return buffer address, in the case of a function
> > > returning a nontrivial data type, on exit from the function.  The
> > > GDB
> > > function should_stop checks to see if RETURN_BUF is non-zero.  By
> > > default,
> > > RETURN_BUF will be set to zero by the new ABI call for all
> > > architectures  
> > 
> > s/ABI/API/
> >   
> > > but PowerPC.  The get_return_value function will be used to obtain
> > > the
> > > return value on these architectures as is currently being done if
> > > RETURN_BUF is zero.  On PowerPC, the new ABI will return a nonzero
> > > address
> > > in RETURN_BUF if the value can be determined.  The value_at
> > > function uses
> > > the return buffer address to get the return value.  
> 
> So, I tried to address all of the above comments about ABI,
> "DW_OP_entries" etc.  The paragraph now reads:
> 
> This patch adds a new gdbarch method to allow PowerPC to access the value
> of r3 on entry to a function. On PowerPC, the new gdb arch method attempts
> to use the DW_OP_entry_value for the DWARF entries, when exiting the
> function, to determine the value of r3 on entry to the function.  This
> requires the use of the -fvar-tracking compiler option to compile the
> user application thus generating the DW_OP_entry_value in the binary.  The
> DW_OP_entry_value entries in the binary file allows GDB to resolve the
> DW_TAG_call_site entries.  This new gdbarch method is used to get the
> return buffer address, in the case of a function returning a nontrivial
> data type, on exit from the function.  The GDB function should_stop checks
> to see if RETURN_BUF is non-zero.  By default, RETURN_BUF will be set to
> zero by the new gdbarch method call for all architectures except PowerPC.
> The get_return_value function will be used to obtain the return value on
> all other architectures as is currently being done if RETURN_BUF is zero.
> On PowerPC, the new gdbarch method will return a nonzero address in
> RETURN_BUF if the value can be determined.  The value_at function uses the
> return buffer address to get the return value.
> 
> Which I think covers all of the comments above. 

Yes, this looks good, though I'd use 'gdbarch' in place of 'gdb arch'.
This is a small nit though; if you'd prefer to make them separate
words, I won't argue about it.

> > >    if (execution_direction == EXEC_REVERSE)
> > > diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
> > > index 14effb93210..59145f9f166 100644
> > > --- a/gdb/ppc-sysv-tdep.c
> > > +++ b/gdb/ppc-sysv-tdep.c
> > > @@ -28,6 +28,7 @@
> > >  #include "objfiles.h"
> > >  #include "infcall.h"
> > >  #include "dwarf2.h"
> > > +#include "dwarf2/loc.h"
> > >  #include "target-float.h"
> > >  #include <algorithm>
> > >  
> > > @@ -2156,3 +2157,39 @@ ppc64_sysv_abi_return_value (struct gdbarch
> > > *gdbarch, struct value *function,
> > >    return RETURN_VALUE_STRUCT_CONVENTION;
> > >  }
> > >  
> > > +CORE_ADDR ppc64_sysv_get_return_buf_addr (struct type *val_type,
> > > +					  frame_info *cur_frame)
> > > +{
> > > +  /* On PowerPC, the ABI specifies r3 is the address where an
> > > argument  
> > 
> > s/specifies/specifies that/
> > 
> > I'm not sure about this phrase:  "where an argument and".  If you
> > mean
> > to say that r3 is sometimes used for arguments (when it's not used
> > for
> > the address of the return value buffer), then that's true, but it's
> > not relevant here.
> > 
> > So, I guess that I'm asking that this comment be reworded somewhat.
> >   
> > > +     and the return value is stored.  The PowerPC ABI does not
> > > guarantee
> > > +     r3 will be preserved when the function returns.  The function
> > > returns
> > > +     the address of the buffer stored in r3.  
> > 
> > I find this part confusing.  If the function returns the address of
> > the buffer, doesn't it do so by returning it in r3?  (And, if so, it
> > seems to me that this code would be unnecessary - so, clearly, I must
> > be missing something...)  
> 
> > > +
> > > +     Attempt to determine the value of r3 on entry to the function
> > > using the
> > > +     DW_OP_entry_value DWARF entries.  This requires compiling the
> > > user
> > > +     program with -fvar-tracking to resolve the DW_TAG_call_sites
> > > in the
> > > +     binary file.  */  
> 
> OK, so some rework here to make things a bit better.  I changed the
> header comment for function ppc64_sysv_get_return_buf_addr to the
> following.  Hopefully this addresses the various questions and
> comments.
> 
>   /* The PowerPC ABI specifies aggregates that are not returned by value
>      are returned in a storage buffer provided by the caller.  The
>      address of the storage buffer is provided as a hidden first input
>      arguement in register r3.  The PowerPC ABI does not guarantee that
>      register r3 will not be changed while executing the function.  Hence, it
>      cannot be assumed that r3 will still contain the address of the storage
>      buffer when execution reaches the end of the function.
> 
>      This function attempts to determine the value of r3 on entry to the
>      function using the DW_OP_entry_value DWARF entries.  This requires
>      compiling the user program with -fvar-tracking to resolve the
>      DW_TAG_call_sites in the binary file.  */
> 
> Hopefully that is clearer and clears up any confusion as to the role of r3.

Thanks for reworking that comment.

> > > +  catch (const gdb_exception_error &e)
> > > +    {
> > > +      warning ("Cannot determine the function return value.\n"
> > > +	       "Try compiling with -fvar-tracking.");  
> > 
> > Will this warning be printed a lot?  (I'm wondering if there should
> > be a
> > way to shut it off...)  
> 
> Hmm, hard to say how often it will get printed.  It is going to be up
> to what the user is trying to do.  If they are stopping on the return
> of functions that return non-trivial structures, they will see the
> message for every function.  Otherwise, the message should not get
> printed. 
> 
> Not aware of anyway we could prompt the user to ask them if they want
> to suppress this message from the command line.  If there is, can you
> give me a pointer to an example?
> 
> We could do something like:
> 
> catch (const gdb_exception_error &e)
>     {
>       static int warned = 0;
> 
>       if (warned++ < 6)
>         warning ("Cannot determine the function return value.\n"
>                  "Try compiling with -fvar-tracking.");
>     }
> 
> So the warning is only printed the first five or whatever number of
> times we want before suppressing the message.  Not sure what the right
> number of times should be? 
> 
> Would adding something like this be agreeable?

Maybe.  If we go that route, I'd recommend printing an additional
message along side the last "Cannot determine the function return value."
message indicating that these messages are now being suppressed.

We have several mechanisms in gdb for suppressing messages already. 
Probably the most used one is the "complaints" facility for
supressing warnings while reading symbols.  (See
gdb/complaints.{h,c}.) I recently added a bfd error supression
mechanism in gdb_bfd.c.  Look for gdb_bfd_error_handler() in that
file.  There's also lim_warning() in ada-lang.c along with an old
FIXME remark indicating that it's doing something similar to that of
complaint().  There may be others, but I don't know for sure.
None of them prompt the user about whether to continue to print
warnings; I'd prefer not to do it that way.  Hard coding it to six (or
something) is okay.  Making it user-settable with some default is
also okay.  That said, this is just one message. It seems like overkill
to add a setting for this one message.

After thinking about this a bit more, I think we should go with your
original code which doesn't suppress any messages.  If we find that
it's too noisy, we can add something along the lines of what you
suggested above.

Kevin


  reply	other threads:[~2022-10-18  1:07 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-11 22:26 [PATCH] PowerPC, add support for printing non-trivial C++ object for the finish command Carl Love
2022-03-13  5:28 ` Joel Brobecker
2022-03-14 10:43 ` Luis Machado
2022-03-14 13:40 ` Tom Tromey
2022-03-14 13:45   ` Luis Machado
2022-03-14 14:58   ` Ulrich Weigand
     [not found]     ` <ce6c71356c4a58fcdfb655a6e50c3a24f812e66c.camel@us.ibm.com>
     [not found]       ` <d9f17525c9a03c20b54015a6a71c36cae50fe4e3.camel@de.ibm.com>
     [not found]         ` <6ca2276426343756e103995e07ff951d6e26837b.camel@us.ibm.com>
     [not found]           ` <939797b94ab71f3f7356747d84a1515939cb3dcc.camel@de.ibm.com>
     [not found]             ` <fccc34c438fda9a35b8a8565e0f5026237e7eab9.camel@us.ibm.com>
     [not found]               ` <bb5b9b137fc11886964113d4b524526b3c733f4a.camel@us.ibm.com>
     [not found]                 ` <1edb818bd2873a3fa5278f28131089d228a0a4f6.camel@de.ibm.com>
     [not found]                   ` <7c884a865d06890cb325225c65d7a52fdfbd20d2.camel@us.ibm.com>
     [not found]                     ` <846ca96309d2732d3db0e4c323a81105c098fa5f.camel@de.ibm.com>
     [not found]                       ` <5a858dd7b957ecf45cf5b00ffc140a839c8ef023.camel@us.ibm.com>
     [not found]                         ` <b634fecae5e33a3d1a278191c37f306a3b8622f2.camel@de.ibm.com>
     [not found]                           ` <25f2380ced176f58a8e3ea9b70c7e7786988d650.camel@us.ibm.com>
     [not found]                             ` <2b0481466e9ecc33d52c74c3a3b4babb05435f47.camel@de.ibm.com>
     [not found]                               ` <df3b049416ff666e7bd3e3a91e4ea90d34256ea5.camel@us.ibm.com>
     [not found]                                 ` <71370ce02bd57827d3b7958772b1594d3591bd16.camel@de.ibm.com>
     [not found]                                   ` <ec9dafb1671699b03b28ee4be528711c6988eaa5.camel@us.ibm.com>
     [not found]                                     ` <148d8d3efcc8d110119e566027bfd0c65dd02525.camel@de.ibm.com>
     [not found]                                       ` <eef62b295e97fc464c22f9d748ff818860137de9.camel@us.ibm.com>
     [not found]                                         ` <afd6fa576f479359618b1ee50b08be8932735da8.camel@de.ibm.com>
     [not found]                                           ` <cb6b19e9d287d2bae4b72627791f2a00af062c48.camel@us.ibm.com>
     [not found]                                             ` <ee7101f86b5c8581905c53347fa603dc23ddc2bd.camel@de.ibm.com>
     [not found]                                               ` <8decd662134d57e8caf43960a1cdc47723e2bfe3.camel@us.ibm.com>
     [not found]                                                 ` <f7cad695cf64540bad8c95cf5fd31691711d0eeb.camel@de.ibm.com>
     [not found]                                                   ` <79d82ed277308ed5ce312bff398e770ab234390a.camel@us.ibm.com>
     [not found]                                                     ` <63f21a897f452d81a73fb386cb99110a359ef0b7.camel@de.ibm.com>
     [not found]                                                       ` <be178bc4f356d7f1937458290cb5883eeee9eee1.camel@us.ibm.com>
     [not found]                                                         ` <dfd935e9414d3dd2c27d1e877d3718ae7510aa07.camel@de.ibm.com>
     [not found]                                                           ` <97275f61ef101a12cde8e5a45008ed8e479424eb.camel@us.ibm.com>
     [not found]                                                             ` <b629440707165f46fb466e48b0c95de3bfa334d2.camel@de.ibm.com>
     [not found]                                                               ` <5a34aaeab59f0099b915d1780c701284a6cf691e.camel@us.ibm.com>
     [not found]                                                                 ` <8aa882863b2f4cef38c22386387c5705bf63c3d5.camel@de.ibm.com>
2022-10-06 16:37                                                                   ` [PATCH 1/2] PowerPC, function ppc64_sysv_abi_return_value add missing return value convention Carl Love
2022-10-08  4:20                                                                     ` Kevin Buettner
2022-10-14 23:20                                                                       ` Carl Love
2022-10-18 18:55                                                                     ` [PATCH 1/2 ver 2] " Carl Love
2022-11-07 20:04                                                                       ` [PATCH 1/2 ver 3] " Carl Love
2022-11-14 16:45                                                                         ` Ulrich Weigand
2022-11-14 19:38                                                                           ` Carl Love
     [not found]                                                               ` <191f5826b228a7614c084c9704b086851d418c78.camel@us.ibm.com>
     [not found]                                                                 ` <5405a79ecd6ed34646ad77eed0779063ee222d37.camel@de.ibm.com>
2022-10-06 16:36                                                                   ` [PATCH 0/2] PowerPC, fix support for printing the function return value for non-trivial values Carl Love
2022-10-18 18:55                                                                     ` [PATCH 0/2 version 2] " Carl Love
2022-10-06 16:37                                                                   ` [PATCH 2/2] " Carl Love
2022-10-08  4:36                                                                     ` Kevin Buettner
2022-10-12 17:01                                                                       ` Carl Love
2022-10-14  2:49                                                                     ` Kevin Buettner
2022-10-14  7:36                                                                       ` Bruno Larsen
2022-10-14 23:25                                                                         ` Carl Love
2022-10-14 23:23                                                                       ` Carl Love
2022-10-18  1:06                                                                         ` Kevin Buettner [this message]
2022-10-18 18:26                                                                           ` Carl Love
2022-10-18 18:55                                                                     ` [PATCH 2/2 ver 2] " Carl Love
2022-10-31 16:07                                                                       ` Carl Love
2022-11-07 14:56                                                                       ` Bruno Larsen
2022-11-07 19:53                                                                         ` Carl Love
2022-11-07 20:04                                                                       ` [PATCH 2/2 ver 3] " Carl Love
2022-11-14 16:47                                                                         ` Ulrich Weigand
2022-11-15  7:15                                                                           ` Tom de Vries
2022-11-15 10:16                                                                             ` Ulrich Weigand
2022-11-15 16:04                                                                               ` Carl Love
2022-11-15 16:55                                                                                 ` Simon Marchi
2022-11-15 23:46                                                                                   ` Carl Love
2022-11-15 17:24                                                                               ` Carl Love
2022-11-15 18:05                                                                                 ` Ulrich Weigand
2022-11-16  1:01                                                                                   ` Carl Love
2022-11-16  9:52                                                                                     ` Ulrich Weigand
2022-11-16 10:12                                                                                     ` Tom de Vries
2022-11-16 10:20                                                                                     ` Lancelot SIX
2022-11-16 15:56                                                                                       ` Carl Love
2022-11-16 20:55                                                                                       ` [PATCH] Change NULL to nullptr in gdb/infcmd.c and gdb/infrun.c Carl Love
2022-11-16 21:15                                                                                         ` Simon Marchi

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=20221017180657.54a9aeec@f35-zws-1 \
    --to=kevinb@redhat.com \
    --cc=Ulrich.Weigand@de.ibm.com \
    --cc=cel@us.ibm.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).