[Pydev-cvs] org.python.pydev.debug/src/org/python/pydev/debug/ui/launching PythonRunner.java,1.2,1.3
Brought to you by:
fabioz
From: Aleksandar T. <at...@us...> - 2004-04-22 10:56:26
|
Update of /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18445/src/org/python/pydev/debug/ui/launching Modified Files: PythonRunner.java PythonRunnerConfig.java Log Message: The beginning of the new debugger technology Index: PythonRunner.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching/PythonRunner.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PythonRunner.java 15 Apr 2004 23:24:49 -0000 1.2 --- PythonRunner.java 22 Apr 2004 10:56:17 -0000 1.3 *************** *** 21,25 **** import org.python.pydev.debug.core.Constants; import org.python.pydev.debug.core.PydevDebugPlugin; ! import org.python.pydev.debug.model.PythonDebugTarget; import org.python.pydev.debug.model.RemoteDebugger; --- 21,25 ---- import org.python.pydev.debug.core.Constants; import org.python.pydev.debug.core.PydevDebugPlugin; ! import org.python.pydev.debug.model.PyDebugTarget; import org.python.pydev.debug.model.RemoteDebugger; *************** *** 32,75 **** public class PythonRunner { - class DebugConnector implements Runnable { - int port; - int timeout; - ServerSocket serverSocket; - Socket socket; // what got accepted - Exception e; - - boolean terminated; - - public DebugConnector(int port, int timeout) throws IOException { - this.port = port; - this.timeout = timeout; - serverSocket = new ServerSocket(port); - } - - Exception getException() { - return e; - } - - public Socket getSocket() { - return socket; - } - - public void stopListening() throws IOException { - if (serverSocket != null) - serverSocket.close(); - terminated = true; - } - - public void run() { - try { - serverSocket.setSoTimeout(timeout); - socket = serverSocket.accept(); - } - catch (IOException e) { - this.e = e; - } - } - } public void runDebug(PythonRunnerConfig config, ILaunch launch, IProgressMonitor monitor) throws CoreException, IOException { if (monitor == null) --- 32,41 ---- public class PythonRunner { + /** + * Launches the config in the debug mode. + * + * Loosely modeled upon Ant launcher. + */ public void runDebug(PythonRunnerConfig config, ILaunch launch, IProgressMonitor monitor) throws CoreException, IOException { if (monitor == null) *************** *** 79,91 **** // Launch & connect to the debugger ! subMonitor.subTask("Finding free socket..."); ! DebugConnector server = new DebugConnector(config.getDebugPort(), config.acceptTimeout); ! subMonitor.worked(1); subMonitor.subTask("Constructing command_line..."); String[] cmdLine = config.getCommandLine(); ! subMonitor.worked(1); ! ! Thread connectThread = new Thread(server, "Pydev debug listener"); ! connectThread.start(); Process p = DebugPlugin.exec(cmdLine, config.workingDirectory); if (p == null) --- 45,53 ---- // Launch & connect to the debugger ! RemoteDebugger debugger = new RemoteDebugger(config); ! debugger.startConnect(subMonitor); subMonitor.subTask("Constructing command_line..."); String[] cmdLine = config.getCommandLine(); ! Process p = DebugPlugin.exec(cmdLine, config.workingDirectory); if (p == null) *************** *** 94,127 **** IProcess process = registerWithDebugPlugin(config, launch, p); ! // Register the process with the debug plugin ! subMonitor.worked(2); ! subMonitor.subTask("Starting debugger..."); ! // Launch the debug listener on a thread, and wait until it completes ! while (connectThread.isAlive()) { ! if (monitor.isCanceled()) { ! server.stopListening(); ! p.destroy(); return; } - try { - p.exitValue(); // throws exception if process has terminated - // process has terminated - stop waiting for a connection - try { - server.stopListening(); - } catch (IOException e) { - // expected - } - checkErrorMessage(process); - } catch (IllegalThreadStateException e) { - // expected while process is alive - } - try { - Thread.sleep(100); - } catch (InterruptedException e) { - } } ! ! Exception ex = server.getException(); ! if (ex != null) { process.terminate(); p.destroy(); --- 56,68 ---- IProcess process = registerWithDebugPlugin(config, launch, p); ! subMonitor.subTask("Waiting for connection..."); ! try { ! boolean userCanceled = debugger.waitForConnect(subMonitor, p, process); ! if (userCanceled) { ! debugger.dispose(); return; } } ! catch (Exception ex) { process.terminate(); p.destroy(); *************** *** 129,148 **** if (ex instanceof SocketTimeoutException) message = "Timed out after " + Float.toString(config.acceptTimeout/1000) + " seconds while waiting for python script to connect."; ! throw new CoreException(new Status(IStatus.ERROR, PydevDebugPlugin.getPluginID(), 0, message, ex)); } // hook up debug model, and we are off & running ! RemoteDebugger debugger = new RemoteDebugger(server.getSocket()); ! PythonDebugTarget t = new PythonDebugTarget(launch, process, ! config.getRunningName(), debugger); ! Thread dt = new Thread(debugger, "Pydev remote debug connection"); ! dt.start(); } /** ! * launches the debug configuration ! * @param config ! * @param launch ! * @param monitor ! * @throws CoreException */ public void run(PythonRunnerConfig config, ILaunch launch, IProgressMonitor monitor) throws CoreException, IOException { --- 70,85 ---- if (ex instanceof SocketTimeoutException) message = "Timed out after " + Float.toString(config.acceptTimeout/1000) + " seconds while waiting for python script to connect."; ! throw new CoreException(new Status(IStatus.ERROR, PydevDebugPlugin.getPluginID(), 0, message, ex)); } + subMonitor.subTask("Done"); // hook up debug model, and we are off & running ! PyDebugTarget t = new PyDebugTarget(launch, process, ! config.file, debugger); } /** ! * Launches the configuration ! * ! * The code is modeled after Ant launching example. */ public void run(PythonRunnerConfig config, ILaunch launch, IProgressMonitor monitor) throws CoreException, IOException { *************** *** 159,163 **** subMonitor.subTask("Constructing command_line..."); String[] cmdLine = config.getCommandLine(); - subMonitor.worked(1); subMonitor.subTask("Exec..."); --- 96,99 ---- *************** *** 167,171 **** // Register the process with the debug plugin - subMonitor.worked(2); subMonitor.subTask("Done"); registerWithDebugPlugin(config, launch, p); --- 103,106 ---- *************** *** 173,177 **** /** ! * TODO document */ private IProcess registerWithDebugPlugin(PythonRunnerConfig config, ILaunch launch, Process p) { --- 108,113 ---- /** ! * The debug plugin needs to be notified about our process. ! * It'll then display the appropriate UI. */ private IProcess registerWithDebugPlugin(PythonRunnerConfig config, ILaunch launch, Process p) { *************** *** 181,190 **** return DebugPlugin.newProcess(launch,p, config.file.lastSegment(), processAttributes); } - - protected void checkErrorMessage(IProcess process) throws CoreException { - String errorMessage= process.getStreamsProxy().getErrorStreamMonitor().getContents(); - if (errorMessage.length() != 0) - // TODO not sure if this is really an error - throw new CoreException(new Status(IStatus.ERROR, PydevDebugPlugin.getPluginID(), 0, "Something got printed in the error stream", null)); - } } --- 117,119 ---- Index: PythonRunnerConfig.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/ui/launching/PythonRunnerConfig.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PythonRunnerConfig.java 15 Apr 2004 23:24:49 -0000 1.2 --- PythonRunnerConfig.java 22 Apr 2004 10:56:17 -0000 1.3 *************** *** 91,95 **** */ public static String getDebugScript() throws CoreException { ! IPath relative = new Path("pysrc").addTrailingSeparator().append("jpydaemon.py"); // IPath relative = new Path("pysrc").addTrailingSeparator().append("rpdb.py"); URL location = org.python.pydev.debug.core.PydevDebugPlugin.getDefault().find(relative); --- 91,96 ---- */ public static String getDebugScript() throws CoreException { ! IPath relative = new Path("pysrc").addTrailingSeparator().append("pydevd.py"); ! // IPath relative = new Path("pysrc").addTrailingSeparator().append("jpydaemon.py"); // IPath relative = new Path("pysrc").addTrailingSeparator().append("rpdb.py"); URL location = org.python.pydev.debug.core.PydevDebugPlugin.getDefault().find(relative); *************** *** 112,118 **** --- 113,125 ---- // cmdArgs.add("-c"); // cmdArgs.add("-p"+Integer.toString(debugPort)); + // jpydebug cmdArgs.add(debugScript); + // cmdArgs.add("localhost"); + // cmdArgs.add(Integer.toString(debugPort)); cmdArgs.add(debugScript); + cmdArgs.add("--client"); cmdArgs.add("localhost"); + cmdArgs.add("--port"); cmdArgs.add(Integer.toString(debugPort)); + cmdArgs.add("--file"); } cmdArgs.add(file.toOSString()); |