From: Julian Gilbey <jdg@debian.org>
Date: Tue, 28 Oct 2025 12:16:57 -0700
Subject: Use buildflags and only build one attach_linux binary

Forwarded: not-needed
Last-Update: 2024-06-30

 Original patch: William Grzybowski <william@grzy.org>
 The original code tries to build both 32-bit and 64-bit versions.
 This patched version only builds one copy of the library for the
 build architecture.
---
 .../add_code_to_python_process.py                  | 109 +--------------------
 pydevd_tracing.py                                  |  92 ++---------------
 2 files changed, 10 insertions(+), 191 deletions(-)

diff --git a/pydevd_attach_to_process/add_code_to_python_process.py b/pydevd_attach_to_process/add_code_to_python_process.py
index 8f5372c..c0bdc65 100644
--- a/pydevd_attach_to_process/add_code_to_python_process.py
+++ b/pydevd_attach_to_process/add_code_to_python_process.py
@@ -76,7 +76,6 @@ import subprocess
 import sys
 import time
 from contextlib import contextmanager
-import platform
 import traceback
 
 try:
@@ -141,114 +140,14 @@ def get_target_filename(is_target_process_64=None, prefix=None, extension=None):
     # and not from the debugger).
     libdir = os.path.dirname(os.path.abspath(__file__))
 
-    if is_target_process_64 is None:
-        if IS_WINDOWS:
-            # i.e.: On windows the target process could have a different bitness (32bit is emulated on 64bit).
-            raise AssertionError("On windows it's expected that the target bitness is specified.")
-
-        # For other platforms, just use the the same bitness of the process we're running in.
-        is_target_process_64 = is_python_64bit()
-
-    arch = ""
-    if IS_WINDOWS:
-        # prefer not using platform.machine() when possible (it's a bit heavyweight as it may
-        # spawn a subprocess).
-        arch = os.environ.get("PROCESSOR_ARCHITEW6432", os.environ.get("PROCESSOR_ARCHITECTURE", ""))
-
-    if not arch:
-        arch = platform.machine()
-        if not arch:
-            print("platform.machine() did not return valid value.")  # This shouldn't happen...
-            return None
-
-    if IS_WINDOWS:
-        if not extension:
-            extension = ".dll"
-        suffix_64 = "amd64"
-        suffix_32 = "x86"
-
-    elif IS_LINUX:
-        if not extension:
-            extension = ".so"
-        suffix_64 = "amd64"
-        suffix_32 = "x86"
-
-    elif IS_MAC:
-        if not extension:
-            extension = ".dylib"
-        suffix_64 = "x86_64"
-        suffix_32 = "x86"
+    # This is a very simplified version for Debian builds
 
-    else:
+    if not IS_LINUX:
         print("Unable to attach to process in platform: %s", sys.platform)
         return None
 
-    if arch.lower() not in ("arm64", "amd64", "x86", "x86_64", "i386", "x86"):
-        # We don't support this processor by default. Still, let's support the case where the
-        # user manually compiled it himself with some heuristics.
-        #
-        # Ideally the user would provide a library in the format: "attach_<arch>.<extension>"
-        # based on the way it's currently compiled -- see:
-        # - windows/compile_windows.bat
-        # - linux_and_mac/compile_linux.sh
-        # - linux_and_mac/compile_mac.sh
-
-        try:
-            found = [name for name in os.listdir(libdir) if name.startswith("attach_") and name.endswith(extension)]
-        except:
-            print("Error listing dir: %s" % (libdir,))
-            traceback.print_exc()
-            return None
-
-        if prefix:
-            expected_name = prefix + arch + extension
-            expected_name_linux = prefix + "linux_" + arch + extension
-        else:
-            # Default is looking for the attach_ / attach_linux
-            expected_name = "attach_" + arch + extension
-            expected_name_linux = "attach_linux_" + arch + extension
-
-        filename = None
-        if expected_name in found:  # Heuristic: user compiled with "attach_<arch>.<extension>"
-            filename = os.path.join(libdir, expected_name)
-
-        elif IS_LINUX and expected_name_linux in found:  # Heuristic: user compiled with "attach_linux_<arch>.<extension>"
-            filename = os.path.join(libdir, expected_name_linux)
-
-        elif len(found) == 1:  # Heuristic: user removed all libraries and just left his own lib.
-            filename = os.path.join(libdir, found[0])
-
-        else:  # Heuristic: there's one additional library which doesn't seem to be our own. Find the odd one.
-            filtered = [name for name in found if not name.endswith((suffix_64 + extension, suffix_32 + extension))]
-            if len(filtered) == 1:  # If more than one is available we can't be sure...
-                filename = os.path.join(libdir, found[0])
-
-        if filename is None:
-            print("Unable to attach to process in arch: %s (did not find %s in %s)." % (arch, expected_name, libdir))
-            return None
-
-        print("Using %s in arch: %s." % (filename, arch))
-
-    else:
-        if is_target_process_64:
-            suffix = suffix_64
-        else:
-            suffix = suffix_32
-
-        if not prefix:
-            # Default is looking for the attach_ / attach_linux
-            if IS_WINDOWS:  # just the extension changes
-                prefix = "attach_"
-            elif IS_MAC:
-                prefix = "attach"
-                suffix = ""
-            elif IS_LINUX:
-                prefix = "attach_linux_"  # historically it has a different name
-            else:
-                print("Unable to attach to process in platform: %s" % (sys.platform,))
-                return None
-
-        filename = os.path.join(libdir, "%s%s%s" % (prefix, suffix, extension))
+    libname = "attach.so"
+    filename = os.path.join(libdir, libname)
 
     if not os.path.exists(filename):
         print("Expected: %s to exist." % (filename,))
diff --git a/pydevd_tracing.py b/pydevd_tracing.py
index a84ea1d..f3c4039 100644
--- a/pydevd_tracing.py
+++ b/pydevd_tracing.py
@@ -14,7 +14,6 @@ from _pydevd_bundle.pydevd_constants import (
 from _pydev_bundle._pydev_saved_modules import thread, threading
 from _pydev_bundle import pydev_log, pydev_monkey
 import os.path
-import platform
 import ctypes
 from io import StringIO
 import sys
@@ -170,95 +169,16 @@ def get_python_helper_lib_filename():
     if not os.path.exists(libdir):
         pydev_log.critical("Expected the directory: %s to exist!", libdir)
 
-    arch = ""
-    if IS_WINDOWS:
-        # prefer not using platform.machine() when possible (it's a bit heavyweight as it may
-        # spawn a subprocess).
-        arch = os.environ.get("PROCESSOR_ARCHITEW6432", os.environ.get("PROCESSOR_ARCHITECTURE", ""))
+    # This is a very simplified version for Debian builds
 
-    if not arch:
-        arch = platform.machine()
-        if not arch:
-            pydev_log.info("platform.machine() did not return valid value.")  # This shouldn't happen...
-            return None
-
-    if IS_WINDOWS:
-        extension = ".dll"
-        suffix_64 = "amd64"
-        suffix_32 = "x86"
-
-    elif IS_LINUX:
-        extension = ".so"
-        suffix_64 = "amd64"
-        suffix_32 = "x86"
-
-    elif IS_MAC:
-        extension = ".dylib"
-        suffix_64 = "x86_64"
-        suffix_32 = "x86"
-
-    else:
-        pydev_log.info("Unable to set trace to all threads in platform: %s", sys.platform)
+    if not IS_LINUX:
+        print("Unable to set trace to all threads in platform: %s", sys.platform)
         return None
 
-    if arch.lower() not in ("arm64", "amd64", "x86", "x86_64", "i386", "x86"):
-        # We don't support this processor by default. Still, let's support the case where the
-        # user manually compiled it himself with some heuristics.
-        #
-        # Ideally the user would provide a library in the format: "attach_<arch>.<extension>"
-        # based on the way it's currently compiled -- see:
-        # - windows/compile_windows.bat
-        # - linux_and_mac/compile_linux.sh
-        # - linux_and_mac/compile_mac.sh
-
-        try:
-            found = [name for name in os.listdir(libdir) if name.startswith("attach_") and name.endswith(extension)]
-        except:
-            if DebugInfoHolder.DEBUG_TRACE_LEVEL >= 1:
-                # There is no need to show this unless debug tracing is enabled.
-                pydev_log.exception("Error listing dir: %s", libdir)
-            return None
-
-        expected_name = "attach_" + arch + extension
-        expected_name_linux = "attach_linux_" + arch + extension
-
-        filename = None
-        if expected_name in found:  # Heuristic: user compiled with "attach_<arch>.<extension>"
-            filename = os.path.join(libdir, expected_name)
-
-        elif IS_LINUX and expected_name_linux in found:  # Heuristic: user compiled with "attach_linux_<arch>.<extension>"
-            filename = os.path.join(libdir, expected_name_linux)
-
-        elif len(found) == 1:  # Heuristic: user removed all libraries and just left his own lib.
-            filename = os.path.join(libdir, found[0])
-
-        else:  # Heuristic: there's one additional library which doesn't seem to be our own. Find the odd one.
-            filtered = [name for name in found if not name.endswith((suffix_64 + extension, suffix_32 + extension))]
-            if len(filtered) == 1:  # If more than one is available we can't be sure...
-                filename = os.path.join(libdir, found[0])
-
-        if filename is None:
-            pydev_log.info("Unable to set trace to all threads in arch: %s (did not find a %s lib in %s).", arch, expected_name, libdir)
-            return None
-
-        pydev_log.info("Using %s lib in arch: %s.", filename, arch)
-
-    else:
-        # Happy path for which we have pre-compiled binaries.
-        if IS_64BIT_PROCESS:
-            suffix = suffix_64
-        else:
-            suffix = suffix_32
-
-        if IS_WINDOWS or IS_MAC:  # just the extension changes
-            prefix = "attach_"
-        elif IS_LINUX:  #
-            prefix = "attach_linux_"  # historically it has a different name
-        else:
-            pydev_log.info("Unable to set trace to all threads in platform: %s", sys.platform)
-            return None
+    libname = "attach.so"
+    filename = os.path.join(libdir, libname)
 
-        filename = os.path.join(libdir, "%s%s%s" % (prefix, suffix, extension))
+    pydev_log.info("Using %s lib.", filename)
 
     if not os.path.exists(filename):
         pydev_log.critical("Expected: %s to exist.", filename)
