From 1cda8a74bf464a16f4f3922c446d449eb120b211 Mon Sep 17 00:00:00 2001 From: Alexey Borokhvostov Date: Sat, 23 Dec 2023 17:50:08 +0700 Subject: [PATCH] PHP: mark a breakpoint as broken when an error is received when breakpoint_set is executed to set a breakpoint --- .../php/dbgp/annotations/BrkpntAnnotation.java | 4 ++-- .../php/dbgp/breakpoints/AbstractBreakpoint.java | 4 ++++ .../php/dbgp/breakpoints/BreakpointModel.java | 11 ++++++++--- .../netbeans/modules/php/dbgp/breakpoints/Utils.java | 5 +++++ .../modules/php/dbgp/packets/BrkpntSetResponse.java | 12 ++++++++++++ 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/annotations/BrkpntAnnotation.java b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/annotations/BrkpntAnnotation.java index 4eadb8192af0..6575796dae2c 100644 --- a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/annotations/BrkpntAnnotation.java +++ b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/annotations/BrkpntAnnotation.java @@ -20,6 +20,7 @@ import org.netbeans.api.debugger.Breakpoint; import org.netbeans.modules.php.dbgp.breakpoints.LineBreakpoint; +import org.netbeans.modules.php.dbgp.breakpoints.Utils; import org.netbeans.spi.debugger.ui.BreakpointAnnotation; import org.openide.text.Annotatable; import org.openide.util.NbBundle; @@ -41,8 +42,7 @@ public BrkpntAnnotation(Annotatable annotatable, LineBreakpoint breakpoint) { @Override public String getAnnotationType() { - Breakpoint.VALIDITY validity = breakpoint.getValidity(); - return validity == Breakpoint.VALIDITY.VALID || validity == Breakpoint.VALIDITY.UNKNOWN + return Utils.isValid(breakpoint) ? BREAKPOINT_ANNOTATION_TYPE : BREAKPOINT_ANNOTATION_TYPE + "_broken"; //NOI18N } diff --git a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/AbstractBreakpoint.java b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/AbstractBreakpoint.java index ba6076545404..832dd66a4b4a 100644 --- a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/AbstractBreakpoint.java +++ b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/AbstractBreakpoint.java @@ -84,6 +84,10 @@ void setInvalid() { setValidity(VALIDITY.INVALID, null); } + public void setInvalid(String reason) { + setValidity(VALIDITY.INVALID, reason); + } + public void reset() { setValidity(VALIDITY.UNKNOWN, null); myId = null; diff --git a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/BreakpointModel.java b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/BreakpointModel.java index aea90c868465..e147d393f8da 100644 --- a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/BreakpointModel.java +++ b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/BreakpointModel.java @@ -49,6 +49,7 @@ public class BreakpointModel extends ViewModelSupport implements NodeModel { public static final String CURRENT_LINE_CONDITIONAL_BREAKPOINT = "org/netbeans/modules/debugger/resources/breakpointsView/ConditionalBreakpointHit"; // NOI18N public static final String DISABLED_LINE_CONDITIONAL_BREAKPOINT = "org/netbeans/modules/debugger/resources/breakpointsView/DisabledConditionalBreakpoint"; // NOI18N public static final String BROKEN_LINE_BREAKPOINT = "org/netbeans/modules/debugger/resources/breakpointsView/Breakpoint_broken"; // NOI18N + public static final String BROKEN_BREAKPOINT = "org/netbeans/modules/debugger/resources/breakpointsView/NonLineBreakpoint_broken"; // NOI18N private static final String METHOD = "TXT_Method"; // NOI18N private static final String EXCEPTION = "TXT_Exception"; // NOI18N private static final String PARENS = "()"; // NOI18N @@ -99,8 +100,7 @@ public String getIconBase(Object node) throws UnknownTypeException { if (!breakpoint.isEnabled()) { return DISABLED_LINE_BREAKPOINT; } else { - VALIDITY validity = breakpoint.getValidity(); - if (validity.equals(VALIDITY.VALID) || validity.equals(VALIDITY.UNKNOWN)) { + if (Utils.isValid(breakpoint)) { return LINE_BREAKPOINT; } else { return BROKEN_LINE_BREAKPOINT; @@ -110,8 +110,13 @@ public String getIconBase(Object node) throws UnknownTypeException { AbstractBreakpoint breakpoint = (AbstractBreakpoint) node; if (!breakpoint.isEnabled()) { return DISABLED_BREAKPOINT; + } else { + if (Utils.isValid(breakpoint)) { + return BREAKPOINT; + } else { + return BROKEN_BREAKPOINT; + } } - return BREAKPOINT; } throw new UnknownTypeException(node); } diff --git a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/Utils.java b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/Utils.java index a247241a34cc..d7886a17f6e6 100644 --- a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/Utils.java +++ b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/Utils.java @@ -23,6 +23,7 @@ import java.util.logging.Logger; import org.netbeans.api.annotations.common.CheckForNull; import org.netbeans.api.debugger.Breakpoint; +import org.netbeans.api.debugger.Breakpoint.VALIDITY; import org.netbeans.api.debugger.DebuggerManager; import org.netbeans.api.options.OptionsDisplayer; import org.netbeans.modules.php.dbgp.DebugSession; @@ -238,4 +239,8 @@ public static boolean isInPhpScript(Line line) { return mimeTypesOnLine.contains(MIME_TYPE); } + public static boolean isValid(Breakpoint breakpoint) { + VALIDITY validity = breakpoint.getValidity(); + return validity == VALIDITY.VALID || validity == VALIDITY.UNKNOWN; + } } diff --git a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/packets/BrkpntSetResponse.java b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/packets/BrkpntSetResponse.java index bccf2f43a4b5..63b38c7ebe6d 100644 --- a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/packets/BrkpntSetResponse.java +++ b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/packets/BrkpntSetResponse.java @@ -30,6 +30,8 @@ public class BrkpntSetResponse extends DbgpResponse { private static final String STATE = "state"; // NOI18N private static final String ID = "id"; // NOI18N + private static final String ERROR = "error"; // NOI18N + private static final String MESSAGE = "message"; // NOI18N BrkpntSetResponse(Node node) { super(node); @@ -56,6 +58,16 @@ public void process(DebugSession session, DbgpCommand command) { // set f.e. for as temporary ( for run to cursor command ). return; } + + Node error = getChild(getNode(), ERROR); + if (error != null) { + Node message = getChild(error, MESSAGE); + if (message != null) { + breakpoint.setInvalid(message.getTextContent()); + return; + } + } + breakpoint.setBreakpointId(getBreakpointId()); if (getState() == State.DISABLED) { breakpoint.disable();