1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

[249227] New TracingConsole solution to allow for GDB traces to be printed.

This commit is contained in:
Marc Khouzam 2009-02-28 08:21:28 +00:00
parent 516d06123b
commit 0f18d800c1
6 changed files with 111 additions and 2 deletions

View file

@ -58,7 +58,7 @@ import org.eclipse.debug.core.model.ITerminate;
*/
@ThreadSafe
public class GdbLaunch extends Launch
implements ITerminate, IDisconnect
implements ITerminate, IDisconnect, ITracedLaunch
{
private DefaultDsfExecutor fExecutor;
private DsfSession fSession;

View file

@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright (c) 2009 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.cdt.dsf.gdb.launching;
/**
* This interface is used to indicate that a launch should have
* a TracingConsole.
*
* @see org.eclipse.cdt.dsf.gdb.internal.ui.tracing.TracingConsoleManager
* @see org.eclipse.cdt.dsf.gdb.internal.ui.tracing.TracingConsole
*
* @since 2.0
*/
public interface ITracedLaunch {
}

View file

@ -13,6 +13,7 @@
package org.eclipse.cdt.dsf.gdb.service.command;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Hashtable;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@ -370,6 +371,13 @@ public class GDBControl extends AbstractMIControl implements IGDBControl {
return fInferiorProcess;
}
/**
* @since 2.0
*/
public void setTracingStream(OutputStream tracingStream) {
setMITracingStream(tracingStream);
}
@DsfServiceEventHandler
public void eventDispatched(ICommandControlShutdownDMEvent e) {
// Handle our "GDB Exited" event and stop processing commands.

View file

@ -13,6 +13,7 @@
package org.eclipse.cdt.dsf.gdb.service.command;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Hashtable;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@ -509,6 +510,13 @@ public class GDBControl_7_0 extends AbstractMIControl implements IGDBControl {
return fInferiorProcess;
}
/**
* @since 2.0
*/
public void setTracingStream(OutputStream tracingStream) {
setMITracingStream(tracingStream);
}
@DsfServiceEventHandler
public void eventDispatched(ICommandControlShutdownDMEvent e) {
// Handle our "GDB Exited" event and stop processing commands.

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008 Ericsson and others.
* Copyright (c) 2009 Ericsson and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse License v1.0
* which accompanies this distribution, and is available at
@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.service.command;
import java.io.OutputStream;
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService;
import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch;
@ -33,4 +35,9 @@ public interface IGDBControl extends ICommandControlService {
AbstractCLIProcess getCLIProcess();
MIInferiorProcess getInferiorProcess();
/**
* @since 2.0
*/
void setTracingStream(OutputStream tracingStream);
}

View file

@ -111,6 +111,13 @@ public abstract class AbstractMIControl extends AbstractDsfService
*/
private boolean fStoppedCommandProcessing = false;
/**
* An output stream that MI communication should be output to.
* It serves for debugging. Can be <code>null</code> to disable tracing.
*/
private OutputStream fTracingStream = null;
public AbstractMIControl(DsfSession session) {
super(session);
fUseThreadAndFrameOptions = false;
@ -124,6 +131,25 @@ public abstract class AbstractMIControl extends AbstractDsfService
fUseThreadAndFrameOptions = useThreadAndFrameOptions;
}
/**
* Set the tracing stream for the MI communication. If this method is never
* called, tracing will be off, by default.
*
* @param tracingStream The stream to use. Can be <code>null</code>
* to disable tracing.
* @since 2.0
*/
protected void setMITracingStream(OutputStream tracingStream) {
fTracingStream = tracingStream;
}
/**
* Returns the MI tracing stream.
*/
private OutputStream getMITracingStream() {
return fTracingStream;
}
/**
* Starts the threads that process the debugger input/output channels.
* To be invoked by the initialization routine of the extending class.
@ -524,6 +550,22 @@ public abstract class AbstractMIControl extends AbstractDsfService
fOutputStream.flush();
GdbPlugin.debug(GdbPlugin.getDebugTime() + " " + str); //$NON-NLS-1$
getExecutor().execute(new DsfRunnable() {
public void run() {
if (getMITracingStream() != null) {
try {
getMITracingStream().write(GdbPlugin.getDebugTime().getBytes());
getMITracingStream().write(' ');
getMITracingStream().write(str.getBytes());
} catch (IOException e) {
// The tracing stream could be closed at any time
// since the user can set a preference to turn off
// this tracing.
setMITracingStream(null);
}
}
}
});
}
} catch (IOException e) {
// Shutdown thread in case of IO error.
@ -556,6 +598,26 @@ public abstract class AbstractMIControl extends AbstractDsfService
while ((line = reader.readLine()) != null) {
if (line.length() != 0) {
GdbPlugin.debug(GdbPlugin.getDebugTime() + " " + line +"\n"); //$NON-NLS-1$ //$NON-NLS-2$
final String finalLine = line;
getExecutor().execute(new DsfRunnable() {
public void run() {
if (getMITracingStream() != null) {
try {
getMITracingStream().write(GdbPlugin.getDebugTime().getBytes());
getMITracingStream().write(' ');
getMITracingStream().write(finalLine.getBytes());
getMITracingStream().write('\n');
} catch (IOException e) {
// The tracing stream could be closed at any time
// since the user can set a preference to turn off
// this tracing.
setMITracingStream(null);
}
}
}
});
processMIOutput(line);
}
}