kdb_private.h 11 KB

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