Skip to contentSkip to conversation

Fix for RSP vCont packet

PATCH Lucien Murray-Pitts 3 participants 5 messages Jan 31, 2019 – Feb 5, 2019

lore
Share & tools
lore
#0 lore raw

The result is that vCont now does not recognise the case where no process/thread is provided after the action.

This may not show up with GDB, but using Lauterbach Trace32, and Hexrays IDA Pro this issue is immediately seen. The response is a "$#00" empty packet, showing it is unsupported packet.

This is defined in the RSP document as "An action with no thread-id matches all threads."
(https://sourceware.org/gdb/current/onlinedocs/gdb/Packets.html#vCont-packet )

Thus the valid vCont packets now are as below, however parsing is still not very strict.

  vCont;c/s                 - Step/Continue all threads
  vCont;c/s:[pX.]Y          - Step/Continue optional process X, thread Y
  vCont;C##/S##:[pX.]Y      - Step/Continue with signal ## on optional process X, thread Y

* If X or Y are -1 then it applies the action to all processes/threads.

---
 gdbstub.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
gdbstub.c +14 -2
index bfc7afb509..ce0dde2e24 100644
@@ -1169,6 +1169,7 @@ static int is_query_packet(const char *p, const char *query, char separator)
  */
 static int gdb_handle_vcont(GDBState *s, const char *p)
 {
+    GDBThreadIdKind vcontThreadType ;
     int res, signal = 0;
     char cur_action;
     char *newstates;
@@ -1218,12 +1219,23 @@ static int gdb_handle_vcont(GDBState *s, const char *p)
             goto out;
         }
 
-        if (*p++ != ':') {
+        /*
+         * In the case we have vCont;c or vCont;s - action is on all threads
+         * Alternatively vCont;c;s:p1.1 is a possible, but meaningless format,
+         * And in the else the "vCont;c:p1.1;... format is supported.
+         */
+        if (*p == '\0' || *p == ';') {
+            vcontThreadType = GDB_ALL_THREADS ;
+            pid = 1 ;
+            tid = 1 ;
+        } else if (*p++ == ':') {
+            vcontThreadType = read_thread_id(p, &p, &pid, &tid) ;
+        } else {
             res = -ENOTSUP;
             goto out;
         }
 
-        switch (read_thread_id(p, &p, &pid, &tid)) {
+        switch (vcontThreadType) {
         case GDB_READ_THREAD_ERR:
             res = -EINVAL;
             goto out;
Signature · 1 line
2.17.2
#1 lore raw
Quoted 1 line · Lucien Murray-Pitts

The result is that vCont now does not recognise the case where no process/thread is provided after the action.

Thanks for re-sending; this one came through a lot nicer! Welcome to the community; while a first submission can always be a bit daunting, the maintainers generally will help fix things up as you refine your process for making future submissions run more smoothly.

My next suggestion: wrap your commit message body around 65-70 columns, rather than using long lines. While it may sound archaic, many developers still use 80-column terminals, and 'git log' adds indentation; long lines become difficult to read if you don't manually wrap them.

Quoted 11 lines

This may not show up with GDB, but using Lauterbach Trace32, and Hexrays IDA Pro this issue is immediately seen. The response is a "$#00" empty packet, showing it is unsupported packet.

This is defined in the RSP document as "An action with no thread-id matches all threads."
(https://sourceware.org/gdb/current/onlinedocs/gdb/Packets.html#vCont-packet )

Thus the valid vCont packets now are as below, however parsing is still not very strict.

  vCont;c/s                 - Step/Continue all threads
  vCont;c/s:[pX.]Y          - Step/Continue optional process X, thread Y
  vCont;C##/S##:[pX.]Y      - Step/Continue with signal ## on optional process X, thread Y
Quoted 6 lines

* If X or Y are -1 then it applies the action to all processes/threads.

---
 gdbstub.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

I'll let someone more familiar with gdbstub review the actual patch content for correctness, but I'll do a quick pass for style:

gdbstub.c static int is_query_packet(const char *p, const char *query, char separator) · line 1172

Quoted 10 lines
gdbstub.c +1 -0
index bfc7afb509..ce0dde2e24 100644
@@ -1169,6 +1169,7 @@ static int is_query_packet(const char *p, const char *query, char separator)
  */
 static int gdb_handle_vcont(GDBState *s, const char *p)
 {
+    GDBThreadIdKind vcontThreadType ;

No space before ;

gdbstub.c static int gdb_handle_vcont(GDBState *s, const char *p) · line 1223

Quoted 10 lines
gdbstub.c +2 -1
     int res, signal = 0;
     char cur_action;
     char *newstates;
@@ -1218,12 +1219,23 @@ static int gdb_handle_vcont(GDBState *s, const char *p)
             goto out;
         }
 
-        if (*p++ != ':') {
+        /*
+         * In the case we have vCont;c or vCont;s - action is on all threads

Grammar suggestion: s/In the case/When/, and use a trailing '.' to end the sentence.

gdbstub.c static int gdb_handle_vcont(GDBState *s, const char *p) · line 1225

Quoted 2 lines
gdbstub.c +2 -0
+         * Alternatively vCont;c;s:p1.1 is a possible, but meaningless format,
+         * And in the else the "vCont;c:p1.1;... format is supported.

s/And in the else/otherwise/

gdbstub.c static int gdb_handle_vcont(GDBState *s, const char *p) · line 1230

Quoted 5 lines
gdbstub.c +5 -0
+         */
+        if (*p == '\0' || *p == ';') {
+            vcontThreadType = GDB_ALL_THREADS ;
+            pid = 1 ;
+            tid = 1 ;

Again, no space before ;

Quoted 13 lines
gdbstub.c +4 -1
+        } else if (*p++ == ':') {
+            vcontThreadType = read_thread_id(p, &p, &pid, &tid) ;
+        } else {
             res = -ENOTSUP;
             goto out;
         }
 
-        switch (read_thread_id(p, &p, &pid, &tid)) {
+        switch (vcontThreadType) {
         case GDB_READ_THREAD_ERR:
             res = -EINVAL;
             goto out;
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#2 lore raw
In reply to Lucien Murray-Pitts

Hi Lucien,

Quoted 24 lines · Lucien Murray-Pitts

The result is that vCont now does not recognise the case where no process/thread is provided after the action.

This may not show up with GDB, but using Lauterbach Trace32, and Hexrays IDA Pro this issue is immediately seen. The response is a "$#00" empty packet, showing it is unsupported packet.

This is defined in the RSP document as "An action with no thread-id matches all threads."
(https://sourceware.org/gdb/current/onlinedocs/gdb/Packets.html#vCont-packet )

Thus the valid vCont packets now are as below, however parsing is still not very strict.

  vCont;c/s                 - Step/Continue all threads
  vCont;c/s:[pX.]Y          - Step/Continue optional process X, thread Y
  vCont;C##/S##:[pX.]Y      - Step/Continue with signal ## on optional process X, thread Y

* If X or Y are -1 then it applies the action to all processes/threads.

---
 gdbstub.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
gdbstub.c +0 -0
index bfc7afb509..ce0dde2e24 100644

gdbstub.c static int is_query_packet(const char *p, const char *query, char separator) · line 1172

Quoted 4 lines
gdbstub.c +1 -0
@@ -1169,6 +1169,7 @@ static int is_query_packet(const char *p, const char *query, char separator)
  */
 static int gdb_handle_vcont(GDBState *s, const char *p)
 {
+    GDBThreadIdKind vcontThreadType ;

The coding style for variable names is lower_case_with_underscores (see CODING_STYLE). I think you can go with a simpler name like GDBThreadIdKind kind;

Quoted 4 lines
gdbstub.c +0 -0
     int res, signal = 0;
     char cur_action;
     char *newstates;

gdbstub.c static int gdb_handle_vcont(GDBState *s, const char *p) · line 1227

Quoted 10 lines
gdbstub.c +6 -1
@@ -1218,12 +1219,23 @@ static int gdb_handle_vcont(GDBState *s, const char *p)
             goto out;
         }
 
-        if (*p++ != ':') {
+        /*
+         * In the case we have vCont;c or vCont;s - action is on all threads
+         * Alternatively vCont;c;s:p1.1 is a possible, but meaningless format,
+         * And in the else the "vCont;c:p1.1;... format is supported.
+         */> +        if (*p == '\0' || *p == ';') {
+            vcontThreadType = GDB_ALL_THREAD ;> +            pid = 1 ;

The spec is not clear but I would opt for GDB_ALL_PROCESSES instead of GDB_ALL_THREAD here. pid = 1; is clearly wrong since you don't know if this PID exists or is currently attached.

gdbstub.c static int gdb_handle_vcont(GDBState *s, const char *p) · line 1230

Quoted 1 line
gdbstub.c +1 -0
+            tid = 1 ;

This one is not useful either (not used in the switch..case bellow).

Thanks

Luc

Quoted 13 lines
gdbstub.c +4 -1
+        } else if (*p++ == ':') {
+            vcontThreadType = read_thread_id(p, &p, &pid, &tid) ;
+        } else {
             res = -ENOTSUP;
             goto out;
         }
 
-        switch (read_thread_id(p, &p, &pid, &tid)) {
+        switch (vcontThreadType) {
         case GDB_READ_THREAD_ERR:
             res = -EINVAL;
             goto out;
#3 lore raw

Hi Luc,
Great feedback from both you and Eric - im blown away, I dont thinktheres a single 1byte ascii character left unturned there :)My coding style snuck in erywhere, as did my Scottish English!

    On Friday, February 1, 2019, 10:33:18 PM GMT+9, Luc Michel <[email protected]> wrote: > > +    GDBThreadIdKind vcontThreadType ;
Quoted 1 line

The coding style ... CODING_STYLE ...

Ah I didnt pick up on this whilst reading the Wiki for coding style, thank you!

Quoted 4 lines
Quoted 1 line

+            vcontThreadType = GDB_ALL_THREAD ;> +            pid = 1 ;

The spec is not clear but I would opt for GDB_ALL_PROCESSES instead of GDB_ALL_THREAD here. pid = 1; is clearly wrong since you don't know if this PID exists or is currently attached.

I was in a quandary here, and I did see your previous email too.However, I looked at how the call to read_thread_id() behaved and copied over the same behavior as if the command was vCont;c:-1which I understand to mean continue all threads? So maybe we should look at altering read_thread_id() which sets pid=1 when thereis no "ppid." part to the thread-id description, and if you set "tid=-1" then it performs a GDB_ALL_THREAD

Quoted 1 line

From the vCont spec I also got;"p-1 ... means all processes""An action with no thread-id matches all threads."

"tid=-1 ... matches all threads"
But it is not very clear what happens if you omit ppid and supply tid as -1. What do you think?
Cheers,

Luc

#4 lore raw

Hi,

Quoted 14 lines · Lucien Anti-Spam

Hi Luc,

Great feedback from both you and Eric - im blown away, I dont think theres a single 1byte ascii character left unturned there :) My coding style snuck in erywhere, as did my Scottish English!

Quoted 2 lines · Luc Michel
Quoted 1 line

+    GDBThreadIdKind vcontThreadType ;

The coding style ... CODING_STYLE ...

Ah I didnt pick up on this whilst reading the Wiki for coding style, thank you!

Quoted 1 line
Quoted 1 line

+            vcontThreadType = GDB_ALL_THREAD ;> +            pid = 1 ;

Quoted 8 lines
Quoted 3 lines

The spec is not clear but I would opt for GDB_ALL_PROCESSES instead of GDB_ALL_THREAD here. pid = 1; is clearly wrong since you don't know if this PID exists or is currently attached.

I was in a quandary here, and I did see your previous email too. However, I looked at how the call to read_thread_id() behaved and copied over the same behavior as if the command was vCont;c:-1 which I understand to mean continue all threads?

This is where the spec lacks details. The doc says that the vCont packet is used to "Resume the inferior, specifying different actions for each thread."

So it seems to target only one inferior (i.e. one process).

When multiprocess extension is in use, this packet must be supported, and used in place of 'Hc' (which modifies s->c_cpu) and other action packets (s, S, ...) which are deprecated.

So the question is: when the vCont packet does not specifies a thread-id, what _process_ we should choose?

Going for all process is probably ok because:
- we don't have to bother choosing a PID,
- it will cover the mono-process case correctly (main use-case of this
form of vCont packet I think).

Otherwise, we can go for GDB_ALL_THREAD and take the PID of the first attached CPU. I'm not sure sure which one is better...

Thanks.

Luc

Quoted 20 lines

So maybe we should look at altering read_thread_id() which sets pid=1 when there
is no "ppid." part to the thread-id description, and if you set "tid=-1" then it performs a GDB_ALL_THREAD

From the vCont spec I also got;
"p-1 ... means all processes"
"An action with no thread-id matches all threads." "tid=-1 ... matches all threads"

But it is not very clear what happens if you omit ppid and supply tid as -1.

What do you think?

Cheers,

Luc