Supported on windows
Supported on linux
Supported on embedded
Supported on android

select-frame command

Silently selects a stack frame.

Syntax

select-frame [Frame number]

Parameters

Frame number
Specifies the zero-based frame number that will be selected as a result of running this command.

Remarks

This command changes the selected frame without displaying any additional information. If you want to display the currently selected frame number, use the frame command.

Note that the currently selected frame affects the output of the info args, info locals and info frame commands.

Examples

We will illustrate the select-frame command using a recursive function below:

#include <stdio.h>

void level0()
{
    printf("Reached level 0\n");
}

void test(int level)
{
    if (level > 0)
    {
        int prevLevel = level - 1;
        printf("Level %d\n", level);
        test(prevLevel);
    }
    else
        level0();
}

int main()
{
    test(5);
    return 0;
}

We will set a breakpoint at the level0() function and use the select-frame command to silently select different stack frames. Note that unlike the frame command, the select-frame command does not produce any output:

(gdb) b level0
Breakpoint 1 at 0x804841a: file recursion.cpp, line 5.
(gdb) run
Starting program: /home/testuser/recursionDemo
Level 5
Level 4
Level 3
Level 2
Level 1

Breakpoint 1, level0 () at recursion.cpp:5
5 printf("Reached level 0\n");
(gdb) info locals
No locals.
(gdb) select-frame 1
(gdb) info locals
No locals.
(gdb) select-frame 2
(gdb) info locals
prevLevel = 0
(gdb) select-frame 3
(gdb) info locals
prevLevel = 1
(gdb) select-frame 4
(gdb) info locals
prevLevel = 2
(gdb) frame
#4 0x0804845b in test (level=3) at recursion.cpp:14
14 test(prevLevel);

Compatibility with VisualGDB

Do not execute the select-frame command manually under Visual Studio. Use the Call Stack window to navigate through stack frames instead.

See also