Giter Club home page Giter Club logo

madbg's Introduction

madbg

Tests (GitHub Actions) PyPI Supported Python Versions PyPI version GitHub license

A fully-featured remote debugger for python.

  • Provides a full remote tty, allowing sending keyboard signals to the debugger, tab completion, command history, line editing and more
  • Runs the IPython debugger with all its capabilities
  • Allows attaching to running programs preemptively (does not require gdb, unlike similar tools)
  • Affects the debugged program minimally, although not yet recommended for use in production environments
  • Provides TTY features even when debugged program is a deamon, or run outside a terminal

Installation

pip install madbg

Usage

Madbg provide both a python API and a CLI.

Attaching to a running process

madbg attach <pid>

Or

import madbg
madbg.attach_to_process(pid)

Warning

  • Attaching on linux could potentially deadlock the target process. Not recommneded for use in production environments yet.
  • madbg has to be installed in the target process' interpreter for attach to work.

Starting a debugger

Using the CLI

Run a python file with automatic post-mortem:

madbg run path_to_your_script.py <args_for_script ...>

Run a python module similarly to python -m:

madbg run -m module.name <args_for_script ...>

Start a script, starting the debugger from the first line:

madbg run --use-set-trace script.py <args_for_script ...>

Using the API

Start a debugger in the next line:

madbg.set_trace()

Continue running the program until a client connects, then stop it and start a debugger:

madbg.set_trace_on_connect()

After an exception has occurred, or in an exception context, start a debugger in the frame the exception was raised from:

madbg.post_mortem()

Connecting to a debugger

Using the CLI

madbg connect

Using the API

madbg.connect_to_debugger()

Connection

All madbg API functions and CLI entry points allow using a custom IP and port (the default is 127.0.0.1:3513), for example:

madbg.set_trace(ip='0.0.0.0', port=1337)

or

madbg connect 8.8.8.8 1337

Platforms

Madbg supports linux with python>=3.7.

Possible effects

What madbg does that might affect a debugged program:

  • Changes the pgid and sid of the debugged process
  • Changes the CTTY of the debugged process
  • Affects child processes in unknown ways (Not tested yet)

What madbg doesn't do:

  • Writes or reads from stdio
  • Feeds your cat

madbg's People

Contributors

kmaork avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

madbg's Issues

Python 3.6 support

How to reproduce:

git clone https://github.com/kmaork/madbg.git
cd madbg/
python setup.py install
# python
Python 3.6.8 (default, Mar 19 2021, 05:13:41)
[GCC 8.4.1 20200928 (Red Hat 8.4.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import madbg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/maestro/env/lib64/python3.6/site-packages/madbg-1.1.4-py3.6.egg/madbg/__init__.py", line 1, in <module>
  File "/opt/maestro/env/lib64/python3.6/site-packages/madbg-1.1.4-py3.6.egg/madbg/api.py", line 7, in <module>
ImportError: cannot import name 'nullcontext'

PermissionError: [Errno 1] Operation not permitted

When connecting with madbg client, the script dies and return with this error.

Stack trace:

  File ".../site-packages/madbg/api.py", line 57, in sigio_handler
    debugger, debugger_exit_stack = use_context(RemoteIPythonDebugger.start_from_new_connection(sock))
  File ".../site-packages/madbg/utils.py", line 34, in use_context
    context_value = exit_stack.enter_context(context_manager)
  File "/usr/lib/python3.8/contextlib.py", line 425, in enter_context
    result = _cm_type.__enter__(cm)
  File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File ".../site-packages/madbg/debugger.py", line 170, in start_from_new_connection
    with cls.start(sock.fileno()) as debugger:
  File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File ".../site-packages/madbg/debugger.py", line 133, in start
    pty.make_ctty()
  File ".../site-packages/madbg/tty_utils.py", line 120, in make_ctty
    detach_current_ctty()
  File ".../site-packages/madbg/tty_utils.py", line 85, in detach_current_ctty
    make_session_leader()
  File ".../site-packages/madbg/tty_utils.py", line 33, in make_session_leader
    os.setsid()
PermissionError: [Errno 1] Operation not permitted

I wrote a simple test:

import os

if __name__ == '__main__':
    try:
        os.setsid()
    except OSError as e:
        print(f"os.setsid failed: {e}")
        print(f"pid={os.getpid()}  pgid={os.getpgid(0)}")

Result:

os.setsid failed: [Errno 1] Operation not permitted
pid=132918  pgid=132918

Why does this happen and how do I resolve this?

ModuleNotFoundError: No module named 'fcntl'

PS F:\Workspace\play-with-***\injector> madbg attach 20016
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 196, in _run_module_as_main        
    return _run_code(code, main_globals, None,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2800.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\***\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\Scripts\madbg.exe\__main__.py", line 4, in <module>
  File "C:\Users\***\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\madbg\__init__.py", line 1, in <module>
    from .api import set_trace, set_trace_on_connect, post_mortem, run_with_debugging, attach_to_process
  File "C:\Users\***\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\madbg\api.py", line 11, in <module>
    from fcntl import fcntl, F_GETFL, F_SETFL, F_SETOWN
ModuleNotFoundError: No module named 'fcntl'

I'm using Window 11, Python 3.10

MacOS support?

Can madbg currently be used on MacOS? I'm guessing not given that pyinjector only seems to support Linux and Windows and given that madbg raised the following exception when I tried to attach to a process on MacOS 10.15.7 with Python 3.8.8.

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    import madbg
  File "/Users/lgivon/miniconda3/lib/python3.8/site-packages/madbg/__init__.py", line 1, in <module>
    from .api import set_trace, set_trace_on_connect, post_mortem, run_with_debugging, attach_to_process
  File "/Users/lgivon/miniconda3/lib/python3.8/site-packages/madbg/api.py", line 9, in <module>
    from hypno import inject_py
  File "/Users/lgivon/miniconda3/lib/python3.8/site-packages/hypno/__init__.py", line 1, in <module>
    from .hypno import inject_py
  File "/Users/lgivon/miniconda3/lib/python3.8/site-packages/hypno/hypno.py", line 4, in <module>
    from pyinjector import inject
  File "/Users/lgivon/miniconda3/lib/python3.8/site-packages/pyinjector/__init__.py", line 1, in <module>
    from .pyinjector import inject
  File "/Users/lgivon/miniconda3/lib/python3.8/site-packages/pyinjector/pyinjector.py", line 13, in <module>
    libinjector.injector_attach.argtypes = POINTER(injector_pointer_t), pid_t
  File "/Users/lgivon/miniconda3/lib/python3.8/ctypes/__init__.py", line 386, in __getattr__
    func = self.__getitem__(name)
  File "/Users/lgivon/miniconda3/lib/python3.8/ctypes/__init__.py", line 391, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(0x7fa840e11c00, injector_attach): symbol not found

Inifinite traceback when pressing Ctrl-C on debugged process

Exception in thread Thread-80:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.8/dist-packages/IPython/terminal/debugger.py", line 122, in in_thread
    line = self.pt_app.prompt()
  File "/usr/local/lib/python3.8/dist-packages/prompt_toolkit/shortcuts/prompt.py", line 1013, in prompt
    return self.app.run(set_exception_handler=set_exception_handler)
  File "/usr/local/lib/python3.8/dist-packages/prompt_toolkit/application/application.py", line 848, in run
    return loop.run_until_complete(
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/usr/local/lib/python3.8/dist-packages/prompt_toolkit/application/application.py", line 650, in run_async
    assert not self._is_running, "Application is already running."
AssertionError: Application is already running.

OSError: Bad file descriptor in madbg/debugger.py, sometimes, when connecting to running process

Not sure if this is expected or a known issue. Please take the following program, loop.py:

import time

i = 0
while True:
    i = i + 1
    print(i)
    time.sleep(0.001)

Run it: python loop.py and it will start outputting sequential numbers.

In another shell, run madbg (1.3.2):

$ madbg attach $(pgrep -f loop.py)

The shell running loop.py will typically stop with something like:

Waiting for debugger client on 127.0.0.1:3513
Debugger client connected from ('127.0.0.1', 46754)

And the madbg shell will show an ipdb> prompt - so far so good. Hit 'Q' + Enter to quit ipdb and the loop.py count will continue.

Repeat running madbg attach a few times, eventually the following will occur as loop.py terminates:

5380
5381
5382
Traceback (most recent call last):
  File loop.py, line 5, in <module>
    while True:
  File loop.py, line 5, in <module>
    while True:
  File venv/lib/python3.10/site-packages/madbg/debugger.py, line 64, in trace_dispatch
    return super().trace_dispatch(frame, event, arg)
  File /usr/lib/python3.10/bdb.py, line 90, in trace_dispatch
    return self.dispatch_line(frame)
  File /usr/lib/python3.10/bdb.py, line 114, in dispatch_line
    self.user_line(frame)
  File /usr/lib/python3.10/pdb.py, line 262, in user_line
    self.interaction(frame, None)
  File venv/lib/python3.10/site-packages/IPython/core/debugger.py, line 337, in interaction
    OldPdb.interaction(self, frame, traceback)
  File /usr/lib/python3.10/pdb.py, line 356, in interaction
    self.print_stack_entry(self.stack[self.curindex])
  File venv/lib/python3.10/site-packages/IPython/core/debugger.py, line 411, in print_stack_entry
    print(self.format_stack_entry(frame_lineno, '', context), file=self.stdout)
OSError: [Errno 9] Bad file descriptor
Exception ignored in: <module 'threading' from '/usr/lib/python3.10/threading.py'>
Traceback (most recent call last):
  File /usr/lib/python3.10/threading.py, line 1537, in _shutdown
    atexit_call()
  File /usr/lib/python3.10/contextlib.py, line 584, in close
    self.__exit__(None, None, None)
  File /usr/lib/python3.10/contextlib.py, line 576, in __exit__
    raise exc_details[1]
  File /usr/lib/python3.10/contextlib.py, line 561, in __exit__
    if cb(*exc_details):
  File /usr/lib/python3.10/contextlib.py, line 142, in __exit__
    next(self.gen)
  File venv/lib/python3.10/site-packages/madbg/debugger.py, line 170, in start_from_new_connection
    with cls.start(sock.fileno()) as debugger:
  File /usr/lib/python3.10/contextlib.py, line 142, in __exit__
    next(self.gen)
  File venv/lib/python3.10/site-packages/madbg/debugger.py, line 147, in start
    print('Closing connection', file=slave_writer, flush=True)
OSError: [Errno 9] Bad file descriptor

The madbg instance will have simply terminated with no output, error code 0.

My environment:

$ python --version
3.10.6

$ pip list  | grep hypno
hypno                  1.0.3

$ pip list | grep pyinjector
pyinjector             1.3.0

$ pip list | grep ipython
ipython                8.3.0

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.2 LTS
Release:	22.04
Codename:	jammy

AttributeError: 'TerminalInteractiveShell' object has no attribute 'style'

Hi, I want to report a bug, I am trying to figure out what a stuck pythong script is doing, I gave a try to your module, but unfortunately it crashes with the following stack trace. The server does not have a GUI, it is a plain terminal.

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/madbg/debugger.py", line 124, in start
    yield cls(slave_reader, slave_writer, term_type)
  File "/usr/local/lib/python3.8/dist-packages/madbg/debugger.py", line 30, in __init__
    super().__init__(pt_session_options=dict(input=term_input, output=term_output), stdin=stdin, stdout=stdout)
  File "/usr/local/lib/python3.8/dist-packages/IPython/terminal/debugger.py", line 32, in __init__
    self.pt_init(pt_session_options)
  File "/usr/local/lib/python3.8/dist-packages/IPython/terminal/debugger.py", line 74, in pt_init
    style=self.shell.style,
AttributeError: 'TerminalInteractiveShell' object has no attribute 'style'

Closing connection

AttributeError: dlsym(0x7fe7fd446100, injector_attach): symbol not found

x@192-168-10-195 android-apps-research-2021 % python
Python 3.9.0 (default, Sep 17 2021, 16:39:04) 
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import madbg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/x/.pyenv/versions/3.9.0/lib/python3.9/site-packages/madbg/__init__.py", line 1, in <module>
    from .api import set_trace, set_trace_on_connect, post_mortem, run_with_debugging, attach_to_process
  File "/Users/x/.pyenv/versions/3.9.0/lib/python3.9/site-packages/madbg/api.py", line 9, in <module>
    from hypno import inject_py
  File "/Users/x/.pyenv/versions/3.9.0/lib/python3.9/site-packages/hypno/__init__.py", line 1, in <module>
    from .hypno import inject_py
  File "/Users/x/.pyenv/versions/3.9.0/lib/python3.9/site-packages/hypno/hypno.py", line 4, in <module>
    from pyinjector import inject
  File "/Users/x/.pyenv/versions/3.9.0/lib/python3.9/site-packages/pyinjector/__init__.py", line 1, in <module>
    from .pyinjector import inject, LibraryNotFoundException
  File "/Users/x/.pyenv/versions/3.9.0/lib/python3.9/site-packages/pyinjector/pyinjector.py", line 13, in <module>
    libinjector.injector_attach.argtypes = POINTER(injector_pointer_t), pid_t
  File "/Users/x/.pyenv/versions/3.9.0/lib/python3.9/ctypes/__init__.py", line 387, in __getattr__
    func = self.__getitem__(name)
  File "/Users/x/.pyenv/versions/3.9.0/lib/python3.9/ctypes/__init__.py", line 392, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(0x7fe7fd446100, injector_attach): symbol not found

Can't attach to a process on musl libc

Stacktrace:

Traceback (most recent call last):
  File "/usr/bin/madbg", line 8, in <module>
    sys.exit(cli())
  File "/usr/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3.9/site-packages/madbg/__main__.py", line 34, in attach
    attach_to_process(pid, port, connect_timeout=timeout)
  File "/usr/lib/python3.9/site-packages/madbg/api.py", line 31, in attach_to_process
    _inject_set_trace(pid, ip, port)
  File "/usr/lib/python3.9/site-packages/madbg/api.py", line 25, in _inject_set_trace
    inject_py(pid, f'__import__("signal").signal({sig_num},lambda _,f:__import__("madbg").set_trace(f,"{ip}",{port}))')
  File "/usr/lib/python3.9/site-packages/hypno/hypno.py", line 20, in inject_py
    inject(pid, str(copied_lib))
  File "/usr/lib/python3.9/site-packages/pyinjector/pyinjector.py", line 95, in inject
    injector = Injector.attach(pid)
  File "/usr/lib/python3.9/site-packages/pyinjector/pyinjector.py", line 77, in attach
    call_c_func(libinjector.injector_attach, byref(injector_p), pid,
  File "/usr/lib/python3.9/site-packages/pyinjector/pyinjector.py", line 66, in call_c_func
    raise exception_cls(func.__name__, ret, libinjector.injector_error())
pyinjector.pyinjector.InjectorError: injector_attach returned -4: failed to open /usr/lib/x86_64-linux-gnu/libc-2.31.so. (error: No such file or directory)

Support attaching to processes that can't import madbg

When attaching to a process, madbg injects code that tries to import madbg. If the target process doesn't have madbg in its sys.path, attaching will fail.
The solution is not as simple as adding madbg to the sys.path, as it has dependencies, and some of them might collide with already-loaded versions in the target process.
A potential solution is to try to create a standalone version of madbg, potentially using pex or a similar tool.
Another direction is for madbg to detect the target interpreter, check if madbg is installed, and if not, offer to install it before attaching.
Until any solution is ready, we should make sure that the error is clear and does not affect the target process (see #49).

Could not find libc

getting following error while running on ubuntu docker image:

Traceback (most recent call last):
File "/usr/local/bin/madbg", line 8, in
sys.exit(cli())
File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1130, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/madbg/main.py", line 34, in attach
attach_to_process(pid, port, connect_timeout=timeout)
File "/usr/local/lib/python3.8/dist-packages/madbg/api.py", line 34, in attach_to_process
_inject_set_trace(pid, ip, port)
File "/usr/local/lib/python3.8/dist-packages/madbg/api.py", line 28, in _inject_set_trace
inject_py(pid, f'import("signal").signal({sig_num},lambda _,f:import("madbg").set_trace(f,"{ip}",{port}))')
File "/usr/local/lib/python3.8/dist-packages/hypno/hypno.py", line 20, in inject_py
inject(pid, str(copied_lib))
File "/usr/local/lib/python3.8/dist-packages/pyinjector/pyinjector.py", line 95, in inject
injector = Injector.attach(pid)
File "/usr/local/lib/python3.8/dist-packages/pyinjector/pyinjector.py", line 77, in attach
call_c_func(libinjector.injector_attach, byref(injector_p), pid,
File "/usr/local/lib/python3.8/dist-packages/pyinjector/pyinjector.py", line 66, in call_c_func
raise exception_cls(func.name, ret, libinjector.injector_error())
pyinjector.pyinjector.InjectorError: injector_attach returned -4: Could not find libc

abort: no module named 'madbg'

While attempting to use madbg, I have a stuck Python process present before even installing madbg. I installed madbg into a virtualenv and tried to attach to that process, but that caused an error in the attached process:

abort: no module named 'madbg'

And led to a TimeoutError in the client.

It's not at all obvious from the README that the process to be attached requires that madbg be installed/present. It's sort-of implied by the presence of madbg run commands.

Ways this experience could be improved:

  • In the README, declare that the attached process needs to have madbg installed/importable.
  • Have the client inject the sys.path where madbg is installed (maybe not a good idea?).
  • Provide explicit error handling during attachment if madbg is not importable.

Problem with post_mortem

Hey!
Trying to use post_mortem:

>>> post_mortem() # (after this, connect with CLI)
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    post_mortem()
  File "/home/sight/dvenv/lib/python3.8/site-packages/madbg/api.py", line 73, in post_mortem
    debugger.post_mortem(traceback)
AttributeError: 'int' object has no attribute 'post_mortem'

I believe this is the fix:

def post_mortem(ip=DEFAULT_IP, port=DEFAULT_PORT, traceback=None):
    traceback = traceback or sys.exc_info()[2] or sys.last_traceback
-    with RemoteIPythonDebugger.connect(ip, port) as debugger:
+    with RemoteIPythonDebugger.connect_and_start(ip, port) as debugger:
        debugger.post_mortem(traceback)

ModuleNotFoundError: No module named 'fcntl'

Issue

Please help me with this issue, when I ran madbg for the CLI interface, the error ModuleNotFoundError: No module named 'fcntl' appeared.

Edit

I also tried using the API, appeared with the same error importing it.

timeout when attach to a busy process (100% cpu)

madbg fails to attach, and the running process become DEAD after a while!

$ madbg attach 127108
Traceback (most recent call last):
  File "/home/work/hdd1/yinrong/.conda/envs/torch/bin/madbg", line 8, in <module>
    sys.exit(cli())
  File "/home/work/hdd1/yinrong/.conda/envs/torch/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/work/hdd1/yinrong/.conda/envs/torch/lib/python3.9/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/work/hdd1/yinrong/.conda/envs/torch/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/work/hdd1/yinrong/.conda/envs/torch/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/work/hdd1/yinrong/.conda/envs/torch/lib/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/work/hdd1/yinrong/.conda/envs/torch/lib/python3.9/site-packages/madbg/__main__.py", line 29, in attach
    attach_to_process(pid, port)
  File "/home/work/hdd1/yinrong/.conda/envs/torch/lib/python3.9/site-packages/madbg/api.py", line 31, in attach_to_process
    connect_to_debugger(ip, port, timeout=connect_timeout)
  File "/home/work/hdd1/yinrong/.conda/envs/torch/lib/python3.9/site-packages/madbg/client.py", line 64, in connect_to_debugger
    with connect_to_server(ip, port, timeout) as socket:
  File "/home/work/hdd1/yinrong/.conda/envs/torch/lib/python3.9/contextlib.py", line 117, in __enter__
    return next(self.gen)
  File "/home/work/hdd1/yinrong/.conda/envs/torch/lib/python3.9/site-packages/madbg/client.py", line 56, in connect_to_server
    raise TimeoutError()
TimeoutError
(torch) exit-status: 1

rerun 'madbg attach', the running process exits:

Waiting for connection from debugger console on 127.0.0.1:3513
Waiting for connection from debugger console on 127.0.0.1:3513
OSError: [Errno 98] Address already in use

I use madbg since I want to know what the process is busy doing, however madbg never works in such situation..

Question asyncio stack trace

Hi, your project is great but I have a question ๐Ÿ™‚
With the bt command I can have access to the stack trace from a python process.
But using an asyncio.run on the root of a python script, makes the stack trace not really usefull.
So here is my question; Is there a way to only print the stack trace related to our scripts? Thanks

Consider not changing ctty and emulating signals instead

Changing the ctty is a cause to many complications and potential bugs in the code. For example:

  • Have to add special cases to allow client to force exit
  • Potential bugs while debugging a process with children (sighup delivered to children)
  • Changing ctty requires changing sid and pgid, or pid, which can interfere with some programs
  • Using setsid can cause zombie processes
  • There is apparently no easy way to restore the original ctty

The only (?) advantage of changing the ctty is to allow the tty driver to deliver signals to the process according to keys sent by the client. We could just emulate this behavior ourselves and save all the trouble of changing the actual ctty.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.