forked from microsoft/debugpy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't crash if running under CPython debug build. Fixes microsoft#152
- Loading branch information
Showing
9 changed files
with
154 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/debugpy/_vendored/pydevd/.travis/install_and_run_debug_py.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
14 changes: 5 additions & 9 deletions
14
src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_additional_thread_info.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
# Defines which version of the PyDBAdditionalThreadInfo we'll use. | ||
from _pydevd_bundle.pydevd_constants import ENV_FALSE_LOWER_VALUES, USE_CYTHON_FLAG, \ | ||
ENV_TRUE_LOWER_VALUES | ||
|
||
import os | ||
use_cython = os.getenv('PYDEVD_USE_CYTHON', None) | ||
|
||
if use_cython == 'YES': | ||
if USE_CYTHON_FLAG in ENV_TRUE_LOWER_VALUES: | ||
# We must import the cython version if forcing cython | ||
from _pydevd_bundle.pydevd_cython_wrapper import PyDBAdditionalThreadInfo, set_additional_thread_info, _set_additional_thread_info_lock # @UnusedImport | ||
|
||
elif use_cython == 'NO': | ||
elif USE_CYTHON_FLAG in ENV_FALSE_LOWER_VALUES: | ||
# Use the regular version if not forcing cython | ||
from _pydevd_bundle.pydevd_additional_thread_info_regular import PyDBAdditionalThreadInfo, set_additional_thread_info, _set_additional_thread_info_lock # @UnusedImport @Reimport | ||
|
||
elif use_cython is None: | ||
else: | ||
# Regular: use fallback if not found (message is already given elsewhere). | ||
try: | ||
from _pydevd_bundle.pydevd_cython_wrapper import PyDBAdditionalThreadInfo, set_additional_thread_info, _set_additional_thread_info_lock | ||
except ImportError: | ||
from _pydevd_bundle.pydevd_additional_thread_info_regular import PyDBAdditionalThreadInfo, set_additional_thread_info, _set_additional_thread_info_lock # @UnusedImport | ||
else: | ||
raise RuntimeError('Unexpected value for PYDEVD_USE_CYTHON: %s (accepted: YES, NO)' % (use_cython,)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 6 additions & 11 deletions
17
src/debugpy/_vendored/pydevd/_pydevd_frame_eval/pydevd_frame_eval_main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,33 @@ | ||
import os | ||
import sys | ||
|
||
from _pydev_bundle import pydev_log | ||
from _pydevd_bundle.pydevd_trace_dispatch import USING_CYTHON | ||
|
||
IS_PY36_OR_GREATER = sys.version_info >= (3, 6) | ||
from _pydevd_bundle.pydevd_constants import USE_CYTHON_FLAG, ENV_FALSE_LOWER_VALUES, \ | ||
ENV_TRUE_LOWER_VALUES, IS_PY36_OR_GREATER | ||
|
||
frame_eval_func = None | ||
stop_frame_eval = None | ||
dummy_trace_dispatch = None | ||
clear_thread_local_info = None | ||
|
||
use_cython = os.getenv('PYDEVD_USE_CYTHON', None) | ||
USING_FRAME_EVAL = False | ||
|
||
# "NO" means we should not use frame evaluation, 'YES' we should use it (and fail if not there) and unspecified uses if possible. | ||
use_frame_eval = os.environ.get('PYDEVD_USE_FRAME_EVAL', None) | ||
use_frame_eval = os.environ.get('PYDEVD_USE_FRAME_EVAL', '').lower() | ||
|
||
if use_frame_eval == 'NO' or use_cython == 'NO' or not USING_CYTHON: | ||
if use_frame_eval in ENV_FALSE_LOWER_VALUES or USE_CYTHON_FLAG in ENV_FALSE_LOWER_VALUES or not USING_CYTHON: | ||
pass | ||
|
||
elif use_frame_eval == 'YES': | ||
elif use_frame_eval in ENV_TRUE_LOWER_VALUES: | ||
# Fail if unable to use | ||
from _pydevd_frame_eval.pydevd_frame_eval_cython_wrapper import frame_eval_func, stop_frame_eval, dummy_trace_dispatch, clear_thread_local_info | ||
USING_FRAME_EVAL = True | ||
|
||
elif use_frame_eval is None: | ||
else: | ||
# Try to use if possible | ||
if IS_PY36_OR_GREATER: | ||
try: | ||
from _pydevd_frame_eval.pydevd_frame_eval_cython_wrapper import frame_eval_func, stop_frame_eval, dummy_trace_dispatch, clear_thread_local_info | ||
USING_FRAME_EVAL = True | ||
except ImportError: | ||
pydev_log.show_compile_cython_command_line() | ||
|
||
else: | ||
raise RuntimeError('Unexpected value for PYDEVD_USE_FRAME_EVAL: %s (accepted: YES, NO)' % (use_frame_eval,)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/debugpy/_vendored/pydevd/tests_python/check_debug_python.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
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() | ||
try: | ||
|
||
def some_func(frame, event, arg): | ||
return some_func | ||
|
||
pydevd_tracing.set_trace_to_threads(some_func) | ||
finally: | ||
proceed2.set() | ||
|
||
lib = pydevd_tracing.load_python_helper_lib() | ||
assert lib is None | ||
print('Finished OK') | ||
|
||
|
||
if __name__ == '__main__': | ||
check() |