Setting the Class Scope Using the class Command

The debugger maintains the concept of a current context in which to perform lookup of program variable names. The current context includes a file scope and either a function scope or a class scope. The debugger automatically updates the current context when program execution suspends.

The class command lets you set the scope to a class in the program you are debugging:

 

c++_look_around_command

        : class [ class_name ]

 

If class_name is not specified, the class command displays the current class context.

Setting the class scope nullifies the function scope and vice versa. To return to the default (current function) scope, use the command func 0.

Explicitly setting the debugger's current context to a class enables you to view a class to:

After the class scope is set, you can set breakpoints in the class's member functions and examine data without explicitly mentioning the class name. If you do not want to affect the current context, you can use the scope resolution operator (::) to access a class whose members are not currently visible. Use the class command without an argument to display the current class scope. Specify an argument to change the class scope. After the class scope is set, refer to members of the class by omitting the classname:: prefix.

The following example shows the use of the class command to set the class scope to List<Node> in order to make member function append visible so a breakpoint can be set in append:

 

(idb) stop in append

Symbol "append" is not defined.

append has no valid breakpoint address

Warning: Breakpoint not set

(idb) class List<Node>

class List<Node> {

  class Node* _firstNode;

  List(void);

  void append(class Node* const);

  void print(void);

  ~List(void);

}

(idb) stop in append

[#1: stop in void List<Node>::append(class Node* const)]