]>
Commit | Line | Data |
---|---|---|
3e170ce0 A |
1 | #!/usr/bin/env python |
2 | import sys | |
3 | import struct | |
4 | import mmap | |
5 | import json | |
6 | import cgitb | |
7 | import copy | |
8 | import re | |
9 | import base64 | |
10 | import argparse | |
11 | import os | |
12 | import shlex | |
13 | import subprocess | |
39037602 A |
14 | import logging |
15 | import contextlib | |
16 | import base64 | |
f427ee49 | 17 | import zlib |
3e170ce0 | 18 | |
c3c9b80d A |
19 | # can be removed once we move to Python3.1+ |
20 | from future.utils.surrogateescape import register_surrogateescape | |
21 | register_surrogateescape() | |
22 | ||
5ba3f43e A |
23 | class Globals(object): |
24 | pass | |
25 | G = Globals() | |
26 | G.accept_incomplete_data = False | |
27 | G.data_was_incomplete = False | |
28 | ||
3e170ce0 A |
29 | kcdata_type_def = { |
30 | 'KCDATA_TYPE_INVALID': 0x0, | |
31 | 'KCDATA_TYPE_STRING_DESC': 0x1, | |
32 | 'KCDATA_TYPE_UINT32_DESC': 0x2, | |
33 | 'KCDATA_TYPE_UINT64_DESC': 0x3, | |
34 | 'KCDATA_TYPE_INT32_DESC': 0x4, | |
35 | 'KCDATA_TYPE_INT64_DESC': 0x5, | |
36 | 'KCDATA_TYPE_BINDATA_DESC': 0x6, | |
37 | 'KCDATA_TYPE_ARRAY': 0x11, | |
d9a64523 | 38 | 'KCDATA_TYPE_TYPEDEFINITION': 0x12, |
3e170ce0 | 39 | 'KCDATA_TYPE_CONTAINER_BEGIN': 0x13, |
d9a64523 | 40 | 'KCDATA_TYPE_CONTAINER_END': 0x14, |
39037602 A |
41 | |
42 | 'KCDATA_TYPE_ARRAY_PAD0': 0x20, | |
43 | 'KCDATA_TYPE_ARRAY_PAD1': 0x21, | |
44 | 'KCDATA_TYPE_ARRAY_PAD2': 0x22, | |
45 | 'KCDATA_TYPE_ARRAY_PAD3': 0x23, | |
46 | 'KCDATA_TYPE_ARRAY_PAD4': 0x24, | |
47 | 'KCDATA_TYPE_ARRAY_PAD5': 0x25, | |
48 | 'KCDATA_TYPE_ARRAY_PAD6': 0x26, | |
49 | 'KCDATA_TYPE_ARRAY_PAD7': 0x27, | |
50 | 'KCDATA_TYPE_ARRAY_PAD8': 0x28, | |
51 | 'KCDATA_TYPE_ARRAY_PAD9': 0x29, | |
52 | 'KCDATA_TYPE_ARRAY_PADa': 0x2a, | |
53 | 'KCDATA_TYPE_ARRAY_PADb': 0x2b, | |
54 | 'KCDATA_TYPE_ARRAY_PADc': 0x2c, | |
55 | 'KCDATA_TYPE_ARRAY_PADd': 0x2d, | |
56 | 'KCDATA_TYPE_ARRAY_PADe': 0x2e, | |
57 | 'KCDATA_TYPE_ARRAY_PADf': 0x2f, | |
58 | ||
3e170ce0 A |
59 | 'KCDATA_TYPE_LIBRARY_LOADINFO': 0x30, |
60 | 'KCDATA_TYPE_LIBRARY_LOADINFO64': 0x31, | |
61 | 'KCDATA_TYPE_TIMEBASE': 0x32, | |
39037602 | 62 | 'KCDATA_TYPE_MACH_ABSOLUTE_TIME': 0x33, |
3e170ce0 A |
63 | 'KCDATA_TYPE_TIMEVAL': 0x34, |
64 | 'KCDATA_TYPE_USECS_SINCE_EPOCH': 0x35, | |
39037602 A |
65 | 'KCDATA_TYPE_PID': 0x36, |
66 | 'KCDATA_TYPE_PROCNAME': 0x37, | |
67 | 'KCDATA_TYPE_NESTED_KCDATA': 0x38, | |
68 | ||
3e170ce0 A |
69 | 'STACKSHOT_KCCONTAINER_TASK': 0x903, |
70 | 'STACKSHOT_KCCONTAINER_THREAD': 0x904, | |
39037602 A |
71 | 'STACKSHOT_KCTYPE_DONATING_PIDS': 0x907, |
72 | 'STACKSHOT_KCTYPE_SHAREDCACHE_LOADINFO': 0x908, | |
cb323159 | 73 | 'STACKSHOT_KCTYPE_THREAD_NAME': 0x909, |
3e170ce0 A |
74 | 'STACKSHOT_KCTYPE_KERN_STACKFRAME': 0x90A, |
75 | 'STACKSHOT_KCTYPE_KERN_STACKFRAME64': 0x90B, | |
76 | 'STACKSHOT_KCTYPE_USER_STACKFRAME': 0x90C, | |
77 | 'STACKSHOT_KCTYPE_USER_STACKFRAME64': 0x90D, | |
78 | 'STACKSHOT_KCTYPE_BOOTARGS': 0x90E, | |
79 | 'STACKSHOT_KCTYPE_OSVERSION': 0x90F, | |
80 | 'STACKSHOT_KCTYPE_KERN_PAGE_SIZE': 0x910, | |
81 | 'STACKSHOT_KCTYPE_JETSAM_LEVEL': 0x911, | |
39037602 | 82 | 'STACKSHOT_KCTYPE_DELTA_SINCE_TIMESTAMP': 0x912, |
39037602 A |
83 | 'STACKSHOT_KCTYPE_KERN_STACKLR': 0x913, |
84 | 'STACKSHOT_KCTYPE_KERN_STACKLR64': 0x914, | |
85 | 'STACKSHOT_KCTYPE_USER_STACKLR': 0x915, | |
86 | 'STACKSHOT_KCTYPE_USER_STACKLR64': 0x916, | |
87 | 'STACKSHOT_KCTYPE_NONRUNNABLE_TIDS': 0x917, | |
88 | 'STACKSHOT_KCTYPE_NONRUNNABLE_TASKS': 0x918, | |
89 | 'STACKSHOT_KCTYPE_CPU_TIMES': 0x919, | |
90 | 'STACKSHOT_KCTYPE_STACKSHOT_DURATION': 0x91a, | |
91 | 'STACKSHOT_KCTYPE_STACKSHOT_FAULT_STATS': 0x91b, | |
92 | 'STACKSHOT_KCTYPE_KERNELCACHE_LOADINFO': 0x91c, | |
813fb2f6 | 93 | 'STACKSHOT_KCTYPE_THREAD_WAITINFO' : 0x91d, |
5ba3f43e A |
94 | 'STACKSHOT_KCTYPE_THREAD_GROUP_SNAPSHOT' : 0x91e, |
95 | 'STACKSHOT_KCTYPE_THREAD_GROUP' : 0x91f, | |
96 | 'STACKSHOT_KCTYPE_JETSAM_COALITION_SNAPSHOT' : 0x920, | |
97 | 'STACKSHOT_KCTYPE_JETSAM_COALITION' : 0x921, | |
d9a64523 | 98 | 'STACKSHOT_KCTYPE_THREAD_POLICY_VERSION': 0x922, |
5ba3f43e | 99 | 'STACKSHOT_KCTYPE_INSTRS_CYCLES' : 0x923, |
d9a64523 A |
100 | 'STACKSHOT_KCTYPE_USER_STACKTOP' : 0x924, |
101 | 'STACKSHOT_KCTYPE_ASID' : 0x925, | |
102 | 'STACKSHOT_KCTYPE_PAGE_TABLES' : 0x926, | |
103 | 'STACKSHOT_KCTYPE_SYS_SHAREDCACHE_LAYOUT' : 0x927, | |
cb323159 A |
104 | 'STACKSHOT_KCTYPE_THREAD_DISPATCH_QUEUE_LABEL' : 0x928, |
105 | 'STACKSHOT_KCTYPE_THREAD_TURNSTILEINFO' : 0x929, | |
f427ee49 A |
106 | 'STACKSHOT_KCTYPE_TASK_CPU_ARCHITECTURE' : 0x92a, |
107 | 'STACKSHOT_KCTYPE_LATENCY_INFO' : 0x92b, | |
108 | 'STACKSHOT_KCTYPE_LATENCY_INFO_TASK' : 0x92c, | |
109 | 'STACKSHOT_KCTYPE_LATENCY_INFO_THREAD' : 0x92d, | |
110 | 'STACKSHOT_KCTYPE_LOADINFO64_TEXT_EXEC' : 0x92e, | |
d9a64523 A |
111 | |
112 | 'STACKSHOT_KCTYPE_TASK_DELTA_SNAPSHOT': 0x940, | |
113 | 'STACKSHOT_KCTYPE_THREAD_DELTA_SNAPSHOT': 0x941, | |
5ba3f43e | 114 | |
5ba3f43e | 115 | |
39037602 | 116 | |
3e170ce0 A |
117 | 'KCDATA_TYPE_BUFFER_END': 0xF19158ED, |
118 | ||
119 | ||
120 | 'TASK_CRASHINFO_EXTMODINFO': 0x801, | |
121 | 'TASK_CRASHINFO_BSDINFOWITHUNIQID': 0x802, | |
122 | 'TASK_CRASHINFO_TASKDYLD_INFO': 0x803, | |
123 | 'TASK_CRASHINFO_UUID': 0x804, | |
124 | 'TASK_CRASHINFO_PID': 0x805, | |
125 | 'TASK_CRASHINFO_PPID': 0x806, | |
39037602 A |
126 | |
127 | # Don't want anyone using this. It's struct rusage from whatever machine generated the data | |
128 | #'TASK_CRASHINFO_RUSAGE': 0x807, | |
129 | 'Type_0x807': 0x807, | |
130 | ||
3e170ce0 A |
131 | 'TASK_CRASHINFO_RUSAGE_INFO': 0x808, |
132 | 'TASK_CRASHINFO_PROC_NAME': 0x809, | |
133 | 'TASK_CRASHINFO_PROC_STARTTIME': 0x80B, | |
134 | 'TASK_CRASHINFO_USERSTACK': 0x80C, | |
135 | 'TASK_CRASHINFO_ARGSLEN': 0x80D, | |
136 | 'TASK_CRASHINFO_EXCEPTION_CODES': 0x80E, | |
137 | 'TASK_CRASHINFO_PROC_PATH': 0x80F, | |
138 | 'TASK_CRASHINFO_PROC_CSFLAGS': 0x810, | |
139 | 'TASK_CRASHINFO_PROC_STATUS': 0x811, | |
140 | 'TASK_CRASHINFO_UID': 0x812, | |
141 | 'TASK_CRASHINFO_GID': 0x813, | |
142 | 'TASK_CRASHINFO_PROC_ARGC': 0x814, | |
143 | 'TASK_CRASHINFO_PROC_FLAGS': 0x815, | |
144 | 'TASK_CRASHINFO_CPUTYPE': 0x816, | |
145 | 'TASK_CRASHINFO_WORKQUEUEINFO': 0x817, | |
146 | 'TASK_CRASHINFO_RESPONSIBLE_PID': 0x818, | |
147 | 'TASK_CRASHINFO_DIRTY_FLAGS': 0x819, | |
148 | 'TASK_CRASHINFO_CRASHED_THREADID': 0x81A, | |
39037602 A |
149 | 'TASK_CRASHINFO_COALITION_ID': 0x81B, |
150 | 'EXIT_REASON_SNAPSHOT': 0x1001, | |
151 | 'EXIT_REASON_USER_DESC': 0x1002, | |
152 | 'EXIT_REASON_USER_PAYLOAD': 0x1003, | |
153 | 'EXIT_REASON_CODESIGNING_INFO': 0x1004, | |
5ba3f43e A |
154 | 'EXIT_REASON_WORKLOOP_ID': 0x1005, |
155 | 'EXIT_REASON_DISPATCH_QUEUE_NO': 0x1006, | |
39037602 A |
156 | 'KCDATA_BUFFER_BEGIN_CRASHINFO': 0xDEADF157, |
157 | 'KCDATA_BUFFER_BEGIN_DELTA_STACKSHOT': 0xDE17A59A, | |
158 | 'KCDATA_BUFFER_BEGIN_STACKSHOT': 0x59a25807, | |
f427ee49 | 159 | 'KCDATA_BUFFER_BEGIN_COMPRESSED': 0x434f4d50, |
39037602 A |
160 | 'KCDATA_BUFFER_BEGIN_OS_REASON': 0x53A20900, |
161 | 'KCDATA_BUFFER_BEGIN_XNUPOST_CONFIG': 0x1E21C09F | |
3e170ce0 A |
162 | } |
163 | kcdata_type_def_rev = dict((v, k) for k, v in kcdata_type_def.iteritems()) | |
164 | ||
165 | KNOWN_TYPES_COLLECTION = {} | |
166 | ||
39037602 | 167 | KNOWN_TOPLEVEL_CONTAINER_TYPES = () |
3e170ce0 A |
168 | |
169 | def enum(**args): | |
170 | return type('enum', (), args) | |
171 | ||
c3c9b80d A |
172 | # |
173 | # Decode bytes as UTF-8, using surrogateescape if there are invalid UTF-8 | |
174 | # sequences; see PEP-383 | |
175 | # | |
176 | def BytesToString(b): | |
177 | return b.decode('utf-8', errors="surrogateescape") | |
178 | ||
3e170ce0 A |
179 | KCSUBTYPE_TYPE = enum(KC_ST_CHAR=1, KC_ST_INT8=2, KC_ST_UINT8=3, KC_ST_INT16=4, KC_ST_UINT16=5, KC_ST_INT32=6, KC_ST_UINT32=7, KC_ST_INT64=8, KC_ST_UINT64=9) |
180 | ||
181 | ||
39037602 A |
182 | LEGAL_OLD_STYLE_ARRAY_TYPE_NAMES = ['KCDATA_TYPE_LIBRARY_LOADINFO', |
183 | 'KCDATA_TYPE_LIBRARY_LOADINFO64', | |
184 | 'STACKSHOT_KCTYPE_KERN_STACKFRAME', | |
185 | 'STACKSHOT_KCTYPE_USER_STACKFRAME', | |
186 | 'STACKSHOT_KCTYPE_KERN_STACKFRAME64', | |
187 | 'STACKSHOT_KCTYPE_USER_STACKFRAME64', | |
188 | 'STACKSHOT_KCTYPE_DONATING_PIDS', | |
189 | 'STACKSHOT_KCTYPE_THREAD_DELTA_SNAPSHOT'] | |
190 | ||
191 | KCDATA_FLAGS_STRUCT_PADDING_MASK = 0xf | |
192 | KCDATA_FLAGS_STRUCT_HAS_PADDING = 0x80 | |
193 | ||
3e170ce0 A |
194 | class KCSubTypeElement(object): |
195 | """convert kcdata_subtype_descriptor to """ | |
196 | _unpack_formats = (None, 'c', 'b', 'B', 'h', 'H', 'i', 'I', 'q', 'Q') | |
197 | _ctypes = ('Unknown', 'char', 'int8_t', 'uint8_t', 'int16_t', 'uint16_t', 'int32_t', 'uint32_t', 'int64_t', 'uint64_t') | |
198 | ||
199 | def __init__(self, st_name, st_type, st_size, st_offset=0, st_flag=0, custom_repr=None): | |
200 | self.name = st_name | |
201 | self.offset = st_offset | |
202 | self.type_id = st_type | |
203 | if st_type <= 0 or st_type > KCSUBTYPE_TYPE.KC_ST_UINT64: | |
204 | raise ValueError("Invalid type passed %d" % st_type) | |
205 | self.unpack_fmt = KCSubTypeElement._unpack_formats[self.type_id] | |
206 | self.size = st_size | |
207 | self.totalsize = st_size | |
208 | self.count = 1 | |
209 | self.is_array_type = False | |
210 | self.custom_JsonRepr = custom_repr | |
211 | if (st_flag & 0x1) == 0x1: | |
212 | self.is_array_type = True | |
213 | self.size = st_size & 0xffff | |
214 | self.count = (st_size >> 16) & 0xffff | |
215 | self.totalsize = self.size * self.count | |
216 | ||
217 | @staticmethod | |
218 | def GetSizeForArray(el_count, el_size): | |
219 | return ((el_count & 0xffff) << 16) | (el_size & 0xffff) | |
220 | ||
221 | @staticmethod | |
222 | def FromBinaryTypeData(byte_data): | |
223 | (st_flag, st_type, st_offset, st_size, st_name) = struct.unpack_from('=BBHI32s', byte_data) | |
c3c9b80d | 224 | st_name = BytesToString(st_name.rstrip('\0')) |
3e170ce0 A |
225 | return KCSubTypeElement(st_name, st_type, st_size, st_offset, st_flag) |
226 | ||
227 | @staticmethod | |
a39ff7e2 | 228 | def FromBasicCtype(st_name, st_type, st_offset=0, legacy_size=None): |
3e170ce0 A |
229 | if st_type <= 0 or st_type > KCSUBTYPE_TYPE.KC_ST_UINT64: |
230 | raise ValueError("Invalid type passed %d" % st_type) | |
231 | st_size = struct.calcsize(KCSubTypeElement._unpack_formats[st_type]) | |
232 | st_flag = 0 | |
233 | retval = KCSubTypeElement(st_name, st_type, st_size, st_offset, st_flag, KCSubTypeElement._get_naked_element_value) | |
a39ff7e2 A |
234 | if legacy_size: |
235 | retval.legacy_size = legacy_size | |
3e170ce0 A |
236 | return retval |
237 | ||
238 | @staticmethod | |
239 | def FromKCSubTypeElement(other, name_override=''): | |
240 | _copy = copy.copy(other) | |
241 | if name_override: | |
242 | _copy.name = name_override | |
243 | return copy | |
244 | ||
245 | def GetName(self): | |
246 | return self.name | |
247 | ||
248 | def GetTotalSize(self): | |
249 | return self.totalsize | |
250 | ||
251 | def GetValueAsString(self, base_data, array_pos=0): | |
c3c9b80d A |
252 | v = self.GetValue(base_data, array_pos) |
253 | if isinstance(v, bytes): | |
254 | return BytesToString(v) | |
255 | return str(v) | |
3e170ce0 A |
256 | |
257 | def GetValue(self, base_data, array_pos=0): | |
258 | return struct.unpack_from(self.unpack_fmt, base_data[self.offset + (array_pos * self.size):])[0] | |
259 | ||
260 | @staticmethod | |
261 | def _get_naked_element_value(elementValue, elementName): | |
262 | return json.dumps(elementValue) | |
263 | ||
264 | def __str__(self): | |
265 | if self.is_array_type: | |
266 | return '[%d,%d] %s %s[%d];' % (self.offset, self.totalsize, self.GetCTypeDesc(), self.name, self.count) | |
267 | return '[%d,%d] %s %s;' % (self.offset, self.totalsize, self.GetCTypeDesc(), self.name) | |
268 | ||
269 | def __repr__(self): | |
270 | return str(self) | |
271 | ||
272 | def GetCTypeDesc(self): | |
273 | return KCSubTypeElement._ctypes[self.type_id] | |
274 | ||
275 | def GetStringRepr(self, base_data): | |
276 | if not self.is_array_type: | |
277 | return self.GetValueAsString(base_data) | |
278 | if self.type_id == KCSUBTYPE_TYPE.KC_ST_CHAR: | |
279 | str_len = self.count | |
280 | if len(base_data) < str_len: | |
281 | str_len = len(base_data) | |
282 | str_arr = [] | |
283 | for i in range(str_len): | |
284 | _v = self.GetValue(base_data, i) | |
285 | if ord(_v) == 0: | |
286 | break | |
287 | str_arr.append(self.GetValueAsString(base_data, i)) | |
5ba3f43e | 288 | return json.dumps(''.join(str_arr)) |
39037602 A |
289 | |
290 | count = self.count | |
291 | if count > len(base_data)/self.size: | |
292 | count = len(base_data)/self.size | |
293 | ||
294 | o = '[' + ','.join([self.GetValueAsString(base_data, i) for i in range(count)]) + ']' | |
295 | ||
3e170ce0 A |
296 | return o |
297 | ||
39037602 A |
298 | def GetJsonRepr(self, base_data, flags=0): |
299 | if (flags & (KCDATA_FLAGS_STRUCT_HAS_PADDING | KCDATA_FLAGS_STRUCT_PADDING_MASK)) != 0: | |
300 | padding = (flags & KCDATA_FLAGS_STRUCT_PADDING_MASK) | |
301 | if padding: | |
302 | base_data = base_data[:-padding] | |
3e170ce0 A |
303 | if self.custom_JsonRepr: |
304 | if self.is_array_type: | |
305 | e_data = [self.GetValue(base_data, i) for i in range(self.count)] | |
306 | else: | |
307 | e_data = self.GetValue(base_data) | |
308 | return self.custom_JsonRepr(e_data, self.name) | |
309 | return self.GetStringRepr(base_data) | |
310 | ||
39037602 A |
311 | def sizeof(self): |
312 | return self.totalsize | |
313 | ||
314 | def ShouldSkip(self, data): | |
315 | return len(data) < self.offset + self.totalsize | |
316 | ||
317 | def ShouldMerge(self): | |
318 | return False | |
319 | ||
3e170ce0 A |
320 | |
321 | class KCTypeDescription(object): | |
d9a64523 | 322 | def __init__(self, t_type_id, t_elements=[], t_name='anon', custom_repr=None, legacy_size=None, merge=False, naked=False): |
3e170ce0 A |
323 | self.type_id = t_type_id |
324 | self.elements = t_elements | |
325 | self.name = t_name | |
326 | self.totalsize = 0 | |
327 | self.custom_JsonRepr = custom_repr | |
a39ff7e2 A |
328 | if legacy_size: |
329 | self.legacy_size = legacy_size | |
39037602 | 330 | self.merge = merge |
d9a64523 | 331 | self.naked = naked |
3e170ce0 A |
332 | for e in self.elements: |
333 | self.totalsize += e.GetTotalSize() | |
334 | ||
335 | def ValidateData(self, base_data): | |
336 | if len(base_data) >= self.totalsize: | |
337 | return True | |
338 | return False | |
339 | ||
340 | def GetTypeID(self): | |
341 | return self.type_id | |
342 | ||
343 | def GetName(self): | |
344 | return self.name | |
345 | ||
346 | def __str__(self): | |
347 | o = '%s {\n\t' % self.name + "\n\t".join([str(e) for e in self.elements]) + '\n};' | |
348 | return o | |
349 | ||
350 | @staticmethod | |
351 | def FromKCTypeDescription(other, t_type_id, t_name): | |
a39ff7e2 A |
352 | retval = KCTypeDescription(t_type_id, other.elements, t_name, other.custom_JsonRepr, |
353 | legacy_size=getattr(other, 'legacy_size', None)) | |
3e170ce0 A |
354 | return retval |
355 | ||
39037602 A |
356 | def ShouldMerge(self): |
357 | return self.merge | |
358 | ||
359 | def GetJsonRepr(self, base_data, flags): | |
360 | if (flags & (KCDATA_FLAGS_STRUCT_HAS_PADDING | KCDATA_FLAGS_STRUCT_PADDING_MASK)) != 0: | |
361 | padding = (flags & KCDATA_FLAGS_STRUCT_PADDING_MASK) | |
362 | if padding: | |
363 | base_data = base_data[:-padding] | |
a39ff7e2 | 364 | elif hasattr(self, 'legacy_size') and len(base_data) == self.legacy_size + ((-self.legacy_size) & 0xf): |
39037602 | 365 | base_data = base_data[:self.legacy_size] |
3e170ce0 A |
366 | if self.custom_JsonRepr: |
367 | return self.custom_JsonRepr([e.GetValue(base_data) for e in self.elements]) | |
d9a64523 A |
368 | if self.naked: |
369 | o = ", ".join([e.GetJsonRepr(base_data) for e in self.elements if not e.ShouldSkip(base_data)]) | |
370 | else: | |
371 | o = ", ".join(['"%s": %s' % (e.GetName(), e.GetJsonRepr(base_data)) for e in self.elements if not e.ShouldSkip(base_data)]) | |
39037602 A |
372 | if not self.merge: |
373 | o = '{' + o + '}' | |
3e170ce0 A |
374 | return o |
375 | ||
39037602 A |
376 | def sizeof(self): |
377 | return max(st.totalsize + st.offset for st in self.elements) | |
378 | ||
3e170ce0 A |
379 | |
380 | def GetTypeNameForKey(k): | |
381 | retval = "0x%x" % k | |
382 | if k in KNOWN_TYPES_COLLECTION: | |
383 | retval = KNOWN_TYPES_COLLECTION[k].GetName() | |
384 | elif k in kcdata_type_def_rev: | |
385 | retval = kcdata_type_def_rev[k] | |
386 | return retval | |
387 | ||
388 | ||
389 | def GetTypeForName(n): | |
390 | ret = 0 | |
391 | if n in kcdata_type_def: | |
392 | ret = kcdata_type_def[n] | |
393 | return ret | |
394 | ||
395 | ||
39037602 A |
396 | LEGAL_OLD_STYLE_ARRAY_TYPES = map(GetTypeForName, LEGAL_OLD_STYLE_ARRAY_TYPE_NAMES) |
397 | ||
398 | kcdata_type_def_rev[GetTypeForName('KCDATA_BUFFER_BEGIN_STACKSHOT')] = 'kcdata_stackshot' | |
399 | kcdata_type_def_rev[GetTypeForName('KCDATA_BUFFER_BEGIN_DELTA_STACKSHOT')] = 'kcdata_delta_stackshot' | |
400 | kcdata_type_def_rev[GetTypeForName('KCDATA_BUFFER_BEGIN_CRASHINFO')] = 'kcdata_crashinfo' | |
401 | kcdata_type_def_rev[GetTypeForName('KCDATA_BUFFER_BEGIN_OS_REASON')] = 'kcdata_reason' | |
402 | kcdata_type_def_rev[GetTypeForName('STACKSHOT_KCCONTAINER_TASK')] = 'task_snapshots' | |
403 | kcdata_type_def_rev[GetTypeForName('STACKSHOT_KCCONTAINER_THREAD')] = 'thread_snapshots' | |
404 | kcdata_type_def_rev[GetTypeForName('KCDATA_BUFFER_BEGIN_XNUPOST_CONFIG')] = 'xnupost_testconfig' | |
405 | ||
406 | class Indent(object): | |
407 | def __init__(self): | |
408 | self.n = 0 | |
409 | def __call__(self, end=False): | |
410 | if end: | |
411 | return " " * (self.n-4) | |
412 | else: | |
413 | return " " * self.n | |
414 | @contextlib.contextmanager | |
415 | def indent(self): | |
416 | self.n += 4 | |
417 | try: | |
418 | yield | |
419 | finally: | |
420 | self.n -= 4 | |
421 | ||
422 | INDENT = Indent() | |
423 | ||
3e170ce0 | 424 | class KCObject(object): |
39037602 A |
425 | |
426 | def __init__(self, type_code, data, offset, flags=0): | |
427 | ||
3e170ce0 A |
428 | self.i_type = type_code |
429 | self.i_data = data | |
39037602 | 430 | self.offset = offset |
3e170ce0 | 431 | self.i_size = len(data) |
3e170ce0 A |
432 | self.i_flags = flags |
433 | self.obj_collection = [] | |
434 | self.obj = {} | |
435 | self.is_container_type = False | |
436 | self.is_array_type = False | |
437 | self.is_naked_type = False | |
39037602 A |
438 | self.nested_kcdata = None |
439 | self.i_name = GetTypeNameForKey(type_code) | |
440 | ||
3e170ce0 A |
441 | self.ParseData() |
442 | ||
39037602 A |
443 | if self.i_type == GetTypeForName('KCDATA_TYPE_CONTAINER_BEGIN'): |
444 | self.__class__ = KCContainerObject | |
f427ee49 A |
445 | elif self.i_type == GetTypeForName('KCDATA_BUFFER_BEGIN_COMPRESSED'): |
446 | self.__class__ = KCCompressedBufferObject | |
447 | elif self.i_type in KNOWN_TOPLEVEL_CONTAINER_TYPES: | |
39037602 A |
448 | self.__class__ = KCBufferObject |
449 | ||
450 | self.InitAfterParse() | |
451 | ||
5ba3f43e A |
452 | def __str__(self): |
453 | return "<KCObject at 0x%x>" % self.offset | |
454 | ||
39037602 A |
455 | def InitAfterParse(self): |
456 | pass | |
457 | ||
3e170ce0 A |
458 | @staticmethod |
459 | def FromKCItem(kcitem): | |
39037602 | 460 | return KCObject(kcitem.i_type, kcitem.i_data, kcitem.i_offset, kcitem.i_flags) |
3e170ce0 A |
461 | |
462 | def IsContainerEnd(self): | |
d9a64523 | 463 | return self.i_type == GetTypeForName('KCDATA_TYPE_CONTAINER_END') |
39037602 A |
464 | |
465 | def IsBufferEnd(self): | |
466 | return self.i_type == GetTypeForName('KCDATA_TYPE_BUFFER_END') | |
467 | ||
468 | def IsArray(self): | |
469 | return self.is_array_type | |
470 | ||
471 | def ShouldMerge(self): | |
472 | if self.nested_kcdata: | |
3e170ce0 | 473 | return True |
39037602 A |
474 | elif not self.is_array_type and self.i_type in KNOWN_TYPES_COLLECTION: |
475 | return KNOWN_TYPES_COLLECTION[self.i_type].ShouldMerge() | |
476 | else: | |
477 | return False | |
3e170ce0 A |
478 | |
479 | def GetJsonRepr(self): | |
480 | if self.is_array_type: | |
481 | return '[' + ', '.join([i.GetJsonRepr() for i in self.obj_collection]) + ']' | |
3e170ce0 | 482 | if self.i_type in KNOWN_TYPES_COLLECTION: |
39037602 | 483 | return KNOWN_TYPES_COLLECTION[self.i_type].GetJsonRepr(self.i_data, self.i_flags) |
3e170ce0 A |
484 | if self.is_naked_type: |
485 | return json.dumps(self.obj) | |
39037602 A |
486 | if self.nested_kcdata: |
487 | return self.nested_kcdata.GetJsonRepr() | |
3e170ce0 A |
488 | |
489 | raise NotImplementedError("Broken GetJsonRepr implementation") | |
490 | ||
491 | def ParseData(self): | |
39037602 A |
492 | |
493 | ||
3e170ce0 | 494 | if self.i_type == GetTypeForName('KCDATA_TYPE_CONTAINER_BEGIN'): |
3e170ce0 A |
495 | self.obj['uniqID'] = self.i_flags |
496 | self.i_name = str(self.obj['uniqID']) | |
497 | self.obj['typeID'] = struct.unpack_from('I', self.i_data)[0] | |
39037602 | 498 | logging.info("0x%08x: %sCONTAINER: %s(%x)" % (self.offset, INDENT(), GetTypeNameForKey(self.obj['typeID']), self.i_flags)) |
3e170ce0 | 499 | |
39037602 | 500 | elif self.i_type in (KNOWN_TOPLEVEL_CONTAINER_TYPES): |
3e170ce0 A |
501 | self.obj['uniqID'] = self.i_name |
502 | self.obj['typeID'] = self.i_type | |
39037602 | 503 | logging.info("0x%08x: %s%s" % (self.offset, INDENT(), self.i_name)) |
3e170ce0 | 504 | |
d9a64523 | 505 | elif self.i_type == GetTypeForName('KCDATA_TYPE_CONTAINER_END'): |
3e170ce0 | 506 | self.obj['uniqID'] = self.i_flags |
39037602 | 507 | logging.info("0x%08x: %sEND" % (self.offset, INDENT(end=True))) |
3e170ce0 A |
508 | |
509 | elif self.i_type == GetTypeForName('KCDATA_TYPE_BUFFER_END'): | |
510 | self.obj = '' | |
39037602 | 511 | logging.info("0x%08x: %sEND_BUFFER" % (self.offset, INDENT(end=True))) |
3e170ce0 A |
512 | |
513 | elif self.i_type == GetTypeForName('KCDATA_TYPE_UINT32_DESC'): | |
514 | self.is_naked_type = True | |
515 | u_d = struct.unpack_from('32sI', self.i_data) | |
c3c9b80d | 516 | self.i_name = BytesToString(u_d[0].rstrip('\0')) |
3e170ce0 | 517 | self.obj = u_d[1] |
39037602 | 518 | logging.info("0x%08x: %s%s" % (self.offset, INDENT(), self.i_name)) |
3e170ce0 A |
519 | |
520 | elif self.i_type == GetTypeForName('KCDATA_TYPE_UINT64_DESC'): | |
521 | self.is_naked_type = True | |
522 | u_d = struct.unpack_from('32sQ', self.i_data) | |
c3c9b80d | 523 | self.i_name = BytesToString(u_d[0].rstrip('\0')) |
3e170ce0 | 524 | self.obj = u_d[1] |
39037602 | 525 | logging.info("0x%08x: %s%s" % (self.offset, INDENT(), self.i_name)) |
3e170ce0 | 526 | |
d9a64523 | 527 | elif self.i_type == GetTypeForName('KCDATA_TYPE_TYPEDEFINITION'): |
3e170ce0 A |
528 | self.is_naked_type = True |
529 | u_d = struct.unpack_from('II32s', self.i_data) | |
39037602 A |
530 | self.obj['name'] = u_d[2].split(chr(0))[0] |
531 | self.i_name = "typedef[%s]" % self.obj['name'] | |
3e170ce0 A |
532 | self.obj['typeID'] = u_d[0] |
533 | self.obj['numOfFields'] = u_d[1] | |
534 | element_arr = [] | |
535 | for i in range(u_d[1]): | |
536 | e = KCSubTypeElement.FromBinaryTypeData(self.i_data[40+(i*40):]) | |
3e170ce0 A |
537 | element_arr.append(e) |
538 | type_desc = KCTypeDescription(u_d[0], element_arr, self.obj['name']) | |
3e170ce0 A |
539 | self.obj['fields'] = [str(e) for e in element_arr] |
540 | KNOWN_TYPES_COLLECTION[type_desc.GetTypeID()] = type_desc | |
39037602 | 541 | logging.info("0x%08x: %s%s" % (self.offset, INDENT(), self.i_name)) |
3e170ce0 A |
542 | |
543 | elif self.i_type == GetTypeForName('KCDATA_TYPE_ARRAY'): | |
544 | self.is_array_type = True | |
545 | e_t = (self.i_flags >> 32) & 0xffffffff | |
39037602 A |
546 | if e_t not in LEGAL_OLD_STYLE_ARRAY_TYPES: |
547 | raise Exception, "illegal old-style array type: %s (0x%x)" % (GetTypeNameForKey(e_t), e_t) | |
3e170ce0 | 548 | e_c = self.i_flags & 0xffffffff |
a39ff7e2 | 549 | e_s = KNOWN_TYPES_COLLECTION[e_t].legacy_size |
39037602 | 550 | if e_s * e_c > self.i_size: |
a39ff7e2 | 551 | raise Exception("array too small for its count") |
3e170ce0 A |
552 | self.obj['typeID'] = e_t |
553 | self.i_name = GetTypeNameForKey(e_t) | |
554 | self.i_type = e_t | |
555 | self.obj['numOfElements'] = e_c | |
556 | self.obj['sizeOfElement'] = e_s | |
39037602 | 557 | logging.info("0x%08x: %sARRAY: %s" % (self.offset, INDENT(), self.i_name)) |
3e170ce0 | 558 | #populate the array here by recursive creation of KCObject |
39037602 A |
559 | with INDENT.indent(): |
560 | for _i in range(e_c): | |
561 | _o = KCObject(e_t, self.i_data[(_i * e_s):(_i * e_s) + e_s], self.offset + _i*e_s) | |
562 | self.obj_collection.append(_o) | |
563 | ||
564 | elif self.i_type >= GetTypeForName('KCDATA_TYPE_ARRAY_PAD0') and self.i_type <= GetTypeForName('KCDATA_TYPE_ARRAY_PADf'): | |
565 | self.is_array_type = True | |
566 | e_t = (self.i_flags >> 32) & 0xffffffff | |
567 | e_c = self.i_flags & 0xffffffff | |
568 | e_s = (self.i_size - (self.i_type & 0xf)) / e_c if e_c != 0 else None | |
569 | self.obj['typeID'] = e_t | |
570 | self.i_name = GetTypeNameForKey(e_t) | |
571 | self.i_type = e_t | |
572 | self.obj['numOfElements'] = e_c | |
573 | self.obj['sizeOfElement'] = e_s | |
574 | logging.info("0x%08x: %sARRAY: %s" % (self.offset, INDENT(), self.i_name)) | |
575 | #populate the array here by recursive creation of KCObject | |
576 | with INDENT.indent(): | |
577 | for _i in range(e_c): | |
578 | _o = KCObject(e_t, self.i_data[(_i * e_s):(_i * e_s) + e_s], self.offset + _i*e_s) | |
579 | self.obj_collection.append(_o) | |
580 | ||
581 | elif self.i_type == GetTypeForName('KCDATA_TYPE_NESTED_KCDATA'): | |
582 | logging.info("0x%08x: %sNESTED_KCDATA" % (self.offset, INDENT())) | |
583 | with INDENT.indent(): | |
584 | nested_iterator = kcdata_item_iterator(self.i_data[:self.i_size]) | |
585 | nested_buffer = KCObject.FromKCItem(nested_iterator.next()) | |
586 | if not isinstance(nested_buffer, KCBufferObject): | |
587 | raise Exception, "nested buffer isn't a KCBufferObject" | |
588 | nested_buffer.ReadItems(nested_iterator) | |
589 | self.nested_kcdata = nested_buffer | |
590 | ||
3e170ce0 A |
591 | elif self.i_type in KNOWN_TYPES_COLLECTION: |
592 | self.i_name = KNOWN_TYPES_COLLECTION[self.i_type].GetName() | |
593 | self.is_naked_type = True | |
39037602 | 594 | logging.info("0x%08x: %s%s" % (self.offset, INDENT(), self.i_name)) |
3e170ce0 A |
595 | else: |
596 | self.is_naked_type = True | |
597 | #self.obj = "data of len %d" % len(self.i_data) | |
598 | #self.obj = ''.join(["%x" % ki for ki in struct.unpack('%dB' % len(self.i_data), self.i_data)]) | |
39037602 A |
599 | self.obj = map(ord, self.i_data) |
600 | logging.info("0x%08x: %s%s" % (self.offset, INDENT(), self.i_name)) | |
3e170ce0 A |
601 | |
602 | ||
603 | class KCContainerObject(KCObject): | |
604 | def __init__(self, *args, **kwargs): | |
39037602 A |
605 | assert False |
606 | ||
607 | def InitAfterParse(self): | |
3e170ce0 A |
608 | self.obj_container_dict = {} |
609 | self.obj_nested_objs = {} | |
610 | ||
39037602 A |
611 | def ShouldMerge(self): |
612 | return True | |
613 | ||
3e170ce0 | 614 | def GetJsonRepr(self): |
39037602 A |
615 | # o = '"%s"' % self.obj['uniqID'] + ' : { "typeID" : %d ,' % self.obj['typeID'] |
616 | o = '"%s"' % self.obj['uniqID'] + ' : { ' | |
3e170ce0 | 617 | for (k, v) in self.obj_container_dict.items(): |
39037602 | 618 | if v.ShouldMerge(): |
3e170ce0 A |
619 | o += v.GetJsonRepr() + "," |
620 | else: | |
621 | o += ' "%s" : ' % k + v.GetJsonRepr() + "," | |
622 | ||
623 | for (k, v) in self.obj_nested_objs.items(): | |
624 | o += '"%s" : {' % k + ",".join([vi.GetJsonRepr() for vi in v.values()]) + "} ," | |
625 | ||
626 | o = o.rstrip(',') + "}" | |
627 | ||
628 | return o | |
629 | ||
630 | def AddObject(self, kco): | |
39037602 A |
631 | assert not kco.IsContainerEnd() |
632 | if isinstance(kco, KCContainerObject): | |
3e170ce0 A |
633 | type_name = GetTypeNameForKey(kco.obj['typeID']) |
634 | if type_name not in self.obj_nested_objs: | |
635 | self.obj_nested_objs[type_name] = {} | |
636 | self.obj_nested_objs[type_name][kco.i_name] = kco | |
637 | return | |
39037602 A |
638 | if kco.i_name in self.obj_container_dict: |
639 | if kco.IsArray() and self.obj_container_dict[kco.i_name].IsArray(): | |
640 | self.obj_container_dict[kco.i_name].obj_collection.extend( kco.obj_collection ) | |
641 | else: | |
642 | self.obj_container_dict[kco.i_name] = kco | |
643 | ||
644 | def IsEndMarker(self, o): | |
645 | if not o.IsContainerEnd(): | |
646 | return False | |
647 | if o.i_flags != self.i_flags: | |
648 | raise Exception, "container end marker doesn't match" | |
649 | return True | |
650 | ||
651 | no_end_message = "could not find container end marker" | |
652 | ||
653 | def ReadItems(self, iterator): | |
654 | found_end = False | |
655 | with INDENT.indent(): | |
656 | for i in iterator: | |
657 | o = KCObject.FromKCItem(i) | |
658 | if self.IsEndMarker(o): | |
659 | found_end = True | |
660 | break | |
5ba3f43e A |
661 | if o.IsBufferEnd(): |
662 | break | |
39037602 A |
663 | if isinstance(o, KCContainerObject): |
664 | o.ReadItems(iterator) | |
665 | self.AddObject(o) | |
666 | if not found_end: | |
5ba3f43e A |
667 | if G.accept_incomplete_data: |
668 | if not G.data_was_incomplete: | |
669 | print >>sys.stderr, "kcdata.py WARNING: data is incomplete!" | |
670 | G.data_was_incomplete = True | |
671 | else: | |
672 | raise Exception, self.no_end_message | |
673 | ||
39037602 A |
674 | |
675 | ||
676 | class KCBufferObject(KCContainerObject): | |
677 | ||
678 | def IsEndMarker(self,o): | |
679 | if o.IsContainerEnd(): | |
680 | raise Exception, "container end marker at the toplevel" | |
681 | return o.IsBufferEnd() | |
682 | ||
683 | no_end_message = "could not find buffer end marker" | |
3e170ce0 | 684 | |
f427ee49 A |
685 | class KCCompressedBufferObject(KCContainerObject): |
686 | ||
687 | def ReadItems(self, iterator): | |
688 | self.header = dict() | |
689 | with INDENT.indent(): | |
690 | for i in iterator: | |
691 | o = KCObject.FromKCItem(i) | |
692 | if self.IsEndMarker(o): | |
693 | self.compressed_type = o.i_type | |
694 | self.blob_start = o.offset + 16 | |
695 | break | |
696 | o.ParseData() | |
697 | self.header[o.i_name] = o.obj | |
698 | ||
699 | def IsEndMarker(self, o): | |
700 | return o.i_type in KNOWN_TOPLEVEL_CONTAINER_TYPES | |
701 | ||
702 | def GetCompressedBlob(self, data): | |
703 | if self.header['kcd_c_type'] != 1: | |
704 | raise NotImplementedError | |
705 | blob = data[self.blob_start:self.blob_start+self.header['kcd_c_totalout']] | |
706 | if len(blob) != self.header['kcd_c_totalout']: | |
707 | raise ValueError | |
708 | return blob | |
709 | ||
710 | def Decompress(self, data): | |
711 | start_marker = struct.pack('<IIII', self.compressed_type, 0, 0, 0) | |
712 | end_marker = struct.pack('<IIII', GetTypeForName('KCDATA_TYPE_BUFFER_END'), 0, 0, 0) | |
713 | decompressed = zlib.decompress(self.GetCompressedBlob(data)) | |
714 | if len(decompressed) != self.header['kcd_c_totalin']: | |
715 | raise ValueError, "length of decompressed: %d vs expected %d" % (len(decompressed), self.header['kcd_c_totalin']) | |
716 | alignbytes = b'\x00' * (-len(decompressed) % 16) | |
717 | return start_marker + decompressed + alignbytes + end_marker | |
718 | ||
3e170ce0 A |
719 | |
720 | class KCData_item: | |
721 | """ a basic kcdata_item type object. | |
722 | """ | |
723 | header_size = 16 # (uint32_t + uint32_t + uint64_t) | |
724 | ||
725 | def __init__(self, item_type, item_size, item_flags, item_data): | |
726 | self.i_type = item_type | |
727 | self.i_size = item_size | |
728 | self.i_flags = item_flags | |
729 | self.i_data = item_data | |
39037602 | 730 | self.i_offset = None |
3e170ce0 A |
731 | |
732 | def __init__(self, barray, pos=0): | |
733 | """ create an object by parsing data from bytes array | |
734 | returns : obj - if data is readable | |
735 | raises ValueError if something is not ok. | |
736 | """ | |
737 | self.i_type = struct.unpack('I', barray[pos:pos+4])[0] # int.from_bytes(barray[pos:pos+4]) | |
738 | self.i_size = struct.unpack('I', barray[pos+4:pos+8])[0] # int.from_bytes(barray[pos+4:pos+8]) | |
739 | self.i_flags = struct.unpack('Q', barray[pos+8:pos+16])[0] # int.from_bytes(barray[pos+8:pos+16]) | |
740 | self.i_data = barray[pos+16: (pos + 16 + self.i_size)] | |
39037602 | 741 | self.i_offset = pos |
3e170ce0 A |
742 | |
743 | def __len__(self): | |
744 | return self.i_size + KCData_item.header_size | |
745 | ||
746 | def GetHeaderDescription(self): | |
39037602 A |
747 | outs = "type: 0x%x size: 0x%x flags: 0x%x (%s)" % (self.i_type, self.i_size, self.i_flags, GetTypeNameForKey(self.i_type)) |
748 | if not self.i_offset is None: | |
749 | outs = "pos: 0x%x" % self.i_offset + outs | |
3e170ce0 A |
750 | return outs |
751 | ||
752 | def __str__(self): | |
753 | return self.GetHeaderDescription() | |
754 | ||
39037602 A |
755 | def kcdata_item_iterator(data): |
756 | file_len = len(data) | |
757 | curpos = 0 | |
758 | while curpos < file_len: | |
759 | item = KCData_item(data, curpos) | |
760 | yield item | |
761 | curpos += len(item) | |
3e170ce0 A |
762 | |
763 | def _get_data_element(elementValues): | |
764 | return json.dumps(elementValues[-1]) | |
765 | ||
f427ee49 | 766 | KNOWN_TOPLEVEL_CONTAINER_TYPES = map(GetTypeForName, ('KCDATA_BUFFER_BEGIN_COMPRESSED', 'KCDATA_BUFFER_BEGIN_CRASHINFO', 'KCDATA_BUFFER_BEGIN_STACKSHOT', 'KCDATA_BUFFER_BEGIN_DELTA_STACKSHOT', 'KCDATA_BUFFER_BEGIN_OS_REASON','KCDATA_BUFFER_BEGIN_XNUPOST_CONFIG')) |
39037602 | 767 | |
3e170ce0 A |
768 | KNOWN_TYPES_COLLECTION[GetTypeForName('KCDATA_TYPE_UINT32_DESC')] = KCTypeDescription(GetTypeForName('KCDATA_TYPE_UINT32_DESC'), ( |
769 | KCSubTypeElement('desc', KCSUBTYPE_TYPE.KC_ST_CHAR, KCSubTypeElement.GetSizeForArray(32, 1), 0, 1), | |
770 | KCSubTypeElement('data', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 32, 0) | |
771 | ), | |
772 | 'KCDATA_TYPE_UINT32_DESC', | |
773 | _get_data_element | |
774 | ) | |
775 | ||
776 | KNOWN_TYPES_COLLECTION[GetTypeForName('KCDATA_TYPE_UINT64_DESC')] = KCTypeDescription(GetTypeForName('KCDATA_TYPE_UINT64_DESC'), ( | |
777 | KCSubTypeElement('desc', KCSUBTYPE_TYPE.KC_ST_CHAR, KCSubTypeElement.GetSizeForArray(32, 1), 0, 1), | |
778 | KCSubTypeElement('data', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 32, 0) | |
779 | ), | |
780 | 'KCDATA_TYPE_UINT64_DESC', | |
781 | _get_data_element | |
782 | ) | |
783 | ||
784 | KNOWN_TYPES_COLLECTION[GetTypeForName('KCDATA_TYPE_TIMEBASE')] = KCTypeDescription(GetTypeForName('KCDATA_TYPE_TIMEBASE'), ( | |
39037602 A |
785 | KCSubTypeElement('numer', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 0, 0), |
786 | KCSubTypeElement('denom', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 4, 0) | |
3e170ce0 | 787 | ), |
39037602 | 788 | 'mach_timebase_info' |
3e170ce0 A |
789 | ) |
790 | ||
791 | ||
792 | STACKSHOT_IO_NUM_PRIORITIES = 4 | |
793 | KNOWN_TYPES_COLLECTION[0x901] = KCTypeDescription(0x901, ( | |
39037602 A |
794 | KCSubTypeElement.FromBasicCtype('ss_disk_reads_count', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), |
795 | KCSubTypeElement.FromBasicCtype('ss_disk_reads_size', KCSUBTYPE_TYPE.KC_ST_UINT64, 8), | |
796 | KCSubTypeElement.FromBasicCtype('ss_disk_writes_count', KCSUBTYPE_TYPE.KC_ST_UINT64, 16), | |
797 | KCSubTypeElement.FromBasicCtype('ss_disk_writes_size', KCSUBTYPE_TYPE.KC_ST_UINT64, 24), | |
798 | KCSubTypeElement('ss_io_priority_count', KCSUBTYPE_TYPE.KC_ST_UINT64, KCSubTypeElement.GetSizeForArray(STACKSHOT_IO_NUM_PRIORITIES, 8), 32, 1), | |
799 | KCSubTypeElement('ss_io_priority_size', KCSUBTYPE_TYPE.KC_ST_UINT64, KCSubTypeElement.GetSizeForArray(STACKSHOT_IO_NUM_PRIORITIES, 8), 32 + (STACKSHOT_IO_NUM_PRIORITIES * 8), 1), | |
800 | KCSubTypeElement.FromBasicCtype('ss_paging_count', KCSUBTYPE_TYPE.KC_ST_UINT64, 32 + 2 * (STACKSHOT_IO_NUM_PRIORITIES * 8)), | |
801 | KCSubTypeElement.FromBasicCtype('ss_paging_size', KCSUBTYPE_TYPE.KC_ST_UINT64, 40 + 2 * (STACKSHOT_IO_NUM_PRIORITIES * 8)), | |
802 | KCSubTypeElement.FromBasicCtype('ss_non_paging_count', KCSUBTYPE_TYPE.KC_ST_UINT64, 48 + 2 * (STACKSHOT_IO_NUM_PRIORITIES * 8)), | |
803 | KCSubTypeElement.FromBasicCtype('ss_non_paging_size', KCSUBTYPE_TYPE.KC_ST_UINT64, 56 + 2 * (STACKSHOT_IO_NUM_PRIORITIES * 8)), | |
804 | KCSubTypeElement.FromBasicCtype('ss_data_count', KCSUBTYPE_TYPE.KC_ST_UINT64, 64 + 2 * (STACKSHOT_IO_NUM_PRIORITIES * 8)), | |
805 | KCSubTypeElement.FromBasicCtype('ss_data_size', KCSUBTYPE_TYPE.KC_ST_UINT64, 72 + 2 * (STACKSHOT_IO_NUM_PRIORITIES * 8)), | |
806 | KCSubTypeElement.FromBasicCtype('ss_metadata_count', KCSUBTYPE_TYPE.KC_ST_UINT64, 80 + 2 * (STACKSHOT_IO_NUM_PRIORITIES * 8)), | |
807 | KCSubTypeElement.FromBasicCtype('ss_metadata_size', KCSUBTYPE_TYPE.KC_ST_UINT64, 88 + 2 * (STACKSHOT_IO_NUM_PRIORITIES * 8)) | |
3e170ce0 A |
808 | ), |
809 | 'io_statistics' | |
810 | ) | |
811 | ||
812 | KNOWN_TYPES_COLLECTION[0x902] = KCTypeDescription(0x902, ( | |
813 | KCSubTypeElement('snapshot_magic', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 4 * 0, 0), | |
814 | KCSubTypeElement('free_pages', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 4 * 1, 0), | |
815 | KCSubTypeElement('active_pages', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 4 * 2, 0), | |
816 | KCSubTypeElement('inactive_pages', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 4 * 3, 0), | |
817 | KCSubTypeElement('purgeable_pages', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 4 * 4, 0), | |
818 | KCSubTypeElement('wired_pages', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 4 * 5, 0), | |
819 | KCSubTypeElement('speculative_pages', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 4 * 6, 0), | |
820 | KCSubTypeElement('throttled_pages', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 4 * 7, 0), | |
821 | KCSubTypeElement('filebacked_pages', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 4 * 8, 0), | |
822 | KCSubTypeElement('compressions', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 4 * 9, 0), | |
823 | KCSubTypeElement('decompressions', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 4 * 10, 0), | |
824 | KCSubTypeElement('compressor_size', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 4 * 11, 0), | |
825 | KCSubTypeElement('busy_buffer_count', KCSUBTYPE_TYPE.KC_ST_INT32, 4, 4 * 12, 0), | |
826 | KCSubTypeElement('pages_wanted', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 4 * 13, 0), | |
827 | KCSubTypeElement('pages_reclaimed', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 4 * 14, 0), | |
828 | KCSubTypeElement('pages_wanted_reclaimed_valid', KCSUBTYPE_TYPE.KC_ST_UINT8, 1, 4 * 15, 0) | |
829 | ), | |
830 | 'mem_and_io_snapshot' | |
831 | ) | |
832 | ||
833 | ||
834 | KNOWN_TYPES_COLLECTION[0x905] = KCTypeDescription(0x905, ( | |
39037602 A |
835 | KCSubTypeElement.FromBasicCtype('ts_unique_pid', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), |
836 | KCSubTypeElement.FromBasicCtype('ts_ss_flags', KCSUBTYPE_TYPE.KC_ST_UINT64, 8), | |
837 | KCSubTypeElement.FromBasicCtype('ts_user_time_in_terminated_thre', KCSUBTYPE_TYPE.KC_ST_UINT64, 16), | |
838 | KCSubTypeElement.FromBasicCtype('ts_system_time_in_terminated_th', KCSUBTYPE_TYPE.KC_ST_UINT64, 24), | |
839 | KCSubTypeElement.FromBasicCtype('ts_p_start_sec', KCSUBTYPE_TYPE.KC_ST_UINT64, 32), | |
840 | KCSubTypeElement.FromBasicCtype('ts_task_size', KCSUBTYPE_TYPE.KC_ST_UINT64, 40), | |
841 | KCSubTypeElement.FromBasicCtype('ts_max_resident_size', KCSUBTYPE_TYPE.KC_ST_UINT64, 48), | |
842 | KCSubTypeElement.FromBasicCtype('ts_suspend_count', KCSUBTYPE_TYPE.KC_ST_UINT32, 56), | |
843 | KCSubTypeElement.FromBasicCtype('ts_faults', KCSUBTYPE_TYPE.KC_ST_UINT32, 60), | |
844 | KCSubTypeElement.FromBasicCtype('ts_pageins', KCSUBTYPE_TYPE.KC_ST_UINT32, 64), | |
845 | KCSubTypeElement.FromBasicCtype('ts_cow_faults', KCSUBTYPE_TYPE.KC_ST_UINT32, 68), | |
846 | KCSubTypeElement.FromBasicCtype('ts_was_throttled', KCSUBTYPE_TYPE.KC_ST_UINT32, 72), | |
847 | KCSubTypeElement.FromBasicCtype('ts_did_throttle', KCSUBTYPE_TYPE.KC_ST_UINT32, 76), | |
848 | KCSubTypeElement.FromBasicCtype('ts_latency_qos', KCSUBTYPE_TYPE.KC_ST_UINT32, 80), | |
849 | KCSubTypeElement.FromBasicCtype('ts_pid', KCSUBTYPE_TYPE.KC_ST_INT32, 84), | |
850 | KCSubTypeElement('ts_p_comm', KCSUBTYPE_TYPE.KC_ST_CHAR, KCSubTypeElement.GetSizeForArray(32, 1), 88, 1) | |
3e170ce0 | 851 | ), |
39037602 | 852 | 'task_snapshot' |
3e170ce0 A |
853 | ) |
854 | ||
855 | KNOWN_TYPES_COLLECTION[0x906] = KCTypeDescription(0x906, ( | |
39037602 A |
856 | KCSubTypeElement.FromBasicCtype('ths_thread_id', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), |
857 | KCSubTypeElement.FromBasicCtype('ths_wait_event', KCSUBTYPE_TYPE.KC_ST_UINT64, 8), | |
858 | KCSubTypeElement.FromBasicCtype('ths_continuation', KCSUBTYPE_TYPE.KC_ST_UINT64, 16), | |
859 | KCSubTypeElement.FromBasicCtype('ths_total_syscalls', KCSUBTYPE_TYPE.KC_ST_UINT64, 24), | |
860 | KCSubTypeElement.FromBasicCtype('ths_voucher_identifier', KCSUBTYPE_TYPE.KC_ST_UINT64, 32), | |
861 | KCSubTypeElement.FromBasicCtype('ths_dqserialnum', KCSUBTYPE_TYPE.KC_ST_UINT64, 40), | |
862 | KCSubTypeElement.FromBasicCtype('ths_user_time', KCSUBTYPE_TYPE.KC_ST_UINT64, 48), | |
863 | KCSubTypeElement.FromBasicCtype('ths_sys_time', KCSUBTYPE_TYPE.KC_ST_UINT64, 56), | |
864 | KCSubTypeElement.FromBasicCtype('ths_ss_flags', KCSUBTYPE_TYPE.KC_ST_UINT64, 64), | |
865 | KCSubTypeElement.FromBasicCtype('ths_last_run_time', KCSUBTYPE_TYPE.KC_ST_UINT64, 72), | |
866 | KCSubTypeElement.FromBasicCtype('ths_last_made_runnable_time', KCSUBTYPE_TYPE.KC_ST_UINT64, 80), | |
867 | KCSubTypeElement.FromBasicCtype('ths_state', KCSUBTYPE_TYPE.KC_ST_UINT32, 88), | |
868 | KCSubTypeElement.FromBasicCtype('ths_sched_flags', KCSUBTYPE_TYPE.KC_ST_UINT32, 92), | |
869 | KCSubTypeElement.FromBasicCtype('ths_base_priority', KCSUBTYPE_TYPE.KC_ST_INT16, 96), | |
870 | KCSubTypeElement.FromBasicCtype('ths_sched_priority', KCSUBTYPE_TYPE.KC_ST_INT16, 98), | |
871 | KCSubTypeElement.FromBasicCtype('ths_eqos', KCSUBTYPE_TYPE.KC_ST_UINT8, 100), | |
872 | KCSubTypeElement.FromBasicCtype('ths_rqos', KCSUBTYPE_TYPE.KC_ST_UINT8, 101), | |
873 | KCSubTypeElement.FromBasicCtype('ths_rqos_override', KCSUBTYPE_TYPE.KC_ST_UINT8, 102), | |
874 | KCSubTypeElement.FromBasicCtype('ths_io_tier', KCSUBTYPE_TYPE.KC_ST_UINT8, 103), | |
875 | KCSubTypeElement.FromBasicCtype('ths_thread_t', KCSUBTYPE_TYPE.KC_ST_UINT64, 104), | |
5ba3f43e A |
876 | KCSubTypeElement.FromBasicCtype('ths_requested_policy', KCSUBTYPE_TYPE.KC_ST_UINT64, 112), |
877 | KCSubTypeElement.FromBasicCtype('ths_effective_policy', KCSUBTYPE_TYPE.KC_ST_UINT64, 120), | |
39037602 A |
878 | ), |
879 | 'thread_snapshot', | |
880 | legacy_size = 0x68 | |
881 | ) | |
882 | ||
cb323159 A |
883 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_THREAD_DISPATCH_QUEUE_LABEL')] = KCSubTypeElement('dispatch_queue_label', KCSUBTYPE_TYPE.KC_ST_CHAR, |
884 | KCSubTypeElement.GetSizeForArray(64, 1), 0, 1) | |
885 | ||
39037602 A |
886 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_THREAD_DELTA_SNAPSHOT')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_THREAD_DELTA_SNAPSHOT'), ( |
887 | KCSubTypeElement.FromBasicCtype('tds_thread_id', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
888 | KCSubTypeElement.FromBasicCtype('tds_voucher_identifier', KCSUBTYPE_TYPE.KC_ST_UINT64, 8), | |
889 | KCSubTypeElement.FromBasicCtype('tds_ss_flags', KCSUBTYPE_TYPE.KC_ST_UINT64, 16), | |
890 | KCSubTypeElement.FromBasicCtype('tds_last_made_runnable_time', KCSUBTYPE_TYPE.KC_ST_UINT64, 24), | |
891 | KCSubTypeElement.FromBasicCtype('tds_state', KCSUBTYPE_TYPE.KC_ST_UINT32, 32), | |
892 | KCSubTypeElement.FromBasicCtype('tds_sched_flags', KCSUBTYPE_TYPE.KC_ST_UINT32, 36), | |
893 | KCSubTypeElement.FromBasicCtype('tds_base_priority', KCSUBTYPE_TYPE.KC_ST_INT16, 40), | |
894 | KCSubTypeElement.FromBasicCtype('tds_sched_priority', KCSUBTYPE_TYPE.KC_ST_INT16, 42), | |
895 | KCSubTypeElement.FromBasicCtype('tds_eqos', KCSUBTYPE_TYPE.KC_ST_UINT8, 44), | |
896 | KCSubTypeElement.FromBasicCtype('tds_rqos', KCSUBTYPE_TYPE.KC_ST_UINT8, 45), | |
897 | KCSubTypeElement.FromBasicCtype('tds_rqos_override', KCSUBTYPE_TYPE.KC_ST_UINT8, 46), | |
898 | KCSubTypeElement.FromBasicCtype('tds_io_tier', KCSUBTYPE_TYPE.KC_ST_UINT8, 47), | |
a39ff7e2 A |
899 | KCSubTypeElement.FromBasicCtype('tds_requested_policy', KCSUBTYPE_TYPE.KC_ST_UINT64, 48), |
900 | KCSubTypeElement.FromBasicCtype('tds_effective_policy', KCSUBTYPE_TYPE.KC_ST_UINT64, 56), | |
39037602 | 901 | ), |
a39ff7e2 A |
902 | 'thread_delta_snapshot', |
903 | legacy_size = 48 | |
39037602 A |
904 | ) |
905 | ||
906 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_TASK_DELTA_SNAPSHOT')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_TASK_DELTA_SNAPSHOT'), ( | |
907 | KCSubTypeElement.FromBasicCtype('tds_unique_pid', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
908 | KCSubTypeElement.FromBasicCtype('tds_ss_flags', KCSUBTYPE_TYPE.KC_ST_UINT64, 8), | |
909 | KCSubTypeElement.FromBasicCtype('tds_user_time_in_terminated_thr', KCSUBTYPE_TYPE.KC_ST_UINT64, 16), | |
910 | KCSubTypeElement.FromBasicCtype('tds_system_time_in_terminated_t', KCSUBTYPE_TYPE.KC_ST_UINT64, 24), | |
911 | KCSubTypeElement.FromBasicCtype('tds_task_size', KCSUBTYPE_TYPE.KC_ST_UINT64, 32), | |
912 | KCSubTypeElement.FromBasicCtype('tds_max_resident_size', KCSUBTYPE_TYPE.KC_ST_UINT64, 40), | |
913 | KCSubTypeElement.FromBasicCtype('tds_suspend_count', KCSUBTYPE_TYPE.KC_ST_UINT32, 48), | |
914 | KCSubTypeElement.FromBasicCtype('tds_faults', KCSUBTYPE_TYPE.KC_ST_UINT32, 52), | |
915 | KCSubTypeElement.FromBasicCtype('tds_pageins', KCSUBTYPE_TYPE.KC_ST_UINT32, 56), | |
916 | KCSubTypeElement.FromBasicCtype('tds_cow_faults', KCSUBTYPE_TYPE.KC_ST_UINT32, 60), | |
917 | KCSubTypeElement.FromBasicCtype('tds_was_throttled', KCSUBTYPE_TYPE.KC_ST_UINT32, 64), | |
918 | KCSubTypeElement.FromBasicCtype('tds_did_throttle', KCSUBTYPE_TYPE.KC_ST_UINT32, 68), | |
919 | KCSubTypeElement.FromBasicCtype('tds_latency_qos', KCSUBTYPE_TYPE.KC_ST_UINT32, 72), | |
3e170ce0 | 920 | ), |
39037602 | 921 | 'task_delta_snapshot' |
3e170ce0 A |
922 | ) |
923 | ||
39037602 | 924 | |
cb323159 | 925 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_THREAD_NAME')] = KCSubTypeElement('pth_name', KCSUBTYPE_TYPE.KC_ST_CHAR, KCSubTypeElement.GetSizeForArray(64, 1), 0, 1) |
3e170ce0 | 926 | |
d9a64523 A |
927 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_SYS_SHAREDCACHE_LAYOUT')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_SYS_SHAREDCACHE_LAYOUT'), ( |
928 | KCSubTypeElement('imageLoadAddress', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0), | |
929 | KCSubTypeElement('imageUUID', KCSUBTYPE_TYPE.KC_ST_UINT8, KCSubTypeElement.GetSizeForArray(16, 1), 8, 1) | |
930 | ), | |
931 | 'system_shared_cache_layout' | |
932 | ) | |
3e170ce0 A |
933 | |
934 | KNOWN_TYPES_COLLECTION[GetTypeForName('KCDATA_TYPE_LIBRARY_LOADINFO64')] = KCTypeDescription(GetTypeForName('KCDATA_TYPE_LIBRARY_LOADINFO64'), ( | |
39037602 A |
935 | KCSubTypeElement('imageLoadAddress', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0), |
936 | KCSubTypeElement('imageUUID', KCSUBTYPE_TYPE.KC_ST_UINT8, KCSubTypeElement.GetSizeForArray(16, 1), 8, 1) | |
3e170ce0 | 937 | ), |
a39ff7e2 A |
938 | 'dyld_load_info', |
939 | legacy_size = 24 | |
3e170ce0 A |
940 | ) |
941 | ||
942 | KNOWN_TYPES_COLLECTION[GetTypeForName('KCDATA_TYPE_LIBRARY_LOADINFO')] = KCTypeDescription(GetTypeForName('KCDATA_TYPE_LIBRARY_LOADINFO'), ( | |
39037602 A |
943 | KCSubTypeElement('imageLoadAddress', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 0, 0), |
944 | KCSubTypeElement('imageUUID', KCSUBTYPE_TYPE.KC_ST_UINT8, KCSubTypeElement.GetSizeForArray(16, 1), 4, 1) | |
3e170ce0 | 945 | ), |
a39ff7e2 A |
946 | 'dyld_load_info', |
947 | legacy_size = 20 | |
3e170ce0 A |
948 | ) |
949 | ||
f427ee49 A |
950 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_LOADINFO64_TEXT_EXEC')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_LOADINFO64_TEXT_EXEC'), ( |
951 | KCSubTypeElement('imageLoadAddress', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0), | |
952 | KCSubTypeElement('imageUUID', KCSUBTYPE_TYPE.KC_ST_UINT8, KCSubTypeElement.GetSizeForArray(16, 1), 8, 1), | |
953 | ), | |
954 | 'dyld_load_info_text_exec' | |
955 | ) | |
956 | ||
39037602 A |
957 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_SHAREDCACHE_LOADINFO')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_SHAREDCACHE_LOADINFO'), ( |
958 | KCSubTypeElement('imageLoadAddress', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0), | |
959 | KCSubTypeElement('imageUUID', KCSUBTYPE_TYPE.KC_ST_UINT8, KCSubTypeElement.GetSizeForArray(16, 1), 8, 1), | |
960 | KCSubTypeElement('imageSlidBaseAddress', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 24, 0), | |
c3c9b80d | 961 | KCSubTypeElement('sharedCacheSlidFirstMapping', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 32, 0), |
39037602 A |
962 | ), |
963 | 'shared_cache_dyld_load_info', | |
964 | legacy_size = 0x18 | |
965 | ) | |
966 | ||
967 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_KERNELCACHE_LOADINFO')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_KERNELCACHE_LOADINFO'), ( | |
968 | KCSubTypeElement('imageLoadAddress', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0), | |
969 | KCSubTypeElement('imageUUID', KCSUBTYPE_TYPE.KC_ST_UINT8, KCSubTypeElement.GetSizeForArray(16, 1), 8, 1), | |
970 | ), | |
971 | 'kernelcache_load_info' | |
972 | ) | |
3e170ce0 A |
973 | |
974 | KNOWN_TYPES_COLLECTION[0x33] = KCSubTypeElement('mach_absolute_time', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0, KCSubTypeElement._get_naked_element_value) | |
a39ff7e2 | 975 | KNOWN_TYPES_COLLECTION[0x907] = KCSubTypeElement.FromBasicCtype('donating_pids', KCSUBTYPE_TYPE.KC_ST_INT32, legacy_size=4) |
3e170ce0 A |
976 | |
977 | KNOWN_TYPES_COLLECTION[GetTypeForName('KCDATA_TYPE_USECS_SINCE_EPOCH')] = KCSubTypeElement('usecs_since_epoch', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0, KCSubTypeElement._get_naked_element_value) | |
978 | ||
979 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_KERN_STACKFRAME')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_KERN_STACKFRAME'), ( | |
980 | KCSubTypeElement.FromBasicCtype('lr', KCSUBTYPE_TYPE.KC_ST_UINT32), | |
981 | KCSubTypeElement.FromBasicCtype('sp', KCSUBTYPE_TYPE.KC_ST_UINT32, 4) | |
982 | ), | |
a39ff7e2 A |
983 | 'kernel_stack_frames', |
984 | legacy_size = 8 | |
3e170ce0 A |
985 | ) |
986 | ||
39037602 A |
987 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_KERN_STACKLR')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_KERN_STACKLR'), ( |
988 | KCSubTypeElement.FromBasicCtype('lr', KCSUBTYPE_TYPE.KC_ST_UINT32), | |
989 | ), | |
990 | 'kernel_stack_frames' | |
991 | ) | |
992 | ||
993 | ||
3e170ce0 A |
994 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_USER_STACKFRAME')] = KCTypeDescription.FromKCTypeDescription( |
995 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_KERN_STACKFRAME')], | |
996 | GetTypeForName('STACKSHOT_KCTYPE_USER_STACKFRAME'), | |
997 | 'user_stack_frames' | |
998 | ) | |
999 | ||
39037602 A |
1000 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_USER_STACKLR')] = KCTypeDescription.FromKCTypeDescription( |
1001 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_KERN_STACKLR')], | |
1002 | GetTypeForName('STACKSHOT_KCTYPE_USER_STACKLR'), | |
1003 | 'user_stack_frames' | |
1004 | ) | |
1005 | ||
3e170ce0 A |
1006 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_KERN_STACKFRAME64')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_KERN_STACKFRAME64'), ( |
1007 | KCSubTypeElement.FromBasicCtype('lr', KCSUBTYPE_TYPE.KC_ST_UINT64), | |
1008 | KCSubTypeElement.FromBasicCtype('sp', KCSUBTYPE_TYPE.KC_ST_UINT64, 8) | |
1009 | ), | |
a39ff7e2 A |
1010 | 'kernel_stack_frames', |
1011 | legacy_size = 16 | |
3e170ce0 A |
1012 | ) |
1013 | ||
1014 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_USER_STACKFRAME64')] = KCTypeDescription.FromKCTypeDescription( | |
1015 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_KERN_STACKFRAME64')], | |
1016 | GetTypeForName('STACKSHOT_KCTYPE_USER_STACKFRAME64'), | |
1017 | 'user_stack_frames' | |
1018 | ) | |
1019 | ||
39037602 A |
1020 | |
1021 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_KERN_STACKLR64')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_KERN_STACKLR64'), ( | |
1022 | KCSubTypeElement.FromBasicCtype('lr', KCSUBTYPE_TYPE.KC_ST_UINT64), | |
1023 | ), | |
1024 | 'kernel_stack_frames' | |
1025 | ) | |
1026 | ||
1027 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_USER_STACKLR64')] = KCTypeDescription.FromKCTypeDescription( | |
1028 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_KERN_STACKLR64')], | |
1029 | GetTypeForName('STACKSHOT_KCTYPE_USER_STACKLR64'), | |
1030 | 'user_stack_frames' | |
1031 | ) | |
1032 | ||
1033 | ||
1034 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_NONRUNNABLE_TIDS')] = KCSubTypeElement.FromBasicCtype('nonrunnable_threads', KCSUBTYPE_TYPE.KC_ST_INT64) | |
1035 | ||
1036 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_NONRUNNABLE_TASKS')] = KCSubTypeElement.FromBasicCtype('nonrunnable_tasks', KCSUBTYPE_TYPE.KC_ST_INT64) | |
1037 | ||
3e170ce0 A |
1038 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_OSVERSION')] = KCSubTypeElement('osversion', KCSUBTYPE_TYPE.KC_ST_CHAR, |
1039 | KCSubTypeElement.GetSizeForArray(256, 1), 0, 1) | |
1040 | ||
39037602 | 1041 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_BOOTARGS')] = KCSubTypeElement('boot_args', KCSUBTYPE_TYPE.KC_ST_CHAR, |
3e170ce0 A |
1042 | KCSubTypeElement.GetSizeForArray(256, 1), 0, 1) |
1043 | ||
1044 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_KERN_PAGE_SIZE')] = KCSubTypeElement('kernel_page_size', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 0, 0, KCSubTypeElement._get_naked_element_value) | |
1045 | ||
5ba3f43e A |
1046 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_THREAD_POLICY_VERSION')] = KCSubTypeElement('thread_policy_version', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 0, 0, KCSubTypeElement._get_naked_element_value) |
1047 | ||
3e170ce0 A |
1048 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_JETSAM_LEVEL')] = KCSubTypeElement('jetsam_level', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 0, 0, KCSubTypeElement._get_naked_element_value) |
1049 | ||
39037602 A |
1050 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_DELTA_SINCE_TIMESTAMP')] = KCSubTypeElement("stackshot_delta_since_timestamp", KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0, KCSubTypeElement._get_naked_element_value) |
1051 | ||
1052 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_STACKSHOT_FAULT_STATS')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_STACKSHOT_FAULT_STATS'), | |
1053 | ( | |
1054 | KCSubTypeElement.FromBasicCtype('sfs_pages_faulted_in', KCSUBTYPE_TYPE.KC_ST_UINT32, 0), | |
1055 | KCSubTypeElement.FromBasicCtype('sfs_time_spent_faulting', KCSUBTYPE_TYPE.KC_ST_UINT64, 4), | |
1056 | KCSubTypeElement.FromBasicCtype('sfs_system_max_fault_time', KCSUBTYPE_TYPE.KC_ST_UINT64, 12), | |
1057 | KCSubTypeElement.FromBasicCtype('sfs_stopped_faulting', KCSUBTYPE_TYPE.KC_ST_UINT8, 20) | |
1058 | ), | |
1059 | 'stackshot_fault_stats') | |
3e170ce0 | 1060 | |
813fb2f6 A |
1061 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_THREAD_WAITINFO')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_THREAD_WAITINFO'), |
1062 | ( | |
1063 | KCSubTypeElement.FromBasicCtype('owner', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
1064 | KCSubTypeElement.FromBasicCtype('waiter', KCSUBTYPE_TYPE.KC_ST_UINT64, 8), | |
1065 | KCSubTypeElement.FromBasicCtype('context', KCSUBTYPE_TYPE.KC_ST_UINT64, 16), | |
1066 | KCSubTypeElement.FromBasicCtype('wait_type', KCSUBTYPE_TYPE.KC_ST_UINT8, 24) | |
1067 | ), | |
1068 | 'thread_waitinfo') | |
1069 | ||
cb323159 A |
1070 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_THREAD_TURNSTILEINFO')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_THREAD_TURNSTILEINFO'), |
1071 | ( | |
1072 | KCSubTypeElement.FromBasicCtype('waiter', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
1073 | KCSubTypeElement.FromBasicCtype('turnstile_context', KCSUBTYPE_TYPE.KC_ST_UINT64, 8), | |
1074 | KCSubTypeElement.FromBasicCtype('turnstile_priority', KCSUBTYPE_TYPE.KC_ST_UINT8, 16), | |
1075 | KCSubTypeElement.FromBasicCtype('number_of_hops', KCSUBTYPE_TYPE.KC_ST_UINT8, 17), | |
1076 | KCSubTypeElement.FromBasicCtype('turnstile_flags', KCSUBTYPE_TYPE.KC_ST_UINT64, 18), | |
1077 | ), | |
1078 | 'thread_turnstileinfo') | |
1079 | ||
5ba3f43e A |
1080 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_THREAD_GROUP_SNAPSHOT')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_THREAD_GROUP'), |
1081 | ( | |
1082 | KCSubTypeElement.FromBasicCtype('tgs_id', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
5c9f4661 A |
1083 | KCSubTypeElement('tgs_name', KCSUBTYPE_TYPE.KC_ST_CHAR, KCSubTypeElement.GetSizeForArray(16, 1), |
1084 | 8, 1), | |
1085 | KCSubTypeElement.FromBasicCtype('tgs_flags', KCSUBTYPE_TYPE.KC_ST_UINT64, 24), | |
5ba3f43e A |
1086 | ), |
1087 | 'thread_group_snapshot') | |
1088 | ||
1089 | ||
1090 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_THREAD_GROUP')] = KCSubTypeElement('thread_group', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0, KCSubTypeElement._get_naked_element_value) | |
1091 | ||
1092 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_JETSAM_COALITION_SNAPSHOT')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_JETSAM_COALITION_SNAPSHOT'), | |
1093 | ( | |
1094 | KCSubTypeElement.FromBasicCtype('jcs_id', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
1095 | KCSubTypeElement.FromBasicCtype('jcs_flags', KCSUBTYPE_TYPE.KC_ST_UINT64, 8), | |
1096 | KCSubTypeElement.FromBasicCtype('jcs_thread_group', KCSUBTYPE_TYPE.KC_ST_UINT64, 16), | |
1097 | KCSubTypeElement.FromBasicCtype('jcs_leader_task_uniqueid', KCSUBTYPE_TYPE.KC_ST_UINT64, 24) | |
1098 | ), | |
1099 | 'jetsam_coalition_snapshot') | |
1100 | ||
1101 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_JETSAM_COALITION')] = KCSubTypeElement('jetsam_coalition', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0, KCSubTypeElement._get_naked_element_value) | |
1102 | ||
1103 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_INSTRS_CYCLES')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_INSTRS_CYCLES'), | |
1104 | ( | |
1105 | KCSubTypeElement.FromBasicCtype('ics_instructions', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
1106 | KCSubTypeElement.FromBasicCtype('ics_cycles', KCSUBTYPE_TYPE.KC_ST_UINT64, 8) | |
1107 | ), | |
1108 | 'instrs_cycles_snapshot') | |
1109 | ||
f427ee49 A |
1110 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_TASK_CPU_ARCHITECTURE')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_TASK_CPU_ARCHITECTURE'), |
1111 | ( | |
1112 | KCSubTypeElement.FromBasicCtype('cputype', KCSUBTYPE_TYPE.KC_ST_INT32, 0), | |
1113 | KCSubTypeElement.FromBasicCtype('cpusubtype', KCSUBTYPE_TYPE.KC_ST_INT32, 4) | |
1114 | ), | |
1115 | 'task_cpu_architecture') | |
1116 | ||
1117 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_LATENCY_INFO')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_LATENCY_INFO'), | |
1118 | ( | |
1119 | KCSubTypeElement.FromBasicCtype('latency_version', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
1120 | KCSubTypeElement.FromBasicCtype('setup_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 8), | |
1121 | KCSubTypeElement.FromBasicCtype('total_task_iteration_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 16), | |
1122 | KCSubTypeElement.FromBasicCtype('total_terminated_task_iteration_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 24) | |
1123 | ), | |
1124 | 'stackshot_latency_collection') | |
1125 | ||
1126 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_LATENCY_INFO_TASK')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_LATENCY_INFO_TASK'), | |
1127 | ( | |
1128 | KCSubTypeElement.FromBasicCtype('task_uniqueid', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
1129 | KCSubTypeElement.FromBasicCtype('setup_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 8), | |
1130 | KCSubTypeElement.FromBasicCtype('task_thread_count_loop_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 16), | |
1131 | KCSubTypeElement.FromBasicCtype('task_thread_data_loop_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 24), | |
1132 | KCSubTypeElement.FromBasicCtype('cur_tsnap_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 32), | |
1133 | KCSubTypeElement.FromBasicCtype('pmap_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 40), | |
1134 | KCSubTypeElement.FromBasicCtype('bsd_proc_ids_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 48), | |
1135 | KCSubTypeElement.FromBasicCtype('misc_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 56), | |
1136 | KCSubTypeElement.FromBasicCtype('misc2_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 64), | |
1137 | KCSubTypeElement.FromBasicCtype('end_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 72) | |
1138 | ), | |
1139 | 'stackshot_latency_task') | |
1140 | ||
1141 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_LATENCY_INFO_THREAD')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_LATENCY_INFO_THREAD'), | |
1142 | ( | |
1143 | KCSubTypeElement.FromBasicCtype('thread_id', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
1144 | KCSubTypeElement.FromBasicCtype('cur_thsnap1_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 8), | |
1145 | KCSubTypeElement.FromBasicCtype('dispatch_serial_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 16), | |
1146 | KCSubTypeElement.FromBasicCtype('dispatch_label_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 24), | |
1147 | KCSubTypeElement.FromBasicCtype('cur_thsnap2_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 32), | |
1148 | KCSubTypeElement.FromBasicCtype('thread_name_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 40), | |
1149 | KCSubTypeElement.FromBasicCtype('sur_times_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 48), | |
1150 | KCSubTypeElement.FromBasicCtype('user_stack_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 56), | |
1151 | KCSubTypeElement.FromBasicCtype('kernel_stack_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 64), | |
1152 | KCSubTypeElement.FromBasicCtype('misc_latency', KCSUBTYPE_TYPE.KC_ST_UINT64, 72), | |
1153 | ), | |
1154 | 'stackshot_latency_thread') | |
1155 | ||
d9a64523 A |
1156 | def set_type(name, *args): |
1157 | typ = GetTypeForName(name) | |
1158 | KNOWN_TYPES_COLLECTION[typ] = KCTypeDescription(GetTypeForName(typ), *args) | |
1159 | ||
1160 | ||
1161 | set_type('STACKSHOT_KCTYPE_USER_STACKTOP', | |
1162 | ( | |
1163 | KCSubTypeElement.FromBasicCtype('sp', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
1164 | KCSubTypeElement('stack_contents', KCSUBTYPE_TYPE.KC_ST_UINT8, KCSubTypeElement.GetSizeForArray(8, 1), 8, 1), | |
1165 | ), | |
1166 | 'user_stacktop') | |
1167 | ||
3e170ce0 A |
1168 | #KNOWN_TYPES_COLLECTION[0x907] = KCSubTypeElement('donating_pids', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 0, 0, KCSubTypeElement._get_naked_element_value) |
1169 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_PID')] = KCSubTypeElement('pid', KCSUBTYPE_TYPE.KC_ST_INT32, 4, 0, 0) | |
1170 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_PPID')] = KCSubTypeElement('ppid', KCSUBTYPE_TYPE.KC_ST_INT32, 4, 0, 0) | |
1171 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_PROC_NAME')] = KCSubTypeElement('p_comm', KCSUBTYPE_TYPE.KC_ST_CHAR, | |
1172 | KCSubTypeElement.GetSizeForArray(32, 1), 0, 1) | |
1173 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_USERSTACK')] = KCSubTypeElement('userstack_ptr', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0) | |
1174 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_ARGSLEN')] = KCSubTypeElement('p_argslen', KCSUBTYPE_TYPE.KC_ST_INT32, 4, 0, 0) | |
1175 | ||
1176 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_PROC_PATH')] = KCSubTypeElement('p_path', KCSUBTYPE_TYPE.KC_ST_CHAR, | |
1177 | KCSubTypeElement.GetSizeForArray(1024, 1), 0, 1) | |
1178 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_PROC_CSFLAGS')] = KCSubTypeElement('p_csflags', KCSUBTYPE_TYPE.KC_ST_INT32, 4, 0, 0) | |
1179 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_UID')] = KCSubTypeElement('uid', KCSUBTYPE_TYPE.KC_ST_INT32, 4, 0, 0) | |
1180 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_GID')] = KCSubTypeElement('gid', KCSUBTYPE_TYPE.KC_ST_INT32, 4, 0, 0) | |
1181 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_PROC_ARGC')] = KCSubTypeElement('argc', KCSUBTYPE_TYPE.KC_ST_INT32, 4, 0, 0) | |
1182 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_PROC_FLAGS')] = KCSubTypeElement('p_flags', KCSUBTYPE_TYPE.KC_ST_INT32, 4, 0, 0) | |
1183 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_CPUTYPE')] = KCSubTypeElement('cputype', KCSUBTYPE_TYPE.KC_ST_INT32, 4, 0, 0) | |
1184 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_RESPONSIBLE_PID')] = KCSubTypeElement('responsible_pid', KCSUBTYPE_TYPE.KC_ST_INT32, 4, 0, 0) | |
1185 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_DIRTY_FLAGS')] = KCSubTypeElement('dirty_flags', KCSUBTYPE_TYPE.KC_ST_INT32, 4, 0, 0) | |
1186 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_CRASHED_THREADID')] = KCSubTypeElement('crashed_threadid', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0) | |
39037602 | 1187 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_COALITION_ID')] = KCSubTypeElement('coalition_id', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0) |
3e170ce0 A |
1188 | |
1189 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_PROC_STATUS')] = KCSubTypeElement('p_status', KCSUBTYPE_TYPE.KC_ST_UINT8, 1, 0, 0) | |
1190 | ||
1191 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_BSDINFOWITHUNIQID')] = KCTypeDescription(GetTypeForName('TASK_CRASHINFO_BSDINFOWITHUNIQID'), | |
1192 | ( KCSubTypeElement('p_uuid', KCSUBTYPE_TYPE.KC_ST_UINT8, KCSubTypeElement.GetSizeForArray(16, 1), 0, 1), | |
1193 | KCSubTypeElement.FromBasicCtype('p_uniqueid', KCSUBTYPE_TYPE.KC_ST_UINT64, 16), | |
1194 | KCSubTypeElement.FromBasicCtype('p_puniqueid', KCSUBTYPE_TYPE.KC_ST_UINT64, 24) | |
1195 | ), | |
1196 | 'proc_uniqidentifierinfo') | |
1197 | ||
39037602 A |
1198 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_EXCEPTION_CODES')] = ( |
1199 | KCTypeDescription(GetTypeForName('TASK_CRASHINFO_EXCEPTION_CODES'), | |
1200 | (KCSubTypeElement.FromBasicCtype('code_0', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
1201 | KCSubTypeElement.FromBasicCtype('code_1', KCSUBTYPE_TYPE.KC_ST_UINT64, 8)), | |
1202 | 'mach_exception_data_t')) | |
1203 | ||
1204 | ||
1205 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_PROC_STARTTIME')] = ( | |
1206 | KCTypeDescription(GetTypeForName('TASK_CRASHINFO_PROC_STARTTIME'), | |
1207 | (KCSubTypeElement.FromBasicCtype('tv_sec', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
1208 | KCSubTypeElement.FromBasicCtype('tv_usec', KCSUBTYPE_TYPE.KC_ST_UINT64, 8)), | |
1209 | 'proc_starttime')) | |
1210 | ||
3e170ce0 A |
1211 | |
1212 | KNOWN_TYPES_COLLECTION[GetTypeForName('TASK_CRASHINFO_RUSAGE_INFO')] = KCTypeDescription(GetTypeForName('TASK_CRASHINFO_RUSAGE_INFO'), | |
1213 | ( | |
1214 | KCSubTypeElement('ri_uuid', KCSUBTYPE_TYPE.KC_ST_UINT8, KCSubTypeElement.GetSizeForArray(16, 1), 0, 1), | |
1215 | KCSubTypeElement.FromBasicCtype('ri_user_time', KCSUBTYPE_TYPE.KC_ST_UINT64, 16), | |
1216 | KCSubTypeElement.FromBasicCtype('ri_system_time', KCSUBTYPE_TYPE.KC_ST_UINT64, 24), | |
1217 | KCSubTypeElement.FromBasicCtype('ri_pkg_idle_wkups', KCSUBTYPE_TYPE.KC_ST_UINT64, 32), | |
1218 | KCSubTypeElement.FromBasicCtype('ri_interrupt_wkups', KCSUBTYPE_TYPE.KC_ST_UINT64, 40), | |
1219 | KCSubTypeElement.FromBasicCtype('ri_pageins', KCSUBTYPE_TYPE.KC_ST_UINT64, 48), | |
1220 | KCSubTypeElement.FromBasicCtype('ri_wired_size', KCSUBTYPE_TYPE.KC_ST_UINT64, 56), | |
1221 | KCSubTypeElement.FromBasicCtype('ri_resident_size', KCSUBTYPE_TYPE.KC_ST_UINT64, 64), | |
1222 | KCSubTypeElement.FromBasicCtype('ri_phys_footprint', KCSUBTYPE_TYPE.KC_ST_UINT64, 72), | |
1223 | KCSubTypeElement.FromBasicCtype('ri_proc_start_abstime', KCSUBTYPE_TYPE.KC_ST_UINT64, 80), | |
1224 | KCSubTypeElement.FromBasicCtype('ri_proc_exit_abstime', KCSUBTYPE_TYPE.KC_ST_UINT64, 88), | |
1225 | KCSubTypeElement.FromBasicCtype('ri_child_user_time', KCSUBTYPE_TYPE.KC_ST_UINT64, 96), | |
1226 | KCSubTypeElement.FromBasicCtype('ri_child_system_time', KCSUBTYPE_TYPE.KC_ST_UINT64, 104), | |
1227 | KCSubTypeElement.FromBasicCtype('ri_child_pkg_idle_wkups', KCSUBTYPE_TYPE.KC_ST_UINT64, 112), | |
1228 | KCSubTypeElement.FromBasicCtype('ri_child_interrupt_wkups', KCSUBTYPE_TYPE.KC_ST_UINT64, 120), | |
1229 | KCSubTypeElement.FromBasicCtype('ri_child_pageins', KCSUBTYPE_TYPE.KC_ST_UINT64, 128), | |
1230 | KCSubTypeElement.FromBasicCtype('ri_child_elapsed_abstime', KCSUBTYPE_TYPE.KC_ST_UINT64, 136), | |
1231 | KCSubTypeElement.FromBasicCtype('ri_diskio_bytesread', KCSUBTYPE_TYPE.KC_ST_UINT64, 144), | |
1232 | KCSubTypeElement.FromBasicCtype('ri_diskio_byteswritten', KCSUBTYPE_TYPE.KC_ST_UINT64, 152), | |
1233 | KCSubTypeElement.FromBasicCtype('ri_cpu_time_qos_default', KCSUBTYPE_TYPE.KC_ST_UINT64, 160), | |
1234 | KCSubTypeElement.FromBasicCtype('ri_cpu_time_qos_maintenance', KCSUBTYPE_TYPE.KC_ST_UINT64, 168), | |
1235 | KCSubTypeElement.FromBasicCtype('ri_cpu_time_qos_background', KCSUBTYPE_TYPE.KC_ST_UINT64, 176), | |
1236 | KCSubTypeElement.FromBasicCtype('ri_cpu_time_qos_utility', KCSUBTYPE_TYPE.KC_ST_UINT64, 184), | |
1237 | KCSubTypeElement.FromBasicCtype('ri_cpu_time_qos_legacy', KCSUBTYPE_TYPE.KC_ST_UINT64, 192), | |
1238 | KCSubTypeElement.FromBasicCtype('ri_cpu_time_qos_user_initiated', KCSUBTYPE_TYPE.KC_ST_UINT64, 200), | |
39037602 | 1239 | KCSubTypeElement.FromBasicCtype('ri_cpu_time_qos_user_interactiv', KCSUBTYPE_TYPE.KC_ST_UINT64, 208), |
3e170ce0 A |
1240 | KCSubTypeElement.FromBasicCtype('ri_billed_system_time', KCSUBTYPE_TYPE.KC_ST_UINT64, 216), |
1241 | KCSubTypeElement.FromBasicCtype('ri_serviced_system_time', KCSUBTYPE_TYPE.KC_ST_UINT64, 224) | |
1242 | ), | |
39037602 A |
1243 | 'rusage_info') |
1244 | ||
1245 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_CPU_TIMES')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_CPU_TIMES'), | |
1246 | ( | |
1247 | KCSubTypeElement.FromBasicCtype('user_usec', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
1248 | KCSubTypeElement.FromBasicCtype('system_usec', KCSUBTYPE_TYPE.KC_ST_UINT64, 8), | |
d9a64523 | 1249 | KCSubTypeElement.FromBasicCtype('runnable_usec', KCSUBTYPE_TYPE.KC_ST_UINT64, 16), |
39037602 A |
1250 | ), 'cpu_times') |
1251 | ||
1252 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_STACKSHOT_DURATION')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_STACKSHOT_DURATION'), | |
1253 | ( | |
1254 | KCSubTypeElement.FromBasicCtype('stackshot_duration', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
1255 | KCSubTypeElement.FromBasicCtype('stackshot_duration_outer', KCSUBTYPE_TYPE.KC_ST_UINT64, 8), | |
c3c9b80d | 1256 | KCSubTypeElement.FromBasicCtype('stackshot_duration_prior', KCSUBTYPE_TYPE.KC_ST_UINT64, 16), |
39037602 A |
1257 | ), 'stackshot_duration', merge=True |
1258 | ) | |
1259 | ||
1260 | KNOWN_TYPES_COLLECTION[GetTypeForName('KCDATA_TYPE_PROCNAME')] = ( | |
1261 | KCSubTypeElement("proc_name", KCSUBTYPE_TYPE.KC_ST_CHAR, KCSubTypeElement.GetSizeForArray(-1, 1), 0, 1)) | |
1262 | ||
1263 | KNOWN_TYPES_COLLECTION[GetTypeForName('KCDATA_TYPE_PID')] = ( | |
1264 | KCSubTypeElement('pid', KCSUBTYPE_TYPE.KC_ST_INT32, 4, 0, 0)) | |
1265 | ||
1266 | KNOWN_TYPES_COLLECTION[GetTypeForName('EXIT_REASON_SNAPSHOT')] = KCTypeDescription(GetTypeForName('EXIT_REASON_SNAPSHOT'), | |
1267 | ( | |
1268 | KCSubTypeElement.FromBasicCtype('ers_namespace', KCSUBTYPE_TYPE.KC_ST_UINT32, 0), | |
1269 | KCSubTypeElement.FromBasicCtype('ers_code', KCSUBTYPE_TYPE.KC_ST_UINT64, 4), | |
1270 | KCSubTypeElement.FromBasicCtype('ers_flags', KCSUBTYPE_TYPE.KC_ST_UINT64, 12), | |
1271 | ), 'exit_reason_basic_info') | |
1272 | ||
1273 | KNOWN_TYPES_COLLECTION[GetTypeForName('EXIT_REASON_USER_DESC')] = ( | |
1274 | KCSubTypeElement("exit_reason_user_description", KCSUBTYPE_TYPE.KC_ST_CHAR, KCSubTypeElement.GetSizeForArray(-1, 1), 0, 1)) | |
1275 | ||
1276 | KNOWN_TYPES_COLLECTION[GetTypeForName('EXIT_REASON_USER_PAYLOAD')] = KCSubTypeElement('exit_reason_user_payload', | |
1277 | KCSUBTYPE_TYPE.KC_ST_UINT8, KCSubTypeElement.GetSizeForArray(-1, 1), 0, 1) | |
1278 | ||
1279 | KNOWN_TYPES_COLLECTION[GetTypeForName('EXIT_REASON_CODESIGNING_INFO')] = KCTypeDescription(GetTypeForName('EXIT_REASON_CODESIGNING_INFO'), | |
1280 | ( | |
1281 | KCSubTypeElement.FromBasicCtype('ceri_virt_addr', KCSUBTYPE_TYPE.KC_ST_UINT64, 0), | |
1282 | KCSubTypeElement.FromBasicCtype('ceri_file_offset', KCSUBTYPE_TYPE.KC_ST_UINT64, 8), | |
1283 | KCSubTypeElement("ceri_pathname", KCSUBTYPE_TYPE.KC_ST_CHAR, KCSubTypeElement.GetSizeForArray(1024, 1), 16, 1), | |
1284 | KCSubTypeElement("ceri_filename", KCSUBTYPE_TYPE.KC_ST_CHAR, KCSubTypeElement.GetSizeForArray(1024, 1), 1040, 1), | |
1285 | KCSubTypeElement.FromBasicCtype('ceri_codesig_modtime_secs', KCSUBTYPE_TYPE.KC_ST_UINT64, 2064), | |
1286 | KCSubTypeElement.FromBasicCtype('ceri_codesig_modtime_nsecs', KCSUBTYPE_TYPE.KC_ST_UINT64, 2072), | |
1287 | KCSubTypeElement.FromBasicCtype('ceri_page_modtime_secs', KCSUBTYPE_TYPE.KC_ST_UINT64, 2080), | |
1288 | KCSubTypeElement.FromBasicCtype('ceri_page_modtime_nsecs', KCSUBTYPE_TYPE.KC_ST_UINT64, 2088), | |
1289 | KCSubTypeElement.FromBasicCtype('ceri_path_truncated', KCSUBTYPE_TYPE.KC_ST_UINT8, 2096), | |
1290 | KCSubTypeElement.FromBasicCtype('ceri_object_codesigned', KCSUBTYPE_TYPE.KC_ST_UINT8, 2097), | |
1291 | KCSubTypeElement.FromBasicCtype('ceri_page_codesig_validated', KCSUBTYPE_TYPE.KC_ST_UINT8, 2098), | |
1292 | KCSubTypeElement.FromBasicCtype('ceri_page_codesig_tainted', KCSUBTYPE_TYPE.KC_ST_UINT8, 2099), | |
1293 | KCSubTypeElement.FromBasicCtype('ceri_page_codesig_nx', KCSUBTYPE_TYPE.KC_ST_UINT8, 2100), | |
1294 | KCSubTypeElement.FromBasicCtype('ceri_page_wpmapped', KCSUBTYPE_TYPE.KC_ST_UINT8, 2101), | |
1295 | KCSubTypeElement.FromBasicCtype('ceri_page_slid', KCSUBTYPE_TYPE.KC_ST_UINT8, 2102), | |
1296 | KCSubTypeElement.FromBasicCtype('ceri_page_dirty', KCSUBTYPE_TYPE.KC_ST_UINT8, 2103), | |
1297 | KCSubTypeElement.FromBasicCtype('ceri_page_shadow_depth', KCSUBTYPE_TYPE.KC_ST_UINT32, 2104), | |
1298 | ), 'exit_reason_codesigning_info') | |
1299 | ||
5ba3f43e A |
1300 | KNOWN_TYPES_COLLECTION[GetTypeForName('EXIT_REASON_WORKLOOP_ID')] = ( |
1301 | KCSubTypeElement('exit_reason_workloop_id', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0, KCSubTypeElement._get_naked_element_value)) | |
1302 | ||
1303 | KNOWN_TYPES_COLLECTION[GetTypeForName('EXIT_REASON_DISPATCH_QUEUE_NO')] = ( | |
1304 | KCSubTypeElement('exit_reason_dispatch_queue_no', KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0, KCSubTypeElement._get_naked_element_value)) | |
3e170ce0 | 1305 | |
d9a64523 A |
1306 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_ASID')] = ( |
1307 | KCSubTypeElement('ts_asid', KCSUBTYPE_TYPE.KC_ST_UINT32, 4, 0, 0)) | |
1308 | ||
1309 | KNOWN_TYPES_COLLECTION[GetTypeForName('STACKSHOT_KCTYPE_PAGE_TABLES')] = KCTypeDescription(GetTypeForName('STACKSHOT_KCTYPE_PAGE_TABLES'), ( | |
1310 | KCSubTypeElement(None, KCSUBTYPE_TYPE.KC_ST_UINT64, 8, 0, 0, KCSubTypeElement._get_naked_element_value), ), | |
1311 | 'ts_pagetable', | |
1312 | merge=True, | |
1313 | naked=True | |
1314 | ) | |
1315 | ||
3e170ce0 | 1316 | def GetSecondsFromMATime(mat, tb): |
cb323159 | 1317 | return (float(long(mat) * tb['numer']) / tb['denom']) / 1e9 |
3e170ce0 A |
1318 | |
1319 | def FindLibraryForAddress(liblist, address): | |
1320 | current_lib = None | |
1321 | for l in liblist: | |
1322 | if address >= l[1]: | |
1323 | current_lib = l | |
1324 | return current_lib | |
1325 | ||
1326 | def FindIndexOfLibInCatalog(catalog, lib): | |
1327 | index = None | |
1328 | i = 0 | |
1329 | for l in catalog: | |
1330 | if l[0] == lib[0] and l[1] == lib[1]: | |
1331 | index = i | |
1332 | break | |
1333 | i += 1 | |
1334 | ||
1335 | if index is None: | |
1336 | catalog.append(lib) | |
1337 | index = len(catalog) - 1 | |
1338 | ||
1339 | return index | |
1340 | ||
1341 | def GetOffsetOfAddressForLib(lib, address): | |
1342 | return (address - lib[1]) | |
1343 | ||
1344 | def GetSymbolInfoForFrame(catalog, liblist, address): | |
1345 | lib = FindLibraryForAddress(liblist, address) | |
1346 | if not lib: | |
1347 | lib = ["00000000000000000000000000000000",0,"A"] | |
1348 | offset = GetOffsetOfAddressForLib(lib, address) | |
1349 | index = FindIndexOfLibInCatalog(catalog, lib) | |
1350 | return [index, offset] | |
1351 | ||
1352 | def GetStateDescription(s): | |
1353 | retval = [] | |
1354 | TH_WAIT = 0x01 | |
1355 | TH_SUSP = 0x02 | |
1356 | TH_RUN = 0x04 | |
1357 | TH_UNINT = 0x08 | |
1358 | TH_TERMINATE = 0x10 | |
1359 | TH_TERMINATE2 = 0x20 | |
d9a64523 | 1360 | TH_WAIT_REPORT = 0x40 |
3e170ce0 A |
1361 | TH_IDLE = 0x80 |
1362 | if (s & TH_WAIT): | |
1363 | retval.append("TH_WAIT") | |
1364 | if (s & TH_SUSP): | |
1365 | retval.append("TH_SUSP") | |
1366 | if (s & TH_RUN): | |
1367 | retval.append("TH_RUN") | |
1368 | if (s & TH_UNINT): | |
1369 | retval.append("TH_UNINT") | |
1370 | if (s & TH_TERMINATE): | |
1371 | retval.append("TH_TERMINATE") | |
1372 | if (s & TH_TERMINATE2): | |
1373 | retval.append("TH_TERMINATE2") | |
d9a64523 A |
1374 | if (s & TH_WAIT_REPORT): |
1375 | retval.append("TH_WAIT_REPORT") | |
3e170ce0 A |
1376 | if (s & TH_IDLE): |
1377 | retval.append("TH_IDLE") | |
1378 | return retval | |
1379 | ||
39037602 A |
1380 | |
1381 | def format_uuid(elementValues): | |
1382 | return ''.join("%02x" % i for i in elementValues) | |
1383 | ||
5ba3f43e A |
1384 | kThreadWaitNone = 0x00 |
1385 | kThreadWaitKernelMutex = 0x01 | |
1386 | kThreadWaitPortReceive = 0x02 | |
1387 | kThreadWaitPortSetReceive = 0x03 | |
1388 | kThreadWaitPortSend = 0x04 | |
1389 | kThreadWaitPortSendInTransit = 0x05 | |
1390 | kThreadWaitSemaphore = 0x06 | |
1391 | kThreadWaitKernelRWLockRead = 0x07 | |
1392 | kThreadWaitKernelRWLockWrite = 0x08 | |
1393 | kThreadWaitKernelRWLockUpgrade = 0x09 | |
1394 | kThreadWaitUserLock = 0x0a | |
1395 | kThreadWaitPThreadMutex = 0x0b | |
1396 | kThreadWaitPThreadRWLockRead = 0x0c | |
1397 | kThreadWaitPThreadRWLockWrite = 0x0d | |
1398 | kThreadWaitPThreadCondVar = 0x0e | |
1399 | kThreadWaitParkedWorkQueue = 0x0f | |
1400 | kThreadWaitWorkloopSyncWait = 0x10 | |
d9a64523 | 1401 | kThreadWaitOnProcess = 0x11 |
f427ee49 A |
1402 | kThreadWaitSleepWithInheritor = 0x12 |
1403 | kThreadWaitEventlink = 0x13 | |
ea3f0419 | 1404 | kThreadWaitCompressor = 0x14 |
5ba3f43e A |
1405 | |
1406 | ||
1407 | UINT64_MAX = 0xffffffffffffffff | |
1408 | STACKSHOT_WAITOWNER_KERNEL = (UINT64_MAX - 1) | |
1409 | STACKSHOT_WAITOWNER_PORT_LOCKED = (UINT64_MAX - 2) | |
1410 | STACKSHOT_WAITOWNER_PSET_LOCKED = (UINT64_MAX - 3) | |
1411 | STACKSHOT_WAITOWNER_INTRANSIT = (UINT64_MAX - 4) | |
1412 | STACKSHOT_WAITOWNER_MTXSPIN = (UINT64_MAX - 5) | |
1413 | STACKSHOT_WAITOWNER_THREQUESTED = (UINT64_MAX - 6) | |
1414 | STACKSHOT_WAITOWNER_SUSPENDED = (UINT64_MAX - 7) | |
1415 | ||
f427ee49 A |
1416 | STACKSHOT_TURNSTILE_STATUS_UNKNOWN = 0x01 |
1417 | STACKSHOT_TURNSTILE_STATUS_LOCKED_WAITQ = 0x02 | |
1418 | STACKSHOT_TURNSTILE_STATUS_WORKQUEUE = 0x04 | |
1419 | STACKSHOT_TURNSTILE_STATUS_THREAD = 0x08 | |
1420 | STACKSHOT_TURNSTILE_STATUS_BLOCKED_ON_TASK = 0x10 | |
1421 | STACKSHOT_TURNSTILE_STATUS_HELD_IPLOCK = 0x20 | |
cb323159 | 1422 | |
5ba3f43e A |
1423 | def formatWaitInfo(info): |
1424 | s = 'thread %d: ' % info['waiter']; | |
1425 | type = info['wait_type'] | |
1426 | context = info['context'] | |
1427 | owner = info['owner'] | |
1428 | if type == kThreadWaitKernelMutex: | |
1429 | s += 'kernel mutex %x' % context | |
1430 | if owner == STACKSHOT_WAITOWNER_MTXSPIN: | |
1431 | s += " in spin mode" | |
1432 | elif owner: | |
1433 | s += " owned by thread %u" % owner | |
1434 | else: | |
1435 | s += "with unknown owner" | |
1436 | elif type == kThreadWaitPortReceive: | |
1437 | s += "mach_msg receive on " | |
1438 | if owner == STACKSHOT_WAITOWNER_PORT_LOCKED: | |
1439 | s += "locked port %x" % context | |
1440 | elif owner == STACKSHOT_WAITOWNER_INTRANSIT: | |
1441 | s += "intransit port %x" % context | |
1442 | elif owner: | |
1443 | s += "port %x name %x" % (context, owner) | |
1444 | else: | |
1445 | s += "port %x" % context | |
1446 | elif type == kThreadWaitPortSetReceive: | |
1447 | if owner == STACKSHOT_WAITOWNER_PSET_LOCKED: | |
1448 | s += "mach_msg receive on locked port set %x" % context | |
1449 | else: | |
1450 | s += "mach_msg receive on port set %x" % context | |
1451 | elif type == kThreadWaitPortSend: | |
1452 | s += "mach_msg send on " | |
1453 | if owner == STACKSHOT_WAITOWNER_PORT_LOCKED: | |
1454 | s += "locked port %x" % context | |
1455 | elif owner == STACKSHOT_WAITOWNER_INTRANSIT: | |
1456 | s += "intransit port %x" % context | |
1457 | elif owner == STACKSHOT_WAITOWNER_KERNEL: | |
1458 | s += "port %x owned by kernel" % context | |
1459 | elif owner: | |
1460 | s += "port %x owned by pid %d" % (context, owner) | |
1461 | else: | |
1462 | s += "port %x with unknown owner" % context | |
1463 | elif type == kThreadWaitPortSendInTransit: | |
1464 | s += "mach_msg send on port %x in transit to " % context | |
1465 | if owner: | |
1466 | s += "port %x" % owner | |
1467 | else: | |
1468 | s += "unknown port" | |
1469 | elif type == kThreadWaitSemaphore: | |
a39ff7e2 | 1470 | s += "semaphore port %x " % context |
5ba3f43e A |
1471 | if owner: |
1472 | s += "owned by pid %d" % owner | |
1473 | else: | |
1474 | s += "with unknown owner" | |
1475 | elif type == kThreadWaitKernelRWLockRead: | |
1476 | s += "krwlock %x for reading" % context | |
1477 | elif type == kThreadWaitKernelRWLockWrite: | |
1478 | s += "krwlock %x for writing" % context | |
1479 | elif type == kThreadWaitKernelRWLockUpgrade: | |
1480 | s += "krwlock %x for upgrading" % context | |
1481 | elif type == kThreadWaitUserLock: | |
1482 | if owner: | |
a39ff7e2 | 1483 | s += "unfair lock %x owned by thread %d" % (context, owner) |
5ba3f43e A |
1484 | else: |
1485 | s += "spin lock %x" % context | |
1486 | elif type == kThreadWaitPThreadMutex: | |
1487 | s += "pthread mutex %x" % context | |
1488 | if owner: | |
a39ff7e2 | 1489 | s += " owned by thread %d" % owner |
5ba3f43e A |
1490 | else: |
1491 | s += " with unknown owner" | |
1492 | elif type == kThreadWaitPThreadRWLockRead: | |
1493 | s += "pthread rwlock %x for reading" % context | |
1494 | elif type == kThreadWaitPThreadRWLockWrite: | |
1495 | s += "pthread rwlock %x for writing" % context | |
1496 | elif type == kThreadWaitPThreadCondVar: | |
1497 | s += "pthread condvar %x" % context | |
1498 | elif type == kThreadWaitWorkloopSyncWait: | |
1499 | s += "workloop sync wait" | |
1500 | if owner == STACKSHOT_WAITOWNER_SUSPENDED: | |
1501 | s += ", suspended" | |
1502 | elif owner == STACKSHOT_WAITOWNER_THREQUESTED: | |
1503 | s += ", thread requested" | |
1504 | elif owner != 0: | |
1505 | s += ", owned by thread %u" % owner | |
1506 | else: | |
1507 | s += ", unknown owner" | |
1508 | s += ", workloop id %x" % context | |
d9a64523 | 1509 | elif type == kThreadWaitOnProcess: |
cb323159 A |
1510 | if owner == 2**64-1: |
1511 | s += "waitpid, for any children" | |
1512 | elif 2**32 <= owner and owner < 2**64-1: | |
1513 | s += "waitpid, for process group %d" % abs(owner - 2**64) | |
1514 | else: | |
1515 | s += "waitpid, for pid %d" % owner | |
f427ee49 A |
1516 | elif type == kThreadWaitSleepWithInheritor: |
1517 | if owner == 0: | |
1518 | s += "turnstile, held waitq" | |
1519 | else: | |
1520 | s += "turnstile, pushing thread %d" % owner | |
1521 | elif type == kThreadWaitEventlink: | |
1522 | if owner == 0: | |
1523 | s += "eventlink, held waitq" | |
1524 | else: | |
1525 | s += "eventlink, signaled by thread %d" % owner | |
ea3f0419 A |
1526 | elif type == kThreadWaitCompressor: |
1527 | s += "in compressor segment %x, busy for thread %d" % (context, owner) | |
d9a64523 | 1528 | |
5ba3f43e A |
1529 | else: |
1530 | s += "unknown type %d (owner %d, context %x)" % (type, owner, context) | |
1531 | ||
1532 | return s | |
cb323159 A |
1533 | |
1534 | def formatTurnstileInfo(ti): | |
1535 | if ti is None: | |
1536 | return " [no turnstile]" | |
1537 | ||
1538 | ts_flags = int(ti['turnstile_flags']) | |
1539 | ctx = int(ti['turnstile_context']) | |
1540 | hop = int(ti['number_of_hops']) | |
1541 | prio = int(ti['turnstile_priority']) | |
f427ee49 A |
1542 | if ts_flags & STACKSHOT_TURNSTILE_STATUS_HELD_IPLOCK: |
1543 | return " [turnstile blocked on task, but ip_lock was held]" | |
1544 | if ts_flags & STACKSHOT_TURNSTILE_STATUS_BLOCKED_ON_TASK: | |
1545 | return " [turnstile blocked on task pid %d, hops: %d, priority: %d]" % (ctx, hop, prio) | |
cb323159 A |
1546 | if ts_flags & STACKSHOT_TURNSTILE_STATUS_LOCKED_WAITQ: |
1547 | return " [turnstile was in process of being updated]" | |
1548 | if ts_flags & STACKSHOT_TURNSTILE_STATUS_WORKQUEUE: | |
1549 | return " [blocked on workqueue: 0x%x, hops: %x, priority: %d]" % (ctx, hop, prio) | |
1550 | if ts_flags & STACKSHOT_TURNSTILE_STATUS_THREAD: | |
1551 | return " [blocked on: %d, hops: %x, priority: %d]" % (ctx, hop, prio) | |
1552 | if ts_flags & STACKSHOT_TURNSTILE_STATUS_UNKNOWN: | |
1553 | return " [turnstile with unknown inheritor]" | |
1554 | ||
1555 | return " [unknown turnstile status!]" | |
5ba3f43e | 1556 | |
cb323159 A |
1557 | def formatWaitInfoWithTurnstiles(waitinfos, tsinfos): |
1558 | wis_tis = [] | |
1559 | for w in waitinfos: | |
1560 | found_pair = False | |
1561 | for t in tsinfos: | |
1562 | if int(w['waiter']) == int(t['waiter']): | |
1563 | wis_tis.append((w, t)) | |
1564 | found_pair = True | |
1565 | break | |
1566 | if not found_pair: | |
1567 | wis_tis.append((w, None)) | |
1568 | ||
1569 | return map(lambda (wi, ti): formatWaitInfo(wi) + formatTurnstileInfo(ti), wis_tis) | |
5ba3f43e | 1570 | |
0a7de745 | 1571 | def SaveStackshotReport(j, outfile_name, incomplete): |
3e170ce0 A |
1572 | import time |
1573 | from operator import itemgetter, attrgetter | |
39037602 | 1574 | ss = j.get('kcdata_stackshot') |
3e170ce0 A |
1575 | if not ss: |
1576 | print "No KCDATA_BUFFER_BEGIN_STACKSHOT object found. Skipping writing report." | |
1577 | return | |
5c9f4661 | 1578 | |
f427ee49 | 1579 | timestamp = ss.get('usecs_since_epoch') |
5c9f4661 | 1580 | try: |
f427ee49 | 1581 | timestamp = time.strftime("%Y-%m-%d %H:%M:%S +0000",time.gmtime(timestamp / 1000000 if timestamp else None)) |
5c9f4661 A |
1582 | except ValueError, e: |
1583 | print "couldn't convert timestamp:", str(e) | |
1584 | timestamp = None | |
1585 | ||
3e170ce0 | 1586 | os_version = ss.get('osversion', 'Unknown') |
39037602 | 1587 | timebase = ss.get('mach_timebase_info', {"denom": 1, "numer": 1}) |
39037602 | 1588 | |
0a7de745 A |
1589 | dsc_common = None |
1590 | shared_cache_info = ss.get('shared_cache_dyld_load_info') | |
1591 | if shared_cache_info: | |
1592 | shared_cache_base_addr = shared_cache_info['imageSlidBaseAddress'] | |
1593 | dsc_common = [format_uuid(shared_cache_info['imageUUID']), shared_cache_info['imageSlidBaseAddress'], "S" ] | |
1594 | print "Shared cache UUID found from the binary data is <%s> " % str(dsc_common[0]) | |
d9a64523 A |
1595 | |
1596 | dsc_layout = ss.get('system_shared_cache_layout') | |
3e170ce0 A |
1597 | |
1598 | dsc_libs = [] | |
0a7de745 | 1599 | if dsc_layout: |
d9a64523 A |
1600 | print "Found in memory system shared cache layout with {} images".format(len(dsc_layout)) |
1601 | slide = ss.get('shared_cache_dyld_load_info')['imageLoadAddress'] | |
1602 | ||
1603 | for image in dsc_layout: | |
1604 | dsc_libs.append([format_uuid(image['imageUUID']), image['imageLoadAddress'] + slide, "C"]) | |
3e170ce0 A |
1605 | |
1606 | AllImageCatalog = [] | |
1607 | obj = {} | |
1608 | obj["kernel"] = os_version | |
5c9f4661 A |
1609 | if timestamp is not None: |
1610 | obj["date"] = timestamp | |
3e170ce0 A |
1611 | obj["reason"] = "kernel panic stackshot" |
1612 | obj["incident"] = "ABCDEFGH-1234-56IJ-789K-0LMNOPQRSTUV" | |
1613 | obj["crashReporterKey"] = "12ab34cd45aabbccdd6712ab34cd45aabbccdd67" | |
39037602 | 1614 | obj["bootArgs"] = ss.get('boot_args','') |
3e170ce0 A |
1615 | obj["frontmostPids"] = [0] |
1616 | obj["exception"] = "0xDEADF157" | |
1617 | obj["processByPid"] = {} | |
5ba3f43e A |
1618 | |
1619 | if incomplete: | |
1620 | obj["reason"] = "!!!INCOMPLETE!!! kernel panic stackshot" | |
1621 | obj["notes"] = "This stackshot report generated from incomplete data! Some information is missing! " | |
1622 | ||
3e170ce0 | 1623 | processByPid = obj["processByPid"] |
39037602 | 1624 | ssplist = ss.get('task_snapshots', {}) |
3e170ce0 A |
1625 | kern_load_info = [] |
1626 | if "0" in ssplist: | |
39037602 A |
1627 | kc_uuid = ssplist["0"].get('kernelcache_load_info', None) |
1628 | if kc_uuid: | |
1629 | kernelcache_uuid = [format_uuid(kc_uuid['imageUUID']), kc_uuid['imageLoadAddress'], "U" ] | |
1630 | kern_load_info.append(kernelcache_uuid) | |
1631 | ||
3e170ce0 A |
1632 | kl_infos = ssplist["0"].get("dyld_load_info", []) |
1633 | for dlinfo in kl_infos: | |
39037602 | 1634 | kern_load_info.append([format_uuid(dlinfo['imageUUID']), dlinfo['imageLoadAddress'], "K"]) |
f427ee49 A |
1635 | |
1636 | kl_infos_text_exec = ssplist["0"].get("dyld_load_info_text_exec", []) | |
1637 | for dlinfo in kl_infos_text_exec: | |
1638 | kern_load_info.append([format_uuid(dlinfo['imageUUID']), dlinfo['imageLoadAddress'], "T"]) | |
1639 | ||
3e170ce0 A |
1640 | for pid,piddata in ssplist.iteritems(): |
1641 | processByPid[str(pid)] = {} | |
1642 | tsnap = processByPid[str(pid)] | |
1643 | pr_lib_dsc = dsc_common | |
39037602 A |
1644 | if 'shared_cache_dyld_load_info' in tsnap: |
1645 | if 'imageSlidBaseAddress' in tsnap.get('shared_cache_dyld_load_info'): | |
1646 | shared_cache_base_addr = tsnap.get('shared_cache_dyld_load_info')['imageSlidBaseAddress'] | |
1647 | else: | |
1648 | print "Specific task shared cache format does not include slid shared cache base address. Skipping writing report." | |
1649 | return | |
1650 | ||
1651 | pr_lib_dsc = [format_uuid(tsnap.get('shared_cache_dyld_load_info')['imageUUID']), | |
1652 | tsnap.get('shared_cache_dyld_load_info')['imageSlidBaseAddress'], | |
0a7de745 | 1653 | "S"] |
3e170ce0 A |
1654 | |
1655 | pr_libs = [] | |
0a7de745 | 1656 | if len(dsc_libs) == 0 and pr_lib_dsc: |
3e170ce0 A |
1657 | pr_libs.append(pr_lib_dsc) |
1658 | _lib_type = "P" | |
1659 | if int(pid) == 0: | |
1660 | _lib_type = "K" | |
1661 | pr_libs = [] | |
1662 | else: | |
1663 | for dlinfo in piddata.get('dyld_load_info',[]): | |
39037602 | 1664 | pr_libs.append([format_uuid(dlinfo['imageUUID']), dlinfo['imageLoadAddress'], _lib_type]) |
3e170ce0 A |
1665 | |
1666 | pr_libs.extend(kern_load_info) | |
1667 | pr_libs.extend(dsc_libs) | |
1668 | ||
1669 | pr_libs.sort(key=itemgetter(1)) | |
1670 | ||
5ba3f43e A |
1671 | if 'task_snapshot' not in piddata: |
1672 | continue | |
39037602 A |
1673 | tasksnap = piddata['task_snapshot'] |
1674 | tsnap["pid"] = tasksnap["ts_pid"] | |
d9a64523 A |
1675 | if 'ts_asid' in piddata: |
1676 | tsnap["asid"] = piddata["ts_asid"] | |
1677 | ||
1678 | if 'ts_pagetable' in piddata: | |
1679 | pagetables = [] | |
1680 | for tte in piddata["ts_pagetable"]: | |
1681 | pagetables.append(tte) | |
1682 | tsnap["pageTables"] = pagetables | |
1683 | ||
39037602 A |
1684 | tsnap["residentMemoryBytes"] = tasksnap["ts_task_size"] |
1685 | tsnap["timesDidThrottle"] = tasksnap["ts_did_throttle"] | |
1686 | tsnap["systemTimeTask"] = GetSecondsFromMATime(tasksnap["ts_system_time_in_terminated_th"], timebase) | |
1687 | tsnap["pageIns"] = tasksnap["ts_pageins"] | |
1688 | tsnap["pageFaults"] = tasksnap["ts_faults"] | |
1689 | tsnap["userTimeTask"] = GetSecondsFromMATime(tasksnap[ "ts_user_time_in_terminated_thre"], timebase) | |
1690 | tsnap["procname"] = tasksnap["ts_p_comm"] | |
1691 | tsnap["copyOnWriteFaults"] = tasksnap["ts_cow_faults"] | |
1692 | tsnap["timesThrottled"] = tasksnap["ts_was_throttled"] | |
3e170ce0 A |
1693 | tsnap["threadById"] = {} |
1694 | threadByID = tsnap["threadById"] | |
39037602 | 1695 | thlist = piddata.get('thread_snapshots', {}) |
3e170ce0 A |
1696 | for tid,thdata in thlist.iteritems(): |
1697 | threadByID[str(tid)] = {} | |
1698 | thsnap = threadByID[str(tid)] | |
39037602 | 1699 | if "thread_snapshot" not in thdata: |
4bd07ac2 A |
1700 | print "Found broken thread state for thread ID: %s." % tid |
1701 | break | |
39037602 A |
1702 | threadsnap = thdata["thread_snapshot"] |
1703 | thsnap["userTime"] = GetSecondsFromMATime(threadsnap["ths_user_time"], timebase) | |
1704 | thsnap["id"] = threadsnap["ths_thread_id"] | |
1705 | thsnap["basePriority"] = threadsnap["ths_base_priority"] | |
1706 | thsnap["systemTime"] = threadsnap["ths_sys_time"] | |
1707 | thsnap["schedPriority"] = threadsnap["ths_sched_priority"] | |
1708 | thsnap["state"] = GetStateDescription(threadsnap['ths_state']) | |
1709 | thsnap["qosEffective"] = threadsnap["ths_eqos"] | |
1710 | thsnap["qosRequested"] = threadsnap["ths_rqos"] | |
1711 | ||
cb323159 A |
1712 | if "pth_name" in thdata: |
1713 | thsnap["name"] = thdata["pth_name"]; | |
1714 | ||
39037602 A |
1715 | if threadsnap['ths_continuation']: |
1716 | thsnap["continuation"] = GetSymbolInfoForFrame(AllImageCatalog, pr_libs, threadsnap['ths_continuation']) | |
3e170ce0 A |
1717 | if "kernel_stack_frames" in thdata: |
1718 | kuserframes = [] | |
1719 | for f in thdata["kernel_stack_frames"]: | |
1720 | kuserframes.append(GetSymbolInfoForFrame(AllImageCatalog, pr_libs, f['lr'])) | |
1721 | thsnap["kernelFrames"] = kuserframes | |
1722 | ||
1723 | if "user_stack_frames" in thdata: | |
1724 | uframes = [] | |
1725 | for f in thdata["user_stack_frames"]: | |
1726 | uframes.append(GetSymbolInfoForFrame(AllImageCatalog, pr_libs, f['lr'])) | |
1727 | thsnap["userFrames"] = uframes | |
d9a64523 A |
1728 | |
1729 | if "user_stacktop" in thdata: | |
1730 | (address,) = struct.unpack("<Q", struct.pack("B"*8, *thdata["user_stacktop"]["stack_contents"])) | |
1731 | thsnap["userStacktop"] = GetSymbolInfoForFrame(AllImageCatalog, pr_libs, address) | |
1732 | ||
39037602 A |
1733 | if threadsnap['ths_wait_event']: |
1734 | thsnap["waitEvent"] = GetSymbolInfoForFrame(AllImageCatalog, pr_libs, threadsnap['ths_wait_event']) | |
3e170ce0 | 1735 | |
cb323159 A |
1736 | if 'thread_waitinfo' in piddata and 'thread_turnstileinfo' in piddata: |
1737 | tsnap['waitInfo'] = formatWaitInfoWithTurnstiles(piddata['thread_waitinfo'] , piddata['thread_turnstileinfo']) | |
1738 | elif 'thread_waitinfo' in piddata: | |
5ba3f43e A |
1739 | tsnap['waitInfo'] = map(formatWaitInfo, piddata['thread_waitinfo']) |
1740 | ||
3e170ce0 | 1741 | obj['binaryImages'] = AllImageCatalog |
5ba3f43e A |
1742 | if outfile_name == '-': |
1743 | fh = sys.stdout | |
1744 | else: | |
1745 | fh = open(outfile_name, "w") | |
5c9f4661 A |
1746 | |
1747 | header = {} | |
1748 | header['bug_type'] = 288 | |
1749 | if timestamp is not None: | |
1750 | header['timestamp'] = timestamp | |
1751 | header['os_version'] = os_version | |
1752 | fh.write(json.dumps(header)) | |
1753 | fh.write("\n") | |
1754 | ||
3e170ce0 A |
1755 | fh.write(json.dumps(obj, sort_keys=False, indent=2, separators=(',', ': '))) |
1756 | fh.close() | |
1757 | ||
1758 | ## Base utils for interacting with shell ## | |
1759 | def RunCommand(bash_cmd_string, get_stderr = True): | |
1760 | """ | |
1761 | returns: (int,str) : exit_code and output_str | |
1762 | """ | |
1763 | print "RUNNING: %s" % bash_cmd_string | |
1764 | cmd_args = shlex.split(bash_cmd_string) | |
1765 | output_str = "" | |
1766 | exit_code = 0 | |
1767 | try: | |
1768 | if get_stderr: | |
1769 | output_str = subprocess.check_output(cmd_args, stderr=subprocess.STDOUT) | |
1770 | else: | |
1771 | output_str = subprocess.check_output(cmd_args, stderr=None) | |
1772 | except subprocess.CalledProcessError, e: | |
1773 | exit_code = e.returncode | |
1774 | finally: | |
1775 | return (exit_code, output_str) | |
1776 | ||
3e170ce0 | 1777 | |
39037602 A |
1778 | @contextlib.contextmanager |
1779 | def data_from_stream(stream): | |
1780 | try: | |
1781 | fmap = mmap.mmap(stream.fileno(), 0, mmap.MAP_SHARED, mmap.PROT_READ) | |
1782 | except: | |
1783 | yield stream.read() | |
1784 | else: | |
1785 | try: | |
1786 | yield fmap | |
1787 | finally: | |
1788 | fmap.close() | |
1789 | ||
1790 | def iterate_kcdatas(kcdata_file): | |
1791 | with data_from_stream(kcdata_file) as data: | |
1792 | iterator = kcdata_item_iterator(data) | |
1793 | kcdata_buffer = KCObject.FromKCItem(iterator.next()) | |
f427ee49 A |
1794 | |
1795 | if isinstance(kcdata_buffer, KCCompressedBufferObject): | |
1796 | kcdata_buffer.ReadItems(iterator) | |
1797 | decompressed = kcdata_buffer.Decompress(data) | |
1798 | iterator = kcdata_item_iterator(decompressed) | |
1799 | kcdata_buffer = KCObject.FromKCItem(iterator.next()) | |
1800 | ||
cb323159 | 1801 | if not isinstance(kcdata_buffer, KCBufferObject): |
f427ee49 | 1802 | # ktrace stackshot chunk |
cb323159 A |
1803 | iterator = kcdata_item_iterator(data[16:]) |
1804 | kcdata_buffer = KCObject.FromKCItem(iterator.next()) | |
f427ee49 | 1805 | |
39037602 A |
1806 | if not isinstance(kcdata_buffer, KCBufferObject): |
1807 | try: | |
1808 | decoded = base64.b64decode(data) | |
1809 | except: | |
1810 | pass | |
1811 | else: | |
1812 | iterator = kcdata_item_iterator(decoded) | |
1813 | kcdata_buffer = KCObject.FromKCItem(iterator.next()) | |
1814 | if not isinstance(kcdata_buffer, KCBufferObject): | |
1815 | import gzip | |
1816 | from io import BytesIO | |
1817 | try: | |
1818 | decompressed = gzip.GzipFile(fileobj=BytesIO(data[:])).read() | |
1819 | except: | |
1820 | pass | |
1821 | else: | |
1822 | iterator = kcdata_item_iterator(decompressed) | |
1823 | kcdata_buffer = KCObject.FromKCItem(iterator.next()) | |
f427ee49 | 1824 | |
39037602 A |
1825 | if not isinstance(kcdata_buffer, KCBufferObject): |
1826 | raise Exception, "unknown file type" | |
1827 | ||
f427ee49 | 1828 | |
39037602 A |
1829 | kcdata_buffer.ReadItems(iterator) |
1830 | yield kcdata_buffer | |
1831 | ||
1832 | for magic in iterator: | |
1833 | kcdata_buffer = KCObject.FromKCItem(magic) | |
cb323159 A |
1834 | if kcdata_buffer.i_type == 0: |
1835 | continue | |
39037602 A |
1836 | if not isinstance(kcdata_buffer, KCBufferObject): |
1837 | raise Exception, "unknown file type" | |
1838 | kcdata_buffer.ReadItems(iterator) | |
1839 | yield kcdata_buffer | |
1840 | ||
3e170ce0 | 1841 | |
5ba3f43e A |
1842 | def prettify(data): |
1843 | if isinstance(data, list): | |
1844 | return map(prettify, data); | |
1845 | ||
1846 | elif isinstance(data, dict): | |
1847 | newdata = dict() | |
1848 | for key, value in data.items(): | |
1849 | if 'uuid' in key.lower() and isinstance(value, list) and len(value) == 16: | |
1850 | value = '%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X' % tuple(value) | |
1851 | elif 'address' in key.lower() and isinstance(value, (int, long)): | |
1852 | value = '0x%X' % value | |
c3c9b80d | 1853 | elif key == 'lr' or key == 'sharedCacheSlidFirstMapping': |
d9a64523 | 1854 | value = '0x%X' % value |
a39ff7e2 A |
1855 | elif key == 'thread_waitinfo': |
1856 | value = map(formatWaitInfo, value) | |
d9a64523 | 1857 | elif key == 'stack_contents': |
d9a64523 A |
1858 | (address,) = struct.unpack("<Q", struct.pack("B"*8, *value)) |
1859 | value = '0x%X' % address | |
5ba3f43e A |
1860 | else: |
1861 | value = prettify(value); | |
1862 | newdata[key] = value | |
1863 | ||
1864 | return newdata | |
1865 | ||
1866 | else: | |
1867 | return data | |
1868 | ||
3e170ce0 A |
1869 | |
1870 | if __name__ == '__main__': | |
c3c9b80d A |
1871 | parser = argparse.ArgumentParser(description="Decode a kcdata binary file.") |
1872 | parser.add_argument("-l", "--listtypes", action="store_true", required=False, default=False, | |
1873 | help="List all known types", | |
1874 | dest="list_known_types") | |
1875 | ||
1876 | parser.add_argument("-s", "--stackshot", required=False, default=False, | |
1877 | help="Generate a stackshot report file", | |
1878 | dest="stackshot_file") | |
1879 | ||
1880 | parser.add_argument("--multiple", help="look for multiple stackshots in a single file", action='store_true') | |
1881 | ||
1882 | parser.add_argument("-p", "--plist", required=False, default=False, | |
1883 | help="output as plist", action="store_true") | |
1884 | ||
1885 | parser.add_argument("-S", "--sdk", required=False, default="", help="sdk property passed to xcrun command to find the required tools. Default is empty string.", dest="sdk") | |
1886 | parser.add_argument("--pretty", default=False, action='store_true', help="make the output a little more human readable") | |
1887 | parser.add_argument("--incomplete", action='store_true', help="accept incomplete data") | |
1888 | parser.add_argument("kcdata_file", type=argparse.FileType('r'), help="Path to a kcdata binary file.") | |
1889 | ||
1890 | class VerboseAction(argparse.Action): | |
1891 | def __call__(self, parser, namespace, values, option_string=None): | |
1892 | logging.basicConfig(level=logging.INFO, stream=sys.stderr, format='%(message)s') | |
1893 | parser.add_argument('-v', "--verbose", action=VerboseAction, nargs=0) | |
1894 | ||
3e170ce0 A |
1895 | args = parser.parse_args() |
1896 | ||
39037602 A |
1897 | if args.multiple and args.stackshot_file: |
1898 | raise NotImplementedError | |
1899 | ||
3e170ce0 A |
1900 | if args.list_known_types: |
1901 | for (n, t) in KNOWN_TYPES_COLLECTION.items(): | |
1902 | print "%d : %s " % (n, str(t)) | |
1903 | sys.exit(1) | |
1904 | ||
5ba3f43e A |
1905 | if args.incomplete or args.stackshot_file: |
1906 | G.accept_incomplete_data = True | |
1907 | ||
39037602 A |
1908 | for i,kcdata_buffer in enumerate(iterate_kcdatas(args.kcdata_file)): |
1909 | if i > 0 and not args.multiple: | |
1910 | break | |
3e170ce0 | 1911 | |
39037602 A |
1912 | str_data = "{" + kcdata_buffer.GetJsonRepr() + "}" |
1913 | str_data = str_data.replace("\t", " ") | |
1914 | ||
1915 | try: | |
1916 | json_obj = json.loads(str_data) | |
1917 | except: | |
1918 | print >>sys.stderr, "JSON reparsing failed! Printing string data!\n" | |
1919 | import textwrap | |
1920 | print textwrap.fill(str_data, 100) | |
1921 | raise | |
3e170ce0 | 1922 | |
5ba3f43e A |
1923 | if args.pretty: |
1924 | json_obj = prettify(json_obj) | |
1925 | ||
3e170ce0 | 1926 | if args.stackshot_file: |
0a7de745 | 1927 | SaveStackshotReport(json_obj, args.stackshot_file, G.data_was_incomplete) |
39037602 A |
1928 | elif args.plist: |
1929 | import Foundation | |
1930 | plist = Foundation.NSPropertyListSerialization.dataWithPropertyList_format_options_error_( | |
1931 | json_obj, Foundation.NSPropertyListXMLFormat_v1_0, 0, None)[0].bytes().tobytes() | |
1932 | #sigh. on some pythons long integers are getting output with L's in the plist. | |
1933 | plist = re.sub(r'^(\s*<integer>\d+)L(</integer>\s*)$', r"\1\2", plist, flags=re.MULTILINE) | |
1934 | print plist, | |
3e170ce0 A |
1935 | else: |
1936 | print json.dumps(json_obj, sort_keys=True, indent=4, separators=(',', ': ')) |