Skip to content

Commit 91de136

Browse files
authored
Merge pull request #6389 from apple/dwim-print-cherries
[lldb] Cherry pick dwim-print updates
2 parents 9e08f24 + b981228 commit 91de136

File tree

10 files changed

+88
-54
lines changed

10 files changed

+88
-54
lines changed

lldb/source/Commands/CommandObjectDWIMPrint.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ CommandObjectDWIMPrint::CommandObjectDWIMPrint(CommandInterpreter &interpreter)
3232
"Print a variable or expression.",
3333
"dwim-print [<variable-name> | <expression>]",
3434
eCommandProcessMustBePaused | eCommandTryTargetAPILock) {
35+
36+
CommandArgumentData var_name_arg(eArgTypeVarName, eArgRepeatPlain);
37+
m_arguments.push_back({var_name_arg});
38+
3539
m_option_group.Append(&m_format_options,
3640
OptionGroupFormat::OPTION_GROUP_FORMAT |
3741
OptionGroupFormat::OPTION_GROUP_GDB_FMT,
@@ -44,6 +48,13 @@ CommandObjectDWIMPrint::CommandObjectDWIMPrint(CommandInterpreter &interpreter)
4448

4549
Options *CommandObjectDWIMPrint::GetOptions() { return &m_option_group; }
4650

51+
void CommandObjectDWIMPrint::HandleArgumentCompletion(
52+
CompletionRequest &request, OptionElementVector &opt_element_vector) {
53+
CommandCompletions::InvokeCommonCompletionCallbacks(
54+
GetCommandInterpreter(), CommandCompletions::eVariablePathCompletion,
55+
request, nullptr);
56+
}
57+
4758
bool CommandObjectDWIMPrint::DoExecute(StringRef command,
4859
CommandReturnObject &result) {
4960
m_option_group.NotifyOptionParsingStarting(&m_exe_ctx);

lldb/source/Commands/CommandObjectDWIMPrint.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ class CommandObjectDWIMPrint : public CommandObjectRaw {
3737

3838
Options *GetOptions() override;
3939

40+
bool WantsCompletion() override { return true; }
41+
42+
void
43+
HandleArgumentCompletion(CompletionRequest &request,
44+
OptionElementVector &opt_element_vector) override;
45+
4046
private:
4147
bool DoExecute(llvm::StringRef command, CommandReturnObject &result) override;
4248

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,24 +412,21 @@ void CommandInterpreter::Initialize() {
412412

413413
alias_arguments_vector_sp = std::make_shared<OptionArgVector>();
414414

415-
cmd_obj_sp = GetCommandSPExact("expression");
415+
cmd_obj_sp = GetCommandSPExact("dwim-print");
416416
if (cmd_obj_sp) {
417417
AddAlias("p", cmd_obj_sp, "--")->SetHelpLong("");
418418
AddAlias("print", cmd_obj_sp, "--")->SetHelpLong("");
419-
AddAlias("call", cmd_obj_sp, "--")->SetHelpLong("");
420419
if (auto *po = AddAlias("po", cmd_obj_sp, "-O --")) {
421420
po->SetHelp("Evaluate an expression on the current thread. Displays any "
422421
"returned value with formatting "
423422
"controlled by the type's author.");
424423
po->SetHelpLong("");
425424
}
425+
}
426426

427-
#ifdef LLDB_ENABLE_SWIFT
428-
// FIXME: Upstream the REPL command together with support for a default
429-
// language, similar to what exists for scripting.
430-
AddAlias("repl", cmd_obj_sp, "--repl --language swift -- ");
431-
#endif
432-
427+
cmd_obj_sp = GetCommandSPExact("expression");
428+
if (cmd_obj_sp) {
429+
AddAlias("call", cmd_obj_sp, "--")->SetHelpLong("");
433430
CommandAlias *parray_alias =
434431
AddAlias("parray", cmd_obj_sp, "--element-count %1 --");
435432
if (parray_alias) {
@@ -447,6 +444,12 @@ void CommandInterpreter::Initialize() {
447444
"objects in memory, and will call po on them.");
448445
poarray_alias->SetHelpLong("");
449446
}
447+
448+
#ifdef LLDB_ENABLE_SWIFT
449+
// FIXME: Upstream the REPL command together with support for a default
450+
// language, similar to what exists for scripting.
451+
AddAlias("repl", cmd_obj_sp, "--repl --language swift -- ");
452+
#endif
450453
}
451454

452455
cmd_obj_sp = GetCommandSPExact("platform shell");

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

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,42 +36,55 @@ def test_de(self):
3636

3737
def test_frame_variable(self):
3838
self.build()
39-
self.main_source = "main.cpp"
40-
self.main_source_spec = lldb.SBFileSpec(self.main_source)
4139

42-
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
43-
'// Break here', self.main_source_spec)
40+
_, process, _, _ = lldbutil.run_to_source_breakpoint(
41+
self, '// Break here', lldb.SBFileSpec("main.cpp"))
4442
self.assertState(process.GetState(), lldb.eStateStopped)
4543

4644
# Since CommandInterpreter has been corrected to update the current execution
4745
# context at the beginning of HandleCompletion, we're here explicitly testing
4846
# the scenario where "frame var" is completed without any preceding commands.
47+
self.do_test_variable_completion('frame variable')
4948

50-
self.complete_from_to('frame variable fo',
51-
'frame variable fooo')
52-
self.complete_from_to('frame variable fooo.',
53-
'frame variable fooo.')
54-
self.complete_from_to('frame variable fooo.dd',
55-
'frame variable fooo.dd')
56-
57-
self.complete_from_to('frame variable ptr_fooo->',
58-
'frame variable ptr_fooo->')
59-
self.complete_from_to('frame variable ptr_fooo->dd',
60-
'frame variable ptr_fooo->dd')
61-
62-
self.complete_from_to('frame variable cont',
63-
'frame variable container')
64-
self.complete_from_to('frame variable container.',
65-
'frame variable container.MemberVar')
66-
self.complete_from_to('frame variable container.Mem',
67-
'frame variable container.MemberVar')
68-
69-
self.complete_from_to('frame variable ptr_cont',
70-
'frame variable ptr_container')
71-
self.complete_from_to('frame variable ptr_container->',
72-
'frame variable ptr_container->MemberVar')
73-
self.complete_from_to('frame variable ptr_container->Mem',
74-
'frame variable ptr_container->MemberVar')
49+
def test_dwim_print(self):
50+
self.build()
51+
52+
_, process, _, _ = lldbutil.run_to_source_breakpoint(
53+
self, '// Break here', lldb.SBFileSpec("main.cpp"))
54+
self.assertState(process.GetState(), lldb.eStateStopped)
55+
56+
# Since CommandInterpreter has been corrected to update the current execution
57+
# context at the beginning of HandleCompletion, we're here explicitly testing
58+
# the scenario where "frame var" is completed without any preceding commands.
59+
self.do_test_variable_completion('dwim-print')
60+
61+
62+
def do_test_variable_completion(self, command):
63+
self.complete_from_to(f'{command} fo',
64+
f'{command} fooo')
65+
self.complete_from_to(f'{command} fooo.',
66+
f'{command} fooo.')
67+
self.complete_from_to(f'{command} fooo.dd',
68+
f'{command} fooo.dd')
69+
70+
self.complete_from_to(f'{command} ptr_fooo->',
71+
f'{command} ptr_fooo->')
72+
self.complete_from_to(f'{command} ptr_fooo->dd',
73+
f'{command} ptr_fooo->dd')
74+
75+
self.complete_from_to(f'{command} cont',
76+
f'{command} container')
77+
self.complete_from_to(f'{command} container.',
78+
f'{command} container.MemberVar')
79+
self.complete_from_to(f'{command} container.Mem',
80+
f'{command} container.MemberVar')
81+
82+
self.complete_from_to(f'{command} ptr_cont',
83+
f'{command} ptr_container')
84+
self.complete_from_to(f'{command} ptr_container->',
85+
f'{command} ptr_container->MemberVar')
86+
self.complete_from_to(f'{command} ptr_container->Mem',
87+
f'{command} ptr_container->MemberVar')
7588

7689
def test_process_attach_dash_dash_con(self):
7790
"""Test that 'process attach --con' completes to 'process attach --continue '."""

lldb/test/API/lang/swift/clangimporter/hard_macro_conflict/TestSwiftHardMacroConflict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test(self):
3535
process.Continue()
3636
threads = lldbutil.get_threads_stopped_at_breakpoint(
3737
process, b_breakpoint)
38-
self.expect("p foo", error=True)
38+
self.expect("expression foo", error=True)
3939

4040
per_module_fallback = 0
4141
import io

lldb/test/API/lang/swift/clangimporter/objcmain_conflicting_dylibs_bridging_headers/TestSwiftObjCMainConflictingDylibsBridgingHeader.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ def test(self):
3838

3939

4040
self.expect("fr var bar", "expected result", substrs=["42"])
41-
self.expect("p bar", "expected result", substrs=["$R0", "42"])
42-
self.expect("p $R0", "expected result", substrs=["$R1", "42"])
43-
self.expect("p $R1", "expected result", substrs=["$R2", "42"])
41+
self.expect("expression bar", "expected result", substrs=["$R0", "42"])
42+
self.expect("expression $R0", "expected result", substrs=["$R1", "42"])
43+
self.expect("expression $R1", "expected result", substrs=["$R2", "42"])
4444

4545
foo_breakpoint = target.BreakpointCreateBySourceRegex(
4646
'break here', lldb.SBFileSpec('Foo.swift'))
4747
process.Continue()
4848
self.expect("fr var foo", "expected result", substrs=["23"])
49-
self.expect("p foo", "expected result", substrs=["$R3", "23"])
50-
self.expect("p $R3", "expected result", substrs=["23"])
51-
self.expect("p $R4", "expected result", substrs=["23"])
49+
self.expect("expression foo", "expected result", substrs=["$R3", "23"])
50+
self.expect("expression $R3", "expected result", substrs=["23"])
51+
self.expect("expression $R4", "expected result", substrs=["23"])

lldb/test/API/lang/swift/clangimporter/rewrite_clang_paths/TestSwiftRewriteClangPaths.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ def dotest(self, remap):
8282

8383
if remap:
8484
comment = "returns correct value"
85-
self.expect("p foo", comment, substrs=["x", "23"])
86-
self.expect("p bar", comment, substrs=["y", "42"])
85+
self.expect("expression foo", comment, substrs=["x", "23"])
86+
self.expect("expression bar", comment, substrs=["y", "42"])
8787
self.expect("fr var foo", comment, substrs=["x", "23"])
8888
self.expect("fr var bar", comment, substrs=["y", "42"])
8989
self.assertTrue(os.path.isdir(mod_cache), "module cache exists")
9090
else:
91-
self.expect("p foo", error=True)
91+
self.expect("expression foo", error=True)
9292

9393
# Scan through the types log.
9494
errs = 0

lldb/test/API/lang/swift/parseable_interfaces/dsym/TestSwiftInterfaceDsym.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_sanity_negative(self):
114114
# prints the type *name*.
115115
self.assertEqual(var.GetTypeName(), "AA.MyPoint")
116116
# Evaluating an expression fails, though.
117-
self.expect("p x", error=1)
117+
self.expect("expression x", error=1)
118118

119119
@swiftTest
120120
@skipIf(archs=no_match("x86_64"))
@@ -153,7 +153,7 @@ def test_sanity_positive(self):
153153

154154
# The expression evaluator sees the whole program, so it also
155155
# sees the private members.
156-
self.expect("p x", substrs=["x = 10"])
156+
self.expect("expression x", substrs=["x = 10"])
157157
# FIXME: this doesn't work, the summary/value is null/null.
158158
#lldbutil.check_expression(
159159
# self, frame, "x", "x = 10", use_summary=False)
@@ -168,5 +168,5 @@ def test_sanity_positive(self):
168168
# MyPoint.x is private and we should still see it.
169169
child_x = var.GetChildMemberWithName("x")
170170
lldbutil.check_variable(self, child_x, value="10")
171-
self.expect("p self", substrs=["x = 10"])
171+
self.expect("expression self", substrs=["x = 10"])
172172

lldb/test/API/lang/swift/private_discriminator/TestSwiftPrivateDiscriminator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def test(self):
2828
self.expect("e --bind-generic-types true -- self", error=True, substrs=["Hint"])
2929
# This should work because expression evaluation automatically falls back
3030
# to not binding generic parameters.
31-
self.expect("p self", substrs=['Generic', '<T>', 'n', '23'])
31+
self.expect("expression self", substrs=['Generic', '<T>', 'n', '23'])
3232

3333
process.Continue()
3434
# This should work.
3535
self.expect("frame var -d run -- visible",
3636
substrs=['Generic.Visible', 'n', '42'])
37-
self.expect("p visible", substrs=['Generic.Visible', 'n', '42'])
37+
self.expect("expression visible", substrs=['Generic.Visible', 'n', '42'])

lldb/tools/lldb-vscode/lldb-vscode.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,8 +1062,9 @@ void request_completions(const llvm::json::Object &request) {
10621062
text = text.substr(1);
10631063
actual_column--;
10641064
} else {
1065-
text = "p " + text;
1066-
actual_column += 2;
1065+
char command[] = "expression -- ";
1066+
text = command + text;
1067+
actual_column += strlen(command);
10671068
}
10681069
lldb::SBStringList matches;
10691070
lldb::SBStringList descriptions;

0 commit comments

Comments
 (0)