27 MemDump(
const char* msg_,
int len_) : m_dump (NULL)
40 if (len_ <= 0 || msg_ == (
char*) NULL) {
42 DL((
ASSAERR,
"Data length requested: %d <= 0!\n", len_));
66 final_len = (int (len_/16) + 1 + (len_ % 16 ? 1:0)) * 74;
68 m_dump =
new char[final_len];
69 memset (
m_dump,
' ', final_len);
75 for (i = 0; i < len_; i++)
77 sprintf(hex,
"%01x%01x", p[i] >> 4 & 0x0f, p[i] & 0x0f);
80 if (p[i] ==
'\n') { sprintf(ascii,
"\\n"); ascii+=2; }
81 else if (p[i] ==
'\t') { sprintf(ascii,
"\\t"); ascii+=2; }
82 else if (p[i] ==
'\v') { sprintf(ascii,
"\\v"); ascii+=2; }
83 else if (p[i] ==
'\b') { sprintf(ascii,
"\\b"); ascii+=2; }
84 else if (p[i] ==
'\r') { sprintf(ascii,
"\\r"); ascii+=2; }
85 else if (p[i] ==
'\f') { sprintf(ascii,
"\\f"); ascii+=2; }
86 else if (p[i] ==
'\a') { sprintf(ascii,
"\\a"); ascii+=2; }
87 else if (p[i] ==
'\0') { sprintf(ascii,
"\\0"); ascii+=2; }
89 sprintf (ascii++,
"%c", ((p[i] <
' ' || p [i] >
'~') ?
'.' : p [i]));
100 sprintf (ascii++,
"\n");
106 m_dump [final_len-1] =
'\0';
111 dump_to_log (
unsigned long mask_,
const char* info_,
const char* msg_,
int len_)
118 if (
LOGGER->group_enabled (
static_cast<Group> (mask_)) && len_ > 0)
121 DL((mask_,
"(%d bytes) %s\n", len_, info_));
An abstraction to message logging facility.
#define DL(X)
A macro for writing debug message to the Logger.
#define LOGGER
A shortcut to locate a singleton object of class Logger.
A Hex/Ascii memory dump of similar to od(1) UNIX utility.
static const char m_empty_str[]
static Null string
MemDump(const char *msg_, int len_)
Constructor converts original binary image to hex and ascii representation, and stores resultant imag...
const char * getMemDump() const
Obtain a pointer to the dump image (null-terminated char string).
char * m_dump
pointer to converted image
static void dump_to_log(unsigned long mask_, const char *info_, const char *msg_, int len_)
Write hex/ascii dump of a memory region to log file.
@ ASSAERR
ASSA and system errors