db_command.c revision 1.27.4.1 1 1.27.4.1 chs /* $NetBSD: db_command.c,v 1.27.4.1 1998/11/09 06:06:31 chs Exp $ */
2 1.12 cgd
3 1.1 cgd /*
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.1 cgd *
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.1 cgd *
14 1.1 cgd * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
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.1 cgd *
18 1.1 cgd * Carnegie Mellon requests users of this software to return to
19 1.1 cgd *
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.1 cgd *
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.27 tron #include "opt_ddb.h"
30 1.25 mrg #include "opt_uvm.h"
31 1.5 mycroft
32 1.1 cgd /*
33 1.1 cgd * Command dispatcher.
34 1.1 cgd */
35 1.7 mycroft #include <sys/param.h>
36 1.18 christos #include <sys/systm.h>
37 1.23 scottr #include <sys/reboot.h>
38 1.7 mycroft #include <sys/proc.h>
39 1.27.4.1 chs #include <sys/vnode.h>
40 1.15 gwr
41 1.1 cgd #include <machine/db_machdep.h> /* type definitions */
42 1.1 cgd
43 1.1 cgd #include <ddb/db_lex.h>
44 1.1 cgd #include <ddb/db_output.h>
45 1.10 pk #include <ddb/db_command.h>
46 1.16 christos #include <ddb/db_break.h>
47 1.16 christos #include <ddb/db_watch.h>
48 1.16 christos #include <ddb/db_run.h>
49 1.16 christos #include <ddb/db_variables.h>
50 1.16 christos #include <ddb/db_interface.h>
51 1.16 christos #include <ddb/db_sym.h>
52 1.16 christos #include <ddb/db_extern.h>
53 1.16 christos
54 1.16 christos #include <vm/vm.h>
55 1.1 cgd
56 1.24 mrg #if defined(UVM)
57 1.24 mrg #include <uvm/uvm_extern.h>
58 1.26 jonathan #include <uvm/uvm_ddb.h>
59 1.24 mrg #endif
60 1.24 mrg
61 1.1 cgd /*
62 1.1 cgd * Exported global variables
63 1.1 cgd */
64 1.1 cgd boolean_t db_cmd_loop_done;
65 1.17 gwr label_t *db_recover;
66 1.1 cgd
67 1.1 cgd /*
68 1.1 cgd * if 'ed' style: 'dot' is set at start of last item printed,
69 1.1 cgd * and '+' points to next line.
70 1.1 cgd * Otherwise: 'dot' points to next item, '..' points to last.
71 1.1 cgd */
72 1.1 cgd boolean_t db_ed_style = TRUE;
73 1.1 cgd
74 1.1 cgd /*
75 1.1 cgd * Utility routine - discard tokens through end-of-line.
76 1.1 cgd */
77 1.1 cgd void
78 1.1 cgd db_skip_to_eol()
79 1.1 cgd {
80 1.1 cgd int t;
81 1.1 cgd do {
82 1.1 cgd t = db_read_token();
83 1.1 cgd } while (t != tEOL);
84 1.1 cgd }
85 1.1 cgd
86 1.1 cgd /*
87 1.1 cgd * Results of command search.
88 1.1 cgd */
89 1.1 cgd #define CMD_UNIQUE 0
90 1.1 cgd #define CMD_FOUND 1
91 1.1 cgd #define CMD_NONE 2
92 1.1 cgd #define CMD_AMBIGUOUS 3
93 1.1 cgd #define CMD_HELP 4
94 1.1 cgd
95 1.1 cgd /*
96 1.1 cgd * Search for command prefix.
97 1.1 cgd */
98 1.1 cgd int
99 1.1 cgd db_cmd_search(name, table, cmdp)
100 1.10 pk char *name;
101 1.10 pk struct db_command *table;
102 1.10 pk struct db_command **cmdp; /* out */
103 1.1 cgd {
104 1.10 pk struct db_command *cmd;
105 1.10 pk int result = CMD_NONE;
106 1.1 cgd
107 1.1 cgd for (cmd = table; cmd->name != 0; cmd++) {
108 1.1 cgd register char *lp;
109 1.1 cgd register char *rp;
110 1.1 cgd register int c;
111 1.1 cgd
112 1.1 cgd lp = name;
113 1.1 cgd rp = cmd->name;
114 1.1 cgd while ((c = *lp) == *rp) {
115 1.1 cgd if (c == 0) {
116 1.1 cgd /* complete match */
117 1.1 cgd *cmdp = cmd;
118 1.1 cgd return (CMD_UNIQUE);
119 1.1 cgd }
120 1.1 cgd lp++;
121 1.1 cgd rp++;
122 1.1 cgd }
123 1.1 cgd if (c == 0) {
124 1.1 cgd /* end of name, not end of command -
125 1.1 cgd partial match */
126 1.1 cgd if (result == CMD_FOUND) {
127 1.1 cgd result = CMD_AMBIGUOUS;
128 1.1 cgd /* but keep looking for a full match -
129 1.1 cgd this lets us match single letters */
130 1.1 cgd }
131 1.1 cgd else {
132 1.1 cgd *cmdp = cmd;
133 1.1 cgd result = CMD_FOUND;
134 1.1 cgd }
135 1.1 cgd }
136 1.1 cgd }
137 1.1 cgd if (result == CMD_NONE) {
138 1.1 cgd /* check for 'help' */
139 1.1 cgd if (name[0] == 'h' && name[1] == 'e'
140 1.1 cgd && name[2] == 'l' && name[3] == 'p')
141 1.1 cgd result = CMD_HELP;
142 1.1 cgd }
143 1.1 cgd return (result);
144 1.1 cgd }
145 1.1 cgd
146 1.1 cgd void
147 1.1 cgd db_cmd_list(table)
148 1.10 pk struct db_command *table;
149 1.1 cgd {
150 1.10 pk register struct db_command *cmd;
151 1.1 cgd
152 1.1 cgd for (cmd = table; cmd->name != 0; cmd++) {
153 1.1 cgd db_printf("%-12s", cmd->name);
154 1.1 cgd db_end_line();
155 1.1 cgd }
156 1.1 cgd }
157 1.1 cgd
158 1.1 cgd void
159 1.1 cgd db_command(last_cmdp, cmd_table)
160 1.10 pk struct db_command **last_cmdp; /* IN_OUT */
161 1.10 pk struct db_command *cmd_table;
162 1.1 cgd {
163 1.10 pk struct db_command *cmd;
164 1.1 cgd int t;
165 1.1 cgd char modif[TOK_STRING_SIZE];
166 1.1 cgd db_expr_t addr, count;
167 1.16 christos boolean_t have_addr = FALSE;
168 1.1 cgd int result;
169 1.1 cgd
170 1.1 cgd t = db_read_token();
171 1.1 cgd if (t == tEOL) {
172 1.1 cgd /* empty line repeats last command, at 'next' */
173 1.1 cgd cmd = *last_cmdp;
174 1.1 cgd addr = (db_expr_t)db_next;
175 1.1 cgd have_addr = FALSE;
176 1.1 cgd count = 1;
177 1.1 cgd modif[0] = '\0';
178 1.1 cgd }
179 1.1 cgd else if (t == tEXCL) {
180 1.16 christos db_fncall(0, 0, 0, NULL);
181 1.1 cgd return;
182 1.1 cgd }
183 1.1 cgd else if (t != tIDENT) {
184 1.1 cgd db_printf("?\n");
185 1.1 cgd db_flush_lex();
186 1.1 cgd return;
187 1.1 cgd }
188 1.1 cgd else {
189 1.1 cgd /*
190 1.1 cgd * Search for command
191 1.1 cgd */
192 1.1 cgd while (cmd_table) {
193 1.1 cgd result = db_cmd_search(db_tok_string,
194 1.1 cgd cmd_table,
195 1.1 cgd &cmd);
196 1.1 cgd switch (result) {
197 1.1 cgd case CMD_NONE:
198 1.1 cgd db_printf("No such command\n");
199 1.1 cgd db_flush_lex();
200 1.1 cgd return;
201 1.1 cgd case CMD_AMBIGUOUS:
202 1.1 cgd db_printf("Ambiguous\n");
203 1.1 cgd db_flush_lex();
204 1.1 cgd return;
205 1.1 cgd case CMD_HELP:
206 1.1 cgd db_cmd_list(cmd_table);
207 1.1 cgd db_flush_lex();
208 1.1 cgd return;
209 1.1 cgd default:
210 1.1 cgd break;
211 1.1 cgd }
212 1.1 cgd if ((cmd_table = cmd->more) != 0) {
213 1.1 cgd t = db_read_token();
214 1.1 cgd if (t != tIDENT) {
215 1.1 cgd db_cmd_list(cmd_table);
216 1.1 cgd db_flush_lex();
217 1.1 cgd return;
218 1.1 cgd }
219 1.1 cgd }
220 1.1 cgd }
221 1.1 cgd
222 1.1 cgd if ((cmd->flag & CS_OWN) == 0) {
223 1.1 cgd /*
224 1.1 cgd * Standard syntax:
225 1.1 cgd * command [/modifier] [addr] [,count]
226 1.1 cgd */
227 1.1 cgd t = db_read_token();
228 1.1 cgd if (t == tSLASH) {
229 1.1 cgd t = db_read_token();
230 1.1 cgd if (t != tIDENT) {
231 1.1 cgd db_printf("Bad modifier\n");
232 1.1 cgd db_flush_lex();
233 1.1 cgd return;
234 1.1 cgd }
235 1.1 cgd db_strcpy(modif, db_tok_string);
236 1.1 cgd }
237 1.1 cgd else {
238 1.1 cgd db_unread_token(t);
239 1.1 cgd modif[0] = '\0';
240 1.1 cgd }
241 1.1 cgd
242 1.1 cgd if (db_expression(&addr)) {
243 1.1 cgd db_dot = (db_addr_t) addr;
244 1.1 cgd db_last_addr = db_dot;
245 1.1 cgd have_addr = TRUE;
246 1.1 cgd }
247 1.1 cgd else {
248 1.1 cgd addr = (db_expr_t) db_dot;
249 1.1 cgd have_addr = FALSE;
250 1.1 cgd }
251 1.1 cgd t = db_read_token();
252 1.1 cgd if (t == tCOMMA) {
253 1.1 cgd if (!db_expression(&count)) {
254 1.1 cgd db_printf("Count missing\n");
255 1.1 cgd db_flush_lex();
256 1.1 cgd return;
257 1.1 cgd }
258 1.1 cgd }
259 1.1 cgd else {
260 1.1 cgd db_unread_token(t);
261 1.1 cgd count = -1;
262 1.1 cgd }
263 1.1 cgd if ((cmd->flag & CS_MORE) == 0) {
264 1.1 cgd db_skip_to_eol();
265 1.1 cgd }
266 1.1 cgd }
267 1.1 cgd }
268 1.1 cgd *last_cmdp = cmd;
269 1.1 cgd if (cmd != 0) {
270 1.1 cgd /*
271 1.1 cgd * Execute the command.
272 1.1 cgd */
273 1.1 cgd (*cmd->fcn)(addr, have_addr, count, modif);
274 1.1 cgd
275 1.1 cgd if (cmd->flag & CS_SET_DOT) {
276 1.1 cgd /*
277 1.1 cgd * If command changes dot, set dot to
278 1.1 cgd * previous address displayed (if 'ed' style).
279 1.1 cgd */
280 1.1 cgd if (db_ed_style) {
281 1.1 cgd db_dot = db_prev;
282 1.1 cgd }
283 1.1 cgd else {
284 1.1 cgd db_dot = db_next;
285 1.1 cgd }
286 1.1 cgd }
287 1.1 cgd else {
288 1.1 cgd /*
289 1.1 cgd * If command does not change dot,
290 1.1 cgd * set 'next' location to be the same.
291 1.1 cgd */
292 1.1 cgd db_next = db_dot;
293 1.1 cgd }
294 1.1 cgd }
295 1.1 cgd }
296 1.1 cgd
297 1.4 brezak /*ARGSUSED*/
298 1.4 brezak void
299 1.4 brezak db_map_print_cmd(addr, have_addr, count, modif)
300 1.4 brezak db_expr_t addr;
301 1.4 brezak int have_addr;
302 1.4 brezak db_expr_t count;
303 1.4 brezak char * modif;
304 1.4 brezak {
305 1.4 brezak boolean_t full = FALSE;
306 1.4 brezak
307 1.4 brezak if (modif[0] == 'f')
308 1.4 brezak full = TRUE;
309 1.4 brezak
310 1.24 mrg #if defined(UVM)
311 1.24 mrg uvm_map_printit((vm_map_t) addr, full, db_printf);
312 1.24 mrg #else
313 1.16 christos _vm_map_print((vm_map_t) addr, full, db_printf);
314 1.24 mrg #endif
315 1.4 brezak }
316 1.4 brezak
317 1.4 brezak /*ARGSUSED*/
318 1.4 brezak void
319 1.4 brezak db_object_print_cmd(addr, have_addr, count, modif)
320 1.4 brezak db_expr_t addr;
321 1.4 brezak int have_addr;
322 1.4 brezak db_expr_t count;
323 1.4 brezak char * modif;
324 1.4 brezak {
325 1.4 brezak boolean_t full = FALSE;
326 1.4 brezak
327 1.4 brezak if (modif[0] == 'f')
328 1.4 brezak full = TRUE;
329 1.4 brezak
330 1.24 mrg #if defined(UVM)
331 1.24 mrg uvm_object_printit((struct uvm_object *) addr, full, db_printf);
332 1.24 mrg #else
333 1.16 christos _vm_object_print((vm_object_t) addr, full, db_printf);
334 1.24 mrg #endif
335 1.24 mrg }
336 1.24 mrg
337 1.24 mrg /*ARGSUSED*/
338 1.24 mrg void
339 1.24 mrg db_page_print_cmd(addr, have_addr, count, modif)
340 1.24 mrg db_expr_t addr;
341 1.24 mrg int have_addr;
342 1.24 mrg db_expr_t count;
343 1.24 mrg char * modif;
344 1.24 mrg {
345 1.24 mrg boolean_t full = FALSE;
346 1.24 mrg
347 1.24 mrg if (modif[0] == 'f')
348 1.24 mrg full = TRUE;
349 1.24 mrg
350 1.24 mrg #if defined(UVM)
351 1.24 mrg uvm_page_printit((struct vm_page *) addr, full, db_printf);
352 1.24 mrg #else
353 1.24 mrg printf("only supported by UVM\n");
354 1.24 mrg #endif
355 1.4 brezak }
356 1.4 brezak
357 1.27.4.1 chs /*ARGSUSED*/
358 1.27.4.1 chs void
359 1.27.4.1 chs db_buf_print_cmd(addr, have_addr, count, modif)
360 1.27.4.1 chs db_expr_t addr;
361 1.27.4.1 chs int have_addr;
362 1.27.4.1 chs db_expr_t count;
363 1.27.4.1 chs char * modif;
364 1.27.4.1 chs {
365 1.27.4.1 chs boolean_t full = FALSE;
366 1.27.4.1 chs
367 1.27.4.1 chs if (modif[0] == 'f')
368 1.27.4.1 chs full = TRUE;
369 1.27.4.1 chs
370 1.27.4.1 chs vfs_buf_print((struct buf *)addr, full, db_printf);
371 1.27.4.1 chs }
372 1.27.4.1 chs
373 1.27.4.1 chs /*ARGSUSED*/
374 1.27.4.1 chs void
375 1.27.4.1 chs db_vnode_print_cmd(addr, have_addr, count, modif)
376 1.27.4.1 chs db_expr_t addr;
377 1.27.4.1 chs int have_addr;
378 1.27.4.1 chs db_expr_t count;
379 1.27.4.1 chs char * modif;
380 1.27.4.1 chs {
381 1.27.4.1 chs boolean_t full = FALSE;
382 1.27.4.1 chs
383 1.27.4.1 chs if (modif[0] == 'f')
384 1.27.4.1 chs full = TRUE;
385 1.27.4.1 chs
386 1.27.4.1 chs vfs_vnode_print((struct vnode *) addr, full, db_printf);
387 1.27.4.1 chs }
388 1.27.4.1 chs
389 1.1 cgd /*
390 1.1 cgd * 'show' commands
391 1.1 cgd */
392 1.1 cgd
393 1.10 pk struct db_command db_show_all_cmds[] = {
394 1.16 christos { "procs", db_show_all_procs, 0, NULL },
395 1.16 christos { "callout", db_show_callout, 0, NULL },
396 1.16 christos { NULL, NULL, 0, NULL }
397 1.1 cgd };
398 1.1 cgd
399 1.10 pk struct db_command db_show_cmds[] = {
400 1.16 christos { "all", NULL, 0, db_show_all_cmds },
401 1.16 christos { "registers", db_show_regs, 0, NULL },
402 1.16 christos { "breaks", db_listbreak_cmd, 0, NULL },
403 1.16 christos { "watches", db_listwatch_cmd, 0, NULL },
404 1.16 christos { "map", db_map_print_cmd, 0, NULL },
405 1.16 christos { "object", db_object_print_cmd, 0, NULL },
406 1.24 mrg { "page", db_page_print_cmd, 0, NULL },
407 1.27.4.1 chs { "buf", db_buf_print_cmd, 0, NULL },
408 1.27.4.1 chs { "vnode", db_vnode_print_cmd, 0, NULL },
409 1.16 christos { NULL, NULL, 0, NULL, }
410 1.1 cgd };
411 1.1 cgd
412 1.10 pk struct db_command db_command_table[] = {
413 1.6 brezak #ifdef DB_MACHINE_COMMANDS
414 1.6 brezak /* this must be the first entry, if it exists */
415 1.16 christos { "machine", NULL, 0, NULL},
416 1.6 brezak #endif
417 1.16 christos { "print", db_print_cmd, 0, NULL },
418 1.16 christos { "examine", db_examine_cmd, CS_SET_DOT, NULL },
419 1.16 christos { "x", db_examine_cmd, CS_SET_DOT, NULL },
420 1.16 christos { "search", db_search_cmd, CS_OWN|CS_SET_DOT, NULL },
421 1.16 christos { "set", db_set_cmd, CS_OWN, NULL },
422 1.16 christos { "write", db_write_cmd, CS_MORE|CS_SET_DOT, NULL },
423 1.16 christos { "w", db_write_cmd, CS_MORE|CS_SET_DOT, NULL },
424 1.16 christos { "delete", db_delete_cmd, 0, NULL },
425 1.16 christos { "d", db_delete_cmd, 0, NULL },
426 1.16 christos { "break", db_breakpoint_cmd, 0, NULL },
427 1.16 christos { "dwatch", db_deletewatch_cmd, 0, NULL },
428 1.16 christos { "watch", db_watchpoint_cmd, CS_MORE, NULL },
429 1.16 christos { "step", db_single_step_cmd, 0, NULL },
430 1.16 christos { "s", db_single_step_cmd, 0, NULL },
431 1.16 christos { "continue", db_continue_cmd, 0, NULL },
432 1.16 christos { "c", db_continue_cmd, 0, NULL },
433 1.16 christos { "until", db_trace_until_call_cmd,0, NULL },
434 1.16 christos { "next", db_trace_until_matching_cmd,0, NULL },
435 1.16 christos { "match", db_trace_until_matching_cmd,0, NULL },
436 1.16 christos { "trace", db_stack_trace_cmd, 0, NULL },
437 1.16 christos { "call", db_fncall, CS_OWN, NULL },
438 1.16 christos { "ps", db_show_all_procs, 0, NULL },
439 1.23 scottr { "kill", db_kill_proc, CS_OWN, NULL },
440 1.16 christos { "callout", db_show_callout, 0, NULL },
441 1.23 scottr { "reboot", db_reboot_cmd, CS_OWN, NULL },
442 1.16 christos { "show", NULL, 0, db_show_cmds },
443 1.16 christos { NULL, NULL, 0, NULL }
444 1.1 cgd };
445 1.6 brezak
446 1.6 brezak #ifdef DB_MACHINE_COMMANDS
447 1.6 brezak
448 1.6 brezak /* this function should be called to install the machine dependent
449 1.6 brezak commands. It should be called before the debugger is enabled */
450 1.6 brezak void db_machine_commands_install(ptr)
451 1.6 brezak struct db_command *ptr;
452 1.6 brezak {
453 1.6 brezak db_command_table[0].more = ptr;
454 1.6 brezak return;
455 1.6 brezak }
456 1.6 brezak
457 1.6 brezak #endif
458 1.1 cgd
459 1.10 pk struct db_command *db_last_command = 0;
460 1.1 cgd
461 1.1 cgd void
462 1.1 cgd db_help_cmd()
463 1.1 cgd {
464 1.10 pk struct db_command *cmd = db_command_table;
465 1.1 cgd
466 1.1 cgd while (cmd->name != 0) {
467 1.1 cgd db_printf("%-12s", cmd->name);
468 1.1 cgd db_end_line();
469 1.1 cgd cmd++;
470 1.1 cgd }
471 1.1 cgd }
472 1.1 cgd
473 1.1 cgd void
474 1.1 cgd db_command_loop()
475 1.1 cgd {
476 1.17 gwr label_t db_jmpbuf;
477 1.17 gwr label_t *savejmp;
478 1.8 mycroft extern int db_output_line;
479 1.4 brezak
480 1.1 cgd /*
481 1.1 cgd * Initialize 'prev' and 'next' to dot.
482 1.1 cgd */
483 1.1 cgd db_prev = db_dot;
484 1.1 cgd db_next = db_dot;
485 1.1 cgd
486 1.1 cgd db_cmd_loop_done = 0;
487 1.17 gwr
488 1.17 gwr savejmp = db_recover;
489 1.17 gwr db_recover = &db_jmpbuf;
490 1.17 gwr (void) setjmp(&db_jmpbuf);
491 1.8 mycroft
492 1.1 cgd while (!db_cmd_loop_done) {
493 1.8 mycroft if (db_print_position() != 0)
494 1.8 mycroft db_printf("\n");
495 1.8 mycroft db_output_line = 0;
496 1.1 cgd
497 1.8 mycroft db_printf("db> ");
498 1.8 mycroft (void) db_read_line();
499 1.1 cgd
500 1.8 mycroft db_command(&db_last_command, db_command_table);
501 1.8 mycroft }
502 1.1 cgd
503 1.8 mycroft db_recover = savejmp;
504 1.1 cgd }
505 1.1 cgd
506 1.1 cgd void
507 1.1 cgd db_error(s)
508 1.1 cgd char *s;
509 1.1 cgd {
510 1.1 cgd if (s)
511 1.1 cgd db_printf(s);
512 1.1 cgd db_flush_lex();
513 1.19 christos longjmp(db_recover);
514 1.1 cgd }
515 1.1 cgd
516 1.1 cgd
517 1.1 cgd /*
518 1.1 cgd * Call random function:
519 1.1 cgd * !expr(arg,arg,arg)
520 1.1 cgd */
521 1.16 christos /*ARGSUSED*/
522 1.1 cgd void
523 1.16 christos db_fncall(addr, have_addr, count, modif)
524 1.16 christos db_expr_t addr;
525 1.16 christos int have_addr;
526 1.16 christos db_expr_t count;
527 1.16 christos char * modif;
528 1.1 cgd {
529 1.1 cgd db_expr_t fn_addr;
530 1.1 cgd #define MAXARGS 11
531 1.1 cgd db_expr_t args[MAXARGS];
532 1.1 cgd int nargs = 0;
533 1.1 cgd db_expr_t retval;
534 1.16 christos db_expr_t (*func) __P((db_expr_t, ...));
535 1.1 cgd int t;
536 1.1 cgd
537 1.1 cgd if (!db_expression(&fn_addr)) {
538 1.1 cgd db_printf("Bad function\n");
539 1.1 cgd db_flush_lex();
540 1.1 cgd return;
541 1.1 cgd }
542 1.16 christos func = (db_expr_t (*) __P((db_expr_t, ...))) fn_addr;
543 1.1 cgd
544 1.1 cgd t = db_read_token();
545 1.1 cgd if (t == tLPAREN) {
546 1.1 cgd if (db_expression(&args[0])) {
547 1.1 cgd nargs++;
548 1.1 cgd while ((t = db_read_token()) == tCOMMA) {
549 1.1 cgd if (nargs == MAXARGS) {
550 1.1 cgd db_printf("Too many arguments\n");
551 1.1 cgd db_flush_lex();
552 1.1 cgd return;
553 1.1 cgd }
554 1.1 cgd if (!db_expression(&args[nargs])) {
555 1.1 cgd db_printf("Argument missing\n");
556 1.1 cgd db_flush_lex();
557 1.1 cgd return;
558 1.1 cgd }
559 1.1 cgd nargs++;
560 1.1 cgd }
561 1.1 cgd db_unread_token(t);
562 1.1 cgd }
563 1.1 cgd if (db_read_token() != tRPAREN) {
564 1.1 cgd db_printf("?\n");
565 1.1 cgd db_flush_lex();
566 1.1 cgd return;
567 1.1 cgd }
568 1.1 cgd }
569 1.1 cgd db_skip_to_eol();
570 1.1 cgd
571 1.1 cgd while (nargs < MAXARGS) {
572 1.1 cgd args[nargs++] = 0;
573 1.1 cgd }
574 1.1 cgd
575 1.1 cgd retval = (*func)(args[0], args[1], args[2], args[3], args[4],
576 1.20 christos args[5], args[6], args[7], args[8], args[9]);
577 1.21 mycroft db_printf("%#ln\n", retval);
578 1.23 scottr }
579 1.23 scottr
580 1.23 scottr void
581 1.23 scottr db_reboot_cmd(addr, have_addr, count, modif)
582 1.23 scottr db_expr_t addr;
583 1.23 scottr int have_addr;
584 1.23 scottr db_expr_t count;
585 1.23 scottr char * modif;
586 1.23 scottr {
587 1.23 scottr db_expr_t bootflags;
588 1.23 scottr
589 1.23 scottr /* Flags, default to RB_AUTOBOOT */
590 1.23 scottr if (!db_expression(&bootflags))
591 1.23 scottr bootflags = (db_expr_t)RB_AUTOBOOT;
592 1.23 scottr if (db_read_token() != tEOL) {
593 1.23 scottr db_error("?\n");
594 1.23 scottr /*NOTREACHED*/
595 1.23 scottr }
596 1.23 scottr cpu_reboot((int)bootflags, NULL);
597 1.1 cgd }
598