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