14 #if defined(JIT_DEBUG)
15 printf(
"-- jit --\n");
16 printf(
"; function definition: %p ; %u bytes\n", asmb->ptr, asmb->len);
17 # if defined(HAVE_LIBUDIS86) && (POTION_JIT_TARGET == POTION_X86)
22 ud_set_input_buffer(&ud_obj, asmb->ptr, asmb->len);
23 ud_set_mode(&ud_obj,
__WORDSIZE == 64 ? 64 : 32);
24 ud_set_syntax(&ud_obj, UD_SYN_ATT);
26 while (ud_disassemble(&ud_obj)) {
27 printf(
"0x%012lx 0x%lx %-24s \t%s\n", (
unsigned long)(ud_insn_off(&ud_obj)+(
unsigned long)asmb->ptr),
28 (
long)ud_insn_off(&ud_obj), ud_insn_hex(&ud_obj), ud_insn_asm(&ud_obj));
32 # if defined(HAVE_LIBDISTORM64) && (POTION_JIT_TARGET == POTION_X86)
34 #define MAX_INSTRUCTIONS 2048
35 #define MAX_TEXT_SIZE (60)
36 typedef enum {Decode16Bits = 0, Decode32Bits = 1, Decode64Bits = 2} _DecodeType;
37 typedef enum {DECRES_NONE, DECRES_SUCCESS, DECRES_MEMORYERR, DECRES_INPUTERR} _DecodeResult;
38 typedef long _OffsetType;
41 int8_t p[MAX_TEXT_SIZE];
46 _WString instructionHex;
50 _DecodeResult distorm_decode64(_OffsetType,
58 _DecodedInst disassembled[MAX_INSTRUCTIONS];
59 unsigned int decodedInstructionsCount = 0;
60 _OffsetType offset = 0;
63 distorm_decode64(offset,
64 (
const unsigned char*)asmb->ptr,
66 PN_SIZE_T == 8 ? Decode64Bits : Decode32Bits,
69 &decodedInstructionsCount);
70 for (i = 0; i < decodedInstructionsCount; i++) {
71 printf(
"0x%012lx 0x%04x (%02d) %-24s %s%s%s\r\n",
72 disassembled[i].offset + (
unsigned long)asmb->ptr,
73 (
unsigned int)disassembled[i].offset,
75 (
char*)disassembled[i].instructionHex.p,
76 (
char*)disassembled[i].mnemonic.p,
77 disassembled[i].operands.pos != 0 ?
" " :
"",
78 (
char*)disassembled[i].operands.p);
82 # if defined(HAVE_LIBDISASM) && (POTION_JIT_TARGET == POTION_X86)
83 # define LINE_SIZE 255
92 x86_init(opt_none, NULL, NULL);
93 while ( pos < size ) {
94 insnsize = x86_disasm(asmb->ptr, size, 0, pos, &insn);
97 x86_format_insn(&insn, line, LINE_SIZE, att_syntax);
98 printf(
"0x%x\t", pos);
99 for ( i = 0; i < 10; i++ ) {
100 if ( i < insn.size ) printf(
"%02x", insn.bytes[i]);
103 printf(
"%s\n", line);
106 printf(
"Invalid instruction at 0x%x. size=0x%x\n", pos, size);
114 for (ai = 0; ai < asmb->len; ai++) {
115 printf(
"%x ", asmb->ptr[ai]);