2 Test target commands: target.auto-install-main-executable.
6 import gdbremote_testcase
8 from lldbsuite
.test
.decorators
import *
9 from lldbsuite
.test
.lldbtest
import *
10 from lldbsuite
.test
import lldbutil
13 class TestAutoInstallMainExecutable(gdbremote_testcase
.GdbRemoteTestCaseBase
):
14 mydir
= TestBase
.compute_mydir(__file__
)
17 super(TestAutoInstallMainExecutable
, self
).setUp()
18 self
._initial
_platform
= lldb
.DBG
.GetSelectedPlatform()
21 lldb
.DBG
.SetSelectedPlatform(self
._initial
_platform
)
22 super(TestAutoInstallMainExecutable
, self
).tearDown()
27 @expectedFailureAll(hostoslist
=["windows"], triple
='.*-android')
28 def test_target_auto_install_main_executable(self
):
30 self
.init_llgs_test(False)
32 # Manually install the modified binary.
33 working_dir
= lldb
.remote_platform
.GetWorkingDirectory()
34 src_device
= lldb
.SBFileSpec(self
.getBuildArtifact("a.device.out"))
35 dest
= lldb
.SBFileSpec(os
.path
.join(working_dir
, "a.out"))
36 err
= lldb
.remote_platform
.Put(src_device
, dest
)
39 "Unable copy '%s' to '%s'.\n>>> %s" %
40 (src_device
.GetFilename(), working_dir
, err
.GetCString()))
42 m
= re
.search("^(.*)://([^/]*):(.*)$", configuration
.lldb_platform_url
)
45 hostport
= int(m
.group(3))
46 listen_url
= "*:"+str(hostport
+1)
56 self
.debug_monitor_exe
,
59 self
.addTearDownHook(self
.cleanupSubprocesses
)
61 # Wait for the new process gets ready.
64 new_debugger
= lldb
.SBDebugger
.Create()
65 new_debugger
.SetAsync(False)
67 def del_debugger(new_debugger
=new_debugger
):
69 self
.addTearDownHook(del_debugger
)
71 new_platform
= lldb
.SBPlatform(lldb
.remote_platform
.GetName())
72 new_debugger
.SetSelectedPlatform(new_platform
)
73 new_interpreter
= new_debugger
.GetCommandInterpreter()
75 connect_url
= "%s://%s:%s" % (protocol
, hostname
, str(hostport
+1))
77 command
= "platform connect %s" % (connect_url
)
79 result
= lldb
.SBCommandReturnObject()
81 # Test the default setting.
82 new_interpreter
.HandleCommand("settings show target.auto-install-main-executable", result
)
84 result
.Succeeded() and
85 "target.auto-install-main-executable (boolean) = true" in result
.GetOutput(),
86 "Default settings for target.auto-install-main-executable failed.: %s - %s" %
87 (result
.GetOutput(), result
.GetError()))
89 # Disable the auto install.
90 new_interpreter
.HandleCommand("settings set target.auto-install-main-executable false", result
)
91 new_interpreter
.HandleCommand("settings show target.auto-install-main-executable", result
)
93 result
.Succeeded() and
94 "target.auto-install-main-executable (boolean) = false" in result
.GetOutput(),
95 "Default settings for target.auto-install-main-executable failed.: %s - %s" %
96 (result
.GetOutput(), result
.GetError()))
98 new_interpreter
.HandleCommand("platform select %s"%configuration
.lldb_platform_name
, result
)
99 new_interpreter
.HandleCommand(command
, result
)
103 "platform process connect failed: %s - %s" %
104 (result
.GetOutput(),result
.GetError()))
106 # Create the target with the original file.
107 new_interpreter
.HandleCommand("target create --remote-file %s %s "%
108 (os
.path
.join(working_dir
,dest
.GetFilename()), self
.getBuildArtifact("a.out")),
112 "platform create failed: %s - %s" %
113 (result
.GetOutput(),result
.GetError()))
115 target
= new_debugger
.GetSelectedTarget()
116 breakpoint
= target
.BreakpointCreateByName("main")
118 launch_info
= lldb
.SBLaunchInfo(None)
119 error
= lldb
.SBError()
120 process
= target
.Launch(launch_info
, error
)
121 self
.assertTrue(process
, PROCESS_IS_VALID
)
123 thread
= lldbutil
.get_stopped_thread(process
, lldb
.eStopReasonBreakpoint
)
126 "There should be a thread stopped due to breakpoint")
128 frame
= thread
.GetFrameAtIndex(0)
129 self
.assertEqual(frame
.GetFunction().GetName(), "main")
131 new_interpreter
.HandleCommand("target variable build", result
)
133 result
.Succeeded() and
134 '"device"' in result
.GetOutput(),
135 "Magic in the binary is wrong: %s " % result
.GetOutput())