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