All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luc Michel <luc.michel@greensocs.com>
To: qemu-devel@nongnu.org
Cc: "Luc Michel" <luc.michel@greensocs.com>,
	qemu-arm@nongnu.org, "Peter Maydell" <peter.maydell@linaro.org>,
	saipava@xilinx.com, edgari@xilinx.com, alistair@alistair23.me,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	mark.burton@greensocs.com,
	"Eduardo Habkost" <ehabkost@redhat.com>
Subject: [Qemu-devel] [PATCH v5 03/16] gdbstub: add multiprocess support to '?' packets
Date: Sat, 10 Nov 2018 09:11:34 +0100	[thread overview]
Message-ID: <20181110081147.4027-4-luc.michel@greensocs.com> (raw)
In-Reply-To: <20181110081147.4027-1-luc.michel@greensocs.com>

The gdb_get_cpu_pid() function does the PID lookup for the given CPU. It
checks if the CPU is a direct child of a CPU cluster. If it is, the
returned PID is the cluster ID plus one (cluster IDs start at 0, GDB
PIDs at 1). When the CPU is not a child of such a container, the PID of
the first process is returned.

The gdb_fmt_thread_id() function generates the string to be used to identify
a given thread, in a response packet for the peer. This function
supports generating thread IDs when multiprocess mode is enabled (in the
form `p<pid>.<tid>').

Use them in the reply to a '?' request.

Signed-off-by: Luc Michel <luc.michel@greensocs.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
---
 gdbstub.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 58 insertions(+), 2 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 0d70b89598..d26bad4b67 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -638,10 +638,52 @@ static int memtox(char *buf, const char *mem, int len)
         }
     }
     return p - buf;
 }
 
+static uint32_t gdb_get_cpu_pid(const GDBState *s, CPUState *cpu)
+{
+#ifndef CONFIG_USER_ONLY
+    gchar *path, *name;
+    Object *obj;
+    CPUClusterState *cluster;
+    uint32_t ret;
+
+    path = object_get_canonical_path(OBJECT(cpu));
+    name = object_get_canonical_path_component(OBJECT(cpu));
+
+    if (path == NULL) {
+        ret = s->processes[0].pid;
+        goto out;
+    }
+
+    /*
+     * Retrieve the CPU parent path by removing the last '/' and the CPU name
+     * from the CPU canonical path. */
+    path[strlen(path) - strlen(name) - 1] = '\0';
+
+    obj = object_resolve_path_type(path, TYPE_CPU_CLUSTER, NULL);
+
+    if (obj == NULL) {
+        ret = s->processes[0].pid;
+        goto out;
+    }
+
+    cluster = CPU_CLUSTER(obj);
+    ret = cluster->cluster_id + 1;
+
+out:
+    g_free(name);
+    g_free(path);
+
+    return ret;
+
+#else
+    return s->processes[0].pid;
+#endif
+}
+
 static const char *get_feature_xml(const char *p, const char **newp,
                                    CPUClass *cc)
 {
     size_t len;
     int i;
@@ -907,10 +949,23 @@ static CPUState *find_cpu(uint32_t thread_id)
     }
 
     return NULL;
 }
 
+static char *gdb_fmt_thread_id(const GDBState *s, CPUState *cpu,
+                           char *buf, size_t buf_size)
+{
+    if (s->multiprocess) {
+        snprintf(buf, buf_size, "p%02x.%02x",
+                 gdb_get_cpu_pid(s, cpu), cpu_gdb_index(cpu));
+    } else {
+        snprintf(buf, buf_size, "%02x", cpu_gdb_index(cpu));
+    }
+
+    return buf;
+}
+
 static int is_query_packet(const char *p, const char *query, char separator)
 {
     unsigned int query_len = strlen(query);
 
     return strncmp(p, query, query_len) == 0 &&
@@ -1018,22 +1073,23 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
     const char *p;
     uint32_t thread;
     int ch, reg_size, type, res;
     uint8_t mem_buf[MAX_PACKET_LENGTH];
     char buf[sizeof(mem_buf) + 1 /* trailing NUL */];
+    char thread_id[16];
     uint8_t *registers;
     target_ulong addr, len;
 
     trace_gdbstub_io_command(line_buf);
 
     p = line_buf;
     ch = *p++;
     switch(ch) {
     case '?':
         /* TODO: Make this return the correct value for user-mode.  */
-        snprintf(buf, sizeof(buf), "T%02xthread:%02x;", GDB_SIGNAL_TRAP,
-                 cpu_gdb_index(s->c_cpu));
+        snprintf(buf, sizeof(buf), "T%02xthread:%s;", GDB_SIGNAL_TRAP,
+                 gdb_fmt_thread_id(s, s->c_cpu, thread_id, sizeof(thread_id)));
         put_packet(s, buf);
         /* Remove all the breakpoints when this query is issued,
          * because gdb is doing and initial connect and the state
          * should be cleaned up.
          */
-- 
2.19.1

  parent reply	other threads:[~2018-11-10  8:13 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-10  8:11 [Qemu-devel] [PATCH v5 00/16] gdbstub: support for the multiprocess extension Luc Michel
2018-11-10  8:11 ` [Qemu-devel] [PATCH v5 01/16] hw/cpu: introduce CPU clusters Luc Michel
2018-11-13 10:38   ` [Qemu-devel] [Qemu-arm] " Edgar E. Iglesias
2018-11-10  8:11 ` [Qemu-devel] [PATCH v5 02/16] gdbstub: introduce GDB processes Luc Michel
2018-11-13 10:52   ` [Qemu-devel] [Qemu-arm] " Edgar E. Iglesias
2018-11-14 10:14     ` Luc Michel
2018-11-14 10:31       ` Edgar E. Iglesias
2018-11-10  8:11 ` Luc Michel [this message]
2018-11-13 11:06   ` [Qemu-devel] [Qemu-arm] [PATCH v5 03/16] gdbstub: add multiprocess support to '?' packets Edgar E. Iglesias
2018-11-14  8:43     ` Luc Michel
2018-11-14 10:27       ` Edgar E. Iglesias
2018-11-15  8:00         ` Luc Michel
2018-11-10  8:11 ` [Qemu-devel] [PATCH v5 04/16] gdbstub: add multiprocess support to 'H' and 'T' packets Luc Michel
2018-11-10  8:11 ` [Qemu-devel] [PATCH v5 05/16] gdbstub: add multiprocess support to vCont packets Luc Michel
2018-11-10  8:11 ` [Qemu-devel] [PATCH v5 06/16] gdbstub: add multiprocess support to 'sC' packets Luc Michel
2018-11-10  8:11 ` [Qemu-devel] [PATCH v5 07/16] gdbstub: add multiprocess support to (f|s)ThreadInfo and ThreadExtraInfo Luc Michel
2018-11-10  8:11 ` [Qemu-devel] [PATCH v5 08/16] gdbstub: add multiprocess support to Xfer:features:read: Luc Michel
2018-11-10  8:11 ` [Qemu-devel] [PATCH v5 09/16] gdbstub: add multiprocess support to gdb_vm_state_change() Luc Michel
2018-11-10  8:11 ` [Qemu-devel] [PATCH v5 10/16] gdbstub: add multiprocess support to 'D' packets Luc Michel
2018-11-10  8:11 ` [Qemu-devel] [PATCH v5 11/16] gdbstub: add support for extended mode packet Luc Michel
2018-11-10  8:11 ` [Qemu-devel] [PATCH v5 12/16] gdbstub: add support for vAttach packets Luc Michel
2018-11-10  8:11 ` [Qemu-devel] [PATCH v5 13/16] gdbstub: processes initialization on new peer connection Luc Michel
2018-11-10  8:11 ` [Qemu-devel] [PATCH v5 14/16] gdbstub: gdb_set_stop_cpu: ignore request when process is not attached Luc Michel
2018-11-10  8:11 ` [Qemu-devel] [PATCH v5 15/16] gdbstub: add multiprocess extension support Luc Michel
2018-11-10  8:11 ` [Qemu-devel] [PATCH v5 16/16] arm/xlnx-zynqmp: put APUs and RPUs in separate CPU clusters Luc Michel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181110081147.4027-4-luc.michel@greensocs.com \
    --to=luc.michel@greensocs.com \
    --cc=alistair@alistair23.me \
    --cc=edgari@xilinx.com \
    --cc=ehabkost@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=mark.burton@greensocs.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=saipava@xilinx.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.