From fd0881e3c097de36f708f5b595b7985e5a1b7eee Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Tue, 17 Apr 2007 18:11:11 +0000 Subject: [PATCH] Started implementing the guts of the launcher. --- .../debug/gdbjtag/core/GDBJtagDebugger.java | 57 ++++++++- .../GDBJtagLaunchConfigurationDelegate.java | 108 ++++++++---------- 2 files changed, 98 insertions(+), 67 deletions(-) diff --git a/jtag/org.eclipse.cdt.debug.gdbjtag.core/src/org/eclipse/cdt/debug/gdbjtag/core/GDBJtagDebugger.java b/jtag/org.eclipse.cdt.debug.gdbjtag.core/src/org/eclipse/cdt/debug/gdbjtag/core/GDBJtagDebugger.java index 01d756e49ff..5f2b98a5adf 100644 --- a/jtag/org.eclipse.cdt.debug.gdbjtag.core/src/org/eclipse/cdt/debug/gdbjtag/core/GDBJtagDebugger.java +++ b/jtag/org.eclipse.cdt.debug.gdbjtag.core/src/org/eclipse/cdt/debug/gdbjtag/core/GDBJtagDebugger.java @@ -15,9 +15,16 @@ import java.io.File; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.debug.core.cdi.ICDISession; +import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; import org.eclipse.cdt.debug.mi.core.AbstractGDBCDIDebugger; +import org.eclipse.cdt.debug.mi.core.MIException; import org.eclipse.cdt.debug.mi.core.MIPlugin; +import org.eclipse.cdt.debug.mi.core.MISession; +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; +import org.eclipse.cdt.debug.mi.core.command.MIGDBSetNewConsole; +import org.eclipse.cdt.debug.mi.core.output.MIInfo; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.debug.core.ILaunch; @@ -31,14 +38,12 @@ public class GDBJtagDebugger extends AbstractGDBCDIDebugger { public ICDISession createSession(ILaunch launch, File executable, IProgressMonitor monitor) throws CoreException { - // TODO Auto-generated method stub - return null; + return super.createSession(launch, executable, monitor); } public ICDISession createDebuggerSession(ILaunch launch, IBinaryObject exe, IProgressMonitor monitor) throws CoreException { - // TODO Auto-generated method stub - return null; + return super.createDebuggerSession(launch, exe, monitor); } protected CommandFactory getCommandFactory(ILaunchConfiguration config) @@ -47,4 +52,48 @@ public class GDBJtagDebugger extends AbstractGDBCDIDebugger { return new GDBJtagCommandFactory(miVersion); } + protected void doStartSession(ILaunch launch, Session session, IProgressMonitor monitor) throws CoreException { + ILaunchConfiguration config = launch.getLaunchConfiguration(); + ICDITarget[] targets = session.getTargets(); + if (targets.length == 0 || !(targets[0] instanceof Target)) + return ; // TODO should raise an exception + MISession miSession = ((Target)targets[0]).getMISession(); + getMISession( session ); + CommandFactory factory = miSession.getCommandFactory(); + try { + MIGDBSetNewConsole newConsole = factory.createMIGDBSetNewConsole(); + miSession.postCommand( newConsole ); + MIInfo info = newConsole.getMIInfo(); + if ( info == null ) { + throw new MIException( MIPlugin.getResourceString( "src.common.No_answer" ) ); //$NON-NLS-1$ + } + } + catch( MIException e ) { + // We ignore this exception, for example + // on GNU/Linux the new-console is an error. + } + + // TODO execute init script + + // TODO execute load + } + + protected MISession getMISession(Session session) { + ICDITarget[] targets = session.getTargets(); + if (targets.length == 0 || !(targets[0] instanceof Target)) + return null; + return ((Target)targets[0]).getMISession(); + } + + public void doRunSession(ILaunch launch, ICDISession session, IProgressMonitor monitor) { + ILaunchConfiguration config = launch.getLaunchConfiguration(); + ICDITarget[] targets = session.getTargets(); + if ( targets.length == 0 || !(targets[0] instanceof Target) ) + return; + MISession miSession = ((Target)targets[0]).getMISession(); + CommandFactory factory = miSession.getCommandFactory(); + + // TODO execute run script + } + } diff --git a/jtag/org.eclipse.cdt.debug.gdbjtag.core/src/org/eclipse/cdt/debug/gdbjtag/core/GDBJtagLaunchConfigurationDelegate.java b/jtag/org.eclipse.cdt.debug.gdbjtag.core/src/org/eclipse/cdt/debug/gdbjtag/core/GDBJtagLaunchConfigurationDelegate.java index ec19f429dd2..95e96095436 100644 --- a/jtag/org.eclipse.cdt.debug.gdbjtag.core/src/org/eclipse/cdt/debug/gdbjtag/core/GDBJtagLaunchConfigurationDelegate.java +++ b/jtag/org.eclipse.cdt.debug.gdbjtag.core/src/org/eclipse/cdt/debug/gdbjtag/core/GDBJtagLaunchConfigurationDelegate.java @@ -10,15 +10,24 @@ **********************************************************************/ package org.eclipse.cdt.debug.gdbjtag.core; +import java.io.File; + +import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.debug.core.CDIDebugModel; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; -import org.eclipse.cdt.debug.core.ICDebugConfiguration; +import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.ICDISession; +import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; import org.eclipse.cdt.launch.AbstractCLaunchDelegate; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.model.IProcess; /** * @author Doug Schaefer @@ -37,69 +46,42 @@ public class GDBJtagLaunchConfigurationDelegate extends AbstractCLaunchDelegate setDefaultSourceLocator(launch, configuration); if (mode.equals(ILaunchManager.DEBUG_MODE)) { - ICDebugConfiguration debugConfig = getDebugConfig(configuration); - ICDISession dsession = null; - String debugMode = configuration - .getAttribute( - ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, - ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN); + GDBJtagDebugger debugger = new GDBJtagDebugger(); + ICProject project = verifyCProject(configuration); + IPath exePath = verifyProgramPath(configuration); + File exeFile = exePath != null ? exePath.toFile() : null; + ICDISession session = debugger.createSession(launch, exeFile, monitor); + IBinaryObject exeBinary = null; + if ( exePath != null ) { + exeBinary = verifyBinary(project, exePath); + } + boolean defaultRun = configuration.getAttribute(GDBJtagConstants.ATTR_USE_DEFAULT_RUN, GDBJtagConstants.DEFAULT_USE_DEFAULT_RUN); + + try { + monitor.worked(1); - if (debugMode - .equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) { -// dsession = ((EmbeddedGDBCDIDebugger) debugConfig -// .createDebugger()).createDebuggerSession(this, -// launch, exeFileInfo, new SubProgressMonitor( -// monitor, 8)); -// -// ICDITarget[] dtargets = dsession.getTargets(); -// // setFactory(dtargets); -// try { -// -// monitor.worked(1); -// -// executeGDBScript( -// configuration, -// LaunchConfigurationConstants.ATTR_DEBUGGER_COMMANDS_INIT, -// dtargets); -// monitor.worked(2); -// -// queryTargetState(dtargets); -// -// // create the Launch targets/processes for eclipse. -// for (int i = 0; i < dtargets.length; i++) { -// Target target = (Target) dtargets[i]; -// target.setConfiguration(new Configuration(target)); -// Process process = target.getProcess(); -// IProcess iprocess = null; -// if (process != null) { -// iprocess = DebugPlugin.newProcess(launch, -// process, renderProcessLabel(exePath -// .toOSString())); -// } -// CDIDebugModel.newDebugTarget(launch, projectInfo, -// dtargets[i], -// renderTargetLabel(debugConfig), iprocess, -// exeFileInfo, true, true, false); -// /* FIX!!!! put up a console view for */ -// // if (process != null) { -// // iprocess = DebugPlugin.newProcess(launch, -// // process, -// // renderProcessLabel(exePath.toOSString())); -// // } -// } -// executeGDBScript( -// configuration, -// LaunchConfigurationConstants.ATTR_DEBUGGER_COMMANDS_RUN, -// dtargets); -// -// } catch (CoreException e) { -// try { -// dsession.terminate(); -// } catch (CDIException e1) { -// // ignore -// } -// throw e; -// } + // create the Launch targets/processes for eclipse. + ICDITarget[] targets = session.getTargets(); + for( int i = 0; i < targets.length; i++ ) { + Process process = targets[i].getProcess(); + IProcess iprocess = null; + if ( process != null ) { + iprocess = DebugPlugin.newProcess(launch, process, renderProcessLabel(exePath.toOSString()), + getDefaultProcessMap() ); + } + CDIDebugModel.newDebugTarget(launch, project.getProject(), targets[i], + renderProcessLabel("GDB Hardware Debugger"), iprocess, exeBinary, true, false, defaultRun); + } + + if (!defaultRun) + debugger.doRunSession(launch, session, monitor); + } catch (CoreException e) { + try { + session.terminate(); + } catch (CDIException e1) { + // ignore + } + throw e; } } else { cancel("TargetConfiguration not supported",