public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Simon Marchi <simon.marchi@polymtl.ca>, gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: Re: [PATCH v2 11/14] gdb: move displaced stepping logic to gdbarch, allow starting concurrent displaced steps
Date: Fri, 4 Dec 2020 01:50:41 +0000	[thread overview]
Message-ID: <cd536505-e895-83ae-c3b1-2a1e776c7fbe@palves.net> (raw)
In-Reply-To: <20201202154805.1484317-12-simon.marchi@polymtl.ca>

Very good!  Only a few minor comments below.  Otherwise OK.

On 12/2/20 3:48 PM, Simon Marchi via Gdb-patches wrote:

> +displaced_step_finish_status
> +displaced_step_buffer::finish (gdbarch *arch, thread_info *thread,
> +			       gdb_signal sig)
> +{
> +  gdb_assert (thread->displaced_step_state.in_progress ());
> +  gdb_assert (thread == m_current_thread);
> +
> +  /* Move this to a local variable so it's released in case something goes
> +     wrong.  */
> +  displaced_step_copy_insn_closure_up copy_insn_closure
> +    = std::move (m_copy_insn_closure);
> +  gdb_assert (copy_insn_closure != nullptr);
> +
> +  /* Reset m_current_thread immediately to mark the buffer as available, in case

Uppercase m_current_thread.

> +     something goes wrong below.  */
> +  m_current_thread = nullptr;
> +
> +  /* Now that a buffer gets freed, tell GDB it can ask us to prepare a displaced

How about "tell infrun" instead of "tell GDB"?  This is all in GDB.

> +     step again for this inferior.  Do that here in case something goes wrong
> +     below.  */
> +  thread->inf->displaced_step_state.unavailable = false;
> +
> +  ULONGEST len = gdbarch_max_insn_length (arch);
> +


> @@ -1927,14 +1833,41 @@ static step_over_what thread_still_needs_step_over (struct thread_info *tp);
>  static bool
>  start_step_over (void)
>  {
> -  struct thread_info *tp, *next;
> +  thread_info *next;
>  
>    /* Don't start a new step-over if we already have an in-line
>       step-over operation ongoing.  */
>    if (step_over_info_valid_p ())
>      return false;
>  
> -  for (tp = global_thread_step_over_chain_head; tp != NULL; tp = next)
> +  /* Steal the global thread step over chain.  As we try to initiate displaced
> +     steps, threads will be enqueued in the global chain if no buffers are
> +     available.  If we iterated on the global chain directly, we might iterate
> +     indefinitely.  */
> +  thread_info *threads_to_step = global_thread_step_over_chain_head;
> +  global_thread_step_over_chain_head = NULL;
> +
> +  infrun_debug_printf ("stealing global queue of threads to step, length = %d",
> +		       thread_step_over_chain_length (threads_to_step));
> +
> +  bool started = false;
> +
> +  /* On scope exit (whatever the reason, return or exception), if there are
> +     threads left in the THREADS_TO_STEP chain, put back these threads in the
> +     global list.  */
> +  SCOPE_EXIT {

This format looks un-GNU-ish to me.  I've been putting the {
on the following line, indented by two spaces, like if it was
a if/for/while block, like:

  SCOPE_EXIT
    {

... unless the whole thing fits in one line:

  SCOPE_EXIT { foo (); };

> +    if (threads_to_step == nullptr)
> +      infrun_debug_printf ("step-over queue now empty");
> +    else
> +      {
> +	infrun_debug_printf ("putting back %d threads to step in global queue",
> +			     thread_step_over_chain_length (threads_to_step));
> +
> +	global_thread_step_over_chain_enqueue_chain (threads_to_step);
> +      }
> +  };
> +
> +  for (thread_info *tp = threads_to_step; tp != NULL; tp = next)
>      {
>        struct execution_control_state ecss;
>        struct execution_control_state *ecs = &ecss;
> @@ -1943,12 +1876,23 @@ start_step_over (void)
>  
>        gdb_assert (!tp->stop_requested);
>  
> -      next = global_thread_step_over_chain_next (tp);
> +      next = thread_step_over_chain_next (threads_to_step, tp);
>  
> -      /* If this inferior already has a displaced step in process,
> -	 don't start a new one.  */
> -      if (displaced_step_in_progress (tp->inf))
> -	continue;
> +      if (tp->inf->displaced_step_state.unavailable)
> +	{
> +	  /* The arch told us to not even try preparing another displaced step
> +	     for this inferior.  Just leave the thread in THREADS_TO_STEP, it
> +	     will get moved to the global chain on scope exit.  */
> +	  continue;
> +	}
> +
> +      /* Remove thread from the THREADS_TO_STEP chain.  If anything goes wrong
> +	 while we try to prepare the displaced step, we don't add it back to
> +	 the global step over chain.  This is to avoid a thread staying in the
> +	 step over chain indefinitely if something go wrong when resuming it.

something goes wrong

> +	 If the error is intermittent and it still needs a step over, it will
> +	 get enqueued again when we try to resume it normally.  */
> +      thread_step_over_chain_remove (&threads_to_step, tp);


  reply	other threads:[~2020-12-04  1:50 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-02 15:47 [PATCH v2 00/14] Concurrent displaced stepping Simon Marchi
2020-12-02 15:47 ` [PATCH v2 01/14] gdb: add inferior_execd observable Simon Marchi
2020-12-04  1:45   ` Pedro Alves
2020-12-02 15:47 ` [PATCH v2 02/14] gdb: clear inferior displaced stepping state and in-line step-over info on exec Simon Marchi
2020-12-02 17:16   ` Simon Marchi
2020-12-04  1:54     ` Pedro Alves
2020-12-04 20:49       ` Simon Marchi
2020-12-04  1:48   ` Pedro Alves
2020-12-04 21:03     ` Simon Marchi
2020-12-02 15:47 ` [PATCH v2 03/14] gdb: restore displaced step buffer bytes when another thread forks Simon Marchi
2020-12-04  1:48   ` Pedro Alves
2020-12-02 15:47 ` [PATCH v2 04/14] gdb: get rid of get_displaced_stepping_state Simon Marchi
2020-12-04  1:48   ` Pedro Alves
2020-12-04 21:06     ` Simon Marchi
2020-12-02 15:47 ` [PATCH v2 05/14] gdb: rename things related to step over chains Simon Marchi
2020-12-04  1:49   ` Pedro Alves
2020-12-04 21:04     ` Simon Marchi
2020-12-02 15:47 ` [PATCH v2 06/14] gdb: rename displaced_step_closure to displaced_step_copy_insn_closure Simon Marchi
2020-12-04  1:49   ` Pedro Alves
2020-12-02 15:47 ` [PATCH v2 07/14] gdb: rename displaced_step_fixup to displaced_step_finish Simon Marchi
2020-12-04  1:49   ` Pedro Alves
2020-12-02 15:47 ` [PATCH v2 08/14] gdb: introduce status enum for displaced step prepare/finish Simon Marchi
2020-12-04  1:49   ` Pedro Alves
2020-12-04 21:08     ` Simon Marchi
2020-12-02 15:48 ` [PATCH v2 09/14] gdb: pass inferior to get_linux_inferior_data Simon Marchi
2020-12-04  1:50   ` Pedro Alves
2020-12-02 15:48 ` [PATCH v2 10/14] gdb: move displaced stepping types to displaced-stepping.{h, c} Simon Marchi
2020-12-04  1:50   ` Pedro Alves
2020-12-02 15:48 ` [PATCH v2 11/14] gdb: move displaced stepping logic to gdbarch, allow starting concurrent displaced steps Simon Marchi
2020-12-04  1:50   ` Pedro Alves [this message]
2020-12-04 21:11     ` Simon Marchi
2020-12-02 15:48 ` [PATCH v2 12/14] gdb: change linux gdbarch data from post to pre-init Simon Marchi
2020-12-04  1:50   ` Pedro Alves
2020-12-02 15:48 ` [PATCH v2 13/14] gdb: make displaced stepping implementation capable of managing multiple buffers Simon Marchi
2020-12-04  1:51   ` Pedro Alves
2020-12-04 21:14     ` Simon Marchi
2020-12-02 15:48 ` [PATCH v2 14/14] gdb: use two displaced step buffers on amd64/Linux Simon Marchi
2020-12-04  1:51   ` Pedro Alves
2020-12-04  1:56 ` [PATCH v2 00/14] Concurrent displaced stepping Pedro Alves
2020-12-04 21:52   ` 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=cd536505-e895-83ae-c3b1-2a1e776c7fbe@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.com \
    --cc=simon.marchi@polymtl.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).