1""" 2Test target commands: target.auto-install-main-executable. 3""" 4 5import time 6import gdbremote_testcase 7 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class TestAutoInstallMainExecutable(gdbremote_testcase.GdbRemoteTestCaseBase): 14 mydir = TestBase.compute_mydir(__file__) 15 16 @llgs_test 17 @no_debug_info_test 18 @skipIf(remote=False) 19 @expectedFailureAll(hostoslist=["windows"], triple='.*-android') 20 def test_target_auto_install_main_executable(self): 21 self.build() 22 self.init_llgs_test(False) 23 24 # Manually install the modified binary. 25 working_dir = lldb.remote_platform.GetWorkingDirectory() 26 src_device = lldb.SBFileSpec(self.getBuildArtifact("a.device.out")) 27 dest = lldb.SBFileSpec(os.path.join(working_dir, "a.out")) 28 err = lldb.remote_platform.Put(src_device, dest) 29 if err.Fail(): 30 raise RuntimeError( 31 "Unable copy '%s' to '%s'.\n>>> %s" % 32 (src_device.GetFilename(), working_dir, err.GetCString())) 33 34 m = re.search("^(.*)://([^/]*):(.*)$", configuration.lldb_platform_url) 35 protocol = m.group(1) 36 hostname = m.group(2) 37 hostport = int(m.group(3)) 38 listen_url = "*:"+str(hostport+1) 39 40 commandline_args = [ 41 "platform", 42 "--listen", 43 listen_url, 44 "--server" 45 ] 46 47 self.spawnSubprocess( 48 self.debug_monitor_exe, 49 commandline_args, 50 install_remote=False) 51 52 # Wait for the new process gets ready. 53 time.sleep(0.1) 54 55 self.dbg.SetAsync(False) 56 57 new_platform = lldb.SBPlatform(lldb.remote_platform.GetName()) 58 self.dbg.SetSelectedPlatform(new_platform) 59 60 connect_url = "%s://%s:%s" % (protocol, hostname, str(hostport+1)) 61 62 # Test the default setting. 63 self.expect("settings show target.auto-install-main-executable", 64 substrs=["target.auto-install-main-executable (boolean) = true"], 65 msg="Default settings for target.auto-install-main-executable failed.") 66 67 # Disable the auto install. 68 self.runCmd("settings set target.auto-install-main-executable false") 69 self.expect("settings show target.auto-install-main-executable", 70 substrs=["target.auto-install-main-executable (boolean) = false"]) 71 72 self.runCmd("platform select %s"%configuration.lldb_platform_name) 73 self.runCmd("platform connect %s" % (connect_url)) 74 75 # Create the target with the original file. 76 self.runCmd("target create --remote-file %s %s "% 77 (os.path.join(working_dir,dest.GetFilename()), 78 self.getBuildArtifact("a.out"))) 79 80 target = new_debugger.GetSelectedTarget() 81 breakpoint = target.BreakpointCreateByName("main") 82 83 launch_info = lldb.SBLaunchInfo(None) 84 error = lldb.SBError() 85 process = target.Launch(launch_info, error) 86 self.assertTrue(process, PROCESS_IS_VALID) 87 88 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) 89 self.assertTrue( 90 thread.IsValid(), 91 "There should be a thread stopped due to breakpoint") 92 93 frame = thread.GetFrameAtIndex(0) 94 self.assertEqual(frame.GetFunction().GetName(), "main") 95 96 self.expect("target variable build", substrs=['"device"'], 97 msg="Magic in the binary is wrong") 98 99 process.Continue() 100