Back to home page

OSCL-LXR

 
 

    


0001 #ifndef _KDB_H
0002 #define _KDB_H
0003 
0004 /*
0005  * Kernel Debugger Architecture Independent Global Headers
0006  *
0007  * This file is subject to the terms and conditions of the GNU General Public
0008  * License.  See the file "COPYING" in the main directory of this archive
0009  * for more details.
0010  *
0011  * Copyright (c) 2000-2007 Silicon Graphics, Inc.  All Rights Reserved.
0012  * Copyright (C) 2000 Stephane Eranian <eranian@hpl.hp.com>
0013  * Copyright (C) 2009 Jason Wessel <jason.wessel@windriver.com>
0014  */
0015 
0016 #include <linux/list.h>
0017 
0018 /* Shifted versions of the command enable bits are be used if the command
0019  * has no arguments (see kdb_check_flags). This allows commands, such as
0020  * go, to have different permissions depending upon whether it is called
0021  * with an argument.
0022  */
0023 #define KDB_ENABLE_NO_ARGS_SHIFT 10
0024 
0025 typedef enum {
0026     KDB_ENABLE_ALL = (1 << 0), /* Enable everything */
0027     KDB_ENABLE_MEM_READ = (1 << 1),
0028     KDB_ENABLE_MEM_WRITE = (1 << 2),
0029     KDB_ENABLE_REG_READ = (1 << 3),
0030     KDB_ENABLE_REG_WRITE = (1 << 4),
0031     KDB_ENABLE_INSPECT = (1 << 5),
0032     KDB_ENABLE_FLOW_CTRL = (1 << 6),
0033     KDB_ENABLE_SIGNAL = (1 << 7),
0034     KDB_ENABLE_REBOOT = (1 << 8),
0035     /* User exposed values stop here, all remaining flags are
0036      * exclusively used to describe a commands behaviour.
0037      */
0038 
0039     KDB_ENABLE_ALWAYS_SAFE = (1 << 9),
0040     KDB_ENABLE_MASK = (1 << KDB_ENABLE_NO_ARGS_SHIFT) - 1,
0041 
0042     KDB_ENABLE_ALL_NO_ARGS = KDB_ENABLE_ALL << KDB_ENABLE_NO_ARGS_SHIFT,
0043     KDB_ENABLE_MEM_READ_NO_ARGS = KDB_ENABLE_MEM_READ
0044                       << KDB_ENABLE_NO_ARGS_SHIFT,
0045     KDB_ENABLE_MEM_WRITE_NO_ARGS = KDB_ENABLE_MEM_WRITE
0046                        << KDB_ENABLE_NO_ARGS_SHIFT,
0047     KDB_ENABLE_REG_READ_NO_ARGS = KDB_ENABLE_REG_READ
0048                       << KDB_ENABLE_NO_ARGS_SHIFT,
0049     KDB_ENABLE_REG_WRITE_NO_ARGS = KDB_ENABLE_REG_WRITE
0050                        << KDB_ENABLE_NO_ARGS_SHIFT,
0051     KDB_ENABLE_INSPECT_NO_ARGS = KDB_ENABLE_INSPECT
0052                      << KDB_ENABLE_NO_ARGS_SHIFT,
0053     KDB_ENABLE_FLOW_CTRL_NO_ARGS = KDB_ENABLE_FLOW_CTRL
0054                        << KDB_ENABLE_NO_ARGS_SHIFT,
0055     KDB_ENABLE_SIGNAL_NO_ARGS = KDB_ENABLE_SIGNAL
0056                     << KDB_ENABLE_NO_ARGS_SHIFT,
0057     KDB_ENABLE_REBOOT_NO_ARGS = KDB_ENABLE_REBOOT
0058                     << KDB_ENABLE_NO_ARGS_SHIFT,
0059     KDB_ENABLE_ALWAYS_SAFE_NO_ARGS = KDB_ENABLE_ALWAYS_SAFE
0060                      << KDB_ENABLE_NO_ARGS_SHIFT,
0061     KDB_ENABLE_MASK_NO_ARGS = KDB_ENABLE_MASK << KDB_ENABLE_NO_ARGS_SHIFT,
0062 
0063     KDB_REPEAT_NO_ARGS = 0x40000000, /* Repeat the command w/o arguments */
0064     KDB_REPEAT_WITH_ARGS = 0x80000000, /* Repeat the command with args */
0065 } kdb_cmdflags_t;
0066 
0067 typedef int (*kdb_func_t)(int, const char **);
0068 
0069 /* The KDB shell command table */
0070 typedef struct _kdbtab {
0071     char    *name;          /* Command name */
0072     kdb_func_t func;        /* Function to execute command */
0073     char    *usage;         /* Usage String for this command */
0074     char    *help;          /* Help message for this command */
0075     short    minlen;        /* Minimum legal # cmd chars required */
0076     kdb_cmdflags_t flags;       /* Command behaviour flags */
0077     struct list_head list_node; /* Command list */
0078 } kdbtab_t;
0079 
0080 #ifdef  CONFIG_KGDB_KDB
0081 #include <linux/init.h>
0082 #include <linux/sched.h>
0083 #include <linux/atomic.h>
0084 
0085 #define KDB_POLL_FUNC_MAX   5
0086 extern int kdb_poll_idx;
0087 
0088 /*
0089  * kdb_initial_cpu is initialized to -1, and is set to the cpu
0090  * number whenever the kernel debugger is entered.
0091  */
0092 extern int kdb_initial_cpu;
0093 
0094 /* Types and messages used for dynamically added kdb shell commands */
0095 
0096 #define KDB_MAXARGS    16 /* Maximum number of arguments to a function  */
0097 
0098 /* KDB return codes from a command or internal kdb function */
0099 #define KDB_NOTFOUND    (-1)
0100 #define KDB_ARGCOUNT    (-2)
0101 #define KDB_BADWIDTH    (-3)
0102 #define KDB_BADRADIX    (-4)
0103 #define KDB_NOTENV  (-5)
0104 #define KDB_NOENVVALUE  (-6)
0105 #define KDB_NOTIMP  (-7)
0106 #define KDB_ENVFULL (-8)
0107 #define KDB_ENVBUFFULL  (-9)
0108 #define KDB_TOOMANYBPT  (-10)
0109 #define KDB_TOOMANYDBREGS (-11)
0110 #define KDB_DUPBPT  (-12)
0111 #define KDB_BPTNOTFOUND (-13)
0112 #define KDB_BADMODE (-14)
0113 #define KDB_BADINT  (-15)
0114 #define KDB_INVADDRFMT  (-16)
0115 #define KDB_BADREG      (-17)
0116 #define KDB_BADCPUNUM   (-18)
0117 #define KDB_BADLENGTH   (-19)
0118 #define KDB_NOBP    (-20)
0119 #define KDB_BADADDR (-21)
0120 #define KDB_NOPERM  (-22)
0121 
0122 /*
0123  * kdb_diemsg
0124  *
0125  *  Contains a pointer to the last string supplied to the
0126  *  kernel 'die' panic function.
0127  */
0128 extern const char *kdb_diemsg;
0129 
0130 #define KDB_FLAG_EARLYKDB   (1 << 0) /* set from boot parameter kdb=early */
0131 #define KDB_FLAG_CATASTROPHIC   (1 << 1) /* A catastrophic event has occurred */
0132 #define KDB_FLAG_CMD_INTERRUPT  (1 << 2) /* Previous command was interrupted */
0133 #define KDB_FLAG_NOIPI      (1 << 3) /* Do not send IPIs */
0134 #define KDB_FLAG_NO_CONSOLE (1 << 5) /* No console is available,
0135                       * kdb is disabled */
0136 #define KDB_FLAG_NO_VT_CONSOLE  (1 << 6) /* No VT console is available, do
0137                       * not use keyboard */
0138 #define KDB_FLAG_NO_I8042   (1 << 7) /* No i8042 chip is available, do
0139                       * not use keyboard */
0140 
0141 extern unsigned int kdb_flags;  /* Global flags, see kdb_state for per cpu state */
0142 
0143 extern void kdb_save_flags(void);
0144 extern void kdb_restore_flags(void);
0145 
0146 #define KDB_FLAG(flag)      (kdb_flags & KDB_FLAG_##flag)
0147 #define KDB_FLAG_SET(flag)  ((void)(kdb_flags |= KDB_FLAG_##flag))
0148 #define KDB_FLAG_CLEAR(flag)    ((void)(kdb_flags &= ~KDB_FLAG_##flag))
0149 
0150 /*
0151  * External entry point for the kernel debugger.  The pt_regs
0152  * at the time of entry are supplied along with the reason for
0153  * entry to the kernel debugger.
0154  */
0155 
0156 typedef enum {
0157     KDB_REASON_ENTER = 1,   /* KDB_ENTER() trap/fault - regs valid */
0158     KDB_REASON_ENTER_SLAVE, /* KDB_ENTER_SLAVE() trap/fault - regs valid */
0159     KDB_REASON_BREAK,   /* Breakpoint inst. - regs valid */
0160     KDB_REASON_DEBUG,   /* Debug Fault - regs valid */
0161     KDB_REASON_OOPS,    /* Kernel Oops - regs valid */
0162     KDB_REASON_SWITCH,  /* CPU switch - regs valid*/
0163     KDB_REASON_KEYBOARD,    /* Keyboard entry - regs valid */
0164     KDB_REASON_NMI,     /* Non-maskable interrupt; regs valid */
0165     KDB_REASON_RECURSE, /* Recursive entry to kdb;
0166                  * regs probably valid */
0167     KDB_REASON_SSTEP,   /* Single Step trap. - regs valid */
0168     KDB_REASON_SYSTEM_NMI,  /* In NMI due to SYSTEM cmd; regs valid */
0169 } kdb_reason_t;
0170 
0171 enum kdb_msgsrc {
0172     KDB_MSGSRC_INTERNAL, /* direct call to kdb_printf() */
0173     KDB_MSGSRC_PRINTK, /* trapped from printk() */
0174 };
0175 
0176 extern int kdb_trap_printk;
0177 extern int kdb_printf_cpu;
0178 extern __printf(2, 0) int vkdb_printf(enum kdb_msgsrc src, const char *fmt,
0179                       va_list args);
0180 extern __printf(1, 2) int kdb_printf(const char *, ...);
0181 typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...);
0182 
0183 extern void kdb_init(int level);
0184 
0185 /* Access to kdb specific polling devices */
0186 typedef int (*get_char_func)(void);
0187 extern get_char_func kdb_poll_funcs[];
0188 extern int kdb_get_kbd_char(void);
0189 
0190 static inline
0191 int kdb_process_cpu(const struct task_struct *p)
0192 {
0193     unsigned int cpu = task_cpu(p);
0194     if (cpu > num_possible_cpus())
0195         cpu = 0;
0196     return cpu;
0197 }
0198 
0199 #ifdef CONFIG_KALLSYMS
0200 extern const char *kdb_walk_kallsyms(loff_t *pos);
0201 #else /* ! CONFIG_KALLSYMS */
0202 static inline const char *kdb_walk_kallsyms(loff_t *pos)
0203 {
0204     return NULL;
0205 }
0206 #endif /* ! CONFIG_KALLSYMS */
0207 
0208 /* Dynamic kdb shell command registration */
0209 extern int kdb_register(kdbtab_t *cmd);
0210 extern void kdb_unregister(kdbtab_t *cmd);
0211 #else /* ! CONFIG_KGDB_KDB */
0212 static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; }
0213 static inline void kdb_init(int level) {}
0214 static inline int kdb_register(kdbtab_t *cmd) { return 0; }
0215 static inline void kdb_unregister(kdbtab_t *cmd) {}
0216 #endif  /* CONFIG_KGDB_KDB */
0217 enum {
0218     KDB_NOT_INITIALIZED,
0219     KDB_INIT_EARLY,
0220     KDB_INIT_FULL,
0221 };
0222 
0223 extern int kdbgetintenv(const char *, int *);
0224 extern int kdb_set(int, const char **);
0225 int kdb_lsmod(int argc, const char **argv);
0226 
0227 #endif  /* !_KDB_H */