kdb_private.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #ifndef _KDBPRIVATE_H
  2. #define _KDBPRIVATE_H
  3. /*
  4. * Kernel Debugger Architecture Independent Private 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-2004 Silicon Graphics, Inc. All Rights Reserved.
  11. * Copyright (c) 2009 Wind River Systems, Inc. All Rights Reserved.
  12. */
  13. #include <linux/kgdb.h>
  14. #include "../debug_core.h"
  15. /* Kernel Debugger Command codes. Must not overlap with error codes. */
  16. #define KDB_CMD_GO (-1001)
  17. #define KDB_CMD_CPU (-1002)
  18. #define KDB_CMD_SS (-1003)
  19. #define KDB_CMD_KGDB (-1005)
  20. /* Internal debug flags */
  21. #define KDB_DEBUG_FLAG_BP 0x0002 /* Breakpoint subsystem debug */
  22. #define KDB_DEBUG_FLAG_BB_SUMM 0x0004 /* Basic block analysis, summary only */
  23. #define KDB_DEBUG_FLAG_AR 0x0008 /* Activation record, generic */
  24. #define KDB_DEBUG_FLAG_ARA 0x0010 /* Activation record, arch specific */
  25. #define KDB_DEBUG_FLAG_BB 0x0020 /* All basic block analysis */
  26. #define KDB_DEBUG_FLAG_STATE 0x0040 /* State flags */
  27. #define KDB_DEBUG_FLAG_MASK 0xffff /* All debug flags */
  28. #define KDB_DEBUG_FLAG_SHIFT 16 /* Shift factor for dbflags */
  29. #define KDB_DEBUG(flag) (kdb_flags & \
  30. (KDB_DEBUG_FLAG_##flag << KDB_DEBUG_FLAG_SHIFT))
  31. #define KDB_DEBUG_STATE(text, value) if (KDB_DEBUG(STATE)) \
  32. kdb_print_state(text, value)
  33. #if BITS_PER_LONG == 32
  34. #define KDB_PLATFORM_ENV "BYTESPERWORD=4"
  35. #define kdb_machreg_fmt "0x%lx"
  36. #define kdb_machreg_fmt0 "0x%08lx"
  37. #define kdb_bfd_vma_fmt "0x%lx"
  38. #define kdb_bfd_vma_fmt0 "0x%08lx"
  39. #define kdb_elfw_addr_fmt "0x%x"
  40. #define kdb_elfw_addr_fmt0 "0x%08x"
  41. #define kdb_f_count_fmt "%d"
  42. #elif BITS_PER_LONG == 64
  43. #define KDB_PLATFORM_ENV "BYTESPERWORD=8"
  44. #define kdb_machreg_fmt "0x%lx"
  45. #define kdb_machreg_fmt0 "0x%016lx"
  46. #define kdb_bfd_vma_fmt "0x%lx"
  47. #define kdb_bfd_vma_fmt0 "0x%016lx"
  48. #define kdb_elfw_addr_fmt "0x%x"
  49. #define kdb_elfw_addr_fmt0 "0x%016x"
  50. #define kdb_f_count_fmt "%ld"
  51. #endif
  52. /*
  53. * KDB_MAXBPT describes the total number of breakpoints
  54. * supported by this architecure.
  55. */
  56. #define KDB_MAXBPT 16
  57. /* Symbol table format returned by kallsyms. */
  58. typedef struct __ksymtab {
  59. unsigned long value; /* Address of symbol */
  60. const char *mod_name; /* Module containing symbol or
  61. * "kernel" */
  62. unsigned long mod_start;
  63. unsigned long mod_end;
  64. const char *sec_name; /* Section containing symbol */
  65. unsigned long sec_start;
  66. unsigned long sec_end;
  67. const char *sym_name; /* Full symbol name, including
  68. * any version */
  69. unsigned long sym_start;
  70. unsigned long sym_end;
  71. } kdb_symtab_t;
  72. extern int kallsyms_symbol_next(char *prefix_name, int flag, int buf_size);
  73. extern int kallsyms_symbol_complete(char *prefix_name, int max_len);
  74. /* Exported Symbols for kernel loadable modules to use. */
  75. extern int kdb_getarea_size(void *, unsigned long, size_t);
  76. extern int kdb_putarea_size(unsigned long, void *, size_t);
  77. /*
  78. * Like get_user and put_user, kdb_getarea and kdb_putarea take variable
  79. * names, not pointers. The underlying *_size functions take pointers.
  80. */
  81. #define kdb_getarea(x, addr) kdb_getarea_size(&(x), addr, sizeof((x)))
  82. #define kdb_putarea(addr, x) kdb_putarea_size(addr, &(x), sizeof((x)))
  83. extern int kdb_getphysword(unsigned long *word,
  84. unsigned long addr, size_t size);
  85. extern int kdb_getword(unsigned long *, unsigned long, size_t);
  86. extern int kdb_putword(unsigned long, unsigned long, size_t);
  87. extern int kdbgetularg(const char *, unsigned long *);
  88. extern int kdbgetu64arg(const char *, u64 *);
  89. extern char *kdbgetenv(const char *);
  90. extern int kdbgetaddrarg(int, const char **, int*, unsigned long *,
  91. long *, char **);
  92. extern int kdbgetsymval(const char *, kdb_symtab_t *);
  93. extern int kdbnearsym(unsigned long, kdb_symtab_t *);
  94. extern void kdbnearsym_cleanup(void);
  95. extern char *kdb_strdup(const char *str, gfp_t type);
  96. extern void kdb_symbol_print(unsigned long, const kdb_symtab_t *, unsigned int);
  97. /* Routine for debugging the debugger state. */
  98. extern void kdb_print_state(const char *, int);
  99. extern int kdb_state;
  100. #define KDB_STATE_KDB 0x00000001 /* Cpu is inside kdb */
  101. #define KDB_STATE_LEAVING 0x00000002 /* Cpu is leaving kdb */
  102. #define KDB_STATE_CMD 0x00000004 /* Running a kdb command */
  103. #define KDB_STATE_KDB_CONTROL 0x00000008 /* This cpu is under
  104. * kdb control */
  105. #define KDB_STATE_HOLD_CPU 0x00000010 /* Hold this cpu inside kdb */
  106. #define KDB_STATE_DOING_SS 0x00000020 /* Doing ss command */
  107. #define KDB_STATE_SSBPT 0x00000080 /* Install breakpoint
  108. * after one ss, independent of
  109. * DOING_SS */
  110. #define KDB_STATE_REENTRY 0x00000100 /* Valid re-entry into kdb */
  111. #define KDB_STATE_SUPPRESS 0x00000200 /* Suppress error messages */
  112. #define KDB_STATE_PAGER 0x00000400 /* pager is available */
  113. #define KDB_STATE_GO_SWITCH 0x00000800 /* go is switching
  114. * back to initial cpu */
  115. #define KDB_STATE_WAIT_IPI 0x00002000 /* Waiting for kdb_ipi() NMI */
  116. #define KDB_STATE_RECURSE 0x00004000 /* Recursive entry to kdb */
  117. #define KDB_STATE_IP_ADJUSTED 0x00008000 /* Restart IP has been
  118. * adjusted */
  119. #define KDB_STATE_GO1 0x00010000 /* go only releases one cpu */
  120. #define KDB_STATE_KEYBOARD 0x00020000 /* kdb entered via
  121. * keyboard on this cpu */
  122. #define KDB_STATE_KEXEC 0x00040000 /* kexec issued */
  123. #define KDB_STATE_DOING_KGDB 0x00080000 /* kgdb enter now issued */
  124. #define KDB_STATE_KGDB_TRANS 0x00200000 /* Transition to kgdb */
  125. #define KDB_STATE_ARCH 0xff000000 /* Reserved for arch
  126. * specific use */
  127. #define KDB_STATE(flag) (kdb_state & KDB_STATE_##flag)
  128. #define KDB_STATE_SET(flag) ((void)(kdb_state |= KDB_STATE_##flag))
  129. #define KDB_STATE_CLEAR(flag) ((void)(kdb_state &= ~KDB_STATE_##flag))
  130. extern int kdb_nextline; /* Current number of lines displayed */
  131. typedef struct _kdb_bp {
  132. unsigned long bp_addr; /* Address breakpoint is present at */
  133. unsigned int bp_free:1; /* This entry is available */
  134. unsigned int bp_enabled:1; /* Breakpoint is active in register */
  135. unsigned int bp_type:4; /* Uses hardware register */
  136. unsigned int bp_installed:1; /* Breakpoint is installed */
  137. unsigned int bp_delay:1; /* Do delayed bp handling */
  138. unsigned int bp_delayed:1; /* Delayed breakpoint */
  139. unsigned int bph_length; /* HW break length */
  140. } kdb_bp_t;
  141. #ifdef CONFIG_KGDB_KDB
  142. extern kdb_bp_t kdb_breakpoints[/* KDB_MAXBPT */];
  143. /* The KDB shell command table */
  144. typedef struct _kdbtab {
  145. char *cmd_name; /* Command name */
  146. kdb_func_t cmd_func; /* Function to execute command */
  147. char *cmd_usage; /* Usage String for this command */
  148. char *cmd_help; /* Help message for this command */
  149. short cmd_minlen; /* Minimum legal # command
  150. * chars required */
  151. kdb_cmdflags_t cmd_flags; /* Command behaviour flags */
  152. } kdbtab_t;
  153. extern int kdb_bt(int, const char **); /* KDB display back trace */
  154. /* KDB breakpoint management functions */
  155. extern void kdb_initbptab(void);
  156. extern void kdb_bp_install(struct pt_regs *);
  157. extern void kdb_bp_remove(void);
  158. typedef enum {
  159. KDB_DB_BPT, /* Breakpoint */
  160. KDB_DB_SS, /* Single-step trap */
  161. KDB_DB_SSBPT, /* Single step over breakpoint */
  162. KDB_DB_NOBPT /* Spurious breakpoint */
  163. } kdb_dbtrap_t;
  164. extern int kdb_main_loop(kdb_reason_t, kdb_reason_t,
  165. int, kdb_dbtrap_t, struct pt_regs *);
  166. /* Miscellaneous functions and data areas */
  167. extern int kdb_grepping_flag;
  168. #define KDB_GREPPING_FLAG_SEARCH 0x8000
  169. extern char kdb_grep_string[];
  170. #define KDB_GREP_STRLEN 256
  171. extern int kdb_grep_leading;
  172. extern int kdb_grep_trailing;
  173. extern char *kdb_cmds[];
  174. extern unsigned long kdb_task_state_string(const char *);
  175. extern char kdb_task_state_char (const struct task_struct *);
  176. extern unsigned long kdb_task_state(const struct task_struct *p,
  177. unsigned long mask);
  178. extern void kdb_ps_suppressed(void);
  179. extern void kdb_ps1(const struct task_struct *p);
  180. extern void kdb_print_nameval(const char *name, unsigned long val);
  181. extern void kdb_send_sig(struct task_struct *p, int sig);
  182. extern void kdb_meminfo_proc_show(void);
  183. extern char *kdb_getstr(char *, size_t, const char *);
  184. extern void kdb_gdb_state_pass(char *buf);
  185. /* Defines for kdb_symbol_print */
  186. #define KDB_SP_SPACEB 0x0001 /* Space before string */
  187. #define KDB_SP_SPACEA 0x0002 /* Space after string */
  188. #define KDB_SP_PAREN 0x0004 /* Parenthesis around string */
  189. #define KDB_SP_VALUE 0x0008 /* Print the value of the address */
  190. #define KDB_SP_SYMSIZE 0x0010 /* Print the size of the symbol */
  191. #define KDB_SP_NEWLINE 0x0020 /* Newline after string */
  192. #define KDB_SP_DEFAULT (KDB_SP_VALUE|KDB_SP_PAREN)
  193. #define KDB_TSK(cpu) kgdb_info[cpu].task
  194. #define KDB_TSKREGS(cpu) kgdb_info[cpu].debuggerinfo
  195. extern struct task_struct *kdb_curr_task(int);
  196. #define kdb_task_has_cpu(p) (task_curr(p))
  197. /* Simplify coexistence with NPTL */
  198. #define kdb_do_each_thread(g, p) do_each_thread(g, p)
  199. #define kdb_while_each_thread(g, p) while_each_thread(g, p)
  200. #define GFP_KDB (in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
  201. extern void *debug_kmalloc(size_t size, gfp_t flags);
  202. extern void debug_kfree(void *);
  203. extern void debug_kusage(void);
  204. extern void kdb_set_current_task(struct task_struct *);
  205. extern struct task_struct *kdb_current_task;
  206. #ifdef CONFIG_KDB_KEYBOARD
  207. extern void kdb_kbd_cleanup_state(void);
  208. #else /* ! CONFIG_KDB_KEYBOARD */
  209. #define kdb_kbd_cleanup_state()
  210. #endif /* ! CONFIG_KDB_KEYBOARD */
  211. #ifdef CONFIG_MODULES
  212. extern struct list_head *kdb_modules;
  213. #endif /* CONFIG_MODULES */
  214. extern char kdb_prompt_str[];
  215. #define KDB_WORD_SIZE ((int)sizeof(unsigned long))
  216. #endif /* CONFIG_KGDB_KDB */
  217. #endif /* !_KDBPRIVATE_H */