2 * SPDX-License-Identifier: MIT-CMU
4 * Mach Operating System
5 * Copyright (c) 1991,1990 Carnegie Mellon University
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
29 * Author: David B. Golub, Carnegie Mellon University
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/systm.h>
41 #include <ddb/db_lex.h>
42 #include <ddb/db_output.h>
43 #include <ddb/db_command.h>
44 #include <ddb/db_sym.h>
45 #include <ddb/db_access.h>
47 static char db_examine_format[TOK_STRING_SIZE] = "x";
49 static void db_examine(db_addr_t, char *, int);
50 static void db_search(db_addr_t, int, db_expr_t, db_expr_t, u_int);
53 * Examine (print) data.
57 db_examine_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif)
60 db_strcpy(db_examine_format, modif);
65 db_examine((db_addr_t) addr, db_examine_format, count);
69 db_examine(db_addr_t addr, char *fmt, int count)
77 while (--count >= 0 && !db_pager_quit) {
80 while ((c = *fp++) != 0) {
94 case 'a': /* address */
95 size = sizeof(void *);
96 /* always forces a new line */
97 if (db_print_position() != 0)
100 db_printsym(addr, DB_STGY_ANY);
104 if (db_print_position() == 0) {
105 /* Print the address. */
106 db_printsym(addr, DB_STGY_ANY);
113 case 'r': /* signed, current radix */
114 value = db_get_value(addr, size, true);
116 db_printf("%+-*lr", width, (long)value);
118 case 'x': /* unsigned hex */
119 value = db_get_value(addr, size, false);
121 db_printf("%-*lx", width, (long)value);
123 case 'z': /* signed hex */
124 value = db_get_value(addr, size, true);
126 db_printf("%-*ly", width, (long)value);
128 case 'd': /* signed decimal */
129 value = db_get_value(addr, size, true);
131 db_printf("%-*ld", width, (long)value);
133 case 'u': /* unsigned decimal */
134 value = db_get_value(addr, size, false);
136 db_printf("%-*lu", width, (long)value);
138 case 'o': /* unsigned octal */
139 value = db_get_value(addr, size, false);
141 db_printf("%-*lo", width, (long)value);
143 case 'c': /* character */
144 value = db_get_value(addr, 1, false);
146 if (value >= ' ' && value <= '~')
147 db_printf("%c", (int)value);
149 db_printf("\\%03o", (int)value);
151 case 's': /* null-terminated string */
153 value = db_get_value(addr, 1, false);
157 if (value >= ' ' && value <= '~')
158 db_printf("%c", (int)value);
160 db_printf("\\%03o", (int)value);
163 case 'S': /* symbol */
164 value = db_get_value(addr, sizeof(void *),
166 addr += sizeof(void *);
167 db_printsym(value, DB_STGY_ANY);
169 case 'i': /* instruction */
170 addr = db_disasm(addr, false);
172 case 'I': /* instruction, alternate form */
173 addr = db_disasm(addr, true);
178 if (db_print_position() != 0)
190 static char db_print_format = 'x';
194 db_print_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif)
198 if (modif[0] != '\0')
199 db_print_format = modif[0];
201 switch (db_print_format) {
203 db_printsym((db_addr_t)addr, DB_STGY_ANY);
206 db_printf("%+11lr", (long)addr);
209 db_printf("%8lx", (unsigned long)addr);
212 db_printf("%8ly", (long)addr);
215 db_printf("%11ld", (long)addr);
218 db_printf("%11lu", (unsigned long)addr);
221 db_printf("%16lo", (unsigned long)addr);
225 if (value >= ' ' && value <= '~')
226 db_printf("%c", (int)value);
228 db_printf("\\%03o", (int)value);
231 db_print_format = 'x';
232 db_error("Syntax error: unsupported print modifier\n");
239 db_print_loc_and_inst(db_addr_t loc)
243 db_printsym(loc, DB_STGY_PROC);
244 if (db_search_symbol(loc, DB_STGY_PROC, &off) != C_DB_SYM_NULL) {
246 (void)db_disasm(loc, false);
251 * Search for a value in memory.
252 * Syntax: search [/bhl] addr value [mask] [,count]
255 db_search_cmd(db_expr_t dummy1, bool dummy2, db_expr_t dummy3, char *dummy4)
269 db_printf("Bad modifier\n");
274 if (!strcmp(db_tok_string, "b"))
276 else if (!strcmp(db_tok_string, "h"))
278 else if (!strcmp(db_tok_string, "l"))
287 if (!db_expression((db_expr_t *)&addr)) {
288 db_printf("Address missing\n");
293 if (!db_expression(&value)) {
294 db_printf("Value missing\n");
299 if (!db_expression(&mask))
304 if (!db_expression(&count)) {
305 db_printf("Count missing\n");
311 count = -1; /* effectively forever */
315 db_search(addr, size, value, mask, count);
319 db_search(db_addr_t addr, int size, db_expr_t value, db_expr_t mask,
322 while (count-- != 0) {
324 if ((db_get_value(addr, size, false) & mask) == value)