NetBSD/sys/ddb/db_examine.c

328 lines
6.6 KiB
C
Raw Normal View History

/* $NetBSD: db_examine.c,v 1.9 1994/11/17 04:51:50 gwr Exp $ */
1994-10-06 08:20:42 +03:00
/*
1993-03-21 12:45:37 +03:00
* Mach Operating System
* Copyright (c) 1991,1990 Carnegie Mellon University
* All Rights Reserved.
1994-10-06 08:20:42 +03:00
*
1993-03-21 12:45:37 +03: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.
1994-10-06 08:20:42 +03:00
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
1993-03-21 12:45:37 +03:00
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
1994-10-06 08:20:42 +03:00
*
1993-03-21 12:45:37 +03:00
* Carnegie Mellon requests users of this software to return to
1994-10-06 08:20:42 +03:00
*
1993-03-21 12:45:37 +03:00
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
1994-10-06 08:20:42 +03:00
*
1993-03-21 12:45:37 +03:00
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
1993-05-20 07:39:04 +04:00
*
1993-03-21 12:45:37 +03:00
* Author: David B. Golub, Carnegie Mellon University
* Date: 7/90
*/
1993-12-18 07:46:25 +03:00
#include <sys/param.h>
#include <sys/proc.h>
1993-03-21 12:45:37 +03:00
#include <machine/db_machdep.h> /* type definitions */
#include <ddb/db_lex.h>
#include <ddb/db_output.h>
#include <ddb/db_command.h>
#include <ddb/db_sym.h>
char db_examine_format[TOK_STRING_SIZE] = "x";
extern db_addr_t db_disasm(/* db_addr_t, boolean_t */);
/* instruction disassembler */
/*
* Examine (print) data. Syntax is:
* x/[bhl][cdiorsuxz]*
* For example, the command:
* x/bxxxx
* should print:
* address: 01 23 45 67
1993-03-21 12:45:37 +03:00
*/
/*ARGSUSED*/
void
db_examine_cmd(addr, have_addr, count, modif)
db_expr_t addr;
int have_addr;
db_expr_t count;
char * modif;
{
if (modif[0] != '\0')
1994-10-06 08:20:42 +03:00
db_strcpy(db_examine_format, modif);
1993-03-21 12:45:37 +03:00
if (count == -1)
1994-10-06 08:20:42 +03:00
count = 1;
1993-03-21 12:45:37 +03:00
db_examine((db_addr_t) addr, db_examine_format, count);
}
db_examine(addr, fmt, count)
register
db_addr_t addr;
1993-03-21 12:45:37 +03:00
char * fmt; /* format string */
int count; /* repeat count */
{
int c;
db_expr_t value;
int size;
int width;
char * fp;
1994-10-06 08:20:42 +03:00
1993-03-21 12:45:37 +03:00
while (--count >= 0) {
1994-10-06 08:20:42 +03:00
fp = fmt;
size = 4;
width = 12;
1994-10-06 08:20:42 +03:00
while ((c = *fp++) != 0) {
if (db_print_position() == 0) {
/* Always print the address. */
db_printsym(addr, DB_STGY_ANY);
db_printf(":\t");
db_prev = addr;
}
switch (c) {
case 'b': /* byte */
size = 1;
width = 4;
break;
case 'h': /* half-word */
size = 2;
width = 8;
break;
case 'l': /* long-word */
size = 4;
width = 12;
break;
1994-10-06 08:20:42 +03:00
case 'a': /* address */
db_printf("= 0x%x\n", addr);
break;
case 'r': /* signed, current radix */
1993-03-21 12:45:37 +03:00
value = db_get_value(addr, size, TRUE);
addr += size;
db_printf("%-*r", width, value);
break;
case 'x': /* unsigned hex */
1993-03-21 12:45:37 +03:00
value = db_get_value(addr, size, FALSE);
addr += size;
db_printf("%-*x", width, value);
break;
case 'z': /* signed hex */
1993-03-21 12:45:37 +03:00
value = db_get_value(addr, size, TRUE);
addr += size;
db_printf("%-*z", width, value);
break;
case 'd': /* signed decimal */
1993-03-21 12:45:37 +03:00
value = db_get_value(addr, size, TRUE);
addr += size;
db_printf("%-*d", width, value);
break;
case 'u': /* unsigned decimal */
1993-03-21 12:45:37 +03:00
value = db_get_value(addr, size, FALSE);
addr += size;
db_printf("%-*u", width, value);
break;
case 'o': /* unsigned octal */
1993-03-21 12:45:37 +03:00
value = db_get_value(addr, size, FALSE);
addr += size;
db_printf("%-*o", width, value);
break;
case 'c': /* character */
1993-03-21 12:45:37 +03:00
value = db_get_value(addr, 1, FALSE);
addr += 1;
if (value >= ' ' && value <= '~')
1994-10-06 08:20:42 +03:00
db_printf("%c", value);
1993-03-21 12:45:37 +03:00
else
1994-10-06 08:20:42 +03:00
db_printf("\\%03o", value);
1993-03-21 12:45:37 +03:00
break;
case 's': /* null-terminated string */
1993-03-21 12:45:37 +03:00
for (;;) {
1994-10-06 08:20:42 +03:00
value = db_get_value(addr, 1, FALSE);
addr += 1;
if (value == 0)
break;
1994-10-06 08:20:42 +03:00
if (value >= ' ' && value <= '~')
db_printf("%c", value);
1994-10-06 08:20:42 +03:00
else
db_printf("\\%03o", value);
1993-03-21 12:45:37 +03:00
}
break;
case 'i': /* instruction */
1993-03-21 12:45:37 +03:00
addr = db_disasm(addr, FALSE);
break;
case 'I': /* instruction, alternate form */
1993-03-21 12:45:37 +03:00
addr = db_disasm(addr, TRUE);
break;
default:
1993-03-21 12:45:37 +03:00
break;
}
if (db_print_position() != 0)
db_end_line();
1994-10-06 08:20:42 +03:00
}
1993-03-21 12:45:37 +03:00
}
db_next = addr;
}
/*
* Print value.
*/
char db_print_format = 'x';
/*ARGSUSED*/
void
db_print_cmd(addr, have_addr, count, modif)
db_expr_t addr;
int have_addr;
db_expr_t count;
char * modif;
{
db_expr_t value;
if (modif[0] != '\0')
1994-10-06 08:20:42 +03:00
db_print_format = modif[0];
1993-03-21 12:45:37 +03:00
switch (db_print_format) {
1994-10-06 08:20:42 +03:00
case 'a':
1993-03-21 12:45:37 +03:00
db_printsym((db_addr_t)addr, DB_STGY_ANY);
break;
1994-10-06 08:20:42 +03:00
case 'r':
1993-03-21 12:45:37 +03:00
db_printf("%11r", addr);
break;
1994-10-06 08:20:42 +03:00
case 'x':
1993-03-21 12:45:37 +03:00
db_printf("%8x", addr);
break;
1994-10-06 08:20:42 +03:00
case 'z':
1993-03-21 12:45:37 +03:00
db_printf("%8z", addr);
break;
1994-10-06 08:20:42 +03:00
case 'd':
1993-03-21 12:45:37 +03:00
db_printf("%11d", addr);
break;
1994-10-06 08:20:42 +03:00
case 'u':
1993-03-21 12:45:37 +03:00
db_printf("%11u", addr);
break;
1994-10-06 08:20:42 +03:00
case 'o':
1993-03-21 12:45:37 +03:00
db_printf("%16o", addr);
break;
1994-10-06 08:20:42 +03:00
case 'c':
1993-03-21 12:45:37 +03:00
value = addr & 0xFF;
if (value >= ' ' && value <= '~')
1994-10-06 08:20:42 +03:00
db_printf("%c", value);
1993-03-21 12:45:37 +03:00
else
1994-10-06 08:20:42 +03:00
db_printf("\\%03o", value);
1993-03-21 12:45:37 +03:00
break;
}
db_printf("\n");
}
db_print_loc_and_inst(loc)
db_addr_t loc;
{
db_printsym(loc, DB_STGY_PROC);
db_printf(":\t");
(void) db_disasm(loc, FALSE);
1993-03-21 12:45:37 +03:00
}
db_strcpy(dst, src)
register char *dst;
register char *src;
{
while (*dst++ = *src++)
1994-10-06 08:20:42 +03:00
;
1993-03-21 12:45:37 +03:00
}
/*
* Search for a value in memory.
* Syntax: search [/bhl] addr value [mask] [,count]
*/
void
db_search_cmd()
{
int t;
db_addr_t addr;
int size;
db_expr_t value;
db_expr_t mask;
unsigned int count;
t = db_read_token();
if (t == tSLASH) {
1994-10-06 08:20:42 +03:00
t = db_read_token();
if (t != tIDENT) {
bad_modifier:
db_printf("Bad modifier\n");
db_flush_lex();
return;
}
1993-03-21 12:45:37 +03:00
1994-10-06 08:20:42 +03:00
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;
1993-03-21 12:45:37 +03:00
} else {
1994-10-06 08:20:42 +03:00
db_unread_token(t);
size = 4;
1993-03-21 12:45:37 +03:00
}
if (!db_expression(&addr)) {
1994-10-06 08:20:42 +03:00
db_printf("Address missing\n");
db_flush_lex();
return;
1993-03-21 12:45:37 +03:00
}
if (!db_expression(&value)) {
1994-10-06 08:20:42 +03:00
db_printf("Value missing\n");
db_flush_lex();
return;
1993-03-21 12:45:37 +03:00
}
if (!db_expression(&mask))
1994-10-06 08:20:42 +03:00
mask = 0xffffffff;
1993-03-21 12:45:37 +03:00
t = db_read_token();
if (t == tCOMMA) {
1994-10-06 08:20:42 +03:00
if (!db_expression(&count)) {
db_printf("Count missing\n");
db_flush_lex();
return;
}
1993-03-21 12:45:37 +03:00
} else {
1994-10-06 08:20:42 +03:00
db_unread_token(t);
count = -1; /* effectively forever */
1993-03-21 12:45:37 +03:00
}
db_skip_to_eol();
db_search(addr, size, value, mask, count);
}
db_search(addr, size, value, mask, count)
register
db_addr_t addr;
int size;
db_expr_t value;
db_expr_t mask;
unsigned int count;
{
while (count-- != 0) {
db_prev = addr;
if ((db_get_value(addr, size, FALSE) & mask) == value)
break;
addr += size;
}
db_next = addr;
}