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(db_expr_t addr, bool have_addr, db_expr_t count, char *modif)
58 db_strcpy(db_examine_format, modif);
63 db_examine((db_addr_t) addr, db_examine_format, count);
67 db_examine(db_addr_t addr, char *fmt, int count)
75 while (--count >= 0 && !db_pager_quit) {
78 while ((c = *fp++) != 0) {
92 case 'a': /* address */
93 size = sizeof(void *);
94 /* always forces a new line */
95 if (db_print_position() != 0)
98 db_printsym(addr, DB_STGY_ANY);
102 if (db_print_position() == 0) {
103 /* Print the address. */
104 db_printsym(addr, DB_STGY_ANY);
111 case 'r': /* signed, current radix */
112 value = db_get_value(addr, size, true);
114 db_printf("%+-*lr", width, (long)value);
116 case 'x': /* unsigned hex */
117 value = db_get_value(addr, size, false);
119 db_printf("%-*lx", width, (long)value);
121 case 'z': /* signed hex */
122 value = db_get_value(addr, size, true);
124 db_printf("%-*ly", width, (long)value);
126 case 'd': /* signed decimal */
127 value = db_get_value(addr, size, true);
129 db_printf("%-*ld", width, (long)value);
131 case 'u': /* unsigned decimal */
132 value = db_get_value(addr, size, false);
134 db_printf("%-*lu", width, (long)value);
136 case 'o': /* unsigned octal */
137 value = db_get_value(addr, size, false);
139 db_printf("%-*lo", width, (long)value);
141 case 'c': /* character */
142 value = db_get_value(addr, 1, false);
144 if (value >= ' ' && value <= '~')
145 db_printf("%c", (int)value);
147 db_printf("\\%03o", (int)value);
149 case 's': /* null-terminated string */
151 value = db_get_value(addr, 1, false);
155 if (value >= ' ' && value <= '~')
156 db_printf("%c", (int)value);
158 db_printf("\\%03o", (int)value);
161 case 'S': /* symbol */
162 value = db_get_value(addr, sizeof(void *),
164 addr += sizeof(void *);
165 db_printsym(value, DB_STGY_ANY);
167 case 'i': /* instruction */
168 addr = db_disasm(addr, false);
170 case 'I': /* instruction, alternate form */
171 addr = db_disasm(addr, true);
176 if (db_print_position() != 0)
188 static char db_print_format = 'x';
192 db_print_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif)
196 if (modif[0] != '\0')
197 db_print_format = modif[0];
199 switch (db_print_format) {
201 db_printsym((db_addr_t)addr, DB_STGY_ANY);
204 db_printf("%+11lr", (long)addr);
207 db_printf("%8lx", (unsigned long)addr);
210 db_printf("%8ly", (long)addr);
213 db_printf("%11ld", (long)addr);
216 db_printf("%11lu", (unsigned long)addr);
219 db_printf("%16lo", (unsigned long)addr);
223 if (value >= ' ' && value <= '~')
224 db_printf("%c", (int)value);
226 db_printf("\\%03o", (int)value);
229 db_print_format = 'x';
230 db_error("Syntax error: unsupported print modifier\n");
237 db_print_loc_and_inst(db_addr_t loc)
241 db_printsym(loc, DB_STGY_PROC);
242 if (db_search_symbol(loc, DB_STGY_PROC, &off) != C_DB_SYM_NULL) {
244 (void)db_disasm(loc, true);
249 * Search for a value in memory.
250 * Syntax: search [/bhl] addr value [mask] [,count]
253 db_search_cmd(db_expr_t dummy1, bool dummy2, db_expr_t dummy3, char *dummy4)
267 db_printf("Bad modifier\n");
272 if (!strcmp(db_tok_string, "b"))
274 else if (!strcmp(db_tok_string, "h"))
276 else if (!strcmp(db_tok_string, "l"))
285 if (!db_expression((db_expr_t *)&addr)) {
286 db_printf("Address missing\n");
291 if (!db_expression(&value)) {
292 db_printf("Value missing\n");
297 if (!db_expression(&mask))
302 if (!db_expression(&count)) {
303 db_printf("Count missing\n");
309 count = -1; /* effectively forever */
313 db_search(addr, size, value, mask, count);
317 db_search(db_addr_t addr, int size, db_expr_t value, db_expr_t mask,
320 while (count-- != 0) {
322 if ((db_get_value(addr, size, false) & mask) == value)