From b3e38d9e194cfc15e62f7d08da35142e33205e69 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Fri, 27 Apr 2007 11:11:01 +0000 Subject: [PATCH] Bug 135250: Patch to fix function breakpoints. --- .../internal/core/CBreakpointManager.java | 12 +--- .../debug/mi/core/cdi/BreakpointManager.java | 26 ++++++--- .../cdt/debug/mi/core/cdi/EventManager.java | 6 +- .../cdt/debug/mi/core/CLIProcessor.java | 56 +++++++++++++++++-- .../core/event/MIBreakpointChangedEvent.java | 32 ++++++++--- 5 files changed, 97 insertions(+), 35 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CBreakpointManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CBreakpointManager.java index d2424d650ca..e29f6564dc7 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CBreakpointManager.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CBreakpointManager.java @@ -770,7 +770,7 @@ public class CBreakpointManager implements IBreakpointsListener, IBreakpointMana try { ICDILocator location = cdiBreakpoint.getLocator(); String file = location.getFile(); - if ( !isEmpty( file ) ) { + if ( cdiBreakpoint instanceof ICDILineBreakpoint ) { Object sourceElement = getSourceElement( file ); String sourceHandle = file; IResource resource = getProject(); @@ -783,17 +783,11 @@ public class CBreakpointManager implements IBreakpointsListener, IBreakpointMana resource = ResourcesPlugin.getWorkspace().getRoot(); } breakpoint = createLineBreakpoint( sourceHandle, resource, cdiBreakpoint ); -// else if ( !isEmpty( cdiBreakpoint.getLocation().getFunction() ) ) { -// breakpoint = createFunctionBreakpoint( cdiBreakpoint ); -// } -// else if ( ! cdiBreakpoint.getLocation().getAddress().equals( BigInteger.ZERO ) ) { -// breakpoint = createAddressBreakpoint( cdiBreakpoint ); -// } } - else if ( !isEmpty( location.getFunction() ) ) { + else if ( cdiBreakpoint instanceof ICDIFunctionBreakpoint ) { breakpoint = createFunctionBreakpoint( cdiBreakpoint ); } - else if ( !location.getAddress().equals( BigInteger.ZERO ) ) { + else if ( cdiBreakpoint instanceof ICDIAddressBreakpoint ) { breakpoint = createAddressBreakpoint( cdiBreakpoint ); } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java index 66fb5561736..9f26b43d778 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java @@ -373,9 +373,15 @@ public class BreakpointManager extends Manager { } } - /** - */ public void update(Target target) throws CDIException { + update(target, null); + } + + /** + * Pass the event that causes this update + * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=135250 + */ + public void update(Target target, MIEvent event) throws CDIException { MISession miSession = target.getMISession(); MIBreakpoint[] allMIBreakpoints = getAllMIBreakpoints(miSession); List bList = getBreakpointsList(target); @@ -429,29 +435,33 @@ public class BreakpointManager extends Manager { wpoint.setMIBreakpoints(new MIBreakpoint[] {allMIBreakpoints[i]}); bList.add(wpoint); } else { + int hint = MIBreakpointChangedEvent.HINT_NONE; + if (event instanceof MIBreakpointChangedEvent) { + hint = ((MIBreakpointChangedEvent)event).getHint(); + } String function = allMIBreakpoints[i].getFunction(); String file = allMIBreakpoints[i].getFile(); int line = allMIBreakpoints[i].getLine(); String addr = allMIBreakpoints[i].getAddress(); boolean enabled = allMIBreakpoints[i].isEnabled(); - if (file != null && file.length() > 0 && line > 0) { + if (hint == MIBreakpointChangedEvent.HINT_NEW_LINE_BREAKPOINT || + (hint == MIBreakpointChangedEvent.HINT_NONE && file != null && file.length() > 0 && line > 0)) { LineLocation location = createLineLocation (allMIBreakpoints[i].getFile(), allMIBreakpoints[i].getLine()); - // By default new breakpoint are LineBreakpoint Breakpoint newBreakpoint = new LineBreakpoint(target, type, location, condition, enabled); newBreakpoint.setMIBreakpoints(new MIBreakpoint[] {allMIBreakpoints[i]}); bList.add(newBreakpoint); - } else if (function != null && function.length() > 0) { + } else if (hint == MIBreakpointChangedEvent.HINT_NEW_FUNCTION_BREAKPOINT || + (hint == MIBreakpointChangedEvent.HINT_NONE && function != null && function.length() > 0)) { FunctionLocation location = createFunctionLocation(file, function); - // By default new breakpoint are LineBreakpoint Breakpoint newBreakpoint = new FunctionBreakpoint(target, type, location, condition, enabled); newBreakpoint.setMIBreakpoints(new MIBreakpoint[] {allMIBreakpoints[i]}); bList.add(newBreakpoint); - } else if (addr != null && addr.length() > 0) { + } else if (hint == MIBreakpointChangedEvent.HINT_NEW_ADDRESS_BREAKPOINT || + (hint == MIBreakpointChangedEvent.HINT_NONE && addr != null && addr.length() > 0)) { BigInteger big = MIFormat.getBigInteger(addr); AddressLocation location = createAddressLocation (big); - // By default new breakpoint are LineBreakpoint Breakpoint newBreakpoint = new AddressBreakpoint(target, type, location, condition, enabled); newBreakpoint.setMIBreakpoints(new MIBreakpoint[] {allMIBreakpoints[i]}); bList.add(newBreakpoint); diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java index 52d83f7a50e..92d87865002 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/EventManager.java @@ -126,10 +126,10 @@ public class EventManager extends SessionObject implements ICDIEventManager, Obs if (bpoint.getNumber() > 0) { cdiList.add(new ChangedEvent(session, bpoint)); } else { - // Something change we do not know what - // Let the breakpoint manager handle it with an update(). try { - session.getBreakpointManager().update(currentTarget); + // Pass the event to access to the event's hint + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=135250 + session.getBreakpointManager().update(currentTarget, miEvent); } catch (CDIException e) { } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/CLIProcessor.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/CLIProcessor.java index 7fd44d4b150..e28fc375240 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/CLIProcessor.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/CLIProcessor.java @@ -11,6 +11,8 @@ package org.eclipse.cdt.debug.mi.core; +import java.util.StringTokenizer; + import org.eclipse.cdt.debug.mi.core.command.CLICommand; import org.eclipse.cdt.debug.mi.core.command.MIInterpreterExecConsole; import org.eclipse.cdt.debug.mi.core.event.MIBreakpointChangedEvent; @@ -47,7 +49,8 @@ public class CLIProcessor { } } - void processStateChanges(int token, String operation) { + void processStateChanges(int token, String op) { + String operation = op; // Get the command name. int indx = operation.indexOf(' '); if (indx != -1) { @@ -83,8 +86,9 @@ public class CLIProcessor { } } - void processSettingChanges(int token, String operation) { + void processSettingChanges(int token, String command) { // Get the command name. + String operation = command; int indx = operation.indexOf(' '); if (indx != -1) { operation = operation.substring(0, indx).trim(); @@ -99,8 +103,15 @@ public class CLIProcessor { isChangeBreakpoint(operation) || isDeletingBreakpoint(operation)) { // We know something change, we just do not know what. - // So the easiest way is to let the top layer handle it. - session.fireEvent(new MIBreakpointChangedEvent(session, 0)); + // So the easiest way is to let the top layer handle it. + // But we can parse the command line to hint the top layer + // on the breakpoint type. + // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=135250 + int hint = MIBreakpointChangedEvent.HINT_NONE; + if (isSettingBreakpoint(operation)) { + hint = getBreakpointHint(command); + } + session.fireEvent(new MIBreakpointChangedEvent(session, 0, hint)); } else if (isSettingSignal(operation)) { // We do no know which signal let the upper layer find it. session.fireEvent(new MISignalChangedEvent(session, "")); //$NON-NLS-1$ @@ -201,6 +212,41 @@ public class CLIProcessor { return isChange; } + int getBreakpointHint(String command) { + StringTokenizer st = new StringTokenizer(command); + // get operation + String op = st.nextToken(); + if (op.startsWith("rb") && "rbreak".indexOf(op) != -1) { //$NON-NLS-1$ //$NON-NLS-2$ + // only function breakpoints can be set using rbreak + return MIBreakpointChangedEvent.HINT_NEW_FUNCTION_BREAKPOINT; + } + if ( !st.hasMoreTokens() ) { + // "break" with no arguments + return MIBreakpointChangedEvent.HINT_NEW_LINE_BREAKPOINT; + } + String token = st.nextToken(); + if ("if".equals(token) || "ignore".equals(token) || token.charAt(0) == '+' || token.charAt(0) == '-') { //$NON-NLS-1$ //$NON-NLS-2$ + // conditional "break" with no location argument + // or "break +/- offset" + return MIBreakpointChangedEvent.HINT_NEW_LINE_BREAKPOINT; + } + if (token.charAt(0) == '*') { + return MIBreakpointChangedEvent.HINT_NEW_ADDRESS_BREAKPOINT; + } + int index = token.lastIndexOf( ':' ); + String lineNumber = token; + if (index != -1 && index+1 < token.length()) { + lineNumber = token.substring(index+1, token.length()); + } + try { + Integer.parseInt( lineNumber ); + } + catch(NumberFormatException e) { + return MIBreakpointChangedEvent.HINT_NEW_FUNCTION_BREAKPOINT; + } + return MIBreakpointChangedEvent.HINT_NEW_LINE_BREAKPOINT; + } + boolean isSettingSignal(String operation) { boolean isChange = false; /* changing signal: handle, signal */ @@ -217,6 +263,4 @@ public class CLIProcessor { boolean isDetach(String operation) { return (operation.startsWith("det") && "detach".indexOf(operation) != -1); //$NON-NLS-1$ //$NON-NLS-2$ } - - } diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/event/MIBreakpointChangedEvent.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/event/MIBreakpointChangedEvent.java index ded3a06ac81..247b4a80aba 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/event/MIBreakpointChangedEvent.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/event/MIBreakpointChangedEvent.java @@ -12,26 +12,40 @@ package org.eclipse.cdt.debug.mi.core.event; import org.eclipse.cdt.debug.mi.core.MISession; - - -/** - * - */ public class MIBreakpointChangedEvent extends MIChangedEvent { - int no; + /** + * We need these flags to notify the upper layer what kind of a breakpoint + * has been set from the console. + * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=135250 + */ + public static final int HINT_NONE = 0; + public static final int HINT_NEW_LINE_BREAKPOINT = 1; + public static final int HINT_NEW_FUNCTION_BREAKPOINT = 2; + public static final int HINT_NEW_ADDRESS_BREAKPOINT = 3; + + int no = 0; + int hint = HINT_NONE; public MIBreakpointChangedEvent(MISession source, int number) { - this(source, 0, number); + this(source, 0, number, 0); } - public MIBreakpointChangedEvent(MISession source, int id, int number) { + public MIBreakpointChangedEvent(MISession source, int number, int hint) { + this(source, 0, number, hint); + } + + public MIBreakpointChangedEvent(MISession source, int id, int number, int hint) { super(source, id); - no = number; + this.no = number; + this.hint = hint; } public int getNumber() { return no; } + public int getHint() { + return hint; + } }