⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractdebugtarget.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.python.pydev.debug.model;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IBreakpointManager;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchListener;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IMemoryBlock;
import org.eclipse.debug.core.model.IStackFrame;
import org.eclipse.debug.core.model.IThread;
import org.eclipse.debug.internal.ui.views.console.ProcessConsole;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocumentListener;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.internal.console.IOConsolePartition;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.tasklist.ITaskListResourceAdapter;
import org.python.pydev.core.ExtensionHelper;
import org.python.pydev.core.log.Log;
import org.python.pydev.debug.core.IConsoleInputListener;
import org.python.pydev.debug.core.PydevDebugPlugin;
import org.python.pydev.debug.core.PydevDebugPrefs;
import org.python.pydev.debug.model.remote.AbstractDebuggerCommand;
import org.python.pydev.debug.model.remote.AbstractRemoteDebugger;
import org.python.pydev.debug.model.remote.RemoveBreakpointCommand;
import org.python.pydev.debug.model.remote.RunCommand;
import org.python.pydev.debug.model.remote.SetBreakpointCommand;
import org.python.pydev.debug.model.remote.ThreadListCommand;
import org.python.pydev.debug.model.remote.VersionCommand;

public abstract class AbstractDebugTarget extends PlatformObject implements IDebugTarget, ILaunchListener {
	
	protected IPath file;
	protected PyThread[] threads;
	protected boolean disconnected = false;
	protected AbstractRemoteDebugger debugger;	
	protected ILaunch launch;
    private ValueModificationChecker modificationChecker;

    public AbstractDebugTarget() {
        modificationChecker = new ValueModificationChecker();
    }
    
    public ValueModificationChecker getModificationChecker(){
        return modificationChecker;
    }
	
	public abstract boolean canTerminate();
	public abstract boolean isTerminated();
	public abstract void terminate() throws DebugException;
	
	public AbstractRemoteDebugger getDebugger() {
		return debugger;
	}
	
	public void debuggerDisconnected() {
		disconnected = true;
		fireEvent(new DebugEvent(this, DebugEvent.CHANGE));
	}
	
	public void launchAdded(ILaunch launch) {
		// noop
	}

	public void launchChanged(ILaunch launch) {
		// noop		
	}
	
	// From IDebugElement
	public String getModelIdentifier() {
		return PyDebugModelPresentation.PY_DEBUG_MODEL_ID;
	}
	// From IDebugElement
	public IDebugTarget getDebugTarget() {
		return this;
	}	
	
	public String getName() throws DebugException {
		if (file != null)
			return file.lastSegment();
		else
			return "unknown";
	}
	
	public boolean canResume() {
		for (int i=0; i< threads.length; i++)
			if (threads[i].canResume())
				return true;
		return false;
	}

	public boolean canSuspend() {
		for (int i=0; i< threads.length; i++)
			if (threads[i].canSuspend())
				return true;
		return false;
	}

	public boolean isSuspended() {
		return false;
	}

	public void resume() throws DebugException {
		for (int i=0; i< threads.length; i++)
			threads[i].resume();
	}

	public void suspend() throws DebugException {
		for (int i=0; i< threads.length; i++){
			threads[i].suspend();
		}
	}
	
	public IThread[] getThreads() throws DebugException {
		if (debugger == null){
			return null;
		}
		
		if (threads == null) {
			ThreadListCommand cmd = new ThreadListCommand(debugger, this);
			debugger.postCommand(cmd);
			try {
				cmd.waitUntilDone(1000);
				threads = cmd.getThreads();
			} catch (InterruptedException e) {
				threads = new PyThread[0];
			}
		}
		return threads;
	}

	public boolean hasThreads() throws DebugException {
		return true;
	}

    //Breakpoints ------------------------------------------------------------------------------------------------------
	public boolean supportsBreakpoint(IBreakpoint breakpoint) {
		return breakpoint instanceof PyBreakpoint;
	}
	
	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(), b.getCondition(), b.getFunctionName());
				debugger.postCommand(cmd);
			}
		} catch (CoreException e) {
			e.printStackTrace();
		}
	}

	public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) {
		if (breakpoint instanceof PyBreakpoint) {
			PyBreakpoint b = (PyBreakpoint)breakpoint;
			RemoveBreakpointCommand cmd = new RemoveBreakpointCommand(debugger, b.getFile(), b.getLine());
			debugger.postCommand(cmd);
		}
	}

	public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) {
		if (breakpoint instanceof PyBreakpoint) {
			breakpointRemoved(breakpoint, null);
			breakpointAdded(breakpoint);
		}
	}
	//End Breakpoints --------------------------------------------------------------------------------------------------

    
    // Storage retrieval is not supported
	public boolean supportsStorageRetrieval() {
		return false;
	}

	public IMemoryBlock getMemoryBlock(long startAddress, long length) throws DebugException {
		return null;
	}	

	/**
	 * When a command that originates from daemon is received,
	 * this routine processes it.
	 * The responses to commands originating from here
	 * are processed by commands themselves
	 */
	public void processCommand(String sCmdCode, String sSeqCode, String payload) {
		try {
            int cmdCode = Integer.parseInt(sCmdCode);
            
            if (cmdCode == AbstractDebuggerCommand.CMD_THREAD_CREATED){
                processThreadCreated(payload);
                
            }else if (cmdCode == AbstractDebuggerCommand.CMD_THREAD_KILL){
                processThreadKilled(payload);
                
            }else if (cmdCode == AbstractDebuggerCommand.CMD_THREAD_SUSPEND){
                processThreadSuspended(payload);
                
            }else if (cmdCode == AbstractDebuggerCommand.CMD_THREAD_RUN){
                processThreadRun(payload);
                
            }else{
                PydevDebugPlugin.log(IStatus.WARNING, "Unexpected debugger command:" + sCmdCode+"\nseq:"+sSeqCode+"\npayload:"+payload, null);
            }
        } catch (Exception e) {
            PydevDebugPlugin.log(IStatus.ERROR, "Error processing: " + sCmdCode+"\npayload: "+payload, e); 
        }	
	}

	protected void fireEvent(DebugEvent event) {
		DebugPlugin manager= DebugPlugin.getDefault();
		if (manager != null) {
			manager.fireDebugEventSet(new DebugEvent[]{event});
		}
	}

	/**
	 * @return an existing thread with a given id (null if none)
	 */
	protected PyThread findThreadByID(String thread_id)  {		
		for (IThread thread : threads){
			if (thread_id.equals(((PyThread)thread).getId())){
				return (PyThread)thread;
            }
        }
		return null;
	}
	
	/**
	 * Add it to the list of threads
	 */
	private void processThreadCreated(String payload) {
		
		PyThread[] newThreads;
		try {
			newThreads = XMLUtils.ThreadsFromXML(this, payload);
		} catch (CoreException e) {
			PydevDebugPlugin.errorDialog("Error in processThreadCreated", e);
			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 {
					
                    PyThread[] newnewThreads = new PyThread[newSize];
					int i = 0;
                    
					for (PyThread newThread: newThreads){
						if (!((PyThread)newThread).isPydevThread()){
							newnewThreads[i] = newThread;
                            i += 1;
                        }
                    }
                    
					newThreads = newnewThreads;
                    
				}
			}
		}

		// add threads to the thread list, and fire event

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -