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