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