This Python C extension provides stack unwinding capabilities using three different methods:
- GNU Backtrace
- libunwind
- libdw (DWARF debug info)
-
get_stack_gnu()
: Stack unwinding using GNU's backtrace functions -
get_stack_unwind()
: Stack unwinding using libunwind -
get_stack_dwarf()
: Stack unwinding using libdw
The following libraries are required to build the extension:
- libunwind
- libdw
- libelf
- Python development headers
On Debian/Ubuntu:
sudo apt-get install python3-dev libunwind-dev libdw-dev libelf-dev
On Fedora/RHEL:
sudo dnf install python3-devel libunwind-devel elfutils-devel
On Arch Linux:
sudo pacman -S python libunwind elfutils
- Clone this repository:
git clone <repository-url>
cd python-stack-unwinder
- Build the extension:
python setup.py build_ext --inplace
import stackunwind
# Get stack trace using GNU backtrace
stack = stackunwind.get_stack_gnu()
print("GNU Backtrace:")
for frame in stack:
print(f" {frame}")
# Get stack trace using libunwind
stack = stackunwind.get_stack_unwind()
print("\nlibunwind:")
for frame in stack:
print(f" {frame}")
# Get stack trace using libdw
stack = stackunwind.get_stack_dwarf()
print("\nlibdw:")
for frame in stack:
print(f" {frame}")