Supported on windows
Supported on linux
Supported on embedded
Not supported on android

set backtrace past-main command

Specifies whether GDB will display frames below main() in the backtrace.


set backtrace past-main on
set backtrace past-main off
show backtrace past-main


In this mode GDB will show the frames below main(), such as mainCRTStartup(). This mode can be useful when debugging CRT-related issues.
In this mode GDB will not hide the frames below main(). This mode is selected by default and is useful when debugging most normal programs.

Default value

The default value for the backtrace past-main variable is off.


Note that if you set the backtrace past-main variable to on, GDB will display the frames below main() but not below the entry point of your executable. Use the set backtrace past-entry command to override this behavior.


In this example we will debug a simple program consisting of 2 functions:

#include <stdio.h>

void func()
    printf("Hello from func()\n");

int main(int argc, char *argv[])
    return 0;

The following example shows how the set backtrace past-main command affects the output of the backtrace command:

(gdb) b func
Breakpoint 1 at 0x401392: file 0.cpp, line 5.
(gdb) run
Starting program: c:\mingw\bin\0.exe
[New Thread 176.0xb8]

Breakpoint 1, func () at 0.cpp:5
5 printf("Hello from func()\n");
(gdb) show backtrace past-main
Whether backtraces should continue past "main" is off.
(gdb) backtrace
#0 func () at 0.cpp:5
#1 0x004013b0 in main (argc=1, argv=0x3e3f48) at 0.cpp:10
(gdb) set backtrace past-main on
(gdb) backtrace
#0 func () at 0.cpp:5
#1 0x004013b0 in main (argc=1, argv=0x3e3f48) at 0.cpp:10
#2 0x004010b9 in __mingw_CRTStartup () at ../mingw/crt1.c:244
#3 0x00401284 in mainCRTStartup () at ../mingw/crt1.c:264

Compatibility with VisualGDB

You can use the GDB Session window to execute the set backtrace past-main command manually when using VisualGDB.

See also