JIT now properly handles debug mode

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40246
This commit is contained in:
David Anderson 2007-01-01 03:23:57 +00:00
parent 378e4d20f3
commit 2a8542f7a4
2 changed files with 34 additions and 11 deletions

View File

@ -1306,11 +1306,12 @@ inline void WriteOp_Break(JitWriter *jit)
CompData *data = (CompData *)jit->data;
if (data->debug)
{
jit->write_ubyte(IA32_INT3);
//mov ecx, <cip>
jitoffs_t wr = IA32_Mov_Reg_Imm32(jit, AMX_REG_TMP, 0);
jitoffs_t save = jit->get_outputpos();
jit->set_outputpos(wr);
jit->write_uint32((uint32_t)(jit->outbase + wr));
jit->write_uint32((uint32_t)(wr));
jit->set_outputpos(save);
wr = IA32_Call_Imm32(jit, 0);
@ -1849,8 +1850,8 @@ jitoffs_t RelocLookup(JitWriter *jit, cell_t pcode_offs, bool relative)
*/
pcode_offs += jit->get_inputpos();
}
/* Offset must always be 1)positive and 2)less than the codesize */
assert(pcode_offs >= 0 && (uint32_t)pcode_offs < data->codesize);
/* Offset must always be 1)positive and 2)less than or equal to the codesize */
assert(pcode_offs >= 0 && (uint32_t)pcode_offs <= data->codesize);
/* Do the lookup in the native dictionary. */
return *(jitoffs_t *)(data->rebase + pcode_offs);
} else {
@ -1916,7 +1917,8 @@ sp_context_t *JITX86::CompileToContext(ICompilation *co, int *err)
writer.inbase = (cell_t *)code;
writer.outptr = NULL;
writer.outbase = NULL;
data->rebase = (jitcode_t)engine->BaseAlloc(plugin->pcode_size);
/* Allocate relocation. One extra cell for final CIP. */
data->rebase = (jitcode_t)engine->BaseAlloc(plugin->pcode_size + sizeof(cell_t));
/* We will jump back here for second pass */
jit_rewind:
@ -1935,6 +1937,13 @@ jit_rewind:
WriteOp_Sysreq_N_Function(jit);
}
/* Write the debug section if we need it */
if (data->debug == true)
{
data->jit_break = jit->get_outputpos();
Write_BreakDebug(jit);
}
/* Plugins compiled with -O0 will need this! */
data->jit_sysreq_c = jit->get_outputpos();
WriteOp_Sysreq_C_Function(jit);
@ -1986,6 +1995,11 @@ jit_rewind:
/* Write these last because error jumps should be unpredicted, and thus forward */
WriteErrorRoutines(data, jit);
/* Write the final CIP to the last position in the reloc array */
pcode_offs = (jitoffs_t)((uint8_t *)writer.inptr - code);
native_offs = jit->get_outputpos();
*((jitoffs_t *)(data->rebase + pcode_offs)) = native_offs;
/* the total codesize is now known! */
codemem = writer.get_outputpos();
writer.outbase = (jitcode_t)engine->ExecAlloc(codemem);
@ -2196,7 +2210,12 @@ bool JITX86::SetCompilationOption(ICompilation *co, const char *key, const char
if (strcmp(key, "debug") == 0)
{
data->debug = (atoi(val) == 1);
if ((atoi(val) == 1) || !strcmp(val, "yes"))
{
data->debug = true;
} else {
data->debug = false;
}
if (data->debug && !(data->plugin->flags & SP_FLAG_DEBUG))
{
data->debug = false;

View File

@ -127,24 +127,26 @@ jitoffs_t Write_Execute_Function(JitWriter *jit)
void Write_BreakDebug(JitWriter *jit)
{
//push ecx
//push edi
//mov edi, ecx
//mov ecx, [esi+ctx]
//cmp [ecx+dbreak], 0
//jnz :nocall
IA32_Push_Reg(jit, AMX_REG_TMP);
IA32_Push_Reg(jit, REG_EDI);
IA32_Mov_Reg_Rm(jit, REG_EDI, REG_ECX, MOD_REG);
IA32_Mov_Reg_Rm_Disp8(jit, AMX_REG_TMP, AMX_REG_INFO, AMX_INFO_CONTEXT);
IA32_Cmp_Rm_Disp8_Imm8(jit, AMX_REG_TMP, offsetof(sp_context_t, dbreak), 0);
jitoffs_t jmp = IA32_Jump_Cond_Imm8(jit, CC_NZ, 0);
jitoffs_t jmp = IA32_Jump_Cond_Imm8(jit, CC_Z, 0);
/* NOTE, Hack! PUSHAD pushes EDI last which still has the CIP */
//pushad
IA32_Pushad(jit);
//push [esi+frm]
//push ctx
//mov ecx, [ecx+dbreak]
//call ecx
//add esp, 8
//popad
IA32_Pushad(jit);
IA32_Push_Rm_Disp8(jit, AMX_REG_INFO, AMX_INFO_FRAME); //:TODO: move to regs and push? and dont disp for 0
IA32_Push_Reg(jit, AMX_REG_TMP);
IA32_Mov_Reg_Rm_Disp8(jit, AMX_REG_TMP, AMX_REG_TMP, offsetof(sp_context_t, dbreak));
@ -153,8 +155,10 @@ void Write_BreakDebug(JitWriter *jit)
IA32_Popad(jit);
//:nocall
//pop edi
//ret
IA32_Pop_Reg(jit, REG_EDI);
IA32_Send_Jump8_Here(jit, jmp);
IA32_Add_Rm_Imm8(jit, REG_ESP, 4*1, MOD_REG);
IA32_Return(jit);
}