From ff371a918fb5a06161a6e1c14140c567ff23dd96 Mon Sep 17 00:00:00 2001 From: dianqk Date: Sat, 29 Jul 2023 21:22:13 +0800 Subject: [PATCH] [lldb] If the function cannot be found, use the symbol to get instructions. --- .../task-switch/TestSwiftTaskSwitch.py | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lldb/test/API/lang/swift/async/stepping/step-in/task-switch/TestSwiftTaskSwitch.py b/lldb/test/API/lang/swift/async/stepping/step-in/task-switch/TestSwiftTaskSwitch.py index 0b41c8e8fad94..551431e2e7d63 100644 --- a/lldb/test/API/lang/swift/async/stepping/step-in/task-switch/TestSwiftTaskSwitch.py +++ b/lldb/test/API/lang/swift/async/stepping/step-in/task-switch/TestSwiftTaskSwitch.py @@ -15,11 +15,25 @@ def test(self): target, _, thread, _ = lldbutil.run_to_source_breakpoint(self, "await f()", src) self.assertEqual(thread.frame[0].function.mangled, "$s1a5entryO4mainyyYaFZ") - function = target.FindFunctions("$s1a5entryO4mainyyYaFZTQ0_")[0].function - instructions = list(function.GetInstructions(target)) + sym_ctx_list = target.FindFunctions("$s1a5entryO4mainyyYaFZTQ0_", lldb.eFunctionNameTypeAuto) + self.assertEquals(sym_ctx_list.GetSize(), 1) + symbolContext = sym_ctx_list.GetContextAtIndex(0) + function = symbolContext.GetFunction() + if function: + instructions = list(function.GetInstructions(target)) + else: + symbol = symbolContext.GetSymbol() + self.assertIsNotNone(symbol) + instructions = list(symbol.GetInstructions(target)) # Expected to be a trampoline that tail calls `swift_task_switch`. - self.assertIn("swift_task_switch", instructions[-1].GetComment(target)) + for inst in reversed(instructions): + control_flow_kind = inst.GetControlFlowKind(target) + if control_flow_kind == lldb.eInstructionControlFlowKindOther: + continue + self.assertEqual(control_flow_kind, lldb.eInstructionControlFlowKindJump) + self.assertIn("swift_task_switch", inst.GetComment(target)) + break # Using the line table, build a set of the non-zero line numbers for # this this function - and verify that there is exactly one line.