This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Prevent crash when completing ambiguous subcommands
ClosedPublic

Authored by JDevlieghere on Jul 6 2023, 12:25 PM.

Details

Summary

Fix a crash when trying to complete an ambiguous subcommand. Take set s tar for example: here s is ambiguous between set and show. Pressing TAB after this input currently crashes LLDB because we go look for the subcommand and fail to find one, but still add the original command (s) as a completion. This causes problems later on when we're trying to insert the completion and find that the "completed string" is shorter than the input string and call std::string::substr to eliminate the common prefix.

frame #12: 0x0000000133fafb44 liblldb.17.0.0git.dylib`lldb_private::Editline::TabCommand(this=0x000000010a645aa0, ch=9) at Editline.cpp:1044:24
   1041   std::string longest_prefix = completions.LongestCommonPrefix();
   1042   if (!longest_prefix.empty())
   1043     longest_prefix =
-> 1044         longest_prefix.substr(request.GetCursorArgumentPrefix().size());
(lldb) v longest_prefix
(std::string) longest_prefix = "s"
(lldb) p request.GetCursorArgumentPrefix().size()
(size_t) 3

rdar://111848598

Diff Detail

Event Timeline

JDevlieghere created this revision.Jul 6 2023, 12:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2023, 12:25 PM
JDevlieghere requested review of this revision.Jul 6 2023, 12:25 PM
jingham accepted this revision.Jul 10 2023, 1:56 PM

This looks like it might be the place where we also say "set s could either be set or show". But that's actually done elsewhere so this change is okay. We should maybe make sure we have a test for setting s<TAB> -> {set or show} options.

This revision is now accepted and ready to land.Jul 10 2023, 1:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 10 2023, 2:50 PM