Browse code

Trace instructions in bytecode VM

Jonas Zaddach authored on 2018/12/19 23:39:58
Showing 1 changed files
... ...
@@ -89,6 +89,7 @@ static inline int bcfail(const char *msg, long a, long b,
89 89
 #define TRACE_R(x) cli_dbgmsg("bytecode trace: %u, read %llx\n", pc, (long long)x);
90 90
 #define TRACE_W(x, w, p) cli_dbgmsg("bytecode trace: %u, write%d @%u %llx\n", pc, p, w, (long long)(x));
91 91
 #define TRACE_EXEC(id, dest, ty, stack) cli_dbgmsg("bytecode trace: executing %d, -> %u (%u); %u\n", id, dest, ty, stack)
92
+#define TRACE_INST(inst) do {unsigned bbnum = 0; printf("LibClamAV debug: bytecode trace: executing instruction "); cli_byteinst_describe(inst, &bbnum); printf("\n");} while (0)
92 93
 #define TRACE_API(s, dest, ty, stack) cli_dbgmsg("bytecode trace: executing %s, -> %u (%u); %u\n", s, dest, ty, stack)
93 94
 #else
94 95
 #define CHECK_UNREACHABLE return CL_EBYTECODE
... ...
@@ -96,6 +97,7 @@ static inline int bcfail(const char *msg, long a, long b,
96 96
 #define TRACE_R(x)
97 97
 #define TRACE_W(x, w, p)
98 98
 #define TRACE_EXEC(id, dest, ty, stack)
99
+#define TRACE_INST(inst)
99 100
 #define TRACE_API(s, dest, ty, stack)
100 101
 #endif
101 102
 
... ...
@@ -725,6 +727,9 @@ int cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct
725 725
                 break;
726 726
             }
727 727
         }
728
+
729
+        TRACE_INST(inst);
730
+
728 731
         switch (inst->interp_op) {
729 732
             DEFINE_BINOP(OP_BC_ADD, res = op0 + op1);
730 733
             DEFINE_BINOP(OP_BC_SUB, res = op0 - op1);