function::print_ubacktrace - Linux


Overview

function::print_ubacktrace is a powerful debugger tool that prints a concise representation of the current call stack, including function names, source file paths, and line numbers. It’s particularly useful for:

  • Debugging stack-based programs and analyzing the flow of execution.
  • Identifying the source of errors or crashes and tracing their root causes.
  • Understanding the call hierarchy and relationships between different components.

Syntax

function::print_ubacktrace [--nocolor]

Options/Flags

  • –nocolor (optional): Disables color output for a more compact representation.

Examples

Simple Usage:

function::print_ubacktrace

Colored Output:

function::print_ubacktrace

# [  0] /home/user/proj/main.cpp:15
# [  1] /usr/lib/libstdc++.so.6:0x40084e53b0
# [  2] /usr/lib/libstdc++.so.6:0x40084e43d0

Contextual Information:

function::print_ubacktrace --nocolor

call stack:

# 0  main                                                  /home/user/proj/main.cpp:15
# 1  std::_124 __cxxabiv1::__uncaught_exceptions           /usr/lib/libstdc++.so.6:0x40084e53b0
# 2  std::terminate                                        /usr/lib/libstdc++.so.6:0x40084e43d0
# 3  __gnu_cxx::new_allocator<std::pair<std::string, std::string> >::_M_destroy                   /usr/lib/libstdc++.so.6:0x40084e2e70
# 4  std::__1::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()  /usr/lib/libstdc++.so.6:0x40084e0020
# 5  std::_124 __cxxabiv1::__uncaught_exceptions           /usr/lib/libstdc++.so.6:0x40084e53b0
# 6  std::terminate                                        /usr/lib/libstdc++.so.6:0x40084e43d0

Common Issues

  • Missing Symbols: If a function name is not resolved, it may appear as a hexadecimal address. This can occur with optimized builds or when symbols are stripped from the executable.
  • Oversized Stacks: Very large stack traces can overwhelm the terminal window. Use the --nocolor option to reduce the output size or pipe the output to a paging tool like less.

Integration

function::print_ubacktrace can be integrated with other debugging tools to provide additional context:

  • GDB: Used as a complement to bt.
  • Valgrind: Can be combined with --track-origins=yes to display a detailed call stack with memory allocation information.

Related Commands

  • backtrace: Prints a backtrace in the traditional GDB format.
  • gdb: A full-featured debugger that provides stack traces and other analysis tools.