ddb.h revision 174910
1/*-
2 * Copyright (c) 1993, Garrett A. Wollman.
3 * Copyright (c) 1993, University of Vermont and State Agricultural College.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the University nor the names of its contributors
15 *    may be used to endorse or promote products derived from this software
16 *    without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * $FreeBSD: head/sys/ddb/ddb.h 174910 2007-12-25 23:06:51Z rwatson $
31 */
32
33/*
34 * Necessary declarations for the `ddb' kernel debugger.
35 */
36
37#ifndef _DDB_DDB_H_
38#define	_DDB_DDB_H_
39
40#ifdef SYSCTL_DECL
41SYSCTL_DECL(_debug_ddb);
42#endif
43
44#include <machine/db_machdep.h>		/* type definitions */
45
46#ifndef DB_MAXARGS
47#define	DB_MAXARGS	10
48#endif
49
50#ifndef DB_CALL
51#define	DB_CALL	db_fncall_generic
52#else
53int	DB_CALL(db_expr_t, db_expr_t *, int, db_expr_t[]);
54#endif
55
56typedef void db_cmdfcn_t(db_expr_t addr, boolean_t have_addr, db_expr_t count,
57	    char *modif);
58
59#define DB_COMMAND(cmd_name, func_name) \
60	DB_FUNC(cmd_name, func_name, db_cmd_set, 0, NULL)
61#define DB_SHOW_COMMAND(cmd_name, func_name) \
62	DB_FUNC(cmd_name, func_name, db_show_cmd_set, 0, NULL)
63
64#define	DB_SET(cmd_name, func_name, set, flag, more)		\
65static const struct command __CONCAT(cmd_name,_cmd) = {		\
66	__STRING(cmd_name),					\
67	func_name,						\
68	flag,							\
69	more							\
70};								\
71TEXT_SET(set, __CONCAT(cmd_name,_cmd))
72
73#define DB_FUNC(cmd_name, func_name, set, flag, more)		\
74static db_cmdfcn_t	func_name;				\
75								\
76DB_SET(cmd_name, func_name, set, flag, more);			\
77								\
78static void							\
79func_name(addr, have_addr, count, modif)			\
80	db_expr_t addr;						\
81	boolean_t have_addr;					\
82	db_expr_t count;					\
83	char *modif;
84
85extern db_expr_t db_maxoff;
86extern int db_indent;
87extern int db_inst_count;
88extern int db_load_count;
89extern int db_store_count;
90extern volatile int db_pager_quit;
91extern db_expr_t db_radix;
92extern db_expr_t db_max_width;
93extern db_expr_t db_tab_stop_width;
94extern db_expr_t db_lines_per_page;
95
96struct thread;
97struct vm_map;
98
99void		db_check_interrupt(void);
100void		db_clear_watchpoints(void);
101db_addr_t	db_disasm(db_addr_t loc, boolean_t altfmt);
102				/* instruction disassembler */
103void		db_error(const char *s);
104int		db_expression(db_expr_t *valuep);
105int		db_get_variable(db_expr_t *valuep);
106void		db_iprintf(const char *,...) __printflike(1, 2);
107struct proc	*db_lookup_proc(db_expr_t addr);
108struct thread	*db_lookup_thread(db_expr_t addr, boolean_t check_pid);
109struct vm_map	*db_map_addr(vm_offset_t);
110boolean_t	db_map_current(struct vm_map *);
111boolean_t	db_map_equal(struct vm_map *, struct vm_map *);
112int		db_md_set_watchpoint(db_expr_t addr, db_expr_t size);
113int		db_md_clr_watchpoint(db_expr_t addr, db_expr_t size);
114void		db_md_list_watchpoints(void);
115void		db_print_loc_and_inst(db_addr_t loc);
116void		db_print_thread(void);
117void		db_printf(const char *fmt, ...) __printflike(1, 2);
118int		db_read_bytes(vm_offset_t addr, size_t size, char *data);
119				/* machine-dependent */
120int		db_readline(char *lstart, int lsize);
121void		db_restart_at_pc(boolean_t watchpt);
122int		db_set_variable(db_expr_t value);
123void		db_set_watchpoints(void);
124void		db_skip_to_eol(void);
125boolean_t	db_stop_at_pc(boolean_t *is_breakpoint);
126#define		db_strcpy	strcpy
127void		db_trace_self(void);
128int		db_trace_thread(struct thread *, int);
129int		db_value_of_name(const char *name, db_expr_t *valuep);
130int		db_write_bytes(vm_offset_t addr, size_t size, char *data);
131
132db_cmdfcn_t	db_breakpoint_cmd;
133db_cmdfcn_t	db_capture_cmd;
134db_cmdfcn_t	db_continue_cmd;
135db_cmdfcn_t	db_delete_cmd;
136db_cmdfcn_t	db_deletehwatch_cmd;
137db_cmdfcn_t	db_deletewatch_cmd;
138db_cmdfcn_t	db_examine_cmd;
139db_cmdfcn_t	db_hwatchpoint_cmd;
140db_cmdfcn_t	db_listbreak_cmd;
141db_cmdfcn_t	db_print_cmd;
142db_cmdfcn_t	db_ps;
143db_cmdfcn_t	db_search_cmd;
144db_cmdfcn_t	db_set_cmd;
145db_cmdfcn_t	db_set_thread;
146db_cmdfcn_t	db_show_regs;
147db_cmdfcn_t	db_show_threads;
148db_cmdfcn_t	db_single_step_cmd;
149db_cmdfcn_t	db_trace_until_call_cmd;
150db_cmdfcn_t	db_trace_until_matching_cmd;
151db_cmdfcn_t	db_watchpoint_cmd;
152db_cmdfcn_t	db_write_cmd;
153
154/*
155 * Command table.
156 */
157struct command;
158
159struct command_table {
160	struct command *table;
161	struct command **aux_tablep;
162	struct command **aux_tablep_end;
163};
164
165struct command {
166	char *	name;		/* command name */
167	db_cmdfcn_t *fcn;	/* function to call */
168	int	flag;		/* extra info: */
169#define	CS_OWN		0x1	/* non-standard syntax */
170#define	CS_MORE		0x2	/* standard syntax, but may have other words
171				 * at end */
172#define	CS_SET_DOT	0x100	/* set dot after command */
173	struct command_table *more; /* another level of command */
174};
175
176/*
177 * Interface between DDB and the DDB output capture facility.
178 */
179struct dumperinfo;
180void	db_capture_dump(struct dumperinfo *di);
181void	db_capture_enterpager(void);
182void	db_capture_exitpager(void);
183void	db_capture_write(char *buffer, u_int buflen);
184void	db_capture_writech(char ch);
185
186#endif /* !_DDB_DDB_H_ */
187