The following sections explain the commands and subcommands necessary to prepare programs for debugging; execute programs; set, display, and delete breakpoints; continue programs; single-step through a program; stop programs; and kill programs.
Compile the program using the cc command to a file such as adbsamp2 by entering the following:
cc adbsamp2.c -o adbsamp2
To start the debug session, enter:
The C language does not generate statement labels for programs. Therefore, you cannot refer to individual C language statements when using the debug program. To use execution commands effectively, you must be familiar with the instructions that the C compiler generates and how those instructions relate to individual C language statements. One useful technique is to create an assembler language listing of your C program before using the adb program. Then, refer to the listing as you use the debug program. To create an assembler language listing, use the -S or -qList flag of the cc command.
For example, to create an assembler language listing of the example program, adbsamp2.c, use the following command:
cc -S adbsamp2.c -o adbsamp2
This command creates the adbsamp2.s file, that contains the assembler language listing for the program, and compiles the program to the executable file, adbsamp2.
You can execute a program by using the :r or :R subcommand. The commands have the form:
[ Address ][,Count ] :r [Arguments ]
[ Address ][,Count ] :R [Arguments ]
In this format, the Address parameter gives the address at which to start running the program; the Count parameter is the number of breakpoints to skip before one is taken; and the Arguments parameter provides the command-line arguments, such as file names and options, to pass to the program.
If you do not supply an Address value, the adb program uses the start of the program. To run the program from the beginning enter:
If you supply a Count value, the adb program ignores all breakpoints until the given number has been encountered. For example, to skip the first five named breakpoints, use the command:
If you provide arguments, separate them by at least one space each. The arguments are passed to the program in the same way the system shell passes command-line arguments to a program. You can use the shell redirection symbols.
The :R subcommand passes the command arguments through the shell before starting program operation. You can use shell pattern-matching characters in the arguments to refer to multiple files or other input values. The shell expands arguments containing pattern-matching characters before passing them to the program. This feature is useful if the program expects multiple file names. For example, the following command passes the argument [a-z]* to the shell where it is expanded to a list of the corresponding file names before being passed to the program:
The :r and :R subcommands remove the contents of all registers and destroy the current stack before starting the program. This operation halts any previous copy of the program that may be running.
To set a breakpoint in a program, use the :b subcommand. Breakpoints stop operation when the program reaches the specified address. Control then returns to the adb debug program. The command has the form:
[Address] [,Count ] :b [Command]
In this format, the Address parameter must be a valid instruction address; the Count parameter is a count of the number of times you want the breakpoint to be skipped before it causes the program to stop; and the Command parameter is the adb command you want to execute each time that the instruction is executed (regardless of whether the breakpoint stops the program). If the specified command sets . (period) to a value of 0, the breakpoint causes a stop.
Set breakpoints to stop program execution at a specific place in the program, such as the beginning of a function, so that you can look at the contents of registers and memory. For example, when debugging the example adbsamp2 program, the following command sets a breakpoint at the start of the function named f:
The breakpoint is taken just as control enters the function and before the function's stack frame is created.
A breakpoint with a count is used within a function that is called several times during the operation of a program, or within the instructions that correspond to a for or while statement. Such a breakpoint allows the program to continue to run until the given function or instructions have been executed the specified number of times. For example, the following command sets a breakpoint for the second time that the f function is called in the adbsamp2 program:
The breakpoint does not stop the function until the second time the function is run.
Use the $b subcommand to display the location and count of each currently defined breakpoint. This command displays a list of the breakpoints by address and any count or commands specified for the breakpoints. For example, the following example sets two breakpoints in the adbsamp2 file and then uses the $b subcommand to display those breakpoints:
.f+4:b .f+8:b$v $b breakpoints count brkpt command 1 .f+8 $v 1 .f+4
When the program runs, it stops at the first breakpoint that it finds, such as .f+4 . If you use the :c subcommand to continue execution, the program stops again at the next breakpoint and starts the $v subcommand. The command and response sequence looks like the following example:
:r adbsamp2:running breakpoint .f+4: st r3,32(r1) :c adbsamp2:running variables b = 268435456 d = 236 e = 268435512 m = 264 breakpoint .f+8 l r15,32(r1)
To use the :d subcommand to delete a breakpoint from a program, enter:
In this format, the Address parameter gives the address of the breakpoint to delete.
For example, when debugging the example adbsamp2 program, entering the following command deletes the breakpoint at the start of the f function:
To use the :c subcommand to continue the execution of a program after it has been stopped by a breakpoint enter:
[Address ] [,Count ] :c [Signal ]
In this format, the Address parameter gives the address of the instruction at which to continue operation; the Count parameter gives the number of breakpoints to ignore; and the Signal parameter is the number of the signal to send to the program.
If you do not supply an Address parameter, the program starts at the next instruction after the breakpoint. If you supply a Count parameter, the adb debug program ignores the first Count breakpoints.
If the program is stopped using the Interrupt or Quit key, this signal is automatically passed to the program upon restarting. To prevent this signal from being passed, enter the command in the form:
[Address] [,Count] :c 0
The command argument 0 prevents a signal from being sent to the subprocess.
Use the :s subcommand to run a program in single steps or one instruction at a time. This command issues an instruction and returns control to the adb debug program. The command has the form:
[Aaddress ] [,Count ] :s [Signal]
In this format, the Address parameter gives the address of the instruction you want to execute, and the Count parameter is the number of times you want to repeat the command. If there is no current subprocess, the ObjectFile parameter is run as a subprocess. In this case, no signal can be sent and the remainder of the line is treated as arguments to the subprocess. If you do not supply a value for the Address parameter, the adb program uses the current address. If you supply the Count parameter, the adb program continues to issue each successive instruction until the Count parameter instructions have been run. Breakpoints are ignored while single-stepping. For example, the following command issues the first five instructions in the main function:
Use either the Interrupt or Quit key to stop running a program at any time. Pressing either of these keys stops the current program and returns control to the adb program. These keys are useful with programs that have infinite loops or other program errors.
When you press the Interrupt or Quit key to stop a program, the adb program automatically saves the signal. If you start the program again using the :c command, the adb program automatically passes the signal to the program. This feature is useful when testing a program that uses these signals as part of its processing. To continue running the program without sending signals, use the command:
The command argument 0 (zero) prevents a signal from being sent to the program.
To stop a program you are debugging, use the :k subcommand. This command stops the process created for the program and returns control to the adb debug program. The command clears the current contents of the system unit registers and stack and begins the program again. The following example shows the use of the :k subcommand to clear the current process from the adb program:
adb Debug Program Overview.
adb Debug Program Expressions.
adb Debug Program Subcommands.
Example adb Program: adbsamp.
Example adb Program: adbsamp3.