|
| 1 | +import lldb |
| 2 | +from lldbsuite.test.decorators import * |
| 3 | +import lldbsuite.test.lldbtest as lldbtest |
| 4 | +import lldbsuite.test.lldbutil as lldbutil |
| 5 | +import os |
| 6 | +import platform |
| 7 | + |
| 8 | +class TestStepThroughAllocatingInit(lldbtest.TestBase): |
| 9 | + mydir = lldbtest.TestBase.compute_mydir(__file__) |
| 10 | + |
| 11 | + @swiftTest |
| 12 | + def test_swift_stepping_api(self): |
| 13 | + """Test that step in using the Python API steps through thunk.""" |
| 14 | + self.build() |
| 15 | + self.do_test(True) |
| 16 | + |
| 17 | + @swiftTest |
| 18 | + def test_swift_stepping_cli(self): |
| 19 | + """Same test with the cli - it goes a slightly different path than |
| 20 | + the API.""" |
| 21 | + self.build() |
| 22 | + self.do_test(False) |
| 23 | + |
| 24 | + def setUp(self): |
| 25 | + lldbtest.TestBase.setUp(self) |
| 26 | + self.main_source = "main.swift" |
| 27 | + self.main_source_spec = lldb.SBFileSpec(self.main_source) |
| 28 | + # If you are running against a debug swift you are going to |
| 29 | + # end up stepping into the stdlib and that will make stepping |
| 30 | + # tests impossible to write. So avoid that. |
| 31 | + |
| 32 | + if platform.system() == 'Darwin': |
| 33 | + lib_name = "libswiftCore.dylib" |
| 34 | + else: |
| 35 | + lib_name = "libswiftCore.so" |
| 36 | + |
| 37 | + self.dbg.HandleCommand( |
| 38 | + "settings set " |
| 39 | + "target.process.thread.step-avoid-libraries {}".format(lib_name)) |
| 40 | + |
| 41 | + def do_test(self, use_api): |
| 42 | + """Tests that we can step reliably in swift code.""" |
| 43 | + exe_name = "a.out" |
| 44 | + exe = self.getBuildArtifact(exe_name) |
| 45 | + |
| 46 | + target, process, thread, breakpoint = lldbutil.run_to_source_breakpoint(self, |
| 47 | + 'Break here to step into init', self.main_source_spec) |
| 48 | + |
| 49 | + # Step into the function. |
| 50 | + if use_api: |
| 51 | + thread.StepInto() |
| 52 | + else: |
| 53 | + self.runCmd("thread step-in") |
| 54 | + frame_0 = thread.frames[0] |
| 55 | + self.assertIn('Foo.init()', frame_0.GetFunctionName()) |
| 56 | + |
| 57 | + # Check that our parent frame is indeed allocating_init (otherwise we aren't |
| 58 | + # testing what we think we're testing... |
| 59 | + frame_1 = thread.frames[1] |
| 60 | + self.assertIn("allocating_init", frame_1.GetFunctionName()) |
| 61 | + |
| 62 | + # Step one line so some_string is initialized, make sure we can |
| 63 | + # get its value: |
| 64 | + thread.StepOver() |
| 65 | + frame_0 = thread.frames[0] |
| 66 | + self.assertIn('Foo.init()', frame_0.GetFunctionName()) |
| 67 | + var = frame_0.FindVariable("some_string") |
| 68 | + self.assertTrue(var.GetError().Success()) |
| 69 | + self.assertEqual(var.GetSummary(), '"foo"') |
| 70 | + |
| 71 | + # Now make sure that stepping out steps past the thunk: |
| 72 | + thread.StepOut() |
| 73 | + frame_0 = thread.frames[0] |
| 74 | + self.assertIn("doSomething", frame_0.GetFunctionName()) |
0 commit comments