xref: /xnu-8796.141.3/tools/lldbmacros/xnudefines.py (revision 1b191cb58250d0705d8a51287127505aa4bc0789)
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    Note: The Format of the function has to be populate_<variable_name> so that the automated updating will pick it up.
9"""
10from __future__ import absolute_import
11
12import os, re
13
14def GetStateString(strings_dict, state):
15    """ Turn a dictionary from flag value to flag name and a state mask with
16        those flags into a space-separated string of names.
17
18        params:
19            strings_dict: a dictionary of flag values to flag names
20            state: the value to get the state string of
21        return:
22            a space separated list of flag names present in state
23    """
24    max_mask = max(strings_dict.keys())
25
26    first = True
27    output = ''
28    mask = 0x1
29    while mask <= max_mask:
30        bit = int(state & mask)
31        if bit:
32            if bit in strings_dict:
33                if not first:
34                    output += ' '
35                else:
36                    first = False
37                output += strings_dict[int(state & mask)]
38            else:
39                output += '{:#x}'.format(mask)
40        mask = mask << 1
41
42    return output
43
44KDBG_NOWRAP           = 0x00000002
45KDBG_WRAPPED          = 0x00000008
46KDBG_TYPEFILTER_CHECK = 0x00400000
47KDBG_BUFINIT          = 0x80000000
48KDCOPYBUF_COUNT       = 8192
49KDS_PTR_NULL          = 0xffffffff
50DBG_FUNC_START        = 0x01
51DBG_FUNC_END          = 0x02
52
53kdebug_flags_strings = { 0x00100000: 'RANGECHECK',
54                         0x00200000: 'VALCHECK',
55                         KDBG_TYPEFILTER_CHECK: 'TYPEFILTER_CHECK',
56                         KDBG_BUFINIT: 'BUFINIT' }
57
58kperf_samplers_strings = { 1 << 0: 'TH_INFO',
59                           1 << 1: 'TH_SNAP',
60                           1 << 2: 'KSTACK',
61                           1 << 3: 'USTACK',
62                           1 << 4: 'PMC_THREAD',
63                           1 << 5: 'PMC_CPU',
64                           1 << 6: 'PMC_CONFIG',
65                           1 << 7: 'MEMINFO',
66                           1 << 8: 'TH_SCHED',
67                           1 << 9: 'TH_DISP',
68                           1 << 10: 'TK_SNAP' }
69
70lcpu_self = 0xFFFE
71arm_level2_access_strings = [ " noaccess",
72                              " supervisor(readwrite) user(noaccess)",
73                              " supervisor(readwrite) user(readonly)",
74                              " supervisor(readwrite) user(readwrite)",
75                              " noaccess(reserved)",
76                              " supervisor(readonly) user(noaccess)",
77                              " supervisor(readonly) user(readonly)",
78                              " supervisor(readonly) user(readonly)",
79                              " "
80                             ]
81
82thread_qos_short_strings = { 0: '--',
83                             1: 'MT',
84                             2: 'BG',
85                             3: 'UT',
86                             4: 'DF',
87                             5: 'IN',
88                             6: 'UI',
89                             7: 'MG' }
90
91KQWQ_NBUCKETS = 7
92KQWL_NBUCKETS = 6
93
94DTYPE_VNODE = 1
95DTYPE_SOCKET = 2
96DTYPE_PSXSHM = 3
97DTYPE_PSXSEM = 4
98DTYPE_KQUEUE = 5
99DTYPE_PIPE = 6
100DTYPE_FSEVENTS = 7
101DTYPE_ATALK = 8
102DTYPE_NETPOLICY = 9
103filetype_strings = { DTYPE_VNODE: 'VNODE',
104                     DTYPE_SOCKET: 'SOCKET',
105                     DTYPE_PSXSHM: 'PSXSHM',
106                     DTYPE_PSXSEM: 'PSXSEM',
107                     DTYPE_KQUEUE: 'KQUEUE',
108                     DTYPE_PIPE: 'PIPE',
109                     DTYPE_FSEVENTS: 'FSEVENTS',
110                     DTYPE_ATALK: 'APLTALK',
111                     DTYPE_NETPOLICY: 'NETPOLI'
112                     }
113
114mach_msg_type_descriptor_strings = {0: "PORT", 1: "OOLDESC", 2: "OOLPORTS", 3: "OOLVOLATILE"}
115
116proc_state_strings = ["", "Idle", "Run", "Sleep", "Stop", "Zombie", "Reaping"]
117proc_flag_explain_strings = {
118        0x00000001: 'may hold advisory locks',
119        0x00000002: 'has a controlling tty',
120        # Also used to singal 32-bit process.
121        0x00000004: 'process is 64 bit',
122        0x00000008: 'No SIGCHLD on child stop',
123        0x00000010: 'waiting for child exec/exit',
124        0x00000020: 'has started profiling',
125        0x00000040: 'in select; wakeup/waiting danger',
126        0x00000080: 'was stopped and continued',
127        0x00000100: 'has set privileges since last exec',
128        0x00000200: 'system process: no signals, stats, or swap',
129        0x00000400: 'timing out during sleep',
130        0x00000800: 'debugged process being traced',
131        0x00001000: 'address space layout randomization disabled',
132        0x00002000: 'exit in progress',
133        0x00004000: 'process has called exec',
134        0x00008000: 'owe process an addupc()',
135        0x00010000: 'affinity for Rosetta children',
136        0x00020000: 'wants to run Rosetta',
137        0x00040000: 'has wait() in progress',
138        0x00080000: 'checks for OPENEVT flag set on open',
139        0x00100000: 'can call vfs_markdependency()',
140        0x00200000: 'has called reboot()',
141        0x00400000: 'Reserved',
142        0x00800000: 'Reserved',
143        0x01000000: 'has thread cwd',
144        0x02000000: 'Reserved',
145        0x04000000: 'process has adopted persona',
146        0x08000000: 'Reserved',
147        0x10000000: 'no shared libraries',
148        0x20000000: 'force quota on root',
149        0x40000000: 'no zombies when children exit',
150        0x80000000: 'no hangs on remote FS ops'
151        }
152
153FSHIFT = 11
154FSCALE = 1 << FSHIFT
155
156DBG_TRACE               = 1
157DBG_TRACE_INFO          = 2
158RAW_VERSION1            = 0x55aa0101
159EVENTS_PER_STORAGE_UNIT = 2048
160
161EMBEDDED_PANIC_MAGIC = 0x46554E4B
162EMBEDDED_PANIC_STACKSHOT_SUCCEEDED_FLAG = 0x02
163
164MACOS_PANIC_MAGIC = 0x44454544
165MACOS_PANIC_STACKSHOT_SUCCEEDED_FLAG = 0x04
166
167AURR_PANIC_MAGIC = 0x41555252
168AURR_PANIC_VERSION = 1
169
170CRASHLOG_PANIC_STRING_LEN = 32
171AURR_CRASHLOG_PANIC_VERSION = 2
172
173# File:EXTERNAL_HEADER/mach-o/loader.h
174# (struct proc *)->p_proc_ro->p_platform_data.p_platform
175P_PLATFORM_MACOS = 1
176P_PLATFORM_IOS = 2
177P_PLATFORM_TVOS = 3
178P_PLATFORM_WATCHOS = 4
179P_PLATFORM_BRIDGEOS = 5
180P_PLATFORM_MACCATALYST = 6
181P_PLATFORM_IOSSIMULATOR = 7
182P_PLATFORM_TVOSSIMULATOR = 8
183P_PLATFORM_WATCHOSSIMULATOR = 9
184P_PLATFORM_DRIVERKIT = 10
185
186
187if __name__ == "__main__":
188    pass
189
190