1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 367256 - Debugger doesn't handle invalid breakpoints properly

Change-Id: I4a86015c61164edf9a7840acb40b7b74a4cf8e61
This commit is contained in:
Mikhail Khodjaiants 2016-11-28 12:28:37 -05:00 committed by Gerrit Code Review @ Eclipse.org
parent 6ca1d5cc28
commit cf51cb6b13
3 changed files with 146 additions and 4 deletions

View file

@ -67,6 +67,7 @@ import org.eclipse.cdt.dsf.mi.service.command.AbstractMIControl;
import org.eclipse.cdt.dsf.mi.service.command.CLIEventProcessor; import org.eclipse.cdt.dsf.mi.service.command.CLIEventProcessor;
import org.eclipse.cdt.dsf.mi.service.command.CommandFactory; import org.eclipse.cdt.dsf.mi.service.command.CommandFactory;
import org.eclipse.cdt.dsf.mi.service.command.IEventProcessor; import org.eclipse.cdt.dsf.mi.service.command.IEventProcessor;
import org.eclipse.cdt.dsf.mi.service.command.MIAsyncErrorProcessor;
import org.eclipse.cdt.dsf.mi.service.command.MIControlDMContext; import org.eclipse.cdt.dsf.mi.service.command.MIControlDMContext;
import org.eclipse.cdt.dsf.mi.service.command.MIRunControlEventProcessor; import org.eclipse.cdt.dsf.mi.service.command.MIRunControlEventProcessor;
import org.eclipse.cdt.dsf.mi.service.command.output.MIConsoleStreamOutput; import org.eclipse.cdt.dsf.mi.service.command.output.MIConsoleStreamOutput;
@ -193,6 +194,7 @@ public class GDBControl extends AbstractMIControl implements IGDBControl {
private IEventProcessor fMIEventProcessor; private IEventProcessor fMIEventProcessor;
private IEventProcessor fCLICommandProcessor; private IEventProcessor fCLICommandProcessor;
private IEventProcessor fControlEventProcessor; private IEventProcessor fControlEventProcessor;
private IEventProcessor fMIAsyncErrorProcessor;
private Process fBackendProcess; private Process fBackendProcess;
private GdbCommandTimeoutManager fCommandTimeoutManager; private GdbCommandTimeoutManager fCommandTimeoutManager;
@ -571,6 +573,7 @@ public class GDBControl extends AbstractMIControl implements IGDBControl {
fCLICommandProcessor = createCLIEventProcessor(GDBControl.this, getContext()); fCLICommandProcessor = createCLIEventProcessor(GDBControl.this, getContext());
fMIEventProcessor = createMIRunControlEventProcessor(GDBControl.this, getContext()); fMIEventProcessor = createMIRunControlEventProcessor(GDBControl.this, getContext());
fControlEventProcessor = createControlEventProcessor(); fControlEventProcessor = createControlEventProcessor();
fMIAsyncErrorProcessor = createMIAsyncErrorProcessor(GDBControl.this);
requestMonitor.done(); requestMonitor.done();
} }
@ -580,6 +583,7 @@ public class GDBControl extends AbstractMIControl implements IGDBControl {
fControlEventProcessor.dispose(); fControlEventProcessor.dispose();
fCLICommandProcessor.dispose(); fCLICommandProcessor.dispose();
fMIEventProcessor.dispose(); fMIEventProcessor.dispose();
fMIAsyncErrorProcessor.dispose();
if (fBackendProcess instanceof AbstractCLIProcess) { if (fBackendProcess instanceof AbstractCLIProcess) {
((AbstractCLIProcess)fBackendProcess).dispose(); ((AbstractCLIProcess)fBackendProcess).dispose();
} }
@ -730,6 +734,13 @@ public class GDBControl extends AbstractMIControl implements IGDBControl {
return new ControlEventProcessor(); return new ControlEventProcessor();
} }
/**
* @since 5.3
*/
protected IEventProcessor createMIAsyncErrorProcessor(AbstractMIControl connection) {
return new MIAsyncErrorProcessor(connection);
}
/** @since 5.2 */ /** @since 5.2 */
protected Process createBackendProcess() throws IOException { protected Process createBackendProcess() throws IOException {
if (fMIBackend.isFullGdbConsoleSupported()) { if (fMIBackend.isFullGdbConsoleSupported()) {

View file

@ -0,0 +1,124 @@
/*******************************************************************************
* Copyright (c) 2016 Mentor Graphics and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Mentor Graphics - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.cdt.dsf.datamodel.IDMContext;
import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext;
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService;
import org.eclipse.cdt.dsf.debug.service.command.ICommandResult;
import org.eclipse.cdt.dsf.debug.service.command.ICommandToken;
import org.eclipse.cdt.dsf.mi.service.command.commands.MICommand;
import org.eclipse.cdt.dsf.mi.service.command.events.MIErrorEvent;
import org.eclipse.cdt.dsf.mi.service.command.output.MIInfo;
import org.eclipse.cdt.dsf.mi.service.command.output.MIOutput;
import org.eclipse.cdt.dsf.mi.service.command.output.MIResultRecord;
import org.eclipse.cdt.dsf.service.DsfSession;
/**
* In some cases GDB reports 'exec-*' commands failure after the '^running' event is fired.
* For instance, if an invalid breakpoint is set no error is reported but the consequent
* 'exec-continue' command fails.
*
* 36-exec-continue --thread 1
* 36^running
* *running,thread-id="all"
* (gdb)
* &"Warning:\n"
* &"Cannot insert breakpoint 2.\n"
* &"Cannot access memory at address 0x0\n"
* &"\n"
* 36^error,msg="Command aborted."
* (gdb)
*
* This class handles these type of situations by firing MIErrorEvent when such an error appears.
*
* @since 5.3
*/
public class MIAsyncErrorProcessor implements IEventProcessor {
final private ICommandControlService fCommandControl;
private Map<IExecutionDMContext, Integer> fRunCommands = new HashMap<>();
public MIAsyncErrorProcessor(ICommandControlService commandControl) {
super();
fCommandControl = commandControl;
fCommandControl.addCommandListener(this);
fCommandControl.addEventListener(this);
}
@Override
public void eventReceived(Object output) {
MIResultRecord rr = ((MIOutput)output).getMIResultRecord();
// Handling the asynchronous error case, i.e. when the "<token>^running" event
// appears before "<token>^error, msg=<error_message>" for run control commands.
if (rr != null && MIResultRecord.ERROR.equals(rr.getResultClass())) {
handleAsyncError((MIOutput)output);
}
}
@Override
public void commandQueued(ICommandToken token) {
}
@Override
public void commandSent(ICommandToken token) {
}
@Override
public void commandRemoved(ICommandToken token) {
}
@SuppressWarnings("unchecked")
@Override
public void commandDone(ICommandToken token, ICommandResult result) {
if (token.getCommand() instanceof MICommand<?> && result instanceof MIInfo && ((MIInfo)result).isRunning()) {
IDMContext ctx = ((MICommand<MIInfo>)token.getCommand()).getContext();
if (ctx instanceof IExecutionDMContext) {
MIResultRecord rr = ((MIInfo)result).getMIOutput().getMIResultRecord();
if (rr != null) {
fRunCommands.put((IExecutionDMContext)ctx, Integer.valueOf(rr.getToken()));
}
}
}
}
@Override
public void dispose() {
fCommandControl.removeCommandListener(this);
fCommandControl.removeEventListener(this);
fRunCommands.clear();
}
protected ICommandControlService getCommandControl() {
return fCommandControl;
}
protected void handleAsyncError(MIOutput output) {
int token = output.getMIResultRecord().getToken();
for (Entry<IExecutionDMContext, Integer> entry : fRunCommands.entrySet()) {
if (entry.getValue().intValue() == token && DsfSession.isSessionActive(entry.getKey().getSessionId())) {
fireStoppedEvent(output, entry.getKey());
}
}
}
protected void fireStoppedEvent(final MIOutput output, final IExecutionDMContext ctx) {
DsfSession session = DsfSession.getSession(ctx.getSessionId());
int token = output.getMIResultRecord().getToken();
session.dispatchEvent(MIErrorEvent.parse(ctx, token, output.getMIResultRecord().getMIResults(), output.getMIOOBRecords()), null);
}
}

View file

@ -52,9 +52,11 @@ public class MIErrorEvent extends MIStoppedEvent {
return log; return log;
} }
/**
* @since 5.3
*/
public static MIErrorEvent parse( public static MIErrorEvent parse(
IContainerDMContext containerDmc, int token, MIResult[] results, MIOOBRecord[] oobs) IExecutionDMContext execDmc, int token, MIResult[] results, MIOOBRecord[] oobs) {
{
String msg = "", log = ""; //$NON-NLS-1$ //$NON-NLS-2$ String msg = "", log = ""; //$NON-NLS-1$ //$NON-NLS-2$
if (results != null) { if (results != null) {
@ -81,7 +83,12 @@ public class MIErrorEvent extends MIStoppedEvent {
} }
log = sb.toString(); log = sb.toString();
} }
return new MIErrorEvent(containerDmc, token, results, oobs, msg, log); return new MIErrorEvent(execDmc, token, results, oobs, msg, log);
}
public static MIErrorEvent parse(
IContainerDMContext containerDmc, int token, MIResult[] results, MIOOBRecord[] oobs) {
return MIErrorEvent.parse((IExecutionDMContext)containerDmc, token, results, oobs);
} }
@Override @Override