set backtrace limit command
Sets the maximum amount of frames displayed by the backtrace command.
Syntax
set backtrace limit 0
show backtrace limit
Parameters
- Frame count
- Specifies the maximum amount of frames displayed by the backtrace command. Specify 0 for unlimited amount of frames.
Default value
The default value for the backtrace limit variable is unlimited.
Remarks
Note that even if you specify the frame count explicitly when invoking the backtrace command, the maximum amount of frames that are displayed will not exceed the limit set by this command.
Examples
We will demonstrate the set backtrace limit command using a simple recursive program:
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;
}
In this example, main() calls test(5), test(5) calls test(4) and so on until test(0) calls level0(). We will put a breakpoint at level0() and demonstrate how the set backtrace limit command affects the output of the backtrace command:
Breakpoint 1 at 0x804841a: file recursion.cpp, line 5.
(gdb) run
Starting program: /home/testuser/recursion
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) show backtrace limit
An upper bound on the number of backtrace levels is unlimited.
(gdb) set backtrace limit 3
(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
(gdb) backtrace 5
#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
(gdb) set backtrace limit 100
(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) set backtrace limit 0
(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
Compatibility with VisualGDB
If you use the set backtrace limit command with VisualGDB, it will affect both the output of the backtrace command and the contents of the Call Stack window in Visual Studio.