diff options
author | Jorenar <dev@jorenar.com> | 2025-05-25 17:40:25 +0200 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2025-05-29 11:04:18 -0600 |
commit | aed5eee5a355788637fea8004fbb96f4eee35efa (patch) | |
tree | 089c328f15920cd7e4db6eb1100360ff801cf54f /gdb/python | |
parent | bc5237a2632c5fca868feebc1ac4974be5dda4a3 (diff) | |
download | binutils-aed5eee5a355788637fea8004fbb96f4eee35efa.zip binutils-aed5eee5a355788637fea8004fbb96f4eee35efa.tar.gz binutils-aed5eee5a355788637fea8004fbb96f4eee35efa.tar.bz2 |
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 <tom@tromey.com>
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/lib/gdb/dap/completions.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/gdb/python/lib/gdb/dap/completions.py b/gdb/python/lib/gdb/dap/completions.py index 85acc43..e5003ff 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 |