Home | History | Annotate | Line # | Download | only in ddb
db_command.c revision 1.114.6.5
      1  1.114.6.5  mjf /*	$NetBSD: db_command.c,v 1.114.6.5 2009/01/17 13:28:51 mjf Exp $	*/
      2  1.114.6.2  mjf /*
      3  1.114.6.2  mjf  * Mach Operating System
      4  1.114.6.2  mjf  * Copyright (c) 1991,1990 Carnegie Mellon University
      5  1.114.6.2  mjf  * All Rights Reserved.
      6  1.114.6.2  mjf  *
      7  1.114.6.2  mjf  * Permission to use, copy, modify and distribute this software and its
      8  1.114.6.2  mjf  * documentation is hereby granted, provided that both the copyright
      9  1.114.6.2  mjf  * notice and this permission notice appear in all copies of the
     10  1.114.6.2  mjf  * software, derivative works or modified versions, and any portions
     11  1.114.6.2  mjf  * thereof, and that both notices appear in supporting documentation.
     12  1.114.6.2  mjf  *
     13  1.114.6.2  mjf  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     14  1.114.6.2  mjf  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
     15  1.114.6.2  mjf  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     16  1.114.6.2  mjf  *
     17  1.114.6.2  mjf  * Carnegie Mellon requests users of this software to return to
     18  1.114.6.2  mjf  *
     19  1.114.6.2  mjf  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     20  1.114.6.2  mjf  *  School of Computer Science
     21  1.114.6.2  mjf  *  Carnegie Mellon University
     22  1.114.6.2  mjf  *  Pittsburgh PA 15213-3890
     23  1.114.6.2  mjf  *
     24  1.114.6.2  mjf  * any improvements or extensions that they make and grant Carnegie the
     25  1.114.6.2  mjf  * rights to redistribute these changes.
     26  1.114.6.2  mjf  */
     27  1.114.6.2  mjf /*
     28  1.114.6.2  mjf  * Copyright (c) 1996, 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
     29  1.114.6.2  mjf  * All rights reserved.
     30  1.114.6.2  mjf  *
     31  1.114.6.2  mjf  * This code is derived from software contributed to The NetBSD Foundation
     32  1.114.6.2  mjf  * by Adam Hamsik.
     33  1.114.6.2  mjf  *
     34  1.114.6.2  mjf  * Redistribution and use in source and binary forms, with or without
     35  1.114.6.2  mjf  * modification, are permitted provided that the following conditions
     36  1.114.6.2  mjf  * are met:
     37  1.114.6.2  mjf  * 1. Redistributions of source code must retain the above copyright
     38  1.114.6.2  mjf  *    notice, this list of conditions and the following disclaimer.
     39  1.114.6.2  mjf  * 2. Redistributions in binary form must reproduce the above copyright
     40  1.114.6.2  mjf  *    notice, this list of conditions and the following disclaimer in the
     41  1.114.6.2  mjf  *    documentation and/or other materials provided with the distribution.
     42  1.114.6.2  mjf  *
     43  1.114.6.2  mjf  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     44  1.114.6.2  mjf  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     45  1.114.6.2  mjf  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     46  1.114.6.2  mjf  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     47  1.114.6.2  mjf  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     48  1.114.6.2  mjf  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     49  1.114.6.2  mjf  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     50  1.114.6.2  mjf  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     51  1.114.6.2  mjf  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     52  1.114.6.2  mjf  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     53  1.114.6.2  mjf  * POSSIBILITY OF SUCH DAMAGE.
     54  1.114.6.2  mjf  */
     55  1.114.6.2  mjf 
     56  1.114.6.2  mjf /*
     57  1.114.6.2  mjf  * Command dispatcher.
     58  1.114.6.2  mjf  */
     59  1.114.6.2  mjf 
     60  1.114.6.2  mjf #include <sys/cdefs.h>
     61  1.114.6.5  mjf __KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.114.6.5 2009/01/17 13:28:51 mjf Exp $");
     62  1.114.6.2  mjf 
     63  1.114.6.5  mjf #include "opt_aio.h"
     64  1.114.6.2  mjf #include "opt_ddb.h"
     65  1.114.6.2  mjf #include "opt_kgdb.h"
     66  1.114.6.2  mjf #include "opt_inet.h"
     67  1.114.6.3  mjf #include "opt_uvmhist.h"
     68  1.114.6.2  mjf #include "opt_ddbparam.h"
     69  1.114.6.2  mjf 
     70  1.114.6.2  mjf #include <sys/param.h>
     71  1.114.6.2  mjf #include <sys/systm.h>
     72  1.114.6.2  mjf #include <sys/reboot.h>
     73  1.114.6.2  mjf #include <sys/device.h>
     74  1.114.6.2  mjf #include <sys/lwp.h>
     75  1.114.6.2  mjf #include <sys/malloc.h>
     76  1.114.6.2  mjf #include <sys/mbuf.h>
     77  1.114.6.2  mjf #include <sys/namei.h>
     78  1.114.6.2  mjf #include <sys/pool.h>
     79  1.114.6.2  mjf #include <sys/proc.h>
     80  1.114.6.2  mjf #include <sys/vnode.h>
     81  1.114.6.2  mjf #include <sys/vmem.h>
     82  1.114.6.2  mjf #include <sys/lockdebug.h>
     83  1.114.6.2  mjf #include <sys/sleepq.h>
     84  1.114.6.2  mjf #include <sys/cpu.h>
     85  1.114.6.5  mjf #include <sys/buf.h>
     86  1.114.6.5  mjf #include <sys/module.h>
     87  1.114.6.2  mjf 
     88  1.114.6.2  mjf /*include queue macros*/
     89  1.114.6.2  mjf #include <sys/queue.h>
     90  1.114.6.2  mjf 
     91  1.114.6.2  mjf #include <machine/db_machdep.h>		/* type definitions */
     92  1.114.6.2  mjf 
     93  1.114.6.2  mjf #if defined(_KERNEL_OPT)
     94  1.114.6.2  mjf #include "opt_multiprocessor.h"
     95  1.114.6.2  mjf #endif
     96  1.114.6.2  mjf 
     97  1.114.6.2  mjf #include <ddb/db_lex.h>
     98  1.114.6.2  mjf #include <ddb/db_output.h>
     99  1.114.6.2  mjf #include <ddb/db_command.h>
    100  1.114.6.2  mjf #include <ddb/db_break.h>
    101  1.114.6.2  mjf #include <ddb/db_watch.h>
    102  1.114.6.2  mjf #include <ddb/db_run.h>
    103  1.114.6.2  mjf #include <ddb/db_variables.h>
    104  1.114.6.2  mjf #include <ddb/db_interface.h>
    105  1.114.6.2  mjf #include <ddb/db_sym.h>
    106  1.114.6.2  mjf #include <ddb/db_extern.h>
    107  1.114.6.2  mjf 
    108  1.114.6.2  mjf #include <uvm/uvm_extern.h>
    109  1.114.6.2  mjf #include <uvm/uvm_ddb.h>
    110  1.114.6.2  mjf 
    111  1.114.6.2  mjf #include "arp.h"
    112  1.114.6.2  mjf 
    113  1.114.6.2  mjf /*
    114  1.114.6.2  mjf  * Results of command search.
    115  1.114.6.2  mjf  */
    116  1.114.6.5  mjf #define	CMD_EXACT		0
    117  1.114.6.5  mjf #define	CMD_PREFIX		1
    118  1.114.6.5  mjf #define	CMD_NONE		2
    119  1.114.6.2  mjf #define	CMD_AMBIGUOUS	3
    120  1.114.6.2  mjf 
    121  1.114.6.2  mjf /*
    122  1.114.6.2  mjf  * Exported global variables
    123  1.114.6.2  mjf  */
    124  1.114.6.2  mjf bool		db_cmd_loop_done;
    125  1.114.6.2  mjf label_t		*db_recover;
    126  1.114.6.2  mjf db_addr_t	db_dot;
    127  1.114.6.2  mjf db_addr_t	db_last_addr;
    128  1.114.6.2  mjf db_addr_t	db_prev;
    129  1.114.6.2  mjf db_addr_t	db_next;
    130  1.114.6.2  mjf 
    131  1.114.6.2  mjf 
    132  1.114.6.2  mjf /*
    133  1.114.6.5  mjf  * New DDB api for adding and removing commands uses three lists, because
    134  1.114.6.5  mjf  * we use two types of commands
    135  1.114.6.5  mjf  * a) standard commands without subcommands -> reboot
    136  1.114.6.5  mjf  * b) show commands which are subcommands of show command -> show aio_jobs
    137  1.114.6.5  mjf  * c) if defined machine specific commands
    138  1.114.6.5  mjf  *
    139  1.114.6.5  mjf  * ddb_add_cmd, ddb_rem_cmd use type (DDB_SHOW_CMD||DDB_BASE_CMD)argument to
    140  1.114.6.5  mjf  * add them to representativ lists.
    141  1.114.6.5  mjf  */
    142  1.114.6.2  mjf 
    143  1.114.6.2  mjf static const struct db_command db_command_table[];
    144  1.114.6.2  mjf static const struct db_command db_show_cmds[];
    145  1.114.6.5  mjf 
    146  1.114.6.2  mjf #ifdef DB_MACHINE_COMMANDS
    147  1.114.6.2  mjf static const struct db_command db_machine_command_table[];
    148  1.114.6.2  mjf #endif
    149  1.114.6.2  mjf 
    150  1.114.6.2  mjf /* the global queue of all command tables */
    151  1.114.6.2  mjf TAILQ_HEAD(db_cmd_tbl_en_head, db_cmd_tbl_en);
    152  1.114.6.2  mjf 
    153  1.114.6.2  mjf /* TAILQ entry used to register command tables */
    154  1.114.6.2  mjf struct db_cmd_tbl_en {
    155  1.114.6.2  mjf 	const struct db_command *db_cmd;	/* cmd table */
    156  1.114.6.2  mjf 	TAILQ_ENTRY(db_cmd_tbl_en) db_cmd_next;
    157  1.114.6.2  mjf };
    158  1.114.6.2  mjf 
    159  1.114.6.2  mjf /* head of base commands list */
    160  1.114.6.2  mjf static struct db_cmd_tbl_en_head db_base_cmd_list =
    161  1.114.6.2  mjf 	TAILQ_HEAD_INITIALIZER(db_base_cmd_list);
    162  1.114.6.2  mjf static struct db_cmd_tbl_en db_base_cmd_builtins =
    163  1.114.6.2  mjf      { .db_cmd = db_command_table };
    164  1.114.6.2  mjf 
    165  1.114.6.2  mjf /* head of show commands list */
    166  1.114.6.2  mjf static struct db_cmd_tbl_en_head db_show_cmd_list =
    167  1.114.6.2  mjf 	TAILQ_HEAD_INITIALIZER(db_show_cmd_list);
    168  1.114.6.2  mjf static struct db_cmd_tbl_en db_show_cmd_builtins =
    169  1.114.6.2  mjf      { .db_cmd = db_show_cmds };
    170  1.114.6.2  mjf 
    171  1.114.6.2  mjf /* head of machine commands list */
    172  1.114.6.2  mjf static struct db_cmd_tbl_en_head db_mach_cmd_list =
    173  1.114.6.2  mjf 	TAILQ_HEAD_INITIALIZER(db_mach_cmd_list);
    174  1.114.6.2  mjf #ifdef DB_MACHINE_COMMANDS
    175  1.114.6.2  mjf static struct db_cmd_tbl_en db_mach_cmd_builtins =
    176  1.114.6.2  mjf      { .db_cmd = db_machine_command_table };
    177  1.114.6.2  mjf #endif
    178  1.114.6.2  mjf 
    179  1.114.6.2  mjf /*
    180  1.114.6.2  mjf  * if 'ed' style: 'dot' is set at start of last item printed,
    181  1.114.6.2  mjf  * and '+' points to next line.
    182  1.114.6.2  mjf  * Otherwise: 'dot' points to next item, '..' points to last.
    183  1.114.6.2  mjf  */
    184  1.114.6.2  mjf static bool	 db_ed_style = true;
    185  1.114.6.2  mjf 
    186  1.114.6.2  mjf static void	db_init_commands(void);
    187  1.114.6.2  mjf static int	db_register_tbl_entry(uint8_t type,
    188  1.114.6.2  mjf     struct db_cmd_tbl_en *list_ent);
    189  1.114.6.2  mjf static void	db_cmd_list(const struct db_cmd_tbl_en_head *);
    190  1.114.6.5  mjf static int	db_cmd_search(const char *, struct db_cmd_tbl_en_head *,
    191  1.114.6.5  mjf 			      const struct db_command **);
    192  1.114.6.5  mjf static int	db_cmd_search_table(const char *, const struct db_command *,
    193  1.114.6.5  mjf 				    const struct db_command **);
    194  1.114.6.5  mjf static void	db_cmd_search_failed(char *, int);
    195  1.114.6.5  mjf static const struct db_command *db_read_command(void);
    196  1.114.6.2  mjf static void	db_command(const struct db_command **);
    197  1.114.6.2  mjf static void	db_buf_print_cmd(db_expr_t, bool, db_expr_t, const char *);
    198  1.114.6.2  mjf static void	db_event_print_cmd(db_expr_t, bool, db_expr_t, const char *);
    199  1.114.6.2  mjf static void	db_fncall(db_expr_t, bool, db_expr_t, const char *);
    200  1.114.6.2  mjf static void     db_help_print_cmd(db_expr_t, bool, db_expr_t, const char *);
    201  1.114.6.2  mjf static void	db_lock_print_cmd(db_expr_t, bool, db_expr_t, const char *);
    202  1.114.6.2  mjf static void	db_mount_print_cmd(db_expr_t, bool, db_expr_t, const char *);
    203  1.114.6.2  mjf static void	db_mbuf_print_cmd(db_expr_t, bool, db_expr_t, const char *);
    204  1.114.6.2  mjf static void	db_malloc_print_cmd(db_expr_t, bool, db_expr_t, const char *);
    205  1.114.6.2  mjf static void	db_map_print_cmd(db_expr_t, bool, db_expr_t, const char *);
    206  1.114.6.2  mjf static void	db_namecache_print_cmd(db_expr_t, bool, db_expr_t,
    207  1.114.6.2  mjf 		    const char *);
    208  1.114.6.2  mjf static void	db_object_print_cmd(db_expr_t, bool, db_expr_t, const char *);
    209  1.114.6.2  mjf static void	db_page_print_cmd(db_expr_t, bool, db_expr_t, const char *);
    210  1.114.6.2  mjf static void	db_show_all_pages(db_expr_t, bool, db_expr_t, const char *);
    211  1.114.6.2  mjf static void	db_pool_print_cmd(db_expr_t, bool, db_expr_t, const char *);
    212  1.114.6.2  mjf static void	db_reboot_cmd(db_expr_t, bool, db_expr_t, const char *);
    213  1.114.6.2  mjf static void	db_sifting_cmd(db_expr_t, bool, db_expr_t, const char *);
    214  1.114.6.2  mjf static void	db_stack_trace_cmd(db_expr_t, bool, db_expr_t, const char *);
    215  1.114.6.2  mjf static void	db_sync_cmd(db_expr_t, bool, db_expr_t, const char *);
    216  1.114.6.2  mjf static void	db_whatis_cmd(db_expr_t, bool, db_expr_t, const char *);
    217  1.114.6.2  mjf static void	db_uvmexp_print_cmd(db_expr_t, bool, db_expr_t, const char *);
    218  1.114.6.3  mjf #ifdef UVMHIST
    219  1.114.6.3  mjf static void	db_uvmhist_print_cmd(db_expr_t, bool, db_expr_t, const char *);
    220  1.114.6.3  mjf #endif
    221  1.114.6.2  mjf static void	db_vnode_print_cmd(db_expr_t, bool, db_expr_t, const char *);
    222  1.114.6.5  mjf static void	db_vmem_print_cmd(db_expr_t, bool, db_expr_t, const char *);
    223  1.114.6.5  mjf static void	db_show_all_vmems(db_expr_t, bool, db_expr_t, const char *);
    224  1.114.6.2  mjf 
    225  1.114.6.2  mjf static const struct db_command db_show_cmds[] = {
    226  1.114.6.2  mjf 	/*added from all sub cmds*/
    227  1.114.6.2  mjf 	{ DDB_ADD_CMD("callout",  db_show_callout,
    228  1.114.6.2  mjf 	    0 ,"List all used callout functions.",NULL,NULL) },
    229  1.114.6.2  mjf 	{ DDB_ADD_CMD("pages",	db_show_all_pages,
    230  1.114.6.2  mjf 	    0 ,"List all used memory pages.",NULL,NULL) },
    231  1.114.6.2  mjf 	{ DDB_ADD_CMD("procs",	db_show_all_procs,
    232  1.114.6.2  mjf 	    0 ,"List all processes.",NULL,NULL) },
    233  1.114.6.2  mjf 	{ DDB_ADD_CMD("pools",	db_show_all_pools,
    234  1.114.6.2  mjf 	    0 ,"Show all poolS",NULL,NULL) },
    235  1.114.6.5  mjf #ifdef AIO
    236  1.114.6.2  mjf 	/*added from all sub cmds*/
    237  1.114.6.2  mjf 	{ DDB_ADD_CMD("aio_jobs",	db_show_aio_jobs,	0,
    238  1.114.6.2  mjf 	    "Show aio jobs",NULL,NULL) },
    239  1.114.6.5  mjf #endif
    240  1.114.6.2  mjf 	{ DDB_ADD_CMD("all",	NULL,
    241  1.114.6.2  mjf 	    CS_COMPAT, NULL,NULL,NULL) },
    242  1.114.6.2  mjf #if defined(INET) && (NARP > 0)
    243  1.114.6.2  mjf 	{ DDB_ADD_CMD("arptab",	db_show_arptab,		0,NULL,NULL,NULL) },
    244  1.114.6.2  mjf #endif
    245  1.114.6.2  mjf 	{ DDB_ADD_CMD("breaks",	db_listbreak_cmd, 	0,
    246  1.114.6.2  mjf 	    "Display all breaks.",NULL,NULL) },
    247  1.114.6.2  mjf 	{ DDB_ADD_CMD("buf",	db_buf_print_cmd,	0,
    248  1.114.6.2  mjf 	    "Print the struct buf at address.", "[/f] address",NULL) },
    249  1.114.6.2  mjf 	{ DDB_ADD_CMD("event",	db_event_print_cmd,	0,
    250  1.114.6.2  mjf 	    "Print all the non-zero evcnt(9) event counters.", "[/f]",NULL) },
    251  1.114.6.3  mjf 	{ DDB_ADD_CMD("files", db_show_files_cmd,	0,
    252  1.114.6.3  mjf 	    "Print the files open by process at address",
    253  1.114.6.3  mjf 	    "[/f] address", NULL) },
    254  1.114.6.2  mjf 	{ DDB_ADD_CMD("lock",	db_lock_print_cmd,	0,NULL,NULL,NULL) },
    255  1.114.6.2  mjf 	{ DDB_ADD_CMD("malloc",	db_malloc_print_cmd,0,NULL,NULL,NULL) },
    256  1.114.6.2  mjf 	{ DDB_ADD_CMD("map",	db_map_print_cmd,	0,
    257  1.114.6.2  mjf 	    "Print the vm_map at address.", "[/f] address",NULL) },
    258  1.114.6.5  mjf 	{ DDB_ADD_CMD("module", db_show_module_cmd,	0,
    259  1.114.6.5  mjf 	    "Print kernel modules", NULL, NULL) },
    260  1.114.6.2  mjf 	{ DDB_ADD_CMD("mount",	db_mount_print_cmd,	0,
    261  1.114.6.2  mjf 	    "Print the mount structure at address.", "[/f] address",NULL) },
    262  1.114.6.4  mjf 	{ DDB_ADD_CMD("mqueue", db_show_mqueue_cmd,	0,
    263  1.114.6.4  mjf 	    "Print the message queues", NULL, NULL) },
    264  1.114.6.2  mjf 	{ DDB_ADD_CMD("mbuf",	db_mbuf_print_cmd,	0,NULL,NULL,
    265  1.114.6.2  mjf 	    "-c prints all mbuf chains") },
    266  1.114.6.2  mjf 	{ DDB_ADD_CMD("ncache",	db_namecache_print_cmd,	0,
    267  1.114.6.2  mjf 	    "Dump the namecache list.", "address",NULL) },
    268  1.114.6.2  mjf 	{ DDB_ADD_CMD("object",	db_object_print_cmd,	0,
    269  1.114.6.2  mjf 	    "Print the vm_object at address.", "[/f] address",NULL) },
    270  1.114.6.2  mjf 	{ DDB_ADD_CMD("page",	db_page_print_cmd,	0,
    271  1.114.6.2  mjf 	    "Print the vm_page at address.", "[/f] address",NULL) },
    272  1.114.6.2  mjf 	{ DDB_ADD_CMD("pool",	db_pool_print_cmd,	0,
    273  1.114.6.2  mjf 	    "Print the pool at address.", "[/clp] address",NULL) },
    274  1.114.6.2  mjf 	{ DDB_ADD_CMD("registers",	db_show_regs,		0,
    275  1.114.6.2  mjf 	    "Display the register set.", "[/u]",NULL) },
    276  1.114.6.2  mjf 	{ DDB_ADD_CMD("sched_qs",	db_show_sched_qs,	0,
    277  1.114.6.2  mjf 	    "Print the state of the scheduler's run queues.",
    278  1.114.6.2  mjf 	    NULL,NULL) },
    279  1.114.6.2  mjf 	{ DDB_ADD_CMD("uvmexp",	db_uvmexp_print_cmd, 0,
    280  1.114.6.2  mjf 	    "Print a selection of UVM counters and statistics.",
    281  1.114.6.2  mjf 	    NULL,NULL) },
    282  1.114.6.3  mjf #ifdef UVMHIST
    283  1.114.6.3  mjf 	{ DDB_ADD_CMD("uvmhist", db_uvmhist_print_cmd, 0,
    284  1.114.6.3  mjf 	    "Print the UVM history logs.",
    285  1.114.6.3  mjf 	    NULL,NULL) },
    286  1.114.6.3  mjf #endif
    287  1.114.6.2  mjf 	{ DDB_ADD_CMD("vnode",	db_vnode_print_cmd,	0,
    288  1.114.6.2  mjf 	    "Print the vnode at address.", "[/f] address",NULL) },
    289  1.114.6.5  mjf 	{ DDB_ADD_CMD("vmem", db_vmem_print_cmd,	0,
    290  1.114.6.5  mjf 	    "Print the vmem usage.", "[/a] address", NULL) },
    291  1.114.6.5  mjf 	{ DDB_ADD_CMD("vmems", db_show_all_vmems,	0,
    292  1.114.6.5  mjf 	    "Show all vmems.", NULL, NULL) },
    293  1.114.6.2  mjf 	{ DDB_ADD_CMD("watches",	db_listwatch_cmd, 	0,
    294  1.114.6.2  mjf 	    "Display all watchpoints.", NULL,NULL) },
    295  1.114.6.2  mjf 	{ DDB_ADD_CMD(NULL,		NULL,			0,NULL,NULL,NULL) }
    296  1.114.6.2  mjf };
    297  1.114.6.2  mjf 
    298  1.114.6.2  mjf /* arch/<arch>/<arch>/db_interface.c */
    299  1.114.6.2  mjf #ifdef DB_MACHINE_COMMANDS
    300  1.114.6.2  mjf extern const struct db_command db_machine_command_table[];
    301  1.114.6.2  mjf #endif
    302  1.114.6.2  mjf 
    303  1.114.6.2  mjf static const struct db_command db_command_table[] = {
    304  1.114.6.2  mjf 	{ DDB_ADD_CMD("b",		db_breakpoint_cmd,	0,
    305  1.114.6.2  mjf 	    "Set a breakpoint at address", "[/u] address[,count].",NULL) },
    306  1.114.6.2  mjf 	{ DDB_ADD_CMD("break",	db_breakpoint_cmd,	0,
    307  1.114.6.2  mjf 	    "Set a breakpoint at address", "[/u] address[,count].",NULL) },
    308  1.114.6.2  mjf 	{ DDB_ADD_CMD("bt",		db_stack_trace_cmd,	0,
    309  1.114.6.2  mjf 	    "Show backtrace.", "See help trace.",NULL) },
    310  1.114.6.2  mjf 	{ DDB_ADD_CMD("c",		db_continue_cmd,	0,
    311  1.114.6.2  mjf 	    "Continue execution.", "[/c]",NULL) },
    312  1.114.6.2  mjf 	{ DDB_ADD_CMD("call",	db_fncall,		CS_OWN,
    313  1.114.6.2  mjf 	    "Call the function", "address[(expression[,...])]",NULL) },
    314  1.114.6.2  mjf 	{ DDB_ADD_CMD("callout",	db_show_callout,	0, NULL,
    315  1.114.6.2  mjf 	    NULL,NULL ) },
    316  1.114.6.2  mjf 	{ DDB_ADD_CMD("continue",	db_continue_cmd,	0,
    317  1.114.6.2  mjf 	    "Continue execution.", "[/c]",NULL) },
    318  1.114.6.2  mjf 	{ DDB_ADD_CMD("d",		db_delete_cmd,		0,
    319  1.114.6.2  mjf 	    "Delete a breakpoint.", "address | #number",NULL) },
    320  1.114.6.2  mjf 	{ DDB_ADD_CMD("delete",	db_delete_cmd,		0,
    321  1.114.6.2  mjf 	    "Delete a breakpoint.", "address | #number",NULL) },
    322  1.114.6.2  mjf 	{ DDB_ADD_CMD("dmesg",	db_dmesg,		0,
    323  1.114.6.2  mjf 	    "Show kernel message buffer.", "[count]",NULL) },
    324  1.114.6.2  mjf 	{ DDB_ADD_CMD("dwatch",	db_deletewatch_cmd,	0,
    325  1.114.6.2  mjf 	    "Delete the watchpoint.", "address",NULL) },
    326  1.114.6.2  mjf 	{ DDB_ADD_CMD("examine",	db_examine_cmd,		CS_SET_DOT,
    327  1.114.6.2  mjf 	    "Display the address locations.",
    328  1.114.6.2  mjf 	    "[/modifier] address[,count]",NULL) },
    329  1.114.6.2  mjf 	{ DDB_ADD_CMD("help",   db_help_print_cmd, CS_OWN|CS_NOREPEAT,
    330  1.114.6.2  mjf 	    "Display help about commands",
    331  1.114.6.2  mjf 	    "Use other commands as arguments.",NULL) },
    332  1.114.6.2  mjf 	{ DDB_ADD_CMD("kill",	db_kill_proc,		CS_OWN,
    333  1.114.6.2  mjf 	    "Send a signal to the process","pid[,signal_number]",
    334  1.114.6.2  mjf 	    "   pid:\t\t\tthe process id (may need 0t prefix for decimal)\n"
    335  1.114.6.2  mjf 	    "   signal_number:\tthe signal to send") },
    336  1.114.6.2  mjf #ifdef KGDB
    337  1.114.6.2  mjf 	{ DDB_ADD_CMD("kgdb",	db_kgdb_cmd,	0,	NULL,NULL,NULL) },
    338  1.114.6.2  mjf #endif
    339  1.114.6.2  mjf 	{ DDB_ADD_CMD("machine",NULL,CS_MACH,
    340  1.114.6.2  mjf 	    "Architecture specific functions.",NULL,NULL) },
    341  1.114.6.2  mjf 	{ DDB_ADD_CMD("match",	db_trace_until_matching_cmd,0,
    342  1.114.6.2  mjf 	    "Stop at the matching return instruction.","See help next",NULL) },
    343  1.114.6.2  mjf 	{ DDB_ADD_CMD("next",	db_trace_until_matching_cmd,0,
    344  1.114.6.2  mjf 	    "Stop at the matching return instruction.","[/p]",NULL) },
    345  1.114.6.2  mjf 	{ DDB_ADD_CMD("p",		db_print_cmd,		0,
    346  1.114.6.2  mjf 	    "Print address according to the format.",
    347  1.114.6.2  mjf 	    "[/axzodurc] address [address ...]",NULL) },
    348  1.114.6.2  mjf 	{ DDB_ADD_CMD("print",	db_print_cmd,		0,
    349  1.114.6.2  mjf 	    "Print address according to the format.",
    350  1.114.6.2  mjf 	    "[/axzodurc] address [address ...]",NULL) },
    351  1.114.6.2  mjf 	{ DDB_ADD_CMD("ps",		db_show_all_procs,	0,
    352  1.114.6.2  mjf 	    "Print all processes.","See show all procs",NULL) },
    353  1.114.6.2  mjf 	{ DDB_ADD_CMD("reboot",	db_reboot_cmd,		CS_OWN,
    354  1.114.6.2  mjf 	    "Reboot","0x1  RB_ASKNAME, 0x2 RB_SINGLE, 0x4 RB_NOSYNC, 0x8 RB_HALT,"
    355  1.114.6.2  mjf 	    "0x40 RB_KDB, 0x100 RB_DUMP, 0x808 RB_POWERDOWN",NULL) },
    356  1.114.6.2  mjf 	{ DDB_ADD_CMD("s",		db_single_step_cmd,	0,
    357  1.114.6.2  mjf 	    "Single-step count times.","[/p] [,count]",NULL) },
    358  1.114.6.2  mjf 	{ DDB_ADD_CMD("search",	db_search_cmd,		CS_OWN|CS_SET_DOT,
    359  1.114.6.2  mjf 	    "Search memory from address for value.",
    360  1.114.6.2  mjf 	    "[/bhl] address value [mask] [,count]",NULL) },
    361  1.114.6.2  mjf 	{ DDB_ADD_CMD("set",	db_set_cmd,		CS_OWN,
    362  1.114.6.2  mjf 	    "Set the named variable","$variable [=] expression",NULL) },
    363  1.114.6.2  mjf 	{ DDB_ADD_CMD("show",	NULL, CS_SHOW,
    364  1.114.6.2  mjf 	    "Show kernel stats.", NULL,NULL) },
    365  1.114.6.2  mjf 	{ DDB_ADD_CMD("sifting",	db_sifting_cmd,		CS_OWN,
    366  1.114.6.2  mjf 	    "Search the symbol tables ","[/F] string",NULL) },
    367  1.114.6.2  mjf 	{ DDB_ADD_CMD("step",	db_single_step_cmd,	0,
    368  1.114.6.2  mjf 	    "Single-step count times.","[/p] [,count]",NULL) },
    369  1.114.6.2  mjf 	{ DDB_ADD_CMD("sync",	db_sync_cmd,		CS_OWN,
    370  1.114.6.2  mjf 	    "Force a crash dump, and then reboot.",NULL,NULL) },
    371  1.114.6.2  mjf 	{ DDB_ADD_CMD("trace",	db_stack_trace_cmd,	0,
    372  1.114.6.2  mjf 	    "Stack trace from frame-address.",
    373  1.114.6.2  mjf 	    "[/u[l]] [frame-address][,count]",NULL) },
    374  1.114.6.2  mjf 	{ DDB_ADD_CMD("until",	db_trace_until_call_cmd,0,
    375  1.114.6.2  mjf 	    "Stop at the next call or return instruction.","[/p]",NULL) },
    376  1.114.6.2  mjf 	{ DDB_ADD_CMD("w",		db_write_cmd,		CS_MORE|CS_SET_DOT,
    377  1.114.6.2  mjf 	    "Write the expressions at succeeding locations.",
    378  1.114.6.2  mjf 	    "[/bhl] address expression [expression ...]",NULL) },
    379  1.114.6.2  mjf 	{ DDB_ADD_CMD("watch",	db_watchpoint_cmd,	CS_MORE,
    380  1.114.6.2  mjf 	    "Set a watchpoint for a region. ","address[,size]",NULL) },
    381  1.114.6.2  mjf 	{ DDB_ADD_CMD("whatis",	db_whatis_cmd, 0,
    382  1.114.6.2  mjf 	    "Describe what an address is", "address", NULL) },
    383  1.114.6.2  mjf 	{ DDB_ADD_CMD("write",	db_write_cmd,		CS_MORE|CS_SET_DOT,
    384  1.114.6.2  mjf 	    "Write the expressions at succeeding locations.",
    385  1.114.6.2  mjf 	    "[/bhl] address expression [expression ...]",NULL) },
    386  1.114.6.2  mjf 	{ DDB_ADD_CMD("x",		db_examine_cmd,		CS_SET_DOT,
    387  1.114.6.2  mjf 	    "Display the address locations.",
    388  1.114.6.2  mjf 	    "[/modifier] address[,count]",NULL) },
    389  1.114.6.2  mjf 	{ DDB_ADD_CMD(NULL, 	NULL,		   0, NULL, NULL, NULL) }
    390  1.114.6.2  mjf };
    391  1.114.6.2  mjf 
    392  1.114.6.2  mjf static const struct db_command	*db_last_command = NULL;
    393  1.114.6.2  mjf #if defined(DDB_COMMANDONENTER)
    394  1.114.6.2  mjf char db_cmd_on_enter[DB_LINE_MAXLEN + 1] = ___STRING(DDB_COMMANDONENTER);
    395  1.114.6.2  mjf #else /* defined(DDB_COMMANDONENTER) */
    396  1.114.6.2  mjf char db_cmd_on_enter[DB_LINE_MAXLEN + 1] = "";
    397  1.114.6.2  mjf #endif /* defined(DDB_COMMANDONENTER) */
    398  1.114.6.2  mjf #define	DB_LINE_SEP	';'
    399  1.114.6.2  mjf 
    400  1.114.6.2  mjf /*
    401  1.114.6.2  mjf  * Utility routine - discard tokens through end-of-line.
    402  1.114.6.2  mjf  */
    403  1.114.6.2  mjf void
    404  1.114.6.2  mjf db_skip_to_eol(void)
    405  1.114.6.2  mjf {
    406  1.114.6.2  mjf 	int t;
    407  1.114.6.2  mjf 
    408  1.114.6.2  mjf 	do {
    409  1.114.6.2  mjf 		t = db_read_token();
    410  1.114.6.2  mjf 	} while (t != tEOL);
    411  1.114.6.2  mjf }
    412  1.114.6.2  mjf 
    413  1.114.6.2  mjf void
    414  1.114.6.2  mjf db_error(const char *s)
    415  1.114.6.2  mjf {
    416  1.114.6.2  mjf 
    417  1.114.6.2  mjf 	if (s)
    418  1.114.6.2  mjf 		db_printf("%s", s);
    419  1.114.6.2  mjf 	db_flush_lex();
    420  1.114.6.2  mjf 	longjmp(db_recover);
    421  1.114.6.2  mjf }
    422  1.114.6.2  mjf 
    423  1.114.6.5  mjf /*
    424  1.114.6.5  mjf  * Execute commandlist after ddb start
    425  1.114.6.5  mjf  * This function goes through the command list created from commands and ';'
    426  1.114.6.2  mjf  */
    427  1.114.6.2  mjf static void
    428  1.114.6.2  mjf db_execute_commandlist(const char *cmdlist)
    429  1.114.6.2  mjf {
    430  1.114.6.2  mjf 	const char *cmd = cmdlist;
    431  1.114.6.2  mjf 	const struct db_command	*dummy = NULL;
    432  1.114.6.2  mjf 
    433  1.114.6.2  mjf 	while (*cmd != '\0') {
    434  1.114.6.2  mjf 		const char *ep = cmd;
    435  1.114.6.2  mjf 
    436  1.114.6.2  mjf 		while (*ep != '\0' && *ep != DB_LINE_SEP) {
    437  1.114.6.2  mjf 			ep++;
    438  1.114.6.2  mjf 		}
    439  1.114.6.2  mjf 		db_set_line(cmd, ep);
    440  1.114.6.2  mjf 		db_command(&dummy);
    441  1.114.6.2  mjf 		cmd = ep;
    442  1.114.6.2  mjf 		if (*cmd == DB_LINE_SEP) {
    443  1.114.6.2  mjf 			cmd++;
    444  1.114.6.2  mjf 		}
    445  1.114.6.2  mjf 	}
    446  1.114.6.2  mjf }
    447  1.114.6.2  mjf 
    448  1.114.6.5  mjf /* Initialize ddb command tables */
    449  1.114.6.2  mjf void
    450  1.114.6.2  mjf db_init_commands(void)
    451  1.114.6.2  mjf {
    452  1.114.6.2  mjf 	static bool done = false;
    453  1.114.6.2  mjf 
    454  1.114.6.2  mjf 	if (done) return;
    455  1.114.6.2  mjf 	done = true;
    456  1.114.6.2  mjf 
    457  1.114.6.2  mjf 	/* register command tables */
    458  1.114.6.2  mjf 	(void)db_register_tbl_entry(DDB_BASE_CMD, &db_base_cmd_builtins);
    459  1.114.6.2  mjf #ifdef DB_MACHINE_COMMANDS
    460  1.114.6.2  mjf 	(void)db_register_tbl_entry(DDB_MACH_CMD, &db_mach_cmd_builtins);
    461  1.114.6.2  mjf #endif
    462  1.114.6.2  mjf 	(void)db_register_tbl_entry(DDB_SHOW_CMD, &db_show_cmd_builtins);
    463  1.114.6.2  mjf }
    464  1.114.6.2  mjf 
    465  1.114.6.2  mjf 
    466  1.114.6.2  mjf /*
    467  1.114.6.2  mjf  * Add command table to the specified list
    468  1.114.6.2  mjf  * Arg:
    469  1.114.6.2  mjf  * int type specifies type of command table DDB_SHOW_CMD|DDB_BASE_CMD|DDB_MAC_CMD
    470  1.114.6.2  mjf  * *cmd_tbl poiter to static allocated db_command table
    471  1.114.6.2  mjf  *
    472  1.114.6.5  mjf  * Command table must be NULL terminated array of struct db_command
    473  1.114.6.2  mjf  */
    474  1.114.6.2  mjf int
    475  1.114.6.2  mjf db_register_tbl(uint8_t type, const struct db_command *cmd_tbl)
    476  1.114.6.2  mjf {
    477  1.114.6.2  mjf 	struct db_cmd_tbl_en *list_ent;
    478  1.114.6.5  mjf 
    479  1.114.6.5  mjf 	/* empty list - ignore */
    480  1.114.6.2  mjf 	if (cmd_tbl->name == 0)
    481  1.114.6.2  mjf 		return 0;
    482  1.114.6.2  mjf 
    483  1.114.6.2  mjf 	/* force builtin commands to be registered first */
    484  1.114.6.2  mjf 	db_init_commands();
    485  1.114.6.2  mjf 
    486  1.114.6.2  mjf 	/* now create a list entry for this table */
    487  1.114.6.2  mjf 	list_ent = malloc(sizeof(struct db_cmd_tbl_en), M_TEMP, M_ZERO);
    488  1.114.6.2  mjf 	if (list_ent == NULL)
    489  1.114.6.2  mjf 		return ENOMEM;
    490  1.114.6.2  mjf 	list_ent->db_cmd=cmd_tbl;
    491  1.114.6.2  mjf 
    492  1.114.6.2  mjf 	/* and register it */
    493  1.114.6.2  mjf 	return db_register_tbl_entry(type, list_ent);
    494  1.114.6.2  mjf }
    495  1.114.6.2  mjf 
    496  1.114.6.2  mjf static int
    497  1.114.6.2  mjf db_register_tbl_entry(uint8_t type, struct db_cmd_tbl_en *list_ent)
    498  1.114.6.2  mjf {
    499  1.114.6.2  mjf 	struct db_cmd_tbl_en_head *list;
    500  1.114.6.2  mjf 
    501  1.114.6.2  mjf 	switch(type) {
    502  1.114.6.2  mjf 	case DDB_BASE_CMD:
    503  1.114.6.2  mjf 		list = &db_base_cmd_list;
    504  1.114.6.2  mjf 		break;
    505  1.114.6.2  mjf 	case DDB_SHOW_CMD:
    506  1.114.6.2  mjf 		list = &db_show_cmd_list;
    507  1.114.6.2  mjf 		break;
    508  1.114.6.2  mjf 	case DDB_MACH_CMD:
    509  1.114.6.2  mjf 		list = &db_mach_cmd_list;
    510  1.114.6.2  mjf 		break;
    511  1.114.6.2  mjf 	default:
    512  1.114.6.2  mjf 		return ENOENT;
    513  1.114.6.2  mjf 	}
    514  1.114.6.2  mjf 
    515  1.114.6.2  mjf 	TAILQ_INSERT_TAIL(list, list_ent, db_cmd_next);
    516  1.114.6.2  mjf 
    517  1.114.6.2  mjf 	return 0;
    518  1.114.6.2  mjf }
    519  1.114.6.2  mjf 
    520  1.114.6.2  mjf /*
    521  1.114.6.2  mjf  * Remove command table specified with db_cmd address == cmd_tbl
    522  1.114.6.2  mjf  */
    523  1.114.6.2  mjf int
    524  1.114.6.2  mjf db_unregister_tbl(uint8_t type,const struct db_command *cmd_tbl)
    525  1.114.6.2  mjf {
    526  1.114.6.2  mjf 	struct db_cmd_tbl_en *list_ent;
    527  1.114.6.2  mjf 	struct db_cmd_tbl_en_head *list;
    528  1.114.6.2  mjf 
    529  1.114.6.2  mjf 	/* find list on which the entry should live */
    530  1.114.6.2  mjf 	switch (type) {
    531  1.114.6.2  mjf 	case DDB_BASE_CMD:
    532  1.114.6.2  mjf 		list=&db_base_cmd_list;
    533  1.114.6.2  mjf 		break;
    534  1.114.6.2  mjf 	case DDB_SHOW_CMD:
    535  1.114.6.2  mjf 		list=&db_show_cmd_list;
    536  1.114.6.2  mjf 		break;
    537  1.114.6.2  mjf 	case DDB_MACH_CMD:
    538  1.114.6.2  mjf 		list=&db_mach_cmd_list;
    539  1.114.6.2  mjf 		break;
    540  1.114.6.2  mjf 	default:
    541  1.114.6.2  mjf 		return EINVAL;
    542  1.114.6.2  mjf 	}
    543  1.114.6.2  mjf 
    544  1.114.6.5  mjf 	TAILQ_FOREACH (list_ent, list, db_cmd_next) {
    545  1.114.6.2  mjf 		if (list_ent->db_cmd == cmd_tbl){
    546  1.114.6.2  mjf 			TAILQ_REMOVE(list,
    547  1.114.6.5  mjf 			    list_ent, db_cmd_next);
    548  1.114.6.2  mjf 			free(list_ent,M_TEMP);
    549  1.114.6.2  mjf 			return 0;
    550  1.114.6.2  mjf 		}
    551  1.114.6.2  mjf 	}
    552  1.114.6.2  mjf 	return ENOENT;
    553  1.114.6.3  mjf }
    554  1.114.6.2  mjf 
    555  1.114.6.5  mjf /* This function is called from machine trap code. */
    556  1.114.6.2  mjf void
    557  1.114.6.2  mjf db_command_loop(void)
    558  1.114.6.2  mjf {
    559  1.114.6.2  mjf 	label_t	db_jmpbuf;
    560  1.114.6.2  mjf 	label_t	*savejmp;
    561  1.114.6.2  mjf 
    562  1.114.6.2  mjf 	/*
    563  1.114.6.2  mjf 	 * Initialize 'prev' and 'next' to dot.
    564  1.114.6.2  mjf 	 */
    565  1.114.6.2  mjf 	db_prev = db_dot;
    566  1.114.6.2  mjf 	db_next = db_dot;
    567  1.114.6.2  mjf 
    568  1.114.6.2  mjf 	db_cmd_loop_done = false;
    569  1.114.6.2  mjf 
    570  1.114.6.5  mjf 	/* Init default command tables add machine, base,
    571  1.114.6.5  mjf 	   show command tables to the list */
    572  1.114.6.2  mjf 	db_init_commands();
    573  1.114.6.2  mjf 
    574  1.114.6.5  mjf 	/* save context for return from ddb */
    575  1.114.6.2  mjf 	savejmp = db_recover;
    576  1.114.6.2  mjf 	db_recover = &db_jmpbuf;
    577  1.114.6.2  mjf 	(void) setjmp(&db_jmpbuf);
    578  1.114.6.2  mjf 
    579  1.114.6.5  mjf 	/* Execute default ddb start commands */
    580  1.114.6.2  mjf 	db_execute_commandlist(db_cmd_on_enter);
    581  1.114.6.2  mjf 
    582  1.114.6.2  mjf 	(void) setjmp(&db_jmpbuf);
    583  1.114.6.2  mjf 	while (!db_cmd_loop_done) {
    584  1.114.6.2  mjf 		if (db_print_position() != 0)
    585  1.114.6.2  mjf 			db_printf("\n");
    586  1.114.6.2  mjf 		db_output_line = 0;
    587  1.114.6.2  mjf 
    588  1.114.6.2  mjf 
    589  1.114.6.2  mjf #ifdef MULTIPROCESSOR
    590  1.114.6.2  mjf 		db_printf("db{%ld}> ", (long)cpu_number());
    591  1.114.6.2  mjf #else
    592  1.114.6.2  mjf 		db_printf("db> ");
    593  1.114.6.2  mjf #endif
    594  1.114.6.2  mjf 		(void) db_read_line();
    595  1.114.6.2  mjf 
    596  1.114.6.2  mjf 		db_command(&db_last_command);
    597  1.114.6.2  mjf 	}
    598  1.114.6.2  mjf 
    599  1.114.6.2  mjf 	db_recover = savejmp;
    600  1.114.6.2  mjf }
    601  1.114.6.2  mjf 
    602  1.114.6.2  mjf /*
    603  1.114.6.5  mjf  * Search command table for command prefix
    604  1.114.6.2  mjf  */
    605  1.114.6.2  mjf static int
    606  1.114.6.5  mjf db_cmd_search_table(const char *name,
    607  1.114.6.5  mjf 		    const struct db_command *table,
    608  1.114.6.5  mjf 		    const struct db_command **cmdp)
    609  1.114.6.2  mjf {
    610  1.114.6.3  mjf 
    611  1.114.6.2  mjf 	const struct db_command	*cmd;
    612  1.114.6.2  mjf 	int result;
    613  1.114.6.2  mjf 
    614  1.114.6.2  mjf 	result = CMD_NONE;
    615  1.114.6.2  mjf 	*cmdp = NULL;
    616  1.114.6.5  mjf 
    617  1.114.6.2  mjf 	for (cmd = table; cmd->name != 0; cmd++) {
    618  1.114.6.2  mjf 		const char *lp;
    619  1.114.6.2  mjf 		const char *rp;
    620  1.114.6.2  mjf 
    621  1.114.6.2  mjf 		lp = name;
    622  1.114.6.2  mjf 		rp = cmd->name;
    623  1.114.6.2  mjf 		while (*lp != '\0' && *lp == *rp) {
    624  1.114.6.2  mjf 			rp++;
    625  1.114.6.2  mjf 			lp++;
    626  1.114.6.2  mjf 		}
    627  1.114.6.2  mjf 
    628  1.114.6.2  mjf 		if (*lp != '\0') /* mismatch or extra chars in name */
    629  1.114.6.2  mjf 			continue;
    630  1.114.6.2  mjf 
    631  1.114.6.5  mjf 		if (*rp == '\0') { /* exact match */
    632  1.114.6.2  mjf 			*cmdp = cmd;
    633  1.114.6.5  mjf 			return (CMD_EXACT);
    634  1.114.6.2  mjf 		}
    635  1.114.6.2  mjf 
    636  1.114.6.2  mjf 		/* prefix match: end of name, not end of command */
    637  1.114.6.2  mjf 		if (result == CMD_NONE) {
    638  1.114.6.5  mjf 			result = CMD_PREFIX;
    639  1.114.6.2  mjf 			*cmdp = cmd;
    640  1.114.6.2  mjf 		}
    641  1.114.6.5  mjf 		else if (result == CMD_PREFIX) {
    642  1.114.6.2  mjf 			result = CMD_AMBIGUOUS;
    643  1.114.6.2  mjf 			*cmdp = NULL;
    644  1.114.6.2  mjf 		}
    645  1.114.6.2  mjf 	}
    646  1.114.6.2  mjf 
    647  1.114.6.2  mjf 	return (result);
    648  1.114.6.2  mjf }
    649  1.114.6.2  mjf 
    650  1.114.6.5  mjf 
    651  1.114.6.2  mjf /*
    652  1.114.6.5  mjf  * Search list of command tables for command
    653  1.114.6.5  mjf  */
    654  1.114.6.5  mjf static int
    655  1.114.6.5  mjf db_cmd_search(const char *name,
    656  1.114.6.5  mjf 	      struct db_cmd_tbl_en_head *list_head,
    657  1.114.6.5  mjf 	      const struct db_command **cmdp)
    658  1.114.6.5  mjf {
    659  1.114.6.5  mjf 	struct db_cmd_tbl_en *list_ent;
    660  1.114.6.5  mjf 	const struct db_command *found_command;
    661  1.114.6.5  mjf 	bool accept_prefix_match;
    662  1.114.6.5  mjf 	int result;
    663  1.114.6.5  mjf 
    664  1.114.6.5  mjf 	result = CMD_NONE;
    665  1.114.6.5  mjf 	found_command = NULL;
    666  1.114.6.5  mjf 	accept_prefix_match = true;
    667  1.114.6.5  mjf 
    668  1.114.6.5  mjf 	TAILQ_FOREACH(list_ent, list_head, db_cmd_next) {
    669  1.114.6.5  mjf 		const struct db_command *cmd;
    670  1.114.6.5  mjf 		int found;
    671  1.114.6.5  mjf 
    672  1.114.6.5  mjf 		found = db_cmd_search_table(name, list_ent->db_cmd, &cmd);
    673  1.114.6.5  mjf 		if (found == CMD_EXACT) {
    674  1.114.6.5  mjf 			result = CMD_EXACT;
    675  1.114.6.5  mjf 			found_command = cmd;
    676  1.114.6.5  mjf 			break;
    677  1.114.6.5  mjf 		}
    678  1.114.6.5  mjf 
    679  1.114.6.5  mjf 		if (found == CMD_PREFIX) {
    680  1.114.6.5  mjf 			if (accept_prefix_match) {
    681  1.114.6.5  mjf 				/*
    682  1.114.6.5  mjf 				 * Continue search, but note current result
    683  1.114.6.5  mjf 				 * in case we won't find anything else.
    684  1.114.6.5  mjf 				 */
    685  1.114.6.5  mjf 				accept_prefix_match = false;
    686  1.114.6.5  mjf 				result = CMD_PREFIX;
    687  1.114.6.5  mjf 				found_command = cmd;
    688  1.114.6.5  mjf 			} else {
    689  1.114.6.5  mjf 				/*
    690  1.114.6.5  mjf 				 * Watch out for globally ambiguous
    691  1.114.6.5  mjf 				 * prefix match that is not locally
    692  1.114.6.5  mjf 				 * ambiguous - with one match in one
    693  1.114.6.5  mjf 				 * table and another match(es) in
    694  1.114.6.5  mjf 				 * another table.
    695  1.114.6.5  mjf 				 */
    696  1.114.6.5  mjf 				result = CMD_AMBIGUOUS;
    697  1.114.6.5  mjf 				found_command = NULL;
    698  1.114.6.5  mjf 			}
    699  1.114.6.5  mjf 		}
    700  1.114.6.5  mjf 		else if (found == CMD_AMBIGUOUS) {
    701  1.114.6.5  mjf 			accept_prefix_match = false;
    702  1.114.6.5  mjf 			result = CMD_AMBIGUOUS;
    703  1.114.6.5  mjf 			found_command = NULL;
    704  1.114.6.5  mjf 		}
    705  1.114.6.5  mjf 	}
    706  1.114.6.5  mjf 
    707  1.114.6.5  mjf 	*cmdp = found_command;
    708  1.114.6.5  mjf 	return result;
    709  1.114.6.5  mjf }
    710  1.114.6.5  mjf 
    711  1.114.6.5  mjf static void
    712  1.114.6.5  mjf db_cmd_search_failed(char *name, int search_result)
    713  1.114.6.5  mjf {
    714  1.114.6.5  mjf 	if (search_result == CMD_NONE)
    715  1.114.6.5  mjf 		db_printf("No such command: %s\n", name);
    716  1.114.6.5  mjf 	else
    717  1.114.6.5  mjf 		db_printf("Ambiguous command: %s\n", name);
    718  1.114.6.5  mjf }
    719  1.114.6.5  mjf 
    720  1.114.6.5  mjf 
    721  1.114.6.5  mjf /*
    722  1.114.6.5  mjf  * List commands to the console.
    723  1.114.6.2  mjf  */
    724  1.114.6.2  mjf static void
    725  1.114.6.2  mjf db_cmd_list(const struct db_cmd_tbl_en_head *list)
    726  1.114.6.2  mjf {
    727  1.114.6.2  mjf 
    728  1.114.6.2  mjf 	struct db_cmd_tbl_en *list_ent;
    729  1.114.6.2  mjf 	const struct db_command *table;
    730  1.114.6.2  mjf 	size_t		i, j, w, columns, lines, numcmds, width=0;
    731  1.114.6.2  mjf 	const char	*p;
    732  1.114.6.2  mjf 
    733  1.114.6.2  mjf 	TAILQ_FOREACH(list_ent,list,db_cmd_next) {
    734  1.114.6.2  mjf 		table = list_ent->db_cmd;
    735  1.114.6.2  mjf 		for (i = 0; table[i].name != NULL; i++) {
    736  1.114.6.2  mjf 			w = strlen(table[i].name);
    737  1.114.6.2  mjf 			if (w > width)
    738  1.114.6.2  mjf 				width = w;
    739  1.114.6.2  mjf 		}
    740  1.114.6.2  mjf 	}
    741  1.114.6.2  mjf 
    742  1.114.6.2  mjf 	width = DB_NEXT_TAB(width);
    743  1.114.6.2  mjf 
    744  1.114.6.2  mjf 	columns = db_max_width / width;
    745  1.114.6.2  mjf 	if (columns == 0)
    746  1.114.6.2  mjf 		columns = 1;
    747  1.114.6.2  mjf 
    748  1.114.6.2  mjf 	TAILQ_FOREACH(list_ent,list,db_cmd_next) {
    749  1.114.6.2  mjf 		table = list_ent->db_cmd;
    750  1.114.6.2  mjf 
    751  1.114.6.2  mjf 		for (numcmds = 0; table[numcmds].name != NULL; numcmds++)
    752  1.114.6.2  mjf 			;
    753  1.114.6.2  mjf 		lines = (numcmds + columns - 1) / columns;
    754  1.114.6.3  mjf 
    755  1.114.6.2  mjf 		for (i = 0; i < lines; i++) {
    756  1.114.6.2  mjf 			for (j = 0; j < columns; j++) {
    757  1.114.6.2  mjf 				p = table[j * lines + i].name;
    758  1.114.6.2  mjf 				if (p)
    759  1.114.6.2  mjf 					db_printf("%s", p);
    760  1.114.6.2  mjf 				if (j * lines + i + lines >= numcmds) {
    761  1.114.6.2  mjf 					db_putchar('\n');
    762  1.114.6.2  mjf 					break;
    763  1.114.6.2  mjf 				}
    764  1.114.6.2  mjf 				if (p) {
    765  1.114.6.2  mjf 					w = strlen(p);
    766  1.114.6.2  mjf 					while (w < width) {
    767  1.114.6.2  mjf 						w = DB_NEXT_TAB(w);
    768  1.114.6.2  mjf 						db_putchar('\t');
    769  1.114.6.2  mjf 					}
    770  1.114.6.2  mjf 				}
    771  1.114.6.2  mjf 			}
    772  1.114.6.2  mjf 		}
    773  1.114.6.2  mjf 	}
    774  1.114.6.2  mjf 	return;
    775  1.114.6.2  mjf }
    776  1.114.6.2  mjf 
    777  1.114.6.2  mjf /*
    778  1.114.6.5  mjf  * Read complete command with all subcommands, starting with current
    779  1.114.6.5  mjf  * db_tok_string. If subcommand is missing, print the list of all
    780  1.114.6.5  mjf  * subcommands.  If command/subcommand is not found, print an error
    781  1.114.6.5  mjf  * message.  Returns pointer to "leaf" command or NULL.
    782  1.114.6.2  mjf  */
    783  1.114.6.5  mjf static const struct db_command *
    784  1.114.6.5  mjf db_read_command(void)
    785  1.114.6.2  mjf {
    786  1.114.6.5  mjf 	const struct db_command *command;
    787  1.114.6.5  mjf 	struct db_cmd_tbl_en_head *list;
    788  1.114.6.5  mjf 	int found;
    789  1.114.6.5  mjf 	int t;
    790  1.114.6.2  mjf 
    791  1.114.6.5  mjf 	list = &db_base_cmd_list;
    792  1.114.6.5  mjf 	do {
    793  1.114.6.5  mjf 		found = db_cmd_search(db_tok_string, list, &command);
    794  1.114.6.5  mjf 		if (command == NULL) {
    795  1.114.6.5  mjf 			db_cmd_search_failed(db_tok_string, found);
    796  1.114.6.5  mjf 			db_flush_lex();
    797  1.114.6.5  mjf 			return NULL;
    798  1.114.6.5  mjf 		}
    799  1.114.6.2  mjf 
    800  1.114.6.5  mjf 		if (command->flag == CS_SHOW)
    801  1.114.6.5  mjf 			list = &db_show_cmd_list;
    802  1.114.6.5  mjf 		else if (command->flag == CS_MACH)
    803  1.114.6.5  mjf 			list = &db_mach_cmd_list;
    804  1.114.6.5  mjf 		else if (command->flag == CS_COMPAT)
    805  1.114.6.5  mjf 			/* same list */;
    806  1.114.6.5  mjf 		else
    807  1.114.6.5  mjf 			break; /* expect no more subcommands */
    808  1.114.6.2  mjf 
    809  1.114.6.5  mjf 		t = db_read_token(); /* read subcommand */
    810  1.114.6.5  mjf 		if (t != tIDENT) {
    811  1.114.6.5  mjf 			/* if none given - just print all of them */
    812  1.114.6.5  mjf 			db_cmd_list(list);
    813  1.114.6.5  mjf 			db_flush_lex();
    814  1.114.6.5  mjf 			return NULL;
    815  1.114.6.2  mjf 		}
    816  1.114.6.5  mjf 	} while (list != NULL);
    817  1.114.6.2  mjf 
    818  1.114.6.5  mjf 	return command;
    819  1.114.6.2  mjf }
    820  1.114.6.2  mjf 
    821  1.114.6.2  mjf /*
    822  1.114.6.5  mjf  * Parse command line and execute apropriate function.
    823  1.114.6.2  mjf  */
    824  1.114.6.2  mjf static void
    825  1.114.6.2  mjf db_command(const struct db_command **last_cmdp)
    826  1.114.6.2  mjf {
    827  1.114.6.2  mjf 	const struct db_command *command;
    828  1.114.6.5  mjf 	static db_expr_t last_count;
    829  1.114.6.2  mjf 	db_expr_t	addr, count;
    830  1.114.6.5  mjf 	char		modif[TOK_STRING_SIZE];
    831  1.114.6.5  mjf 
    832  1.114.6.5  mjf 	int			t;
    833  1.114.6.2  mjf 	bool		have_addr = false;
    834  1.114.6.2  mjf 
    835  1.114.6.5  mjf 	command = NULL;
    836  1.114.6.5  mjf 	last_count = 0;
    837  1.114.6.5  mjf 
    838  1.114.6.2  mjf 	t = db_read_token();
    839  1.114.6.2  mjf 	if ((t == tEOL) || (t == tCOMMA)) {
    840  1.114.6.2  mjf 		/*
    841  1.114.6.2  mjf 		 * An empty line repeats last command, at 'next'.
    842  1.114.6.2  mjf 		 * Only a count repeats the last command with the new count.
    843  1.114.6.2  mjf 		 */
    844  1.114.6.2  mjf 		command = *last_cmdp;
    845  1.114.6.2  mjf 
    846  1.114.6.2  mjf 		if (!command)
    847  1.114.6.2  mjf 			return;
    848  1.114.6.2  mjf 
    849  1.114.6.2  mjf 		addr = (db_expr_t)db_next;
    850  1.114.6.2  mjf 		if (t == tCOMMA) {
    851  1.114.6.2  mjf 			if (!db_expression(&count)) {
    852  1.114.6.2  mjf 				db_printf("Count missing\n");
    853  1.114.6.2  mjf 				db_flush_lex();
    854  1.114.6.2  mjf 				return;
    855  1.114.6.2  mjf 			}
    856  1.114.6.2  mjf 		} else
    857  1.114.6.2  mjf 			count = last_count;
    858  1.114.6.2  mjf 		have_addr = false;
    859  1.114.6.2  mjf 		modif[0] = '\0';
    860  1.114.6.2  mjf 		db_skip_to_eol();
    861  1.114.6.2  mjf 
    862  1.114.6.2  mjf 	} else if (t == tEXCL) {
    863  1.114.6.2  mjf 		db_fncall(0, 0, 0, NULL);
    864  1.114.6.2  mjf 		return;
    865  1.114.6.2  mjf 
    866  1.114.6.2  mjf 	} else if (t != tIDENT) {
    867  1.114.6.2  mjf 		db_printf("?\n");
    868  1.114.6.2  mjf 		db_flush_lex();
    869  1.114.6.2  mjf 		return;
    870  1.114.6.2  mjf 
    871  1.114.6.2  mjf 	} else {
    872  1.114.6.2  mjf 
    873  1.114.6.5  mjf 		command = db_read_command();
    874  1.114.6.5  mjf 		if (command == NULL)
    875  1.114.6.2  mjf 			return;
    876  1.114.6.2  mjf 
    877  1.114.6.2  mjf 		if ((command->flag & CS_OWN) == 0) {
    878  1.114.6.2  mjf 
    879  1.114.6.2  mjf 			/*
    880  1.114.6.2  mjf 			 * Standard syntax:
    881  1.114.6.2  mjf 			 * command [/modifier] [addr] [,count]
    882  1.114.6.2  mjf 			 */
    883  1.114.6.2  mjf 			t = db_read_token(); /* get modifier */
    884  1.114.6.3  mjf 			if (t == tSLASH) {
    885  1.114.6.2  mjf 				t = db_read_token();
    886  1.114.6.2  mjf 				if (t != tIDENT) {
    887  1.114.6.2  mjf 					db_printf("Bad modifier\n");
    888  1.114.6.2  mjf 					db_flush_lex();
    889  1.114.6.2  mjf 					return;
    890  1.114.6.2  mjf 				}
    891  1.114.6.2  mjf 				/* save modifier */
    892  1.114.6.2  mjf 				strlcpy(modif, db_tok_string, sizeof(modif));
    893  1.114.6.3  mjf 
    894  1.114.6.2  mjf 			} else {
    895  1.114.6.2  mjf 				db_unread_token(t);
    896  1.114.6.2  mjf 				modif[0] = '\0';
    897  1.114.6.2  mjf 			}
    898  1.114.6.2  mjf 
    899  1.114.6.2  mjf 			if (db_expression(&addr)) { /*get address*/
    900  1.114.6.2  mjf 				db_dot = (db_addr_t) addr;
    901  1.114.6.2  mjf 				db_last_addr = db_dot;
    902  1.114.6.2  mjf 				have_addr = true;
    903  1.114.6.2  mjf 			} else {
    904  1.114.6.2  mjf 				addr = (db_expr_t) db_dot;
    905  1.114.6.2  mjf 				have_addr = false;
    906  1.114.6.2  mjf 			}
    907  1.114.6.2  mjf 
    908  1.114.6.2  mjf 			t = db_read_token();
    909  1.114.6.2  mjf 			if (t == tCOMMA) { /*Get count*/
    910  1.114.6.2  mjf 				if (!db_expression(&count)) {
    911  1.114.6.2  mjf 					db_printf("Count missing\n");
    912  1.114.6.2  mjf 					db_flush_lex();
    913  1.114.6.2  mjf 					return;
    914  1.114.6.2  mjf 				}
    915  1.114.6.3  mjf 			} else {
    916  1.114.6.2  mjf 				db_unread_token(t);
    917  1.114.6.2  mjf 				count = -1;
    918  1.114.6.2  mjf 			}
    919  1.114.6.2  mjf 			if ((command->flag & CS_MORE) == 0) {
    920  1.114.6.2  mjf 				db_skip_to_eol();
    921  1.114.6.2  mjf 			}
    922  1.114.6.2  mjf 		}
    923  1.114.6.2  mjf 	}
    924  1.114.6.2  mjf 
    925  1.114.6.5  mjf 	if (command != NULL && command->flag & CS_NOREPEAT) {
    926  1.114.6.2  mjf 		*last_cmdp = NULL;
    927  1.114.6.2  mjf 		last_count = 0;
    928  1.114.6.2  mjf 	} else {
    929  1.114.6.2  mjf 		*last_cmdp = command;
    930  1.114.6.2  mjf 		last_count = count;
    931  1.114.6.2  mjf 	}
    932  1.114.6.2  mjf 
    933  1.114.6.5  mjf 
    934  1.114.6.2  mjf 	if (command != NULL) {
    935  1.114.6.2  mjf 		/*
    936  1.114.6.2  mjf 		 * Execute the command.
    937  1.114.6.2  mjf 		 */
    938  1.114.6.2  mjf 		if (command->fcn != NULL)
    939  1.114.6.2  mjf 			(*command->fcn)(addr, have_addr, count, modif);
    940  1.114.6.2  mjf 
    941  1.114.6.2  mjf 		if (command->flag & CS_SET_DOT) {
    942  1.114.6.2  mjf 			/*
    943  1.114.6.2  mjf 			 * If command changes dot, set dot to
    944  1.114.6.2  mjf 			 * previous address displayed (if 'ed' style).
    945  1.114.6.2  mjf 			 */
    946  1.114.6.2  mjf 			if (db_ed_style)
    947  1.114.6.2  mjf 				db_dot = db_prev;
    948  1.114.6.2  mjf 			else
    949  1.114.6.2  mjf 				db_dot = db_next;
    950  1.114.6.2  mjf 		} else {
    951  1.114.6.2  mjf 			/*
    952  1.114.6.2  mjf 			 * If command does not change dot,
    953  1.114.6.2  mjf 			 * set 'next' location to be the same.
    954  1.114.6.2  mjf 			 */
    955  1.114.6.2  mjf 			db_next = db_dot;
    956  1.114.6.2  mjf 		}
    957  1.114.6.2  mjf 	}
    958  1.114.6.2  mjf }
    959  1.114.6.2  mjf 
    960  1.114.6.2  mjf /*
    961  1.114.6.2  mjf  * Print help for commands
    962  1.114.6.2  mjf  */
    963  1.114.6.2  mjf static void
    964  1.114.6.2  mjf db_help_print_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
    965  1.114.6.5  mjf const char *modif)
    966  1.114.6.2  mjf {
    967  1.114.6.5  mjf 	const struct db_command *command;
    968  1.114.6.5  mjf 	int t;
    969  1.114.6.3  mjf 
    970  1.114.6.2  mjf 	t = db_read_token();
    971  1.114.6.3  mjf 
    972  1.114.6.5  mjf 	/* is there another command after the "help"? */
    973  1.114.6.5  mjf 	if (t != tIDENT) {
    974  1.114.6.5  mjf 		/* print base commands */
    975  1.114.6.5  mjf 		db_cmd_list(&db_base_cmd_list);
    976  1.114.6.5  mjf 		return;
    977  1.114.6.5  mjf 	}
    978  1.114.6.2  mjf 
    979  1.114.6.5  mjf 	command = db_read_command();
    980  1.114.6.5  mjf 	if (command == NULL)
    981  1.114.6.5  mjf 		return;
    982  1.114.6.2  mjf 
    983  1.114.6.2  mjf #ifdef DDB_VERBOSE_HELP
    984  1.114.6.5  mjf 	db_printf("Command: %s\n", command->name);
    985  1.114.6.5  mjf 	if (command->cmd_descr != NULL)
    986  1.114.6.5  mjf 		db_printf(" Description: %s\n", command->cmd_descr);
    987  1.114.6.5  mjf 	if (command->cmd_arg != NULL)
    988  1.114.6.5  mjf 		db_printf(" Arguments: %s\n", command->cmd_arg);
    989  1.114.6.5  mjf 	if (command->cmd_arg_help != NULL)
    990  1.114.6.5  mjf 		db_printf(" Arguments description:\n%s\n",
    991  1.114.6.5  mjf 			  command->cmd_arg_help);
    992  1.114.6.5  mjf 	if ((command->cmd_arg == NULL) && (command->cmd_descr == NULL))
    993  1.114.6.5  mjf 		db_printf(" No help message.\n");
    994  1.114.6.2  mjf #endif
    995  1.114.6.2  mjf 
    996  1.114.6.5  mjf 	db_skip_to_eol();
    997  1.114.6.2  mjf }
    998  1.114.6.2  mjf 
    999  1.114.6.2  mjf /*ARGSUSED*/
   1000  1.114.6.2  mjf static void
   1001  1.114.6.2  mjf db_map_print_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
   1002  1.114.6.2  mjf     const char *modif)
   1003  1.114.6.2  mjf {
   1004  1.114.6.2  mjf 	bool full = false;
   1005  1.114.6.2  mjf 
   1006  1.114.6.2  mjf 	if (modif[0] == 'f')
   1007  1.114.6.2  mjf 		full = true;
   1008  1.114.6.2  mjf 
   1009  1.114.6.2  mjf 	if (have_addr == false)
   1010  1.114.6.4  mjf 		addr = (db_expr_t)(uintptr_t) kernel_map;
   1011  1.114.6.2  mjf 
   1012  1.114.6.4  mjf 	uvm_map_printit((struct vm_map *)(uintptr_t) addr, full, db_printf);
   1013  1.114.6.2  mjf }
   1014  1.114.6.2  mjf 
   1015  1.114.6.2  mjf /*ARGSUSED*/
   1016  1.114.6.2  mjf static void
   1017  1.114.6.2  mjf db_malloc_print_cmd(db_expr_t addr, bool have_addr,
   1018  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1019  1.114.6.2  mjf {
   1020  1.114.6.2  mjf 
   1021  1.114.6.2  mjf #ifdef MALLOC_DEBUG
   1022  1.114.6.2  mjf 	if (!have_addr)
   1023  1.114.6.2  mjf 		addr = 0;
   1024  1.114.6.2  mjf 
   1025  1.114.6.2  mjf 	debug_malloc_printit(db_printf, (vaddr_t) addr);
   1026  1.114.6.2  mjf #else
   1027  1.114.6.2  mjf 	db_printf("The kernel is not built with the MALLOC_DEBUG option.\n");
   1028  1.114.6.2  mjf #endif /* MALLOC_DEBUG */
   1029  1.114.6.2  mjf }
   1030  1.114.6.2  mjf 
   1031  1.114.6.2  mjf /*ARGSUSED*/
   1032  1.114.6.2  mjf static void
   1033  1.114.6.2  mjf db_object_print_cmd(db_expr_t addr, bool have_addr,
   1034  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1035  1.114.6.2  mjf {
   1036  1.114.6.2  mjf 	bool full = false;
   1037  1.114.6.2  mjf 
   1038  1.114.6.2  mjf 	if (modif[0] == 'f')
   1039  1.114.6.2  mjf 		full = true;
   1040  1.114.6.2  mjf 
   1041  1.114.6.4  mjf 	uvm_object_printit((struct uvm_object *)(uintptr_t) addr, full,
   1042  1.114.6.2  mjf 	    db_printf);
   1043  1.114.6.2  mjf }
   1044  1.114.6.2  mjf 
   1045  1.114.6.2  mjf /*ARGSUSED*/
   1046  1.114.6.2  mjf static void
   1047  1.114.6.2  mjf db_page_print_cmd(db_expr_t addr, bool have_addr,
   1048  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1049  1.114.6.2  mjf {
   1050  1.114.6.2  mjf 	bool full = false;
   1051  1.114.6.2  mjf 
   1052  1.114.6.2  mjf 	if (modif[0] == 'f')
   1053  1.114.6.2  mjf 		full = true;
   1054  1.114.6.2  mjf 
   1055  1.114.6.4  mjf 	uvm_page_printit((struct vm_page *)(uintptr_t) addr, full, db_printf);
   1056  1.114.6.2  mjf }
   1057  1.114.6.2  mjf 
   1058  1.114.6.2  mjf /*ARGSUSED*/
   1059  1.114.6.2  mjf static void
   1060  1.114.6.2  mjf db_show_all_pages(db_expr_t addr, bool have_addr,
   1061  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1062  1.114.6.2  mjf {
   1063  1.114.6.2  mjf 
   1064  1.114.6.2  mjf 	uvm_page_printall(db_printf);
   1065  1.114.6.2  mjf }
   1066  1.114.6.2  mjf 
   1067  1.114.6.2  mjf /*ARGSUSED*/
   1068  1.114.6.2  mjf static void
   1069  1.114.6.2  mjf db_buf_print_cmd(db_expr_t addr, bool have_addr,
   1070  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1071  1.114.6.2  mjf {
   1072  1.114.6.2  mjf 	bool full = false;
   1073  1.114.6.2  mjf 
   1074  1.114.6.2  mjf 	if (modif[0] == 'f')
   1075  1.114.6.2  mjf 		full = true;
   1076  1.114.6.2  mjf 
   1077  1.114.6.4  mjf 	vfs_buf_print((struct buf *)(uintptr_t) addr, full, db_printf);
   1078  1.114.6.2  mjf }
   1079  1.114.6.2  mjf 
   1080  1.114.6.2  mjf /*ARGSUSED*/
   1081  1.114.6.2  mjf static void
   1082  1.114.6.2  mjf db_event_print_cmd(db_expr_t addr, bool have_addr,
   1083  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1084  1.114.6.2  mjf {
   1085  1.114.6.2  mjf 	bool full = false;
   1086  1.114.6.2  mjf 
   1087  1.114.6.2  mjf 	if (modif[0] == 'f')
   1088  1.114.6.2  mjf 		full = true;
   1089  1.114.6.2  mjf 
   1090  1.114.6.2  mjf 	event_print(full, db_printf);
   1091  1.114.6.2  mjf }
   1092  1.114.6.2  mjf 
   1093  1.114.6.2  mjf /*ARGSUSED*/
   1094  1.114.6.2  mjf static void
   1095  1.114.6.2  mjf db_vnode_print_cmd(db_expr_t addr, bool have_addr,
   1096  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1097  1.114.6.2  mjf {
   1098  1.114.6.2  mjf 	bool full = false;
   1099  1.114.6.2  mjf 
   1100  1.114.6.2  mjf 	if (modif[0] == 'f')
   1101  1.114.6.2  mjf 		full = true;
   1102  1.114.6.2  mjf 
   1103  1.114.6.4  mjf 	vfs_vnode_print((struct vnode *)(uintptr_t) addr, full, db_printf);
   1104  1.114.6.2  mjf }
   1105  1.114.6.2  mjf 
   1106  1.114.6.5  mjf /*ARGSUSED*/
   1107  1.114.6.5  mjf static void
   1108  1.114.6.5  mjf db_vmem_print_cmd(db_expr_t addr, bool have_addr,
   1109  1.114.6.5  mjf     db_expr_t count, const char *modif)
   1110  1.114.6.5  mjf {
   1111  1.114.6.5  mjf 	vmem_print((uintptr_t) addr, modif, db_printf);
   1112  1.114.6.5  mjf }
   1113  1.114.6.5  mjf 
   1114  1.114.6.5  mjf /*ARGSUSED*/
   1115  1.114.6.5  mjf static void
   1116  1.114.6.5  mjf db_show_all_vmems(db_expr_t addr, bool have_addr,
   1117  1.114.6.5  mjf     db_expr_t count, const char *modif)
   1118  1.114.6.5  mjf {
   1119  1.114.6.5  mjf 	vmem_print((uintptr_t)addr, "a", db_printf);
   1120  1.114.6.5  mjf }
   1121  1.114.6.5  mjf 
   1122  1.114.6.2  mjf static void
   1123  1.114.6.2  mjf db_mount_print_cmd(db_expr_t addr, bool have_addr,
   1124  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1125  1.114.6.2  mjf {
   1126  1.114.6.2  mjf 	bool full = false;
   1127  1.114.6.2  mjf 
   1128  1.114.6.2  mjf 	if (modif[0] == 'f')
   1129  1.114.6.2  mjf 		full = true;
   1130  1.114.6.2  mjf 
   1131  1.114.6.4  mjf 	vfs_mount_print((struct mount *)(uintptr_t) addr, full, db_printf);
   1132  1.114.6.2  mjf }
   1133  1.114.6.2  mjf 
   1134  1.114.6.2  mjf /*ARGSUSED*/
   1135  1.114.6.2  mjf static void
   1136  1.114.6.2  mjf db_mbuf_print_cmd(db_expr_t addr, bool have_addr,
   1137  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1138  1.114.6.2  mjf {
   1139  1.114.6.2  mjf 
   1140  1.114.6.4  mjf 	m_print((const struct mbuf *)(uintptr_t) addr, modif, db_printf);
   1141  1.114.6.2  mjf }
   1142  1.114.6.2  mjf 
   1143  1.114.6.2  mjf /*ARGSUSED*/
   1144  1.114.6.2  mjf static void
   1145  1.114.6.2  mjf db_pool_print_cmd(db_expr_t addr, bool have_addr,
   1146  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1147  1.114.6.2  mjf {
   1148  1.114.6.2  mjf 
   1149  1.114.6.4  mjf 	pool_printit((struct pool *)(uintptr_t) addr, modif, db_printf);
   1150  1.114.6.2  mjf }
   1151  1.114.6.2  mjf 
   1152  1.114.6.2  mjf /*ARGSUSED*/
   1153  1.114.6.2  mjf static void
   1154  1.114.6.2  mjf db_namecache_print_cmd(db_expr_t addr, bool have_addr,
   1155  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1156  1.114.6.2  mjf {
   1157  1.114.6.2  mjf 
   1158  1.114.6.4  mjf 	namecache_print((struct vnode *)(uintptr_t) addr, db_printf);
   1159  1.114.6.2  mjf }
   1160  1.114.6.2  mjf 
   1161  1.114.6.2  mjf /*ARGSUSED*/
   1162  1.114.6.2  mjf static void
   1163  1.114.6.2  mjf db_uvmexp_print_cmd(db_expr_t addr, bool have_addr,
   1164  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1165  1.114.6.2  mjf {
   1166  1.114.6.2  mjf 
   1167  1.114.6.2  mjf 	uvmexp_print(db_printf);
   1168  1.114.6.2  mjf }
   1169  1.114.6.2  mjf 
   1170  1.114.6.3  mjf #ifdef UVMHIST
   1171  1.114.6.3  mjf /*ARGSUSED*/
   1172  1.114.6.3  mjf static void
   1173  1.114.6.3  mjf db_uvmhist_print_cmd(db_expr_t addr, bool have_addr,
   1174  1.114.6.3  mjf     db_expr_t count, const char *modif)
   1175  1.114.6.3  mjf {
   1176  1.114.6.3  mjf 
   1177  1.114.6.3  mjf 	uvmhist_print(db_printf);
   1178  1.114.6.3  mjf }
   1179  1.114.6.3  mjf #endif
   1180  1.114.6.3  mjf 
   1181  1.114.6.2  mjf /*ARGSUSED*/
   1182  1.114.6.2  mjf static void
   1183  1.114.6.2  mjf db_lock_print_cmd(db_expr_t addr, bool have_addr,
   1184  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1185  1.114.6.2  mjf {
   1186  1.114.6.2  mjf 
   1187  1.114.6.5  mjf 	lockdebug_lock_print((void *)(uintptr_t)addr, db_printf);
   1188  1.114.6.2  mjf }
   1189  1.114.6.2  mjf 
   1190  1.114.6.2  mjf /*
   1191  1.114.6.2  mjf  * Call random function:
   1192  1.114.6.2  mjf  * !expr(arg,arg,arg)
   1193  1.114.6.2  mjf  */
   1194  1.114.6.2  mjf /*ARGSUSED*/
   1195  1.114.6.2  mjf static void
   1196  1.114.6.2  mjf db_fncall(db_expr_t addr, bool have_addr,
   1197  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1198  1.114.6.2  mjf {
   1199  1.114.6.2  mjf 	db_expr_t	fn_addr;
   1200  1.114.6.2  mjf #define	MAXARGS		11
   1201  1.114.6.2  mjf 	db_expr_t	args[MAXARGS];
   1202  1.114.6.2  mjf 	int		nargs = 0;
   1203  1.114.6.2  mjf 	db_expr_t	retval;
   1204  1.114.6.2  mjf 	db_expr_t	(*func)(db_expr_t, ...);
   1205  1.114.6.2  mjf 	int		t;
   1206  1.114.6.2  mjf 
   1207  1.114.6.2  mjf 	if (!db_expression(&fn_addr)) {
   1208  1.114.6.2  mjf 		db_printf("Bad function\n");
   1209  1.114.6.2  mjf 		db_flush_lex();
   1210  1.114.6.2  mjf 		return;
   1211  1.114.6.2  mjf 	}
   1212  1.114.6.4  mjf 	func = (db_expr_t (*)(db_expr_t, ...))(uintptr_t) fn_addr;
   1213  1.114.6.2  mjf 
   1214  1.114.6.2  mjf 	t = db_read_token();
   1215  1.114.6.2  mjf 	if (t == tLPAREN) {
   1216  1.114.6.2  mjf 		if (db_expression(&args[0])) {
   1217  1.114.6.2  mjf 			nargs++;
   1218  1.114.6.2  mjf 			while ((t = db_read_token()) == tCOMMA) {
   1219  1.114.6.2  mjf 				if (nargs == MAXARGS) {
   1220  1.114.6.2  mjf 					db_printf("Too many arguments\n");
   1221  1.114.6.2  mjf 					db_flush_lex();
   1222  1.114.6.2  mjf 					return;
   1223  1.114.6.2  mjf 				}
   1224  1.114.6.2  mjf 				if (!db_expression(&args[nargs])) {
   1225  1.114.6.2  mjf 					db_printf("Argument missing\n");
   1226  1.114.6.2  mjf 					db_flush_lex();
   1227  1.114.6.2  mjf 					return;
   1228  1.114.6.2  mjf 				}
   1229  1.114.6.2  mjf 				nargs++;
   1230  1.114.6.2  mjf 			}
   1231  1.114.6.2  mjf 			db_unread_token(t);
   1232  1.114.6.2  mjf 		}
   1233  1.114.6.2  mjf 		if (db_read_token() != tRPAREN) {
   1234  1.114.6.2  mjf 			db_printf("?\n");
   1235  1.114.6.2  mjf 			db_flush_lex();
   1236  1.114.6.2  mjf 			return;
   1237  1.114.6.2  mjf 		}
   1238  1.114.6.2  mjf 	}
   1239  1.114.6.2  mjf 	db_skip_to_eol();
   1240  1.114.6.2  mjf 
   1241  1.114.6.2  mjf 	while (nargs < MAXARGS) {
   1242  1.114.6.2  mjf 		args[nargs++] = 0;
   1243  1.114.6.2  mjf 	}
   1244  1.114.6.2  mjf 
   1245  1.114.6.2  mjf 	retval = (*func)(args[0], args[1], args[2], args[3], args[4],
   1246  1.114.6.2  mjf 			 args[5], args[6], args[7], args[8], args[9]);
   1247  1.114.6.2  mjf 	db_printf("%s\n", db_num_to_str(retval));
   1248  1.114.6.2  mjf }
   1249  1.114.6.2  mjf 
   1250  1.114.6.2  mjf static void
   1251  1.114.6.2  mjf db_reboot_cmd(db_expr_t addr, bool have_addr,
   1252  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1253  1.114.6.2  mjf {
   1254  1.114.6.2  mjf 	db_expr_t bootflags;
   1255  1.114.6.2  mjf 
   1256  1.114.6.2  mjf 	/* Flags, default to RB_AUTOBOOT */
   1257  1.114.6.2  mjf 	if (!db_expression(&bootflags))
   1258  1.114.6.2  mjf 		bootflags = (db_expr_t)RB_AUTOBOOT;
   1259  1.114.6.2  mjf 	if (db_read_token() != tEOL) {
   1260  1.114.6.2  mjf 		db_error("?\n");
   1261  1.114.6.2  mjf 		/*NOTREACHED*/
   1262  1.114.6.2  mjf 	}
   1263  1.114.6.2  mjf 	/*
   1264  1.114.6.2  mjf 	 * We are leaving DDB, never to return upward.
   1265  1.114.6.2  mjf 	 * Clear db_recover so that we can debug faults in functions
   1266  1.114.6.2  mjf 	 * called from cpu_reboot.
   1267  1.114.6.2  mjf 	 */
   1268  1.114.6.2  mjf 	db_recover = 0;
   1269  1.114.6.2  mjf 	cpu_reboot((int)bootflags, NULL);
   1270  1.114.6.2  mjf }
   1271  1.114.6.2  mjf 
   1272  1.114.6.2  mjf static void
   1273  1.114.6.2  mjf db_sifting_cmd(db_expr_t addr, bool have_addr,
   1274  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1275  1.114.6.2  mjf {
   1276  1.114.6.2  mjf 	int	mode, t;
   1277  1.114.6.2  mjf 
   1278  1.114.6.2  mjf 	t = db_read_token();
   1279  1.114.6.2  mjf 	if (t == tSLASH) {
   1280  1.114.6.2  mjf 		t = db_read_token();
   1281  1.114.6.2  mjf 		if (t != tIDENT) {
   1282  1.114.6.2  mjf 			bad_modifier:
   1283  1.114.6.2  mjf 			db_printf("Bad modifier\n");
   1284  1.114.6.2  mjf 			db_flush_lex();
   1285  1.114.6.2  mjf 			return;
   1286  1.114.6.2  mjf 		}
   1287  1.114.6.2  mjf 		if (!strcmp(db_tok_string, "F"))
   1288  1.114.6.2  mjf 			mode = 'F';
   1289  1.114.6.2  mjf 		else
   1290  1.114.6.2  mjf 			goto bad_modifier;
   1291  1.114.6.2  mjf 		t = db_read_token();
   1292  1.114.6.2  mjf 	} else
   1293  1.114.6.2  mjf 		mode = 0;
   1294  1.114.6.2  mjf 
   1295  1.114.6.2  mjf 	if (t == tIDENT)
   1296  1.114.6.2  mjf 		db_sifting(db_tok_string, mode);
   1297  1.114.6.2  mjf 	else {
   1298  1.114.6.2  mjf 		db_printf("Bad argument (non-string)\n");
   1299  1.114.6.2  mjf 		db_flush_lex();
   1300  1.114.6.2  mjf 	}
   1301  1.114.6.2  mjf }
   1302  1.114.6.2  mjf 
   1303  1.114.6.2  mjf static void
   1304  1.114.6.2  mjf db_stack_trace_cmd(db_expr_t addr, bool have_addr, db_expr_t count, const char *modif)
   1305  1.114.6.2  mjf {
   1306  1.114.6.2  mjf 	register const char *cp = modif;
   1307  1.114.6.2  mjf 	register char c;
   1308  1.114.6.2  mjf 	void (*pr)(const char *, ...);
   1309  1.114.6.2  mjf 
   1310  1.114.6.2  mjf 	pr = db_printf;
   1311  1.114.6.2  mjf 	while ((c = *cp++) != 0)
   1312  1.114.6.2  mjf 		if (c == 'l')
   1313  1.114.6.2  mjf 			pr = printf;
   1314  1.114.6.2  mjf 
   1315  1.114.6.2  mjf 	if (count == -1)
   1316  1.114.6.2  mjf 		count = 65535;
   1317  1.114.6.2  mjf 
   1318  1.114.6.2  mjf 	db_stack_trace_print(addr, have_addr, count, modif, pr);
   1319  1.114.6.2  mjf }
   1320  1.114.6.2  mjf 
   1321  1.114.6.2  mjf static void
   1322  1.114.6.2  mjf db_sync_cmd(db_expr_t addr, bool have_addr,
   1323  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1324  1.114.6.2  mjf {
   1325  1.114.6.2  mjf 
   1326  1.114.6.2  mjf 	/*
   1327  1.114.6.2  mjf 	 * We are leaving DDB, never to return upward.
   1328  1.114.6.2  mjf 	 * Clear db_recover so that we can debug faults in functions
   1329  1.114.6.2  mjf 	 * called from cpu_reboot.
   1330  1.114.6.2  mjf 	 */
   1331  1.114.6.2  mjf 	db_recover = 0;
   1332  1.114.6.2  mjf 	panicstr = "dump forced via kernel debugger";
   1333  1.114.6.2  mjf 	cpu_reboot(RB_DUMP, NULL);
   1334  1.114.6.2  mjf }
   1335  1.114.6.2  mjf 
   1336  1.114.6.2  mjf /*
   1337  1.114.6.2  mjf  * Describe what an address is
   1338  1.114.6.2  mjf  */
   1339  1.114.6.2  mjf void
   1340  1.114.6.2  mjf db_whatis_cmd(db_expr_t address, bool have_addr,
   1341  1.114.6.2  mjf     db_expr_t count, const char *modif)
   1342  1.114.6.2  mjf {
   1343  1.114.6.2  mjf 	const uintptr_t addr = (uintptr_t)address;
   1344  1.114.6.2  mjf 
   1345  1.114.6.2  mjf 	lwp_whatis(addr, db_printf);
   1346  1.114.6.2  mjf 	pool_whatis(addr, db_printf);
   1347  1.114.6.2  mjf 	vmem_whatis(addr, db_printf);
   1348  1.114.6.2  mjf 	uvm_whatis(addr, db_printf);
   1349  1.114.6.5  mjf 	module_whatis(addr, db_printf);
   1350  1.114.6.2  mjf }
   1351