1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

[Bug 379169] Would like to log Rx/Tx threads from GDBControl

I have added a Debug Tracing class to internal.gdb. and then I'm calling
that class as messages pass out of Eclipse to GDB and then when
responses come back from GDB. This class can be used to add debug
tracing to other classes, but I'm not sure right now what people want to
be able to log. I have amended the two affected classes to include
copyright updates. I have also added the UI components to plugin.xml
In addition, I have altered GdbCommandTimeoutManager to use the new
tracing format so we can trace timeouts in the same way. Includes
JavaDoc on the new file.


Change-Id: Icf2af2aaa99dec010db77faf081eb2b8954b3b2a
Reviewed-on: https://git.eclipse.org/r/5972
IP-Clean: Marc Khouzam <marc.khouzam@ericsson.com>
Tested-by: Marc Khouzam <marc.khouzam@ericsson.com>
Reviewed-by: Marc Khouzam <marc.khouzam@ericsson.com>
This commit is contained in:
Jason 2012-06-01 13:26:05 -06:00 committed by Marc Khouzam
parent cd368cbf94
commit ea9adbf5e0
6 changed files with 150 additions and 36 deletions

View file

@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2006, 2009 Wind River Systems and others.
# Copyright (c) 2006, 2012 Wind River Systems 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
@ -8,6 +8,7 @@
# Contributors:
# Wind River Systems - initial API and implementation
# IBM Corporation
# Jason Litton (Sage Electronic Engineering, LLC) - Added label for dynamic tracing (Bug 379169)
###############################################################################
pluginName=GDB DSF Debugger Integration Core
providerName=Eclipse CDT
@ -20,3 +21,4 @@ launchDelegate.attach.name=GDB (DSF) Attach to Process
launchDelegate.attach.description=Attach the GDB debugger, integrated using the Debugger Services Framework (DSF), to a running program locally or remotely.
launchDelegate.postmortem.name=GDB (DSF) Postmortem Debugger
launchDelegate.postmortem.description=Load an application dump using the GDB debugger integrated using the Debugger Services Framework (DSF).
cdt.dsf.gdb.component.label = CDT GDB Core

View file

@ -74,4 +74,15 @@
id="org.eclipse.cdt.dsf.gdb.GdbProcessFactory">
</processFactory>
</extension>
<extension
point = "org.eclipse.ui.trace.traceComponents">
<component
id="org.eclipse.cdt.dsf.gdb.component"
label="%cdt.dsf.gdb.component.label">
<bundle
consumed="true"
name="org.eclipse.cdt.dsf.gdb">
</bundle>
</component>
</extension>
</plugin>

View file

@ -0,0 +1,95 @@
/*******************************************************************************
* Copyright (c) 2012 Sage Electronic Engineering, LLC. 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:
* Jason Litton (Sage Electronic Engineering, LLC) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.internal;
import java.util.Hashtable;
import org.eclipse.osgi.service.debug.DebugOptions;
import org.eclipse.osgi.service.debug.DebugOptionsListener;
import org.eclipse.osgi.service.debug.DebugTrace;
import org.osgi.framework.BundleContext;
/**
* Hooks our debug options to the Platform trace functonality.
* In essence, we can open Window -> Preferences -> Tracing
* and turn on debug options for this package. The debug output
* will come out on the console and can be saved directly to
* a file. Classes that need to be debugged can call into
* GdbDebugOptions to get debug flags. If new flags need to be
* created, they will need to have a unique identifier and added to
* the .options file in this plugin
*
* @since 4.1
*
*/
public class GdbDebugOptions implements DebugOptionsListener {
private static final String DEBUG_FLAG = "org.eclipse.cdt.dsf.gdb/debug"; //$NON-NLS-1$
private static final String DEBUG_TIMEOUTS_FLAG = "org.eclipse.cdt.dsf.gdb/debug/timeouts"; //$NON-NLS-1$
public static boolean DEBUG = false;
public static boolean DEBUG_COMMAND_TIMEOUTS = false;
/**
* The {@link DebugTrace} object to print to OSGi tracing
*/
private static DebugTrace fgDebugTrace;
/**
* Constructor
*/
public GdbDebugOptions(BundleContext context) {
Hashtable<String, String> props = new Hashtable<String, String>(2);
props.put(org.eclipse.osgi.service.debug.DebugOptions.LISTENER_SYMBOLICNAME, GdbPlugin.getUniqueIdentifier());
context.registerService(DebugOptionsListener.class.getName(), this, props);
}
@Override
public void optionsChanged(DebugOptions options) {
fgDebugTrace = options.newDebugTrace(GdbPlugin.getUniqueIdentifier());
DEBUG = options.getBooleanOption(DEBUG_FLAG, false);
DEBUG_COMMAND_TIMEOUTS = options.getBooleanOption(DEBUG_TIMEOUTS_FLAG, false);
}
/**
* Prints the given message to System.out and to the OSGi tracing (if started)
* @param option the option or <code>null</code>
* @param message the message to print or <code>null</code>
* @param throwable the {@link Throwable} or <code>null</code>
*/
public static void trace(String option, String message, Throwable throwable) {
//divide the string into substrings of 100 chars or less for printing
//to console
String systemPrintableMessage = message;
while (systemPrintableMessage.length() > 100) {
String partial = systemPrintableMessage.substring(0, 100);
systemPrintableMessage = systemPrintableMessage.substring(100);
System.out.println(partial + "\\"); //$NON-NLS-1$
}
System.out.print(systemPrintableMessage);
//then pass the original message to be traced into a file
if(fgDebugTrace != null) {
fgDebugTrace.trace(option, message, throwable);
}
}
/**
* Prints the given message to System.out and to the OSGi tracing (if enabled)
*
* @param message the message or <code>null</code>
*/
public static void trace(String message) {
trace(null, message, null);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2009 Wind River Systems and others.
* Copyright (c) 2006, 2012 Wind River Systems 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
@ -8,6 +8,7 @@
* Contributors:
* Wind River Systems - initial API and implementation
* Abeer Bagul (Tensilica) - Updated error message (Bug 339048)
* Jason Litton (Sage Electronic Engineering, LLC) - Added support for dynamic tracing option (Bug 379169)
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.internal;
@ -18,7 +19,6 @@ import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.Query;
import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin;
@ -30,16 +30,13 @@ import org.osgi.framework.BundleContext;
*/
public class GdbPlugin extends Plugin {
// Debugging flag
public static boolean DEBUG = false;
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.cdt.dsf.gdb"; //$NON-NLS-1$
// The shared instance
private static GdbPlugin plugin;
private static BundleContext fgBundleContext;
private static BundleContext fgBundleContext;
/**
* The constructor
@ -57,7 +54,7 @@ public class GdbPlugin extends Plugin {
super.start(context);
plugin = this;
DEBUG = "true".equals(Platform.getDebugOption("org.eclipse.cdt.dsf.gdb/debug")); //$NON-NLS-1$//$NON-NLS-2$
new GdbDebugOptions(context);
}
/*
@ -131,17 +128,6 @@ public class GdbPlugin extends Plugin {
}
}
public static void debug(String message) {
if (DEBUG) {
while (message.length() > 100) {
String partial = message.substring(0, 100);
message = message.substring(100);
System.out.println(partial + "\\"); //$NON-NLS-1$
}
System.out.print(message);
}
}
public static String getDebugTime() {
StringBuilder traceBuilder = new StringBuilder();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Mentor Graphics and others.
* Copyright (c) 2011, 2012 Mentor Graphics 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
@ -7,6 +7,7 @@
*
* Contributors:
* Mentor Graphics - Initial API and implementation
* Jason Litton (Sage Electronic Engineering, LLC) - Use Dynamic Tracing option (Bug 379169)
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.service.command;
@ -20,6 +21,7 @@ import org.eclipse.cdt.dsf.debug.service.command.ICommandListener;
import org.eclipse.cdt.dsf.debug.service.command.ICommandResult;
import org.eclipse.cdt.dsf.debug.service.command.ICommandToken;
import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
import org.eclipse.cdt.dsf.gdb.internal.GdbDebugOptions;
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
import org.eclipse.cdt.dsf.mi.service.command.AbstractMIControl;
import org.eclipse.cdt.dsf.mi.service.command.commands.MICommand;
@ -50,7 +52,11 @@ public class GdbCommandTimeoutManager implements ICommandListener, IPreferenceCh
void commandTimedOut( ICommandToken token );
}
/**
* @deprecated The DEBUG flag is replaced with the GdbDebugOptions.DEBUG_COMMAND_TIMEOUTS
*/
@Deprecated
public final static boolean DEBUG = "true".equals( Platform.getDebugOption( "org.eclipse.cdt.dsf.gdb/debug/timeouts" ) ); //$NON-NLS-1$//$NON-NLS-2$
private class QueueEntry {
@ -141,12 +147,14 @@ public class GdbCommandTimeoutManager implements ICommandListener, IPreferenceCh
// expires.
long commandTimeout = getTimeoutForCommand( entry.fCommandToken.getCommand() );
if ( DEBUG ) {
if ( GdbDebugOptions.DEBUG_COMMAND_TIMEOUTS ) {
String commandText = entry.fCommandToken.getCommand().toString();
if ( commandText.endsWith( "\n" ) ) //$NON-NLS-1$
commandText = commandText.substring( 0, commandText.length() - 1 );
printDebugMessage( String.format( "Processing command '%s', command timeout is %d", //$NON-NLS-1$
commandText, Long.valueOf( commandTimeout ) ) );
printDebugMessage( String.format( "Processing command '%s', command timeout is %d", //$NON-NLS-1$
commandText, Long.valueOf( commandTimeout ) ) );
}
long currentTime = System.currentTimeMillis();
@ -167,12 +175,14 @@ public class GdbCommandTimeoutManager implements ICommandListener, IPreferenceCh
// Adjust the wait timeout because the time remaining for
// the current command to expire may be less than the current wait timeout.
timeout = Math.min( timeout, commandTimeout - elapsedTime );
if ( DEBUG ) {
if ( GdbDebugOptions.DEBUG_COMMAND_TIMEOUTS ) {
String commandText = entry.fCommandToken.getCommand().toString();
if ( commandText.endsWith( "\n" ) ) //$NON-NLS-1$
commandText = commandText.substring( 0, commandText.length() - 1 );
printDebugMessage( String.format( "Setting timeout %d for command '%s'", Long.valueOf( timeout ), commandText ) ); //$NON-NLS-1$
}
}
}
@ -191,7 +201,7 @@ public class GdbCommandTimeoutManager implements ICommandListener, IPreferenceCh
private synchronized void setWaitTimout( int waitTimeout ) {
fWaitTimeout = waitTimeout;
if ( DEBUG )
if ( GdbDebugOptions.DEBUG_COMMAND_TIMEOUTS )
printDebugMessage( String.format( "Wait timeout is set to %d", Integer.valueOf( fWaitTimeout ) ) ); //$NON-NLS-1$
}
@ -278,7 +288,7 @@ public class GdbCommandTimeoutManager implements ICommandListener, IPreferenceCh
if ( !isTimeoutEnabled() )
return;
int commandTimeout = getTimeoutForCommand( token.getCommand() );
if ( DEBUG ) {
if ( GdbDebugOptions.DEBUG_COMMAND_TIMEOUTS ) {
String commandText = token.getCommand().toString();
if ( commandText.endsWith( "\n" ) ) //$NON-NLS-1$
commandText = commandText.substring( 0, commandText.length() - 1 );
@ -310,7 +320,7 @@ public class GdbCommandTimeoutManager implements ICommandListener, IPreferenceCh
if ( !isTimeoutEnabled() )
return;
fCommandQueue.remove( new QueueEntry( 0, token ) );
if ( DEBUG ) {
if ( GdbDebugOptions.DEBUG_COMMAND_TIMEOUTS ) {
String commandText = token.getCommand().toString();
if ( commandText.endsWith( "\n" ) ) //$NON-NLS-1$
commandText = commandText.substring( 0, commandText.length() - 1 );
@ -379,7 +389,7 @@ public class GdbCommandTimeoutManager implements ICommandListener, IPreferenceCh
}
protected void processTimedOutCommand( ICommandToken token ) {
if ( DEBUG ) {
if ( GdbDebugOptions.DEBUG_COMMAND_TIMEOUTS ) {
String commandText = token.getCommand().toString();
if ( commandText.endsWith( "\n" ) ) //$NON-NLS-1$
commandText = commandText.substring( 0, commandText.length() - 1 );
@ -407,7 +417,10 @@ public class GdbCommandTimeoutManager implements ICommandListener, IPreferenceCh
}
private void printDebugMessage( String message ) {
System.out.println( String.format( "%s %s %s", GdbPlugin.getDebugTime(), TIMEOUT_TRACE_IDENTIFIER, message ) ); //$NON-NLS-1$
if(GdbDebugOptions.DEBUG_COMMAND_TIMEOUTS) {
GdbDebugOptions.trace(String.format( "%s %s %s\n", GdbPlugin.getDebugTime(), TIMEOUT_TRACE_IDENTIFIER, message)); //$NON-NLS-1$
}
}
private int calculateWaitTimeout() {
@ -432,7 +445,7 @@ public class GdbCommandTimeoutManager implements ICommandListener, IPreferenceCh
if ( nextEntry != null ) {
nextEntry.fTimestamp = currentTime;
if ( DEBUG ) {
if ( GdbDebugOptions.DEBUG_COMMAND_TIMEOUTS ) {
String commandText = nextEntry.fCommandToken.getCommand().toString();
if ( commandText.endsWith( "\n" ) ) //$NON-NLS-1$
commandText = commandText.substring( 0, commandText.length() - 1 );

View file

@ -11,6 +11,7 @@
* Nokia - create and use backend service.
* Onur Akdemir (TUBITAK BILGEM-ITI) - Multi-process debugging (Bug 237306)
* Marc Khouzam (Ericsson) - New method to properly created ErrorThread (Bug 350837)
* Jason Litton (Sage Electronic Engineering, LLC) - Use Dynamic Tracing option (Bug 379169)
*******************************************************************************/
package org.eclipse.cdt.dsf.mi.service.command;
@ -42,6 +43,7 @@ import org.eclipse.cdt.dsf.debug.service.command.ICommandListener;
import org.eclipse.cdt.dsf.debug.service.command.ICommandResult;
import org.eclipse.cdt.dsf.debug.service.command.ICommandToken;
import org.eclipse.cdt.dsf.debug.service.command.IEventListener;
import org.eclipse.cdt.dsf.gdb.internal.GdbDebugOptions;
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
import org.eclipse.cdt.dsf.mi.service.IMICommandControl;
import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext;
@ -74,7 +76,7 @@ import com.ibm.icu.text.MessageFormat;
public abstract class AbstractMIControl extends AbstractDsfService
implements IMICommandControl
{
private static final String MI_TRACE_IDENTIFIER = " [MI] "; //$NON-NLS-1$
private static final String MI_TRACE_IDENTIFIER = "[MI]"; //$NON-NLS-1$
/*
* Thread control variables for the transmit and receive threads.
@ -661,8 +663,10 @@ public abstract class AbstractMIControl extends AbstractDsfService
if (fOutputStream != null) {
fOutputStream.write(str.getBytes());
fOutputStream.flush();
GdbPlugin.debug(GdbPlugin.getDebugTime() + MI_TRACE_IDENTIFIER + str);
if (GdbDebugOptions.DEBUG) {
GdbDebugOptions.trace(String.format( "%s %s %s", GdbPlugin.getDebugTime(), MI_TRACE_IDENTIFIER, str)); //$NON-NLS-1$
}
if (getMITracingStream() != null) {
try {
String message = GdbPlugin.getDebugTime() + " " + str; //$NON-NLS-1$
@ -724,7 +728,10 @@ public abstract class AbstractMIControl extends AbstractDsfService
String line;
while ((line = reader.readLine()) != null) {
if (line.length() != 0) {
GdbPlugin.debug(GdbPlugin.getDebugTime() + MI_TRACE_IDENTIFIER + line + "\n"); //$NON-NLS-1$
//Write Gdb response to sysout or file
if(GdbDebugOptions.DEBUG) {
GdbDebugOptions.trace(String.format( "%s %s %s\n", GdbPlugin.getDebugTime(), MI_TRACE_IDENTIFIER, line)); //$NON-NLS-1$
}
final String finalLine = line;
if (getMITracingStream() != null) {