kastiglione created this revision.
kastiglione added a reviewer: aprantl.
Herald added a project: All.
kastiglione requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
Enable completion of variables for `dwim-print` command.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D145124
Files:
lldb/source/Commands/CommandObjectDWIMPrint.cpp
lldb/source/Commands/CommandObjectDWIMPrint.h
lldb/test/API/functionalities/completion/TestCompletion.py
Index: lldb/test/API/functionalities/completion/TestCompletion.py
===================================================================
--- lldb/test/API/functionalities/completion/TestCompletion.py
+++ lldb/test/API/functionalities/completion/TestCompletion.py
@@ -36,42 +36,55 @@
def test_frame_variable(self):
self.build()
- self.main_source = "main.cpp"
- self.main_source_spec = lldb.SBFileSpec(self.main_source)
- (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
- '// Break here', self.main_source_spec)
+ _, process, _, _ = lldbutil.run_to_source_breakpoint(
+ self, '// Break here', lldb.SBFileSpec("main.cpp"))
self.assertState(process.GetState(), lldb.eStateStopped)
# Since CommandInterpreter has been corrected to update the current execution
# context at the beginning of HandleCompletion, we're here explicitly testing
# the scenario where "frame var" is completed without any preceding commands.
+ self.do_test_variable_completion('frame variable')
- self.complete_from_to('frame variable fo',
- 'frame variable fooo')
- self.complete_from_to('frame variable fooo.',
- 'frame variable fooo.')
- self.complete_from_to('frame variable fooo.dd',
- 'frame variable fooo.dd')
+ def test_dwim_print(self):
+ self.build()
- self.complete_from_to('frame variable ptr_fooo->',
- 'frame variable ptr_fooo->')
- self.complete_from_to('frame variable ptr_fooo->dd',
- 'frame variable ptr_fooo->dd')
+ _, process, _, _ = lldbutil.run_to_source_breakpoint(
+ self, '// Break here', lldb.SBFileSpec("main.cpp"))
+ self.assertState(process.GetState(), lldb.eStateStopped)
- self.complete_from_to('frame variable cont',
- 'frame variable container')
- self.complete_from_to('frame variable container.',
- 'frame variable container.MemberVar')
- self.complete_from_to('frame variable container.Mem',
- 'frame variable container.MemberVar')
+ # Since CommandInterpreter has been corrected to update the current execution
+ # context at the beginning of HandleCompletion, we're here explicitly testing
+ # the scenario where "frame var" is completed without any preceding commands.
+ self.do_test_variable_completion('dwim-print')
- self.complete_from_to('frame variable ptr_cont',
- 'frame variable ptr_container')
- self.complete_from_to('frame variable ptr_container->',
- 'frame variable ptr_container->MemberVar')
- self.complete_from_to('frame variable ptr_container->Mem',
- 'frame variable ptr_container->MemberVar')
+
+ def do_test_variable_completion(self, command):
+ self.complete_from_to(f'{command} fo',
+ f'{command} fooo')
+ self.complete_from_to(f'{command} fooo.',
+ f'{command} fooo.')
+ 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->dd',
+ f'{command} ptr_fooo->dd')
+
+ self.complete_from_to(f'{command} cont',
+ f'{command} container')
+ self.complete_from_to(f'{command} container.',
+ f'{command} container.MemberVar')
+ self.complete_from_to(f'{command} container.Mem',
+ f'{command} container.MemberVar')
+
+ self.complete_from_to(f'{command} ptr_cont',
+ f'{command} ptr_container')
+ self.complete_from_to(f'{command} ptr_container->',
+ f'{command} ptr_container->MemberVar')
+ self.complete_from_to(f'{command} ptr_container->Mem',
+ f'{command} ptr_container->MemberVar')
def test_process_attach_dash_dash_con(self):
"""Test that 'process attach --con' completes to 'process attach --continue '."""
Index: lldb/source/Commands/CommandObjectDWIMPrint.h
===================================================================
--- lldb/source/Commands/CommandObjectDWIMPrint.h
+++ lldb/source/Commands/CommandObjectDWIMPrint.h
@@ -37,6 +37,12 @@
Options *GetOptions() override;
+ bool WantsCompletion() override { return true; }
+
+ void
+ HandleArgumentCompletion(CompletionRequest &request,
+ OptionElementVector &opt_element_vector) override;
+
private:
bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override;
Index: lldb/source/Commands/CommandObjectDWIMPrint.cpp
===================================================================
--- lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -32,6 +32,10 @@
"Print a variable or expression.",
"dwim-print [<variable-name> | <expression>]",
eCommandProcessMustBePaused | eCommandTryTargetAPILock) {
+
+ CommandArgumentData var_name_arg(eArgTypeVarName, eArgRepeatPlain);
+ m_arguments.push_back({var_name_arg});
+
m_option_group.Append(&m_format_options,
OptionGroupFormat::OPTION_GROUP_FORMAT |
OptionGroupFormat::OPTION_GROUP_GDB_FMT,
@@ -44,6 +48,13 @@
Options *CommandObjectDWIMPrint::GetOptions() { return &m_option_group; }
+void CommandObjectDWIMPrint::HandleArgumentCompletion(
+ CompletionRequest &request, OptionElementVector &opt_element_vector) {
+ CommandCompletions::InvokeCommonCompletionCallbacks(
+ GetCommandInterpreter(), CommandCompletions::eVariablePathCompletion,
+ request, nullptr);
+}
+
bool CommandObjectDWIMPrint::DoExecute(StringRef command,
CommandReturnObject &result) {
m_option_group.NotifyOptionParsingStarting(&m_exe_ctx);
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits