Commit 321a1972 authored by Jeremy White's avatar Jeremy White Committed by Alexandre Julliard

Add debugstr_hex_dump to allow display hex dumps of data in any

debugging message.
parent 699d3cf8
......@@ -14,6 +14,7 @@ extern LPSTR debugstr_w (LPCWSTR s);
extern LPSTR debugres_a (LPCSTR res);
extern LPSTR debugres_w (LPCWSTR res);
extern void debug_dumpstr (LPCSTR s);
extern LPSTR debugstr_hex_dump (const void *ptr, int len);
#ifdef __GNUC__
extern int dbg_printf(const char *format, ...) __attribute__((format (printf,1,2)));
......@@ -21,4 +22,5 @@ extern int dbg_printf(const char *format, ...) __attribute__((format (printf,1,2
extern int dbg_printf(const char *format, ...);
#endif
#endif /* __WINE_DEBUGSTR_H */
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "debugstr.h"
#include "debugtools.h"
......@@ -198,3 +200,107 @@ int dbg_printf(const char *format, ...)
return ret;
}
/*--< Function >---------------------------------------------------------
**
** debugstr_hex_dump
**
** Description:
** This function creates a hex dump, with a readable ascii
** section, for displaying memory.
**
** Parameters:
** 1. ptr Pointer to memory
** 2. len How much to dump.
**
** Returns:
** Temporarily allocated buffer, with the hex dump in it.
** Don't rely on this pointer being around for very long, just
** long enough to use it in a TRACE statement; e.g.:
** TRACE("struct dump is \n%s", debugstr_hex_dump(&x, sizeof(x)));
**
**-------------------------------------------------------------------------*/
LPSTR
debugstr_hex_dump (const void *ptr, int len)
{
/* Locals */
char dumpbuf[59];
char charbuf[20];
char tempbuf[8];
const char *p;
int i;
unsigned int nosign;
LPSTR dst;
LPSTR outptr;
/* Begin function dbg_hex_dump */
/*-----------------------------------------------------------------------
** Allocate an output buffer
** A reasonable value is one line overhand (80 chars), and
** then one line (80) for every 16 bytes.
**---------------------------------------------------------------------*/
outptr = dst = gimme1 ((len * (80 / 16)) + 80);
/*-----------------------------------------------------------------------
** Loop throught the input buffer, one character at a time
**---------------------------------------------------------------------*/
for (i = 0, p = ptr; (i < len); i++, p++)
{
/*-------------------------------------------------------------------
** If we're just starting a line,
** we need to possibly flush the old line, and then
** intialize the line buffer.
**-----------------------------------------------------------------*/
if ((i % 16) == 0)
{
if (i)
{
sprintf(outptr, " %-43.43s %-16.16s\n", dumpbuf, charbuf);
outptr += strlen(outptr);
}
sprintf (dumpbuf, "%04x: ", i);
strcpy (charbuf, "");
}
/*-------------------------------------------------------------------
** Add the current data byte to the dump section.
**-----------------------------------------------------------------*/
nosign = (unsigned char) *p;
sprintf (tempbuf, "%02X", nosign);
/*-------------------------------------------------------------------
** If we're two DWORDS through, add a hyphen for readability,
** if it's a DWORD boundary, add a space for more
** readability.
**-----------------------------------------------------------------*/
if ((i % 16) == 7)
strcat(tempbuf, " - ");
else if ( (i % 4) == 3)
strcat(tempbuf, " ");
strcat (dumpbuf, tempbuf);
/*-------------------------------------------------------------------
** Add the current byte to the character display part of the
** hex dump
**-----------------------------------------------------------------*/
sprintf (tempbuf, "%c", isprint(*p) ? *p : '.');
strcat (charbuf, tempbuf);
}
/*-----------------------------------------------------------------------
** Flush the last line, if any
**---------------------------------------------------------------------*/
if (i > 0)
{
sprintf(outptr, " %-43.43s %-16.16s\n", dumpbuf, charbuf);
outptr += strlen(outptr);
}
return(dst);
} /* End function dbg_hex_dump */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment