Download Simics User Guide for Unix

Transcript
12.2. Using GDB with Simics
12.2
Using GDB with Simics
This chapter describes how to use gdb-remote, a Simics module that lets you connect a
GDB session running on your host machine to the simulated machine using GDB’s remote
debugging protocol, and use GDB to debug software running on the target machine.
If you load the gdb-remote module in Simics, you can use the remote debugging feature
of GDB, the GNU debugger, to connect one or more GDB processes to Simics over TCP/IP. In
order to do this, you need a GDB compiled to support the simulation’s target architecture on
whichever host you’re running. The gdb-remote module only supports version 5.0 or later
of GDB, but other versions may work as well. Unfortunately GDB’s remote protocol does
not include any version checking, so the behavior is undefined if you use other versions.
For information on how to obtain and compile GDB, see section 12.2.3.
To connect a GDB session to Simics, start your Simics session and run the new-gdbremote command, optionally followed by a TCP/IP port number, which defaults to 9123
otherwise. This will automatically load the gdb-remote module.
When a configuration is loaded, Simics will start listening to incoming TCP/IP connections on the specified port. Run the simulated machine up to the point where you want to
connect GDB. To inspect a user process or dynamically loaded parts of the kernel, the easiest
solution might be to insert magic instructions at carefully chosen points. For static kernel
debugging, a simple breakpoint on a suitable address will solve the problem.
Note: When debugging the start-up phase of an operating system, it might happen that
gdb gets confused by the machine state and disconnects when you try to connect. In this
case, execute a few instructions and try again.
Once Simics is in the desired state, start your GDB session, load any debugging information into it, and then connect it to Simics using the target remote host:port command, where
host is the host Simics is running on, and port is the TCP/IP port number as described above.
Here is a short sample session using bagle, a Sun UltraSPARC machine running Linux:
(gdb) set architecture sparc:v9a
(gdb) symbol-file vmlinux
Reading symbols from vmlinux...done.
(gdb) target remote localhost:9123
Remote debugging using localhost:9123
time_init () at /usr/src/linux/include/asm/time.h:52
(gdb)
Note: For some architectures, you need to give a command to GDB before connecting
(the set architecture command in the session above). These are tabulated in the reference
manual’s section on gdb-remote, and will also be printed on the Simics console when you
run new-gdb-remote.
From this point, you can use GDB to control the target machine by entering normal GDB
commands such as continue, step, stepi, info regs, breakpoint, etc.
146