mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 06:32:10 +02:00
[269927] Allow to save gdb console and gdb traces console
This commit is contained in:
parent
918d81b3f7
commit
fd94bb434b
12 changed files with 290 additions and 10 deletions
Binary file not shown.
After Width: | Height: | Size: 609 B |
|
@ -544,5 +544,17 @@
|
|||
</activityPatternBinding>
|
||||
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.console.consolePageParticipants">
|
||||
<consolePageParticipant
|
||||
class="org.eclipse.cdt.dsf.gdb.internal.ui.console.ConsolePageParticipant"
|
||||
id="org.eclipse.cdt.dsf.gdb.ui.dsfGdbConsolePageParticipant">
|
||||
<enablement>
|
||||
<instanceof
|
||||
value="org.eclipse.ui.console.IOConsole">
|
||||
</instanceof>
|
||||
</enablement>
|
||||
</consolePageParticipant>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems and others.
|
||||
* Copyright (c) 2008, 2010 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
|
||||
|
@ -11,7 +11,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.dsf.gdb.internal.ui;
|
||||
|
||||
import org.eclipse.cdt.dsf.gdb.internal.ui.tracing.TracingConsoleManager;
|
||||
import org.eclipse.cdt.dsf.gdb.internal.ui.console.TracingConsoleManager;
|
||||
import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch;
|
||||
import org.eclipse.cdt.dsf.gdb.launching.LaunchMessages;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Marc-Andre Laperle 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:
|
||||
* Marc-Andre Laperle - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.dsf.gdb.internal.ui.console;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
/**
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ConsoleMessages extends NLS {
|
||||
private static final String BUNDLE_NAME= "org.eclipse.cdt.dsf.gdb.internal.ui.console.ConsoleMessages"; //$NON-NLS-1$
|
||||
|
||||
public static String ConsoleMessages_trace_console_name;
|
||||
public static String ConsoleMessages_trace_console_terminated;
|
||||
|
||||
public static String ConsoleMessages_save_action_tooltip;
|
||||
public static String ConsoleMessages_save_confirm_overwrite_title;
|
||||
public static String ConsoleMessages_save_confirm_overwrite_desc;
|
||||
public static String ConsoleMessages_save_info_io_error_title;
|
||||
public static String ConsoleMessages_save_info_io_error_desc;
|
||||
|
||||
static {
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(BUNDLE_NAME, ConsoleMessages.class);
|
||||
}
|
||||
|
||||
private ConsoleMessages() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
##########################################################################
|
||||
# Copyright (c) 2010 Marc-Andre Laperle 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:
|
||||
# Marc-Andre Laperle - Initial API and implementation
|
||||
##########################################################################
|
||||
|
||||
ConsoleMessages_trace_console_name=gdb traces
|
||||
ConsoleMessages_trace_console_terminated=<terminated>
|
||||
|
||||
ConsoleMessages_save_action_tooltip=Save console content
|
||||
ConsoleMessages_save_confirm_overwrite_title=Confirm overwrite
|
||||
ConsoleMessages_save_confirm_overwrite_desc=File exists, do you want overwrite it?
|
||||
ConsoleMessages_save_info_io_error_title=Error
|
||||
ConsoleMessages_save_info_io_error_desc=Error during save console content. Task failed.
|
|
@ -0,0 +1,72 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Marc-Andre Laperle 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:
|
||||
* Marc-Andre Laperle - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.dsf.gdb.internal.ui.console;
|
||||
|
||||
import org.eclipse.cdt.dsf.gdb.launching.GDBProcess;
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
import org.eclipse.jface.action.Separator;
|
||||
import org.eclipse.ui.console.IConsole;
|
||||
import org.eclipse.ui.console.IConsoleConstants;
|
||||
import org.eclipse.ui.console.IConsolePageParticipant;
|
||||
import org.eclipse.ui.console.TextConsole;
|
||||
import org.eclipse.ui.part.IPageBookViewPage;
|
||||
|
||||
/**
|
||||
* A console page participant for both the gdb tracing console and the gdb CLI console
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ConsolePageParticipant implements IConsolePageParticipant{
|
||||
|
||||
public void init(IPageBookViewPage page, IConsole console) {
|
||||
if(console instanceof TracingConsole || isConsoleGdbCli(console))
|
||||
{
|
||||
TextConsole textConsole = (TextConsole) console;
|
||||
|
||||
// Add the save console action
|
||||
IToolBarManager toolBarManager = page.getSite().getActionBars().getToolBarManager();
|
||||
toolBarManager.appendToGroup(IConsoleConstants.OUTPUT_GROUP, new Separator());
|
||||
ConsoleSaveAction saveConsole = new ConsoleSaveAction(textConsole);
|
||||
toolBarManager.appendToGroup(IConsoleConstants.OUTPUT_GROUP, saveConsole);
|
||||
toolBarManager.appendToGroup(IConsoleConstants.OUTPUT_GROUP, new Separator());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the the console is the gdb CLI. We don't rely on the attached
|
||||
* process name. Instead we check if the process is an instance of GDBProcess
|
||||
*
|
||||
* @param console The console to check
|
||||
* @return true if the the console is the gdb CLI
|
||||
*/
|
||||
private boolean isConsoleGdbCli(IConsole console) {
|
||||
if(console instanceof org.eclipse.debug.ui.console.IConsole) {
|
||||
org.eclipse.debug.ui.console.IConsole debugConsole = (org.eclipse.debug.ui.console.IConsole)console;
|
||||
return (debugConsole.getProcess() instanceof GDBProcess);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Object getAdapter(Class adapter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
public void activated() {
|
||||
}
|
||||
|
||||
public void deactivated() {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Marc-Andre Laperle 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:
|
||||
* Marc-Andre Laperle - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.dsf.gdb.internal.ui.console;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.BusyIndicator;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.FileDialog;
|
||||
import org.eclipse.ui.console.TextConsole;
|
||||
|
||||
/**
|
||||
* An action to save the gdb traces. Inspired by MiConsoleSaveAction
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ConsoleSaveAction extends Action{
|
||||
private TextConsole fConsole;
|
||||
|
||||
public ConsoleSaveAction(TextConsole console) {
|
||||
super();
|
||||
setToolTipText( ConsoleMessages.ConsoleMessages_save_action_tooltip);
|
||||
setImageDescriptor(GdbUIPlugin.imageDescriptorFromPlugin(GdbUIPlugin.PLUGIN_ID,IConsoleImagesConst.IMG_SAVE_CONSOLE));
|
||||
fConsole = console;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
FileDialog fileDialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
|
||||
final String fileName = fileDialog.open();
|
||||
if(fileName==null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Runnable saveJob = new Runnable() {
|
||||
public void run() {
|
||||
saveContent(fileName);
|
||||
}
|
||||
};
|
||||
BusyIndicator.showWhile(Display.getCurrent(), saveJob);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the content from the tracing console to a file
|
||||
*
|
||||
* @param fileName The fileName of the File to save to
|
||||
*/
|
||||
protected void saveContent(String fileName) {
|
||||
try {
|
||||
boolean confirmed = true;
|
||||
|
||||
File file = new File(fileName);
|
||||
if(file.exists()) {
|
||||
confirmed = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(),
|
||||
ConsoleMessages.ConsoleMessages_save_confirm_overwrite_title,
|
||||
ConsoleMessages.ConsoleMessages_save_confirm_overwrite_desc);
|
||||
}
|
||||
if(confirmed) {
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(fileName));
|
||||
out.write(fConsole.getDocument().get());
|
||||
out.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
MessageDialog.openError(Display.getCurrent().getActiveShell(),
|
||||
ConsoleMessages.ConsoleMessages_save_info_io_error_title,
|
||||
ConsoleMessages.ConsoleMessages_save_info_io_error_desc);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Marc-Andre Laperle 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:
|
||||
* Marc-Andre Laperle - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.dsf.gdb.internal.ui.console;
|
||||
|
||||
/**
|
||||
* @since 2.1
|
||||
*/
|
||||
public interface IConsoleImagesConst {
|
||||
public static final String IMG_SAVE_CONSOLE = "icons/full/obj16/save_console.gif"; //$NON-NLS-1$
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Ericsson and others.
|
||||
* Copyright (c) 2009, 2010 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
|
||||
|
@ -8,7 +8,7 @@
|
|||
* Contributors:
|
||||
* Ericsson - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.dsf.gdb.internal.ui.tracing;
|
||||
package org.eclipse.cdt.dsf.gdb.internal.ui.console;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
@ -39,6 +39,9 @@ import org.eclipse.ui.console.IOConsole;
|
|||
* Any input to this console is read and discarded, since this console should be
|
||||
* read-only. We don't actually make the console read-only because it is nice
|
||||
* for the user to be able to add delimiters such as empty lines within the traces.
|
||||
*
|
||||
* @since 2.1
|
||||
* This class was moved from package org.eclipse.cdt.dsf.gdb.internal.ui.tracing
|
||||
*/
|
||||
public class TracingConsole extends IOConsole {
|
||||
private ILaunch fLaunch;
|
||||
|
@ -123,7 +126,7 @@ public class TracingConsole extends IOConsole {
|
|||
}
|
||||
|
||||
if (fLaunch.isTerminated()) {
|
||||
return "<terminated> " + label;
|
||||
return ConsoleMessages.ConsoleMessages_trace_console_terminated + label;
|
||||
}
|
||||
|
||||
return label;
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 Ericsson and others.
|
||||
* Copyright (c) 2009, 2010 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
|
||||
|
@ -8,7 +8,7 @@
|
|||
* Contributors:
|
||||
* Ericsson - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.dsf.gdb.internal.ui.tracing;
|
||||
package org.eclipse.cdt.dsf.gdb.internal.ui.console;
|
||||
|
||||
import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
|
||||
import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin;
|
||||
|
@ -26,6 +26,9 @@ import org.eclipse.ui.console.IConsoleManager;
|
|||
/**
|
||||
* A tracing console manager which adds and removes tracing consoles
|
||||
* based on launch events and preference events.
|
||||
*
|
||||
* @since 2.1
|
||||
* This class was moved from package org.eclipse.cdt.dsf.gdb.internal.ui.tracing
|
||||
*/
|
||||
public class TracingConsoleManager implements ILaunchesListener2, IPropertyChangeListener {
|
||||
|
||||
|
@ -117,7 +120,7 @@ public class TracingConsoleManager implements ILaunchesListener2, IPropertyChang
|
|||
if (getConsole(launch) == null) {
|
||||
if (launch.isTerminated() == false) {
|
||||
// Create and new tracing console.
|
||||
TracingConsole console = new TracingConsole(launch, "gdb traces");
|
||||
TracingConsole console = new TracingConsole(launch, ConsoleMessages.ConsoleMessages_trace_console_name);
|
||||
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{console});
|
||||
} // else we don't display a new console for a terminated launch
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Marc-Andre Laperle 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:
|
||||
* Marc-Andre Laperle - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.dsf.gdb.launching;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.debug.core.ILaunch;
|
||||
import org.eclipse.debug.core.model.RuntimeProcess;
|
||||
|
||||
/**
|
||||
* A process for the gdb backend to differentiate it from the inferior
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public class GDBProcess extends RuntimeProcess {
|
||||
|
||||
public GDBProcess(ILaunch launch, Process process, String name,
|
||||
Map<String, String> attributes) {
|
||||
super(launch, process, name, attributes);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2008 Wind River Systems and others.
|
||||
* Copyright (c) 2006, 2010 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
|
||||
|
@ -178,7 +178,8 @@ public class GdbLaunch extends DsfLaunch
|
|||
}
|
||||
}).get();
|
||||
|
||||
DebugPlugin.newProcess(this, cliProc, label);
|
||||
GDBProcess gdbProcess = new GDBProcess(this, cliProc, label, null);
|
||||
addProcess(gdbProcess);
|
||||
} catch (InterruptedException e) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, 0, "Interrupted while waiting for get process callable.", e)); //$NON-NLS-1$
|
||||
} catch (ExecutionException e) {
|
||||
|
|
Loading…
Add table
Reference in a new issue