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

📄 abstractdebugtarget.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		if (threads == null){
			threads = newThreads;
            
        } else {
			PyThread[] combined = new PyThread[threads.length + newThreads.length];
			int i = 0;
			for (i = 0; i < threads.length; i++){
				combined[i] = threads[i];
            }
            
			for (int j = 0; j < newThreads.length; i++, j++){
				combined[i] = newThreads[j];
            }
			threads = combined;
		}
		// Now notify debugger that new threads were added
		for (int i =0; i< newThreads.length; i++){ 
			fireEvent(new DebugEvent(newThreads[i], DebugEvent.CREATE));
        }
	}
	
	// Remote this from our thread list
	private void processThreadKilled(String thread_id) {
		PyThread threadToDelete = findThreadByID(thread_id);
		if (threadToDelete != null) {
			int j = 0;
			PyThread[] newThreads = new PyThread[threads.length - 1];
			for (int i=0; i < threads.length; i++){
				if (threads[i] != threadToDelete){ 
					newThreads[j++] = threads[i];
                }
            }
			threads = newThreads;
			fireEvent(new DebugEvent(threadToDelete, DebugEvent.TERMINATE));
		}
	}

	private void processThreadSuspended(String payload) {
		Object[] threadNstack;
		try {
			threadNstack = XMLUtils.XMLToStack(this, payload);
		} catch (CoreException e) {
			PydevDebugPlugin.errorDialog("Error reading ThreadSuspended", e);
			return;
		}
        
		PyThread t = (PyThread)threadNstack[0];
		int reason = DebugEvent.UNSPECIFIED;
		String stopReason = (String) threadNstack[1];
		
        if (stopReason != null) {
			int stopReason_i = Integer.parseInt(stopReason);
            
			if (stopReason_i == AbstractDebuggerCommand.CMD_STEP_OVER ||
				stopReason_i == AbstractDebuggerCommand.CMD_STEP_INTO ||
				stopReason_i == AbstractDebuggerCommand.CMD_STEP_RETURN){
				reason = DebugEvent.STEP_END;
                
            }else if (stopReason_i == AbstractDebuggerCommand.CMD_THREAD_SUSPEND){
				reason = DebugEvent.CLIENT_REQUEST;
                
            }else if (stopReason_i == AbstractDebuggerCommand.CMD_SET_BREAK){
				reason = DebugEvent.BREAKPOINT;
                
            }else {
				PydevDebugPlugin.log(IStatus.ERROR, "Unexpected reason for suspension", null);
				reason = DebugEvent.UNSPECIFIED;
			}
		}
		if (t != null) {
            modificationChecker.onlyLeaveThreads((PyThread[]) this.threads);
            
			IStackFrame stackFrame[] = (IStackFrame[])threadNstack[2]; 
			modificationChecker.onlyLeaveStack(t, stackFrame);
            
			t.setSuspended(true, stackFrame );
			fireEvent(new DebugEvent(t, DebugEvent.SUSPEND, reason));		
		}
	}
	
    

	// thread_id\tresume_reason
	static Pattern threadRunPattern = Pattern.compile("(-?\\d+)\\t(\\w*)");
	/**
	 * ThreadRun event processing
	 */
	private void processThreadRun(String payload) {
		String threadID = "";
		int resumeReason = DebugEvent.UNSPECIFIED;
		Matcher m = threadRunPattern.matcher(payload);
		if (m.matches()) {
			threadID = m.group(1);
			try {
				int raw_reason = Integer.parseInt(m.group(2));
				if (raw_reason == AbstractDebuggerCommand.CMD_STEP_OVER)
					resumeReason = DebugEvent.STEP_OVER;
				else if (raw_reason == AbstractDebuggerCommand.CMD_STEP_RETURN)
					resumeReason = DebugEvent.STEP_RETURN;
				else if (raw_reason == AbstractDebuggerCommand.CMD_STEP_INTO)
					resumeReason = DebugEvent.STEP_INTO;
				else if (raw_reason == AbstractDebuggerCommand.CMD_THREAD_RUN)
					resumeReason = DebugEvent.CLIENT_REQUEST;
				else {
					PydevDebugPlugin.log(IStatus.ERROR, "Unexpected resume reason code", null);
					resumeReason = DebugEvent.UNSPECIFIED;
				}				
			}
			catch (NumberFormatException e) {
				// expected, when pydevd reports "None"
				resumeReason = DebugEvent.UNSPECIFIED;
			}
		}
		else{
			PydevDebugPlugin.log(IStatus.ERROR, "Unexpected treadRun payload " + payload, null);
        }
		
		PyThread t = (PyThread)findThreadByID(threadID);
		if (t != null) {
			t.setSuspended(false, null);
			fireEvent(new DebugEvent(t, DebugEvent.RESUME, resumeReason));
		}
	}
	
    /**
     * 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 all projects
        addBreakpointsFor(ResourcesPlugin.getWorkspace().getRoot());

        // Send the run command, and we are off
        RunCommand run = new RunCommand(debugger);
        debugger.postCommand(run);
    }

    /**
     * Adds the breakpoints associated with a container.
     * @param container the container we're interested in (usually workspace root)
     */
    private void addBreakpointsFor(IContainer container) {
        try {
            IMarker[] markers = container.findMarkers(PyBreakpoint.PY_BREAK_MARKER, true, IResource.DEPTH_INFINITE);
            IMarker[] condMarkers = container.findMarkers(PyBreakpoint.PY_CONDITIONAL_BREAK_MARKER, true, IResource.DEPTH_INFINITE);
            IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
            
            for (IMarker marker : markers) {
                PyBreakpoint brk = (PyBreakpoint) breakpointManager.getBreakpoint(marker);
                
                if (brk.isEnabled()) {
                    SetBreakpointCommand cmd = new SetBreakpointCommand(debugger, brk.getFile(), brk.getLine(), brk.getCondition(), brk.getFunctionName());
                    debugger.postCommand(cmd);
                }
            }
            
            for (IMarker marker: condMarkers) {
            	PyBreakpoint brk = (PyBreakpoint) breakpointManager.getBreakpoint(marker);
            	if (brk.isEnabled()) {
            		SetBreakpointCommand cmd = new SetBreakpointCommand(debugger, brk.getFile(), brk.getLine(), brk.getCondition(), brk.getFunctionName());
            		debugger.postCommand(cmd);
            	}
            }
        } catch (Throwable t) {
            PydevDebugPlugin.errorDialog("Error setting breakpoints", t);
        }
    }
    
    /**
     * This function adds the input listener extension point, so that plugins that only care about
     * the input in the console can know about it.
     */
    @SuppressWarnings("unchecked")
    public void addConsoleInputListener(){
    	IConsole console = DebugUITools.getConsole(this.getProcess());
	    if (console instanceof ProcessConsole) {
	    	final ProcessConsole c = (ProcessConsole) console;
	    	final List<IConsoleInputListener> participants = ExtensionHelper.getParticipants(ExtensionHelper.PYDEV_DEBUG_CONSOLE_INPUT_LISTENER);
	    	final AbstractDebugTarget target = this;
	    	//let's listen the doc for the changes
	    	c.getDocument().addDocumentListener(new IDocumentListener(){

				public void documentAboutToBeChanged(DocumentEvent event) {
					//only report when we have a new line
					if(event.fText.indexOf('\r') != -1 || event.fText.indexOf('\n') != -1){
						try {
							ITypedRegion partition = event.fDocument.getPartition(event.fOffset);
							if(partition instanceof IOConsolePartition){
								IOConsolePartition p = (IOConsolePartition) partition;
								
								//we only communicate about inputs (because we only care about what the user writes)
								if(p.getType().equals(IOConsolePartition.INPUT_PARTITION_TYPE)){
									if(event.fText.length() <= 2){
										//the user typed something
										final String inputFound = p.getString();
										for (IConsoleInputListener listener : participants) {
											listener.newLineReceived(inputFound, target);
										}
									}
									
								}
							}
						} catch (Exception e) {
							Log.log(e);
						}
					}
					
				}

				public void documentChanged(DocumentEvent event) {
					//only report when we have a new line
					if(event.fText.indexOf('\r') != -1 || event.fText.indexOf('\n') != -1){
						try {
							ITypedRegion partition = event.fDocument.getPartition(event.fOffset);
							if(partition instanceof IOConsolePartition){
								IOConsolePartition p = (IOConsolePartition) partition;
								
								//we only communicate about inputs (because we only care about what the user writes)
								if(p.getType().equals(IOConsolePartition.INPUT_PARTITION_TYPE)){
									if(event.fText.length() > 2){
										//the user pasted something
										for (IConsoleInputListener listener : participants) {
											listener.pasteReceived(event.fText, target);
										}
									}
									
								}
							}
						} catch (Exception e) {
							Log.log(e);
						}
					}
				}
	    		
	    	});
	    }
    }

	
	public boolean canDisconnect() {
		return !disconnected;
	}

	public void disconnect() throws DebugException {
		if (debugger != null) {
			debugger.disconnect();
		}
        modificationChecker = null;
	}

	public boolean isDisconnected() {
		return disconnected;
	}
	
	public Object getAdapter(Class adapter) {		
		// Not really sure what to do here, but I am trying
		if (adapter.equals(ILaunch.class)){
			return launch;
            
        }else if (adapter.equals(IResource.class)) {
			// used by Variable ContextManager, and Project:Properties menu item
			if( file!=null ) {
				IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(file);
                
				if (files != null && files.length > 0){
					return files[0];

                }else{
					return null;
                    
                }
			}
            
		} else if (adapter.equals(IPropertySource.class)){
			return launch.getAdapter(adapter);
            
        } else if (adapter.equals(ITaskListResourceAdapter.class) 
				|| adapter.equals(org.eclipse.debug.ui.actions.IRunToLineTarget.class) 
				|| adapter.equals(org.eclipse.debug.ui.actions.IToggleBreakpointsTarget.class) 
				){
			return  super.getAdapter(adapter);
        }
		// System.err.println("Need adapter " + adapter.toString());
		return super.getAdapter(adapter);
	}

}

⌨️ 快捷键说明

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