Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kmaork committed Sep 2, 2022
1 parent 6cbd235 commit c4a103f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 2 additions & 5 deletions madbg/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@
from .consts import DEFAULT_ADDR, DEFAULT_CONNECT_TIMEOUT, Addr
from .debugger import RemoteIPythonDebugger

DEBUGGER_CONNECTED_SIGNAL = signal.SIGUSR1


def start(addr: Addr = DEFAULT_ADDR):
DebuggerServer.make_sure_listening_at(addr)


def _inject_set_trace(pid: int, addr: Addr = DEFAULT_ADDR):
ip, port = addr
assert isinstance(ip, str)
assert re.fullmatch('[.0-9]+', ip)
assert isinstance(port, int)
sig_num = DEBUGGER_CONNECTED_SIGNAL.value
inject_py(pid, f'__import__("signal").signal({sig_num},lambda _,f:__import__("madbg").set_trace(f,"{ip}",{port}))')
os.kill(pid, sig_num)
inject_py(pid, f'__import__("madbg").start(({ip!r},{port}))')


# TODO: DEFAULT_PORT
Expand Down
14 changes: 13 additions & 1 deletion madbg/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,29 @@ def make_sure_listening_at(cls, addr: Addr):
cls.STATE.set(Future())
debugger = RemoteIPythonDebugger()
prepare_injection(debugger)
Thread(daemon=True, target=cls._run, args=(DEFAULT_ADDR, debugger)).start()
Thread(daemon=True, target=cls._run, args=(addr, debugger)).start()
elif state.done():
# Raise the exception
state.result()
else:
# TODO
raise RuntimeError('No support for double bind')


"""
Next steps:
- attach
need to do something very minimal during attach, like registering a signal handler or add pending action
pending action is better than another fucking signal, but it will wait for stuck syscalls...
pyinjector.pyinjector.InjectorError: injector_inject returned -1: The target process unexpectedly stopped by signal 17.
pyinjector issues:
- getting the python error back to us or at least know that it failed
- threads
- deadlock
- client-level detach (c-z, c-\)
- support mac n windows
python -c $'import madbg; madbg.start()\nwhile 1: print(__import__("time").sleep(1) or ":)")'
- There is only one debugger with one session
- A trace can start at any thread because of a set_trace(), or a client setting it
Expand Down

0 comments on commit c4a103f

Please sign in to comment.