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

set backtrace past-entry command

Specifies whether GDB will try to unwind the frames below the module entry point in the backtrace.

Syntax

set backtrace past-entry on
set backtrace past-entry off
show backtrace past-entry

Modes

on
In this mode GDB will try to unwind and display the frames below the entry point. This mode can be useful when debugging custom loaders and other system-level code. Note that this mode will have no effect unless you set backtrace past-main is set to on.
off
In this mode GDB will not hide the frames below the entry point.

Default value

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

Remarks

Note that if you set the backtrace past-entry variable to on, without setting backtrace past-main to on, GDB will stop the backtrace on main() and will not show the entry point or the frames below it.

Examples

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[])
{
    func();
    return 0;
}

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

GNU gdb (GDB) 7.5
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from C:\MinGW32\bin\0.exe...done.
(gdb) break func
Breakpoint 1 at 0x4013b6: file 0.cpp, line 5.
(gdb) run
Starting program: C:\MinGW32\bin\0.exe
[New Thread 12304.0x3238]

Breakpoint 1, func () at 0.cpp:5
5 printf("Hello from func()\n");
(gdb) backtrace
#0 func () at 0.cpp:5
#1 0x004013d4 in main (argc=1, argv=0x9c17f0) at 0.cpp:10
(gdb) show backtrace past-entry
Whether backtraces should continue past the entry point of a program is off.
(gdb) set backtrace past-main on
(gdb) backtrace
#0 func () at 0.cpp:5
#1 0x004013d4 in main (argc=1, argv=0x9c17f0) at 0.cpp:10
#2 0x004010fd in __mingw_CRTStartup ()
#3 0x00401295 in mainCRTStartup ()
(gdb) set backtrace past-entry on
(gdb) backtrace
#0 func () at 0.cpp:5
#1 0x004013d4 in main (argc=1, argv=0x9c17f0) at 0.cpp:10
#2 0x004010fd in __mingw_CRTStartup ()
#3 0x00401295 in mainCRTStartup ()
#4 0x763633aa in KERNEL32!BaseCleanupAppcompatCacheSupport ()
from C:\Windows\syswow64\kernel32.dll
#5 0x0028ffd4 in ?? ()
#6 0x76fc9f72 in ntdll!RtlpNtSetValueKey ()
from C:\Windows\system32\ntdll.dll
#7 0x7efde000 in ?? ()
#8 0x76fc9f45 in ntdll!RtlpNtSetValueKey ()
from C:\Windows\system32\ntdll.dll
#9 0x00401280 in _gnu_exception_handler@4 ()
#10 0xffffffff in ?? ()
#11 0x77057428 in wcstombs () from C:\Windows\system32\ntdll.dll
#12 0x00000000 in ?? ()

Note that the frames below mainCRTStartup() are invalid as the stack below the mainCrtStartup() frame does not contain actual return addresses and the guessing performed by GDB produced invalid results.

Compatibility with VisualGDB

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

See also