1798Swollman/*- 2798Swollman * Copyright (c) 1993, Garrett A. Wollman. 3798Swollman * Copyright (c) 1993, University of Vermont and State Agricultural College. 4798Swollman * All rights reserved. 5798Swollman * 6798Swollman * Redistribution and use in source and binary forms, with or without 7798Swollman * modification, are permitted provided that the following conditions 8798Swollman * are met: 9798Swollman * 1. Redistributions of source code must retain the above copyright 10798Swollman * notice, this list of conditions and the following disclaimer. 11798Swollman * 2. Redistributions in binary form must reproduce the above copyright 12798Swollman * notice, this list of conditions and the following disclaimer in the 13798Swollman * documentation and/or other materials provided with the distribution. 14798Swollman * 3. Neither the name of the University nor the names of its contributors 15798Swollman * may be used to endorse or promote products derived from this software 16798Swollman * without specific prior written permission. 17798Swollman * 18798Swollman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19798Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20798Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21798Swollman * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22798Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23798Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24798Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25798Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26798Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27798Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28798Swollman * SUCH DAMAGE. 29798Swollman * 3050477Speter * $FreeBSD$ 31798Swollman */ 32798Swollman 33798Swollman/* 34798Swollman * Necessary declarations for the `ddb' kernel debugger. 35798Swollman */ 36798Swollman 3712472Sbde#ifndef _DDB_DDB_H_ 3812472Sbde#define _DDB_DDB_H_ 39798Swollman 40174910Srwatson#ifdef SYSCTL_DECL 41174910SrwatsonSYSCTL_DECL(_debug_ddb); 42174910Srwatson#endif 43174910Srwatson 441549Srgrimes#include <machine/db_machdep.h> /* type definitions */ 45798Swollman 46183054Ssam#include <sys/queue.h> /* LIST_* */ 47183054Ssam#include <sys/kernel.h> /* SYSINIT */ 48183054Ssam 49147745Smarcel#ifndef DB_MAXARGS 50147745Smarcel#define DB_MAXARGS 10 51147745Smarcel#endif 52147745Smarcel 53174914Srwatson#ifndef DB_MAXLINE 54174914Srwatson#define DB_MAXLINE 120 55174914Srwatson#endif 56174914Srwatson 57174914Srwatson#ifndef DB_MAXSCRIPTS 58174914Srwatson#define DB_MAXSCRIPTS 8 59174914Srwatson#endif 60174914Srwatson 61174914Srwatson#ifndef DB_MAXSCRIPTNAME 62174914Srwatson#define DB_MAXSCRIPTNAME 32 63174914Srwatson#endif 64174914Srwatson 65174914Srwatson#ifndef DB_MAXSCRIPTLEN 66174914Srwatson#define DB_MAXSCRIPTLEN 128 67174914Srwatson#endif 68174914Srwatson 69174914Srwatson#ifndef DB_MAXSCRIPTRECURSION 70174914Srwatson#define DB_MAXSCRIPTRECURSION 3 71174914Srwatson#endif 72174914Srwatson 73147745Smarcel#ifndef DB_CALL 74147745Smarcel#define DB_CALL db_fncall_generic 75147745Smarcel#else 76147745Smarcelint DB_CALL(db_expr_t, db_expr_t *, int, db_expr_t[]); 77147745Smarcel#endif 78147745Smarcel 79183054Ssam/* 80183054Ssam * There are three "command tables": 81183054Ssam * - One for simple commands; a list of these is displayed 82183054Ssam * by typing 'help' at the debugger prompt. 83183054Ssam * - One for sub-commands of 'show'; to see this type 'show' 84183054Ssam * without any arguments. 85183054Ssam * - The last one for sub-commands of 'show all'; type 'show all' 86183054Ssam * without any argument to get a list. 87183054Ssam */ 88183054Ssamstruct command; 89183054SsamLIST_HEAD(command_table, command); 90183054Ssamextern struct command_table db_cmd_table; 91183054Ssamextern struct command_table db_show_table; 92183054Ssamextern struct command_table db_show_all_table; 93183054Ssam 94183054Ssam/* 95183054Ssam * Type signature for a function implementing a ddb command. 96183054Ssam */ 9793009Sbdetypedef void db_cmdfcn_t(db_expr_t addr, boolean_t have_addr, db_expr_t count, 9893009Sbde char *modif); 9912472Sbde 100183054Ssam/* 101183054Ssam * Command table entry. 102183054Ssam */ 103183054Ssamstruct command { 104183054Ssam char * name; /* command name */ 105183054Ssam db_cmdfcn_t *fcn; /* function to call */ 106183054Ssam int flag; /* extra info: */ 107183054Ssam#define CS_OWN 0x1 /* non-standard syntax */ 108183054Ssam#define CS_MORE 0x2 /* standard syntax, but may have other words 109183054Ssam * at end */ 110183054Ssam#define CS_SET_DOT 0x100 /* set dot after command */ 111183054Ssam struct command_table *more; /* another level of command */ 112183054Ssam LIST_ENTRY(command) next; /* next entry in the command table */ 113183054Ssam}; 11418296Sbde 115183054Ssam/* 116183054Ssam * Arrange for the specified ddb command to be defined and 117183054Ssam * bound to the specified function. Commands can be defined 118183054Ssam * in modules in which case they will be available only when 119183054Ssam * the module is loaded. 120183054Ssam */ 121264210Spfg#define _DB_SET(_suffix, _name, _func, list, _flag, _more) \ 122183054Ssamstatic struct command __CONCAT(_name,_suffix) = { \ 123183054Ssam .name = __STRING(_name), \ 124183054Ssam .fcn = _func, \ 125183054Ssam .flag = _flag, \ 126183054Ssam .more = _more \ 12718296Sbde}; \ 128183054Ssamstatic void __CONCAT(__CONCAT(_name,_suffix),_add)(void *arg __unused) \ 129183054Ssam { db_command_register(&list, &__CONCAT(_name,_suffix)); } \ 130183054SsamSYSINIT(__CONCAT(_name,_suffix), SI_SUB_KLD, SI_ORDER_ANY, \ 131183054Ssam __CONCAT(__CONCAT(_name,_suffix),_add), NULL); \ 132183054Ssamstatic void __CONCAT(__CONCAT(_name,_suffix),_del)(void *arg __unused) \ 133183054Ssam { db_command_unregister(&list, &__CONCAT(_name,_suffix)); } \ 134183054SsamSYSUNINIT(__CONCAT(_name,_suffix), SI_SUB_KLD, SI_ORDER_ANY, \ 135183054Ssam __CONCAT(__CONCAT(_name,_suffix),_del), NULL); 136156412Sjhb 137183054Ssam/* 138183054Ssam * Like _DB_SET but also create the function declaration which 139183054Ssam * must be followed immediately by the body; e.g. 140183054Ssam * _DB_FUNC(_cmd, panic, db_panic, db_cmd_table, 0, NULL) 141183054Ssam * { 142183054Ssam * ...panic implementation... 143183054Ssam * } 144183054Ssam * 145183054Ssam * This macro is mostly used to define commands placed in one of 146183054Ssam * the ddb command tables; see DB_COMMAND, etc. below. 147183054Ssam */ 148264210Spfg#define _DB_FUNC(_suffix, _name, _func, list, _flag, _more) \ 149183054Ssamstatic db_cmdfcn_t _func; \ 150183054Ssam_DB_SET(_suffix, _name, _func, list, _flag, _more); \ 15118296Sbdestatic void \ 152183054Ssam_func(db_expr_t addr, boolean_t have_addr, db_expr_t count, char *modif) 15318296Sbde 154183054Ssam/* common idom provided for backwards compatibility */ 155264210Spfg#define DB_FUNC(_name, _func, list, _flag, _more) \ 156183054Ssam _DB_FUNC(_cmd, _name, _func, list, _flag, _more) 157183054Ssam 158264210Spfg#define DB_COMMAND(cmd_name, func_name) \ 159183054Ssam _DB_FUNC(_cmd, cmd_name, func_name, db_cmd_table, 0, NULL) 160264210Spfg#define DB_ALIAS(alias_name, func_name) \ 161183054Ssam _DB_SET(_cmd, alias_name, func_name, db_cmd_table, 0, NULL) 162264210Spfg#define DB_SHOW_COMMAND(cmd_name, func_name) \ 163183054Ssam _DB_FUNC(_show, cmd_name, func_name, db_show_table, 0, NULL) 164264210Spfg#define DB_SHOW_ALIAS(alias_name, func_name) \ 165183054Ssam _DB_SET(_show, alias_name, func_name, db_show_table, 0, NULL) 166264210Spfg#define DB_SHOW_ALL_COMMAND(cmd_name, func_name) \ 167183054Ssam _DB_FUNC(_show_all, cmd_name, func_name, db_show_all_table, 0, NULL) 168264210Spfg#define DB_SHOW_ALL_ALIAS(alias_name, func_name) \ 169183054Ssam _DB_SET(_show_all, alias_name, func_name, db_show_all_table, 0, NULL) 170183054Ssam 17137504Sbdeextern db_expr_t db_maxoff; 17218296Sbdeextern int db_indent; 173798Swollmanextern int db_inst_count; 174798Swollmanextern int db_load_count; 175798Swollmanextern int db_store_count; 176160312Sjhbextern volatile int db_pager_quit; 17737504Sbdeextern db_expr_t db_radix; 17837504Sbdeextern db_expr_t db_max_width; 17937504Sbdeextern db_expr_t db_tab_stop_width; 180137117Sjhbextern db_expr_t db_lines_per_page; 181798Swollman 182131952Smarcelstruct thread; 18318296Sbdestruct vm_map; 18412472Sbde 18592756Salfredvoid db_check_interrupt(void); 18692756Salfredvoid db_clear_watchpoints(void); 18792756Salfreddb_addr_t db_disasm(db_addr_t loc, boolean_t altfmt); 18812472Sbde /* instruction disassembler */ 189103746Smarkmvoid db_error(const char *s); 19092756Salfredint db_expression(db_expr_t *valuep); 19192756Salfredint db_get_variable(db_expr_t *valuep); 19292756Salfredvoid db_iprintf(const char *,...) __printflike(1, 2); 193158029Sjhbstruct proc *db_lookup_proc(db_expr_t addr); 194158029Sjhbstruct thread *db_lookup_thread(db_expr_t addr, boolean_t check_pid); 19592756Salfredstruct vm_map *db_map_addr(vm_offset_t); 19692756Salfredboolean_t db_map_current(struct vm_map *); 19792756Salfredboolean_t db_map_equal(struct vm_map *, struct vm_map *); 198149925Smarcelint db_md_set_watchpoint(db_expr_t addr, db_expr_t size); 199149925Smarcelint db_md_clr_watchpoint(db_expr_t addr, db_expr_t size); 200149925Smarcelvoid db_md_list_watchpoints(void); 20192756Salfredvoid db_print_loc_and_inst(db_addr_t loc); 202131952Smarcelvoid db_print_thread(void); 203207922Sattilioint db_printf(const char *fmt, ...) __printflike(1, 2); 204131952Smarcelint db_read_bytes(vm_offset_t addr, size_t size, char *data); 205798Swollman /* machine-dependent */ 20692756Salfredint db_readline(char *lstart, int lsize); 20792756Salfredvoid db_restart_at_pc(boolean_t watchpt); 208131952Smarcelint db_set_variable(db_expr_t value); 20992756Salfredvoid db_set_watchpoints(void); 21092756Salfredvoid db_skip_to_eol(void); 21192756Salfredboolean_t db_stop_at_pc(boolean_t *is_breakpoint); 21212472Sbde#define db_strcpy strcpy 213131952Smarcelvoid db_trace_self(void); 214131952Smarcelint db_trace_thread(struct thread *, int); 21592756Salfredint db_value_of_name(const char *name, db_expr_t *valuep); 216195699Srwatsonint db_value_of_name_pcpu(const char *name, db_expr_t *valuep); 217195699Srwatsonint db_value_of_name_vnet(const char *name, db_expr_t *valuep); 218131952Smarcelint db_write_bytes(vm_offset_t addr, size_t size, char *data); 219183054Ssamvoid db_command_register(struct command_table *, struct command *); 220183054Ssamvoid db_command_unregister(struct command_table *, struct command *); 221798Swollman 22212472Sbdedb_cmdfcn_t db_breakpoint_cmd; 223174910Srwatsondb_cmdfcn_t db_capture_cmd; 22412472Sbdedb_cmdfcn_t db_continue_cmd; 22512472Sbdedb_cmdfcn_t db_delete_cmd; 22679573Sbsddb_cmdfcn_t db_deletehwatch_cmd; 22712472Sbdedb_cmdfcn_t db_deletewatch_cmd; 22812472Sbdedb_cmdfcn_t db_examine_cmd; 229228569Skibdb_cmdfcn_t db_findstack_cmd; 23079573Sbsddb_cmdfcn_t db_hwatchpoint_cmd; 23112472Sbdedb_cmdfcn_t db_listbreak_cmd; 232174914Srwatsondb_cmdfcn_t db_scripts_cmd; 23312472Sbdedb_cmdfcn_t db_print_cmd; 23412472Sbdedb_cmdfcn_t db_ps; 235174914Srwatsondb_cmdfcn_t db_run_cmd; 236174914Srwatsondb_cmdfcn_t db_script_cmd; 23712472Sbdedb_cmdfcn_t db_search_cmd; 23812472Sbdedb_cmdfcn_t db_set_cmd; 239131952Smarceldb_cmdfcn_t db_set_thread; 24012472Sbdedb_cmdfcn_t db_show_regs; 241131952Smarceldb_cmdfcn_t db_show_threads; 24212472Sbdedb_cmdfcn_t db_single_step_cmd; 243174921Srwatsondb_cmdfcn_t db_textdump_cmd; 24412472Sbdedb_cmdfcn_t db_trace_until_call_cmd; 24512472Sbdedb_cmdfcn_t db_trace_until_matching_cmd; 246174914Srwatsondb_cmdfcn_t db_unscript_cmd; 24712472Sbdedb_cmdfcn_t db_watchpoint_cmd; 24812472Sbdedb_cmdfcn_t db_write_cmd; 249798Swollman 25018296Sbde/* 251174910Srwatson * Interface between DDB and the DDB output capture facility. 252174910Srwatson */ 253174910Srwatsonstruct dumperinfo; 254174910Srwatsonvoid db_capture_dump(struct dumperinfo *di); 255174910Srwatsonvoid db_capture_enterpager(void); 256174910Srwatsonvoid db_capture_exitpager(void); 257174910Srwatsonvoid db_capture_write(char *buffer, u_int buflen); 258174910Srwatsonvoid db_capture_writech(char ch); 259174910Srwatson 260174914Srwatson/* 261174914Srwatson * Interface between DDB and the script facility. 262174914Srwatson */ 263174914Srwatsonvoid db_script_kdbenter(const char *eventname); /* KDB enter event. */ 264174914Srwatson 265174921Srwatson/* 266174921Srwatson * Interface between DDB and the textdump facility. 267174921Srwatson * 268174921Srwatson * Text dump blocks are of a fixed size; textdump_block_buffer is a 269174921Srwatson * statically allocated buffer that code interacting with textdumps can use 270174921Srwatson * to prepare and hold a pending block in when calling writenextblock(). 271174921Srwatson */ 272174921Srwatson#define TEXTDUMP_BLOCKSIZE 512 273174921Srwatsonextern char textdump_block_buffer[TEXTDUMP_BLOCKSIZE]; 274174921Srwatson 275174921Srwatsonvoid textdump_mkustar(char *block_buffer, const char *filename, 276174921Srwatson u_int size); 277174921Srwatsonvoid textdump_restoreoff(off_t offset); 278174921Srwatsonvoid textdump_saveoff(off_t *offsetp); 279174921Srwatsonint textdump_writenextblock(struct dumperinfo *di, char *buffer); 280174921Srwatson 281174921Srwatson/* 282174921Srwatson * Interface between the kernel and textdumps. 283174921Srwatson */ 284174921Srwatsonextern int textdump_pending; /* Call textdump_dumpsys() instead. */ 285174921Srwatsonvoid textdump_dumpsys(struct dumperinfo *di); 286174921Srwatson 28712472Sbde#endif /* !_DDB_DDB_H_ */ 288