diff mbox series

[v2,2/4] gdbstub: rename cpu_index -> cpu_gdb_index

Message ID 20170601144915.20778-3-alex.bennee@linaro.org
State New
Headers show
Series some gdbstub fixes for debug and vcont | expand

Commit Message

Alex Bennée June 1, 2017, 2:49 p.m. UTC
This is to make it clear the index is purely a gdbstub function and
should not be confused with the value of cpu->cpu_index.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 gdbstub.c              | 12 ++++++------
 include/exec/gdbstub.h |  7 ++++++-
 2 files changed, 12 insertions(+), 7 deletions(-)

-- 
2.13.0

Comments

Greg Kurz June 1, 2017, 3:13 p.m. UTC | #1
On Thu,  1 Jun 2017 15:49:13 +0100
Alex Bennée <alex.bennee@linaro.org> wrote:

> This is to make it clear the index is purely a gdbstub function and

> should not be confused with the value of cpu->cpu_index.

> 

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> ---


Reviewed-by: Greg Kurz <groug@kaod.org>


>  gdbstub.c              | 12 ++++++------

>  include/exec/gdbstub.h |  7 ++++++-

>  2 files changed, 12 insertions(+), 7 deletions(-)

> 

> diff --git a/gdbstub.c b/gdbstub.c

> index a249846954..026d1fe6bb 100644

> --- a/gdbstub.c

> +++ b/gdbstub.c

> @@ -837,7 +837,7 @@ static CPUState *find_cpu(uint32_t thread_id)

>      CPUState *cpu;

>  

>      CPU_FOREACH(cpu) {

> -        if (cpu_index(cpu) == thread_id) {

> +        if (cpu_gdb_index(cpu) == thread_id) {

>              return cpu;

>          }

>      }

> @@ -925,7 +925,7 @@ static int gdb_handle_vcont(GDBState *s, const char *p)

>              idx = tmp;

>              /* 0 means any thread, so we pick the first valid CPU */

>              if (!idx) {

> -                idx = cpu_index(first_cpu);

> +                idx = cpu_gdb_index(first_cpu);

>              }

>  

>              /*

> @@ -975,7 +975,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)

>      case '?':

>          /* TODO: Make this return the correct value for user-mode.  */

>          snprintf(buf, sizeof(buf), "T%02xthread:%02x;", GDB_SIGNAL_TRAP,

> -                 cpu_index(s->c_cpu));

> +                 cpu_gdb_index(s->c_cpu));

>          put_packet(s, buf);

>          /* Remove all the breakpoints when this query is issued,

>           * because gdb is doing and initial connect and the state

> @@ -1243,7 +1243,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)

>          } else if (strcmp(p,"sThreadInfo") == 0) {

>          report_cpuinfo:

>              if (s->query_cpu) {

> -                snprintf(buf, sizeof(buf), "m%x", cpu_index(s->query_cpu));

> +                snprintf(buf, sizeof(buf), "m%x", cpu_gdb_index(s->query_cpu));

>                  put_packet(s, buf);

>                  s->query_cpu = CPU_NEXT(s->query_cpu);

>              } else

> @@ -1400,7 +1400,7 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state)

>              }

>              snprintf(buf, sizeof(buf),

>                       "T%02xthread:%02x;%swatch:" TARGET_FMT_lx ";",

> -                     GDB_SIGNAL_TRAP, cpu_index(cpu), type,

> +                     GDB_SIGNAL_TRAP, cpu_gdb_index(cpu), type,

>                       (target_ulong)cpu->watchpoint_hit->vaddr);

>              cpu->watchpoint_hit = NULL;

>              goto send_packet;

> @@ -1434,7 +1434,7 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state)

>          break;

>      }

>      gdb_set_stop_cpu(cpu);

> -    snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret, cpu_index(cpu));

> +    snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret, cpu_gdb_index(cpu));

>  

>  send_packet:

>      put_packet(s, buf);

> diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h

> index f9708bbcd6..c4fe567600 100644

> --- a/include/exec/gdbstub.h

> +++ b/include/exec/gdbstub.h

> @@ -58,7 +58,12 @@ void gdb_register_coprocessor(CPUState *cpu,

>                                gdb_reg_cb get_reg, gdb_reg_cb set_reg,

>                                int num_regs, const char *xml, int g_pos);

>  

> -static inline int cpu_index(CPUState *cpu)

> +/* Return the GDB index for a given vCPU state.

> + *

> + * For user mode this is simply the thread id. In system mode GDB

> + * numbers CPUs from 1 as 0 is reserved as an "any cpu" index.

> + */

> +static inline int cpu_gdb_index(CPUState *cpu)

>  {

>  #if defined(CONFIG_USER_ONLY)

>      return cpu->host_tid;
Claudio Imbrenda June 1, 2017, 3:48 p.m. UTC | #2
On Thu,  1 Jun 2017 15:49:13 +0100
Alex Bennée <alex.bennee@linaro.org> wrote:

> This is to make it clear the index is purely a gdbstub function and

> should not be confused with the value of cpu->cpu_index.

> 

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> ---

>  gdbstub.c              | 12 ++++++------

>  include/exec/gdbstub.h |  7 ++++++-

>  2 files changed, 12 insertions(+), 7 deletions(-)

> 

> diff --git a/gdbstub.c b/gdbstub.c

> index a249846954..026d1fe6bb 100644

> --- a/gdbstub.c

> +++ b/gdbstub.c

> @@ -837,7 +837,7 @@ static CPUState *find_cpu(uint32_t thread_id)

>      CPUState *cpu;

> 

>      CPU_FOREACH(cpu) {

> -        if (cpu_index(cpu) == thread_id) {

> +        if (cpu_gdb_index(cpu) == thread_id) {

>              return cpu;

>          }

>      }

> @@ -925,7 +925,7 @@ static int gdb_handle_vcont(GDBState *s, const

> char *p) idx = tmp;

>              /* 0 means any thread, so we pick the first valid CPU */

>              if (!idx) {

> -                idx = cpu_index(first_cpu);

> +                idx = cpu_gdb_index(first_cpu);

>              }

> 

>              /*

> @@ -975,7 +975,7 @@ static int gdb_handle_packet(GDBState *s, const

> char *line_buf) case '?':

>          /* TODO: Make this return the correct value for user-mode.

> */ snprintf(buf, sizeof(buf), "T%02xthread:%02x;", GDB_SIGNAL_TRAP,

> -                 cpu_index(s->c_cpu));

> +                 cpu_gdb_index(s->c_cpu));

>          put_packet(s, buf);

>          /* Remove all the breakpoints when this query is issued,

>           * because gdb is doing and initial connect and the state

> @@ -1243,7 +1243,7 @@ static int gdb_handle_packet(GDBState *s, const

> char *line_buf) } else if (strcmp(p,"sThreadInfo") == 0) {

>          report_cpuinfo:

>              if (s->query_cpu) {

> -                snprintf(buf, sizeof(buf), "m%x",

> cpu_index(s->query_cpu));

> +                snprintf(buf, sizeof(buf), "m%x",

> cpu_gdb_index(s->query_cpu)); put_packet(s, buf);

>                  s->query_cpu = CPU_NEXT(s->query_cpu);

>              } else

> @@ -1400,7 +1400,7 @@ static void gdb_vm_state_change(void *opaque,

> int running, RunState state) }

>              snprintf(buf, sizeof(buf),

>                       "T%02xthread:%02x;%swatch:" TARGET_FMT_lx ";",

> -                     GDB_SIGNAL_TRAP, cpu_index(cpu), type,

> +                     GDB_SIGNAL_TRAP, cpu_gdb_index(cpu), type,

>                       (target_ulong)cpu->watchpoint_hit->vaddr);

>              cpu->watchpoint_hit = NULL;

>              goto send_packet;

> @@ -1434,7 +1434,7 @@ static void gdb_vm_state_change(void *opaque,

> int running, RunState state) break;

>      }

>      gdb_set_stop_cpu(cpu);

> -    snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret,

> cpu_index(cpu));

> +    snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret,

> cpu_gdb_index(cpu));

> 

>  send_packet:

>      put_packet(s, buf);

> diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h

> index f9708bbcd6..c4fe567600 100644

> --- a/include/exec/gdbstub.h

> +++ b/include/exec/gdbstub.h

> @@ -58,7 +58,12 @@ void gdb_register_coprocessor(CPUState *cpu,

>                                gdb_reg_cb get_reg, gdb_reg_cb set_reg,

>                                int num_regs, const char *xml, int

> g_pos);

> 

> -static inline int cpu_index(CPUState *cpu)

> +/* Return the GDB index for a given vCPU state.

> + *

> + * For user mode this is simply the thread id. In system mode GDB

> + * numbers CPUs from 1 as 0 is reserved as an "any cpu" index.

> + */

> +static inline int cpu_gdb_index(CPUState *cpu)

>  {

>  #if defined(CONFIG_USER_ONLY)

>      return cpu->host_tid;


I like this solution

Reviewed-by: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
Philippe Mathieu-Daudé June 2, 2017, 5:02 a.m. UTC | #3
On 06/01/2017 11:49 AM, Alex Bennée wrote:
> This is to make it clear the index is purely a gdbstub function and

> should not be confused with the value of cpu->cpu_index.

>

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>


Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


> ---

>  gdbstub.c              | 12 ++++++------

>  include/exec/gdbstub.h |  7 ++++++-

>  2 files changed, 12 insertions(+), 7 deletions(-)

>

> diff --git a/gdbstub.c b/gdbstub.c

> index a249846954..026d1fe6bb 100644

> --- a/gdbstub.c

> +++ b/gdbstub.c

> @@ -837,7 +837,7 @@ static CPUState *find_cpu(uint32_t thread_id)

>      CPUState *cpu;

>

>      CPU_FOREACH(cpu) {

> -        if (cpu_index(cpu) == thread_id) {

> +        if (cpu_gdb_index(cpu) == thread_id) {

>              return cpu;

>          }

>      }

> @@ -925,7 +925,7 @@ static int gdb_handle_vcont(GDBState *s, const char *p)

>              idx = tmp;

>              /* 0 means any thread, so we pick the first valid CPU */

>              if (!idx) {

> -                idx = cpu_index(first_cpu);

> +                idx = cpu_gdb_index(first_cpu);

>              }

>

>              /*

> @@ -975,7 +975,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)

>      case '?':

>          /* TODO: Make this return the correct value for user-mode.  */

>          snprintf(buf, sizeof(buf), "T%02xthread:%02x;", GDB_SIGNAL_TRAP,

> -                 cpu_index(s->c_cpu));

> +                 cpu_gdb_index(s->c_cpu));

>          put_packet(s, buf);

>          /* Remove all the breakpoints when this query is issued,

>           * because gdb is doing and initial connect and the state

> @@ -1243,7 +1243,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)

>          } else if (strcmp(p,"sThreadInfo") == 0) {

>          report_cpuinfo:

>              if (s->query_cpu) {

> -                snprintf(buf, sizeof(buf), "m%x", cpu_index(s->query_cpu));

> +                snprintf(buf, sizeof(buf), "m%x", cpu_gdb_index(s->query_cpu));

>                  put_packet(s, buf);

>                  s->query_cpu = CPU_NEXT(s->query_cpu);

>              } else

> @@ -1400,7 +1400,7 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state)

>              }

>              snprintf(buf, sizeof(buf),

>                       "T%02xthread:%02x;%swatch:" TARGET_FMT_lx ";",

> -                     GDB_SIGNAL_TRAP, cpu_index(cpu), type,

> +                     GDB_SIGNAL_TRAP, cpu_gdb_index(cpu), type,

>                       (target_ulong)cpu->watchpoint_hit->vaddr);

>              cpu->watchpoint_hit = NULL;

>              goto send_packet;

> @@ -1434,7 +1434,7 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state)

>          break;

>      }

>      gdb_set_stop_cpu(cpu);

> -    snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret, cpu_index(cpu));

> +    snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret, cpu_gdb_index(cpu));

>

>  send_packet:

>      put_packet(s, buf);

> diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h

> index f9708bbcd6..c4fe567600 100644

> --- a/include/exec/gdbstub.h

> +++ b/include/exec/gdbstub.h

> @@ -58,7 +58,12 @@ void gdb_register_coprocessor(CPUState *cpu,

>                                gdb_reg_cb get_reg, gdb_reg_cb set_reg,

>                                int num_regs, const char *xml, int g_pos);

>

> -static inline int cpu_index(CPUState *cpu)

> +/* Return the GDB index for a given vCPU state.

> + *

> + * For user mode this is simply the thread id. In system mode GDB

> + * numbers CPUs from 1 as 0 is reserved as an "any cpu" index.

> + */

> +static inline int cpu_gdb_index(CPUState *cpu)

>  {

>  #if defined(CONFIG_USER_ONLY)

>      return cpu->host_tid;

>
diff mbox series

Patch

diff --git a/gdbstub.c b/gdbstub.c
index a249846954..026d1fe6bb 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -837,7 +837,7 @@  static CPUState *find_cpu(uint32_t thread_id)
     CPUState *cpu;
 
     CPU_FOREACH(cpu) {
-        if (cpu_index(cpu) == thread_id) {
+        if (cpu_gdb_index(cpu) == thread_id) {
             return cpu;
         }
     }
@@ -925,7 +925,7 @@  static int gdb_handle_vcont(GDBState *s, const char *p)
             idx = tmp;
             /* 0 means any thread, so we pick the first valid CPU */
             if (!idx) {
-                idx = cpu_index(first_cpu);
+                idx = cpu_gdb_index(first_cpu);
             }
 
             /*
@@ -975,7 +975,7 @@  static int gdb_handle_packet(GDBState *s, const char *line_buf)
     case '?':
         /* TODO: Make this return the correct value for user-mode.  */
         snprintf(buf, sizeof(buf), "T%02xthread:%02x;", GDB_SIGNAL_TRAP,
-                 cpu_index(s->c_cpu));
+                 cpu_gdb_index(s->c_cpu));
         put_packet(s, buf);
         /* Remove all the breakpoints when this query is issued,
          * because gdb is doing and initial connect and the state
@@ -1243,7 +1243,7 @@  static int gdb_handle_packet(GDBState *s, const char *line_buf)
         } else if (strcmp(p,"sThreadInfo") == 0) {
         report_cpuinfo:
             if (s->query_cpu) {
-                snprintf(buf, sizeof(buf), "m%x", cpu_index(s->query_cpu));
+                snprintf(buf, sizeof(buf), "m%x", cpu_gdb_index(s->query_cpu));
                 put_packet(s, buf);
                 s->query_cpu = CPU_NEXT(s->query_cpu);
             } else
@@ -1400,7 +1400,7 @@  static void gdb_vm_state_change(void *opaque, int running, RunState state)
             }
             snprintf(buf, sizeof(buf),
                      "T%02xthread:%02x;%swatch:" TARGET_FMT_lx ";",
-                     GDB_SIGNAL_TRAP, cpu_index(cpu), type,
+                     GDB_SIGNAL_TRAP, cpu_gdb_index(cpu), type,
                      (target_ulong)cpu->watchpoint_hit->vaddr);
             cpu->watchpoint_hit = NULL;
             goto send_packet;
@@ -1434,7 +1434,7 @@  static void gdb_vm_state_change(void *opaque, int running, RunState state)
         break;
     }
     gdb_set_stop_cpu(cpu);
-    snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret, cpu_index(cpu));
+    snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret, cpu_gdb_index(cpu));
 
 send_packet:
     put_packet(s, buf);
diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
index f9708bbcd6..c4fe567600 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -58,7 +58,12 @@  void gdb_register_coprocessor(CPUState *cpu,
                               gdb_reg_cb get_reg, gdb_reg_cb set_reg,
                               int num_regs, const char *xml, int g_pos);
 
-static inline int cpu_index(CPUState *cpu)
+/* Return the GDB index for a given vCPU state.
+ *
+ * For user mode this is simply the thread id. In system mode GDB
+ * numbers CPUs from 1 as 0 is reserved as an "any cpu" index.
+ */
+static inline int cpu_gdb_index(CPUState *cpu)
 {
 #if defined(CONFIG_USER_ONLY)
     return cpu->host_tid;