Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Aaron Merey <amerey@redhat.com>
To: Simon Marchi <simark@simark.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] debuginfod-support.c: Replace globals with user_data
Date: Thu, 13 Aug 2020 17:54:51 -0400	[thread overview]
Message-ID: <CAJDtP-QMnzjAjtBhno+7QO8zF_r59yVYUFWXjCi6=g0aswp-9w@mail.gmail.com> (raw)
In-Reply-To: <468f4240-a259-8ce0-1788-00b3d6e6146b@simark.ca>

On Wed, Aug 12, 2020 at 5:45 PM Simon Marchi <simark@simark.ca> wrote:
> Hi Aaron,
>
> Thanks, just a few minor things, the patch LGTM with those fixed.
>
> > diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
> > index f4a227b040..3f51aaaf43 100644
> > --- a/gdb/debuginfod-support.c
> > +++ b/gdb/debuginfod-support.c
> > @@ -43,29 +43,37 @@ debuginfod_debuginfo_query (const unsigned char *build_id,
> >  #else
> >  #include <elfutils/debuginfod.h>
> >
> > -/* TODO: Use debuginfod API extensions instead of these globals.  */
> > -static std::string desc;
> > -static std::string fname;
> > -static bool has_printed;
> > +struct user_data
> > +{
> > +  user_data (const char *desc, const char *fname, bool has_printed)
> > +    : desc (desc), fname (fname), has_printed (has_printed)
>
> There's no need for the `has_printed` parameter.  Just initialize the `has_printed` field to false below.
>
> > +  { }
> > +
> > +  const char * const desc;
> > +  const char * const fname;
> > +  bool has_printed;
> > +};
> >
> >  static int
> >  progressfn (debuginfod_client *c, long cur, long total)
> >  {
> > +  user_data *data = static_cast<user_data *> (debuginfod_get_user_data (c));
> > +
> >    if (check_quit_flag ())
> >      {
> >        printf_filtered ("Cancelling download of %s %ps...\n",
> > -                    desc.c_str (),
> > -                    styled_string (file_name_style.style (), fname.c_str ()));
> > +                    data->desc,
> > +                    styled_string (file_name_style.style (), data->fname));
> >        return 1;
> >      }
> >
> > -  if (!has_printed && total != 0)
> > +  if (!data->has_printed && total != 0)
> >      {
> >        /* Print this message only once.  */
> > -      has_printed = true;
> > +      data->has_printed = true;
> >        printf_filtered ("Downloading %s %ps...\n",
> > -                    desc.c_str (),
> > -                    styled_string (file_name_style.style (), fname.c_str ()));
> > +                    data->desc,
> > +                    styled_string (file_name_style.style (), data->fname));
> >      }
> >
> >    return 0;
> > @@ -98,10 +106,9 @@ debuginfod_source_query (const unsigned char *build_id,
> >    if (c == nullptr)
> >      return scoped_fd (-ENOMEM);
> >
> > -  desc = std::string ("source file");
> > -  fname = std::string (srcpath);
> > -  has_printed = false;
> > +  struct user_data data ("source file", srcpath, false);
>
> Omit the `struct` keyword when referring to the new type.
>
> >
> > +  debuginfod_set_user_data (c, &data);
> >    scoped_fd fd (debuginfod_find_source (c,
> >                                       build_id,
> >                                       build_id_len,
> > @@ -136,11 +143,10 @@ debuginfod_debuginfo_query (const unsigned char *build_id,
> >    if (c == nullptr)
> >      return scoped_fd (-ENOMEM);
> >
> > -  desc = std::string ("separate debug info for");
> > -  fname = std::string (filename);
> > -  has_printed = false;
> >    char *dname = nullptr;
> > +  struct user_data data ("separate debug info for", filename, false);
>
> Same here.

Thanks Simon, I pushed the patch with these changes.

Aaron



      reply	other threads:[~2020-08-13 21:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-31 22:44 Aaron Merey
2020-08-01 14:44 ` Simon Marchi
2020-08-12 21:39   ` Aaron Merey
2020-08-12 21:45     ` Simon Marchi
2020-08-13 21:54       ` Aaron Merey [this message]

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='CAJDtP-QMnzjAjtBhno+7QO8zF_r59yVYUFWXjCi6=g0aswp-9w@mail.gmail.com' \
    --to=amerey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    /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