summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@airbus.com>2018-11-27 15:05:05 +0100
committerKévin Le Gouguec <kevin.legouguec@airbus.com>2018-11-27 15:17:39 +0100
commit1f359c1cdbb7a9bd41f3cb9717187e8aeacce43b (patch)
tree6f1b05ef18e1860ae7140f38c0cc6f4f9098dc1a /src
parent30b6de9dd377259685cfd0aedabd1f891fcf0d44 (diff)
downloadlilliput-ae-implem-1f359c1cdbb7a9bd41f3cb9717187e8aeacce43b.tar.xz
Changement du format de traces
Diffstat (limited to 'src')
-rw-r--r--src/debug.h64
1 files changed, 43 insertions, 21 deletions
diff --git a/src/debug.h b/src/debug.h
index 87140e5..c7fa343 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -5,46 +5,68 @@
#include <stdio.h>
-static inline void debug_dump_lanes(FILE *output, const char *header, size_t len, const uint8_t buf[len], int indent)
-{
- if (!output)
- {
- return;
- }
+extern FILE *DUMP; /* Define this variable somewhere (eg with DUMP = stderr). */
+
- fprintf(output, "%s\n", header);
+static inline void debug_dump_lanes(const char *header, size_t len, const uint8_t buf[len], int indent)
+{
+ fprintf(DUMP, "%s\n", header);
for (size_t line=0; line<len/8; line++)
{
- fprintf(output, "%*s", indent, "");
+ fprintf(DUMP, "%*s", indent, "");
for (size_t b=0; b<8; b++)
{
/* start with MSB */
size_t byte_index = len-(1+line*8+b);
- fprintf(output, "%*s%02x", 5, "", buf[byte_index]);
+ fprintf(DUMP, "%*s%02x", 5, "", buf[byte_index]);
}
- fprintf(output, "\n");
+ fprintf(DUMP, "\n");
}
- fprintf(output, "\n");
+ fprintf(DUMP, "\n");
}
-static inline void debug_dump_buffer(FILE *output, const char *header, size_t len, const uint8_t buf[len], int indent)
+static inline void debug_dump_buffer(const char *header, size_t len, const uint8_t buf[len], int indent)
{
- if (!output)
+ fprintf(DUMP, "%*s%s\n", indent, "", header);
+
+ if (len%8 != 0)
{
- return;
+ fprintf(DUMP, "%*s", (int)(3*(8-len%8))+indent, "");
+ for (size_t b=0; b<len%8; b++)
+ {
+ size_t byte_index = len-1-b;
+ fprintf(DUMP, "%02x ", buf[byte_index]);
+ }
+ fprintf(DUMP, "\n");
}
- fprintf(output, "%s\n", header);
+ if (len/8 == 0)
+ return;
- fprintf(output, "%*s", indent, "");
- for (size_t b=0; b<len; b++)
+ for (size_t line=0; line<len/8; line++)
{
- /* start with MSB */
- size_t byte_index = len-1-b;
- fprintf(output, "%*s%02x", 5, "", buf[byte_index]);
+ fprintf(DUMP, "%*s", indent, "");
+ for (size_t b=0; b<8; b++)
+ {
+ /* start with MSB */
+ size_t byte_index = 8*(len/8 - 1 - line) + 7-b;
+ /* fprintf(DUMP, "[%zu / %zu => %zu]", line, b, byte_index); */
+ fprintf(DUMP, "%02x ", buf[byte_index]);
+ }
+ fprintf(DUMP, "\n");
}
- fprintf(output, "\n");
+
+ fprintf(DUMP, "\n");
}
+static inline void debug_open_dump(const char *vector_name)
+{
+ size_t namelen = snprintf(NULL, 0, "/tmp/test-%s.txt", vector_name);
+ char name[namelen+1];
+ snprintf(name, sizeof(name), "/tmp/test-%s.txt", vector_name);
+ DUMP = fopen(name, "w");
+}
+
+
#endif /* DEBUG_H */