From nobody Mon Feb 9 12:42:33 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1556786465; cv=none; d=zoho.com; s=zohoarc; b=ja7BIcv4yBgUF24enV2gI7dehjYbQ9SEknoRmh66CLPR+PV9H2KCmO/C8Rp4a5BKpEjGhpHgKCgpQWrBO9aZUjgscF3I59Nc4wsNKJdwy6pqvvlCBXc/ZeMMuoUiJK1R7NHSNZBHERDtZDlEgNs79/ZfdBth/n3Dn/p4S3nDbhc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556786465; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=9rzWu4duvgFxDEBnKAIuNQA/7quDWlJb65aR2J7JxiI=; b=P/QwYjXTn5RkFLrkoOC4KEggw5neWaMwa0u289GRTKi6lvOwfTjrjJIJyGFDRFIaAvppHE/odgLaf7qAqDZUHrXXm5Y8xPvQN0JC/GekMeV3nDF3OvzF2eMkN708OEbZ9DgR2KIwzgocQ2jioq7f9TWyS/IIkWYtkGNgUfp6tDo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556786465861703.9230735818087; Thu, 2 May 2019 01:41:05 -0700 (PDT) Received: from localhost ([127.0.0.1]:47577 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hM7H1-00088B-OQ for importer@patchew.org; Thu, 02 May 2019 04:40:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:42966) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hM6tk-0003bZ-8L for qemu-devel@nongnu.org; Thu, 02 May 2019 04:16:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hM6th-0008Nd-6V for qemu-devel@nongnu.org; Thu, 02 May 2019 04:16:55 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:34197) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hM6te-0007dd-Uh for qemu-devel@nongnu.org; Thu, 02 May 2019 04:16:52 -0400 Received: by mail-wr1-x442.google.com with SMTP id e9so2033954wrc.1 for ; Thu, 02 May 2019 01:16:38 -0700 (PDT) Received: from localhost.localdomain ([176.230.64.186]) by smtp.gmail.com with ESMTPSA id d16sm44698367wra.54.2019.05.02.01.16.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 May 2019 01:16:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9rzWu4duvgFxDEBnKAIuNQA/7quDWlJb65aR2J7JxiI=; b=A4jux+ENCuhtWTSrnCh5ENhh5ZnFcFlzyVcE61x4X8LetUQlEcBnnJBBPbaQ63sMGm /tANAiA/REQ1N/uxjQo/uHH9b+etHDkyIaNFflL3Q5sQfkYBQu0zhzDnR3Kwuf6Ad22M IxbJINqrCnGIYlcbDPB3UiFKS0zrZvaf5FgGKCJf+dea1bipz56Sx0Pfvc4G3q4KxqxH JdbeEIY/GACflhQXLUdW2ZImrIRW3WGdDZ7iHDcI3AaJl2czIJAkF0l9TsYz0EZPUpxV JAMYoBrAKlEv5aEXBrhGzXAhVIL9PTchmhN165luG/djAT8i459XuEssDT4ITigZEEMX s4Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9rzWu4duvgFxDEBnKAIuNQA/7quDWlJb65aR2J7JxiI=; b=nmWgqodjY1GuLqp7mUNpDcl9qrhn15iVM78eHXwVEP/3CFgJxiBqWRrq+Necu66A+4 d/i94tvs/QH3Vm+KZjZApza9WwExDGBC/fFJkV8Tp+IEXHQpSRrbiZ377rpxuetzaNiQ yswNEYYniVx2rrYKsCoRm3a4Anw/LBxU1THEnpAFyK7A2ekJpi97axpnlNHdmIBMChCO e7vCgF/7dFzlbLNjo24YfznCvg29dbuIfNRmAU3MFDYk0edDH3LOqt+WgLqlhZLCyxEe wvcuodpYPf0qbuJMig+PFezyWkXqWrQrs8IZ7E6oDsR4dmlAvAcr9YeENMTHThrcNRw4 TfRA== X-Gm-Message-State: APjAAAXIFReIbwJNR8veRdwu0z/UZ4xIzl9xLEBn55mM3e2Q2QBxrm+o i6Z7w1CfHDMIxIRx7KCD371Ma6LD X-Google-Smtp-Source: APXvYqx32IlAsUvmrU6tQ1611x1T79nzAWtGjpzkSpuw/uN11tg1HGLlmERgqUYy6rQZU8KzbctsWQ== X-Received: by 2002:adf:df04:: with SMTP id y4mr1847896wrl.100.1556784997481; Thu, 02 May 2019 01:16:37 -0700 (PDT) From: Jon Doron To: qemu-devel@nongnu.org Date: Thu, 2 May 2019 11:15:46 +0300 Message-Id: <20190502081554.5521-20-arilou@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190502081554.5521-1-arilou@gmail.com> References: <20190502081554.5521-1-arilou@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v9 19/27] gdbstub: Implement generic set (Q pkt) with new infra X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alex.bennee@linaro.org, Jon Doron Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Jon Doron --- gdbstub.c | 213 +++++++----------------------------------------------- 1 file changed, 25 insertions(+), 188 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 83ae8738cc..2fd0d66f4d 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1130,14 +1130,6 @@ static GDBThreadIdKind read_thread_id(const char *bu= f, const char **end_buf, return GDB_ONE_THREAD; } =20 -static int is_query_packet(const char *p, const char *query, char separato= r) -{ - unsigned int query_len =3D strlen(query); - - return strncmp(p, query, query_len) =3D=3D 0 && - (p[query_len] =3D=3D '\0' || p[query_len] =3D=3D separator); -} - /** * gdb_handle_vcont - Parses and handles a vCont packet. * returns -ENOTSUP if a command is unsupported, -EINVAL or -ERANGE if the= re is @@ -2232,18 +2224,28 @@ static void handle_gen_query(GdbCmdContext *gdb_ctx= , void *user_ctx) } } =20 +static void handle_gen_set(GdbCmdContext *gdb_ctx, void *user_ctx) +{ + if (!gdb_ctx->num_params) { + return; + } + + if (!process_string_cmd(gdb_ctx->s, NULL, gdb_ctx->params[0].data, + gdb_gen_query_set_common_table, + ARRAY_SIZE(gdb_gen_query_set_common_table))) { + return; + } + + put_packet(gdb_ctx->s, ""); +} + 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, type; + int ch; uint8_t mem_buf[MAX_PACKET_LENGTH]; char buf[sizeof(mem_buf) + 1 /* trailing NUL */]; char thread_id[16]; - target_ulong addr, len; const GdbCmdParseEntry *cmd_parser =3D NULL; =20 trace_gdbstub_io_command(line_buf); @@ -2456,182 +2458,17 @@ static int gdb_handle_packet(GDBState *s, const ch= ar *line_buf) } break; case 'Q': - /* parse any 'q' packets here */ - if (!strcmp(p,"qemu.sstepbits")) { - /* Query Breakpoint bit definitions */ - snprintf(buf, sizeof(buf), "ENABLE=3D%x,NOIRQ=3D%x,NOTIMER=3D%= x", - SSTEP_ENABLE, - SSTEP_NOIRQ, - SSTEP_NOTIMER); - put_packet(s, buf); - break; - } else if (is_query_packet(p, "qemu.sstep", '=3D')) { - /* Display or change the sstep_flags */ - p +=3D 10; - if (*p !=3D '=3D') { - /* Display current setting */ - snprintf(buf, sizeof(buf), "0x%x", sstep_flags); - put_packet(s, buf); - break; - } - p++; - type =3D strtoul(p, (char **)&p, 16); - sstep_flags =3D type; - put_packet(s, "OK"); - break; - } else if (strcmp(p,"C") =3D=3D 0) { - /* - * "Current thread" remains vague in the spec, so always return - * the first thread of the current process (gdb returns the - * first thread). - */ - cpu =3D get_first_cpu_in_process(s, gdb_get_cpu_process(s, s->= g_cpu)); - snprintf(buf, sizeof(buf), "QC%s", - gdb_fmt_thread_id(s, cpu, thread_id, sizeof(thread_id= ))); - put_packet(s, buf); - break; - } else if (strcmp(p,"fThreadInfo") =3D=3D 0) { - s->query_cpu =3D gdb_first_attached_cpu(s); - goto report_cpuinfo; - } else if (strcmp(p,"sThreadInfo") =3D=3D 0) { - report_cpuinfo: - if (s->query_cpu) { - snprintf(buf, sizeof(buf), "m%s", - gdb_fmt_thread_id(s, s->query_cpu, - thread_id, sizeof(thread_id))); - put_packet(s, buf); - s->query_cpu =3D gdb_next_attached_cpu(s, s->query_cpu); - } else - put_packet(s, "l"); - break; - } else if (strncmp(p,"ThreadExtraInfo,", 16) =3D=3D 0) { - if (read_thread_id(p + 16, &p, &pid, &tid) =3D=3D GDB_READ_THR= EAD_ERR) { - put_packet(s, "E22"); - break; - } - cpu =3D gdb_get_cpu(s, pid, tid); - if (cpu !=3D NULL) { - cpu_synchronize_state(cpu); - - if (s->multiprocess && (s->process_num > 1)) { - /* Print the CPU model and name in multiprocess mode */ - ObjectClass *oc =3D object_get_class(OBJECT(cpu)); - const char *cpu_model =3D object_class_get_name(oc); - char *cpu_name =3D - object_get_canonical_path_component(OBJECT(cpu)); - len =3D snprintf((char *)mem_buf, sizeof(buf) / 2, - "%s %s [%s]", cpu_model, cpu_name, - cpu->halted ? "halted " : "running"); - g_free(cpu_name); - } else { - /* memtohex() doubles the required space */ - len =3D snprintf((char *)mem_buf, sizeof(buf) / 2, - "CPU#%d [%s]", cpu->cpu_index, - cpu->halted ? "halted " : "running"); - } - trace_gdbstub_op_extra_info((char *)mem_buf); - memtohex(buf, mem_buf, len); - put_packet(s, buf); - } - break; - } -#ifdef CONFIG_USER_ONLY - else if (strcmp(p, "Offsets") =3D=3D 0) { - TaskState *ts =3D s->c_cpu->opaque; - - snprintf(buf, sizeof(buf), - "Text=3D" TARGET_ABI_FMT_lx ";Data=3D" TARGET_ABI_FMT= _lx - ";Bss=3D" TARGET_ABI_FMT_lx, - ts->info->code_offset, - ts->info->data_offset, - ts->info->data_offset); - put_packet(s, buf); - break; - } -#else /* !CONFIG_USER_ONLY */ - else if (strncmp(p, "Rcmd,", 5) =3D=3D 0) { - int len =3D strlen(p + 5); - - if ((len % 2) !=3D 0) { - put_packet(s, "E01"); - break; - } - len =3D len / 2; - hextomem(mem_buf, p + 5, len); - mem_buf[len++] =3D 0; - qemu_chr_be_write(s->mon_chr, mem_buf, len); - put_packet(s, "OK"); - break; - } -#endif /* !CONFIG_USER_ONLY */ - if (is_query_packet(p, "Supported", ':')) { - snprintf(buf, sizeof(buf), "PacketSize=3D%x", MAX_PACKET_LENGT= H); - cc =3D CPU_GET_CLASS(first_cpu); - if (cc->gdb_core_xml_file !=3D NULL) { - pstrcat(buf, sizeof(buf), ";qXfer:features:read+"); - } - - if (strstr(p, "multiprocess+")) { - s->multiprocess =3D true; - } - pstrcat(buf, sizeof(buf), ";multiprocess+"); - - put_packet(s, buf); - break; - } - if (strncmp(p, "Xfer:features:read:", 19) =3D=3D 0) { - const char *xml; - target_ulong total_len; - - 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; - } - - gdb_has_xml =3D true; - p +=3D 19; - xml =3D get_feature_xml(s, p, &p, process); - if (!xml) { - snprintf(buf, sizeof(buf), "E00"); - put_packet(s, buf); - break; - } - - if (*p =3D=3D ':') - p++; - addr =3D strtoul(p, (char **)&p, 16); - if (*p =3D=3D ',') - p++; - len =3D strtoul(p, (char **)&p, 16); - - total_len =3D strlen(xml); - if (addr > total_len) { - snprintf(buf, sizeof(buf), "E00"); - put_packet(s, buf); - break; - } - if (len > (MAX_PACKET_LENGTH - 5) / 2) - len =3D (MAX_PACKET_LENGTH - 5) / 2; - if (len < total_len - addr) { - buf[0] =3D 'm'; - len =3D memtox(buf + 1, xml + addr, len); - } else { - buf[0] =3D 'l'; - len =3D memtox(buf + 1, xml + addr, total_len - addr); - } - put_packet_binary(s, buf, len + 1, true); - break; - } - if (is_query_packet(p, "Attached", ':')) { - put_packet(s, GDB_ATTACHED); - break; + { + static const GdbCmdParseEntry gen_set_cmd_desc =3D { + .handler =3D handle_gen_set, + .cmd =3D "Q", + .cmd_startswith =3D 1, + .schema =3D "s0" + }; + cmd_parser =3D &gen_set_cmd_desc; } - /* Unrecognised 'q' command. */ - goto unknown_command; - + break; default: - unknown_command: /* put empty packet */ buf[0] =3D '\0'; put_packet(s, buf); --=20 2.20.1