def debug(file, port_num, debug_id, debug_options, run_as = 'script'):
# remove us from modules so there's no trace of us
sys.modules['$visualstudio_py_debugger'] = sys.modules['visualstudio_py_debugger']
__name__ = '$visualstudio_py_debugger'
del sys.modules['visualstudio_py_debugger']
wait_on_normal_exit = 'WaitOnNormalExit' in debug_options
attach_process(port_num, debug_id, debug_options, report = True)
# setup the current thread
cur_thread = new_thread()
cur_thread.stepping = STEPPING_LAUNCH_BREAK
# start tracing on this thread
sys.settrace(cur_thread.trace_func)
# now execute main file
globals_obj = {'__name__': '__main__'}
try:
if run_as == 'module':
exec_module(file, globals_obj)
elif run_as == 'code':
exec_code(file, '<string>', globals_obj)
else:
exec_file(file, globals_obj)
finally:
sys.settrace(None)
THREADS_LOCK.acquire()
del THREADS[cur_thread.id]
THREADS_LOCK.release()
report_thread_exit(cur_thread)
# Give VS debugger a chance to process commands
# by waiting for ack of "last" command
global _threading
if _threading is None:
import threading
_threading = threading
global last_ack_event
last_ack_event = _threading.Event()
with _SendLockCtx:
write_bytes(conn, LAST)
last_ack_event.wait(5)
if wait_on_normal_exit:
do_wait()
# Code objects for functions which are going to be at the bottom of the stack, right below the first
# stack frame for user code. When we walk the stack to determine whether to report or block on a given
# frame, hitting any of these means that we walked all the frames that we needed to look at.
评论列表
文章目录