1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

2005-07-18 Alain Magloire

GDB has now four different version of MI, so it has become
	important to give the user the choice of the version.
	* mi/org/eclipse/cdt/debug/mi/core/MISession.java
	* mi/org/eclipse/cdt/debug/mi/core/RxThread.java
	* mi/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java
	* mi/org/eclipse/cdt/debug/mi/core/command/MICommand.java
	+ mi/org/eclipse/cdt/debug/mi/core/command/MIVersion.java
	* src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger.java
	* src/org/eclipse/cdt/debug/mi/core/GDBDebugger.java
	* src/org/eclipse/cdt/debug/mi/core/GDBServerCDIDebugger.java
	* src/org/eclipse/cdt/debug/mi/core/MIPlugin.java
	* src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java
This commit is contained in:
Alain Magloire 2005-07-19 00:30:04 +00:00
parent 053f04b5da
commit 8ca570cd07
12 changed files with 276 additions and 119 deletions

View file

@ -1,3 +1,17 @@
2005-07-18 Alain Magloire
GDB has now four different version of MI, so it has become
important to give the user the choice of the version.
* mi/org/eclipse/cdt/debug/mi/core/MISession.java
* mi/org/eclipse/cdt/debug/mi/core/RxThread.java
* mi/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java
* mi/org/eclipse/cdt/debug/mi/core/command/MICommand.java
+ mi/org/eclipse/cdt/debug/mi/core/command/MIVersion.java
* src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger.java
* src/org/eclipse/cdt/debug/mi/core/GDBDebugger.java
* src/org/eclipse/cdt/debug/mi/core/GDBServerCDIDebugger.java
* src/org/eclipse/cdt/debug/mi/core/MIPlugin.java
* src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java
2005-07-10 Alain Magloire 2005-07-10 Alain Magloire
Fix for PR 100992: Setting breakpoints for methods Fix for PR 100992: Setting breakpoints for methods
* cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java * cdi/org/eclipse/cdt/debug/mi/core/cdi/BreakpointManager.java

View file

@ -27,11 +27,14 @@ import org.eclipse.cdt.debug.mi.core.command.MIGDBSet;
import org.eclipse.cdt.debug.mi.core.command.MIGDBShowExitCode; import org.eclipse.cdt.debug.mi.core.command.MIGDBShowExitCode;
import org.eclipse.cdt.debug.mi.core.command.MIGDBShowPrompt; import org.eclipse.cdt.debug.mi.core.command.MIGDBShowPrompt;
import org.eclipse.cdt.debug.mi.core.command.MIInterpreterExecConsole; import org.eclipse.cdt.debug.mi.core.command.MIInterpreterExecConsole;
import org.eclipse.cdt.debug.mi.core.command.MIVersion;
import org.eclipse.cdt.debug.mi.core.event.MIEvent; import org.eclipse.cdt.debug.mi.core.event.MIEvent;
import org.eclipse.cdt.debug.mi.core.event.MIGDBExitEvent; import org.eclipse.cdt.debug.mi.core.event.MIGDBExitEvent;
import org.eclipse.cdt.debug.mi.core.output.MIGDBShowInfo; import org.eclipse.cdt.debug.mi.core.output.MIGDBShowInfo;
import org.eclipse.cdt.debug.mi.core.output.MIOutput; import org.eclipse.cdt.debug.mi.core.output.MIOutput;
import org.eclipse.cdt.debug.mi.core.output.MIParser; import org.eclipse.cdt.debug.mi.core.output.MIParser;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
/** /**
* Represents a GDB/MI session. * Represents a GDB/MI session.
@ -88,27 +91,56 @@ public class MISession extends Observable {
MIInferior inferior; MIInferior inferior;
/** /**
* Create the gdb session. * @param process
* @param tty
* @param type
* @param commandTimeout
* @param launchTimeout
* @param miVersion
* @param monitor
* @throws MIException
*/
public MISession(MIProcess process, IMITTY tty, int type, int commandTimeout, int launchTimeout, String miVersion, IProgressMonitor monitor) throws MIException {
this(process, tty, type, new CommandFactory(miVersion), commandTimeout, launchTimeout, monitor);
}
/**
* Create the gdb session. Assume MIVersion 1
* *
* @deprecated use the other constructors with the MIVersion
* @param Process gdb Process. * @param Process gdb Process.
* @param pty Terminal to use for the inferior. * @param pty Terminal to use for the inferior.
* @param timeout time in milliseconds to wait for command response. * @param timeout time in milliseconds to wait for command response.
* @param type the type of debugin session. * @param type the type of debugin session.
*/ */
public MISession(MIProcess process, IMITTY tty, int timeout, int type, int launchTimeout) throws MIException { public MISession(MIProcess process, IMITTY tty, int commandTimeout, int type, int launchTimeout) throws MIException {
this(process, tty, type, commandTimeout, launchTimeout, MIVersion.MI1, new NullProgressMonitor());
// Assume mi1 for now if (useExecConsole()) {
String miVersion = "mi1"; //$NON-NLS-1$ // if exec console is present, assume MI2 supported
setCommandFactory(new CommandFactory(MIVersion.MI2));
}
}
/**
* Create the gdb session.
*
* @param type the type of debugging session.
* @param commandFactory the MI command factory
* @param Process gdb Process.
* @param pty Terminal to use for the inferior.
* @param timeout time in milliseconds to wait for command response.
*/
public MISession(MIProcess process, IMITTY tty, int type, CommandFactory commandFactory, int commandTimeout, int launchTimeout, IProgressMonitor monitor) throws MIException {
gdbProcess = process; gdbProcess = process;
inChannel = process.getInputStream(); inChannel = process.getInputStream();
outChannel = process.getOutputStream(); outChannel = process.getOutputStream();
cmdTimeout = timeout; factory = commandFactory;
cmdTimeout = commandTimeout;
sessionType = type; sessionType = type;
parser = new MIParser(); parser = new MIParser();
inferior = new MIInferior(this, tty); inferior = new MIInferior(this, tty);
@ -116,12 +148,21 @@ public class MISession extends Observable {
txQueue = new CommandQueue(); txQueue = new CommandQueue();
rxQueue = new CommandQueue(); rxQueue = new CommandQueue();
eventQueue = new Queue(); eventQueue = new Queue();
txThread = new TxThread(this);
rxThread = new RxThread(this);
eventThread = new EventThread(this);
// initialize/setup
setup(launchTimeout, new NullProgressMonitor());
}
protected void setup(int launchTimeout, IProgressMonitor monitor) throws MIException {
// The Process may have terminated earlier because // The Process may have terminated earlier because
// of bad arguments etc .. check this here and bail out. // of bad arguments etc .. check this here and bail out.
try { try {
process.exitValue(); gdbProcess.exitValue();
InputStream err = process.getErrorStream(); InputStream err = gdbProcess.getErrorStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(err)); BufferedReader reader = new BufferedReader(new InputStreamReader(err));
String line = null; String line = null;
try { try {
@ -137,54 +178,21 @@ public class MISession extends Observable {
} catch (IllegalThreadStateException e) { } catch (IllegalThreadStateException e) {
// Ok, it means the process is alive. // Ok, it means the process is alive.
} }
txThread = new TxThread(this); if (monitor.isCanceled()) {
rxThread = new RxThread(this); throw new MIException(MIPlugin.getResourceString("src.MISession.Process_Terminated")); //$NON-NLS-1$
eventThread = new EventThread(this); }
txThread.start(); txThread.start();
rxThread.start(); rxThread.start();
eventThread.start(); eventThread.start();
// Disable a certain number of irritations from gdb.
// Like confirmation and screen size.
try {
MIGDBSet confirm = new MIGDBSet(miVersion, new String[]{"confirm", "off"}); //$NON-NLS-1$ //$NON-NLS-2$
postCommand(confirm, launchTimeout);
confirm.getMIInfo();
MIGDBSet width = new MIGDBSet(miVersion, new String[]{"width", "0"}); //$NON-NLS-1$ //$NON-NLS-2$
postCommand(width, launchTimeout);
width.getMIInfo();
MIGDBSet height = new MIGDBSet(miVersion, new String[]{"height", "0"}); //$NON-NLS-1$ //$NON-NLS-2$
postCommand(height, launchTimeout);
height.getMIInfo();
// Try to discover is "-interpreter-exec" is supported.
try {
MIInterpreterExecConsole echo = new MIInterpreterExecConsole(miVersion, "echo"); //$NON-NLS-1$
postCommand(echo, launchTimeout);
echo.getMIInfo();
useInterpreterExecConsole = true;
} catch (MIException e) {
//
}
// Get GDB's prompt
MIGDBShowPrompt prompt = new MIGDBShowPrompt(miVersion);
postCommand(prompt);
MIGDBShowInfo infoPrompt = prompt.getMIGDBShowInfo();
String value = infoPrompt.getValue();
if (value != null && value.length() > 0) {
parser.cliPrompt = value.trim();
}
if (useInterpreterExecConsole) {
miVersion = "mi2"; //$NON-NLS-1$
}
factory = new CommandFactory(miVersion); //$NON-NI try {
if (monitor.isCanceled()) {
throw new MIException(MIPlugin.getResourceString("src.MISession.Process_Terminated")); //$NON-NLS-1$
}
initialize(launchTimeout, monitor);
} catch (MIException exc) { } catch (MIException exc) {
// Kill the Transmition thread. // Kill the Transmition thread.
if (txThread.isAlive()) { if (txThread.isAlive()) {
@ -202,6 +210,69 @@ public class MISession extends Observable {
throw exc; throw exc;
} }
} }
protected void initialize(int launchTimeout, IProgressMonitor monitor) throws MIException {
// Disable a certain number of irritations from gdb.
// Like confirmation and screen size.
MIGDBSet confirm = getCommandFactory().createMIGDBSet(new String[]{"confirm", "off"}); //$NON-NLS-1$ //$NON-NLS-2$
postCommand(confirm, launchTimeout);
confirm.getMIInfo();
if (monitor.isCanceled()) {
throw new MIException(MIPlugin.getResourceString("src.MISession.Process_Terminated")); //$NON-NLS-1$
}
MIGDBSet width = getCommandFactory().createMIGDBSet(new String[]{"width", "0"}); //$NON-NLS-1$ //$NON-NLS-2$
postCommand(width, launchTimeout);
width.getMIInfo();
if (monitor.isCanceled()) {
throw new MIException(MIPlugin.getResourceString("src.MISession.Process_Terminated")); //$NON-NLS-1$
}
MIGDBSet height = getCommandFactory().createMIGDBSet(new String[]{"height", "0"}); //$NON-NLS-1$ //$NON-NLS-2$
postCommand(height, launchTimeout);
height.getMIInfo();
if (monitor.isCanceled()) {
throw new MIException(MIPlugin.getResourceString("src.MISession.Process_Terminated")); //$NON-NLS-1$
}
useInterpreterExecConsole = canUseInterpreterExecConsole();
if (monitor.isCanceled()) {
throw new MIException(MIPlugin.getResourceString("src.MISession.Process_Terminated")); //$NON-NLS-1$
}
String prompt = getCLIPrompt();
if (monitor.isCanceled()) {
throw new MIException(MIPlugin.getResourceString("src.MISession.Process_Terminated")); //$NON-NLS-1$
}
if (prompt != null) {
getMIParser().cliPrompt = prompt;
}
}
protected boolean canUseInterpreterExecConsole() {
// Try to discover if "-interpreter-exec" is supported.
try {
MIInterpreterExecConsole echo = getCommandFactory().createMIInterpreterExecConsole("echo"); //$NON-NLS-1$
postCommand(echo);
echo.getMIInfo();
return true;
} catch (MIException e) {
//
}
return false;
}
protected String getCLIPrompt() throws MIException {
// Get GDB's prompt
MIGDBShowPrompt prompt = getCommandFactory().createMIGDBShowPrompt();
postCommand(prompt);
MIGDBShowInfo infoPrompt = prompt.getMIGDBShowInfo();
String value = infoPrompt.getValue();
if (value != null && value.length() > 0) {
return value.trim();
}
return null;
}
/** /**
* get MI Console Stream. * get MI Console Stream.
@ -364,7 +435,7 @@ public class MISession extends Observable {
} }
postCommand0(cmd, timeout); postCommand0(cmd, timeout);
} }
/** /**
* if timeout < 0 the operation will not try to way for * if timeout < 0 the operation will not try to way for
* answer from gdb. * answer from gdb.
@ -375,7 +446,9 @@ public class MISession extends Observable {
*/ */
public synchronized void postCommand0(Command cmd, long timeout) throws MIException { public synchronized void postCommand0(Command cmd, long timeout) throws MIException {
// TRACING: print the command; // TRACING: print the command;
MIPlugin.getDefault().debugLog(cmd.toString()); if (MIPlugin.getDefault().isDebugging()) {
MIPlugin.getDefault().debugLog(cmd.toString());
}
txQueue.addCommand(cmd); txQueue.addCommand(cmd);
@ -457,7 +530,7 @@ public class MISession extends Observable {
// Although we will close the pipe(). It is cleaner // Although we will close the pipe(). It is cleaner
// to give a chance to gdb to cleanup. // to give a chance to gdb to cleanup.
// send the exit(-gdb-exit). But we only wait a maximum of 2 sec. // send the exit(-gdb-exit). But we only wait a maximum of 2 sec.
MIGDBExit exit = factory.createMIGDBExit(); MIGDBExit exit = getCommandFactory().createMIGDBExit();
try { try {
postCommand0(exit, 2000); postCommand0(exit, 2000);
} catch (MIException e) { } catch (MIException e) {
@ -548,12 +621,17 @@ public class MISession extends Observable {
super.notifyObservers(arg); super.notifyObservers(arg);
} }
OutputStream getConsolePipe() { OutputStream getConsolePipe() {
if (miOutConsolePipe == null) {
getMIConsoleStream();
}
return miOutConsolePipe; return miOutConsolePipe;
} }
OutputStream getLogPipe() { OutputStream getLogPipe() {
if (miOutLogPipe == null) {
getMILogStream();
}
return miOutLogPipe; return miOutLogPipe;
} }

View file

@ -86,7 +86,9 @@ public class RxThread extends Thread {
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
// TRACING: print the output. // TRACING: print the output.
MIPlugin.getDefault().debugLog(line); if (MIPlugin.getDefault().isDebugging()) {
MIPlugin.getDefault().debugLog(line);
}
setPrompt(line); setPrompt(line);
processMIOutput(line + "\n"); //$NON-NLS-1$ processMIOutput(line + "\n"); //$NON-NLS-1$
} }

View file

@ -228,6 +228,10 @@ public class CommandFactory {
return new MIGDBShow(getMIVersion(), params); return new MIGDBShow(getMIVersion(), params);
} }
public MIGDBShowPrompt createMIGDBShowPrompt() {
return new MIGDBShowPrompt(getMIVersion());
}
public MIGDBShowExitCode createMIGDBShowExitCode() { public MIGDBShowExitCode createMIGDBShowExitCode() {
return new MIGDBShowExitCode(getMIVersion()); return new MIGDBShowExitCode(getMIVersion());
} }
@ -349,7 +353,7 @@ public class CommandFactory {
} }
public MIVarCreate createMIVarCreate(String name, String frameAddr, String expression) { public MIVarCreate createMIVarCreate(String name, String frameAddr, String expression) {
return new MIVarCreate(name, frameAddr, expression); return new MIVarCreate(getMIVersion(), name, frameAddr, expression);
} }
public MIVarDelete createMIVarDelete(String name) { public MIVarDelete createMIVarDelete(String name) {

View file

@ -58,7 +58,7 @@ public class MICommand extends Command {
* @return * @return
*/ */
public boolean isMI1() { public boolean isMI1() {
return "mi1".equalsIgnoreCase(fMIVersion); //$NON-NLS-1$ return MIVersion.MI1.equalsIgnoreCase(fMIVersion); //$NON-NLS-1$
} }
/** /**
@ -66,7 +66,7 @@ public class MICommand extends Command {
* @return * @return
*/ */
public boolean isMI2() { public boolean isMI2() {
return "mi2".equalsIgnoreCase(fMIVersion); //$NON-NLS-1$ return MIVersion.MI2.equalsIgnoreCase(fMIVersion); //$NON-NLS-1$
} }
/** /**

View file

@ -0,0 +1,20 @@
package org.eclipse.cdt.debug.mi.core.command;
/**
* TODO: Make this an enum type.
* MI Version constants.
*/
public class MIVersion {
public static final String MI1 = "mi1"; //$NON-NLS-1$
public static final String MI2 = "mi2"; //$NON-NLS-1$
public static final String MI3 = "mi3"; //$NON-NLS-1$
public static int compare(String v1, String v2) {
return v1.compareToIgnoreCase(v2);
}
public static boolean equals(String v1, String v2) {
return v1.equalsIgnoreCase(v2);
}
}

View file

@ -94,13 +94,14 @@ public class GDBCDIDebugger implements ICDIDebugger {
boolean failed = false; boolean failed = false;
try { try {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$
boolean usePty = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, true); boolean usePty = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, true);
File cwd = getProjectPath(config).toFile(); File cwd = getProjectPath(config).toFile();
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
if (usePty) { if (usePty) {
session = MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), cwd, gdbinit, monitor); session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getPath().toFile(), cwd, gdbinit, monitor);
} else { } else {
session = MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), cwd, gdbinit, null, monitor); session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getPath().toFile(), cwd, gdbinit, null, monitor);
} }
initializeLibraries(config, session); initializeLibraries(config, session);
return session; return session;
@ -129,11 +130,12 @@ public class GDBCDIDebugger implements ICDIDebugger {
boolean failed = false; boolean failed = false;
try { try {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$
int pid = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_ATTACH_PROCESS_ID, -1); int pid = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_ATTACH_PROCESS_ID, -1);
File cwd = getProjectPath(config).toFile(); File cwd = getProjectPath(config).toFile();
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
File exeFile = exe != null ? exe.getPath().toFile() : null; File exeFile = exe != null ? exe.getPath().toFile() : null;
session = MIPlugin.getDefault().createCSession(gdb, exeFile, pid, null, cwd, gdbinit, monitor); session = MIPlugin.getDefault().createCSession(gdb, miVersion, exeFile, pid, null, cwd, gdbinit, monitor);
initializeLibraries(config, session); initializeLibraries(config, session);
return session; return session;
} catch (Exception e) { } catch (Exception e) {
@ -161,10 +163,11 @@ public class GDBCDIDebugger implements ICDIDebugger {
boolean failed = false; boolean failed = false;
try { try {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$
File cwd = getProjectPath(config).toFile(); File cwd = getProjectPath(config).toFile();
IPath coreFile = new Path(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_COREFILE_PATH, (String)null)); IPath coreFile = new Path(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_COREFILE_PATH, (String)null));
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
session = MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), coreFile.toFile(), cwd, gdbinit, monitor); session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getPath().toFile(), coreFile.toFile(), cwd, gdbinit, monitor);
initializeLibraries(config, session); initializeLibraries(config, session);
return session; return session;
} catch (Exception e) { } catch (Exception e) {

View file

@ -15,6 +15,7 @@ import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.debug.core.ICDebugger; import org.eclipse.cdt.debug.core.ICDebugger;
import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDISession; import org.eclipse.cdt.debug.core.cdi.ICDISession;
@ -73,9 +74,10 @@ public class GDBDebugger implements ICDebugger {
boolean failed = false; boolean failed = false;
try { try {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$
File cwd = exe.getProject().getLocation().toFile(); File cwd = exe.getProject().getLocation().toFile();
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
session = MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), cwd, gdbinit, null); session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getLocation().toFile(), cwd, gdbinit, null);
initializeLibraries(config, session); initializeLibraries(config, session);
return session; return session;
} catch (IOException e) { } catch (IOException e) {
@ -105,9 +107,10 @@ public class GDBDebugger implements ICDebugger {
boolean failed = false; boolean failed = false;
try { try {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$
File cwd = exe.getProject().getLocation().toFile(); File cwd = exe.getProject().getLocation().toFile();
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
session = MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), pid, null, cwd, gdbinit, null); session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getLocation().toFile(), pid, null, cwd, gdbinit, null);
initializeLibraries(config, session); initializeLibraries(config, session);
return session; return session;
} catch (IOException e) { } catch (IOException e) {
@ -137,9 +140,10 @@ public class GDBDebugger implements ICDebugger {
boolean failed = false; boolean failed = false;
try { try {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$
File cwd = exe.getProject().getLocation().toFile(); File cwd = exe.getProject().getLocation().toFile();
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
session = MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), corefile.toFile(), cwd, gdbinit, null); session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getLocation().toFile(), corefile.toFile(), cwd, gdbinit, null);
initializeLibraries(config, session); initializeLibraries(config, session);
return session; return session;
} catch (IOException e) { } catch (IOException e) {

View file

@ -14,6 +14,7 @@ package org.eclipse.cdt.debug.mi.core;
import java.io.File; import java.io.File;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget; import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
import org.eclipse.cdt.debug.mi.core.cdi.Session; 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.cdi.model.Target;
@ -43,6 +44,7 @@ public class GDBServerCDIDebugger extends GDBCDIDebugger {
boolean failed = false; boolean failed = false;
try { try {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$
File cwd = getProjectPath(config).toFile(); File cwd = getProjectPath(config).toFile();
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
if (config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, false)) { if (config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, false)) {
@ -50,7 +52,7 @@ public class GDBServerCDIDebugger extends GDBCDIDebugger {
remote += ":"; //$NON-NLS-1$ remote += ":"; //$NON-NLS-1$
remote += config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, "invalid"); //$NON-NLS-1$ remote += config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, "invalid"); //$NON-NLS-1$
String[] args = new String[] {"remote", remote}; //$NON-NLS-1$ String[] args = new String[] {"remote", remote}; //$NON-NLS-1$
session = MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), 0, args, cwd, gdbinit, monitor); session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getPath().toFile(), 0, args, cwd, gdbinit, monitor);
} else { } else {
MIPlugin plugin = MIPlugin.getDefault(); MIPlugin plugin = MIPlugin.getDefault();
Preferences prefs = plugin.getPluginPreferences(); Preferences prefs = plugin.getPluginPreferences();
@ -58,7 +60,7 @@ public class GDBServerCDIDebugger extends GDBCDIDebugger {
String remote = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV, "invalid"); //$NON-NLS-1$ String remote = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV, "invalid"); //$NON-NLS-1$
String remoteBaud = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV_SPEED, "invalid"); //$NON-NLS-1$ String remoteBaud = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV_SPEED, "invalid"); //$NON-NLS-1$
session = MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), -1, null, cwd, gdbinit, monitor); session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getPath().toFile(), -1, null, cwd, gdbinit, monitor);
ICDITarget[] targets = session.getTargets(); ICDITarget[] targets = session.getTargets();
for (int i = 0; i < targets.length; ++i) { for (int i = 0; i < targets.length; ++i) {
Target target = (Target)targets[i]; Target target = (Target)targets[i];

View file

@ -16,6 +16,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.debug.core.ICDebugger; import org.eclipse.cdt.debug.core.ICDebugger;
import org.eclipse.cdt.debug.core.cdi.CDIException; import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDISession; import org.eclipse.cdt.debug.core.cdi.ICDISession;
@ -63,6 +64,7 @@ public class GDBServerDebugger implements ICDebugger {
boolean failed = false; boolean failed = false;
try { try {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$ String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
String miVersion = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_PROTOCOL, "mi"); //$NON-NLS-1$
File cwd = exe.getProject().getLocation().toFile(); File cwd = exe.getProject().getLocation().toFile();
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$ String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
if (config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, false)) { if (config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, false)) {
@ -70,7 +72,7 @@ public class GDBServerDebugger implements ICDebugger {
remote += ":"; //$NON-NLS-1$ remote += ":"; //$NON-NLS-1$
remote += config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, "invalid"); //$NON-NLS-1$ remote += config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, "invalid"); //$NON-NLS-1$
String[] args = new String[] {"remote", remote}; //$NON-NLS-1$ String[] args = new String[] {"remote", remote}; //$NON-NLS-1$
session = MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), 0, args, cwd, gdbinit, null); session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getLocation().toFile(), 0, args, cwd, gdbinit, null);
} else { } else {
MIPlugin plugin = MIPlugin.getDefault(); MIPlugin plugin = MIPlugin.getDefault();
Preferences prefs = plugin.getPluginPreferences(); Preferences prefs = plugin.getPluginPreferences();
@ -78,7 +80,7 @@ public class GDBServerDebugger implements ICDebugger {
String remote = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV, "invalid"); //$NON-NLS-1$ String remote = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV, "invalid"); //$NON-NLS-1$
String remoteBaud = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV_SPEED, "invalid"); //$NON-NLS-1$ String remoteBaud = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV_SPEED, "invalid"); //$NON-NLS-1$
session = MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), -1, null, cwd, gdbinit, null); session = MIPlugin.getDefault().createCSession(gdb, miVersion, exe.getLocation().toFile(), -1, null, cwd, gdbinit, null);
ICDITarget[] targets = session.getTargets(); ICDITarget[] targets = session.getTargets();
for (int i = 0; i < targets.length; ++i) { for (int i = 0; i < targets.length; ++i) {
Target target = (Target)targets[i]; Target target = (Target)targets[i];

View file

@ -17,11 +17,13 @@ import java.io.OutputStream;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.eclipse.cdt.debug.mi.core.cdi.Session; import org.eclipse.cdt.debug.mi.core.cdi.Session;
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.CommandFactory;
import org.eclipse.cdt.debug.mi.core.command.MIStackListFrames; import org.eclipse.cdt.debug.mi.core.command.MIStackListFrames;
import org.eclipse.cdt.debug.mi.core.command.CLITargetAttach;
import org.eclipse.cdt.debug.mi.core.command.MITargetSelect; import org.eclipse.cdt.debug.mi.core.command.MITargetSelect;
import org.eclipse.cdt.debug.mi.core.command.MIVersion;
import org.eclipse.cdt.debug.mi.core.output.MIInfo; import org.eclipse.cdt.debug.mi.core.output.MIInfo;
import org.eclipse.cdt.utils.pty.PTY; import org.eclipse.cdt.utils.pty.PTY;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
@ -60,7 +62,7 @@ public class MIPlugin extends Plugin {
} }
/** /**
* The constructor * The constructor
* @see org.eclipse.core.runtime.Plugin#Plugin(IPluginDescriptor) * @see org.eclipse.core.runtime.Plugin#Plugin()
*/ */
public MIPlugin() { public MIPlugin() {
super(); super();
@ -83,8 +85,8 @@ public class MIPlugin extends Plugin {
* @throws MIException * @throws MIException
* @return MISession * @return MISession
*/ */
public MISession createMISession(MIProcess process, IMITTY pty, int timeout, int type, int launchTimeout) throws MIException { public MISession createMISession(MIProcess process, IMITTY pty, int timeout, int type, int launchTimeout, String miVersion, IProgressMonitor monitor) throws MIException {
return new MISession(process, pty, timeout, type, launchTimeout); return new MISession(process, pty, type, timeout, launchTimeout, miVersion, monitor);
} }
/** /**
@ -95,21 +97,22 @@ public class MIPlugin extends Plugin {
* @throws MIException * @throws MIException
* @return MISession * @return MISession
*/ */
public MISession createMISession(MIProcess process, IMITTY pty, int type) throws MIException { public MISession createMISession(MIProcess process, IMITTY pty, int type, String miVersion, IProgressMonitor monitor) throws MIException {
MIPlugin miPlugin = getDefault(); MIPlugin miPlugin = getDefault();
Preferences prefs = miPlugin.getPluginPreferences(); Preferences prefs = miPlugin.getPluginPreferences();
int timeout = prefs.getInt(IMIConstants.PREF_REQUEST_TIMEOUT); int timeout = prefs.getInt(IMIConstants.PREF_REQUEST_TIMEOUT);
int launchTimeout = prefs.getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT); int launchTimeout = prefs.getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT);
return createMISession(process, pty, timeout, type, launchTimeout); return createMISession(process, pty, timeout, type, launchTimeout, miVersion, monitor);
} }
/** /**
* Method createCSession. * Method createCSession; Create an new PTY instance and launch gdb in mi for local debug.
*
* @param program * @param program
* @return ICDISession * @return ICDISession
* @throws MIException * @throws MIException
*/ */
public Session createCSession(String gdb, File program, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException { public Session createCSession(String gdb, String miVersion, File program, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException {
IMITTY pty = null; IMITTY pty = null;
boolean failed = false; boolean failed = false;
@ -121,7 +124,7 @@ public class MIPlugin extends Plugin {
} }
try { try {
return createCSession(gdb, program, cwd, gdbinit, pty, monitor); return createCSession(gdb, miVersion, program, cwd, gdbinit, pty, monitor);
} catch (IOException exc) { } catch (IOException exc) {
failed = true; failed = true;
throw exc; throw exc;
@ -149,12 +152,12 @@ public class MIPlugin extends Plugin {
} }
/** /**
* Method createCSession. * Method createCSession; lauch gdb in mi mode for local debugging
* @param program * @param program
* @return ICDISession * @return ICDISession
* @throws IOException * @throws IOException
*/ */
public Session createCSession(String gdb, File program, File cwd, String gdbinit, IMITTY pty, IProgressMonitor monitor) throws IOException, MIException { public Session createCSession(String gdb, String miVersion, File program, File cwd, String gdbinit, IMITTY pty, IProgressMonitor monitor) throws IOException, MIException {
if (gdb == null || gdb.length() == 0) { if (gdb == null || gdb.length() == 0) {
gdb = GDB; gdb = GDB;
} }
@ -170,23 +173,33 @@ public class MIPlugin extends Plugin {
String[] args; String[] args;
if (pty != null) { if (pty != null) {
if (program == null) { if (program == null) {
args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-tty", pty.getSlaveName(), "-i", "mi"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-tty", pty.getSlaveName(), "-i", miVersion}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
} else { } else {
args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-tty", pty.getSlaveName(), "-i", "mi", program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-tty", pty.getSlaveName(), "-i", miVersion, program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
} }
} else { } else {
if (program == null) { if (program == null) {
args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-i", "mi"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-i", miVersion}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
} else { } else {
args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-i", "mi", program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-i", miVersion, program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
} }
} }
MIProcess pgdb = new MIProcessAdapter(args, monitor); int launchTimeout = MIPlugin.getDefault().getPluginPreferences().getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT);
MIProcess pgdb = new MIProcessAdapter(args, launchTimeout, monitor);
if (MIPlugin.getDefault().isDebugging()) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < args.length; ++i) {
sb.append(args[i]);
sb.append(' ');
}
MIPlugin.getDefault().debugLog(sb.toString());
}
MISession session; MISession session;
try { try {
session = createMISession(pgdb, pty, MISession.PROGRAM); session = createMISession(pgdb, pty, MISession.PROGRAM, miVersion, monitor);
} catch (MIException e) { } catch (MIException e) {
pgdb.destroy(); pgdb.destroy();
throw e; throw e;
@ -213,13 +226,13 @@ public class MIPlugin extends Plugin {
} }
/** /**
* Method createCSession. * Method createCSession; Post mortem debug with a core file.
* @param program * @param program
* @param core * @param core
* @return ICDISession * @return ICDISession
* @throws IOException * @throws IOException
*/ */
public Session createCSession(String gdb, File program, File core, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException { public Session createCSession(String gdb, String miVersion, File program, File core, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException {
if (gdb == null || gdb.length() == 0) { if (gdb == null || gdb.length() == 0) {
gdb = GDB; gdb = GDB;
} }
@ -234,14 +247,26 @@ public class MIPlugin extends Plugin {
String[] args; String[] args;
if (program == null) { if (program == null) {
args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi", "-c", core.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", miVersion, "-c", core.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
} else { } else {
args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi", "-c", core.getAbsolutePath(), program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", miVersion, "-c", core.getAbsolutePath(), program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
} }
MIProcess pgdb = new MIProcessAdapter(args, monitor);
int launchTimeout = MIPlugin.getDefault().getPluginPreferences().getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT);
MIProcess pgdb = new MIProcessAdapter(args, launchTimeout, monitor);
if (MIPlugin.getDefault().isDebugging()) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < args.length; ++i) {
sb.append(args[i]);
sb.append(' ');
}
MIPlugin.getDefault().debugLog(sb.toString());
}
MISession session; MISession session;
try { try {
session = createMISession(pgdb, null, MISession.CORE); session = createMISession(pgdb, null, MISession.CORE, miVersion, monitor);
//@@@ We have to manually set the suspended state when doing post-mortem //@@@ We have to manually set the suspended state when doing post-mortem
session.getMIInferior().setSuspended(); session.getMIInferior().setSuspended();
} catch (MIException e) { } catch (MIException e) {
@ -252,13 +277,13 @@ public class MIPlugin extends Plugin {
} }
/** /**
* Method createCSession. * Method createCSession; remote debuging by selectin a target.
* @param program * @param program
* @param pid * @param pid
* @return ICDISession * @return ICDISession
* @throws IOException * @throws IOException
*/ */
public Session createCSession(String gdb, File program, int pid, String[] targetParams, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException { public Session createCSession(String gdb, String miVersion, File program, int pid, String[] targetParams, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException {
if (gdb == null || gdb.length() == 0) { if (gdb == null || gdb.length() == 0) {
gdb = GDB; gdb = GDB;
} }
@ -273,14 +298,26 @@ public class MIPlugin extends Plugin {
String[] args; String[] args;
if (program == null) { if (program == null) {
args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", miVersion}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
} else { } else {
args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi", program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", miVersion, program.getAbsolutePath()}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
} }
MIProcess pgdb = new MIProcessAdapter(args, monitor);
int launchTimeout = MIPlugin.getDefault().getPluginPreferences().getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT);
MIProcess pgdb = new MIProcessAdapter(args, launchTimeout, monitor);
if (MIPlugin.getDefault().isDebugging()) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < args.length; ++i) {
sb.append(args[i]);
sb.append(' ');
}
MIPlugin.getDefault().debugLog(sb.toString());
}
MISession session; MISession session;
try { try {
session = createMISession(pgdb, null, MISession.ATTACH); session = createMISession(pgdb, null, MISession.ATTACH, miVersion, monitor);
} catch (MIException e) { } catch (MIException e) {
pgdb.destroy(); pgdb.destroy();
throw e; throw e;
@ -337,9 +374,9 @@ public class MIPlugin extends Plugin {
// This is to verbose for a log file, better use the console. // This is to verbose for a log file, better use the console.
// getDefault().getLog().log(StatusUtil.newStatus(Status.ERROR, message, null)); // getDefault().getLog().log(StatusUtil.newStatus(Status.ERROR, message, null));
// ALERT:FIXME: For example for big buffers say 4k length, // ALERT:FIXME: For example for big buffers say 4k length,
// the console will simply blow taking down eclipse. // the console will simply blows taking down eclipse.
// This seems only to happen in Eclipse-gtk and Eclipse-motif // This seems only to happen in Eclipse-gtk and Eclipse-motif
// on GNU/Linux, so it will be break in smaller chunks. // on GNU/Linux, so we break the lines in smaller chunks.
while (message.length() > 100) { while (message.length() > 100) {
String partial = message.substring(0, 100); String partial = message.substring(0, 100);
message = message.substring(100); message = message.substring(100);

View file

@ -21,16 +21,20 @@ import java.io.Reader;
import org.eclipse.cdt.utils.spawner.ProcessFactory; import org.eclipse.cdt.utils.spawner.ProcessFactory;
import org.eclipse.cdt.utils.spawner.Spawner; import org.eclipse.cdt.utils.spawner.Spawner;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Preferences;
/** /**
*/ */
public class MIProcessAdapter implements MIProcess { public class MIProcessAdapter implements MIProcess {
Process fGDBProcess; Process fGDBProcess;
private static final int ONE_SECOND = 1000;
public MIProcessAdapter(String[] args, IProgressMonitor monitor) throws IOException { public MIProcessAdapter(String[] args, IProgressMonitor monitor) throws IOException {
fGDBProcess = getGDBProcess(args, monitor); this(args, 0, monitor);
}
public MIProcessAdapter(String[] args, int launchTimeout, IProgressMonitor monitor) throws IOException {
fGDBProcess = getGDBProcess(args, launchTimeout, monitor);
} }
/** /**
@ -41,17 +45,7 @@ public class MIProcessAdapter implements MIProcess {
* @return Process * @return Process
* @throws IOException * @throws IOException
*/ */
protected Process getGDBProcess(String[] args, IProgressMonitor monitor) throws IOException { protected Process getGDBProcess(String[] args, int launchTimeout, IProgressMonitor monitor) throws IOException {
int ONE_SECOND = 1000;
if (MIPlugin.getDefault().isDebugging()) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < args.length; ++i) {
sb.append(args[i]);
sb.append(' ');
}
MIPlugin.getDefault().debugLog(sb.toString());
}
final Process pgdb = ProcessFactory.getFactory().exec(args); final Process pgdb = ProcessFactory.getFactory().exec(args);
Thread syncStartup = new Thread("GDB Start") { //$NON-NLS-1$ Thread syncStartup = new Thread("GDB Start") { //$NON-NLS-1$
public void run() { public void run() {
@ -74,10 +68,7 @@ public class MIProcessAdapter implements MIProcess {
}; };
syncStartup.start(); syncStartup.start();
MIPlugin miPlugin = MIPlugin.getDefault();
Preferences prefs = miPlugin.getPluginPreferences();
int timepass = 0; int timepass = 0;
int launchTimeout = prefs.getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT);
if (launchTimeout <= 0) { if (launchTimeout <= 0) {
// Simulate we are waiting forever. // Simulate we are waiting forever.
launchTimeout = Integer.MAX_VALUE; launchTimeout = Integer.MAX_VALUE;