From 9fe63ea09d83e740c0f9c96c99043362fe501885 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Wed, 9 May 2012 15:17:19 -0400 Subject: [PATCH] Bug 379043 - Safer to explicitly set 'target-async off' (CDI) --- .../cdt/debug/mi/core/GDBCDIDebugger2.java | 27 ++++++++++++++++++- .../debug/mi/core/GDBServerCDIDebugger2.java | 24 +++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger2.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger2.java index c58b5f482e3..cfad08fbd3b 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger2.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger2.java @@ -11,7 +11,6 @@ package org.eclipse.cdt.debug.mi.core; import java.io.File; -import com.ibm.icu.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -19,11 +18,13 @@ import java.util.List; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; +import org.eclipse.cdt.debug.mi.core.cdi.CdiResources; import org.eclipse.cdt.debug.mi.core.cdi.Session; import org.eclipse.cdt.debug.mi.core.cdi.SharedLibraryManager; import org.eclipse.cdt.debug.mi.core.cdi.model.Target; import org.eclipse.cdt.debug.mi.core.command.CLITargetAttach; import org.eclipse.cdt.debug.mi.core.command.CommandFactory; +import org.eclipse.cdt.debug.mi.core.command.MIGDBSet; import org.eclipse.cdt.debug.mi.core.command.MIGDBSetNewConsole; import org.eclipse.cdt.debug.mi.core.output.MIInfo; import org.eclipse.core.resources.IProject; @@ -36,6 +37,8 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.variables.VariablesPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; + +import com.ibm.icu.text.MessageFormat; /** * Implementing the cdebugger extension point for basic launch configurations. @@ -107,6 +110,7 @@ public class GDBCDIDebugger2 extends AbstractGDBCDIDebugger { @Override protected void doStartSession( ILaunch launch, Session session, IProgressMonitor monitor ) throws CoreException { ILaunchConfiguration config = launch.getLaunchConfiguration(); + setAsyncMode( config, session ); initializeLibraries( config, session ); if ( monitor.isCanceled() ) { throw new OperationCanceledException(); @@ -261,4 +265,25 @@ public class GDBCDIDebugger2 extends AbstractGDBCDIDebugger { String gdbinit = config.getAttribute( IMILaunchConfigurationConstants.ATTR_GDB_INIT, IMILaunchConfigurationConstants.DEBUGGER_GDB_INIT_DEFAULT ); return (gdbinit != null && gdbinit.length() > 0) ? "--command=" + gdbinit : "--nx"; //$NON-NLS-1$ //$NON-NLS-2$ } + + private void setAsyncMode( ILaunchConfiguration config, Session session ) throws CoreException { + ICDITarget[] dtargets = session.getTargets(); + for( int i = 0; i < dtargets.length; ++i ) { + MISession miSession = ((Target)dtargets[i]).getMISession(); + try { + MIGDBSet setAsyncMode = miSession.getCommandFactory().createMIGDBSet( + new String[] { + "target-async", //$NON-NLS-1$ + "0" //$NON-NLS-1$ + } ); + miSession.postCommand( setAsyncMode ); + MIInfo info = setAsyncMode.getMIInfo(); + if (info == null) { + throw newCoreException(new CDIException(CdiResources.getString( "cdi.Common.No_answer"))); //$NON-NLS-1$ + } + } catch (MIException e) { + // Earlier versions of GDB don't support "target-async". + } + } + } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerCDIDebugger2.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerCDIDebugger2.java index e61fd0031f8..37365ef3fed 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerCDIDebugger2.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBServerCDIDebugger2.java @@ -11,7 +11,9 @@ package org.eclipse.cdt.debug.mi.core; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; +import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; +import org.eclipse.cdt.debug.mi.core.cdi.CdiResources; import org.eclipse.cdt.debug.mi.core.cdi.Session; import org.eclipse.cdt.debug.mi.core.cdi.model.Target; import org.eclipse.cdt.debug.mi.core.command.CommandFactory; @@ -35,6 +37,7 @@ public class GDBServerCDIDebugger2 extends GDBCDIDebugger2 { @Override protected void doStartSession( ILaunch launch, Session session, IProgressMonitor monitor ) throws CoreException { ILaunchConfiguration config = launch.getLaunchConfiguration(); + setAsyncMode( config, session ); initializeLibraries( config, session ); if ( monitor.isCanceled() ) { throw new OperationCanceledException(); @@ -134,4 +137,25 @@ public class GDBServerCDIDebugger2 extends GDBCDIDebugger2 { protected boolean usePty( ILaunchConfiguration config ) throws CoreException { return false; } + + private void setAsyncMode( ILaunchConfiguration config, Session session ) throws CoreException { + ICDITarget[] dtargets = session.getTargets(); + for( int i = 0; i < dtargets.length; ++i ) { + MISession miSession = ((Target)dtargets[i]).getMISession(); + try { + MIGDBSet setAsyncMode = miSession.getCommandFactory().createMIGDBSet( + new String[] { + "target-async", //$NON-NLS-1$ + "0" //$NON-NLS-1$ + } ); + miSession.postCommand( setAsyncMode ); + MIInfo info = setAsyncMode.getMIInfo(); + if (info == null) { + throw newCoreException(new CDIException(CdiResources.getString( "cdi.Common.No_answer"))); //$NON-NLS-1$ + } + } catch (MIException e) { + // Earlier versions of GDB don't support "target-async". + } + } + } }