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