From 7f6e7f8c9b5785a2e219d1fb030a3a197bedb665 Mon Sep 17 00:00:00 2001 From: Marc Dumais Date: Mon, 23 Jan 2017 12:57:02 -0500 Subject: [PATCH] Bug 510615 - Launch dialog, handle spaces in gdb path The path to GDB is set in the launch dialog, under the Debugger tab. If the path to GDB contains one or more spaces, and is not within double quotes, GDB will not be found and the launch will fail. This patch improves the use cases around the "Browse" button, to select GDB's path. 1) if the user clicks on the "Browse" button, the browse dialog will open in the correct place, no matter the presence of space(s). 2) When GDB's path is selected with the "Browse" button, it's then set in the "GDB debugger" field. This patch looks at the selected path and adds surrounding double quotes if there is any space within, and strips any double quotes if there are no spaces. Change-Id: I202f574772965af3a491d449b9e9a97e8c61e2b0 --- .../internal/ui/launching/GdbCoreDebuggerPage.java | 11 ++++++++++- .../gdb/internal/ui/launching/GdbDebuggerPage.java | 11 ++++++++++- .../internal/docker/launcher/GdbDebuggerPage.java | 12 ++++++++++-- .../llvm/dsf/lldb/ui/internal/LLDBCDebuggerPage.java | 11 ++++++++++- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/GdbCoreDebuggerPage.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/GdbCoreDebuggerPage.java index 43230042c69..18e1b8e8a9f 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/GdbCoreDebuggerPage.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/GdbCoreDebuggerPage.java @@ -207,12 +207,21 @@ public class GdbCoreDebuggerPage extends AbstractCDebuggerPage implements Observ String gdbCommand = fGDBCommandText.getText().trim(); int lastSeparatorIndex = gdbCommand.lastIndexOf(File.separator); if (lastSeparatorIndex != -1) { - dialog.setFilterPath(gdbCommand.substring(0, lastSeparatorIndex)); + String cmd = gdbCommand.substring(0, lastSeparatorIndex); + // remove double quotes, since they interfere with + // "setFilterPath()" below + cmd = cmd.replaceAll("\\\"", ""); //$NON-NLS-1$//$NON-NLS-2$ + dialog.setFilterPath(cmd); } String res = dialog.open(); if (res == null) { return; } + // path contains space(s)? + if (res.contains(" ")) { //$NON-NLS-1$ + // surround it in double quotes + res = '"' + res + '"'; + } fGDBCommandText.setText(res); } }); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/GdbDebuggerPage.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/GdbDebuggerPage.java index 8f96caeebb9..751aeca2747 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/GdbDebuggerPage.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/GdbDebuggerPage.java @@ -365,12 +365,21 @@ public class GdbDebuggerPage extends AbstractCDebuggerPage implements Observer { String gdbCommand = fGDBCommandText.getText().trim(); int lastSeparatorIndex = gdbCommand.lastIndexOf(File.separator); if (lastSeparatorIndex != -1) { - dialog.setFilterPath(gdbCommand.substring(0, lastSeparatorIndex)); + String cmd = gdbCommand.substring(0, lastSeparatorIndex); + // remove double quotes, since they interfere with + // "setFilterPath()" below + cmd = cmd.replaceAll("\\\"", ""); //$NON-NLS-1$//$NON-NLS-2$ + dialog.setFilterPath(cmd); } String res = dialog.open(); if (res == null) { return; } + // path contains space(s)? + if (res.contains(" ")) { //$NON-NLS-1$ + // surround it in double quotes + res = '"' + res + '"'; + } fGDBCommandText.setText(res); } }); diff --git a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/GdbDebuggerPage.java b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/GdbDebuggerPage.java index 01ad626dfaa..073ba62effb 100644 --- a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/GdbDebuggerPage.java +++ b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/GdbDebuggerPage.java @@ -347,13 +347,21 @@ public class GdbDebuggerPage extends AbstractCDebuggerPage implements Observer { String gdbCommand = fGDBCommandText.getText().trim(); int lastSeparatorIndex = gdbCommand.lastIndexOf(File.separator); if (lastSeparatorIndex != -1) { - dialog.setFilterPath( - gdbCommand.substring(0, lastSeparatorIndex)); + String cmd = gdbCommand.substring(0, lastSeparatorIndex); + // remove double quotes, since they interfere with + // "setFilterPath()" below + cmd = cmd.replaceAll("\\\"", ""); //$NON-NLS-1$//$NON-NLS-2$ + dialog.setFilterPath(cmd); } String res = dialog.open(); if (res == null) { return; } + // path contains space(s)? + if (res.contains(" ")) { //$NON-NLS-1$ + // surround it in double quotes + res = '"' + res + '"'; + } fGDBCommandText.setText(res); } }); diff --git a/llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/src/org/eclipse/cdt/llvm/dsf/lldb/ui/internal/LLDBCDebuggerPage.java b/llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/src/org/eclipse/cdt/llvm/dsf/lldb/ui/internal/LLDBCDebuggerPage.java index 1d5eafa72e4..abba8a1a248 100644 --- a/llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/src/org/eclipse/cdt/llvm/dsf/lldb/ui/internal/LLDBCDebuggerPage.java +++ b/llvm/org.eclipse.cdt.llvm.dsf.lldb.ui/src/org/eclipse/cdt/llvm/dsf/lldb/ui/internal/LLDBCDebuggerPage.java @@ -72,12 +72,21 @@ public class LLDBCDebuggerPage extends AbstractCDebuggerPage { String lldbCommand = fLLDBCommandText.getText().trim(); int lastSeparatorIndex = lldbCommand.lastIndexOf(File.separator); if (lastSeparatorIndex != -1) { - dialog.setFilterPath(lldbCommand.substring(0, lastSeparatorIndex)); + String cmd = lldbCommand.substring(0, lastSeparatorIndex); + // remove double quotes, since they interfere with + // "setFilterPath()" below + cmd = cmd.replaceAll("\\\"", ""); //$NON-NLS-1$//$NON-NLS-2$ + dialog.setFilterPath(cmd); } String res = dialog.open(); if (res == null) { return; } + // path contains space(s)? + if (res.contains(" ")) { //$NON-NLS-1$ + // surround it in double quotes + res = '"' + res + '"'; + } fLLDBCommandText.setText(res); } });