94 lines · python
1"""2Test lldb-dap disassemble request3"""4 5from lldbsuite.test.decorators import skipIfWindows6from lldbsuite.test.lldbtest import line_number7import lldbdap_testcase8 9 10class TestDAP_disassemble(lldbdap_testcase.DAPTestCaseBase):11 @skipIfWindows12 def test_disassemble(self):13 """14 Tests the 'disassemble' request.15 """16 program = self.getBuildArtifact("a.out")17 self.build_and_launch(program)18 source = "main.c"19 bp_line_no = line_number(source, "// breakpoint 1")20 self.set_source_breakpoints(source, [bp_line_no])21 self.continue_to_next_stop()22 23 insts_with_bp, pc_with_bp_assembly = self.disassemble(frameIndex=0)24 self.assertIn("location", pc_with_bp_assembly, "Source location missing.")25 self.assertEqual(26 pc_with_bp_assembly["line"], bp_line_no, "Expects the same line number"27 )28 no_bp = self.set_source_breakpoints(source, [])29 self.assertEqual(len(no_bp), 0, "Expects no breakpoints.")30 self.assertIn(31 "instruction", pc_with_bp_assembly, "Assembly instruction missing."32 )33 34 insts_no_bp, pc_no_bp_assembly = self.disassemble(frameIndex=0)35 self.assertIn("location", pc_no_bp_assembly, "Source location missing.")36 self.assertEqual(37 pc_with_bp_assembly["line"], bp_line_no, "Expects the same line number"38 )39 # the disassembly instructions should be the same with breakpoint and no breakpoint;40 self.assertDictEqual(41 insts_with_bp,42 insts_no_bp,43 "Expects instructions are the same after removing breakpoints.",44 )45 self.assertIn("instruction", pc_no_bp_assembly, "Assembly instruction missing.")46 47 self.continue_to_exit()48 49 @skipIfWindows50 def test_disassemble_backwards(self):51 """52 Tests the 'disassemble' request with a backwards disassembly range.53 """54 program = self.getBuildArtifact("a.out")55 self.build_and_launch(program)56 source = "main.c"57 self.set_source_breakpoints(source, [line_number(source, "// breakpoint 1")])58 self.continue_to_next_stop()59 60 instruction_pointer_reference = self.get_stackFrames()[1][61 "instructionPointerReference"62 ]63 backwards_instructions = 20064 instructions_count = 40065 instructions = self.dap_server.request_disassemble(66 memoryReference=instruction_pointer_reference,67 instructionOffset=-backwards_instructions,68 instructionCount=instructions_count,69 )70 71 self.assertEqual(72 len(instructions),73 instructions_count,74 "Disassemble request should return the exact requested number of instructions.",75 )76 77 frame_instruction_index = next(78 (79 i80 for i, instruction in enumerate(instructions)81 if instruction["address"] == instruction_pointer_reference82 ),83 -1,84 )85 self.assertEqual(86 frame_instruction_index,87 backwards_instructions,88 f"requested instruction should be preceeded by {backwards_instructions} instructions. Actual index: {frame_instruction_index}",89 )90 91 # clear breakpoints92 self.set_source_breakpoints(source, [])93 self.continue_to_exit()94