Contents|Index|Previous|Next

GDB and SPARClet

GDB enables developers to debug tasks running on SPARClet targets from a Unix host. GDB uses code that runs on both the Unix host and on the SPARClet target. The program, gdb, is installed and executed on the Unix host.

timeout args
GDB now supports the option, remotetimeout. This option is set by the user; args represents the number of seconds GDB waits for responses.

When compiling for debugging, include the option, -g, to get debug information and the option, -Ttext, to relocate the program to where you wish to load it on the target. You may also want to add the option, -n, or the option, -N, in order to reduce the size of the sections. Use the following command input as an example.

sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N

You can use objdump to verify that the addresses are what you intended.

sparclet-aout-objdump --headers --syms prog

Once you have set your Unix execution search path to find GDB, you are ready to run GDB. From your Unix host, run gdb (or sparclet-aout- gdb, depending on your installation). GDB shows its prompt (gdbslet)

Setting file to debug

The GDB command, file, lets you choose which program to debug as the following example shows. GDB then attempts to read the symbol table of prog.

(gdbslet) file prog

GDB locates the file by searching the directories listed in the command search path. If the file was compiled with debug information (using the option, -g), source files will be searched as well. GDB locates the source files by searching the directories listed in the directory search path (see Your program’s environment). If it fails to find a file, it displays a message such as: prog: No such file or directory.

When this happens, add the appropriate directories to the search paths with the GDB commands, path and dir, and execute the target command again.

Connecting to SPARClet

The GDB command, target, lets you connect to a SPARClet target. To connect to a target on serial port called ttya, use the following command at the SPARClet GDB prompt, gdbslet.

target sparclet /dev/ttya

GDB displays messages like the following output.

Remote target sparclet connected to /dev/ttya
main () at ../prog.c:3
Connected to ttya.

SPARClet download

Once connected to the SPARClet target, you can use the GDB load command to download the file from the host to the target. The file name and load offset should be given as arguments to the load command. Since the file format is a.out, the program must be loaded to the starting address. You can use the binary utility, objdump, to find out what this value is. The load offset is an offset which is added to the vma (virtual memory address) of each of the file’s sections. For instance, if the program, prog, was linked to text address, 0x1201000, with data at 0x12010160 and bss at 0x12010170, in GDB, use the command, load prog 0x12010000, at the prompt, (gdbslet).

You’ll then see the following output.

Loading section .text, size 0xdb0 vma 0x12010000

If the code is loaded at a different address than that to which the program was linked, you may need to use the section and add-symbol-file commands to tell GDB where to map the symbol table.

Running and debugging

Now begin debugging the task using any of GDB’s commands: b, step, run, and so on (for help with GDB commands, use the command, help). The following example shows what you’d do and see for execution control.

(gdbslet) b main
Breakpoint 1 at 0x12010000: file prog.c, line 3.

This insturction sets a breakpoint at line 3 for the file. Then you use the command, run. The following is an example of what you’d then see.

(gdbslet) run

The following is an example of the output from GDB you’d then see.

Starting program: prog
Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
3 char *symarg = 0;

Then, at your prompt, use the command, step, and set the next breakpoint at 4. The following is an example of what you’d then see.

(gdbslet) step
4 char *execarg = "hello!";
(gdbslet)