Community
Participate
Working Groups
Created attachment 220018 [details] Print.java It should be possible to copy program parameters from the Eclipse launch configuration dialog or from the process properties dialog to the command line and get the same results as when launching from Eclipse. While trying to fix bug 387026, I found a couple of bugs in the program argument parsing code (compared to command line). The main omission is that command lines concatenate "quoted args" and non-whitespace characters that precede or follow the quoted string. DebugPlugin#parseArguments(String), ProcessPropertyPage#setCommandLine(Text, String), and StandardVMRunner#renderCommandLine(String[]) don't do that. Further problems are the bugs in JDK's ProcessImpl on Windows: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6511002 http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6518827 http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6468220 ... and Microsoft's "ingenious" quoting/escaping rules: http://msdn.microsoft.com/en-us/library/a1y7w461.aspx I first wanted to fix the problems I found, but then they became so numerous and platform-dependent that I had to time-box my efforts. I mainly opened this bug to document the problems in case someone wants to fix them. If this bug is going to be fixed, then we should fix all problems at once. Otherwise, existing launch configurations will be broken, and even if users manage to recover, fixing the remaining issues will break them again. The attached Print.java is a nice test case, but it misses some of the intricacies of Microsoft's "Parsing C Command-Line Arguments" (since I wrote it before I found that document).
Created attachment 220626 [details] Fix for platform.debug I realized that bug 387026 cannot be fixed cleanly without fixing this bug. These two patches implement the complete solution that allows lossless round-trips (parse > render > parse). The tests verify that the underlying platforms agree with our code. This patch also includes the fix for bug 387026.
Created attachment 220627 [details] Fix for jdt.debug
*** Bug 387026 has been marked as a duplicate of this bug. ***
Looks good and even has a tonne of unit tests! Thanks Markus. pushed to platform: http://git.eclipse.org/c/platform/eclipse.platform.debug.git/commit/?id=37978528c6f546dbacda8aaa7c9b284e602b5b44 pushed to JDT: http://git.eclipse.org/c/jdt/eclipse.jdt.debug.git/commit/?id=b1c4d1bf43987166eb09b71cb584335481ef878e
> Looks good and even has a tonne of unit tests! Yeah, this was a case where "test first" development really paid out (because the API and the expected results were clear from the beginning).
Reopening as this change appears to be causing 22 test failures on the build machines. They pass when run locally. The failures all look like the following: testEmpty Error N/A java.lang.NullPointerException at org.eclipse.core.internal.runtime.Activator.getURLConverter(Activator.java:321) at org.eclipse.core.runtime.FileLocator.toFileURL(FileLocator.java:205) at org.eclipe.debug.tests.launching.ArgumentParsingTests.runCommandLine(ArgumentParsingTests.java:78) at org.eclipe.debug.tests.launching.ArgumentParsingTests.execute(ArgumentParsingTests.java:61) at org.eclipe.debug.tests.launching.ArgumentParsingTests.execute(ArgumentParsingTests.java:52) at org.eclipe.debug.tests.launching.ArgumentParsingTests.testEmpty(ArgumentParsingTests.java:118) at org.eclipse.test.EclipseTestRunner.run(EclipseTestRunner.java:650) at org.eclipse.test.EclipseTestRunner.run(EclipseTestRunner.java:305) at org.eclipse.test.UITestApplication$2.run(UITestApplication.java:197) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35) ...
(In reply to comment #6) Sorry about the NPE. I wrongly assumed that the test bundle would be unJARed when automated tests are run. I'll fix this for M3.
Fixed with http://git.eclipse.org/c/platform/eclipse.platform.debug.git/commit/?id=aeb204dd5975c4bd3ed2a35f43b44c0b5095860e
ArgumentTests.testProgramArgEmptyString found a bug on *nix platforms. Fixed with http://git.eclipse.org/c/platform/eclipse.platform.debug.git/commit/?id=7f144247727de01bfce8af95c05a898f6ec16d55
(In reply to comment #9) I should also have fixed that in the Windows parser. With that fix, I can also revert org.eclipse.jdt.debug.tests.core.ArgumentTests#testProgramArgOneQuote() to correctly parse a single " as one empty argument. (On the command line, this is only supported on Windows; in sh, it's a "continuation"). Fixed with http://git.eclipse.org/c/platform/eclipse.platform.debug.git/commit/?id=b644a77916417dbe0eafa2ea3b3842931e283abc and http://git.eclipse.org/c/jdt/eclipse.jdt.debug.git/commit/?id=377a54c2a7fd426ef9cf643cc2766fe39162b69d
Text#addSegmentListener(..) is missing an implementation on the Mac, see bug 383185. Changed the process properties page to use StyledText instead: http://git.eclipse.org/c/platform/eclipse.platform.debug.git/commit/?id=a68f972007c011994af90bf8a7a9f1b81616f306
> Text#addSegmentListener(..) is missing an implementation on the Mac Bug 388578, I meant.
Found another problem on Windows. My External Tools launch configuration to show the selected resource in the Windows Explorer doesn't work any more if the resource_loc contains spaces: C:\WINDOWS\explorer.exe /E,/select=${resource_loc} Analysis: I fell into the same trap as the designers of the ProcessBuilder and Runtime#exec(String[] cmdarray, ..) APIs. These APIs cannot be implemented properly on Windows, since a Windows process is not created with a list of arguments, but with a single commandline argument to the native CreateProcess method. There's no "correct" way to split a Windows command line into arguments, since argument parsing is implemented separately by each application. Likewise, there's no "correct" way to quote/escape and merge an array of arguments into an equivalent command line. Some applications use the rules cited by http://msdn.microsoft.com/en-us/library/a1y7w461.aspx , but others don't. E.g.: explorer.exe /E,/select="C:\path\with spaces\embedded" works explorer.exe /E,/select=C:\path\with spaces\embedded works explorer.exe "/E,/select=C:\path\with spaces\embedded" fails! For External Tools launch configurations, the workaround from http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6511002 should not be applied. The workaround should be removed from DebugPlugin#exec(String[], ..) again. It should only be used in the AbstractVMRunner, where we know how the java.exe application will parse arguments.
(In reply to comment #13) Fixed with http://git.eclipse.org/c/jdt/eclipse.jdt.debug.git/commit/?id=446a70bae405a9bb5cbc26e762ad61d87b3a4c52 and http://git.eclipse.org/c/platform/eclipse.platform.debug.git/commit/?id=05be2519c00be901ef1067b044790fa07dc9871e