kdb.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 <asm/atomic.h>
  18. #define KDB_POLL_FUNC_MAX 5
  19. /*
  20. * kdb_initial_cpu is initialized to -1, and is set to the cpu
  21. * number whenever the kernel debugger is entered.
  22. */
  23. extern int kdb_initial_cpu;
  24. extern atomic_t kdb_event;
  25. /*
  26. * kdb_diemsg
  27. *
  28. * Contains a pointer to the last string supplied to the
  29. * kernel 'die' panic function.
  30. */
  31. extern const char *kdb_diemsg;
  32. #define KDB_FLAG_EARLYKDB (1 << 0) /* set from boot parameter kdb=early */
  33. #define KDB_FLAG_CATASTROPHIC (1 << 1) /* A catastrophic event has occurred */
  34. #define KDB_FLAG_CMD_INTERRUPT (1 << 2) /* Previous command was interrupted */
  35. #define KDB_FLAG_NOIPI (1 << 3) /* Do not send IPIs */
  36. #define KDB_FLAG_ONLY_DO_DUMP (1 << 4) /* Only do a dump, used when
  37. * kdb is off */
  38. #define KDB_FLAG_NO_CONSOLE (1 << 5) /* No console is available,
  39. * kdb is disabled */
  40. #define KDB_FLAG_NO_VT_CONSOLE (1 << 6) /* No VT console is available, do
  41. * not use keyboard */
  42. #define KDB_FLAG_NO_I8042 (1 << 7) /* No i8042 chip is available, do
  43. * not use keyboard */
  44. extern int kdb_flags; /* Global flags, see kdb_state for per cpu state */
  45. extern void kdb_save_flags(void);
  46. extern void kdb_restore_flags(void);
  47. #define KDB_FLAG(flag) (kdb_flags & KDB_FLAG_##flag)
  48. #define KDB_FLAG_SET(flag) ((void)(kdb_flags |= KDB_FLAG_##flag))
  49. #define KDB_FLAG_CLEAR(flag) ((void)(kdb_flags &= ~KDB_FLAG_##flag))
  50. /*
  51. * External entry point for the kernel debugger. The pt_regs
  52. * at the time of entry are supplied along with the reason for
  53. * entry to the kernel debugger.
  54. */
  55. typedef enum {
  56. KDB_REASON_ENTER = 1, /* KDB_ENTER() trap/fault - regs valid */
  57. KDB_REASON_ENTER_SLAVE, /* KDB_ENTER_SLAVE() trap/fault - regs valid */
  58. KDB_REASON_BREAK, /* Breakpoint inst. - regs valid */
  59. KDB_REASON_DEBUG, /* Debug Fault - regs valid */
  60. KDB_REASON_OOPS, /* Kernel Oops - regs valid */
  61. KDB_REASON_SWITCH, /* CPU switch - regs valid*/
  62. KDB_REASON_KEYBOARD, /* Keyboard entry - regs valid */
  63. KDB_REASON_NMI, /* Non-maskable interrupt; regs valid */
  64. KDB_REASON_RECURSE, /* Recursive entry to kdb;
  65. * regs probably valid */
  66. KDB_REASON_SSTEP, /* Single Step trap. - regs valid */
  67. } kdb_reason_t;
  68. extern int kdb_printf(const char *, ...)
  69. __attribute__ ((format (printf, 1, 2)));
  70. typedef int (*kdb_printf_t)(const char *, ...)
  71. __attribute__ ((format (printf, 1, 2)));
  72. extern void kdb_init(int level);
  73. /* Access to kdb specific polling devices */
  74. typedef int (*get_char_func)(void);
  75. extern get_char_func kdb_poll_funcs[];
  76. extern int kdb_get_kbd_char(void);
  77. static inline
  78. int kdb_process_cpu(const struct task_struct *p)
  79. {
  80. unsigned int cpu = task_thread_info(p)->cpu;
  81. if (cpu > num_possible_cpus())
  82. cpu = 0;
  83. return cpu;
  84. }
  85. /* kdb access to register set for stack dumping */
  86. extern struct pt_regs *kdb_current_regs;
  87. #else /* ! CONFIG_KGDB_KDB */
  88. #define kdb_printf(...)
  89. #define kdb_init(x)
  90. #endif /* CONFIG_KGDB_KDB */
  91. enum {
  92. KDB_NOT_INITIALIZED,
  93. KDB_INIT_EARLY,
  94. KDB_INIT_FULL,
  95. };
  96. #endif /* !_KDB_H */