kdb.h 7.2 KB

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