Supported on windows
Supported on linux
Supported on android
frame command
Selects a stack frame or displays the currently selected stack frame.
Syntax
frame
frame [Frame number]
f
f [Frame number]
frame [Frame number]
f
f [Frame number]
Parameters
- Frame number
- Specifies the zero-based frame number that will be selected as a result of running this command. If no frame number is specified, this command displays the currently selected frame.
Remarks
The frame command displays brief information about the selected frame after selecting it. If you want to avoid it, use the select-frame command that is a silent version of 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 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;
}
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 frame command to select different stack frames and display various information about them.
(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) backtrace
#0 level0 () at recursion.cpp:5
#1 0x08048462 in test (level=0) at recursion.cpp:17
#2 0x0804845b in test (level=1) at recursion.cpp:14
#3 0x0804845b in test (level=2) at recursion.cpp:14
#4 0x0804845b in test (level=3) at recursion.cpp:14
#5 0x0804845b in test (level=4) at recursion.cpp:14
#6 0x0804845b in test (level=5) at recursion.cpp:14
#7 0x08048479 in main () at recursion.cpp:22
(gdb) frame
#0 level0 () at recursion.cpp:5
5 printf("Reached level 0\n");
(gdb) info args
No arguments.
(gdb) frame 1
#1 0x08048462 in test (level=0) at recursion.cpp:17
17 level0();
(gdb) info args
level = 0
(gdb) frame 2
#2 0x0804845b in test (level=1) at recursion.cpp:14
14 test(prevLevel);
(gdb) info args
level = 1
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) backtrace
#0 level0 () at recursion.cpp:5
#1 0x08048462 in test (level=0) at recursion.cpp:17
#2 0x0804845b in test (level=1) at recursion.cpp:14
#3 0x0804845b in test (level=2) at recursion.cpp:14
#4 0x0804845b in test (level=3) at recursion.cpp:14
#5 0x0804845b in test (level=4) at recursion.cpp:14
#6 0x0804845b in test (level=5) at recursion.cpp:14
#7 0x08048479 in main () at recursion.cpp:22
(gdb) frame
#0 level0 () at recursion.cpp:5
5 printf("Reached level 0\n");
(gdb) info args
No arguments.
(gdb) frame 1
#1 0x08048462 in test (level=0) at recursion.cpp:17
17 level0();
(gdb) info args
level = 0
(gdb) frame 2
#2 0x0804845b in test (level=1) at recursion.cpp:14
14 test(prevLevel);
(gdb) info args
level = 1
Compatibility with VisualGDB
Do not execute the frame command manually under Visual Studio. Use the Call Stack window to navigate through stack frames instead.