Using GDB with Systemsim

1 Overview

This document explains how gdb can be used for source-level and machine-level debugging of programs running under Systemsim.

Systemsim operates as a `remote target' for gdb. This means that gdb runs in one process on a machine, while the Systemsim simulator runs as a separate process. The two are connected via sockets and communicate over the network. It is not necessary for both simulator and gdb to be running on the same machine.

Systemsim runs normally, simulating execution of your test program. As it does so, it `listens' for requests from gdb via the socket every few seconds. When it detects that gdb has requested control, it stops simulating, sends its current state (the complete register set, for the most part) to gdb, and waits for commands. Your commands to gdb, such as `breakpoint' and `print', cause gdb to communicate with Systemsim to read and write memory, change register contents, and so forth. When you issue a gdb command such as `continue' or `next', gdb tells Systemsim to continue simulating instructions until a breakpoint is encountered or until gdb interrupts Systemsim again.

To the user, the debugging session looks much like debugging an ordinary application. Some commands, such as `target', are unique to the remote target environment, but most gdb commands used for ordinary application debugging are the same when used with Systemsim.

2 Building your test program

When building the test program to be run under gdb, you must specify the `-g' compile and link option if you expect to do source-level debugging. You will need to make available to gdb a copy of your executable file so that it can read the symbol table, line number information, and read-only memory contents. This can be the same file that you give to Systemsim, if that file is accessible to both Systemsim and gdb.

3 Starting gdb

3.1 Gaining control at the start with gdb

The major difference in running gdb with Systemsim is this: gdb doesn't start the execution of the program to be debugged, Systemsim does.

Systemsim monitors the port that gdb will use. This port defaults to 2345 but is configurable in the TCL script with:

     mysim config gdb_port <port number>
  

The gdb port is monitored every few second while the code is running. You may also call-out to the debugger with:

    mysim debugger wait <seconds>
  
Using 0 for <seconds> will wait indefinately for gdb to connect.

3.2 Telling gdb where to find your program and its source code

You start gdb after Systemsim is running:

 powerpc-eabi-gdb

Tell gdb which program is being run by Systemsim:

 file ~/test3

Then tell where the source files for test3 are:

 dir ~/testing

You can issue as many `dir' commands as necessary, one directory per command. Each new directory gets pre-pended to the front of gdb's source search path.

3.3 Connecting gdb to Systemsim

Before connecting to Systemsim, you should specify to gdb the particular version of the PowerPC architecture supported by Systemsim using the set architecture gdb command:

For most 64-bit PowerPC architectures, use "powerpc:a35":

    (gdb) set architecture powerpc:a35

For PowerPC 750 architectures, use "powerpc:750":

    (gdb) set architecture powerpc:750

Once you set up the architecture you may now use the standard remote method. First, tell Systemsim to connect to gdb with the command:

    systemsim% mysim debugger wait 0
Systemsim will print the port number it is using for the GDB connection.

Then, in GDB:

    (gdb) target remote :<port>

It is possible to send tcl commands to Systemsim from GDB. The output will appear on the Systemsim console as if it was typed there. This command is:

    (gdb) monitor <tcl command>

3.4 Debugging a Program Running on Systemsim

At this point, you can use normal GDB commands to debug the program running in Systemsim:

	step: source-level stepping
	stepi: step one machine instruction
	ctrl-c: pause simulation and get gdb prompt.
	info registers: print the registers
	info float: print floating point registers
	p/x $pc: print the PC
	p/x $r1: print register r1
	detach: return to Systemsim prompt.

4 Source-level debugging

Debugging with gdb and Systemsim at the source code level is pretty much the same as debugging an ordinary application at the source level. Breakpoints can be set, variables inspected, and so on. For information on how to do this please see GDB manual