]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Rose program: Improvements to debug/assertions
authorJustin Viiret <justin.viiret@intel.com>
Mon, 15 Feb 2016 02:41:21 +0000 (13:41 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Tue, 1 Mar 2016 00:35:09 +0000 (11:35 +1100)
- Add current pc to debug printf.
- Assert that pc doesn't escape the RoseEngine structure.

src/rose/program_runtime.h

index 590d9ec3143a96c3b30fcab3755d0d0d28041aa5..3fbaeb32cb49dec4da28ae192a9ee24ccc52a398 100644 (file)
@@ -808,10 +808,10 @@ char roseCheckBounds(u64a end, u64a min_bound, u64a max_bound) {
     return end >= min_bound && end <= max_bound;
 }
 
-
 #define PROGRAM_CASE(name)                                                     \
     case ROSE_INSTR_##name: {                                                  \
-        DEBUG_PRINTF("instruction: " #name " (%u)\n", ROSE_INSTR_##name);      \
+        DEBUG_PRINTF("instruction: " #name " (pc=%u)\n",                       \
+                     programOffset + (u32)(pc - pc_base));                     \
         const struct ROSE_STRUCT_##name *ri =                                  \
             (const struct ROSE_STRUCT_##name *)pc;
 
@@ -848,7 +848,9 @@ hwlmcb_rv_t roseRunProgram(const struct RoseEngine *t,
 
     for (;;) {
         assert(ISALIGNED_N(pc, ROSE_INSTR_MIN_ALIGN));
-        u8 code = *(const u8 *)pc;
+        assert(pc >= pc_base);
+        assert((pc - pc_base) < t->size);
+        const u8 code = *(const u8 *)pc;
         assert(code <= ROSE_INSTR_END);
 
         switch ((enum RoseInstructionCode)code) {