From 178f0659011ad6ffe334a54d751a53a0950a0495 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Sat, 12 Apr 2008 01:16:56 +0000 Subject: [PATCH] Bug 212916 Support for redirecting the inferior's input/output to a terminal. --- .../launching/FinalLaunchSequence.java | 21 ++++++++++++++ .../launching/ServicesLaunchSequence.java | 4 ++- .../service/command/GDBControl.java | 27 +++++++++++++++--- .../mi/service/command/MIInferiorProcess.java | 2 +- .../command/commands/MIInferiorTTYSet.java | 28 +++++++++++++++++++ 5 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/commands/MIInferiorTTYSet.java 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 6aa82d22e21..1521d46e93c 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 @@ -41,6 +41,7 @@ import org.eclipse.dd.mi.service.command.commands.MIFileExecFile; import org.eclipse.dd.mi.service.command.commands.MIFileSymbolFile; import org.eclipse.dd.mi.service.command.commands.MIGDBSetAutoSolib; import org.eclipse.dd.mi.service.command.commands.MIGDBSetSolibSearchPath; +import org.eclipse.dd.mi.service.command.commands.MIInferiorTTYSet; import org.eclipse.dd.mi.service.command.commands.MITargetSelect; import org.eclipse.dd.mi.service.command.output.MIBreakInsertInfo; import org.eclipse.dd.mi.service.command.output.MIInfo; @@ -60,6 +61,26 @@ public class FinalLaunchSequence extends Sequence { requestMonitor.done(); }}, + /* + * Specify connection of inferior input/output with a terminal. + */ + new Step() { @Override + public void execute(RequestMonitor requestMonitor) { + try { + boolean useTerminal = fLaunch.getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, true); + + if (useTerminal) { + fCommandControl.queueCommand( + new MIInferiorTTYSet(fCommandControl.getControlDMContext(), fCommandControl.getPtyName()), + new DataRequestMonitor(getExecutor(), requestMonitor)); + } else { + requestMonitor.done(); + } + } catch (CoreException e) { + requestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Cannot get terminal option", e)); //$NON-NLS-1$ + requestMonitor.done(); + } + }}, /* * Source the gdbinit file specified in the launch */ diff --git a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/ServicesLaunchSequence.java b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/ServicesLaunchSequence.java index 8dc218b1a26..f267b647282 100644 --- a/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/ServicesLaunchSequence.java +++ b/plugins/org.eclipse.dd.gdb/src/org/eclipse/dd/gdb/internal/provisional/launching/ServicesLaunchSequence.java @@ -43,9 +43,11 @@ public class ServicesLaunchSequence extends Sequence { @Override public void execute(RequestMonitor requestMonitor) { String debugMode = ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN; + boolean useTerminal = true; try { debugMode = fLaunch.getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE, ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN ); + useTerminal = fLaunch.getLaunchConfiguration().getAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, true); } catch (CoreException e) { } @@ -64,7 +66,7 @@ public class ServicesLaunchSequence extends Sequence { // // Create the connection. // - fCommandControl = new GDBControl(fSession, getGDBPath(), fExecPath, fSessionType, 30); + fCommandControl = new GDBControl(fSession, getGDBPath(), fExecPath, fSessionType, useTerminal, 30); fCommandControl.initialize(requestMonitor); } }, 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 9eb3786b1c0..ec3c3432c03 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 @@ -23,6 +23,7 @@ import java.util.List; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import org.eclipse.cdt.utils.pty.PTY; import org.eclipse.cdt.utils.spawner.ProcessFactory; import org.eclipse.cdt.utils.spawner.Spawner; import org.eclipse.core.runtime.IPath; @@ -97,16 +98,19 @@ public class GDBControl extends AbstractMIControl { private MIRunControlEventProcessor fMIEventProcessor; private CLIEventProcessor fCLICommandProcessor; private AbstractCLIProcess fCLIProcess; - private MIInferiorProcess fInferiorProcess; + private MIInferiorProcess fInferiorProcess = null; - public GDBControl(DsfSession session, IPath gdbPath, IPath execPath, SessionType type, int gdbLaunchTimeout) { + boolean fUseTerminal; + private PTY fPty; + + public GDBControl(DsfSession session, IPath gdbPath, IPath execPath, SessionType type, boolean useTerminal, int gdbLaunchTimeout) { super(session); fSessionType = type; fGdbPath = gdbPath; fExecPath = execPath; fGDBLaunchTimeout = gdbLaunchTimeout; fControlDmc = new GDBControlDMContext(session.getId(), getClass().getName() + ":" + ++fgInstanceCounter); //$NON-NLS-1$ - + fUseTerminal = useTerminal; } @Override @@ -257,6 +261,10 @@ public class GDBControl extends AbstractMIControl { public void getInferiorProcessId(DataRequestMonitor rm) { } + + public String getPtyName() { + return fPty.getSlaveName(); + } @DsfServiceEventHandler public void eventDispatched(ExitedEvent e) { @@ -518,8 +526,19 @@ public class GDBControl extends AbstractMIControl { requestMonitor.done(); return; } + + if (fUseTerminal) { + try { + fPty = new PTY(); + fInferiorProcess = new GDBInferiorProcess(GDBControl.this, fPty); + } catch (IOException e) { + } + } - fInferiorProcess = new GDBInferiorProcess(GDBControl.this, fProcess.getOutputStream()); + // If !fUseTerminal or IOException was caught + if (fInferiorProcess == null) + fInferiorProcess = new GDBInferiorProcess(GDBControl.this, fProcess.getOutputStream()); + fCLICommandProcessor = new CLIEventProcessor(GDBControl.this, fControlDmc, fInferiorProcess); fMIEventProcessor = new MIRunControlEventProcessor(GDBControl.this, fControlDmc); diff --git a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/MIInferiorProcess.java b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/MIInferiorProcess.java index 3e0c9e7eb54..a25455ddbc5 100644 --- a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/MIInferiorProcess.java +++ b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/MIInferiorProcess.java @@ -291,7 +291,7 @@ public class MIInferiorProcess extends Process fInputStream.close(); } catch (IOException e) {} try { - fInputStreamPiped.close(); + if (fInputStreamPiped != null) fInputStreamPiped.close(); } catch (IOException e) {} try { fErrorStream.close(); diff --git a/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/commands/MIInferiorTTYSet.java b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/commands/MIInferiorTTYSet.java new file mode 100644 index 00000000000..15c99586cb6 --- /dev/null +++ b/plugins/org.eclipse.dd.mi/src/org/eclipse/dd/mi/service/command/commands/MIInferiorTTYSet.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * 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; + + +/** + * -inferior-tty-set TTY + * + * Set terminal for future runs of the program being debugged. + */ +public class MIInferiorTTYSet extends MICommand +{ + public MIInferiorTTYSet(MIControlDMContext dmc, String tty) { + super(dmc, "-inferior-tty-set", null, new String[] {tty}); //$NON-NLS-1$ + } +} \ No newline at end of file