Re: Virtual Machine and GDB

Michael Snyder
2006-08-21T19:13:36Z

On Mon, 2006-08-21 at 19:49 +0100, Cai Qian wrote:
> Hi,
>
> On 8/21/06, Michael Snyder <Michael.Snyder@palmsource.com> wrote:
> > On Mon, 2006-08-21 at 18:59 +0100, Cai Qian wrote:
> > > Hi,
> > >
> > > On 8/21/06, Neo <cjia@cse.unl.edu> wrote:
> > > > Cai,
> > > >
> > > > I am wondering why you need to debug the VM remotely. Maybe you have
> > > > your own requirements, such as for embedded systems. But I think you
> > > > need to first make sure you can debug any binary running on your target
> > > > board remotely. Then, you can treat the VM as the rest ordinary binary.
> > > >
> > >
> > > I don't want to debug VM itself here, but executable running on the
> > > VM. As my VM has a new instruction set, and GDB is quite unlikely to
> > > run locally.
> >
> > OK, so you have two issues:
> > 1) You need to get gdbserver running in your VM, and provide
> > some means for gdbserver to talk to a gdb that is running in the
> > outside world. Unles you have access to a serial port, the
> > obvious way to do this is to get a IP stack running in the VM,
> > assign it an IP address, and let gdbserver open up a socket.
> > Then gdb (running somewhere outside of the VM) can attach to
> > the socket.
> >
>
> I have implemented a debug server in VM. At the moment, it can read
> the RSP messages from remote GDB through socket. So, I think I have
> done this part.

Great...

> > 2) You need to teach gdb to understand the architecture of
> > your virtual machine -- the word size, the instruction language,
> > the register set, and so forth. That doesn't mean porting gdb
> > to RUN on the VM -- it just means teaching gdb how to DEBUG
> > the VM (meaning, debug something that is running in the VM).
> >
>
> How can I achieve this part? At the moment, after received a packet
> from remote GDB, I am trying to parse the packet first, and then send
> the right response to GDB. For example, if VM received a "info
> registers" command at the debug socket, it will try to collect
> register information, and then generate a right RSP message back. Or,
> if it received "next", I can set a flag in VM to indicate to only
> execute one instruction. Is that a right way to do?

Well, what's the register set of your VM? Is it a virtual pentium?
In that case, you have nothing to do except make sure that the gdb
was configured and built with --target=i386-xxx. Similarly if the
virtual machine is (or pretends to be) any other known architecture.

If it's emulating some new, previously unknown architecture with a
unique register set and instruction set, then you need to do what
we call a target base port of gdb -- that is, teach gdb how to
interpret this new machine architecture.