diff options
author | Andrew Burgess <aburgess@redhat.com> | 2021-08-31 14:04:11 +0100 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2021-11-30 12:10:40 +0000 |
commit | e5b176f25ff51f6811b82f549b7524618d5c2f6b (patch) | |
tree | 2f8edc639e385d0099180fd0a76f300cc25126d6 /gdb/remote.h | |
parent | 0e3b7c25eea80717638617ebafac611ed970def8 (diff) | |
download | gdb-e5b176f25ff51f6811b82f549b7524618d5c2f6b.zip gdb-e5b176f25ff51f6811b82f549b7524618d5c2f6b.tar.gz gdb-e5b176f25ff51f6811b82f549b7524618d5c2f6b.tar.bz2 |
gdb: make packet_command function available outside remote.c
In a later commit I will add a Python API to access the 'maint packet'
functionality, that is, sending a user specified packet to the target.
To make implementing this easier, this commit refactors how this
command is currently implemented so that the packet_command function
is now global.
The new global send_remote_packet function takes an object that is an
implementation of an abstract interface. Two functions within this
interface are then called, one just before a packet is sent to the
remote target, and one when the reply has been received from the
remote target. Using an interface object in this way allows (1) for
the error checking to be done before the first callback is made, this
means we only print out what packet it being sent once we know we are
going to actually send it, and (2) we don't need to make a copy of the
reply if all we want to do is print it.
One user visible changes after this commit are the error
messages, which I've changed to be less 'maint packet' command
focused, this will make them (I hope) better for when
send_remote_packet can be called from Python code.
So: "command can only be used with remote target"
Becomes: "packets can only be sent to a remote target"
And: "remote-packet command requires packet text as argument"
Becomes: "a remote packet must not be empty"
Additionally, in this commit, I've added support for packet replies
that contain binary data. Before this commit, the code that printed
the reply treated the reply as a C string, it assumed that the string
only contained printable characters, and had a null character only at
the end.
One way to show the problem with this is if we try to read the auxv
data from a remote target, the auxv data is binary, so, before this
commit:
(gdb) target remote :54321
...
(gdb) maint packet qXfer:auxv:read::0,1000
sending: "qXfer:auxv:read::0,1000"
received: "l!"
(gdb)
And after this commit:
(gdb) target remote :54321
...
(gdb) maint packet qXfer:auxv:read::0,1000
sending: "qXfer:auxv:read::0,1000"
received: "l!\x00\x00\x00\x00\x00\x00\x00\x00\xf0\xfc\xf7\xff\x7f\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\xff\xf>
(gdb)
The binary contents of the reply are now printed as escaped hex.
Diffstat (limited to 'gdb/remote.h')
-rw-r--r-- | gdb/remote.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/gdb/remote.h b/gdb/remote.h index 46bfa01..0178294 100644 --- a/gdb/remote.h +++ b/gdb/remote.h @@ -78,4 +78,39 @@ extern int remote_register_number_and_offset (struct gdbarch *gdbarch, extern void remote_notif_get_pending_events (remote_target *remote, struct notif_client *np); extern bool remote_target_is_non_stop_p (remote_target *t); + +/* An abstract class that represents the set of callbacks that are made + from the send_remote_packet function (declared below). */ + +struct send_remote_packet_callbacks +{ + /* The SENDING callback is called once send_remote_packet has performed + its error checking and setup, just before the packet is sent to the + remote target. BUF is the content of the packet that will be sent + (before any of the protocol specific prefix, suffix, or escaping is + applied). */ + + virtual void sending (gdb::array_view<const char> &buf) = 0; + + /* The RECEIVED callback is called once a reply has been received from + the remote target. The content of the reply is in BUF which can't be + modified, and which is not guaranteed to remain valid after the + RECEIVED call has returned. If you need to preserve the contents of + BUF then a copy should be taken. */ + + virtual void received (gdb::array_view<const char> &buf) = 0; +}; + +/* Send BUF to the current remote target. If BUF points to an empty + string, either zero length, or the first character is the null + character, then an error is thrown. If the current target is not a + remote target then an error is thrown. + + Calls CALLBACKS->sending() just before the packet is sent to the remote + target, and calls CALLBACKS->received() with the reply once this is + received from the remote target. */ + +extern void send_remote_packet (gdb::array_view<const char> &buf, + send_remote_packet_callbacks *callbacks); + #endif |