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