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.
30 * Author: David B. Golub, Carnegie Mellon University
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 __P((db_addr_t, char *, int));
48 static void db_search __P((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) {
87 while ((c = *fp++) != 0) {
105 case 'a': /* address */
106 /* always forces a new line */
107 if (db_print_position() != 0)
110 db_printsym(addr, DB_STGY_ANY);
114 if (db_print_position() == 0) {
115 /* Print the address. */
116 db_printsym(addr, DB_STGY_ANY);
122 case 'r': /* signed, current radix */
123 value = db_get_value(addr, size, TRUE);
125 db_printf("%+-*lr", width, (long)value);
127 case 'x': /* unsigned hex */
128 value = db_get_value(addr, size, FALSE);
130 db_printf("%-*lx", width, (long)value);
132 case 'z': /* signed hex */
133 value = db_get_value(addr, size, TRUE);
135 db_printf("%-*lz", width, (long)value);
137 case 'd': /* signed decimal */
138 value = db_get_value(addr, size, TRUE);
140 db_printf("%-*ld", width, (long)value);
142 case 'u': /* unsigned decimal */
143 value = db_get_value(addr, size, FALSE);
145 db_printf("%-*lu", width, (long)value);
147 case 'o': /* unsigned octal */
148 value = db_get_value(addr, size, FALSE);
150 db_printf("%-*lo", width, (long)value);
152 case 'c': /* character */
153 value = db_get_value(addr, 1, FALSE);
155 if (value >= ' ' && value <= '~')
156 db_printf("%c", (int)value);
158 db_printf("\\%03o", (int)value);
160 case 's': /* null-terminated string */
162 value = db_get_value(addr, 1, FALSE);
166 if (value >= ' ' && value <= '~')
167 db_printf("%c", (int)value);
169 db_printf("\\%03o", (int)value);
172 case 'i': /* instruction */
173 addr = db_disasm(addr, FALSE);
175 case 'I': /* instruction, alternate form */
176 addr = db_disasm(addr, TRUE);
181 if (db_print_position() != 0)
193 static char db_print_format = 'x';
197 db_print_cmd(addr, have_addr, count, modif)
205 if (modif[0] != '\0')
206 db_print_format = modif[0];
208 switch (db_print_format) {
210 db_printsym((db_addr_t)addr, DB_STGY_ANY);
213 db_printf("%+11lr", (long)addr);
216 db_printf("%8lx", (unsigned long)addr);
219 db_printf("%8lz", (long)addr);
222 db_printf("%11ld", (long)addr);
225 db_printf("%11lu", (unsigned long)addr);
228 db_printf("%16lo", (unsigned long)addr);
232 if (value >= ' ' && value <= '~')
233 db_printf("%c", (int)value);
235 db_printf("\\%03o", (int)value);
242 db_print_loc_and_inst(loc)
245 db_printsym(loc, DB_STGY_PROC);
247 (void) db_disasm(loc, TRUE);
251 * Search for a value in memory.
252 * Syntax: search [/bhl] addr value [mask] [,count]
255 db_search_cmd(dummy1, dummy2, dummy3, dummy4)
273 db_printf("Bad modifier\n");
278 if (!strcmp(db_tok_string, "b"))
280 else if (!strcmp(db_tok_string, "h"))
282 else if (!strcmp(db_tok_string, "l"))
291 if (!db_expression((db_expr_t *)&addr)) {
292 db_printf("Address missing\n");
297 if (!db_expression(&value)) {
298 db_printf("Value missing\n");
303 if (!db_expression(&mask))
308 if (!db_expression(&count)) {
309 db_printf("Count missing\n");
315 count = -1; /* effectively forever */
319 db_search(addr, size, value, mask, count);
323 db_search(addr, size, value, mask, count)
331 while (count-- != 0) {
333 if ((db_get_value(addr, size, FALSE) & mask) == value)