import sys
import time
from contextlib import contextmanager
-import platform
import traceback
try:
# and not from the debugger).
libdir = os.path.dirname(__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 ('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 or IS_MAC: # just the extension changes
- prefix = 'attach_'
- 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,))
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
# and not from the debugger).
libdir = os.path.join(os.path.dirname(__file__), 'pydevd_attach_to_process')
- 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 attach to process in platform: %s', sys.platform)
return None
- if arch.lower() not in ('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)