mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
Fix various bugs around handling of disconnect in JsonIOStream and JsonMessageChannel. Fix handling of DAP "terminated" event in debug.Session. Add --ptvsd-logs and --pydevd-logs switches to pytest. Improve message logging to fully capture the raw message data in the logs if deserialization fails. Log all debuggee environment variables in debug.Session, and improve log readability.
40 lines
1 KiB
Python
40 lines
1 KiB
Python
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License. See LICENSE in the project root
|
|
# for license information.
|
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
import contextlib
|
|
import os
|
|
|
|
from ptvsd.common import log
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def enabled(filename):
|
|
os.environ['PYDEVD_DEBUG'] = 'True'
|
|
os.environ['PYDEVD_DEBUG_FILE'] = filename
|
|
log.debug("pydevd log will be at {0}", filename)
|
|
try:
|
|
yield
|
|
finally:
|
|
del os.environ['PYDEVD_DEBUG']
|
|
del os.environ['PYDEVD_DEBUG_FILE']
|
|
|
|
|
|
def dump(why):
|
|
assert why
|
|
|
|
pydevd_debug_file = os.environ.get('PYDEVD_DEBUG_FILE')
|
|
if not pydevd_debug_file:
|
|
return
|
|
|
|
try:
|
|
f = open(pydevd_debug_file)
|
|
with f:
|
|
pydevd_log = f.read()
|
|
except Exception:
|
|
log.exception("Test {0}, but pydevd log {1} could not be retrieved.", why, pydevd_debug_file)
|
|
return
|
|
|
|
log.info("Test {0}; pydevd log:\n\n{1}", why, pydevd_log)
|