* src/vm/jit/show.cpp (show_method): Now shows patcher references as well.
authorMichael Starzinger <michi@complang.tuwien.ac.at>
Mon, 31 Aug 2009 14:51:17 +0000 (16:51 +0200)
committerMichael Starzinger <michi@complang.tuwien.ac.at>
Mon, 31 Aug 2009 14:51:17 +0000 (16:51 +0200)
* src/vm/jit/patcher-common.cpp (patcher_list_show): Supports above task.
* src/vm/jit/patcher-common.hpp: Likewise.
* src/vm/global.h (PRINTF_FORMAT_INTPTR_T): Added very useful define.

src/vm/global.h
src/vm/jit/patcher-common.cpp
src/vm/jit/patcher-common.hpp
src/vm/jit/show.cpp

index 420352c6a1c0636e16b8771cad188b4c634a38d4..4443a806f0782a9c3974ddbd55371c86e8e51e87 100644 (file)
@@ -77,8 +77,10 @@ typedef union {
 /* Define printf formats which change size between 32- and 64-bit. */
 
 #if SIZEOF_VOID_P == 8
+# define PRINTF_FORMAT_INTPTR_T   "0x%016lx"
 # define PRINTF_FORMAT_INT64_T    "%ld"
 #else
+# define PRINTF_FORMAT_INTPTR_T   "0x%08lx"
 # define PRINTF_FORMAT_INT64_T    "%lld"
 #endif
 
index c96f14808d0a2061db872d7841b75a6052f538fc..5992bea1f0c4d067639d6344ede5dd03407b884a 100644 (file)
@@ -160,6 +160,49 @@ static patchref_t* patcher_list_find(codeinfo* code, void* pc)
 }
 
 
+/**
+ * Show the content of the whole patcher reference list for
+ * debugging purposes.
+ *
+ * @param code The codeinfo containing the patcher list.
+ */
+#if !defined(NDEBUG)
+void patcher_list_show(codeinfo *code)
+{
+       for (List<patchref_t>::iterator it = code->patchers->begin(); it != code->patchers->end(); it++) {
+               patchref_t& pr = *it;
+
+               // Lookup name in patcher function list.
+               patcher_function_list_t* l;
+               for (l = patcher_function_list; l->patcher != NULL; l++)
+                       if (l->patcher == pr.patcher)
+                               break;
+
+               // Display information about patcher.
+               printf("\tpatcher pc:"PRINTF_FORMAT_INTPTR_T, pr.mpc);
+               printf(" datap:"PRINTF_FORMAT_INTPTR_T, pr.datap);
+               printf(" ref:"PRINTF_FORMAT_INTPTR_T, (intptr_t) pr.ref);
+#if PATCHER_CALL_SIZE == 4
+               printf(" mcode:%08x", (uint32_t) pr.mcode);
+#elif PATCHER_CALL_SIZE == 2
+               printf(" mcode:%04x", (uint16_t) pr.mcode);
+#else
+# error Unknown PATCHER_CALL_SIZE
+#endif
+               printf(" type:%s\n", l->name);
+
+               // Display machine code of patched position.
+#if 0 && defined(ENABLE_DISASSEMBLER)
+               printf("\t\tcurrent -> ");
+               disassinstr((uint8_t*) pr.mpc);
+               printf("\t\tapplied -> ");
+               disassinstr((uint8_t*) &(pr.mcode));
+#endif
+       }
+}
+#endif
+
+
 /* patcher_add_patch_ref *******************************************************
 
    Appends a new patcher reference to the list of patching positions.
index 72ed1ec0bf5a9948d0af08ef9de861bd9f633492..159c6f5aa9e9ad53fdb023836c0ce21c8a153732 100644 (file)
@@ -71,6 +71,10 @@ void patcher_list_create(codeinfo *code);
 void patcher_list_reset(codeinfo *code);
 void patcher_list_free(codeinfo *code);
 
+#if !defined(NDEBUG)
+void patcher_list_show(codeinfo *code);
+#endif
+
 void patcher_add_patch_ref(jitdata *jd, functionptr patcher, void* ref, s4 disp);
 
 void patcher_resolve(jitdata* jd);
index 24b64dfd03e41339a4a08c51aab180f3c425067a..6210c59b98da1b3f56bb2926af711d5d27f9b20b 100644 (file)
@@ -192,7 +192,7 @@ void show_method(jitdata *jd, int stage)
        }
 
        if (stage >= SHOW_PARSE) {
-               printf("Exceptions (Number: %d):\n", jd->exceptiontablelength);
+               printf("Exceptions (number=%d):\n", jd->exceptiontablelength);
                for (ex = jd->exceptiontable; ex != NULL; ex = ex->down) {
                        printf("    L%03d ... ", ex->start->nr );
                        printf("L%03d  = ", ex->end->nr);
@@ -311,12 +311,12 @@ void show_method(jitdata *jd, int stage)
                int max;
 
                max = rd->memuse;
-               printf("Stack slots: (memuse=%d", rd->memuse);
+               printf("Stack slots (memuse=%d", rd->memuse);
                if (irstage >= SHOW_CODE) {
                        printf(", stackframesize=%d", cd->stackframesize);
                        max = cd->stackframesize;
                }
-               printf(")\n");
+               printf("):\n");
                for (i = 0; i < max; ++i) {
                        printf("    M%02d = 0x%02x(sp): ", i, i * 8);
                        for (j = 0; j < jd->vartop; ++j) {
@@ -333,6 +333,13 @@ void show_method(jitdata *jd, int stage)
                printf("\n");
        }
 
+       if (!code->patchers->empty()) {
+               int number = code->patchers->size();
+               printf("Patcher References (number=%d):\n", number);
+               patcher_list_show(code);
+               printf("\n");
+       }
+
 #if defined(ENABLE_REPLACEMENT)
        if (code->rplpoints) {
                printf("Replacement Points:\n");