kernel debug: rewrite dump_block to use a single dprintf call

In the syslog, each dprintf call is prefixed with a KERN: prefix,
rendering the dump unreadable. Bufferize things to print each line with
a single call.

Change-Id: I27c1b1f74434fbc6e554acb0a716f0700821bc8d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5305
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
PulkoMandy 2022-05-11 17:48:53 +02:00 committed by Adrien Destugues
parent a5c0d1a80e
commit 580f28da6d

View File

@ -2329,33 +2329,34 @@ dump_block(const char* buffer, int size, const char* prefix)
{
const int DUMPED_BLOCK_SIZE = 16;
int i;
char lineBuffer[3 + DUMPED_BLOCK_SIZE * 4];
for (i = 0; i < size;) {
char* pointer = lineBuffer;
int start = i;
dprintf("%s%04x ", prefix, i);
for (; i < start + DUMPED_BLOCK_SIZE; i++) {
if (!(i % 4))
dprintf(" ");
pointer += sprintf(pointer, " ");
if (i >= size)
dprintf(" ");
pointer += sprintf(pointer, " ");
else
dprintf("%02x", *(unsigned char*)(buffer + i));
pointer += sprintf(pointer, "%02x", *(unsigned char*)(buffer + i));
}
dprintf(" ");
pointer += sprintf(pointer, " ");
for (i = start; i < start + DUMPED_BLOCK_SIZE; i++) {
if (i < size) {
char c = buffer[i];
if (c < 30)
dprintf(".");
pointer += sprintf(pointer, ".");
else
dprintf("%c", c);
pointer += sprintf(pointer, "%c", c);
} else
break;
}
dprintf("\n");
dprintf("%s%04x%s\n", prefix, start, lineBuffer);
}
}