Skip to content

Commit bb2178c

Browse files
author
Aman Agarwal
committed
Synced Launch and Attach Codepaths
1 parent 22def4d commit bb2178c

8 files changed

Lines changed: 56 additions & 34 deletions

pythonFiles/PythonTools/ptvsd/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@
5454
DONT_DEBUG.append(os.path.normcase(__file__))
5555

5656
sys.argv = script_argv
57-
exec_file(script_argv[0], {'__name__': '__main__'})
57+
exec_file(script_argv[0], {'__name__': '__main__'})

pythonFiles/PythonTools/ptvsd/visualstudio_py_debugger.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,8 @@ def report_execution_error(exc_text, execution_id):
21942194

21952195
def report_execution_exception(execution_id, exc_info):
21962196
try:
2197-
exc_text = str(exc_info[1])
2197+
exc_type, exc_value, traceback = exc_info
2198+
exc_text = '{}: {}'.format(get_exception_name(exc_type), exc_value)
21982199
except:
21992200
exc_text = 'An exception was thrown'
22002201

@@ -2605,9 +2606,14 @@ def parse_debug_options(s):
26052606
# Accept current Process id to pass back to debugger
26062607
def debug(file, port_num, debug_id, debug_options, currentPid, run_as = 'script'):
26072608
# remove us from modules so there's no trace of us
2608-
sys.modules['$visualstudio_py_debugger'] = sys.modules['visualstudio_py_debugger']
2609-
__name__ = '$visualstudio_py_debugger'
2610-
del sys.modules['visualstudio_py_debugger']
2609+
if sys.modules.has_key('visualstudio_py_debugger'):
2610+
sys.modules['$visualstudio_py_debugger'] = sys.modules['visualstudio_py_debugger']
2611+
__name__ = '$visualstudio_py_debugger'
2612+
del sys.modules['visualstudio_py_debugger']
2613+
elif sys.modules.has_key('ptvsd.visualstudio_py_debugger'):
2614+
sys.modules['$ptvsd.visualstudio_py_debugger'] = sys.modules['ptvsd.visualstudio_py_debugger']
2615+
__name__ = '$ptvsd.visualstudio_py_debugger'
2616+
del sys.modules['ptvsd.visualstudio_py_debugger']
26112617

26122618
wait_on_normal_exit = 'WaitOnNormalExit' in debug_options
26132619

@@ -2631,6 +2637,8 @@ def debug(file, port_num, debug_id, debug_options, currentPid, run_as = 'script'
26312637
elif run_as == 'code':
26322638
exec_code(file, '<string>', globals_obj)
26332639
else:
2640+
# fix sys.path to be the script file dir
2641+
sys.path[0] = ''
26342642
exec_file(file, globals_obj)
26352643
finally:
26362644
sys.settrace(None)

pythonFiles/PythonTools/visualstudio_ipython_repl.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
import re
2323
import sys
24-
from visualstudio_py_repl import BasicReplBackend, ReplBackend, UnsupportedReplException, _command_line_to_args_list
25-
from visualstudio_py_util import to_bytes
24+
from ptvsd.visualstudio_py_repl import BasicReplBackend, ReplBackend, UnsupportedReplException, _command_line_to_args_list
25+
from ptvsd.visualstudio_py_util import to_bytes
2626
try:
2727
import thread
2828
except:
@@ -401,7 +401,7 @@ def init_debugger(self):
401401
def __visualstudio_debugger_init():
402402
import sys
403403
sys.path.append(''' + repr(path.dirname(__file__)) + ''')
404-
import visualstudio_py_debugger
404+
import ptvsd.visualstudio_py_debugger as visualstudio_py_debugger
405405
new_thread = visualstudio_py_debugger.new_thread()
406406
sys.settrace(new_thread.trace_func)
407407
visualstudio_py_debugger.intercept_threads(True)
@@ -413,7 +413,7 @@ def __visualstudio_debugger_init():
413413
def attach_process(self, port, debugger_id):
414414
self.run_command('''
415415
def __visualstudio_debugger_attach():
416-
import visualstudio_py_debugger
416+
import ptvsd.visualstudio_py_debugger as visual_studio_py_debugger
417417
418418
def do_detach():
419419
visualstudio_py_debugger.DETACH_CALLBACKS.remove(do_detach)
@@ -427,4 +427,4 @@ def do_detach():
427427

428428
class IPythonBackendWithoutPyLab(IPythonBackend):
429429
def get_extra_arguments(self):
430-
return []
430+
return []

pythonFiles/PythonTools/visualstudio_py_debugger.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747
try:
4848
# In the local attach scenario, visualstudio_py_util is injected into globals()
4949
# by PyDebugAttach before loading this module, and cannot be imported.
50-
_vspu = visualstudio_py_util
50+
_vspu = ptvsd.visualstudio_py_util
5151
except:
5252
try:
53-
import visualstudio_py_util as _vspu
54-
except ImportError:
5553
import ptvsd.visualstudio_py_util as _vspu
54+
except ImportError:
55+
import visualstudio_py_util as _vspu
5656

5757
to_bytes = _vspu.to_bytes
5858
exec_file = _vspu.exec_file
@@ -69,15 +69,17 @@
6969
try:
7070
# In the local attach scenario, visualstudio_py_repl is injected into globals()
7171
# by PyDebugAttach before loading this module, and cannot be imported.
72-
_vspr = visualstudio_py_repl
72+
_vspr = ptvsd.visualstudio_py_repl
7373
except:
7474
try:
75-
import visualstudio_py_repl as _vspr
76-
except ImportError:
7775
import ptvsd.visualstudio_py_repl as _vspr
76+
except ImportError:
77+
import visualstudio_py_repl as _vspr
78+
7879

7980
try:
8081
import stackless
82+
stackless.tasklet # work-around lazy on-demand importers
8183
except ImportError:
8284
stackless = None
8385

@@ -2361,9 +2363,16 @@ def _excepthook(exc_type, exc_value, exc_tb):
23612363
global debugger_thread_id
23622364
debugger_thread_id = _start_new_thread(DebuggerLoop(conn).loop, ())
23632365

2364-
for mod_name, mod_value in sys.modules.items():
2366+
for mod_value in list(sys.modules.values()):
23652367
try:
2366-
filename = getattr(mod_value, '__file__', None)
2368+
lazyModule = False
2369+
try:
2370+
lazyModule = mod_value.__class__.__name__ == 'LazyImporter'
2371+
except:
2372+
lazyModule = False
2373+
filename = None
2374+
if not lazyModule:
2375+
filename = getattr(mod_value, '__file__', None)
23672376
if filename is not None:
23682377
try:
23692378
fullpath = path.abspath(filename)
@@ -2372,7 +2381,7 @@ def _excepthook(exc_type, exc_value, exc_tb):
23722381
else:
23732382
MODULES.append((filename, Module(fullpath)))
23742383
except:
2375-
traceback.print_exc()
2384+
traceback.print_exc()
23762385

23772386
if report:
23782387
THREADS_LOCK.acquire()
@@ -2597,9 +2606,14 @@ def parse_debug_options(s):
25972606
# Accept current Process id to pass back to debugger
25982607
def debug(file, port_num, debug_id, debug_options, currentPid, run_as = 'script'):
25992608
# remove us from modules so there's no trace of us
2600-
sys.modules['$visualstudio_py_debugger'] = sys.modules['visualstudio_py_debugger']
2601-
__name__ = '$visualstudio_py_debugger'
2602-
del sys.modules['visualstudio_py_debugger']
2609+
if sys.modules.has_key('visualstudio_py_debugger'):
2610+
sys.modules['$visualstudio_py_debugger'] = sys.modules['visualstudio_py_debugger']
2611+
__name__ = '$visualstudio_py_debugger'
2612+
del sys.modules['visualstudio_py_debugger']
2613+
elif sys.modules.has_key('ptvsd.visualstudio_py_debugger'):
2614+
sys.modules['$ptvsd.visualstudio_py_debugger'] = sys.modules['ptvsd.visualstudio_py_debugger']
2615+
__name__ = '$ptvsd.visualstudio_py_debugger'
2616+
del sys.modules['ptvsd.visualstudio_py_debugger']
26032617

26042618
wait_on_normal_exit = 'WaitOnNormalExit' in debug_options
26052619

@@ -2753,4 +2767,4 @@ def _get_template_line(frame):
27532767
return _offset_to_line_number(_read_file(file_name), source[1][0])
27542768
except:
27552769
return None
2756-
## End modification by Don Jayamanne
2770+
## End modification by Don Jayamanne

pythonFiles/PythonTools/visualstudio_py_launcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def launch():
2929
import sys
3030
import traceback
3131
try:
32-
import visualstudio_py_debugger as vspd
32+
import ptvsd.visualstudio_py_debugger as vspd
3333
except:
3434
traceback.print_exc()
3535
print('''

pythonFiles/PythonTools/visualstudio_py_launcher_nodebug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import time
1010
import socket
1111
try:
12-
import visualstudio_py_util as _vspu
12+
import ptvsd.visualstudio_py_util as _vspu
1313
except:
1414
traceback.print_exc()
1515
print("""Internal error detected. Please copy the above traceback and report at

pythonFiles/PythonTools/visualstudio_py_repl.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@
4949
try:
5050
# In the local attach scenario, visualstudio_py_util is injected into globals()
5151
# by PyDebugAttach before loading this module, and cannot be imported.
52-
_vspu = visualstudio_py_util
52+
_vspu = ptvsd.visualstudio_py_util
5353
except:
5454
try:
55-
import visualstudio_py_util as _vspu
56-
except ImportError:
5755
import ptvsd.visualstudio_py_util as _vspu
56+
except ImportError:
57+
import visualstudio_py_util as _vspu
5858
to_bytes = _vspu.to_bytes
5959
read_bytes = _vspu.read_bytes
6060
read_int = _vspu.read_int
@@ -350,7 +350,7 @@ def _cmd_excx(self):
350350
self.execute_file_ex(filetype, filename, args)
351351

352352
def _cmd_debug_attach(self):
353-
import visualstudio_py_debugger
353+
import ptvsd.visualstudio_py_debugger as visualstudio_py_debugger
354354
port = read_int(self.conn)
355355
id = read_string(self.conn)
356356
debug_options = visualstudio_py_debugger.parse_debug_options(read_string(self.conn))
@@ -384,7 +384,7 @@ def on_debugger_detach(self):
384384
def init_debugger(self):
385385
from os import path
386386
sys.path.append(path.dirname(__file__))
387-
import visualstudio_py_debugger
387+
import ptvsd.visualstudio_py_debugger as visualstudio_py_debugger
388388
visualstudio_py_debugger.DONT_DEBUG.append(path.normcase(__file__))
389389
new_thread = visualstudio_py_debugger.new_thread()
390390
sys.settrace(new_thread.trace_func)
@@ -1005,13 +1005,13 @@ def flush(self):
10051005
sys.stdout.flush()
10061006

10071007
def do_detach(self):
1008-
import visualstudio_py_debugger
1008+
import ptvsd.visualstudio_py_debugger as visualstudio_py_debugger
10091009
visualstudio_py_debugger.DETACH_CALLBACKS.remove(self.do_detach)
10101010
self.on_debugger_detach()
10111011

10121012
def attach_process(self, port, debugger_id, debug_options):
10131013
def execute_attach_process_work_item():
1014-
import visualstudio_py_debugger
1014+
import ptvsd.visualstudio_py_debugger as visualstudio_py_debugger
10151015
visualstudio_py_debugger.DETACH_CALLBACKS.append(self.do_detach)
10161016
visualstudio_py_debugger.attach_process(port, debugger_id, debug_options, report=True, block=True)
10171017

@@ -1388,4 +1388,4 @@ def _run_repl():
13881388
_debug_write(traceback.format_exc())
13891389
_debug_write('exiting')
13901390
input()
1391-
raise
1391+
raise

pythonFiles/completionServer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# http://pydoc.net/Python/magni/1.4.0/magni.tests.ipynb_examples/
2929
# http://www.xavierdupre.fr/app/pyquickhelper/helpsphinx/_modules/pyquickhelper/ipythonhelper/notebook_runner.html
3030

31-
import visualstudio_py_util as _vspu
31+
import ptvsd.visualstudio_py_util as _vspu
3232

3333
to_bytes = _vspu.to_bytes
3434
read_bytes = _vspu.read_bytes

0 commit comments

Comments
 (0)