4.  Maps

      UNIX supports several executable file formats. These are used to tell the loader how to load the program file. File type 407 is the most common and is generated by a C compiler invocation such as cc pgm.c. A 410 file is produced by a C compiler command of the form cc -n pgm.c, whereas a 411 file is produced by cc -i pgm.c. ADB interprets these different file formats and provides access to the different segments through a set of maps (see Figure 8). To print the maps type:
$m

      In 407 files, both text (instructions) and data are intermixed. This makes it impossible for ADB to differentiate data from instructions and some of the printed symbolic addresses look incorrect; for example, printing data addresses as offsets from routines.

      In 410 files (shared text), the instructions are separated from data and ?* accesses the data part of the a.out file. The ?* request tells ADB to use the second part of the map in the a.out file. Accessing data in the core file shows the data after it was modified by the execution of the program. Notice also that the data segment may have grown during program execution.

      In 411 files (separated I & D space), the instructions and data are also separated. However, in this case, since data is mapped through a separate set of segmentation registers, the base of the data segment is also relative to address zero. In this case since the addresses overlap it is necessary to use the ?* operator to access the data space of the a.out file. In both 410 and 411 files the corresponding core file does not contain the program text.

      Figure 9 shows the display of three maps for the same program linked as a 407, 410, 411 respectively. The b, e, and f fields are used by ADB to map addresses into file addresses. The "f1" field is the length of the header at the beginning of the file (020 bytes for an a.out file and 02000 bytes for a core file). The "f2" field is the displacement from the beginning of the file to the data. For a 407 file with mixed text and data this is the same as the length of the header; for 410 and 411 files this is the length of the header plus the size of the text portion.

      The "b" and "e" fields are the starting and ending locations for a segment. Given an address, A, the location in the file (either a.out or core) is calculated as:
b1<=A<=e1 => file address = (A-b1)+f1
b2<=A<=e2 => file address = (A-b2)+f2
A user can access locations by using the ADB defined variables. The $v request prints the variables initialized by ADB:
b base address of data segment
d length of the data segment
s length of the stack
t length of the text
m execution type (407,410,411)

      In Figure 9 those variables not present are zero. Use can be made of these variables by expressions such as:
<b
in the address field. Similarly the value of the variable can be changed by an assignment request such as:
02000>b
that sets b to octal 2000. These variables are useful to know if the file under examination is an executable or core image file.

      ADB reads the header of the core image file to find the values for these variables. If the second file specified does not seem to be a core file, or if it is missing then the header of the executable file is used instead.