1from __future__ import absolute_import, print_function 2 3from builtins import range 4 5from xnu import * 6from scheduler import GetRecentTimestamp 7import xnudefines 8 9ulock_types = { 10 1: "COMPARE_AND_WAIT", 11 2: "UNFAIR_LOCK", 12 3: "UNFAIR_LOCK64_SHARED", 13 4: "COMPARE_AND_WAIT64", 14 5: "COMPARE_AND_WAIT64_SHARED" 15} 16 17@header("{:<20s} {:<20s} {:<20s} {:<10s} {:<20s} {:<20s} {:<20s}".format( 18 'ull_t', 'kind', 'addr/obj', 'pid/offs', 'owner', 'turnstile', 'waiters')) 19def GetUlockSummary(ull): 20 code = int(ull.ull_opcode) 21 if code in ulock_types: 22 ull_type = ulock_types[code] 23 else: 24 ull_type = "{:#x}".format(code) 25 26 s = "{ull: <#20x} {ull_type: <20s}".format(ull=ull, ull_type=ull_type) 27 ulk=ull.ull_key 28 if int(ulk.ulk_key_type) == 1: 29 s += " {ulk.ulk_addr: <#20x} {ulk.ulk_pid: <10d}".format(ulk=ulk) 30 elif int(ulk.ulk_key_type) == 2: 31 s += " {ulk.ulk_object: <#20x} {ulk.ulk_offset: <10d}".format(ulk=ulk) 32 else: 33 s += " {:<20s} {:<10s}".format("", "") 34 35 return s + " {ull.ull_owner: <#20x} {ull.ull_turnstile: <#20x} {ull.ull_nwaiters: >7d}".format(ull=ull) 36 37@lldb_command('showallulocks', fancy=True) 38def ShowAllUlocks(cmd_args=None, cmd_options={}, O=None): 39 """ Display a summary of all the ulocks in the system 40 41 usage: showallulocks 42 """ 43 44 with O.table(GetUlockSummary.header): 45 count = kern.globals.ull_hash_buckets; 46 buckets = kern.globals.ull_bucket 47 for i in range(0, count): 48 for ull in IterateLinkageChain(addressof(buckets[i].ulb_head), 'ull_t *', 'ull_hash_link'): 49 print(GetUlockSummary(ull)) 50