
    Bi[                    H   d Z ddlZddlmZ ddlZddlmZ ej                  dd dk  r ed      ddl	Z	ddl
Z
ddlZddlZddlmZ dd	lmZ dd
lmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( ddl)m*Z* ddl)m+Z+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl1m3Z3 ddl1m4Z4 ddl5m6Z6m7Z7 ddl8Z8ddl5m9Z9 ddl5m:Z: ddl;m<Z< ddl=m>Z>m?Z?m@Z@ ddlAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\ ddl]m^Z^m_Z_ ddl`maZambZb ddlcmdZd ddlemfZgmhZhmiZimjZj ddlkmlZlmmZmmnZn ddlompZp ddlqmrZr ddlsmtZtmuZumvZvmwZw dd lxmyZymzZz dd!l{m|Z|m}Z}m~Z~ ddlZdd"lmZ dd#l{mZmZ ej                  Zd$Zg ZeD ]  Zej                   ee              d%j                  e      ZdSd&Z e        e ZdZerdd'lmZ e2j"                  Ze2j&                  Zej*                  Z	 d(j/                  d)       d*ad*ad*ad*Zd*a e.       Z G d+ d,eN      Z G d- d.eN      Z G d/ d0e      Z G d1 d2e      Z G d3 d4e      Z G d5 d6e      Zd7 Zd8 ZdSd9ZdTd:Z G d; d<e      ZdSd=ZdSd>Z	 	 	 	 	 	 	 	 	 dUd?Z e4jZ                         Zd@ ZdA Z G dB dCe      Z G dD dEeP      ZdF ZdG ZdH Z G dI dJ      ZdK ZdL ZdM ZddNlmZ ddOl5mZ  ejz                  e      D ]  Zej                  eP        dQ ZedRk(  r e        yy#  Y xY w)VzF
Entry point module (keep at root):

This module starts the debugger.
    N)contextmanager)collect_return_info   r      zThe PyDev.Debugger requires Python 2.6 onwards to be run. If you need to use an older Python version, use an older version of the debugger.)partial)defaultdict)IS_JYTH_LESS25
IS_PYCHARMget_thread_idget_current_thread_id	dict_keysdict_iter_itemsDebugInfoHolderPYTHON_SUSPENDSTATE_SUSPEND	STATE_RUN	get_framexrangeclear_cached_thread_idINTERACTIVE_MODE_AVAILABLESHOW_DEBUG_INFO_ENVIS_PY34_OR_GREATERIS_PY36_OR_GREATERIS_PY2NULL	NO_FTRACEdummy_excepthook
IS_CPYTHONGOTO_HAS_RESPONSE)fix_getpass)pydev_imports	pydev_log)getfilesystemencoding)is_thread_alive)	threading)time)thread)	pydevd_iopydevd_vm_type)pydevd_utils)pydevd_vars)	overrides)ExceptionBreakpointset_fallback_excepthookdisable_excepthook)CMD_SET_BREAKCMD_SET_NEXT_STATEMENTCMD_STEP_INTOCMD_STEP_OVERCMD_STEP_RETURNCMD_STEP_INTO_MY_CODECMD_THREAD_SUSPENDCMD_RUN_TO_LINECMD_ADD_EXCEPTION_BREAKCMD_SMART_STEP_INTOInternalConsoleExecNetCommandFactoryPyDBDaemonThread_queueReaderThreadGetGlobalDebuggerget_global_debuggerset_global_debuggerWriterThread
pydevd_logstart_clientstart_serverInternalGetBreakpointExceptionInternalSendCurrExceptionTrace'InternalSendCurrExceptionTraceProceededCommunicationRolerun_as_pydevd_daemon_thread)CustomFramesContainercustom_frames_container_init)add_exception_to_frameremove_exception_from_frame)kill_all_pydev_threads)trace_dispatchglobal_cache_skipsglobal_cache_frame_skipsshow_tracing_warning)frame_eval_funcdummy_trace_dispatchshow_frame_eval_warning)set_additional_thread_info)save_main_module)ThreadingLoggerAsyncioLoggersend_messagecur_time)wrap_threadswrap_asyncio)get_fullnamerPathget_package_dir)
DONT_TRACE)*get_abs_path_real_path_and_base_from_frameNORM_PATHS_AND_BASE_CONTAINER)      r   .c                 V    | ddl m} |} t        j                  dk\  r| t        _        y y )Nr   )breakpointhook)      )$_pydevd_bundle.pydevd_breakpointhookrj   sysversion_info)pydevd_breakpointhookrj   s     1/usr/local/lib/python3.12/dist-packages/pydevd.pyinstall_breakpointhookrr   J   s.    $G .
6! 3 "    )PluginManagerdummyutf-8Fc                   B    e Zd Zd Z eej                        d        Zy)PyDBCommandThreadc                     t        j                  |        |j                  | _        || _        | j	                  d       y )Nzpydevd.CommandThread)r=   __init___py_db_command_thread_eventpy_dbsetNameselfr|   s     rq   rz   zPyDBCommandThread.__init__{   s2    !!$'+0+L+L(
+,rs   c                    t        j                  d       | j                  ry 	 | j                  s^	 | j                  j	                          | j                  j                          | j                  j                  d       | j                  s]y y #  t        dd       Y TxY w#  t        j                  t        j                         d          Y y xY w)N333333?r   z#Finishing debug communication...(2))r'   sleepkillReceivedr|   process_internal_commandsrD   r{   clearwaitr#   debugrn   exc_infor   s    rq   _on_runzPyDBCommandThread._on_run   s     	

3		/''IJJ88: 006680055c: ''Iq"GH	/OOCLLN1-.s#   B" B AB" BB" ",CN)__name__
__module____qualname__rz   r-   r=   r    rs   rq   rx   rx   y   s'    - ''(/ )/rs   rx   c                   P    e Zd Zd Z eej                        d        ZddZd Zy)CheckOutputThreadc                 l    t        j                  |        || _        | j                  d       d| _        y )Nzpydevd.CheckAliveThreadF)r=   rz   r|   r}   daemonr~   s     rq   rz   zCheckOutputThread.__init__   s+    !!$'
./rs   c                    | j                   st        j                  d       | j                  j	                         su| j                  j
                  j                         rQ	 t        j                  d       | j                  j                          t                | j                          d| _         | j                  j                          | j                   sy y #  t        j                          Y XxY w)Nr   z)No threads alive, finishing debug sessionT)r   r'   r   r|   has_threads_alivewriteremptyr#   r   finish_debugging_sessionrP   	traceback	print_excwait_pydb_threads_to_finishcheck_output_redirectr   s    rq   r   zCheckOutputThread._on_run   s    ##JJsO:://1djj6G6G6M6M6O*OO$OPJJ779*, 002$(!JJ,,. ##*'')s   !9C C2c           
         t        j                  d       | j                  }t        j                         }t        j                         ||z   k  rQt	        |      dk(  r|j                  | d       ry t        j                  d       t        j                         ||z   k  rQt        j                  ddj                  |D cg c]  }|| us|j                          c}      z         y c c}w )Nz)Waiting for pydb daemon threads to finishrf   {Gz?z9The following pydb threads may not finished correctly: %sz, )	r#   r   created_pydb_daemon_threadsr'   lengetr   joingetName)r   timeoutpydb_daemon_threads
started_atts        rq   r   z-CheckOutputThread.wait_pydb_threads_to_finish   s    CD">>YY[
iikJ00&'1,1D1H1Ht1TJJt iikJ00 	S)):M$_QQRZ^Q^QYY[$_`a 	b$_s    	C*
C*c                     d| _         y NT)r   r   s    rq   do_kill_pydev_threadz&CheckOutputThread.do_kill_pydev_thread   s
     rs   N)      ?)	r   r   r   rz   r-   r=   r   r   r   r   rs   rq   r   r      s2     ''(/ )/"	b!rs   r   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	TrackedLockzGThe lock that tracks if it has been acquired by the current thread
    c                     t        j                         | _        t        j                         | _        d| j
                  _        y NF)r(   allocate_lock_lockr&   local_tlsis_lock_acquiredr   s    rq   rz   zTrackedLock.__init__   s,    ))+
OO%	%*		"rs   c                 Z    | j                   j                          d| j                  _        y r   )r   acquirer   r   r   s    rq   r   zTrackedLock.acquire   s    

%)		"rs   c                 Z    | j                   j                          d| j                  _        y r   )r   releaser   r   r   s    rq   r   zTrackedLock.release   s    

%*		"rs   c                 $    | j                          y N)r   r   s    rq   	__enter__zTrackedLock.__enter__       rs   c                 $    | j                          y r   )r   )r   exc_typeexc_valexc_tbs       rq   __exit__zTrackedLock.__exit__   r   rs   c                 .    | j                   j                  S r   )r   r   r   s    rq   is_acquired_by_current_threadz)TrackedLock.is_acquired_by_current_thread   s    yy)))rs   N)
r   r   r   __doc__rz   r   r   r   r   r   r   rs   rq   r   r      s%    +*+*rs   r   c                   P    e Zd ZdZg dZdZd Zd Zd Zd Z	d Z
d	 Zed
        Zy)"AbstractSingleNotificationBehaviora  
    The basic usage should be:

    # Increment the request time for the suspend.
    single_notification_behavior.increment_suspend_time()

    # Notify that this is a pause request (when a pause, not a breakpoint).
    single_notification_behavior.on_pause()

    # Mark threads to be suspended.
    set_suspend(...)

    # On do_wait_suspend, use notify_thread_suspended:
    def do_wait_suspend(...):
        with single_notification_behavior.notify_thread_suspended(thread_id):
            ...
    )_last_resume_notification_time_last_suspend_notification_timer   _next_request_time_suspend_time_request_suspended_thread_ids_pause_requestedr   c                     t        t        t        j                               | _        d| _        d| _        | j	                         | _        t        j                         | _
        t               | _        d| _        y )NF)r   next	itertoolscountr   r   r   r   r(   r   r   setr   r   r   s    rq   rz   z+AbstractSingleNotificationBehavior.__init__   s[    ")$	0A"B/1,.0+%)%<%<%>"))+
%(U" %rs   c                     t        d      Nz#abstract: subclasses must override.AssertionErrorr   	thread_idstop_reasons      rq   send_suspend_notificationz<AbstractSingleNotificationBehavior.send_suspend_notification      BCCrs   c                     t        d      r   r   r   r   s     rq   send_resume_notificationz;AbstractSingleNotificationBehavior.send_resume_notification	  r   rs   c                 p    | j                   5  | j                         | _        d d d        y # 1 sw Y   y xY wr   )r   r   r   r   s    rq   increment_suspend_timez9AbstractSingleNotificationBehavior.increment_suspend_time  s3    ZZ 	C)-)@)@)BD&	C 	C 	Cs   ,5c                     | j                   5  d| _        | j                  }d d d        t        | j                         y # 1 sw Y    xY wr   )r   r   r   rK   _notify_after_timeoutr   global_suspend_times     rq   on_pausez+AbstractSingleNotificationBehavior.on_pause  sG     ZZ 	=$(D!"&"<"<	= 	$D$>$>@ST	= 	=s   A  A	c                 ,   t        j                  | j                         | j                  5  | j                  rH|| j
                  kD  r9|| _        | j                  t        t        | j                              t               d d d        y # 1 sw Y   y xY wr   )
r'   r   NOTIFY_OF_PAUSE_TIMEOUTr   r   r   r   r   iterr7   r   s     rq   r   z8AbstractSingleNotificationBehavior._notify_after_timeout  st    

4//0ZZ 	o))&)M)MM;ND8224T=W=W8X3Y[mn	o 	o 	os   AB

Bc              #   ,  K   | j                   5  | j                  }|rd| _        | j                  j                  |       |t        k7  s|r<| j
                  | j                  kD  r#| j
                  | _        | j                  ||       d d d        	 d  | j                   5  | j                  j                  |       | j                  | j                  k  r"| j                  | _	        | j                  |       d d d        y # 1 sw Y   zxY w# 1 sw Y   y xY w# | j                   5  | j                  j                  |       | j                  | j                  k  r"| j                  | _	        | j                  |       d d d        w # 1 sw Y   w xY wxY wwr   )r   r   r   addr7   r   r   r   remover   r   )r   r   r   pause_requesteds       rq   notify_thread_suspendedz:AbstractSingleNotificationBehavior.notify_thread_suspended!  s\    ZZ 	K"33O(-%&&**95 00O--0T0TT;?;U;UD8229kJ	K	=  =**11)<669]9]]:>:^:^D711)<	= =%	K 	K$= = =**11)<669]9]]:>:^:^D711)<	= = =sg   FA8D FD F AD7	F D	FDFF%AF<	FF
FFN)r   r   r   r   	__slots__r   rz   r   r   r   r   r   r   r   r   rs   rq   r   r      sM    $I !&DDCUo = =rs   r   c                       e Zd Zej                  ddgz   Zd Z eej                        d        Z eej                        d        Z eej                        e
d               Z	y)"ThreadsSuspendedSingleNotification!multi_threads_single_notification_py_dbc                 p    t         j                  |        d| _        t        j                  |      | _        y r   )r   rz   r   weakrefrefr   r~   s     rq   rz   z+ThreadsSuspendedSingleNotification.__init__A  s(    *33D916.kk%(rs   c                     | j                         }|5|j                  j                  |j                  j	                  |             y y r   )r   r   add_commandcmd_factory&make_thread_resume_single_notification)r   r   r|   s      rq   r   z;ThreadsSuspendedSingleNotification.send_resume_notificationG  s<    LL$$U%6%6%]%]^g%hi rs   c                     | j                         }|6|j                  j                  |j                  j	                  ||             y y r   )r   r   r   r   'make_thread_suspend_single_notification)r   r   r   r|   s       rq   r   z<ThreadsSuspendedSingleNotification.send_suspend_notificationM  s?    LL$$U%6%6%^%^_hju%vw rs   c              #      K   | j                   r%t        j                  | ||      5  d  d d d        y d  y # 1 sw Y   y xY wwr   )r   r   r   r   s      rq   r   z:ThreadsSuspendedSingleNotification.notify_thread_suspendedS  sF      113KKDR[]hi    s   $A9AAAN)r   r   r   r   r   rz   r-   r   r   r   r   r   rs   rq   r   r   <  s    2<<+X@7 7I) 1JJKj Lj
 1KKLx Mx
 1IIJ  Krs   r   c                      e Zd ZdZd:dZd Zd;dZd Zd<dZd<dZ	e
d	        Zej                  d
        Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd:dZ d:dZ!d  Z"d! Z#d" Z$	 d<d#Z%d$ Z&d=d%Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d>d-Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d:d4Z6d5 Z7d?d6Z8d7 Z9d8 Z:d9 Z;e<Z=e>Z>e?Z?y)@PyDBa8   Main debugging class
    Lots of stuff going on here:

    PyDB starts two threads on startup that connect to remote debugger (RDB)
    The threads continuously read & write commands to RDB.
    PyDB communicates with these threads through command queues.
       Every RDB command is processed by calling process_net_command.
       Every PyDB net command is sent to the net by posting NetCommand to WriterThread queue

       Some commands need to be executed on the right thread (suspend/resume & friends)
       These are placed on the internal command queue.
    c                    |rt        |        t        j                          d | _        d | _        d | _        d | _        d | _        t               | _	        t        t        j                        | _        i | _        d| _        i | _        i | _        i | _        i | _        d| _        t+               | _        t/        j0                         | _        t5        j6                         | _        |r| j8                  t:        _        d| _        d| _        d | _         t        jB                  | _!        d| _"        d| _#        d| _$        d| _%        d| _&        d| _'        d| _(        d| _)        i | _*        d| _+        i | _,        d | _-        d| _.        d| _/        d | _0        d | _1        d| _2        d| _3        i | _4        i | _5        d| _6        to        jp                         | _8        to        jr                         | _9        d| _:        d| _;        d| _<        d| _=        d| _>        t        |       | _@        t5        j                         | _B        t               | _D        d | _E        t        | _F        d| _G        y )Nr   FTr   )HrB   pydevd_tracingreplace_sys_set_trace_funcreaderr   output_checker_threadpy_db_command_threadquittingr<   r   r	   r>   Queue
_cmd_queuebreakpointsmtimefile_to_id_to_line_breakpointfile_to_id_to_plugin_breakpointbreak_on_uncaught_exceptionsbreak_on_caught_exceptionsready_to_runr   
_main_lockr(   r   _lock_running_thread_idsr&   Eventr{   rL   _finish_debugging_session_termination_event_setsignature_factorySetTrace)skip_on_exceptions_thrown_in_same_context7ignore_exceptions_thrown_in_lines_with_ignore_exception$skip_suspend_on_breakpoint_exceptionskip_print_breakpoint_exceptiondisable_property_tracedisable_property_getter_tracedisable_property_setter_tracedisable_property_deleter_trace_running_thread_ids_set_breakpoints_with_id.filename_to_lines_where_exceptions_are_ignoredpluginhas_plugin_line_breakshas_plugin_exception_breaksthread_analyserasyncio_analyser
mpl_in_usempl_hooks_in_debug_consolempl_modules_for_patching_filename_to_not_in_scopefirst_breakpoint_reachedr+   is_filter_enabledis_filter_librariesshow_return_valuesremove_return_values_flagredirect_outputuse_frame_evalstop_on_startr   &_threads_suspended_single_notificationr   _local_thread_trace_funcdict#process_created_msg_received_eventscommunication_roler   stop_on_failed_tests)r   set_as_globals     rq   rz   zPyDB.__init__o  s9   %557%)"$(!,.%fll3 
-/*/1, -/)*,'!%-(.(<(<(>%+4??+<(@D@`@`!=).&&+#!%&//9>6GKD 571/1, ',#-2*-2*.3+ $& (-% ?A; &+#+0(# $  */'(*%)+&(-%!-!?!?!A#/#C#C#E "').&$ #" 7YY]6^3(1(9% 4860"&#6  %*!rs   c                 l    	 | j                   j                  }|S # t        $ r | j                  }Y |S w xY wr   )r2  thread_trace_funcAttributeErrorrQ   )r   r9  s     rq   get_thread_local_trace_funcz PyDB.get_thread_local_trace_func  sD    	4 $ = = O O !   	4 $ 3 3  	4s    33Nc                    t                | j                  W| j                          t        j                  | j                         t
        r!|rt        j                  | j                         y|| j                         }n|| j                  _	        t        j                  |       t
        r|rt        j                  |       yyy)aT  
        Enables tracing.

        If in regular mode (tracing), will set the tracing function to the tracing
        function for this thread -- by default it's `PyDB.trace_dispatch`, but after
        `PyDB.enable_tracing` is called with a `thread_trace_func`, the given function will
        be the default for the given thread.
        N)
r/   rU   r   r  rV   r   set_trace_to_threadsr;  r2  r9  )r   r9  apply_to_all_threadss      rq   enable_tracingzPyDB.enable_tracing  s     	 !+  "##D$=$=>233D4M4MN$ $ @ @ B>OD)); 12.//0AB /:rs   c                 .    t        j                  d        y r   )r   r  r   s    rq   disable_tracingzPyDB.disable_tracing  s    %rs   c                 n    | j                   sy| xj                  dz  c_        |s| j                          yy)zh
        When breakpoints change, we have to re-evaluate all the assumptions we've made so far.
        Nrf   )r  r  !set_tracing_for_untraced_contexts)r   removeds     rq   on_breakpoints_changedzPyDB.on_breakpoints_changed  s3       

a
 224 rs   c                    d }|rt        j                         }t        d t               D              }t        rCt        j                         }|j                         D ]  \  }}||vs| j                  |        y t               }	 |D ]G  }|j                  |v s||u rt        |      }	|	j                  |      }	 || j                  |       d }I 	 d }d }d }d }	y # d }w xY w# d }d }d }d }	w xY w)Nc              3   h   K   | ]*  }t        |d d      st        |dd      r|j                   , yw)is_pydev_daemon_threadFpydev_do_not_traceN)getattrident).0r   s     rq   	<genexpr>z9PyDB.set_tracing_for_untraced_contexts.<locals>.<genexpr>  s6       
q2E:gaI]_d>e GG 
s   02)r&   current_threadr   threadingEnumerater   rn   _current_framesitemsset_trace_for_frame_and_parentsrK  rX   get_topmost_frame)
r   ignore_current_threadignore_threadignore_thread_idstid_to_framer   framethreadsr   additional_infos
             rq   rC  z&PyDB.set_tracing_for_untraced_contexts  s!     %446M  
/1 
 

  ..0L$0$6$6$8 @ 	5$5588?@ )*G'  
%Aww"33qM7I &@&CO+==a@E% , @@G $
% "& !%"&s$   4C$ <CC$ C!!C$ $
C.c                 .    | j                   j                  S r   r1  r   r   s    rq   r   z&PyDB.multi_threads_single_notification.  s    ::\\\rs   c                 &    || j                   _        y r   r\  )r   notifys     rq   r   z&PyDB.multi_threads_single_notification2  s    X^33Urs   c                 ^    | j                   t        rt        |       | _         | j                   S r   )r   SUPPORT_PLUGINSrt   r   s    rq   get_plugin_lazy_initzPyDB.get_plugin_lazy_init6  s$    ;;?'-DK{{rs   c                 ,    t        j                  |      S r   )r+   in_project_rootsr   filenames     rq   in_project_scopezPyDB.in_project_scope;  s    ,,X66rs   c                 ,    t        j                  |      S r   )r+   is_ignored_by_filterrd  s     rq   is_ignored_by_filterszPyDB.is_ignored_by_filters>  s    00::rs   c                 ,    t        j                  |      S r   )r+   #is_exception_trace_in_project_scoper   traces     rq   rk  z(PyDB.is_exception_trace_in_project_scopeA      ??FFrs   c                 ,    t        j                  |      S r   )r+   #is_top_level_trace_in_project_scoperl  s     rq   rp  z(PyDB.is_top_level_trace_in_project_scopeD  rn  rs   c                 ,    t        j                  |      S r   )r+   is_test_item_or_set_up_caller)r   rX  s     rq   rr  z"PyDB.is_test_item_or_set_up_callerG  s    99%@@rs   c                     d| _         y r   )r6  r   s    rq   set_unit_tests_debugging_modez"PyDB.set_unit_tests_debugging_modeJ  s
    $(!rs   c                     t        j                         D ]Q  }t        |t              rt	        j
                  d       t        |      s4|j                         rt        |d      sQ y y)NWError in debugger: Found PyDBDaemonThread not marked with is_pydev_daemon_thread=True.
__pydevd_main_threadTF)	r+   get_non_pydevd_threads
isinstancer=   r#   
error_oncer%   isDaemonhasattr)r   r   s     rq   r   zPyDB.has_threads_aliveM  s\    446 	 A!-.$$np q!zz|wq2H'I	  rs   c                     d| _         y r   )r  r   s    rq   r   zPyDB.finish_debugging_sessionY  s
    )-&rs   c                    	 |j                  d        t        |      | _        t        |      | _        | j                  j                          | j                  j                          t        j                  d       y #  Y nxY w)N皙?)
settimeoutrC   r   r?   r  startr'   r   )r   socks     rq   initialize_networkzPyDB.initialize_network]  sb    	OOD! #4("4(

3	s   A= =Bc                     |r"t         j                  | _        t        ||      }n t         j                  | _        t        |      }| j                  |       y r   )rJ   CLIENTr5  rE   SERVERrF   r  )r   hostportss       rq   connectzPyDB.connecti  sE    &7&>&>D#T4(A&7&>&>D#T"A"rs   c                 p    |j                  d      r||j                  d      dz   d }| j                  |   S )zm returns internal command queue for a given thread.
        if new queue is created, notify the RDB about it 	__frame__|rf   N)
startswithrfindr  r   s     rq   get_internal_queuezPyDB.get_internal_queuet  s<     ,!)//#"6":";<Iy))rs   c                 H    | j                  |      }|j                  |       y)z) if thread_id is *, post to the '*' queueN)r  put)r   int_cmdr   queues       rq   post_internal_commandzPyDB.post_internal_command{  s    ''	2		'rs   c                 d    |a |a|xs || _        t         r
t                t        rt	                y y r   )bufferStdOutToServerbufferStdErrToServerr.  init_stdout_redirectinit_stderr_redirect)r   redirect_stdoutredirect_stderrs      rq   enable_output_redirectionzPyDB.enable_output_redirection  s4      /..A/ " "  rs   c                 F    t         r
t                t        rt                y y r   )r  r  r  r  r   s    rq   r   zPyDB.check_output_redirect  s       " "  rs   c                     ddl m} t        | j                        D ]-  }|j	                  || j                  j                  |             / y )Nr   )import_hook_manager)_pydev_bundle.pydev_import_hookr  r   r'  add_module_namepop)r   r  modules      rq    init_matplotlib_in_debug_consolez%PyDB.init_matplotlib_in_debug_console  sC    G = => 	cF//8U8U8Y8YZ`8ab	crs   c                 z    ddl mm}m}m  G d d      fd}ddlm}  ||       fd||d| _        y )	Nr   )activate_matplotlibactivate_pylabactivate_pyplotdo_enable_guic                       e Zd ZdZy)7PyDB.init_matplotlib_support.<locals>._MatplotlibHelperFN)r   r   r   _return_control_oscr   rs   rq   _MatplotlibHelperr    s    "'rs   r  c                  @     j                     _          j                   S r   )r  )r  s   rq   return_controlz4PyDB.init_matplotlib_support.<locals>.return_control  s$     9J8]8]4]1$888rs   )set_return_control_callbackc                              S r   r   )r  r  s   rq   <lambda>z.PyDB.init_matplotlib_support.<locals>.<lambda>  s    ?RS`?a rs   )
matplotlibzmatplotlib.pyplotpylab)pydev_ipython.matplotlibtoolsr  r  r  r  pydev_ipython.inputhookr  r'  )r   r  r  r  r  r  r  r  s        @@@rq   init_matplotlib_supportzPyDB.init_matplotlib_support  s:    uu	( 	(	9 	H#N37a>M2@)C%rs   c                     t        | j                        dkD  rWt        | j                        D ]>  }|t        j                  v s| j                  j                  |      } |        d| _        @ y y )Nr   T)r   r'  r   rn   modulesr  r%  )r   r  activate_functions      rq   _activate_mpl_if_neededzPyDB._activate_mpl_if_needed  sd    t,,-1#D$A$AB +S[[((,(E(E(I(I&(Q%%'&*DO	+ 2rs   c                 B    	 ddl m}  |       }|r |        y y #  Y y xY w)Nr   )get_inputhook)r  r  )r   r  	inputhooks      rq   _call_mpl_hookzPyDB._call_mpl_hook  s(    	=%I 	s    c                 h   | j                   y |r| j                  nt        5  || j                  v r
	 d d d        y t	        |      }|j
                  r
	 d d d        y || j                  |<   d d d        | j                   j                  | j                  j                  |             y # 1 sw Y   >xY wr   )	r   r  r   r  rX   pydev_notify_killr   r   make_thread_created_message)r   r   r(   use_lockrZ  s        rq   notify_thread_createdzPyDB.notify_thread_created  s    ;;
 .6T**D 
	9D444
	9 
	9 9@O00 
	9 
	9 39D$$Y/
	9 	 0 0 L LV TU
	9 
	9s   B(B(B((B1c                 z   | j                   y|r| j                  nt        5  | j                  j	                  |d      }|
	 ddd       y|j
                  j                  }|sd|j
                  _        ddd       | j                   j                  | j                  j                  |             y# 1 sw Y   >xY w)z: if thread is not alive, cancel trace_dispatch processing NT)
r   r  r   r  r  rZ  r  r   r   make_thread_killed_message)r   r   r  r(   was_notifieds        rq   notify_thread_not_alivezPyDB.notify_thread_not_alive  s    ;;.6T**D 	@--11)TBF~	@ 	@
 "11CCL;?&&8	@ 	 0 0 K KI VW	@ 	@s    B1)B11B:c           	      8   | j                   5  | j                          i }t               }g }| j                  5  |D ]  }t	        |dd      rt        |t              rt        j                  d       7t        |      sC| j                  so|D ]j  }t        |      }t        |       t        |      }||k7  s*t        j                  |      s@t        j                  |      }t        j                   ||       l t        |      }|||<   | j#                  ||d        t%        | j                  j'                               }	|	D ]  }||vs|j)                  |        |D ]  }| j+                  |d        	 ddd       t-        |      dk(  r5| j/                          |D ]  }t1        |d      s|j3                          ! nt5        t7                     }
|
dfD ]  }| j9                  |      }g }	 	 |j;                  d      }| j<                  s/t        |t>              r	 | jA                          d	| _!        d	| _        |jK                  |
      r(tE        d
dtM        |             |jO                  |        n'tE        d
dtM        |             |j)                  |        ddd       y# 1 sw Y   3xY w#  tE        d
dtG        jH                                Y xY w# tP        jR                  $ r |D ]  }|jU                  |        Y 0w xY w# 1 sw Y   yxY w)z2This function processes internal commands
        rH  Frv  )r  Nr   r   *Tr   z*Matplotlib support in debug console failedzprocessing internal command z NOT processing internal command )+r  r   rO  r  rJ  ry  r=   r#   rz  r%   r  r   r   r,   has_additional_frames_by_idget_additional_frames_by_idadd_additional_frame_by_idr  listkeysappendr  r   r   r|  r   r   threadingCurrentThreadr  r   r&  r;   r  r%  rD   r   
format_exccan_be_executed_bystrdo_itr>   Emptyr  )r   program_threads_aliveall_threadsprogram_threads_deadr   existing_threadold_thread_idr   frames_by_id
thread_idscurr_thread_idr  cmds_to_add_backr  s                 rq   r   zPyDB.process_internal_commands  s*    __ X	/&&($&!,.K#% .. &L$ QAq":EB#A'78!,,  .H  I(+#77 4? h0=o0N 6q 9,9!,<	#,#='2'N'N}']7B7^7^_l7m(3(N(NyZf(gh %2!$4	;<-i8229a%2P9Q> "$":":"?"?"AB
!+ ?I (==,33I>? "6 LI00U0KLK&LR ()Q.--/$ 1Aq"89..01 "77M7O!P"0#!6 /I 33I>E (*$/"&+ii&6G#'#B#BzRY[nGo!x$($I$I$K6:DO CG ?&99.I *1.LcRYl [ 'd 3 *1.PRUV]R^ _ 0 7 7 @# #/uX	/ X	/&L &LH!x$.q2^`i`t`t`v$w "<< /'7 /G!IIg.//kX	/ X	/s   +LAJ+>7J+6J+A?J+-J+:7L2A L3.K"J89A(K!L+J5	0L8!KK+L	LLLLc                 v    i }t        |      D ]  \  }}|||j                  <    |||<   | j                          y r   )r   lineclear_skip_caches)r   fileid_to_breakpointr  
break_dictbreakpoint_idpybreakpoints          rq   consolidate_breakpointszPyDB.consolidate_breakpointsI  sI    
+:;K+L 	9'M<,8J|(()	9 'D rs   c                 T    t        j                          t        j                          y r   )rR   r   rS   r   s    rq   r  zPyDB.clear_skip_cachesQ  s      " &&(rs   c           	         	 t        |||||||      }|j                  rR| j
                  j                         }	||	|<   t        j                  dkD  rt        j                  d|	d       |	| _        |j                  rR| j                  j                         }	||	|<   t        j                  dkD  rt        j                  d|	d       |	| _
        |S # t        $ r t        j                  d|d       Y y w xY w)Nz,Error unable to add break on exception for: z# (exception could not be imported)
r   z!Exceptions to hook on terminate: 
zExceptions to hook always: )r.   ImportErrorr#   errornotify_on_unhandled_exceptionsr  copyr   DEBUG_TRACE_BREAKPOINTSnotify_on_handled_exceptionsr  )
r   	exception	condition
expressionr  r  notify_on_first_raise_onlyignore_librariesebcps
             rq   add_break_on_exceptionzPyDB.add_break_on_exceptionU  s    	$,.* B ,,22779BByM66:2 OP02D-**00557BByM66:R IJ.0D+	%  	OOt}  A	s   C "C65C6c                     t        |      }t        |_        ||_        |j                  dk(  rt
        |_        t        |_        |S )Nr   )rX   r   suspend_typer   pydev_step_cmdr3   r   pydev_state)r   r(   r   infos       rq   _mark_suspendzPyDB._mark_suspend}  sC    )&1*("$ #0D )rs   c                 t   | j                   j                          |r| j                   j                          | j                  ||      }|r'|j	                  |      }|	 | j                  |       d}|t        k(  r1|j                  %|j                  }d|_        | j                  ||       |s| j                  rd}|rmt        j                         }|D ]S  }	t        |	dd      r|	|u r| j                  |	t              }|j	                  |	      }|@	 | j                  |       d}U yy# d}w xY w# d}w xY w)a  
        :param thread:
            The thread which should be suspended.

        :param stop_reason:
            Reason why the thread was suspended.

        :param suspend_other_threads:
            Whether to force other threads to be suspended (i.e.: when hitting a breakpoint
            with a suspend all threads policy).

        :param is_pause:
            If this is a pause to suspend all threads, any thread can be considered as the 'main'
            thread paused.
        NTrI  )r1  r   r   r   rS  rR  r1    conditional_breakpoint_exception$_send_breakpoint_condition_exceptionr   r+   rx  rJ  r7   )
r   r(   r   suspend_other_threadsis_pauser  rX  &conditional_breakpoint_exception_tupler  r   s
             rq   set_suspendzPyDB.set_suspend  sN     	33JJL77@@B!!&+6**62E !88? E -'D,Q,Q,]595Z5Z248D155f>de$)O)O %)! &==?K  )12D9F{ --a1CDD 2215E () @@G$(E) ! !E< %)Es   D, D3,D03D7c                     t        |      }|r4t        |      dk(  r%|\  }}t        |||      }| j                  ||       yyy)zoIf conditional breakpoint raises an exception during evaluation
        send exception details to java
        r   N)r   r   rG   r  )r   r(   r  r   r   
stacktracer  s          rq   r  z)PyDB._send_breakpoint_condition_exception  sP     "&)	1c:`6aef6f#I Hj4Y*UG&&w	: 7g1rs   c                 X    t        |      }t        |||      }| j                  ||       y)zSends details on the exception which was caught (and where we stopped) to the java side.

        arg is: exception type, description, traceback object
        N)r   rH   r  )r   r(   argcurr_frame_idr   r  s         rq   send_caught_exception_stackz PyDB.send_caught_exception_stack  s,    
 "&)	0CO""7I6rs   c                 t    t        |      }t        |      }| j                  ||       | j                          y)zXSends that some thread was resumed and is no longer showing an exception trace.
        N)r   rI   r  r   )r   r(   r   r  s       rq   %send_caught_exception_stack_proceededz*PyDB.send_caught_exception_stack_proceeded  s4     "&)	9)D""7I6&&(rs   c                 n    | j                   j                         }| j                  j                  |       y)z=Sends a message that a new process has been created.
        N)r   make_process_created_messager   r   r   cmds     rq   send_process_created_messagez!PyDB.send_process_created_message  s*     ;;=$rs   c                    | j                   t        j                  k(  r| j                  j	                         rt        j                  d       y| j                  j                         }t        j                         }|| j                  |j                  <   | j                  j                  |       |j                          yy)aF  When `PyDB` works in server mode this method sends a message that a
        new process is going to be created. After that it waits for the
        response from the IDE to be sure that the IDE received this message.
        Waiting for the response is required because the current process might
        become substituted before it actually sends the message and the IDE
        will not try to connect to `PyDB` in this case.

        When `PyDB` works in client mode this method does nothing because the
        substituted process will try to connect to the IDE itself.
        z/Skip sending process substitution notification
N)r5  rJ   r  r  r   r#   r   r   r  r&   r  r4  seqr   r   r   )r   r  events      rq    send_process_will_be_substitutedz%PyDB.send_process_will_be_substituted  s     ""&7&>&>><<>  RS""??ACOO%E@ED44SWW=KK##C(JJL ?rs   c                     d}d}|j                   }|dk(  s|dk(  rE|j                  j                  }|dv rd}|dk(  s||k(  r|}	| j                  |_        |	|_         d}nd}|||fS )	NF r  r  )?z<module>r  Tz.jump is available only within the bottom frame)f_linenof_codeco_namerQ   f_trace)
r   rX  r  	func_name	next_linestopresponse_msgold_linecurr_func_namer  s
             rq   set_next_statementzPyDB.set_next_statement  s    >>F?e{2
 #\\11N !22!#C>Y#>  $ 3 3!%OX|++rs   c                    | j                   j                          	 t               }|D ]d  }t        |dd      st	        |d      st	        |d      s+|j
                  |k(  s;|j                  |k(  sK|j                  j                          f 	 | j                   j                          y #  t        j                          Y 3xY w# | j                   j                          w xY w)NrH  Fcancel_eventr   )r  r   rO  rJ  r|  r   frame_idr(  r   r   r   r   )r   r   r)  r  r   s        rq   cancel_async_evaluationzPyDB.cancel_async_evaluation  s    !		&,.K  )16>71nC]bijkmxbyy0QZZ85KNN&&() OO##%	"!OO##%s:   B+ B+ B+ B+ #B+ 3B+ C +CC C"c                 h   | j                          d}t        |      }|j                  }	|j                  j                  }
|r|j                  j
                  }d|j                  _        i }|r/|d   }|(|j                  ||j                  <   |j                  }|(| j                  j                  |||	||
|      }|j                          |j                  }| j                  j                  |       t        j                   5  g }t#        t        j$                        D ]  \  }}|j&                  |j(                  k(  r| j                  j                  | j                  j+                  ||j,                               | j                  j                  | j                  j                  ||j.                  t0        d|
             |j3                  |        	 ddd       | j4                  j7                  ||	      5  | j9                  |||||
       ddd       y# 1 sw Y   ExY w# 1 sw Y   yxY w)a   busy waits until the thread state changes to RUN
        it expects thread's state as attributes of the thread.
        Upon running, processes any outstanding Stepping commands.

        :param is_unhandled_exception:
            If True we should use the line of the exception instead of the current line in the frame
            as the paused location on the top-level frame (exception info must be passed on 'arg').
        r  rm  r   N)frame_to_lineno)r   r   r   rZ  trace_suspend_typepydev_message	tb_linenotb_frametb_nextr   make_thread_suspend_messager   thread_stack_strr   r   rL   custom_frames_lockr   custom_framesr   rK  !make_custom_frame_created_messagenamerX  r7   r  r1  r   _do_wait_suspend)r   r(   rX  r  r  send_suspend_messageis_unhandled_exceptionr3  r   r   r  messager,  tbr  from_this_threadr)  custom_frames                     rq   do_wait_suspendzPyDB.do_wait_suspend+  s    	&&( *&1	((--@@,,::G8?F""5 O%Vn35<<OBKK0B n "">>y%Q\^egs  FU>  VC!!#"33KK##C("55 		2!*9:O:]:]*^ 2&,))V\\9KK++D,<,<,^,^_giuiziz,{|KK++D,<,<,X,XYacocucu  xJ  LN  P\  -]  ^ ''12		2 88PPQZ\gh 	]!!&%\K[\	] 	]		2 		2	] 	]s   CH<H(H%(H1c                 	   |j                   }|j                  t        k(  r| j                  s| j	                          |j                  t        k(  rm| j                  sa| j
                  r| j                          | j                          t        j                  d       |j                  t        k(  r| j                  sa| j                  t        |      t        t        |                   |j                  t        k(  s|j                  t         k(  rd |_        d |j$                  _        n|j                  t(        k(  r+||_        d |j$                  _        | j+                  |       nl|j                  t,        k(  r+| j+                  |       d |_        ||j$                  _        n.|j                  t.        k(  s|j                  t0        k(  r| j+                  |       d}d}	|j2                  }
t4        sc| j7                  |||j8                  |j:                        \  }}}	|rd|_        t        |_        t<        |_        | jA                  ||||||       y 	 | j7                  |||j8                  |j:                        \  }}
}	tD        rL|jF                  }| jH                  jK                  |||	      }| jL                  jO                  |       d|_#        	 |ru| jH                  jQ                  t        |      |j                        }| jL                  jO                  |       t        |_        t0        |_        | jS                  ||||       y d|_        t        |_        t<        |_        | jS                  ||||d       y |j                  tT        k(  r@|jV                  }|||_        | j+                  |       nd |_        d|_        tX        |_        ~| jH                  jQ                  t        |      |j                        }| jL                  jO                  |       tZ        j\                  5  |D ]6  }| jL                  jO                  | jH                  j_                  |             8 	 d d d        y # tB        $ r}d|z  }	Y d }~d }~ww xY w# tD        rL|jF                  }| jH                  jK                  |||	      }| jL                  jO                  |       d|_#        w w xY w# 1 sw Y   y xY w)Nr   Fr  r   z%s)r9  )0rZ  r  r   r  r  r%  r  r   r'   r   r*  r   r  idr  r3   r6   pydev_step_stoppydev_smart_step_contextsmart_step_stopr4   rR  r:   r8   r2   r  r   r&  pydev_func_namepydev_next_liner7   r   r8  
ValueErrorr    r.  r   "make_set_next_stmnt_status_messager   r   make_thread_run_messager?  r5   f_backr   rL   r4  r  )r   r(   rX  r  r  r  r=  r  r"  r#  r$  _er  r  
back_framer)  s                    rq   r8  zPyDB._do_wait_suspendZ  sL   %%},T5S5S((*""m3D<Z<Z??'')..0

4  ""m3D<Z<Z 	$$%:6%BC5	NS -/43F3FJ_3_#'D <@D))9  M1#(D <@D))9007  $77007#'D <AD))9  O3t7J7JNd7d007DL~~H(,(?(?udNbNbdhdxdx(y%a*,D''4D$);F& ))&%\Scd	0373J3J5RWY]YmYmos  pD  pD  4E0D(L )"00"..QQRUW[]ij//4-/***BBCXY_C`bfbubuvCKK++C0'4D$)?F&((sC*,D''4D$);F&((sY^(_  O3J%',$44U;
 (,$&(##, 667LV7TVZViVij$"55 	_, _''(8(8(S(ST\(]^_	_ 	_U " ,#'!8L, )"00"..QQRUW[]ij//4-/*	 )N	_ 	_s7   ,Q4 .<S'4	R=RR RR AS$'S0c                 j   t        j                  d       t        |      }t        j                  ||       |\  }}}t        j                  |      }t        j                  t        k7  rt        |||       t                	 	 t        ||       | j                  |t               | j                  ||d|d       t%        |       t        j&                  |       d }y # t         $ r}	|	d }	~	w t        j"                  d|d   d       Y QxY w# t%        |       t        j&                  |       d }w xY w)NzWe are stopping in post-mortem
r  T)r:  z2We've got an error while stopping in post-mortem: r   r  )r#   r   r   r,   r  r+   $get_top_level_trace_in_project_scopern   
excepthookr   original_excepthookr0   rN   r  r9   r?  KeyboardInterruptr  rO   remove_additional_frame_by_id)
r   r(   rX  frames_byidr  r   exctypevaluer<  rL  s
             rq   stop_on_unhandled_exceptionz PyDB.stop_on_unhandled_exception  s   :;!&)	..y+F >>rB>>--3	f&uc2  )@A$$VUK]a$b (.55i@E % f\_`a\b de'.55i@Es$   8C 	D&C((!D	D $D2c                 ~   |j                  dd      }|rJ |	 t        |j                  j                     }t        |d         }|U|r*|j                  G|j                  t        ur5t        |_        n)|j                  | j                  ur| j                  |_        |j                  }|~y #  t	        |      }Y xY w)NdisableFr   )
r  re   r  co_filenamerd   get_file_typer  r   rQ   rJ  )r   rX  kwargsrY  abs_path_real_path_and_base	file_types         rq   rR  z$PyDB.set_trace_for_frame_and_parents  s    **Y.z`.KELLLdLd.e+
 &&A"&EFI }}0U]])5S(1]]$*=*==$($7$7EMLLE% ( !`.XY^._+s   B- -B<c                     | j                   }||j                          t        |       x}| _         |j                          y r   )r  r   rx   r  )r   curr_pydb_command_threadnew_pydb_command_threads      rq   _create_pydb_command_threadz PyDB._create_pydb_command_thread  s@    #'#<#< #/$99;>OPT>UU$";%%'rs   c                     | j                   }||j                          t        |       x}| _         |j                          y r   )r  r   r   r  )r   curr_output_checker_threadr  s      rq   _create_check_output_threadz PyDB._create_check_output_thread  s?    %)%?%?"%1&;;==Nt=TT :##%rs   c                 D    | j                          | j                          y r   )rb  re  r   s    rq   start_auxiliary_daemon_threadsz#PyDB.start_auxiliary_daemon_threads  s    ((*((*rs   c                    | j                          | j                  s| j                  | j                  | j	                          d| _        | j                          |rt        j                  | j                         t        st        r7| j                  j                  d      }| j                  j                  |       yy)zO Shared code to prepare debugging by installing traces and registering threads Ncython)rb  r.  r  r#  re  rU   patch_threadsr   r  rQ   rT   rW   r   make_show_warning_messager   r   )r   enable_tracing_from_startr  s      rq   prepare_to_runzPyDB.prepare_to_run  s    ((*4#9#9#EI]I]Ii,,.#'D $##D$7$78#:""<<XFCKK##C( $;rs   c                 l    	 t        j                  | j                         ddlm}  |        y #  Y xY w)Nr   )patch_thread_modules)r&   settracerQ   _pydev_bundle.pydev_monkeyro  )r   ro  s     rq   rj  zPyDB.patch_threads  s1    	t223 	D		s   / 3c                 p
   d }d}|rdt         j                  vr t         j                  j                  dd       |j                  d      \  }}}|}t	        |      }	|	gt        |      }
|
#t         j                  j                  d|z         y t	        d|z        }	|	#t         j                  j                  d|z         y |	}n)|	}t        j                  j                  |	      }
t        j                  j                  |
d      }t        j                  j                  |
d      }|	j                  d      rDt        j                  j                  |      r|}	nt        j                  j                  |      rv|}	ns|	j                  d	      rbt        j                  j                  |      r"t        j                  j                  |      s|}	n!t        j                  j                  |      r|}	|	t         j                  d<   t        j                  j                  |      rAt        j                  j                  |d      }t        j                  j                  |      r|}d }|"t!        |d
      }|j"                  }	 t$        |d<   ||}t         j                  d   dk7  r?|=|j(                  j+                  t         j                  d         rt         j                  d= |sIt         j                  j                  dt        j                  j-                  t/        |            d          |ru| j0                  s"t3        j4                  d       | j0                  s"| j6                  s$| j8                  s| j:                  s| j<                  rd | _        | jA                          tC               }tE        |      }| jF                  YtI                | jF                  jK                  tM                      tO        dd|jQ                         |dd|dd tS        |      
       | jT                  %tV        r
tY                tO        dddddd|dd d 
       	 tZ        r| j]                          tc        t         d      rt        jd                          | jg                  ||       | jh                  r tk        |      }tl        |jn                  _8        |r| js                          | ju                  ||||||      S # t&        $ r Y sw xY w#  t         j                  j                  d       t_        j`                          Y xY w)Nr  r   :zNo module named %s
z%s.__main__z__main__.pyz__main__.pycz__init__.pycz__init__.pypydevd__builtins__r  threading_eventr(   r  rf   )parentasyncio_eventTaskr"  )rX  rw  z&Matplotlib support in debugger failed
	exc_clear);rn   pathinsert	partitionr`   rb   stderrwriteosdirnamer   endswithexistsargvisdirisfilerY   __dict__ru  	NameError__file__r  splitra   r  r'   r   r  r!  r"  r  rU   rm  r  r   r#  r^   set_start_timer]   r\   r   r   r$  r   r_   r   r  r   r   r|  rz  r  r0  rX   r6   rZ  r  r?  _exec)r   r  globalslocals	is_module	set_tracemodule_nameentry_point_fnrK  re  mod_dirmain_pymain_pyc
new_targetmr   r   r  s                     rq   runzPyDB.run  s    !2&'+~~c':$D!nK#D)H)+6?JJ$$%;d%BC+MK,GHH'

(()?$)FG'''//(3'',,w>77<<@$$^4ww~~h/#+0#*&&}5ww~~h/w8O#+0#*"CHHQK77==dM:Jww~~j)!? x0AjjG*6' >F 88A;"1::3H3HRS3U
 HHOOArww}}U4[9!<=''

3 '' ..$2M2MQUQqQq-- (,$ !"$)!,	+N  //
;*Aqyy{IxQXZ^`acgp}~  qA  B  ,!!VVXvtUV^bkop	"),,.
 3$MMO 	""9a0-a0D/DA, !zz)^[$QWXX[  t	"JJFG!s   >	S. S> .	S;:S;>5T5c                 N   |st        j                  |||       |S |r&t        |d|g||      }t        ||      } |        |S ddl}	t        |	d      r@t        j                  dd dk  r|	j                  |d       |S |	j                  |d	       |S |	j                  |       |S )
zs
        This function should have frames tracked by unhandled exceptions (the `_exec` name is important).
        r   )levelfromlistr  r  N_run_module_as_mainr   r   F)	set_argv0)
alter_argv)
r"   execfile
__import__rJ  runpyr|  rn   ro   r  
run_module)
r   r  r  r  r  r  r  modfuncr  s
             rq   r  z
PyDB._exec  s     ""4&9(   A@PZajpqsN3  5"78''+v511+1O
  11+%1P  $$[1rs   c                    t         j                  j                          t         j                  j                          | j	                          | j
                  j                         }| j                  j                  |       y r   )	rn   stdoutflushr~  r   r   make_exit_messager   r   r  s     rq   exitingzPyDB.exiting  sT    



""$002$rs   c                 h   | j                          t        j                         }ddlm} |j                  d d|j                  dt        j                  j                  t        j                  j                  t                          ||      }t        |      }t        j                  |t        |      |i       | j                   j#                  ||      }| j$                  j'                  |       	 | j(                  r| j+                          | j-                          t/        j0                  d       B)Nr   )pydevd_frame_utilsr   Consoler   )r  r&   currentThread_pydevd_bundler  FrameFCoder  r{  abspathr  r  r   r,   r  rA  r   make_show_console_messager   r   r%  r  r   r'   r   )r   r  r(   r  rX  r   r  s          rq   wait_for_commandszPyDB.wait_for_commands  s    $$&((*5"((r3E3K3KILNGGOO\^\c\c\k\klt\uLv4x zA  CJK)&1	..y2e9e:LM88EJ$##%**,JJt rs   )Tr   )F)FF)TF)NNFT)@r   r   r   r   rz   r;  r?  rA  rE  rC  propertyr   setterra  rf  ri  rk  rp  rr  rt  r   r   r  r  r  r  r  r   r  r  r  r  r  r  r   r  r  r  r   r  r  r  r  r  r  r&  r*  r?  r8  rW  rR  rb  re  rg  rm  rj  r  r  r  r  _trace_dispatchrQ   rU   rV   r   rs   rq   r   r   `  sp   b*H!C6&5&'P ] ] '--_ ._
7;GGA)
.
#*

##cC.+V,X [/z!) &P;)|	;7)%2,0&-]^a_F.4(&+)"DYL6%( %N%O/rs   r   c                 "    d| d<   d| d<   d| d<   y )NTDEBUG_RECORD_SOCKET_READSrf   r  rk   DEBUG_TRACE_LEVELr   setups    rq   	set_debugr    s#    )-E
%&'(E
#$!"E
rs   c                 2    ddl m} |j                  |        y )Nr   )pydev_monkey_qt)_pydev_bundler  patch_qt)qt_support_moder  s     rq   enable_qt_supportr    s    -_-rs   c                 .    t        j                  |        y)zE
    Helper to dump thread info (default is printing to stderr).
    N)r+   dump_threads)streams    rq   r  r    s     f%rs   c                     t         j                  j                  d       t         j                  j                  d       | rt        j                  d       y y )NzUsage:
zUpydevd.py --port N [(--client hostname) | --server] --file executable [file_options]
r   )rn   r  r  exit)doExits    rq   usager    s:    JJZ JJmn rs   c                        e Zd ZddZd Zd Zy)_CustomWriterNc                     t        |dt        j                  j                  dd            | _        || _        |rt        ||d|      | _        || _        y)a  
        :param out_ctx:
            1=stdout and 2=stderr

        :param wrap_stream:
            Either sys.stdout or sys.stderr.

        :param bool wrap_buffer:
            If True the buffer attribute (which wraps writing bytes) should be
            wrapped.

        :param callable(str) on_write:
            May be a custom callable to be called when to write something.
            If not passed the default implementation will create an io message
            and send it through the debugger.
        encodingPYTHONIOENCODINGrv   F)wrap_bufferon_writeN)	rJ  r  environr   r  _out_ctxr  buffer	_on_write)r   out_ctxwrap_streamr  r  s        rq   rz   z_CustomWriter.__init__  sI    "  ZHZ\c9de'%ZbcDK!rs   c                      y r   r   r   s    rq   r  z_CustomWriter.flush  s    rs   c                    | j                   | j                  |       y |rt        r#t        |t              r@|j	                  dd      }n-t        |t
              r|j                  | j                  d      }t               }|B|j                  j                  || j                        }|j                  j                  |       y y y )Nrv   replace)errors)r  r   ry  unicodeencodebytesdecoder  rA   r   make_io_messager  r   r   )r   r  r|   r  s       rq   r  z_CustomWriter.write  s    >>%NN1a))4A a'yAA')E  ''774==I((-	 ! rs   r   )r   r   r   rz   r  r  r   rs   rq   r  r    s    "..rs   r  c                     t        t        d      skt        sdnd}t        j                  }t	        d|||       t        _        |t        _        t        j                  |t        j
                  |      t        _        y y )N_pydevd_out_buffer_TFrf   )	r|  rn   r   r  r  r  stdout_originalr)   IORedirectorr  r  originals      rq   r  r  *  [    3-."(de::"/8[("S&++Hc6M6M{[
 /rs   c                     t        t        d      skt        sdnd}t        j                  }t	        d|||       t        _        |t        _        t        j                  |t        j
                  |      t        _        y y )N_pydevd_err_buffer_TFr   )	r|  rn   r   r~  r  r  stderr_originalr)   r  r  s      rq   r  r  2  r  rs   c	           
          t         j                          	 t        | |||||||       t         j                          y# t         j                          w xY w)a  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 (default is the local
        host)

    @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 current and future
        threads will also have the tracing enabled.

    @param overwrite_prev_trace: deprecated

    @param patch_multiprocessing: if True we'll patch the functions which create new processes so that launched
        processes are debugged.

    @param stop_at_frame: if passed it'll stop at the given frame, otherwise it'll stop in the function which
        called this method.
    N)_set_trace_lockr   _locked_settracer   )	r  stdoutToServerstderrToServerr  suspendtrace_only_current_threadoverwrite_prev_tracepatch_multiprocessingstop_at_frames	            rq   rp  rp  >  sQ    J "%!		
 	!!s	   = Ac                    |r	 ddl m} |j                          i t        _        t
        st        j                          t        j                  | dt        |      |d}	|	t        _	        t               }
|
j                  | |       da|a|at        r
t                t        r
t!                t#        |
       t%               }t'        |      }|
j(                  s"t+        j,                  d       |
j(                  s"|
j/                  t1               j2                         t4        j6                  j9                          	 t;        t4        j<                        D ]   \  }}|
j/                  |j>                         " 	 t4        j6                  jA                          |
jC                          |
jE                  d       |s"|
jG                          |
jI                  d       tK        jL                  tN               ndtQ               }
|
j/                  t1               j2                         t%               }t'        |      }|
jE                          |s|
jG                          |rB|)tR        |_*        tV        |_,        ||_-        t\        |_/        y |
ja                  |tb               y y #  Y xY w# t4        j6                  jA                          w xY w)	Nr   pydev_monkeyF)clientserverr  multiprocessTr  )r>  )rT  )2r  r  patch_new_process_functionsr=   r   	connectedr*   
setup_typeSetupHolderr  intr   r  r  r  r  r  patch_stdinr  rX   r  r'   r   rR  r   rJ  rL   r4  r   r   r5  rX  r   rg  r?  rj  rC  atexitregister	stoptracerA   r   r  r4   r  rB  r   r  r  r1   )r  r  r  r  r  r  r  r  r  r  debuggerr   rZ  _frameIdr>  s                  rq   r  r  v  sQ    	72 446 460!!#$D	 5	E !&K6t$ 	-- " "H"$4Q7''JJsO '' 	001C1CD0088:	?*9:O:]:]*^ M&,889K9KLM "44<<>//1T:(""$ 66T6R 		" '(001C1CD"$4Q7!(""$ $ +4O'-:O*.;O++9O(   M2 m	j "44<<>s   J! =<J) !J&) K	c                  >   t         rt        j                          t        j                  d        	 t        j                  d        ddlm}   |         t               }|r5|j                  t               d       |j                          t                da y y #  Y VxY w)Nr   )undo_patch_thread_modulesT)rY  F)r  r   restore_sys_set_trace_funcrn   rp  r&   rq  r  rA   rR  r   r  rP   )r  r  s     rq   r  r    s    113T	t$ 	I!#&(44Y[$4O"$	+ 	s   B Bc                       e Zd Zd Zd Zd Zy)
Dispatcherc                     d | _         y r   )r  r   s    rq   rz   zDispatcher.__init__   s	    	rs   c                     || _         || _        t        | j                   | j                        | _        t	        |       | _        d| j
                  _        | j
                  j                          y r   )r  r  rE   r  DispatchReaderr  rI  r  )r   r  r  s      rq   r  zDispatcher.connect  sL    		"499dii8$T*).&rs   c                 H    	 | j                   j                          y #  Y y xY wr   )r  r   r   s    rq   closezDispatcher.close  s!    	KK,,.	s    !N)r   r   r   rz   r  r  r   rs   rq   r	  r	    s    rs   r	  c                   N    e Zd Zd Z eej                        d        Zd Zd Zy)r  c                 f    || _         t        j                  | | j                   j                         y r   )
dispatcherr?   rz   r  )r   r  s     rq   rz   zDispatchReader.__init__  s#    $dDOO$:$:;rs   c                 b    t        j                         }d|_        t        j                  |       S r   )r&   r  rH  r?   r   )r   dummy_threads     rq   r   zDispatchReader._on_run  s)     ..0.3+##D))rs   c                 .    t        j                  |        y r   )r?   handle_exceptr   s    rq   r  zDispatchReader.handle_except  s    ""4(rs   c                 R    |dk(  r"t        |      | j                  _        d| _        y y )Nc   T)r  r  r  r   )r   cmd_idr  texts       rq   process_commandzDispatchReader.process_command  s&    R<#&t9DOO  $D rs   N)	r   r   r   rz   r-   r?   r   r  r  r   rs   rq   r  r    s0    < |##$* %*
)%rs   r  c                 &    | j                  dd      S )z
    The new connection dispatch approach is used by PyDev when the `multiprocess` option is set,
    the existing connection approach is used by PyCharm when the `multiproc` option is set.
    	multiprocF)r   r  s    rq   _should_use_existing_connectionr  %  s    
 99[%((rs   c                      t         j                  } | d   }| d   }t        |       r=t               }	 |j	                  ||       |j
                  }|j                          ||fS ||fS # |j                          w xY w)Nr  r  )r  r  r  r	  r  r  r  )r  r  r  r  s       rq   dispatchr  -  s{    E?D=D&u-\
	tT*??D:4: s   A' 'A9c                      ddl m}  d| _        ddlm} t               \  }}ddl} |j                          |)dada	t                | |        t        ||dddd       yy)zo
    When creating a fork from a process in the debugger, we need to reset the whole debugger environment!
    r   )GlobalDebuggerHolderN)clear_thread_local_infoFT)r  r  r  r  r  )_pydevd_bundle.pydevd_constantsr!  
global_dbg)_pydevd_frame_eval.pydevd_frame_eval_mainr"  r  r   r  r  forkedrM   rp  )r!  r"  r  r  r   s        rq   settrace_forkedr'  ;  sq     E&*#QJD$-N--/	$&".#%*/%)&*	
 rs   c                       e Zd ZdZy)r  N)r   r   r   r  r   rs   rq   r  r  _  s    Ers   r  c                 <   ddd}|j                  |        |} t               }| d   rat        j                         t        j                  j
                  k(  r t        j                  j                  d       nddl	m
}  |       |_        | d   rt        | d          y	y	)
z/

    :type setup_options: dict[str, bool]
    Fr  )save-signatures
qt-supportr*  zACollecting run-time type information is not supported for Jython
r   )SignatureFactoryr+  N)updater@   r*   get_vm_typePydevdVmTypeJYTHONrn   r~  r  _pydevd_bundle.pydevd_signaturer,  r  r  )setup_optionsdefault_optionsr  r,  s       rq   apply_debugger_optionsr4  d  s    
 +0rBO=)#M "H&'%%'>+F+F+M+MMJJab I)9);H&\"-56 #rs   c                 T    ddl m} t        j                  } || |      t        _        y )Nr   )DebugConsoleStdIn)_pydev_bundle.pydev_stdinr6  rn   stdin)r  r6  
orig_stdins      rq   r  r  z  s    ;J!(J7CIrs   c                  0   t               } | sy | j                          t        j                         \  }}}|rE|j                  j
                  j                  }| j                  |      rd|vrn|j                  }|rE|rd}|j                  }|r|j                  |j                  u rd }|r|j                  j
                  j                  }t        t        j                  j                  |            sd|v rnD|dz  }|j                  r/|j                  j                  |j                  ur|j                  }nn|r	 |j                  |      }d |_        t#        j$                  t'        |      |||       t)                y # t        $ r
 ||_        Y Fw xY w)N_pydevdrf   )limit)rA   rA  rn   r   r0  r  rZ  rf  r1  r[  r  r{  basenamewith_tracebackr:  __traceback__	__cause__r   print_exceptiontyper0   )r  rK  rV  r<  re  r<  r1  s          rq   handle_keyboard_interruptrC    sa   "$H<<>LAub
;;%%11$$X.9H3LZZ	 
 
** w''2;;6G''..::HRWW--h78I<QQJE7??#;#;7CSCS#S!// 	%((,E !!$u+ubF  	%"$E	%s   =F FF)DebuggerEventHandler)pydevd_extension_utils)debugger_versionc                     	 ddl m}   | t        j                        }|t        _        d   r:	 dt        j                         z  }t        j                  j                  d|z         t        j                          t        j                   d|d	   z         t        j                   d
t#        t        j                        z         t%        j&                  |j)                  dd              t*        rt-        |       |j)                  dt.        j0                        t.        _        |j)                  dt.        j2                        t.        _        |j)                  dt.        j4                        t.        _        |d   }|d   }|d	   }d}t7               }	 ddlm} |d   r|j=                          nP|d   rt        j                   d       t?               }		 |	jA                  ||       |	jB                  `|	jB                  }t        j                   d|z         t        jD                  dt        j                         z         	 |j=                          nt        jF                  d       |	jI                          n	 |jK                          |jM                  d      dk7  r`t        jN                  jQ                  |      jS                  d      r1t        jN                  jU                  |      }
t        jN                  jW                  |
d      }t        jN                  jY                  |      r	 t[        |d      }	 |j]                         j_                         D ]  }|ja                         }|jS                  d      s%|dd  ja                         }|jc                  d d      }|je                  d!      }tg        |d         dkD  rd"}n$tg        |d         dk(  rtg        |d         d#k\  rd"} n |jI                          	 	 dd$l4m5} |jm                          |d%   }tq        |       |rt        j                  j                  d&       t        jN                  jU                  tr              }t        jN                  jW                  |d'      }t        j                  ju                  dd(|z          dd l;}tr        |d)<   t        j                  ju                  d*d+|jy                  |      z         t        j                  ju                  d,d-       t        j                  ju                  d.d/       |j{                  |d	   d d |d0       y |d1   rt}               |_?        |d2   rt        rt               |_B        t        |       	 |jA                  ||       d"aE	 |j{                  |d	   d d |      }|d6   r|j                  |       y y # t        $ r# t        j                          t        d       Y w xY w#  d}Y xY w#  t        jF                  d       t        j                          Y xY w# |	jI                          w xY w#  t        jF                  d       t        j                          Y xY w# |jI                          w xY w#  t        j                          Y xY w#  Y xY w#  	 t        jn                          n#  Y nxY wY xY w#  t        j                  j                  d3|d4|d5       t        j                          t        j                  d       Y xY w# t        $ r}t                 d }~ww xY w)7Nr   )process_command_linerf   zprint-in-debugger-startupz
 (pid: %s)r  zpydev debugger: starting%s
zExecuting file %sr  zarguments: %svm_typer  r  r  r  r  Fr  r  r  zStarted in multiproc mode
zReceived port %d
z)pydev debugger: process %d is connecting
z!Error patching process functions
z8pydev debugger: couldn't get port for new debug process
zdev_appserver.pyr   VERSIONrzrelease:   "rh   Trl   )pydevd_stacklessr  z6pydev debugger: google app engine integration enabled
z!pydev_app_engine_debug_startup.pyz--python_startup_script=rt  r   z--python_startup_args=%srk   z--automatic_restart=norg   z--max_module_instances=1)r  zsave-threadingzsave-asynciozCould not connect to z: r  zcmd-line)I+_pydevd_bundle.pydevd_command_line_handlingrH  rn   r  r  r  rG  r   r   r  r  getpidr~  r  r!   r#   r   r  r*   r  r   r   r  r   r  r  r  r   r  r  r  r	  r  r  r  r  r  (patch_new_process_functions_with_warningfindr{  r=  r  r  r   r  openread
splitlinesstripr  r  r  r  rN  patch_stacklessrz  r  r  r|  jsondumpsr  rZ   r#  r   r[   r$  r4  r  r  rR  rC  r  )rH  r  pidr  r  ffix_app_engine_debugr  r  r  appserver_dirversion_filer  r  versionrN  r  curr_dirapp_engine_startup_filerX  r  rL  s                         rq   mainrb    s   T$SXX.!
 ()	,C 	

7#=>OO'%-78OOOS]23 eii	489%05		:UWf  XA  XA  1BO-.3ii8QSbSzSz.{O+(-		2EGhGh(iO%=D?DfA vH=2.  446;OO9:#J#""4.??.%??DOO$8$$>?NN#OQSQZQZQ\#\].$@@B
 OO$_`  "&EEG vv()R/77##A&112DE$&GGOOA$6M#%77<<y#ILww~~l32%),%<F/,2KKM,D,D,F !.D+/::<D'+z'B/3ABx~~/?26,,sB2G29--2D+.wqz?Q+>CG,@-0_-A/271:!/CGK0D(-!. !' 	4((* hI

RS77??8,"$'',,x9\"]58OOP"h5

58IIK3456 	U6]D$	UK!"'6'8H$ !,9O)u%	T4( 		ll5=$iHG
 &&w/ A  a	C\.!(LM!++-   "& DE##%4 !'2%//1wX	MMO	<	JJdKL!HHQK ! 	%'	s   'W W5 Z' A,X0 W? X0 ;Y .Z ;AY6 >A1Y6 /Z Z/ [ \+ (W21W25W<?+X-*X0 0Y+Y36ZZ Z$'Z,/[2[[[	[A\(+	]4\??]__main__r   )r   )	NFFi.  TFFFN)r   rn   
contextlibr   r   -_pydevd_bundle.pydevd_collect_try_except_infor   ro   RuntimeErrorr   r   r  r   	functoolsr   collectionsr	   r#  r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r  r!   r"   r#   (_pydev_bundle._pydev_filesystem_encodingr$   #_pydev_bundle.pydev_is_thread_aliver%    _pydev_imps._pydev_saved_modulesr&   r'   r(   r  r)   r*   r   r+   r,   _pydev_bundle.pydev_overrider-   !_pydevd_bundle.pydevd_breakpointsr.   r/   r0   _pydevd_bundle.pydevd_commr1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   #_pydevd_bundle.pydevd_custom_framesrL   rM   !_pydevd_bundle.pydevd_frame_utilsrN   rO   -_pydevd_bundle.pydevd_kill_all_pydevd_threadsrP   $_pydevd_bundle.pydevd_trace_dispatchrQ   r  rR   rS   rT   r%  rU   rV   rW   ,_pydevd_bundle.pydevd_additional_thread_inforX   _pydevd_bundle.pydevd_utilsrY   5pydevd_concurrency_analyser.pydevd_concurrency_loggerrZ   r[   r\   r]   2pydevd_concurrency_analyser.pydevd_thread_wrappersr^   r_   pydevd_file_utilsr`   ra   rb   pydev_ipython&_pydevd_bundle.pydevd_dont_trace_filesrc   rd   re   r   r[  __version_info____version_info_str__vr  r  r   __version__rr   r`  rt   "_pydevd_bundle.pydevd_plugin_utils	enumeraterO  r  r  __excepthook__rQ  r  r  r  r  remoter&  file_system_encodingrx   r   objectr   r   r   r   r  r  r  r  r  r  r  rp  r   r  r  r  r	  r  r  r  r'  r  r4  r  rC  #_pydevd_bundle.pydevd_extension_apirD  rE  extensions_of_typehandleron_debugger_modules_loadedrb  r   r   rs   rq   <module>r     sD  
  %  MBQ& 
  e  f  f   	   #M M M M M M M & 2 J ? 6 1 3 4  ' & 2 n n\ \ \ \ \ \ \ \ d a Pk kD D S 8 x x Y B B  = g  	 (AA'( hh+,
3   $$@ (( "00 (( 	NN7
 	  		,. /( /D&!( &!R*& *4[= [=|)K H{06 {0z##.
&1.F 1.h\\ 
	#2"l '&&&(m3`2 $%\ %()
H 
7,8&T E 18%889MN EG&&&DE
h0T zF g?	s   7L L!