Skip to content

Commit

Permalink
PY-44191 PY-48163 Provide Attach to process binary for Linux AArch6…
Browse files Browse the repository at this point in the history
…4 and universal binary for macOS

Now we use the following binaries for `Attach to process`:

Windows:
- `attach_amd64.dll`
- `attach_x86.dll`
(no changes in this commit, no ARM64 support)

Linux:
- `attach_linux_amd64.so`
- `attach_linux_x86.so`
- `attach_linux_aarch64.so`
(the last one was added)

macOS:
- `attach.dylib`
(universal binary containing both arm64 and x86_64 code)

Note, `attach_x86.dylib` was removed and was not merged into the universal binary because Apple dropped support for 32-bit apps in macOS Catalina (10.15). However, there is still obsolete code for macOS i386 in the `pydev` module that should be dropped in the future

GitOrigin-RevId: 51cdf976eaf5580218cf6026849e4da51c9370e6
  • Loading branch information
artemmukhin authored and intellij-monorepo-bot committed Mar 9, 2023
1 parent 054f99c commit 2e7109f
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 35 deletions.
4 changes: 3 additions & 1 deletion python/helpers/pydev/_pydevd_bundle/pydevd_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ def dummy_excepthook(exctype, value, traceback):
IS_WINDOWS = "windows" in System.Environment.OSVersion.VersionString.lower()

IS_64BIT_PROCESS = sys.maxsize > (2 ** 32)
IS_ARM64 = platform.machine() == 'arm64'

# `aarch64` on Linux, `arm64` on macOS
IS_AARCH64 = platform.machine().lower() in ['aarch64', 'arm64']

IS_LINUX = sys.platform.startswith('linux')
IS_MACOS = sys.platform == 'darwin'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,10 @@ def is_mac():
return platform.system() == 'Darwin'


def is_mac_arm64():
def is_aarch64():
import platform
return platform.machine() == 'arm64'
# `aarch64` on Linux, `arm64` on macOS
return platform.machine().lower() in ['aarch64', 'arm64']


def run_python_code_windows(pid, python_code, connect_debugger_tracing=False, show_debug_info=0):
Expand Down Expand Up @@ -452,11 +453,15 @@ def run_python_code_linux(pid, python_code, connect_debugger_tracing=False, show

# Valid arguments for arch are i386, i386:x86-64, i386:x64-32, i8086,
# i386:intel, i386:x86-64:intel, i386:x64-32:intel, i386:nacl,
# i386:x86-64:nacl, i386:x64-32:nacl, auto.
# i386:x86-64:nacl, i386:x64-32:nacl, aarch64, auto.

if is_python_64bit():
suffix = 'amd64'
arch = 'i386:x86-64'
if is_aarch64():
suffix = 'aarch64'
arch = 'aarch64'
else:
suffix = 'amd64'
arch = 'i386:x86-64'
else:
suffix = 'x86'
arch = 'i386'
Expand Down Expand Up @@ -539,19 +544,16 @@ def run_python_code_mac(pid, python_code, connect_debugger_tracing=False, show_d
# i386:x86-64:nacl, i386:x64-32:nacl, auto, arm64

if is_python_64bit():
if is_mac_arm64():
suffix = 'arm64.dylib'
if is_aarch64():
arch = 'arm64'
else:
suffix = 'x86_64.dylib'
arch = 'i386:x86-64'
else:
suffix = 'x86.dylib'
arch = 'i386'

debug('Attaching with arch: %s'% (arch,))

target_dll = os.path.join(filedir, 'attach_%s' % suffix)
target_dll = os.path.join(filedir, 'attach.dylib')
target_dll = os.path.normpath(target_dll)
if not os.path.exists(target_dll):
raise RuntimeError('Could not find dll file to inject: %s' % target_dll)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
g++ -march=armv8-a -shared -o attach_linux_aarch64.so -fPIC -nostartfiles attach.cpp
mv attach_linux_aarch64.so ../attach_linux_aarch64.so
echo Compiled aarch64
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
g++ -fPIC -D_REENTRANT -std=c++11 -arch x86_64 -c -o attach_x86_64.o attach.cpp
g++ -dynamiclib -nostartfiles -arch x86_64 -o attach_x86_64.dylib attach_x86_64.o -lc
rm attach_x86_64.o
mv attach_x86_64.dylib ../attach_x86_64.dylib

clang++ -fPIC -D_REENTRANT -std=c++11 -arch arm64 -c -o attach_arm64.o attach.cpp
clang++ -dynamiclib -nostartfiles -arch arm64 -o attach_arm64.dylib attach_arm64.o -lc
rm attach_arm64.o

g++ -fPIC -D_REENTRANT -std=c++11 -arch i386 -c -o attach_x86.o attach.cpp
g++ -dynamiclib -nostartfiles -arch i386 -o attach_x86.dylib attach_x86.o -lc
rm attach_x86.o
mv attach_x86.dylib ../attach_x86.dylib
clang++ -fPIC -D_REENTRANT -std=c++11 -arch x86_64 -c -o attach_x86_64.o attach.cpp
clang++ -dynamiclib -nostartfiles -arch x86_64 -o attach_x86_64.dylib attach_x86_64.o -lc
rm attach_x86_64.o

lipo -create attach_arm64.dylib attach_x86_64.dylib -output attach.dylib
rm attach_arm64.dylib attach_x86_64.dylib
mv attach.dylib ../attach.dylib

This file was deleted.

17 changes: 6 additions & 11 deletions python/helpers/pydev/pydevd_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from _pydev_bundle import pydev_log, pydev_monkey
from _pydevd_bundle.pydevd_constants import get_frame, IS_PY2, IS_PY37_OR_GREATER, IS_CPYTHON, IS_WINDOWS, IS_LINUX, IS_MACOS, \
IS_64BIT_PROCESS, IS_ARM64, IS_PYCHARM_ATTACH
IS_64BIT_PROCESS, IS_AARCH64, IS_PYCHARM_ATTACH
from _pydev_imps._pydev_saved_modules import thread, threading

try:
Expand Down Expand Up @@ -112,22 +112,17 @@ def load_python_helper_lib():

elif IS_LINUX:
if IS_64BIT_PROCESS:
suffix = 'amd64'
if IS_AARCH64:
suffix = 'aarch64'
else:
suffix = 'amd64'
else:
suffix = 'x86'

filename = os.path.join(os.path.dirname(__file__), 'pydevd_attach_to_process', 'attach_linux_%s.so' % (suffix,))

elif IS_MACOS:
if IS_64BIT_PROCESS:
if IS_ARM64:
suffix = 'arm64.dylib'
else:
suffix = 'x86_64.dylib'
else:
suffix = 'x86.dylib'

filename = os.path.join(os.path.dirname(__file__), 'pydevd_attach_to_process', 'attach_%s' % (suffix,))
filename = os.path.join(os.path.dirname(__file__), 'pydevd_attach_to_process', 'attach.dylib')

else:
pydev_log.info('Unable to set trace to all threads in platform: %s' % sys.platform)
Expand Down

0 comments on commit 2e7109f

Please sign in to comment.