1""" 2Test that you can set breakpoint and hit the C++ language exception breakpoint 3""" 4 5 6import lldb 7from lldbsuite.test.decorators import * 8from lldbsuite.test.lldbtest import * 9from lldbsuite.test import lldbutil 10 11 12class TestCPPExceptionBreakpoint(TestBase): 13 my_var = 10 14 15 @add_test_categories(["pyapi"]) 16 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24538") 17 def test_cpp_exception_breakpoint(self): 18 """Test setting and hitting the C++ exception breakpoint.""" 19 self.build() 20 self.do_cpp_exception_bkpt() 21 22 @add_test_categories(["pyapi"]) 23 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24538") 24 def test_dummy_target_cpp_exception_breakpoint(self): 25 """Test setting and hitting the C++ exception breakpoint from dummy target.""" 26 self.build() 27 self.do_dummy_target_cpp_exception_bkpt() 28 29 def setUp(self): 30 TestBase.setUp(self) 31 self.main_source = "main.c" 32 self.main_source_spec = lldb.SBFileSpec(self.main_source) 33 34 def do_cpp_exception_bkpt(self): 35 exe = self.getBuildArtifact("a.out") 36 error = lldb.SBError() 37 38 self.target = self.dbg.CreateTarget(exe) 39 self.assertTrue(self.target, VALID_TARGET) 40 41 exception_bkpt = self.target.BreakpointCreateForException( 42 lldb.eLanguageTypeC_plus_plus, False, True 43 ) 44 self.assertTrue(exception_bkpt.IsValid(), "Created exception breakpoint.") 45 46 process = self.target.LaunchSimple( 47 None, None, self.get_process_working_directory() 48 ) 49 self.assertTrue(process, PROCESS_IS_VALID) 50 51 thread_list = lldbutil.get_threads_stopped_at_breakpoint( 52 process, exception_bkpt 53 ) 54 self.assertEqual( 55 len(thread_list), 1, "One thread stopped at the exception breakpoint." 56 ) 57 58 def do_dummy_target_cpp_exception_bkpt(self): 59 exe = self.getBuildArtifact("a.out") 60 error = lldb.SBError() 61 62 dummy_exception_bkpt = self.dbg.GetDummyTarget().BreakpointCreateForException( 63 lldb.eLanguageTypeC_plus_plus, False, True 64 ) 65 self.assertTrue( 66 dummy_exception_bkpt.IsValid(), 67 "Created exception breakpoint in dummy target.", 68 ) 69 70 self.target = self.dbg.CreateTarget(exe) 71 self.assertTrue(self.target, VALID_TARGET) 72 73 exception_bkpt = self.target.GetBreakpointAtIndex(0) 74 self.assertTrue( 75 exception_bkpt.IsValid(), 76 "Target primed with exception breakpoint from dummy target.", 77 ) 78 79 process = self.target.LaunchSimple( 80 None, None, self.get_process_working_directory() 81 ) 82 self.assertTrue(process, PROCESS_IS_VALID) 83 84 thread_list = lldbutil.get_threads_stopped_at_breakpoint( 85 process, exception_bkpt 86 ) 87 self.assertEqual( 88 len(thread_list), 1, "One thread stopped at the exception breakpoint." 89 ) 90