Skip to content

Commit

Permalink
Show bytecode when source code cannot be fetched.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Mar 29, 2020
1 parent eb76fbb commit 8fc238e
Show file tree
Hide file tree
Showing 22 changed files with 1,815 additions and 427 deletions.
2 changes: 0 additions & 2 deletions src/debugpy/_vendored/pydevd/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ matrix:
- PYDEVD_PYTHON_VERSION=3.8
- PYDEVD_USE_CYTHON=NO
- PYDEVD_TEST_VM=CPYTHON
- CHECK_CYTHON_GENERATED=YES
- PYDEVD_USE_CONDA=NO

# i.e.: https://www.python.org/download/pre-releases/
Expand All @@ -94,7 +93,6 @@ matrix:
- PYDEVD_PYTHON_VERSION=3.6
- PYDEVD_USE_CYTHON=YES
- PYDEVD_TEST_VM=CPYTHON
- CHECK_CYTHON_GENERATED=YES

before_install:
# CPython / Pypy setup
Expand Down
35 changes: 34 additions & 1 deletion src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import os
import subprocess
import ctypes
from _pydevd_bundle.pydevd_collect_bytecode_info import code_to_bytecode_representation
import itertools
import linecache

try:
import dis
Expand Down Expand Up @@ -631,6 +634,36 @@ def request_load_source(self, py_db, seq, filename):

py_db.writer.add_command(cmd)

def get_decompiled_source_from_frame_id(self, py_db, frame_id):
'''
:param py_db:
:param frame_id:
:throws Exception:
If unable to get the frame in the currently paused frames or if some error happened
when decompiling.
'''
variable = py_db.suspended_frames_manager.get_variable(int(frame_id))
frame = variable.value

# Check if it's in the linecache first.
lines = (linecache.getline(frame.f_code.co_filename, i) for i in itertools.count(1))
lines = itertools.takewhile(bool, lines) # empty lines are '\n', EOF is ''

source = ''.join(lines)
if not source:
source = code_to_bytecode_representation(frame.f_code)

return source

def request_load_source_from_frame_id(self, py_db, seq, frame_id):
try:
source = self.get_decompiled_source_from_frame_id(py_db, frame_id)
cmd = py_db.cmd_factory.make_load_source_from_frame_id_message(seq, source)
except:
cmd = py_db.cmd_factory.make_error_message(seq, get_exception_traceback_str())

py_db.writer.add_command(cmd)

def add_python_exception_breakpoint(
self,
py_db,
Expand Down Expand Up @@ -983,5 +1016,5 @@ class PROCESSENTRY32(ctypes.Structure):
break
finally:
kernel32.CloseHandle(snapshot)

return ppid_and_pids
Loading

0 comments on commit 8fc238e

Please sign in to comment.