debugfile: replace mixed string/control character notation with hexdump

Example of old notation:

    [10]O[0,0]jartha[0,254,142,131]c[133]hL^{[170][[251,199]+E[181]U+t[247,183,129,165,152]#$[164,22,10,169]r[150,212,3,232,3,0,0,2,0,0,0,8,0]0[8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,9,2,0,0,1,0,217,161,192] D[0,0,0,0,0,0,0]

Example of new notation:

         0:  01 0e 6a 61  72 74 68 61  00 57 00 09  5a 00 42 00  ..jartha.W..Z.B.
        16:  02 01 00 b7  6a d4 20 6f  2b 45 b5                  ....j. o+E.
This commit is contained in:
James R 2023-05-24 18:31:38 -07:00
parent d2482287a9
commit 3ad30c0c7a

View file

@ -731,39 +731,46 @@ static UINT32 NetbufferChecksum(void)
#ifdef DEBUGFILE
static void fprintfstring(char *s, size_t len)
static void fprintfline(char *s, size_t len)
{
INT32 mode = 0;
size_t i;
for (i = 0; i < len; i++)
if (s[i] < 32)
for (i = 0; i < 16; ++i)
{
if (i < len)
{
if (!mode)
{
fprintf(debugfile, "[%d", (UINT8)s[i]);
mode = 1;
}
else
fprintf(debugfile, ",%d", (UINT8)s[i]);
fprintf(debugfile, "%02x%s",
((unsigned char*)s)[i],
i % 4 == 3 ? " " : " ");
}
else
{
if (mode)
{
fprintf(debugfile, "]");
mode = 0;
}
fprintf(debugfile, "%c", s[i]);
fprintf(debugfile, "%*s", i % 4 == 3 ? 4 : 3, "");
}
if (mode)
fprintf(debugfile, "]");
}
for (i = 0; i < len; ++i)
{
fprintf(debugfile, "%c", isprint(s[i]) ? s[i] : '.');
}
fprintf(debugfile, "\n");
}
static void fprintfstring(char *s, size_t len)
{
size_t i;
for (i = 0; i < len; i += 16)
{
fprintf(debugfile, "%10s: ", sizeu1(i));
fprintfline(&s[i], min(len - i, 16));
}
}
static void fprintfstringnewline(char *s, size_t len)
{
fprintfstring(s, len);
fprintf(debugfile, "\n");
}
/// \warning Keep this up-to-date if you add/remove/rename packet types
@ -847,7 +854,7 @@ static void DebugPrintpacket(const char *header)
UINT8 *cmd = (UINT8 *)(&serverpak->cmds[serverpak->numslots * serverpak->numtics]);
size_t ntxtcmd = &((UINT8 *)netbuffer)[doomcom->datalength] - cmd;
fprintf(debugfile, " firsttic %u ply %d tics %d ntxtcmd %s\n ",
fprintf(debugfile, " firsttic %u ply %d tics %d ntxtcmd %s\n",
(UINT32)serverpak->starttic, serverpak->numslots, serverpak->numtics, sizeu1(ntxtcmd));
/// \todo Display more readable information about net commands
fprintfstringnewline((char *)cmd, ntxtcmd);
@ -881,7 +888,7 @@ static void DebugPrintpacket(const char *header)
case PT_TEXTCMD2:
case PT_TEXTCMD3:
case PT_TEXTCMD4:
fprintf(debugfile, " length %d\n ", netbuffer->u.textcmd[0]);
fprintf(debugfile, " length %d\n", netbuffer->u.textcmd[0]);
fprintf(debugfile, "[%s]", netxcmdnames[netbuffer->u.textcmd[1] - 1]);
fprintfstringnewline((char *)netbuffer->u.textcmd + 2, netbuffer->u.textcmd[0] - 1);
break;