blob: 410decacff8fc7907622e99b9cbf7f3c32b1aefb [file] [log] [blame]
Jason Wessel5d5314d2010-05-20 21:04:20 -05001#ifndef _KDB_H
2#define _KDB_H
3
4/*
5 * Kernel Debugger Architecture Independent Global Headers
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 *
11 * Copyright (c) 2000-2007 Silicon Graphics, Inc. All Rights Reserved.
12 * Copyright (C) 2000 Stephane Eranian <eranian@hpl.hp.com>
13 * Copyright (C) 2009 Jason Wessel <jason.wessel@windriver.com>
14 */
15
Daniel Thompson9452e972014-11-06 14:36:45 +000016/* Shifted versions of the command enable bits are be used if the command
17 * has no arguments (see kdb_check_flags). This allows commands, such as
18 * go, to have different permissions depending upon whether it is called
19 * with an argument.
20 */
21#define KDB_ENABLE_NO_ARGS_SHIFT 10
22
Anton Vorontsov729043e2012-09-24 14:27:52 -070023typedef enum {
Daniel Thompson9452e972014-11-06 14:36:45 +000024 KDB_ENABLE_ALL = (1 << 0), /* Enable everything */
25 KDB_ENABLE_MEM_READ = (1 << 1),
26 KDB_ENABLE_MEM_WRITE = (1 << 2),
27 KDB_ENABLE_REG_READ = (1 << 3),
28 KDB_ENABLE_REG_WRITE = (1 << 4),
29 KDB_ENABLE_INSPECT = (1 << 5),
30 KDB_ENABLE_FLOW_CTRL = (1 << 6),
31 KDB_ENABLE_SIGNAL = (1 << 7),
32 KDB_ENABLE_REBOOT = (1 << 8),
33 /* User exposed values stop here, all remaining flags are
34 * exclusively used to describe a commands behaviour.
35 */
36
37 KDB_ENABLE_ALWAYS_SAFE = (1 << 9),
38 KDB_ENABLE_MASK = (1 << KDB_ENABLE_NO_ARGS_SHIFT) - 1,
39
40 KDB_ENABLE_ALL_NO_ARGS = KDB_ENABLE_ALL << KDB_ENABLE_NO_ARGS_SHIFT,
41 KDB_ENABLE_MEM_READ_NO_ARGS = KDB_ENABLE_MEM_READ
42 << KDB_ENABLE_NO_ARGS_SHIFT,
43 KDB_ENABLE_MEM_WRITE_NO_ARGS = KDB_ENABLE_MEM_WRITE
44 << KDB_ENABLE_NO_ARGS_SHIFT,
45 KDB_ENABLE_REG_READ_NO_ARGS = KDB_ENABLE_REG_READ
46 << KDB_ENABLE_NO_ARGS_SHIFT,
47 KDB_ENABLE_REG_WRITE_NO_ARGS = KDB_ENABLE_REG_WRITE
48 << KDB_ENABLE_NO_ARGS_SHIFT,
49 KDB_ENABLE_INSPECT_NO_ARGS = KDB_ENABLE_INSPECT
50 << KDB_ENABLE_NO_ARGS_SHIFT,
51 KDB_ENABLE_FLOW_CTRL_NO_ARGS = KDB_ENABLE_FLOW_CTRL
52 << KDB_ENABLE_NO_ARGS_SHIFT,
53 KDB_ENABLE_SIGNAL_NO_ARGS = KDB_ENABLE_SIGNAL
54 << KDB_ENABLE_NO_ARGS_SHIFT,
55 KDB_ENABLE_REBOOT_NO_ARGS = KDB_ENABLE_REBOOT
56 << KDB_ENABLE_NO_ARGS_SHIFT,
57 KDB_ENABLE_ALWAYS_SAFE_NO_ARGS = KDB_ENABLE_ALWAYS_SAFE
58 << KDB_ENABLE_NO_ARGS_SHIFT,
59 KDB_ENABLE_MASK_NO_ARGS = KDB_ENABLE_MASK << KDB_ENABLE_NO_ARGS_SHIFT,
60
61 KDB_REPEAT_NO_ARGS = 0x40000000, /* Repeat the command w/o arguments */
62 KDB_REPEAT_WITH_ARGS = 0x80000000, /* Repeat the command with args */
Anton Vorontsov15a42a92014-11-06 14:36:41 +000063} kdb_cmdflags_t;
Anton Vorontsov729043e2012-09-24 14:27:52 -070064
65typedef int (*kdb_func_t)(int, const char **);
66
Jason Wessel5d5314d2010-05-20 21:04:20 -050067#ifdef CONFIG_KGDB_KDB
68#include <linux/init.h>
69#include <linux/sched.h>
Arun Sharma600634972011-07-26 16:09:06 -070070#include <linux/atomic.h>
Jason Wessel5d5314d2010-05-20 21:04:20 -050071
72#define KDB_POLL_FUNC_MAX 5
Jason Wesself5316b42010-05-20 21:04:22 -050073extern int kdb_poll_idx;
Jason Wessel5d5314d2010-05-20 21:04:20 -050074
75/*
76 * kdb_initial_cpu is initialized to -1, and is set to the cpu
77 * number whenever the kernel debugger is entered.
78 */
79extern int kdb_initial_cpu;
80extern atomic_t kdb_event;
81
Jason Wesself7030bb2010-10-11 10:20:14 -050082/* Types and messages used for dynamically added kdb shell commands */
83
84#define KDB_MAXARGS 16 /* Maximum number of arguments to a function */
85
Jason Wesself7030bb2010-10-11 10:20:14 -050086/* KDB return codes from a command or internal kdb function */
87#define KDB_NOTFOUND (-1)
88#define KDB_ARGCOUNT (-2)
89#define KDB_BADWIDTH (-3)
90#define KDB_BADRADIX (-4)
91#define KDB_NOTENV (-5)
92#define KDB_NOENVVALUE (-6)
93#define KDB_NOTIMP (-7)
94#define KDB_ENVFULL (-8)
95#define KDB_ENVBUFFULL (-9)
96#define KDB_TOOMANYBPT (-10)
97#define KDB_TOOMANYDBREGS (-11)
98#define KDB_DUPBPT (-12)
99#define KDB_BPTNOTFOUND (-13)
100#define KDB_BADMODE (-14)
101#define KDB_BADINT (-15)
102#define KDB_INVADDRFMT (-16)
103#define KDB_BADREG (-17)
104#define KDB_BADCPUNUM (-18)
105#define KDB_BADLENGTH (-19)
106#define KDB_NOBP (-20)
107#define KDB_BADADDR (-21)
Anton Vorontsov420c2b12014-11-06 14:36:46 +0000108#define KDB_NOPERM (-22)
Jason Wesself7030bb2010-10-11 10:20:14 -0500109
Jason Wessel5d5314d2010-05-20 21:04:20 -0500110/*
111 * kdb_diemsg
112 *
113 * Contains a pointer to the last string supplied to the
114 * kernel 'die' panic function.
115 */
116extern const char *kdb_diemsg;
117
118#define KDB_FLAG_EARLYKDB (1 << 0) /* set from boot parameter kdb=early */
119#define KDB_FLAG_CATASTROPHIC (1 << 1) /* A catastrophic event has occurred */
120#define KDB_FLAG_CMD_INTERRUPT (1 << 2) /* Previous command was interrupted */
121#define KDB_FLAG_NOIPI (1 << 3) /* Do not send IPIs */
Jason Wessel5d5314d2010-05-20 21:04:20 -0500122#define KDB_FLAG_NO_CONSOLE (1 << 5) /* No console is available,
123 * kdb is disabled */
124#define KDB_FLAG_NO_VT_CONSOLE (1 << 6) /* No VT console is available, do
125 * not use keyboard */
126#define KDB_FLAG_NO_I8042 (1 << 7) /* No i8042 chip is available, do
127 * not use keyboard */
128
129extern int kdb_flags; /* Global flags, see kdb_state for per cpu state */
130
131extern void kdb_save_flags(void);
132extern void kdb_restore_flags(void);
133
134#define KDB_FLAG(flag) (kdb_flags & KDB_FLAG_##flag)
135#define KDB_FLAG_SET(flag) ((void)(kdb_flags |= KDB_FLAG_##flag))
136#define KDB_FLAG_CLEAR(flag) ((void)(kdb_flags &= ~KDB_FLAG_##flag))
137
138/*
139 * External entry point for the kernel debugger. The pt_regs
140 * at the time of entry are supplied along with the reason for
141 * entry to the kernel debugger.
142 */
143
144typedef enum {
145 KDB_REASON_ENTER = 1, /* KDB_ENTER() trap/fault - regs valid */
146 KDB_REASON_ENTER_SLAVE, /* KDB_ENTER_SLAVE() trap/fault - regs valid */
147 KDB_REASON_BREAK, /* Breakpoint inst. - regs valid */
148 KDB_REASON_DEBUG, /* Debug Fault - regs valid */
149 KDB_REASON_OOPS, /* Kernel Oops - regs valid */
150 KDB_REASON_SWITCH, /* CPU switch - regs valid*/
151 KDB_REASON_KEYBOARD, /* Keyboard entry - regs valid */
152 KDB_REASON_NMI, /* Non-maskable interrupt; regs valid */
153 KDB_REASON_RECURSE, /* Recursive entry to kdb;
154 * regs probably valid */
155 KDB_REASON_SSTEP, /* Single Step trap. - regs valid */
Mike Travis8daaa5f2013-10-02 10:14:18 -0500156 KDB_REASON_SYSTEM_NMI, /* In NMI due to SYSTEM cmd; regs valid */
Jason Wessel5d5314d2010-05-20 21:04:20 -0500157} kdb_reason_t;
158
Daniel Thompsonf7d4ca82014-11-07 18:37:57 +0000159enum kdb_msgsrc {
160 KDB_MSGSRC_INTERNAL, /* direct call to kdb_printf() */
161 KDB_MSGSRC_PRINTK, /* trapped from printk() */
162};
163
Jason Wesseld37d39a2010-05-20 21:04:27 -0500164extern int kdb_trap_printk;
Daniel Thompsonf7d4ca82014-11-07 18:37:57 +0000165extern __printf(2, 0) int vkdb_printf(enum kdb_msgsrc src, const char *fmt,
166 va_list args);
Joe Perchesb9075fa2011-10-31 17:11:33 -0700167extern __printf(1, 2) int kdb_printf(const char *, ...);
168typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...);
Jason Wessel5d5314d2010-05-20 21:04:20 -0500169
170extern void kdb_init(int level);
171
172/* Access to kdb specific polling devices */
173typedef int (*get_char_func)(void);
174extern get_char_func kdb_poll_funcs[];
175extern int kdb_get_kbd_char(void);
176
177static inline
178int kdb_process_cpu(const struct task_struct *p)
179{
Andy Lutomirskie558af62016-07-28 15:48:20 -0700180 unsigned int cpu = task_cpu(p);
Jason Wessel5d5314d2010-05-20 21:04:20 -0500181 if (cpu > num_possible_cpus())
182 cpu = 0;
183 return cpu;
184}
185
186/* kdb access to register set for stack dumping */
187extern struct pt_regs *kdb_current_regs;
Jason Wessel91b152a2010-08-23 09:20:14 -0500188#ifdef CONFIG_KALLSYMS
189extern const char *kdb_walk_kallsyms(loff_t *pos);
190#else /* ! CONFIG_KALLSYMS */
191static inline const char *kdb_walk_kallsyms(loff_t *pos)
192{
193 return NULL;
194}
195#endif /* ! CONFIG_KALLSYMS */
Jason Wessel5d5314d2010-05-20 21:04:20 -0500196
Jason Wesself7030bb2010-10-11 10:20:14 -0500197/* Dynamic kdb shell command registration */
198extern int kdb_register(char *, kdb_func_t, char *, char *, short);
Anton Vorontsov42c884c2014-11-06 14:36:42 +0000199extern int kdb_register_flags(char *, kdb_func_t, char *, char *,
200 short, kdb_cmdflags_t);
Jason Wesself7030bb2010-10-11 10:20:14 -0500201extern int kdb_unregister(char *);
Jason Wessel5d5314d2010-05-20 21:04:20 -0500202#else /* ! CONFIG_KGDB_KDB */
Anton Vorontsov729043e2012-09-24 14:27:52 -0700203static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; }
204static inline void kdb_init(int level) {}
205static inline int kdb_register(char *cmd, kdb_func_t func, char *usage,
206 char *help, short minlen) { return 0; }
Anton Vorontsov42c884c2014-11-06 14:36:42 +0000207static inline int kdb_register_flags(char *cmd, kdb_func_t func, char *usage,
208 char *help, short minlen,
209 kdb_cmdflags_t flags) { return 0; }
Anton Vorontsov729043e2012-09-24 14:27:52 -0700210static inline int kdb_unregister(char *cmd) { return 0; }
Jason Wessel5d5314d2010-05-20 21:04:20 -0500211#endif /* CONFIG_KGDB_KDB */
212enum {
213 KDB_NOT_INITIALIZED,
214 KDB_INIT_EARLY,
215 KDB_INIT_FULL,
216};
Jason Wessel81d44502010-08-05 09:22:30 -0500217
218extern int kdbgetintenv(const char *, int *);
219extern int kdb_set(int, const char **);
220
Jason Wessel5d5314d2010-05-20 21:04:20 -0500221#endif /* !_KDB_H */