python3-trepan icon indicating copy to clipboard operation
python3-trepan copied to clipboard

No support for PYTHONBREAKPOINT

Open jadkik opened this issue 5 years ago • 2 comments

I was trying to use this debugger and expected some kind of compatibility with the pdb family of debuggers and the PYTHONBREAKPOINT and breakpoint() built-in that was introduced in Python 3.7+ with PEP 553.

I ended up writing a small separate module that basically provides a set_trace kind of method that is configurable with some command line variables:

import sys
import os


def set_trace():
    from trepan.interfaces import server as Mserver
    from trepan.api import debug
    interface = os.getenv('TREPAN3K_INTERFACE', 'USER')
    if interface == 'USER':
        dbg_opts = {}
    else:
        connection_opts = {'IO': 'TCP', 'PORT': os.getenv('TREPAN3K_TCP_PORT', 5555)}
        intf = Mserver.ServerInterface(connection_opts=connection_opts)
        dbg_opts = {'interface': intf}
        print(f'Starting {connection_opts["IO"]} server listening on {connection_opts["PORT"]}.', file=sys.stderr)
        print(f'Use `python3 -m trepan.client --port {connection_opts["PORT"]}` to enter debugger.', file=sys.stderr)
    debug(dbg_opts=dbg_opts, step_ignore=0, level=1)

Usage would be something like that (if that function is put in trepan.api):

export PYTHONBREAKPOINT=trepan.api.set_trace
export TREPAN3K_INTERFACE=TCP
export TREPAN3K_TCP_PORT=1095
python3 run_some_script_that_calls_breakpoint_builtin.py
python3 -m trepan.client --port 1095

Is that something that would make sense to be in the core of this project or would you prefer it to be a standalone thing? As is, you can already use it with PYTHONBREAKPOINT=trepan.api.debug, so this would only make it easier to configure the parameters of the debug function using env vars.

jadkik avatar Feb 20 '20 11:02 jadkik

If you are up to a PR, this can go into trepan3k.

More generally I'd like to see a total rewrite exclusively for trepan3k for 3.7+. I started writing this over 7 years ago.

There are parts of it that are still a bit unique, however the code hasn't been tracking changes to Python.

rocky avatar Feb 20 '20 11:02 rocky

I have PYTHONBREAKPOINT=trepan.api.debug and it seems to work OK. Is this still subtly broken (perhaps contributing to the issues I've documented)?

jaccarmac avatar Aug 18 '22 15:08 jaccarmac