]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/debug.h
xnu-1486.2.11.tar.gz
[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 int32_t pid;
43 uint64_t wait_event;
44 uint64_t continuation;
45 uint64_t thread_id;
46 int32_t state;
47 char ss_flags;
48 /* We restrict ourselves to a statically defined
49 * (current as of 2009) length for the
50 * p_comm string, due to scoping issues (osfmk/bsd and user/kernel
51 * binary compatibility).
52 */
53 char p_comm[17];
54 } __attribute__ ((packed));
55
56 enum {
57 kUser64_p = 0x1,
58 kKernel64_p = 0x2,
59 kHasDispatchSerial = 0x4
60 };
61
62 enum {STACKSHOT_GET_DQ = 1};
63 #define STACKSHOT_DISPATCH_OFFSET_MASK 0xffff0000
64 #define STACKSHOT_DISPATCH_OFFSET_SHIFT 16
65
66 #endif /* __APPLE_API_UNSTABLE */
67 #endif /* __APPLE_API_PRIVATE */
68
69 #ifdef KERNEL_PRIVATE
70
71 extern unsigned int systemLogDiags;
72 extern char debug_buf[];
73
74 #ifdef MACH_KERNEL_PRIVATE
75
76 extern unsigned int halt_in_debugger;
77
78 extern unsigned int switch_debugger;
79
80 extern unsigned int current_debugger;
81 #define NO_CUR_DB 0x0
82 #define KDP_CUR_DB 0x1
83 #define KDB_CUR_DB 0x2
84
85 extern unsigned int active_debugger;
86 extern unsigned int debug_mode;
87 extern unsigned int disable_debug_output;
88
89 extern unsigned int panicDebugging;
90 extern unsigned int logPanicDataToScreen;
91
92 extern int db_run_mode;
93
94 /* modes the system may be running in */
95
96 #define STEP_NONE 0
97 #define STEP_ONCE 1
98 #define STEP_RETURN 2
99 #define STEP_CALLT 3
100 #define STEP_CONTINUE 4
101 #define STEP_INVISIBLE 5
102 #define STEP_COUNT 6
103 #define STEP_TRACE 7 /* Show all calls to functions and returns */
104
105 extern const char *panicstr;
106 extern volatile unsigned int nestedpanic;
107 extern int unsigned long panic_caller;
108
109 extern char *debug_buf_ptr;
110 extern unsigned int debug_buf_size;
111
112 extern void debug_log_init(void);
113 extern void debug_putc(char);
114
115 extern void panic_init(void);
116
117 int packA(char *inbuf, uint32_t length, uint32_t buflen);
118 void unpackA(char *inbuf, uint32_t length);
119
120 void panic_display_system_configuration(void);
121 void panic_display_zprint(void);
122
123 #endif /* MACH_KERNEL_PRIVATE */
124
125 #define DB_HALT 0x1
126 #define DB_PRT 0x2
127 #define DB_NMI 0x4
128 #define DB_KPRT 0x8
129 #define DB_KDB 0x10
130 #define DB_SLOG 0x20
131 #define DB_ARP 0x40
132 #define DB_KDP_BP_DIS 0x80
133 #define DB_LOG_PI_SCRN 0x100
134 #define DB_KDP_GETC_ENA 0x200
135
136 #define DB_KERN_DUMP_ON_PANIC 0x400 /* Trigger core dump on panic*/
137 #define DB_KERN_DUMP_ON_NMI 0x800 /* Trigger core dump on NMI */
138 #define DB_DBG_POST_CORE 0x1000 /*Wait in debugger after NMI core */
139 #define DB_PANICLOG_DUMP 0x2000 /* Send paniclog on panic,not core*/
140 #define DB_REBOOT_POST_CORE 0x4000 /* Attempt to reboot after
141 * post-panic crashdump/paniclog
142 * dump.
143 */
144
145 #if DEBUG
146 /*
147 * For the DEBUG kernel, support the following:
148 * sysctl -w debug.kprint_syscall=<syscall_mask>
149 * sysctl -w debug.kprint_syscall_process=<p_comm>
150 * <syscall_mask> should be an OR of the masks below
151 * for UNIX, MACH, MDEP, or IPC. This debugging aid
152 * assumes the task/process is locked/wired and will
153 * not go away during evaluation. If no process is
154 * specified, all processes will be traced
155 */
156 extern int debug_kprint_syscall;
157 extern int debug_kprint_current_process(const char **namep);
158 #define DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, namep) \
159 ( (debug_kprint_syscall & (mask)) && debug_kprint_current_process(namep) )
160 #define DEBUG_KPRINT_SYSCALL_MASK(mask, fmt, args...) do { \
161 const char *dks_name = NULL; \
162 if (DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, &dks_name)) { \
163 kprintf("[%s%s%p]" fmt, dks_name ? dks_name : "", \
164 dks_name ? "@" : "", current_thread(), args); \
165 } \
166 } while (0)
167 #else /* !DEBUG */
168 #define DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, namep) (0)
169 #define DEBUG_KPRINT_SYSCALL_MASK(mask, fmt, args...) do { } while(0)
170 #endif /* !DEBUG */
171
172 enum {
173 DEBUG_KPRINT_SYSCALL_UNIX_MASK = 1 << 0,
174 DEBUG_KPRINT_SYSCALL_MACH_MASK = 1 << 1,
175 DEBUG_KPRINT_SYSCALL_MDEP_MASK = 1 << 2,
176 DEBUG_KPRINT_SYSCALL_IPC_MASK = 1 << 3
177 };
178
179 #define DEBUG_KPRINT_SYSCALL_PREDICATE(mask) \
180 DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, NULL)
181 #define DEBUG_KPRINT_SYSCALL_UNIX(fmt, args...) \
182 DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_UNIX_MASK,fmt,args)
183 #define DEBUG_KPRINT_SYSCALL_MACH(fmt, args...) \
184 DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_MACH_MASK,fmt,args)
185 #define DEBUG_KPRINT_SYSCALL_MDEP(fmt, args...) \
186 DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_MDEP_MASK,fmt,args)
187 #define DEBUG_KPRINT_SYSCALL_IPC(fmt, args...) \
188 DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_IPC_MASK,fmt,args)
189
190 #endif /* KERNEL_PRIVATE */
191
192 __BEGIN_DECLS
193
194 extern void panic(const char *string, ...) __printflike(1,2);
195
196 #if KERNEL_PRIVATE
197 void _consume_panic_args(int, ...);
198 #endif
199
200 #if CONFIG_NO_PANIC_STRINGS
201 #if KERNEL_PRIVATE
202 #define panic_plain(x, ...) _consume_panic_args( 0, ## __VA_ARGS__ )
203 #define panic(x, ...) _consume_panic_args( 0, ## __VA_ARGS__ )
204 #else
205 #define panic_plain(...) (panic)((char *)0)
206 #define panic(...) (panic)((char *)0)
207 #endif
208 #else /* CONFIGS_NO_PANIC_STRINGS */
209 #define panic_plain(ex, ...) \
210 (panic)(ex, ## __VA_ARGS__)
211 #define __STRINGIFY(x) #x
212 #define LINE_NUMBER(x) __STRINGIFY(x)
213 #define PANIC_LOCATION __FILE__ ":" LINE_NUMBER(__LINE__)
214 #define panic(ex, ...) \
215 (panic)(# ex "@" PANIC_LOCATION, ## __VA_ARGS__)
216 #endif /* CONFIGS_NO_PANIC_STRINGS */
217
218 void populate_model_name(char *);
219 unsigned panic_active(void);
220 __END_DECLS
221
222 #endif /* _KERN_DEBUG_H_ */