Skip to content

Commit

Permalink
os.path.join does not always work for paths on remote platforms.
Browse files Browse the repository at this point in the history
Summary:
Since we don't yet have remote windows debugging, it should be safe to assume
that the remote target uses unix path separators.

Reviewers: ovyalov, zturner, clayborg, vharron

Reviewed By: vharron

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D9633

llvm-svn: 237006
  • Loading branch information
chaoren committed May 11, 2015
1 parent 59b60af commit 3e2bdb4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
23 changes: 11 additions & 12 deletions lldb/test/lldbtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import unittest2
import lldb
import lldbtest_config
import lldbutil
from _pyio import __metaclass__

# See also dotest.parseOptionsAndInitTestdirs(), where the environment variables
Expand Down Expand Up @@ -304,11 +305,9 @@ def pid(self):
return self._pid

def launch(self, executable, args):
remote_work_dir = lldb.remote_platform.GetWorkingDirectory()

if self._install_remote:
src_path = executable
dst_path = os.path.join(remote_work_dir, os.path.basename(executable))
dst_path = lldbutil.append_to_remote_wd(os.path.basename(executable))

dst_file_spec = lldb.SBFileSpec(dst_path, False)
err = lldb.remote_platform.Install(lldb.SBFileSpec(src_path, True), dst_file_spec)
Expand All @@ -320,7 +319,7 @@ def launch(self, executable, args):

launch_info = lldb.SBLaunchInfo(args)
launch_info.SetExecutableFile(dst_file_spec, True)
launch_info.SetWorkingDirectory(remote_work_dir)
launch_info.SetWorkingDirectory(lldb.remote_platform.GetWorkingDirectory())

# Redirect stdout and stderr to /dev/null
launch_info.AddSuppressFileAction(1, False, True)
Expand Down Expand Up @@ -1389,7 +1388,7 @@ def markExpectedFailure(self,err,bugnumber):
if bugnumber == None:
print >> sbuf, "expected failure"
else:
print >> sbuf, "expected failure (problem id:" + str(bugnumber) + ")"
print >> sbuf, "expected failure (problem id:" + str(bugnumber) + ")"

def markSkippedTest(self):
"""Callback invoked when a test is skipped."""
Expand All @@ -1410,7 +1409,7 @@ def markUnexpectedSuccess(self, bugnumber):
if bugnumber == None:
print >> sbuf, "unexpected success"
else:
print >> sbuf, "unexpected success (problem id:" + str(bugnumber) + ")"
print >> sbuf, "unexpected success (problem id:" + str(bugnumber) + ")"

def getRerunArgs(self):
return " -f %s.%s" % (self.__class__.__name__, self._testMethodName)
Expand Down Expand Up @@ -2003,11 +2002,11 @@ def DecoratedLaunchSimple(argv, envp, wd):
lldb.pre_flight(self)

if lldb.remote_platform:
#remote_test_dir = os.path.join(lldb.remote_platform_working_dir, self.mydir)
remote_test_dir = os.path.join(lldb.remote_platform_working_dir,
self.getArchitecture(),
str(self.test_number),
self.mydir)
remote_test_dir = lldbutil.join_remote_paths(
lldb.remote_platform_working_dir,
self.getArchitecture(),
str(self.test_number),
self.mydir)
error = lldb.remote_platform.MakeDirectory(remote_test_dir, 0700)
if error.Success():
lldb.remote_platform.SetWorkingDirectory(remote_test_dir)
Expand Down Expand Up @@ -2056,7 +2055,7 @@ def registerSharedLibrariesWithTarget(self, target, shlibs):
if lldb.remote_platform:
# We must set the remote install location if we want the shared library
# to get uploaded to the remote target
remote_shlib_path = os.path.join(lldb.remote_platform.GetWorkingDirectory(), os.path.basename(local_shlib_path))
remote_shlib_path = lldbutil.append_to_remote_wd(os.path.basename(local_shlib_path))
shlib_module.SetRemoteInstallFileSpec(lldb.SBFileSpec(remote_shlib_path, False))

return environment
Expand Down
13 changes: 13 additions & 0 deletions lldb/test/lldbutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,3 +890,16 @@ def format(self, value, buffer=None):
BasicFormatter.format(self, child, buffer=output, indent=new_indent)

return output.getvalue()

# ===========================================================
# Utility functions for path manipulation on remote platforms
# ===========================================================

def join_remote_paths(*paths):
# TODO: update with actual platform name for remote windows once it exists
if lldb.remote_platform.GetName() == 'remote-windows':
return os.path.join(*paths).replace(os.path.sep, '\\')
return os.path.join(*paths).replace(os.path.sep, '/')

def append_to_remote_wd(*paths):
return join_remote_paths(lldb.remote_platform.GetWorkingDirectory(), *paths)
2 changes: 1 addition & 1 deletion lldb/test/python_api/target/TestTargetAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def launch_new_process_and_redirect_stdout(self):
# The inferior should run to completion after "process.Continue()" call.
local_path = "stdout.txt";
if lldb.remote_platform:
stdout_path = os.path.join(lldb.remote_platform.GetWorkingDirectory(), "lldb-stdout-redirect.txt")
stdout_path = lldbutil.append_to_remote_wd("lldb-stdout-redirect.txt")
else:
stdout_path = local_path
error = lldb.SBError()
Expand Down
3 changes: 1 addition & 2 deletions lldb/test/tools/lldb-server/TestLldbGdbServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ def install_and_create_launch_args(self):
exe_path = os.path.abspath('a.out')
if not lldb.remote_platform:
return [exe_path]
remote_work_dir = lldb.remote_platform.GetWorkingDirectory()
remote_path = os.path.join(remote_work_dir, os.path.basename(exe_path))
remote_path = lldbutil.append_to_remote_wd(os.path.basename(exe_path))
remote_file_spec = lldb.SBFileSpec(remote_path, False)
err = lldb.remote_platform.Install(lldb.SBFileSpec(exe_path, True), remote_file_spec)
if err.Fail():
Expand Down
3 changes: 1 addition & 2 deletions lldb/test/tools/lldb-server/gdbremote_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,7 @@ def prep_debug_monitor_and_inferior(self, inferior_args=None, inferior_sleep_sec
inferior_exe_path = os.path.abspath("a.out")

if lldb.remote_platform:
remote_work_dir = lldb.remote_platform.GetWorkingDirectory()
remote_path = os.path.join(remote_work_dir, os.path.basename(inferior_exe_path))
remote_path = lldbutil.append_to_remote_wd(os.path.basename(inferior_exe_path))
remote_file_spec = lldb.SBFileSpec(remote_path, False)
err = lldb.remote_platform.Install(lldb.SBFileSpec(inferior_exe_path, True), remote_file_spec)
if err.Fail():
Expand Down
2 changes: 1 addition & 1 deletion lldb/test/types/AbstractBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def process_launch_o(self, localPath):
if lldb.remote_platform:
# process launch -o requires a path that is valid on the target
self.assertIsNotNone(lldb.remote_platform.GetWorkingDirectory())
remote_path = os.path.join(lldb.remote_platform.GetWorkingDirectory(), "lldb-stdout-redirect.txt")
remote_path = lldbutil.append_to_remote_wd("lldb-stdout-redirect.txt")
self.runCmd('process launch -o {remote}'.format(remote=remote_path))
# copy remote_path to local host
self.runCmd('platform get-file {remote} "{local}"'.format(
Expand Down

0 comments on commit 3e2bdb4

Please sign in to comment.