To display the current address after each machine instruction, enter:
main , 5 ? ia
This produces output such as the following when used with the example program adbsamp:
.main: .main: mflr 0 .main+4: st r0, 0x8(r1) .main+8: stu rs, (r1) .main+c: li l r4, 0x1 .main+10: oril r3, r4, 0x0 .main+14:
To make it clearer that the current address does not belong to the instruction that appears on the same line, add the new-line format character to the command:
.main , 5 ? ian
In addition, you can put a number before a formatting character to indicate the number of times to repeat that format.
To print a listing of instructions and include addresses after every fourth instruction, use the following command:
This instruction produces the following output when used with the example program adbsamp:
.main: mflr 0 st r0, 0x8(r1) stu r1, -56(r1) lil r4, 0x1 .main+10: oril r3, r4, 0x0 bl .f l r0, Ox40(r1) ai r1, r1, 0x38 .main+20: mtlr r0 br Invalid opcode Invalid opcode .main+30:
Be careful where you put the number.
The following command, though similar to the previous command, does not produce the same output:
.main: .main: mflr 0 .main+4: .main+4: .main+4: .main+4: st r0, 0x8(r1) .main+8: .main+8: .main+8: .main+8: stu r1, (r1) .main+c: .main+c: .main+c: .main+c:
You can combine format requests to provide elaborate displays. For example, entering the following command displays instruction mnemonics followed by their hexadecimal equivalent:
In this example, the display starts at the address main . The negative count (-1) causes an indefinite call of the command, so that the display continues until an error condition (such as end-of-file) occurs. In the format, i displays the mnemonic instruction at that location, the ^ moves the current address back to the beginning of the instruction, and x re-displays the instruction as a hexadecimal number. Finally, n sends a newline character to the terminal. The output is similar to the following, only longer:
.main: .main: mflr 0 7c0802a6 st r0, 0x8(r1) 9001008 st r1, -56(r1) 9421ffc8 lil r4, 0x1 38800001 oril r3, r4, 0x0 60830000 bl - .f 4bffff71 l r0, 0x40(r1) 80010040 ai r1, r1, 0x38 30210038 mtlr r0 7c0803a6
The following example shows how to combine formats in the ? or / subcommand to display different types of values when stored together in the same program. It uses the adbsamp program. For the commands to have variables with which to work, you must first set a breakpoint to stop the program, and then run the program until it finds the breakpoint. Use the :b command to set a breakpoint:
Use the $b command to show that the breakpoint is set:
$b breakpoints count bkpt command 1 .main+4
Run the program until it finds the breakpoint by entering:
:r adbsamp: running breakpoint .main+4: st r0, 0x8(r1)
You can now display conditions of the program when it stopped. To display the value of each individual variable, give its name and corresponding format in a / (slash) command. For example, the following command displays the contents of str1 as a string:
str1/s str1: str1: This is a character string
The following command displays the contents of number as a decimal integer:
number/D number: number: 456
You can choose to view a variable in a variety of formats. For example, you can display the long variable lnum as a 4-byte decimal, octal, and hexadecimal number by entering the commands:
lnum/D lnum: lnum: 1234 lnum/O lnum: lnum: 2322 lnum/X lnum: lnum: 4d2
You can also examine variables in other formats. For example, the following command displays some variables as eight hexadecimal values on a line and continues for five lines:
str1,5/8x str1: str1: 5468 6973 2069 7320 6120 6368 6172 6163 7465 7220 7374 7269 6e67 0 0 0 0 number: 0 1c8 0 0 0 4d2 0 0 3fa0 0 0 0 5468 6973 2069 7320 7468 6520 7365 636f 6e64 2063 6861 7261
Since the data contains a combination of numeric and string values, 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:
str1,5/4x4^8Cn str1: str1: 5468 6973 2069 7320 This is 6120 6368 6172 6163 a charac 7465 7220 7374 7269 ter stri 6e67 0 0 0 ng~@~@~@~@~@~@ 0 1c8 0 0 ~@~@~A~<c8>~@~@~@~@
In this case, the command displays four values in hexadecimal, then displays 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:
str1,5/4x4^8t8Cna str1: str1: 5468 6973 2069 7320 This is str1+8: 6120 6368 6172 6163 a charac str1+10: 7465 7220 7374 7269 ter stri str1+18: 6e67 0 0 1 ng~@~@~@~@~@~A number: number: 0 1c8 0 0 ~@~@~A~<c8>~@~@~@~@ fpt:
adb Debug Program Overview.
Using adb Expressions.
Displaying and Manipulating the Source File with the adb Program.
Example adb Program: adbsamp2.
Example adb Program: adbsamp3.