• Keine Ergebnisse gefunden

Types of Watch Expressions

Im Dokument Turbo Pascal® (Seite 142-149)

So far, the only expressions you've seen in the Watch window are integer variables and arrays. You can actually put any kind of constant, variable, or data structure in as an expression; you can also put in Pascal expressions.

Specifically, here's what you can add and how it will be displayed:

• Integers: Integers are displayed in decimal values; you can also display them in hexadecimal. Examples:

-23 $10

• Reals: Reals are displayed without an exponent, if possible. Examples:

38328.27 6.283e23 0.00299823532

• Characters: Printable characters (including the extended graphics characters) are displayed as themselves, within single quotes; control characters (ASCII codes 0 .. 31) have their ASCII codes displayed.

Examples:

'b' '0' #4

You can elect to have control characters be treated as "printable."

• Booleans: Booleans are displayed as either True or False.

• Enumerated data types: The data types are displayed as their actual named values (in all uppercase); for example,

RED JAN WEDNESDAY

• Pointers: The current contents of a pointer are displayed as a pointer in (segment:offset) hexadecimal format. Examples:

PTR($3632,$106) PTR(DSEG,$AB) PTR(CSEG,$220)

• Strings: The current contents of a string are displayed within single quotes. Example:

'Droid'

• Arrays: The current contents of an array are displayed within parentheses, with elements separated by commas. Multidimensional arrays are displayed as nested lists. Examples:

(-42,23,2292,0,684) ((10,20) (20,40) (40,60))

• Records: The current contents of a record are displayed within parentheses, with fields separated by commas. Nested records are dis-played as nested lists. Examples:

(5,10,'Borland' ,RED,TRUE) (5.6,7.8, (TRUE,'O' ,9),TUES)

• Sets: The current elements of a set are displayed within brackets, with expressions separated by commas; subranges are used when possible.

Examples:

[MON,WED,FRIl ['0' •. '9' ,'A' oo'F'l

• Files: A file's current status is displayed in the format (status,fname), where status is CLOSED, OPEN, INPUT, or OUTPUT, and fname is the name of the disk file assigned to the file variable. Example:

(OPEN,'BUDGET.DTA') (INPUT,'INPUT.TXT')

Format Specifiers

To control exactly how information is displayed in the Watch window, Turbo Pascal allows you to add format specifiers to your Watch expressions.

A format specifier follows the Watch expression, separated from it by a single comma.

A format specifier consists of an optional repeat count (an integer), followed by zero or more format characters; no spaces are required between the repeat count and the format characters. Table 6.2 lists the available format specifiers, and describes their effects.

The repeat count is used to display consecutive variables, such as the elements of an array. For example, assuming List is an array of 10 integers, the Watch expression List would display:

List: (10,20,30,40,50,60,70,80,90,100)

If you want to look at a particular range of the array, you can specify the index of the first element, and add a repeat count:

List[6],3: 60,70,80

The above technique is particularly useful for dealing with arrays that are too large to be displayed completely on a single line.

Repeat counts aren't limited to arrays; any variable may be followed by a repeat count. The general syntax var, x simply displays x consecutive variables of the same type as var, starting at the address of var. Note however, that the repeat count is ignored if the Watch expression does not denote a variable. A good rule of thumb is that a given construct is a variable if it can legally appear on the left-hand side of an assignment statement, or be used as a var parameter to a procedure or function.

Character

Table 6.2: Debug Expression Format Characters

Function

Hexadecimal. Has the same effect as the H specifier.

Character. Shows special display characters for control characters (ASCII 0 .. 31); by default, such characters are shown as ASCII values using the #xx syntax. Affects characters and strings.

Decimal. All integer values are displayed in decimal.

Affects simple integer expressions as well as structures (arrays and records) containing integers.

Floating-point. n is an integer between 2 and 18 specifying the number of significant digits to display. The detauft value is 11. Affects only floating-point vaIues.

Hexadecimal. All integer values are displayed in hexa-decimal with a preceding '$' character. Affects simple integer expressions as well as structures (arrays and records) containing integers.

Memory. Displays a memory dump of a variable. The expreSSIOn must be a construct that would be valid on the left-hand side of an assignment statement (that is, a construct that denotes a memory address); otherwise, the M specifier is ignored. By default, each byte of the variable is snown as two hexadecimal digits. Adding a 0 specifier causes the bytes to be displayed m decimal, and adding an H, $, or X specifier causes the bites to be displayed in hexadecimal with a preceding '$ character. A C or an S specifier causes the variable to be displayed as a string (with or without special characters). The default number of bytes displayed corresponds to the size of the variable, but a repeat count may be used to specify an exact number of bytes. Note: Because of the way lNTEL architecture stores data, the memory dump may not look the way you expect it to. For example, integers are stored with the low byte first, then the high byte.

Pointer. Displays pointers in seg : ols format rather than the default Ptr(seg,ofs) format. For example; displays 3EAO:0020 instead of Ptrf$3EAO,$20). Affects only pointer values.

Record. Displays record field names, such as (X:1;Y:10;Z:S) instead of (r,10,S). Affects only record variables.

String. Shows control characters (ASCII 0 .. 31) as ASCII values using the #xx syntax. Since this is the default character and string display format, the S specifier is only useful in conjunction with the M specifier.

Hexadecimal. Has the same effect as the H specifier.

To demonstrate the use of format specifiers, assume that the following types and variables have been declared:

type

NarnePtr = ~NameReci

NarneRec = record

var

Next: NamePtri Count: Integer;

Narne: strinq[31]i and;

List: array[1 •• 10] of Integer;

P: NamePtr;

Given the above declarations, the following Watch expressions can be constructed:

List: (10,20,30,40,50,60,70,80,90,100) List[6],3H: $3C,$46,$50

P: PTR($3EAO,$C) P,P: 3EAO:OOOC

P~: (PTR($3EF2,$2),412,'John')

P~,R$: (NEXT:PTR($3EF2,$2)iCOUNT:$19C;NAME:'John')

P~.Next~,R: (NEXT:NIL;COUNT:377;NAME:'Joe') Mem[$40:0],10M: F8 03 F8 02 00 00 00 00 BC 03 Mem[$40:0],10MD: 248 3 248 2 0 000 188 3

Typecasting

Typecasting is another powerful feature you can use to modify how Watch expressions are displayed, letting you interpret data as a different type than it would normally be. This can be especially useful if you're working with an address or a generic pointer, and you want to view it as pointing to a particular data type.

Suppose your program has a variable DFile that is of type file of MyRec,

and you execute the following sequence of code:

Assign(DFile,'INPUT.REC');

Reset (DFile) ;

If you add DFile as a watch, the corresponding line in the Watch window will look like this:

DFile: (OPEN,'INPUT.REC')

But you might want more information about the file record itself. If you change your program so that it uses the Dos unit, then you can modify the DFile watch to FileRec (DFile) ,rh, which means, "Display DFile as if it were a record of type FileRec (declared in the Dos unit), with all record fields

labeled and all integer values displayed in hexadecimal." The result in the Watch window might look something like this:

FileRec(DFile),rh: (HANDLE:$6;MODE:$D7B3;RECSIZE:$14;PRIVATE:($0,$0, ••• ))

The record is too large to view at once; however, you can use the cursor movement keys to scroll the data not visible on the screen (see the section

"Editing the Watch Window" on page 133).

With this typecasting, you can now watch specific fields of DFile. For example, you could view the UserData field by adding the expression FileRec(DFile) .UserData to the Watch window:

FileRec (DFile) .UserData: (0, 0, 0, 0, 0,0, 0, 0, 0,0, 0, 0, 0,0, 0, 0)

You can apply the same technique to data structures and types of your own design. If they're declared in your program or units, you can typecast to them in the Watch window. The rules for typecasting are explained in Chapter 6 of the Reference Guide, "Expressions."

Expressions

As we mentioned earlier, you can use expressions as Watch expressions; you could have calculations, comparisons, address offsets, and other such expressions. Table 6.3 lists the kinds of features legal in a Watch expression, as well as acceptable values.

Table 6.3: \M:Jtch Expression Values Legal in a Watch Expression Acceptable Values Literals and Constants

All types, including user-defined types and elements of data structures:

Any integer expression within the variable's range bounds.

Any floating-point (or integer) expression within the variable's eXEonent range; excess significant digits are droppea.

Any character expression, including any printable character surrounded by single quotes; integer expressions typecast to char using Chr or Cfuir();

ASCII constants (#, followed by any a value from

o to 255).

True and False; any Boolean expression.

Any compatible enumerated constant; in-range integer expressions typecast to a compatible enumerated type.

Any compatible Eointer; any compatible typecast expression; the function Ptr (with appropriate parameters).

Any string constant (text enclosed by single quotes); string variables; string expressions consisting of string constants and variables concatenated with the + operator.

Any set constant (compatible elements sur-rounded by square brackets); any compatible set expression, including the u~ of set operators +, -,

*.

Following standard Pascal rules.

All normal Pascal operators, plus Turbo Pascal extensions such as xor, @, and so on.

In other words, the expression must be a normal, legal Pascal expression, and can use any or all of the features described in Table 6.3. See "Modifi-cation Issues" on page 136 for information on how to modify Watch expres-sions.

Im Dokument Turbo Pascal® (Seite 142-149)