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