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