]>
git.saurik.com Git - apple/xnu.git/blob - tools/lldbmacros/turnstile.py
7 @lldb_type_summary(['struct turnstile *'])
8 @header("{0: <20s} {1: <5s} {2: <20s} {3: <8s} {4: <8s} {5: <23s} {6: <20s} {7: <16s} {8: <20s} {9: <20s}".format("turnstile", "pri", "waitq", "type", "state", "inheritor", "proprietor", "gen count", "thread", "prev_thread"))
9 def GetTurnstileSummary(turnstile
):
10 """ Summarizes the turnstile
11 params: turnstile = value of the object of type struct turnstile *
12 returns: String with summary of the type.
15 type_and_gencount
= Cast(addressof(turnstile
.ts_type_gencount
), 'union turnstile_type_gencount *')
18 if type_and_gencount
.ts_type
== 0:
19 turnstile_type
= "none "
20 elif type_and_gencount
.ts_type
== 1:
21 turnstile_type
= "knl_mtx"
22 elif type_and_gencount
.ts_type
== 2:
23 turnstile_type
= "ulock "
24 elif type_and_gencount
.ts_type
== 3:
25 turnstile_type
= "pth_mtx"
26 elif type_and_gencount
.ts_type
== 4:
27 turnstile_type
= "syn_ipc"
28 elif type_and_gencount
.ts_type
== 5:
29 turnstile_type
= "kqwl "
30 elif type_and_gencount
.ts_type
== 6:
31 turnstile_type
= "workq "
32 elif type_and_gencount
.ts_type
== 7:
33 turnstile_type
= "knote "
36 if turnstile
.ts_state
& 0x1:
37 turnstile_state
+= "T"
38 elif turnstile
.ts_state
& 0x2:
39 turnstile_state
+= "F"
40 elif turnstile
.ts_state
& 0x4:
41 turnstile_state
+= "H"
42 elif turnstile
.ts_state
& 0x8:
43 turnstile_state
+= "P"
45 if turnstile
.ts_inheritor_flags
& 0x4:
47 elif turnstile
.ts_inheritor_flags
& 0x8:
49 elif turnstile
.ts_inheritor_flags
& 0x40:
54 format_str
= "{0: <#020x} {1: <5d} {2: <#020x} {3: <8s} {4: <8s} {6: <2s}:{5: <#020x} {7: <#020x} {8: <16d}"
55 out_string
= format_str
.format(turnstile
, turnstile
.ts_priority
, addressof(turnstile
.ts_waitq
),
56 turnstile_type
, turnstile_state
, turnstile
.ts_inheritor
, inheritor_type
,
57 turnstile
.ts_proprietor
, type_and_gencount
.ts_gencount
)
60 format_str
= " {0: <#020x} {1: <#020x}"
61 if hasattr(turnstile
, 'ts_thread'):
62 out_string
+= format_str
.format(turnstile
.ts_thread
, turnstile
.ts_prev_thread
)
66 def PrintTurnstile(turnstile
):
67 """ print turnstile and it's free list.
69 turnstile - turnstile to print
71 print GetTurnstileSummary(turnstile
)
73 """ print turnstile freelist if its not on a thread or freelist """
74 if turnstile
.ts_state
& 0x3 == 0:
76 for free_turnstile
in IterateListEntry(turnstile
.ts_free_turnstiles
, 'struct turnstile *', 'ts_free_elm', 's'):
78 print " Turnstile free List"
79 header_str
= " " + GetTurnstileSummary
.header
82 print " " + GetTurnstileSummary(free_turnstile
)
86 # Macro: showturnstile
87 @lldb_command('showturnstile')
88 def ShowTurnstile(cmd_args
=None, cmd_options
={}):
89 """ show the turnstile and all free turnstiles hanging off the turnstile.
90 Usage: (lldb)showturnstile <struct turnstile *>
93 raise ArgumentError("Please provide arguments")
95 turnstile
= kern
.GetValueFromAddress(cmd_args
[0], 'struct turnstile *')
96 print GetTurnstileSummary
.header
97 PrintTurnstile(turnstile
)
99 # EndMacro: showturnstile
101 @lldb_command('showturnstilehashtable')
102 def ShowTurnstileHashTable(cmd_args
=None, cmd_options
={}):
103 """ show the global hash table for turnstiles.
104 Usage: (lldb)showturnstilehashtable
106 print GetTurnstileSummary
.header
107 turnstile_htable_buckets
= kern
.globals.ts_htable_buckets
108 for index
in range(0, turnstile_htable_buckets
):
109 turnstile_bucket
= GetObjectAtIndexFromArray(kern
.globals.turnstile_htable
, index
)
110 for turnstile
in IterateQueue(turnstile_bucket
.ts_ht_bucket_list
, 'struct turnstile *', 'ts_htable_link'):
111 PrintTurnstile(turnstile
)
115 # Macro: showallturnstiles
116 @lldb_command('showallturnstiles')
117 def ShowAllTurnstiles(cmd_args
=None, cmd_options
={}):
118 """ A DEVELOPMENT macro that walks the list of all allocated turnstile objects
120 usage: (lldb) showallturnstiles
122 if not hasattr(kern
.globals, 'turnstiles_list'):
123 print "It seems you are running a build of kernel that does not have the list of all turnstiles."
125 print GetTurnstileSummary
.header
126 for turnstile
in IterateQueue(kern
.globals.turnstiles_list
, 'struct turnstile *', 'ts_global_elm'):
127 PrintTurnstile(turnstile
)
129 # EndMacro showallturnstiles
131 # Macro: showallbusyturnstiles
132 @lldb_command('showallbusyturnstiles')
133 def ShowAllTurnstiles(cmd_args
=None, cmd_options
={}):
134 """ A DEVELOPMENT macro that walks the list of all allocated turnstile objects
136 usage: (lldb) showallbusyturnstiles
138 if not hasattr(kern
.globals, 'turnstiles_list'):
139 print "It seems you are running a build of kernel that does not have the list of all turnstiles."
141 print GetTurnstileSummary
.header
142 for turnstile
in IterateQueue(kern
.globals.turnstiles_list
, 'struct turnstile *', 'ts_global_elm'):
143 if turnstile
.ts_state
& 0x3 == 0:
144 PrintTurnstile(turnstile
)
146 # EndMacro showallbusyturnstiles