2 * Copyright (c) 1993, Garrett A. Wollman.
3 * Copyright (c) 1993, University of Vermont and State Agricultural College.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
34 * Necessary declarations for the `ddb' kernel debugger.
41 SYSCTL_DECL(_debug_ddb);
44 #include <machine/db_machdep.h> /* type definitions */
51 #define DB_MAXLINE 120
55 #define DB_MAXSCRIPTS 8
58 #ifndef DB_MAXSCRIPTNAME
59 #define DB_MAXSCRIPTNAME 32
62 #ifndef DB_MAXSCRIPTLEN
63 #define DB_MAXSCRIPTLEN 128
66 #ifndef DB_MAXSCRIPTRECURSION
67 #define DB_MAXSCRIPTRECURSION 3
71 #define DB_CALL db_fncall_generic
73 int DB_CALL(db_expr_t, db_expr_t *, int, db_expr_t[]);
76 typedef void db_cmdfcn_t(db_expr_t addr, boolean_t have_addr, db_expr_t count,
79 #define DB_COMMAND(cmd_name, func_name) \
80 DB_FUNC(cmd_name, func_name, db_cmd_set, 0, NULL)
81 #define DB_SHOW_COMMAND(cmd_name, func_name) \
82 DB_FUNC(cmd_name, func_name, db_show_cmd_set, 0, NULL)
83 #define DB_SHOW_ALL_COMMAND(cmd_name, func_name) \
84 DB_FUNC(cmd_name, func_name, db_show_all_cmd_set, 0, NULL)
86 #define DB_SET(cmd_name, func_name, set, flag, more) \
87 static const struct command __CONCAT(cmd_name,_cmd) = { \
93 TEXT_SET(set, __CONCAT(cmd_name,_cmd))
95 #define DB_FUNC(cmd_name, func_name, set, flag, more) \
96 static db_cmdfcn_t func_name; \
98 DB_SET(cmd_name, func_name, set, flag, more); \
101 func_name(addr, have_addr, count, modif) \
103 boolean_t have_addr; \
107 extern db_expr_t db_maxoff;
108 extern int db_indent;
109 extern int db_inst_count;
110 extern int db_load_count;
111 extern int db_store_count;
112 extern volatile int db_pager_quit;
113 extern db_expr_t db_radix;
114 extern db_expr_t db_max_width;
115 extern db_expr_t db_tab_stop_width;
116 extern db_expr_t db_lines_per_page;
121 void db_check_interrupt(void);
122 void db_clear_watchpoints(void);
123 db_addr_t db_disasm(db_addr_t loc, boolean_t altfmt);
124 /* instruction disassembler */
125 void db_error(const char *s);
126 int db_expression(db_expr_t *valuep);
127 int db_get_variable(db_expr_t *valuep);
128 void db_iprintf(const char *,...) __printflike(1, 2);
129 struct proc *db_lookup_proc(db_expr_t addr);
130 struct thread *db_lookup_thread(db_expr_t addr, boolean_t check_pid);
131 struct vm_map *db_map_addr(vm_offset_t);
132 boolean_t db_map_current(struct vm_map *);
133 boolean_t db_map_equal(struct vm_map *, struct vm_map *);
134 int db_md_set_watchpoint(db_expr_t addr, db_expr_t size);
135 int db_md_clr_watchpoint(db_expr_t addr, db_expr_t size);
136 void db_md_list_watchpoints(void);
137 void db_print_loc_and_inst(db_addr_t loc);
138 void db_print_thread(void);
139 void db_printf(const char *fmt, ...) __printflike(1, 2);
140 int db_read_bytes(vm_offset_t addr, size_t size, char *data);
141 /* machine-dependent */
142 int db_readline(char *lstart, int lsize);
143 void db_restart_at_pc(boolean_t watchpt);
144 int db_set_variable(db_expr_t value);
145 void db_set_watchpoints(void);
146 void db_skip_to_eol(void);
147 boolean_t db_stop_at_pc(boolean_t *is_breakpoint);
148 #define db_strcpy strcpy
149 void db_trace_self(void);
150 int db_trace_thread(struct thread *, int);
151 int db_value_of_name(const char *name, db_expr_t *valuep);
152 int db_write_bytes(vm_offset_t addr, size_t size, char *data);
154 db_cmdfcn_t db_breakpoint_cmd;
155 db_cmdfcn_t db_capture_cmd;
156 db_cmdfcn_t db_continue_cmd;
157 db_cmdfcn_t db_delete_cmd;
158 db_cmdfcn_t db_deletehwatch_cmd;
159 db_cmdfcn_t db_deletewatch_cmd;
160 db_cmdfcn_t db_examine_cmd;
161 db_cmdfcn_t db_hwatchpoint_cmd;
162 db_cmdfcn_t db_listbreak_cmd;
163 db_cmdfcn_t db_scripts_cmd;
164 db_cmdfcn_t db_print_cmd;
166 db_cmdfcn_t db_run_cmd;
167 db_cmdfcn_t db_script_cmd;
168 db_cmdfcn_t db_search_cmd;
169 db_cmdfcn_t db_set_cmd;
170 db_cmdfcn_t db_set_thread;
171 db_cmdfcn_t db_show_regs;
172 db_cmdfcn_t db_show_threads;
173 db_cmdfcn_t db_single_step_cmd;
174 db_cmdfcn_t db_textdump_cmd;
175 db_cmdfcn_t db_trace_until_call_cmd;
176 db_cmdfcn_t db_trace_until_matching_cmd;
177 db_cmdfcn_t db_unscript_cmd;
178 db_cmdfcn_t db_watchpoint_cmd;
179 db_cmdfcn_t db_write_cmd;
186 struct command_table {
187 struct command *table;
188 struct command **aux_tablep;
189 struct command **aux_tablep_end;
193 char * name; /* command name */
194 db_cmdfcn_t *fcn; /* function to call */
195 int flag; /* extra info: */
196 #define CS_OWN 0x1 /* non-standard syntax */
197 #define CS_MORE 0x2 /* standard syntax, but may have other words
199 #define CS_SET_DOT 0x100 /* set dot after command */
200 struct command_table *more; /* another level of command */
204 * Interface between DDB and the DDB output capture facility.
207 void db_capture_dump(struct dumperinfo *di);
208 void db_capture_enterpager(void);
209 void db_capture_exitpager(void);
210 void db_capture_write(char *buffer, u_int buflen);
211 void db_capture_writech(char ch);
214 * Interface between DDB and the script facility.
216 void db_script_kdbenter(const char *eventname); /* KDB enter event. */
219 * Interface between DDB and the textdump facility.
221 * Text dump blocks are of a fixed size; textdump_block_buffer is a
222 * statically allocated buffer that code interacting with textdumps can use
223 * to prepare and hold a pending block in when calling writenextblock().
225 #define TEXTDUMP_BLOCKSIZE 512
226 extern char textdump_block_buffer[TEXTDUMP_BLOCKSIZE];
228 void textdump_mkustar(char *block_buffer, const char *filename,
230 void textdump_restoreoff(off_t offset);
231 void textdump_saveoff(off_t *offsetp);
232 int textdump_writenextblock(struct dumperinfo *di, char *buffer);
235 * Interface between the kernel and textdumps.
237 extern int textdump_pending; /* Call textdump_dumpsys() instead. */
238 void textdump_dumpsys(struct dumperinfo *di);
240 #endif /* !_DDB_DDB_H_ */