aboutsummaryrefslogtreecommitdiffstats
path: root/trace.c
blob: 8b96e23277b203c12887ef6605831b47f0054733 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "compiler.h"
#include "trace.h"

void trace_dump_data(const char *prefix, const void *data, unsigned int l)
{
    unsigned int i, j;
    const uint8_t *p = data;

    for (i = 0; i < l; i += 16) {
        fprintf(tracef, "%s: %04x : ", prefix, i);

        for (j = 0; j < 16; j++) {
            if (i + j < l)
                fprintf(tracef, " %02x", p[j]);
            else
                fputs("   ", tracef);

            if (j == 8)
                fputs(" -", tracef);
        }

        fputs(" [", tracef);

        for (j = 0; j < 16; j++) {
            char c;

            if (i + j < l)
                c = p[j];
            else
                c = ' ';

            if (c < ' ' || c > '~')
                c = '.';

            fputc(c, tracef);
        }

        fputs("]\n", tracef);
        p += 16;
    }
}