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