From 61219787f7af63c8e7455f02aa21d06bea57096a Mon Sep 17 00:00:00 2001 From: ehouse Date: Sat, 2 Oct 2004 03:53:23 +0000 Subject: [PATCH] add logmem debugging utility --- palm/palmutil.c | 26 ++++++++++++++++++++++++++ palm/xptypes.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/palm/palmutil.c b/palm/palmutil.c index 42b48ba74..67d6b0850 100644 --- a/palm/palmutil.c +++ b/palm/palmutil.c @@ -655,4 +655,30 @@ palm_logf( char* format, ... ) logToMemo( buf ); } /* palm_logf */ +#define ROWSIZE 8 + +void +palm_logmem( unsigned char* ptr, int nBytes ) +{ + XP_U16 nRows = (nBytes + ROWSIZE-1) / ROWSIZE; + char buf[(ROWSIZE*3)+5]; + char* bp; + unsigned char* end = ptr + nBytes; + XP_U16 i, j; + + for ( i = 0; i < nRows; ++i ) { + bp = buf; + bp += StrPrintF( (Char*)buf, "%3x:", i * ROWSIZE ); + + for ( j = 0; j < ROWSIZE && ptr < end; ++j ) { + char sbuf[6]; + StrPrintF( sbuf, "%x ", (XP_U16)*ptr++ ); + StrCat( buf, &sbuf[2] ); + bp += 3; + } + + logToMemo( buf ); + } +} + #endif /* DEBUG */ diff --git a/palm/xptypes.h b/palm/xptypes.h index f68b3a1b7..fdb51f837 100644 --- a/palm/xptypes.h +++ b/palm/xptypes.h @@ -48,6 +48,7 @@ void palm_assert(Boolean b, int line, char* fileName ); void palm_warnf( char* format, ... ); void palm_logf( char* format, ... ); XP_U16 palm_snprintf( XP_UCHAR* buf, XP_U16 len, XP_UCHAR* format, ... ); +void palm_logmem( unsigned char* ptr, int nBytes ); XP_S16 palm_memcmp( XP_U8* p1, XP_U8* p2, XP_U16 nBytes ); XP_U8* palm_realloc(XP_U8* in, XP_U16 size); @@ -100,9 +101,11 @@ XP_U8* palm_realloc(XP_U8* in, XP_U16 size); #ifdef DEBUG #define XP_LOGF palm_logf #define XP_WARNF palm_warnf +#define XP_LOGMEM palm_logmem #else #define XP_WARNF if(0)p_ignore #define XP_LOGF if(0)p_ignore +#define XP_LOGMEM if(0)p_ignore #endif /* Assumes big-endian, of course */