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.
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.
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.
18 strings_dict: a dictionary of flag values to flag names
19 state: the value to get the state string of
21 a space separated list of flag names present in state
23 max_mask
= max(strings_dict
.keys())
28 while mask
<= max_mask
:
29 bit
= int(state
& mask
)
31 if bit
in strings_dict
:
36 output
+= strings_dict
[int(state
& mask
)]
38 output
+= '{:#x}'.format(mask
)
43 kdebug_flags_strings
= { 0x00100000: 'RANGECHECK',
44 0x00200000: 'VALCHECK',
45 0x00400000: 'TYPEFILTER_CHECK',
46 0x80000000: 'BUFINIT' }
47 kdebug_typefilter_check
= 0x00400000
49 kperf_samplers_strings
= { 1 << 0: 'TH_INFO',
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)",
73 kq_state_strings
= { 0x0000: '',
89 kn_state_strings
= { 0x0000: '',
97 0x0080: 'DEFERDELETE',
103 thread_qos_short_strings
= { 0: '--',
126 filetype_strings
= { DTYPE_VNODE
: 'VNODE',
127 DTYPE_SOCKET
: 'SOCKET',
128 DTYPE_PSXSHM
: 'PSXSHM',
129 DTYPE_PSXSEM
: 'PSXSEM',
130 DTYPE_KQUEUE
: 'KQUEUE',
132 DTYPE_FSEVENTS
: 'FSEVENTS',
133 DTYPE_ATALK
: 'APLTALK',
134 DTYPE_NETPOLICY
: 'NETPOLI'
137 mach_msg_type_descriptor_strings
= {0: "PORT", 1: "OOLDESC", 2: "OOLPORTS", 3: "OOLVOLATILE"}
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"
174 #File: xnu/osfmk/kern/ipc_kobject.h
175 # string representations for Kobject types
176 kobject_types
= ['', 'THREAD', 'TASK', 'HOST', 'HOST_PRIV', 'PROCESSOR', 'PSET', 'PSET_NAME', 'TIMER', 'PAGER_REQ', 'DEVICE', 'XMM_OBJECT', 'XMM_PAGER', 'XMM_KERNEL', 'XMM_REPLY',
177 'NOTDEF 15', 'NOTDEF 16', 'HOST_SEC', 'LEDGER', 'MASTER_DEV', 'TASK_NAME', 'SUBSYTEM', 'IO_DONE_QUE', 'SEMAPHORE', 'LOCK_SET', 'CLOCK', 'CLOCK_CTRL' , 'IOKIT_SPARE',
178 'NAMED_MEM', 'IOKIT_CON', 'IOKIT_OBJ', 'UPL', 'MEM_OBJ_CONTROL', 'AU_SESSIONPORT', 'FILEPORT', 'LABELH', 'TASK_RESUME', 'VOUCHER', 'VOUCHER_ATTR_CONTROL', 'WORK_INTERVAL',
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.
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
196 KDBG_BFINIT
= 0x80000000
198 KDCOPYBUF_COUNT
= 8192
199 KDS_PTR_NULL
= 0xffffffff
203 RAW_VERSION1
= 0x55aa0101
204 EVENTS_PER_STORAGE_UNIT
= 2048
206 EMBEDDED_PANIC_MAGIC
= 0x46554E4B
207 EMBEDDED_PANIC_STACKSHOT_SUCCEEDED_FLAG
= 0x02
209 MACOS_PANIC_MAGIC
= 0x44454544
210 MACOS_PANIC_STACKSHOT_SUCCEEDED_FLAG
= 0x04
212 AURR_PANIC_MAGIC
= 0x41555252
213 AURR_PANIC_STRING_LEN
= 112
214 AURR_PANIC_VERSION
= 1
216 CRASHLOG_PANIC_STRING_LEN
= 32
217 AURR_CRASHLOG_PANIC_VERSION
= 2
219 if __name__
== "__main__":
220 populate_kobject_types("../../")