5.  Advanced Usage

      It is possible with ADB to combine formatting requests to provide elaborate displays. Below are several examples.

5.1.  Formatted dump

      The line:
prints 4 octal words followed by their ASCII interpretation from the data space of the core image file. Broken down, the various request pieces mean:

<b The base address of the data segment.

<b,-1 Print from the base address to the end of file. A negative count is used here and elsewhere to loop indefinitely or until some error condition (like end of file) is detected.

The format 4o4^8Cn is broken down as follows:

4o Print 4 octal locations.

4^ Backup the current address 4 locations (to the original start of the field).

8C Print 8 consecutive characters using an escape convention; each character in the range 0 to 037 is printed as @ followed by the corresponding character in the range 0140 to 0177. An @ is printed as @@.

n Print a newline.

      The request:
could have been used instead to allow the printing to stop at the end of the data segment (<d provides the data segment size in bytes).

      The formatting requests can be combined with ADB's ability to read in a script to produce a core image dump script. ADB is invoked as:
adb a.out core < dump
to read in a script file, dump, of requests. An example of such a script is:
=3n"C Stack Backtrace"
=3n"C External Variables"
=3n"Data Segment"

      The request 120$w sets the width of the output to 120 characters (normally, the width is 80 characters). ADB attempts to print addresses as:
symbol + offset
The request 4095$s increases the maximum permissible offset to the nearest symbolic address from 255 (default) to 4095. The request = can be used to print literal strings. Thus, headings are provided in this dump program with requests of the form:
=3n"C Stack Backtrace"
that spaces three lines and prints the literal string. The request $v prints all non-zero ADB variables (see Figure 8). The request 0$s sets the maximum offset for symbol matches to zero thus suppressing the printing of symbolic labels in favor of octal values. Note that this is only done for the printing of the data segment. The request:
prints a dump from the base of the data segment to the end of file with an octal address field and eight octal numbers per line.

      Figure 11 shows the results of some formatting requests on the C program of Figure 10.

5.2.  Directory Dump

      As another illustration (Figure 12) consider a set of requests to dump the contents of a directory (which is made up of an integer inumber followed by a 14 character name):
adb dir -
0,-1? u8t14cn
In this example, the u prints the inumber as an unsigned decimal integer, the 8t means that ADB will space to the next multiple of 8 on the output line, and the 14c prints the 14 character file name.

5.3.  Ilist Dump

      Similarly the contents of the ilist of a file system, (e.g. /dev/src, on UNIX systems distributed by the UNIX Support Group; see UNIX Programmer's Manual Section V) could be dumped with the following set of requests:
adb /dev/src -
?m <b
In this example the value of the base for the map was changed to 02000 (by saying ?m<b) since that is the start of an ilist within a file system. An artifice (brd above) was used to print the 24 bit size field as a byte, a space, and a decimal integer. The last access time and last modify time are printed with the 2Y operator. Figure 12 shows portions of these requests as applied to a directory and file system.

5.4.  Converting values

      ADB may be used to convert values from one representation to another. For example:
072 = odx
will print
072 58 #3a
which is the octal, decimal and hexadecimal representations of 072 (octal). The format is remembered so that typing subsequent numbers will print them in the given formats. Character values may be converted similarly, for example:
'a' = co
a 0141
It may also be used to evaluate expressions but be warned that all binary operators have the same precedence which is lower than that for unary operators.