From patchwork Wed Apr 24 14:27:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Doron X-Patchwork-Id: 1090165 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="O3I12ntM"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44q2t70mfCz9sCJ for ; Thu, 25 Apr 2019 00:35:39 +1000 (AEST) Received: from localhost ([127.0.0.1]:42615 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIzn-0004js-D1 for incoming@patchwork.ozlabs.org; Wed, 24 Apr 2019 10:35:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIyw-0004gM-Ii for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:34:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hJIsf-0001EA-KL for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:28:18 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:56247) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hJIsf-0001Dz-Bw for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:28:13 -0400 Received: by mail-wm1-x344.google.com with SMTP id o25so4874322wmf.5 for ; Wed, 24 Apr 2019 07:28:13 -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=nVBujIY8jQ+mCz54eBD0alHwA5ZhV8sSGiqMXpK+lfg=; b=O3I12ntMIrwwTqn+FL8G+VgtwcDGMItToIsQRPv0ZMo+eaGhv8iaJ1zKBasFzy86DJ Kd/YG7Lkhxaf+nCjlPJ53gRv8SCWMFn+z84bKHB8HovK3yRkj0b+ehwpGy8G9IrbWP2w niimMLxGqkkYYxctCJ6DQt6x0VF942IpYMFAm7wqPpBoOWp7pOp4hdwVsE1dqJbqz8jx NTUKdlFpy0rs8zn84qQqokhoYScxTgVfg4yA/+opUlIwV9mxmcXAi8A4WgVAbRJqSsbY r7lX7DRGVJk/1rA5eQBmuS+KqHBDPaIp5BkC73bGAfYibRrEi+blShitSQk8wK209bsq aJCw== 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=nVBujIY8jQ+mCz54eBD0alHwA5ZhV8sSGiqMXpK+lfg=; b=ZkqpEFjs9Qgpi1Z/IOihvBaXkkuOvN6g4f0Xq3QRSqYTG4BFXCww0ErH7sH3BbrlrG YnsikPE4rCcHnQfNai2u/FhwNARUOHvyIRBTKk8s3dSyhVrFnSie9abhzq44VbSFZ24F AfONGaxhajp7boF0KX/Crwe68ql+scEnSWZf5B5dccKTGw4TYDb3kx8g8uotscjv9cb3 7b9RoBcZ66sVfAAGXditC8f7wXeXR0UmpODu4J5f0lqKRwchs40+/Wzwu/p2lEQaH2+J K4fcyzy5qxy4l/UI5r7vPDHjWN6OuxuOh6eZgXMSeaGz00vJIOsQGmQgw2nHAedJ5kSd A9FQ== X-Gm-Message-State: APjAAAWutR+5RNAc9TVuCQJBPBhpp9VML6uGgm24pAalqgYgtFfV7hWd pJI5t2c7KQeP2qzlGVMblPGXn70W X-Google-Smtp-Source: APXvYqxKsq3B2d43lMqK2sKCb8H1/c6aM4sobQ2vhKvMK5i6Ufgs7QZ1+YmcalXt3TuCm+8euz2jLQ== X-Received: by 2002:a1c:1d4:: with SMTP id 203mr6880579wmb.101.1556116091562; Wed, 24 Apr 2019 07:28:11 -0700 (PDT) Received: from linux.local ([31.154.166.148]) by smtp.gmail.com with ESMTPSA id q7sm5518041wmc.11.2019.04.24.07.28.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Apr 2019 07:28:10 -0700 (PDT) From: arilou@gmail.com To: qemu-devel@nongnu.org Date: Wed, 24 Apr 2019 17:27:13 +0300 Message-Id: <20190424142714.28460-19-arilou@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190424142714.28460-1-arilou@gmail.com> References: <20190424142714.28460-1-arilou@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 Subject: [Qemu-devel] [PATCH v3 19/20] 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: Jon Doron Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Jon Doron Signed-off-by: Jon Doron --- gdbstub.c | 213 +++++++----------------------------------------------- 1 file changed, 25 insertions(+), 188 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index f8389528fe..c206a9a7c6 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1130,14 +1130,6 @@ static GDBThreadIdKind read_thread_id(const char *buf, const char **end_buf, return GDB_ONE_THREAD; } -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 && - (p[query_len] == '\0' || p[query_len] == separator); -} - /** * gdb_handle_vcont - Parses and handles a vCont packet. * returns -ENOTSUP if a command is unsupported, -EINVAL or -ERANGE if there is @@ -2256,18 +2248,28 @@ static void handle_gen_query(GdbCmdContext *gdb_ctx, void *user_ctx) } } +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; trace_gdbstub_io_command(line_buf); @@ -2479,182 +2481,17 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) } break; case 'Q': - /* parse any 'q' packets here */ - if (!strcmp(p,"qemu.sstepbits")) { - /* Query Breakpoint bit definitions */ - snprintf(buf, sizeof(buf), "ENABLE=%x,NOIRQ=%x,NOTIMER=%x", - SSTEP_ENABLE, - SSTEP_NOIRQ, - SSTEP_NOTIMER); - put_packet(s, buf); - break; - } else if (is_query_packet(p, "qemu.sstep", '=')) { - /* Display or change the sstep_flags */ - p += 10; - if (*p != '=') { - /* Display current setting */ - snprintf(buf, sizeof(buf), "0x%x", sstep_flags); - put_packet(s, buf); - break; - } - p++; - type = strtoul(p, (char **)&p, 16); - sstep_flags = type; - put_packet(s, "OK"); - break; - } else if (strcmp(p,"C") == 0) { - /* - * "Current thread" remains vague in the spec, so always return - * the first thread of the current process (gdb returns the - * first thread). - */ - cpu = 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") == 0) { - s->query_cpu = gdb_first_attached_cpu(s); - goto report_cpuinfo; - } else if (strcmp(p,"sThreadInfo") == 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 = gdb_next_attached_cpu(s, s->query_cpu); - } else - put_packet(s, "l"); - break; - } else if (strncmp(p,"ThreadExtraInfo,", 16) == 0) { - if (read_thread_id(p + 16, &p, &pid, &tid) == GDB_READ_THREAD_ERR) { - put_packet(s, "E22"); - break; - } - cpu = gdb_get_cpu(s, pid, tid); - if (cpu != NULL) { - cpu_synchronize_state(cpu); - - if (s->multiprocess && (s->process_num > 1)) { - /* Print the CPU model and name in multiprocess mode */ - ObjectClass *oc = object_get_class(OBJECT(cpu)); - const char *cpu_model = object_class_get_name(oc); - char *cpu_name = - object_get_canonical_path_component(OBJECT(cpu)); - len = 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 = 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") == 0) { - TaskState *ts = s->c_cpu->opaque; - - snprintf(buf, sizeof(buf), - "Text=" TARGET_ABI_FMT_lx ";Data=" TARGET_ABI_FMT_lx - ";Bss=" 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) == 0) { - int len = strlen(p + 5); - - if ((len % 2) != 0) { - put_packet(s, "E01"); - break; - } - len = len / 2; - hextomem(mem_buf, p + 5, len); - mem_buf[len++] = 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=%x", MAX_PACKET_LENGTH); - cc = CPU_GET_CLASS(first_cpu); - if (cc->gdb_core_xml_file != NULL) { - pstrcat(buf, sizeof(buf), ";qXfer:features:read+"); - } - - if (strstr(p, "multiprocess+")) { - s->multiprocess = true; - } - pstrcat(buf, sizeof(buf), ";multiprocess+"); - - put_packet(s, buf); - break; - } - if (strncmp(p, "Xfer:features:read:", 19) == 0) { - const char *xml; - target_ulong total_len; - - process = gdb_get_cpu_process(s, s->g_cpu); - cc = CPU_GET_CLASS(s->g_cpu); - if (cc->gdb_core_xml_file == NULL) { - goto unknown_command; - } - - gdb_has_xml = true; - p += 19; - xml = get_feature_xml(s, p, &p, process); - if (!xml) { - snprintf(buf, sizeof(buf), "E00"); - put_packet(s, buf); - break; - } - - if (*p == ':') - p++; - addr = strtoul(p, (char **)&p, 16); - if (*p == ',') - p++; - len = strtoul(p, (char **)&p, 16); - - total_len = strlen(xml); - if (addr > total_len) { - snprintf(buf, sizeof(buf), "E00"); - put_packet(s, buf); - break; - } - if (len > (MAX_PACKET_LENGTH - 5) / 2) - len = (MAX_PACKET_LENGTH - 5) / 2; - if (len < total_len - addr) { - buf[0] = 'm'; - len = memtox(buf + 1, xml + addr, len); - } else { - buf[0] = 'l'; - len = 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 GdbCmdParseEntry gen_set_cmd_desc = { + .handler = handle_gen_set, + .cmd = "Q", + .cmd_startswith = 1, + .schema = "s0" + }; + process_string_cmd(s, NULL, line_buf, &gen_set_cmd_desc, 1); } - /* Unrecognised 'q' command. */ - goto unknown_command; - + break; default: - unknown_command: /* put empty packet */ buf[0] = '\0'; put_packet(s, buf);