db_command.c revision 1.75 1 1.75 atatat /* $NetBSD: db_command.c,v 1.75 2004/03/24 15:34:52 atatat Exp $ */
2 1.12 cgd
3 1.64 simonb /*
4 1.1 cgd * Mach Operating System
5 1.1 cgd * Copyright (c) 1991,1990 Carnegie Mellon University
6 1.1 cgd * All Rights Reserved.
7 1.64 simonb *
8 1.1 cgd * Permission to use, copy, modify and distribute this software and its
9 1.1 cgd * documentation is hereby granted, provided that both the copyright
10 1.1 cgd * notice and this permission notice appear in all copies of the
11 1.1 cgd * software, derivative works or modified versions, and any portions
12 1.1 cgd * thereof, and that both notices appear in supporting documentation.
13 1.64 simonb *
14 1.30 pk * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 1.1 cgd * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 1.1 cgd * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 1.64 simonb *
18 1.1 cgd * Carnegie Mellon requests users of this software to return to
19 1.64 simonb *
20 1.1 cgd * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 1.1 cgd * School of Computer Science
22 1.1 cgd * Carnegie Mellon University
23 1.1 cgd * Pittsburgh PA 15213-3890
24 1.64 simonb *
25 1.1 cgd * any improvements or extensions that they make and grant Carnegie the
26 1.1 cgd * rights to redistribute these changes.
27 1.1 cgd */
28 1.25 mrg
29 1.63 lukem /*
30 1.63 lukem * Command dispatcher.
31 1.63 lukem */
32 1.63 lukem
33 1.63 lukem #include <sys/cdefs.h>
34 1.75 atatat __KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.75 2004/03/24 15:34:52 atatat Exp $");
35 1.63 lukem
36 1.27 tron #include "opt_ddb.h"
37 1.69 briggs #include "opt_kgdb.h"
38 1.40 jhawk #include "opt_inet.h"
39 1.5 mycroft
40 1.7 mycroft #include <sys/param.h>
41 1.18 christos #include <sys/systm.h>
42 1.23 scottr #include <sys/reboot.h>
43 1.65 simonb #include <sys/device.h>
44 1.65 simonb #include <sys/malloc.h>
45 1.65 simonb #include <sys/namei.h>
46 1.65 simonb #include <sys/pool.h>
47 1.7 mycroft #include <sys/proc.h>
48 1.36 chs #include <sys/vnode.h>
49 1.15 gwr
50 1.1 cgd #include <machine/db_machdep.h> /* type definitions */
51 1.1 cgd
52 1.58 mrg #if defined(_KERNEL_OPT)
53 1.34 sommerfe #include "opt_multiprocessor.h"
54 1.34 sommerfe #endif
55 1.34 sommerfe #ifdef MULTIPROCESSOR
56 1.34 sommerfe #include <machine/cpu.h>
57 1.34 sommerfe #endif
58 1.34 sommerfe
59 1.1 cgd #include <ddb/db_lex.h>
60 1.1 cgd #include <ddb/db_output.h>
61 1.10 pk #include <ddb/db_command.h>
62 1.16 christos #include <ddb/db_break.h>
63 1.16 christos #include <ddb/db_watch.h>
64 1.16 christos #include <ddb/db_run.h>
65 1.16 christos #include <ddb/db_variables.h>
66 1.16 christos #include <ddb/db_interface.h>
67 1.16 christos #include <ddb/db_sym.h>
68 1.16 christos #include <ddb/db_extern.h>
69 1.1 cgd
70 1.24 mrg #include <uvm/uvm_extern.h>
71 1.26 jonathan #include <uvm/uvm_ddb.h>
72 1.24 mrg
73 1.46 jhawk #include "arp.h"
74 1.46 jhawk
75 1.1 cgd /*
76 1.64 simonb * Results of command search.
77 1.64 simonb */
78 1.64 simonb #define CMD_UNIQUE 0
79 1.64 simonb #define CMD_FOUND 1
80 1.64 simonb #define CMD_NONE 2
81 1.64 simonb #define CMD_AMBIGUOUS 3
82 1.64 simonb #define CMD_HELP 4
83 1.64 simonb
84 1.64 simonb /*
85 1.1 cgd * Exported global variables
86 1.1 cgd */
87 1.1 cgd boolean_t db_cmd_loop_done;
88 1.17 gwr label_t *db_recover;
89 1.64 simonb db_addr_t db_dot;
90 1.64 simonb db_addr_t db_last_addr;
91 1.64 simonb db_addr_t db_prev;
92 1.64 simonb db_addr_t db_next;
93 1.1 cgd
94 1.1 cgd /*
95 1.1 cgd * if 'ed' style: 'dot' is set at start of last item printed,
96 1.1 cgd * and '+' points to next line.
97 1.1 cgd * Otherwise: 'dot' points to next item, '..' points to last.
98 1.1 cgd */
99 1.64 simonb static boolean_t db_ed_style = TRUE;
100 1.64 simonb
101 1.65 simonb static void db_buf_print_cmd(db_expr_t, int, db_expr_t, char *);
102 1.65 simonb static void db_cmd_list(const struct db_command *);
103 1.64 simonb static int db_cmd_search(const char *, const struct db_command *,
104 1.64 simonb const struct db_command **);
105 1.64 simonb static void db_command(const struct db_command **,
106 1.64 simonb const struct db_command *);
107 1.65 simonb static void db_event_print_cmd(db_expr_t, int, db_expr_t, char *);
108 1.65 simonb static void db_fncall(db_expr_t, int, db_expr_t, char *);
109 1.65 simonb static void db_malloc_print_cmd(db_expr_t, int, db_expr_t, char *);
110 1.64 simonb static void db_map_print_cmd(db_expr_t, int, db_expr_t, char *);
111 1.65 simonb static void db_namecache_print_cmd(db_expr_t, int, db_expr_t, char *);
112 1.64 simonb static void db_object_print_cmd(db_expr_t, int, db_expr_t, char *);
113 1.64 simonb static void db_page_print_cmd(db_expr_t, int, db_expr_t, char *);
114 1.64 simonb static void db_pool_print_cmd(db_expr_t, int, db_expr_t, char *);
115 1.64 simonb static void db_reboot_cmd(db_expr_t, int, db_expr_t, char *);
116 1.64 simonb static void db_sifting_cmd(db_expr_t, int, db_expr_t, char *);
117 1.64 simonb static void db_stack_trace_cmd(db_expr_t, int, db_expr_t, char *);
118 1.64 simonb static void db_sync_cmd(db_expr_t, int, db_expr_t, char *);
119 1.65 simonb static void db_uvmexp_print_cmd(db_expr_t, int, db_expr_t, char *);
120 1.65 simonb static void db_vnode_print_cmd(db_expr_t, int, db_expr_t, char *);
121 1.74 dbj static void db_mount_print_cmd(db_expr_t, int, db_expr_t, char *);
122 1.64 simonb
123 1.64 simonb /*
124 1.64 simonb * 'show' commands
125 1.64 simonb */
126 1.64 simonb
127 1.64 simonb static const struct db_command db_show_all_cmds[] = {
128 1.64 simonb { "callout", db_show_callout, 0, NULL },
129 1.64 simonb { "procs", db_show_all_procs, 0, NULL },
130 1.64 simonb { NULL, NULL, 0, NULL }
131 1.64 simonb };
132 1.64 simonb
133 1.64 simonb static const struct db_command db_show_cmds[] = {
134 1.64 simonb { "all", NULL, 0, db_show_all_cmds },
135 1.64 simonb #if defined(INET) && (NARP > 0)
136 1.64 simonb { "arptab", db_show_arptab, 0, NULL },
137 1.64 simonb #endif
138 1.64 simonb { "breaks", db_listbreak_cmd, 0, NULL },
139 1.64 simonb { "buf", db_buf_print_cmd, 0, NULL },
140 1.65 simonb { "event", db_event_print_cmd, 0, NULL },
141 1.65 simonb { "malloc", db_malloc_print_cmd, 0, NULL },
142 1.64 simonb { "map", db_map_print_cmd, 0, NULL },
143 1.74 dbj { "mount", db_mount_print_cmd, 0, NULL },
144 1.64 simonb { "ncache", db_namecache_print_cmd, 0, NULL },
145 1.64 simonb { "object", db_object_print_cmd, 0, NULL },
146 1.64 simonb { "page", db_page_print_cmd, 0, NULL },
147 1.64 simonb { "pool", db_pool_print_cmd, 0, NULL },
148 1.64 simonb { "registers", db_show_regs, 0, NULL },
149 1.72 thorpej { "sched_qs", db_show_sched_qs, 0, NULL },
150 1.64 simonb { "uvmexp", db_uvmexp_print_cmd, 0, NULL },
151 1.64 simonb { "vnode", db_vnode_print_cmd, 0, NULL },
152 1.64 simonb { "watches", db_listwatch_cmd, 0, NULL },
153 1.64 simonb { NULL, NULL, 0, NULL }
154 1.64 simonb };
155 1.64 simonb
156 1.64 simonb static const struct db_command db_command_table[] = {
157 1.73 chs { "b", db_breakpoint_cmd, 0, NULL },
158 1.64 simonb { "break", db_breakpoint_cmd, 0, NULL },
159 1.68 jmc { "bt", db_stack_trace_cmd, 0, NULL },
160 1.64 simonb { "c", db_continue_cmd, 0, NULL },
161 1.64 simonb { "call", db_fncall, CS_OWN, NULL },
162 1.64 simonb { "callout", db_show_callout, 0, NULL },
163 1.64 simonb { "continue", db_continue_cmd, 0, NULL },
164 1.64 simonb { "d", db_delete_cmd, 0, NULL },
165 1.64 simonb { "delete", db_delete_cmd, 0, NULL },
166 1.64 simonb { "dmesg", db_dmesg, 0, NULL },
167 1.64 simonb { "dwatch", db_deletewatch_cmd, 0, NULL },
168 1.64 simonb { "examine", db_examine_cmd, CS_SET_DOT, NULL },
169 1.75 atatat { "fg", db_continue_cmd, 0, NULL },
170 1.64 simonb { "kill", db_kill_proc, CS_OWN, NULL },
171 1.69 briggs #ifdef KGDB
172 1.69 briggs { "kgdb", db_kgdb_cmd, 0, NULL },
173 1.69 briggs #endif
174 1.64 simonb #ifdef DB_MACHINE_COMMANDS
175 1.64 simonb { "machine", NULL, 0, db_machine_command_table },
176 1.64 simonb #endif
177 1.64 simonb { "match", db_trace_until_matching_cmd,0, NULL },
178 1.64 simonb { "next", db_trace_until_matching_cmd,0, NULL },
179 1.64 simonb { "p", db_print_cmd, 0, NULL },
180 1.64 simonb { "print", db_print_cmd, 0, NULL },
181 1.64 simonb { "ps", db_show_all_procs, 0, NULL },
182 1.64 simonb { "reboot", db_reboot_cmd, CS_OWN, NULL },
183 1.64 simonb { "s", db_single_step_cmd, 0, NULL },
184 1.64 simonb { "search", db_search_cmd, CS_OWN|CS_SET_DOT, NULL },
185 1.64 simonb { "set", db_set_cmd, CS_OWN, NULL },
186 1.64 simonb { "show", NULL, 0, db_show_cmds },
187 1.64 simonb { "sifting", db_sifting_cmd, CS_OWN, NULL },
188 1.64 simonb { "step", db_single_step_cmd, 0, NULL },
189 1.64 simonb { "sync", db_sync_cmd, CS_OWN, NULL },
190 1.64 simonb { "trace", db_stack_trace_cmd, 0, NULL },
191 1.64 simonb { "until", db_trace_until_call_cmd,0, NULL },
192 1.64 simonb { "w", db_write_cmd, CS_MORE|CS_SET_DOT, NULL },
193 1.64 simonb { "watch", db_watchpoint_cmd, CS_MORE, NULL },
194 1.64 simonb { "write", db_write_cmd, CS_MORE|CS_SET_DOT, NULL },
195 1.64 simonb { "x", db_examine_cmd, CS_SET_DOT, NULL },
196 1.64 simonb { NULL, NULL, 0, NULL }
197 1.64 simonb };
198 1.64 simonb
199 1.64 simonb static const struct db_command *db_last_command = NULL;
200 1.1 cgd
201 1.1 cgd /*
202 1.1 cgd * Utility routine - discard tokens through end-of-line.
203 1.1 cgd */
204 1.1 cgd void
205 1.64 simonb db_skip_to_eol(void)
206 1.1 cgd {
207 1.64 simonb int t;
208 1.64 simonb
209 1.1 cgd do {
210 1.64 simonb t = db_read_token();
211 1.1 cgd } while (t != tEOL);
212 1.1 cgd }
213 1.1 cgd
214 1.64 simonb void
215 1.64 simonb db_error(s)
216 1.64 simonb char *s;
217 1.64 simonb {
218 1.64 simonb
219 1.64 simonb if (s)
220 1.64 simonb db_printf("%s", s);
221 1.64 simonb db_flush_lex();
222 1.64 simonb longjmp(db_recover);
223 1.64 simonb }
224 1.64 simonb
225 1.64 simonb void
226 1.64 simonb db_command_loop(void)
227 1.64 simonb {
228 1.64 simonb label_t db_jmpbuf;
229 1.64 simonb label_t *savejmp;
230 1.64 simonb
231 1.64 simonb /*
232 1.64 simonb * Initialize 'prev' and 'next' to dot.
233 1.64 simonb */
234 1.64 simonb db_prev = db_dot;
235 1.64 simonb db_next = db_dot;
236 1.64 simonb
237 1.64 simonb db_cmd_loop_done = 0;
238 1.64 simonb
239 1.64 simonb savejmp = db_recover;
240 1.64 simonb db_recover = &db_jmpbuf;
241 1.64 simonb (void) setjmp(&db_jmpbuf);
242 1.64 simonb
243 1.64 simonb while (!db_cmd_loop_done) {
244 1.64 simonb if (db_print_position() != 0)
245 1.64 simonb db_printf("\n");
246 1.64 simonb db_output_line = 0;
247 1.64 simonb
248 1.64 simonb
249 1.64 simonb #ifdef MULTIPROCESSOR
250 1.64 simonb db_printf("db{%ld}> ", (long)cpu_number());
251 1.64 simonb #else
252 1.64 simonb db_printf("db> ");
253 1.64 simonb #endif
254 1.64 simonb (void) db_read_line();
255 1.64 simonb
256 1.64 simonb db_command(&db_last_command, db_command_table);
257 1.64 simonb }
258 1.64 simonb
259 1.64 simonb db_recover = savejmp;
260 1.64 simonb }
261 1.1 cgd
262 1.1 cgd /*
263 1.1 cgd * Search for command prefix.
264 1.1 cgd */
265 1.64 simonb static int
266 1.64 simonb db_cmd_search(const char *name, const struct db_command *table,
267 1.64 simonb const struct db_command **cmdp)
268 1.1 cgd {
269 1.53 jdolecek const struct db_command *cmd;
270 1.10 pk int result = CMD_NONE;
271 1.1 cgd
272 1.1 cgd for (cmd = table; cmd->name != 0; cmd++) {
273 1.64 simonb const char *lp;
274 1.64 simonb const char *rp;
275 1.64 simonb int c;
276 1.64 simonb
277 1.64 simonb lp = name;
278 1.64 simonb rp = cmd->name;
279 1.64 simonb while ((c = *lp) == *rp) {
280 1.64 simonb if (c == 0) {
281 1.64 simonb /* complete match */
282 1.64 simonb *cmdp = cmd;
283 1.64 simonb return (CMD_UNIQUE);
284 1.64 simonb }
285 1.64 simonb lp++;
286 1.64 simonb rp++;
287 1.64 simonb }
288 1.1 cgd if (c == 0) {
289 1.64 simonb /* end of name, not end of command -
290 1.64 simonb partial match */
291 1.64 simonb if (result == CMD_FOUND) {
292 1.64 simonb result = CMD_AMBIGUOUS;
293 1.64 simonb /* but keep looking for a full match -
294 1.64 simonb this lets us match single letters */
295 1.64 simonb } else {
296 1.64 simonb *cmdp = cmd;
297 1.64 simonb result = CMD_FOUND;
298 1.64 simonb }
299 1.1 cgd }
300 1.1 cgd }
301 1.1 cgd if (result == CMD_NONE) {
302 1.64 simonb /* check for 'help' */
303 1.1 cgd if (name[0] == 'h' && name[1] == 'e'
304 1.1 cgd && name[2] == 'l' && name[3] == 'p')
305 1.1 cgd result = CMD_HELP;
306 1.1 cgd }
307 1.1 cgd return (result);
308 1.1 cgd }
309 1.1 cgd
310 1.64 simonb static void
311 1.64 simonb db_cmd_list(const struct db_command *table)
312 1.1 cgd {
313 1.67 simonb int i, j, w, columns, lines, width=0, numcmds;
314 1.53 jdolecek const char *p;
315 1.1 cgd
316 1.32 lukem for (numcmds = 0; table[numcmds].name != NULL; numcmds++) {
317 1.32 lukem w = strlen(table[numcmds].name);
318 1.32 lukem if (w > width)
319 1.32 lukem width = w;
320 1.32 lukem }
321 1.32 lukem width = DB_NEXT_TAB(width);
322 1.32 lukem
323 1.32 lukem columns = db_max_width / width;
324 1.32 lukem if (columns == 0)
325 1.32 lukem columns = 1;
326 1.32 lukem lines = (numcmds + columns - 1) / columns;
327 1.32 lukem for (i = 0; i < lines; i++) {
328 1.32 lukem for (j = 0; j < columns; j++) {
329 1.32 lukem p = table[j * lines + i].name;
330 1.32 lukem if (p)
331 1.32 lukem db_printf("%s", p);
332 1.32 lukem if (j * lines + i + lines >= numcmds) {
333 1.32 lukem db_putchar('\n');
334 1.32 lukem break;
335 1.32 lukem }
336 1.32 lukem w = strlen(p);
337 1.32 lukem while (w < width) {
338 1.32 lukem w = DB_NEXT_TAB(w);
339 1.32 lukem db_putchar('\t');
340 1.32 lukem }
341 1.32 lukem }
342 1.1 cgd }
343 1.1 cgd }
344 1.1 cgd
345 1.64 simonb static void
346 1.64 simonb db_command(const struct db_command **last_cmdp,
347 1.64 simonb const struct db_command *cmd_table)
348 1.1 cgd {
349 1.53 jdolecek const struct db_command *cmd;
350 1.1 cgd int t;
351 1.1 cgd char modif[TOK_STRING_SIZE];
352 1.1 cgd db_expr_t addr, count;
353 1.16 christos boolean_t have_addr = FALSE;
354 1.1 cgd int result;
355 1.1 cgd
356 1.64 simonb static db_expr_t last_count = 0;
357 1.38 jhawk
358 1.1 cgd t = db_read_token();
359 1.38 jhawk if ((t == tEOL) || (t == tCOMMA)) {
360 1.1 cgd /*
361 1.64 simonb * An empty line repeats last command, at 'next'.
362 1.64 simonb * Only a count repeats the last command with the new count.
363 1.64 simonb */
364 1.64 simonb cmd = *last_cmdp;
365 1.64 simonb addr = (db_expr_t)db_next;
366 1.64 simonb if (t == tCOMMA) {
367 1.64 simonb if (!db_expression(&count)) {
368 1.64 simonb db_printf("Count missing\n");
369 1.64 simonb db_flush_lex();
370 1.64 simonb return;
371 1.64 simonb }
372 1.64 simonb } else
373 1.64 simonb count = last_count;
374 1.64 simonb have_addr = FALSE;
375 1.64 simonb modif[0] = '\0';
376 1.64 simonb db_skip_to_eol();
377 1.64 simonb } else if (t == tEXCL) {
378 1.64 simonb db_fncall(0, 0, 0, NULL);
379 1.64 simonb return;
380 1.64 simonb } else if (t != tIDENT) {
381 1.64 simonb db_printf("?\n");
382 1.64 simonb db_flush_lex();
383 1.64 simonb return;
384 1.64 simonb } else {
385 1.64 simonb /*
386 1.64 simonb * Search for command
387 1.1 cgd */
388 1.64 simonb while (cmd_table) {
389 1.64 simonb result = db_cmd_search(db_tok_string, cmd_table, &cmd);
390 1.64 simonb switch (result) {
391 1.64 simonb case CMD_NONE:
392 1.64 simonb db_printf("No such command\n");
393 1.64 simonb db_flush_lex();
394 1.64 simonb return;
395 1.64 simonb case CMD_AMBIGUOUS:
396 1.64 simonb db_printf("Ambiguous\n");
397 1.64 simonb db_flush_lex();
398 1.64 simonb return;
399 1.64 simonb case CMD_HELP:
400 1.64 simonb db_cmd_list(cmd_table);
401 1.64 simonb db_flush_lex();
402 1.64 simonb return;
403 1.64 simonb default:
404 1.64 simonb break;
405 1.64 simonb }
406 1.64 simonb if ((cmd_table = cmd->more) != 0) {
407 1.64 simonb t = db_read_token();
408 1.64 simonb if (t != tIDENT) {
409 1.64 simonb db_cmd_list(cmd_table);
410 1.64 simonb db_flush_lex();
411 1.64 simonb return;
412 1.64 simonb }
413 1.64 simonb }
414 1.1 cgd }
415 1.1 cgd
416 1.64 simonb if ((cmd->flag & CS_OWN) == 0) {
417 1.64 simonb /*
418 1.64 simonb * Standard syntax:
419 1.64 simonb * command [/modifier] [addr] [,count]
420 1.64 simonb */
421 1.64 simonb t = db_read_token();
422 1.64 simonb if (t == tSLASH) {
423 1.64 simonb t = db_read_token();
424 1.64 simonb if (t != tIDENT) {
425 1.64 simonb db_printf("Bad modifier\n");
426 1.64 simonb db_flush_lex();
427 1.64 simonb return;
428 1.64 simonb }
429 1.71 itojun strlcpy(modif, db_tok_string, sizeof(modif));
430 1.64 simonb } else {
431 1.64 simonb db_unread_token(t);
432 1.64 simonb modif[0] = '\0';
433 1.64 simonb }
434 1.64 simonb
435 1.64 simonb if (db_expression(&addr)) {
436 1.64 simonb db_dot = (db_addr_t) addr;
437 1.64 simonb db_last_addr = db_dot;
438 1.64 simonb have_addr = TRUE;
439 1.64 simonb } else {
440 1.64 simonb addr = (db_expr_t) db_dot;
441 1.64 simonb have_addr = FALSE;
442 1.64 simonb }
443 1.64 simonb t = db_read_token();
444 1.64 simonb if (t == tCOMMA) {
445 1.64 simonb if (!db_expression(&count)) {
446 1.64 simonb db_printf("Count missing\n");
447 1.64 simonb db_flush_lex();
448 1.64 simonb return;
449 1.64 simonb }
450 1.64 simonb } else {
451 1.64 simonb db_unread_token(t);
452 1.64 simonb count = -1;
453 1.64 simonb }
454 1.64 simonb if ((cmd->flag & CS_MORE) == 0) {
455 1.64 simonb db_skip_to_eol();
456 1.64 simonb }
457 1.1 cgd }
458 1.1 cgd }
459 1.1 cgd *last_cmdp = cmd;
460 1.38 jhawk last_count = count;
461 1.1 cgd if (cmd != 0) {
462 1.1 cgd /*
463 1.64 simonb * Execute the command.
464 1.1 cgd */
465 1.64 simonb (*cmd->fcn)(addr, have_addr, count, modif);
466 1.64 simonb
467 1.64 simonb if (cmd->flag & CS_SET_DOT) {
468 1.64 simonb /*
469 1.64 simonb * If command changes dot, set dot to
470 1.64 simonb * previous address displayed (if 'ed' style).
471 1.64 simonb */
472 1.64 simonb if (db_ed_style)
473 1.64 simonb db_dot = db_prev;
474 1.64 simonb else
475 1.64 simonb db_dot = db_next;
476 1.64 simonb } else {
477 1.64 simonb /*
478 1.64 simonb * If command does not change dot,
479 1.64 simonb * set 'next' location to be the same.
480 1.64 simonb */
481 1.64 simonb db_next = db_dot;
482 1.1 cgd }
483 1.1 cgd }
484 1.1 cgd }
485 1.1 cgd
486 1.4 brezak /*ARGSUSED*/
487 1.64 simonb static void
488 1.64 simonb db_map_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
489 1.64 simonb {
490 1.64 simonb boolean_t full = FALSE;
491 1.64 simonb
492 1.64 simonb if (modif[0] == 'f')
493 1.64 simonb full = TRUE;
494 1.60 matt
495 1.60 matt if (have_addr == FALSE)
496 1.66 scw addr = (db_expr_t)(intptr_t) kernel_map;
497 1.4 brezak
498 1.66 scw uvm_map_printit((struct vm_map *)(intptr_t) addr, full, db_printf);
499 1.4 brezak }
500 1.4 brezak
501 1.4 brezak /*ARGSUSED*/
502 1.64 simonb static void
503 1.64 simonb db_malloc_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
504 1.62 thorpej {
505 1.64 simonb
506 1.62 thorpej #ifdef MALLOC_DEBUG
507 1.62 thorpej if (!have_addr)
508 1.62 thorpej addr = 0;
509 1.62 thorpej
510 1.62 thorpej debug_malloc_printit(db_printf, (vaddr_t) addr);
511 1.62 thorpej #else
512 1.62 thorpej db_printf("The kernel is not built with the MALLOC_DEBUG option.\n");
513 1.62 thorpej #endif /* MALLOC_DEBUG */
514 1.62 thorpej }
515 1.62 thorpej
516 1.62 thorpej /*ARGSUSED*/
517 1.64 simonb static void
518 1.64 simonb db_object_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
519 1.64 simonb {
520 1.64 simonb boolean_t full = FALSE;
521 1.64 simonb
522 1.64 simonb if (modif[0] == 'f')
523 1.64 simonb full = TRUE;
524 1.4 brezak
525 1.66 scw uvm_object_printit((struct uvm_object *)(intptr_t) addr, full,
526 1.66 scw db_printf);
527 1.24 mrg }
528 1.24 mrg
529 1.24 mrg /*ARGSUSED*/
530 1.64 simonb static void
531 1.64 simonb db_page_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
532 1.64 simonb {
533 1.64 simonb boolean_t full = FALSE;
534 1.64 simonb
535 1.64 simonb if (modif[0] == 'f')
536 1.64 simonb full = TRUE;
537 1.24 mrg
538 1.66 scw uvm_page_printit((struct vm_page *)(intptr_t) addr, full, db_printf);
539 1.36 chs }
540 1.36 chs
541 1.36 chs /*ARGSUSED*/
542 1.64 simonb static void
543 1.64 simonb db_buf_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
544 1.36 chs {
545 1.36 chs boolean_t full = FALSE;
546 1.64 simonb
547 1.36 chs if (modif[0] == 'f')
548 1.36 chs full = TRUE;
549 1.36 chs
550 1.66 scw vfs_buf_print((struct buf *)(intptr_t) addr, full, db_printf);
551 1.65 simonb }
552 1.65 simonb
553 1.65 simonb /*ARGSUSED*/
554 1.65 simonb static void
555 1.65 simonb db_event_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
556 1.65 simonb {
557 1.65 simonb boolean_t full = FALSE;
558 1.65 simonb
559 1.65 simonb if (modif[0] == 'f')
560 1.65 simonb full = TRUE;
561 1.65 simonb
562 1.65 simonb event_print(full, db_printf);
563 1.36 chs }
564 1.36 chs
565 1.36 chs /*ARGSUSED*/
566 1.64 simonb static void
567 1.64 simonb db_vnode_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
568 1.36 chs {
569 1.36 chs boolean_t full = FALSE;
570 1.64 simonb
571 1.36 chs if (modif[0] == 'f')
572 1.36 chs full = TRUE;
573 1.36 chs
574 1.66 scw vfs_vnode_print((struct vnode *)(intptr_t) addr, full, db_printf);
575 1.74 dbj }
576 1.74 dbj
577 1.74 dbj static void
578 1.74 dbj db_mount_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
579 1.74 dbj {
580 1.74 dbj boolean_t full = FALSE;
581 1.74 dbj
582 1.74 dbj if (modif[0] == 'f')
583 1.74 dbj full = TRUE;
584 1.74 dbj
585 1.74 dbj vfs_mount_print((struct mount *)(intptr_t) addr, full, db_printf);
586 1.4 brezak }
587 1.4 brezak
588 1.31 thorpej /*ARGSUSED*/
589 1.64 simonb static void
590 1.64 simonb db_pool_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
591 1.31 thorpej {
592 1.64 simonb
593 1.66 scw pool_printit((struct pool *)(intptr_t) addr, modif, db_printf);
594 1.51 chs }
595 1.31 thorpej
596 1.51 chs /*ARGSUSED*/
597 1.64 simonb static void
598 1.64 simonb db_namecache_print_cmd(db_expr_t addr, int have_addr, db_expr_t count,
599 1.64 simonb char *modif)
600 1.51 chs {
601 1.64 simonb
602 1.66 scw namecache_print((struct vnode *)(intptr_t) addr, db_printf);
603 1.51 chs }
604 1.51 chs
605 1.51 chs /*ARGSUSED*/
606 1.64 simonb static void
607 1.64 simonb db_uvmexp_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
608 1.51 chs {
609 1.64 simonb
610 1.51 chs uvmexp_print(db_printf);
611 1.31 thorpej }
612 1.31 thorpej
613 1.1 cgd /*
614 1.1 cgd * Call random function:
615 1.1 cgd * !expr(arg,arg,arg)
616 1.1 cgd */
617 1.16 christos /*ARGSUSED*/
618 1.64 simonb static void
619 1.64 simonb db_fncall(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
620 1.1 cgd {
621 1.1 cgd db_expr_t fn_addr;
622 1.1 cgd #define MAXARGS 11
623 1.1 cgd db_expr_t args[MAXARGS];
624 1.1 cgd int nargs = 0;
625 1.1 cgd db_expr_t retval;
626 1.64 simonb db_expr_t (*func)(db_expr_t, ...);
627 1.1 cgd int t;
628 1.1 cgd
629 1.1 cgd if (!db_expression(&fn_addr)) {
630 1.64 simonb db_printf("Bad function\n");
631 1.64 simonb db_flush_lex();
632 1.64 simonb return;
633 1.1 cgd }
634 1.66 scw func = (db_expr_t (*)(db_expr_t, ...))(intptr_t) fn_addr;
635 1.1 cgd
636 1.1 cgd t = db_read_token();
637 1.1 cgd if (t == tLPAREN) {
638 1.64 simonb if (db_expression(&args[0])) {
639 1.64 simonb nargs++;
640 1.64 simonb while ((t = db_read_token()) == tCOMMA) {
641 1.64 simonb if (nargs == MAXARGS) {
642 1.64 simonb db_printf("Too many arguments\n");
643 1.64 simonb db_flush_lex();
644 1.64 simonb return;
645 1.64 simonb }
646 1.64 simonb if (!db_expression(&args[nargs])) {
647 1.64 simonb db_printf("Argument missing\n");
648 1.64 simonb db_flush_lex();
649 1.64 simonb return;
650 1.64 simonb }
651 1.64 simonb nargs++;
652 1.64 simonb }
653 1.64 simonb db_unread_token(t);
654 1.64 simonb }
655 1.64 simonb if (db_read_token() != tRPAREN) {
656 1.64 simonb db_printf("?\n");
657 1.1 cgd db_flush_lex();
658 1.1 cgd return;
659 1.1 cgd }
660 1.1 cgd }
661 1.1 cgd db_skip_to_eol();
662 1.1 cgd
663 1.1 cgd while (nargs < MAXARGS) {
664 1.64 simonb args[nargs++] = 0;
665 1.1 cgd }
666 1.1 cgd
667 1.1 cgd retval = (*func)(args[0], args[1], args[2], args[3], args[4],
668 1.20 christos args[5], args[6], args[7], args[8], args[9]);
669 1.45 jhawk db_printf("%s\n", db_num_to_str(retval));
670 1.23 scottr }
671 1.23 scottr
672 1.64 simonb static void
673 1.64 simonb db_reboot_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
674 1.23 scottr {
675 1.23 scottr db_expr_t bootflags;
676 1.23 scottr
677 1.23 scottr /* Flags, default to RB_AUTOBOOT */
678 1.23 scottr if (!db_expression(&bootflags))
679 1.23 scottr bootflags = (db_expr_t)RB_AUTOBOOT;
680 1.23 scottr if (db_read_token() != tEOL) {
681 1.64 simonb db_error("?\n");
682 1.64 simonb /*NOTREACHED*/
683 1.23 scottr }
684 1.47 sommerfe /*
685 1.47 sommerfe * We are leaving DDB, never to return upward.
686 1.47 sommerfe * Clear db_recover so that we can debug faults in functions
687 1.47 sommerfe * called from cpu_reboot.
688 1.47 sommerfe */
689 1.47 sommerfe db_recover = 0;
690 1.23 scottr cpu_reboot((int)bootflags, NULL);
691 1.41 jhawk }
692 1.41 jhawk
693 1.64 simonb static void
694 1.64 simonb db_sifting_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
695 1.41 jhawk {
696 1.41 jhawk int mode, t;
697 1.41 jhawk
698 1.41 jhawk t = db_read_token();
699 1.41 jhawk if (t == tSLASH) {
700 1.41 jhawk t = db_read_token();
701 1.41 jhawk if (t != tIDENT) {
702 1.41 jhawk bad_modifier:
703 1.41 jhawk db_printf("Bad modifier\n");
704 1.41 jhawk db_flush_lex();
705 1.41 jhawk return;
706 1.41 jhawk }
707 1.41 jhawk if (!strcmp(db_tok_string, "F"))
708 1.41 jhawk mode = 'F';
709 1.41 jhawk else
710 1.41 jhawk goto bad_modifier;
711 1.41 jhawk t = db_read_token();
712 1.41 jhawk } else
713 1.41 jhawk mode = 0;
714 1.41 jhawk
715 1.51 chs if (t == tIDENT)
716 1.41 jhawk db_sifting(db_tok_string, mode);
717 1.41 jhawk else {
718 1.41 jhawk db_printf("Bad argument (non-string)\n");
719 1.41 jhawk db_flush_lex();
720 1.41 jhawk }
721 1.43 jhawk }
722 1.43 jhawk
723 1.64 simonb static void
724 1.64 simonb db_stack_trace_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
725 1.43 jhawk {
726 1.70 atatat register char *cp = modif;
727 1.70 atatat register char c;
728 1.70 atatat void (*pr)(const char *, ...);
729 1.70 atatat
730 1.70 atatat pr = db_printf;
731 1.70 atatat while ((c = *cp++) != 0)
732 1.70 atatat if (c == 'l')
733 1.70 atatat pr = printf;
734 1.64 simonb
735 1.43 jhawk if (count == -1)
736 1.43 jhawk count = 65535;
737 1.43 jhawk
738 1.70 atatat db_stack_trace_print(addr, have_addr, count, modif, pr);
739 1.32 lukem }
740 1.32 lukem
741 1.64 simonb static void
742 1.64 simonb db_sync_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
743 1.32 lukem {
744 1.64 simonb
745 1.47 sommerfe /*
746 1.47 sommerfe * We are leaving DDB, never to return upward.
747 1.47 sommerfe * Clear db_recover so that we can debug faults in functions
748 1.47 sommerfe * called from cpu_reboot.
749 1.47 sommerfe */
750 1.47 sommerfe db_recover = 0;
751 1.32 lukem cpu_reboot(RB_DUMP, NULL);
752 1.1 cgd }
753