Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc Intel XENIX 286 Programmers Guide (86) - Tenox.tc

09.06.2013 Views

XENIX Programming adb: Program Debugger You can also examine all variables as a whole. For example, if you wish to see them all in hexadecimal, type str1,5/8x This command displays eight hexadecimal values on a line and continues for five lines. Since the data contains a combination of numeric and string values, it is worthwhile to display each value as both a number and a character to see where the actual strings are located. You can do this with one command by typing str1,5/4x4"' 8Cn In this case, the command displays four values in hexadecimal, then the same values as eight ASCII characters. The caret ("') is used four times just before displaying the characters to set the current address back to the starting address for that line. To make the display easier to read, you can insert a tab between the values and characters and give an address for each line by typing str1,5/4x4"'8t8Cna Debugging Program Execution adb provides a variety of commands to control the execution of programs being debugged. The following sections explain how to use these commands as well as how to display the contents of memory and registers. Note that C does not generate statement labels for programs. Thus it is not possible to refer to individual C statements when using the debugger. To use execution commands effectively, you must be familiar with the instructions generated by the C compiler and how they relate to individual C statements. One useful technique is to create an assembly language listing of your C program before using adb, then refer to the listing as you use the debugger. To create an assembly language listing, use the -S option of the cc command (see Chapter 2, "cc: C Compiler"). Executing a Program You can execute a program by using the :r or :R commands. The commands have the form address ] [,count ] : r [ arguments ] address ] [,count ] : R [ arguments ] where address gives the address at which to start execution, count is the number of breakpoints you wish to skip before one is taken, and arguments are the command line arguments, such as file names and options, you wish to pass to the program. 6-13

adb: Program Debugger XENIX Programming If no address is given, then the start of the program is used. Thus, to execute the program from the beginning, type : r If a count is given, adb will ignore all breakpoints until the given number have been encountered. For example, the command ,S:r causes adb to skip the first five breakpoints. If arguments are given, they must be separated 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 may use the shell redirection symbols if you wish. The :R command passes the command arguments through the shell before starting program execution. This means you can use shell metacharacters in the arguments to refer to multiple files or other input values. The shell expands arguments containing metacharacters before passing them on to the program. The command is especially useful if the program expects multiple file names. For example, the command :R [a-z]*.s passes the argument "[a-z]* .s" 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 commands remove the contents of all registers and destroy the current stack before starting the program. This kills any previous copy of the program you may have been running. Setting Breakpoints You can set a breakpoint in a program by using the :br com mand. Breakpoints cause execution of the program to stop when it reaches the specified address. Control then returns to adb. The command has the form address [, count ] :br command where address is a valid instruction address, count is a count of the number of times you wish the breakpoint to be skipped before it causes the program to stop, and command is the adb command you wish to execute when the breakpoint is taken. 6-14

adb: Program Debugger <strong>XENIX</strong> Programming<br />

If no address is given, then the start of the program is used. Thus, to execute the<br />

program from the beginning, type<br />

: r<br />

If a count is given, adb will ignore all breakpoints until the given number have been<br />

encountered. For example, the command<br />

,S:r<br />

causes adb to skip the first five breakpoints.<br />

If arguments are given, they must be separated by at least one space each. The<br />

arguments are passed to the program in the same way the system shell passes command<br />

line arguments to a program. You may use the shell redirection symbols if you wish.<br />

The :R command passes the command arguments through the shell before starting<br />

program execution. This means you can use shell metacharacters in the arguments to<br />

refer to multiple files or other input values. The shell expands arguments containing<br />

metacharacters before passing them on to the program.<br />

The command is especially useful if the program expects multiple file names. For<br />

example, the command<br />

:R [a-z]*.s<br />

passes the argument "[a-z]* .s" to the shell, where it is expanded to a list of the<br />

corresponding file names before being passed to the program.<br />

The :r and :R commands remove the contents of all registers and destroy the current<br />

stack before starting the program. This kills any previous copy of the program you may<br />

have been running.<br />

Setting Breakpoints<br />

You can set a breakpoint in a program by using the :br com mand. Breakpoints cause<br />

execution of the program to stop when it reaches the specified address. Control then<br />

returns to adb. The command has the form<br />

address [, count ] :br command<br />

where address is a valid instruction address, count is a count of the number of times you<br />

wish the breakpoint to be skipped before it causes the program to stop, and command is<br />

the adb command you wish to execute when the breakpoint is taken.<br />

6-14

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!