diff --git a/madbg/debugger.py b/madbg/debugger.py index c9a5305..036b148 100644 --- a/madbg/debugger.py +++ b/madbg/debugger.py @@ -47,7 +47,6 @@ def trace_dispatch(self, frame, event, arg, check_debugging_global=False, done_c return super().trace_dispatch(frame, event, arg) except BdbQuit: bdb_quit = True - raise finally: if (done_callback is not None) and (self.quitting or bdb_quit): done_callback() diff --git a/setup.cfg b/setup.cfg index bd1ccf0..124b2d8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,7 +9,7 @@ install_requires = [metadata] name = madbg -version = 1.1.2 +version = 1.1.3 description = A fully-featured remote debugger for python author = Maor Kleinberger author_email = kmaork@gmail.com diff --git a/tests/system/test_madbg.py b/tests/system/test_madbg.py index b65ffcb..4376781 100644 --- a/tests/system/test_madbg.py +++ b/tests/system/test_madbg.py @@ -13,7 +13,12 @@ JOIN_TIMEOUT = 5 -def run_set_trace_process(start_with_ctty, port) -> bool: +def run_set_trace(start_with_ctty, port): + enter_pty(start_with_ctty) + madbg.set_trace(port=port) + + +def run_set_trace_and_expect_var_to_change(start_with_ctty, port) -> bool: """ Set two vars to the same value, start the debugger, and return True if one of the vars has changed. """ @@ -23,7 +28,7 @@ def run_set_trace_process(start_with_ctty, port) -> bool: return original_value != value_to_change -def run_set_trace_on_connect_process(start_with_ctty, port) -> bool: +def run_set_trace_on_connect(start_with_ctty, port) -> bool: """ Enter an infinite loop and break it using set_trace_on_connect. """ @@ -35,7 +40,7 @@ def run_set_trace_on_connect_process(start_with_ctty, port) -> bool: return True -def run_client_process(port: int, debugger_input: bytes): +def run_client(port: int, debugger_input: bytes): """ Run client process and return client's tty output """ master_fd = enter_pty(True) os.write(master_fd, debugger_input) @@ -54,18 +59,25 @@ def run_client_process(port: int, debugger_input: bytes): def test_set_trace(port, start_debugger_with_ctty): - debugger_future = run_in_process(run_set_trace_process, start_debugger_with_ctty, port) - client_future = run_in_process(run_client_process, port, b'value_to_change += 1\nc\n') + debugger_future = run_in_process(run_set_trace_and_expect_var_to_change, start_debugger_with_ctty, port) + client_future = run_in_process(run_client, port, b'value_to_change += 1\nc\n') assert debugger_future.result(JOIN_TIMEOUT) client_output = client_future.result(JOIN_TIMEOUT) - # TODO: why does this assert fail? - #assert b'Closing connection' in client_output + # TODO: why does this assert fail? Problem in piping? + # assert b'Closing connection' in client_output + + +def test_set_trace_and_quit_debugger(port, start_debugger_with_ctty): + debugger_future = run_in_process(run_set_trace, start_debugger_with_ctty, port) + client_future = run_in_process(run_client, port, b'q\n') + debugger_future.result(JOIN_TIMEOUT) + client_future.result(JOIN_TIMEOUT) def test_set_trace_with_failing_debugger(port, start_debugger_with_ctty, monkeypatch): monkeypatch.setattr(RemoteIPythonDebugger, '__init__', Mock(side_effect=lambda *a, **k: 1 / 0)) - debugger_future = run_in_process(run_set_trace_process, start_debugger_with_ctty, port) - client_future = run_in_process(run_client_process, port, b'value_to_change += 1\nc\n') + debugger_future = run_in_process(run_set_trace, start_debugger_with_ctty, port) + client_future = run_in_process(run_client, port, b'bla\n') with raises(ZeroDivisionError): debugger_future.result(JOIN_TIMEOUT) client_output = client_future.result(JOIN_TIMEOUT) @@ -73,10 +85,10 @@ def test_set_trace_with_failing_debugger(port, start_debugger_with_ctty, monkeyp def test_set_trace_on_connect(port, start_debugger_with_ctty): - debugger_future = run_in_process(run_set_trace_on_connect_process, start_debugger_with_ctty, port) + debugger_future = run_in_process(run_set_trace_on_connect, start_debugger_with_ctty, port) # let the loop run a little time.sleep(0.5) assert not debugger_future.done() - client_future = run_in_process(run_client_process, port, b'conti = False\nc\n') + client_future = run_in_process(run_client, port, b'conti = False\nc\n') assert debugger_future.result(JOIN_TIMEOUT) client_future.result(JOIN_TIMEOUT)