Re: [Pydev-code] Adding New Debug Feature - "Set Next Statement"
Brought to you by:
fabioz
From: Fabio Z. <fa...@gm...> - 2011-01-04 09:53:43
|
On Tue, Jan 4, 2011 at 5:09 AM, Hussain Bohra <hus...@ya...> wrote: > Hi Fabio, > > Current Pydev code has a 'Run To Line' feature which effectively works like > the 'Set Next Statement' of Visual Studio. While debugging python code we > realised that 'Run To Line' feature skips all lines between source line and > target line. This is not the case when we do 'Run To Line' in Java code. > Also, the pydev debugger breaks if the 'Run To Line' target is within a > 'For' or 'While' loop, with following exception: > > Traceback (most recent call last): > > File > "D:\Sims4\PyDev\pydev_1_6_3-0\aptana-Pydev-e2a3355\plugins\org.python.pydev.debug\pysrc\pydevd.py", > line 1148, in <module> > > debugger.run(setup['file'], None, None) > > File > "D:\Sims4\PyDev\pydev_1_6_3-0\aptana-Pydev-e2a3355\plugins\org.python.pydev.debug\pysrc\pydevd.py", > line 948, in run > > exec(compile(contents+"\n", file, 'exec'), globals, locals) #execute the > script > > File "D:\Sims4\runtime-EclipseApplication\Sims4Projects\src\gamescript.py", > line 69, in <module> > > debug_test() > > File "D:\Sims4\runtime-EclipseApplication\Sims4Projects\src\gamescript.py", > line 44, in debug_test > > for j in range(1, 50): > > File "D:\Sims4\runtime-EclipseApplication\Sims4Projects\src\gamescript.py", > line 44, in debug_test > > for j in range(1, 50): > > File > "D:\Sims4\PyDev\pydev_1_6_3-0\aptana-Pydev-e2a3355\plugins\org.python.pydev.debug\pysrc\pydevd_frame.py", > line 102, in trace_dispatch > > self.doWaitSuspend(thread, frame, event, arg) > > File > "D:\Sims4\PyDev\pydev_1_6_3-0\aptana-Pydev-e2a3355\plugins\org.python.pydev.debug\pysrc\pydevd_frame.py", > line 25, in doWaitSuspend > > self._args[0].doWaitSuspend(*args, **kwargs) > > File > "D:\Sims4\PyDev\pydev_1_6_3-0\aptana-Pydev-e2a3355\plugins\org.python.pydev.debug\pysrc\pydevd.py", > line 732, in doWaitSuspend > > frame.f_lineno = line > > ValueError: can't jump into the middle of a block > > > > We propose to add a new debugging feature in PyDev i.e. 'Set Next Statement' > wherein we will prevent the 'Set Next' target to be within a 'For' or > 'While' loop. > > The approach with which we are developing this is as follows: > > Added a new interface i.e. > 'org.python.pydev.debug.ui.actions.ISetNextTarget' and concrete > implementation class i.e. 'org.python.pydev.debug.model.PySetNextTarget'. > Added a new class 'org.python.pydev.debug.ui.actions.RetargetSetNextAction' > that implements 'org.eclipse.debug.internal.ui.actions.RetargetAction' > Added class to adapt PyEdit object into ISetNextTarget i.e. > 'org.python.pydev.debug.ui.PyEditSetNextAdapterFactory'. > We have added the extension points for Command, Action, Menu, Key Binding > and Adapters in 'org.python.pydev.debug\plugin.xml'. > We have also added the following line in > 'org.python.pydev.debug.model.remote.AbstractDebuggerCommand.java' > > static public final int CMD_SET_NEXT_STATEMENT = 121; > > On the python side we have changed/added following lines: > > > > 1.) Added new variable CMD_SET_NEXT_STATEMENT = > > 121 and > > Added '121':'CMD_SET_NEXT_STATEMENT', in 'ID_TO_MEANING'. > > in org.python.pydev.debug\pysrc\pydevd_comm.py > > > > 2.) Changed > > 'elif cmd_id == CMD_RUN_TO_LINE' To > > 'elif cmd_id == CMD_RUN_TO_LINE or cmd_id == CMD_SET_NEXT_STATEMENT' > > in PyDB.processNetCommand in 'org.python.pydev.debug\pysrc\pydevd.py' > > > > Inspite of making these changes it is not writing the correct command and > XML on 'WriterThread'. > > > > On 'Run To Line' It writes following on WriterThread: > > ('received command', '118\t27\tpid4980_seq1\t42\tdebug_test') > > sending cmd: CMD_THREAD_SUSPEND 105 20 <xml><thread id="pid4980_seq1" > stop_reason="111"><frame id="55169480" name="debug_test" > file="d%253A%255Csims4%255Cruntime-eclipseapplication%255Csims4projects%255Csrc%255Cgamescript.py" > line="42">"</frame><frame id="55571240" name="%26lt%3Bmodule%26gt%3B" > file="d%253A%255Csims4%255Cruntime-eclipseapplication%255Csims4projects%255Csrc%255Cgamescript.py" > line="62">"</frame><frame id="30904736" name="run" > file="d%253A%255Csims4%255Cpydev%255Cpydev_1_6_3-0%255Captana-pydev-e2a3355%255Cplugins%255Corg.python.pydev.debug%255Cpysrc%255Cpydevd.py" > line="951">"</frame><frame id="52251784" name="%26lt%3Bmodule%26gt%3B" > file="d%253A%255Csims4%255Cpydev%255Cpydev_1_6_3-0%255Captana-pydev-e2a3355%255Cplugins%255Corg.python.pydev.debug%255Cpysrc%255Cpydevd.py" > line="1151">"</frame></thread></xml> > > > > However in my new command implementation it writes only the following: > > ('received command ', '121\t29\tpid4980_seq1\t49\tdebug_test') > sending cmd: CMD_THREAD_RUN 106 22 pid4980_seq1 121 > > Please let me know if I am missing some thing. > > > In order to prevent the 'Set Next' target from being set within a 'For' or > 'While' loop, We have added new methods i.e. 'VisitFor' and 'VisitWhile' in > 'org.python.pydev.parser.visitors.scope.EasyASTIteratorVisitor' > which generates atomic node (ASTEntry) for 'For' and 'While'. > > I also need to modify 'NodeUtils.GetLineEnd' method to get end of line for > 'For' and 'While' Loops. > > Please let us know your views, comments and feedback on my problem and > approach. > > Thanks and Regards, > Hussain Bohra > > Hi Hussain, Just a doubt here... the idea is still making the jump when it gets out of the For or While or actually making a run to line? (I mean, if it's an actual 'run to line', then it makes sense creating a new action, if it's not, then maybe the proper way wouldn't be re-targeting the current action, but just changing the current run to line to be different to handle the while/for). Personally, I think it'd be nice having the current action (which is actually the jump) in an action called 'set next statement' (which could probably be changed to handle the behavior to exhaust the current for/while before making the jump) and a new action which would be the real 'run to line'. As for the comments on the changes, it's a bit hard to say what could be wrong just from your description below (which seems right), so, I guess I'd have to take a look at the actual implementation... I saw that you forked pydev on github (https://github.com/hussainbohra/Pydev/), but your changes don't seem to be there, so, it'd be nice if you created a branch on git, committed the code there and passed me the link to the branch so that I can take a look at it. Just a note... for the EasyASTIteratorVisitor, it might be better creating a subclass for getting the additional for/while, as there might be clients that break if you change what it returns. Cheers, Fabio |