@@ -123,9 +123,9 @@ def _addr_info(prog: Program, addr: int):
123
123
def get_mutex_lock_info (
124
124
prog : Program ,
125
125
stack : bool ,
126
+ graph : DependencyGraph ,
126
127
time : Optional [int ] = None ,
127
128
pid : Optional [int ] = None ,
128
- graph : Optional [DependencyGraph ] = None ,
129
129
) -> None :
130
130
"""Scan for mutex and show details"""
131
131
wtask = None
@@ -158,11 +158,10 @@ def get_mutex_lock_info(
158
158
159
159
struct_owner = mutex_owner (prog , mutex )
160
160
index = 0
161
- if graph :
162
- graph .add_edge (
163
- DependencyGraph .Node .from_object (struct_owner ),
164
- DependencyGraph .Node .from_object (mutex ),
165
- )
161
+ graph .add_edge (
162
+ DependencyGraph .Node .from_object (struct_owner ),
163
+ DependencyGraph .Node .from_object (mutex ),
164
+ )
166
165
167
166
if pid is None :
168
167
if time is None :
@@ -173,19 +172,17 @@ def get_mutex_lock_info(
173
172
index = index + 1
174
173
175
174
if waittime > timens or timens == 0 :
176
- if graph :
177
- graph .add_edge (
178
- DependencyGraph .Node .from_object (mutex ),
179
- DependencyGraph .Node .from_object (waiter ),
180
- )
175
+ graph .add_edge (
176
+ DependencyGraph .Node .from_object (mutex ),
177
+ DependencyGraph .Node .from_object (waiter ),
178
+ )
181
179
else :
182
180
continue
183
181
else :
184
- if graph :
185
- graph .add_edge (
186
- DependencyGraph .Node .from_object (mutex ),
187
- DependencyGraph .Node .from_object (wtask ),
188
- )
182
+ graph .add_edge (
183
+ DependencyGraph .Node .from_object (mutex ),
184
+ DependencyGraph .Node .from_object (wtask ),
185
+ )
189
186
190
187
191
188
def scan_mutex_lock (
@@ -453,6 +450,29 @@ def scan_lock(
453
450
scan_rwsem_lock (prog , stack , time , pid )
454
451
455
452
453
+ def get_deadlock_info (
454
+ prog : Program ,
455
+ stack : bool ,
456
+ time : Optional [int ] = None ,
457
+ pid : Optional [int ] = None ,
458
+ ) -> None :
459
+ graph : DependencyGraph = DependencyGraph ()
460
+ get_mutex_lock_info (prog , stack , graph )
461
+ cycles = graph .detect_cycle ()
462
+ if not cycles :
463
+ print ("No cycle found" )
464
+ return
465
+
466
+ print ("Cycle Detected!!" )
467
+ cycle_count = 1
468
+ for cycle in cycles :
469
+ print (f"---- { cycle_count } ----" )
470
+ for node in cycle :
471
+ print (f"[{ node .name } (0x{ node .address :x} )]" , end = " -> " )
472
+ print ("" )
473
+ cycle_count += 1
474
+
475
+
456
476
class Locking (CorelensModule ):
457
477
"""Display active mutex and semaphores and their waiters"""
458
478
@@ -490,3 +510,4 @@ def run(self, prog: Program, args: argparse.Namespace) -> None:
490
510
print ("Dont filter with both time and PID" )
491
511
return
492
512
scan_lock (prog , args .stack , args .time , args .pid )
513
+ get_deadlock_info (prog , args .stack , args .time , args .pid )
0 commit comments