|
| 1 | +import dap_server |
| 2 | +import shutil |
| 3 | +from lldbsuite.test.decorators import * |
| 4 | +from lldbsuite.test.lldbtest import * |
| 5 | +from lldbsuite.test import lldbutil |
| 6 | +import lldbdap_testcase |
| 7 | +import os |
| 8 | +import lldb |
| 9 | + |
| 10 | + |
| 11 | +class TestDAP_InstructionBreakpointTestCase(lldbdap_testcase.DAPTestCaseBase): |
| 12 | + NO_DEBUG_INFO_TESTCASE = True |
| 13 | + |
| 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 | + def test_instruction_breakpoint(self): |
| 21 | + self.build() |
| 22 | + self.instruction_breakpoint_test() |
| 23 | + |
| 24 | + def instruction_breakpoint_test(self): |
| 25 | + """Sample test to ensure SBFrame::Disassemble produces SOME output""" |
| 26 | + # Create a target by the debugger. |
| 27 | + target = self.createTestTarget() |
| 28 | + |
| 29 | + main_line = line_number("main.cpp", "breakpoint 1") |
| 30 | + |
| 31 | + program = self.getBuildArtifact("a.out") |
| 32 | + self.build_and_launch(program) |
| 33 | + |
| 34 | + # Set source breakpoint 1 |
| 35 | + response = self.dap_server.request_setBreakpoints(self.main_path, [main_line]) |
| 36 | + breakpoints = response["body"]["breakpoints"] |
| 37 | + self.assertEquals(len(breakpoints), 1) |
| 38 | + breakpoint = breakpoints[0] |
| 39 | + self.assertEqual( |
| 40 | + breakpoint["line"], main_line, "incorrect breakpoint source line" |
| 41 | + ) |
| 42 | + self.assertTrue(breakpoint["verified"], "breakpoint is not verified") |
| 43 | + self.assertEqual( |
| 44 | + self.main_basename, breakpoint["source"]["name"], "incorrect source name" |
| 45 | + ) |
| 46 | + self.assertEqual( |
| 47 | + self.main_path, breakpoint["source"]["path"], "incorrect source file path" |
| 48 | + ) |
| 49 | + other_breakpoint_id = breakpoint["id"] |
| 50 | + |
| 51 | + # Continue and then verifiy the breakpoint |
| 52 | + self.dap_server.request_continue() |
| 53 | + self.verify_breakpoint_hit([other_breakpoint_id]) |
| 54 | + |
| 55 | + # now we check the stack trace making sure that we got mapped source paths |
| 56 | + frames = self.dap_server.request_stackTrace()["body"]["stackFrames"] |
| 57 | + intstructionPointerReference = [] |
| 58 | + setIntstructionBreakpoints = [] |
| 59 | + intstructionPointerReference.append(frames[0]["instructionPointerReference"]) |
| 60 | + self.assertEqual( |
| 61 | + frames[0]["source"]["name"], self.main_basename, "incorrect source name" |
| 62 | + ) |
| 63 | + self.assertEqual( |
| 64 | + frames[0]["source"]["path"], self.main_path, "incorrect source file path" |
| 65 | + ) |
| 66 | + |
| 67 | + # Check disassembly view |
| 68 | + instruction = self.disassemble(frameIndex=0) |
| 69 | + self.assertEqual( |
| 70 | + instruction["address"], |
| 71 | + intstructionPointerReference[0], |
| 72 | + "current breakpoint reference is not in the disaasembly view", |
| 73 | + ) |
| 74 | + |
| 75 | + # Get next instruction address to set instruction breakpoint |
| 76 | + disassembled_instruction_list = self.dap_server.disassembled_instructions |
| 77 | + instruction_addr_list = list(disassembled_instruction_list.keys()) |
| 78 | + index = instruction_addr_list.index(intstructionPointerReference[0]) |
| 79 | + if len(instruction_addr_list) >= (index + 1): |
| 80 | + next_inst_addr = instruction_addr_list[index + 1] |
| 81 | + if len(next_inst_addr) > 2: |
| 82 | + setIntstructionBreakpoints.append(next_inst_addr) |
| 83 | + instruction_breakpoint_response = ( |
| 84 | + self.dap_server.request_setInstructionBreakpoints( |
| 85 | + setIntstructionBreakpoints |
| 86 | + ) |
| 87 | + ) |
| 88 | + inst_breakpoints = instruction_breakpoint_response["body"][ |
| 89 | + "breakpoints" |
| 90 | + ] |
| 91 | + self.assertEqual( |
| 92 | + inst_breakpoints[0]["instructionReference"], |
| 93 | + next_inst_addr, |
| 94 | + "Instruction breakpoint has not been resolved or failed to relocate the instruction breakpoint", |
| 95 | + ) |
| 96 | + self.dap_server.request_continue() |
| 97 | + self.verify_breakpoint_hit([inst_breakpoints[0]["id"]]) |
0 commit comments