db_command.c revision 1.84 1 /* $NetBSD: db_command.c,v 1.84 2006/02/19 18:52:29 bjh21 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.84 2006/02/19 18:52:29 bjh21 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 w = strlen(p);
377 while (w < width) {
378 w = DB_NEXT_TAB(w);
379 db_putchar('\t');
380 }
381 }
382 }
383 }
384
385 static void
386 db_command(const struct db_command **last_cmdp,
387 const struct db_command *cmd_table)
388 {
389 const struct db_command *cmd;
390 int t;
391 char modif[TOK_STRING_SIZE];
392 db_expr_t addr, count;
393 boolean_t have_addr = FALSE;
394 int result;
395
396 static db_expr_t last_count = 0;
397
398 t = db_read_token();
399 if ((t == tEOL) || (t == tCOMMA)) {
400 /*
401 * An empty line repeats last command, at 'next'.
402 * Only a count repeats the last command with the new count.
403 */
404 cmd = *last_cmdp;
405 addr = (db_expr_t)db_next;
406 if (t == tCOMMA) {
407 if (!db_expression(&count)) {
408 db_printf("Count missing\n");
409 db_flush_lex();
410 return;
411 }
412 } else
413 count = last_count;
414 have_addr = FALSE;
415 modif[0] = '\0';
416 db_skip_to_eol();
417 } else if (t == tEXCL) {
418 db_fncall(0, 0, 0, NULL);
419 return;
420 } else if (t != tIDENT) {
421 db_printf("?\n");
422 db_flush_lex();
423 return;
424 } else {
425 /*
426 * Search for command
427 */
428 while (cmd_table) {
429 result = db_cmd_search(db_tok_string, cmd_table, &cmd);
430 switch (result) {
431 case CMD_NONE:
432 db_printf("No such command\n");
433 db_flush_lex();
434 return;
435 case CMD_AMBIGUOUS:
436 db_printf("Ambiguous\n");
437 db_flush_lex();
438 return;
439 case CMD_HELP:
440 db_cmd_list(cmd_table);
441 db_flush_lex();
442 return;
443 default:
444 break;
445 }
446 if ((cmd_table = cmd->more) != 0) {
447 t = db_read_token();
448 if (t != tIDENT) {
449 db_cmd_list(cmd_table);
450 db_flush_lex();
451 return;
452 }
453 }
454 }
455
456 if ((cmd->flag & CS_OWN) == 0) {
457 /*
458 * Standard syntax:
459 * command [/modifier] [addr] [,count]
460 */
461 t = db_read_token();
462 if (t == tSLASH) {
463 t = db_read_token();
464 if (t != tIDENT) {
465 db_printf("Bad modifier\n");
466 db_flush_lex();
467 return;
468 }
469 strlcpy(modif, db_tok_string, sizeof(modif));
470 } else {
471 db_unread_token(t);
472 modif[0] = '\0';
473 }
474
475 if (db_expression(&addr)) {
476 db_dot = (db_addr_t) addr;
477 db_last_addr = db_dot;
478 have_addr = TRUE;
479 } else {
480 addr = (db_expr_t) db_dot;
481 have_addr = FALSE;
482 }
483 t = db_read_token();
484 if (t == tCOMMA) {
485 if (!db_expression(&count)) {
486 db_printf("Count missing\n");
487 db_flush_lex();
488 return;
489 }
490 } else {
491 db_unread_token(t);
492 count = -1;
493 }
494 if ((cmd->flag & CS_MORE) == 0) {
495 db_skip_to_eol();
496 }
497 }
498 }
499 *last_cmdp = cmd;
500 last_count = count;
501 if (cmd != 0) {
502 /*
503 * Execute the command.
504 */
505 (*cmd->fcn)(addr, have_addr, count, modif);
506
507 if (cmd->flag & CS_SET_DOT) {
508 /*
509 * If command changes dot, set dot to
510 * previous address displayed (if 'ed' style).
511 */
512 if (db_ed_style)
513 db_dot = db_prev;
514 else
515 db_dot = db_next;
516 } else {
517 /*
518 * If command does not change dot,
519 * set 'next' location to be the same.
520 */
521 db_next = db_dot;
522 }
523 }
524 }
525
526 /*ARGSUSED*/
527 static void
528 db_map_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
529 {
530 boolean_t full = FALSE;
531
532 if (modif[0] == 'f')
533 full = TRUE;
534
535 if (have_addr == FALSE)
536 addr = (db_expr_t)(intptr_t) kernel_map;
537
538 uvm_map_printit((struct vm_map *)(intptr_t) addr, full, db_printf);
539 }
540
541 /*ARGSUSED*/
542 static void
543 db_malloc_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
544 {
545
546 #ifdef MALLOC_DEBUG
547 if (!have_addr)
548 addr = 0;
549
550 debug_malloc_printit(db_printf, (vaddr_t) addr);
551 #else
552 db_printf("The kernel is not built with the MALLOC_DEBUG option.\n");
553 #endif /* MALLOC_DEBUG */
554 }
555
556 /*ARGSUSED*/
557 static void
558 db_object_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
559 {
560 boolean_t full = FALSE;
561
562 if (modif[0] == 'f')
563 full = TRUE;
564
565 uvm_object_printit((struct uvm_object *)(intptr_t) addr, full,
566 db_printf);
567 }
568
569 /*ARGSUSED*/
570 static void
571 db_page_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
572 {
573 boolean_t full = FALSE;
574
575 if (modif[0] == 'f')
576 full = TRUE;
577
578 uvm_page_printit((struct vm_page *)(intptr_t) addr, full, db_printf);
579 }
580
581 /*ARGSUSED*/
582 static void
583 db_show_all_pages(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
584 {
585
586 uvm_page_printall(db_printf);
587 }
588
589 /*ARGSUSED*/
590 static void
591 db_buf_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
592 {
593 boolean_t full = FALSE;
594
595 if (modif[0] == 'f')
596 full = TRUE;
597
598 vfs_buf_print((struct buf *)(intptr_t) addr, full, db_printf);
599 }
600
601 /*ARGSUSED*/
602 static void
603 db_event_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
604 {
605 boolean_t full = FALSE;
606
607 if (modif[0] == 'f')
608 full = TRUE;
609
610 event_print(full, db_printf);
611 }
612
613 /*ARGSUSED*/
614 static void
615 db_vnode_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
616 {
617 boolean_t full = FALSE;
618
619 if (modif[0] == 'f')
620 full = TRUE;
621
622 vfs_vnode_print((struct vnode *)(intptr_t) addr, full, db_printf);
623 }
624
625 static void
626 db_mount_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
627 {
628 boolean_t full = FALSE;
629
630 if (modif[0] == 'f')
631 full = TRUE;
632
633 vfs_mount_print((struct mount *)(intptr_t) addr, full, db_printf);
634 }
635
636 /*ARGSUSED*/
637 static void
638 db_mbuf_print_cmd(db_expr_t addr, int have_addr, db_expr_t count,
639 const char *modif)
640 {
641
642 m_print((const struct mbuf *)(intptr_t) addr, modif, db_printf);
643 }
644
645 /*ARGSUSED*/
646 static void
647 db_pool_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
648 {
649
650 pool_printit((struct pool *)(intptr_t) addr, modif, db_printf);
651 }
652
653 /*ARGSUSED*/
654 static void
655 db_namecache_print_cmd(db_expr_t addr, int have_addr, db_expr_t count,
656 const char *modif)
657 {
658
659 namecache_print((struct vnode *)(intptr_t) addr, db_printf);
660 }
661
662 /*ARGSUSED*/
663 static void
664 db_uvmexp_print_cmd(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
665 {
666
667 uvmexp_print(db_printf);
668 }
669
670 /*
671 * Call random function:
672 * !expr(arg,arg,arg)
673 */
674 /*ARGSUSED*/
675 static void
676 db_fncall(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
677 {
678 db_expr_t fn_addr;
679 #define MAXARGS 11
680 db_expr_t args[MAXARGS];
681 int nargs = 0;
682 db_expr_t retval;
683 db_expr_t (*func)(db_expr_t, ...);
684 int t;
685
686 if (!db_expression(&fn_addr)) {
687 db_printf("Bad function\n");
688 db_flush_lex();
689 return;
690 }
691 func = (db_expr_t (*)(db_expr_t, ...))(intptr_t) fn_addr;
692
693 t = db_read_token();
694 if (t == tLPAREN) {
695 if (db_expression(&args[0])) {
696 nargs++;
697 while ((t = db_read_token()) == tCOMMA) {
698 if (nargs == MAXARGS) {
699 db_printf("Too many arguments\n");
700 db_flush_lex();
701 return;
702 }
703 if (!db_expression(&args[nargs])) {
704 db_printf("Argument missing\n");
705 db_flush_lex();
706 return;
707 }
708 nargs++;
709 }
710 db_unread_token(t);
711 }
712 if (db_read_token() != tRPAREN) {
713 db_printf("?\n");
714 db_flush_lex();
715 return;
716 }
717 }
718 db_skip_to_eol();
719
720 while (nargs < MAXARGS) {
721 args[nargs++] = 0;
722 }
723
724 retval = (*func)(args[0], args[1], args[2], args[3], args[4],
725 args[5], args[6], args[7], args[8], args[9]);
726 db_printf("%s\n", db_num_to_str(retval));
727 }
728
729 static void
730 db_reboot_cmd(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
731 {
732 db_expr_t bootflags;
733
734 /* Flags, default to RB_AUTOBOOT */
735 if (!db_expression(&bootflags))
736 bootflags = (db_expr_t)RB_AUTOBOOT;
737 if (db_read_token() != tEOL) {
738 db_error("?\n");
739 /*NOTREACHED*/
740 }
741 /*
742 * We are leaving DDB, never to return upward.
743 * Clear db_recover so that we can debug faults in functions
744 * called from cpu_reboot.
745 */
746 db_recover = 0;
747 cpu_reboot((int)bootflags, NULL);
748 }
749
750 static void
751 db_sifting_cmd(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
752 {
753 int mode, t;
754
755 t = db_read_token();
756 if (t == tSLASH) {
757 t = db_read_token();
758 if (t != tIDENT) {
759 bad_modifier:
760 db_printf("Bad modifier\n");
761 db_flush_lex();
762 return;
763 }
764 if (!strcmp(db_tok_string, "F"))
765 mode = 'F';
766 else
767 goto bad_modifier;
768 t = db_read_token();
769 } else
770 mode = 0;
771
772 if (t == tIDENT)
773 db_sifting(db_tok_string, mode);
774 else {
775 db_printf("Bad argument (non-string)\n");
776 db_flush_lex();
777 }
778 }
779
780 static void
781 db_stack_trace_cmd(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
782 {
783 register const char *cp = modif;
784 register char c;
785 void (*pr)(const char *, ...);
786
787 pr = db_printf;
788 while ((c = *cp++) != 0)
789 if (c == 'l')
790 pr = printf;
791
792 if (count == -1)
793 count = 65535;
794
795 db_stack_trace_print(addr, have_addr, count, modif, pr);
796 }
797
798 static void
799 db_sync_cmd(db_expr_t addr, int have_addr, db_expr_t count, const char *modif)
800 {
801
802 /*
803 * We are leaving DDB, never to return upward.
804 * Clear db_recover so that we can debug faults in functions
805 * called from cpu_reboot.
806 */
807 db_recover = 0;
808 cpu_reboot(RB_DUMP, NULL);
809 }
810