Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Oct 7, 2023
1 parent 6182f48 commit 6cd3a51
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 67 deletions.
8 changes: 4 additions & 4 deletions _pydevd_bundle/pydevd_collect_bytecode_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def iter_instructions(co):


def collect_return_info(co, use_func_first_line=False):
if not hasattr(co, 'co_lnotab'):
if not hasattr(co, 'co_lines') and not hasattr(co, 'co_lnotab'):
return []

if use_func_first_line:
Expand All @@ -165,7 +165,7 @@ def collect_return_info(co, use_func_first_line=False):
op_offset_to_line = dict(dis.findlinestarts(co))
for instruction in iter_instructions(co):
curr_op_name = instruction.opname
if curr_op_name in ('RETURN_VALUE', 'RETURN_CONST'):
if curr_op_name == 'RETURN_VALUE':
lst.append(ReturnInfo(_get_line(op_offset_to_line, instruction.offset, firstlineno, search=True)))

return lst
Expand Down Expand Up @@ -256,7 +256,7 @@ def _get_except_target_info(instructions, exception_end_instruction_index, offse

def collect_try_except_info(co, use_func_first_line=False):
# We no longer have 'END_FINALLY', so, we need to do things differently in Python 3.9
if not hasattr(co, 'co_lnotab'):
if not hasattr(co, 'co_lines') and not hasattr(co, 'co_lnotab'):
return []

if use_func_first_line:
Expand Down Expand Up @@ -376,7 +376,7 @@ def _get_except_target_info(instructions, exception_end_instruction_index, offse

def collect_try_except_info(co, use_func_first_line=False):
# We no longer have 'END_FINALLY', so, we need to do things differently in Python 3.9
if not hasattr(co, 'co_lnotab'):
if not hasattr(co, 'co_lines') and not hasattr(co, 'co_lnotab'):
return []

if use_func_first_line:
Expand Down
2 changes: 1 addition & 1 deletion _pydevd_bundle/pydevd_net_command_factory_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def make_get_thread_stack_message(self, py_db, seq, thread_id, topmost_frame, fm
source_reference = pydevd_file_utils.get_client_filename_source_reference(filename_in_utf8)

if not source_reference and not applied_mapping and not os.path.exists(original_filename):
if getattr(frame.f_code, 'co_lnotab', None):
if getattr(frame.f_code, 'co_lines', None) or getattr(frame.f_code, 'co_lnotab', None):
# Create a source-reference to be used where we provide the source by decompiling the code.
# Note: When the time comes to retrieve the source reference in this case, we'll
# check the linecache first (see: get_decompiled_source_from_frame_id).
Expand Down
19 changes: 6 additions & 13 deletions _pydevd_bundle/pydevd_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import ctypes
from importlib import import_module
from importlib.util import module_from_spec, spec_from_file_location
from urllib.parse import quote # @UnresolvedImport
import time
import inspect
Expand All @@ -23,20 +24,12 @@ def save_main_module(file, module_name):
# This will prevent the pydevd script from contaminating the namespace for the script to be debugged
# pretend pydevd is not the main module, and
# convince the file to be debugged that it was loaded as main
sys.modules[module_name] = sys.modules['__main__']
sys.modules[module_name].__name__ = module_name

with warnings.catch_warnings():
warnings.simplefilter("ignore", category=DeprecationWarning)
warnings.simplefilter("ignore", category=PendingDeprecationWarning)
from imp import new_module

m = new_module('__main__')
m = sys.modules[module_name] = sys.modules['__main__']
m.__name__ = module_name
loader = m.__loader__ if hasattr(m, '__loader__') else None
spec = spec_from_file_location('__main__', file, loader=loader)
m = module_from_spec(spec)
sys.modules['__main__'] = m
if hasattr(sys.modules[module_name], '__loader__'):
m.__loader__ = getattr(sys.modules[module_name], '__loader__')
m.__file__ = file

return m


Expand Down
8 changes: 7 additions & 1 deletion pydevd_attach_to_process/add_code_to_python_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,13 @@ def get_target_filename(is_target_process_64=None, prefix=None, extension=None):

def run_python_code_windows(pid, python_code, connect_debugger_tracing=False, show_debug_info=0):
assert '\'' not in python_code, 'Having a single quote messes with our command.'
from winappdbg.process import Process

# Suppress winappdbg warning about sql package missing.
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=ImportWarning)
from winappdbg.process import Process

if not isinstance(python_code, bytes):
python_code = python_code.encode('utf-8')

Expand Down
16 changes: 9 additions & 7 deletions pydevd_attach_to_process/linux_and_mac/compile_linux.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
g++ -m64 -shared -o attach_linux_amd64.so -fPIC -nostartfiles attach.cpp
mv attach_linux_amd64.so ../attach_linux_amd64.so
echo Compiled amd64
set -e

echo Note: may need "sudo apt-get install libx32gcc-4.8-dev" and "sudo apt-get install libc6-dev-i386" and "sudo apt-get install g++-multilib" to compile 32 bits
ARCH="$(uname -m)"
case $ARCH in
i*86) SUFFIX=x86;;
x86_64*) SUFFIX=amd64;;
*) echo >&2 "unsupported: $ARCH"; exit 1;;
esac

g++ -m32 -shared -o attach_linux_x86.so -fPIC -nostartfiles attach.cpp
mv attach_linux_x86.so ../attach_linux_x86.so
echo Compiled x86
SRC="$(dirname "$0")/.."
g++ -std=c++11 -shared -fPIC -nostartfiles $SRC/linux_and_mac/attach.cpp -o $SRC/attach_linux_$SUFFIX.so
9 changes: 4 additions & 5 deletions pydevd_attach_to_process/linux_and_mac/compile_mac.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
g++ -fPIC -D_REENTRANT -std=c++11 -arch x86_64 -c -o attach_x86_64.o attach.cpp
g++ -dynamiclib -nostartfiles -arch x86_64 -o attach_x86_64.dylib attach_x86_64.o -lc
rm attach_x86_64.o
mv attach_x86_64.dylib ../attach_x86_64.dylib

set -e
SRC="$(dirname "$0")/.."
g++ -fPIC -D_REENTRANT -std=c++11 -arch x86_64 -c $SRC/linux_and_mac/attach.cpp -o $SRC/attach_x86_64.o
g++ -dynamiclib -nostartfiles -arch x86_64 -lc $SRC/attach_x86_64.o -o $SRC/attach_x86_64.dylib
3 changes: 3 additions & 0 deletions pydevd_attach_to_process/windows/compile_windows.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
setlocal
@cd /d %~dp0

@set VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
@echo Using vswhere at %VSWHERE%
@for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set VSDIR=%%i
Expand Down
8 changes: 0 additions & 8 deletions pydevd_plugins/__init__.py

This file was deleted.

7 changes: 0 additions & 7 deletions pydevd_plugins/extensions/__init__.py

This file was deleted.

7 changes: 0 additions & 7 deletions pydevd_plugins/extensions/types/__init__.py

This file was deleted.

7 changes: 0 additions & 7 deletions tests_python/my_extensions/pydevd_plugins/__init__.py

This file was deleted.

This file was deleted.

0 comments on commit 6cd3a51

Please sign in to comment.