function::backtrace - Linux


Overview

function::backtrace captures the stack trace of the current function and provides a human-readable representation of it. It can be useful for debugging purposes, especially in complex applications with multiple function calls.

Syntax

function::backtrace [--demangle] [--as-tree] [--native]

Options/Flags

  • --demangle: Demangles symbol names for better readability.
  • --as-tree: Outputs the stack trace as a tree for easier visualization.
  • --native: Ignores JIT transformations (available only in certain contexts).

Examples

Simple Example

$ function::backtrace
# Traceback (most recent call first):
#   <function_name>
#   <function_name>
#   <function_name>

Output as a Tree

$ function::backtrace --as-tree
├─ <function_name>
│  ├─ <function_name>
│  └─ <function_name>
└─ <function_name>

Demangle Symbol Names

$ function::backtrace --demangle
# Traceback (most recent call first):
#   main
#   function_name
#   function_name

Common Issues

  • Mismatched Stack Trace: If the stack trace is incomplete or incorrect, ensure you are using the correct executable or binary.

  • JIT Transformations: In certain environments, JIT transformations may alter the stack trace. Use --native to ignore these.

Integration

function::backtrace can be integrated with other commands for more advanced debugging:

# Print the stack trace and output it to a file
function::backtrace --as-tree > stack_trace.txt

# Use grep to filter the stack trace for specific keywords
function::backtrace | grep "function_name"

Related Commands

  • gdb: A graphical debugger for C++ and other languages.
  • lldb: A debugger for LLVM-based languages.
  • strace: Traces system calls and signals.