def __set__(self, obj, value): global_debugger = get_global_debugger() try: if global_debugger is not None and global_debugger.disable_property_setter_trace: pydevd_tracing.SetTrace(None) if self.fset is None: raise AttributeError("can't set attribute") self.fset(obj, value) finally: if global_debugger is not None: pydevd_tracing.SetTrace(global_debugger.trace_dispatch)
def __delete__(self, obj): global_debugger = get_global_debugger() try: if global_debugger is not None and global_debugger.disable_property_deleter_trace: pydevd_tracing.SetTrace(None) if self.fdel is None: raise AttributeError("can't delete attribute") self.fdel(obj) finally: if global_debugger is not None: pydevd_tracing.SetTrace(global_debugger.trace_dispatch)
def __get__(self, obj, objtype=None): if obj is None: return self global_debugger = get_global_debugger() try: if global_debugger is not None and global_debugger.disable_property_getter_trace: pydevd_tracing.SetTrace(None) if self.fget is None: raise AttributeError("unreadable attribute") return self.fget(obj) finally: if global_debugger is not None: pydevd_tracing.SetTrace(global_debugger.trace_dispatch)
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')
def OnRun( self ): """ just loop and write responses """ pydevd_tracing.SetTrace( None ) # no debugging on this thread try: while not self.killReceived: try: cmd = self.cmdQueue.get( 1 ) except: # PydevdLog(0, 'Finishing debug communication...(1)') # when liberating the thread here, we could have errors because we were shutting down # but the thread was still not liberated return out = cmd.getOutgoing() if DEBUG_TRACE_LEVEL >= 1: out_message = 'sending cmd: ' out_message += ID_TO_MEANING.get( out[:3], 'UNKNOWN' ) out_message += ' ' out_message += out try: sys.stderr.write( '%s\n' % ( out_message, ) ) except: pass if IS_PY3K: out = bytearray( out, 'utf-8' ) self.sock.send( out ) # TODO: this does not guarantee that all message are sent (and jython does not have a send all) if time is None: break # interpreter shutdown time.sleep( self.timeout ) except Exception: GlobalDebuggerHolder.globalDbg.FinishDebuggingSession() if DEBUG_TRACE_LEVEL >= 0: traceback.print_exc()
def set_trace_in_qt(): import pydevd_tracing from _pydevd_bundle.pydevd_comm import get_global_debugger debugger = get_global_debugger() if debugger is not None: pydevd_tracing.SetTrace(debugger.trace_dispatch, debugger.frame_eval_func)
def OnRun(self): time.sleep( 5 ) #this one will only start later on (because otherwise we may not have any non-daemon threads run_traced = True if pydevd_vm_type.GetVmType( ) == pydevd_vm_type.PydevdVmType.JYTHON and sys.hexversion <= 0x020201f0: #don't run untraced threads if we're in jython 2.2.1 or lower #jython bug: if we start a thread and another thread changes the tracing facility #it affects other threads (it's not set only for the thread but globally) #Bug: http://sourceforge.net/tracker/index.php?func=detail&aid=1870039&group_id=12867&atid=112867 run_traced = False if run_traced: pydevd_tracing.SetTrace(None) # no debugging on this thread try: while not self.killReceived: try: self.pyDb.processInternalCommands() except: PydevdLog(0, 'Finishing debug communication...(2)') time.sleep(0.5) except: pass
def OnRun( self ): pydevd_tracing.SetTrace( None ) # no debugging on this thread buffer = "" try: while not self.killReceived: try: r = self.sock.recv( 1024 ) except: GlobalDebuggerHolder.globalDbg.FinishDebuggingSession() break # Finished communication. if IS_PY3K: r = r.decode( 'utf-8' ) buffer += r if DebugInfoHolder.DEBUG_RECORD_SOCKET_READS: sys.stdout.write( 'received >>%s<<\n' % ( buffer, ) ) if len( buffer ) == 0: GlobalDebuggerHolder.globalDbg.FinishDebuggingSession() break while buffer.find( '\n' ) != -1: command, buffer = buffer.split( '\n', 1 ) args = command.split( '\t', 2 ) PydevdLog( 1, "received command ", ID_TO_MEANING.get( args[0], int( args[0] ) ), "Args: " + str( args[2:] ) ) try: GlobalDebuggerHolder.globalDbg.processNetCommand( int( args[0] ), int( args[1] ), args[2] ) except: traceback.print_exc() sys.stderr.write( "Can't process net command: %s\n" % command ) sys.stderr.flush() except: traceback.print_exc() GlobalDebuggerHolder.globalDbg.FinishDebuggingSession()
def _excepthook(exctype, value, tb): global _handle_exceptions if _handle_exceptions: exception_breakpoint = get_exception_breakpoint(exctype, _handle_exceptions) else: exception_breakpoint = None #Always call the original excepthook before going on to call the debugger post mortem to show it. _original_excepthook(exctype, value, tb) if not exception_breakpoint: return if tb is None: #sometimes it can be None, e.g. with GTK return frames = [] while tb: frames.append(tb.tb_frame) tb = tb.tb_next thread = threadingCurrentThread() frames_byid = dict([(id(frame),frame) for frame in frames]) frame = frames[-1] thread.additionalInfo.exception = (exctype, value, tb) thread.additionalInfo.pydev_force_stop_at_exception = (frame, frames_byid) thread.additionalInfo.message = exception_breakpoint.qname debugger = GetGlobalDebugger() pydevd_tracing.SetTrace(None) #no tracing from here pydev_log.debug('Handling post-mortem stop on exception breakpoint %s'% exception_breakpoint.qname) debugger.handle_post_mortem_stop(thread.additionalInfo, thread)
def __call__(self): # We monkey-patch the thread creation so that this function is called in the new thread. At this point # we notify of its creation and start tracing it. global_debugger = get_global_debugger() thread_id = None if global_debugger is not None: # Note: if this is a thread from threading.py, we're too early in the boostrap process (because we mocked # the start_new_thread internal machinery and thread._bootstrap has not finished), so, the code below needs # to make sure that we use the current thread bound to the original function and not use # threading.currentThread() unless we're sure it's a dummy thread. t = getattr(self.original_func, '__self__', getattr(self.original_func, 'im_self', None)) if not isinstance(t, threading.Thread): # This is not a threading.Thread but a Dummy thread (so, get it as a dummy thread using # currentThread). t = threading.currentThread() if not getattr(t, 'is_pydev_daemon_thread', False): thread_id = get_current_thread_id(t) global_debugger.notify_thread_created(thread_id, t) _on_set_trace_for_new_thread(global_debugger) if getattr(global_debugger, 'thread_analyser', None) is not None: try: from pydevd_concurrency_analyser.pydevd_concurrency_logger import log_new_thread log_new_thread(global_debugger, t) except: sys.stderr.write( "Failed to detect new thread for visualization") try: try: ret = self.original_func(*self.args, **self.kwargs) except: # If threads die with the debugger alive, it's possible that we # have exceptions during teardown (Python goes through each module # and sets their attributes to None). In this situation, don't # report spurious exceptions because of that. if sys is None or pydevd_tracing is None: return finally: if sys is None or pydevd_tracing is None: return else: if thread_id is not None and global_debugger is not None: global_debugger.notify_thread_not_alive(thread_id) frame = sys._getframe() while frame is not None: if frame.f_trace is not None: frame.f_trace = NO_FTRACE frame = frame.f_back pydevd_tracing.SetTrace(None) return ret
def _excepthook(exctype, value, tb): global _handle_exceptions if _handle_exceptions: exception_breakpoint = get_exception_breakpoint( exctype, _handle_exceptions) else: exception_breakpoint = None #Always call the original excepthook before going on to call the debugger post mortem to show it. _original_excepthook(exctype, value, tb) if not exception_breakpoint: return if tb is None: #sometimes it can be None, e.g. with GTK return if exctype is KeyboardInterrupt: return frames = [] debugger = get_global_debugger() user_frame = None while tb: frame = tb.tb_frame if exception_breakpoint.ignore_libraries and not debugger.not_in_scope( frame.f_code.co_filename): user_frame = tb.tb_frame frames.append(tb.tb_frame) tb = tb.tb_next thread = threadingCurrentThread() frames_byid = dict([(id(frame), frame) for frame in frames]) if exception_breakpoint.ignore_libraries and user_frame is not None: frame = user_frame else: frame = frames[-1] exception = (exctype, value, tb) _set_additional_info_if_needed(thread) try: thread.additional_info.pydev_message = exception_breakpoint.qname except: thread.additional_info.pydev_message = exception_breakpoint.qname.encode( 'utf-8') pydevd_tracing.SetTrace(None) #no tracing from here pydev_log.debug('Handling post-mortem stop on exception breakpoint %s' % exception_breakpoint.qname) debugger.handle_post_mortem_stop(thread, frame, frames_byid, exception)
def OnRun(self): pydevd_tracing.SetTrace(None) # no debugging on this thread buffer = "" try: while not self.killReceived: try: r = self.sock.recv(1024) except: GlobalDebuggerHolder.globalDbg.FinishDebuggingSession() break #Finished communication. #Note: the java backend is always expected to pass utf-8 encoded strings. We now work with unicode #internally and thus, we may need to convert to the actual encoding where needed (i.e.: filenames #on python 2 may need to be converted to the filesystem encoding). if hasattr(r, 'decode'): r = r.decode('utf-8') buffer += r if DebugInfoHolder.DEBUG_RECORD_SOCKET_READS: sys.stdout.write('received >>%s<<\n' % (buffer, )) if len(buffer) == 0: GlobalDebuggerHolder.globalDbg.FinishDebuggingSession() break while buffer.find('\n') != -1: command, buffer = buffer.split('\n', 1) if DEBUG_TRACE_LEVEL >= 1: out_message = 'receive cmd <-- ' out_message += "%20s" % ID_TO_MEANING.get( command[:3], 'UNKNOWN') out_message += ' ' out_message += unquote(unquote(command)).replace( '\n', ' ') try: sys.stderr.write('%s\n' % (out_message, )) except: pass args = command.split('\t', 2) try: GlobalDebuggerHolder.globalDbg.processNetCommand( int(args[0]), int(args[1]), args[2]) except: traceback.print_exc() sys.stderr.write("Can't process net command: %s\n" % command) sys.stderr.flush() except: traceback.print_exc() GlobalDebuggerHolder.globalDbg.FinishDebuggingSession()
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', )
def attach_to_pydev(): # remove any redirection from previous debugging if getattr(sys, "_pyxll_pydev_orig_stdout", None) is None: sys._pyxll_pydev_orig_stdout = sys.stdout if getattr(sys, "_pyxll_pydev_orig_stderr", None) is None: sys._pyxll_pydev_orig_stderr = sys.stderr sys.stdout = sys._pyxll_pydev_orig_stdout sys.stderr = sys._pyxll_pydev_orig_stderr # stop any existing PyDev debugger dbg = pydevd.GetGlobalDebugger() if dbg: dbg.FinishDebuggingSession() time.sleep(0.1) pydevd_tracing.SetTrace(None) # remove any additional info for the current thread if threading: try: del threading.currentThread().__dict__["additionalInfo"] except KeyError: pass pydevd.SetGlobalDebugger(None) pydevd.connected = False time.sleep(0.1) _log.info("Attempting to attach to the PyDev debugger") try: pydevd.settrace(stdoutToServer=True, stderrToServer=True, suspend=False) except Exception as e: xlcAlert("Failed to connect to PyDev\n" "Check the debug server is running.\n" "Error: %s" % e) return xlcAlert("Attatched to PyDev")
def excepthook(exctype, value, tb): global _handle_exceptions if _handle_exceptions is not None: exception_breakpoint = get_exception_breakpoint( exctype, _handle_exceptions, NOTIFY_ON_TERMINATE) else: exception_breakpoint = None if exception_breakpoint is None: return _original_excepthook(exctype, value, tb) #Always call the original excepthook before going on to call the debugger post mortem to show it. _original_excepthook(exctype, value, tb) if tb is None: #sometimes it can be None, e.g. with GTK return frames = [] traceback = tb while tb: frames.append(tb.tb_frame) tb = tb.tb_next thread = threadingCurrentThread() frames_byid = dict([(id(frame), frame) for frame in frames]) frame = frames[-1] thread.additionalInfo.exception = (exctype, value, tb) thread.additionalInfo.pydev_force_stop_at_exception = (frame, frames_byid) thread.additionalInfo.message = exception_breakpoint.qname #sys.exc_info = lambda : (exctype, value, traceback) debugger = GetGlobalDebugger() debugger.force_post_mortem_stop += 1 pydevd_tracing.SetTrace(None) #no tracing from here debugger.handle_post_mortem_stop(thread.additionalInfo, thread)
def set_trace_in_qt(): import pydevd_tracing from pydevd_comm import GetGlobalDebugger debugger = GetGlobalDebugger() if debugger is not None: pydevd_tracing.SetTrace(debugger.trace_dispatch)
def _locked_settrace(host, stdoutToServer, stderrToServer, port, suspend, trace_only_current_thread): if host is None: import pydev_localhost host = pydev_localhost.get_localhost() global connected global bufferStdOutToServer global bufferStdErrToServer if not connected: connected = True bufferStdOutToServer = stdoutToServer bufferStdErrToServer = stderrToServer pydevd_vm_type.SetupType() debugger = PyDB() debugger.connect(host, port) net = NetCommand(str(CMD_THREAD_CREATE), 0, '<xml><thread name="pydevd.reader" id="-1"/></xml>') debugger.writer.addCommand(net) net = NetCommand(str(CMD_THREAD_CREATE), 0, '<xml><thread name="pydevd.writer" id="-1"/></xml>') debugger.writer.addCommand(net) if bufferStdOutToServer: sys.stdoutBuf = pydevd_io.IOBuf() sys.stdout = pydevd_io.IORedirector( sys.stdout, sys.stdoutBuf) #@UndefinedVariable if bufferStdErrToServer: sys.stderrBuf = pydevd_io.IOBuf() sys.stderr = pydevd_io.IORedirector( sys.stderr, sys.stderrBuf) #@UndefinedVariable SetTraceForParents(GetFrame(), debugger.trace_dispatch) t = threadingCurrentThread() try: additionalInfo = t.additionalInfo except AttributeError: additionalInfo = PyDBAdditionalThreadInfo() t.additionalInfo = additionalInfo while not debugger.readyToRun: time.sleep(0.1) # busy wait until we receive run command if suspend: debugger.setSuspend(t, CMD_SET_BREAK) #note that we do that through pydevd_tracing.SetTrace so that the tracing #is not warned to the user! pydevd_tracing.SetTrace(debugger.trace_dispatch) if not trace_only_current_thread: #Trace future threads? try: #not available in jython! threading.settrace( debugger.trace_dispatch) # for all future threads except: pass try: thread.start_new_thread = pydev_start_new_thread thread.start_new = pydev_start_new_thread except: pass PyDBCommandThread(debugger).start() else: #ok, we're already in debug mode, with all set, so, let's just set the break debugger = GetGlobalDebugger() SetTraceForParents(GetFrame(), debugger.trace_dispatch) t = threadingCurrentThread() try: additionalInfo = t.additionalInfo except AttributeError: additionalInfo = PyDBAdditionalThreadInfo() t.additionalInfo = additionalInfo pydevd_tracing.SetTrace(debugger.trace_dispatch) if not trace_only_current_thread: #Trace future threads? try: #not available in jython! threading.settrace( debugger.trace_dispatch) # for all future threads except: pass try: thread.start_new_thread = pydev_start_new_thread thread.start_new = pydev_start_new_thread except: pass if suspend: debugger.setSuspend(t, CMD_SET_BREAK)
def settrace(host='localhost', stdoutToServer=False, stderrToServer=False, port=5678, suspend=True, trace_only_current_thread=True): '''Sets the tracing function with the pydev debug function and initializes needed facilities. @param host: the user may specify another host, if the debug server is not in the same machine @param stdoutToServer: when this is true, the stdout is passed to the debug server @param stderrToServer: when this is true, the stderr is passed to the debug server so that they are printed in its console and not in this process console. @param port: specifies which port to use for communicating with the server (note that the server must be started in the same port). @note: currently it's hard-coded at 5678 in the client @param suspend: whether a breakpoint should be emulated as soon as this function is called. @param trace_only_current_thread: determines if only the current thread will be traced or all future threads will also have the tracing enabled. ''' global connected global bufferStdOutToServer global bufferStdErrToServer if not connected: connected = True bufferStdOutToServer = stdoutToServer bufferStdErrToServer = stderrToServer pydevd_vm_type.SetupType() debugger = PyDB() debugger.connect(host, port) net = NetCommand(str(CMD_THREAD_CREATE), 0, '<xml><thread name="pydevd.reader" id="-1"/></xml>') debugger.writer.addCommand(net) net = NetCommand(str(CMD_THREAD_CREATE), 0, '<xml><thread name="pydevd.writer" id="-1"/></xml>') debugger.writer.addCommand(net) if bufferStdOutToServer: sys.stdoutBuf = pydevd_io.IOBuf() sys.stdout = pydevd_io.IORedirector( sys.stdout, sys.stdoutBuf) #@UndefinedVariable if bufferStdErrToServer: sys.stderrBuf = pydevd_io.IOBuf() sys.stderr = pydevd_io.IORedirector( sys.stderr, sys.stderrBuf) #@UndefinedVariable SetTraceForParents(GetFrame(), debugger.trace_dispatch) t = threadingCurrentThread() try: additionalInfo = t.additionalInfo except AttributeError: additionalInfo = PyDBAdditionalThreadInfo() t.additionalInfo = additionalInfo while not debugger.readyToRun: time.sleep(0.1) # busy wait until we receive run command if suspend: debugger.setSuspend(t, CMD_SET_BREAK) #note that we do that through pydevd_tracing.SetTrace so that the tracing #is not warned to the user! pydevd_tracing.SetTrace(debugger.trace_dispatch) if not trace_only_current_thread: #Trace future threads? try: #not available in jython! threading.settrace( debugger.trace_dispatch) # for all future threads except: pass try: thread.start_new_thread = pydev_start_new_thread thread.start_new = pydev_start_new_thread except: pass PyDBCommandThread(debugger).start() else: #ok, we're already in debug mode, with all set, so, let's just set the break debugger = GetGlobalDebugger() SetTraceForParents(GetFrame(), debugger.trace_dispatch) t = threadingCurrentThread() try: additionalInfo = t.additionalInfo except AttributeError: additionalInfo = PyDBAdditionalThreadInfo() t.additionalInfo = additionalInfo pydevd_tracing.SetTrace(debugger.trace_dispatch) if not trace_only_current_thread: #Trace future threads? try: #not available in jython! threading.settrace( debugger.trace_dispatch) # for all future threads except: pass try: thread.start_new_thread = pydev_start_new_thread thread.start_new = pydev_start_new_thread except: pass if suspend: debugger.setSuspend(t, CMD_SET_BREAK)
def stopTrace(self): if self.dontTraceMe: pydevd_tracing.SetTrace(None) # no debugging on this thread
def __call__(self): global_debugger = GetGlobalDebugger() pydevd_tracing.SetTrace(global_debugger.trace_dispatch) self.original_func(*self.args, **self.kwargs)
def add_exec(self, code_fragment, debugger=None): # In case sys.excepthook called, use original excepthook #PyDev-877: Debug console freezes with Python 3.5+ # (showtraceback does it on python 3.5 onwards) sys.excepthook = sys.__excepthook__ try: original_in = sys.stdin try: help = None if 'pydoc' in sys.modules: pydoc = sys.modules[ 'pydoc'] # Don't import it if it still is not there. if hasattr(pydoc, 'help'): # You never know how will the API be changed, so, let's code defensively here help = pydoc.help if not hasattr(help, 'input'): help = None except: # Just ignore any error here pass more = False try: sys.stdin = self.create_std_in(debugger, original_in) try: if help is not None: # This will enable the help() function to work. try: try: help.input = sys.stdin except AttributeError: help._input = sys.stdin except: help = None if not self._input_error_printed: self._input_error_printed = True sys.stderr.write( '\nError when trying to update pydoc.help.input\n' ) sys.stderr.write( '(help() may not work -- please report this as a bug in the pydev bugtracker).\n\n' ) traceback.print_exc() try: self.start_exec() if hasattr(self, 'debugger'): import pydevd_tracing pydevd_tracing.SetTrace( self.debugger.trace_dispatch) more = self.do_add_exec(code_fragment) if hasattr(self, 'debugger'): import pydevd_tracing pydevd_tracing.SetTrace(None) self.finish_exec(more) finally: if help is not None: try: try: help.input = original_in except AttributeError: help._input = original_in except: pass finally: sys.stdin = original_in except SystemExit: raise except: traceback.print_exc() finally: sys.__excepthook__ = sys.excepthook return more
def addExec(self, code_fragment): original_in = sys.stdin try: help = None if 'pydoc' in sys.modules: pydoc = sys.modules[ 'pydoc'] #Don't import it if it still is not there. if hasattr(pydoc, 'help'): #You never know how will the API be changed, so, let's code defensively here help = pydoc.help if not hasattr(help, 'input'): help = None except: #Just ignore any error here pass more = False try: sys.stdin = self.createStdIn() try: if help is not None: #This will enable the help() function to work. try: try: help.input = sys.stdin except AttributeError: help._input = sys.stdin except: help = None if not self._input_error_printed: self._input_error_printed = True sys.stderr.write( '\nError when trying to update pydoc.help.input\n' ) sys.stderr.write( '(help() may not work -- please report this as a bug in the pydev bugtracker).\n\n' ) traceback.print_exc() try: self.startExec() if hasattr(self, 'debugger'): import pydevd_tracing pydevd_tracing.SetTrace(self.debugger.trace_dispatch) more = self.doAddExec(code_fragment) if hasattr(self, 'debugger'): import pydevd_tracing pydevd_tracing.SetTrace(None) self.finishExec(more) finally: if help is not None: try: try: help.input = original_in except AttributeError: help._input = original_in except: pass finally: sys.stdin = original_in except SystemExit: raise except: traceback.print_exc() return more
def _stop_trace(self): if self.pydev_do_not_trace: pydevd_tracing.SetTrace(None) # no debugging on this thread
def run(self, file, globals=None, locals=None): if globals is None: #patch provided by: Scott Schlesier - when script is run, it does not #use globals from pydevd: #This will prevent the pydevd script from contaminating the namespace for the script to be debugged #pretend pydevd is not the main module, and #convince the file to be debugged that it was loaded as main sys.modules['pydevd'] = sys.modules['__main__'] sys.modules['pydevd'].__name__ = 'pydevd' from imp import new_module m = new_module('__main__') sys.modules['__main__'] = m m.__file__ = file globals = m.__dict__ if locals is None: locals = globals #Predefined (writable) attributes: __name__ is the module's name; #__doc__ is the module's documentation string, or None if unavailable; #__file__ is the pathname of the file from which the module was loaded, #if it was loaded from a file. The __file__ attribute is not present for #C modules that are statically linked into the interpreter; for extension modules #loaded dynamically from a shared library, it is the pathname of the shared library file. #I think this is an ugly hack, bug it works (seems to) for the bug that says that sys.path should be the same in #debug and run. if m.__file__.startswith(sys.path[0]): #print >> sys.stderr, 'Deleting: ', sys.path[0] del sys.path[0] #now, the local directory has to be added to the pythonpath #sys.path.insert(0, os.getcwd()) #Changed: it's not the local directory, but the directory of the file launched #The file being run ust be in the pythonpath (even if it was not before) sys.path.insert(0, os.path.split(file)[0]) # for completness, we'll register the pydevd.reader & pydevd.writer threads net = NetCommand(str(CMD_THREAD_CREATE), 0, '<xml><thread name="pydevd.reader" id="-1"/></xml>') self.writer.addCommand(net) net = NetCommand(str(CMD_THREAD_CREATE), 0, '<xml><thread name="pydevd.writer" id="-1"/></xml>') self.writer.addCommand(net) pydevd_tracing.SetTrace(self.trace_dispatch) try: #not available in jython! threading.settrace(self.trace_dispatch) # for all future threads except: pass try: thread.start_new_thread = pydev_start_new_thread thread.start_new = pydev_start_new_thread except: pass while not self.readyToRun: time.sleep(0.1) # busy wait until we receive run command PyDBCommandThread(debugger).start() pydev_imports.execfile(file, globals, locals) #execute the script
if f_trace.__class__.__name__ != 'SafeCallWrapper': raise AssertionError('Expected %s to be SafeCallWrapper' % (f_trace.__class__.__name__, )) check_with_no_trace() def check_revert_to_dummy(): check_with_no_trace() if __name__ == '__main__': # Check how frame eval works. if sys.version_info[0:2] < (3, 6): raise AssertionError( 'Only available for Python 3.6 onwards. Found: %s' % (sys.version_info[0:1], )) check_with_no_trace() # break on global (step over) check_step_in_then_step_return() import pydevd_tracing import pydevd # This is what a remote attach would do (should revert to the frame eval mode). pydevd_tracing.SetTrace(pydevd.get_global_debugger().trace_dispatch) check_revert_to_dummy() print('TEST SUCEEDED!')