All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 0/4] some gdbstub fixes for debug and vcont
@ 2017-06-02 13:05 Alex Bennée
  2017-06-02 13:05 ` [Qemu-devel] [PATCH v3 1/4] gdbstub: modernise DEBUG_GDB Alex Bennée
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Alex Bennée @ 2017-06-02 13:05 UTC (permalink / raw)
  To: peter.maydell, pbonzini, doug16k, imbrenda; +Cc: qemu-devel, Alex Bennée

Hi,

This is v3 and hopefully the final version the gdbstub fixes. There is
one minor change to patch two where I pulled forward the move of
cpu_gdb_index into gdbstub.c from the third patch.

Otherwise it is basically a re-base and a whole host of Reviewed-by
tags.

So the final question is who's tree is going to accept these patches?

The gdbstub is currently marked as "Odd fixes" via qemu-devel. If no
one wants to take it via their tree and Peter is happy I can roll the
pullreq directly.

Alex Bennée (4):
  gdbstub: modernise DEBUG_GDB
  gdbstub: rename cpu_index -> cpu_gdb_index
  qom/cpu: remove host_tid field
  gdbstub: don't fail on vCont;C04:0;c packets

 gdbstub.c              | 117 ++++++++++++++++++++++++-------------------------
 include/exec/gdbstub.h |   9 ----
 include/qom/cpu.h      |   2 -
 linux-user/syscall.c   |   1 -
 4 files changed, 57 insertions(+), 72 deletions(-)

-- 
2.13.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH v3 1/4] gdbstub: modernise DEBUG_GDB
  2017-06-02 13:05 [Qemu-devel] [PATCH v3 0/4] some gdbstub fixes for debug and vcont Alex Bennée
@ 2017-06-02 13:05 ` Alex Bennée
  2017-06-02 13:05 ` [Qemu-devel] [PATCH v3 2/4] gdbstub: rename cpu_index -> cpu_gdb_index Alex Bennée
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Alex Bennée @ 2017-06-02 13:05 UTC (permalink / raw)
  To: peter.maydell, pbonzini, doug16k, imbrenda; +Cc: qemu-devel, Alex Bennée

Convert the a gdb_debug helper which compiles away to nothing when not
used but still ensures the format strings are checked. There is some
minor code motion for the incorrect checksum message to report it
before we attempt to send the reply.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Greg Kurz <groug@kaod.org>
---
 gdbstub.c | 77 +++++++++++++++++++++++++++------------------------------------
 1 file changed, 33 insertions(+), 44 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 86eed4f97c..a249846954 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -271,7 +271,20 @@ static int gdb_signal_to_target (int sig)
         return -1;
 }
 
-//#define DEBUG_GDB
+/* #define DEBUG_GDB */
+
+#ifdef DEBUG_GDB
+# define DEBUG_GDB_GATE 1
+#else
+# define DEBUG_GDB_GATE 0
+#endif
+
+#define gdb_debug(fmt, ...) do { \
+    if (DEBUG_GDB_GATE) { \
+        fprintf(stderr, "%s: " fmt, __func__, ## __VA_ARGS__); \
+    } \
+} while (0)
+
 
 typedef struct GDBRegisterState {
     int base_reg;
@@ -547,9 +560,7 @@ static int put_packet_binary(GDBState *s, const char *buf, int len)
 /* return -1 if error, 0 if OK */
 static int put_packet(GDBState *s, const char *buf)
 {
-#ifdef DEBUG_GDB
-    printf("reply='%s'\n", buf);
-#endif
+    gdb_debug("reply='%s'\n", buf);
 
     return put_packet_binary(s, buf, strlen(buf));
 }
@@ -955,9 +966,9 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
     uint8_t *registers;
     target_ulong addr, len;
 
-#ifdef DEBUG_GDB
-    printf("command='%s'\n", line_buf);
-#endif
+
+    gdb_debug("command='%s'\n", line_buf);
+
     p = line_buf;
     ch = *p++;
     switch(ch) {
@@ -1518,17 +1529,14 @@ static void gdb_read_byte(GDBState *s, int ch)
         /* Waiting for a response to the last packet.  If we see the start
            of a new command then abandon the previous response.  */
         if (ch == '-') {
-#ifdef DEBUG_GDB
-            printf("Got NACK, retransmitting\n");
-#endif
+            gdb_debug("Got NACK, retransmitting\n");
             put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len);
+        } else if (ch == '+') {
+            gdb_debug("Got ACK\n");
+        } else {
+            gdb_debug("Got '%c' when expecting ACK/NACK\n", ch);
         }
-#ifdef DEBUG_GDB
-        else if (ch == '+')
-            printf("Got ACK\n");
-        else
-            printf("Got '%c' when expecting ACK/NACK\n", ch);
-#endif
+
         if (ch == '+' || ch == '$')
             s->last_packet_len = 0;
         if (ch != '$')
@@ -1549,9 +1557,7 @@ static void gdb_read_byte(GDBState *s, int ch)
                 s->line_sum = 0;
                 s->state = RS_GETLINE;
             } else {
-#ifdef DEBUG_GDB
-                printf("gdbstub received garbage between packets: 0x%x\n", ch);
-#endif
+                gdb_debug("received garbage between packets: 0x%x\n", ch);
             }
             break;
         case RS_GETLINE:
@@ -1567,9 +1573,7 @@ static void gdb_read_byte(GDBState *s, int ch)
                 /* end of command, start of checksum*/
                 s->state = RS_CHKSUM1;
             } else if (s->line_buf_index >= sizeof(s->line_buf) - 1) {
-#ifdef DEBUG_GDB
-                printf("gdbstub command buffer overrun, dropping command\n");
-#endif
+                gdb_debug("command buffer overrun, dropping command\n");
                 s->state = RS_IDLE;
             } else {
                 /* unescaped command character */
@@ -1583,9 +1587,7 @@ static void gdb_read_byte(GDBState *s, int ch)
                 s->state = RS_CHKSUM1;
             } else if (s->line_buf_index >= sizeof(s->line_buf) - 1) {
                 /* command buffer overrun */
-#ifdef DEBUG_GDB
-                printf("gdbstub command buffer overrun, dropping command\n");
-#endif
+                gdb_debug("command buffer overrun, dropping command\n");
                 s->state = RS_IDLE;
             } else {
                 /* parse escaped character and leave escape state */
@@ -1597,25 +1599,18 @@ static void gdb_read_byte(GDBState *s, int ch)
         case RS_GETLINE_RLE:
             if (ch < ' ') {
                 /* invalid RLE count encoding */
-#ifdef DEBUG_GDB
-                printf("gdbstub got invalid RLE count: 0x%x\n", ch);
-#endif
+                gdb_debug("got invalid RLE count: 0x%x\n", ch);
                 s->state = RS_GETLINE;
             } else {
                 /* decode repeat length */
                 int repeat = (unsigned char)ch - ' ' + 3;
                 if (s->line_buf_index + repeat >= sizeof(s->line_buf) - 1) {
                     /* that many repeats would overrun the command buffer */
-#ifdef DEBUG_GDB
-                    printf("gdbstub command buffer overrun,"
-                           " dropping command\n");
-#endif
+                    gdb_debug("command buffer overrun, dropping command\n");
                     s->state = RS_IDLE;
                 } else if (s->line_buf_index < 1) {
                     /* got a repeat but we have nothing to repeat */
-#ifdef DEBUG_GDB
-                    printf("gdbstub got invalid RLE sequence\n");
-#endif
+                    gdb_debug("got invalid RLE sequence\n");
                     s->state = RS_GETLINE;
                 } else {
                     /* repeat the last character */
@@ -1630,9 +1625,7 @@ static void gdb_read_byte(GDBState *s, int ch)
         case RS_CHKSUM1:
             /* get high hex digit of checksum */
             if (!isxdigit(ch)) {
-#ifdef DEBUG_GDB
-                printf("gdbstub got invalid command checksum digit\n");
-#endif
+                gdb_debug("got invalid command checksum digit\n");
                 s->state = RS_GETLINE;
                 break;
             }
@@ -1643,21 +1636,17 @@ static void gdb_read_byte(GDBState *s, int ch)
         case RS_CHKSUM2:
             /* get low hex digit of checksum */
             if (!isxdigit(ch)) {
-#ifdef DEBUG_GDB
-                printf("gdbstub got invalid command checksum digit\n");
-#endif
+                gdb_debug("got invalid command checksum digit\n");
                 s->state = RS_GETLINE;
                 break;
             }
             s->line_csum |= fromhex(ch);
 
             if (s->line_csum != (s->line_sum & 0xff)) {
+                gdb_debug("got command packet with incorrect checksum\n");
                 /* send NAK reply */
                 reply = '-';
                 put_buffer(s, &reply, 1);
-#ifdef DEBUG_GDB
-                printf("gdbstub got command packet with incorrect checksum\n");
-#endif
                 s->state = RS_IDLE;
             } else {
                 /* send ACK reply */
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH v3 2/4] gdbstub: rename cpu_index -> cpu_gdb_index
  2017-06-02 13:05 [Qemu-devel] [PATCH v3 0/4] some gdbstub fixes for debug and vcont Alex Bennée
  2017-06-02 13:05 ` [Qemu-devel] [PATCH v3 1/4] gdbstub: modernise DEBUG_GDB Alex Bennée
@ 2017-06-02 13:05 ` Alex Bennée
  2017-06-02 13:05 ` [Qemu-devel] [PATCH v3 3/4] qom/cpu: remove host_tid field Alex Bennée
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Alex Bennée @ 2017-06-02 13:05 UTC (permalink / raw)
  To: peter.maydell, pbonzini, doug16k, imbrenda; +Cc: qemu-devel, Alex Bennée

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. At the same
time we move the function from the header to gdbstub itself which will
help with later changes.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

---
v3
  - move cpu_gdb_index into gdbstub
---
 gdbstub.c              | 26 ++++++++++++++++++++------
 include/exec/gdbstub.h |  9 ---------
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index a249846954..57befe16e2 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -55,6 +55,20 @@ static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr,
     return cpu_memory_rw_debug(cpu, addr, buf, len, is_write);
 }
 
+/* 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;
+#else
+    return cpu->cpu_index + 1;
+#endif
+}
+
 enum {
     GDB_SIGNAL_0 = 0,
     GDB_SIGNAL_INT = 2,
@@ -837,7 +851,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 +939,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 +989,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 +1257,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 +1414,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 +1448,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..9aa7756d92 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -58,15 +58,6 @@ 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)
-{
-#if defined(CONFIG_USER_ONLY)
-    return cpu->host_tid;
-#else
-    return cpu->cpu_index + 1;
-#endif
-}
-
 /* The GDB remote protocol transfers values in target byte order.  This means
  * we can use the raw memory access routines to access the value buffer.
  * Conveniently, these also handle the case where the buffer is mis-aligned.
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH v3 3/4] qom/cpu: remove host_tid field
  2017-06-02 13:05 [Qemu-devel] [PATCH v3 0/4] some gdbstub fixes for debug and vcont Alex Bennée
  2017-06-02 13:05 ` [Qemu-devel] [PATCH v3 1/4] gdbstub: modernise DEBUG_GDB Alex Bennée
  2017-06-02 13:05 ` [Qemu-devel] [PATCH v3 2/4] gdbstub: rename cpu_index -> cpu_gdb_index Alex Bennée
@ 2017-06-02 13:05 ` Alex Bennée
  2017-06-05 13:47   ` Paolo Bonzini
  2017-06-02 13:05 ` [Qemu-devel] [PATCH v3 4/4] gdbstub: don't fail on vCont; C04:0; c packets Alex Bennée
  2017-06-05 13:48 ` [Qemu-devel] [PATCH v3 0/4] some gdbstub fixes for debug and vcont Paolo Bonzini
  4 siblings, 1 reply; 9+ messages in thread
From: Alex Bennée @ 2017-06-02 13:05 UTC (permalink / raw)
  To: peter.maydell, pbonzini, doug16k, imbrenda
  Cc: qemu-devel, Alex Bennée, Riku Voipio, Laurent Vivier

This was only used by the gdbstub and even then was only being set for
subsequent threads. Rather the continue duplicating the number just
make the gdbstub get the information from TaskState structure.

Now the tid is correctly reported for all threads the bug I was seeing
with "vCont;C04:0;c" packets is fixed as the correct tid is reported
to gdb.

I moved cpu_gdb_index into the gdbstub to facilitate easy access to
the TaskState which is used elsewhere in gdbstub.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>

---
v3
  - fix merge, did move of function in previous commit
---
 gdbstub.c            | 3 ++-
 include/qom/cpu.h    | 2 --
 linux-user/syscall.c | 1 -
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 57befe16e2..45a3a0b16b 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -63,7 +63,8 @@ static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr,
 static inline int cpu_gdb_index(CPUState *cpu)
 {
 #if defined(CONFIG_USER_ONLY)
-    return cpu->host_tid;
+    TaskState *ts = (TaskState *) cpu->opaque;
+    return ts->ts_tid;
 #else
     return cpu->cpu_index + 1;
 #endif
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 55214ce131..909e7ae994 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -266,7 +266,6 @@ struct qemu_work_item;
  * @nr_cores: Number of cores within this CPU package.
  * @nr_threads: Number of threads within this CPU.
  * @numa_node: NUMA node this CPU is belonging to.
- * @host_tid: Host thread ID.
  * @running: #true if CPU is currently running (lockless).
  * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end;
  * valid under cpu_list_lock.
@@ -321,7 +320,6 @@ struct CPUState {
     HANDLE hThread;
 #endif
     int thread_id;
-    uint32_t host_tid;
     bool running, has_waiter;
     struct QemuCond *halt_cond;
     bool thread_kicked;
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 925ae11ea6..003943b736 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6219,7 +6219,6 @@ static void *clone_func(void *arg)
     thread_cpu = cpu;
     ts = (TaskState *)cpu->opaque;
     info->tid = gettid();
-    cpu->host_tid = info->tid;
     task_settid(ts);
     if (info->child_tidptr)
         put_user_u32(info->tid, info->child_tidptr);
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH v3 4/4] gdbstub: don't fail on vCont; C04:0; c packets
  2017-06-02 13:05 [Qemu-devel] [PATCH v3 0/4] some gdbstub fixes for debug and vcont Alex Bennée
                   ` (2 preceding siblings ...)
  2017-06-02 13:05 ` [Qemu-devel] [PATCH v3 3/4] qom/cpu: remove host_tid field Alex Bennée
@ 2017-06-02 13:05 ` Alex Bennée
  2017-06-05 20:56   ` Philippe Mathieu-Daudé
  2017-06-05 13:48 ` [Qemu-devel] [PATCH v3 0/4] some gdbstub fixes for debug and vcont Paolo Bonzini
  4 siblings, 1 reply; 9+ messages in thread
From: Alex Bennée @ 2017-06-02 13:05 UTC (permalink / raw)
  To: peter.maydell, pbonzini, doug16k, imbrenda; +Cc: qemu-devel, Alex Bennée

The thread-id of 0 means any CPU but we then ignore the fact we find
the first_cpu in this case who can have an index of 0. Instead of
bailing out just test if we have managed to match up thread-id to a
CPU.

Otherwise you get:
  gdb_handle_packet: command='vCont;C04:0;c'
  put_packet: reply='E22'

The actual reason for gdb sending vCont;C04:0;c was fixed in a
previous commit where we ensure the first_cpu's tid is correctly
reported to gdb however we should still behave correctly next time it
does send 0.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>

---
v2
  - used Greg's less convoluted suggestion
  - expand commit message
---
 gdbstub.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 45a3a0b16b..6b1e72e9f7 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -937,23 +937,16 @@ static int gdb_handle_vcont(GDBState *s, const char *p)
             if (res) {
                 goto out;
             }
-            idx = tmp;
+
             /* 0 means any thread, so we pick the first valid CPU */
-            if (!idx) {
-                idx = cpu_gdb_index(first_cpu);
-            }
+            cpu = tmp ? find_cpu(tmp) : first_cpu;
 
-            /*
-             * If we are in user mode, the thread specified is actually a
-             * thread id, and not an index. We need to find the actual
-             * CPU first, and only then we can use its index.
-             */
-            cpu = find_cpu(idx);
             /* invalid CPU/thread specified */
-            if (!idx || !cpu) {
+            if (!cpu) {
                 res = -EINVAL;
                 goto out;
             }
+
             /* only use if no previous match occourred */
             if (newstates[cpu->cpu_index] == 1) {
                 newstates[cpu->cpu_index] = cur_action;
-- 
2.13.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v3 3/4] qom/cpu: remove host_tid field
  2017-06-02 13:05 ` [Qemu-devel] [PATCH v3 3/4] qom/cpu: remove host_tid field Alex Bennée
@ 2017-06-05 13:47   ` Paolo Bonzini
  2017-06-05 15:10     ` Alex Bennée
  0 siblings, 1 reply; 9+ messages in thread
From: Paolo Bonzini @ 2017-06-05 13:47 UTC (permalink / raw)
  To: Alex Bennée, peter.maydell, doug16k, imbrenda
  Cc: qemu-devel, Riku Voipio, Laurent Vivier



On 02/06/2017 15:05, Alex Bennée wrote:
> This was only used by the gdbstub and even then was only being set for
> subsequent threads. Rather the continue duplicating the number just
> make the gdbstub get the information from TaskState structure.
> 
> Now the tid is correctly reported for all threads the bug I was seeing
> with "vCont;C04:0;c" packets is fixed as the correct tid is reported
> to gdb.
> 
> I moved cpu_gdb_index into the gdbstub to facilitate easy access to
> the TaskState which is used elsewhere in gdbstub.

I think bsd-user does not have ts_tid?

Thanks,

Paolo

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reviewed-by: Greg Kurz <groug@kaod.org>
> Reviewed-by: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> Reviewed-by: Laurent Vivier <laurent@vivier.eu>
> 
> ---
> v3
>   - fix merge, did move of function in previous commit
> ---
>  gdbstub.c            | 3 ++-
>  include/qom/cpu.h    | 2 --
>  linux-user/syscall.c | 1 -
>  3 files changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/gdbstub.c b/gdbstub.c
> index 57befe16e2..45a3a0b16b 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -63,7 +63,8 @@ static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr,
>  static inline int cpu_gdb_index(CPUState *cpu)
>  {
>  #if defined(CONFIG_USER_ONLY)
> -    return cpu->host_tid;
> +    TaskState *ts = (TaskState *) cpu->opaque;
> +    return ts->ts_tid;
>  #else
>      return cpu->cpu_index + 1;
>  #endif
> diff --git a/include/qom/cpu.h b/include/qom/cpu.h
> index 55214ce131..909e7ae994 100644
> --- a/include/qom/cpu.h
> +++ b/include/qom/cpu.h
> @@ -266,7 +266,6 @@ struct qemu_work_item;
>   * @nr_cores: Number of cores within this CPU package.
>   * @nr_threads: Number of threads within this CPU.
>   * @numa_node: NUMA node this CPU is belonging to.
> - * @host_tid: Host thread ID.
>   * @running: #true if CPU is currently running (lockless).
>   * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end;
>   * valid under cpu_list_lock.
> @@ -321,7 +320,6 @@ struct CPUState {
>      HANDLE hThread;
>  #endif
>      int thread_id;
> -    uint32_t host_tid;
>      bool running, has_waiter;
>      struct QemuCond *halt_cond;
>      bool thread_kicked;
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 925ae11ea6..003943b736 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -6219,7 +6219,6 @@ static void *clone_func(void *arg)
>      thread_cpu = cpu;
>      ts = (TaskState *)cpu->opaque;
>      info->tid = gettid();
> -    cpu->host_tid = info->tid;
>      task_settid(ts);
>      if (info->child_tidptr)
>          put_user_u32(info->tid, info->child_tidptr);
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v3 0/4] some gdbstub fixes for debug and vcont
  2017-06-02 13:05 [Qemu-devel] [PATCH v3 0/4] some gdbstub fixes for debug and vcont Alex Bennée
                   ` (3 preceding siblings ...)
  2017-06-02 13:05 ` [Qemu-devel] [PATCH v3 4/4] gdbstub: don't fail on vCont; C04:0; c packets Alex Bennée
@ 2017-06-05 13:48 ` Paolo Bonzini
  4 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2017-06-05 13:48 UTC (permalink / raw)
  To: Alex Bennée, peter.maydell, doug16k, imbrenda; +Cc: qemu-devel



On 02/06/2017 15:05, Alex Bennée wrote:
> Hi,
> 
> This is v3 and hopefully the final version the gdbstub fixes. There is
> one minor change to patch two where I pulled forward the move of
> cpu_gdb_index into gdbstub.c from the third patch.
> 
> Otherwise it is basically a re-base and a whole host of Reviewed-by
> tags.
> 
> So the final question is who's tree is going to accept these patches?
> 
> The gdbstub is currently marked as "Odd fixes" via qemu-devel. If no
> one wants to take it via their tree and Peter is happy I can roll the
> pullreq directly.

With pleasure (but I reported an issue on patch 3).

Thanks,

Paolo

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v3 3/4] qom/cpu: remove host_tid field
  2017-06-05 13:47   ` Paolo Bonzini
@ 2017-06-05 15:10     ` Alex Bennée
  0 siblings, 0 replies; 9+ messages in thread
From: Alex Bennée @ 2017-06-05 15:10 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: peter.maydell, doug16k, imbrenda, qemu-devel, Riku Voipio,
	Laurent Vivier


Paolo Bonzini <pbonzini@redhat.com> writes:

> On 02/06/2017 15:05, Alex Bennée wrote:
>> This was only used by the gdbstub and even then was only being set for
>> subsequent threads. Rather the continue duplicating the number just
>> make the gdbstub get the information from TaskState structure.
>>
>> Now the tid is correctly reported for all threads the bug I was seeing
>> with "vCont;C04:0;c" packets is fixed as the correct tid is reported
>> to gdb.
>>
>> I moved cpu_gdb_index into the gdbstub to facilitate easy access to
>> the TaskState which is used elsewhere in gdbstub.
>
> I think bsd-user does not have ts_tid?

I'll test the build on BSD, I think I have a VM somewhere.

>
> Thanks,
>
> Paolo
>
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> Reviewed-by: Greg Kurz <groug@kaod.org>
>> Reviewed-by: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
>> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> Reviewed-by: Laurent Vivier <laurent@vivier.eu>
>>
>> ---
>> v3
>>   - fix merge, did move of function in previous commit
>> ---
>>  gdbstub.c            | 3 ++-
>>  include/qom/cpu.h    | 2 --
>>  linux-user/syscall.c | 1 -
>>  3 files changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/gdbstub.c b/gdbstub.c
>> index 57befe16e2..45a3a0b16b 100644
>> --- a/gdbstub.c
>> +++ b/gdbstub.c
>> @@ -63,7 +63,8 @@ static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr,
>>  static inline int cpu_gdb_index(CPUState *cpu)
>>  {
>>  #if defined(CONFIG_USER_ONLY)
>> -    return cpu->host_tid;
>> +    TaskState *ts = (TaskState *) cpu->opaque;
>> +    return ts->ts_tid;
>>  #else
>>      return cpu->cpu_index + 1;
>>  #endif
>> diff --git a/include/qom/cpu.h b/include/qom/cpu.h
>> index 55214ce131..909e7ae994 100644
>> --- a/include/qom/cpu.h
>> +++ b/include/qom/cpu.h
>> @@ -266,7 +266,6 @@ struct qemu_work_item;
>>   * @nr_cores: Number of cores within this CPU package.
>>   * @nr_threads: Number of threads within this CPU.
>>   * @numa_node: NUMA node this CPU is belonging to.
>> - * @host_tid: Host thread ID.
>>   * @running: #true if CPU is currently running (lockless).
>>   * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end;
>>   * valid under cpu_list_lock.
>> @@ -321,7 +320,6 @@ struct CPUState {
>>      HANDLE hThread;
>>  #endif
>>      int thread_id;
>> -    uint32_t host_tid;
>>      bool running, has_waiter;
>>      struct QemuCond *halt_cond;
>>      bool thread_kicked;
>> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
>> index 925ae11ea6..003943b736 100644
>> --- a/linux-user/syscall.c
>> +++ b/linux-user/syscall.c
>> @@ -6219,7 +6219,6 @@ static void *clone_func(void *arg)
>>      thread_cpu = cpu;
>>      ts = (TaskState *)cpu->opaque;
>>      info->tid = gettid();
>> -    cpu->host_tid = info->tid;
>>      task_settid(ts);
>>      if (info->child_tidptr)
>>          put_user_u32(info->tid, info->child_tidptr);
>>


--
Alex Bennée

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PATCH v3 4/4] gdbstub: don't fail on vCont; C04:0; c packets
  2017-06-02 13:05 ` [Qemu-devel] [PATCH v3 4/4] gdbstub: don't fail on vCont; C04:0; c packets Alex Bennée
@ 2017-06-05 20:56   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 9+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-06-05 20:56 UTC (permalink / raw)
  To: Alex Bennée, peter.maydell, pbonzini, doug16k, imbrenda; +Cc: qemu-devel

On 06/02/2017 10:05 AM, Alex Bennée wrote:
> The thread-id of 0 means any CPU but we then ignore the fact we find
> the first_cpu in this case who can have an index of 0. Instead of
> bailing out just test if we have managed to match up thread-id to a
> CPU.
>
> Otherwise you get:
>   gdb_handle_packet: command='vCont;C04:0;c'
>   put_packet: reply='E22'
>
> The actual reason for gdb sending vCont;C04:0;c was fixed in a
> previous commit where we ensure the first_cpu's tid is correctly
> reported to gdb however we should still behave correctly next time it
> does send 0.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reviewed-by: Greg Kurz <groug@kaod.org>
> Reviewed-by: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>

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

>
> ---
> v2
>   - used Greg's less convoluted suggestion
>   - expand commit message
> ---
>  gdbstub.c | 15 ++++-----------
>  1 file changed, 4 insertions(+), 11 deletions(-)
>
> diff --git a/gdbstub.c b/gdbstub.c
> index 45a3a0b16b..6b1e72e9f7 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -937,23 +937,16 @@ static int gdb_handle_vcont(GDBState *s, const char *p)
>              if (res) {
>                  goto out;
>              }
> -            idx = tmp;
> +
>              /* 0 means any thread, so we pick the first valid CPU */
> -            if (!idx) {
> -                idx = cpu_gdb_index(first_cpu);
> -            }
> +            cpu = tmp ? find_cpu(tmp) : first_cpu;
>
> -            /*
> -             * If we are in user mode, the thread specified is actually a
> -             * thread id, and not an index. We need to find the actual
> -             * CPU first, and only then we can use its index.
> -             */
> -            cpu = find_cpu(idx);
>              /* invalid CPU/thread specified */
> -            if (!idx || !cpu) {
> +            if (!cpu) {
>                  res = -EINVAL;
>                  goto out;
>              }
> +
>              /* only use if no previous match occourred */
>              if (newstates[cpu->cpu_index] == 1) {
>                  newstates[cpu->cpu_index] = cur_action;
>

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-06-05 20:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-02 13:05 [Qemu-devel] [PATCH v3 0/4] some gdbstub fixes for debug and vcont Alex Bennée
2017-06-02 13:05 ` [Qemu-devel] [PATCH v3 1/4] gdbstub: modernise DEBUG_GDB Alex Bennée
2017-06-02 13:05 ` [Qemu-devel] [PATCH v3 2/4] gdbstub: rename cpu_index -> cpu_gdb_index Alex Bennée
2017-06-02 13:05 ` [Qemu-devel] [PATCH v3 3/4] qom/cpu: remove host_tid field Alex Bennée
2017-06-05 13:47   ` Paolo Bonzini
2017-06-05 15:10     ` Alex Bennée
2017-06-02 13:05 ` [Qemu-devel] [PATCH v3 4/4] gdbstub: don't fail on vCont; C04:0; c packets Alex Bennée
2017-06-05 20:56   ` Philippe Mathieu-Daudé
2017-06-05 13:48 ` [Qemu-devel] [PATCH v3 0/4] some gdbstub fixes for debug and vcont Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.