100 lines · python
1from dap_server import Source2import shutil3from lldbsuite.test.decorators import *4from lldbsuite.test.lldbtest import *5from lldbsuite.test import lldbutil6import lldbdap_testcase7import os8import lldb9 10 11class TestDAP_InstructionBreakpointTestCase(lldbdap_testcase.DAPTestCaseBase):12 NO_DEBUG_INFO_TESTCASE = True13 14 def setUp(self):15 lldbdap_testcase.DAPTestCaseBase.setUp(self)16 17 self.main_basename = "main-copy.cpp"18 self.main_path = os.path.realpath(self.getBuildArtifact(self.main_basename))19 20 @skipIfWindows21 def test_instruction_breakpoint(self):22 self.build()23 self.instruction_breakpoint_test()24 25 def instruction_breakpoint_test(self):26 """Sample test to ensure SBFrame::Disassemble produces SOME output"""27 # Create a target by the debugger.28 target = self.createTestTarget()29 30 main_line = line_number("main.cpp", "breakpoint 1")31 32 program = self.getBuildArtifact("a.out")33 self.build_and_launch(program)34 35 # Set source breakpoint 136 response = self.dap_server.request_setBreakpoints(37 Source.build(path=self.main_path), [main_line]38 )39 breakpoints = response["body"]["breakpoints"]40 self.assertEqual(len(breakpoints), 1)41 breakpoint = breakpoints[0]42 self.assertEqual(43 breakpoint["line"], main_line, "incorrect breakpoint source line"44 )45 self.assertTrue(breakpoint["verified"], "breakpoint is not verified")46 self.assertEqual(47 self.main_basename, breakpoint["source"]["name"], "incorrect source name"48 )49 self.assertEqual(50 self.main_path, breakpoint["source"]["path"], "incorrect source file path"51 )52 other_breakpoint_id = breakpoint["id"]53 54 # Continue and then verifiy the breakpoint55 self.dap_server.request_continue()56 self.verify_breakpoint_hit([other_breakpoint_id])57 58 # now we check the stack trace making sure that we got mapped source paths59 frames = self.dap_server.request_stackTrace()["body"]["stackFrames"]60 intstructionPointerReference = []61 setIntstructionBreakpoints = []62 intstructionPointerReference.append(frames[0]["instructionPointerReference"])63 self.assertEqual(64 frames[0]["source"]["name"], self.main_basename, "incorrect source name"65 )66 self.assertEqual(67 frames[0]["source"]["path"], self.main_path, "incorrect source file path"68 )69 70 # Check disassembly view71 disassembled_instructions, instruction = self.disassemble(frameIndex=0)72 self.assertEqual(73 instruction["address"],74 intstructionPointerReference[0],75 "current breakpoint reference is not in the disaasembly view",76 )77 78 # Get next instruction address to set instruction breakpoint79 instruction_addr_list = list(disassembled_instructions.keys())80 index = instruction_addr_list.index(intstructionPointerReference[0])81 if len(instruction_addr_list) >= (index + 1):82 next_inst_addr = instruction_addr_list[index + 1]83 if len(next_inst_addr) > 2:84 setIntstructionBreakpoints.append(next_inst_addr)85 instruction_breakpoint_response = (86 self.dap_server.request_setInstructionBreakpoints(87 setIntstructionBreakpoints88 )89 )90 inst_breakpoints = instruction_breakpoint_response["body"][91 "breakpoints"92 ]93 self.assertEqual(94 inst_breakpoints[0]["instructionReference"],95 next_inst_addr,96 "Instruction breakpoint has not been resolved or failed to relocate the instruction breakpoint",97 )98 self.dap_server.request_continue()99 self.verify_breakpoint_hit([inst_breakpoints[0]["id"]])100