]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dap: fix completion request for empty strings
authorJorenar <dev@jorenar.com>
Sun, 25 May 2025 15:40:25 +0000 (17:40 +0200)
committerTom Tromey <tromey@adacore.com>
Thu, 29 May 2025 17:04:18 +0000 (11:04 -0600)
When DAP completion requests receives empty string to complete,
the script crashes due trying to access element -1 from list
being a result of `text.splitlines()` (which for `text == ""`
evaluates into empty list).

This patch adds simple check if `text` is populated, and when it
is not, skips transformations and assigns correct result directly.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/python/lib/gdb/dap/completions.py

index 85acc43dc8ec5039bf0d4d460a0efee4e3f2be31..e5003fff96da41252769b2a480c4b7b0367ac3c8 100644 (file)
@@ -39,8 +39,11 @@ def completions(
         line = 1
     else:
         line = import_line(line)
-    text = text.splitlines()[line - 1]
-    text = text[: column - 1]
+    if text:
+        text = text.splitlines()[line - 1]
+        text = text[: column - 1]
+    else:
+        text = ""
     mi_result = exec_mi_and_log("-complete", text)
     result = []
     completion = None