ddb.h revision 263973
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 263973 2014-03-31 16:37:41Z pfg $ 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#include <sys/queue.h> /* LIST_* */ 47#include <sys/kernel.h> /* SYSINIT */ 48 49#ifndef DB_MAXARGS 50#define DB_MAXARGS 10 51#endif 52 53#ifndef DB_MAXLINE 54#define DB_MAXLINE 120 55#endif 56 57#ifndef DB_MAXSCRIPTS 58#define DB_MAXSCRIPTS 8 59#endif 60 61#ifndef DB_MAXSCRIPTNAME 62#define DB_MAXSCRIPTNAME 32 63#endif 64 65#ifndef DB_MAXSCRIPTLEN 66#define DB_MAXSCRIPTLEN 128 67#endif 68 69#ifndef DB_MAXSCRIPTRECURSION 70#define DB_MAXSCRIPTRECURSION 3 71#endif 72 73#ifndef DB_CALL 74#define DB_CALL db_fncall_generic 75#else 76int DB_CALL(db_expr_t, db_expr_t *, int, db_expr_t[]); 77#endif 78 79/* 80 * There are three "command tables": 81 * - One for simple commands; a list of these is displayed 82 * by typing 'help' at the debugger prompt. 83 * - One for sub-commands of 'show'; to see this type 'show' 84 * without any arguments. 85 * - The last one for sub-commands of 'show all'; type 'show all' 86 * without any argument to get a list. 87 */ 88struct command; 89LIST_HEAD(command_table, command); 90extern struct command_table db_cmd_table; 91extern struct command_table db_show_table; 92extern struct command_table db_show_all_table; 93 94/* 95 * Type signature for a function implementing a ddb command. 96 */ 97typedef void db_cmdfcn_t(db_expr_t addr, boolean_t have_addr, db_expr_t count, 98 char *modif); 99 100/* 101 * Command table entry. 102 */ 103struct command { 104 char * name; /* command name */ 105 db_cmdfcn_t *fcn; /* function to call */ 106 int flag; /* extra info: */ 107#define CS_OWN 0x1 /* non-standard syntax */ 108#define CS_MORE 0x2 /* standard syntax, but may have other words 109 * at end */ 110#define CS_SET_DOT 0x100 /* set dot after command */ 111 struct command_table *more; /* another level of command */ 112 LIST_ENTRY(command) next; /* next entry in the command table */ 113}; 114 115/* 116 * Arrange for the specified ddb command to be defined and 117 * bound to the specified function. Commands can be defined 118 * in modules in which case they will be available only when 119 * the module is loaded. 120 */ 121#define _DB_SET(_suffix, _name, _func, list, _flag, _more) \ 122static struct command __CONCAT(_name,_suffix) = { \ 123 .name = __STRING(_name), \ 124 .fcn = _func, \ 125 .flag = _flag, \ 126 .more = _more \ 127}; \ 128static void __CONCAT(__CONCAT(_name,_suffix),_add)(void *arg __unused) \ 129 { db_command_register(&list, &__CONCAT(_name,_suffix)); } \ 130SYSINIT(__CONCAT(_name,_suffix), SI_SUB_KLD, SI_ORDER_ANY, \ 131 __CONCAT(__CONCAT(_name,_suffix),_add), NULL); \ 132static void __CONCAT(__CONCAT(_name,_suffix),_del)(void *arg __unused) \ 133 { db_command_unregister(&list, &__CONCAT(_name,_suffix)); } \ 134SYSUNINIT(__CONCAT(_name,_suffix), SI_SUB_KLD, SI_ORDER_ANY, \ 135 __CONCAT(__CONCAT(_name,_suffix),_del), NULL); 136 137/* 138 * Like _DB_SET but also create the function declaration which 139 * must be followed immediately by the body; e.g. 140 * _DB_FUNC(_cmd, panic, db_panic, db_cmd_table, 0, NULL) 141 * { 142 * ...panic implementation... 143 * } 144 * 145 * This macro is mostly used to define commands placed in one of 146 * the ddb command tables; see DB_COMMAND, etc. below. 147 */ 148#define _DB_FUNC(_suffix, _name, _func, list, _flag, _more) \ 149static db_cmdfcn_t _func; \ 150_DB_SET(_suffix, _name, _func, list, _flag, _more); \ 151static void \ 152_func(db_expr_t addr, boolean_t have_addr, db_expr_t count, char *modif) 153 154/* common idom provided for backwards compatibility */ 155#define DB_FUNC(_name, _func, list, _flag, _more) \ 156 _DB_FUNC(_cmd, _name, _func, list, _flag, _more) 157 158#define DB_COMMAND(cmd_name, func_name) \ 159 _DB_FUNC(_cmd, cmd_name, func_name, db_cmd_table, 0, NULL) 160#define DB_ALIAS(alias_name, func_name) \ 161 _DB_SET(_cmd, alias_name, func_name, db_cmd_table, 0, NULL) 162#define DB_SHOW_COMMAND(cmd_name, func_name) \ 163 _DB_FUNC(_show, cmd_name, func_name, db_show_table, 0, NULL) 164#define DB_SHOW_ALIAS(alias_name, func_name) \ 165 _DB_SET(_show, alias_name, func_name, db_show_table, 0, NULL) 166#define DB_SHOW_ALL_COMMAND(cmd_name, func_name) \ 167 _DB_FUNC(_show_all, cmd_name, func_name, db_show_all_table, 0, NULL) 168#define DB_SHOW_ALL_ALIAS(alias_name, func_name) \ 169 _DB_SET(_show_all, alias_name, func_name, db_show_all_table, 0, NULL) 170 171extern db_expr_t db_maxoff; 172extern int db_indent; 173extern int db_inst_count; 174extern int db_load_count; 175extern int db_store_count; 176extern volatile int db_pager_quit; 177extern db_expr_t db_radix; 178extern db_expr_t db_max_width; 179extern db_expr_t db_tab_stop_width; 180extern db_expr_t db_lines_per_page; 181 182struct thread; 183struct vm_map; 184 185void db_check_interrupt(void); 186void db_clear_watchpoints(void); 187db_addr_t db_disasm(db_addr_t loc, boolean_t altfmt); 188 /* instruction disassembler */ 189void db_error(const char *s); 190int db_expression(db_expr_t *valuep); 191int db_get_variable(db_expr_t *valuep); 192void db_iprintf(const char *,...) __printflike(1, 2); 193struct proc *db_lookup_proc(db_expr_t addr); 194struct thread *db_lookup_thread(db_expr_t addr, boolean_t check_pid); 195struct vm_map *db_map_addr(vm_offset_t); 196boolean_t db_map_current(struct vm_map *); 197boolean_t db_map_equal(struct vm_map *, struct vm_map *); 198int db_md_set_watchpoint(db_expr_t addr, db_expr_t size); 199int db_md_clr_watchpoint(db_expr_t addr, db_expr_t size); 200void db_md_list_watchpoints(void); 201void db_print_loc_and_inst(db_addr_t loc); 202void db_print_thread(void); 203int db_printf(const char *fmt, ...) __printflike(1, 2); 204int db_read_bytes(vm_offset_t addr, size_t size, char *data); 205 /* machine-dependent */ 206int db_readline(char *lstart, int lsize); 207void db_restart_at_pc(boolean_t watchpt); 208int db_set_variable(db_expr_t value); 209void db_set_watchpoints(void); 210void db_skip_to_eol(void); 211boolean_t db_stop_at_pc(boolean_t *is_breakpoint); 212#define db_strcpy strcpy 213void db_trace_self(void); 214int db_trace_thread(struct thread *, int); 215int db_value_of_name(const char *name, db_expr_t *valuep); 216int db_value_of_name_pcpu(const char *name, db_expr_t *valuep); 217int db_value_of_name_vnet(const char *name, db_expr_t *valuep); 218int db_write_bytes(vm_offset_t addr, size_t size, char *data); 219void db_command_register(struct command_table *, struct command *); 220void db_command_unregister(struct command_table *, struct command *); 221 222db_cmdfcn_t db_breakpoint_cmd; 223db_cmdfcn_t db_capture_cmd; 224db_cmdfcn_t db_continue_cmd; 225db_cmdfcn_t db_delete_cmd; 226db_cmdfcn_t db_deletehwatch_cmd; 227db_cmdfcn_t db_deletewatch_cmd; 228db_cmdfcn_t db_examine_cmd; 229db_cmdfcn_t db_findstack_cmd; 230db_cmdfcn_t db_hwatchpoint_cmd; 231db_cmdfcn_t db_listbreak_cmd; 232db_cmdfcn_t db_scripts_cmd; 233db_cmdfcn_t db_print_cmd; 234db_cmdfcn_t db_ps; 235db_cmdfcn_t db_run_cmd; 236db_cmdfcn_t db_script_cmd; 237db_cmdfcn_t db_search_cmd; 238db_cmdfcn_t db_set_cmd; 239db_cmdfcn_t db_set_thread; 240db_cmdfcn_t db_show_regs; 241db_cmdfcn_t db_show_threads; 242db_cmdfcn_t db_single_step_cmd; 243db_cmdfcn_t db_textdump_cmd; 244db_cmdfcn_t db_trace_until_call_cmd; 245db_cmdfcn_t db_trace_until_matching_cmd; 246db_cmdfcn_t db_unscript_cmd; 247db_cmdfcn_t db_watchpoint_cmd; 248db_cmdfcn_t db_write_cmd; 249 250/* 251 * Interface between DDB and the DDB output capture facility. 252 */ 253struct dumperinfo; 254void db_capture_dump(struct dumperinfo *di); 255void db_capture_enterpager(void); 256void db_capture_exitpager(void); 257void db_capture_write(char *buffer, u_int buflen); 258void db_capture_writech(char ch); 259 260/* 261 * Interface between DDB and the script facility. 262 */ 263void db_script_kdbenter(const char *eventname); /* KDB enter event. */ 264 265/* 266 * Interface between DDB and the textdump facility. 267 * 268 * Text dump blocks are of a fixed size; textdump_block_buffer is a 269 * statically allocated buffer that code interacting with textdumps can use 270 * to prepare and hold a pending block in when calling writenextblock(). 271 */ 272#define TEXTDUMP_BLOCKSIZE 512 273extern char textdump_block_buffer[TEXTDUMP_BLOCKSIZE]; 274 275void textdump_mkustar(char *block_buffer, const char *filename, 276 u_int size); 277void textdump_restoreoff(off_t offset); 278void textdump_saveoff(off_t *offsetp); 279int textdump_writenextblock(struct dumperinfo *di, char *buffer); 280 281/* 282 * Interface between the kernel and textdumps. 283 */ 284extern int textdump_pending; /* Call textdump_dumpsys() instead. */ 285void textdump_dumpsys(struct dumperinfo *di); 286 287#endif /* !_DDB_DDB_H_ */ 288