kdb.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. #ifdef CONFIG_KGDB_KDB
  15. #include <linux/init.h>
  16. #include <linux/sched.h>
  17. #include <linux/atomic.h>
  18. #define KDB_POLL_FUNC_MAX 5
  19. extern int kdb_poll_idx;
  20. /*
  21. * kdb_initial_cpu is initialized to -1, and is set to the cpu
  22. * number whenever the kernel debugger is entered.
  23. */
  24. extern int kdb_initial_cpu;
  25. extern atomic_t kdb_event;
  26. /* Types and messages used for dynamically added kdb shell commands */
  27. #define KDB_MAXARGS 16 /* Maximum number of arguments to a function */
  28. typedef enum {
  29. KDB_REPEAT_NONE = 0, /* Do not repeat this command */
  30. KDB_REPEAT_NO_ARGS, /* Repeat the command without arguments */
  31. KDB_REPEAT_WITH_ARGS, /* Repeat the command including its arguments */
  32. } kdb_repeat_t;
  33. typedef int (*kdb_func_t)(int, const char **);
  34. /* KDB return codes from a command or internal kdb function */
  35. #define KDB_NOTFOUND (-1)
  36. #define KDB_ARGCOUNT (-2)
  37. #define KDB_BADWIDTH (-3)
  38. #define KDB_BADRADIX (-4)
  39. #define KDB_NOTENV (-5)
  40. #define KDB_NOENVVALUE (-6)
  41. #define KDB_NOTIMP (-7)
  42. #define KDB_ENVFULL (-8)
  43. #define KDB_ENVBUFFULL (-9)
  44. #define KDB_TOOMANYBPT (-10)
  45. #define KDB_TOOMANYDBREGS (-11)
  46. #define KDB_DUPBPT (-12)
  47. #define KDB_BPTNOTFOUND (-13)
  48. #define KDB_BADMODE (-14)
  49. #define KDB_BADINT (-15)
  50. #define KDB_INVADDRFMT (-16)
  51. #define KDB_BADREG (-17)
  52. #define KDB_BADCPUNUM (-18)
  53. #define KDB_BADLENGTH (-19)
  54. #define KDB_NOBP (-20)
  55. #define KDB_BADADDR (-21)
  56. /*
  57. * kdb_diemsg
  58. *
  59. * Contains a pointer to the last string supplied to the
  60. * kernel 'die' panic function.
  61. */
  62. extern const char *kdb_diemsg;
  63. #define KDB_FLAG_EARLYKDB (1 << 0) /* set from boot parameter kdb=early */
  64. #define KDB_FLAG_CATASTROPHIC (1 << 1) /* A catastrophic event has occurred */
  65. #define KDB_FLAG_CMD_INTERRUPT (1 << 2) /* Previous command was interrupted */
  66. #define KDB_FLAG_NOIPI (1 << 3) /* Do not send IPIs */
  67. #define KDB_FLAG_ONLY_DO_DUMP (1 << 4) /* Only do a dump, used when
  68. * kdb is off */
  69. #define KDB_FLAG_NO_CONSOLE (1 << 5) /* No console is available,
  70. * kdb is disabled */
  71. #define KDB_FLAG_NO_VT_CONSOLE (1 << 6) /* No VT console is available, do
  72. * not use keyboard */
  73. #define KDB_FLAG_NO_I8042 (1 << 7) /* No i8042 chip is available, do
  74. * not use keyboard */
  75. extern int kdb_flags; /* Global flags, see kdb_state for per cpu state */
  76. extern void kdb_save_flags(void);
  77. extern void kdb_restore_flags(void);
  78. #define KDB_FLAG(flag) (kdb_flags & KDB_FLAG_##flag)
  79. #define KDB_FLAG_SET(flag) ((void)(kdb_flags |= KDB_FLAG_##flag))
  80. #define KDB_FLAG_CLEAR(flag) ((void)(kdb_flags &= ~KDB_FLAG_##flag))
  81. /*
  82. * External entry point for the kernel debugger. The pt_regs
  83. * at the time of entry are supplied along with the reason for
  84. * entry to the kernel debugger.
  85. */
  86. typedef enum {
  87. KDB_REASON_ENTER = 1, /* KDB_ENTER() trap/fault - regs valid */
  88. KDB_REASON_ENTER_SLAVE, /* KDB_ENTER_SLAVE() trap/fault - regs valid */
  89. KDB_REASON_BREAK, /* Breakpoint inst. - regs valid */
  90. KDB_REASON_DEBUG, /* Debug Fault - regs valid */
  91. KDB_REASON_OOPS, /* Kernel Oops - regs valid */
  92. KDB_REASON_SWITCH, /* CPU switch - regs valid*/
  93. KDB_REASON_KEYBOARD, /* Keyboard entry - regs valid */
  94. KDB_REASON_NMI, /* Non-maskable interrupt; regs valid */
  95. KDB_REASON_RECURSE, /* Recursive entry to kdb;
  96. * regs probably valid */
  97. KDB_REASON_SSTEP, /* Single Step trap. - regs valid */
  98. } kdb_reason_t;
  99. extern int kdb_trap_printk;
  100. extern __printf(1, 0) int vkdb_printf(const char *fmt, va_list args);
  101. extern __printf(1, 2) int kdb_printf(const char *, ...);
  102. typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...);
  103. extern void kdb_init(int level);
  104. /* Access to kdb specific polling devices */
  105. typedef int (*get_char_func)(void);
  106. extern get_char_func kdb_poll_funcs[];
  107. extern int kdb_get_kbd_char(void);
  108. static inline
  109. int kdb_process_cpu(const struct task_struct *p)
  110. {
  111. unsigned int cpu = task_thread_info(p)->cpu;
  112. if (cpu > num_possible_cpus())
  113. cpu = 0;
  114. return cpu;
  115. }
  116. /* kdb access to register set for stack dumping */
  117. extern struct pt_regs *kdb_current_regs;
  118. #ifdef CONFIG_KALLSYMS
  119. extern const char *kdb_walk_kallsyms(loff_t *pos);
  120. #else /* ! CONFIG_KALLSYMS */
  121. static inline const char *kdb_walk_kallsyms(loff_t *pos)
  122. {
  123. return NULL;
  124. }
  125. #endif /* ! CONFIG_KALLSYMS */
  126. /* Dynamic kdb shell command registration */
  127. extern int kdb_register(char *, kdb_func_t, char *, char *, short);
  128. extern int kdb_register_repeat(char *, kdb_func_t, char *, char *,
  129. short, kdb_repeat_t);
  130. extern int kdb_unregister(char *);
  131. #else /* ! CONFIG_KGDB_KDB */
  132. #define kdb_printf(...)
  133. #define kdb_init(x)
  134. #define kdb_register(...)
  135. #define kdb_register_repeat(...)
  136. #define kdb_uregister(x)
  137. #endif /* CONFIG_KGDB_KDB */
  138. enum {
  139. KDB_NOT_INITIALIZED,
  140. KDB_INIT_EARLY,
  141. KDB_INIT_FULL,
  142. };
  143. extern int kdbgetintenv(const char *, int *);
  144. extern int kdb_set(int, const char **);
  145. #endif /* !_KDB_H */