Skip to content

[lldb] Add lldbutil.install_to_target() helper #91944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 14, 2024

Conversation

slydiman
Copy link
Contributor

It can be used in tests #91918, #91931 and such.

@llvmbot
Copy link
Member

llvmbot commented May 13, 2024

@llvm/pr-subscribers-lldb

Author: Dmitry Vasilyev (slydiman)

Changes

It can be used in tests #91918, #91931 and such.


Full diff: https://github.com/llvm/llvm-project/pull/91944.diff

1 Files Affected:

  • (modified) lldb/packages/Python/lldbsuite/test/lldbutil.py (+16)
diff --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py b/lldb/packages/Python/lldbsuite/test/lldbutil.py
index 58eb37fd742d7..e67b68b727b80 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -1654,6 +1654,22 @@ def find_library_callable(test):
     )
 
 
+def target_install(test, filename):
+    path = test.getBuildArtifact(filename)
+    if lldb.remote_platform:
+        remote_path = lldbutil.append_to_process_working_directory(test, filename)
+        err = lldb.remote_platform.Install(
+            lldb.SBFileSpec(path, True), lldb.SBFileSpec(remote_path, False)
+        )
+        if err.Fail():
+            raise Exception(
+                "remote_platform.Install('%s', '%s') failed: %s"
+                % (path, remote_path, err)
+            )
+        path = remote_path
+    return path
+
+
 def read_file_on_target(test, remote):
     if lldb.remote_platform:
         local = test.getBuildArtifact("file_from_target")

@slydiman slydiman requested a review from labath May 13, 2024 12:02
Comment on lines 1658 to 1662
test.assertTrue(filename or path, "filename or path must be specified.")
if filename is None:
filename = os.path.basename(path)
if path is None:
path = test.getBuildArtifact(filename)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit... magical. Can we just have the caller specify a full path to the thing it wants to install? self.getBuildArtifact is not that much extra typing.

Copy link
Contributor Author

@slydiman slydiman May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expected the following usage:

  1. Use filename (most common usage):
target_path = lldbutil.install_to_target(self, "a.out")
  1. Use path:
local_path = self.getBuildArtifact("some_file")
# write to local_path here 
...
# avoid typing "some_file" constant twice, just extract the filename from the local_path
target_path = lldbutil.install_to_target(self, path=local_path) 
  1. Use both:
# "temp" is the filename on the remote target
target_path = lldbutil.install_to_target(self, "temp", local_temp_path_outside_build_dir)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I kept only the full path parameter. Updated. Thanks.

@@ -1654,6 +1654,26 @@ def find_library_callable(test):
)


def target_install(test, filename=None, path=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is optional, but I think something like install_to_target would be a better match for the naming style of the surrounding functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Thanks.

@slydiman slydiman requested a review from labath May 13, 2024 16:08
@slydiman slydiman changed the title [lldb] Add lldbutil.target_install() helper [lldb] Add lldbutil.install_to_target() helper May 14, 2024
@slydiman slydiman merged commit c441aa5 into llvm:main May 14, 2024
4 checks passed
@slydiman slydiman deleted the lldbutil-target_install branch July 25, 2024 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants