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