1"""Test the lldb public C++ api breakpoint callbacks.""" 2 3# __package__ = "lldbsuite.test" 4 5 6import os 7from lldbsuite.test.decorators import * 8from lldbsuite.test.lldbtest import * 9from lldbsuite.test import lldbutil 10 11 12@skipIfNoSBHeaders 13class SBBreakpointCallbackCase(TestBase): 14 NO_DEBUG_INFO_TESTCASE = True 15 16 def setUp(self): 17 TestBase.setUp(self) 18 self.generateSource("driver.cpp") 19 self.generateSource("listener_test.cpp") 20 self.generateSource("test_breakpoint_callback.cpp") 21 self.generateSource("test_breakpoint_location_callback.cpp") 22 self.generateSource("test_listener_event_description.cpp") 23 self.generateSource("test_listener_event_process_state.cpp") 24 self.generateSource("test_listener_resume.cpp") 25 self.generateSource("test_stop-hook.cpp") 26 27 @skipIfRemote 28 # clang-cl does not support throw or catch (llvm.org/pr24538) 29 @skipIfWindows 30 @skipIfHostIncompatibleWithTarget 31 def test_python_stop_hook(self): 32 """Test that you can run a python command in a stop-hook when stdin is File based.""" 33 self.build_and_test("driver.cpp test_stop-hook.cpp", "test_python_stop_hook") 34 35 @skipIfRemote 36 # clang-cl does not support throw or catch (llvm.org/pr24538) 37 @skipIfWindows 38 @skipIfHostIncompatibleWithTarget 39 def test_breakpoint_callback(self): 40 """Test the that SBBreakpoint callback is invoked when a breakpoint is hit.""" 41 self.build_and_test( 42 "driver.cpp test_breakpoint_callback.cpp", "test_breakpoint_callback" 43 ) 44 45 @skipIfRemote 46 # clang-cl does not support throw or catch (llvm.org/pr24538) 47 @skipIfWindows 48 @skipIfHostIncompatibleWithTarget 49 def test_breakpoint_location_callback(self): 50 """Test the that SBBreakpointLocation callback is invoked when a breakpoint is hit.""" 51 self.build_and_test( 52 "driver.cpp test_breakpoint_location_callback.cpp", 53 "test_breakpoint_location_callback", 54 ) 55 56 @skipIfRemote 57 # clang-cl does not support throw or catch (llvm.org/pr24538) 58 @skipIfWindows 59 @expectedFlakeyFreeBSD 60 @skipIfHostIncompatibleWithTarget 61 def test_sb_api_listener_event_description(self): 62 """Test the description of an SBListener breakpoint event is valid.""" 63 self.build_and_test( 64 "driver.cpp listener_test.cpp test_listener_event_description.cpp", 65 "test_listener_event_description", 66 ) 67 68 @skipIfRemote 69 # clang-cl does not support throw or catch (llvm.org/pr24538) 70 @skipIfWindows 71 @expectedFlakeyFreeBSD 72 @skipIfHostIncompatibleWithTarget 73 def test_sb_api_listener_event_process_state(self): 74 """Test that a registered SBListener receives events when a process 75 changes state. 76 """ 77 self.build_and_test( 78 "driver.cpp listener_test.cpp test_listener_event_process_state.cpp", 79 "test_listener_event_process_state", 80 ) 81 82 @skipIfRemote 83 # clang-cl does not support throw or catch (llvm.org/pr24538) 84 @skipIfWindows 85 @expectedFlakeyFreeBSD 86 @skipIf(oslist=["linux"]) # flakey 87 @skipIfHostIncompatibleWithTarget 88 def test_sb_api_listener_resume(self): 89 """Test that a process can be resumed from a non-main thread.""" 90 self.build_and_test( 91 "driver.cpp listener_test.cpp test_listener_resume.cpp", 92 "test_listener_resume", 93 ) 94 95 def build_and_test(self, sources, test_name, args=None): 96 """Build LLDB test from sources, and run expecting 0 exit code""" 97 98 # These tests link against host lldb API. 99 # Compiler's target triple must match liblldb triple 100 # because remote is disabled, we can assume that the os is the same 101 # still need to check architecture 102 if self.getLldbArchitecture() != self.getArchitecture(): 103 self.skipTest( 104 "This test is only run if the target arch is the same as the lldb binary arch" 105 ) 106 107 self.inferior = "inferior_program" 108 self.buildProgram("inferior.cpp", self.inferior) 109 self.addTearDownHook(lambda: os.remove(self.getBuildArtifact(self.inferior))) 110 111 self.buildDriver(sources, test_name) 112 self.addTearDownHook(lambda: os.remove(self.getBuildArtifact(test_name))) 113 114 test_exe = self.getBuildArtifact(test_name) 115 exe = [test_exe, self.getBuildArtifact(self.inferior)] 116 117 env = {self.dylibPath: self.getLLDBLibraryEnvVal()} 118 if "LLDB_DEBUGSERVER_PATH" in os.environ: 119 env["LLDB_DEBUGSERVER_PATH"] = os.environ["LLDB_DEBUGSERVER_PATH"] 120 try: 121 if self.TraceOn(): 122 print("Running test %s" % " ".join(exe)) 123 check_call(exe, env=env) 124 else: 125 with open(os.devnull, "w") as fnull: 126 check_call(exe, env=env, stdout=fnull, stderr=fnull) 127 except subprocess.CalledProcessError as e: 128 self.fail(e) 129 130 def build_program(self, sources, program): 131 return self.buildDriver(sources, program) 132