Message ID | 54CCA038.8000704@web.de |
---|---|
State | New |
Headers | show |
Hi, I was skimming the list, and noticed: On 01/31/2015 10:28 AM, Jan Kiszka wrote: > @@ -1187,6 +1193,10 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) > put_packet_binary(s, buf, len + 1); > break; > } > + if (strncmp(p, "Attached", 8) == 0) { This looks like it'd mishandle a future qAttached2 packet. It should be doing something like: if (strncmp(p, "Attached", 8) == 0 && (p[8] == '\0' || p[8] == ':')) { or: if (strcmp(p, "Attached") == 0 || strncmp(p, "Attached:", 9) == 0) { Likewise other packets, if they have the same issue. (I'm not familiar with qemu's stub's internals.) Thanks, Pedro Alves
On 2015-02-04 14:36, Pedro Alves wrote: > Hi, I was skimming the list, and noticed: > > On 01/31/2015 10:28 AM, Jan Kiszka wrote: >> @@ -1187,6 +1193,10 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) >> put_packet_binary(s, buf, len + 1); >> break; >> } >> + if (strncmp(p, "Attached", 8) == 0) { > > This looks like it'd mishandle a future qAttached2 packet. > > It should be doing something like: > > if (strncmp(p, "Attached", 8) == 0 && > (p[8] == '\0' || p[8] == ':')) { > > or: > > if (strcmp(p, "Attached") == 0 || strncmp(p, "Attached:", 9) == 0) { > > > Likewise other packets, if they have the same issue. > (I'm not familiar with qemu's stub's internals.) Thanks for the remark! Will update the patch using the easier readable second variant. Jan
On 4 February 2015 at 13:36, Pedro Alves <palves@redhat.com> wrote: > > This looks like it'd mishandle a future qAttached2 packet. > > It should be doing something like: > > if (strncmp(p, "Attached", 8) == 0 && > (p[8] == '\0' || p[8] == ':')) { > > or: > > if (strcmp(p, "Attached") == 0 || strncmp(p, "Attached:", 9) == 0) { > > > Likewise other packets, if they have the same issue. > (I'm not familiar with qemu's stub's internals.) Looks like we get this wrong for a lot of our existing query packet handling too... Maybe worth having a utility function for "is this a foo query packet" rather than raw strcmp/strncmp? -- PMM
diff --git a/gdbstub.c b/gdbstub.c index e4a1a79..da3e7cb 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -41,6 +41,12 @@ #include "qemu/sockets.h" #include "sysemu/kvm.h" +#ifdef CONFIG_USER_ONLY +#define GDB_ATTACHED "0" +#else +#define GDB_ATTACHED "1" +#endif + static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr, uint8_t *buf, int len, bool is_write) { @@ -1187,6 +1193,10 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) put_packet_binary(s, buf, len + 1); break; } + if (strncmp(p, "Attached", 8) == 0) { + put_packet(s, GDB_ATTACHED); + break; + } /* Unrecognised 'q' command. */ goto unknown_command;