]> git.saurik.com Git - apple/xnu.git/blob - tools/lldbmacros/ktrace.py
xnu-3789.1.32.tar.gz
[apple/xnu.git] / tools / lldbmacros / ktrace.py
1 from xnu import *
2 from utils import *
3
4 # From the defines in bsd/sys/kdebug.h:
5
6 KdebugClassNames = {
7 1: "MACH",
8 2: "NETWORK",
9 3: "FSYSTEM",
10 4: "BSD",
11 5: "IOKIT",
12 6: "DRIVERS",
13 7: "TRACE",
14 8: "DLIL",
15 9: "WORKQUEUE",
16 10: "CORESTORAGE",
17 11: "CG",
18 20: "MISC",
19 30: "SECURITY",
20 31: "DYLD",
21 32: "QT",
22 33: "APPS",
23 34: "LAUNCHD",
24 36: "PPT",
25 37: "PERF",
26 38: "IMPORTANCE",
27 39: "PERFCTRL",
28 40: "BANK",
29 41: "XPC",
30 42: "ATM",
31 43: "ARIADNE",
32 44: "DAEMON",
33 45: "ENERGYTRACE",
34 49: "IMG",
35 50: "CLPC",
36 128: "ANS",
37 129: "SIO",
38 130: "SEP",
39 131: "ISP",
40 132: "OSCAR",
41 133: "EMBEDDEDGFX"
42 }
43
44 def GetKdebugClassName(class_num):
45 return (KdebugClassNames[class_num] + ' ({})'.format(class_num) if class_num in KdebugClassNames else 'unknown ({})'.format(class_num))
46
47 @lldb_type_summary(['typefilter_t'])
48 @header('{0: <20s}'.format("class") + ' '.join(map('{:02x}'.format, xrange(0, 255, 8))))
49 def GetKdebugTypefilter(typefilter):
50 """ Summarizes the provided typefilter.
51 """
52 classes = 256
53 subclasses_per_class = 256
54
55 # 8 bits at a time
56 subclasses_per_element = 64
57 cur_typefilter = cast(typefilter, 'uint64_t *')
58 subclasses_fmts = ' '.join(['{:02x}'] * 8)
59
60 elements_per_class = subclasses_per_class / subclasses_per_element
61
62 out_str = ''
63 for i in xrange(0, classes):
64 print_class = False
65 subclasses = [0] * elements_per_class
66
67 # check subclass ranges for set bits, remember those subclasses
68 for j in xrange(0, elements_per_class):
69 element = unsigned(cur_typefilter[i * elements_per_class + j])
70 if element != 0:
71 print_class = True
72 if print_class:
73 subclasses[j] = element
74
75 # if any of the bits were set in a class, print the entire class
76 if print_class:
77 out_str += '{:<20s}'.format(GetKdebugClassName(i))
78 for element in subclasses:
79 # split up the 64-bit values into byte-sized pieces
80 bytes = [unsigned((element >> i) & 0xff) for i in (0, 8, 16, 24, 32, 40, 48, 56)]
81 out_str += subclasses_fmts.format(*bytes)
82 out_str += ' '
83
84 out_str += '\n'
85
86 return out_str
87
88 @lldb_command('showkdebugtypefilter')
89 def ShowKdebugTypefilter(cmd_args=None):
90 """ Show the current kdebug typefilter (or the typefilter at an address)
91
92 usage: showkdebugtypefilter [<address>]
93 """
94
95 if cmd_args:
96 print GetKdebugTypefilter.header
97 print '-' * len(GetKdebugTypefilter.header)
98
99 typefilter = kern.GetValueFromAddress(cmd_args[0], 'typefilter_t')
100 if unsigned(typefilter) == 0:
101 raise ArgumentError('argument provided is NULL')
102
103 print GetKdebugTypefilter()
104 return
105
106 typefilter = kern.globals.kdbg_typefilter
107 if unsigned(typefilter) == 0:
108 raise ArgumentError('no argument provided and active typefilter is not set')
109
110 print GetKdebugTypefilter.header
111 print '-' * len(GetKdebugTypefilter.header)
112 print GetKdebugTypefilter(typefilter)