def test_with_run_command(self): self.build() exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target and target.IsValid(), "Target is valid") file_spec = lldb.SBFileSpec ("main.cpp", False) breakpoint1 = target.BreakpointCreateBySourceRegex('// Set break point at this line.', file_spec) self.assertTrue(breakpoint1 and breakpoint1.IsValid()) breakpoint2 = target.BreakpointCreateBySourceRegex('// Set second break point at this line.', file_spec) self.assertTrue(breakpoint2 and breakpoint2.IsValid()) # Run the program, it should stop at breakpoint 1. process = target.LaunchSimple(None, None, self.get_process_working_directory()) lldbutil.skip_if_library_missing(self, target, lldbutil.PrintableRegex("libc\+\+")) self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID) self.assertEqual(len(lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint1)), 1) # verify our list is displayed correctly self.expect("frame variable *numbers_list", substrs=['[0] = 1', '[1] = 2', '[2] = 3', '[3] = 4', '[5] = 6']) # Continue to breakpoint 2. process.Continue() self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID) self.assertEqual(len(lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint2)), 1) # The list is now inconsistent. However, we should be able to get the first three # elements at least (and most importantly, not crash). self.expect("frame variable *numbers_list", substrs=['[0] = 1', '[1] = 2', '[2] = 3']) # Run to completion. process.Continue() self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
def test(self): """Test that we find the right file-local private decls using the discriminator""" self.build() exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints a_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.a_source_spec) self.assertTrue(a_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) b_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.b_source_spec) self.assertTrue(b_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) main_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.main_source_spec) self.assertTrue( main_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, a_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") self.check_expression("privateVariable", "\"five\"") process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, b_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") self.check_expression("privateVariable", "3", False) process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, main_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") self.check_expression("privateVariable", None) self.check_expression("privateVariable as Int", "3", False) self.check_expression("privateVariable as String", "\"five\"")
def do_test(self): """Test that we use the right compiler flags when debugging""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) def cleanup(): execute_command("make cleanup") self.addTearDownHook(cleanup) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints main_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.main_source_spec) self.assertTrue( main_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) modb_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.modb_source_spec) self.assertTrue( modb_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, modb_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("myThree") three = var.GetChildMemberWithName("three") lldbutil.check_variable(self, var, False, typename="modb.MyStruct") lldbutil.check_variable(self, three, False, value="3") process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, main_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("a") lldbutil.check_variable(self, var, False, value="2") var = self.frame.FindVariable("b") lldbutil.check_variable(self, var, False, value="3") var = self.frame.EvaluateExpression("fA()") lldbutil.check_variable(self, var, False, value="2")
def test_swift_private_typealias(self): """Test that we can correctly print variables whose types are private type aliases""" self.build() exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint1 = target.BreakpointCreateBySourceRegex( 'breakpoint 1', self.a_source_spec) breakpoint2 = target.BreakpointCreateBySourceRegex( 'breakpoint 2', self.a_source_spec) self.assertTrue(breakpoint1.GetNumLocations() > 0, VALID_BREAKPOINT) self.assertTrue(breakpoint2.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint1) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("i") lldbutil.check_variable( self, var, False, typename="a.MyStruct.Type.IntegerType", value="123") process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint2) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("a") dict_child_0 = var.GetChildAtIndex(0) child_0 = dict_child_0.GetChildAtIndex(0) child_1 = dict_child_0.GetChildAtIndex(1) lldbutil.check_variable( self, var, False, typename="Swift.Dictionary<Swift.String, a.MyStruct.Type.IntegerType>") lldbutil.check_variable(self, child_0, False, '"hello"') lldbutil.check_variable(self, child_1, False, value='234')
def test(self): if self.getArchitecture() == 'x86_64': source = os.path.join (os.getcwd(), "main.cpp") o_file = os.path.join (os.getcwd(), "main.o") execute_command ("'%s' -g -O0 -arch i386 -arch x86_64 '%s' -c -o '%s'" % (os.environ["CC"], source, o_file)) execute_command ("'%s' -g -O0 -arch i386 -arch x86_64 '%s'" % (os.environ["CC"], o_file)) if self.debug_info != "dsym": dsym_path = os.path.join (os.getcwd(), "a.out.dSYM") execute_command ("rm -rf '%s'" % (dsym_path)) else: self.build() exe = os.path.join (os.getcwd(), "a.out") # Create the target target = self.dbg.CreateTarget(exe) # Create any breakpoints we need breakpoint = target.BreakpointCreateBySourceRegex ('Set breakpoint 1 here', lldb.SBFileSpec ("main.cpp", False)) self.assertTrue(breakpoint, VALID_BREAKPOINT) # Launch the process process = target.LaunchSimple (None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) for i in range(6): # The stop reason of the thread should be breakpoint. self.assertTrue(process.GetState() == lldb.eStateStopped, STOPPED_DUE_TO_BREAKPOINT) threads = lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint) self.assertTrue(len(threads) == 1) # We had a deadlock tearing down the TypeSystemMap on exec, but only if some # expression had been evaluated. So make sure we do that here so the teardown # is not trivial. thread = threads[0] value = thread.frames[0].EvaluateExpression("1 + 2") self.assertTrue(value.IsValid(), "Expression evaluated successfully") int_value = value.GetValueAsSigned() self.assertTrue(int_value == 3, "Expression got the right result.") # Run and we should stop due to exec process.Continue() self.assertTrue(process.GetState() == lldb.eStateStopped, "Process should be stopped at __dyld_start") threads = lldbutil.get_stopped_threads(process, lldb.eStopReasonExec) self.assertTrue(len(threads) == 1, "We got a thread stopped for exec.") # Run and we should stop at breakpoint in main after exec process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint) self.assertTrue(len(threads) == 1, "Stopped at breakpoint in exec'ed process.")
def test_swift_private_decl_name(self): """Test that we correctly find private decls""" self.build() self.do_test() exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints a_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.a_source_spec) self.assertTrue(a_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) b_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.b_source_spec) self.assertTrue(b_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, a_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("a") child_a = var.GetChildMemberWithName("a") child_b = var.GetChildMemberWithName("b") child_c = var.GetChildMemberWithName("c") lldbutil.check_variable(self, var, False, typename="a.S.A") lldbutil.check_variable(self, child_a, False, value="1") lldbutil.check_variable(self, child_b, False, '"hello"') lldbutil.check_variable(self, child_c, False, value='1.25') process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, b_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("a") child_a = var.GetChildMemberWithName("a") child_b = var.GetChildMemberWithName("b") child_c = var.GetChildMemberWithName("c") lldbutil.check_variable(self, var, False, typename="a.S.A") lldbutil.check_variable(self, child_a, False, value="3") lldbutil.check_variable(self, child_b, False, '"goodbye"') lldbutil.check_variable(self, child_c, False, value='1.25')
def do_test(self): """Tests that we properly vend synthetic children for Swift.Dictionary""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint1 = target.BreakpointCreateBySourceRegex('// Set first breakpoint here.', self.main_source_spec) breakpoint2 = target.BreakpointCreateBySourceRegex('// Set second breakpoint here.', self.main_source_spec) self.assertTrue(breakpoint1.GetNumLocations() > 0, VALID_BREAKPOINT) self.assertTrue(breakpoint2.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint1) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd("type summary delete main.StringWrapper", check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) enumvar = self.get_variable("myOptionalU").GetStaticValue() self.assertTrue(enumvar.GetValue() is None, "static type has a value when it shouldn't") enumvar = enumvar.GetDynamicValue(lldb.eDynamicCanRunTarget) self.assertTrue(enumvar.GetValue() == "Some", "dynamic type's value should be Some") self.assertTrue(enumvar.GetSummary() == "3", "Some's summary should be 3") self.runCmd("continue") threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint2) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") value = self.get_variable("value") lldbutil.check_variable (self, value, use_dynamic = True, summary = '"Now with Content"', typename = 'String?')
def do_test(self): """Test that we correctly find private extension decls across modules""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) def cleanup(): execute_command("make cleanup") self.addTearDownHook(cleanup) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints a_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.a_source_spec) self.assertTrue(a_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) b_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.b_source_spec) self.assertTrue(b_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, a_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("a") child_v = var.GetChildMemberWithName("v") lldbutil.check_variable(self, var, False, typename="moda.S.A") lldbutil.check_variable(self, child_v, False, value="1") process.Continue() threads = lldbutil.get_threads_stopped_at_breakpoint( process, b_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("a") child_v = var.GetChildMemberWithName("v") lldbutil.check_variable(self, var, False, typename="moda.S.A") lldbutil.check_variable(self, child_v, False, value="3")
def do_test(self): """Test that LLDB understands generic enums with more than one payload type""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") self.expect("frame variable one", substrs=['One', '1234']) self.expect("frame variable two", substrs=['TheOther', '"some value"']) self.expect("expression one", substrs=['One', '1234']) self.expect("expression two", substrs=['TheOther', '"some value"'])
def test_with_python_api(self): """Test that a global ObjC object found before the process is started updates correctly.""" self.build() exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) bkpt = target.BreakpointCreateBySourceRegex ('NSLog', self.main_source) self.assertTrue(bkpt, VALID_BREAKPOINT) # Before we launch, make an SBValue for our global object pointer: g_obj_ptr = target.FindFirstGlobalVariable("g_obj_ptr") self.assertTrue(g_obj_ptr.GetError().Success(), "Made the g_obj_ptr") self.assertTrue(g_obj_ptr.GetValueAsUnsigned(10) == 0, "g_obj_ptr is initially null") # Now launch the process, and do not stop at entry point. process = target.LaunchSimple (None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, bkpt) if len(threads) != 1: self.fail ("Failed to stop at breakpoint 1.") thread = threads[0] dyn_value = g_obj_ptr.GetDynamicValue(lldb.eDynamicCanRunTarget) self.assertTrue(dyn_value.GetError().Success(), "Dynamic value is valid") self.assertTrue(dyn_value.GetObjectDescription() == "Some NSString")
def do_test(self): """Test simple swift expressions""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints pure_swift_bkpt = target.BreakpointCreateBySourceRegex( 'Stop here in Pure Swift class', self.main_source_spec) self.assertTrue( pure_swift_bkpt.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, pure_swift_bkpt) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") self.check_expression("m_computed_ivar == 5", "true") self.check_expression("m_ivar", "10", use_summary=False) self.check_expression("self.m_ivar == 11", "false")
def do_test(self): """Test the Any type""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( '// Set a breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") foo_objc = self.frame.FindVariable("foo_objc") foo_swift = self.frame.FindVariable("foo_swift") self.check_foo(foo_objc) self.check_foo(foo_swift)
def test_with_python_api(self): """Test calling functions in class methods.""" self.build() exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line) self.assertTrue(bpt, VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. process = target.LaunchSimple (None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt) # Make sure we stopped at the first breakpoint. self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.") self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.") # Now make sure we can call a function in the class method we've stopped in. frame = thread_list[0].GetFrameAtIndex(0) self.assertTrue (frame, "Got a valid frame 0 frame.") cmd_value = frame.EvaluateExpression ("(int)[Foo doSomethingWithString:@\"Hello\"]") self.assertTrue (cmd_value.IsValid()) self.assertTrue (cmd_value.GetValueAsUnsigned() == 5)
def step_in_template(self): """Use Python APIs to test stepping in to templated functions.""" exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) break_1_in_main = target.BreakpointCreateBySourceRegex("// Call max_value template", self.main_source_spec) self.assertTrue(break_1_in_main, VALID_BREAKPOINT) break_2_in_main = target.BreakpointCreateBySourceRegex("// Call max_value specialized", self.main_source_spec) self.assertTrue(break_2_in_main, VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. self.process = target.LaunchSimple(None, None, self.get_process_working_directory()) self.assertTrue(self.process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint(self.process, break_1_in_main) if len(threads) != 1: self.fail("Failed to stop at first breakpoint in main.") self.thread = threads[0] step_sequence = [["// In max_value template", "into"]] self.run_step_sequence(step_sequence) threads = lldbutil.continue_to_breakpoint(self.process, break_2_in_main) self.assertEqual(len(threads), 1, "Successfully ran to call site of second caller_trivial_1 call.") self.thread = threads[0] step_sequence = [["// In max_value specialized", "into"]] self.run_step_sequence(step_sequence)
def test_with_python_api(self): """Test function call thread safety.""" self.build() exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) self.main_source_spec = lldb.SBFileSpec(self.main_source) break1 = target.BreakpointCreateByName("stopper", 'a.out') self.assertTrue(break1, VALID_BREAKPOINT) process = target.LaunchSimple( None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint(process, break1) if len(threads) != 1: self.fail("Failed to stop at breakpoint 1.") self.check_number_of_threads(process) main_thread = lldb.SBThread() select_thread = lldb.SBThread() for idx in range(0, process.GetNumThreads()): t = process.GetThreadAtIndex(idx) if t.GetName() == "main thread": main_thread = t if t.GetName() == "select thread": select_thread = t self.assertTrue( main_thread.IsValid() and select_thread.IsValid(), "Got both expected threads") self.safe_to_call_func_on_main_thread(main_thread) self.safe_to_call_func_on_select_thread(select_thread)
def do_test(self): """Test expressions in class func contexts""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) breakpoints = [None] # Set the breakpoints for i in range(1,8): breakpoints.append(target.BreakpointCreateBySourceRegex("breakpoint " + str(i), self.main_source_spec)) self.assertTrue(breakpoints[i].GetNumLocations() > 0, "Didn't get valid breakpoint for %s"%(str(i))) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Check each context for i in range(1,8): # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoints[i]) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") self.check_expression ("i", str(i), False) self.runCmd("continue")
def do_test(self, patterns, should_stop): """Tests that swift error throws are correctly caught by the Swift Error breakpoint""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.target = target self.assertTrue(target, VALID_TARGET) # Set the breakpoints swift_error_bkpt = target.BreakpointCreateForException(lldb.eLanguageTypeSwift, False, True, patterns) # Note, I'm not checking locations here because we never know them before launch. # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.process = process if should_stop: self.assertTrue(process, PROCESS_IS_VALID) breakpoint_threads = lldbutil.get_threads_stopped_at_breakpoint(process, swift_error_bkpt) self.assertTrue(len(breakpoint_threads) == 1, "We didn't stop at the error breakpoint") else: exit_state = process.GetState() self.assertTrue(exit_state == lldb.eStateExited, "We stopped at the error breakpoint when we shouldn't have.") target.BreakpointDelete(swift_error_bkpt.GetID())
def launchProcess(self): exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) bpt = target.BreakpointCreateByLocation( self.main_source, self.break_line) self.assertTrue(bpt, VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. process = target.LaunchSimple( None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt) # Make sure we stopped at the first breakpoint. self.assertTrue( len(thread_list) != 0, "No thread stopped at our breakpoint.") self.assertTrue(len(thread_list) == 1, "More than one thread stopped at our breakpoint.") frame = thread_list[0].GetFrameAtIndex(0) self.assertTrue(frame, "Got a valid frame 0 frame.")
def do_check_consistency(self): """Check formatting for T? and T!""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0]
def do_test(self): """Test the Swift.Range<T> type""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") self.expect("frame variable a", substrs=['(Range<Int>) a = 1..<101']) self.expect("frame variable b", substrs=['(Range<Int>) b = 1..<100'])
def test_with_python_api(self): """Test expression parser respect for ObjC built-in types.""" self.build() exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line) self.assertTrue(bpt, VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. process = target.LaunchSimple (None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. thread_list = lldbutil.get_threads_stopped_at_breakpoint (process, bpt) # Make sure we stopped at the first breakpoint. self.assertTrue (len(thread_list) != 0, "No thread stopped at our breakpoint.") self.assertTrue (len(thread_list) == 1, "More than one thread stopped at our breakpoint.") # Now make sure we can call a function in the class method we've stopped in. frame = thread_list[0].GetFrameAtIndex(0) self.assertTrue (frame, "Got a valid frame 0 frame.") self.expect("expr (foo)", patterns = ["\(ns::id\) \$.* = 0"]) self.expect("expr id my_id = 0; my_id", patterns = ["\(id\) \$.* = nil"])
def test_with_python_api(self): """Test passing structs to Objective-C methods.""" self.build() exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line) self.assertTrue(bpt, VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. process = target.LaunchSimple(None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt) # Make sure we stopped at the first breakpoint. self.assertTrue(len(thread_list) != 0, "No thread stopped at our breakpoint.") self.assertTrue(len(thread_list) == 1, "More than one thread stopped at our breakpoint.") frame = thread_list[0].GetFrameAtIndex(0) self.assertTrue(frame, "Got a valid frame 0 frame.") self.expect("p [summer sumThings:tts]", substrs=["9"]) self.expect("po [NSValue valueWithRect:rect]", substrs=["NSRect: {{0, 0}, {10, 20}}"]) # Now make sure we can call a method that returns a struct without crashing. cmd_value = frame.EvaluateExpression("[provider getRange]") self.assertTrue(cmd_value.IsValid())
def do_test(self): """Test the AnyObject type""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_object = self.frame.FindVariable("object") lldbutil.check_variable(self,var_object,use_dynamic=False,typename="AnyObject") lldbutil.check_variable(self,var_object,use_dynamic=True,typename="a.SomeClass") var_object_x = var_object.GetDynamicValue(lldb.eDynamicCanRunTarget).GetChildMemberWithName("x") lldbutil.check_variable(self,var_object_x,use_dynamic=False,value='12',typename="Swift.Int")
def inline_stepping_step_over(self): """Use Python APIs to test stepping over and hitting breakpoints.""" exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) break_1_in_main = target.BreakpointCreateBySourceRegex( "// At second call of caller_ref_1 in main.", self.main_source_spec ) self.assertTrue(break_1_in_main, VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. self.process = target.LaunchSimple(None, None, self.get_process_working_directory()) self.assertTrue(self.process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint(self.process, break_1_in_main) if len(threads) != 1: self.fail("Failed to stop at first breakpoint in main.") self.thread = threads[0] step_sequence = [ ["// In caller_ref_1.", "into"], ["// In caller_ref_2.", "into"], ["// At increment in caller_ref_2.", "over"], ] self.run_step_sequence(step_sequence)
def test_formatters_api(self): """Test that SBFrame::FindValue finds things but does not duplicate the entire variables list""" self.build() self.setTearDownCleanup() exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here', lldb.SBFileSpec("main.cpp")) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") self.assertTrue(self.frame.GetVariables(True,True,False,True).GetSize() == 2, "variable count is off") self.assertFalse(self.frame.FindValue("NoSuchThing",lldb.eValueTypeVariableArgument,lldb.eDynamicCanRunTarget).IsValid(), "found something that should not be here") self.assertTrue(self.frame.GetVariables(True,True,False,True).GetSize() == 2, "variable count is off after failed FindValue()") self.assertTrue(self.frame.FindValue("a",lldb.eValueTypeVariableArgument,lldb.eDynamicCanRunTarget).IsValid(), "FindValue() didn't find an argument") self.assertTrue(self.frame.GetVariables(True,True,False,True).GetSize() == 2, "variable count is off after successful FindValue()")
def do_test(self): """Check formatting for Swift.Array<T> that are bridged from ObjC""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.expect( "frame variable -d run -- swarr", substrs=['123456', '234567', '345678', '1.25', 'false']) self.expect( "expression -d run -- swarr", substrs=['123456', '234567', '345678', '1.25', 'false'])
def do_test(self): """Test that tagged pointers are formatted correctly in a Swift context""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex('break here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_a = self.frame.FindVariable("a") var_b = self.frame.FindVariable("b") lldbutil.check_variable(self,var_a,True,"Int64(3)") lldbutil.check_variable(self,var_b,True,"Int64(3)")
def do_test(self): """Test the Any type""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, lldbtest.VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, lldbtest.VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, lldbtest.PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_c = self.frame.FindVariable("c") var_c_x = var_c.GetChildMemberWithName("x") var_q = self.frame.FindVariable("q") lldbutil.check_variable(self,var_c_x,True,value="12") lldbutil.check_variable(self,var_q,True,value="12") self.expect("expression -d run -- q", substrs=['12']) self.expect("frame variable -d run -- q", substrs=['12'])
def do_test(self): """Test the formatting of briged Swift metatypes""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_k = self.frame.FindVariable("k") lldbutil.check_variable(self,var_k,False,"NSString")
def do_test(self): """Make sure expressions ignore access control""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") self.check_expression("foo.m_a", "3", use_summary=False)
def test_python(self): """Test that we obey thread conditioned breakpoints.""" self.build() exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) main_source_spec = lldb.SBFileSpec ("main.cpp") # Set a breakpoint in the thread body, and make it active for only the first thread. break_thread_body = target.BreakpointCreateBySourceRegex ("Break here in thread body.", main_source_spec) self.assertTrue (break_thread_body.IsValid() and break_thread_body.GetNumLocations() > 0, "Failed to set thread body breakpoint.") process = target.LaunchSimple (None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint (process, break_thread_body) victim_thread = threads[0] # Pick one of the threads, and change the breakpoint so it ONLY stops for this thread, # but add a condition that it won't stop for this thread's my_value. The other threads # pass the condition, so they should stop, but if the thread-specification is working # they should not stop. So nobody should hit the breakpoint anymore, and we should # just exit cleanly. frame = victim_thread.GetFrameAtIndex(0) value = frame.FindVariable("my_value").GetValueAsSigned(0) self.assertTrue (value > 0 and value < 11, "Got a reasonable value for my_value.") cond_string = "my_value != %d"%(value) break_thread_body.SetThreadID(victim_thread.GetThreadID()) break_thread_body.SetCondition (cond_string) process.Continue() next_stop_state = process.GetState() self.assertTrue (next_stop_state == lldb.eStateExited, "We should have not hit the breakpoint again.")
def test_with_python_api(self): """Test calling functions in class methods.""" self.build() exe = self.getBuildArtifact("a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) bpt = target.BreakpointCreateByLocation( self.main_source, self.break_line) self.assertTrue(bpt, VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. process = target.LaunchSimple( None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt) # Make sure we stopped at the first breakpoint. self.assertTrue( len(thread_list) != 0, "No thread stopped at our breakpoint.") self.assertTrue(len(thread_list) == 1, "More than one thread stopped at our breakpoint.") # Now make sure we can call a function in the class method we've # stopped in. frame = thread_list[0].GetFrameAtIndex(0) self.assertTrue(frame, "Got a valid frame 0 frame.") cmd_value = frame.EvaluateExpression( "(int)[Foo doSomethingWithString:@\"Hello\"]") if self.TraceOn(): if cmd_value.IsValid(): print("cmd_value is valid") print("cmd_value has the value %d" % cmd_value.GetValueAsUnsigned()) self.assertTrue(cmd_value.IsValid()) self.assertTrue(cmd_value.GetValueAsUnsigned() == 5)
def do_ivar_test(self): """Test expressions in generic contexts""" exe_name = "a.out" exe = self.getBuildArtifact(exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, lldbtest.VALID_TARGET) breakpoints = [] # Set the breakpoints only in the class functions: class_bkpts = [2, 3, 5, 6] for i in range(0, 4): breakpoints.append( target.BreakpointCreateBySourceRegex( "breakpoint " + str(class_bkpts[i]), self.main_source_spec)) self.assertTrue(breakpoints[i].GetNumLocations() > 0, lldbtest.VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, lldbtest.PROCESS_IS_VALID) # Check each context for i in range(0, 4): # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoints[i]) self.assertTrue(len(threads) == 1) self.check_expression("m_t", str(class_bkpts[i]), use_summary=False) self.check_expression("m_s.m_s", str(class_bkpts[i]), use_summary=False) self.runCmd("continue")
def test_with_python_api(self): """Test passing structs to Objective-C methods.""" self.build() exe = self.getBuildArtifact("a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) bpt = target.BreakpointCreateByLocation( self.main_source, self.break_line) self.assertTrue(bpt, VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. process = target.LaunchSimple( None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt) # Make sure we stopped at the first breakpoint. self.assertTrue( len(thread_list) != 0, "No thread stopped at our breakpoint.") self.assertTrue(len(thread_list) == 1, "More than one thread stopped at our breakpoint.") frame = thread_list[0].GetFrameAtIndex(0) self.assertTrue(frame, "Got a valid frame 0 frame.") self.expect("p [summer sumThings:tts]", substrs=['9']) self.expect( "po [NSValue valueWithRect:rect]", substrs=['NSRect: {{0, 0}, {10, 20}}']) # Now make sure we can call a method that returns a struct without # crashing. cmd_value = frame.EvaluateExpression("[provider getRange]") self.assertTrue(cmd_value.IsValid())
def do_test(self): """Test the formatting of Swift metatypes""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_s = self.frame.FindVariable("s") var_c = self.frame.FindVariable("c") # Enrico, there is no k var in the .swift file, and there is # no check on the k below. Commenting out for you to resolve. # var_k = self.frame.FindVariable("k") var_f = self.frame.FindVariable("f") var_t = self.frame.FindVariable("t") var_p = self.frame.FindVariable("p") lldbutil.check_variable(self, var_s, False, "String") lldbutil.check_variable(self, var_c, False, "a.D") lldbutil.check_variable(self, var_f, False, "Int -> Int") lldbutil.check_variable(self, var_t, False, "(Int, Int, String)") lldbutil.check_variable(self, var_p, False, "P")
def test_expressions_in_class_functions(self): """Test expressions in class func contexts""" self.build() target = self.dbg.CreateTarget(self.getBuildArtifact()) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoints = [None] for i in range(1, 8): breakpoints.append( target.BreakpointCreateBySourceRegex( "breakpoint " + str(i), lldb.SBFileSpec('main.swift'))) self.assertTrue(breakpoints[i].GetNumLocations() > 0, "Didn't get valid breakpoint for %s" % (str(i))) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Check each context for i in range(1, 8): # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoints[i]) self.assertTrue(len(threads) == 1) self.check_expression("i", str(i), False) if i == 6: self.check_expression("self", "a.H<Int>") frame = threads[0].GetFrameAtIndex(0) lldbutil.check_variable( self, frame.FindVariable("self"), use_dynamic=True, # FIXME: This should be '@thick a.H<Swift.Int>.Type' # but valobj.GetDynamicValue(lldb.eDynamicCanRunTarget) # doesn't seem to do its job. # rdar://problem/69889462 typename='@thin a.H<τ_0_0>.Type') self.runCmd("continue")
def do_test(self): """Test that we are able to deal with ObjC-imported types""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") nss = self.frame.FindVariable("nss") nsn = self.frame.FindVariable("nsn") nsmo = self.frame.FindVariable("nsmo") nsmd = self.frame.FindVariable("nsmd") lldbutil.check_variable(self, nss, use_dynamic=False, typename="Foundation.NSString") lldbutil.check_variable(self, nsn, use_dynamic=False, typename="Foundation.NSNumber") lldbutil.check_variable(self, nsmo, use_dynamic=False, typename="CoreData.NSManagedObject") lldbutil.check_variable(self, nsmd, use_dynamic=False, typename="Foundation.NSMutableDictionary") #pending rdar://15798504, but not critical for the test #lldbutil.check_variable(self, nss, use_dynamic=True, summary='@"abc"') lldbutil.check_variable(self, nsn, use_dynamic=True, summary='(long)3') lldbutil.check_variable(self, nsmo, use_dynamic=True, typename='NSManagedObject *') lldbutil.check_variable(self, nsmd, use_dynamic=True, summary='1 key/value pair')
def step_in_template(self): """Use Python APIs to test stepping in to templated functions.""" exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) break_1_in_main = target.BreakpointCreateBySourceRegex( '// Call max_value template', self.main_source_spec) self.assertTrue(break_1_in_main, VALID_BREAKPOINT) break_2_in_main = target.BreakpointCreateBySourceRegex( '// Call max_value specialized', self.main_source_spec) self.assertTrue(break_2_in_main, VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. self.process = target.LaunchSimple( None, None, self.get_process_working_directory()) self.assertTrue(self.process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( self.process, break_1_in_main) if len(threads) != 1: self.fail("Failed to stop at first breakpoint in main.") self.thread = threads[0] step_sequence = [["// In max_value template", "into"]] self.run_step_sequence(step_sequence) threads = lldbutil.continue_to_breakpoint(self.process, break_2_in_main) self.assertEqual( len(threads), 1, "Successfully ran to call site of second caller_trivial_1 call.") self.thread = threads[0] step_sequence = [["// In max_value specialized", "into"]] self.run_step_sequence(step_sequence)
def do_test(self): exe = self.getBuildArtifact("a.out") # Create a target by the debugger. target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) breakpoint = target.BreakpointCreateBySourceRegex("break here", lldb.SBFileSpec("main.cpp")) self.assertTrue(breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT) error = lldb.SBError() launch_info = lldb.SBLaunchInfo(None) process = target.Launch(launch_info, error) self.assertTrue(process, PROCESS_IS_VALID) # Did we hit our breakpoint? threads = lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint) self.assertTrue( len(threads) == 1, "There should be a thread stopped at our breakpoint") self.assertTrue(breakpoint.GetHitCount() == 1) thread = threads[0] # Here's what we expect to see in the backtrace: # frame #0: ... a.out`sink() at main.cpp:13:4 [opt] # frame #1: ... a.out`func3() at main.cpp:14:1 [opt] [artificial] # frame #2: ... a.out`func2() at main.cpp:18:62 [opt] # frame #3: ... a.out`func1() at main.cpp:18:85 [opt] [artificial] # frame #4: ... a.out`main at main.cpp:23:3 [opt] names = ["sink()", "func3()", "func2()", "func1()", "main"] artificiality = [False, True, False, True, False] for idx, (name, is_artificial) in enumerate(zip(names, artificiality)): frame = thread.GetFrameAtIndex(idx) self.assertTrue(frame.GetDisplayFunctionName() == name) self.assertTrue(frame.IsArtificial() == is_artificial)
def do_test(self): """Tests that Enum variables display correctly""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( '// Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) thread = threads[0] frame = thread.frames[0] self.assertTrue(frame, "Frame 0 is valid.") # Get the function pointer variable from our frame func_ptr_value = frame.FindVariable('func_ptr') # Grab the function pointer value as an unsigned load address func_ptr_addr = func_ptr_value.GetValueAsUnsigned() # Resolve the load address into a section + offset address (lldb.SBAddress) func_ptr_so_addr = target.ResolveLoadAddress(func_ptr_addr) # Get the debug info function for this address func_ptr_function = func_ptr_so_addr.GetFunction() # Make sure the function pointer correctly resolved to our a.bar function self.assertTrue('a.bar () -> ()' == func_ptr_function.name)
def do_cpp_exception_bkpt(self): exe = os.path.join(os.getcwd(), "a.out") error = lldb.SBError() self.target = self.dbg.CreateTarget(exe) self.assertTrue(self.target, VALID_TARGET) exception_bkpt = self.target.BreakpointCreateForException( lldb.eLanguageTypeC_plus_plus, False, True) self.assertTrue(exception_bkpt.IsValid(), "Created exception breakpoint.") process = self.target.LaunchSimple( None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) thread_list = lldbutil.get_threads_stopped_at_breakpoint( process, exception_bkpt) self.assertTrue( len(thread_list) == 1, "One thread stopped at the exception breakpoint.")
def expect_self_var_available_at_breakpoint( self, process, breakpoint, module_name): # Frame #0 should be at the given breakpoint threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertEquals(1, len(threads)) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") patterns = [ # Ensure we report a self with an address. r"self\s*=\s*0x[0-9a-fA-F]+", # Ensure we think it is an NSObject. r"ObjectiveC.NSObject"] substrs = [ "(%s.%s)" % (module_name, module_name) ] self.expect("frame variable self", patterns=patterns, substrs=substrs)
def sample_test(self): """You might use the test implementation in several ways, say so here.""" exe = os.path.join(os.getcwd(), "a.out") # Create a target by the debugger. target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Now create a breakpoint in main.c at the source matching # "Set a breakpoint here" breakpoint = target.BreakpointCreateBySourceRegex( "Set a breakpoint here", lldb.SBFileSpec("main.c")) self.assertTrue(breakpoint and breakpoint.GetNumLocations() >= 1, VALID_BREAKPOINT) error = lldb.SBError() # This is the launch info. If you want to launch with arguments or # environment variables, add them using SetArguments or # SetEnvironmentEntries launch_info = lldb.SBLaunchInfo(None) process = target.Launch(launch_info, error) self.assertTrue(process, PROCESS_IS_VALID) # Did we hit our breakpoint? from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint threads = get_threads_stopped_at_breakpoint(process, breakpoint) self.assertTrue( len(threads) == 1, "There should be a thread stopped at our breakpoint") # The hit count for the breakpoint should be 1. self.assertTrue(breakpoint.GetHitCount() == 1) frame = threads[0].GetFrameAtIndex(0) test_var = frame.FindVariable("test_var") self.assertTrue(test_var.GetError().Success(), "Failed to fetch test_var") test_value = test_var.GetValueAsUnsigned() self.assertEqual(test_value, 10, "Got the right value for test_var")
def test_with_python_api(self): """Test calling methods on super.""" self.build() exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) bpt = target.BreakpointCreateByLocation( self.main_source, self.break_line) self.assertTrue(bpt, VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. process = target.LaunchSimple( None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt) # Make sure we stopped at the first breakpoint. self.assertTrue( len(thread_list) != 0, "No thread stopped at our breakpoint.") self.assertTrue(len(thread_list) == 1, "More than one thread stopped at our breakpoint.") # Now make sure we can call a function in the class method we've # stopped in. frame = thread_list[0].GetFrameAtIndex(0) self.assertTrue(frame, "Got a valid frame 0 frame.") cmd_value = frame.EvaluateExpression("[self get]") self.assertTrue(cmd_value.IsValid()) self.assertTrue(cmd_value.GetValueAsUnsigned() == 2) cmd_value = frame.EvaluateExpression("[super get]") self.assertTrue(cmd_value.IsValid()) self.assertTrue(cmd_value.GetValueAsUnsigned() == 1)
def do_test(self): """Test that archetype-typed objects get resolved to their proper location in memory""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set a breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var = self.frame.FindVariable("things") var.SetPreferDynamicValue(lldb.eDynamicCanRunTarget) var.SetPreferSyntheticValue(True) self.assertTrue(var.GetError().Success(), "Failed to get things: %s"%(var.GetError().GetCString())) self.assertEqual(var.GetNumChildren(), 4, "Got the right number of children") type_name = var.GetTypeName() self.assertEqual(type_name, "Swift.Array<Swift.Int>", "Wrong typename: %s."%(type_name)) for i in range(0,4): child = var.GetChildAtIndex(i) self.assertTrue(child.GetError().Success(), "Failed to get things[%d]: %s"%(i, var.GetError().GetCString())) value = child.GetValueAsUnsigned() self.assertEqual(value, i, "Wrong value: %d not %d."%(value, i))
def test_swift_module_search_paths(self): """ Tests that we can import modules located using target.swift-module-search-paths """ # Build and run the dummy target self.build() exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) a_breakpoint = target.BreakpointCreateBySourceRegex( 'break here', self.main_source_spec) self.assertTrue(a_breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, a_breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") # Add the current working dir to the swift-module-search-paths self.runCmd("settings append target.swift-module-search-paths .") # import the module self.runCmd("e import Module") # Check that we know about the function declared in the module self.match("e plusTen(10)", "error: Couldn't lookup symbols:", error=True)
def do_test(self): """Tests that we can break and display simple types""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) thread = threads[0] frame = thread.frames[0] self.assertTrue(frame.IsValid(), "Couldn't get a frame.") true_vars = ["reg_true", "odd_true", "odd_true_works", "odd_false_works"] for name in true_vars: var = frame.FindVariable(name) summary = var.GetSummary() self.assertTrue(summary == "true", "%s should be true, was: %s"%(name, summary)) false_vars = ["reg_false", "odd_false"] for name in false_vars: var = frame.FindVariable(name) summary = var.GetSummary() self.assertTrue(summary == "false", "%s should be false, was: %s"%(name, summary))
def frame_disassemble_test(self): """Sample test to ensure SBFrame::Disassemble produces SOME output""" exe = self.getBuildArtifact("a.out") # Create a target by the debugger. target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Now create a breakpoint in main.c at the source matching # "Set a breakpoint here" breakpoint = target.BreakpointCreateBySourceRegex( "Set a breakpoint here", lldb.SBFileSpec("main.cpp")) self.assertTrue(breakpoint and breakpoint.GetNumLocations() >= 1, VALID_BREAKPOINT) error = lldb.SBError() # This is the launch info. If you want to launch with arguments or # environment variables, add them using SetArguments or # SetEnvironmentEntries launch_info = target.GetLaunchInfo() process = target.Launch(launch_info, error) self.assertTrue(process, PROCESS_IS_VALID) # Did we hit our breakpoint? from lldbsuite.test.lldbutil import get_threads_stopped_at_breakpoint threads = get_threads_stopped_at_breakpoint(process, breakpoint) self.assertTrue( len(threads) == 1, "There should be a thread stopped at our breakpoint") # The hit count for the breakpoint should be 1. self.assertEquals(breakpoint.GetHitCount(), 1) frame = threads[0].GetFrameAtIndex(0) disassembly = frame.Disassemble() self.assertNotEqual(disassembly, "") self.assertNotIn("error", disassembly) self.assertIn(": nop", disassembly)
def test_with_python_api(self): """Test that we can find stripped Objective-C ivars in the runtime""" self.build() exe = self.getBuildArtifact("a.out.stripped") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) self.dbg.HandleCommand("add-dsym " + self.getBuildArtifact("a.out.dSYM")) breakpoint = target.BreakpointCreateByLocation(self.main_source, self.stop_line) self.assertTrue( breakpoint.IsValid() and breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, self.get_process_working_directory()) self.assertTrue(process, "Created a process.") self.assertEqual(process.GetState(), lldb.eStateStopped, "Stopped it too.") thread_list = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertEquals(len(thread_list), 1) thread = thread_list[0] frame = thread.GetFrameAtIndex(0) self.assertTrue(frame, "frame 0 is valid") # Test the expression for mc->_foo error = lldb.SBError() ivar = frame.EvaluateExpression("(mc->_foo)") self.assertTrue(ivar, "Got result for mc->_foo") ivar_value = ivar.GetValueAsSigned(error) self.assertTrue(error.Success()) self.assertEquals(ivar_value, 3)
def do_test(self): """Tests that we can break and display simple types""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex('Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.expect("frame variable object",substrs = ['(JustSomeType) object = 0x']) self.expect("frame variable -d run-target -- object",substrs = ['(Int) object = 255']) self.runCmd("continue") self.runCmd("frame select 0") self.expect("frame variable --show-types c", substrs = ['(Int) c = 255']) self.expect("frame variable --raw-output --show-types o_some", substrs = ['(Swift.Optional<Swift.String>) o_some = Some {', '(Swift.String) Some =']) self.expect("frame variable --raw-output --show-types o_none", substrs = ['(Swift.Optional<Swift.String>) o_none = None']) self.expect("frame variable o_some o_none", substrs=['(String?) o_some = "Hello"','(String?) o_none = nil'])
def do_test(self): """Test Arrays of Arrays in Swift""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( '// break here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") var_aInt = self.frame.FindVariable("aInt") var_aC = self.frame.FindVariable("aC") lldbutil.check_variable(self, var_aInt, False, num_children=6) lldbutil.check_variable(self, var_aC, False, num_children=5) for i in range(0, 6): var_aIntChild = var_aInt.GetChildAtIndex(i) lldbutil.check_children(self, var_aIntChild, check_for_idx) for i in range(0, 5): var_aCChild = var_aC.GetChildAtIndex(i) lldbutil.check_children(self, var_aCChild, check_for_C)
def do_test(self, setter_method): """Test that we obey thread conditioned breakpoints.""" self.build() main_source_spec = lldb.SBFileSpec("main.cpp") (target, process, main_thread, main_breakpoint) = lldbutil.run_to_source_breakpoint( self, "Set main breakpoint here", main_source_spec) main_thread_id = main_thread.GetThreadID() # This test works by setting a breakpoint in a function conditioned to stop only on # the main thread, and then calling this function on a secondary thread, joining, # and then calling again on the main thread. If the thread specific breakpoint works # then it should not be hit on the secondary thread, only on the main # thread. thread_breakpoint = target.BreakpointCreateBySourceRegex( "Set thread-specific breakpoint here", main_source_spec) self.assertGreater( thread_breakpoint.GetNumLocations(), 0, "thread breakpoint has no locations associated with it.") # Set the thread-specific breakpoint to only stop on the main thread. The run the function # on another thread and join on it. If the thread-specific breakpoint works, the next # stop should be on the main thread. main_thread_id = main_thread.GetThreadID() setter_method(main_thread, thread_breakpoint) process.Continue() next_stop_state = process.GetState() self.assertEqual(next_stop_state, lldb.eStateStopped, "We should have stopped at the thread breakpoint.") stopped_threads = lldbutil.get_threads_stopped_at_breakpoint( process, thread_breakpoint) self.assertEqual( len(stopped_threads), 1, "thread breakpoint stopped at unexpected number of threads") self.assertEqual(stopped_threads[0].GetThreadID(), main_thread_id, "thread breakpoint stopped at the wrong thread")
def get_to_starting_point(self): exe = self.getBuildArtifact("a.out") error = lldb.SBError() self.target = self.dbg.CreateTarget(exe) self.assertTrue(self.target, VALID_TARGET) inner_bkpt = self.target.BreakpointCreateBySourceRegex( "Stop here and step out of me", self.main_source_spec) self.assertTrue(inner_bkpt, VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. self.process = self.target.LaunchSimple( None, None, self.get_process_working_directory()) self.assertTrue(self.process, PROCESS_IS_VALID) # Now finish, and make sure the return value is correct. threads = lldbutil.get_threads_stopped_at_breakpoint( self.process, inner_bkpt) self.assertTrue(len(threads) == 1, "Stopped at inner breakpoint.") self.thread = threads[0]
def do_test(self): """Test that LLDB can reconstruct tuple labels from metadata""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, lldbtest.VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex('break here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, lldbtest.VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, lldbtest.PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint (process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") the_tuple = self.frame.FindVariable('x') the_tuple.SetPreferDynamicValue(lldb.eDynamicCanRunTarget) the_tuple.SetPreferSyntheticValue(True) self.assertTrue(the_tuple.GetChildAtIndex(0).GetName() == 'x', '.0 == x') self.assertTrue(the_tuple.GetChildAtIndex(1).GetName() == '1', '.1 == 1') self.assertTrue(the_tuple.GetChildAtIndex(2).GetName() == 'z', '.2 == z') self.assertTrue(the_tuple.GetChildAtIndex(3).GetName() == '3', '.3 == 3') self.assertTrue(the_tuple.GetChildAtIndex(4).GetName() == 'q', '.4 == q') self.assertTrue(the_tuple.GetChildAtIndex(5).GetName() == 'w', '.5 == q') self.expect('frame variable -d run -- x.w', substrs=['72']) self.expect('expression -d run -- x.z', substrs=['36'])
def do_test(self): """Test expressions in class func contexts""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) breakpoints = [None] # Set the breakpoints for i in range(1, 8): breakpoints.append( target.BreakpointCreateBySourceRegex("breakpoint " + str(i), self.main_source_spec)) self.assertTrue( breakpoints[i].GetNumLocations() > 0, "Didn't get valid breakpoint for {0!s}".format((str(i)))) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Check each context for i in range(1, 8): # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoints[i]) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") self.check_expression("i", str(i), False) self.runCmd("continue")
def auto_continue_location(self): bpno = self.make_target_and_bkpt(pattern="Set a[^ ]* breakpoint here", num_expected_loc=2) bkpt = self.target.FindBreakpointByID(bpno) bkpt.SetAutoContinue(False) loc = lldb.SBBreakpointLocation() for i in range(0, 2): func_name = bkpt.location[i].GetAddress().function.name if func_name == "main": loc = bkpt.location[i] self.assertTrue(loc.IsValid(), "Didn't find a location in main") loc.SetAutoContinue(True) process = self.launch_it(lldb.eStateStopped) threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt) self.assertEqual(len(threads), 1, "Didn't get one thread stopped at our breakpoint") func_name = threads[0].frame[0].function.name self.assertEqual(func_name, "call_me")
def test_vector_values(self): self.build() exe = self.getBuildArtifact("a.out") error = lldb.SBError() self.target = self.dbg.CreateTarget(exe) self.assertTrue(self.target, VALID_TARGET) main_bktp = self.target.BreakpointCreateByName("main", exe) self.assertTrue(main_bktp, VALID_BREAKPOINT) self.process = self.target.LaunchSimple( None, None, self.get_process_working_directory()) self.assertEqual(len(lldbutil.get_threads_stopped_at_breakpoint( self.process, main_bktp)), 1) self.return_and_test_struct_value("return_vector_size_float32_8") self.return_and_test_struct_value("return_vector_size_float32_16") self.return_and_test_struct_value("return_vector_size_float32_32") self.return_and_test_struct_value("return_ext_vector_size_float32_2") self.return_and_test_struct_value("return_ext_vector_size_float32_4") self.return_and_test_struct_value("return_ext_vector_size_float32_8")
def repl_set_up(self): """ Playgrounds REPL test specific setup that must happen after class setup """ exe_name = "PlaygroundStub" exe = self.getBuildArtifact(exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) self.registerSharedLibrariesWithTarget(target, ['libPlaygroundsRuntime.dylib']) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.PlaygroundStub_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) process = target.LaunchSimple(None, None, self.getBuildDir()) self.assertTrue(process, PROCESS_IS_VALID) threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") # Configure lldb self.options = lldb.SBExpressionOptions() self.options.SetLanguage(lldb.eLanguageTypeSwift) self.options.SetPlaygroundTransformEnabled() self.options.SetREPLMode() # Add cleanup to tear down def cleanup(): self.execute_command("make cleanup") self.addTearDownHook(cleanup)
def do_test(self): """Test that we are able to deal with C-imported types from CoreGraphics""" exe_name = "a.out" exe = os.path.join(os.getcwd(), exe_name) # Create the target target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set the breakpoints breakpoint = target.BreakpointCreateBySourceRegex( 'Set breakpoint here', self.main_source_spec) self.assertTrue(breakpoint.GetNumLocations() > 0, VALID_BREAKPOINT) # Launch the process, and do not stop at the entry point. process = target.LaunchSimple(None, None, os.getcwd()) self.assertTrue(process, PROCESS_IS_VALID) # Frame #0 should be at our breakpoint. threads = lldbutil.get_threads_stopped_at_breakpoint( process, breakpoint) self.assertTrue(len(threads) == 1) self.thread = threads[0] self.frame = self.thread.frames[0] self.assertTrue(self.frame, "Frame 0 is valid.") rect = self.frame.FindVariable("cgrect") self.assertTrue(rect.IsValid(), "Got the cgrect variable") origin_var = rect.GetChildMemberWithName("origin") self.assertTrue(origin_var.IsValid(), "Got origin from cgrect") x_var = origin_var.GetChildMemberWithName("x") self.assertTrue(x_var.IsValid(), "Got valid x from cgrect.origin") x_native = x_var.GetChildMemberWithName("native") self.assertTrue( x_native.IsValid(), "Got valid native from cgrect.origin.x") self.assertTrue(x_native.GetValue() == "10", "Value of x is correct")
def test_with_python_api(self): """Test expression parser respect for ObjC built-in types.""" self.build() exe = self.getBuildArtifact("a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) bpt = target.BreakpointCreateByLocation(self.main_source, self.break_line) self.assertTrue(bpt, VALID_BREAKPOINT) # Now launch the process, and do not stop at entry point. process = target.LaunchSimple(None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. thread_list = lldbutil.get_threads_stopped_at_breakpoint(process, bpt) # Make sure we stopped at the first breakpoint. self.assertTrue( len(thread_list) != 0, "No thread stopped at our breakpoint.") self.assertEquals(len(thread_list), 1, "More than one thread stopped at our breakpoint.") # Now make sure we can call a function in the class method we've # stopped in. frame = thread_list[0].GetFrameAtIndex(0) self.assertTrue(frame, "Got a valid frame 0 frame.") self.expect("expr (foo)", patterns=["\(ns::id\) \$.* = 0"]) self.expect("expr --language Objective-C++ -- id my_id = 0; my_id", patterns=["\(id\) \$.* = nil"]) self.expect("expr --language C++ -- id my_id = 0; my_id", patterns=["\(id\) \$.* = nullptr"])