All Projects → DamZiobro → gdb-automatic-deadlock-detector

DamZiobro / gdb-automatic-deadlock-detector

Licence: MIT license
Script adds new command to GDB which allows automatically detect C/C++ thread locking and deadlocks in GDB debugger

Programming Languages

python
139335 projects - #7 most used programming language
c
50402 projects - #5 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to gdb-automatic-deadlock-detector

gdb-dashboard
Modular visual interface for GDB in Python
Stars: ✭ 8,699 (+14398.33%)
Mutual labels:  gdb, gdb-commands
gdb 2 root
This python script adds some usefull command to stripped vmlinux image
Stars: ✭ 20 (-66.67%)
Mutual labels:  gdb, gdb-commands
stack-inspector
A gdb command to inspect the size of objects on the stack
Stars: ✭ 57 (-5%)
Mutual labels:  gdb, gdb-commands
asm2cfg
Python command-line tool and GDB extension to view and save x86, ARM and objdump assembly files as control-flow graph (CFG) pdf files
Stars: ✭ 42 (-30%)
Mutual labels:  gdb
youtube-dl-nas
youtube download queue websocket server with login for private NAS.
Stars: ✭ 136 (+126.67%)
Mutual labels:  thread
QmlThread
More powerful Thread module in QML.
Stars: ✭ 31 (-48.33%)
Mutual labels:  thread
TheVimIDE
Modern Vim IDE with support for C/C++, Java, Python, Lua, PHP, JavaScript, Ruby and much more ...
Stars: ✭ 33 (-45%)
Mutual labels:  gdb
simpledbm
SimpleDBM is an Open Source Multi-Threaded Embeddable Transactional Database Engine in Java.
Stars: ✭ 51 (-15%)
Mutual labels:  deadlock-detection
hpc
Learning and practice of high performance computing (CUDA, Vulkan, OpenCL, OpenMP, TBB, SSE/AVX, NEON, MPI, coroutines, etc. )
Stars: ✭ 39 (-35%)
Mutual labels:  thread
threadproxy.nim
Simplify Nim Inter-Thread Communication
Stars: ✭ 23 (-61.67%)
Mutual labels:  thread
concurrent-programming-for-java
🚀Java并发编程实战
Stars: ✭ 55 (-8.33%)
Mutual labels:  thread
jstackSeries.sh
Script for capturing a series of thread dumps from a Java process using jstack (on Linux and Windows)
Stars: ✭ 28 (-53.33%)
Mutual labels:  thread
raspberry-pi
Raspberry Pi distribution of Alpha
Stars: ✭ 39 (-35%)
Mutual labels:  gdb
gdb-cheatsheet
GDB cheatsheet for reversing binaries
Stars: ✭ 20 (-66.67%)
Mutual labels:  gdb
hello-world-gdb
Simple hello world program for debugging with gdb
Stars: ✭ 29 (-51.67%)
Mutual labels:  gdb
Thread
type safe multi-threading made easier
Stars: ✭ 34 (-43.33%)
Mutual labels:  thread
YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (+221.67%)
Mutual labels:  thread
openthread-mqttsn
This repository contains examples using MQTT-SN client implementation for Thread network based on OpenThread SDK.
Stars: ✭ 22 (-63.33%)
Mutual labels:  thread
CVIP
C/C++/Golang/Linux...知识整理
Stars: ✭ 62 (+3.33%)
Mutual labels:  gdb
OverRide
Binary Exploitation and Reverse-Engineering (from assembly into C)
Stars: ✭ 69 (+15%)
Mutual labels:  gdb

gdb-automatic-deadlock-detector

Script adds new GDB command which automatically detects C/C++ thread lockups and deadlocks in GDB debugger.

It automates process of deadlock detection described in this instruction: https://en.wikibooks.org/wiki/Linux_Applications_Debugging_Techniques/Deadlocks

Automation is written as GDB Python script based on Python GBD API: https://sourceware.org/gdb/onlinedocs/gdb/Python-API.html

This script adds new 'blocked' command to GDB. 'blocked' command shows which threads are blocking other threads (or are deadlocked each other) ex.

(gdb) blocked
********************************************************************************
Displaying blocking threads using 'blocked' command
Thread: 7960 waits for thread: 7959 AND DEADLOCKED
Thread: 7959 waits for thread: 7960 AND DEADLOCKED
********************************************************************************

It means that thread 7960 waits for mutex holded by thread 7959 AND thread 7959 waits for mutex holded by thread 7960 - so threas 7959 and 7960 are deadlocked

Preparing sample deadlocked app

  1. Compile sample application containing thread deadlock.
gcc -pthread deadlockExample.c -o deadlockExample
  1. Make sure that your Linux OS can dump core files from the processes. Set it up by:
ulimit -c unlimited
  1. Run compiled application
./deadlockExample
  1. Notice that this application stucks (because of deadlock). Run another terminal and send SIGABRT signal (signal nr 6) to the running app:
kill -6 $(pidof deadlockExample)
  1. You should have core file outputed to your PWD dir.
  2. Also you need to have your GDB compiled with Python support. Check whether you can run 'python' command in your GDB. If not the recompile your GDB using this instruction: https://askubuntu.com/questions/513626/cannot-compile-gdb7-8-with-python-support

Usage

  1. See content of the 'gdbcommands' file - it contains commands wilchi will be invoked in GDB to run this to detect deadlock automatically (notice import our Python script gdbDisplayLockedThreads and invoking 'blocked' command):
python 
import sys
sys.path.append('.')
import gdbDisplayLockedThreads
end 
thread apply all bt 
blocked
  1. Run gdb and invoke commands from 'gdbcommands' file automatically:
gdb -c core ./deadlockExample -x ./gdbcommands -batch
  1. Output shows all backtraces of threads from deadlockExample followed by additional info of which threads are waiting for mutexes holding by other threads ex.
Thread 3 (Thread 0x7efc4958f700 (LWP 7960))
  #0 __lll_lock_wait () at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:135
  #1 0x00007efc4a164cfd in __GI___pthread_mutex_lock (mutex=0x601300 <write_mutex>) at ../nptl/pthread_mutex_lock.c:80
  #2 0x0000000000400aae in readTest ()
  #3 0x00007efc4a1626aa in start_thread (arg=0x7efc4958f700) at pthread_create.c:333
  #4 0x00007efc49e97eed in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

Thread 2 (Thread 0x7efc49d90700 (LWP 7959)):
  #0 __lll_lock_wait () at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:135
  #1 0x00007efc4a164cfd in __GI___pthread_mutex_lock (mutex=0x6012c0 <read_mutex>) at ../nptl/pthread_mutex_lock.c:80
  #2 0x0000000000400a00 in writeTest ()
  #3 0x00007efc4a1626aa in start_thread (arg=0x7efc49d90700) at pthread_create.c:333
  #4 0x00007efc49e97eed in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
 
Thread 1 (Thread 0x7efc4a564700 (LWP 7958)):
  #0 0x00007efc4a1638ed in pthread_join (threadid=139622035818960, thread_return=0x0) at pthread_join.c:90
  #1 0x0000000000400b95 in main ()

********************************************************************************
Displaying blocking threads using 'blocked' command
Thread: 7960 waits for thread: 7959 AND DEADLOCKED
Thread: 7959 waits for thread: 7960 AND DEADLOCKED
********************************************************************************

It means that thread 7960 waits for mutex holded by thread 7959 AND thread 7959 waits for mutex holded by thread 7960 - so threas 7959 and 7960 are deadlocked

  1. Now you can detect deadlock for any core using this quick gdb command from point 2 or 'blocked' command from gdb.

Enjoy your deadlock detections !

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].