diff mbox series

[for-4.0] gdbstub: fix vCont packet handling when no thread is specified

Message ID 20190325110452.6756-1-luc.michel@greensocs.com
State New
Headers show
Series [for-4.0] gdbstub: fix vCont packet handling when no thread is specified | expand

Commit Message

Luc Michel March 25, 2019, 11:04 a.m. UTC
The vCont packet accepts a series of actions, each being applied on a
given thread ID. Giving no thread ID for an action is valid and means
"all threads".

This commit fixes vCont packets being incorrectly rejected when no
thread ID was given for an action.

In multiprocess mode, the GDB Remote Protocol specification is unclear
on what "all threads" means. We choose to apply the action on all
threads of all attached processes.

This commit is based on the initial fix by Lucien Murray-Pitts.

Fixes: e40e5204af8388
Reported-by: Lucien Murray-Pitts <lucienmp_antispam@yahoo.com>
Reported-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Luc Michel <luc.michel@greensocs.com>
---
 gdbstub.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Comments

Richard Henderson March 26, 2019, 3:32 a.m. UTC | #1
On 3/25/19 4:04 AM, Luc Michel wrote:
> The vCont packet accepts a series of actions, each being applied on a
> given thread ID. Giving no thread ID for an action is valid and means
> "all threads".
> 
> This commit fixes vCont packets being incorrectly rejected when no
> thread ID was given for an action.
> 
> In multiprocess mode, the GDB Remote Protocol specification is unclear
> on what "all threads" means. We choose to apply the action on all
> threads of all attached processes.
> 
> This commit is based on the initial fix by Lucien Murray-Pitts.
> 
> Fixes: e40e5204af8388
> Reported-by: Lucien Murray-Pitts <lucienmp_antispam@yahoo.com>
> Reported-by: Jan Kiszka <jan.kiszka@siemens.com>
> Signed-off-by: Luc Michel <luc.michel@greensocs.com>
> ---
>  gdbstub.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~
Peter Maydell March 26, 2019, 10:42 a.m. UTC | #2
On Mon, 25 Mar 2019 at 11:05, Luc Michel <luc.michel@greensocs.com> wrote:
>
> The vCont packet accepts a series of actions, each being applied on a
> given thread ID. Giving no thread ID for an action is valid and means
> "all threads".
>
> This commit fixes vCont packets being incorrectly rejected when no
> thread ID was given for an action.
>
> In multiprocess mode, the GDB Remote Protocol specification is unclear
> on what "all threads" means. We choose to apply the action on all
> threads of all attached processes.
>
> This commit is based on the initial fix by Lucien Murray-Pitts.
>
> Fixes: e40e5204af8388
> Reported-by: Lucien Murray-Pitts <lucienmp_antispam@yahoo.com>
> Reported-by: Jan Kiszka <jan.kiszka@siemens.com>
> Signed-off-by: Luc Michel <luc.michel@greensocs.com>
> ---



Applied to target-arm.next, thanks.

-- PMM
diff mbox series

Patch

diff --git a/gdbstub.c b/gdbstub.c
index bc774ae992..d54abd17cc 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1150,10 +1150,11 @@  static int gdb_handle_vcont(GDBState *s, const char *p)
     char *newstates;
     unsigned long tmp;
     uint32_t pid, tid;
     GDBProcess *process;
     CPUState *cpu;
+    GDBThreadIdKind kind;
 #ifdef CONFIG_USER_ONLY
     int max_cpus = 1; /* global variable max_cpus exists only in system mode */
 
     CPU_FOREACH(cpu) {
         max_cpus = max_cpus <= cpu->cpu_index ? cpu->cpu_index + 1 : max_cpus;
@@ -1192,16 +1193,25 @@  static int gdb_handle_vcont(GDBState *s, const char *p)
             /* unknown/invalid/unsupported command */
             res = -ENOTSUP;
             goto out;
         }
 
-        if (*p++ != ':') {
+        if (*p == '\0' || *p == ';') {
+            /*
+             * No thread specifier, action is on "all threads". The
+             * specification is unclear regarding the process to act on. We
+             * choose all processes.
+             */
+            kind = GDB_ALL_PROCESSES;
+        } else if (*p++ == ':') {
+            kind = read_thread_id(p, &p, &pid, &tid);
+        } else {
             res = -ENOTSUP;
             goto out;
         }
 
-        switch (read_thread_id(p, &p, &pid, &tid)) {
+        switch (kind) {
         case GDB_READ_THREAD_ERR:
             res = -EINVAL;
             goto out;
 
         case GDB_ALL_PROCESSES: