]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/debug.h
66702bc161d028efb3c7ac3d82962ea18c10687a
[apple/xnu.git] / osfmk / kern / debug.h
1 /*
2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #ifndef _KERN_DEBUG_H_
30 #define _KERN_DEBUG_H_
31
32 #include <sys/cdefs.h>
33 #include <stdint.h>
34
35 #ifdef __APPLE_API_PRIVATE
36 #ifdef __APPLE_API_UNSTABLE
37
38 struct thread_snapshot {
39 uint32_t snapshot_magic;
40 uint32_t nkern_frames;
41 uint32_t nuser_frames;
42 uint64_t wait_event;
43 uint64_t continuation;
44 uint64_t thread_id;
45 uint64_t user_time;
46 uint64_t system_time;
47 int32_t state;
48 char ss_flags;
49 } __attribute__ ((packed));
50
51 struct task_snapshot {
52 uint32_t snapshot_magic;
53 int32_t pid;
54 uint32_t nloadinfos;
55 uint64_t user_time_in_terminated_threads;
56 uint64_t system_time_in_terminated_threads;
57 int suspend_count;
58 int task_size; // pages
59 int faults; // number of page faults
60 int pageins; // number of actual pageins
61 int cow_faults; // number of copy-on-write faults
62 char ss_flags;
63 /* We restrict ourselves to a statically defined
64 * (current as of 2009) length for the
65 * p_comm string, due to scoping issues (osfmk/bsd and user/kernel
66 * binary compatibility).
67 */
68 char p_comm[17];
69 } __attribute__ ((packed));
70
71
72 struct mem_snapshot {
73 uint32_t snapshot_magic;
74 uint32_t free_pages;
75 uint32_t active_pages;
76 uint32_t inactive_pages;
77 uint32_t purgeable_pages;
78 uint32_t wired_pages;
79 uint32_t speculative_pages;
80 uint32_t throttled_pages;
81 } __attribute__((packed));
82
83 enum {
84 kUser64_p = 0x1,
85 kKernel64_p = 0x2,
86 kHasDispatchSerial = 0x4,
87 kTerminatedSnapshot = 0x8
88 };
89
90 enum {
91 STACKSHOT_GET_DQ = 0x1,
92 STACKSHOT_SAVE_LOADINFO = 0x2,
93 STACKSHOT_GET_GLOBAL_MEM_STATS = 0x4
94 };
95
96 #define STACKSHOT_THREAD_SNAPSHOT_MAGIC 0xfeedface
97 #define STACKSHOT_TASK_SNAPSHOT_MAGIC 0xdecafbad
98 #define STACKSHOT_MEM_SNAPSHOT_MAGIC 0xabcddcba
99
100 #endif /* __APPLE_API_UNSTABLE */
101 #endif /* __APPLE_API_PRIVATE */
102
103 #ifdef KERNEL_PRIVATE
104
105 extern unsigned int systemLogDiags;
106 extern char debug_buf[];
107 extern unsigned int debug_boot_arg;
108 extern char kernel_uuid[];
109
110 #ifdef MACH_KERNEL_PRIVATE
111
112 extern unsigned int halt_in_debugger;
113
114 extern unsigned int switch_debugger;
115
116 extern unsigned int current_debugger;
117 #define NO_CUR_DB 0x0
118 #define KDP_CUR_DB 0x1
119 #define KDB_CUR_DB 0x2
120
121 extern unsigned int active_debugger;
122 extern unsigned int debug_mode;
123 extern unsigned int disable_debug_output;
124
125 extern unsigned int panicDebugging;
126 extern unsigned int logPanicDataToScreen;
127
128 extern int db_run_mode;
129
130 /* modes the system may be running in */
131
132 #define STEP_NONE 0
133 #define STEP_ONCE 1
134 #define STEP_RETURN 2
135 #define STEP_CALLT 3
136 #define STEP_CONTINUE 4
137 #define STEP_INVISIBLE 5
138 #define STEP_COUNT 6
139 #define STEP_TRACE 7 /* Show all calls to functions and returns */
140
141 extern const char *panicstr;
142 extern volatile unsigned int nestedpanic;
143 extern int unsigned long panic_caller;
144
145 extern char *debug_buf_ptr;
146 extern unsigned int debug_buf_size;
147
148 extern void debug_log_init(void);
149 extern void debug_putc(char);
150
151 extern void panic_init(void);
152
153 int packA(char *inbuf, uint32_t length, uint32_t buflen);
154 void unpackA(char *inbuf, uint32_t length);
155
156 void panic_display_system_configuration(void);
157 void panic_display_zprint(void);
158 #if CONFIG_ZLEAKS
159 void panic_display_ztrace(void);
160 #endif /* CONFIG_ZLEAKS */
161 #endif /* MACH_KERNEL_PRIVATE */
162
163 #define DB_HALT 0x1
164 #define DB_PRT 0x2
165 #define DB_NMI 0x4
166 #define DB_KPRT 0x8
167 #define DB_KDB 0x10
168 #define DB_SLOG 0x20
169 #define DB_ARP 0x40
170 #define DB_KDP_BP_DIS 0x80
171 #define DB_LOG_PI_SCRN 0x100
172 #define DB_KDP_GETC_ENA 0x200
173
174 #define DB_KERN_DUMP_ON_PANIC 0x400 /* Trigger core dump on panic*/
175 #define DB_KERN_DUMP_ON_NMI 0x800 /* Trigger core dump on NMI */
176 #define DB_DBG_POST_CORE 0x1000 /*Wait in debugger after NMI core */
177 #define DB_PANICLOG_DUMP 0x2000 /* Send paniclog on panic,not core*/
178 #define DB_REBOOT_POST_CORE 0x4000 /* Attempt to reboot after
179 * post-panic crashdump/paniclog
180 * dump.
181 */
182
183 #if DEBUG
184 /*
185 * For the DEBUG kernel, support the following:
186 * sysctl -w debug.kprint_syscall=<syscall_mask>
187 * sysctl -w debug.kprint_syscall_process=<p_comm>
188 * <syscall_mask> should be an OR of the masks below
189 * for UNIX, MACH, MDEP, or IPC. This debugging aid
190 * assumes the task/process is locked/wired and will
191 * not go away during evaluation. If no process is
192 * specified, all processes will be traced
193 */
194 extern int debug_kprint_syscall;
195 extern int debug_kprint_current_process(const char **namep);
196 #define DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, namep) \
197 ( (debug_kprint_syscall & (mask)) && debug_kprint_current_process(namep) )
198 #define DEBUG_KPRINT_SYSCALL_MASK(mask, fmt, args...) do { \
199 const char *dks_name = NULL; \
200 if (DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, &dks_name)) { \
201 kprintf("[%s%s%p]" fmt, dks_name ? dks_name : "", \
202 dks_name ? "@" : "", current_thread(), args); \
203 } \
204 } while (0)
205 #else /* !DEBUG */
206 #define DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, namep) (0)
207 #define DEBUG_KPRINT_SYSCALL_MASK(mask, fmt, args...) do { } while(0)
208 #endif /* !DEBUG */
209
210 enum {
211 DEBUG_KPRINT_SYSCALL_UNIX_MASK = 1 << 0,
212 DEBUG_KPRINT_SYSCALL_MACH_MASK = 1 << 1,
213 DEBUG_KPRINT_SYSCALL_MDEP_MASK = 1 << 2,
214 DEBUG_KPRINT_SYSCALL_IPC_MASK = 1 << 3
215 };
216
217 #define DEBUG_KPRINT_SYSCALL_PREDICATE(mask) \
218 DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, NULL)
219 #define DEBUG_KPRINT_SYSCALL_UNIX(fmt, args...) \
220 DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_UNIX_MASK,fmt,args)
221 #define DEBUG_KPRINT_SYSCALL_MACH(fmt, args...) \
222 DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_MACH_MASK,fmt,args)
223 #define DEBUG_KPRINT_SYSCALL_MDEP(fmt, args...) \
224 DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_MDEP_MASK,fmt,args)
225 #define DEBUG_KPRINT_SYSCALL_IPC(fmt, args...) \
226 DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_IPC_MASK,fmt,args)
227
228 #endif /* KERNEL_PRIVATE */
229
230 __BEGIN_DECLS
231
232 extern void panic(const char *string, ...) __printflike(1,2);
233
234 #if KERNEL_PRIVATE
235 void _consume_panic_args(int, ...);
236 #endif
237
238 #if CONFIG_NO_PANIC_STRINGS
239 #if KERNEL_PRIVATE
240 #define panic_plain(x, ...) _consume_panic_args( 0, ## __VA_ARGS__ )
241 #define panic(x, ...) _consume_panic_args( 0, ## __VA_ARGS__ )
242 #else
243 #define panic_plain(...) (panic)((char *)0)
244 #define panic(...) (panic)((char *)0)
245 #endif
246 #else /* CONFIGS_NO_PANIC_STRINGS */
247 #define panic_plain(ex, ...) \
248 (panic)(ex, ## __VA_ARGS__)
249 #define __STRINGIFY(x) #x
250 #define LINE_NUMBER(x) __STRINGIFY(x)
251 #define PANIC_LOCATION __FILE__ ":" LINE_NUMBER(__LINE__)
252 #define panic(ex, ...) \
253 (panic)(# ex "@" PANIC_LOCATION, ## __VA_ARGS__)
254 #endif /* CONFIGS_NO_PANIC_STRINGS */
255
256 void populate_model_name(char *);
257 unsigned panic_active(void);
258 __END_DECLS
259
260 #endif /* _KERN_DEBUG_H_ */