]>
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. | |
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 | """ | |
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) | |
30 | if bit and bit in strings_dict: | |
31 | if not first: | |
32 | output += ' ' | |
33 | else: | |
34 | first = False | |
35 | output += strings_dict[int(state & mask)] | |
36 | mask = mask << 1 | |
37 | ||
38 | return output | |
39 | ||
40 | kdebug_flags_strings = { 0x00100000: 'RANGECHECK', | |
41 | 0x00200000: 'VALCHECK', | |
42 | 0x00400000: 'TYPEFILTER_CHECK', | |
43 | 0x80000000: 'BUFINIT' } | |
44 | kdebug_typefilter_check = 0x00400000 | |
45 | ||
46 | kperf_samplers_strings = { 1 << 0: 'TH_INFO', | |
47 | 1 << 1: 'TH_SNAP', | |
48 | 1 << 2: 'KSTACK', | |
49 | 1 << 3: 'USTACK', | |
50 | 1 << 4: 'PMC_THREAD', | |
51 | 1 << 5: 'PMC_CPU', | |
52 | 1 << 6: 'PMC_CONFIG', | |
53 | 1 << 7: 'MEMINFO', | |
54 | 1 << 8: 'TH_SCHED', | |
55 | 1 << 9: 'TH_DISP', | |
56 | 1 << 10: 'TK_SNAP' } | |
57 | ||
39236c6e A |
58 | lcpu_self = 0xFFFE |
59 | arm_level2_access_strings = [ " noaccess", | |
60 | " supervisor(readwrite) user(noaccess)", | |
61 | " supervisor(readwrite) user(readonly)", | |
62 | " supervisor(readwrite) user(readwrite)", | |
63 | " noaccess(reserved)", | |
64 | " supervisor(readonly) user(noaccess)", | |
65 | " supervisor(readonly) user(readonly)", | |
66 | " supervisor(readonly) user(readonly)", | |
67 | " " | |
68 | ] | |
39037602 | 69 | kq_state_strings = {0:"", 1:"SEL", 2:"SLEEP", 4:"PROCWAIT", 8:"KEV32", 16:"KEV64", 32:"QOS", 64:"WORKQ", 128:"PROCESS", 256: "DRAIN"} |
fe8ab488 | 70 | |
39037602 | 71 | kn_state_strings = {0:"", 1:"ACTIVE", 2:"QUEUED", 4:"DISABLED", 8:"DROPPING", 16:"USERWAIT", 32:"ATTACHING", 64:"STAYQUED", 128:"DEFERDROP"} |
3e170ce0 A |
72 | |
73 | mach_msg_type_descriptor_strings = {0: "PORT", 1: "OOLDESC", 2: "OOLPORTS", 3: "OOLVOLATILE"} | |
74 | ||
39236c6e A |
75 | proc_state_strings = [ "", "Idle", "Run", "Sleep", "Stop", "Zombie", "Reaping" ] |
76 | proc_flag_explain_strings = ["!0x00000004 - process is 32 bit", #only exception that does not follow bit settings | |
77 | "0x00000001 - may hold advisory locks", | |
78 | "0x00000002 - has a controlling tty", | |
79 | "0x00000004 - process is 64 bit", | |
80 | "0x00000008 - no SIGCHLD on child stop", | |
81 | "0x00000010 - waiting for child exec/exit", | |
82 | "0x00000020 - has started profiling", | |
83 | "0x00000040 - in select; wakeup/waiting danger", | |
84 | "0x00000080 - was stopped and continued", | |
85 | "0x00000100 - has set privileges since exec", | |
86 | "0x00000200 - system process: no signals, stats, or swap", | |
87 | "0x00000400 - timing out during a sleep", | |
88 | "0x00000800 - debugged process being traced", | |
89 | "0x00001000 - debugging process has waited for child", | |
90 | "0x00002000 - exit in progress", | |
91 | "0x00004000 - process has called exec", | |
92 | "0x00008000 - owe process an addupc() XXX", | |
93 | "0x00010000 - affinity for Rosetta children", | |
94 | "0x00020000 - wants to run Rosetta", | |
95 | "0x00040000 - has wait() in progress", | |
96 | "0x00080000 - kdebug tracing on for this process", | |
97 | "0x00100000 - blocked due to SIGTTOU or SIGTTIN", | |
98 | "0x00200000 - has called reboot()", | |
99 | "0x00400000 - is TBE state", | |
100 | "0x00800000 - signal exceptions", | |
101 | "0x01000000 - has thread cwd", | |
102 | "0x02000000 - has vfork() children", | |
103 | "0x04000000 - not allowed to attach", | |
104 | "0x08000000 - vfork() in progress", | |
105 | "0x10000000 - no shared libraries", | |
106 | "0x20000000 - force quota for root", | |
107 | "0x40000000 - no zombies when children exit", | |
108 | "0x80000000 - don't hang on remote FS ops" | |
109 | ] | |
110 | #File: xnu/osfmk/kern/ipc_kobject.h | |
111 | # string representations for Kobject types | |
112 | kobject_types = ['', 'THREAD', 'TASK', 'HOST', 'HOST_PRIV', 'PROCESSOR', 'PSET', 'PSET_NAME', 'TIMER', 'PAGER_REQ', 'DEVICE', 'XMM_OBJECT', 'XMM_PAGER', 'XMM_KERNEL', 'XMM_REPLY', | |
3e170ce0 | 113 | 'NOTDEF 15', 'NOTDEF 16', 'HOST_SEC', 'LEDGER', 'MASTER_DEV', 'TASK_NAME', 'SUBSYTEM', 'IO_DONE_QUE', 'SEMAPHORE', 'LOCK_SET', 'CLOCK', 'CLOCK_CTRL' , 'IOKIT_SPARE', |
fe8ab488 | 114 | 'NAMED_MEM', 'IOKIT_CON', 'IOKIT_OBJ', 'UPL', 'MEM_OBJ_CONTROL', 'AU_SESSIONPORT', 'FILEPORT', 'LABELH', 'TASK_RESUME', 'VOUCHER', 'VOUCHER_ATTR_CONTROL'] |
39236c6e A |
115 | |
116 | def populate_kobject_types(xnu_dir_path): | |
117 | """ Function to read data from header file xnu/osfmk/kern/ipc_kobject.h | |
118 | and populate the known kobject types. | |
119 | """ | |
120 | filename = os.path.join(xnu_dir_path, 'osfmk', 'kern', 'ipc_kobject.h') | |
121 | filedata = open(filename).read() | |
122 | object_regex = re.compile("^#define\s+(IKOT_[A-Z_]*)\s+(\d+)\s*",re.MULTILINE|re.DOTALL) | |
123 | kobject_found_types =[] | |
124 | for v in object_regex.findall(filedata): | |
125 | kobject_found_types.append(v[0]) | |
126 | return kobject_found_types | |
127 | ||
128 | if __name__ == "__main__": | |
129 | populate_kobject_types("../../") | |
fe8ab488 | 130 |