public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Sandra Loosemore <sandra@codesourcery.com>
To: Paul Koning <paul_koning@dell.com>
Cc: "gdb@sourceware.org" <gdb@sourceware.org>,
	Luis Machado	<lgustavo@codesourcery.com>
Subject: Re: how to fix internal errors on connection to remote stub?
Date: Sun, 25 Jan 2015 05:54:00 -0000	[thread overview]
Message-ID: <54C2A2DF.1050005@codesourcery.com> (raw)
In-Reply-To: <EBF95162-046E-4C79-8FA0-48D190939B38@dell.com>

On 01/23/2015 11:07 AM, Paul Koning wrote:
>
> If gdbserver is sending something that confuses gdb, the default
> answer is that this is a gdb bug (it should not fall over) and
> possibly in addition a gdbserver bug (it should obey the protocol
> spec).   The reason I say “default answer” is because of the standard
> distributed systems rule that itÂ’s always your bug if a received
> packet causes you to malfunction; the fact that the packet was
> invalid is not an excuse.
>
> You said that the stub is in an “inconsistent state”.  I’m not sure
> about that.  The target is stopped by the initial connection, and at
> that point you have a target thread, itÂ’s stopped, it has registers,
> so itÂ’s in some state that can be reported.  Yes, that state has no
> connection to the program GDB knows about, because itÂ’s not in the
> target yet.  So the target might be in some boot loader or other bit
> of skeleton code, but itÂ’s obviously executing something.  So I donÂ’t
> think “inconsistent” applies from the gdbserver point of view.

Hmmm, I'm not so sure about this.  In the situations where we have been 
hitting this problem, a more exact description of what is going on in 
the stub is this:  it previously completed normal execution of some 
other program in a different gdb instance and sent a 'W' packet.  When a 
new gdb instance reconnects to the stub, the target is still sitting 
stopped at the semihosting breakpoint that triggered the 'W' packet. 
That's why I'm wondering whether the response it should be giving to the 
initial '?' packet on the new connection should be 'W' ("the program has 
exited and has no meaningful state any more") instead of 'S' ("the 
program is stopped").  But GDB only accepts a 'W' reply to '?' in 
extended-remote mode, which isn't supported by this stub.

> Instead, it seems that gdb, when it queries gdbserver for the stopped
> inferior state, gets back stuff that doesnÂ’t fit in the program itÂ’s
> been told about.  But so what?  That can happen in other places for
> other reasons, and gdb usually handles that just fine.  Consider the
> “heuristic fencepost” machinery that protects from wild backtraces.
> So it seems that we just have some gaps in gdbÂ’s robustness, and
> those are bugs that should be fixed.
>
> New commands or new protocol mechanisms donÂ’t seem like the right
> answer; itÂ’s not the userÂ’s job to work around gdb bugs, nor is it
> gdbserverÂ’s job to know that it is out of sync with gdb.

It does seem like GDB could do a better job here of checking that the 
code in target memory (e.g., the instruction at the reported PC) matches 
what's expected from the program it's trying to debug.  While fixing 
that might make these errors less likely, it wouldn't be as foolproof as 
the stub simply telling GDB that it definitely has no useful program 
state to report yet.

-Sandra

      reply	other threads:[~2015-01-23 19:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-23 18:07 Sandra Loosemore
2015-01-23 19:37 ` Paul Koning
2015-01-25  5:54   ` Sandra Loosemore [this message]

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=54C2A2DF.1050005@codesourcery.com \
    --to=sandra@codesourcery.com \
    --cc=gdb@sourceware.org \
    --cc=lgustavo@codesourcery.com \
    --cc=paul_koning@dell.com \
    /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).