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.
Enable pydevd to be used in DAP mode directly. WIP: microsoft#532
- Loading branch information
Showing
14 changed files
with
200 additions
and
65 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
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
54 changes: 53 additions & 1 deletion
54
src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_defaults.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,8 +1,60 @@ | ||
''' | ||
This module holds the customization settings for the debugger. | ||
''' | ||
|
||
from _pydevd_bundle.pydevd_constants import QUOTED_LINE_PROTOCOL | ||
from _pydev_bundle import pydev_log | ||
import sys | ||
|
||
|
||
class PydevdCustomization(object): | ||
DEFAULT_PROTOCOL = QUOTED_LINE_PROTOCOL | ||
DEFAULT_PROTOCOL: str = QUOTED_LINE_PROTOCOL | ||
|
||
# Debug mode may be set to 'debugpy-dap'. | ||
# | ||
# In 'debugpy-dap' mode the following settings are done to PyDB: | ||
# | ||
# py_db.skip_suspend_on_breakpoint_exception = (BaseException,) | ||
# py_db.skip_print_breakpoint_exception = (NameError,) | ||
# py_db.multi_threads_single_notification = True | ||
DEBUG_MODE: str = '' | ||
|
||
# This may be a <sys_path_entry>;<module_name> to be pre-imported | ||
# Something as: 'c:/temp/foo;my_module.bar' | ||
# | ||
# What's done in this case is something as: | ||
# | ||
# sys.path.insert(0, <sys_path_entry>) | ||
# try: | ||
# import <module_name> | ||
# finally: | ||
# del sys.path[0] | ||
# | ||
# If the pre-import fails an output message is | ||
# sent (but apart from that debugger execution | ||
# should continue). | ||
PREIMPORT: str = '' | ||
|
||
|
||
def on_pydb_init(py_db): | ||
if PydevdCustomization.DEBUG_MODE == 'debugpy-dap': | ||
py_db.skip_suspend_on_breakpoint_exception = (BaseException,) | ||
py_db.skip_print_breakpoint_exception = (NameError,) | ||
py_db.multi_threads_single_notification = True | ||
|
||
if PydevdCustomization.PREIMPORT: | ||
try: | ||
sys_path_entry, module_name = PydevdCustomization.PREIMPORT.rsplit(';', maxsplit=1) | ||
except Exception: | ||
pydev_log.exception("Expected ';' in %s" % (PydevdCustomization.PREIMPORT,)) | ||
else: | ||
try: | ||
sys.path.insert(0, sys_path_entry) | ||
try: | ||
__import__(module_name) | ||
finally: | ||
sys.path.remove(sys_path_entry) | ||
except Exception: | ||
pydev_log.exception( | ||
"Error importing %s (with sys.path entry: %s)" % (module_name, sys_path_entry)) | ||
|
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
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
45 changes: 45 additions & 0 deletions
45
...py/_vendored/pydevd/tests_python/resources/_debugger_case_wait_for_attach_debugpy_mode.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,45 @@ | ||
import os | ||
import sys | ||
port = int(sys.argv[1]) | ||
root_dirname = os.path.dirname(os.path.dirname(__file__)) | ||
|
||
if root_dirname not in sys.path: | ||
sys.path.append(root_dirname) | ||
|
||
import pydevd | ||
|
||
# Ensure that pydevd uses JSON protocol | ||
from _pydevd_bundle import pydevd_constants | ||
from _pydevd_bundle import pydevd_defaults | ||
pydevd_defaults.PydevdCustomization.DEFAULT_PROTOCOL = pydevd_constants.HTTP_JSON_PROTOCOL | ||
|
||
# Enable some defaults related to debugpy such as sending a single notification when | ||
# threads pause and stopping on any exception. | ||
pydevd_defaults.PydevdCustomization.DEBUG_MODE = 'debugpy-dap' | ||
|
||
import tempfile | ||
with tempfile.TemporaryDirectory('w') as tempdir: | ||
with open(os.path.join(tempdir, 'my_custom_module.py'), 'w') as stream: | ||
stream.write("print('Loaded my_custom_module')") | ||
|
||
pydevd_defaults.PydevdCustomization.PREIMPORT = '%s;my_custom_module' % (tempdir,) | ||
assert 'my_custom_module' not in sys.modules | ||
|
||
assert sys.gettrace() is None | ||
print('enable attach to port: %s' % (port,)) | ||
pydevd._enable_attach(('127.0.0.1', port)) | ||
|
||
assert pydevd.get_global_debugger() is not None | ||
# Set as a part of debugpy-dap | ||
assert pydevd.get_global_debugger().multi_threads_single_notification | ||
assert sys.gettrace() is not None | ||
|
||
assert 'my_custom_module' in sys.modules | ||
|
||
a = 10 # Break 1 | ||
print('wait for attach') | ||
pydevd._wait_for_attach() | ||
|
||
a = 20 # Break 2 | ||
|
||
print('TEST SUCEEDED!') |
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
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
Oops, something went wrong.