Chapter Contents

Previous

Next
Debugging C++ Programs Using the SAS/C Debugger

Specifying Expressions

The debugger supports the use of operators, types, and casts that are specific to C++. This section delineates these items and explains how expressions are evaluated for C++ programs in the debugger. Note that only standard C++ operators are supported in expressions. That is, user-defined overloaded operators cannot be used. This includes the use of complex and I/O stream operators. For example, you cannot specify print (a+b) where a and b are complex.


Operators

(member pointer)">The following operators are supported in debugger expressions:

:: (unary scope)
indicates the scope operator (identifies the object or function as file-scope).

:: (binary scope)
indicates the scope operator (identifies the object or function as a member of a class).

->*
indicates a member-pointer.

.*
indicates a member-pointer.

Only one level of :: is supported after a . or -> operator. For example, the following is not valid syntax in a debugger command:

p->A::BB::c


Casts

In addition to the syntax for casts supported for C in the debugger, the keyword class is supported as in

(class TAG*)ADD

Casts to reference types are not supported. If two classes you are referencing are related (that is, one is derived from the other), the debugger performs the cast and issues a message that indicates address translation may have occurred.


Data Types

All debugger commands that support expressions support the following C++ data types:

The following sections detail any special considerations for using debugger commands with C++ data types. Static members of class objects do not participate in any assign , copy , dump , monitor , print , return , or watch commands that deal with objects of type class . For example, because all classes share the same static data, if you copy a class with the copy command, you do not modify static members.

A member-pointer is not considered a pointer in the C or C++ sense. Therefore, it is invalid to specify an expression of type member-pointer in a command (such as dump ) that takes an address for an operand.

assign command

The assign command can be used to assign a pointer to an object of a derived class to a pointer to the base class. When multiple inheritance is used, this can cause the values of the derived pointer and the base pointer as printed by the print command to differ. This can also occur for assignments involving member-pointers.

An assignment to a reference assigns to the referenced object.

An assignment to a class object is permitted using an initializer list or a class object only if the class does not have base classes and if no user-defined constructors need be invoked to initialize the class object.

dump command and Dump window

The dump command and the Dump window support all the data types listed earlier in this section. The dump command takes an address as an argument and, by default, dumps memory corresponding to the size of the object. A member pointer can be one of two sizes, depending on whether it is a data pointer or a function pointer:
data pointers are 4 bytes long.
function pointers are 12 bytes long.
A member-pointer is not considered to yield an address type. Therefore the following command is not valid:

dump member-pointer

The following command dumps the referenced object, as explained in Expression Evaluation:

dump reference-object


monitor command

You cannot monitor an object through a reference variable. You can only monitor the reference variable itself. If you set a monitor on a class object that con- tains a reference, the storage allocated for the class object (which includes the storage allocated to the reference variable) is monitored. That is, the referenced object is not monitored.

For objects of derived classes, the base objects are also monitored. Because the entire storage of an object is monitored, it is possible for the monitor to be triggered without any change in the printed value. That is, for some data types (such as function member-pointers), some parts of the value may not be reflected in the value produced by the print command. The debugger attempts to detect corruption of control data and hidden pointers to virtual base classes (that is, members of a class that are in addition to those members you have explicitly created). If your program is erroneously overwriting memory, it could overwrite some of these control data or hidden pointers. Even though this corruption does not affect the value that is printed, the monitor is triggered.

return command

For a function that returns a reference, the return command returns a reference. A function may return a class using an initializer list or a class object only if the class does not have base classes and if no constructors are needed to initialize the class.

transfer command

For a reference type object, use the C++ notation for references (such as class myobject& ) in the typeof keyword of the transfer command.

whatis command

The whatis command uses the C++ notation for references (such as myobject& ) in its output.

For classes, whatis displays the following information, in addition to the usual C information:


Expression Evaluation

Normal C++ rules are followed in expression evaluation, with the following exception. If a static member is dereferenced using the -> or . operator, the expression to the left of the -> or . operator is evaluated by the debugger.


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.