]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/debug.h
xnu-2050.48.11.tar.gz
[apple/xnu.git] / osfmk / kern / debug.h
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b 27 */
9bccf70c 28
1c79356b
A
29#ifndef _KERN_DEBUG_H_
30#define _KERN_DEBUG_H_
31
91447636 32#include <sys/cdefs.h>
2d21ac55 33#include <stdint.h>
9bccf70c 34
b0d623f7
A
35#ifdef __APPLE_API_PRIVATE
36#ifdef __APPLE_API_UNSTABLE
37
38struct thread_snapshot {
39 uint32_t snapshot_magic;
40 uint32_t nkern_frames;
41 uint32_t nuser_frames;
b0d623f7 42 uint64_t wait_event;
6d2010ae 43 uint64_t continuation;
b0d623f7 44 uint64_t thread_id;
6d2010ae
A
45 uint64_t user_time;
46 uint64_t system_time;
b0d623f7 47 int32_t state;
316670eb
A
48 int32_t sched_pri; // scheduled (current) priority
49 int32_t sched_flags; // scheduler flags
b0d623f7 50 char ss_flags;
b7266188
A
51} __attribute__ ((packed));
52
53struct task_snapshot {
54 uint32_t snapshot_magic;
55 int32_t pid;
56 uint32_t nloadinfos;
6d2010ae
A
57 uint64_t user_time_in_terminated_threads;
58 uint64_t system_time_in_terminated_threads;
59 int suspend_count;
60 int task_size; // pages
61 int faults; // number of page faults
62 int pageins; // number of actual pageins
63 int cow_faults; // number of copy-on-write faults
b7266188 64 char ss_flags;
b0d623f7
A
65 /* We restrict ourselves to a statically defined
66 * (current as of 2009) length for the
67 * p_comm string, due to scoping issues (osfmk/bsd and user/kernel
68 * binary compatibility).
69 */
70 char p_comm[17];
71} __attribute__ ((packed));
72
6d2010ae 73
316670eb 74struct mem_and_io_snapshot {
6d2010ae
A
75 uint32_t snapshot_magic;
76 uint32_t free_pages;
77 uint32_t active_pages;
78 uint32_t inactive_pages;
79 uint32_t purgeable_pages;
80 uint32_t wired_pages;
81 uint32_t speculative_pages;
82 uint32_t throttled_pages;
316670eb
A
83 int busy_buffer_count;
84 uint32_t pages_wanted;
85 uint32_t pages_reclaimed;
86 uint8_t pages_wanted_reclaimed_valid; // did mach_vm_pressure_monitor succeed?
6d2010ae
A
87} __attribute__((packed));
88
316670eb 89
b0d623f7
A
90enum {
91 kUser64_p = 0x1,
92 kKernel64_p = 0x2,
6d2010ae 93 kHasDispatchSerial = 0x4,
316670eb
A
94 kTerminatedSnapshot = 0x8,
95 kPidSuspended = 0x10, // true for suspended task
96 kFrozen = 0x20 // true for hibernated task (along with pidsuspended)
b0d623f7
A
97};
98
316670eb
A
99#define VM_PRESSURE_TIME_WINDOW 5 /* seconds */
100
b7266188 101enum {
6d2010ae
A
102 STACKSHOT_GET_DQ = 0x1,
103 STACKSHOT_SAVE_LOADINFO = 0x2,
104 STACKSHOT_GET_GLOBAL_MEM_STATS = 0x4
b7266188
A
105};
106
316670eb
A
107#define STACKSHOT_THREAD_SNAPSHOT_MAGIC 0xfeedface
108#define STACKSHOT_TASK_SNAPSHOT_MAGIC 0xdecafbad
109#define STACKSHOT_MEM_AND_IO_SNAPSHOT_MAGIC 0xbfcabcde
b0d623f7
A
110
111#endif /* __APPLE_API_UNSTABLE */
112#endif /* __APPLE_API_PRIVATE */
113
91447636 114#ifdef KERNEL_PRIVATE
1c79356b
A
115
116extern unsigned int systemLogDiags;
593a1d5f 117extern char debug_buf[];
b7266188 118extern unsigned int debug_boot_arg;
6d2010ae 119extern char kernel_uuid[];
1c79356b
A
120
121#ifdef MACH_KERNEL_PRIVATE
122
123extern unsigned int halt_in_debugger;
124
125extern unsigned int switch_debugger;
126
127extern unsigned int current_debugger;
128#define NO_CUR_DB 0x0
129#define KDP_CUR_DB 0x1
130#define KDB_CUR_DB 0x2
131
6d2010ae 132extern unsigned int active_debugger;
1c79356b 133extern unsigned int debug_mode;
593a1d5f 134extern unsigned int disable_debug_output;
9bccf70c 135
6d2010ae
A
136extern unsigned int panicDebugging;
137extern unsigned int logPanicDataToScreen;
1c79356b
A
138
139extern int db_run_mode;
140
141/* modes the system may be running in */
142
143#define STEP_NONE 0
144#define STEP_ONCE 1
145#define STEP_RETURN 2
146#define STEP_CALLT 3
147#define STEP_CONTINUE 4
148#define STEP_INVISIBLE 5
149#define STEP_COUNT 6
150#define STEP_TRACE 7 /* Show all calls to functions and returns */
151
91447636
A
152extern const char *panicstr;
153extern volatile unsigned int nestedpanic;
2d21ac55 154extern int unsigned long panic_caller;
1c79356b 155
9bccf70c
A
156extern char *debug_buf_ptr;
157extern unsigned int debug_buf_size;
158
159extern void debug_log_init(void);
160extern void debug_putc(char);
161
91447636
A
162extern void panic_init(void);
163
2d21ac55
A
164int packA(char *inbuf, uint32_t length, uint32_t buflen);
165void unpackA(char *inbuf, uint32_t length);
166
167void panic_display_system_configuration(void);
c910b4d9 168void panic_display_zprint(void);
6d2010ae
A
169#if CONFIG_ZLEAKS
170void panic_display_ztrace(void);
171#endif /* CONFIG_ZLEAKS */
1c79356b
A
172#endif /* MACH_KERNEL_PRIVATE */
173
174#define DB_HALT 0x1
175#define DB_PRT 0x2
176#define DB_NMI 0x4
177#define DB_KPRT 0x8
178#define DB_KDB 0x10
179#define DB_SLOG 0x20
9bccf70c
A
180#define DB_ARP 0x40
181#define DB_KDP_BP_DIS 0x80
182#define DB_LOG_PI_SCRN 0x100
55e303ae 183#define DB_KDP_GETC_ENA 0x200
9bccf70c 184
b0d623f7
A
185#define DB_KERN_DUMP_ON_PANIC 0x400 /* Trigger core dump on panic*/
186#define DB_KERN_DUMP_ON_NMI 0x800 /* Trigger core dump on NMI */
187#define DB_DBG_POST_CORE 0x1000 /*Wait in debugger after NMI core */
188#define DB_PANICLOG_DUMP 0x2000 /* Send paniclog on panic,not core*/
189#define DB_REBOOT_POST_CORE 0x4000 /* Attempt to reboot after
190 * post-panic crashdump/paniclog
191 * dump.
192 */
91447636 193
b0d623f7
A
194#if DEBUG
195/*
196 * For the DEBUG kernel, support the following:
197 * sysctl -w debug.kprint_syscall=<syscall_mask>
198 * sysctl -w debug.kprint_syscall_process=<p_comm>
199 * <syscall_mask> should be an OR of the masks below
200 * for UNIX, MACH, MDEP, or IPC. This debugging aid
201 * assumes the task/process is locked/wired and will
202 * not go away during evaluation. If no process is
203 * specified, all processes will be traced
204 */
205extern int debug_kprint_syscall;
206extern int debug_kprint_current_process(const char **namep);
207#define DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, namep) \
208 ( (debug_kprint_syscall & (mask)) && debug_kprint_current_process(namep) )
209#define DEBUG_KPRINT_SYSCALL_MASK(mask, fmt, args...) do { \
210 const char *dks_name = NULL; \
211 if (DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, &dks_name)) { \
212 kprintf("[%s%s%p]" fmt, dks_name ? dks_name : "", \
213 dks_name ? "@" : "", current_thread(), args); \
214 } \
215 } while (0)
216#else /* !DEBUG */
217#define DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, namep) (0)
316670eb 218#define DEBUG_KPRINT_SYSCALL_MASK(mask, fmt, args...) do { } while (0) /* kprintf(fmt, args) */
b0d623f7
A
219#endif /* !DEBUG */
220
221enum {
222 DEBUG_KPRINT_SYSCALL_UNIX_MASK = 1 << 0,
223 DEBUG_KPRINT_SYSCALL_MACH_MASK = 1 << 1,
224 DEBUG_KPRINT_SYSCALL_MDEP_MASK = 1 << 2,
225 DEBUG_KPRINT_SYSCALL_IPC_MASK = 1 << 3
226};
227
228#define DEBUG_KPRINT_SYSCALL_PREDICATE(mask) \
229 DEBUG_KPRINT_SYSCALL_PREDICATE_INTERNAL(mask, NULL)
230#define DEBUG_KPRINT_SYSCALL_UNIX(fmt, args...) \
231 DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_UNIX_MASK,fmt,args)
232#define DEBUG_KPRINT_SYSCALL_MACH(fmt, args...) \
233 DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_MACH_MASK,fmt,args)
234#define DEBUG_KPRINT_SYSCALL_MDEP(fmt, args...) \
235 DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_MDEP_MASK,fmt,args)
236#define DEBUG_KPRINT_SYSCALL_IPC(fmt, args...) \
237 DEBUG_KPRINT_SYSCALL_MASK(DEBUG_KPRINT_SYSCALL_IPC_MASK,fmt,args)
593a1d5f 238
91447636
A
239#endif /* KERNEL_PRIVATE */
240
241__BEGIN_DECLS
242
2d21ac55 243extern void panic(const char *string, ...) __printflike(1,2);
b0d623f7
A
244
245#if KERNEL_PRIVATE
246void _consume_panic_args(int, ...);
316670eb 247void panic_context(unsigned int reason, void *ctx, const char *string, ...);
b0d623f7
A
248#endif
249
2d21ac55 250#if CONFIG_NO_PANIC_STRINGS
b0d623f7
A
251#if KERNEL_PRIVATE
252#define panic_plain(x, ...) _consume_panic_args( 0, ## __VA_ARGS__ )
253#define panic(x, ...) _consume_panic_args( 0, ## __VA_ARGS__ )
254#else
2d21ac55
A
255#define panic_plain(...) (panic)((char *)0)
256#define panic(...) (panic)((char *)0)
b0d623f7 257#endif
2d21ac55
A
258#else /* CONFIGS_NO_PANIC_STRINGS */
259#define panic_plain(ex, ...) \
260 (panic)(ex, ## __VA_ARGS__)
261#define __STRINGIFY(x) #x
262#define LINE_NUMBER(x) __STRINGIFY(x)
263#define PANIC_LOCATION __FILE__ ":" LINE_NUMBER(__LINE__)
264#define panic(ex, ...) \
265 (panic)(# ex "@" PANIC_LOCATION, ## __VA_ARGS__)
266#endif /* CONFIGS_NO_PANIC_STRINGS */
267
268void populate_model_name(char *);
269unsigned panic_active(void);
91447636 270__END_DECLS
1c79356b
A
271
272#endif /* _KERN_DEBUG_H_ */