public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Luis Machado <luis.machado@linaro.org>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: gdb@gnu.org, "QEMU Developers" <qemu-devel@nongnu.org>,
	"Pavel Dovgalyuk" <pavel.dovgalyuk@ispras.ru>,
	"Daniel P. Berrangé" <berrange@redhat.com>
Subject: Re: Best approach for supporting snapshots for QEMU's gdbstub?
Date: Mon, 17 May 2021 14:54:15 -0300	[thread overview]
Message-ID: <ef3a9b58-6ecf-d4c1-b501-2b4d390304ec@linaro.org> (raw)
In-Reply-To: <87bl99e03j.fsf@linaro.org>

On 5/17/21 2:27 PM, Alex Bennée wrote:
> 
> Luis Machado <luis.machado@linaro.org> writes:
> 
>> Hi,
>>
>> On 5/14/21 1:06 PM, Alex Bennée wrote:
>>> Hi,
>>> I've been playing around with QEMU's reverse debugging support which
>>> I have working with Pavel's latest patches for supporting virtio with
>>> record/replay. Once you get the right command line it works well enough
>>> although currently each step backwards requires replaying the entire
>>> execution history until you get to the right point.
>>> QEMU can quite easily snapshot the entire VM state so I was looking
>>> to
>>> see what the best way to integrate this would be. As far as I can tell
>>> there are two interfaces gdb supports: bookmarks and checkpoints.
>>> As far as I can tell bookmarks where added as part of GDB's reverse
>>> debugging support but attempting to use them from the gdbstub reports:
>>>     (gdb) bookmark
>>>     You can't do that when your target is `remote'
>>> so I guess that would need an extension to the stub protocol to
>>> support?
>>>
>>
>> Right. We don't support reverse step/next/continue for remote targets.
>> I think this would be the most appropriate way to implement this
>> feature in GDB. But it is not trivial.
> 
> You do because ";ReverseStep+;ReverseContinue+" is part of the gdbstub
> negotiation handshake.

Interesting... I was looking at the vCont; packets for inferior 
movement. The regular c/C/s/S packet are deprecated and vCont; 
equivalents should be used instead.

It seems the reverse continue (bc) and reverse step (bs) packets can be 
used, but they are not vCont packets.

That's confusing. I suppose nobody took the time to implement bc/bs 
equivalents for vCont.

> 
> Out of interest how is rr implemented? It presents a gdb interface so I
> thought it was some implemented using some remote magic.

I don't know. I have never used rr.

> 
> <snip>
> 
>>> We could of course just add a custom monitor command like the
>>> qemu.sstep= command which could be used manually. However that would be
>>> a QEMU gdbstub specific approach.
>>
>> That would be an easy and quick way to allow GDB to control things in
>> QEMU, but I wouldn't say it is the best. Monitor commands are
>> basically a bypass of the RSP where GDB sends/receives commands
>> to/from the remote target.
> 
> We have some underlying commands we can set via the monitor including:
> 
>    monitor info replay
>    monitor replay_seek <N>
>    monitor replay_break <N>
> 
>>
>>> The other thing would be to be more intelligent on QEMU's side and
>>> save
>>> snapshots each time we hit an event, for example each time we hit a
>>> given breakpoint. However I do worry that might lead to snapshots
>>> growing quite quickly.
>>
>> GDB would need to be aware of such snapshots for them to be useful.
>> Otherwise GDB wouldn't be able to use them to restore state.
> 
> What does GDB need to know about them? Does it include something like
> the icount at a particular point.

GDB needs to know they exist so the user can choose to go back to such 
snapshots. I haven't dealt with remote reverse execution 
implementations, but if this information can be exposed to

> 
> I'm curious at how a break and reverse-continue is meant to work if that
> breakpoint is hit multiple times from the start of a run. You need to
> know if the last time you hit a particular breakpoint was in fact the
> last time before where the user was when they hit reverse-continue.

When you have record/replay on, there is no real "continue". GDB will 
instruction-step everything and will record register values and memory 
changes.

When you reverse instruction-step, GDB will restore the state for the 
previous snapshot. When you reverse continue, GDB will do the same and 
will move the state backwards snapshot by snapshot.

It is not very efficient.

So, in that sense, GDB will hit all of the breakpoints again. It doesn't 
keep track of how many times the breakpoint was hit. It only keeps track 
of how many instructions were recorded and what register/memory changes 
happened.

If you hit an instruction that GDB doesn't know how to calculate 
register/memory changes for, it will stop dead on its tracks. In that 
sense, it is also not very easy to maintain and takes a lot of 
instruction-parsing to work correctly.

No wonder there are more performatic solutions out there. :-)

> 
>>
>>> Any thoughts/suggestions?
>>>
> 
> 

  reply	other threads:[~2021-05-17 17:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-14 16:06 Alex Bennée
2021-05-15  6:12 ` Pavel Dovgalyuk
2021-05-17 16:49 ` Luis Machado
2021-05-17 17:27   ` Alex Bennée
2021-05-17 17:54     ` Luis Machado [this message]
2021-05-17 19:01     ` Peter Maydell
2021-05-18  5:26     ` Pavel Dovgalyuk

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=ef3a9b58-6ecf-d4c1-b501-2b4d390304ec@linaro.org \
    --to=luis.machado@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=gdb@gnu.org \
    --cc=pavel.dovgalyuk@ispras.ru \
    --cc=qemu-devel@nongnu.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).