15.3.5 Displaying Structures

MASM adds structure and union information to the debugging table. You can display MASM structures in expanded form, just as you would in C, Basic, Pascal, or FORTRAN.

Structures contain multiple data values, often of different data types, arranged in one or more layers. Therefore, they are often referred to as “aggregate” data items. CodeView lets you control how much of a structure is shown; that is, whether all, part, or none of its components are displayed.

The following example defines a structure and pointer types to implement a simple linked list:

PTRLINKEDLIST TYPEDEF PTR LINKEDLIST

PTRDATAWORD TYPEDEF PTR WORD

LINKEDLIST STRUCT

ptrNext PTRLINKEDLIST 0

ptrData PTRDATAWORD 0

LINKEDLIST ENDS

rootNode linkedList < >

Once rootNode has been defined, the program calls the MALLOC function (which is available from the libraries of Microsoft high-level languages) to allocate memory for a structure pointer and a data pointer. The addresses of each are assigned to the corresponding pointers in rootNode, readying the list for its first entry.

The program stores a list item at the memory location specified by the preceding pointer, then calls MALLOC to allocate memory for the next list item. This process is repeated for each new list item, creating a linked list of data structures.

To display the linked list of structures, add rootNode to the Watch window. It initially appears in the form:

+rootnode = {...}

The brackets indicate that this is an aggregate variable (since it's a structure). The plus sign (+) indicates that the structure has not yet been expanded to display its components.

To expand rootnode, double-click its display line. (Position the mouse pointer anywhere on the line and press the left mouse button twice, rapidly.) You can also move the cursor to the line and press ENTER. The Watch window display changes to

-rootnode

+ptrnext = 0F00:1111

ptrdata = 0x0032 "2"

The address and data values shown here are arbitrary. They depend on the data values stored and on the memory location from where MALLOC obtained free space. The minus sign () indicates that rootnode has been fully expanded; no further expansion is possible. The plus sign (+) indicates that ptrnext points to another structure that has not been expanded.

Any structure element can be independently expanded or contracted. To expand the next structure, double-click ptrnext, or press ENTER when the cursor is on that line. The Watch window display changes to

-rootnode

-ptrnext = 0F00:1111

+ptrnext = 0F00:2222

ptrdata = 0x0034 "4"

ptrdata = 0x0032 "2"

Note that both the data value and its ASCII equivalent are displayed. To contract the structure, double-click its line a second time or position the cursor on the line and press ENTER.

The process of expanding structures pointed to by ptrnext may be repeated indefinitely until you reach the last structure in the list. Its identifier will be prefixed with a minus sign, indicating that no more space for structures has been allocated.

Summary: You can view individual elements instead of the entire structure.

If you want to view only one or two elements of a large structure, indicate the specific structure elements in the Expression field of the Add Watch dialog box. Structure elements are separated by a dot (.), so you would type

rootnode.ptrnext.ptrnext

to view the pointer from the third structure in the list.