Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly close the remote session #896

Merged
merged 3 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -3506,8 +3506,8 @@ def exit_handler(_: "gdb.ExitedEvent") -> None:
reset_all_caches()
gef.session.qemu_mode = False
if gef.session.remote:
# make sure the tempdir is trashed
del(gef.session.remote)
gef.session.remote.close()
del gef.session.remote
gef.session.remote = None
return

Expand Down Expand Up @@ -9964,13 +9964,13 @@ def tmux_setup(self) -> None:
forcing the context to be redirected there."""
tmux = which("tmux")
ok("tmux session found, splitting window...")

pane, pty = subprocess.check_output([tmux, "splitw", "-h", '-F#{session_name}:#{window_index}.#{pane_index}-#{pane_tty}', "-P"]).decode().strip().split("-")
atexit.register(lambda : subprocess.run([tmux, "kill-pane", "-t", pane]))
# clear the screen and let it wait for input forever
gdb.execute(f"! {tmux} send-keys -t {pane} 'clear ; cat' C-m")
gdb.execute(f"! {tmux} select-pane -L")

ok(f"Setting `context.redirect` to '{pty}'...")
gdb.execute(f"gef config context.redirect {pty}")
ok("Done!")
Expand Down Expand Up @@ -10536,7 +10536,7 @@ def __init__(self, host: str, port: int, pid: int =-1, qemu: Optional[pathlib.Pa
raise EnvironmentError(f"Failed to create a proper environment for {self.target}")
return

def __del__(self) -> None:
def close(self) -> None:
self.__local_root_fd.cleanup()
try:
gef_on_new_unhook(self.remote_objfile_event_handler)
Expand Down
15 changes: 15 additions & 0 deletions tests/regressions/gdbserver_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from tests.utils import (
GefUnitTestGeneric,
gdb_run_cmd,
gdbserver_session,
)


class RegressionGdbserverConnection(GefUnitTestGeneric):
def test_can_establish_connection_to_gdbserver_again_after_disconnect(self):
"""Ensure that gdb can connect to a gdbserver again after disconnecting (PR #896)."""

with gdbserver_session(port=5001) as _, gdbserver_session(port=5002) as _:
buf = gdb_run_cmd("gef-remote 127.0.0.1 5001",
after=["detach", "gef-remote 127.0.0.1 5002", "continue"])
self.assertNoException(buf)