This directory contains a collection of gdb
scripts that we have found helpful. These scripts use the gdb extension Python API.
How to run the scripts
To run the scripts, fire up gdb
and load a script with source -v
. Example:
3 (gdb) source -v ./folly/experimental/gdb/deadlock.py
4 Type "deadlock" to detect deadlocks.
5 # At this point, any new commands defined in `deadlock.py` are available.
What does each script do?
Consider the following program that always deadlocks:
4 folly::Baton<> b1, b2, b3;
6 auto t1 = std::thread([&m1, &m2, &b1, &b2] {
7 std::lock_guard<std::mutex> g1(m1);
10 std::lock_guard<std::mutex> g2(m2);
13 auto t2 = std::thread([&m3, &m2, &b3, &b2] {
14 std::lock_guard<std::mutex> g2(m2);
17 std::lock_guard<std::mutex> g3(m3);
20 auto t3 = std::thread([&m3, &m1, &b3, &b1] {
21 std::lock_guard<std::mutex> g3(m3);
24 std::lock_guard<std::mutex> g1(m1);
The deadlock.py
script introduces a new deadlock
command that can help us identify the threads and mutexes involved with the deadlock.
3 (gdb) source -v ./folly/experimental/gdb/deadlock.py
4 Type "deadlock" to detect deadlocks.
7 Thread 2 (LWP 2174497) is waiting on mutex (0x00007ffcff42a4c0) held by Thread 3 (LWP 2174498)
8 Thread 3 (LWP 2174498) is waiting on mutex (0x00007ffcff42a4f0) held by Thread 4 (LWP 2174499)
9 Thread 4 (LWP 2174499) is waiting on mutex (0x00007ffcff42a490) held by Thread 2 (LWP 2174497)
NOTE: This script only works on Linux and requires debug symbols to be installed for the pthread
library.