Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Yao Qi <yao@codesourcery.com>
To: "gdb@sourceware.org" <gdb@sourceware.org>
Subject: gdb in non-stop/sync mode connects to gdbserver
Date: Thu, 22 Nov 2012 16:09:00 -0000	[thread overview]
Message-ID: <50AE4E3D.8000701@codesourcery.com> (raw)

Hello,
When running moribund-step.exp with boardfile 'unix', we'll get two passes,

   PASS: gdb.base/moribund-step.exp: set non-stop on
   PASS: gdb.base/moribund-step.exp: step

However, when running it with boardilfe native-gdbserver, we'll get only 
one pass,

   PASS: gdb.base/moribund-step.exp: set non-stop on

in fact, gdb hang there when connecting to gdbserver.  Supposing gdb is 
in non-stop and sync mode, here is callgraph of functions related to 
'connecting to remote gdbserver'.

remote_start_remote
   1) putpkt ("QNonStop:1");
   2) remote_thread_info
        |
        +-> remote_notice_new_inferior
              |
              +-> notice_new_inferior
              |     |
              |     +-> target_stop and then wait_for_inferior [A]
              +-> attach_command_post_wait
                    |
                    + target_stop (in non-stop mode, and no wait) [B]

  3) putpkt ("?")
  4) init_wait_for_inferior
  5) check packet replied to "?", and handle stop reply if needed.

After step 1), GDBserver knows that "we are in non-stop mode".  In step 
2), gdb calls target_stop in [A], sending 'vCont;t' to stop one thread, 
and expect to get a %Stop notification.  However, when gdbserver 
launches program, the thread has been stopped before gdb connects to 
gdbserver.  So the stop request from gdb is ignored by gdbserver (shown 
by the gdbserver log below),

   getpkt ("vCont;t:p45df.45df");  [no ack sent]
   already stopped LWP 17887 at GDB's request
   Need step over [LWP 17887]? Ignoring, should remain stopped
   Resuming, no pending status or step over needed
   putpkt ("$OK#9a"); [noack mode]

and no %Stop notification is sent back to gdb.  Then, gdb hang there.

The problem is that gdb wants to get a certain thread stopped, but 
doesn't know its state, so has to blindly force to stop it, and expect a 
%Stop notification to come.  Then, I am wondering if gdbserver can sends 
the state of threads, if known, to gdb when gdb connects, and gdb don't 
have to stop threads if they are already stopped.  Is it a good way to 
go?  We can achieve this by add new attribute 'state' in the xml 
returned to qxfer:threads:read.  My experiments show it works, but not 
sure if I miss something important.

Doing this is not enough to fix the problem I mentioned at the 
beginning.  There is another problem in the following steps.  Supposing 
gdb doesn't call target_stop in [A], gdb will call target_stop in [B],

       GDB            GDBserver
[B]   'vCont;t'  ->
                  <- 'OK'
3)    '?'        ->
                  <- 'T0505:xxxxx'
4)
5) process stop reply and send 'vStopped'
      'vStopped'  ->
                  <- 'OK'

This process requires that there is no packet sent in step 4), because 
gdb is expecting to get a stop reply.  Unfortunately, 
breakpoint_init_inferior, called by init_wait_for_inferior, has to 
access inferior memory, so 'm' packet is sent out.  Looks like the fix 
to this problem is to move all functions which cause sending packets in 
step 4) after step 5).  Does it sound a good idea?

I've got a patch to fix the two problems, but I am not sure it is on a 
right direction.  If it is correct, I'll polish the patch, and post it.

-- 
Yao (齐尧)


             reply	other threads:[~2012-11-22 16:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-22 16:09 Yao Qi [this message]
2012-11-22 18:16 ` Pedro Alves
2012-11-23  1:35   ` Yao Qi

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=50AE4E3D.8000701@codesourcery.com \
    --to=yao@codesourcery.com \
    --cc=gdb@sourceware.org \
    /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