From aed5eee5a355788637fea8004fbb96f4eee35efa Mon Sep 17 00:00:00 2001 From: Jorenar Date: Sun, 25 May 2025 17:40:25 +0200 Subject: [PATCH] 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 --- gdb/python/lib/gdb/dap/completions.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 -- 2.47.2