Skip to content

Conversation

@Theldus
Copy link
Contributor

@Theldus Theldus commented Aug 31, 2023

Summary

This PR brings two small fixes that prevents from using GDB stub normally:

  1. Fixes an out-of-bounds issue when the ENABLE_GDBSTUB_LOG flag is set.

  2. Remove an additional space in the response of the 'qfThreadInfo' package that prevents GDB from recognizing the current thread.

With these fixes, GDB now works like a charm here.

(There is a more detailed explanation of each fix in the commit messages)

Checklist

References

https://sourceware.org/gdb/onlinedocs/gdb/General-Query-Packets.html

The issue happens when the ENABLE_GDBSTUB_LOG flag is set, more
specifically within the gdbstub_client_respond() function. This is
due to the fact that the string 'GDB Stub: Sending response: ' and
the newline character '\n' total 29 characters. When combined with
the 995 characters of client->response, the total is 1024 bytes.
However, the pclog_ex() buffer size is also 1024 bytes, leaving no
room for the null terminator '\0'. As a result, when attempting to
print the text on the screen, a segmentation fault occurs.

This commit fixes this by decreasing the response text's size by one
byte.
When GDB sends the 'qfThreadInfo' packet, one of the possible responses
is 'm thread-id', as specified in [1]. However, contrary to what the
documentation implies, there is no space between 'm' and the thread-id.
In the current approach, GDB isn't even able to recognize that there's
any active thread, as the code sends "m 1" instead of "m1".

This commit addresses this by removing the space in the response.

Ref:
[1]: https://sourceware.org/gdb/onlinedocs/gdb/General-Query-Packets.html
@richardg867 richardg867 merged commit 4bde11c into 86Box:master Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants