From fd2aea41f3619b2a4e263f3151db39b1a5d29277 Mon Sep 17 00:00:00 2001 From: Fabio Zadrozny Date: Mon, 25 Feb 2019 15:58:14 -0300 Subject: [PATCH] Fixes issue identifying ptvsd files (fixes stop on entry). #1159 (#1160) --- src/ptvsd/futures.py | 6 +++++- src/ptvsd/wrapper.py | 3 ++- tests/func/test_stop_on_entry.py | 36 ++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 tests/func/test_stop_on_entry.py diff --git a/src/ptvsd/futures.py b/src/ptvsd/futures.py index d36175a1..0678889b 100644 --- a/src/ptvsd/futures.py +++ b/src/ptvsd/futures.py @@ -118,7 +118,10 @@ class EventLoop(object): # thread, so, just silence it. pass else: - traceback.print_exc() + try: + traceback.print_exc() + except: + pass # Could give an error during shutdown. def stop(self): self._stop = True @@ -173,4 +176,5 @@ def wrap_async(f): callback(None) return result + return g diff --git a/src/ptvsd/wrapper.py b/src/ptvsd/wrapper.py index 0374d78a..129dc68a 100644 --- a/src/ptvsd/wrapper.py +++ b/src/ptvsd/wrapper.py @@ -39,6 +39,7 @@ import _pydevd_bundle.pydevd_comm_constants as pydevd_comm_constants # noqa import _pydevd_bundle.pydevd_extension_api as pydevd_extapi # noqa import _pydevd_bundle.pydevd_extension_utils as pydevd_extutil # noqa import _pydevd_bundle.pydevd_frame as pydevd_frame # noqa +from pydevd_file_utils import get_abs_path_real_path_and_base_from_file # noqa # from _pydevd_bundle.pydevd_comm import pydevd_log from _pydevd_bundle.pydevd_dont_trace_files import PYDEV_FILE # noqa from _pydevd_bundle import pydevd_additional_thread_info @@ -151,7 +152,7 @@ SafeReprPresentationProvider._instance = SafeReprPresentationProvider() str_handlers = pydevd_extutil.EXTENSION_MANAGER_INSTANCE.type_to_instance.setdefault(pydevd_extapi.StrPresentationProvider, []) # noqa str_handlers.insert(0, SafeReprPresentationProvider._instance) -PTVSD_DIR_PATH = os.path.dirname(os.path.abspath(__file__)) + os.path.sep +PTVSD_DIR_PATH = os.path.dirname(os.path.abspath(get_abs_path_real_path_and_base_from_file(__file__)[0])) + os.path.sep NORM_PTVSD_DIR_PATH = os.path.normcase(PTVSD_DIR_PATH) diff --git a/tests/func/test_stop_on_entry.py b/tests/func/test_stop_on_entry.py new file mode 100644 index 00000000..ecb191c9 --- /dev/null +++ b/tests/func/test_stop_on_entry.py @@ -0,0 +1,36 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See LICENSE in the project root +# for license information. + +from __future__ import print_function, with_statement, absolute_import + +from tests.helpers.pattern import Path +from tests.helpers.session import DebugSession +from tests.helpers.timeline import Event +import pytest + + +@pytest.mark.parametrize('start_method', ['launch']) +def test_stop_on_entry(run_as, start_method, tmpdir): + testfile = tmpdir.join('test.py') + with testfile.open('w') as stream: + stream.write(''' +stop_here = 1 +print('done') +''') + + with DebugSession() as session: + session.initialize( + target=(run_as, str(testfile)), + start_method=start_method, + ignore_unobserved=[Event('continued')], + debug_options=['StopOnEntry'], + ) + + session.start_debugging() + hit = session.wait_for_thread_stopped() + frames = hit.stacktrace.body['stackFrames'] + assert frames[0]['source']['path'] == Path(str(testfile)) + + session.send_request('continue').wait_for_response(freeze=False) + session.wait_for_exit()