kdb.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #ifndef _KDB_H
  2. #define _KDB_H
  3. /*
  4. * Kernel Debugger Architecture Independent Global Headers
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. *
  10. * Copyright (c) 2000-2007 Silicon Graphics, Inc. All Rights Reserved.
  11. * Copyright (C) 2000 Stephane Eranian <[email protected]>
  12. * Copyright (C) 2009 Jason Wessel <[email protected]>
  13. */
  14. #include <linux/list.h>
  15. /* Shifted versions of the command enable bits are be used if the command
  16. * has no arguments (see kdb_check_flags). This allows commands, such as
  17. * go, to have different permissions depending upon whether it is called
  18. * with an argument.
  19. */
  20. #define KDB_ENABLE_NO_ARGS_SHIFT 10
  21. typedef enum {
  22. KDB_ENABLE_ALL = (1 << 0), /* Enable everything */
  23. KDB_ENABLE_MEM_READ = (1 << 1),
  24. KDB_ENABLE_MEM_WRITE = (1 << 2),
  25. KDB_ENABLE_REG_READ = (1 << 3),
  26. KDB_ENABLE_REG_WRITE = (1 << 4),
  27. KDB_ENABLE_INSPECT = (1 << 5),
  28. KDB_ENABLE_FLOW_CTRL = (1 << 6),
  29. KDB_ENABLE_SIGNAL = (1 << 7),
  30. KDB_ENABLE_REBOOT = (1 << 8),
  31. /* User exposed values stop here, all remaining flags are
  32. * exclusively used to describe a commands behaviour.
  33. */
  34. KDB_ENABLE_ALWAYS_SAFE = (1 << 9),
  35. KDB_ENABLE_MASK = (1 << KDB_ENABLE_NO_ARGS_SHIFT) - 1,
  36. KDB_ENABLE_ALL_NO_ARGS = KDB_ENABLE_ALL << KDB_ENABLE_NO_ARGS_SHIFT,
  37. KDB_ENABLE_MEM_READ_NO_ARGS = KDB_ENABLE_MEM_READ
  38. << KDB_ENABLE_NO_ARGS_SHIFT,
  39. KDB_ENABLE_MEM_WRITE_NO_ARGS = KDB_ENABLE_MEM_WRITE
  40. << KDB_ENABLE_NO_ARGS_SHIFT,
  41. KDB_ENABLE_REG_READ_NO_ARGS = KDB_ENABLE_REG_READ
  42. << KDB_ENABLE_NO_ARGS_SHIFT,
  43. KDB_ENABLE_REG_WRITE_NO_ARGS = KDB_ENABLE_REG_WRITE
  44. << KDB_ENABLE_NO_ARGS_SHIFT,
  45. KDB_ENABLE_INSPECT_NO_ARGS = KDB_ENABLE_INSPECT
  46. << KDB_ENABLE_NO_ARGS_SHIFT,
  47. KDB_ENABLE_FLOW_CTRL_NO_ARGS = KDB_ENABLE_FLOW_CTRL
  48. << KDB_ENABLE_NO_ARGS_SHIFT,
  49. KDB_ENABLE_SIGNAL_NO_ARGS = KDB_ENABLE_SIGNAL
  50. << KDB_ENABLE_NO_ARGS_SHIFT,
  51. KDB_ENABLE_REBOOT_NO_ARGS = KDB_ENABLE_REBOOT
  52. << KDB_ENABLE_NO_ARGS_SHIFT,
  53. KDB_ENABLE_ALWAYS_SAFE_NO_ARGS = KDB_ENABLE_ALWAYS_SAFE
  54. << KDB_ENABLE_NO_ARGS_SHIFT,
  55. KDB_ENABLE_MASK_NO_ARGS = KDB_ENABLE_MASK << KDB_ENABLE_NO_ARGS_SHIFT,
  56. KDB_REPEAT_NO_ARGS = 0x40000000, /* Repeat the command w/o arguments */
  57. KDB_REPEAT_WITH_ARGS = 0x80000000, /* Repeat the command with args */
  58. } kdb_cmdflags_t;
  59. typedef int (*kdb_func_t)(int, const char **);
  60. /* The KDB shell command table */
  61. typedef struct _kdbtab {
  62. char *name; /* Command name */
  63. kdb_func_t func; /* Function to execute command */
  64. char *usage; /* Usage String for this command */
  65. char *help; /* Help message for this command */
  66. short minlen; /* Minimum legal # cmd chars required */
  67. kdb_cmdflags_t flags; /* Command behaviour flags */
  68. struct list_head list_node; /* Command list */
  69. } kdbtab_t;
  70. #ifdef CONFIG_KGDB_KDB
  71. #include <linux/init.h>
  72. #include <linux/sched.h>
  73. #include <linux/atomic.h>
  74. #define KDB_POLL_FUNC_MAX 5
  75. extern int kdb_poll_idx;
  76. /*
  77. * kdb_initial_cpu is initialized to -1, and is set to the cpu
  78. * number whenever the kernel debugger is entered.
  79. */
  80. extern int kdb_initial_cpu;
  81. /* Types and messages used for dynamically added kdb shell commands */
  82. #define KDB_MAXARGS 16 /* Maximum number of arguments to a function */
  83. /* KDB return codes from a command or internal kdb function */
  84. #define KDB_NOTFOUND (-1)
  85. #define KDB_ARGCOUNT (-2)
  86. #define KDB_BADWIDTH (-3)
  87. #define KDB_BADRADIX (-4)
  88. #define KDB_NOTENV (-5)
  89. #define KDB_NOENVVALUE (-6)
  90. #define KDB_NOTIMP (-7)
  91. #define KDB_ENVFULL (-8)
  92. #define KDB_ENVBUFFULL (-9)
  93. #define KDB_TOOMANYBPT (-10)
  94. #define KDB_TOOMANYDBREGS (-11)
  95. #define KDB_DUPBPT (-12)
  96. #define KDB_BPTNOTFOUND (-13)
  97. #define KDB_BADMODE (-14)
  98. #define KDB_BADINT (-15)
  99. #define KDB_INVADDRFMT (-16)
  100. #define KDB_BADREG (-17)
  101. #define KDB_BADCPUNUM (-18)
  102. #define KDB_BADLENGTH (-19)
  103. #define KDB_NOBP (-20)
  104. #define KDB_BADADDR (-21)
  105. #define KDB_NOPERM (-22)
  106. /*
  107. * kdb_diemsg
  108. *
  109. * Contains a pointer to the last string supplied to the
  110. * kernel 'die' panic function.
  111. */
  112. extern const char *kdb_diemsg;
  113. #define KDB_FLAG_EARLYKDB (1 << 0) /* set from boot parameter kdb=early */
  114. #define KDB_FLAG_CATASTROPHIC (1 << 1) /* A catastrophic event has occurred */
  115. #define KDB_FLAG_CMD_INTERRUPT (1 << 2) /* Previous command was interrupted */
  116. #define KDB_FLAG_NOIPI (1 << 3) /* Do not send IPIs */
  117. #define KDB_FLAG_NO_CONSOLE (1 << 5) /* No console is available,
  118. * kdb is disabled */
  119. #define KDB_FLAG_NO_VT_CONSOLE (1 << 6) /* No VT console is available, do
  120. * not use keyboard */
  121. #define KDB_FLAG_NO_I8042 (1 << 7) /* No i8042 chip is available, do
  122. * not use keyboard */
  123. extern unsigned int kdb_flags; /* Global flags, see kdb_state for per cpu state */
  124. extern void kdb_save_flags(void);
  125. extern void kdb_restore_flags(void);
  126. #define KDB_FLAG(flag) (kdb_flags & KDB_FLAG_##flag)
  127. #define KDB_FLAG_SET(flag) ((void)(kdb_flags |= KDB_FLAG_##flag))
  128. #define KDB_FLAG_CLEAR(flag) ((void)(kdb_flags &= ~KDB_FLAG_##flag))
  129. /*
  130. * External entry point for the kernel debugger. The pt_regs
  131. * at the time of entry are supplied along with the reason for
  132. * entry to the kernel debugger.
  133. */
  134. typedef enum {
  135. KDB_REASON_ENTER = 1, /* KDB_ENTER() trap/fault - regs valid */
  136. KDB_REASON_ENTER_SLAVE, /* KDB_ENTER_SLAVE() trap/fault - regs valid */
  137. KDB_REASON_BREAK, /* Breakpoint inst. - regs valid */
  138. KDB_REASON_DEBUG, /* Debug Fault - regs valid */
  139. KDB_REASON_OOPS, /* Kernel Oops - regs valid */
  140. KDB_REASON_SWITCH, /* CPU switch - regs valid*/
  141. KDB_REASON_KEYBOARD, /* Keyboard entry - regs valid */
  142. KDB_REASON_NMI, /* Non-maskable interrupt; regs valid */
  143. KDB_REASON_RECURSE, /* Recursive entry to kdb;
  144. * regs probably valid */
  145. KDB_REASON_SSTEP, /* Single Step trap. - regs valid */
  146. KDB_REASON_SYSTEM_NMI, /* In NMI due to SYSTEM cmd; regs valid */
  147. } kdb_reason_t;
  148. enum kdb_msgsrc {
  149. KDB_MSGSRC_INTERNAL, /* direct call to kdb_printf() */
  150. KDB_MSGSRC_PRINTK, /* trapped from printk() */
  151. };
  152. extern int kdb_trap_printk;
  153. extern int kdb_printf_cpu;
  154. extern __printf(2, 0) int vkdb_printf(enum kdb_msgsrc src, const char *fmt,
  155. va_list args);
  156. extern __printf(1, 2) int kdb_printf(const char *, ...);
  157. typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...);
  158. extern void kdb_init(int level);
  159. /* Access to kdb specific polling devices */
  160. typedef int (*get_char_func)(void);
  161. extern get_char_func kdb_poll_funcs[];
  162. extern int kdb_get_kbd_char(void);
  163. static inline
  164. int kdb_process_cpu(const struct task_struct *p)
  165. {
  166. unsigned int cpu = task_cpu(p);
  167. if (cpu > num_possible_cpus())
  168. cpu = 0;
  169. return cpu;
  170. }
  171. #ifdef CONFIG_KALLSYMS
  172. extern const char *kdb_walk_kallsyms(loff_t *pos);
  173. #else /* ! CONFIG_KALLSYMS */
  174. static inline const char *kdb_walk_kallsyms(loff_t *pos)
  175. {
  176. return NULL;
  177. }
  178. #endif /* ! CONFIG_KALLSYMS */
  179. /* Dynamic kdb shell command registration */
  180. extern int kdb_register(kdbtab_t *cmd);
  181. extern void kdb_unregister(kdbtab_t *cmd);
  182. #else /* ! CONFIG_KGDB_KDB */
  183. static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; }
  184. static inline void kdb_init(int level) {}
  185. static inline int kdb_register(kdbtab_t *cmd) { return 0; }
  186. static inline void kdb_unregister(kdbtab_t *cmd) {}
  187. #endif /* CONFIG_KGDB_KDB */
  188. enum {
  189. KDB_NOT_INITIALIZED,
  190. KDB_INIT_EARLY,
  191. KDB_INIT_FULL,
  192. };
  193. extern int kdbgetintenv(const char *, int *);
  194. extern int kdb_set(int, const char **);
  195. int kdb_lsmod(int argc, const char **argv);
  196. #endif /* !_KDB_H */