2005-01-06 01:34:41 +00:00
|
|
|
/*-
|
1993-06-12 14:58:17 +00:00
|
|
|
* Mach Operating System
|
|
|
|
* Copyright (c) 1991,1990 Carnegie Mellon University
|
|
|
|
* All Rights Reserved.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* Permission to use, copy, modify and distribute this software and its
|
|
|
|
* documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
|
1993-06-12 14:58:17 +00:00
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
|
|
|
|
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* Carnegie Mellon requests users of this software to return to
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Author: David B. Golub, Carnegie Mellon University
|
|
|
|
* Date: 7/90
|
|
|
|
*/
|
1999-05-13 06:07:44 +00:00
|
|
|
|
2003-06-10 22:09:23 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/param.h>
|
1999-05-13 06:07:44 +00:00
|
|
|
#include <sys/systm.h>
|
1993-11-25 01:38:01 +00:00
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <ddb/ddb.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <ddb/db_lex.h>
|
|
|
|
#include <ddb/db_output.h>
|
|
|
|
#include <ddb/db_command.h>
|
|
|
|
#include <ddb/db_sym.h>
|
|
|
|
#include <ddb/db_access.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-11-29 10:25:50 +00:00
|
|
|
static char db_examine_format[TOK_STRING_SIZE] = "x";
|
1993-06-12 14:58:17 +00:00
|
|
|
|
2002-03-20 05:14:42 +00:00
|
|
|
static void db_examine(db_addr_t, char *, int);
|
|
|
|
static void db_search(db_addr_t, int, db_expr_t, db_expr_t, u_int);
|
1993-11-25 01:38:01 +00:00
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
/*
|
|
|
|
* Examine (print) data.
|
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
2014-10-12 18:01:52 +00:00
|
|
|
db_examine_cmd(db_expr_t addr, boolean_t have_addr, db_expr_t count,
|
|
|
|
char *modif)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
if (modif[0] != '\0')
|
|
|
|
db_strcpy(db_examine_format, modif);
|
|
|
|
|
|
|
|
if (count == -1)
|
|
|
|
count = 1;
|
|
|
|
|
|
|
|
db_examine((db_addr_t) addr, db_examine_format, count);
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static void
|
2014-10-12 18:01:52 +00:00
|
|
|
db_examine(db_addr_t addr, char *fmt, int count)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
db_expr_t value;
|
|
|
|
int size;
|
|
|
|
int width;
|
|
|
|
char * fp;
|
|
|
|
|
2007-10-27 20:19:11 +00:00
|
|
|
while (--count >= 0 && !db_pager_quit) {
|
1993-06-12 14:58:17 +00:00
|
|
|
fp = fmt;
|
|
|
|
size = 4;
|
|
|
|
while ((c = *fp++) != 0) {
|
|
|
|
switch (c) {
|
|
|
|
case 'b':
|
|
|
|
size = 1;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
size = 2;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
size = 4;
|
|
|
|
break;
|
1998-07-05 10:10:33 +00:00
|
|
|
case 'g':
|
|
|
|
size = 8;
|
|
|
|
break;
|
1993-06-12 14:58:17 +00:00
|
|
|
case 'a': /* address */
|
2002-06-25 15:59:24 +00:00
|
|
|
size = sizeof(void *);
|
1993-06-12 14:58:17 +00:00
|
|
|
/* always forces a new line */
|
|
|
|
if (db_print_position() != 0)
|
|
|
|
db_printf("\n");
|
|
|
|
db_prev = addr;
|
|
|
|
db_printsym(addr, DB_STGY_ANY);
|
|
|
|
db_printf(":\t");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (db_print_position() == 0) {
|
1995-05-22 13:07:12 +00:00
|
|
|
/* Print the address. */
|
|
|
|
db_printsym(addr, DB_STGY_ANY);
|
|
|
|
db_printf(":\t");
|
1993-06-12 14:58:17 +00:00
|
|
|
db_prev = addr;
|
|
|
|
}
|
|
|
|
|
2002-06-25 15:59:24 +00:00
|
|
|
width = size * 4;
|
1993-06-12 14:58:17 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'r': /* signed, current radix */
|
2015-05-18 22:27:46 +00:00
|
|
|
value = db_get_value(addr, size, true);
|
1993-06-12 14:58:17 +00:00
|
|
|
addr += size;
|
1999-07-01 19:42:56 +00:00
|
|
|
db_printf("%+-*lr", width, (long)value);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
case 'x': /* unsigned hex */
|
2015-05-18 22:27:46 +00:00
|
|
|
value = db_get_value(addr, size, false);
|
1993-06-12 14:58:17 +00:00
|
|
|
addr += size;
|
1999-07-01 19:42:56 +00:00
|
|
|
db_printf("%-*lx", width, (long)value);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
case 'z': /* signed hex */
|
2015-05-18 22:27:46 +00:00
|
|
|
value = db_get_value(addr, size, true);
|
1993-06-12 14:58:17 +00:00
|
|
|
addr += size;
|
2002-10-25 19:41:32 +00:00
|
|
|
db_printf("%-*ly", width, (long)value);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
case 'd': /* signed decimal */
|
2015-05-18 22:27:46 +00:00
|
|
|
value = db_get_value(addr, size, true);
|
1993-06-12 14:58:17 +00:00
|
|
|
addr += size;
|
1999-07-01 19:42:56 +00:00
|
|
|
db_printf("%-*ld", width, (long)value);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
case 'u': /* unsigned decimal */
|
2015-05-18 22:27:46 +00:00
|
|
|
value = db_get_value(addr, size, false);
|
1993-06-12 14:58:17 +00:00
|
|
|
addr += size;
|
1999-07-01 19:42:56 +00:00
|
|
|
db_printf("%-*lu", width, (long)value);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
case 'o': /* unsigned octal */
|
2015-05-18 22:27:46 +00:00
|
|
|
value = db_get_value(addr, size, false);
|
1993-06-12 14:58:17 +00:00
|
|
|
addr += size;
|
1999-07-01 19:42:56 +00:00
|
|
|
db_printf("%-*lo", width, (long)value);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
case 'c': /* character */
|
2015-05-18 22:27:46 +00:00
|
|
|
value = db_get_value(addr, 1, false);
|
1993-06-12 14:58:17 +00:00
|
|
|
addr += 1;
|
|
|
|
if (value >= ' ' && value <= '~')
|
1999-07-01 19:42:56 +00:00
|
|
|
db_printf("%c", (int)value);
|
1993-06-12 14:58:17 +00:00
|
|
|
else
|
1999-07-01 19:42:56 +00:00
|
|
|
db_printf("\\%03o", (int)value);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
case 's': /* null-terminated string */
|
|
|
|
for (;;) {
|
2015-05-18 22:27:46 +00:00
|
|
|
value = db_get_value(addr, 1, false);
|
1993-06-12 14:58:17 +00:00
|
|
|
addr += 1;
|
|
|
|
if (value == 0)
|
|
|
|
break;
|
|
|
|
if (value >= ' ' && value <= '~')
|
1999-07-01 19:42:56 +00:00
|
|
|
db_printf("%c", (int)value);
|
1993-06-12 14:58:17 +00:00
|
|
|
else
|
1999-07-01 19:42:56 +00:00
|
|
|
db_printf("\\%03o", (int)value);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-03-07 18:09:07 +00:00
|
|
|
case 'S': /* symbol */
|
|
|
|
value = db_get_value(addr, sizeof(void *),
|
2015-05-18 22:27:46 +00:00
|
|
|
false);
|
2008-03-07 18:09:07 +00:00
|
|
|
addr += sizeof(void *);
|
|
|
|
db_printsym(value, DB_STGY_ANY);
|
|
|
|
break;
|
1993-06-12 14:58:17 +00:00
|
|
|
case 'i': /* instruction */
|
2015-05-18 22:27:46 +00:00
|
|
|
addr = db_disasm(addr, false);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
case 'I': /* instruction, alternate form */
|
2015-05-18 22:27:46 +00:00
|
|
|
addr = db_disasm(addr, true);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (db_print_position() != 0)
|
2006-10-08 18:15:08 +00:00
|
|
|
db_end_line(1);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
db_next = addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print value.
|
|
|
|
*/
|
1995-11-29 10:25:50 +00:00
|
|
|
static char db_print_format = 'x';
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
/*ARGSUSED*/
|
|
|
|
void
|
2014-10-12 18:01:52 +00:00
|
|
|
db_print_cmd(db_expr_t addr, boolean_t have_addr, db_expr_t count,
|
|
|
|
char *modif)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
db_expr_t value;
|
|
|
|
|
|
|
|
if (modif[0] != '\0')
|
|
|
|
db_print_format = modif[0];
|
|
|
|
|
|
|
|
switch (db_print_format) {
|
|
|
|
case 'a':
|
|
|
|
db_printsym((db_addr_t)addr, DB_STGY_ANY);
|
|
|
|
break;
|
|
|
|
case 'r':
|
1998-07-08 10:53:58 +00:00
|
|
|
db_printf("%+11lr", (long)addr);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
case 'x':
|
1998-07-08 06:27:22 +00:00
|
|
|
db_printf("%8lx", (unsigned long)addr);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
case 'z':
|
2002-10-25 19:41:32 +00:00
|
|
|
db_printf("%8ly", (long)addr);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
case 'd':
|
1998-07-08 06:27:22 +00:00
|
|
|
db_printf("%11ld", (long)addr);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
case 'u':
|
1998-07-08 06:27:22 +00:00
|
|
|
db_printf("%11lu", (unsigned long)addr);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
case 'o':
|
1998-07-08 06:27:22 +00:00
|
|
|
db_printf("%16lo", (unsigned long)addr);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
value = addr & 0xFF;
|
|
|
|
if (value >= ' ' && value <= '~')
|
1999-07-01 19:42:56 +00:00
|
|
|
db_printf("%c", (int)value);
|
1993-06-12 14:58:17 +00:00
|
|
|
else
|
1999-07-01 19:42:56 +00:00
|
|
|
db_printf("\\%03o", (int)value);
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
db_printf("\n");
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
void
|
2014-10-12 18:01:52 +00:00
|
|
|
db_print_loc_and_inst(db_addr_t loc)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
db_printsym(loc, DB_STGY_PROC);
|
|
|
|
db_printf(":\t");
|
2015-05-18 22:27:46 +00:00
|
|
|
(void) db_disasm(loc, true);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search for a value in memory.
|
|
|
|
* Syntax: search [/bhl] addr value [mask] [,count]
|
|
|
|
*/
|
|
|
|
void
|
2014-10-12 18:01:52 +00:00
|
|
|
db_search_cmd(db_expr_t dummy1, boolean_t dummy2, db_expr_t dummy3,
|
|
|
|
char *dummy4)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
int t;
|
|
|
|
db_addr_t addr;
|
|
|
|
int size;
|
|
|
|
db_expr_t value;
|
|
|
|
db_expr_t mask;
|
1998-06-10 10:57:29 +00:00
|
|
|
db_expr_t count;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
t = db_read_token();
|
|
|
|
if (t == tSLASH) {
|
|
|
|
t = db_read_token();
|
|
|
|
if (t != tIDENT) {
|
|
|
|
bad_modifier:
|
|
|
|
db_printf("Bad modifier\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(db_tok_string, "b"))
|
|
|
|
size = 1;
|
|
|
|
else if (!strcmp(db_tok_string, "h"))
|
|
|
|
size = 2;
|
|
|
|
else if (!strcmp(db_tok_string, "l"))
|
|
|
|
size = 4;
|
|
|
|
else
|
|
|
|
goto bad_modifier;
|
|
|
|
} else {
|
|
|
|
db_unread_token(t);
|
|
|
|
size = 4;
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
if (!db_expression((db_expr_t *)&addr)) {
|
1993-06-12 14:58:17 +00:00
|
|
|
db_printf("Address missing\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!db_expression(&value)) {
|
|
|
|
db_printf("Value missing\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!db_expression(&mask))
|
1993-12-19 00:55:01 +00:00
|
|
|
mask = 0xffffffffUL;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
t = db_read_token();
|
|
|
|
if (t == tCOMMA) {
|
|
|
|
if (!db_expression(&count)) {
|
|
|
|
db_printf("Count missing\n");
|
|
|
|
db_flush_lex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
db_unread_token(t);
|
|
|
|
count = -1; /* effectively forever */
|
|
|
|
}
|
|
|
|
db_skip_to_eol();
|
|
|
|
|
|
|
|
db_search(addr, size, value, mask, count);
|
|
|
|
}
|
|
|
|
|
1993-11-25 01:38:01 +00:00
|
|
|
static void
|
2014-10-12 18:01:52 +00:00
|
|
|
db_search(db_addr_t addr, int size, db_expr_t value, db_expr_t mask,
|
|
|
|
unsigned int count)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
while (count-- != 0) {
|
|
|
|
db_prev = addr;
|
2015-05-18 22:27:46 +00:00
|
|
|
if ((db_get_value(addr, size, false) & mask) == value)
|
1993-06-12 14:58:17 +00:00
|
|
|
break;
|
|
|
|
addr += size;
|
|
|
|
}
|
|
|
|
db_next = addr;
|
|
|
|
}
|