mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
2004-10-20 Alain Magloire
Use the new ICDIDebugger interface * mi/org/eclipse/cdt/debug/mi/core/MIInferior.java * mi/org/eclipse/cdt/debug/mi/core/MISession.java * mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java * src/org/eclipse/cdt/debug/mi/core/CygwinGDBCDIDebugger.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/GDBServerDebugger.java * src/org/eclipse/cdt/debug/mi/core/MIPlugin.java * src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java * plugin.xml
This commit is contained in:
parent
96930791c6
commit
bc9547c99e
12 changed files with 477 additions and 55 deletions
|
@ -1,3 +1,17 @@
|
|||
2004-10-20 Alain Magloire
|
||||
Use the new ICDIDebugger interface
|
||||
|
||||
* mi/org/eclipse/cdt/debug/mi/core/MIInferior.java
|
||||
* mi/org/eclipse/cdt/debug/mi/core/MISession.java
|
||||
* mi/org/eclipse/cdt/debug/mi/core/SessionProcess.java
|
||||
* src/org/eclipse/cdt/debug/mi/core/CygwinGDBCDIDebugger.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/GDBServerDebugger.java
|
||||
* src/org/eclipse/cdt/debug/mi/core/MIPlugin.java
|
||||
* src/org/eclipse/cdt/debug/mi/core/MIProcessAdapter.java
|
||||
* plugin.xml
|
||||
|
||||
2004-10-20 David Inglis
|
||||
Fixed terminated delay for corefile
|
||||
* mi/org/eclipse/cdt/debug/mi/core/MIInferior.java
|
||||
|
|
|
@ -168,12 +168,13 @@ public class MIInferior extends Process {
|
|||
// - For PostMortem(Core): send event
|
||||
// else noop
|
||||
if ((session.isAttachSession() && isConnected()) || (session.isProgramSession() && !isTerminated())) {
|
||||
|
||||
// Try to interrupt the inferior, first.
|
||||
if (isRunning()) {
|
||||
interrupt();
|
||||
}
|
||||
CommandFactory factory = session.getCommandFactory();
|
||||
MIExecAbort abort = factory.createMIExecAbort();
|
||||
// Try to interrupt the inferior, first.
|
||||
interrupt();
|
||||
session.postCommand(abort);
|
||||
session.postCommand0(abort, session.getCommandTimeout());
|
||||
abort.getMIInfo();
|
||||
setTerminated(abort.getToken(), true);
|
||||
} else if (session.isCoreSession() && !isTerminated()){
|
||||
|
@ -248,7 +249,7 @@ public class MIInferior extends Process {
|
|||
}
|
||||
|
||||
public synchronized void setTerminated() {
|
||||
setTerminated(0, false);
|
||||
setTerminated(0, true);
|
||||
}
|
||||
|
||||
synchronized void setTerminated(int token, boolean fireEvent) {
|
||||
|
|
|
@ -292,7 +292,7 @@ public class MISession extends Observable {
|
|||
/**
|
||||
* Sends a command to gdb, and wait(timeout) for a response.
|
||||
*/
|
||||
public synchronized void postCommand(Command cmd, long timeout) throws MIException {
|
||||
public void postCommand(Command cmd, long timeout) throws MIException {
|
||||
|
||||
// Test if we are in a sane state.
|
||||
if (!txThread.isAlive() || !rxThread.isAlive()) {
|
||||
|
@ -311,7 +311,10 @@ public class MISession extends Observable {
|
|||
if (isTerminated()) {
|
||||
throw new MIException(MIPlugin.getResourceString("src.MISession.Session_terminated")); //$NON-NLS-1$
|
||||
}
|
||||
postCommand0(cmd, timeout);
|
||||
}
|
||||
|
||||
public synchronized void postCommand0(Command cmd, long timeout) throws MIException {
|
||||
// TRACING: print the command;
|
||||
MIPlugin.getDefault().debugLog(cmd.toString());
|
||||
|
||||
|
@ -374,12 +377,12 @@ public class MISession extends Observable {
|
|||
if (isTerminated()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
terminated = true;
|
||||
|
||||
// Destroy any MI Inferior(Process) and streams.
|
||||
inferior.destroy();
|
||||
|
||||
|
||||
// {in,out}Channel is use as predicate/condition
|
||||
// in the {RX,TX,Event}Thread to detect termination
|
||||
// and bail out. So they are set to null.
|
||||
|
@ -462,23 +465,17 @@ public class MISession extends Observable {
|
|||
}
|
||||
|
||||
// Allow (10 secs) for the EventThread to finish processing the queue.
|
||||
Queue queue = getEventQueue();
|
||||
for (int i = 0; !queue.isEmpty() && i < 5; i++) {
|
||||
if (!eventThread.equals(Thread.currentThread())) {
|
||||
// Kill the event Thread.
|
||||
try {
|
||||
java.lang.Thread.sleep(2000);
|
||||
if (eventThread.isAlive()) {
|
||||
eventThread.interrupt();
|
||||
eventThread.join(cmdTimeout);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Kill the event Thread.
|
||||
try {
|
||||
if (eventThread.isAlive()) {
|
||||
eventThread.interrupt();
|
||||
eventThread.join(cmdTimeout);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
|
||||
// Tell the observers that the session is terminated
|
||||
notifyObservers(new MIGDBExitEvent(this, 0));
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ public class SessionProcess extends Process {
|
|||
* @see java.lang.Process#destroy()
|
||||
*/
|
||||
public void destroy() {
|
||||
session.getGDBProcess().destroy();
|
||||
session.terminate();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
name="%GDBDebugger.name"
|
||||
modes="run,core,attach"
|
||||
cpu="native"
|
||||
class="org.eclipse.cdt.debug.mi.core.GDBDebugger"
|
||||
class="org.eclipse.cdt.debug.mi.core.GDBCDIDebugger"
|
||||
id="org.eclipse.cdt.debug.mi.core.CDebugger">
|
||||
</debugger>
|
||||
<debugger
|
||||
|
@ -36,7 +36,7 @@
|
|||
name="%CygwinGDBDebugger.name"
|
||||
modes="run,core,attach"
|
||||
cpu="native"
|
||||
class="org.eclipse.cdt.debug.mi.core.CygwinGDBDebugger"
|
||||
class="org.eclipse.cdt.debug.mi.core.CygwinGDBCDIDebugger"
|
||||
id="org.eclipse.cdt.debug.mi.core.CygwinCDebugger">
|
||||
</debugger>
|
||||
<debugger
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.debug.mi.core;
|
||||
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDISession;
|
||||
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.model.Target;
|
||||
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
|
||||
import org.eclipse.cdt.debug.mi.core.command.MIGDBSet;
|
||||
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.ILaunchConfiguration;
|
||||
|
||||
/**
|
||||
* @author User
|
||||
*
|
||||
* TODO To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
public class CygwinGDBCDIDebugger extends GDBCDIDebugger {
|
||||
static final CygwinCommandFactory commandFactory = new CygwinCommandFactory();
|
||||
|
||||
protected void initializeLibraries(ILaunchConfiguration config, Session session) throws CoreException {
|
||||
// the "search-solib-path" and "stop-on-solib-events" options are not supported in CygWin
|
||||
}
|
||||
|
||||
public ICDISession createLaunchSession(ILaunchConfiguration config, IBinaryExecutable exe, IProgressMonitor monitor) throws CoreException {
|
||||
Session session = (Session) super.createLaunchSession(config, exe, monitor);
|
||||
ICDITarget[] targets = session.getTargets();
|
||||
for (int i = 0; i < targets.length; ++i) {
|
||||
Target target = (Target)targets[i];
|
||||
MISession miSession = target.getMISession();
|
||||
miSession.setCommandFactory(commandFactory);
|
||||
// For windows we need to start the inferior in a new console window
|
||||
// to separate the Inferior std{in,out,err} from gdb std{in,out,err}
|
||||
try {
|
||||
CommandFactory factory = miSession.getCommandFactory();
|
||||
MIGDBSet set = factory.createMIGDBSet(new String[] { "new-console" }); //$NON-NLS-1$
|
||||
miSession.postCommand(set);
|
||||
MIInfo info = set.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.
|
||||
}
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
public ICDISession createAttachSession(ILaunchConfiguration config, IBinaryExecutable exe, IProgressMonitor monitor) throws CoreException {
|
||||
Session session = (Session) super.createAttachSession(config, exe, monitor);
|
||||
ICDITarget[] targets = session.getTargets();
|
||||
for (int i = 0; i < targets.length; ++i) {
|
||||
Target target = (Target)targets[i];
|
||||
target.getMISession().setCommandFactory(commandFactory);
|
||||
}
|
||||
initializeLibraries(config, session);
|
||||
return session;
|
||||
}
|
||||
|
||||
public ICDISession createCoreSession(ILaunchConfiguration config, IBinaryExecutable exe, IProgressMonitor monitor) throws CoreException {
|
||||
Session session = (Session) super.createCoreSession(config, exe, monitor);
|
||||
ICDITarget[] targets = session.getTargets();
|
||||
for (int i = 0; i < targets.length; ++i) {
|
||||
Target target = (Target)targets[i];
|
||||
target.getMISession().setCommandFactory(commandFactory);
|
||||
}
|
||||
initializeLibraries(config, session);
|
||||
return session;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,285 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.debug.mi.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable;
|
||||
import org.eclipse.cdt.debug.core.ICDIDebugger;
|
||||
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
|
||||
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDISession;
|
||||
import org.eclipse.cdt.debug.core.cdi.ICDISharedLibraryManager;
|
||||
import org.eclipse.cdt.debug.mi.core.cdi.Session;
|
||||
import org.eclipse.cdt.debug.mi.core.cdi.SharedLibraryManager;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.MultiStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.debug.core.DebugPlugin;
|
||||
import org.eclipse.debug.core.ILaunch;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.debug.core.model.IProcess;
|
||||
|
||||
/**
|
||||
* @author User
|
||||
*
|
||||
* TODO To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
public class GDBCDIDebugger implements ICDIDebugger {
|
||||
|
||||
ILaunch fLaunch;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.debug.core.ICDIDebugger#createDebuggerSession(org.eclipse.debug.core.ILaunch, org.eclipse.cdt.core.IBinaryParser.IBinaryExecutable, org.eclipse.core.runtime.IProgressMonitor)
|
||||
*/
|
||||
public ICDISession createDebuggerSession(ILaunch launch, IBinaryExecutable exe, IProgressMonitor monitor)
|
||||
throws CoreException {
|
||||
fLaunch = launch;
|
||||
ILaunchConfiguration config = launch.getLaunchConfiguration();
|
||||
ICDISession dsession = null;
|
||||
String debugMode = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
|
||||
ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
|
||||
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
if (monitor.isCanceled()) {
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
|
||||
if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN)) {
|
||||
dsession = createLaunchSession(config, exe, monitor);
|
||||
} else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH)) {
|
||||
dsession = createAttachSession(config, exe, monitor);
|
||||
} else if (debugMode.equals(ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE)) {
|
||||
dsession = createCoreSession(config, exe, monitor);
|
||||
}
|
||||
if (dsession != null) {
|
||||
Process debugger;
|
||||
try {
|
||||
debugger = dsession.getSessionProcess();
|
||||
if (debugger != null ) {
|
||||
IProcess debuggerProcess = DebugPlugin.newProcess(launch, debugger, renderDebuggerProcessLabel());
|
||||
launch.addProcess(debuggerProcess);
|
||||
}
|
||||
} catch (CDIException e) {
|
||||
// Should we just ignore ?
|
||||
}
|
||||
}
|
||||
|
||||
return dsession;
|
||||
}
|
||||
|
||||
public ICDISession createLaunchSession(ILaunchConfiguration config, IBinaryExecutable exe, IProgressMonitor monitor) throws CoreException {
|
||||
Session session = null;
|
||||
boolean failed = false;
|
||||
try {
|
||||
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
|
||||
File cwd = getProjectPath(config).toFile();
|
||||
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
|
||||
session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), cwd, gdbinit, monitor);
|
||||
initializeLibraries(config, session);
|
||||
return session;
|
||||
} catch (Exception e) {
|
||||
// Catch all wrap them up and rethrow
|
||||
failed = true;
|
||||
if (e instanceof CoreException) {
|
||||
throw (CoreException)e;
|
||||
}
|
||||
throw newCoreException(e);
|
||||
} finally {
|
||||
if (failed) {
|
||||
if (session != null) {
|
||||
try {
|
||||
session.terminate();
|
||||
} catch (Exception ex) {
|
||||
// ignore the exception here.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ICDISession createAttachSession(ILaunchConfiguration config, IBinaryExecutable exe, IProgressMonitor monitor) throws CoreException {
|
||||
Session session = null;
|
||||
boolean failed = false;
|
||||
try {
|
||||
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
|
||||
int pid = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_ATTACH_PROCESS_ID, -1);
|
||||
File cwd = getProjectPath(config).toFile();
|
||||
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
|
||||
session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), pid, null, cwd, gdbinit, monitor);
|
||||
initializeLibraries(config, session);
|
||||
return session;
|
||||
} catch (Exception e) {
|
||||
// Catch all wrap them up and rethrow
|
||||
failed = true;
|
||||
if (e instanceof CoreException) {
|
||||
throw (CoreException)e;
|
||||
}
|
||||
throw newCoreException(e);
|
||||
} finally {
|
||||
if (failed) {
|
||||
if (session != null) {
|
||||
try {
|
||||
session.terminate();
|
||||
} catch (Exception ex) {
|
||||
// ignore the exception here.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ICDISession createCoreSession(ILaunchConfiguration config, IBinaryExecutable exe, IProgressMonitor monitor) throws CoreException {
|
||||
Session session = null;
|
||||
boolean failed = false;
|
||||
try {
|
||||
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
|
||||
File cwd = getProjectPath(config).toFile();
|
||||
IPath coreFile = new Path(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_COREFILE_PATH, (String)null));
|
||||
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
|
||||
session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getPath().toFile(), coreFile.toFile(), cwd, gdbinit, monitor);
|
||||
initializeLibraries(config, session);
|
||||
return session;
|
||||
} catch (Exception e) {
|
||||
// Catch all wrap them up and rethrow
|
||||
failed = true;
|
||||
if (e instanceof CoreException) {
|
||||
throw (CoreException)e;
|
||||
}
|
||||
throw newCoreException(e);
|
||||
} finally {
|
||||
if (failed) {
|
||||
if (session != null) {
|
||||
try {
|
||||
session.terminate();
|
||||
} catch (Exception ex) {
|
||||
// ignore the exception here.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void initializeLibraries(ILaunchConfiguration config, Session session) throws CoreException {
|
||||
try {
|
||||
ICDISharedLibraryManager manager = session.getSharedLibraryManager();
|
||||
if (manager instanceof SharedLibraryManager) {
|
||||
SharedLibraryManager mgr = (SharedLibraryManager)manager;
|
||||
boolean autolib = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_AUTO_SOLIB, IMILaunchConfigurationConstants.DEBUGGER_AUTO_SOLIB_DEFAULT);
|
||||
boolean stopOnSolibEvents = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_STOP_ON_SOLIB_EVENTS, IMILaunchConfigurationConstants.DEBUGGER_STOP_ON_SOLIB_EVENTS_DEFAULT);
|
||||
try {
|
||||
mgr.setAutoLoadSymbols(autolib);
|
||||
mgr.setStopOnSolibEvents(stopOnSolibEvents);
|
||||
// The idea is that if the user set autolib, by default
|
||||
// we provide with the capability of deferred breakpoints
|
||||
// And we set setStopOnSolib events for them(but they should not see those things.
|
||||
//
|
||||
// If the user explicitly set stopOnSolibEvents well it probably
|
||||
// means that they wanted to see those events so do no do deferred breakpoints.
|
||||
if (autolib && !stopOnSolibEvents) {
|
||||
mgr.setDeferredBreakpoint(true);
|
||||
mgr.setStopOnSolibEvents(true);
|
||||
}
|
||||
} catch (CDIException e) {
|
||||
// Ignore this error
|
||||
// it seems to be a real problem on many gdb platform
|
||||
}
|
||||
}
|
||||
List p = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUGGER_SOLIB_PATH, Collections.EMPTY_LIST);
|
||||
if (p.size() > 0) {
|
||||
String[] oldPaths = manager.getSharedLibraryPaths();
|
||||
String[] paths = new String[oldPaths.length + p.size()];
|
||||
System.arraycopy(p.toArray(new String[p.size()]), 0, paths, 0, p.size());
|
||||
System.arraycopy(oldPaths, 0, paths, p.size(), oldPaths.length);
|
||||
manager.setSharedLibraryPaths(paths);
|
||||
}
|
||||
} catch (CDIException e) {
|
||||
throw newCoreException(MIPlugin.getResourceString("src.GDBDebugger.Error_initializing_shared_lib_options") + e.getMessage(), e); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
public static IPath getProjectPath(ILaunchConfiguration configuration) throws CoreException {
|
||||
String projectName = getProjectName(configuration);
|
||||
if (projectName != null) {
|
||||
projectName = projectName.trim();
|
||||
if (projectName.length() > 0) {
|
||||
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
|
||||
IPath p = project.getLocation();
|
||||
if (p != null) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Path.EMPTY;
|
||||
}
|
||||
|
||||
public static String getProjectName(ILaunchConfiguration configuration) throws CoreException {
|
||||
return configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null);
|
||||
}
|
||||
|
||||
protected ILaunch getLauch() {
|
||||
return fLaunch;
|
||||
}
|
||||
|
||||
protected String renderDebuggerProcessLabel() {
|
||||
String format = "{0} ({1})"; //$NON-NLS-1$
|
||||
String timestamp = DateFormat.getInstance().format(new Date(System.currentTimeMillis()));
|
||||
return MessageFormat.format(format, new String[]{
|
||||
"Debugger Process", timestamp}); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws a core exception with an error status object built from the given
|
||||
* message, lower level exception, and error code.
|
||||
*
|
||||
* @param message
|
||||
* the status message
|
||||
* @param exception
|
||||
* lower level exception associated with the error, or
|
||||
* <code>null</code> if none
|
||||
* @param code
|
||||
* error code
|
||||
*/
|
||||
protected CoreException newCoreException(Throwable exception) {
|
||||
String message = MIPlugin.getResourceString("src.GDBDebugger.Error_creating_session") + exception.getMessage();//$NON-NLS-1$
|
||||
int code = ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR;
|
||||
String ID = MIPlugin.getUniqueIdentifier();
|
||||
MultiStatus status = new MultiStatus(ID, code, message, exception);
|
||||
status.add(new Status(IStatus.ERROR, ID, code, exception == null ? new String() : exception.getLocalizedMessage(), exception));
|
||||
return new CoreException(status);
|
||||
}
|
||||
|
||||
protected CoreException newCoreException(String message, Throwable exception) {
|
||||
int code = ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR;
|
||||
String ID = MIPlugin.getUniqueIdentifier();
|
||||
MultiStatus status = new MultiStatus(ID, code, message, exception);
|
||||
status.add(new Status(IStatus.ERROR, ID, code, exception == null ? new String() : exception.getLocalizedMessage(), exception));
|
||||
return new CoreException(status);
|
||||
}
|
||||
|
||||
}
|
|
@ -24,6 +24,7 @@ import org.eclipse.cdt.debug.mi.core.cdi.SharedLibraryManager;
|
|||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
|
||||
public class GDBDebugger implements ICDebugger {
|
||||
|
@ -73,7 +74,7 @@ public class GDBDebugger implements ICDebugger {
|
|||
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
|
||||
File cwd = exe.getProject().getLocation().toFile();
|
||||
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
|
||||
session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), cwd, gdbinit);
|
||||
session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), cwd, gdbinit, null);
|
||||
initializeLibraries(config, session);
|
||||
return session;
|
||||
} catch (IOException e) {
|
||||
|
@ -105,7 +106,7 @@ public class GDBDebugger implements ICDebugger {
|
|||
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
|
||||
File cwd = exe.getProject().getLocation().toFile();
|
||||
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
|
||||
session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), pid, null, cwd, gdbinit);
|
||||
session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), pid, null, cwd, gdbinit, null);
|
||||
initializeLibraries(config, session);
|
||||
return session;
|
||||
} catch (IOException e) {
|
||||
|
@ -137,7 +138,7 @@ public class GDBDebugger implements ICDebugger {
|
|||
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); //$NON-NLS-1$
|
||||
File cwd = exe.getProject().getLocation().toFile();
|
||||
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); //$NON-NLS-1$
|
||||
session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), corefile.toFile(), cwd, gdbinit);
|
||||
session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), corefile.toFile(), cwd, gdbinit, null);
|
||||
initializeLibraries(config, session);
|
||||
return session;
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -69,7 +69,7 @@ public class GDBServerDebugger implements ICDebugger {
|
|||
remote += ":"; //$NON-NLS-1$
|
||||
remote += config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, "invalid"); //$NON-NLS-1$
|
||||
String[] args = new String[] {"remote", remote}; //$NON-NLS-1$
|
||||
session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), 0, args, cwd, gdbinit);
|
||||
session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), 0, args, cwd, gdbinit, null);
|
||||
} else {
|
||||
MIPlugin plugin = MIPlugin.getDefault();
|
||||
Preferences prefs = plugin.getPluginPreferences();
|
||||
|
@ -77,7 +77,7 @@ public class GDBServerDebugger implements ICDebugger {
|
|||
|
||||
String remote = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV, "invalid"); //$NON-NLS-1$
|
||||
String remoteBaud = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV_SPEED, "invalid"); //$NON-NLS-1$
|
||||
session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), -1, null, cwd, gdbinit);
|
||||
session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), -1, null, cwd, gdbinit, null);
|
||||
ICDITarget[] targets = session.getTargets();
|
||||
for (int i = 0; i < targets.length; ++i) {
|
||||
Target target = (Target)targets[i];
|
||||
|
|
|
@ -26,6 +26,8 @@ import org.eclipse.cdt.debug.mi.core.command.MITargetAttach;
|
|||
import org.eclipse.cdt.debug.mi.core.command.MITargetSelect;
|
||||
import org.eclipse.cdt.debug.mi.core.output.MIInfo;
|
||||
import org.eclipse.cdt.utils.pty.PTY;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
import org.eclipse.core.runtime.Preferences;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
@ -109,7 +111,7 @@ public class MIPlugin extends Plugin {
|
|||
* @return ICDISession
|
||||
* @throws MIException
|
||||
*/
|
||||
public ICDISession createCSession(String gdb, File program, File cwd, String gdbinit) throws IOException, MIException {
|
||||
public ICDISession createCSession(String gdb, File program, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException {
|
||||
IMITTY pty = null;
|
||||
boolean failed = false;
|
||||
|
||||
|
@ -117,10 +119,11 @@ public class MIPlugin extends Plugin {
|
|||
PTY pseudo = new PTY();
|
||||
pty = new MITTYAdapter(pseudo);
|
||||
} catch (IOException e) {
|
||||
// Should we not print/log this ?
|
||||
}
|
||||
|
||||
try {
|
||||
return createCSession(gdb, program, cwd, gdbinit, pty);
|
||||
return createCSession(gdb, program, cwd, gdbinit, pty, monitor);
|
||||
} catch (IOException exc) {
|
||||
failed = true;
|
||||
throw exc;
|
||||
|
@ -153,7 +156,7 @@ public class MIPlugin extends Plugin {
|
|||
* @return ICDISession
|
||||
* @throws IOException
|
||||
*/
|
||||
public ICDISession createCSession(String gdb, File program, File cwd, String gdbinit, IMITTY pty) throws IOException, MIException {
|
||||
public ICDISession createCSession(String gdb, File program, File cwd, String gdbinit, IMITTY pty, IProgressMonitor monitor) throws IOException, MIException {
|
||||
if (gdb == null || gdb.length() == 0) {
|
||||
gdb = GDB;
|
||||
}
|
||||
|
@ -162,6 +165,10 @@ public class MIPlugin extends Plugin {
|
|||
gdbinit = GDBINIT;
|
||||
}
|
||||
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
|
||||
String[] args;
|
||||
if (pty != null) {
|
||||
if (program == null) {
|
||||
|
@ -177,7 +184,7 @@ public class MIPlugin extends Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
MIProcess pgdb = new MIProcessAdapter(args);
|
||||
MIProcess pgdb = new MIProcessAdapter(args, monitor);
|
||||
|
||||
MISession session;
|
||||
try {
|
||||
|
@ -213,7 +220,7 @@ public class MIPlugin extends Plugin {
|
|||
* @return ICDISession
|
||||
* @throws IOException
|
||||
*/
|
||||
public ICDISession createCSession(String gdb, File program, File core, File cwd, String gdbinit) throws IOException, MIException {
|
||||
public ICDISession createCSession(String gdb, File program, File core, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException {
|
||||
if (gdb == null || gdb.length() == 0) {
|
||||
gdb = GDB;
|
||||
}
|
||||
|
@ -221,14 +228,18 @@ public class MIPlugin extends Plugin {
|
|||
if (gdbinit == null || gdbinit.length() == 0) {
|
||||
gdbinit = GDBINIT;
|
||||
}
|
||||
|
||||
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
|
||||
String[] args;
|
||||
if (program == null) {
|
||||
args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1", "-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 {
|
||||
args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1", "-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);
|
||||
MIProcess pgdb = new MIProcessAdapter(args, monitor);
|
||||
MISession session;
|
||||
try {
|
||||
session = createMISession(pgdb, null, MISession.CORE);
|
||||
|
@ -248,7 +259,7 @@ public class MIPlugin extends Plugin {
|
|||
* @return ICDISession
|
||||
* @throws IOException
|
||||
*/
|
||||
public ICDISession createCSession(String gdb, File program, int pid, String[] targetParams, File cwd, String gdbinit) throws IOException, MIException {
|
||||
public ICDISession createCSession(String gdb, File program, int pid, String[] targetParams, File cwd, String gdbinit, IProgressMonitor monitor) throws IOException, MIException {
|
||||
if (gdb == null || gdb.length() == 0) {
|
||||
gdb = GDB;
|
||||
}
|
||||
|
@ -257,13 +268,17 @@ public class MIPlugin extends Plugin {
|
|||
gdbinit = GDBINIT;
|
||||
}
|
||||
|
||||
if (monitor == null) {
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
|
||||
String[] args;
|
||||
if (program == null) {
|
||||
args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
|
||||
} else {
|
||||
args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1", 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);
|
||||
MIProcess pgdb = new MIProcessAdapter(args, monitor);
|
||||
MISession session;
|
||||
try {
|
||||
session = createMISession(pgdb, null, MISession.ATTACH);
|
||||
|
|
|
@ -16,6 +16,8 @@ src.GDBServerDebugger.GDBServer_attaching_unsupported=GDBServer does not support
|
|||
src.GDBServerDebugger.GDBServer_corefiles_unsupported=GDBServer does not support core files
|
||||
src.GDBDebugger.Error_initializing_shared_lib_options=Error initializing shared library options:
|
||||
src.GDBDebugger.Error_creating_session=Error creating session:
|
||||
src.GDBDebugger.Error_launch_timeout=Launch timeout
|
||||
src.GDBDebugger.Error_launch_cancel=Launch cancel
|
||||
src.MISession.Process_Terminated=Process Terminated
|
||||
src.MISession.Thread_Terminated={R,T}xThread terminated
|
||||
src.MISession.Target_not_suspended=Target is not suspended
|
||||
|
@ -25,3 +27,4 @@ src.CygwinGDBDebugger.Error_init_shared_lib_options=Error initializing shared li
|
|||
src.MIInferior.target_is_suspended=target is suspended
|
||||
src.MIInferior.No_session=No MI Session
|
||||
src.MIInferior.Failed_to_interrupt=Failed to interrupt
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.io.Reader;
|
|||
|
||||
import org.eclipse.cdt.utils.spawner.ProcessFactory;
|
||||
import org.eclipse.cdt.utils.spawner.Spawner;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.Preferences;
|
||||
|
||||
/**
|
||||
|
@ -28,19 +29,21 @@ public class MIProcessAdapter implements MIProcess {
|
|||
|
||||
Process fGDBProcess;
|
||||
|
||||
public MIProcessAdapter(String[] args) throws IOException {
|
||||
fGDBProcess = getGDBProcess(args);
|
||||
public MIProcessAdapter(String[] args, IProgressMonitor monitor) throws IOException {
|
||||
fGDBProcess = getGDBProcess(args, monitor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do some basic synchronisation, gdb may take some time to load for
|
||||
* whatever reasons.
|
||||
* whatever reasons and we need to be able to let the user bailout.
|
||||
*
|
||||
* @param args
|
||||
* @return Process
|
||||
* @throws IOException
|
||||
*/
|
||||
protected Process getGDBProcess(String[] args) throws IOException {
|
||||
protected Process getGDBProcess(String[] args, IProgressMonitor monitor) throws IOException {
|
||||
int ONE_SECOND = 1000;
|
||||
|
||||
if (MIPlugin.getDefault().isDebugging()) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < args.length; ++i) {
|
||||
|
@ -65,32 +68,49 @@ public class MIProcessAdapter implements MIProcess {
|
|||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Do nothing
|
||||
}
|
||||
synchronized (pgdb) {
|
||||
pgdb.notifyAll();
|
||||
// Do nothing, ignore the errors
|
||||
}
|
||||
}
|
||||
};
|
||||
syncStartup.start();
|
||||
|
||||
synchronized (pgdb) {
|
||||
MIPlugin miPlugin = MIPlugin.getDefault();
|
||||
Preferences prefs = miPlugin.getPluginPreferences();
|
||||
int launchTimeout = prefs
|
||||
.getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT);
|
||||
while (syncStartup.isAlive()) {
|
||||
MIPlugin miPlugin = MIPlugin.getDefault();
|
||||
Preferences prefs = miPlugin.getPluginPreferences();
|
||||
int timepass = 0;
|
||||
int launchTimeout = prefs.getInt(IMIConstants.PREF_REQUEST_LAUNCH_TIMEOUT);
|
||||
if (launchTimeout <= 0) {
|
||||
// Simulate we are waiting forever.
|
||||
launchTimeout = Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
// To respect the IProgressMonitor we can not use wait/notify
|
||||
// instead we have to loop and check for the monitor to allow to cancel the thread.
|
||||
// The monitor is check every 1 second delay;
|
||||
for (timepass = 0; timepass < launchTimeout; timepass += ONE_SECOND) {
|
||||
if (syncStartup.isAlive() && !monitor.isCanceled()) {
|
||||
try {
|
||||
pgdb.wait(launchTimeout);
|
||||
break;
|
||||
Thread.sleep(ONE_SECOND);
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
syncStartup.interrupt();
|
||||
syncStartup.join(1000);
|
||||
syncStartup.join(ONE_SECOND);
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
}
|
||||
if (monitor.isCanceled()) {
|
||||
pgdb.destroy();
|
||||
String message = MIPlugin.getResourceString("src.GDBDebugger.Error_creating_session");//$NON-NLS-1$
|
||||
throw new IOException(message);
|
||||
} else if (timepass > launchTimeout) {
|
||||
pgdb.destroy();
|
||||
String message = MIPlugin.getResourceString("src.GDBDebugger.Error_launch_timeout"); //$NON-NLS-1$
|
||||
throw new IOException(message);
|
||||
}
|
||||
return pgdb;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue