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