aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2024-09-11 09:25:45 -0600
committerTom Tromey <tromey@adacore.com>2024-09-13 09:34:50 -0600
commitc7e57281af00830d6d147ed8e4b87d17e6ad4b7b (patch)
tree1af6bc1f474622588e6d9e72e6d31877d9d6d423 /gdb/python
parentedb09798f2cd60b72591da9fe5f2e1bee50c5d83 (diff)
downloadbinutils-c7e57281af00830d6d147ed8e4b87d17e6ad4b7b.zip
binutils-c7e57281af00830d6d147ed8e4b87d17e6ad4b7b.tar.gz
binutils-c7e57281af00830d6d147ed8e4b87d17e6ad4b7b.tar.bz2
Add quoting to 'file' invocations in DAP
Oleg Tolmatcev noticed that DAP launch and attach requests don't properly handle Windows filenames, because "file" doesn't handle the backslash characters correctly. This patch adds quoting to the command in an attempt to fix this.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/lib/gdb/dap/launch.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/gdb/python/lib/gdb/dap/launch.py b/gdb/python/lib/gdb/dap/launch.py
index 2674e02..df1f667 100644
--- a/gdb/python/lib/gdb/dap/launch.py
+++ b/gdb/python/lib/gdb/dap/launch.py
@@ -13,6 +13,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import re
+
# These are deprecated in 3.9, but required in older versions.
from typing import Mapping, Optional, Sequence
@@ -20,7 +22,16 @@ import gdb
from .events import exec_and_expect_stop, expect_process, expect_stop
from .server import capability, request
-from .startup import DAPException, exec_and_log
+from .startup import DAPException, exec_and_log, in_gdb_thread
+
+
+# A wrapper for the 'file' command that correctly quotes its argument.
+@in_gdb_thread
+def file_command(program):
+ # Handle whitespace, quotes, and backslashes here. Exactly what
+ # to quote depends on libiberty's buildargv and safe-ctype.
+ program = re.sub("[ \t\n\r\f\v\\\\'\"]", "\\\\\\g<0>", program)
+ exec_and_log("file " + program)
# Any parameters here are necessarily extensions -- DAP requires this
@@ -39,7 +50,7 @@ def launch(
if cwd is not None:
exec_and_log("cd " + cwd)
if program is not None:
- exec_and_log("file " + program)
+ file_command(program)
inf = gdb.selected_inferior()
if stopAtBeginningOfMainSubprogram:
main = inf.main_name
@@ -63,7 +74,7 @@ def attach(
**args,
):
if program is not None:
- exec_and_log("file " + program)
+ file_command(program)
if pid is not None:
cmd = "attach " + str(pid)
elif target is not None: