Skip to content

Commit eaa0e34

Browse files
authored
Merge pull request #8350 from Michael137/bugfix/lldb-tab-completion-crash-to-20230725
[cherry-pick][stable/20230725] [LLDB] Fix crash when using tab completion on class variables 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. (cherry picked from commit de55188)
2 parents 0f7e2fa + 73975fd commit eaa0e34

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

lldb/source/Symbol/Variable.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,15 +509,17 @@ static void PrivateAutoCompleteMembers(
509509
CompilerType member_compiler_type = compiler_type.GetFieldAtIndex(
510510
i, member_name, nullptr, nullptr, nullptr);
511511

512-
if (partial_member_name.empty() ||
513-
llvm::StringRef(member_name).startswith(partial_member_name)) {
512+
if (partial_member_name.empty()) {
513+
request.AddCompletion((prefix_path + member_name).str());
514+
} else if (llvm::StringRef(member_name)
515+
.startswith(partial_member_name)) {
514516
if (member_name == partial_member_name) {
515517
PrivateAutoComplete(
516518
frame, partial_path,
517519
prefix_path + member_name, // Anything that has been resolved
518520
// already will be in here
519521
member_compiler_type.GetCanonicalType(), request);
520-
} else {
522+
} else if (partial_path.empty()) {
521523
request.AddCompletion((prefix_path + member_name).str());
522524
}
523525
}

lldb/test/API/functionalities/completion/TestCompletion.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ def test_dwim_print(self):
6060

6161
def do_test_variable_completion(self, command):
6262
self.complete_from_to(f"{command} fo", f"{command} fooo")
63-
self.complete_from_to(f"{command} fooo.", f"{command} fooo.")
63+
self.complete_from_to(f"{command} fooo.", f"{command} fooo.t")
64+
self.complete_from_to(f"{command} fooo.t.", f"{command} fooo.t.x")
6465
self.complete_from_to(f"{command} fooo.dd", f"{command} fooo.dd")
6566

66-
self.complete_from_to(f"{command} ptr_fooo->", f"{command} ptr_fooo->")
67+
self.complete_from_to(f"{command} ptr_fooo->", f"{command} ptr_fooo->t")
68+
self.complete_from_to(f"{command} ptr_fooo->t.", f"{command} ptr_fooo->t.x")
6769
self.complete_from_to(f"{command} ptr_fooo->dd", f"{command} ptr_fooo->dd")
6870

6971
self.complete_from_to(f"{command} cont", f"{command} container")

lldb/test/API/functionalities/completion/main.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
#include <iostream>
22

3+
class Baz {
4+
public:
5+
int x;
6+
};
7+
38
class Foo
49
{
510
public:
6-
int Bar(int x, int y)
7-
{
8-
return x + y;
9-
}
11+
Baz t;
12+
int temp;
13+
14+
int Bar(int x, int y) { return x + y; }
1015
};
1116

1217
namespace { int Quux (void) { return 0; } }

0 commit comments

Comments
 (0)