function::print_backtrace_fileline - Linux


Overview

print_backtrace_fileline is a gdb command used to print a backtrace with file and line numbers on each frame. It provides a more detailed view of the call stack, making it easier to identify the location of errors or issues in your code.

Syntax

print_backtrace_fileline

Options/Flags

This command has no options or flags.

Examples

Simple Usage

To print a backtrace with file and line numbers:

(gdb) print_backtrace_fileline

#0  0x0000000000401534 in foo () at /home/user/project/src/foo.cpp:12
#1  0x000000000040157e in bar () at /home/user/project/src/bar.cpp:17
#2  0x00000000004015c8 in main () at /home/user/project/src/main.cpp:22

Complex Usage

You can use the –skip option to skip a specified number of frames from the backtrace:

(gdb) print_backtrace_fileline --skip=1

#0  0x000000000040157e in bar () at /home/user/project/src/bar.cpp:17
#1  0x00000000004015c8 in main () at /home/user/project/src/main.cpp:22

Common Issues

One common issue is that the backtrace may not include all frames if the function calls are optimized out by the compiler. To avoid this, you can compile your code with debugging symbols turned on.

Integration

print_backtrace_fileline can be used in conjunction with other gdb commands to provide additional information. For example, you can use the info line command to display the source code for the specified file and line number:

(gdb) info line /home/user/project/src/foo.cpp:12

12    void foo() {

Related Commands

  • backtrace – Prints a backtrace without file and line numbers.
  • info line – Displays the source code for the specified file and line number.