Skip to content

Commit

Permalink
Don't crash if running under CPython debug build. Fixes microsoft#152
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed May 22, 2020
1 parent 4715925 commit af89fc8
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/debugpy/_vendored/pydevd/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ matrix:
- PYDEVD_USE_CYTHON=NO
- PYDEVD_TEST_VM=CPYTHON

# Python 3.7
# Python 3.8 debug
- python: 2.7
env:
- PYDEVD_PYTHON_VERSION=3.7
- PYDEVD_USE_CYTHON=YES
- PYDEVD_TEST_VM=CPYTHON
- PYDEVD_PYTHON_VERSION=3.8
- PYDEVD_TEST_VM=CPYTHON_DEBUG
- PYDEVD_USE_CONDA=NO

- python: 3.8
env:
Expand Down Expand Up @@ -124,6 +124,7 @@ install:
# On local machine with jython: c:\bin\jython2.7.0\bin\jython.exe -Dpython.path=.;jython_test_deps/ant.jar;jython_test_deps/junit.jar -m pytest
# On remove machine with python: c:\bin\python27\python.exe -m pytest
script:
- if [[ ("$PYDEVD_TEST_VM" == "CPYTHON_DEBUG") ]]; then ./.travis/install_and_run_debug_py.sh; fi
- if [[ ("$PYDEVD_TEST_VM" == "CPYTHON") ]]; then ./.travis/run_python_pytest.sh; fi
- if [ "$PYDEVD_TEST_VM" == "PYPY" ]; then source activate build_env; pypy3 -m pytest -n auto; fi
- if [ "$PYDEVD_TEST_VM" == "JYTHON" ]; then jython -Dpython.path=.:jython_test_deps/ant.jar:jython_test_deps/junit.jar -m pytest --tb=native; fi
Expand Down
43 changes: 43 additions & 0 deletions src/debugpy/_vendored/pydevd/.travis/install_and_run_debug_py.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Build the cython extensions (to check that we don't crash when they're there in debug mode).
python setup_cython.py build_ext --inplace

curl -L https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz -o Python-3.8.3.tgz
tar -xzf Python-3.8.3.tgz
cd Python-3.8.3
mkdir debug
cd debug
../configure --with-pydebug
make

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
./python get-pip.py

./python -m pip install "pytest"
./python -m pip install "psutil"
./python -m pip install "untangle"

# Check that it worked.
./python -c "import pytest"
./python -c "import psutil"
./python -c "import untangle"

cd ..
cd ..
ls -la

./Python-3.8.3/debug/python -c "import sys;assert hasattr(sys,'gettotalrefcount')"

cd tests_python

# Although we compiled cython, all we're checking is that we don't crash (since it was built for the release env).
../Python-3.8.3/debug/python -m pytest test_debugger_json.py -k "test_case_json_change_breaks or test_remote_debugger_basic"
export PYTHONPATH=..
../Python-3.8.3/debug/python -c "import check_debug_python;check_debug_python.check() "

# pip install "cython"
# pip install trio
# pip install gevent
#
# # Note: track the latest web framework versions.
# pip install "django"
# pip install "cherrypy"
5 changes: 4 additions & 1 deletion src/debugpy/_vendored/pydevd/pydevd_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def restore_sys_set_trace_func():


def load_python_helper_lib():
if not IS_CPYTHON or ctypes is None or sys.version_info[:2] > (3, 8):
if not IS_CPYTHON or ctypes is None or sys.version_info[:2] > (3, 8) or hasattr(sys, 'gettotalrefcount'):
return None

if IS_WINDOWS:
Expand Down Expand Up @@ -159,8 +159,11 @@ def load_python_helper_lib():
def set_trace_to_threads(tracing_func):
lib = load_python_helper_lib()
if lib is None: # This is the case if it's not CPython.
pydev_log.info('Unable to load helper lib to set tracing to all threads (unsupported python vm).')
return -1

pydev_log.info('Successfully Loaded helper lib to set tracing to all threads.')

ret = 0
set_trace_func = TracingFunctionHolder._original_tracing or sys.settrace

Expand Down
36 changes: 36 additions & 0 deletions src/debugpy/_vendored/pydevd/tests_python/check_debug_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sys
import threading
from _pydev_bundle import pydev_log


def check():
with pydev_log.log_context(3, sys.stderr):
assert hasattr(sys, 'gettotalrefcount')
import pydevd_tracing

proceed1 = threading.Event()
proceed2 = threading.Event()

class SomeThread(threading.Thread):

def run(self):
proceed1.set()
proceed2.wait()

t = SomeThread()
t.start()
proceed1.wait()

def some_func(frame, event, arg):
return some_func

pydevd_tracing.set_trace_to_threads(some_func)

proceed2.set()
lib = pydevd_tracing.load_python_helper_lib()
assert lib is None
print('Finished OK')


if __name__ == '__main__':
check()

0 comments on commit af89fc8

Please sign in to comment.