Chapter Contents |
Previous |
Next |
Debugging C++ Programs |
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)::
(binary scope)->*
.*
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.
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.
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. |
dump member-pointer
The following command dumps the referenced object:
dump reference-object
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.
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.
For a reference type object, use the C++ notation for references
(such as
class myobject&
) in the
typeof
keyword of the
transfer
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:
enums
,
typedefs
, and functions,
including function prototypes).
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.