diff --git a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/FinalLaunchSequence.java b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/FinalLaunchSequence.java index cd770d3c529..6aa82d22e21 100644 --- a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/FinalLaunchSequence.java +++ b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/FinalLaunchSequence.java @@ -32,6 +32,7 @@ import org.eclipse.dd.gdb.internal.provisional.service.command.GDBControl; import org.eclipse.dd.gdb.internal.provisional.service.command.GDBControl.SessionType; import org.eclipse.dd.mi.service.CSourceLookup; import org.eclipse.dd.mi.service.MIBreakpointsManager; +import org.eclipse.dd.mi.service.command.commands.CLISource; import org.eclipse.dd.mi.service.command.commands.MIBreakInsert; import org.eclipse.dd.mi.service.command.commands.MICommand; import org.eclipse.dd.mi.service.command.commands.MIExecContinue; @@ -59,6 +60,38 @@ public class FinalLaunchSequence extends Sequence { requestMonitor.done(); }}, + /* + * Source the gdbinit file specified in the launch + */ + new Step() { @Override + public void execute(final RequestMonitor requestMonitor) { + try { + final String gdbinitFile = fLaunch.getLaunchConfiguration().getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, + IMILaunchConfigurationConstants.DEBUGGER_GDB_INIT_DEFAULT ); + if (gdbinitFile != null && gdbinitFile.length() > 0) { + fCommandControl.queueCommand( + new CLISource(fCommandControl.getControlDMContext(), gdbinitFile), + new DataRequestMonitor(getExecutor(), requestMonitor) { + @Override + protected void handleCompleted() { + // If the gdbinitFile is the default, then it may not exist and we + // should not consider this an error. + // If it is not the default, then the user must have specified it and + // we want to warn the user if we can't find it. + if (!gdbinitFile.equals(IMILaunchConfigurationConstants.DEBUGGER_GDB_INIT_DEFAULT )) { + requestMonitor.setStatus(getStatus()); + } + requestMonitor.done(); + } + }); + } else { + requestMonitor.done(); + } + } catch (CoreException e) { + requestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Cannot get gdbinit option", e)); //$NON-NLS-1$ + requestMonitor.done(); + } + }}, /* * Specify the executable file to be debugged. */ diff --git a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/service/command/GDBControl.java b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/service/command/GDBControl.java index 09eee80da61..5c3f2417712 100644 --- a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/service/command/GDBControl.java +++ b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/service/command/GDBControl.java @@ -374,13 +374,19 @@ public class GDBControl extends AbstractMIControl { protected IStatus run(IProgressMonitor monitor) { List commandList = new ArrayList(); + // The goal here is to keep options to an absolute minimum. + // All configuration should be done in the launch sequence + // to allow for easy overriding. commandList.add(fGdbPath.toOSString()); commandList.add("--interpreter"); //$NON-NLS-1$ commandList.add("mi"); //$NON-NLS-1$ + // Don't read the gdbinit file here. It is read explicitly in + // the LaunchSequence to make it easier to customize. + commandList.add("--nx"); //$NON-NLS-1$ String[] commandLine = commandList.toArray(new String[commandList.size()]); - try { + try { fProcess = ProcessFactory.getFactory().exec(commandLine); } catch(IOException e) { String message = MessageFormat.format("Error while launching command", //$NON-NLS-1$ diff --git a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/commands/CLISource.java b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/commands/CLISource.java new file mode 100644 index 00000000000..503055abaaa --- /dev/null +++ b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/commands/CLISource.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2008 Ericsson 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: + * Ericsson - Initial API and implementation + *******************************************************************************/ +package org.eclipse.dd.mi.service.command.commands; + +import org.eclipse.dd.mi.service.command.MIControlDMContext; +import org.eclipse.dd.mi.service.command.output.MIInfo; + +/** + * + * source FILE + * + * Source a file of commands + * + */ +public class CLISource extends CLICommand { + public CLISource(MIControlDMContext ctx, String file) { + super(ctx, "source " + file); //$NON-NLS-1$ + } +} diff --git a/plugins/org.eclipse.dd.tests.gdb/src/org/eclipse/dd/tests/gdb/framework/BaseTestCase.java b/plugins/org.eclipse.dd.tests.gdb/src/org/eclipse/dd/tests/gdb/framework/BaseTestCase.java index a6202a0fce5..cc3fe0ab2cc 100644 --- a/plugins/org.eclipse.dd.tests.gdb/src/org/eclipse/dd/tests/gdb/framework/BaseTestCase.java +++ b/plugins/org.eclipse.dd.tests.gdb/src/org/eclipse/dd/tests/gdb/framework/BaseTestCase.java @@ -58,6 +58,7 @@ public class BaseTestCase { attrs.put(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN, true); attrs.put(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT); attrs.put(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); + attrs.put(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); } @Before