From 1018fe85a99c3e8f132b5ad6d41b38d6255d9aa5 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Mon, 27 Mar 2006 20:34:02 +0000 Subject: [PATCH] Moved the extraction of the stop symbol to the launch. --- debug/org.eclipse.cdt.debug.core/ChangeLog | 5 ++ .../eclipse/cdt/debug/core/CDIDebugModel.java | 50 +++++++++++++++++-- .../internal/core/model/CDebugTarget.java | 40 ++++++++++++++- launch/org.eclipse.cdt.launch/ChangeLog | 5 ++ .../internal/LocalCDILaunchDelegate.java | 5 +- .../internal/LocalRunLaunchDelegate.java | 5 +- 6 files changed, 103 insertions(+), 7 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index 04ca88b2a9b..aa16e0e2835 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,8 @@ +2006-03-27 Mikhail Khodjaiants + Moved the extraction of the stop symbol to the launch. + * CDIDebugModel.java + * CDebugTarget.java + 2006-03-06 Mikhail Khodjaiants Fix for Bug 93777: Postmortem and Local launch need a default preference for selected debugger. * CDebugCorePlugin.java diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java index 6dad099da7f..2517313fb2f 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java @@ -65,6 +65,43 @@ public class CDIDebugModel { return CDebugCorePlugin.getUniqueIdentifier(); } + /** + * Creates and returns a debug target for the given CDI target, with the specified name, and associates it with the given process for console I/O. The debug + * target is added to the given launch. + * + * @param launch the launch the new debug target will be contained in + * @param project the project to use to persist breakpoints. + * @param cdiTarget the CDI target to create a debug target for + * @param name the name to associate with this target, which will be returned from IDebugTarget.getName. + * @param debuggeeProcess the process to associate with the debug target, which will be returned from IDebugTarget.getProcess + * @param file the executable to debug. + * @param allowTerminate allow terminate(). + * @param allowDisconnect allow disconnect(). + * @param stopSymbol place temporary breakpoint at stopSymbol, ignore if null or empty. + * @param resumeTarget resume target. + * @return a debug target + * @throws DebugException + * @since 3.1 + */ + public static IDebugTarget newDebugTarget( final ILaunch launch, final IProject project, final ICDITarget cdiTarget, final String name, final IProcess debuggeeProcess, final IBinaryObject file, final boolean allowTerminate, final boolean allowDisconnect, final String stopSymbol, final boolean resumeTarget ) throws DebugException { + final IDebugTarget[] target = new IDebugTarget[1]; + IWorkspaceRunnable r = new IWorkspaceRunnable() { + + public void run( IProgressMonitor m ) throws CoreException { + target[0] = new CDebugTarget( launch, project, cdiTarget, name, debuggeeProcess, file, allowTerminate, allowDisconnect ); + ((CDebugTarget)target[0]).start( stopSymbol, resumeTarget ); + } + }; + try { + ResourcesPlugin.getWorkspace().run( r, null ); + } + catch( CoreException e ) { + CDebugCorePlugin.log( e ); + throw new DebugException( e.getStatus() ); + } + return target[0]; + } + /** * Creates and returns a debug target for the given CDI target, with the specified name, and associates it with the given process for console I/O. The debug * target is added to the given launch. @@ -81,14 +118,18 @@ public class CDIDebugModel { * @param resumeTarget resume target. * @return a debug target * @throws DebugException + * @deprecated */ public static IDebugTarget newDebugTarget( final ILaunch launch, final IProject project, final ICDITarget cdiTarget, final String name, final IProcess debuggeeProcess, final IBinaryObject file, final boolean allowTerminate, final boolean allowDisconnect, final boolean stopInMain, final boolean resumeTarget ) throws DebugException { final IDebugTarget[] target = new IDebugTarget[1]; IWorkspaceRunnable r = new IWorkspaceRunnable() { public void run( IProgressMonitor m ) throws CoreException { + String stopSymbol = null; + if ( stopInMain ) + stopSymbol = launch.getLaunchConfiguration().getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT ); target[0] = new CDebugTarget( launch, project, cdiTarget, name, debuggeeProcess, file, allowTerminate, allowDisconnect ); - ((CDebugTarget)target[0]).start( stopInMain, resumeTarget ); + ((CDebugTarget)target[0]).start( stopSymbol, resumeTarget ); } }; try { @@ -118,7 +159,7 @@ public class CDIDebugModel { * @throws DebugException */ public static IDebugTarget newDebugTarget( ILaunch launch, IProject project, ICDITarget cdiTarget, final String name, IProcess debuggeeProcess, IBinaryObject file, boolean allowTerminate, boolean allowDisconnect, boolean resumeTarget ) throws DebugException { - return newDebugTarget( launch, project, cdiTarget, name, debuggeeProcess, file, allowTerminate, allowDisconnect, false, resumeTarget ); + return newDebugTarget( launch, project, cdiTarget, name, debuggeeProcess, file, allowTerminate, allowDisconnect, null, resumeTarget ); } /** @@ -454,7 +495,10 @@ public class CDIDebugModel { */ public static IDebugTarget newDebugTarget( ILaunch launch, ICDITarget target, String name, IProcess iprocess, IProcess debuggerProcess, IFile file, boolean allowTerminate, boolean allowDisconnect, boolean stopInMain ) throws CoreException { IBinaryExecutable exeFile = getBinary( file ); - return newDebugTarget( launch, file.getProject(), target, name, iprocess, exeFile, allowTerminate, allowDisconnect, stopInMain, true ); + String stopSymbol = null; + if ( stopInMain ) + stopSymbol = launch.getLaunchConfiguration().getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT ); + return newDebugTarget( launch, file.getProject(), target, name, iprocess, exeFile, allowTerminate, allowDisconnect, stopSymbol, true ); } /** diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java index c5a810d4e1f..7f2f63e0246 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java @@ -270,11 +270,32 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv } public void start( boolean stopInMain, boolean resume ) throws DebugException { + String stopSymbol = null; + try { + if ( stopInMain ) + stopSymbol = getLaunch().getLaunchConfiguration().getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT ); + } + catch( CoreException e ) { + throw new DebugException( e.getStatus() ); + } ICDITargetConfiguration config = getConfiguration(); if ( config.supportsBreakpoints() ) { getBreakpointManager().setInitialBreakpoints(); - if ( stopInMain ) { - stopInMain(); + if ( stopSymbol != null && stopSymbol.length() != 0 ) { + stopAtSymbol( stopSymbol ); + } + } + if ( config.supportsResume() && resume ) { + resume(); + } + } + + public void start( String stopSymbol, boolean resume ) throws DebugException { + ICDITargetConfiguration config = getConfiguration(); + if ( config.supportsBreakpoints() ) { + getBreakpointManager().setInitialBreakpoints(); + if ( stopSymbol != null && stopSymbol.length() != 0 ) { + stopAtSymbol( stopSymbol ); } } if ( config.supportsResume() && resume ) { @@ -1699,6 +1720,21 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv getBreakpointManager().skipBreakpoints( enabled ); } + protected void stopAtSymbol( String stopSymbol ) throws DebugException { + try { + ICDILocation location = getCDITarget().createFunctionLocation( "", stopSymbol ); //$NON-NLS-1$ + setInternalTemporaryBreakpoint( location ); + } + catch( CoreException e ) { + String message = MessageFormat.format( DebugCoreMessages.getString( "CDebugModel.0" ), new String[]{ e.getStatus().getMessage() } ); //$NON-NLS-1$ + IStatus newStatus = new Status( IStatus.WARNING, e.getStatus().getPlugin(), ICDebugInternalConstants.STATUS_CODE_QUESTION, message, null ); + if ( !CDebugUtils.question( newStatus, this ) ) { + terminate(); + throw new DebugException( new Status( IStatus.OK, e.getStatus().getPlugin(), e.getStatus().getCode(), e.getStatus().getMessage(), null ) ); + } + } + } + protected void stopInMain() throws DebugException { String mainSymbol = new String( ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT ); try { diff --git a/launch/org.eclipse.cdt.launch/ChangeLog b/launch/org.eclipse.cdt.launch/ChangeLog index 59d39fd9524..58ced545125 100644 --- a/launch/org.eclipse.cdt.launch/ChangeLog +++ b/launch/org.eclipse.cdt.launch/ChangeLog @@ -1,3 +1,8 @@ +2006-03-27 Mikhail Khodjaiants + Moved the extraction of the stop symbol to the launch. + * LocalCDILaunchDelegate.java + * LocalRunLaunchDelegate.java + 2006-03-15 Mikhail Khodjaiants Reversing previous changes. The existing "verifyProgramPath" method can be used. * AbstractCLaunchDelegate.java diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalCDILaunchDelegate.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalCDILaunchDelegate.java index a48069a9311..5f554c99862 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalCDILaunchDelegate.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalCDILaunchDelegate.java @@ -142,6 +142,9 @@ public class LocalCDILaunchDelegate extends AbstractCLaunchDelegate { monitor.worked( 1 ); boolean stopInMain = config.getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false ); + String stopSymbol = null; + if ( stopInMain ) + stopSymbol = launch.getLaunchConfiguration().getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT ); ICDITarget[] targets = dsession.getTargets(); for( int i = 0; i < targets.length; i++ ) { Process process = targets[i].getProcess(); @@ -149,7 +152,7 @@ public class LocalCDILaunchDelegate extends AbstractCLaunchDelegate { if ( process != null ) { iprocess = DebugPlugin.newProcess( launch, process, renderProcessLabel( exePath.toOSString() ), getDefaultProcessMap() ); } - CDIDebugModel.newDebugTarget( launch, project.getProject(), targets[i], renderTargetLabel( debugConfig ), iprocess, exeFile, true, false, stopInMain, true ); + CDIDebugModel.newDebugTarget( launch, project.getProject(), targets[i], renderTargetLabel( debugConfig ), iprocess, exeFile, true, false, stopSymbol, true ); } } catch( CoreException e ) { diff --git a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalRunLaunchDelegate.java b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalRunLaunchDelegate.java index 0555d2db4d6..286b453af18 100644 --- a/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalRunLaunchDelegate.java +++ b/launch/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/LocalRunLaunchDelegate.java @@ -96,6 +96,9 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate { monitor.worked(1); boolean stopInMain = config .getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, false); + String stopSymbol = null; + if ( stopInMain ) + stopSymbol = launch.getLaunchConfiguration().getAttribute( ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT ); ICDITarget[] targets = dsession.getTargets(); for (int i = 0; i < targets.length; i++) { @@ -105,7 +108,7 @@ public class LocalRunLaunchDelegate extends AbstractCLaunchDelegate { iprocess = DebugPlugin.newProcess(launch, process, renderProcessLabel(exePath.toOSString()), getDefaultProcessMap()); } CDIDebugModel.newDebugTarget(launch, project.getProject(), targets[i], renderTargetLabel(debugConfig), - iprocess, exeFile, true, false, stopInMain, true); + iprocess, exeFile, true, false, stopSymbol, true); } } catch (CoreException e) { try {