diff --git a/python/pydevSrc/com/jetbrains/python/debugger/PyStackFrameInfo.java b/python/pydevSrc/com/jetbrains/python/debugger/PyStackFrameInfo.java index b3163d5a937d..8a635b3fc19c 100644 --- a/python/pydevSrc/com/jetbrains/python/debugger/PyStackFrameInfo.java +++ b/python/pydevSrc/com/jetbrains/python/debugger/PyStackFrameInfo.java @@ -1,6 +1,8 @@ package com.jetbrains.python.debugger; +import org.jetbrains.annotations.NotNull; + public class PyStackFrameInfo { private final String myThreadId; @@ -15,6 +17,7 @@ public class PyStackFrameInfo { myPosition = position; } + @NotNull public String getThreadId() { return myThreadId; } diff --git a/python/pydevSrc/com/jetbrains/python/debugger/pydev/LineBreakpointCommand.java b/python/pydevSrc/com/jetbrains/python/debugger/pydev/LineBreakpointCommand.java index 7e31323cf873..63371db3cf9f 100644 --- a/python/pydevSrc/com/jetbrains/python/debugger/pydev/LineBreakpointCommand.java +++ b/python/pydevSrc/com/jetbrains/python/debugger/pydev/LineBreakpointCommand.java @@ -11,7 +11,7 @@ public abstract class LineBreakpointCommand extends AbstractCommand { protected final int myLine; - public LineBreakpointCommand(RemoteDebugger debugger, + public LineBreakpointCommand(@NotNull RemoteDebugger debugger, String type, int commandCode, @NotNull final String file, final int line) { diff --git a/python/pydevSrc/com/jetbrains/python/debugger/pydev/MultiProcessDebugger.java b/python/pydevSrc/com/jetbrains/python/debugger/pydev/MultiProcessDebugger.java index a84335879fd3..011a68f58f26 100644 --- a/python/pydevSrc/com/jetbrains/python/debugger/pydev/MultiProcessDebugger.java +++ b/python/pydevSrc/com/jetbrains/python/debugger/pydev/MultiProcessDebugger.java @@ -12,6 +12,7 @@ import com.intellij.xdebugger.frame.XValueChildrenList; import com.jetbrains.python.console.pydev.PydevCompletionVariant; import com.jetbrains.python.debugger.*; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.PrintWriter; @@ -365,35 +366,37 @@ public class MultiProcessDebugger implements ProcessDebugger { } @Override - public void setTempBreakpoint(String type, String file, int line) { + public void setTempBreakpoint(@NotNull String type, @NotNull String file, int line) { for (ProcessDebugger d : allDebuggers()) { d.setTempBreakpoint(type, file, line); } } @Override - public void removeTempBreakpoint(String file, int line) { + public void removeTempBreakpoint(@NotNull String file, int line) { for (ProcessDebugger d : allDebuggers()) { d.removeTempBreakpoint(file, line); } } @Override - public void setBreakpoint(String typeId, String file, int line, String condition, String logExpression) { + public void setBreakpoint(@NotNull String typeId, @NotNull String file, int line, @Nullable String condition, + @Nullable String logExpression) { for (ProcessDebugger d : allDebuggers()) { d.setBreakpoint(typeId, file, line, condition, logExpression); } } @Override - public void setBreakpointWithFuncName(String typeId, String file, int line, String condition, String logExpression, String funcName) { + public void setBreakpointWithFuncName(@NotNull String typeId, @NotNull String file, int line, @Nullable String condition, + @Nullable String logExpression, @Nullable String funcName) { for (ProcessDebugger d : allDebuggers()) { d.setBreakpointWithFuncName(typeId, file, line, condition, logExpression, funcName); } } @Override - public void removeBreakpoint(String typeId, String file, int line) { + public void removeBreakpoint(@NotNull String typeId, @NotNull String file, int line) { for (ProcessDebugger d : allDebuggers()) { d.removeBreakpoint(typeId, file, line); } diff --git a/python/pydevSrc/com/jetbrains/python/debugger/pydev/ProcessDebugger.java b/python/pydevSrc/com/jetbrains/python/debugger/pydev/ProcessDebugger.java index 5c9deabfcc5f..e80cb223b8c0 100644 --- a/python/pydevSrc/com/jetbrains/python/debugger/pydev/ProcessDebugger.java +++ b/python/pydevSrc/com/jetbrains/python/debugger/pydev/ProcessDebugger.java @@ -71,15 +71,16 @@ public interface ProcessDebugger { void resumeOrStep(String threadId, ResumeOrStepCommand.Mode mode); - void setTempBreakpoint(String type, String file, int line); + void setTempBreakpoint(@NotNull String type, @NotNull String file, int line); - void removeTempBreakpoint(String file, int line); + void removeTempBreakpoint(@NotNull String file, int line); - void setBreakpoint(String typeId, String file, int line, String condition, String logExpression); + void setBreakpoint(@NotNull String typeId, @NotNull String file, int line, @Nullable String condition, @Nullable String logExpression); - void setBreakpointWithFuncName(String typeId, String file, int line, String condition, String logExpression, String funcName); + void setBreakpointWithFuncName(@NotNull String typeId, @NotNull String file, int line, @Nullable String condition, + @Nullable String logExpression, @Nullable String funcName); - void removeBreakpoint(String typeId, String file, int line); + void removeBreakpoint(@NotNull String typeId, @NotNull String file, int line); void addCloseListener(RemoteDebuggerCloseListener remoteDebuggerCloseListener); diff --git a/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoteDebugger.java b/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoteDebugger.java index 7778a06a4730..ff0a5175efe4 100644 --- a/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoteDebugger.java +++ b/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoteDebugger.java @@ -433,7 +433,7 @@ public class RemoteDebugger implements ProcessDebugger { } @Override - public void setTempBreakpoint(String type, String file, int line) { + public void setTempBreakpoint(@NotNull String type, @NotNull String file, int line) { final SetBreakpointCommand command = new SetBreakpointCommand(this, type, file, line); execute(command); // set temp. breakpoint @@ -441,7 +441,7 @@ public class RemoteDebugger implements ProcessDebugger { } @Override - public void removeTempBreakpoint(String file, int line) { + public void removeTempBreakpoint(@NotNull String file, int line) { String type = myTempBreakpoints.get(Pair.create(file, line)); if (type != null) { final RemoveBreakpointCommand command = new RemoveBreakpointCommand(this, type, file, line); @@ -453,7 +453,8 @@ public class RemoteDebugger implements ProcessDebugger { } @Override - public void setBreakpoint(String typeId, String file, int line, String condition, String logExpression) { + public void setBreakpoint(@NotNull String typeId, @NotNull String file, int line, @Nullable String condition, + @Nullable String logExpression) { final SetBreakpointCommand command = new SetBreakpointCommand(this, typeId, file, line, condition, @@ -462,7 +463,8 @@ public class RemoteDebugger implements ProcessDebugger { } @Override - public void setBreakpointWithFuncName(String typeId, String file, int line, String condition, String logExpression, String funcName) { + public void setBreakpointWithFuncName(@NotNull String typeId, @NotNull String file, int line, @Nullable String condition, + @Nullable String logExpression, @Nullable String funcName) { final SetBreakpointCommand command = new SetBreakpointCommand(this, typeId, file, line, condition, @@ -472,7 +474,7 @@ public class RemoteDebugger implements ProcessDebugger { } @Override - public void removeBreakpoint(String typeId, String file, int line) { + public void removeBreakpoint(@NotNull String typeId, @NotNull String file, int line) { final RemoveBreakpointCommand command = new RemoveBreakpointCommand(this, typeId, file, line); execute(command); diff --git a/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoveBreakpointCommand.java b/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoveBreakpointCommand.java index 893989de38c3..2d933ad01670 100644 --- a/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoveBreakpointCommand.java +++ b/python/pydevSrc/com/jetbrains/python/debugger/pydev/RemoveBreakpointCommand.java @@ -5,7 +5,7 @@ import org.jetbrains.annotations.NotNull; public class RemoveBreakpointCommand extends LineBreakpointCommand { - public RemoveBreakpointCommand(final RemoteDebugger debugger, @NotNull final String type, final String file, final int line) { + public RemoveBreakpointCommand(final RemoteDebugger debugger, @NotNull final String type, @NotNull final String file, final int line) { super(debugger, type, REMOVE_BREAKPOINT, file, line); } } diff --git a/python/pydevSrc/com/jetbrains/python/debugger/pydev/SetBreakpointCommand.java b/python/pydevSrc/com/jetbrains/python/debugger/pydev/SetBreakpointCommand.java index 90061d17ae19..1180e684c1bc 100644 --- a/python/pydevSrc/com/jetbrains/python/debugger/pydev/SetBreakpointCommand.java +++ b/python/pydevSrc/com/jetbrains/python/debugger/pydev/SetBreakpointCommand.java @@ -12,7 +12,7 @@ public class SetBreakpointCommand extends LineBreakpointCommand { public SetBreakpointCommand(@NotNull final RemoteDebugger debugger, @NotNull final String type, @NotNull final String file, - @NotNull final int line) { + final int line) { this(debugger, type, file, line, null, null, null); } @@ -20,7 +20,7 @@ public class SetBreakpointCommand extends LineBreakpointCommand { public SetBreakpointCommand(@NotNull final RemoteDebugger debugger, @NotNull final String type, @NotNull final String file, - @NotNull final int line, + final int line, @Nullable final String condition, @Nullable final String logExpression) { super(debugger, type, SET_BREAKPOINT, file, line); @@ -32,7 +32,7 @@ public class SetBreakpointCommand extends LineBreakpointCommand { public SetBreakpointCommand(@NotNull final RemoteDebugger debugger, @NotNull final String type, @NotNull final String file, - @NotNull final int line, + final int line, @Nullable final String condition, @Nullable final String logExpression, @Nullable final String funcName) { diff --git a/python/src/com/jetbrains/python/debugger/PyDebugProcess.java b/python/src/com/jetbrains/python/debugger/PyDebugProcess.java index 52c7683f4621..609b310a422e 100644 --- a/python/src/com/jetbrains/python/debugger/PyDebugProcess.java +++ b/python/src/com/jetbrains/python/debugger/PyDebugProcess.java @@ -614,7 +614,7 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr return PyDebugSupportUtils.canSaveToTemp(project, name); } - @Nullable + @NotNull private PyStackFrame currentFrame() throws PyDebuggerException { if (!isConnected()) { throw new PyDebuggerException("Disconnected"); @@ -633,24 +633,27 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr return frame; } + @Nullable private String getFunctionName(final XLineBreakpoint breakpoint) { + if (breakpoint.getSourcePosition() == null) { + return null; + } final VirtualFile file = breakpoint.getSourcePosition().getFile(); AccessToken lock = ApplicationManager.getApplication().acquireReadActionLock(); try { final Document document = FileDocumentManager.getInstance().getDocument(file); final Project project = getSession().getProject(); - final String[] funcName = new String[1]; if (document != null) { if (file.getFileType() == PythonFileType.INSTANCE) { PsiElement psiElement = XDebuggerUtil.getInstance().findContextElement(file, breakpoint.getSourcePosition().getOffset(), project, false); PyFunction function = PsiTreeUtil.getParentOfType(psiElement, PyFunction.class); if (function != null) { - funcName[0] = function.getName(); + return function.getName(); } } } - return funcName[0]; + return null; } finally { lock.finish(); @@ -660,9 +663,15 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr public void addBreakpoint(final PySourcePosition position, final XLineBreakpoint breakpoint) { myRegisteredBreakpoints.put(position, breakpoint); if (isConnected()) { + final String conditionExpression = breakpoint.getConditionExpression() == null + ? null + : breakpoint.getConditionExpression().getExpression(); + final String logExpression = breakpoint.getLogExpressionObject() == null + ? null + : breakpoint.getLogExpressionObject().getExpression(); myDebugger.setBreakpointWithFuncName(breakpoint.getType().getId(), position.getFile(), position.getLine(), - breakpoint.getCondition(), - breakpoint.getLogExpression(), + conditionExpression, + logExpression, getFunctionName(breakpoint)); } } @@ -824,7 +833,7 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr try { PyStackFrame frame = currentFrame(); - return frame != null ? frame.getSourcePosition() : null; + return frame.getSourcePosition(); } catch (PyDebuggerException e) { return null;