dotgnu-pnet
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pnet-developers] Debugger with JIT coder


From: Radek Polak
Subject: [Pnet-developers] Debugger with JIT coder
Date: Fri, 28 Jul 2006 17:54:01 +0200
User-agent: Thunderbird 1.5.0.5 (Windows/20060719)

Hello,
could we please discuss debugging with jit coder? I hit problem when i was trying to implement debugger for jit engine. Here is it together with 3 possible solutions. Any comments are welcome.

Current debugger in pnet is working with CVM coder. If we want it working with JIT coder, we have to implement following two functions that are defined in engine/lib_diag.c:

int ILExecProcessWatchMethod(ILExecProcess *process, ILMethod *method);
void ILExecProcessWatchAll(ILExecProcess *process, int flag);


I have not studied how they are implemented in CVM coder. Important thing is that they work in this implementation. Since CVM engine is interpreter, i can imagine how these two functions are implemented, but i am not sure how to implement these functions with jit coder.

Here is how i would do it:

1) setup callback function with jit_debugger_hook_func() - this is common for following three approaches:

2a) call jit_insn_mark_breakpoint() in jit coder before every IL instruction.

In this case our callback function will be called before every instruction. In callback we decide whether stop or not and so on.

This will be obviously very slow. Callback is called N times where N is number of IL instructions executed).

However it's easy to implement and it will be working.

2b) use jit_insn_mark_breakpoint() the same way as above, but only in function that are watched - i would call ILIsBreak() to check if function is watched.

This approach will be very fast, because normaly we have just few breakpoints placed.

However this will not work when you place breakpoint inside function that is already compiled. Well we can recompile the function with breakpoints, but the changes will not take place immediately. Breakpoints will be there after function is called next time and that is too late when you want to implement stepping functions (step in could be ok, but step out would not work)

2c) when function is compiled with jit compiler, we could add nop instructions that are execatly the same size as code produced with jit_insn_mark_breakpoint(). For this we would need to add function like jit_insn_nops_for_breakpoint().

This would leave space for inserting/removing breakpoints when function is compiled. This is very important for implementing stepping functions, because they cant wait for function to be recompiled (see above).

So now ILExecProcessWatchMethod() could just scan compiled method and insert breakpoints instead nops. ILExecProcessWatchAll() would do this for all compiled methods.

This approach would need 3 new API functions in libjit:

jit_insn_nops_for_breakpoint()
jit_function_clear_breakpoints()
jit_function_add_breakpoint()

I am not sure what this approach would do with speed. Every IL instruction will be followed by bunch of nops. My guess is that time in nops could be smaller then time in execution IL, so the debugged program could run faster then 1/2 of it's original speed. In fact it would be much faster, because we are usually not placing any breakpoints in system libraries, so they stay in original speed.


So that is all. Thanks for reading and btw there is download page with working releases for PortableStudio at http://download.gna.org/libide/

Radek


reply via email to

[Prev in Thread] Current Thread [Next in Thread]