poya created this revision.
poya added a reviewer: teemperor.
Herald added a project: LLDB.
poya added a comment.

Tests for the Swift REPL in https://github.com/apple/llvm-project/pull/1388


When tabbing to complete LLDB commands in REPL, characters would at best be 
missing but at worst cause the REPL to crash due to out of range string access.
This patch appends the command character to the completion results to fulfill 
the assumption that all matches are prefixed by the request's cursor argument 
prefix.

Bug report for the Swift REPL
https://bugs.swift.org/browse/SR-12867


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82835

Files:
  lldb/source/Expression/REPL.cpp


Index: lldb/source/Expression/REPL.cpp
===================================================================
--- lldb/source/Expression/REPL.cpp
+++ lldb/source/Expression/REPL.cpp
@@ -457,6 +457,12 @@
     debugger.GetCommandInterpreter().HandleCompletion(sub_request);
     StringList matches, descriptions;
     sub_result.GetMatches(matches);
+    // Prepend command prefix that was excluded in the completion request
+    if (request.GetCursorIndex() == 0) {
+      for (auto &match : matches) {
+        match.insert(0, 1, ':');
+      }
+    }
     sub_result.GetDescriptions(descriptions);
     request.AddCompletions(matches, descriptions);
     return;


Index: lldb/source/Expression/REPL.cpp
===================================================================
--- lldb/source/Expression/REPL.cpp
+++ lldb/source/Expression/REPL.cpp
@@ -457,6 +457,12 @@
     debugger.GetCommandInterpreter().HandleCompletion(sub_request);
     StringList matches, descriptions;
     sub_result.GetMatches(matches);
+    // Prepend command prefix that was excluded in the completion request
+    if (request.GetCursorIndex() == 0) {
+      for (auto &match : matches) {
+        match.insert(0, 1, ':');
+      }
+    }
     sub_result.GetDescriptions(descriptions);
     request.AddCompletions(matches, descriptions);
     return;
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to