199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtTest lldb exception breakpoint command for CPP. 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprecht 699451b44SJordan Rupprecht 799451b44SJordan Rupprechtimport lldb 899451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 999451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 1099451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 1199451b44SJordan Rupprecht 1299451b44SJordan Rupprecht 1399451b44SJordan Rupprechtclass CPPBreakpointTestCase(TestBase): 1499451b44SJordan Rupprecht 1599451b44SJordan Rupprecht def setUp(self): 1699451b44SJordan Rupprecht # Call super's setUp(). 1799451b44SJordan Rupprecht TestBase.setUp(self) 1899451b44SJordan Rupprecht self.source = 'exceptions.cpp' 1999451b44SJordan Rupprecht self.catch_line = line_number( 2099451b44SJordan Rupprecht self.source, '// This is the line you should stop at for catch') 2199451b44SJordan Rupprecht 2299451b44SJordan Rupprecht @expectedFailureAll( 2399451b44SJordan Rupprecht oslist=["windows"], 2499451b44SJordan Rupprecht bugnumber="llvm.org/pr24538, clang-cl does not support throw or catch") 2599451b44SJordan Rupprecht def test(self): 2699451b44SJordan Rupprecht """Test lldb exception breakpoint command for CPP.""" 2799451b44SJordan Rupprecht self.build() 2899451b44SJordan Rupprecht exe = self.getBuildArtifact("a.out") 2999451b44SJordan Rupprecht 3099451b44SJordan Rupprecht # Create a target from the debugger. 3199451b44SJordan Rupprecht 3299451b44SJordan Rupprecht target = self.dbg.CreateTarget(exe) 3399451b44SJordan Rupprecht self.assertTrue(target, VALID_TARGET) 3499451b44SJordan Rupprecht 3599451b44SJordan Rupprecht exception_bkpt = target.BreakpointCreateForException( 3699451b44SJordan Rupprecht lldb.eLanguageTypeC_plus_plus, True, True) 3799451b44SJordan Rupprecht self.assertTrue(exception_bkpt, "Made an exception breakpoint") 3899451b44SJordan Rupprecht 3999451b44SJordan Rupprecht # Now run, and make sure we hit our breakpoint: 4099451b44SJordan Rupprecht process = target.LaunchSimple( 4199451b44SJordan Rupprecht None, None, self.get_process_working_directory()) 4299451b44SJordan Rupprecht self.assertTrue(process, "Got a valid process") 4399451b44SJordan Rupprecht 4499451b44SJordan Rupprecht stopped_threads = [] 4599451b44SJordan Rupprecht stopped_threads = lldbutil.get_threads_stopped_at_breakpoint( 4699451b44SJordan Rupprecht process, exception_bkpt) 47*0ed758b2SDave Lee self.assertEqual( 48*0ed758b2SDave Lee len(stopped_threads), 1, 4999451b44SJordan Rupprecht "Stopped at our exception breakpoint.") 5099451b44SJordan Rupprecht thread = stopped_threads[0] 5199451b44SJordan Rupprecht # Make sure our throw function is still above us on the stack: 5299451b44SJordan Rupprecht 5399451b44SJordan Rupprecht frame_functions = lldbutil.get_function_names(thread) 54*0ed758b2SDave Lee self.assertEqual( 55*0ed758b2SDave Lee frame_functions.count("throws_exception_on_even(int)"), 1, 5699451b44SJordan Rupprecht "Our throw function is still on the stack.") 5799451b44SJordan Rupprecht 5899451b44SJordan Rupprecht # Okay we hit our exception throw breakpoint, now make sure we get our catch breakpoint. 5999451b44SJordan Rupprecht # One potential complication is that we might hit a couple of the exception breakpoints in getting out of the throw. 6099451b44SJordan Rupprecht # so loop till we don't see the throws function on the stack. We should stop one more time for our exception breakpoint 6199451b44SJordan Rupprecht # and that should be the catch... 6299451b44SJordan Rupprecht 6399451b44SJordan Rupprecht while frame_functions.count("throws_exception_on_even(int)") == 1: 6499451b44SJordan Rupprecht stopped_threads = lldbutil.continue_to_breakpoint( 6599451b44SJordan Rupprecht process, exception_bkpt) 66b3a0c4d7SRaphael Isemann self.assertEquals(len(stopped_threads), 1) 6799451b44SJordan Rupprecht 6899451b44SJordan Rupprecht thread = stopped_threads[0] 6999451b44SJordan Rupprecht frame_functions = lldbutil.get_function_names(thread) 7099451b44SJordan Rupprecht 71*0ed758b2SDave Lee self.assertEqual( 72*0ed758b2SDave Lee frame_functions.count("throws_exception_on_even(int)"), 0, 7399451b44SJordan Rupprecht "At catch our throw function is off the stack") 74*0ed758b2SDave Lee self.assertEqual( 75*0ed758b2SDave Lee frame_functions.count("intervening_function(int)"), 0, 7699451b44SJordan Rupprecht "At catch our intervening function is off the stack") 77*0ed758b2SDave Lee self.assertEqual( 78*0ed758b2SDave Lee frame_functions.count("catches_exception(int)"), 1, 7999451b44SJordan Rupprecht "At catch our catch function is on the stack") 80