]> git.saurik.com Git - apple/xnu.git/blame - tools/lldbmacros/xnudefines.py
xnu-4570.71.2.tar.gz
[apple/xnu.git] / tools / lldbmacros / xnudefines.py
CommitLineData
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"""
11import os, re
12
813fb2f6
A
13def 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
43kdebug_flags_strings = { 0x00100000: 'RANGECHECK',
44 0x00200000: 'VALCHECK',
45 0x00400000: 'TYPEFILTER_CHECK',
46 0x80000000: 'BUFINIT' }
47kdebug_typefilter_check = 0x00400000
48
49kperf_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
61lcpu_self = 0xFFFE
62arm_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
73kq_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
86kn_state_strings = { 0x0000: '',
87 0x0001: 'ACTIVE',
88 0x0002: 'QUEUED',
89 0x0004: 'DISABLED',
90 0x0008: 'DROPPING',
91 0x0010: 'USERWAIT',
92 0x0020: 'ATTACHING',
93 0x0040: 'STAYACTIVE',
94 0x0080: 'DEFERDROP',
95 0x0100: 'ATTACHED',
96 0x0200: 'DISPATCH',
97 0x0400: 'UDATASPEC',
98 0x0800: 'SUPPRESS',
99 0x1000: 'STOLENDROP',
100 0x2000: 'REQVANISH',
101 0x4000: 'VANISHED' }
102
103kqrequest_state_strings = { 0x01: 'PROCESSING',
104 0x02: 'THREQUESTED',
105 0x04: 'WAKEUP',
106 0x08: 'BOUND',
107 0x20: 'THOVERCOMMIT',
108 0x40: 'DRAIN' }
109
110thread_qos_short_strings = { 0: '--',
111 1: 'MT',
112 2: 'BG',
113 3: 'UT',
114 4: 'DF',
115 5: 'IN',
116 6: 'UI',
117 7: 'MG' }
118
119KQ_WORKQ = 0x40
120KQ_WORKLOOP = 0x80
121KQWQ_NBUCKETS = 22
122KQWL_NBUCKETS = 8
123
124DTYPE_VNODE = 1
125DTYPE_SOCKET = 2
126DTYPE_PSXSHM = 3
127DTYPE_PSXSEM = 4
128DTYPE_KQUEUE = 5
129DTYPE_PIPE = 6
130DTYPE_FSEVENTS = 7
131DTYPE_ATALK = 8
132DTYPE_NETPOLICY = 9
133filetype_strings = { DTYPE_VNODE: 'VNODE',
134 DTYPE_SOCKET: 'SOCKET',
135 DTYPE_PSXSHM: 'PSXSHM',
136 DTYPE_PSXSEM: 'PSXSEM',
137 DTYPE_KQUEUE: 'KQUEUE',
138 DTYPE_PIPE: 'PIPE',
139 DTYPE_FSEVENTS: 'FSEVENTS',
140 DTYPE_ATALK: 'APLTALK',
141 DTYPE_NETPOLICY: 'NETPOLI'
142 }
3e170ce0
A
143
144mach_msg_type_descriptor_strings = {0: "PORT", 1: "OOLDESC", 2: "OOLPORTS", 3: "OOLVOLATILE"}
145
39236c6e
A
146proc_state_strings = [ "", "Idle", "Run", "Sleep", "Stop", "Zombie", "Reaping" ]
147proc_flag_explain_strings = ["!0x00000004 - process is 32 bit", #only exception that does not follow bit settings
148 "0x00000001 - may hold advisory locks",
149 "0x00000002 - has a controlling tty",
150 "0x00000004 - process is 64 bit",
151 "0x00000008 - no SIGCHLD on child stop",
152 "0x00000010 - waiting for child exec/exit",
153 "0x00000020 - has started profiling",
154 "0x00000040 - in select; wakeup/waiting danger",
155 "0x00000080 - was stopped and continued",
156 "0x00000100 - has set privileges since exec",
157 "0x00000200 - system process: no signals, stats, or swap",
158 "0x00000400 - timing out during a sleep",
159 "0x00000800 - debugged process being traced",
160 "0x00001000 - debugging process has waited for child",
161 "0x00002000 - exit in progress",
162 "0x00004000 - process has called exec",
163 "0x00008000 - owe process an addupc() XXX",
164 "0x00010000 - affinity for Rosetta children",
165 "0x00020000 - wants to run Rosetta",
166 "0x00040000 - has wait() in progress",
167 "0x00080000 - kdebug tracing on for this process",
168 "0x00100000 - blocked due to SIGTTOU or SIGTTIN",
169 "0x00200000 - has called reboot()",
170 "0x00400000 - is TBE state",
171 "0x00800000 - signal exceptions",
172 "0x01000000 - has thread cwd",
173 "0x02000000 - has vfork() children",
174 "0x04000000 - not allowed to attach",
175 "0x08000000 - vfork() in progress",
176 "0x10000000 - no shared libraries",
177 "0x20000000 - force quota for root",
178 "0x40000000 - no zombies when children exit",
179 "0x80000000 - don't hang on remote FS ops"
180 ]
181#File: xnu/osfmk/kern/ipc_kobject.h
182# string representations for Kobject types
183kobject_types = ['', 'THREAD', 'TASK', 'HOST', 'HOST_PRIV', 'PROCESSOR', 'PSET', 'PSET_NAME', 'TIMER', 'PAGER_REQ', 'DEVICE', 'XMM_OBJECT', 'XMM_PAGER', 'XMM_KERNEL', 'XMM_REPLY',
3e170ce0 184 'NOTDEF 15', 'NOTDEF 16', 'HOST_SEC', 'LEDGER', 'MASTER_DEV', 'TASK_NAME', 'SUBSYTEM', 'IO_DONE_QUE', 'SEMAPHORE', 'LOCK_SET', 'CLOCK', 'CLOCK_CTRL' , 'IOKIT_SPARE',
5ba3f43e 185 'NAMED_MEM', 'IOKIT_CON', 'IOKIT_OBJ', 'UPL', 'MEM_OBJ_CONTROL', 'AU_SESSIONPORT', 'FILEPORT', 'LABELH', 'TASK_RESUME', 'VOUCHER', 'VOUCHER_ATTR_CONTROL', 'IKOT_WORK_INTERVAL']
39236c6e
A
186
187def 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
5ba3f43e
A
199KDBG_BFINIT = 0x80000000
200KDBG_WRAPPED = 0x008
201KDCOPYBUF_COUNT = 8192
202KDS_PTR_NULL = 0xffffffff
203
204DBG_TRACE = 1
205DBG_TRACE_INFO = 2
206RAW_VERSION1 = 0x55aa0101
207EVENTS_PER_STORAGE_UNIT = 2048
208
209EMBEDDED_PANIC_MAGIC = 0x46554E4B
210EMBEDDED_PANIC_STACKSHOT_SUCCEEDED_FLAG = 0x02
211
cc8bc92a
A
212MACOS_PANIC_MAGIC = 0x44454544
213
39236c6e
A
214if __name__ == "__main__":
215 populate_kobject_types("../../")
fe8ab488 216