public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Kamil Rytarowski <n54@gmx.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Implement basic threading support in the NetBSD target
Date: Wed, 01 Apr 2020 14:43:49 -0600	[thread overview]
Message-ID: <87lfnfym0q.fsf@tromey.com> (raw)
In-Reply-To: <20200326025314.2392-1-n54@gmx.com> (Kamil Rytarowski's message of "Thu, 26 Mar 2020 03:53:14 +0100")

>>>>> "Kamil" == Kamil Rytarowski <n54@gmx.com> writes:

Kamil> Use sysctl(3) as the portable interface to prompt NetBSD threads on
Kamil> all supported NetBSD versions. In future newer versions could switch
Kamil> to PT_LWPSTATUS ptrace(2) API that will be supported on NetBSD 10.0
Kamil> and newer.

Thank you for the patch.

Kamil> +static void
Kamil> +nbsd_thread_lister (const pid_t pid,
Kamil> +		    std::function<bool (const struct kinfo_lwp *)> callback)

Perhaps a const reference here would be better.
Or maybe gdb::function_view, I'm not sure.

Kamil> +      /* Return true if the specified thread is alive.  */
Kamil> +      auto lwp_alive =
Kamil> +	[&l]()
Kamil> +	{
Kamil> +	  switch (kl->l_stat)
Kamil> +	    {
Kamil> +	    case LSSLEEP:
Kamil> +	    case LSRUN:
Kamil> +	    case LSONPROC:
Kamil> +	    case LSSTOP:
Kamil> +	    case LSSUSPENDED:
Kamil> +	      return true;
Kamil> +	    default:
Kamil> +	      return false;
Kamil> +	    }
Kamil> +	};
Kamil> +
Kamil> +      /* Ignore embryonic or demised threads.  */
Kamil> +      if (!lwp_alive (l))
Kamil> +	continue;

I don't think a lambda is needed here.

Kamil> +bool
Kamil> +nbsd_nat_target::thread_alive (ptid_t ptid)
Kamil> +{
Kamil> +  pid_t pid = ptid.pid ();
Kamil> +  int lwp = ptid.lwp ();
Kamil> +  bool found = false;
Kamil> +
Kamil> +  auto fn =
Kamil> +    [&lwp, &found] (const struct kinfo_lwp *kl)
Kamil> +    {
Kamil> +      if (kl->l_lid == lwp)
Kamil> +	{
Kamil> +	  found = true;
Kamil> +	  return true;
Kamil> +	}
Kamil> +      return false;
Kamil> +    };
Kamil> +
Kamil> +  nbsd_thread_lister (pid, fn);
Kamil> +
Kamil> +  return found;

A classic pattern in gdb is to have one of these iteration functions
(here, nbsd_thread_lister) return bool and have it return true if any
callback returns true, and false otherwise.

That would eliminate this "found" variable.

Kamil> +const char *
Kamil> +nbsd_nat_target::thread_name (struct thread_info *thr)
Kamil> +{
Kamil> +  static char buf[KI_LNAMELEN] = {};
...
Kamil> +  return buf;

This should return NULL if no name was found.
The above bool return would make this easy as well.

Kamil> +      fprintf_unfiltered (gdb_stdlog, "NLWP: pid=%d lwp=%d\n", pid, kl->l_lid);

This line should be removed.

Tom

  parent reply	other threads:[~2020-04-01 20:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-26  2:53 Kamil Rytarowski
2020-03-26  3:16 ` [PATCH v2] " Kamil Rytarowski
2020-03-30 21:17   ` Kamil Rytarowski
2020-04-01 20:44   ` Tom Tromey
2020-04-01 21:03     ` Kamil Rytarowski
2020-04-01 21:01   ` [PATCH v3] " Kamil Rytarowski
2020-04-01 21:33     ` [PATCH v4] " Kamil Rytarowski
2020-04-02 19:05       ` Pedro Alves
2020-04-02 19:22         ` Kamil Rytarowski
2020-04-02 19:24       ` [PATCH v5] " Kamil Rytarowski
2020-04-06  7:26         ` Kamil Rytarowski
2020-04-06 20:50         ` Tom Tromey
2020-04-01 20:43 ` Tom Tromey [this message]
2020-04-01 21:39   ` [PATCH] " Kamil Rytarowski

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=87lfnfym0q.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=n54@gmx.com \
    /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).