Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@false.org>
To: Vladimir Prus <ghost@cs.msu.su>
Cc: gdb@sources.redhat.com
Subject: Re: Multithreaded debugging: strange thread switches
Date: Mon, 23 Jan 2006 16:02:00 -0000	[thread overview]
Message-ID: <20060123155240.GA16524@nevyn.them.org> (raw)
In-Reply-To: <200601231820.33372.ghost@cs.msu.su>

On Mon, Jan 23, 2006 at 06:20:32PM +0300, Vladimir Prus wrote:
> 
> Hello,
> I'm observing strange behaviour when debugging with gdb using a custom stub.
> I have two threads. After connecting, I say "next" several times and that 
> steps in thread 1. Then I say "thread 2" and "next". Gdb then stops again in 
> thread 1, not in thread 2 as I'd expected.
> 
> In the remote protocol I see "Hc1" packet after last "next" though I'd expect 

This, generally, is part of the problem.  If you want this to work, you
need to implement the vCont packet in the stub.  The Hc1 packet is
supposed to mean "step only thread 1, leaving thread 2 stopped", and
that's not what the gdb "next" command is supposed to map to - that's
"step this thread but leave other threads free-running".

> "Hc2", and in infrun.c, function prepare_to_proceed, I see this:
> 
> 
>  if (!ptid_equal (wait_ptid, minus_one_ptid)
>       && !ptid_equal (inferior_ptid, wait_ptid))
>     {
>       /* Switched over from WAIT_PID.  */
>       CORE_ADDR wait_pc = read_pc_pid (wait_ptid);
> 
>       if (wait_pc != read_pc ())
> 	{
> 	  /* Switch back to WAIT_PID thread.  */
> 	  inferior_ptid = wait_ptid;
> 
> 	  /* FIXME: This stuff came from switch_to_thread() in
> 	     thread.c (which should probably be a public function).  */
> 	  flush_cached_frames ();
> 	  registers_changed ();
> 	  stop_pc = wait_pc;
> 	  select_frame (get_current_frame ());
> 	}
> 
> Can somebody explain the reason for this explicit switch back to "wait_ptid"?

I have no idea, but if you remove it you're going to bust the bit below
that steps over breakpoints, and then GDB will really get unhappy. 
Maybe we can adjust that block of code, though.  See the comment in
proceed():

  /* In a multi-threaded task we may select another thread
     and then continue or step.

     But if the old thread was stopped at a breakpoint, it
     will immediately cause another breakpoint stop without
     any execution (i.e. it will report a breakpoint hit
     incorrectly).  So we must step over it first.

     prepare_to_proceed checks the current thread against the thread
     that reported the most recent event.  If a step-over is required
     it returns TRUE and sets the current thread to the old thread. */

The current code was modified to always select the previous thread
in arch-utils.c revision 1.28 in order to support resuming after
hitting Control-C:
  http://sourceware.org/ml/gdb-patches/2001-05/msg00419.html

I can't tell from Jonathan's post what problem he's trying to fix.
Previously the thread would only be switched if (SIGTRAP && breakpoint
here).  Now it's switched if (SIGTRAP || SIGINT) and then we
single-step if (breakpoint here).  Which doesn't make much sense.

-- 
Daniel Jacobowitz
CodeSourcery


  reply	other threads:[~2006-01-23 15:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-23 15:46 Vladimir Prus
2006-01-23 16:02 ` Daniel Jacobowitz [this message]
2006-01-24 14:28   ` Vladimir Prus
2006-01-24 14:41     ` Daniel Jacobowitz
2006-01-24 14:44       ` Vladimir Prus
2006-01-24 16:16         ` Daniel Jacobowitz
2006-01-24 21:21         ` Eli Zaretskii
2006-01-25  0:04   ` vCont [was Re: Multithreaded debugging: strange thread switches] Nathan J. Williams
2006-01-25 11:20     ` Daniel Jacobowitz

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=20060123155240.GA16524@nevyn.them.org \
    --to=drow@false.org \
    --cc=gdb@sources.redhat.com \
    --cc=ghost@cs.msu.su \
    /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