Open Dragorn421 opened 8 months ago
This triggered a discussion on the ares discord starting here: https://discord.com/channels/976404869386747954/976463759935696977/1192472233235464212
Here are some notes:
recompile ares after changing GDB_LOG_MESSAGES
to true
one of the print calls has a bug: print
is used instead of printf
if constexpr(GDB_LOG_MESSAGES) {
print("GDB <: %s\n", cmdBuffer.data());
}
from gdb source,
error (_("Invalid hex digit %d"), a);
so e.g. in Invalid hex digit 79
79 is the codepoint for character O
(letter O)
(this made @HailToDodongo correctly speculate an OK was wrongly sent back as a response)
running gdb with "debug remote" on:
gdb-multiarch build/test_gdb.elf \
-readnow \
-ex 'set debug remote' \
-ex 'set debug remote-packet-max-chars unlimited' \
-ex 'set logging enabled' \
-ex 'set logging file gdb_out.txt' \
...
produces a dump of the sent/received data
this indeed showed an "OK" response to a "memory read" command, which doesn't expect OK (gdb client log:)
[remote] Sending packet: $m800164e0,4#95
[remote] Received Ack
[remote] Packet received: OK
Invalid hex digit 79
more complete logs near the problem area:
in particular:
GDB <: CTRL+C [0x03]
GDB <: m800164e0,4
GDB >: +$8F828020#b2
GDB >: +$S05#b8
it appears the ares gdb server can answer out of order
this is specifically only an issue for Ctrl+C, because of the implementation for reacting to this command:
auto Server::haltProgram() -> void {
forceHalt = true;
haltSignalSent = false;
}
which doesn't prevent further commands from being parsed and answered, before there is an answer about stopping the program.
So the fix to work on implementing is basically "don't answer commands out of order" or "wait for ctrl+c to be answered to further process commands"
Bug description
Pausing execution (^C in gdb) while the program is running and there is a python-implemented breakpoint in gdb doesn't work properly and often hangs
Reproducing
You will need the N64 rom and its elf. They can be built with libdragon and https://github.com/Dragorn421/n64homebrew/tree/15866a5993f3fac7bc020d2eb4c1a20cc6977120/test_gdb or download them: test_gdb.zip
test_gdb.z64
andbuild/test_gdb.elf
(see above)gdb_corrupt.py
andgdbrun.sh
from https://github.com/Dragorn421/n64homebrew/tree/15866a5993f3fac7bc020d2eb4c1a20cc6977120/test_gdbtest_gdb.z64
andgdbrun.sh
(usesbuild/test_gdb.elf
and runsgdb_corrupt.py
)c
Invalid hex digit XX
(XX = placeholder) error shows upSee screenshots below
Expected behavior
There should be no error, or they shouldn't mess up later usage of gdb
Screenshots
"variant" with the breakpoint in
gdb_corrupt.py
doing nothing:"variant" with the breakpoint in
gdb_corrupt.py
doingprint(gdb.parse_and_eval("count"), end="\r")
Notice in both screenshots gdb has been instructed to continue execution, but execution is still paused (as indicated by the stop icon in ares' gdb status and nothing being printed to console)
Additional context
OS: Kubuntu Linux ares version: built from source from v134
Discussion
I am not sure this is a gdb server implementation issue on ares' part, it may well be a gdb client bug, but I think that's less likely given gdb has much more testing/usage than ares does. I'm opening an issue mostly to start documenting this because I expect it's a rabbit hole
I'm thinking "Invalid hex digit XX" could mean there's some miscommunication in the gdb protocol between gdb and ares, that is, a mistake in the ares gdb server implementation, but idk