Skip to content

Commit 8fc238e

Browse files
committed
Show bytecode when source code cannot be fetched.
Fixes microsoft/ptvsd#1304
1 parent eb76fbb commit 8fc238e

22 files changed

+1815
-427
lines changed

src/debugpy/_vendored/pydevd/.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ matrix:
7777
- PYDEVD_PYTHON_VERSION=3.8
7878
- PYDEVD_USE_CYTHON=NO
7979
- PYDEVD_TEST_VM=CPYTHON
80-
- CHECK_CYTHON_GENERATED=YES
8180
- PYDEVD_USE_CONDA=NO
8281

8382
# i.e.: https://www.python.org/download/pre-releases/
@@ -94,7 +93,6 @@ matrix:
9493
- PYDEVD_PYTHON_VERSION=3.6
9594
- PYDEVD_USE_CYTHON=YES
9695
- PYDEVD_TEST_VM=CPYTHON
97-
- CHECK_CYTHON_GENERATED=YES
9896

9997
before_install:
10098
# CPython / Pypy setup

src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_api.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import os
2626
import subprocess
2727
import ctypes
28+
from _pydevd_bundle.pydevd_collect_bytecode_info import code_to_bytecode_representation
29+
import itertools
30+
import linecache
2831

2932
try:
3033
import dis
@@ -631,6 +634,36 @@ def request_load_source(self, py_db, seq, filename):
631634

632635
py_db.writer.add_command(cmd)
633636

637+
def get_decompiled_source_from_frame_id(self, py_db, frame_id):
638+
'''
639+
:param py_db:
640+
:param frame_id:
641+
:throws Exception:
642+
If unable to get the frame in the currently paused frames or if some error happened
643+
when decompiling.
644+
'''
645+
variable = py_db.suspended_frames_manager.get_variable(int(frame_id))
646+
frame = variable.value
647+
648+
# Check if it's in the linecache first.
649+
lines = (linecache.getline(frame.f_code.co_filename, i) for i in itertools.count(1))
650+
lines = itertools.takewhile(bool, lines) # empty lines are '\n', EOF is ''
651+
652+
source = ''.join(lines)
653+
if not source:
654+
source = code_to_bytecode_representation(frame.f_code)
655+
656+
return source
657+
658+
def request_load_source_from_frame_id(self, py_db, seq, frame_id):
659+
try:
660+
source = self.get_decompiled_source_from_frame_id(py_db, frame_id)
661+
cmd = py_db.cmd_factory.make_load_source_from_frame_id_message(seq, source)
662+
except:
663+
cmd = py_db.cmd_factory.make_error_message(seq, get_exception_traceback_str())
664+
665+
py_db.writer.add_command(cmd)
666+
634667
def add_python_exception_breakpoint(
635668
self,
636669
py_db,
@@ -983,5 +1016,5 @@ class PROCESSENTRY32(ctypes.Structure):
9831016
break
9841017
finally:
9851018
kernel32.CloseHandle(snapshot)
986-
1019+
9871020
return ppid_and_pids

0 commit comments

Comments
 (0)