blob: 32d2f407981d65caa48a31b669cea7c0b47521a5 [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
Anton Vorontsov729043e2012-09-24 14:27:52 -070016typedef enum {
17 KDB_REPEAT_NONE = 0, /* Do not repeat this command */
18 KDB_REPEAT_NO_ARGS, /* Repeat the command without arguments */
19 KDB_REPEAT_WITH_ARGS, /* Repeat the command including its arguments */
Anton Vorontsov15a42a92014-11-06 14:36:41 +000020} kdb_cmdflags_t;
Anton Vorontsov729043e2012-09-24 14:27:52 -070021
22typedef int (*kdb_func_t)(int, const char **);
23
Jason Wessel5d5314d2010-05-20 21:04:20 -050024#ifdef CONFIG_KGDB_KDB
25#include <linux/init.h>
26#include <linux/sched.h>
Arun Sharma600634972011-07-26 16:09:06 -070027#include <linux/atomic.h>
Jason Wessel5d5314d2010-05-20 21:04:20 -050028
29#define KDB_POLL_FUNC_MAX 5
Jason Wesself5316b42010-05-20 21:04:22 -050030extern int kdb_poll_idx;
Jason Wessel5d5314d2010-05-20 21:04:20 -050031
32/*
33 * kdb_initial_cpu is initialized to -1, and is set to the cpu
34 * number whenever the kernel debugger is entered.
35 */
36extern int kdb_initial_cpu;
37extern atomic_t kdb_event;
38
Jason Wesself7030bb2010-10-11 10:20:14 -050039/* Types and messages used for dynamically added kdb shell commands */
40
41#define KDB_MAXARGS 16 /* Maximum number of arguments to a function */
42
Jason Wesself7030bb2010-10-11 10:20:14 -050043/* KDB return codes from a command or internal kdb function */
44#define KDB_NOTFOUND (-1)
45#define KDB_ARGCOUNT (-2)
46#define KDB_BADWIDTH (-3)
47#define KDB_BADRADIX (-4)
48#define KDB_NOTENV (-5)
49#define KDB_NOENVVALUE (-6)
50#define KDB_NOTIMP (-7)
51#define KDB_ENVFULL (-8)
52#define KDB_ENVBUFFULL (-9)
53#define KDB_TOOMANYBPT (-10)
54#define KDB_TOOMANYDBREGS (-11)
55#define KDB_DUPBPT (-12)
56#define KDB_BPTNOTFOUND (-13)
57#define KDB_BADMODE (-14)
58#define KDB_BADINT (-15)
59#define KDB_INVADDRFMT (-16)
60#define KDB_BADREG (-17)
61#define KDB_BADCPUNUM (-18)
62#define KDB_BADLENGTH (-19)
63#define KDB_NOBP (-20)
64#define KDB_BADADDR (-21)
65
Jason Wessel5d5314d2010-05-20 21:04:20 -050066/*
67 * kdb_diemsg
68 *
69 * Contains a pointer to the last string supplied to the
70 * kernel 'die' panic function.
71 */
72extern const char *kdb_diemsg;
73
74#define KDB_FLAG_EARLYKDB (1 << 0) /* set from boot parameter kdb=early */
75#define KDB_FLAG_CATASTROPHIC (1 << 1) /* A catastrophic event has occurred */
76#define KDB_FLAG_CMD_INTERRUPT (1 << 2) /* Previous command was interrupted */
77#define KDB_FLAG_NOIPI (1 << 3) /* Do not send IPIs */
Jason Wessel5d5314d2010-05-20 21:04:20 -050078#define KDB_FLAG_NO_CONSOLE (1 << 5) /* No console is available,
79 * kdb is disabled */
80#define KDB_FLAG_NO_VT_CONSOLE (1 << 6) /* No VT console is available, do
81 * not use keyboard */
82#define KDB_FLAG_NO_I8042 (1 << 7) /* No i8042 chip is available, do
83 * not use keyboard */
84
85extern int kdb_flags; /* Global flags, see kdb_state for per cpu state */
86
87extern void kdb_save_flags(void);
88extern void kdb_restore_flags(void);
89
90#define KDB_FLAG(flag) (kdb_flags & KDB_FLAG_##flag)
91#define KDB_FLAG_SET(flag) ((void)(kdb_flags |= KDB_FLAG_##flag))
92#define KDB_FLAG_CLEAR(flag) ((void)(kdb_flags &= ~KDB_FLAG_##flag))
93
94/*
95 * External entry point for the kernel debugger. The pt_regs
96 * at the time of entry are supplied along with the reason for
97 * entry to the kernel debugger.
98 */
99
100typedef enum {
101 KDB_REASON_ENTER = 1, /* KDB_ENTER() trap/fault - regs valid */
102 KDB_REASON_ENTER_SLAVE, /* KDB_ENTER_SLAVE() trap/fault - regs valid */
103 KDB_REASON_BREAK, /* Breakpoint inst. - regs valid */
104 KDB_REASON_DEBUG, /* Debug Fault - regs valid */
105 KDB_REASON_OOPS, /* Kernel Oops - regs valid */
106 KDB_REASON_SWITCH, /* CPU switch - regs valid*/
107 KDB_REASON_KEYBOARD, /* Keyboard entry - regs valid */
108 KDB_REASON_NMI, /* Non-maskable interrupt; regs valid */
109 KDB_REASON_RECURSE, /* Recursive entry to kdb;
110 * regs probably valid */
111 KDB_REASON_SSTEP, /* Single Step trap. - regs valid */
Mike Travis8daaa5f2013-10-02 10:14:18 -0500112 KDB_REASON_SYSTEM_NMI, /* In NMI due to SYSTEM cmd; regs valid */
Jason Wessel5d5314d2010-05-20 21:04:20 -0500113} kdb_reason_t;
114
Jason Wesseld37d39a2010-05-20 21:04:27 -0500115extern int kdb_trap_printk;
Joe Perchesb9075fa2011-10-31 17:11:33 -0700116extern __printf(1, 0) int vkdb_printf(const char *fmt, va_list args);
117extern __printf(1, 2) int kdb_printf(const char *, ...);
118typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...);
Jason Wessel5d5314d2010-05-20 21:04:20 -0500119
120extern void kdb_init(int level);
121
122/* Access to kdb specific polling devices */
123typedef int (*get_char_func)(void);
124extern get_char_func kdb_poll_funcs[];
125extern int kdb_get_kbd_char(void);
126
127static inline
128int kdb_process_cpu(const struct task_struct *p)
129{
130 unsigned int cpu = task_thread_info(p)->cpu;
131 if (cpu > num_possible_cpus())
132 cpu = 0;
133 return cpu;
134}
135
136/* kdb access to register set for stack dumping */
137extern struct pt_regs *kdb_current_regs;
Jason Wessel91b152a2010-08-23 09:20:14 -0500138#ifdef CONFIG_KALLSYMS
139extern const char *kdb_walk_kallsyms(loff_t *pos);
140#else /* ! CONFIG_KALLSYMS */
141static inline const char *kdb_walk_kallsyms(loff_t *pos)
142{
143 return NULL;
144}
145#endif /* ! CONFIG_KALLSYMS */
Jason Wessel5d5314d2010-05-20 21:04:20 -0500146
Jason Wesself7030bb2010-10-11 10:20:14 -0500147/* Dynamic kdb shell command registration */
148extern int kdb_register(char *, kdb_func_t, char *, char *, short);
Anton Vorontsov42c884c2014-11-06 14:36:42 +0000149extern int kdb_register_flags(char *, kdb_func_t, char *, char *,
150 short, kdb_cmdflags_t);
Jason Wesself7030bb2010-10-11 10:20:14 -0500151extern int kdb_unregister(char *);
Jason Wessel5d5314d2010-05-20 21:04:20 -0500152#else /* ! CONFIG_KGDB_KDB */
Anton Vorontsov729043e2012-09-24 14:27:52 -0700153static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; }
154static inline void kdb_init(int level) {}
155static inline int kdb_register(char *cmd, kdb_func_t func, char *usage,
156 char *help, short minlen) { return 0; }
Anton Vorontsov42c884c2014-11-06 14:36:42 +0000157static inline int kdb_register_flags(char *cmd, kdb_func_t func, char *usage,
158 char *help, short minlen,
159 kdb_cmdflags_t flags) { return 0; }
Anton Vorontsov729043e2012-09-24 14:27:52 -0700160static inline int kdb_unregister(char *cmd) { return 0; }
Jason Wessel5d5314d2010-05-20 21:04:20 -0500161#endif /* CONFIG_KGDB_KDB */
162enum {
163 KDB_NOT_INITIALIZED,
164 KDB_INIT_EARLY,
165 KDB_INIT_FULL,
166};
Jason Wessel81d44502010-08-05 09:22:30 -0500167
168extern int kdbgetintenv(const char *, int *);
169extern int kdb_set(int, const char **);
170
Jason Wessel5d5314d2010-05-20 21:04:20 -0500171#endif /* !_KDB_H */