From: Jorenar Date: Sun, 25 May 2025 15:40:25 +0000 (+0200) Subject: gdb/dap: fix completion request for empty strings X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aed5eee5a355788637fea8004fbb96f4eee35efa;p=thirdparty%2Fbinutils-gdb.git gdb/dap: fix completion request for empty strings 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 --- diff --git a/gdb/python/lib/gdb/dap/completions.py b/gdb/python/lib/gdb/dap/completions.py index 85acc43dc8e..e5003fff96d 100644 --- a/gdb/python/lib/gdb/dap/completions.py +++ b/gdb/python/lib/gdb/dap/completions.py @@ -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