]>
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. | |
cb323159 | 7 | |
39236c6e A |
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 | |
cb323159 A |
73 | kq_state_strings = { 0x0000: '', |
74 | 0x0001: 'SEL', | |
75 | 0x0002: 'SLEEP', | |
76 | 0x0004: 'PROCWAIT', | |
77 | 0x0008: '32', | |
78 | 0x0010: '64', | |
79 | 0x0020: 'QOS', | |
80 | 0x0040: 'WQ', | |
81 | 0x0080: 'WL', | |
82 | 0x0100: 'PROCESS', | |
83 | 0x0200: 'DRAIN', | |
84 | 0x0400: 'WAKEUP', | |
85 | 0x0800: 'DYN', | |
86 | 0x1000: 'R2K', | |
87 | 0x2000: 'TS' } | |
5ba3f43e A |
88 | |
89 | kn_state_strings = { 0x0000: '', | |
90 | 0x0001: 'ACTIVE', | |
91 | 0x0002: 'QUEUED', | |
92 | 0x0004: 'DISABLED', | |
93 | 0x0008: 'DROPPING', | |
d9a64523 | 94 | 0x0010: 'LOCKED', |
cb323159 | 95 | 0x0020: 'POSTING', |
5ba3f43e | 96 | 0x0040: 'STAYACTIVE', |
cb323159 A |
97 | 0x0080: 'DEFERDELETE', |
98 | 0x0100: 'MERGE_QOS', | |
99 | 0x0200: 'REQVANISH', | |
100 | 0x0400: 'VANISHED', | |
101 | 0x0800: 'SUPPRESS' } | |
102 | ||
5ba3f43e A |
103 | thread_qos_short_strings = { 0: '--', |
104 | 1: 'MT', | |
105 | 2: 'BG', | |
106 | 3: 'UT', | |
107 | 4: 'DF', | |
108 | 5: 'IN', | |
109 | 6: 'UI', | |
110 | 7: 'MG' } | |
111 | ||
112 | KQ_WORKQ = 0x40 | |
113 | KQ_WORKLOOP = 0x80 | |
d9a64523 | 114 | KQWQ_NBUCKETS = 8 |
5ba3f43e A |
115 | KQWL_NBUCKETS = 8 |
116 | ||
117 | DTYPE_VNODE = 1 | |
118 | DTYPE_SOCKET = 2 | |
119 | DTYPE_PSXSHM = 3 | |
120 | DTYPE_PSXSEM = 4 | |
121 | DTYPE_KQUEUE = 5 | |
122 | DTYPE_PIPE = 6 | |
123 | DTYPE_FSEVENTS = 7 | |
124 | DTYPE_ATALK = 8 | |
125 | DTYPE_NETPOLICY = 9 | |
126 | filetype_strings = { DTYPE_VNODE: 'VNODE', | |
127 | DTYPE_SOCKET: 'SOCKET', | |
128 | DTYPE_PSXSHM: 'PSXSHM', | |
129 | DTYPE_PSXSEM: 'PSXSEM', | |
130 | DTYPE_KQUEUE: 'KQUEUE', | |
131 | DTYPE_PIPE: 'PIPE', | |
132 | DTYPE_FSEVENTS: 'FSEVENTS', | |
133 | DTYPE_ATALK: 'APLTALK', | |
134 | DTYPE_NETPOLICY: 'NETPOLI' | |
135 | } | |
3e170ce0 A |
136 | |
137 | mach_msg_type_descriptor_strings = {0: "PORT", 1: "OOLDESC", 2: "OOLPORTS", 3: "OOLVOLATILE"} | |
138 | ||
39236c6e A |
139 | proc_state_strings = [ "", "Idle", "Run", "Sleep", "Stop", "Zombie", "Reaping" ] |
140 | proc_flag_explain_strings = ["!0x00000004 - process is 32 bit", #only exception that does not follow bit settings | |
141 | "0x00000001 - may hold advisory locks", | |
142 | "0x00000002 - has a controlling tty", | |
143 | "0x00000004 - process is 64 bit", | |
144 | "0x00000008 - no SIGCHLD on child stop", | |
145 | "0x00000010 - waiting for child exec/exit", | |
146 | "0x00000020 - has started profiling", | |
147 | "0x00000040 - in select; wakeup/waiting danger", | |
148 | "0x00000080 - was stopped and continued", | |
149 | "0x00000100 - has set privileges since exec", | |
150 | "0x00000200 - system process: no signals, stats, or swap", | |
151 | "0x00000400 - timing out during a sleep", | |
152 | "0x00000800 - debugged process being traced", | |
153 | "0x00001000 - debugging process has waited for child", | |
154 | "0x00002000 - exit in progress", | |
155 | "0x00004000 - process has called exec", | |
156 | "0x00008000 - owe process an addupc() XXX", | |
157 | "0x00010000 - affinity for Rosetta children", | |
158 | "0x00020000 - wants to run Rosetta", | |
159 | "0x00040000 - has wait() in progress", | |
160 | "0x00080000 - kdebug tracing on for this process", | |
161 | "0x00100000 - blocked due to SIGTTOU or SIGTTIN", | |
162 | "0x00200000 - has called reboot()", | |
163 | "0x00400000 - is TBE state", | |
164 | "0x00800000 - signal exceptions", | |
165 | "0x01000000 - has thread cwd", | |
166 | "0x02000000 - has vfork() children", | |
167 | "0x04000000 - not allowed to attach", | |
168 | "0x08000000 - vfork() in progress", | |
169 | "0x10000000 - no shared libraries", | |
170 | "0x20000000 - force quota for root", | |
171 | "0x40000000 - no zombies when children exit", | |
172 | "0x80000000 - don't hang on remote FS ops" | |
173 | ] | |
174 | #File: xnu/osfmk/kern/ipc_kobject.h | |
175 | # string representations for Kobject types | |
f427ee49 | 176 | kobject_types = ['', 'THREAD_CONTROL', 'TASK_CONTROL', 'HOST', 'HOST_PRIV', 'PROCESSOR', 'PSET', 'PSET_NAME', 'TIMER', 'PAGER_REQ', 'DEVICE', 'XMM_OBJECT', 'XMM_PAGER', 'XMM_KERNEL', 'XMM_REPLY', |
cb323159 | 177 | 'NOTDEF 15', 'NOTDEF 16', 'HOST_SEC', 'LEDGER', 'MASTER_DEV', 'TASK_NAME', 'SUBSYTEM', 'IO_DONE_QUE', 'SEMAPHORE', 'LOCK_SET', 'CLOCK', 'CLOCK_CTRL' , 'IOKIT_SPARE', |
d9a64523 | 178 | 'NAMED_MEM', 'IOKIT_CON', 'IOKIT_OBJ', 'UPL', 'MEM_OBJ_CONTROL', 'AU_SESSIONPORT', 'FILEPORT', 'LABELH', 'TASK_RESUME', 'VOUCHER', 'VOUCHER_ATTR_CONTROL', 'WORK_INTERVAL', |
f427ee49 | 179 | 'UX_HANDLER', 'UEXT_OBJECT', 'ARCADE_REG', 'TASK_INSPECT', 'TASK_READ', 'THREAD_INSPECT', 'THREAD_READ'] |
39236c6e A |
180 | |
181 | def populate_kobject_types(xnu_dir_path): | |
182 | """ Function to read data from header file xnu/osfmk/kern/ipc_kobject.h | |
183 | and populate the known kobject types. | |
184 | """ | |
185 | filename = os.path.join(xnu_dir_path, 'osfmk', 'kern', 'ipc_kobject.h') | |
186 | filedata = open(filename).read() | |
187 | object_regex = re.compile("^#define\s+(IKOT_[A-Z_]*)\s+(\d+)\s*",re.MULTILINE|re.DOTALL) | |
188 | kobject_found_types =[] | |
189 | for v in object_regex.findall(filedata): | |
190 | kobject_found_types.append(v[0]) | |
191 | return kobject_found_types | |
192 | ||
d9a64523 A |
193 | FSHIFT = 11 |
194 | FSCALE = 1 << FSHIFT | |
195 | ||
5ba3f43e A |
196 | KDBG_BFINIT = 0x80000000 |
197 | KDBG_WRAPPED = 0x008 | |
198 | KDCOPYBUF_COUNT = 8192 | |
199 | KDS_PTR_NULL = 0xffffffff | |
200 | ||
201 | DBG_TRACE = 1 | |
202 | DBG_TRACE_INFO = 2 | |
203 | RAW_VERSION1 = 0x55aa0101 | |
204 | EVENTS_PER_STORAGE_UNIT = 2048 | |
205 | ||
206 | EMBEDDED_PANIC_MAGIC = 0x46554E4B | |
207 | EMBEDDED_PANIC_STACKSHOT_SUCCEEDED_FLAG = 0x02 | |
208 | ||
cc8bc92a | 209 | MACOS_PANIC_MAGIC = 0x44454544 |
cb323159 A |
210 | MACOS_PANIC_STACKSHOT_SUCCEEDED_FLAG = 0x04 |
211 | ||
212 | AURR_PANIC_MAGIC = 0x41555252 | |
cb323159 A |
213 | AURR_PANIC_VERSION = 1 |
214 | ||
215 | CRASHLOG_PANIC_STRING_LEN = 32 | |
216 | AURR_CRASHLOG_PANIC_VERSION = 2 | |
cc8bc92a | 217 | |
f427ee49 A |
218 | # File:EXTERNAL_HEADER/mach-o/loader.h |
219 | # (struct proc *)->p_platform | |
220 | P_PLATFORM_MACOS = 1 | |
221 | P_PLATFORM_IOS = 2 | |
222 | P_PLATFORM_TVOS = 3 | |
223 | P_PLATFORM_WATCHOS = 4 | |
224 | P_PLATFORM_BRIDGEOS = 5 | |
225 | P_PLATFORM_MACCATALYST = 6 | |
226 | P_PLATFORM_IOSSIMULATOR = 7 | |
227 | P_PLATFORM_TVOSSIMULATOR = 8 | |
228 | P_PLATFORM_WATCHOSSIMULATOR = 9 | |
229 | P_PLATFORM_DRIVERKIT = 10 | |
230 | ||
39236c6e A |
231 | if __name__ == "__main__": |
232 | populate_kobject_types("../../") | |
cb323159 | 233 |