Skip to content

Commit 13f838e

Browse files
committed
[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 (cherry picked from commit 88636f0) (cherry-picked from commit 329119d52e0004b1f73f71b01f819a05e06c4e7d)
1 parent f248919 commit 13f838e

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ def do_backtrace(self, arg):
3131
".sleep(",
3232
"`second() at main.swift:6",
3333
"`first() at main.swift:2",
34-
"`closure #1 in static Main.main() at main.swift:12:19",
34+
"`closure #1 in static Main.main() at main.swift:12",
3535
],
3636
)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def do_backtrace_selected_task(self, arg):
3131
"thread backtrace",
3232
substrs=[
3333
".sleep(",
34-
"`second() at main.swift:6:",
35-
"`first() at main.swift:2:",
36-
"`closure #1 in static Main.main() at main.swift:12:",
34+
"`second() at main.swift:6",
35+
"`first() at main.swift:2",
36+
"`closure #1 in static Main.main() at main.swift:12",
3737
],
3838
)
3939

0 commit comments

Comments
 (0)