Skip to content

Commit 88636f0

Browse files
authored
[lldb] Fix handling of addresses given to swift task commands (swiftlang#11314)
The DIL implementation of `GetValueForVariableExpressionPath` succeeds when the "variable expression path" is an integer. This code expected the old behavior, where `GetValueForVariableExpressionPath` would fail for an integer value. The fix is to try parsing the command arg as an address first (instead of as a fallback). If the command arg does not parse as an address, then it is tried as a variable expression path. rdar://159531040
1 parent 11ae0c8 commit 88636f0

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,27 +2175,28 @@ ThreadForLiveTaskArgument(Args &command, ExecutionContext &exe_ctx) {
21752175

21762176
StringRef arg = command[0].ref();
21772177

2178-
StackFrame &frame = exe_ctx.GetFrameRef();
2179-
uint32_t path_options =
2180-
StackFrame::eExpressionPathOptionsAllowDirectIVarAccess;
2181-
VariableSP var_sp;
2182-
Status status;
2183-
ValueObjectSP valobj_sp = frame.GetValueForVariableExpressionPath(
2184-
arg, eDynamicDontRunTarget, path_options, var_sp, status);
2185-
21862178
addr_t task_ptr = LLDB_INVALID_ADDRESS;
2187-
if (status.Success() && valobj_sp) {
2188-
if (auto task_obj_sp = valobj_sp->GetChildMemberWithName("_task"))
2189-
task_ptr = task_obj_sp->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
2190-
if (task_ptr == LLDB_INVALID_ADDRESS)
2191-
return llvm::createStringError("failed to access Task pointer");
2192-
} else {
2193-
// The argument is not a valid variable expression, try parsing it as a
2194-
// (task) address.
2195-
if (arg.getAsInteger(0, task_ptr))
2179+
// First try the arg as a task address.
2180+
bool not_addr = arg.getAsInteger(0, task_ptr);
2181+
if (not_addr) {
2182+
StackFrame &frame = exe_ctx.GetFrameRef();
2183+
uint32_t path_options =
2184+
StackFrame::eExpressionPathOptionsAllowDirectIVarAccess;
2185+
VariableSP var_sp;
2186+
Status status;
2187+
ValueObjectSP valobj_sp = frame.GetValueForVariableExpressionPath(
2188+
arg, eDynamicDontRunTarget, path_options, var_sp, status);
2189+
if (!status.Success())
21962190
return status.takeError();
2191+
2192+
if (valobj_sp)
2193+
if (auto task_obj_sp = valobj_sp->GetChildMemberWithName("_task"))
2194+
task_ptr = task_obj_sp->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
21972195
}
21982196

2197+
if (task_ptr == 0 || task_ptr == LLDB_INVALID_ADDRESS)
2198+
return llvm::createStringError("failed to access Task pointer");
2199+
21992200
if (auto *runtime = SwiftLanguageRuntime::Get(exe_ctx.GetProcessSP()))
22002201
if (auto reflection_ctx = runtime->GetReflectionContext()) {
22012202
auto task_info = reflection_ctx->asyncTaskInfo(task_ptr);

lldb/test/API/lang/swift/async/tasks/TestSwiftTaskBacktrace.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
class TestCase(TestBase):
77

8-
@skipIf(bugnumber="rdar://159531040")
98
@swiftTest
109
def test_backtrace_task_variable(self):
1110
self.build()
@@ -14,7 +13,6 @@ def test_backtrace_task_variable(self):
1413
)
1514
self.do_backtrace("task")
1615

17-
@skipIf(bugnumber="rdar://159531040")
1816
@swiftTest
1917
def test_backtrace_task_address(self):
2018
self.build()
@@ -33,6 +31,6 @@ def do_backtrace(self, arg):
3331
".sleep(",
3432
"`second() at main.swift:6",
3533
"`first() at main.swift:2",
36-
"`closure #1 in static Main.main() at main.swift:12:19",
34+
"`closure #1 in static Main.main() at main.swift:12",
3735
],
3836
)

lldb/test/API/lang/swift/async/tasks/TestSwiftTaskSelect.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from lldbsuite.test.lldbtest import TestBase
44
import lldbsuite.test.lldbutil as lldbutil
55

6-
@skipIf(bugnumber="rdar://159531153")
76
class TestCase(TestBase):
87

98
@swiftTest
@@ -31,9 +30,9 @@ def do_backtrace_selected_task(self, arg):
3130
"thread backtrace",
3231
substrs=[
3332
".sleep(",
34-
"`second() at main.swift:6:",
35-
"`first() at main.swift:2:",
36-
"`closure #1 in static Main.main() at main.swift:12:",
33+
"`second() at main.swift:6",
34+
"`first() at main.swift:2",
35+
"`closure #1 in static Main.main() at main.swift:12",
3736
],
3837
)
3938

0 commit comments

Comments
 (0)