Skip to content

[LLDB] Fix crash when using tab completion on class variables #83234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 29, 2024

Conversation

svs-quic
Copy link
Contributor

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

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@svs-quic svs-quic marked this pull request as ready for review February 28, 2024 09:14
@llvmbot llvmbot added the lldb label Feb 28, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 28, 2024

@llvm/pr-subscribers-lldb

Author: Sudharsan Veeravalli (svs-quic)

Changes

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


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

1 Files Affected:

  • (modified) lldb/source/Symbol/Variable.cpp (+5-3)
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());
         }
       }

@Michael137
Copy link
Member

Michael137 commented Feb 28, 2024

Change itself is fine. But could you please add a test in lldb/test/API/functionalities/completion/TestCompletion.py? Specifically in do_test_variable_completion

Copy link

github-actions bot commented Feb 28, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@svs-quic
Copy link
Contributor Author

Change itself is fine. But could you please add a test in lldb/test/API/functionalities/completion/TestCompletion.py? Specifically in do_test_variable_completion

Done

Copy link
Member

@Michael137 Michael137 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm thanks!

@svs-quic
Copy link
Contributor Author

lgtm thanks!

Thanks. I dont think I have commit access . Would you be able to merge this for me?

@Michael137 Michael137 merged commit de55188 into llvm:main Feb 29, 2024
Copy link

@svs-quic Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may recieve a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

self.complete_from_to(f"{command} fooo.dd", f"{command} fooo.dd")

self.complete_from_to(f"{command} ptr_fooo->", f"{command} ptr_fooo->")
self.complete_from_to(f"{command} ptr_fooo->", f"{command} ptr_fooo->t")
self.complete_from_to(f"{command} ptr_fooo->t", f"{command} ptr_fooo->t.x")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been ptr_fooo->t.

Will fix this in a follow up patch

@svs-quic svs-quic deleted the lldb-tabcrash branch February 29, 2024 10:45
svs-quic added a commit to svs-quic/llvm-project that referenced this pull request Feb 29, 2024
Michael137 pushed a commit that referenced this pull request Feb 29, 2024
Missed adding a . in the test check
Michael137 added a commit to Michael137/llvm-project that referenced this pull request Mar 7, 2024
…3234)

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 [llvm#81536](llvm#81536)

---------

Co-authored-by: Michael Buch <[email protected]>
(cherry picked from commit de55188)
Michael137 pushed a commit to Michael137/llvm-project that referenced this pull request Mar 7, 2024
Missed adding a . in the test check

(cherry picked from commit ee297a7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lldb crashes when using tab completion.
3 participants