From 9c6cdeb98468e87bace6104f5f4940e65c7402d7 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Mon, 20 Jan 2003 21:01:25 +0000 Subject: [PATCH] Change the arguement of createCSession() by asking a java.io.File we force the caller to do the check for existance of the executable or the working directory --- .../cdt/debug/mi/core/GDBDebugger.java | 13 ++--- .../eclipse/cdt/debug/mi/core/MIPlugin.java | 54 +++++++++++++++---- 2 files changed, 52 insertions(+), 15 deletions(-) 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 15b4b5a1d98..a7943b0b954 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 @@ -4,6 +4,7 @@ */ package org.eclipse.cdt.debug.mi.core; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -38,9 +39,9 @@ public class GDBDebugger implements ICDebugger { public ICDISession createLaunchSession(ILaunchConfiguration config, IFile exe) throws CDIException { try { String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); - String cwd = exe.getProject().getLocation().toOSString(); + File cwd = exe.getProject().getLocation().toFile(); String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); - CSession session = (CSession)MIPlugin.getDefault().createCSession(cwd, gdbinit, gdb, exe.getLocation().toOSString()); + CSession session = (CSession)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), cwd, gdbinit); initializeLibraries(config, session); return session; } catch (IOException e) { @@ -55,9 +56,9 @@ public class GDBDebugger implements ICDebugger { public ICDISession createAttachSession(ILaunchConfiguration config, IFile exe, int pid) throws CDIException { try { String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); - String cwd = exe.getProject().getLocation().toOSString(); + File cwd = exe.getProject().getLocation().toFile(); String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); - CSession session = (CSession)MIPlugin.getDefault().createCSession(cwd, gdbinit, gdb, exe.getLocation().toOSString(), pid, null); + CSession session = (CSession)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), pid, null, cwd, gdbinit); initializeLibraries(config, session); return session; } catch (IOException e) { @@ -73,9 +74,9 @@ public class GDBDebugger implements ICDebugger { public ICDISession createCoreSession(ILaunchConfiguration config, IFile exe, IPath corefile) throws CDIException { try { String gdb = config.getAttribute(IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, "gdb"); - String cwd = exe.getProject().getLocation().toOSString(); + File cwd = exe.getProject().getLocation().toFile(); String gdbinit = config.getAttribute(IMILaunchConfigurationConstants.ATTR_GDB_INIT, ".gdbinit"); - CSession session = (CSession)MIPlugin.getDefault().createCSession(cwd, gdbinit, gdb, exe.getLocation().toOSString(), corefile.toOSString()); + CSession session = (CSession)MIPlugin.getDefault().createCSession(gdb, exe.getLocation().toFile(), corefile.toFile(), cwd, gdbinit); initializeLibraries(config, session); return session; } catch (IOException e) { 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 b76bd8342b0..ef6c57a58c1 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 @@ -4,6 +4,7 @@ */ package org.eclipse.cdt.debug.mi.core; +import java.io.File; import java.io.IOException; import org.eclipse.cdt.debug.core.cdi.ICDISession; @@ -34,6 +35,9 @@ public class MIPlugin extends Plugin { //The shared instance. private static MIPlugin plugin; + // GDB init command file + private static final String GDBINIT = ".gdbinit"; + /** * The constructor * @see org.eclipse.core.runtime.Plugin#Plugin(IPluginDescriptor) @@ -84,13 +88,13 @@ public class MIPlugin extends Plugin { * @return ICDISession * @throws MIException */ - public ICDISession createCSession(String cwd, String gdbinit, String gdb, String program) throws IOException, MIException { + public ICDISession createCSession(String gdb, File program, File cwd, String gdbinit) throws IOException, MIException { PTY pty = null; try { pty = new PTY(); } catch (IOException e) { } - return createCSession(cwd, gdbinit, gdb, program, pty); + return createCSession(gdb, program, cwd, gdbinit, pty); } /** @@ -99,16 +103,28 @@ public class MIPlugin extends Plugin { * @return ICDISession * @throws IOException */ - public ICDISession createCSession(String cwd, String gdbinit, String gdb, String program, PTY pty) throws IOException, MIException { + public ICDISession createCSession(String gdb, File program, File cwd, String gdbinit, PTY pty) throws IOException, MIException { if (gdb == null || gdb.length() == 0) { gdb = "gdb"; } + + if (gdbinit == null || gdbinit.length() == 0) { + gdbinit = GDBINIT; + } String[] args; if (pty != null) { - args = new String[] {gdb, "--cd="+cwd, "--command="+gdbinit, "-q", "-nw", "-tty", pty.getSlaveName(), "-i", "mi1", program}; + if (program == null) { + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-tty", pty.getSlaveName(), "-i", "mi1"}; + } else { + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-tty", pty.getSlaveName(), "-i", "mi1", program.getAbsolutePath()}; + } } else { - args = new String[] {gdb, "--cd="+cwd, "--command="+gdbinit, "-q", "-nw", "-i", "mi1", program}; + if (program == null) { + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-i", "mi1"}; + } else { + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "-q", "-nw", "-i", "mi1", program.getAbsolutePath()}; + } } Process pgdb = ProcessFactory.getFactory().exec(args); @@ -138,11 +154,21 @@ public class MIPlugin extends Plugin { * @return ICDISession * @throws IOException */ - public ICDISession createCSession(String cwd, String gdbinit, String gdb, String program, String core) throws IOException, MIException { + public ICDISession createCSession(String gdb, File program, File core, File cwd, String gdbinit) throws IOException, MIException { if (gdb == null || gdb.length() == 0) { gdb = "gdb"; } - String[] args = new String[] {gdb, "--cd="+cwd, "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1", program, core}; + + if (gdbinit == null || gdbinit.length() == 0) { + gdbinit = GDBINIT; + } + + String[] args; + if (program == null) { + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1", "-c", core.getAbsolutePath()}; + } else { + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1", "-c", core.getAbsolutePath(), program.getAbsolutePath()}; + } Process pgdb = ProcessFactory.getFactory().exec(args); MISession session = createMISession(pgdb, null, MISession.CORE); return new CSession(session); @@ -155,11 +181,21 @@ public class MIPlugin extends Plugin { * @return ICDISession * @throws IOException */ - public ICDISession createCSession(String cwd, String gdbinit, String gdb, String program, int pid, String[] targetParams) throws IOException, MIException { + public ICDISession createCSession(String gdb, File program, int pid, String[] targetParams, File cwd, String gdbinit) throws IOException, MIException { if (gdb == null || gdb.length() == 0) { gdb = "gdb"; } - String[] args = new String[] {gdb, "--cd="+cwd, "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1", program}; + + if (gdbinit == null || gdbinit.length() == 0) { + gdbinit = GDBINIT; + } + + String[] args; + if (program == null) { + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1"}; + } else { + args = new String[] {gdb, "--cd="+cwd.getAbsolutePath(), "--command="+gdbinit, "--quiet", "-nw", "-i", "mi1", program.getAbsolutePath()}; + } Process pgdb = ProcessFactory.getFactory().exec(args); MISession session = createMISession(pgdb, null, MISession.ATTACH); MIInfo info = null;