kgdb.h 12.1 KB
Newer Older
J
Jason Wessel 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * This provides the callbacks and functions that KGDB needs to share between
 * the core, I/O and arch-specific portions.
 *
 * Author: Amit Kale <amitkale@linsyssoft.com> and
 *         Tom Rini <trini@kernel.crashing.org>
 *
 * 2001-2004 (c) Amit S. Kale and 2003-2005 (c) MontaVista Software, Inc.
 * This file is licensed under the terms of the GNU General Public License
 * version 2. This program is licensed "as is" without any warranty of any
 * kind, whether express or implied.
 */
#ifndef _KGDB_H_
#define _KGDB_H_

#include <linux/linkage.h>
#include <linux/init.h>
A
Arun Sharma 已提交
18
#include <linux/atomic.h>
19
#include <linux/kprobes.h>
J
Jason Wessel 已提交
20
#ifdef CONFIG_HAVE_ARCH_KGDB
J
Jason Wessel 已提交
21
#include <asm/kgdb.h>
J
Jason Wessel 已提交
22
#endif
J
Jason Wessel 已提交
23

J
Jason Wessel 已提交
24
#ifdef CONFIG_KGDB
J
Jason Wessel 已提交
25 26
struct pt_regs;

J
Jason Wessel 已提交
27 28
/**
 *	kgdb_skipexception - (optional) exit kgdb_handle_exception early
J
Jason Wessel 已提交
29 30 31
 *	@exception: Exception vector number
 *	@regs: Current &struct pt_regs.
 *
J
Jason Wessel 已提交
32 33
 *	On some architectures it is required to skip a breakpoint
 *	exception when it occurs after a breakpoint has been removed.
34
 *	This can be implemented in the architecture specific portion of kgdb.
J
Jason Wessel 已提交
35 36 37 38 39 40 41
 */
extern int kgdb_skipexception(int exception, struct pt_regs *regs);

struct tasklet_struct;
struct task_struct;
struct uart_port;

J
Jason Wessel 已提交
42 43 44
/**
 *	kgdb_breakpoint - compiled in breakpoint
 *
45
 *	This will be implemented as a static inline per architecture.  This
J
Jason Wessel 已提交
46 47 48 49
 *	function is called by the kgdb core to execute an architecture
 *	specific trap to cause kgdb to enter the exception processing.
 *
 */
J
Jason Wessel 已提交
50 51 52
void kgdb_breakpoint(void);

extern int kgdb_connected;
53
extern int kgdb_io_module_registered;
J
Jason Wessel 已提交
54 55 56 57 58 59 60 61 62 63 64 65

extern atomic_t			kgdb_setting_breakpoint;
extern atomic_t			kgdb_cpu_doing_single_step;

extern struct task_struct	*kgdb_usethread;
extern struct task_struct	*kgdb_contthread;

enum kgdb_bptype {
	BP_BREAKPOINT = 0,
	BP_HARDWARE_BREAKPOINT,
	BP_WRITE_WATCHPOINT,
	BP_READ_WATCHPOINT,
66 67
	BP_ACCESS_WATCHPOINT,
	BP_POKE_BREAKPOINT,
J
Jason Wessel 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
};

enum kgdb_bpstate {
	BP_UNDEFINED = 0,
	BP_REMOVED,
	BP_SET,
	BP_ACTIVE
};

struct kgdb_bkpt {
	unsigned long		bpt_addr;
	unsigned char		saved_instr[BREAK_INSTR_SIZE];
	enum kgdb_bptype	type;
	enum kgdb_bpstate	state;
};

84 85 86 87 88 89 90 91 92 93 94 95 96
struct dbg_reg_def_t {
	char *name;
	int size;
	int offset;
};

#ifndef DBG_MAX_REG_NUM
#define DBG_MAX_REG_NUM 0
#else
extern struct dbg_reg_def_t dbg_reg_def[];
extern char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs);
extern int dbg_set_reg(int regno, void *mem, struct pt_regs *regs);
#endif
J
Jason Wessel 已提交
97 98 99 100 101 102 103 104 105 106
#ifndef KGDB_MAX_BREAKPOINTS
# define KGDB_MAX_BREAKPOINTS	1000
#endif

#define KGDB_HW_BREAKPOINT	1

/*
 * Functions each KGDB-supporting architecture must provide:
 */

J
Jason Wessel 已提交
107
/**
Z
Zhen Lei 已提交
108
 *	kgdb_arch_init - Perform any architecture specific initialization.
J
Jason Wessel 已提交
109
 *
Z
Zhen Lei 已提交
110
 *	This function will handle the initialization of any architecture
J
Jason Wessel 已提交
111 112 113 114
 *	specific callbacks.
 */
extern int kgdb_arch_init(void);

J
Jason Wessel 已提交
115
/**
J
Jason Wessel 已提交
116 117 118 119 120 121 122
 *	kgdb_arch_exit - Perform any architecture specific uninitalization.
 *
 *	This function will handle the uninitalization of any architecture
 *	specific callbacks, for dynamic registration and unregistration.
 */
extern void kgdb_arch_exit(void);

J
Jason Wessel 已提交
123
/**
J
Jason Wessel 已提交
124 125 126 127 128 129 130 131 132
 *	pt_regs_to_gdb_regs - Convert ptrace regs to GDB regs
 *	@gdb_regs: A pointer to hold the registers in the order GDB wants.
 *	@regs: The &struct pt_regs of the current process.
 *
 *	Convert the pt_regs in @regs into the format for registers that
 *	GDB expects, stored in @gdb_regs.
 */
extern void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs);

J
Jason Wessel 已提交
133
/**
J
Jason Wessel 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147
 *	sleeping_thread_to_gdb_regs - Convert ptrace regs to GDB regs
 *	@gdb_regs: A pointer to hold the registers in the order GDB wants.
 *	@p: The &struct task_struct of the desired process.
 *
 *	Convert the register values of the sleeping process in @p to
 *	the format that GDB expects.
 *	This function is called when kgdb does not have access to the
 *	&struct pt_regs and therefore it should fill the gdb registers
 *	@gdb_regs with what has	been saved in &struct thread_struct
 *	thread field during switch_to.
 */
extern void
sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p);

J
Jason Wessel 已提交
148
/**
J
Jason Wessel 已提交
149 150 151 152 153 154 155 156 157
 *	gdb_regs_to_pt_regs - Convert GDB regs to ptrace regs.
 *	@gdb_regs: A pointer to hold the registers we've received from GDB.
 *	@regs: A pointer to a &struct pt_regs to hold these values in.
 *
 *	Convert the GDB regs in @gdb_regs into the pt_regs, and store them
 *	in @regs.
 */
extern void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs);

J
Jason Wessel 已提交
158
/**
J
Jason Wessel 已提交
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
 *	kgdb_arch_handle_exception - Handle architecture specific GDB packets.
 *	@vector: The error vector of the exception that happened.
 *	@signo: The signal number of the exception that happened.
 *	@err_code: The error code of the exception that happened.
 *	@remcom_in_buffer: The buffer of the packet we have read.
 *	@remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into.
 *	@regs: The &struct pt_regs of the current process.
 *
 *	This function MUST handle the 'c' and 's' command packets,
 *	as well packets to set / remove a hardware breakpoint, if used.
 *	If there are additional packets which the hardware needs to handle,
 *	they are handled here.  The code should return -1 if it wants to
 *	process more packets, and a %0 or %1 if it wants to exit from the
 *	kgdb callback.
 */
extern int
kgdb_arch_handle_exception(int vector, int signo, int err_code,
			   char *remcom_in_buffer,
			   char *remcom_out_buffer,
			   struct pt_regs *regs);

180 181 182 183 184 185 186 187 188 189 190
/**
 *	kgdb_arch_handle_qxfer_pkt - Handle architecture specific GDB XML
 *				     packets.
 *	@remcom_in_buffer: The buffer of the packet we have read.
 *	@remcom_out_buffer: The buffer of %BUFMAX bytes to write a packet into.
 */

extern void
kgdb_arch_handle_qxfer_pkt(char *remcom_in_buffer,
			   char *remcom_out_buffer);

191 192 193 194 195 196 197 198 199 200 201
/**
 *	kgdb_call_nmi_hook - Call kgdb_nmicallback() on the current CPU
 *	@ignored: This parameter is only here to match the prototype.
 *
 *	If you're using the default implementation of kgdb_roundup_cpus()
 *	this function will be called per CPU.  If you don't implement
 *	kgdb_call_nmi_hook() a default will be used.
 */

extern void kgdb_call_nmi_hook(void *ignored);

J
Jason Wessel 已提交
202
/**
J
Jason Wessel 已提交
203 204 205
 *	kgdb_roundup_cpus - Get other CPUs into a holding pattern
 *
 *	On SMP systems, we need to get the attention of the other CPUs
206
 *	and get them into a known state.  This should do what is needed
J
Jason Wessel 已提交
207
 *	to get the other CPUs to call kgdb_wait(). Note that on some arches,
208 209
 *	the NMI approach is not used for rounding up all the CPUs.  Normally
 *	those architectures can just not implement this and get the default.
J
Jason Wessel 已提交
210 211 212
 *
 *	On non-SMP systems, this is not called.
 */
213
extern void kgdb_roundup_cpus(void);
J
Jason Wessel 已提交
214

215 216 217 218 219 220 221 222 223 224 225
/**
 *	kgdb_arch_set_pc - Generic call back to the program counter
 *	@regs: Current &struct pt_regs.
 *  @pc: The new value for the program counter
 *
 *	This function handles updating the program counter and requires an
 *	architecture specific implementation.
 */
extern void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc);


J
Jason Wessel 已提交
226 227
/* Optional functions. */
extern int kgdb_validate_break_address(unsigned long addr);
228 229
extern int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt);
extern int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt);
J
Jason Wessel 已提交
230

231
/**
Z
Zhen Lei 已提交
232
 *	kgdb_arch_late - Perform any architecture specific initialization.
233
 *
Z
Zhen Lei 已提交
234
 *	This function will handle the late initialization of any
235 236 237 238 239 240 241
 *	architecture specific callbacks.  This is an optional function for
 *	handling things like late initialization of hw breakpoints.  The
 *	default implementation does nothing.
 */
extern void kgdb_arch_late(void);


J
Jason Wessel 已提交
242
/**
J
Jason Wessel 已提交
243 244 245 246 247 248 249 250 251 252 253
 * struct kgdb_arch - Describe architecture specific values.
 * @gdb_bpt_instr: The instruction to trigger a breakpoint.
 * @flags: Flags for the breakpoint, currently just %KGDB_HW_BREAKPOINT.
 * @set_breakpoint: Allow an architecture to specify how to set a software
 * breakpoint.
 * @remove_breakpoint: Allow an architecture to specify how to remove a
 * software breakpoint.
 * @set_hw_breakpoint: Allow an architecture to specify how to set a hardware
 * breakpoint.
 * @remove_hw_breakpoint: Allow an architecture to specify how to remove a
 * hardware breakpoint.
254 255
 * @disable_hw_break: Allow an architecture to specify how to disable
 * hardware breakpoints for a single cpu.
J
Jason Wessel 已提交
256 257 258 259
 * @remove_all_hw_break: Allow an architecture to specify how to remove all
 * hardware breakpoints.
 * @correct_hw_break: Allow an architecture to specify how to correct the
 * hardware debug registers.
260
 * @enable_nmi: Manage NMI-triggered entry to KGDB
J
Jason Wessel 已提交
261 262 263 264 265 266 267 268 269
 */
struct kgdb_arch {
	unsigned char		gdb_bpt_instr[BREAK_INSTR_SIZE];
	unsigned long		flags;

	int	(*set_breakpoint)(unsigned long, char *);
	int	(*remove_breakpoint)(unsigned long, char *);
	int	(*set_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
	int	(*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
270
	void	(*disable_hw_break)(struct pt_regs *regs);
J
Jason Wessel 已提交
271 272
	void	(*remove_all_hw_break)(void);
	void	(*correct_hw_break)(void);
273 274

	void	(*enable_nmi)(bool on);
J
Jason Wessel 已提交
275 276
};

J
Jason Wessel 已提交
277
/**
J
Jason Wessel 已提交
278 279 280 281 282 283
 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
 * @name: Name of the I/O driver.
 * @read_char: Pointer to a function that will return one char.
 * @write_char: Pointer to a function that will write one char.
 * @flush: Pointer to a function that will flush any pending writes.
 * @init: Pointer to a function that will initialize the device.
284 285 286
 * @deinit: Pointer to a function that will deinit the device. Implies that
 * this I/O driver is temporary and expects to be replaced. Called when
 * an I/O driver is replaced or explicitly unregistered.
J
Jason Wessel 已提交
287 288 289 290
 * @pre_exception: Pointer to a function that will do any prep work for
 * the I/O driver.
 * @post_exception: Pointer to a function that will do any cleanup work
 * for the I/O driver.
291
 * @cons: valid if the I/O device is a console; else NULL.
J
Jason Wessel 已提交
292 293 294 295 296 297 298
 */
struct kgdb_io {
	const char		*name;
	int			(*read_char) (void);
	void			(*write_char) (u8);
	void			(*flush) (void);
	int			(*init) (void);
299
	void			(*deinit) (void);
J
Jason Wessel 已提交
300 301
	void			(*pre_exception) (void);
	void			(*post_exception) (void);
302
	struct console		*cons;
J
Jason Wessel 已提交
303 304
};

305
extern const struct kgdb_arch		arch_kgdb_ops;
J
Jason Wessel 已提交
306

307
extern unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs);
308

309 310 311 312 313 314 315
#ifdef CONFIG_SERIAL_KGDB_NMI
extern int kgdb_register_nmi_console(void);
extern int kgdb_unregister_nmi_console(void);
extern bool kgdb_nmi_poll_knock(void);
#else
static inline int kgdb_register_nmi_console(void) { return 0; }
static inline int kgdb_unregister_nmi_console(void) { return 0; }
316
static inline bool kgdb_nmi_poll_knock(void) { return true; }
317 318
#endif

J
Jason Wessel 已提交
319 320
extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
321
extern struct kgdb_io *dbg_io_ops;
J
Jason Wessel 已提交
322

323
extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
324
extern char *kgdb_mem2hex(char *mem, char *buf, int count);
J
Jason Wessel 已提交
325 326 327
extern int kgdb_hex2mem(char *buf, char *mem, int count);

extern int kgdb_isremovedbreak(unsigned long addr);
328
extern int kgdb_has_hit_break(unsigned long addr);
J
Jason Wessel 已提交
329 330 331 332 333

extern int
kgdb_handle_exception(int ex_vector, int signo, int err_code,
		      struct pt_regs *regs);
extern int kgdb_nmicallback(int cpu, void *regs);
334 335
extern int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code,
			  atomic_t *snd_rdy);
336
extern void gdbstub_exit(int status);
J
Jason Wessel 已提交
337

338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
/*
 * kgdb and kprobes both use the same (kprobe) blocklist (which makes sense
 * given they are both typically hooked up to the same trap meaning on most
 * architectures one cannot be used to debug the other)
 *
 * However on architectures where kprobes is not (yet) implemented we permit
 * breakpoints everywhere rather than blocking everything by default.
 */
static inline bool kgdb_within_blocklist(unsigned long addr)
{
#ifdef CONFIG_KGDB_HONOUR_BLOCKLIST
	return within_kprobe_blacklist(addr);
#else
	return false;
#endif
}

J
Jason Wessel 已提交
355 356
extern int			kgdb_single_step;
extern atomic_t			kgdb_active;
J
Jason Wessel 已提交
357
#define in_dbg_master() \
358
	(irqs_disabled() && (smp_processor_id() == atomic_read(&kgdb_active)))
359 360
extern bool dbg_is_early;
extern void __init dbg_late_init(void);
361
extern void kgdb_panic(const char *msg);
362
extern void kgdb_free_init_mem(void);
J
Jason Wessel 已提交
363 364
#else /* ! CONFIG_KGDB */
#define in_dbg_master() (0)
365
#define dbg_late_init()
366
static inline void kgdb_panic(const char *msg) {}
367
static inline void kgdb_free_init_mem(void) { }
J
Jason Wessel 已提交
368
#endif /* ! CONFIG_KGDB */
J
Jason Wessel 已提交
369
#endif /* _KGDB_H_ */