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.6 2005/12/23 21:35:44 swildner 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 (db_addr_t, char *, int);
49 static void db_search (db_addr_t, int, db_expr_t, db_expr_t, u_int);
52 * Examine (print) data.
56 db_examine_cmd(db_expr_t addr, boolean_t have_addr, db_expr_t count,
60 db_strcpy(db_examine_format, modif);
65 db_examine((db_addr_t) addr, db_examine_format, count);
74 db_examine(db_addr_t addr, char *fmt, int count)
82 while (--count >= 0) {
86 while ((c = *fp++) != 0) {
104 case 'a': /* address */
105 /* always forces a new line */
106 if (db_print_position() != 0)
109 db_printsym(addr, DB_STGY_ANY);
113 if (db_print_position() == 0) {
114 /* Print the address. */
115 db_printsym(addr, DB_STGY_ANY);
121 case 'r': /* signed, current radix */
122 value = db_get_value(addr, size, TRUE);
124 db_printf("%+-*lr", width, (long)value);
126 case 'x': /* unsigned hex */
127 value = db_get_value(addr, size, FALSE);
129 db_printf("%-*lx", width, (long)value);
131 case 'z': /* signed hex */
132 value = db_get_value(addr, size, TRUE);
134 db_printf("%-*lz", width, (long)value);
136 case 'd': /* signed decimal */
137 value = db_get_value(addr, size, TRUE);
139 db_printf("%-*ld", width, (long)value);
141 case 'u': /* unsigned decimal */
142 value = db_get_value(addr, size, FALSE);
144 db_printf("%-*lu", width, (long)value);
146 case 'o': /* unsigned octal */
147 value = db_get_value(addr, size, FALSE);
149 db_printf("%-*lo", width, (long)value);
151 case 'c': /* character */
152 value = db_get_value(addr, 1, FALSE);
154 if (value >= ' ' && value <= '~')
155 db_printf("%c", (int)value);
157 db_printf("\\%03o", (int)value);
159 case 's': /* null-terminated string */
161 value = db_get_value(addr, 1, FALSE);
165 if (value >= ' ' && value <= '~')
166 db_printf("%c", (int)value);
168 db_printf("\\%03o", (int)value);
171 case 'i': /* instruction */
172 addr = db_disasm(addr, FALSE, NULL);
174 case 'I': /* instruction, alternate form */
175 addr = db_disasm(addr, TRUE, NULL);
180 if (db_print_position() != 0)
192 static char db_print_format = 'x';
196 db_print_cmd(db_expr_t addr, boolean_t have_addr, db_expr_t count, char *modif)
200 if (modif[0] != '\0')
201 db_print_format = modif[0];
203 switch (db_print_format) {
205 db_printsym((db_addr_t)addr, DB_STGY_ANY);
208 db_printf("%+11lr", (long)addr);
211 db_printf("%8lx", (unsigned long)addr);
214 db_printf("%8lz", (long)addr);
217 db_printf("%11ld", (long)addr);
220 db_printf("%11lu", (unsigned long)addr);
223 db_printf("%16lo", (unsigned long)addr);
227 if (value >= ' ' && value <= '~')
228 db_printf("%c", (int)value);
230 db_printf("\\%03o", (int)value);
237 db_print_loc_and_inst(db_addr_t loc, db_regs_t *regs)
239 db_printsym(loc, DB_STGY_PROC);
241 db_disasm(loc, TRUE, regs);
245 * Search for a value in memory.
246 * Syntax: search [/bhl] addr value [mask] [,count]
249 db_search_cmd(db_expr_t dummy1, boolean_t dummy2, db_expr_t dummy3,
264 db_printf("Bad modifier\n");
269 if (!strcmp(db_tok_string, "b"))
271 else if (!strcmp(db_tok_string, "h"))
273 else if (!strcmp(db_tok_string, "l"))
282 if (!db_expression((db_expr_t *)&addr)) {
283 db_printf("Address missing\n");
288 if (!db_expression(&value)) {
289 db_printf("Value missing\n");
294 if (!db_expression(&mask))
299 if (!db_expression(&count)) {
300 db_printf("Count missing\n");
306 count = -1; /* effectively forever */
310 db_search(addr, size, value, mask, count);
314 db_search(db_addr_t addr, int size, db_expr_t value, db_expr_t mask,
317 while (count-- != 0) {
319 if ((db_get_value(addr, size, FALSE) & mask) == value)