[Pydev-cvs] org.python.pydev.debug/src/org/python/pydev/debug/model PyDebugModelPresentation.java,1.
Brought to you by:
fabioz
Update of /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9465/src/org/python/pydev/debug/model Modified Files: PyDebugModelPresentation.java PyVariable.java PyVariableCollection.java PyThread.java PySourceLocator.java PyDebugTarget.java Log Message: Final touches. Debugger is ready to go Index: PyThread.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/model/PyThread.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PyThread.java 5 May 2004 02:02:00 -0000 1.4 --- PyThread.java 7 May 2004 21:50:59 -0000 1.5 *************** *** 56,59 **** --- 56,63 ---- return id; } + + public boolean isPydevThread() { + return isPydevThread; + } public int getPriority() throws DebugException { *************** *** 180,184 **** public IBreakpoint[] getBreakpoints() { ! // TODO Auto-generated method stub return null; } --- 184,189 ---- public IBreakpoint[] getBreakpoints() { ! // should return breakpoint that caused this thread to suspend ! // not implementing this seems to cause no harm return null; } Index: PyVariable.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/model/PyVariable.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyVariable.java 5 May 2004 02:02:00 -0000 1.1 --- PyVariable.java 7 May 2004 21:50:59 -0000 1.2 *************** *** 17,22 **** /** ! * ! * TODO Comment this class * */ --- 17,25 ---- /** ! * Represents a python variable. ! * ! * Eclipse gives you an option to separate implementation of variable ! * and its value. I've found it convenient to roll both of them into 1 ! * class. * */ *************** *** 35,38 **** --- 38,45 ---- } + public String getDetailText() throws DebugException { + return getValueString(); + } + public IValue getValue() throws DebugException { return this; *************** *** 66,70 **** /** ! * TODO valueChanging nterface has not been implemented yet. * When implemented, recently changed variables are shown in red. */ --- 73,77 ---- /** ! * LATER valueChanging nterface has not been implemented yet. * When implemented, recently changed variables are shown in red. */ *************** *** 97,103 **** return target.getAdapter(adapter); else if (adapter.equals(IPropertySource.class) || ! adapter.equals(ITaskListResourceAdapter.class)) return super.getAdapter(adapter); // ongoing, I do not fully understand all the interfaces they'd like me to support System.err.println("PyVariable Need adapter " + adapter.toString()); return super.getAdapter(adapter); --- 104,115 ---- return target.getAdapter(adapter); else if (adapter.equals(IPropertySource.class) || ! adapter.equals(ITaskListResourceAdapter.class) || ! adapter.equals(org.eclipse.ui.IContributorResourceAdapter.class) || ! adapter.equals(org.eclipse.ui.IActionFilter.class) || ! adapter.equals(org.eclipse.ui.model.IWorkbenchAdapter.class) ! ) return super.getAdapter(adapter); // ongoing, I do not fully understand all the interfaces they'd like me to support + // so I print them out as errors System.err.println("PyVariable Need adapter " + adapter.toString()); return super.getAdapter(adapter); Index: PyVariableCollection.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/model/PyVariableCollection.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyVariableCollection.java 5 May 2004 02:02:00 -0000 1.1 --- PyVariableCollection.java 7 May 2004 21:50:59 -0000 1.2 *************** *** 18,23 **** /** ! * ! * TODO Comment this class */ public class PyVariableCollection extends PyVariable implements ICommandResponseListener, IVariableLocator { --- 18,25 ---- /** ! * PyVariableCollection represents container variables. ! * ! * It knows how to fetch its contents over the network. ! * */ public class PyVariableCollection extends PyVariable implements ICommandResponseListener, IVariableLocator { *************** *** 34,37 **** --- 36,54 ---- } + public String getDetailText() throws DebugException { + return super.getDetailText(); + // StringBuffer buf = new StringBuffer(); + // buf.append("{ "); + // for (int i=0; i<variables.length; i++) { + // buf.append(variables[i].getName()); + // buf.append(" : "); + // buf.append(variables[i].getValueString()); + // if (i != variables.length - 1) + // buf.append(", "); + // } + // buf.append(" }"); + // return buf.toString(); + } + public String getPyDBLocation() { return locator.getPyDBLocation() + "\t" + name; Index: PyDebugModelPresentation.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/model/PyDebugModelPresentation.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyDebugModelPresentation.java 7 May 2004 02:03:07 -0000 1.1 --- PyDebugModelPresentation.java 7 May 2004 21:50:59 -0000 1.2 *************** *** 11,15 **** --- 11,18 ---- import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; + import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; + import org.eclipse.core.runtime.Path; + import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.model.IValue; import org.eclipse.debug.ui.IDebugModelPresentation; *************** *** 19,23 **** --- 22,28 ---- import org.eclipse.swt.graphics.Image; import org.eclipse.ui.IEditorInput; + import org.eclipse.ui.IEditorPart; import org.python.pydev.debug.core.PydevDebugPlugin; + import org.python.pydev.plugin.PydevPlugin; /** *************** *** 30,33 **** --- 35,39 ---- protected ListenerList fListeners= new ListenerList(); + protected boolean displayVariableTypeNames = false; // variables display attribute public Image getImage(Object element) { *************** *** 41,44 **** --- 47,54 ---- PydevDebugPlugin.log(IStatus.ERROR, "getImage error", e); } + } else if (element instanceof PyVariableCollection) { + return PydevDebugPlugin.getImageCache().get("icons/greendot_big.gif"); + } else if (element instanceof PyVariable) { + return PydevDebugPlugin.getImageCache().get("icons/greendot.gif"); } else if (element instanceof PyDebugTarget || *************** *** 78,82 **** || element instanceof PyStackFrame || element instanceof PyThread) { ! return null; } PydevDebugPlugin.log(IStatus.ERROR, "unknown debug type", null); --- 88,95 ---- || element instanceof PyStackFrame || element instanceof PyThread) { ! return null; // defaults work ! } else if (element instanceof PyVariableCollection ! || element instanceof PyVariable) { ! return null; // defaults are fine } PydevDebugPlugin.log(IStatus.ERROR, "unknown debug type", null); *************** *** 85,117 **** /** ! * override ! * TODO comment this method */ public void computeDetail(IValue value, IValueDetailListener listener) { ! // TODO Auto-generated method stub ! System.out.println("in detail"); } /** ! * override ! * TODO comment this method */ public IEditorInput getEditorInput(Object element) { ! // TODO Auto-generated method stub return null; } /** ! * override ! * TODO comment this method */ public String getEditorId(IEditorInput input, Object element) { - // TODO Auto-generated method stub return null; } public void setAttribute(String attribute, Object value) { ! // TODO Auto-generated method stub ! System.out.println("setattribute"); } --- 98,140 ---- /** ! * We've got some work to do to replicate here, because we ! * can't return null, and have LazyModel presentation do the default */ public void computeDetail(IValue value, IValueDetailListener listener) { ! if (value instanceof PyVariable) { ! try { ! ((PyVariable)value).getVariables(); ! listener.detailComputed(value, ((PyVariable)value).getDetailText()); ! } catch (DebugException e) { ! PydevDebugPlugin.errorDialog("Unexpected error fetching variable", e); ! } ! } } /** ! * Returns editor to be displayed */ public IEditorInput getEditorInput(Object element) { ! if (element instanceof PyBreakpoint) { ! String file = ((PyBreakpoint)element).getFile(); ! IPath path = new Path(file); ! IEditorPart part = PydevPlugin.doOpenEditor(path, false); ! return part.getEditorInput(); ! } return null; } /** ! * @see org.eclipse.debug.ui.ISourcePresentation#getEditorInput */ public String getEditorId(IEditorInput input, Object element) { return null; } public void setAttribute(String attribute, Object value) { ! if (attribute.equals(IDebugModelPresentation.DISPLAY_VARIABLE_TYPE_NAMES)) ! displayVariableTypeNames = ((Boolean)value).booleanValue(); ! else ! System.err.println("setattribute"); } *************** *** 127,136 **** } - public boolean isLabelProperty(Object element, String property) { // Not really sure what this does. see IBaseLabelProvider:isLabelProperty return false; } - - } --- 150,156 ---- Index: PySourceLocator.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/model/PySourceLocator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PySourceLocator.java 28 Apr 2004 02:49:48 -0000 1.2 --- PySourceLocator.java 7 May 2004 21:50:59 -0000 1.3 *************** *** 12,22 **** import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.python.pydev.plugin.PydevPlugin; /** ! * ! * TODO Comment this class * - * Take a look at IDebugModelPresentation */ public class PySourceLocator implements ISourceLocator, ISourcePresentation { --- 12,21 ---- import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; + import org.python.pydev.editor.PyEdit; import org.python.pydev.plugin.PydevPlugin; /** ! * Locates source files from stack elements * */ public class PySourceLocator implements ISourceLocator, ISourcePresentation { *************** *** 30,34 **** IPath path = ((PyStackFrame)element).getPath(); if (path != null) { ! IEditorPart part = PydevPlugin.getDefault().doOpenEditor(path, false); if (part != null) { return part.getEditorInput(); --- 29,33 ---- IPath path = ((PyStackFrame)element).getPath(); if (path != null) { ! IEditorPart part = PydevPlugin.doOpenEditor(path, false); if (part != null) { return part.getEditorInput(); *************** *** 40,44 **** public String getEditorId(IEditorInput input, Object element) { ! return "org.python.pydev.editor.PythonEditor"; } --- 39,43 ---- public String getEditorId(IEditorInput input, Object element) { ! return PyEdit.EDITOR_ID; } Index: PyDebugTarget.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.debug/src/org/python/pydev/debug/model/PyDebugTarget.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PyDebugTarget.java 7 May 2004 02:03:07 -0000 1.5 --- PyDebugTarget.java 7 May 2004 21:50:59 -0000 1.6 *************** *** 10,14 **** --- 10,16 ---- import org.eclipse.core.resources.IFile; + import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IMarkerDelta; + import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; *************** *** 32,37 **** import org.eclipse.ui.views.tasklist.ITaskListResourceAdapter; import org.python.pydev.debug.core.PydevDebugPlugin; import org.python.pydev.debug.model.remote.*; - /** * Debugger class that represents a single python process. --- 34,39 ---- import org.eclipse.ui.views.tasklist.ITaskListResourceAdapter; import org.python.pydev.debug.core.PydevDebugPlugin; + import org.python.pydev.debug.core.PydevDebugPrefs; import org.python.pydev.debug.model.remote.*; /** * Debugger class that represents a single python process. *************** *** 66,69 **** --- 68,102 ---- } + /** + * Called after debugger has been connected. + * + * Here we send all the initialization commands + */ + public void initialize() { + // we post version command just for fun + // it establishes the connection + debugger.postCommand(new VersionCommand(debugger)); + + // now, register all the breakpoints in our project + IFile launched = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(file); + IProject project = launched.getProject(); + try { + IMarker[] markers = project.findMarkers(PyBreakpoint.PY_BREAK_MARKER, true, IResource.DEPTH_INFINITE); + IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager(); + for (int i= 0; i < markers.length; i++) { + PyBreakpoint brk = (PyBreakpoint)breakpointManager.getBreakpoint(markers[i]); + if (brk.isEnabled()) { + SetBreakpointCommand cmd = new SetBreakpointCommand(debugger, brk.getFile(), brk.getLine()); + debugger.postCommand(cmd); + } + } + } catch (Throwable t) { + PydevDebugPlugin.errorDialog("Error setting breakpoints", t); + } + // Send the run command, and we are off + RunCommand run = new RunCommand(debugger); + debugger.postCommand(run); + } + public RemoteDebugger getDebugger() { return debugger; *************** *** 201,208 **** public void breakpointAdded(IBreakpoint breakpoint) { ! if (breakpoint instanceof PyBreakpoint) { ! PyBreakpoint b = (PyBreakpoint)breakpoint; ! SetBreakpointCommand cmd = new SetBreakpointCommand(debugger, b.getFile(), b.getLine()); ! debugger.postCommand(cmd); } } --- 234,245 ---- public void breakpointAdded(IBreakpoint breakpoint) { ! try { ! if (breakpoint instanceof PyBreakpoint && ((PyBreakpoint)breakpoint).isEnabled()) { ! PyBreakpoint b = (PyBreakpoint)breakpoint; ! SetBreakpointCommand cmd = new SetBreakpointCommand(debugger, b.getFile(), b.getLine()); ! debugger.postCommand(cmd); ! } ! } catch (CoreException e) { ! e.printStackTrace(); } } *************** *** 301,304 **** --- 338,364 ---- return; } + + // Hide Pydevd threads if requested + if (PydevDebugPrefs.getPreferences().getBoolean(PydevDebugPrefs.HIDE_PYDEVD_THREADS)) { + int removeThisMany = 0; + for (int i=0; i< newThreads.length; i++) + if (((PyThread)newThreads[i]).isPydevThread()) + removeThisMany++; + if (removeThisMany > 0) { + int newSize = newThreads.length - removeThisMany; + if (newSize == 0) // no threads to add + return; + else { + IThread[] newnewThreads = new IThread[newSize]; + int ii = 0; + for (int i =0; i< newThreads.length; i++) + if (!((PyThread)newThreads[i]).isPydevThread()) + newnewThreads[ii++] = newThreads[i]; + newThreads = newnewThreads; + } + } + } + + // add threads to the thread list, and fire event if (threads == null) threads = newThreads; *************** *** 362,366 **** } } ! static Pattern threadRunPattern = Pattern.compile("(\\d+)\\t(\\w*)"); /** --- 422,427 ---- } } ! ! // thread_id\tresume_reason static Pattern threadRunPattern = Pattern.compile("(\\d+)\\t(\\w*)"); /** |