Skip to content

Commit

Permalink
gdb.debug: avoid 2s timeout if possible
Browse files Browse the repository at this point in the history
On Ubuntu 22.04 gdb.debug() takes at least 2 seconds. This is because
it prints only "Remote debugging from host 127.0.0.1, port 33398", but
the code expects 2 lines.

It's very unclear what the second line is supposed to be; the only lead
is "* Handle extra newline printed by gdb" in commit 338fbeb ("Improve
pwnup template, gdbserver detection (Gallopsled#1148)"), but I could not trace it
back to the GDB source code, both historic and modern. Perhaps, there
is a non-upstreamed patch in some distro that introduces it.

It should still be safe to skip waiting for the second line if the
first one already starts with "Remote debugging ...", so do it.
  • Loading branch information
mephi42 committed Aug 4, 2024
1 parent 00663aa commit 695ec4e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ The table below shows which release corresponds to each branch, and what date th
- [#2405][2405] Add "none" ssh authentication method
- [#2427][2427] Document behaviour of remote()'s sni argument as string.
- [#2382][2382] added optional port, gdb_args and gdbserver_args parameters to gdb.debug()
- [#2435][2435] Speed up gdbserver handshake in gdb.debug()

[2360]: https://github.com/Gallopsled/pwntools/pull/2360
[2356]: https://github.com/Gallopsled/pwntools/pull/2356
Expand Down
11 changes: 6 additions & 5 deletions pwnlib/gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,12 +717,13 @@ def debug(args, gdbscript=None, gdb_args=None, exe=None, ssh=None, env=None, por

# gdbserver outputs a message when a client connects
garbage = gdbserver.recvline(timeout=1)

# Some versions of gdbserver output an additional message
try:
garbage2 = gdbserver.recvline_startswith(b"Remote debugging from host ", timeout=2)
except EOFError:
pass
message = b"Remote debugging from host "
if not garbage.startswith(message):
try:
garbage2 = gdbserver.recvline_startswith(message, timeout=2)
except EOFError:
pass

return gdbserver

Expand Down

0 comments on commit 695ec4e

Please sign in to comment.