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
Subject: Re: [PATCH 2/2] gdb/remote: return early from remote_check_symbols if waiting for stop reply
Date: Fri, 29 Apr 2022 13:50:44 +0100	[thread overview]
Message-ID: <3bea5140-e1ef-940d-6a60-0f7864534507@palves.net> (raw)
In-Reply-To: <20220424032049.1021263-3-simon.marchi@polymtl.ca>

On 2022-04-24 04:20, Simon Marchi via Gdb-patches wrote:

> What happens is:
> 
>  - After doing the "continue" on inferior 1, the remote target gives us
>    a VFORK_DONE event.  The core ignores it and resumes inferior 1.
>  - Since prune_inferiors is now called after each handled event, in
>    fetch_inferior_event, it is called after we handled that VFORK_DONE
>    event and resumed inferior 1.
>  - Inferior 2 is pruned, which (see backtrace above) causes its program
>    space to be deleted, which clears the symtabs for that program space,
>    which calls the new_objfile observable and remote_new_objfile
>    observer (with a nullptr objfile, to indicate that the previously
>    loaded symbols have been discarded), which calls
>    remote_check_symbols.
> 
> remote_check_symbols is the function that sends the qSymbol packet, to
> let the remote side ask for symbol addresses.  The problem is that the
> remote target is working in all-stop / sync mode and is currently
> resumed.  It has sent a vCont packet to resume the target and is waiting
> for a stop reply.  It can't send any packets in the mean time.  That
> causes the exception to be thrown.

The inferiors that are pruned, their corresponding processes are gone, otherwise
they wouldn't be pruned.  So it seems wrong to even send a qSymbol packet at all,
as qSymbol on the remote end will be interpreted as "new symbols in the current process",
and the remote current process will have nothing to do with the pruned inferior.

Note this comment and target_has_execution check:

 /* Symbol look-up.  */

 void
 remote_target::remote_check_symbols ()
 {
   char *tmp;
   int end;

   /* The remote side has no concept of inferiors that aren't running
      yet, it only knows about running processes.  If we're connected
      but our current inferior is not running, we should not invite the
      remote target to request symbol lookups related to its
      (unrelated) current process.  */
   if (!target_has_execution ())
     return;

So if we're getting past this check, it seems to me that this means that we're calling
remote_check_symbols in the context of some other inferior other than the one that
is being pruned, which seems to be to be the bug here.

Note a bit below that function does:

  /* Make sure the remote is pointing at the right process.  Note
     there's no way to select "no process".  */
  set_general_process ();

... again, this is going to set the remote focus on gdb's current inferior,
but that inferior has no relation to the inferior that was pruned, so the
remote end is going to be querying symbols for a process that hasn't
really changed its symbols.

> 
> This wasn't a problem before, when prune_inferiors was called in
> normal_stop, because it was always called at a time the target was not
> resumed.
> 
> I realized there are simpler ways to trigger this problem.  You only
> need to load a symbol file (which triggers remote_check_symbols) while
> sync execution is ongoing:
> 
>     $ ./gdb -q --data-directory=data-directory -nx a.out \
>           -ex "tar ext :1234" \
> 	  -ex "tb main" \
> 	  -ex c \
> 	  -ex "c&" \
> 	  -ex "add-inferior" \
> 	  -ex "inferior 2" \
> 	  -ex "file /bin/ls"
>     * aborts because of the same exception *
> 

This is a valid problem, but a different problem, IMO.

  parent reply	other threads:[~2022-04-29 12:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-24  3:20 [PATCH 0/2] Fix regressions caused by prune_threads patch Simon Marchi
2022-04-24  3:20 ` [PATCH 1/2] gdb/infrun: make fetch_inferior_event restore thread if exited or signalled Simon Marchi
2022-04-25 17:21   ` Andrew Burgess
2022-04-26 12:43     ` Simon Marchi
2022-04-29 12:37   ` Pedro Alves
2022-04-29 13:25     ` Simon Marchi
2022-04-24  3:20 ` [PATCH 2/2] gdb/remote: return early from remote_check_symbols if waiting for stop reply Simon Marchi
2022-04-26 10:27   ` Andrew Burgess
2022-04-26 14:15     ` Simon Marchi
2022-04-27 10:11       ` Andrew Burgess
2022-04-27 14:01         ` Simon Marchi
2022-04-29 12:50   ` Pedro Alves [this message]
2022-04-29 14:53     ` Simon Marchi
2022-04-29 15:39       ` Pedro Alves
2022-04-29 15:56         ` Simon Marchi
2022-04-29 15:47       ` Pedro Alves

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=3bea5140-e1ef-940d-6a60-0f7864534507@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    --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).