The ILE C source code in Figure 62 includes data definitions of pointers, simple variables, structures, unions, and enumerations. To illustrate what can be done with the ILE source debugger and ILE C applications, the corresponding debug expressions and information are shown in the following sections:
Figure 62. Example of ILE C Source Data Definitions
|
A pointer type variable holds the address of a data object or a function. A pointer can refer to an object of any one data type (except a bit field or a reference). A pointer is classified as a scalar type, which means that it can hold only one value at a time.
For information about using pointers in your programs, see:
.
Use the EVAL debug command to display or change the value of a pointer variable or array. Messages with multiple line responses launch the Evaluate Expression display, which also shows a history of the debug commands entered and the results from these commands. To return to the Display Module Source display, press the Enter key. You can use the Enter key as a toggle switch between displays.
The following figures show examples of debug expressions for pointers.
Figure 63. Examples of Using Pointers in Debug Sessions, Screen 1
+--------------------------------------------------------------------------------+ | Evaluate Expression | | Previous debug expressions | |>eval pc1 | | pc1 = SPP:C0260900107C0000 Displaying pointers | |>eval pc2=pc1 | | pc2=pc1 = SPP:C0260900107C0000 Assigning pointers | |>eval *pc1 | | *pc1 = 'C' Dereferencing pointers | |>eval &pc1 | | &pc1 = SPP:C026090010400000 Taking an address | |>eval *&pc1 | | *&pc1 = SPP:C0260900107C0000 Can build expressions with | | normal C precedence | |>eval *(short *)pc1 | | *(short *)pc1 = -15616 Casting | | Bottom | | Debug . . . _________________________________________________________________| |_______________________________________________________________________________ | | F3=Exit F9=Retrieve F12=Cancel F18=Command entry F19=Left F20=Right | | | +--------------------------------------------------------------------------------+ |
Figure 64. Examples of Using Pointers in Debug Sessions, Screen 2
+--------------------------------------------------------------------------------+ | Evaluate Expression | | Previous debug expressions | |>eval arr1 | | arr1 = SPP:C026090010700000 Unqualified arrays are treated | | as pointers | |>eval *arr1 | | *arr1 = 'A' Dereferencing applies the array type | | (character in this example) | |>eval *arr1:s | | *arr1:s = "ABC" If the expression is an lvalue | | you can override the formatting | |>eval pc1=0 | | pc1=0 = SYP:*NULL Setting a pointer to null by assigning 0 | |>eval fncptr | | fncptr = PRP:A0CD0004F0100000 Function pointers | |>eval *pY->x.p | | *pY->x.p = ' ' Using the arrow operator | | Bottom | | Debug . . . _________________________________________________________________| |_______________________________________________________________________________ | | F3=Exit F9=Retrieve F12=Cancel F18=Command entry F19=Left F20=Right | +--------------------------------------------------------------------------------+ |
Expressions are sequences of operators, operands, and punctuators that specify a computation. The evaluation of expressions is based on the operators that the expressions contain and the context in which they are used.
For information about using expressions and operators in your programs, see:
.
Use the EVAL debug command to display or change the value of a simple expression or operator. Messages with multiple line responses launch the Evaluate Expression display, which also shows a history of the debug commands entered and the results from these commands. To return to the Display Module Source display, press the Enter key. You can use the Enter key as a toggle switch between displays.
This following figure shows examples of debug expressions for simple operations (for example, assignment, arithmetic, or relational operations).
Figure 65. Examples of Simple Operations Used in Debug Expressions
+--------------------------------------------------------------------------------+ | Evaluate Expression | | Previous debug expressions | |>eval i1==u1 || i1<u1 | | i1==u1 || i1<u1 = 0 Logical operations | |>eval i1++ | | i1++ = 100 Unary operators occur in proper order | |>eval i1 | | i1 = 101 Increment has happened after i1 was used | |>eval ++i1 | | ++i1 = 102 Increment has happened before i1 was used | |>eval u1 = -10 | | u1 = -10 = 4294967286 Implicit conversions happen | |>eval (int)u1 | | (int)u1 = -10 | |>eval dec1 Decimal types are displayed but cannot | | dec1 = 12.3 be used in expressions | | Bottom | | Debug . . . _________________________________________________________________| |_______________________________________________________________________________ | | F3=Exit F9=Retrieve F12=Cancel F18=Command entry F19=Left F20=Right | +--------------------------------------------------------------------------------+ |
Both C and C++ allow integer members to be stored into memory spaces smaller than the compiler would ordinarily allow. These space-saving structure members are called bit fields, and their width in bits can be explicitly declared. Bit fields are used in programs that must force a data structure to correspond to a fixed hardware representation and are unlikely to be portable.
For information about using bit fields, see:
.
Use the EVAL debug command to display or change the value of a bit field. Messages with multiple line responses launch the Evaluate Expression display, which also shows a history of the debug commands entered and the results from these commands. To return to the Display Module Source display, press the Enter key. You can use the Enter key as a toggle switch between displays.
The following figure shows examples of debug expressions for bit fields.
Figure 66. Examples of Using Bit Fields in Debug Expressions
+--------------------------------------------------------------------------------+ | Evaluate Expression | | | | Previous debug expressions | | | |>eval bits You can display an entire structure | | bits.b1 = 1 | | bits.b4 = 2 | |>eval bits.b4 = bits.b1 You can work with a single member | | bits.b4 = bits.b1 = 1 | |>eval bits.b1 << 2 Bit fields are fully supported | | bits.b1 << 2 = 4 | |>eval bits.b1 = bits.b1 << 2 You can overflow, but no warning is | | bits.b1 = bits.b1 << 2 = 4 generated | |>eval bits.b1 | | bits.b1 = 0 | | | | | | | | | | Bottom | | Debug . . . _________________________________________________________________| |_______________________________________________________________________________ | | F3=Exit F9=Retrieve F12=Cancel F18=Command entry F19=Left F20=Right | | | +--------------------------------------------------------------------------------+ |
A structure is a class declared with the class_key struct. The members and base classes of a structure are public by default.
A union is a class declared with the class_key union. The members of a union are public by default; a union holds only one data member at a time.
No conversions between structure or union types are allowed, except for the
following:
In C, an assignment conversion between compatible structure or union types is
allowed if the right operand is of a type compatible with that of the left
operand.
For information about using structures and unions in your programs, see:
Use the EVAL debug command to display or change the value of a structure or union. Messages with multiple line responses launch the Evaluate Expression display, which also shows a history of the debug commands entered and the results from these commands. To return to the Display Module Source display, press the Enter key. You can use the Enter key as a toggle switch between displays.
The following shows examples of debug expressions for structures and unions.
Figure 67. Examples of Using Structures and Unions in Debug Expressions
+--------------------------------------------------------------------------------+ | Evaluate Expression | | | | Previous debug expressions | | | |>eval (struct z *)&zz | | (struct z *)&zz = SPP:C005AA0010D00000 You can cast with typedefs | |>eval *(c *)&zz | | *(c *)&zz.a = 1 You can cast with tags | | *(c *)&zz.b = SYP:*NULL | | | |>eval u.x = -10 | | u.x = -10 = -10 You can assign union members | |>eval u | | u.y = 4294967286 You can display and the union will be | | u.x = -10 formatted for each definition | | | | | | | | | | Bottom | | Debug . . . _________________________________________________________________| |_______________________________________________________________________________ | | F3=Exit F9=Retrieve F12=Cancel F18=Command entry F19=Left F20=Right | | | +--------------------------------------------------------------------------------+ |
An enumeration is a data type consisting of a set of values that are named integral constants. It is also referred to as an enumerated type because you must list (enumerate) each of the values in creating a name for each of them. A named value in an enumeration is called an enumeration constant. In addition to providing a way of defining and grouping sets of integral constants, enumerations are useful for variables that have a small number of possible values. For information about using enumerations in your programs, see:
The following figure shows debug expressions for enumerations.
Figure 68. Examples of Using Enumerations in Debug Expressions
+--------------------------------------------------------------------------------+ | Evaluate Expression | | | | | | Previous debug expressions | | | |>eval color | | color = blue (2) Both the enumeration and its value are | |>eval number displayed | | number = three (2) | |>eval (enum color)number Casting to a different enumeration | | (enum color)number = blue (2) | |>eval number = 1 Assigning by number | | number = 1 = two (1) | |>eval number = three Assigning by enumeration | | number = three = three (2) | |>eval arr1[one] Using in an expression | | arr1[one] = 'A' | | | | | | | | Bottom | | Debug . . . _________________________________________________________________| |_______________________________________________________________________________ | | F3=Exit F9=Retrieve F12=Cancel F18=Command entry F19=Left F20=Right | | | +--------------------------------------------------------------------------------+ |
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.