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

New launch configuration for GDBServer, code

from Monta Vista
This commit is contained in:
Alain Magloire 2003-04-06 01:07:23 +00:00
parent b0f43f73ce
commit 54c9ad41e7
7 changed files with 436 additions and 8 deletions

View file

@ -2,4 +2,5 @@ pluginName=C/C++ Development Tools GDB/MI CDI Debugger Core
providerName=Eclipse.org
GDBDebugger.name=GDB Debugger
CygwinGDBDebugger.name=Cygwin GDB Debugger
CygwinGDBDebugger.name=Cygwin GDB Debugger
GDBServer.name=GDB Server

View file

@ -37,6 +37,14 @@
class="org.eclipse.cdt.debug.mi.core.CygwinGDBDebugger"
id="org.eclipse.cdt.debug.mi.core.CygwinCDebugger">
</debugger>
<debugger
platform="native"
name="%GDBServer.name"
modes="run"
cpu="native"
class="org.eclipse.cdt.debug.mi.core.GDBServerDebugger"
id="org.eclipse.cdt.debug.mi.core.GDBServerCDebugger">
</debugger>
</extension>
</plugin>

View file

@ -0,0 +1,82 @@
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation 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:
* Monta Vista - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.mi.core;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.debug.core.ICDebugger;
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.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.ILaunchConfiguration;
public class GDBServerDebugger implements ICDebugger {
void initializeLibraries(ILaunchConfiguration config, Session session) throws CDIException {
try {
ICDISharedLibraryManager mgr = session.getSharedLibraryManager();
if (mgr instanceof SharedLibraryManager) {
boolean autolib = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_AUTO_SOLIB, false);
((SharedLibraryManager)mgr).setAutoLoadSymbols(autolib);
}
List p = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_SOLIB_PATH, new ArrayList(1));
if (p.size() > 0) {
String[] paths = (String[])p.toArray(new String[0]);
mgr.setSharedLibraryPaths(paths);
}
} catch (CoreException e) {
throw new CDIException("Error initializing: " + e.getMessage());
}
}
public ICDISession createLaunchSession(ILaunchConfiguration config, IFile exe) throws CDIException {
try {
String gdb = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb");
File cwd = exe.getProject().getLocation().toFile();
String remote;
if (config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, false)) {
remote = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_HOST, "invalid");
remote += ":";
remote += config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, "invalid");
} else {
remote = config.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV, "invalid");
}
String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit");
String[] args = new String[] {"remote", remote};
Session session = (Session)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), 0, args, cwd, gdbinit);
initializeLibraries(config, session);
return session;
} catch (IOException e) {
throw new CDIException("Error initializing: " + e.getMessage());
} catch (MIException e) {
throw new CDIException("Error initializing: " + e.getMessage());
} catch (CoreException e) {
throw new CDIException("Error initializing: " + e.getMessage());
}
}
public ICDISession createAttachSession(ILaunchConfiguration config, IFile exe, int pid) throws CDIException {
throw new CDIException("GDBServer does not support attaching");
}
public ICDISession createCoreSession(ILaunchConfiguration config, IFile exe, IPath corefile) throws CDIException {
throw new CDIException("GDBServer does not support core files");
}
}

View file

@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation 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:
* Monta Vista - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.mi.core;
public interface IGDBServerMILaunchConfigurationConstants extends IMILaunchConfigurationConstants {
/**
* Launch configuration attribute key. The "remote target xxx" value.
*/
public static final String ATTR_REMOTE_TCP = MIPlugin.getUniqueIdentifier() + ".REMOTE_TCP"; //$NON-NLS-1$
public static final String ATTR_HOST = MIPlugin.getUniqueIdentifier() + ".HOST"; //$NON-NLS-1$
public static final String ATTR_PORT = MIPlugin.getUniqueIdentifier() + ".PORT"; //$NON-NLS-1$
public static final String ATTR_DEV = MIPlugin.getUniqueIdentifier() + ".DEV"; //$NON-NLS-1$
}

View file

@ -199,21 +199,22 @@ public class MIPlugin extends Plugin {
}
Process pgdb = ProcessFactory.getFactory().exec(args);
MISession session = createMISession(pgdb, null, MISession.ATTACH);
MIInfo info = null;
CommandFactory factory = session.getCommandFactory();
if (targetParams != null && targetParams.length > 0) {
MITargetSelect target = factory.createMITargetSelect(targetParams);
session.postCommand(target);
info = target.getMIInfo();
MIInfo info = target.getMIInfo();
if (info == null) {
throw new MIException("No answer");
}
}
MITargetAttach attach = factory.createMITargetAttach(pid);
session.postCommand(attach);
info = attach.getMIInfo();
if (info == null) {
throw new MIException("No answer");
if (pid > 0) {
MITargetAttach attach = factory.createMITargetAttach(pid);
session.postCommand(attach);
MIInfo info = attach.getMIInfo();
if (info == null) {
throw new MIException("No answer");
}
}
//@@@ We have to manually set the suspended state when we attach
session.getMIInferior().setSuspended();

View file

@ -36,6 +36,11 @@
id="org.eclipse.cdt.debug.mi.CygwinDebuggerPage"
debuggerID="org.eclipse.cdt.debug.mi.core.CygwinCDebugger">
</debugPage>
<debuggerPage
class="org.eclipse.cdt.debug.mi.internal.ui.GDBServerDebuggerPage"
id="org.eclipse.cdt.debug.mi.GDBServerDebuggerPage"
debuggerID="org.eclipse.cdt.debug.mi.core.GDBServerCDebugger">
</debuggerPage>
</extension>
<extension
point="org.eclipse.ui.preferencePages">

View file

@ -0,0 +1,307 @@
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation 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:
* Monta Vista - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.mi.internal.ui;
import org.eclipse.cdt.debug.mi.core.IGDBServerMILaunchConfigurationConstants;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
public class GDBServerDebuggerPage extends AbstractLaunchConfigurationTab {
protected Text fDebuggerCommandText;
protected Button fTCPButton;
protected Button fAsyncButton;
protected Text fHostText;
protected Text fHostPort;
protected Text fAsyncDev;
private Button fAutoSoLibButton;
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
GridLayout topLayout = new GridLayout();
topLayout.numColumns = 2;
comp.setLayout(topLayout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
comp.setLayoutData(gd);
setControl(comp);
createVerticalSpacer(comp, 2);
Label debugCommandLabel= new Label(comp, SWT.NONE);
debugCommandLabel.setText("GDBServer gdb executable:");
fDebuggerCommandText= new Text(comp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
fDebuggerCommandText.setLayoutData(gd);
fDebuggerCommandText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent evt) {
updateLaunchConfigurationDialog();
}
});
Composite radioComp = new Composite(comp, SWT.NONE);
GridLayout radioLayout = new GridLayout(2, true);
radioLayout.marginHeight = 0;
radioLayout.marginWidth = 0;
radioComp.setLayout(radioLayout);
gd = new GridData();
gd.horizontalSpan = 2;
radioComp.setLayoutData(gd);
fTCPButton = createRadioButton(radioComp, "Connect using TCP");
fTCPButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
boolean isTcp = fTCPButton.getSelection();
fHostPort.setEnabled(isTcp);
fHostText.setEnabled(isTcp);
updateLaunchConfigurationDialog();
}
});
fAsyncButton = createRadioButton(radioComp, "Connect using a serial port");
fAsyncButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
fAsyncDev.setEnabled(fAsyncButton.getSelection());
updateLaunchConfigurationDialog();
}
});
Label hostTextLabel= new Label(comp, SWT.NONE);
hostTextLabel.setText("GDBServer TCP host:");
fHostText= new Text(comp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
fHostText.setLayoutData(gd);
fHostText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent evt) {
updateLaunchConfigurationDialog();
}
});
Label hostPortLabel= new Label(comp, SWT.NONE);
hostPortLabel.setText("GDBServer TCP port:");
fHostPort= new Text(comp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
fHostPort.setLayoutData(gd);
fHostPort.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent evt) {
updateLaunchConfigurationDialog();
}
});
Label asyncDevLabel= new Label(comp, SWT.NONE);
asyncDevLabel.setText("Serial device:");
fAsyncDev= new Text(comp, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
fAsyncDev.setLayoutData(gd);
fAsyncDev.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent evt) {
updateLaunchConfigurationDialog();
}
});
fTCPButton.setSelection(true);
fAsyncButton.setSelection(false);
fHostText.setEnabled(true);
fHostPort.setEnabled(true);
fAsyncDev.setEnabled(false);
fHostPort.setEnabled(true);
fHostText.setEnabled(true);
fAsyncDev.setEnabled(false);
createVerticalSpacer(comp, 2);
fAutoSoLibButton = new Button(comp, SWT.CHECK ) ;
fAutoSoLibButton.setText("Load shared library symbols automatically");
gd = new GridData();
gd.horizontalSpan = 2;
fAutoSoLibButton.setLayoutData(gd);
/*
ListEditor listEditor = new ListEditor("1", "Shared library search paths:", comp) {
protected String createList(String[] items) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < items.length; i++) {
buf.append(items[i]);
buf.append(';');
}
return buf.toString();
}
protected String getNewInputObject() {
// StringInputDialog dialog= new StringInputDialog(comp.getShell(), "Library Path", null, "Enter a library path", "", null);
// if (dialog.open() == dialog.OK) {
// return dialog.getValue();
// } else {
// return null;
// }
return null;
}
protected String[] parseString(String list) {
StringTokenizer st = new StringTokenizer(list, ";");
ArrayList v = new ArrayList();
while (st.hasMoreElements()) {
v.add(st.nextElement());
}
return (String[]) v.toArray(new String[v.size()]);
}
};
*/
}
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
String attr;
attr = null;
try {
attr = configuration.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEBUG_NAME, (String) null);
} catch (CoreException e) {
}
if (attr == null) {
configuration.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb");
}
/* The booleans should already be correct. */
attr = null;
try {
attr = configuration.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_HOST, (String) null);
} catch (CoreException e) {
}
if (attr == null) {
configuration.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_HOST, "");
}
attr = null;
try {
attr = configuration.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, (String) null);
} catch (CoreException e) {
}
if (attr == null) {
configuration.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, "");
}
attr = null;
try {
attr = configuration.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV, (String) null);
} catch (CoreException e) {
}
if (attr == null) {
configuration.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV, "/dev/ttyS0");
}
}
/**
* @see ILaunchConfigurationTab#isValid(ILaunchConfiguration)
*/
public boolean isValid(ILaunchConfiguration launchConfig) {
boolean valid;
valid= fDebuggerCommandText.getText().length() != 0;
setErrorMessage(null);
setMessage(null);
if (!valid) {
setErrorMessage("Debugger executable must be specified");
setMessage(null);
}
if (valid) {
if (fTCPButton.getSelection()) {
valid = ((fHostText.getText().length() != 0)
&& (fHostPort.getText().length() != 0));
if (!valid) {
setErrorMessage("If TCP is selected, host and port must be specified");
setMessage(null);
}
} else {
valid = fAsyncDev.getText().length() != 0;
if (!valid) {
setErrorMessage("If Async is selected, device must be specified");
setMessage(null);
}
}
}
return valid;
}
public void initializeFrom(ILaunchConfiguration configuration) {
String debuggerCommand = "gdb";
boolean isTcp = false;
String hostText = "";
String hostPort = "";
String asyncDev = "/dev/ttyS0";
boolean autosolib = false;
try {
debuggerCommand = configuration.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb");
autosolib = configuration.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_AUTO_SOLIB, false);
} catch (CoreException e) {
}
try {
isTcp = configuration.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, false);
hostText = configuration.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_HOST, "");
hostPort = configuration.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, "");
asyncDev = configuration.getAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV, "");
} catch (CoreException e) {
}
fDebuggerCommandText.setText(debuggerCommand);
fTCPButton.setSelection(isTcp);
fAsyncButton.setSelection(!isTcp);
fHostText.setText(hostText);
fHostPort.setText(hostPort);
fAsyncDev.setText(asyncDev);
fHostText.setEnabled(isTcp);
fHostPort.setEnabled(isTcp);
fAsyncDev.setEnabled(!isTcp);
fAutoSoLibButton.setSelection(autosolib);
}
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
String debuggerCommand = fDebuggerCommandText.getText();
String hostText = fHostText.getText();
String hostPort = fHostPort.getText();
String asyncDev = fAsyncDev.getText();
debuggerCommand.trim();
hostText.trim();
hostPort.trim();
asyncDev.trim();
configuration.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEBUG_NAME, debuggerCommand);
configuration.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_AUTO_SOLIB, fAutoSoLibButton.getSelection());
configuration.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_REMOTE_TCP, fTCPButton.getSelection());
configuration.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_HOST, hostText);
configuration.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_PORT, hostPort);
configuration.setAttribute(IGDBServerMILaunchConfigurationConstants.ATTR_DEV, asyncDev);
}
public String getName() {
return "GDBServer Debugger Options";
}
/**
* @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#updateLaunchConfigurationDialog()
*/
protected void updateLaunchConfigurationDialog() {
super.updateLaunchConfigurationDialog();
}
}