kdb.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. extern atomic_t kdb_event;
  71. /* Types and messages used for dynamically added kdb shell commands */
  72. #define KDB_MAXARGS 16 /* Maximum number of arguments to a function */
  73. /* KDB return codes from a command or internal kdb function */
  74. #define KDB_NOTFOUND (-1)
  75. #define KDB_ARGCOUNT (-2)
  76. #define KDB_BADWIDTH (-3)
  77. #define KDB_BADRADIX (-4)
  78. #define KDB_NOTENV (-5)
  79. #define KDB_NOENVVALUE (-6)
  80. #define KDB_NOTIMP (-7)
  81. #define KDB_ENVFULL (-8)
  82. #define KDB_ENVBUFFULL (-9)
  83. #define KDB_TOOMANYBPT (-10)
  84. #define KDB_TOOMANYDBREGS (-11)
  85. #define KDB_DUPBPT (-12)
  86. #define KDB_BPTNOTFOUND (-13)
  87. #define KDB_BADMODE (-14)
  88. #define KDB_BADINT (-15)
  89. #define KDB_INVADDRFMT (-16)
  90. #define KDB_BADREG (-17)
  91. #define KDB_BADCPUNUM (-18)
  92. #define KDB_BADLENGTH (-19)
  93. #define KDB_NOBP (-20)
  94. #define KDB_BADADDR (-21)
  95. #define KDB_NOPERM (-22)
  96. /*
  97. * kdb_diemsg
  98. *
  99. * Contains a pointer to the last string supplied to the
  100. * kernel 'die' panic function.
  101. */
  102. extern const char *kdb_diemsg;
  103. #define KDB_FLAG_EARLYKDB (1 << 0) /* set from boot parameter kdb=early */
  104. #define KDB_FLAG_CATASTROPHIC (1 << 1) /* A catastrophic event has occurred */
  105. #define KDB_FLAG_CMD_INTERRUPT (1 << 2) /* Previous command was interrupted */
  106. #define KDB_FLAG_NOIPI (1 << 3) /* Do not send IPIs */
  107. #define KDB_FLAG_NO_CONSOLE (1 << 5) /* No console is available,
  108. * kdb is disabled */
  109. #define KDB_FLAG_NO_VT_CONSOLE (1 << 6) /* No VT console is available, do
  110. * not use keyboard */
  111. #define KDB_FLAG_NO_I8042 (1 << 7) /* No i8042 chip is available, do
  112. * not use keyboard */
  113. extern int kdb_flags; /* Global flags, see kdb_state for per cpu state */
  114. extern void kdb_save_flags(void);
  115. extern void kdb_restore_flags(void);
  116. #define KDB_FLAG(flag) (kdb_flags & KDB_FLAG_##flag)
  117. #define KDB_FLAG_SET(flag) ((void)(kdb_flags |= KDB_FLAG_##flag))
  118. #define KDB_FLAG_CLEAR(flag) ((void)(kdb_flags &= ~KDB_FLAG_##flag))
  119. /*
  120. * External entry point for the kernel debugger. The pt_regs
  121. * at the time of entry are supplied along with the reason for
  122. * entry to the kernel debugger.
  123. */
  124. typedef enum {
  125. KDB_REASON_ENTER = 1, /* KDB_ENTER() trap/fault - regs valid */
  126. KDB_REASON_ENTER_SLAVE, /* KDB_ENTER_SLAVE() trap/fault - regs valid */
  127. KDB_REASON_BREAK, /* Breakpoint inst. - regs valid */
  128. KDB_REASON_DEBUG, /* Debug Fault - regs valid */
  129. KDB_REASON_OOPS, /* Kernel Oops - regs valid */
  130. KDB_REASON_SWITCH, /* CPU switch - regs valid*/
  131. KDB_REASON_KEYBOARD, /* Keyboard entry - regs valid */
  132. KDB_REASON_NMI, /* Non-maskable interrupt; regs valid */
  133. KDB_REASON_RECURSE, /* Recursive entry to kdb;
  134. * regs probably valid */
  135. KDB_REASON_SSTEP, /* Single Step trap. - regs valid */
  136. KDB_REASON_SYSTEM_NMI, /* In NMI due to SYSTEM cmd; regs valid */
  137. } kdb_reason_t;
  138. enum kdb_msgsrc {
  139. KDB_MSGSRC_INTERNAL, /* direct call to kdb_printf() */
  140. KDB_MSGSRC_PRINTK, /* trapped from printk() */
  141. };
  142. extern int kdb_trap_printk;
  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_thread_info(p)->cpu;
  156. if (cpu > num_possible_cpus())
  157. cpu = 0;
  158. return cpu;
  159. }
  160. /* kdb access to register set for stack dumping */
  161. extern struct pt_regs *kdb_current_regs;
  162. #ifdef CONFIG_KALLSYMS
  163. extern const char *kdb_walk_kallsyms(loff_t *pos);
  164. #else /* ! CONFIG_KALLSYMS */
  165. static inline const char *kdb_walk_kallsyms(loff_t *pos)
  166. {
  167. return NULL;
  168. }
  169. #endif /* ! CONFIG_KALLSYMS */
  170. /* Dynamic kdb shell command registration */
  171. extern int kdb_register(char *, kdb_func_t, char *, char *, short);
  172. extern int kdb_register_flags(char *, kdb_func_t, char *, char *,
  173. short, kdb_cmdflags_t);
  174. extern int kdb_unregister(char *);
  175. #else /* ! CONFIG_KGDB_KDB */
  176. static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; }
  177. static inline void kdb_init(int level) {}
  178. static inline int kdb_register(char *cmd, kdb_func_t func, char *usage,
  179. char *help, short minlen) { return 0; }
  180. static inline int kdb_register_flags(char *cmd, kdb_func_t func, char *usage,
  181. char *help, short minlen,
  182. kdb_cmdflags_t flags) { return 0; }
  183. static inline int kdb_unregister(char *cmd) { return 0; }
  184. #endif /* CONFIG_KGDB_KDB */
  185. enum {
  186. KDB_NOT_INITIALIZED,
  187. KDB_INIT_EARLY,
  188. KDB_INIT_FULL,
  189. };
  190. extern int kdbgetintenv(const char *, int *);
  191. extern int kdb_set(int, const char **);
  192. #endif /* !_KDB_H */