Issue1841378

classification
Title: Patch for [ 1757127 ] Jython hangs under PyDev debugger
Type: Severity: normal
Components: None Versions:
Milestone:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, paulj_edgewater
Priority: normal Keywords: patch

Created on 2007-11-30.01:19:35 by paulj_edgewater, last changed 2008-01-13.09:22:54 by cgroves.

Files
File name Uploaded Description Edit Remove
jython_trunk_debug_patch.txt paulj_edgewater, 2007-11-30.01:19:36 A patch version for the trunk
jython_2_2_1_debug_patch.txt paulj_edgewater, 2007-11-30.01:20:33 A patch version for 2.2.1
Messages
msg2961 (view) Author: paulj (paulj_edgewater) Date: 2007-11-30.01:19:35
I'm attaching a patch which I believe fixes (or at least greatly improves) problem 1757127 - Jython hangs under PyDev debugger

I'm attaching two versions: one for trunk, and one for Jython 2.2.1.

There seems to be some incompatibility between PyDev and the current Jython trunk version which causes an error when the interpreter is configured.

Description of change:
--------------------------------

PyDev was unable to debug using recent versions of Jython although it was fully capable of debugging 
using recent versions of CPython.

The root of the problem appears to be that Jython has a single global trace-function hook whereas CPython maintains 
a separate hook for each thread.

This patch changes Jython by moving the trace and profiling hooks from PySystemState.java (global) to ThreadState.java (thread-local) 
and by adjusting other code to adapt to that change.

The source for CPython 2.4 was used for comparision to verify that this is an appropriate fix.

Details of changes:
----------------------------

[ ThreadState.java ]

1) Moved tracefunc and profilefunc here from PySystemState.java

[ PySystemState.java ]

1) Moved tracefunc and profilefunc from here to ThreadState.java
2) In settrace() and setprofile() set the trace and profile functions in the corresponding ThreadState object rather than globally (i.e. PySystemState).

[ PythonTraceFunction.java ]

1) On error, clear the tracefunc and profilefunc in the corresponding ThreadState object rather than globally (i.e. PySystemState).

[ PyTableCode.java ]

1) Use  tracefunc and profilefunc from the corresponding ThreadState object rather than globally.
2) Set the line number in the frame before calling traceCall(). This seems to report the line number consistently with CPython.
3) Removed a large comment that appears to be outdated especially after the changes.

[ PyFrame.java ]

1) Add a comment for setline() since there is method in CPython that has a similar name but does something completely different.

[ InteractiveInterpreter.java ]

1) Use ThreadState rather that PySystemState

[ threading.py ]

1) Added setprofile() and settrace() from CPython 2.5

Testing done:
-------------------

A number of scripts were debugged using PyDev 1.3.8. The following features were tested:
Setting/clearing breakpoints
Stopping at breakpoints
Resuming from breakpoints
Stepping
Return from functions
Examining variables
Terminating a debug session
Some regression tests that use tracing/profiling were run:
test_trace.py - fails, is on the "failures" list. 
Note: CPython 2.4 also fails this test.
test_scope - passes
test_profilehooks - fails, is on the "failures" list
Note: CPython 2.4 also fails this test
Testing not done:
-------------------------
Not tested with any other debugger. Are there any others that work with Jython?
Profiling - this fix involves profiling but no tests were done for that.
Other programs (besides debuggers) that rely on tracing - perhaps other programs depend upon the existing Jython implementation.




msg2962 (view) Author: paulj (paulj_edgewater) Date: 2007-11-30.01:20:33
File Added: jython_2_2_1_debug_patch.txt
msg2963 (view) Author: Charlie Groves (cgroves) Date: 2008-01-13.09:22:54
It looks like profilefunc and tracefunc have been thread local since CPython 2.2 at least, so I've applied this patch to trunk in r4022 and to the 2.2 branch in r4023.  Thanks for the excellent patch and explanation.
History
Date User Action Args
2007-11-30 01:19:35paulj_edgewatercreate