]>
Commit | Line | Data |
---|---|---|
39236c6e A |
1 | #!/usr/bin/env python |
2 | ||
3 | """ This file holds all static values that debugging macros need. These are typically object type strings, #defines in C etc. | |
4 | The objective is to provide a single place to be the bridge between C code in xnu and the python macros used by lldb. | |
5 | If you define a variable which has been copied/referred over from C code and has high chance of changing over time. It would | |
6 | be best to define a supporting function of format "populate_<variable_name>". This will help in running them to repopulate. | |
7 | ||
8 | Please take a look at example of kobject_types below before making changes to this file. | |
9 | Note: The Format of the function has to be populate_<variable_name> so that the automated updating will pick it up. | |
10 | """ | |
11 | import os, re | |
12 | ||
813fb2f6 A |
13 | def GetStateString(strings_dict, state): |
14 | """ Turn a dictionary from flag value to flag name and a state mask with | |
15 | those flags into a space-separated string of names. | |
16 | ||
17 | params: | |
18 | strings_dict: a dictionary of flag values to flag names | |
19 | state: the value to get the state string of | |
20 | return: | |
21 | a space separated list of flag names present in state | |
22 | """ | |
23 | max_mask = max(strings_dict.keys()) | |
24 | ||
25 | first = True | |
26 | output = '' | |
27 | mask = 0x1 | |
28 | while mask <= max_mask: | |
29 | bit = int(state & mask) | |
5ba3f43e A |
30 | if bit: |
31 | if bit in strings_dict: | |
32 | if not first: | |
33 | output += ' ' | |
34 | else: | |
35 | first = False | |
36 | output += strings_dict[int(state & mask)] | |
813fb2f6 | 37 | else: |
5ba3f43e | 38 | output += '{:#x}'.format(mask) |
813fb2f6 A |
39 | mask = mask << 1 |
40 | ||
41 | return output | |
42 | ||
43 | kdebug_flags_strings = { 0x00100000: 'RANGECHECK', | |
44 | 0x00200000: 'VALCHECK', | |
45 | 0x00400000: 'TYPEFILTER_CHECK', | |
46 | 0x80000000: 'BUFINIT' } | |
47 | kdebug_typefilter_check = 0x00400000 | |
48 | ||
49 | kperf_samplers_strings = { 1 << 0: 'TH_INFO', | |
50 | 1 << 1: 'TH_SNAP', | |
51 | 1 << 2: 'KSTACK', | |
52 | 1 << 3: 'USTACK', | |
53 | 1 << 4: 'PMC_THREAD', | |
54 | 1 << 5: 'PMC_CPU', | |
55 | 1 << 6: 'PMC_CONFIG', | |
56 | 1 << 7: 'MEMINFO', | |
57 | 1 << 8: 'TH_SCHED', | |
58 | 1 << 9: 'TH_DISP', | |
59 | 1 << 10: 'TK_SNAP' } | |
60 | ||
39236c6e A |
61 | lcpu_self = 0xFFFE |
62 | arm_level2_access_strings = [ " noaccess", | |
63 | " supervisor(readwrite) user(noaccess)", | |
64 | " supervisor(readwrite) user(readonly)", | |
65 | " supervisor(readwrite) user(readwrite)", | |
66 | " noaccess(reserved)", | |
67 | " supervisor(readonly) user(noaccess)", | |
68 | " supervisor(readonly) user(readonly)", | |
69 | " supervisor(readonly) user(readonly)", | |
70 | " " | |
71 | ] | |
fe8ab488 | 72 | |
5ba3f43e A |
73 | kq_state_strings = { 0x000: '', |
74 | 0x001: 'SEL', | |
75 | 0x002: 'SLEEP', | |
76 | 0x004: 'PROCWAIT', | |
77 | 0x008: 'KEV32', | |
78 | 0x010: 'KEV64', | |
79 | 0x020: 'KEVQOS', | |
80 | 0x040: 'WORKQ', | |
81 | 0x080: 'WORKLOOP', | |
82 | 0x100: 'PROCESS', | |
83 | 0x200: 'DRAIN', | |
84 | 0x400: 'WAKEUP' } | |
85 | ||
86 | kn_state_strings = { 0x0000: '', | |
87 | 0x0001: 'ACTIVE', | |
88 | 0x0002: 'QUEUED', | |
89 | 0x0004: 'DISABLED', | |
90 | 0x0008: 'DROPPING', | |
d9a64523 | 91 | 0x0010: 'LOCKED', |
5ba3f43e A |
92 | 0x0020: 'ATTACHING', |
93 | 0x0040: 'STAYACTIVE', | |
94 | 0x0080: 'DEFERDROP', | |
95 | 0x0100: 'ATTACHED', | |
96 | 0x0200: 'DISPATCH', | |
97 | 0x0400: 'UDATASPEC', | |
98 | 0x0800: 'SUPPRESS', | |
d9a64523 | 99 | 0x1000: 'MERGE_QOS', |
5ba3f43e A |
100 | 0x2000: 'REQVANISH', |
101 | 0x4000: 'VANISHED' } | |
102 | ||
d9a64523 | 103 | kqrequest_state_strings = { 0x01: 'WORKLOOP', |
5ba3f43e A |
104 | 0x02: 'THREQUESTED', |
105 | 0x04: 'WAKEUP', | |
d9a64523 A |
106 | 0x08: 'THOVERCOMMIT', |
107 | 0x10: 'R2K_ARMED', | |
108 | 0x20: 'ALLOC_TURNSTILE' } | |
5ba3f43e A |
109 | thread_qos_short_strings = { 0: '--', |
110 | 1: 'MT', | |
111 | 2: 'BG', | |
112 | 3: 'UT', | |
113 | 4: 'DF', | |
114 | 5: 'IN', | |
115 | 6: 'UI', | |
116 | 7: 'MG' } | |
117 | ||
118 | KQ_WORKQ = 0x40 | |
119 | KQ_WORKLOOP = 0x80 | |
d9a64523 | 120 | KQWQ_NBUCKETS = 8 |
5ba3f43e A |
121 | KQWL_NBUCKETS = 8 |
122 | ||
123 | DTYPE_VNODE = 1 | |
124 | DTYPE_SOCKET = 2 | |
125 | DTYPE_PSXSHM = 3 | |
126 | DTYPE_PSXSEM = 4 | |
127 | DTYPE_KQUEUE = 5 | |
128 | DTYPE_PIPE = 6 | |
129 | DTYPE_FSEVENTS = 7 | |
130 | DTYPE_ATALK = 8 | |
131 | DTYPE_NETPOLICY = 9 | |
132 | filetype_strings = { DTYPE_VNODE: 'VNODE', | |
133 | DTYPE_SOCKET: 'SOCKET', | |
134 | DTYPE_PSXSHM: 'PSXSHM', | |
135 | DTYPE_PSXSEM: 'PSXSEM', | |
136 | DTYPE_KQUEUE: 'KQUEUE', | |
137 | DTYPE_PIPE: 'PIPE', | |
138 | DTYPE_FSEVENTS: 'FSEVENTS', | |
139 | DTYPE_ATALK: 'APLTALK', | |
140 | DTYPE_NETPOLICY: 'NETPOLI' | |
141 | } | |
3e170ce0 A |
142 | |
143 | mach_msg_type_descriptor_strings = {0: "PORT", 1: "OOLDESC", 2: "OOLPORTS", 3: "OOLVOLATILE"} | |
144 | ||
39236c6e A |
145 | proc_state_strings = [ "", "Idle", "Run", "Sleep", "Stop", "Zombie", "Reaping" ] |
146 | proc_flag_explain_strings = ["!0x00000004 - process is 32 bit", #only exception that does not follow bit settings | |
147 | "0x00000001 - may hold advisory locks", | |
148 | "0x00000002 - has a controlling tty", | |
149 | "0x00000004 - process is 64 bit", | |
150 | "0x00000008 - no SIGCHLD on child stop", | |
151 | "0x00000010 - waiting for child exec/exit", | |
152 | "0x00000020 - has started profiling", | |
153 | "0x00000040 - in select; wakeup/waiting danger", | |
154 | "0x00000080 - was stopped and continued", | |
155 | "0x00000100 - has set privileges since exec", | |
156 | "0x00000200 - system process: no signals, stats, or swap", | |
157 | "0x00000400 - timing out during a sleep", | |
158 | "0x00000800 - debugged process being traced", | |
159 | "0x00001000 - debugging process has waited for child", | |
160 | "0x00002000 - exit in progress", | |
161 | "0x00004000 - process has called exec", | |
162 | "0x00008000 - owe process an addupc() XXX", | |
163 | "0x00010000 - affinity for Rosetta children", | |
164 | "0x00020000 - wants to run Rosetta", | |
165 | "0x00040000 - has wait() in progress", | |
166 | "0x00080000 - kdebug tracing on for this process", | |
167 | "0x00100000 - blocked due to SIGTTOU or SIGTTIN", | |
168 | "0x00200000 - has called reboot()", | |
169 | "0x00400000 - is TBE state", | |
170 | "0x00800000 - signal exceptions", | |
171 | "0x01000000 - has thread cwd", | |
172 | "0x02000000 - has vfork() children", | |
173 | "0x04000000 - not allowed to attach", | |
174 | "0x08000000 - vfork() in progress", | |
175 | "0x10000000 - no shared libraries", | |
176 | "0x20000000 - force quota for root", | |
177 | "0x40000000 - no zombies when children exit", | |
178 | "0x80000000 - don't hang on remote FS ops" | |
179 | ] | |
180 | #File: xnu/osfmk/kern/ipc_kobject.h | |
181 | # string representations for Kobject types | |
182 | kobject_types = ['', 'THREAD', 'TASK', 'HOST', 'HOST_PRIV', 'PROCESSOR', 'PSET', 'PSET_NAME', 'TIMER', 'PAGER_REQ', 'DEVICE', 'XMM_OBJECT', 'XMM_PAGER', 'XMM_KERNEL', 'XMM_REPLY', | |
3e170ce0 | 183 | 'NOTDEF 15', 'NOTDEF 16', 'HOST_SEC', 'LEDGER', 'MASTER_DEV', 'TASK_NAME', 'SUBSYTEM', 'IO_DONE_QUE', 'SEMAPHORE', 'LOCK_SET', 'CLOCK', 'CLOCK_CTRL' , 'IOKIT_SPARE', |
d9a64523 A |
184 | 'NAMED_MEM', 'IOKIT_CON', 'IOKIT_OBJ', 'UPL', 'MEM_OBJ_CONTROL', 'AU_SESSIONPORT', 'FILEPORT', 'LABELH', 'TASK_RESUME', 'VOUCHER', 'VOUCHER_ATTR_CONTROL', 'WORK_INTERVAL', |
185 | 'UX_HANDLER'] | |
39236c6e A |
186 | |
187 | def populate_kobject_types(xnu_dir_path): | |
188 | """ Function to read data from header file xnu/osfmk/kern/ipc_kobject.h | |
189 | and populate the known kobject types. | |
190 | """ | |
191 | filename = os.path.join(xnu_dir_path, 'osfmk', 'kern', 'ipc_kobject.h') | |
192 | filedata = open(filename).read() | |
193 | object_regex = re.compile("^#define\s+(IKOT_[A-Z_]*)\s+(\d+)\s*",re.MULTILINE|re.DOTALL) | |
194 | kobject_found_types =[] | |
195 | for v in object_regex.findall(filedata): | |
196 | kobject_found_types.append(v[0]) | |
197 | return kobject_found_types | |
198 | ||
d9a64523 A |
199 | FSHIFT = 11 |
200 | FSCALE = 1 << FSHIFT | |
201 | ||
5ba3f43e A |
202 | KDBG_BFINIT = 0x80000000 |
203 | KDBG_WRAPPED = 0x008 | |
204 | KDCOPYBUF_COUNT = 8192 | |
205 | KDS_PTR_NULL = 0xffffffff | |
206 | ||
207 | DBG_TRACE = 1 | |
208 | DBG_TRACE_INFO = 2 | |
209 | RAW_VERSION1 = 0x55aa0101 | |
210 | EVENTS_PER_STORAGE_UNIT = 2048 | |
211 | ||
212 | EMBEDDED_PANIC_MAGIC = 0x46554E4B | |
213 | EMBEDDED_PANIC_STACKSHOT_SUCCEEDED_FLAG = 0x02 | |
214 | ||
cc8bc92a A |
215 | MACOS_PANIC_MAGIC = 0x44454544 |
216 | ||
39236c6e A |
217 | if __name__ == "__main__": |
218 | populate_kobject_types("../../") | |
fe8ab488 | 219 |