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