[Lldb-commits] [lldb] [LLDB] Fix crash when using tab completion on class variables (PR #83234)

via lldb-commits lldb-commits at lists.llvm.org
Wed Feb 28 01:15:33 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Sudharsan Veeravalli (svs-quic)

<details>
<summary>Changes</summary>

We weren't checking to see if the partial_path was empty before adding completions and this led to crashes when the class object and a variable both start with  the same substring.

Fixes [#<!-- -->81536](https://github.com/llvm/llvm-project/issues/81536)

---
Full diff: https://github.com/llvm/llvm-project/pull/83234.diff


1 Files Affected:

- (modified) lldb/source/Symbol/Variable.cpp (+5-3) 


``````````diff
diff --git a/lldb/source/Symbol/Variable.cpp b/lldb/source/Symbol/Variable.cpp
index 2bb2ff7db4b721..a33c3433d9e245 100644
--- a/lldb/source/Symbol/Variable.cpp
+++ b/lldb/source/Symbol/Variable.cpp
@@ -509,15 +509,17 @@ static void PrivateAutoCompleteMembers(
       CompilerType member_compiler_type = compiler_type.GetFieldAtIndex(
           i, member_name, nullptr, nullptr, nullptr);
 
-      if (partial_member_name.empty() ||
-          llvm::StringRef(member_name).starts_with(partial_member_name)) {
+      if (partial_member_name.empty()) {
+        request.AddCompletion((prefix_path + member_name).str());
+      } else if (llvm::StringRef(member_name)
+                     .starts_with(partial_member_name)) {
         if (member_name == partial_member_name) {
           PrivateAutoComplete(
               frame, partial_path,
               prefix_path + member_name, // Anything that has been resolved
                                          // already will be in here
               member_compiler_type.GetCanonicalType(), request);
-        } else {
+        } else if (partial_path.empty()) {
           request.AddCompletion((prefix_path + member_name).str());
         }
       }

``````````

</details>


https://github.com/llvm/llvm-project/pull/83234


More information about the lldb-commits mailing list