perintah set backtrace limit

Menetapkan jumlah maksimum frame yang ditampilkan oleh perintah backtrace.

Sintaks

set backtrace limit [Jumlah frame]
set backtrace limit 0
show backtrace limit

Parameter

Jumlah frame
Menentukan jumlah maksimum frame yang ditampilkan oleh perintah backtrace. Tentukan 0 untuk jumlah frame tanpa batas.

Nilai Default

Nilai default untuk variabel backtrace limit adalah tanpa batas.

Catatan

Perhatikan bahwa bahkan jika Anda menentukan jumlah frame secara eksplisit saat memanggil perintah backtrace, jumlah maksimum frame yang ditampilkan tidak akan melebihi batas yang ditetapkan oleh perintah ini.

Contoh

Kami akan menunjukkan penggunaan perintah set backtrace limit dengan program rekursif sederhana:

                        
#include 

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;
}
                        
                    

Pada contoh ini, main() memanggil test(5), test(5) memanggil test(4), dan seterusnya hingga test(0) memanggil level0(). Kami akan menempatkan breakpoint di level0() dan menunjukkan bagaimana perintah set backtrace limit memengaruhi output dari perintah backtrace:

                        
(gdb) break level0
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