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

Implement solib-search-path.

This commit is contained in:
Alain Magloire 2002-09-24 19:08:42 +00:00
parent 3c63ff5d56
commit cba9b18bf5
9 changed files with 267 additions and 40 deletions

View file

@ -5,36 +5,65 @@
package org.eclipse.cdt.debug.mi.core;
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.mi.core.cdi.CSession;
import org.eclipse.cdt.debug.mi.core.cdi.SourceManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.debug.core.ILaunchConfiguration;
import sun.security.krb5.internal.crypto.e;
public class GDBDebugger implements ICDebugger {
public ICDISession createLaunchSession(ILaunchConfiguration config, IFile exe) throws CDIException {
void initializeLibraries(ILaunchConfiguration config, CSession session) throws CDIException {
try {
return MIPlugin.getDefault().createCSession(exe.getLocation().toOSString());
SourceManager mgr = (SourceManager)session.getSourceManager();
boolean autolib = config.getAttribute(IMILaunchConfigurationConstants.ATTR_AUTO_SOLIB, false);
if (autolib) {
mgr.setAutoSolib();
}
catch (IOException e) {
List p = config.getAttribute(IMILaunchConfigurationConstants.ATTR_SOLIB_PATH, new ArrayList(1));
if (p.size() > 0) {
String[] paths = (String[])p.toArray(new String[0]);
mgr.setLibraryPaths(paths);
}
} catch (CoreException e) {
throw new CDIException("Error initializing: " + e.getMessage());
}
catch (MIException e) {
}
public ICDISession createLaunchSession(ILaunchConfiguration config, IFile exe) throws CDIException {
try {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb");
CSession session = (CSession)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toOSString());
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 {
try {
return MIPlugin.getDefault().createCSession(exe.getLocation().toOSString(), pid);
}
catch (IOException e) {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb");
CSession session = (CSession)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toOSString(), pid);
initializeLibraries(config, session);
return session;
} catch (IOException e) {
throw new CDIException("Error initializing: " + e.getMessage());
}
catch (MIException e) {
} catch (MIException e) {
throw new CDIException("Error initializing: " + e.getMessage());
} catch (CoreException e) {
throw new CDIException("Error initializing: " + e.getMessage());
}
@ -42,15 +71,17 @@ public class GDBDebugger implements ICDebugger {
public ICDISession createCoreSession(ILaunchConfiguration config, IFile exe, IPath corefile) throws CDIException {
try {
return MIPlugin.getDefault().createCSession(exe.getLocation().toOSString(), corefile.toOSString());
}
catch (IOException e) {
String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb");
CSession session = (CSession)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toOSString(), corefile.toOSString());
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());
}
catch (MIException e) {
throw new CDIException("Error initializing: " + e.getMessage());
}
}
}

View file

@ -8,12 +8,20 @@ package org.eclipse.cdt.debug.mi.core;
public interface IMILaunchConfigurationConstants {
/**
* Launch configuration attribute key. The value is a name of
* a C/C++ project associated with a C/C++ launch configuration.
* Launch configuration attribute key. The value is the name of
* the Debuger associated with a C/C++ launch configuration.
*/
public static final String ATTR_DEBUG_NAME = MIPlugin.getUniqueIdentifier() + ".DEBUG_NAME"; //$NON-NLS-1$
public static final String ATTR_DEBUG_ARGS = MIPlugin.getUniqueIdentifier() + ".DEBUG_ARGS"; //$NON-NLS-1$
/**
* Launch configuration attribute key. The value is a List (array of String) directories for solib-search-path
* the Debuger associated with a C/C++ launch configuration.
*/
public static final String ATTR_SOLIB_PATH = MIPlugin.getUniqueIdentifier() + ".SOLIB_PATH"; //$NON-NLS-1$
/**
* Launch configuration attribute key. Boolean value to set the auto-solib-add
* Debuger/gdb/MI property.
*/
public static final String ATTR_AUTO_SOLIB = MIPlugin.getUniqueIdentifier() + ".AUTO_SOLIB"; //$NON-NLS-1$
}

View file

@ -65,21 +65,25 @@ public class MIPlugin extends Plugin {
* @return ICDISession
* @throws IOException
*/
public ICDISession createCSession(String program) throws IOException, MIException {
public ICDISession createCSession(String gdb, String program) throws IOException, MIException {
if (gdb == null || gdb.length() == 0) {
gdb = "gdb";
}
String[] args;
PTY pty = null;
try {
pty = new PTY();
String ttyName = pty.getSlaveName();
args = new String[] {"gdb", "-q", "-nw", "-tty", ttyName, "-i", "mi", program};
args = new String[] {gdb, "-q", "-nw", "-tty", ttyName, "-i", "mi", program};
} catch (IOException e) {
//e.printStackTrace();
pty = null;
args = new String[] {"gdb", "-q", "-nw", "-i", "mi", program};
}
Process gdb = ProcessFactory.getFactory().exec(args);
MISession session = createMISession(gdb, pty);
Process pgdb = ProcessFactory.getFactory().exec(args);
MISession session = createMISession(pgdb, pty);
/*
try {
CommandFactory factory = session.getCommandFactory();
@ -103,10 +107,13 @@ public class MIPlugin extends Plugin {
* @return ICDISession
* @throws IOException
*/
public ICDISession createCSession(String program, String core) throws IOException, MIException {
String[] args = new String[] {"gdb", "--quiet", "-nw", "-i", "mi", program, core};
Process gdb = ProcessFactory.getFactory().exec(args);
MISession session = createMISession(gdb);
public ICDISession createCSession(String gdb, String program, String core) throws IOException, MIException {
if (gdb == null || gdb.length() == 0) {
gdb = "gdb";
}
String[] args = new String[] {gdb, "--quiet", "-nw", "-i", "mi", program, core};
Process pgdb = ProcessFactory.getFactory().exec(args);
MISession session = createMISession(pgdb);
return new CSession(session);
}
@ -117,10 +124,13 @@ public class MIPlugin extends Plugin {
* @return ICDISession
* @throws IOException
*/
public ICDISession createCSession(String program, int pid) throws IOException, MIException {
String[] args = new String[] {"gdb", "--quiet", "-nw", "-i", "mi", program};
Process gdb = ProcessFactory.getFactory().exec(args);
MISession session = createMISession(gdb);
public ICDISession createCSession(String gdb, String program, int pid) throws IOException, MIException {
if (gdb == null || gdb.length() == 0) {
gdb = "gdb";
}
String[] args = new String[] {gdb, "--quiet", "-nw", "-i", "mi", program};
Process pgdb = ProcessFactory.getFactory().exec(args);
MISession session = createMISession(pgdb);
try {
CommandFactory factory = session.getCommandFactory();
MITargetAttach attach = factory.createMITargetAttach(pid);

View file

@ -13,8 +13,12 @@ import org.eclipse.cdt.debug.mi.core.MIException;
import org.eclipse.cdt.debug.mi.core.MISession;
import org.eclipse.cdt.debug.mi.core.command.CommandFactory;
import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentDirectory;
import org.eclipse.cdt.debug.mi.core.command.MIGDBSetAutoSolib;
import org.eclipse.cdt.debug.mi.core.command.MIGDBSetSolibSearchPath;
import org.eclipse.cdt.debug.mi.core.command.MIGDBShowDirectories;
import org.eclipse.cdt.debug.mi.core.command.MIGDBShowSolibSearchPath;
import org.eclipse.cdt.debug.mi.core.output.MIGDBShowDirectoriesInfo;
import org.eclipse.cdt.debug.mi.core.output.MIGDBShowSolibSearchPathInfo;
import org.eclipse.cdt.debug.mi.core.output.MIInfo;
@ -76,17 +80,41 @@ public class SourceManager extends SessionObject implements ICDISourceManager {
}
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISourceManager#addLibraryPaths(String[])
*/
public void addLibraryPaths(String[] libPaths) throws CDIException {
public void setLibraryPaths(String[] libPaths) throws CDIException {
MISession mi = getCSession().getMISession();
CommandFactory factory = mi.getCommandFactory();
MIGDBSetSolibSearchPath solib = factory.createMIGDBSetSolibSearchPath(libPaths);
try {
mi.postCommand(solib);
MIInfo info = solib.getMIInfo();
} catch (MIException e) {
throw new CDIException(e.getMessage());
}
}
/**
* @see org.eclipse.cdt.debug.core.cdi.ICDISourceManager#getLibraryPaths()
*/
public String[] getLibraryPaths() throws CDIException {
return null;
MISession mi = getCSession().getMISession();
CommandFactory factory = mi.getCommandFactory();
MIGDBShowSolibSearchPath dir = factory.createMIGDBShowSolibSearchPath();
try {
mi.postCommand(dir);
MIGDBShowSolibSearchPathInfo info = dir.getMIGDBShowSolibSearchPathInfo();
return info.getDirectories();
} catch (MIException e) {
throw new CDIException(e.getMessage());
}
}
public void setAutoSolib() throws CDIException {
MISession mi = getCSession().getMISession();
CommandFactory factory = mi.getCommandFactory();
MIGDBSetAutoSolib solib = factory.createMIGDBSetAutoSolib();
try {
mi.postCommand(solib);
MIInfo info = solib.getMIInfo();
} catch (MIException e) {
throw new CDIException(e.getMessage());
}
}
}

View file

@ -163,6 +163,14 @@ public class CommandFactory {
return new MIGDBSet(params);
}
public MIGDBSetAutoSolib createMIGDBSetAutoSolib() {
return new MIGDBSetAutoSolib();
}
public MIGDBSetSolibSearchPath createMIGDBSetSolibSearchPath(String[] params) {
return new MIGDBSetSolibSearchPath(params);
}
public MIGDBShow createMIGDBShow(String[] params) {
return new MIGDBShow(params);
}
@ -175,6 +183,10 @@ public class CommandFactory {
return new MIGDBShowDirectories();
}
public MIGDBShowSolibSearchPath createMIGDBShowSolibSearchPath() {
return new MIGDBShowSolibSearchPath();
}
public MIStackInfoDepth createMIStackInfoDepth(int depth) {
return new MIStackInfoDepth(depth);
}

View file

@ -0,0 +1,20 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.mi.core.command;
/**
*
* -gdb-set
*
* Set an internal GDB variable.
*
*/
public class MIGDBSetAutoSolib extends MIGDBSet {
public MIGDBSetAutoSolib() {
super(new String[] {"auto-solib-add"});
}
}

View file

@ -0,0 +1,32 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.mi.core.command;
/**
*
* -gdb-set
*
* Set an internal GDB variable.
*
*/
public class MIGDBSetSolibSearchPath extends MIGDBSet {
public MIGDBSetSolibSearchPath(String[] paths) {
super(paths);
// Overload the parameter
String sep = System.getProperty("path.separator", ":");
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < paths.length; i++) {
if (buffer.length() == 0) {
buffer.append(paths[i]);
} else {
buffer.append(sep).append(paths[i]);
}
}
String[] p = new String [] {"solib-search-path", buffer.toString()};
setParameters(p);
}
}

View file

@ -0,0 +1,40 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.mi.core.command;
import org.eclipse.cdt.debug.mi.core.MIException;
import org.eclipse.cdt.debug.mi.core.output.MIGDBShowSolibSearchPathInfo;
import org.eclipse.cdt.debug.mi.core.output.MIInfo;
import org.eclipse.cdt.debug.mi.core.output.MIOutput;
/**
*
* -gdb-show directories
*
* Show the current value of a GDB variable(directories).
*
*/
public class MIGDBShowSolibSearchPath extends MIGDBShow {
public MIGDBShowSolibSearchPath() {
super(new String[] { "solib-search-path" });
}
public MIGDBShowSolibSearchPathInfo getMIGDBShowSolibSearchPathInfo() throws MIException {
return (MIGDBShowSolibSearchPathInfo)getMIInfo();
}
public MIInfo getMIInfo() throws MIException {
MIInfo info = null;
MIOutput out = getMIOutput();
if (out != null) {
info = new MIGDBShowSolibSearchPathInfo(out);
if (info.isError()) {
throw new MIException(info.getErrorMsg());
}
}
return info;
}
}

View file

@ -0,0 +1,46 @@
/*
* (c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*/
package org.eclipse.cdt.debug.mi.core.output;
import java.util.StringTokenizer;
/**
* GDB/MI show parsing.
* -gdb-show solib-search-path
* ^done,value=""
* (gdb)
* -gdb-set solib-search-path /tmp:/lib
* ^done
* (gdb)
* -gdb-show solib-search-path
* ^done,value="/tmp:/lib"
*/
public class MIGDBShowSolibSearchPathInfo extends MIGDBShowInfo {
String[] dirs = null;
public MIGDBShowSolibSearchPathInfo(MIOutput o) {
super(o);
}
public String[] getDirectories() {
if (dirs == null) {
String val = getValue();
parseDirectories(val);
}
return dirs;
}
void parseDirectories(String d) {
String sep = System.getProperty("path.separator", ":");
StringTokenizer st = new StringTokenizer(d, sep);
int count = st.countTokens();
dirs = new String[count];
for (int i = 0; st.hasMoreTokens() && i < count; i++) {
dirs[i] = (String)st.nextToken();
}
}
}