From 27043fdba79bc6b5d6032d5fa49cad062c3bfa94 Mon Sep 17 00:00:00 2001 From: Ken Ryall Date: Fri, 4 May 2007 21:12:39 +0000 Subject: [PATCH] Better MI support on Mac OS: MI version of shared lib info, also allow CommandFactory to provide initial directory specification so it can be quoted. --- .../mi/core/cdi/SharedLibraryManager.java | 50 +++++++++++----- .../debug/mi/core/command/CLIInfoLine.java | 2 +- .../debug/mi/core/command/CommandFactory.java | 10 ++++ .../mi/core/command/MIInfoSharedLibrary.java | 30 ++++++++++ .../macos/StandardMacOSCommandFactory.java | 11 ++++ .../debug/mi/core/output/CLIInfoLineInfo.java | 10 ++-- .../core/output/MIInfoSharedLibraryInfo.java | 58 +++++++++++++++++++ .../cdt/debug/mi/core/GDBCDIDebugger2.java | 3 +- 8 files changed, 153 insertions(+), 21 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/MIInfoSharedLibrary.java create mode 100644 debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/MIInfoSharedLibraryInfo.java diff --git a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/SharedLibraryManager.java b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/SharedLibraryManager.java index 1c03b21719a..eef30ba4cd6 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/SharedLibraryManager.java +++ b/debug/org.eclipse.cdt.debug.mi.core/cdi/org/eclipse/cdt/debug/mi/core/cdi/SharedLibraryManager.java @@ -43,6 +43,7 @@ import org.eclipse.cdt.debug.mi.core.command.MIGDBSetSolibSearchPath; import org.eclipse.cdt.debug.mi.core.command.MIGDBSetStopOnSolibEvents; import org.eclipse.cdt.debug.mi.core.command.MIGDBShow; import org.eclipse.cdt.debug.mi.core.command.MIGDBShowSolibSearchPath; +import org.eclipse.cdt.debug.mi.core.command.MIInfoSharedLibrary; import org.eclipse.cdt.debug.mi.core.event.MIBreakpointCreatedEvent; import org.eclipse.cdt.debug.mi.core.event.MIEvent; import org.eclipse.cdt.debug.mi.core.event.MISharedLibChangedEvent; @@ -53,6 +54,7 @@ import org.eclipse.cdt.debug.mi.core.output.MIBreakpoint; import org.eclipse.cdt.debug.mi.core.output.MIGDBShowInfo; 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.MIInfoSharedLibraryInfo; import org.eclipse.cdt.debug.mi.core.output.MIShared; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -86,21 +88,41 @@ public class SharedLibraryManager extends Manager { MIShared[] getMIShareds(MISession miSession) throws CDIException { MIShared[] miLibs = new MIShared[0]; CommandFactory factory = miSession.getCommandFactory(); - CLIInfoSharedLibrary infoShared = factory.createCLIInfoSharedLibrary(); - try { - RxThread rxThread = miSession.getRxThread(); - rxThread.setEnableConsole(false); - miSession.postCommand(infoShared); - CLIInfoSharedLibraryInfo info = infoShared.getMIInfoSharedLibraryInfo(); - if (info == null) { - throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ + MIInfoSharedLibrary infoSharedMI = factory.createMIInfoSharedLibrary(); + + if (infoSharedMI != null) + { + try { + miSession.postCommand(infoSharedMI); + MIInfoSharedLibraryInfo info = infoSharedMI.getMIInfoSharedLibraryInfo(); + if (info == null) { + throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ + } + miLibs = info.getMIShared(); + } catch (MIException e) { + throw new MI2CDIException(e); } - miLibs = info.getMIShared(); - } catch (MIException e) { - throw new MI2CDIException(e); - } finally { - RxThread rxThread = miSession.getRxThread(); - rxThread.setEnableConsole(true); + } + else + { + + CLIInfoSharedLibrary infoShared = factory.createCLIInfoSharedLibrary(); + try { + RxThread rxThread = miSession.getRxThread(); + rxThread.setEnableConsole(false); + miSession.postCommand(infoShared); + CLIInfoSharedLibraryInfo info = infoShared.getMIInfoSharedLibraryInfo(); + if (info == null) { + throw new CDIException(CdiResources.getString("cdi.Common.No_answer")); //$NON-NLS-1$ + } + miLibs = info.getMIShared(); + } catch (MIException e) { + throw new MI2CDIException(e); + } finally { + RxThread rxThread = miSession.getRxThread(); + rxThread.setEnableConsole(true); + } + } return miLibs; } diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CLIInfoLine.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CLIInfoLine.java index 81bdfc9f4c4..3aa9548a1dc 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CLIInfoLine.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CLIInfoLine.java @@ -19,7 +19,7 @@ import org.eclipse.cdt.debug.mi.core.output.MIOutput; public class CLIInfoLine extends CLICommand { public CLIInfoLine(IAddress address) { - super("info line *" + address.toHexAddressString()); + super("info line *" + address.toHexAddressString()); //$NON-NLS-1$ } public CLIInfoLineInfo getMIInfoLineInfo() throws MIException { diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java index 82de011c7d0..e4c1fc3ba7c 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/CommandFactory.java @@ -11,6 +11,8 @@ package org.eclipse.cdt.debug.mi.core.command; +import java.io.File; + import org.eclipse.cdt.core.IAddress; @@ -428,4 +430,12 @@ public class CommandFactory { public MIGDBSetNewConsole createMIGDBSetNewConsole() { return new MIGDBSetNewConsole(getMIVersion()); } + + public MIInfoSharedLibrary createMIInfoSharedLibrary() { + return null; + } + + public String getWorkingDirectory(File cwd) { + return "--cd=" + cwd.getAbsolutePath(); //$NON-NLS-1$ + } } diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/MIInfoSharedLibrary.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/MIInfoSharedLibrary.java new file mode 100644 index 00000000000..8e81070b429 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/MIInfoSharedLibrary.java @@ -0,0 +1,30 @@ +package org.eclipse.cdt.debug.mi.core.command; + +import org.eclipse.cdt.debug.mi.core.MIException; +import org.eclipse.cdt.debug.mi.core.output.MIInfo; +import org.eclipse.cdt.debug.mi.core.output.MIInfoSharedLibraryInfo; +import org.eclipse.cdt.debug.mi.core.output.MIOutput; + +public class MIInfoSharedLibrary extends MICommand { + + public MIInfoSharedLibrary(String miVersion) { + super(miVersion, "info sharedlibrary"); //$NON-NLS-1$ + } + + public MIInfo getMIInfo() throws MIException { + MIInfo info = null; + MIOutput out = getMIOutput(); + if (out != null) { + info = new MIInfoSharedLibraryInfo(out); + if (info.isError()) { + throwMIException(info, out); + } + } + return info; + } + + public MIInfoSharedLibraryInfo getMIInfoSharedLibraryInfo() throws MIException { + return (MIInfoSharedLibraryInfo) getMIInfo(); + } + +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/macos/StandardMacOSCommandFactory.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/macos/StandardMacOSCommandFactory.java index c4d3c6b0842..99feadd3216 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/macos/StandardMacOSCommandFactory.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/command/factories/macos/StandardMacOSCommandFactory.java @@ -10,7 +10,10 @@ ***********************************************************************/ package org.eclipse.cdt.debug.mi.core.command.factories.macos; +import java.io.File; + import org.eclipse.cdt.debug.mi.core.command.MIEnvironmentCD; +import org.eclipse.cdt.debug.mi.core.command.MIInfoSharedLibrary; import org.eclipse.cdt.debug.mi.core.command.factories.StandardCommandFactory; public class StandardMacOSCommandFactory extends StandardCommandFactory { @@ -22,6 +25,10 @@ public class StandardMacOSCommandFactory extends StandardCommandFactory { super(); } + public String getWorkingDirectory(File cwd) { + return "--cd=" + '"' + cwd.getAbsolutePath() + '"'; //$NON-NLS-1$ + } + /** * Constructor for StandardMacOSCommandFactory. */ @@ -33,4 +40,8 @@ public class StandardMacOSCommandFactory extends StandardCommandFactory { return new MacOSMIEnvironmentCD(getMIVersion(), pathdir); } + public MIInfoSharedLibrary createMIInfoSharedLibrary() { + return new MIInfoSharedLibrary(getMIVersion()); + } + } diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/CLIInfoLineInfo.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/CLIInfoLineInfo.java index 2f6675ef72b..4da7591610c 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/CLIInfoLineInfo.java +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/CLIInfoLineInfo.java @@ -71,27 +71,27 @@ public class CLIInfoLineInfo extends MIInfo { } protected void parseLineInfo(String str, List aList) { - String[] strbits = str.split("\\s"); + String[] strbits = str.split("\\s"); //$NON-NLS-1$ for (int i = 0; i < strbits.length; i++) { - if (strbits[i].equals("Line")) + if (strbits[i].equals("Line")) //$NON-NLS-1$ { lineNumber = Integer.parseInt(strbits[i+1]); } else - if (strbits[i].equals("starts")) + if (strbits[i].equals("starts")) //$NON-NLS-1$ { startAddress = new BigInteger(strbits[i+3].substring(2), 16); startLocation = strbits[i+4]; } else - if (strbits[i].equals("ends")) + if (strbits[i].equals("ends")) //$NON-NLS-1$ { endAddress = new BigInteger(strbits[i+2].substring(2), 16); endLocation = strbits[i+3]; } } - strbits = str.split("\""); + strbits = str.split("\""); //$NON-NLS-1$ for (int i = 0; i < strbits.length; i++) { fileName = strbits[1]; } diff --git a/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/MIInfoSharedLibraryInfo.java b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/MIInfoSharedLibraryInfo.java new file mode 100644 index 00000000000..46b43a2da00 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.mi.core/mi/org/eclipse/cdt/debug/mi/core/output/MIInfoSharedLibraryInfo.java @@ -0,0 +1,58 @@ +package org.eclipse.cdt.debug.mi.core.output; + +import java.util.ArrayList; + +public class MIInfoSharedLibraryInfo extends MIInfo { + + MIShared[] shared = new MIShared[0]; + + public MIInfoSharedLibraryInfo(MIOutput record) { + super(record); + parse(); + } + + private void parse() { + if (isDone()) { + ArrayList aList = new ArrayList(); + MIOutput out = getMIOutput(); + MIResultRecord rr = out.getMIResultRecord(); + if (rr != null) { + MIResult[] results = rr.getMIResults(); + for (int i = 0; i < results.length; i++) { + String var = results[i].getVariable(); + if (var.equals("shlib-info")) { //$NON-NLS-1$ + MIValue val = results[i].getMIValue(); + if (val instanceof MITuple) + { + MIResult[] libResults = ((MITuple)val).getMIResults(); + String from = ""; //$NON-NLS-1$ + String to = ""; //$NON-NLS-1$ + boolean syms = true; + String name = ""; //$NON-NLS-1$ + + for (int j = 0; j < libResults.length; j++) { + if (libResults[j].getVariable().equals("description")) //$NON-NLS-1$ + { + name = libResults[j].getMIValue().toString(); + } + if (libResults[j].getVariable().equals("loaded_addr")) //$NON-NLS-1$ + { + from = libResults[j].getMIValue().toString(); + to = from; + } + } + MIShared s = new MIShared(from, to, syms, name); + aList.add(s); + } + } + } + } + shared = (MIShared[]) aList.toArray(new MIShared[aList.size()]); + } + } + + public MIShared[] getMIShared() { + return shared; + } + +} diff --git a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger2.java b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger2.java index 986c084afc4..73d29420821 100644 --- a/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger2.java +++ b/debug/org.eclipse.cdt.debug.mi.core/src/org/eclipse/cdt/debug/mi/core/GDBCDIDebugger2.java @@ -236,7 +236,8 @@ public class GDBCDIDebugger2 extends AbstractGDBCDIDebugger { protected String getWorkingDirectory( ILaunchConfiguration config ) throws CoreException { File cwd = getProjectPath( config ).toFile(); - return "--cd=" + cwd.getAbsolutePath(); //$NON-NLS-1$ + CommandFactory factory = getCommandFactory( config ); + return factory.getWorkingDirectory(cwd); } protected String getCommandFile( ILaunchConfiguration config ) throws CoreException {