function::stack - Linux


Overview

function::stack is a powerful utility for inspecting the stack trace of a running process. It provides a comprehensive view of the program’s execution flow, recent function calls, and memory usage. This command is invaluable for debugging, profiling, and understanding complex software behavior.

Syntax

function::stack [PID] [options]

Parameters:

  • PID: (Optional) Process ID of the target process. If omitted, the current process is inspected.

Options/Flags

  • -f, –full: Display the full stack, including internal functions.
  • -a, –all: Display all threads in the process.
  • -t, –threads: Display only thread information.
  • -s, –symbols: Resolve function names to symbols, providing more detailed information.
  • -o, –output=FILE: Save the stack trace to a specified file.
  • -v, –version: Display version information.
  • -h, –help: Display help information.

Examples

Simple usage:

function::stack

Inspect a specific process:

function::stack 1234

Display full stack with symbols:

function::stack -f -s

Save stack trace to a file:

function::stack -o stack.txt

Common Issues

  • Process not found: Ensure the specified PID is correct or running.
  • Permission denied: Make sure you have sufficient permissions to inspect the target process.
  • Stack overflow: The process’s stack may be too deep to display. Use -f to show the full stack.

Integration

Analyze stack with GDB:

gdb -ex "bt"

Create a flame graph from stack trace:

perf record -g
perf report -F function::stack

Related Commands

  • gdb – Debugger for analyzing and debugging running processes.
  • perf – Performance analyzer for profiling and optimizing software.
  • strace – Traces system calls made by a running process.