llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Alexandre Perez (aperez)

<details>
<summary>Changes</summary>

Fix a crash when tab-completing arguments for parsed commands that have 
arguments but no options.

In `HandleArgumentCompletion`, `GetOptions()` returns `nullptr` when a command 
has no options defined. The code was dereferencing this pointer without a null 
check, causing a segfault when attempting tab completion.

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


2 Files Affected:

- (modified) lldb/source/Commands/CommandObjectCommands.cpp (+2-1) 
- (modified) lldb/test/API/commands/command/script/add/TestAddParsedCommand.py 
(+7) 


``````````diff
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp 
b/lldb/source/Commands/CommandObjectCommands.cpp
index a3293f0f7966d..70f6955507593 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -2037,7 +2037,8 @@ class CommandObjectScriptingObjectParsed : public 
CommandObjectParsed {
     // option_element_vector:
 
     Options *options = GetOptions();
-    auto defs = options->GetDefinitions();
+    auto defs = options ? options->GetDefinitions()
+                        : llvm::ArrayRef<OptionDefinition>();
 
     std::unordered_set<size_t> option_slots;
     for (const auto &elem : option_vec) {
diff --git a/lldb/test/API/commands/command/script/add/TestAddParsedCommand.py 
b/lldb/test/API/commands/command/script/add/TestAddParsedCommand.py
index 9deebe29eaae4..da150499a53a2 100644
--- a/lldb/test/API/commands/command/script/add/TestAddParsedCommand.py
+++ b/lldb/test/API/commands/command/script/add/TestAddParsedCommand.py
@@ -305,6 +305,13 @@ def cleanup():
         matches.AppendList(["answer ", "correct_answer"], 2)
         self.handle_completion(cmd_str, 1, matches, descriptions, False)
 
+        # Test completion for a command with arguments but NO options:
+        cmd_str = "one-arg-no-opt nonexistent_file_xyz"
+        matches.Clear()
+        descriptions.Clear()
+        matches.AppendString("")
+        self.handle_completion(cmd_str, 0, matches, descriptions, False)
+
         # Now make sure get_repeat_command works properly:
 
         # no-args turns off auto-repeat

``````````

</details>


https://github.com/llvm/llvm-project/pull/174868
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to