def attach_to_debugger(debugger_port):
    ipython_shell = get_ipython()

    if sys.platform not in ('darwin', 'win32'):
        # temporarily disable Cython warnings on Linux
        import os
        os.environ['PYDEVD_USE_CYTHON'] = 'NO'
        os.environ['PYDEVD_USE_FRAME_EVAL'] = 'NO'

    import pydevd
    from _pydev_bundle import pydev_localhost

    debugger = pydevd.PyDB()
    ipython_shell.debugger = debugger
    try:
        debugger.connect(pydev_localhost.get_localhost(), debugger_port)
        debugger.prepare_to_run(enable_tracing_from_start=False)
    except:
        traceback.print_exc()
        sys.stderr.write('Failed to connect to target debugger.\n')

    # should be executed only once for kernel
    if not hasattr(ipython_shell, "pydev_cell_info"):
        ipython_shell.pydev_cell_info = DebugCellInfo()
        patch_compile_cache(ipython_shell)
    # save link in debugger for quick access
    debugger.cell_info = ipython_shell.pydev_cell_info
    debugger.cell_info.util_cell_names = {}
    debugger.warn_once_map = {}
Example #2
0
        def do_connect_to_debugger():
            try:
                # Try to import the packages needed to attach the debugger
                import pydevd
                from _pydev_imps._pydev_saved_modules import threading

            except:
                # This happens on Jython embedded in host eclipse
                traceback.print_exc()
                sys.stderr.write('pydevd is not available, cannot connect\n',)

            from _pydev_bundle import pydev_localhost
            threading.currentThread().__pydevd_id__ = "console_main"

            self.orig_find_frame = pydevd_vars.find_frame
            pydevd_vars.find_frame = self._findFrame

            self.debugger = pydevd.PyDB()
            try:
                self.debugger.connect(pydev_localhost.get_localhost(), debuggerPort)
                self.debugger.prepare_to_run()
                import pydevd_tracing
                pydevd_tracing.SetTrace(None)
            except:
                traceback.print_exc()
                sys.stderr.write('Failed to connect to target debugger.\n')

            # Register to process commands when idle
            self.debugrunning = False
            try:
                import pydevconsole
                pydevconsole.set_debug_hook(self.debugger.process_internal_commands)
            except:
                traceback.print_exc()
                sys.stderr.write('Version of Python does not support debuggable Interactive Console.\n')
Example #3
0
    def connectToDebugger(self, debuggerPort):
        '''
        Used to show console with variables connection.
        Mainly, monkey-patches things in the debugger structure so that the debugger protocol works.
        '''
        try:
            # Try to import the packages needed to attach the debugger
            import pydevd
            import pydevd_vars
            import threading
        except:
            # This happens on Jython embedded in host eclipse
            import traceback
            traceback.print_exc()
            return ('pydevd is not available, cannot connect', )

        import pydev_localhost
        threading.currentThread().__pydevd_id__ = "console_main"

        pydevd_vars.findFrame = self._findFrame

        self.debugger = pydevd.PyDB()
        try:
            self.debugger.connect(pydev_localhost.get_localhost(),
                                  debuggerPort)
        except:
            import traceback
            traceback.print_exc()
            return ('Failed to connect to target debugger.')
        return ('connect complete', )
Example #4
0
def _setup_nodebug():
    debugger = pydevd.PyDB()
    debugger.init_matplotlib_support = lambda *arg: None
    # We are invoking run() solely for side effects here - setting up the
    # debugger and connecting to our socket - so the code run is a no-op.
    debugger.run(file='ptvsd._remote:_nop',
                 globals=None,
                 locals=None,
                 is_module=True,
                 set_trace=False)
Example #5
0
def run(address, filename, is_module, *args, **kwargs):
    # TODO: docstring
    # TODO: client/server -> address
    daemon = Daemon()
    if not daemon.wait_for_launch(address):
        return

    debugger = pydevd.PyDB()
    # We do not want some internal methods to get executed in non-debug mode.
    debugger.init_matplotlib_support = lambda *arg: None
    debugger.run(file=filename,
                 globals=None,
                 locals=None,
                 is_module=is_module,
                 set_trace=False)
Example #6
0
        def do_connect_to_debugger():
            try:
                # Try to import the packages needed to attach the debugger
                import pydevd
                from _pydev_imps._pydev_saved_modules import threading

            except:
                # This happens on Jython embedded in host eclipse
                traceback.print_exc()
                sys.stderr.write('pydevd is not available, cannot connect\n', )

            from _pydevd_bundle.pydevd_constants import set_thread_id
            from _pydev_bundle import pydev_localhost
            set_thread_id(threading.currentThread(), "console_main")

            VIRTUAL_FRAME_ID = "1"  # matches PyStackFrameConsole.java
            VIRTUAL_CONSOLE_ID = "console_main"  # matches PyThreadConsole.java
            f = FakeFrame()
            f.f_back = None
            f.f_globals = {
            }  # As globals=locals here, let's simply let it empty (and save a bit of network traffic).
            f.f_locals = self.get_namespace()

            self.debugger = pydevd.PyDB()
            self.debugger.add_fake_frame(thread_id=VIRTUAL_CONSOLE_ID,
                                         frame_id=VIRTUAL_FRAME_ID,
                                         frame=f)
            try:
                pydevd.apply_debugger_options(debugger_options)
                self.debugger.connect(pydev_localhost.get_localhost(),
                                      debuggerPort)
                self.debugger.prepare_to_run()
                self.debugger.disable_tracing()
            except:
                traceback.print_exc()
                sys.stderr.write('Failed to connect to target debugger.\n')

            # Register to process commands when idle
            self.debugrunning = False
            try:
                import pydevconsole
                pydevconsole.set_debug_hook(
                    self.debugger.process_internal_commands)
            except:
                traceback.print_exc()
                sys.stderr.write(
                    'Version of Python does not support debuggable Interactive Console.\n'
                )
Example #7
0
def run(address, filename, is_module, *args, **kwargs):
    # TODO: client/server -> address
    if not start_message_processor(*address):
        return

    debugger = pydevd.PyDB()
    # We do not want some internal methods to get executed in non-debug mode.
    debugger.init_matplotlib_support = lambda *arg: None
    debugger.run(file=filename,
                 globals=None,
                 locals=None,
                 is_module=is_module,
                 set_trace=False)
    # Wait for some time (a little longer than output redirection polling).
    # This is necessary to ensure all output is captured and redirected.
    time.sleep(OUTPUT_POLL_PERIOD + 0.1)
    def connectToDebugger(self, debuggerPort):
        '''
        Used to show console with variables connection.
        Mainly, monkey-patches things in the debugger structure so that the debugger protocol works.
        '''
        try:
            # Try to import the packages needed to attach the debugger
            import pydevd
            import pydevd_vars
            import threading
        except:
            # This happens on Jython embedded in host eclipse
            import traceback
            traceback.print_exc()
            return ('pydevd is not available, cannot connect', )

        import pydev_localhost
        threading.currentThread().__pydevd_id__ = "console_main"

        self.orig_findFrame = pydevd_vars.findFrame
        pydevd_vars.findFrame = self._findFrame

        self.debugger = pydevd.PyDB()
        try:
            self.debugger.connect(pydev_localhost.get_localhost(),
                                  debuggerPort)
            self.debugger.prepareToRun()
            import pydevd_tracing
            pydevd_tracing.SetTrace(None)
        except:
            import traceback
            traceback.print_exc()
            return ('Failed to connect to target debugger.')

        # Register to process commands when idle
        self.debugrunning = False
        try:
            self.server.setDebugHook(self.debugger.processInternalCommands)
        except:
            import traceback
            traceback.print_exc()
            return (
                'Version of Python does not support debuggable Interactive Console.'
            )

        return ('connect complete', )