124 lines · python
1"""2Test lldb-dap setBreakpoints request3"""4 5 6import dap_server7from lldbsuite.test.decorators import *8from lldbsuite.test.lldbtest import *9from lldbsuite.test import lldbutil10import lldbdap_testcase11 12 13class TestDAP_step(lldbdap_testcase.DAPTestCaseBase):14 @skipIfWindows15 def test_step(self):16 """17 Tests the stepping in/out/over in threads.18 """19 program = self.getBuildArtifact("a.out")20 self.build_and_launch(program)21 source = "main.cpp"22 # source_path = os.path.join(os.getcwd(), source)23 breakpoint1_line = line_number(source, "// breakpoint 1")24 lines = [breakpoint1_line]25 # Set breakpoint in the thread function so we can step the threads26 breakpoint_ids = self.set_source_breakpoints(source, lines)27 self.assertEqual(28 len(breakpoint_ids), len(lines), "expect correct number of breakpoints"29 )30 self.continue_to_breakpoints(breakpoint_ids)31 threads = self.dap_server.get_threads()32 for thread in threads:33 if "reason" in thread:34 reason = thread["reason"]35 if reason == "breakpoint":36 # We have a thread that is stopped at our breakpoint.37 # Get the value of "x" and get the source file and line.38 # These will help us determine if we are stepping39 # correctly. If we step a thread correctly we will verify40 # the correct falue for x as it progresses through the41 # program.42 tid = thread["id"]43 x1 = self.get_local_as_int("x", threadId=tid)44 (src1, line1) = self.get_source_and_line(threadId=tid)45 46 # Now step into the "recurse()" function call again and47 # verify, using the new value of "x" and the source file48 # and line if we stepped correctly49 self.stepIn(threadId=tid, waitForStop=True)50 x2 = self.get_local_as_int("x", threadId=tid)51 (src2, line2) = self.get_source_and_line(threadId=tid)52 self.assertEqual(x1, x2 + 1, "verify step in variable")53 self.assertLess(line2, line1, "verify step in line")54 self.assertEqual(src1, src2, "verify step in source")55 56 # Now step out and verify57 self.stepOut(threadId=tid, waitForStop=True)58 x3 = self.get_local_as_int("x", threadId=tid)59 (src3, line3) = self.get_source_and_line(threadId=tid)60 self.assertEqual(x1, x3, "verify step out variable")61 self.assertGreaterEqual(line3, line1, "verify step out line")62 self.assertEqual(src1, src3, "verify step in source")63 64 # Step over and verify65 self.stepOver(threadId=tid, waitForStop=True)66 x4 = self.get_local_as_int("x", threadId=tid)67 (src4, line4) = self.get_source_and_line(threadId=tid)68 self.assertEqual(x4, x3, "verify step over variable")69 self.assertGreater(line4, line3, "verify step over line")70 self.assertEqual(src1, src4, "verify step over source")71 72 # Step a single assembly instruction.73 # Unfortunately, there is no portable way to verify the correct74 # stepping behavior here, because the generated assembly code75 # depends highly on the compiler, its version, the operating76 # system, and many more factors.77 self.stepOver(78 threadId=tid, waitForStop=True, granularity="instruction"79 )80 self.stepIn(81 threadId=tid, waitForStop=True, granularity="instruction"82 )83 84 # only step one thread that is at the breakpoint and stop85 break86 87 def test_step_over_inlined_function(self):88 """89 Test stepping over when the program counter is in another file.90 """91 program = self.getBuildArtifact("a.out")92 self.build_and_launch(program)93 source = "main.cpp"94 breakpoint_lines = [line_number(source, "// breakpoint 2")]95 step_over_pos = line_number(source, "// position_after_step_over")96 breakpoint_ids = self.set_source_breakpoints(source, breakpoint_lines)97 self.assertEqual(98 len(breakpoint_ids),99 len(breakpoint_lines),100 "expect correct number of breakpoints.",101 )102 self.continue_to_breakpoints(breakpoint_ids)103 104 thread_id = self.dap_server.get_thread_id()105 self.stepOver(thread_id)106 levels = 1107 frames = self.get_stackFrames(thread_id, 0, levels)108 self.assertEqual(len(frames), levels, "expect current number of frame levels.")109 top_frame = frames[0]110 self.assertEqual(111 top_frame["source"]["name"], source, "expect we are in the same file."112 )113 self.assertTrue(114 top_frame["source"]["path"].endswith(source),115 f"expect path ending with '{source}'.",116 )117 self.assertEqual(118 top_frame["line"],119 step_over_pos,120 f"expect step_over on line {step_over_pos}",121 )122 123 self.continue_to_exit()124