1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 08:46:02 +02:00

Add tracing capability

Signed-off-by: Greg Watson <g.watson@computer.org>
This commit is contained in:
Greg Watson 2013-10-10 10:09:44 -04:00
parent 1e44f7d4de
commit b1285fd555
7 changed files with 114 additions and 2 deletions

View file

@ -1 +1,2 @@
org.eclipse.remote.core/debug=false
org.eclipse.remote.core/debug/commands=false

View file

@ -12,7 +12,7 @@ Require-Bundle: org.eclipse.core.runtime,
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.remote.core,
org.eclipse.remote.core.exception,
org.eclipse.remote.internal.core;x-friends:="org.eclipse.remote.ui",
org.eclipse.remote.internal.core;x-friends:="org.eclipse.remote.ui,org.eclipse.remote.jsch.core",
org.eclipse.remote.internal.core.messages;x-internal:=true,
org.eclipse.remote.internal.core.preferences;x-friends:="org.eclipse.remote.ui",
org.eclipse.remote.internal.core.services.local;x-internal:=true

View file

@ -93,6 +93,7 @@ public class RemoteCorePlugin extends Plugin {
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
new RemoteDebugOptions(context);
ResourcesPlugin.getWorkspace().addSaveParticipant(getUniqueIdentifier(), new ISaveParticipant() {
@Override
public void saving(ISaveContext saveContext) throws CoreException {

View file

@ -0,0 +1,94 @@
/*******************************************************************************
* 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
* Greg Watson (IBM) - adapted for remote core
*******************************************************************************/
package org.eclipse.remote.internal.core;
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
* RemoteDebugOptions 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
*/
public class RemoteDebugOptions implements DebugOptionsListener {
private static final String DEBUG_FLAG = RemoteCorePlugin.getUniqueIdentifier() + "/debug"; //$NON-NLS-1$
private static final String DEBUG_REMOTE_COMMANDS_FLAG = RemoteCorePlugin.getUniqueIdentifier() + "/debug/commands"; //$NON-NLS-1$
public static boolean DEBUG = false;
public static boolean DEBUG_REMOTE_COMMANDS = false;
/**
* The {@link DebugTrace} object to print to OSGi tracing
*/
private static DebugTrace fDebugTrace;
/**
* Constructor
*/
public RemoteDebugOptions(BundleContext context) {
Hashtable<String, String> props = new Hashtable<String, String>(2);
props.put(DebugOptions.LISTENER_SYMBOLICNAME, RemoteCorePlugin.getUniqueIdentifier());
context.registerService(DebugOptionsListener.class.getName(), this, props);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.osgi.service.debug.DebugOptionsListener#optionsChanged(org.eclipse.osgi.service.debug.DebugOptions)
*/
@Override
public void optionsChanged(DebugOptions options) {
fDebugTrace = options.newDebugTrace(RemoteCorePlugin.getUniqueIdentifier());
DEBUG = options.getBooleanOption(DEBUG_FLAG, false);
DEBUG_REMOTE_COMMANDS = DEBUG & options.getBooleanOption(DEBUG_REMOTE_COMMANDS_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) {
System.out.print(message);
// then pass the original message to be traced into a file
if (fDebugTrace != null) {
fDebugTrace.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

@ -27,6 +27,7 @@ import org.eclipse.remote.core.AbstractRemoteProcessBuilder;
import org.eclipse.remote.core.IRemoteFileManager;
import org.eclipse.remote.core.IRemoteProcess;
import org.eclipse.remote.core.exception.RemoteConnectionException;
import org.eclipse.remote.internal.core.RemoteDebugOptions;
import org.eclipse.remote.internal.jsch.core.messages.Messages;
import com.jcraft.jsch.ChannelExec;
@ -181,6 +182,9 @@ public class JSchProcessBuilder extends AbstractRemoteProcessBuilder {
exec.setPty((flags & ALLOCATE_PTY) == ALLOCATE_PTY);
exec.setXForwarding((flags & FORWARD_X11) == FORWARD_X11);
exec.connect();
if (RemoteDebugOptions.DEBUG_REMOTE_COMMANDS) {
RemoteDebugOptions.trace("executing command: " + command); //$NON-NLS-1$
}
return new JSchProcess(exec, redirectErrorStream());
} catch (RemoteConnectionException e) {
throw new IOException(e.getMessage());

View file

@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.remote.core,
org.eclipse.core.filesystem,
org.eclipse.core.resources
org.eclipse.core.resources,
org.eclipse.ui.trace
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.remote.internal.ui;x-internal:=true,

View file

@ -27,5 +27,16 @@
name="%ConnectionsPreferencePage.name">
</page>
</extension>
<extension
point="org.eclipse.ui.trace.traceComponents">
<component
id="org.eclipse.remote.ui.component"
label="Remote Core">
<bundle
consumed="true"
name="org.eclipse.remote.core">
</bundle>
</component>
</extension>
</plugin>