def run_lldb_process_load_and_unload_commands(self): """Test that lldb process load/unload command work correctly.""" self.copy_shlibs_to_remote() exe = self.getBuildArtifact("a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Break at main.cpp before the call to dlopen(). # Use lldb's process load command to load the dylib, instead. lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) ctx = self.platformContext dylibName = ctx.shlib_prefix + 'loadunload_a.' + ctx.shlib_extension localDylibPath = self.getBuildArtifact(dylibName) if lldb.remote_platform: wd = lldb.remote_platform.GetWorkingDirectory() remoteDylibPath = lldbutil.join_remote_paths(wd, dylibName) else: remoteDylibPath = localDylibPath # Make sure that a_function does not exist at this point. self.expect("image lookup -n a_function", "a_function should not exist yet", error=True, matching=False, patterns=["1 match found"]) # Use lldb 'process load' to load the dylib. self.expect("process load %s --install=%s" % (localDylibPath, remoteDylibPath), "%s loaded correctly" % dylibName, patterns=[ 'Loading "%s".*ok' % re.escape(localDylibPath), 'Image [0-9]+ loaded' ]) # Search for and match the "Image ([0-9]+) loaded" pattern. output = self.res.GetOutput() pattern = re.compile("Image ([0-9]+) loaded") for l in output.split(os.linesep): #print("l:", l) match = pattern.search(l) if match: break index = match.group(1) # Now we should have an entry for a_function. self.expect("image lookup -n a_function", "a_function should now exist", patterns=["1 match found .*%s" % dylibName]) # Use lldb 'process unload' to unload the dylib. self.expect("process unload %s" % index, "%s unloaded correctly" % dylibName, patterns=["Unloading .* with index %s.*ok" % index]) self.runCmd("process continue")
def run_lldb_process_load_and_unload_commands(self): """Test that lldb process load/unload command work correctly.""" self.copy_shlibs_to_remote() exe = self.getBuildArtifact("a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Break at main.cpp before the call to dlopen(). # Use lldb's process load command to load the dylib, instead. lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) ctx = self.platformContext dylibName = ctx.shlib_prefix + 'loadunload_a.' + ctx.shlib_extension localDylibPath = self.getBuildArtifact(dylibName) if lldb.remote_platform: wd = lldb.remote_platform.GetWorkingDirectory() remoteDylibPath = lldbutil.join_remote_paths(wd, dylibName) else: remoteDylibPath = localDylibPath # First make sure that we get some kind of error if process load fails. # We print some error even if the load fails, which isn't formalized. # The only plugin at present (Posix) that supports this says "unknown reasons". # If another plugin shows up, let's require it uses "unknown error" as well. non_existant_shlib = "/NoSuchDir/NoSuchSubdir/ReallyNo/NotAFile" self.expect("process load %s" % (non_existant_shlib), error=True, matching=False, patterns=["unknown reasons"]) # Make sure that a_function does not exist at this point. self.expect("image lookup -n a_function", "a_function should not exist yet", error=True, matching=False, patterns=["1 match found"]) # Use lldb 'process load' to load the dylib. self.expect("process load %s --install=%s" % (localDylibPath, remoteDylibPath), "%s loaded correctly" % dylibName, patterns=[ 'Loading "%s".*ok' % re.escape(localDylibPath), 'Image [0-9]+ loaded' ]) # Search for and match the "Image ([0-9]+) loaded" pattern. output = self.res.GetOutput() pattern = re.compile("Image ([0-9]+) loaded") for l in output.split(os.linesep): self.trace("l:", l) match = pattern.search(l) if match: break index = match.group(1) # Now we should have an entry for a_function. self.expect("image lookup -n a_function", "a_function should now exist", patterns=["1 match found .*%s" % dylibName]) # Use lldb 'process unload' to unload the dylib. self.expect("process unload %s" % index, "%s unloaded correctly" % dylibName, patterns=["Unloading .* with index %s.*ok" % index]) self.runCmd("process continue")
def test_platform_process_connect(self): self.build() self.init_llgs_test(False) working_dir = lldb.remote_platform.GetWorkingDirectory() src = lldb.SBFileSpec(self.getBuildArtifact("a.out")) dest = lldb.SBFileSpec(os.path.join(working_dir, "a.out")) err = lldb.remote_platform.Put(src, dest) if err.Fail(): raise RuntimeError("Unable copy '%s' to '%s'.\n>>> %s" % (f, wd, err.GetCString())) m = re.search("^(.*)://([^:/]*)", configuration.lldb_platform_url) protocol = m.group(1) hostname = m.group(2) unix_protocol = protocol.startswith("unix-") if unix_protocol: p = re.search("^(.*)-connect", protocol) path = lldbutil.join_remote_paths( configuration.lldb_platform_working_dir, self.getBuildDirBasename(), "platform-%d.sock" % int(time.time())) listen_url = "%s://%s" % (p.group(1), path) else: listen_url = "*:0" port_file = "%s/port" % working_dir commandline_args = [ "platform", "--listen", listen_url, "--socket-file", port_file, "--", "%s/a.out" % working_dir, "foo" ] self.spawnSubprocess(self.debug_monitor_exe, commandline_args, install_remote=False) socket_id = lldbutil.wait_for_file_on_target(self, port_file) self.dbg.SetAsync(False) new_platform = lldb.SBPlatform(lldb.remote_platform.GetName()) self.dbg.SetSelectedPlatform(new_platform) if unix_protocol: connect_url = "%s://%s%s" % (protocol, hostname, socket_id) else: connect_url = "%s://%s:%s" % (protocol, hostname, socket_id) command = "platform connect %s" % (connect_url) result = lldb.SBCommandReturnObject() self.dbg.GetCommandInterpreter().HandleCommand(command, result) self.assertTrue( result.Succeeded(), "platform process connect failed: %s" % result.GetOutput()) target = self.dbg.GetSelectedTarget() process = target.GetProcess() thread = process.GetThreadAtIndex(0) breakpoint = target.BreakpointCreateByName("main") process.Continue() frame = thread.GetFrameAtIndex(0) self.assertEqual(frame.GetFunction().GetName(), "main") self.assertEqual(frame.FindVariable("argc").GetValueAsSigned(), 2) process.Continue()