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 2/2] gdb/remote: send qSymbol to all inferiors on startup
Date: Wed, 4 May 2022 13:03:51 +0100	[thread overview]
Message-ID: <e750c5f9-9b3f-1553-4985-b31da0da45d2@palves.net> (raw)
In-Reply-To: <20220430032115.524232-3-simon.marchi@polymtl.ca>

On 2022-04-30 04:21, Simon Marchi via Gdb-patches wrote:
> From: Simon Marchi <simon.marchi@efficios.com>
> 
> start_remote_1 calls remote_check_symbols after things are set up to
> give the remote side a chance to look up symbols.  One call to
> remote_check_symbols sets the "general thread", if needed, and sends one
> qSymbol packet.  In theory, a remote target could have more than one
> process on initial connection, and this would send a qSymbol for only
> one of these processes.

Not theory, it can really happen.

> 
> Change it to iterate on all the target's inferiors and send a qSymbol
> packet for each one.
> 
> I was able to kind of test this by changing gdbserver to spawn two processes on
> startup:
> 
>     diff --git a/gdbserver/server.cc b/gdbserver/server.cc
>     index 33c42714e72..9b682e9f85f 100644
>     --- a/gdbserver/server.cc
>     +++ b/gdbserver/server.cc
>     @@ -3939,6 +3939,7 @@ captured_main (int argc, char *argv[])
> 
>            /* Wait till we are at first instruction in program.  */
>            target_create_inferior (program_path.get (), program_args);
>     +      target_create_inferior (program_path.get (), program_args);
> 
>            /* We are now (hopefully) stopped at the first instruction of
>              the target process.  This assumes that the target process was

You don't need to hack gdbserver.  You can instead connect in extended-remote mode,
and run/start two inferiors.  Then, issue "disconnect".  gdbserver will stay
open, debugging the two processes, waiting for another connection.  Now connect
gdb again to gdbserver, and it will discover the two processes.

> 
> And I was able to see qSymbol being sent for each inferior:
> 
>       [remote] Sending packet: $Hgp828dc.828dc#1f
>       [remote] Packet received: OK
>       [remote] Sending packet: $qSymbol::#5b
>       [remote] Packet received: qSymbol:6764625f6167656e745f6764625f74705f686561705f627566666572
>       [remote] Sending packet: $qSymbol::6764625f6167656e745f6764625f74705f686561705f627566666572#1e
>       [remote] Packet received: qSymbol:6e70746c5f76657273696f6e
>       [remote] Sending packet: $qSymbol::6e70746c5f76657273696f6e#4d
>       [remote] Packet received: OK
>       [remote] Sending packet: $Hgp828dd.828dd#21
>       [remote] Packet received: OK
>       [remote] Sending packet: $qSymbol::#5b
>       [remote] Packet received: qSymbol:6764625f6167656e745f6764625f74705f686561705f627566666572
>       [remote] Sending packet: $qSymbol::6764625f6167656e745f6764625f74705f686561705f627566666572#1e
>       [remote] Packet received: qSymbol:6e70746c5f76657273696f6e
>       [remote] Sending packet: $qSymbol::6e70746c5f76657273696f6e#4d
>       [remote] Packet received: OK
> 
> Note that there would probably be more work to be done to fully support
> this scenario, more things that need to be done for each discovered
> inferior instead of just for one.
> 
> Change-Id: I21c4ecf6367391e2e389b560f0b4bd906cf6472f
> ---
>  gdb/remote.c | 20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/gdb/remote.c b/gdb/remote.c
> index fde6df3f84d5..b82140dc3d09 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -5021,12 +5021,24 @@ remote_target::start_remote_1 (int from_tty, int extended_p)
>  	target_async (1);
>      }
>  
> -  /* If we connected to a live target, do some additional setup.  */
> -  if (target_has_execution ())
> +  /* Give the target a chance to look up symbols.  */
> +  for (inferior *inf : all_inferiors (this))
>      {
> +      /* The inferiors that exist at this point were created from what
> +         was found already running on the remote side, so we know they
> +	 have execution.  */

Something off with indentation -- tabs vs spaces?

Otherwise LGTM.

Pedro Alves

> +      gdb_assert (this->has_execution (inf));
> +
>        /* No use without a symbol-file.  */
> -      if (current_program_space->symfile_object_file)
> -	remote_check_symbols ();
> +      if (inf->pspace->symfile_object_file == nullptr)
> +	continue;
> +
> +      /* Need to switch to a specific thread, because remote_check_symbols
> +         uses INFERIOR_PTID to set the general thread.  */
> +      scoped_restore_current_thread restore_thread;
> +      thread_info *thread = any_thread_of_inferior (inf);
> +      switch_to_thread (thread);
> +      this->remote_check_symbols ();
>      }
>  
>    /* Possibly the target has been engaged in a trace run started

  reply	other threads:[~2022-05-04 12:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-30  3:21 [PATCH v2 0/2] Fix regressions caused by prune_threads patch Simon Marchi
2022-04-30  3:21 ` [PATCH v2 1/2] gdb/remote: iterate on pspace inferiors in remote_new_objfile Simon Marchi
2022-05-04 12:04   ` Pedro Alves
2022-05-04 12:17     ` Simon Marchi
2022-04-30  3:21 ` [PATCH v2 2/2] gdb/remote: send qSymbol to all inferiors on startup Simon Marchi
2022-05-04 12:03   ` Pedro Alves [this message]
2022-05-04 12:25     ` 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=e750c5f9-9b3f-1553-4985-b31da0da45d2@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).