Red Hat Enterprise Linux 4: Debugging with gdb | ||
---|---|---|
Prev | Chapter 20. Configuration-Specific Information | Next |
This section goes into details specific to particular embedded configurations.
ARM Angel monitor, via RDI library interface to ADP protocol. You may use this target to communicate with both boards running the Angel monitor, or with the EmbeddedICE JTAG debug device.
ARM Demon monitor.
A Hitachi SH, H8/300, or H8/500 board, attached via serial line to your host. Use special commands device and speed to control the serial line and the communications speed used.
E7000 emulator for Hitachi H8 and SH.
Hitachi SH-3 and SH-3E target systems.
When you select remote debugging to a Hitachi SH, H8/300, or H8/500 board, the load command downloads your program to the Hitachi board and also opens it as the current executable target for gdb on your host (like the file command).
gdb needs to know these things to talk to your Hitachi SH, H8/300, or H8/500:
that you want to use target hms, the remote debugging interface for Hitachi microprocessors, or target e7000, the in-circuit emulator for the Hitachi SH and the Hitachi 300H. (target hms is the default when gdb is configured specifically for the Hitachi SH, H8/300, or H8/500.)
what serial device connects your host to your Hitachi board (the first serial device available on your host is the default).
what speed to use over the serial device.
Use the special gdb command device port if you need to explicitly set the serial device. The default port is the first available port on your host. This is only necessary on Unix hosts, where it is typically something like /dev/ttya.
gdb has another special command to set the communications speed: speed bps. This command also is only used from Unix hosts; on DOS hosts, set the line speed as usual from outside gdb with the DOS mode command (for instance, mode com2:9600,n,8,1,p for a 9600bps connection).
The device and speed commands are available only when you use a Unix host to debug your Hitachi microprocessor programs. If you use a DOS host, gdb depends on an auxiliary terminate-and-stay-resident program called asynctsr to communicate with the development board through a PC serial port. You must also use the DOS mode command to set up the serial port on the DOS side.
The following sample session illustrates the steps needed to start a program under gdb control on an H8/300. The example uses a sample H8/300 program called t.x. The procedure is the same for the Hitachi SH and the H8/500.
First hook up your development board. In this example, we use a board attached to serial port COM2; if you use a different serial port, substitute its name in the argument of the mode command. When you call asynctsr, the auxiliary comms program used by the debugger, you give it just the numeric part of the serial port's name; for example, asyncstr 2 below runs asyncstr on COM2.
C:\H8300\TEST> asynctsr 2 C:\H8300\TEST> mode com2:9600,n,8,1,p Resident portion of MODE loaded COM2: 9600, n, 8, 1, p |
Warning: We have noticed a bug in PC-NFS that conflicts with asynctsr. If you also run PC-NFS on your DOS host, you may need to disable it, or even boot without it, to use asynctsr to control your development board.
Now that serial communications are set up, and the development board is connected, you can start up gdb. Call gdb with the name of your program as the argument. gdb prompts you, as usual, with the prompt (gdb). Use two special commands to begin your debugging session: target hms to specify cross-debugging to the Hitachi board, and the load command to download your program to the board. load displays the names of the program's sections, and a * for each 2K of data downloaded. (If you want to refresh gdb data on symbols or on the executable file without downloading, use the gdb commands file or symbol-file. These commands, and load itself, are described in (refer to Section 17.1 Commands to specify files.)
(eg-C:\H8300\TEST) gdb t.x gdb is free software and you are welcome to distribute copies of it under certain conditions; type "show copying" to see the conditions. There is absolutely no warranty for gdb; type "show warranty" for details. gdb 2003-07-22-cvs, Copyright 1992 Free Software Foundation, Inc... (gdb) target hms Connected to remote H8/300 HMS system. (gdb) load t.x .text : 0x8000 .. 0xabde *********** .data : 0xabde .. 0xad30 * .stack : 0xf000 .. 0xf014 * |
At this point, you're ready to run or debug your program. From here on, you can use all the usual gdb commands. The break command sets breakpoints; the run command starts your program; print or x display data; the continue command resumes execution after stopping at a breakpoint. You can use the help command at any time to find out more about gdb commands.
Remember, however, that operating system facilities aren't available on your development board; for example, if your program hangs, you can't send an interrupt--but you can press the reset switch!
Use the reset button on the development board
to interrupt your program (don't use ctl-C on the DOS host--it has no way to pass an interrupt signal to the development board); and
to return to the gdb command prompt after your program finishes normally. The communications protocol provides no other way for gdb to detect program completion.
In either case, gdb sees the effect of a reset on the development board as a "normal exit" of your program.
You can use the E7000 in-circuit emulator to develop code for either the Hitachi SH or the H8/300H. Use one of these forms of the target e7000 command to connect gdb to your E7000:
Use this form if your E7000 is connected to a serial port. The port argument identifies what serial port to use (for example, com2). The third argument is the line speed in bits per second (for example, 9600).
If your E7000 is installed as a host on a TCP/IP network, you can just specify its hostname; gdb uses telnet to connect.
Specify which H8/500 memory model (mod) you are using with set memory; check which memory model is in effect with show memory. The accepted values for mod are small, big, medium, and compact.
The Motorola m68k configuration includes ColdFire support, and target command for the following ROM monitors.
ABug ROM monitor for M68K.
CPU32BUG monitor, running on a CPU32 (M68K) board.
dBUG ROM monitor for Motorola ColdFire.
EST-300 ICE monitor, running on a CPU32 (M68K) board.
ROM 68K monitor, running on an M68K IDP board.
ROMBUG ROM monitor for OS/9000.
gdb can use the MIPS remote debugging protocol to talk to a MIPS board attached to a serial line. This is available when you configure gdb with -target=mips-idt-ecoff.
Use these gdb commands to specify the connection to your target board:
To run a program on the board, start up gdb with the name of your program as the argument. To connect to the board, use the command target mips port, where port is the name of the serial port connected to the board. If the program has not already been downloaded to the board, you may use the load command to download it. You can then use all the usual gdb commands.
For example, this sequence connects to the target board through a serial port, and loads and runs a program called prog through the debugger:
host$ gdb prog gdb is free software and … (gdb) target mips /dev/ttyb (gdb) load prog (gdb) run |
On some gdb host configurations, you can specify a TCP connection (for instance, to a serial line managed by a terminal concentrator) instead of a serial port, using the syntax hostname:portnumber.
PMON ROM monitor.
NEC's DDB variant of PMON for Vr4300.
LSI variant of PMON.
Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
Array Tech LSI33K RAID controller board.
gdb also supports these special commands for MIPS targets:
Use the set processor command to set the type of MIPS processor when you want to access processor-type-specific registers. For example, set processor r3041 tells gdb to use the CPU registers appropriate for the 3041 chip. Use the show processor command to see what MIPS processor gdb is using. Use the info reg command to see what registers gdb is using.
If your target board does not support the MIPS floating point coprocessor, you should use the command set mipsfpu none (if you need this, you may wish to put the command in your gdb init file). This tells gdb how to find the return value of functions which return floating point values. It also allows gdb to avoid saving the floating point registers when calling functions on the board. If you are using a floating point coprocessor with only single precision floating point support, as on the r4650 processor, use the command set mipsfpu single. The default double precision floating point coprocessor may be selected using set mipsfpu double.
In previous versions the only choices were double precision or no floating point, so set mipsfpu on will select double precision and set mipsfpu off will select no floating point.
As usual, you can inquire about the mipsfpu variable with show mipsfpu.
You can see some debugging information about communications with the board by setting the remotedebug variable. If you set it to 1 using set remotedebug 1, every packet is displayed. If you set it to 2, every character is displayed. You can check the current value at any time with the command show remotedebug.
You can control the timeout used while waiting for a packet, in the MIPS remote protocol, with the set timeout seconds command. The default is 5 seconds. Similarly, you can control the timeout used while waiting for an acknowledgement of a packet with the set retransmit-timeout seconds command. The default is 3 seconds. You can inspect both values with show timeout and show retransmit-timeout. (These commands are only available when gdb is configured for -target=mips-idt-ecoff.)
The timeout set by set timeout does not apply when gdb is waiting for your program to stop. In that case, gdb waits forever because it has no way of knowing how long the program is going to run before stopping.
See OR1k Architecture document (www.opencores.org) for more information about platform and commands.
Connects to remote JTAG server. JTAG remote server can be either an or1ksim or JTAG server, connected via parallel port to the board.
Example: target jtag jtag://localhost:9999
If connected to or1ksim OpenRISC 1000 Architectural Simulator, proprietary commands can be executed.
Displays spr groups.
Displays register names in selected group.
Shows information about specified spr register.
Writes value to specified spr register.
Some implementations of OpenRISC 1000 Architecture also have hardware trace. It is very similar to gdb trace, except it does not interfere with normal program execution and is thus much faster. Hardware breakpoints/watchpoint triggers can be set using:
Load effective address/data
Store effective address/data
Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
Fetch data
When triggered, it can capture low level data, like: PC, LSEA, LDATA, SDATA, READSPR, WRITESPR, INSTR.
htrace commands:
Set hardware watchpoint on combination of Load/Store Effecive Address(es) or Data. For example:
hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)
hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)
Display information about current HW trace configuration.
Set starting criteria for HW trace.
Set acquisition qualifier for HW trace.
Set HW trace stopping criteria.
Selects the data to be recorded, when qualifier is met and HW trace was triggered.
Enables/disables the HW trace.
Clears currently recorded trace data.
If filename is specified, new trace file is made and any newly collected data will be written there.
Prints trace buffer, using current record configuration.
Set continuous trace mode.
Set suspend trace mode.
DINK32 ROM monitor.
PPCBUG ROM monitor for PowerPC.
SDS monitor, running on a PowerPC board (such as Motorola's ADS).
OP50N monitor, running on an OKI HPPA board.
W89K monitor, running on a Winbond HPPA board.
A Hitachi SH board attached via serial line to your host. Use special commands device and speed to control the serial line and the communications speed used.
E7000 emulator for Hitachi SH.
Hitachi SH-3 and SH-3E target systems.
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.
gdb supports the option remotetimeout. This option is set by the user, and args represents the number of seconds gdb waits for responses.
When compiling for debugging, include the options -g to get debug information and -Ttext to relocate the program to where you wish to load it on the target. You may also want to add the options -n or -N in order to reduce the size of the sections. 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 comes up showing the prompt:
(gdbslet) |
The gdb command file lets you choose with program to debug.
(gdbslet) file prog |
gdb then attempts to read the symbol table of prog. gdb locates the file by searching the directories listed in the command search path. If the file was compiled with debug information (option "-g"), source files will be searched as well. gdb locates the source files by searching the directories listed in the directory search path (refer to Section 6.4 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.
The gdb command target lets you connect to a Sparclet target. To connect to a target on serial port "ttya", type:
(gdbslet) target sparclet /dev/ttya Remote target sparclet connected to /dev/ttya main () at ../prog.c:3 |
gdb displays messages like these:
Connected to ttya. |
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 aout, the program must be loaded to the starting address. You can use 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, type:
(gdbslet) load prog 0x12010000 Loading section .text, size 0xdb0 vma 0x12010000 |
If the code is loaded at a different address then what the program was linked to, you may need to use the section and add-symbol-file commands to tell gdb where to map the symbol table.
You can now begin debugging the task using gdb's execution control commands, b, step, run, etc. See the gdb manual for the list of commands.
(gdbslet) b main Breakpoint 1 at 0x12010000: file prog.c, line 3. (gdbslet) run Starting program: prog Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3 3 char *symarg = 0; (gdbslet) step 4 char *execarg = "hello!"; (gdbslet) |
Fujitsu sparclite boards, used only for the purpose of loading. You must use an additional command to debug the program. For example: target remote dev using gdb standard remote protocol.
gdb may be used with a Tandem ST2000 phone switch, running Tandem's STDBUG protocol.
To connect your ST2000 to the host system, see the manufacturer's manual. Once the ST2000 is physically attached, you can run:
target st2000 dev speed |
to establish it as your debugging environment. dev is normally the name of a serial device, such as /dev/ttya, connected to the ST2000 via a serial line. You can instead specify dev as a TCP connection (for example, to a serial line attached via a terminal concentrator) using the syntax hostname:portnumber.
The load and attach commands are not defined for this target; you must load your program into the ST2000 as you normally would for standalone operation. gdb reads debugging information (such as symbols) from a separate, debugging version of the program available on your host computer.
These auxiliary gdb commands are available to help you with the ST2000 environment:
Send a command to the STDBUG monitor. See the manufacturer's manual for available commands.
Connect the controlling terminal to the STDBUG command monitor. When
you are done interacting with STDBUG, typing either of two character
sequences gets you back to the gdb command prompt:
When configured for debugging Zilog Z8000 targets, gdb includes a Z8000 simulator.
For the Z8000 family, target sim simulates either the Z8002 (the unsegmented variant of the Z8000 architecture) or the Z8001 (the segmented variant). The simulator recognizes which architecture is appropriate by inspecting the object code.
Debug programs on a simulated CPU. If the simulator supports setup options, specify them via args.
After specifying this target, you can debug programs for the simulated CPU in the same style as programs for your host computer; use the file command to load a new program image, the run command to run your program, and so on.
As well as making available all the usual machine registers (refer to Section 10.10 Registers), the Z8000 simulator provides three additional items of information as specially named registers:
Counts clock-ticks in the simulator.
Counts instructions run in the simulator.
Execution time in 60ths of a second.
You can refer to these values in gdb expressions with the usual conventions; for example, b fputc if $cycles>5000 sets a conditional breakpoint that suspends only after at least 5000 simulated clock ticks.