]> git.saurik.com Git - apple/xnu.git/blob - tools/lldbmacros/turnstile.py
xnu-4903.231.4.tar.gz
[apple/xnu.git] / tools / lldbmacros / turnstile.py
1 from xnu import *
2 import sys, shlex
3 from utils import *
4 from waitq import *
5 import xnudefines
6
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.
13 """
14
15 type_and_gencount = Cast(addressof(turnstile.ts_type_gencount), 'union turnstile_type_gencount *')
16 turnstile_type = ""
17
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 "
34
35 turnstile_state = ""
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"
44
45 if turnstile.ts_inheritor_flags & 0x4:
46 inheritor_type = "th"
47 elif turnstile.ts_inheritor_flags & 0x8:
48 inheritor_type = "ts"
49 elif turnstile.ts_inheritor_flags & 0x40:
50 inheritor_type = "wq"
51 else:
52 inheritor_type = "--"
53
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)
58
59 #if DEVELOPMENT
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)
63 #endif
64 return out_string
65
66 def PrintTurnstile(turnstile):
67 """ print turnstile and it's free list.
68 params:
69 turnstile - turnstile to print
70 """
71 print GetTurnstileSummary(turnstile)
72
73 """ print turnstile freelist if its not on a thread or freelist """
74 if turnstile.ts_state & 0x3 == 0:
75 needsHeader = True
76 for free_turnstile in IterateListEntry(turnstile.ts_free_turnstiles, 'struct turnstile *', 'ts_free_elm', 's'):
77 if needsHeader:
78 print " Turnstile free List"
79 header_str = " " + GetTurnstileSummary.header
80 print header_str
81 needsHeader = False
82 print " " + GetTurnstileSummary(free_turnstile)
83 print ""
84 return
85
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 *>
91 """
92 if not cmd_args:
93 raise ArgumentError("Please provide arguments")
94
95 turnstile = kern.GetValueFromAddress(cmd_args[0], 'struct turnstile *')
96 print GetTurnstileSummary.header
97 PrintTurnstile(turnstile)
98 return
99 # EndMacro: showturnstile
100
101 @lldb_command('showturnstilehashtable')
102 def ShowTurnstileHashTable(cmd_args=None, cmd_options={}):
103 """ show the global hash table for turnstiles.
104 Usage: (lldb)showturnstilehashtable
105 """
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)
112 return True
113
114 #if DEVELOPMENT
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
119 and prints them.
120 usage: (lldb) showallturnstiles
121 """
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."
124 return False
125 print GetTurnstileSummary.header
126 for turnstile in IterateQueue(kern.globals.turnstiles_list, 'struct turnstile *', 'ts_global_elm'):
127 PrintTurnstile(turnstile)
128 return True
129 # EndMacro showallturnstiles
130
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
135 and prints them.
136 usage: (lldb) showallbusyturnstiles
137 """
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."
140 return False
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)
145 return True
146 # EndMacro showallbusyturnstiles
147 #endif