blob: 2abc9813ad4a979f48a89a0e54d765715a04b9d3 [file] [log] [blame]
/*
* Wine debugger utility routines
*
* Copyright 1993 Eric Youngdale
* Copyright 1995 Alexandre Julliard
*/
#include <stdio.h>
#include <stdlib.h>
#include "debugger.h"
/***********************************************************************
* DEBUG_Print
*
* Implementation of the 'print' command.
*/
void DEBUG_Print( const DBG_ADDR *addr, int count, char format )
{
if (count != 1)
{
fprintf( stderr, "Count other than 1 is meaningless in 'print' command\n" );
return;
}
if (addr->seg && (addr->seg != 0xffffffff))
{
switch(format)
{
case 'x':
fprintf( stderr, "0x%04lx:", addr->seg );
break;
case 'd':
fprintf( stderr, "%ld:", addr->seg );
break;
case 'c':
break; /* No segment to print */
case 'i':
case 's':
case 'w':
case 'b':
break; /* Meaningless format */
}
}
switch(format)
{
case 'x':
if (addr->seg) fprintf( stderr, "0x%04lx\n", addr->off );
else fprintf( stderr, "0x%08lx\n", addr->off );
break;
case 'd':
fprintf( stderr, "%ld\n", addr->off );
break;
case 'c':
fprintf( stderr, "%d = '%c'\n",
(char)(addr->off & 0xff), (char)(addr->off & 0xff) );
break;
case 'i':
case 's':
case 'w':
case 'b':
fprintf( stderr, "Format specifier '%c' is meaningless in 'print' command\n", format );
break;
}
}
/***********************************************************************
* DEBUG_PrintAddress
*
* Print an 16- or 32-bit address, with the nearest symbol if any.
*/
struct name_hash *
DEBUG_PrintAddress( const DBG_ADDR *addr, int addrlen, int flag )
{
struct name_hash * nh;
const char *name = DEBUG_FindNearestSymbol( addr, flag, &nh, 0 );
if (addr->seg) fprintf( stderr, "0x%04lx:", addr->seg );
if (addrlen == 16) fprintf( stderr, "0x%04lx", addr->off );
else fprintf( stderr, "0x%08lx", addr->off );
if (name) fprintf( stderr, " (%s)", name );
return nh;
}
/***********************************************************************
* DEBUG_PrintAddressAndArgs
*
* Print an 16- or 32-bit address, with the nearest symbol if any.
* Similar to DEBUG_PrintAddress, but we print the arguments to
* each function (if known). This is useful in a backtrace.
*/
struct name_hash *
DEBUG_PrintAddressAndArgs( const DBG_ADDR *addr, int addrlen,
unsigned int ebp, int flag )
{
struct name_hash * nh;
const char *name = DEBUG_FindNearestSymbol( addr, flag, &nh, ebp );
if (addr->seg) fprintf( stderr, "0x%04lx:", addr->seg );
if (addrlen == 16) fprintf( stderr, "0x%04lx", addr->off );
else fprintf( stderr, "0x%08lx", addr->off );
if (name) fprintf( stderr, " (%s)", name );
return nh;
}
/***********************************************************************
* DEBUG_Help
*
* Implementation of the 'help' command.
*/
void DEBUG_Help(void)
{
int i = 0;
static const char * const helptext[] =
{
"The commands accepted by the Wine debugger are a small subset",
"of the commands that gdb would accept.",
"The commands currently are:",
" break [*<addr>] delete break bpnum",
" disable bpnum enable bpnum",
" help quit",
" bt cont",
" step next",
" x <addr> print <expr>",
" set <reg> = <expr> set *<addr> = <expr>",
" symbolfile <filename> define <identifier> <addr>",
" up down\n",
" list <addr> frame <n>\n",
"Wine-specific commands:",
" mode [16,32] walk [wnd,class,queue] <handle>",
" info [reg,stack,break,segments,locals] info [wnd, queue] <handle>\n",
"The 'x' command accepts repeat counts and formats (including 'i') in the",
"same way that gdb does.\n",
" The following are examples of legal expressions:",
" $eax $eax+0x3 0x1000 ($eip + 256) *$eax *($esp + 3)",
" Also, a nm format symbol table can be read from a file using the",
" symbolfile command. Symbols can also be defined individually with",
" the define command.",
"",
NULL
};
while(helptext[i]) fprintf(stderr,"%s\n", helptext[i++]);
}
/***********************************************************************
* DEBUG_List
*
* Implementation of the 'list' command.
*/
void DEBUG_List( DBG_ADDR *addr, int count )
{
static DBG_ADDR lasttime = { 0xffffffff, 0 };
if (addr == NULL) addr = &lasttime;
DBG_FIX_ADDR_SEG( addr, CS_reg(DEBUG_context) );
while (count-- > 0)
{
DEBUG_PrintAddress( addr, dbg_mode, FALSE );
fprintf( stderr, ": " );
if (!DBG_CHECK_READ_PTR( addr, 1 )) return;
DEBUG_Disasm( addr );
fprintf (stderr, "\n");
}
lasttime = *addr;
}