Skip to content

Use target remote for remote connections#1151

Open
hugsy wants to merge 54 commits intomainfrom
hugsy/revisit-target-remote
Open

Use target remote for remote connections#1151
hugsy wants to merge 54 commits intomainfrom
hugsy/revisit-target-remote

Conversation

@hugsy
Copy link
Copy Markdown
Owner

@hugsy hugsy commented Nov 3, 2024

Description

This PR obsoletes gef-remote to be completely replaced by pre and post hooks on target remote directly.
We use some heuristics to determine what type of remote we're connected to reliably.
In some old qemu, we still have to mock a memory layout, but the whole sync thing is not necessary any longer.

Fixes #1080
Fixes #1128

Checklist

  • My code follows the code style of this project.
  • My change includes a change to the documentation, if required.
  • If my change adds new code, adequate tests have been added.
  • I have read and agree to the CONTRIBUTING document.

@hugsy hugsy mentioned this pull request Nov 3, 2024
8 tasks
@hugsy hugsy self-assigned this Nov 3, 2024
@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 3, 2024

🤖 Coverage update for a277661 🔴

Old New
Commit 9fb1d71 a277661
Score 71.2662% 71.197% (-0.0692)

@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 4, 2024

🤖 Coverage update for 6d166f0 🔴

Old New
Commit 9fb1d71 6d166f0
Score 71.2662% 71.197% (-0.0692)

@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 5, 2024

🤖 Coverage update for 79447be 🔴

Old New
Commit 9fb1d71 79447be
Score 71.2662% 71.197% (-0.0692)

@hugsy hugsy linked an issue Nov 5, 2024 that may be closed by this pull request
@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 7, 2024

🤖 Coverage update for ea873bb 🔴

Old New
Commit 9fb1d71 ea873bb
Score 71.2662% 71.197% (-0.0692)

@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 7, 2024

🤖 Coverage update for 4ae683f 🔴

Old New
Commit 9fb1d71 4ae683f
Score 71.2662% 71.197% (-0.0692)

@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 7, 2024

🤖 Coverage update for 8130895 🔴

Old New
Commit 9fb1d71 8130895
Score 71.2662% 71.2358% (-0.0304)

@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 7, 2024

🤖 Coverage update for 7973a3f 🔴

Old New
Commit 9fb1d71 7973a3f
Score 71.2662% 71.197% (-0.0692)

@github-actions
Copy link
Copy Markdown

🤖 Coverage update for b170c41 🟢

Old New
Commit 0c95800 b170c41
Score 71.0775% 71.0775% (0)

@github-actions
Copy link
Copy Markdown

🤖 Coverage update for b170c41 🟢

Old New
Commit 0c95800 b170c41
Score 71.0775% 71.1251% (0.0476)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR shifts remote debugging workflows from GEF’s gef-remote command toward GDB’s native target remote/extended-remote, adds GDB target hooks to initialize GEF’s remote session automatically, and updates/extends the test suite and CI coverage generation accordingly.

Changes:

  • Deprecates gef-remote behavior by routing it to target remote and introduces target remote pre/post hooks to initialize gef.session.remote.
  • Updates tests to use target remote and adds new remote-mode API/regression coverage (including gdbserver --multi and qemu-user scenarios).
  • Tweaks coverage generation (pytest invocation) and CI workflow steps (dependencies + building test binaries).

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
tests/utils.py Uses shutil.which, adds gdbserver multi helpers, configurable startup delay, qemu-user args support, and a random-port helper used across tests.
tests/regressions/gdbserver_connection.py Migrates regression test from gef-remote to target remote.
tests/regressions/1131_target_remote_registers.py Adds a new slow regression test reproducer for target-remote register display.
tests/commands/gef_remote.py Updates command tests to validate sessions via target remote and new RemoteSession(...) string format.
tests/base.py Centralizes port selection via get_random_port() and runs tests under gdb-multiarch.
tests/api/gef_session.py Updates session API tests to use target remote and shared port helper.
tests/api/gef_remote.py Adds API-level tests for detecting remote/extended-remote and differentiating gdbserver multi vs qemu-user.
tests/api/gef_memory.py Updates remote memory-maps tests to use target remote and shared port helper.
scripts/generate-coverage-docs.sh Adjusts pytest invocation for coverage runs (--forked, verbosity, marker selection).
gef.py Introduces target-remote detection helpers, new remote-mode handling, hooks for target remote, and reworks/limits legacy gef-remote behavior.
docs/commands/gef-remote.md Updates docs to emphasize gef-remote deprecation.
.github/workflows/coverage.yml Installs additional requirements, builds binaries, and runs updated coverage generation script.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +37 to 40
python${{ env.PY_VER }} -m pip install --user --upgrade -r tests/requirements.txt -r docs/requirements.txt --quiet
current_score=$(curl --silent https://hugsy.github.io/gef/coverage/gef_py.html | grep pc_cov | sed 's?.*<span class="pc_cov">\([^%]*\)%</span>?\1?g')
make -C tests/binaries
bash scripts/generate-coverage-docs.sh
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow now runs the full test suite for coverage, and this PR adds a test that shells out to wget/unzip. Those packages are not installed in the job currently (only curl is). Either avoid those external dependencies in the test, or install the required packages here to prevent CI failures.

Copilot uses AI. Check for mistakes.
Comment on lines 3730 to 3737
path = evt.new_objfile.filename or ""
elif progspace:
path = progspace.filename or ""
else:
raise RuntimeError("Cannot determine file path")

assert path
try:
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new_objfile_handler() now does assert path after pulling evt.new_objfile.filename/progspace.filename. In practice GDB can emit objfile events with an empty/None filename; asserting here will crash GEF instead of safely ignoring the event. Please replace the assert with an explicit guard (e.g., early-return when not path) and keep handling of special pseudo-paths (like "system-supplied DSO") intact.

Copilot uses AI. Check for mistakes.
Comment on lines +11791 to +11806
def target_remote_hook():
# disable the context until the session has been fully established
gef.temp["context_old_value"] = gef.config["context.enable"]
gef.config["context.enable"] = False


def target_remote_posthook():
if gef.session.remote_initializing:
return
conn = gdb.selected_inferior().connection
if not isinstance(conn, gdb.RemoteTargetConnection):
raise TypeError("Expected type gdb.RemoteTargetConnection")
assert is_target_remote_or_extended(conn), "Target is not remote"
gef.session.remote = GefRemoteSessionManager(conn)

# switch back context to its old context
gef.config["context.enable"] = gef.temp.pop("context_old_value", True)

Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target_remote_hook() disables context.enable before the target remote command runs, but if the command fails (bad host/port, auth, etc.) the post-hook may not execute and context will remain disabled for the rest of the session. Consider restoring the previous value on failure (e.g., wrap the post-hook logic in a defensive try/except that always resets config when the connection isn’t remote, or avoid changing the setting in the pre-hook).

Copilot uses AI. Check for mistakes.
Comment on lines 11625 to 11646
@@ -11639,77 +11645,25 @@
reset_architecture()
return True
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GefRemoteSessionManager.setup() unconditionally does gef.binary = Elf(self.lfile) after setting self.__local_root_path to / for several modes. If the remote executable is not present locally (which is a common target remote workflow), this will raise and break the connection post-hook. Please guard this with an existence check / try-except and fall back to leaving gef.binary unchanged (or use progspace.filename only when it points to a local file).

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@hugsy hugsy requested review from Grazfather and ValekoZ March 11, 2026 15:34
@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 5f53105 🟢

Old New
Commit 0c95800 5f53105
Score 71.0775% 71.0775% (0)

@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 5f53105 🟢

Old New
Commit 0c95800 5f53105
Score 71.0775% 71.1251% (0.0476)

@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 95da20f 🟢

Old New
Commit 0c95800 95da20f
Score 71.0775% 71.0775% (0)

@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 8aa7f9b 🟢

Old New
Commit 0c95800 8aa7f9b
Score 71.0775% 71.0775% (0)

@github-actions
Copy link
Copy Markdown

🤖 Coverage update for f00fa60 🟢

Old New
Commit 0c95800 f00fa60
Score 71.0775% 71.0775% (0)

@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 94c8756 🟢

Old New
Commit 0c95800 94c8756
Score 71.0775% 71.0775% (0)

@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 3d4a4ef 🟢

Old New
Commit 0c95800 3d4a4ef
Score 71.0775% 71.0775% (0)

@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 0fba0d1 🟢

Old New
Commit 0c95800 0fba0d1
Score 71.0775% 71.0775% (0)

@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 0fba0d1 🟢

Old New
Commit 0c95800 0fba0d1
Score 71.0775% 71.1251% (0.0476)

@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 02a5a69 🟢

Old New
Commit 0c95800 02a5a69
Score 71.0775% 71.0775% (0)

@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 02a5a69 🔴

Old New
Commit 0c95800 02a5a69
Score 71.0775% 70.4923% (-0.5852)

Co-authored-by: Frank Dana <ferdnyc@gmail.com>
@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 487262c 🟢

Old New
Commit 0c95800 487262c
Score 71.0775% 71.0775% (0)

@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 487262c 🔴

Old New
Commit 0c95800 487262c
Score 71.0775% 70.4731% (-0.6044)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

6 participants