From cba9b18bf5007c55e961bfce18751b013377a835 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Tue, 24 Sep 2002 19:08:42 +0000 Subject: [PATCH] Implement solib-search-path. --- .../cdt/debug/mi/core/GDBDebugger.java | 65 ++++++++++++++----- .../core/IMILaunchConfigurationConstants.java | 14 +++- .../eclipse/cdt/debug/mi/core/MIPlugin.java | 34 ++++++---- .../cdt/debug/mi/core/cdi/SourceManager.java | 44 ++++++++++--- .../debug/mi/core/command/CommandFactory.java | 12 ++++ .../mi/core/command/MIGDBSetAutoSolib.java | 20 ++++++ .../core/command/MIGDBSetSolibSearchPath.java | 32 +++++++++ .../command/MIGDBShowSolibSearchPath.java | 40 ++++++++++++ .../output/MIGDBShowSolibSearchPathInfo.java | 46 +++++++++++++ 9 files changed, 267 insertions(+), 40 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBSetAutoSolib.java create mode 100644 debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBSetSolibSearchPath.java create mode 100644 debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBShowSolibSearchPath.java create mode 100644 debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIGDBShowSolibSearchPathInfo.java diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBDebugger.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBDebugger.java index 5d4992caf56..e22e2b63b44 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBDebugger.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBDebugger.java @@ -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()); - } - catch (IOException e) { + SourceManager mgr = (SourceManager)session.getSourceManager(); + boolean autolib = config.getAttribute(IMILaunchConfigurationConstants.ATTR_AUTO_SOLIB, false); + if (autolib) { + mgr.setAutoSolib(); + } + 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()); - } - } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/IMILaunchConfigurationConstants.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/IMILaunchConfigurationConstants.java index 0db3e6dd995..0acba800f22 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/IMILaunchConfigurationConstants.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/IMILaunchConfigurationConstants.java @@ -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$ } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java index cd2e85a0d6c..67e4af14248 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/MIPlugin.java @@ -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); diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/SourceManager.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/SourceManager.java index 0ab3b59d209..0765959e5c6 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/SourceManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/cdi/SourceManager.java @@ -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()); + } } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java index 61e421abb55..5159e53cacf 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java @@ -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); } diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBSetAutoSolib.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBSetAutoSolib.java new file mode 100644 index 00000000000..bb141702fbd --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBSetAutoSolib.java @@ -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"}); + } +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBSetSolibSearchPath.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBSetSolibSearchPath.java new file mode 100644 index 00000000000..8a8625d8d76 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBSetSolibSearchPath.java @@ -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); + } +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBShowSolibSearchPath.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBShowSolibSearchPath.java new file mode 100644 index 00000000000..d966194ab3b --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/command/MIGDBShowSolibSearchPath.java @@ -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; + } +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIGDBShowSolibSearchPathInfo.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIGDBShowSolibSearchPathInfo.java new file mode 100644 index 00000000000..413030a030f --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/output/MIGDBShowSolibSearchPathInfo.java @@ -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(); + } + } +}