================
@@ -340,11 +341,101 @@ def find_matching_slice(self):
                     print(
                         (
                             "error\n    error: unable to locate '%s' with UUID 
%s"
-                            % (self.path, self.get_normalized_uuid_string())
+                            % (path, self.get_normalized_uuid_string())
                         )
                     )
                 return False
 
+        def patch_binary_search_path(self):
+            home = os.path.expanduser("~")
+
+            patched_search_path = self.path.replace("/Users/USER", home)
+
+            if "*" in patched_search_path:
+                patched_search_path = patched_search_path[
+                    : patched_search_path.index("*")
+                ]
+
+            return patched_search_path
+
+        def find_binary_with_speculative_path(self, target_uuid):
+            search_path = self.patch_binary_search_path()
+
+            target_uuid = target_uuid.lower()
+            stop_flag = {"found": False}
+
+            with print_lock:
+                print(
+                    "Scanning for '%s' for '%s' ... (ˆC to interrupt)"
+                    % (search_path, os.path.basename(self.path))
+                )
+
+            def is_executable(path):
+                try:
+                    st = os.stat(path)
+                    return stat.S_ISREG(st.st_mode) and (
+                        st.st_mode & (stat.S_IXUSR | stat.S_IXGRP | 
stat.S_IXOTH)
+                    )
+                except:
+                    return False
+
+            def check_uuid(path, target_uuid):
+                try:
+                    output = subprocess.check_output(
+                        ["dwarfdump", "--uuid", path],
+                        text=True,
+                        stderr=subprocess.DEVNULL,
+                    )
+                    for line in output.splitlines():
+                        if target_uuid in line.lower():
+                            return path
+                except:
+                    return None
+                return None
+
+            def scan_directory_recursive(dirpath, target_uuid, stop_flag):
+                for root, _, files in os.walk(dirpath):
+                    if stop_flag.get("found"):
+                        break
+                    for name in files:
+                        path = os.path.join(root, name)
+                        if stop_flag.get("found"):
+                            break
+                        if is_executable(path):
+                            result = check_uuid(path, target_uuid)
+                            if result:
+                                stop_flag["found"] = True
+                                return result
+                return None
+
+            try:
+                subdirs = [
+                    os.path.join(search_path, d)
+                    for d in os.listdir(search_path)
+                    if os.path.isdir(os.path.join(search_path, d))
+                ]
+            except PermissionError:
----------------
bulbazord wrote:

This PermissionError comes from `os.path.isdir` right? Does that mean if _any_ 
directory has a permission error then you wouldn't recurse at all?

https://github.com/llvm/llvm-project/pull/154975
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to