2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie the
24 * rights to redistribute these changes.
27 * Author: David B. Golub, Carnegie Mellon University
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/systm.h>
39 #include <ddb/db_lex.h>
40 #include <ddb/db_output.h>
41 #include <ddb/db_command.h>
42 #include <ddb/db_sym.h>
43 #include <ddb/db_access.h>
45 static char db_examine_format[TOK_STRING_SIZE] = "x";
47 static void db_examine(db_addr_t, char *, int);
48 static void db_search(db_addr_t, int, db_expr_t, db_expr_t, u_int);
51 * Examine (print) data.
55 db_examine_cmd(addr, have_addr, count, modif)
62 db_strcpy(db_examine_format, modif);
67 db_examine((db_addr_t) addr, db_examine_format, count);
71 db_examine(addr, fmt, count)
74 char * fmt; /* format string */
75 int count; /* repeat count */
83 while (--count >= 0 && !db_pager_quit) {
86 while ((c = *fp++) != 0) {
100 case 'a': /* address */
101 size = sizeof(void *);
102 /* always forces a new line */
103 if (db_print_position() != 0)
106 db_printsym(addr, DB_STGY_ANY);
110 if (db_print_position() == 0) {
111 /* Print the address. */
112 db_printsym(addr, DB_STGY_ANY);
119 case 'r': /* signed, current radix */
120 value = db_get_value(addr, size, TRUE);
122 db_printf("%+-*lr", width, (long)value);
124 case 'x': /* unsigned hex */
125 value = db_get_value(addr, size, FALSE);
127 db_printf("%-*lx", width, (long)value);
129 case 'z': /* signed hex */
130 value = db_get_value(addr, size, TRUE);
132 db_printf("%-*ly", width, (long)value);
134 case 'd': /* signed decimal */
135 value = db_get_value(addr, size, TRUE);
137 db_printf("%-*ld", width, (long)value);
139 case 'u': /* unsigned decimal */
140 value = db_get_value(addr, size, FALSE);
142 db_printf("%-*lu", width, (long)value);
144 case 'o': /* unsigned octal */
145 value = db_get_value(addr, size, FALSE);
147 db_printf("%-*lo", width, (long)value);
149 case 'c': /* character */
150 value = db_get_value(addr, 1, FALSE);
152 if (value >= ' ' && value <= '~')
153 db_printf("%c", (int)value);
155 db_printf("\\%03o", (int)value);
157 case 's': /* null-terminated string */
159 value = db_get_value(addr, 1, FALSE);
163 if (value >= ' ' && value <= '~')
164 db_printf("%c", (int)value);
166 db_printf("\\%03o", (int)value);
169 case 'S': /* symbol */
170 value = db_get_value(addr, sizeof(void *),
172 addr += sizeof(void *);
173 db_printsym(value, DB_STGY_ANY);
175 case 'i': /* instruction */
176 addr = db_disasm(addr, FALSE);
178 case 'I': /* instruction, alternate form */
179 addr = db_disasm(addr, TRUE);
184 if (db_print_position() != 0)
196 static char db_print_format = 'x';
200 db_print_cmd(addr, have_addr, count, modif)
208 if (modif[0] != '\0')
209 db_print_format = modif[0];
211 switch (db_print_format) {
213 db_printsym((db_addr_t)addr, DB_STGY_ANY);
216 db_printf("%+11lr", (long)addr);
219 db_printf("%8lx", (unsigned long)addr);
222 db_printf("%8ly", (long)addr);
225 db_printf("%11ld", (long)addr);
228 db_printf("%11lu", (unsigned long)addr);
231 db_printf("%16lo", (unsigned long)addr);
235 if (value >= ' ' && value <= '~')
236 db_printf("%c", (int)value);
238 db_printf("\\%03o", (int)value);
245 db_print_loc_and_inst(loc)
248 db_printsym(loc, DB_STGY_PROC);
250 (void) db_disasm(loc, TRUE);
254 * Search for a value in memory.
255 * Syntax: search [/bhl] addr value [mask] [,count]
258 db_search_cmd(dummy1, dummy2, dummy3, dummy4)
276 db_printf("Bad modifier\n");
281 if (!strcmp(db_tok_string, "b"))
283 else if (!strcmp(db_tok_string, "h"))
285 else if (!strcmp(db_tok_string, "l"))
294 if (!db_expression((db_expr_t *)&addr)) {
295 db_printf("Address missing\n");
300 if (!db_expression(&value)) {
301 db_printf("Value missing\n");
306 if (!db_expression(&mask))
311 if (!db_expression(&count)) {
312 db_printf("Count missing\n");
318 count = -1; /* effectively forever */
322 db_search(addr, size, value, mask, count);
326 db_search(addr, size, value, mask, count)
334 while (count-- != 0) {
336 if ((db_get_value(addr, size, FALSE) & mask) == value)