From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45817) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNb2B-0003pc-Ld for qemu-devel@nongnu.org; Fri, 16 Nov 2018 05:07:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNb29-0001zP-MU for qemu-devel@nongnu.org; Fri, 16 Nov 2018 05:07:31 -0500 Date: Fri, 16 Nov 2018 11:06:59 +0100 From: "Edgar E. Iglesias" Message-ID: <20181116100659.GR7447@toto> References: <20181115094207.22846-1-luc.michel@greensocs.com> <20181115094207.22846-9-luc.michel@greensocs.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <20181115094207.22846-9-luc.michel@greensocs.com> Subject: Re: [Qemu-devel] [PATCH v6 08/16] gdbstub: add multiprocess support to Xfer:features:read: List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luc Michel Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org, Peter Maydell , saipava@xilinx.com, edgari@xilinx.com, alistair@alistair23.me, Philippe =?iso-8859-1?Q?Mathieu-Daud=E9?= , mark.burton@greensocs.com, Eduardo Habkost On Thu, Nov 15, 2018 at 10:41:59AM +0100, Luc Michel wrote: > Change the Xfer:features:read: packet handling to support the > multiprocess extension. This packet is used to request the XML > description of the CPU. In multiprocess mode, different descriptions can > be sent for different processes. >=20 > This function now takes the process to send the description for as a > parameter, and use a buffer in the process structure to store the > generated description. >=20 > It takes the first CPU of the process to generate the description. >=20 > Signed-off-by: Luc Michel > Reviewed-by: Philippe Mathieu-Daud=E9 Reviewed-by: Edgar E. Iglesias > --- > gdbstub.c | 47 +++++++++++++++++++++++++++-------------------- > 1 file changed, 27 insertions(+), 20 deletions(-) >=20 > diff --git a/gdbstub.c b/gdbstub.c > index 292dee8914..4cbc81ae5b 100644 > --- a/gdbstub.c > +++ b/gdbstub.c > @@ -298,10 +298,12 @@ typedef struct GDBRegisterState { > } GDBRegisterState; > =20 > typedef struct GDBProcess { > uint32_t pid; > bool attached; > + > + char target_xml[1024]; > } GDBProcess; > =20 > enum RSState { > RS_INACTIVE, > RS_IDLE, > @@ -804,55 +806,57 @@ static CPUState *gdb_first_cpu(const GDBState *s) > } > =20 > return cpu; > } > =20 > -static const char *get_feature_xml(const char *p, const char **newp, > - CPUClass *cc) > +static const char *get_feature_xml(const GDBState *s, const char *p, > + const char **newp, GDBProcess *proces= s) > { > size_t len; > int i; > const char *name; > - static char target_xml[1024]; > + CPUState *cpu =3D get_first_cpu_in_process(s, process); > + CPUClass *cc =3D CPU_GET_CLASS(cpu); > =20 > len =3D 0; > while (p[len] && p[len] !=3D ':') > len++; > *newp =3D p + len; > =20 > name =3D NULL; > if (strncmp(p, "target.xml", len) =3D=3D 0) { > + char *buf =3D process->target_xml; > + const size_t buf_sz =3D sizeof(process->target_xml); > + > /* Generate the XML description for this CPU. */ > - if (!target_xml[0]) { > + if (!buf[0]) { > GDBRegisterState *r; > - CPUState *cpu =3D first_cpu; > =20 > - pstrcat(target_xml, sizeof(target_xml), > + pstrcat(buf, buf_sz, > "" > "" > ""); > if (cc->gdb_arch_name) { > gchar *arch =3D cc->gdb_arch_name(cpu); > - pstrcat(target_xml, sizeof(target_xml), ""= ); > - pstrcat(target_xml, sizeof(target_xml), arch); > - pstrcat(target_xml, sizeof(target_xml), "= "); > + pstrcat(buf, buf_sz, ""); > + pstrcat(buf, buf_sz, arch); > + pstrcat(buf, buf_sz, ""); > g_free(arch); > } > - pstrcat(target_xml, sizeof(target_xml), " - pstrcat(target_xml, sizeof(target_xml), cc->gdb_core_xml_fil= e); > - pstrcat(target_xml, sizeof(target_xml), "\"/>"); > + pstrcat(buf, buf_sz, " + pstrcat(buf, buf_sz, cc->gdb_core_xml_file); > + pstrcat(buf, buf_sz, "\"/>"); > for (r =3D cpu->gdb_regs; r; r =3D r->next) { > - pstrcat(target_xml, sizeof(target_xml), " - pstrcat(target_xml, sizeof(target_xml), r->xml); > - pstrcat(target_xml, sizeof(target_xml), "\"/>"); > + pstrcat(buf, buf_sz, " + pstrcat(buf, buf_sz, r->xml); > + pstrcat(buf, buf_sz, "\"/>"); > } > - pstrcat(target_xml, sizeof(target_xml), ""); > + pstrcat(buf, buf_sz, ""); > } > - return target_xml; > + return buf; > } > if (cc->gdb_get_dynamic_xml) { > - CPUState *cpu =3D first_cpu; > char *xmlname =3D g_strndup(p, len); > const char *xml =3D cc->gdb_get_dynamic_xml(cpu, xmlname); > =20 > g_free(xmlname); > if (xml) { > @@ -1258,10 +1262,11 @@ out: > } > =20 > static int gdb_handle_packet(GDBState *s, const char *line_buf) > { > CPUState *cpu; > + GDBProcess *process; > CPUClass *cc; > const char *p; > uint32_t pid, tid; > int ch, reg_size, type, res; > uint8_t mem_buf[MAX_PACKET_LENGTH]; > @@ -1639,18 +1644,19 @@ static int gdb_handle_packet(GDBState *s, const c= har *line_buf) > } > if (strncmp(p, "Xfer:features:read:", 19) =3D=3D 0) { > const char *xml; > target_ulong total_len; > =20 > - cc =3D CPU_GET_CLASS(first_cpu); > + process =3D gdb_get_cpu_process(s, s->g_cpu); > + cc =3D CPU_GET_CLASS(s->g_cpu); > if (cc->gdb_core_xml_file =3D=3D NULL) { > goto unknown_command; > } > =20 > gdb_has_xml =3D true; > p +=3D 19; > - xml =3D get_feature_xml(p, &p, cc); > + xml =3D get_feature_xml(s, p, &p, process); > if (!xml) { > snprintf(buf, sizeof(buf), "E00"); > put_packet(s, buf); > break; > } > @@ -2323,10 +2329,11 @@ static int find_cpu_clusters(Object *child, void = *opaque) > * runtime, we enforce here that the machine does not use a clus= ter ID > * that would lead to PID 0. */ > assert(process->pid !=3D UINT32_MAX); > process->pid =3D cluster->cluster_id + 1; > process->attached =3D false; > + process->target_xml[0] =3D '\0'; > =20 > return 0; > } > =20 > return object_child_foreach(child, find_cpu_clusters, opaque); > --=20 > 2.19.1 >=20