Chapter Contents

Previous

Next
Debugging C++ Programs

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

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 the two classes that 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 handle 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 that involve 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 that were 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:

dump reference-object


monitor Command

You cannot monitor an object through a reference variable. You can monitor only the reference variable itself. If you set a monitor on a class object that contains a reference, only the storage allocated for the class object (which includes the storage allocated to the reference variable) is monitored. 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 other than 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 user-defined 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 member selection operator ( -> ) or the selection 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.