mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-24 01:58:16 +02:00
Our u_hexdump() squeezes 16-byte chunks filled of zeros, where the unix hexdump squeezes repeated 16-byte chunks. Turns out panfrost/panvk dumps can be pretty big when when VM dump is requested (PANVK_DEBUG/PAN_MESA_DEBUG=dump) and memory regions are filled with repeated non-zero patterns (like a Z16_UNORM buffer cleared to 1.0, AKA 0xffff). Avoiding the repetition of such non-zero patterns in dumps significantly reduces the size of the dumps. It also clears any confusion for people used to the original hexdump semantics where a star means the previous line is repeated. Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com> Acked-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30692>
50 lines
1 KiB
C
50 lines
1 KiB
C
/*
|
|
* Copyright 2021 Alyssa Rosenzweig
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#ifndef U_HEXDUMP_H
|
|
#define U_HEXDUMP_H
|
|
|
|
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
|
|
static inline void
|
|
u_hexdump(FILE *fp, const uint8_t *hex, size_t cnt, bool with_strings)
|
|
{
|
|
for (unsigned i = 0; i < cnt; ++i) {
|
|
if ((i & 0xF) == 0 && i >= 0x10) {
|
|
unsigned j;
|
|
|
|
for (j = i; j + 0x10 < cnt; j += 0x10) {
|
|
if (memcmp(&hex[j], &hex[j - 0x10], 0x10))
|
|
break;
|
|
}
|
|
|
|
if (j > i) {
|
|
fprintf(fp, "*\n");
|
|
i = j - 1;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
if ((i & 0xF) == 0)
|
|
fprintf(fp, "%06X ", i);
|
|
|
|
fprintf(fp, "%02X ", hex[i]);
|
|
if ((i & 0xF) == 0xF && with_strings) {
|
|
fprintf(fp, " | ");
|
|
for (unsigned j = i & ~0xF; j <= i; ++j) {
|
|
uint8_t c = hex[j];
|
|
fputc((c < 32 || c > 128) ? '.' : c, fp);
|
|
}
|
|
}
|
|
|
|
if ((i & 0xF) == 0xF)
|
|
fprintf(fp, "\n");
|
|
}
|
|
|
|
fprintf(fp, "\n");
|
|
}
|
|
|
|
#endif
|