Debugging a Program With dbx HomeContentsPreviousNextIndex


Chapter 7

Using the Call Stack

This chapter discusses how dbx uses the call stack, and how to use the where, hide, unhide, and pop commands when working with the call stack.

The call stack represents all currently active routines--routines that have been called but have not yet returned to their respective caller.

Because the call stack grows from higher memory to lower memory, up means going toward the caller's frame (and eventually main()) and down means going toward the callee (and eventually the current function). The frame for the routine executing when the program stopped at a breakpoint, after a single-step, or when a fault occurs and produces a core file, is in lower memory. A caller routine, such as main(), is located in higher memory.

This chapter is organized into the following sections:

Finding Your Place on the Stack

Use the where command to find your current location on the stack.

where [-f] [-h] [-q] [-v] number_id

The where command is also useful for learning about the state of a program that has crashed and produced a core file. When this occurs, you can load the core file into dbx. (See Debugging an Existing Core File and "Core File Debugging with dbx" in the Using dbx Commands section of the Sun WorkShop online help.)

For more information on the where command, see "where Command" in the Using dbx Commands section of the SunWorkShop online help.

Walking the Stack and Returning Home

Moving up or down the stack is referred to as "walking the stack." When you visit a function by moving up or down the stack, dbx displays the current function and the source line. The location from which you start , home, is the point where the program stopped executing. From home, you can move up or down the stack using the up, down, or frame commands.

The dbx commands up and down both accept a number argument that instructs dbx to move a number of frames up or down the stack from the current frame. If number is not specified, the default is 1. The -h option includes all hidden frames in the count.

Moving Up and Down the Stack

You can examine the local variables in functions other than the current one.

Moving Up the Stack

To move up the call stack (toward main) number levels:

up [-h] number

For more information, see "up Command" in the Using dbx Commands section of the Sun WorkShop online help.

Moving Down the Stack

To move down the call stack (toward the current stopping point) number levels:

down [-h] number

For more information, see "down Command" in the Using dbx Commands section of the Sun WorkShop online help.

You can also move around the call stack in the Sun WorkShop Debugging window. (See "Moving Around the Call Stack" in the Using the Debugging Window section of the Sun WorkShop online help.)

Moving to a Specific Frame

The frame command is similar to the up and down commands. It lets you go directly to the frame as given by numbers displayed by the where command.

frame
frame -h
frame [-h] number
frame [-h] +[number]
frame [-h] -[number]

The frame command without an argument displays the current frame number. With number, the command lets you go directly to the frame indicated by the number. By including a + (plus sign) or - (minus sign), the command lets you move an increment of one level up (+) or down (-). If you include a plus or minus sign with a number, you can move up or down the specified number of levels. The
-h option includes any hidden frames in the count.

You can also move to a specific frame using the pop command (see Popping the Call Stack), or by using the Sun WorkShop Debugging window (see "Popping the Call Stack to the Current Frame" in the Using the Debugging Window section of the Sun WorkShop online help).

Popping the Call Stack

You can remove the stopped in function from the call stack, making the calling function the new stopped in function.

Unlike moving up or down the call stack, popping the stack changes the execution of your program. When the stopped in function is removed from the stack, it returns your program to its previous state, except for changes to global or static variables, external files, shared members, and similar global states.

The pop command removes one or more frames from the call stack. For example, to pop five frames from the stack, type:

pop 5

You can also pop to a specific frame. To pop to frame 5, type:

pop -f 5

For more information, see "pop Command" in the Using dbx Commands section of the Sun WorkShop online help.

You can also pop the call stack in the Sun WorkShop Debugging window. For more information, see "Popping the Call Stack One Function at a Time," "Popping the Call Stack to the Current Frame," and "Popping Debugger Frames from the Call Stack" in the Using dbx Commands section of the Sun WorkShop online help.

Hiding Stack Frames

Use the hide command to list the stack frame filters currently in effect.

To hide or delete all stack frames matching a regular expression, type:

hide [ regular_expression ]

The regular_expression matches either the function name, or the name of the loadobject, and is a sh or ksh file matching style regular expression.

Use unhide to delete all stack frame filters.

unhide 0

Because the hide command lists the filters with numbers, you can also use the unhide command with the filter number.

unhide [ number | regular_expression ]


Sun Microsystems, Inc.
Copyright information. All rights reserved.
Feedback
Library   |   Contents   |   Previous   |   Next   |   Index