Skip to content

Commit 86fd4f5

Browse files
author
git apple-llvm automerger
committed
Merge commit '99f0b042a85c' from swift/release/6.1 into stable/20240723
2 parents be88cf9 + 99f0b04 commit 86fd4f5

File tree

6 files changed

+78
-27
lines changed

6 files changed

+78
-27
lines changed

lldb/source/Commands/CommandObjectDWIMPrint.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,24 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
153153
result.SetStatus(eReturnStatusSuccessFinishResult);
154154
};
155155

156-
// First, try `expr` as the name of a frame variable.
157-
if (frame) {
158-
auto valobj_sp = frame->FindVariable(ConstString(expr));
159-
if (valobj_sp && valobj_sp->GetError().Success()) {
156+
// First, try `expr` as a _limited_ frame variable expression path: only the
157+
// dot operator (`.`) is permitted for this case.
158+
//
159+
// This is limited to support only unambiguous expression paths. Of note,
160+
// expression paths are not attempted if the expression contain either the
161+
// arrow operator (`->`) or the subscript operator (`[]`). This is because
162+
// both operators can be overloaded in C++, and could result in ambiguity in
163+
// how the expression is handled. Additionally, `*` and `&` are not supported.
164+
const bool try_variable_path =
165+
expr.find_first_of("*&->[]") == StringRef::npos;
166+
if (frame && try_variable_path) {
167+
VariableSP var_sp;
168+
Status status;
169+
auto valobj_sp = frame->GetValueForVariableExpressionPath(
170+
expr, eval_options.GetUseDynamic(),
171+
StackFrame::eExpressionPathOptionsAllowDirectIVarAccess, var_sp,
172+
status);
173+
if (valobj_sp && status.Success() && valobj_sp->GetError().Success()) {
160174
if (!suppress_result) {
161175
if (auto persisted_valobj = valobj_sp->Persist())
162176
valobj_sp = persisted_valobj;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
C_SOURCES := main.c
1+
CXX_SOURCES := main.cpp
22

33
include Makefile.rules

lldb/test/API/commands/dwim-print/TestDWIMPrint.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def _run_cmd(self, cmd: str) -> str:
1616
self.ci.HandleCommand(cmd, result)
1717
return result.GetOutput().rstrip()
1818

19-
VAR_IDENT = re.compile(r"(?:\$\d+|\w+) = ")
19+
VAR_IDENT = re.compile(r"(?:\$\d+|[\w.]+) = ")
2020

2121
def _strip_result_var(self, string: str) -> str:
2222
"""
@@ -121,30 +121,39 @@ def test_empty_expression(self):
121121
def test_nested_values(self):
122122
"""Test dwim-print with nested values (structs, etc)."""
123123
self.build()
124-
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.c"))
124+
lldbutil.run_to_source_breakpoint(
125+
self, "break here", lldb.SBFileSpec("main.cpp")
126+
)
125127
self.runCmd("settings set auto-one-line-summaries false")
126128
self._expect_cmd(f"dwim-print s", "frame variable")
127129
self._expect_cmd(f"dwim-print (struct Structure)s", "expression")
128130

129131
def test_summary_strings(self):
130-
"""Test dwim-print with nested values (structs, etc)."""
132+
"""Test dwim-print with type summaries."""
131133
self.build()
132-
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.c"))
134+
lldbutil.run_to_source_breakpoint(
135+
self, "break here", lldb.SBFileSpec("main.cpp")
136+
)
133137
self.runCmd("settings set auto-one-line-summaries false")
134138
self.runCmd("type summary add -e -s 'stub summary' Structure")
135139
self._expect_cmd(f"dwim-print s", "frame variable")
136140
self._expect_cmd(f"dwim-print (struct Structure)s", "expression")
141+
self.runCmd("type summary delete Structure")
137142

138143
def test_void_result(self):
139144
"""Test dwim-print does not surface an error message for void expressions."""
140145
self.build()
141-
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.c"))
146+
lldbutil.run_to_source_breakpoint(
147+
self, "break here", lldb.SBFileSpec("main.cpp")
148+
)
142149
self.expect("dwim-print (void)15", matching=False, patterns=["(?i)error"])
143150

144151
def test_preserves_persistent_variables(self):
145152
"""Test dwim-print does not delete persistent variables."""
146153
self.build()
147-
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.c"))
154+
lldbutil.run_to_source_breakpoint(
155+
self, "break here", lldb.SBFileSpec("main.cpp")
156+
)
148157
self.expect("dwim-print int $i = 15")
149158
# Run the same expression twice and verify success. This ensures the
150159
# first command does not delete the persistent variable.
@@ -154,5 +163,25 @@ def test_preserves_persistent_variables(self):
154163
def test_missing_type(self):
155164
"""The expected output of po opaque is its address (no error)"""
156165
self.build()
157-
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.c"))
166+
lldbutil.run_to_source_breakpoint(
167+
self, "break here", lldb.SBFileSpec("main.cpp")
168+
)
158169
self.expect("dwim-print -O -- opaque", substrs=["0x"])
170+
171+
def test_variable_expression_path(self):
172+
"""Test dwim-print supports certain variable expression paths."""
173+
self.build()
174+
lldbutil.run_to_source_breakpoint(
175+
self, "break here", lldb.SBFileSpec("main.cpp")
176+
)
177+
self.runCmd("settings set auto-one-line-summaries false")
178+
self._expect_cmd("dwim-print w.s", "frame variable")
179+
self._expect_cmd("dwim-print wp->s", "expression")
180+
181+
def test_direct_child_access(self):
182+
"""Test dwim-print supports accessing members/ivars without qualification."""
183+
self.build()
184+
lldbutil.run_to_source_breakpoint(
185+
self, "break inside", lldb.SBFileSpec("main.cpp")
186+
)
187+
self._expect_cmd("dwim-print number", "frame variable")

lldb/test/API/commands/dwim-print/main.c

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
extern "C" int puts(const char *s);
2+
3+
struct Structure {
4+
int number = 30;
5+
void f() { puts("break inside"); }
6+
};
7+
8+
struct Wrapper {
9+
Structure s;
10+
};
11+
12+
struct Opaque;
13+
14+
int main(int argc, char **argv) {
15+
Structure s;
16+
Wrapper w;
17+
Wrapper *wp = &w;
18+
Opaque *opaque = (Opaque *)(void *)&s;
19+
puts("break here");
20+
s.f();
21+
return 0;
22+
}

lldb/test/API/lang/swift/expression/error_reporting/TestSwiftExpressionErrorReporting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ def check(value):
5656
substrs=['Missing type'])
5757

5858
process.Continue()
59-
self.expect('dwim-print -O -- number', error=True,
59+
self.expect('expression -O -- number', error=True,
6060
substrs=['self', 'not', 'found'])

0 commit comments

Comments
 (0)