From 7f461fba26d7241e160c580dbca9ba1c2656e572 Mon Sep 17 00:00:00 2001 From: Michael Starzinger Date: Mon, 31 Aug 2009 16:51:17 +0200 Subject: [PATCH] * src/vm/jit/show.cpp (show_method): Now shows patcher references as well. * 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 | 2 ++ src/vm/jit/patcher-common.cpp | 43 +++++++++++++++++++++++++++++++++++ src/vm/jit/patcher-common.hpp | 4 ++++ src/vm/jit/show.cpp | 13 ++++++++--- 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/vm/global.h b/src/vm/global.h index 420352c6a..4443a806f 100644 --- a/src/vm/global.h +++ b/src/vm/global.h @@ -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 diff --git a/src/vm/jit/patcher-common.cpp b/src/vm/jit/patcher-common.cpp index c96f14808..5992bea1f 100644 --- a/src/vm/jit/patcher-common.cpp +++ b/src/vm/jit/patcher-common.cpp @@ -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::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. diff --git a/src/vm/jit/patcher-common.hpp b/src/vm/jit/patcher-common.hpp index 72ed1ec0b..159c6f5aa 100644 --- a/src/vm/jit/patcher-common.hpp +++ b/src/vm/jit/patcher-common.hpp @@ -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); diff --git a/src/vm/jit/show.cpp b/src/vm/jit/show.cpp index 24b64dfd0..6210c59b9 100644 --- a/src/vm/jit/show.cpp +++ b/src/vm/jit/show.cpp @@ -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"); -- 2.25.1