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 $
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 (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
, boolean_t have_addr
, db_expr_t count
,
59 db_strcpy(db_examine_format
, modif
);
64 db_examine((db_addr_t
) addr
, db_examine_format
, count
);
73 db_examine(db_addr_t addr
, char *fmt
, int count
)
82 while (--count
>= 0) {
86 while ((c
= *fp
++) != 0) {
105 if (db_print_position() == 0) {
106 /* Print the address. */
107 db_printsym(addr
, DB_STGY_ANY
);
114 size
= sizeof(void *);
115 value
= db_get_value(addr
, size
, TRUE
);
117 db_printsym(value
, DB_STGY_ANY
);
120 size
= sizeof(void *);
121 value
= db_get_value(addr
, size
, TRUE
);
123 db_printf("%p", (void *)value
);
125 case 'r': /* signed, current radix */
126 value
= db_get_value(addr
, size
, TRUE
);
128 db_format_radix(tbuf
, 24, value
, FALSE
);
129 db_printf("%-*s", width
, tbuf
);
131 case 'x': /* unsigned hex */
132 value
= db_get_value(addr
, size
, FALSE
);
134 db_printf("%-*lx", width
, (long)value
);
136 case 'z': /* signed hex */
137 value
= db_get_value(addr
, size
, TRUE
);
139 db_format_hex(tbuf
, 24, value
, FALSE
);
140 db_printf("%-*s", width
, tbuf
);
142 case 'd': /* signed decimal */
143 value
= db_get_value(addr
, size
, TRUE
);
145 db_printf("%-*ld", width
, (long)value
);
147 case 'u': /* unsigned decimal */
148 value
= db_get_value(addr
, size
, FALSE
);
150 db_printf("%-*lu", width
, (long)value
);
152 case 'o': /* unsigned octal */
153 value
= db_get_value(addr
, size
, FALSE
);
155 db_printf("%-*lo", width
, (long)value
);
157 case 'c': /* character */
158 value
= db_get_value(addr
, 1, FALSE
);
160 if (value
>= ' ' && value
<= '~')
161 db_printf("%c", (int)value
);
163 db_printf("\\%03o", (int)value
);
165 case 's': /* null-terminated string */
167 value
= db_get_value(addr
, 1, FALSE
);
171 if (value
>= ' ' && value
<= '~')
172 db_printf("%c", (int)value
);
174 db_printf("\\%03o", (int)value
);
177 case 'i': /* instruction */
178 addr
= db_disasm(addr
, FALSE
, NULL
);
180 case 'I': /* instruction, alternate form */
181 addr
= db_disasm(addr
, TRUE
, NULL
);
186 if (db_print_position() != 0 ||
187 c
== 'a' || c
== 'p') {
200 static char db_print_format
= 'x';
204 db_print_cmd(db_expr_t addr
, boolean_t have_addr
, db_expr_t count
, char *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
);
219 db_format_radix(tbuf
, 24, addr
, FALSE
);
220 db_printf("%11s", tbuf
);
224 db_printf("%8lx", (unsigned long)addr
);
230 db_format_hex(tbuf
, 24, addr
, FALSE
);
231 db_printf("%8s", tbuf
);
235 db_printf("%11ld", (long)addr
);
238 db_printf("%11lu", (unsigned long)addr
);
241 db_printf("%16lo", (unsigned long)addr
);
245 if (value
>= ' ' && value
<= '~')
246 db_printf("%c", (int)value
);
248 db_printf("\\%03o", (int)value
);
255 db_print_loc_and_inst(db_addr_t loc
, db_regs_t
*regs
)
257 db_printsym(loc
, DB_STGY_PROC
);
259 db_disasm(loc
, TRUE
, regs
);
263 * Search for a value in memory.
264 * Syntax: search [/bhl] addr value [mask] [,count]
267 db_search_cmd(db_expr_t dummy1
, boolean_t dummy2
, db_expr_t dummy3
,
282 db_printf("Bad modifier\n");
287 if (!strcmp(db_tok_string
, "b"))
289 else if (!strcmp(db_tok_string
, "h"))
291 else if (!strcmp(db_tok_string
, "l"))
300 if (!db_expression((db_expr_t
*)&addr
)) {
301 db_printf("Address missing\n");
306 if (!db_expression(&value
)) {
307 db_printf("Value missing\n");
312 if (!db_expression(&mask
))
317 if (!db_expression(&count
)) {
318 db_printf("Count missing\n");
324 count
= -1; /* effectively forever */
328 db_search(addr
, size
, value
, mask
, count
);
332 db_search(db_addr_t addr
, int size
, db_expr_t value
, db_expr_t mask
,
335 while (count
-- != 0) {
337 if ((db_get_value(addr
, size
, FALSE
) & mask
) == value
)