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.
26 * $FreeBSD: src/sys/ddb/db_examine.c,v 1.27 1999/08/28 00:41:07 peter Exp $
27 * $DragonFly: src/sys/ddb/db_examine.c,v 1.3 2003/07/26 14:18:51 rob Exp $
31 * Author: David B. Golub, Carnegie Mellon University
35 #include <sys/param.h>
36 #include <sys/systm.h>
40 #include <ddb/db_lex.h>
41 #include <ddb/db_output.h>
42 #include <ddb/db_command.h>
43 #include <ddb/db_sym.h>
44 #include <ddb/db_access.h>
46 static char db_examine_format[TOK_STRING_SIZE] = "x";
48 static void db_examine __P((db_addr_t, char *, int));
49 static void db_search __P((db_addr_t, int, db_expr_t, db_expr_t, u_int));
52 * Examine (print) data.
56 db_examine_cmd(addr, have_addr, count, modif)
63 db_strcpy(db_examine_format, modif);
68 db_examine((db_addr_t) addr, db_examine_format, count);
72 db_examine(addr, fmt, count)
75 char * fmt; /* format string */
76 int count; /* repeat count */
84 while (--count >= 0) {
88 while ((c = *fp++) != 0) {
106 case 'a': /* address */
107 /* always forces a new line */
108 if (db_print_position() != 0)
111 db_printsym(addr, DB_STGY_ANY);
115 if (db_print_position() == 0) {
116 /* Print the address. */
117 db_printsym(addr, DB_STGY_ANY);
123 case 'r': /* signed, current radix */
124 value = db_get_value(addr, size, TRUE);
126 db_printf("%+-*lr", width, (long)value);
128 case 'x': /* unsigned hex */
129 value = db_get_value(addr, size, FALSE);
131 db_printf("%-*lx", width, (long)value);
133 case 'z': /* signed hex */
134 value = db_get_value(addr, size, TRUE);
136 db_printf("%-*lz", width, (long)value);
138 case 'd': /* signed decimal */
139 value = db_get_value(addr, size, TRUE);
141 db_printf("%-*ld", width, (long)value);
143 case 'u': /* unsigned decimal */
144 value = db_get_value(addr, size, FALSE);
146 db_printf("%-*lu", width, (long)value);
148 case 'o': /* unsigned octal */
149 value = db_get_value(addr, size, FALSE);
151 db_printf("%-*lo", width, (long)value);
153 case 'c': /* character */
154 value = db_get_value(addr, 1, FALSE);
156 if (value >= ' ' && value <= '~')
157 db_printf("%c", (int)value);
159 db_printf("\\%03o", (int)value);
161 case 's': /* null-terminated string */
163 value = db_get_value(addr, 1, FALSE);
167 if (value >= ' ' && value <= '~')
168 db_printf("%c", (int)value);
170 db_printf("\\%03o", (int)value);
173 case 'i': /* instruction */
174 addr = db_disasm(addr, FALSE);
176 case 'I': /* instruction, alternate form */
177 addr = db_disasm(addr, TRUE);
182 if (db_print_position() != 0)
194 static char db_print_format = 'x';
198 db_print_cmd(addr, have_addr, count, modif)
206 if (modif[0] != '\0')
207 db_print_format = modif[0];
209 switch (db_print_format) {
211 db_printsym((db_addr_t)addr, DB_STGY_ANY);
214 db_printf("%+11lr", (long)addr);
217 db_printf("%8lx", (unsigned long)addr);
220 db_printf("%8lz", (long)addr);
223 db_printf("%11ld", (long)addr);
226 db_printf("%11lu", (unsigned long)addr);
229 db_printf("%16lo", (unsigned long)addr);
233 if (value >= ' ' && value <= '~')
234 db_printf("%c", (int)value);
236 db_printf("\\%03o", (int)value);
243 db_print_loc_and_inst(loc)
246 db_printsym(loc, DB_STGY_PROC);
248 (void) db_disasm(loc, TRUE);
252 * Search for a value in memory.
253 * Syntax: search [/bhl] addr value [mask] [,count]
256 db_search_cmd(dummy1, dummy2, dummy3, dummy4)
274 db_printf("Bad modifier\n");
279 if (!strcmp(db_tok_string, "b"))
281 else if (!strcmp(db_tok_string, "h"))
283 else if (!strcmp(db_tok_string, "l"))
292 if (!db_expression((db_expr_t *)&addr)) {
293 db_printf("Address missing\n");
298 if (!db_expression(&value)) {
299 db_printf("Value missing\n");
304 if (!db_expression(&mask))
309 if (!db_expression(&count)) {
310 db_printf("Count missing\n");
316 count = -1; /* effectively forever */
320 db_search(addr, size, value, mask, count);
324 db_search(addr, size, value, mask, count)
332 while (count-- != 0) {
334 if ((db_get_value(addr, size, FALSE) & mask) == value)