troizet opened a new pull request, #6366:
URL: https://github.com/apache/netbeans/pull/6366

   What has been done in this PR:
   **1) Added support for exception breakpoints.** (Closes #5434)
   
   Debugging examples:
   
    - without using exception breakpoint
    
   
   
https://github.com/apache/netbeans/assets/9607501/8eafe7b9-9a00-4998-a49c-ba447368d396
   
   - breakpoint on warning
   
   
   
https://github.com/apache/netbeans/assets/9607501/fb59ab0e-bf72-4c42-83e8-f9b2ca7740b2
   
   - breakpoint on MyException class
   
   
   
https://github.com/apache/netbeans/assets/9607501/e70a3cb9-b604-432d-bb20-b459a3ccf616
   
   
   
   
   
   
   
   **2) `Breakpoint_set` and `breakpoint_remove` commands are used instead of 
`breakpoint_update` to change breakpoint state during debugging.**
   
   In the current implementation, enabling/disabling a breakpoint during 
debugging is done by setting the `state` attribute with the 
[breakpoint_update](https://xdebug.org/docs/dbgp#id5) command.
   But for exception breakpoint the `state` attribute has no effect. I checked 
on versions of xdebug: v3.1.6, v3.2.0, v3.2.1. 
   I looked at how this functionality is implemented in `PhpStorm` and `VSCode` 
using the xdebug log file.
   There breakpoint enable/disable is implemented via 
`breakpoint_set`/`breakpoint_remove` commands.
   
   ```diff --git 
a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/BreakpointRuntimeSetter.java
 
b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/BreakpointRuntimeSetter.java
   
   --- 
a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/BreakpointRuntimeSetter.java
   +++ 
b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/breakpoints/BreakpointRuntimeSetter.java
   @@ -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);
   +        }
        }
   ```
   
   For the same reason, I removed the `breakpoint_set` command for a disabled 
breakpoint when debugging starts.
   
   ```diff --git 
a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/packets/InitMessage.java 
b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/packets/InitMessage.java
   
   --- a/php/php.dbgp/src/org/netbeans/modules/php/dbgp/packets/InitMessage.java
   +++ b/php/php.dbgp/src/org/netbeans/modules/php/dbgp/packets/InitMessage.java
   @@ -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;
   ```
   
   **3) Fixed a bug where the previous breakpoint was displayed as the current 
breakpoint in the breakpoint list if the current breakpoint was not found.**
   
   ```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
   
   --- 
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
   
   @@ -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));
            }
        }
   
   ```
   
   
   
   
   
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to