Navigating the Call Stack

You can select one of the call frames as the starting point for examining variables. This call frame provides the current scope in the program for which variables exist, and tells the debugger which instance of those variables whose values you want to see.

DBX Mode

 

change_stack_frame_command

        : up   [ expression]

        | down [ expression]

        | func [ loc ]

GDB Mode

 

change_stack_frame_command

        : up            [ expression]

        | up-silently   [ expression]

        | down          [ expression]

        | down-silently [ expression]

        | frame         [ expression]

 

Use the up command or the down command without the expression to change to the call frame located one level up or down the stack. Specify an expression that evaluates to an integer to change the call frame up or down the specified number of levels. If the number of levels exceeds the number of active calls on the stack in the specified direction, the debugger issues a warning message and the call frame does not change.

When the current call frame changes, the debugger displays the source line corresponding to the last instruction executed in the function executing the selected call frame.

DBX Mode

When large and complex values are passed by value to a routine on the stack, the output of the up and down commands can be voluminous. You can set the control variable $stackargs to 0 to suppress the output of argument values in the up and down commands.

Use the func command without the loc to display the current function. To change the function scope to a function that has a call frame in the call stack, specify the loc either as the name of the function or as an integer expression evaluating to the call level. If you specify the name, the most-recently entered call frame for that function becomes the current call frame.

If no frames are available to select from, the debugger context is set to the static context of the named function. The current scope and current language are set based on that function. Types and static variables local to that function are now visible and can be evaluated.

If you enter an integer expression, the debugger moves to the frame at level n, just as if you had entered up n at the level 0 function.

GDB Mode

up-silently and down-silently commands are similar to up and down respectively. But they work without invoking a new frame.

The frame command selects frame by given number or address. If there is no argument the command displays info about current stack frame.

In the following example, the current call frame is changed to one for method Planet::print so that a variable in that instance of print() can be displayed:

DBX Mode

 

(idb) where 4

#0  0x080553fd in ((Planet*)0x806e298)->Planet::printBody(i=2) "/home/user/examples/solarSystemSrc/planet.cxx":19

#1  0x0804d697 in ((HeavenlyBody*)0x806e298)->HeavenlyBody::printBodyAndItsSatellites(i=2) "/home/user/examples/solarSystemSrc/heavenlyBody.cxx":62

>2  0x0804d6d2 in ((HeavenlyBody*)0x806e168)->HeavenlyBody::printBodyAndItsSatellites(i=1) "/home/user/examples/solarSystemSrc/heavenlyBody.cxx":68

#3  0x08058bf2 in main() "/home/user/examples/solarSystemSrc/main/solarSystem.cxx":120

(idb) list $curline - 5:10

     63

     64     // Recursively deal with the satellites.  Redeclare i for scoping examples.

     65     //

     66     unsigned int j = 1;

     67     for (HeavenlyBody* i = _firstSatellite; i; i = i->_outerNeighbor) {

>    68     i->printBodyAndItsSatellites(j++);     {static int somethingToReturnTo; somethingToReturnTo++; }

     69     }

     70 }

(idb) whatis i

class HeavenlyBody* i

(idb) print i

0x806e298

(idb) func Planet::printBody

virtual void Planet::printBody(unsigned int) in /home/user/examples/solarSystemSrc/planet.cxx line No. 19:

     19     std::cout << "(" << i

(idb) where 4

>0  0x080553fd in ((Planet*)0x806e298)->Planet::printBody(i=2) "/home/user/examples/solarSystemSrc/planet.cxx":19

#1  0x0804d697 in ((HeavenlyBody*)0x806e298)->HeavenlyBody::printBodyAndItsSatellites(i=2) "/home/user/examples/solarSystemSrc/heavenlyBody.cxx":62

#2  0x0804d6d2 in ((HeavenlyBody*)0x806e168)->HeavenlyBody::printBodyAndItsSatellites(i=1) "/home/user/examples/solarSystemSrc/heavenlyBody.cxx":68

#3  0x08058bf2 in main() "/home/user/examples/solarSystemSrc/main/solarSystem.cxx":120

(idb) list $curline - 5:10

     14 {

     15 }

     16

     17 void Planet::printBody(unsigned int i) const

     18 {

>    19     std::cout << "(" << i

     20          << ") Planet [" << HeavenlyBody::name() << "]; ";

     21     printOrbitalParameters();

     22     std::cout << std::endl;

     23 }

(idb) whatis i

unsigned int i

(idb) print i

2

 

In the previous example, instead of entering func Planet::print, you can enter down 2. (You would use down in this case because the current call frame at the start of the example was not the bottommost frame.) Note that the final stack trace in this example lists a call frame for function Planet::print as the current call frame (denoted by the > character).

GDB Mode

There are some commands to print info about the selected stack frame:

info frame

The command prints following info about the current frame:

info frame addr

The command prints a verbose description of the frame at address addr, without selecting that frame.

info args

The command prints the arguments of the selected frame, each on a separate line.

info locals

The command prints the local variables of the selected frame, each on a separate line. These are all variables (declared either static or automatic) accessible at the point of execution of the selected frame.

info catch

The command prints a list of all the exception handlers that are active in the current stack frame at the current point of execution.