Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP: Added support for exception breakpoints. #6366

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions php/php.dbgp/licenseinfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
-->
<licenseinfo>
<fileset>
<file>src/org/netbeans/modules/php/dbgp/resources/class.png</file>
<file>src/org/netbeans/modules/php/dbgp/resources/notice-glyph.gif</file>
<file>src/org/netbeans/modules/php/dbgp/resources/php16Key.png</file>
<file>src/org/netbeans/modules/php/dbgp/resources/undefined.gif</file>
<license ref="Apache-2.0-ASF" />
<comment type="COMMENT_UNSUPPORTED" />
Expand Down
17 changes: 17 additions & 0 deletions php/php.dbgp/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@
<specification-version>1.58</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.editor.completion</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.67</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.editor.document</code-name-base>
<build-prerequisite/>
Expand Down Expand Up @@ -149,6 +158,14 @@
<specification-version>9.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.parsing.indexing</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>9.31</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.php.api.executable</code-name-base>
<build-prerequisite/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
org.netbeans.modules.php.dbgp.breakpoints.DbgpFunctionBreakpointType
org.netbeans.modules.php.dbgp.breakpoints.DbgpExceptionBreakpointType
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class BreakpointModel extends ViewModelSupport implements NodeModel {
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
private static final String METHOD = "TXT_Method"; // NOI18N
private static final String EXCEPTION = "TXT_Exception"; // NOI18N
private static final String PARENS = "()"; // NOI18N
private final Map<DebugSession, AbstractBreakpoint> myCurrentBreakpoints;

Expand All @@ -74,6 +75,12 @@ public String getDisplayName(Object node) throws UnknownTypeException {
builder.append(breakpoint.getFunction());
builder.append(PARENS);
return builder.toString();
} else if (node instanceof ExceptionBreakpoint) {
ExceptionBreakpoint breakpoint = (ExceptionBreakpoint) node;
StringBuilder builder = new StringBuilder(NbBundle.getMessage(BreakpointModel.class, EXCEPTION));
builder.append(" "); // NOI18N
builder.append(breakpoint.getException());
return builder.toString();
}
throw new UnknownTypeException(node);
}
Expand Down Expand Up @@ -119,15 +126,25 @@ public String getShortDescription(Object node) throws UnknownTypeException {

public void setCurrentStack(Stack stack, DebugSession session) {
if (stack == null) {
synchronized (myCurrentBreakpoints) {
AbstractBreakpoint breakpoint = myCurrentBreakpoints.remove(session);
fireChangeEvent(new ModelEvent.NodeChanged(this, breakpoint));
}
removeCurrentBreakpoint(session);
return;
}
String currentCommand = stack.getCurrentCommandName();
if (!foundLineBreakpoint(stack.getFileName().replace("file:///", "file:/"), stack.getLine() - 1, session)) { //NOI18N
foundFunctionBreakpoint(currentCommand, session);
if (!foundFunctionBreakpoint(currentCommand, session)) {
/**
* Clear myCurrentBreakpoints because if the current breakpoints is not found,
* the previous breakpoint will still be shown as current
*/
removeCurrentBreakpoint(session);
}
}
}

private void removeCurrentBreakpoint(DebugSession session) {
synchronized (myCurrentBreakpoints) {
AbstractBreakpoint breakpoint = myCurrentBreakpoints.remove(session);
fireChangeEvent(new ModelEvent.NodeChanged(this, breakpoint));
}
}

Expand Down Expand Up @@ -216,5 +233,4 @@ public boolean accept(Breakpoint breakpoint) {
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ public void propertyChange(PropertyChangeEvent event) {
return;
}
Object source = event.getSource();
performCommand((Breakpoint) source, Lazy.UPDATE_COMMAND);

if (((Breakpoint) source).isEnabled()) {
performCommand((Breakpoint) source, Lazy.SET_COMMAND);
} else {
performCommand((Breakpoint) source, Lazy.REMOVE_COMMAND);
}
}

private void performCommand(Breakpoint breakpoint, Command command) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@
*/
public class BreakpointsReader implements Properties.Reader {

private static final String ENABED = "enabled"; // NOI18N
private static final String ENABLED = "enabled"; // NOI18N
private static final String FUNC_NAME = "functionName"; // NOI18N
private static final String EXCEPTION_NAME = "exceptionName"; // NOI18N
private static final String TYPE = "type"; // NOI18N
private static final String GROUP_NAME = "groupName"; // NOI18N
private static final String[] SUPPORTED_CLASS_NAMES = new String[] {
LineBreakpoint.class.getName(),
FunctionBreakpoint.class.getName(),
ExceptionBreakpoint.class.getName()
};

@Override
public String[] getSupportedClassNames() {
return new String[]{
LineBreakpoint.class.getName(),
FunctionBreakpoint.class.getName()
};
return SUPPORTED_CLASS_NAMES;
}

@Override
Expand All @@ -53,7 +56,7 @@ public Object read(String typeID, Properties properties) {
return null;
}
LineBreakpoint breakpoint = new LineBreakpoint(line);
if (!properties.getBoolean(ENABED, true)) {
if (!properties.getBoolean(ENABLED, true)) {
breakpoint.disable();
}
breakpoint.setGroupName(properties.getString(GROUP_NAME, ""));
Expand All @@ -66,11 +69,19 @@ public Object read(String typeID, Properties properties) {
return null;
}
FunctionBreakpoint breakpoint = new FunctionBreakpoint(type, func);
if (!properties.getBoolean(ENABED, true)) {
if (!properties.getBoolean(ENABLED, true)) {
breakpoint.disable();
}
breakpoint.setGroupName(properties.getString(GROUP_NAME, ""));
return breakpoint;
} else if (typeID.equals(ExceptionBreakpoint.class.getName())) {
String exception = properties.getString(EXCEPTION_NAME, null);
ExceptionBreakpoint breakpoint = new ExceptionBreakpoint(exception);
if (!properties.getBoolean(ENABLED, true)) {
breakpoint.disable();
}
breakpoint.setGroupName(properties.getString(GROUP_NAME, "")); // NOI18N
return breakpoint;
} else {
return null;
}
Expand All @@ -83,15 +94,21 @@ public void write(Object object, Properties properties) {
FileObject fileObject = breakpoint.getLine().getLookup().lookup(FileObject.class);
properties.setString(LineBreakpoint.PROP_URL, fileObject.toURL().toString());
properties.setInt(LineBreakpoint.PROP_LINE_NUMBER, breakpoint.getLine().getLineNumber());
properties.setBoolean(ENABED, breakpoint.isEnabled());
properties.setBoolean(ENABLED, breakpoint.isEnabled());
properties.setString(GROUP_NAME, breakpoint.getGroupName());
properties.setString(LineBreakpoint.PROP_CONDITION, breakpoint.getCondition());
} else if (object instanceof FunctionBreakpoint) {
FunctionBreakpoint breakpoint = (FunctionBreakpoint) object;
String func = breakpoint.getFunction();
properties.setString(FUNC_NAME, func);
properties.setString(TYPE, breakpoint.getType().toString());
properties.setBoolean(ENABED, breakpoint.isEnabled());
properties.setBoolean(ENABLED, breakpoint.isEnabled());
properties.setString(GROUP_NAME, breakpoint.getGroupName());
} else if (object instanceof ExceptionBreakpoint) {
ExceptionBreakpoint breakpoint = (ExceptionBreakpoint) object;
String exception = breakpoint.getException();
properties.setString(EXCEPTION_NAME, exception);
properties.setBoolean(ENABLED, breakpoint.isEnabled());
properties.setString(GROUP_NAME, breakpoint.getGroupName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ LBL_PhpType=PHP
LBL_MethodBreakpointType=Method

TXT_Method=Method
TXT_Exception=Exception
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.php.dbgp.breakpoints;

import javax.swing.JComponent;
import javax.swing.text.JTextComponent;
import org.netbeans.api.editor.EditorRegistry;
import org.netbeans.modules.editor.NbEditorUtilities;
import org.netbeans.modules.php.api.util.FileUtils;

import org.netbeans.modules.php.dbgp.ui.DbgpExceptionBreakpointPanel;
import org.netbeans.spi.debugger.ui.BreakpointType;
import org.openide.filesystems.FileObject;
import org.openide.util.NbBundle;

@NbBundle.Messages({
"DbgpExceptionBreakpointType.CategoryDisplayName=PHP",
"DbgpExceptionBreakpointType.TypeDisplayName=Exception"
})
public class DbgpExceptionBreakpointType extends BreakpointType {

@Override
public String getCategoryDisplayName() {
return Bundle.DbgpExceptionBreakpointType_CategoryDisplayName();
}

@Override
public JComponent getCustomizer() {
return new DbgpExceptionBreakpointPanel();
}

@Override
public String getTypeDisplayName() {
return Bundle.DbgpExceptionBreakpointType_TypeDisplayName();
}

@Override
public boolean isDefault() {
JTextComponent lastFocusedComponent = EditorRegistry.lastFocusedComponent();
if (lastFocusedComponent == null) {
return false;
}
FileObject fileObject = NbEditorUtilities.getFileObject(lastFocusedComponent.getDocument());
if (fileObject == null) {
return false;
}
return FileUtils.isPhpFile(fileObject);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.php.dbgp.breakpoints;

import org.netbeans.modules.php.dbgp.DebugSession;

/**
* Represent breakpoint for exceptions.
*
*
*/
public class ExceptionBreakpoint extends AbstractBreakpoint {
private final String exceptionName;

public ExceptionBreakpoint(String exceptionName) {
this.exceptionName = exceptionName;
}

public String getException() {
return exceptionName;
}

@Override
public boolean isSessionRelated(DebugSession session) {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ public static BrkpntSetCommand getCommand(DebugSession session, SessionId id, Ab
} else {
assert false;
}
} else if (breakpoint instanceof ExceptionBreakpoint) {
ExceptionBreakpoint exceptionBreakpoint = (ExceptionBreakpoint) breakpoint;
command = BrkpntCommandBuilder.buildExceptionBreakpoint(session.getTransactionId(), exceptionBreakpoint);
}
if (command == null) {
breakpoint.setInvalid(); // No command, can not be valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.netbeans.modules.php.dbgp.packets;

import org.netbeans.modules.php.dbgp.SessionId;
import org.netbeans.modules.php.dbgp.breakpoints.ExceptionBreakpoint;
import org.netbeans.modules.php.dbgp.breakpoints.FunctionBreakpoint;
import org.netbeans.modules.php.dbgp.breakpoints.LineBreakpoint;
import org.netbeans.modules.php.dbgp.packets.BrkpntSetCommand.Types;
Expand Down Expand Up @@ -100,6 +101,13 @@ public static BrkpntSetCommand buildExceptionBreakpoint(String transactionId, St
return command;
}

public static BrkpntSetCommand buildExceptionBreakpoint(String transactionId, ExceptionBreakpoint exceptionBreakpoint) {
String exceptionName = exceptionBreakpoint.getException();
BrkpntSetCommand command = buildExceptionBreakpoint(transactionId, exceptionName);
command.setBreakpoint(exceptionBreakpoint);
return command;
}

public static BrkpntSetCommand buildConditionalBreakpoint(String transactionId, String expression) {
BrkpntSetCommand command = new BrkpntSetCommand(transactionId);
command.setType(Types.WATCH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class BrkpntSetCommand extends DbgpCommand {
private static final String STATE_ARG = "-s "; // NOI18N
private static final String TEMP_ARG = "-r "; // NOI18N
private static final String FUNC_ARG = "-m "; // NOI18N
private static final String EXCEPTION_ARG = "-x"; // NOI18N
private static final String EXCEPTION_ARG = "-x "; // NOI18N
private String myFunction;
private Types myType;
private String myFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ private void setBreakpoints(DebugSession session) {
SessionId id = session.getSessionId();
Breakpoint[] breakpoints = DebuggerManager.getDebuggerManager().getBreakpoints();
for (Breakpoint breakpoint : breakpoints) {
if (!(breakpoint instanceof AbstractBreakpoint)) {
if (!(breakpoint instanceof AbstractBreakpoint) ) {
continue;
}
//do not set a breakpoint at debug start if it is not enabled
if (!breakpoint.isEnabled()) {
continue;
}
AbstractBreakpoint brkpnt = (AbstractBreakpoint) breakpoint;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
</file>
</folder>
</folder>
<folder name="x-php-nbdebug-class-exception">
<file name="EditorKit.instance">
<attr name="instanceClass"
stringvalue="org.netbeans.modules.php.dbgp.ui.completion.ExceptionClassNbDebugEditorKit"/>
</file>
</folder>
</folder>
<folder name="AnnotationTypes">
<file name="PHPError.xml" url="PHPError.xml"/>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ DbgpLineBreakpointCustomizerPanel.fileTextField.text=
DbgpLineBreakpointCustomizerPanel.lineNumberLabel.text=&Line Number:
DbgpLineBreakpointCustomizerPanel.fileLabel.text=&File:
DbgpLineBreakpointCustomizerPanel.conditionComboBox.toolTipText=Breakpoint is hit when this condition evaluates to true.
LBL_ExceptionName=&Exception Name:
DbgpExceptionBreakpointPanel.exceptionLabel.AccessibleContext.accessibleDescription=Label for exception name
DbgpExceptionBreakpointPanel.exceptionLabel.AccessibleContext.accessibleName=Exception Name
Loading