From patchwork Fri Jun 7 09:05:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 166133 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp455103ili; Fri, 7 Jun 2019 03:30:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyAebPUfxIwLCLqkpQVXdzjcRLQ2KLmHjQ6MxpXv/g4EorKf/BcB3RDD1GV0x6tc6KJqVWU X-Received: by 2002:aed:33e6:: with SMTP id v93mr45762623qtd.157.1559903405374; Fri, 07 Jun 2019 03:30:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559903405; cv=none; d=google.com; s=arc-20160816; b=k1MbqUKPw+IIKFx5qm/0sr8Fui8lsAlQbzwpj5n9jddEB8YRVZvyRju1CUiJ/bi+Ix +eDki3oTsCwy/lpAMUvnDNJ9MlA9Z/EEjidl4O/kcOEi8TEiGTNj7wmtk6/G7eeqF6nN B+xeaxXv9loC8uJnhW3tnWZhGncxiUCfOLc4RyZpaHnau7JSW0jKWfx38DgxHwRI8WNj Jrnh0tZ9aKW7yjhJ0GV/4zhNv+/ImDdkhdyjVHOzFd4MctHEjqOWrn7gwQrM4JVB/trg PH5fHbveA8l/HtVYlqXTyJTJuaioflxlIL5QHacbf/oc9aX+cbDLnWSCYFe5EDk7eI5P yb4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=M703OVi/yb72s+8BEvwBG9PpAye08L3/Z+ktwqLhEVo=; b=BF5yV3Qa/RE14BLum3aagh0HWTQMfJNh5OVCHBYq06A8alnFj64hesYCg8iYcmf1oQ S+5kCbZKZXkVKAYsDg45FJmDDIWTIQAbP3W3QAoKEcZpUJUPDpWE6aPPj8UyttBJYx0p EXFo1i7Guf5wvrnWwZj1HzEPHZZU5bwmk1cthx0FFOOoPV/oTOZw38+TidrU5T5Fdobk jPgv1FbZ9Bdku1CLauovjtUoNVNlIoJ0lUIYBl9LTm4ARXucJ2m6OjDUYJWA98u83QpL RPoWAmiEFr52uIKhz68MZov36zGGlnd2LI3I9C1Ke+tGaK0MujwoNMfk/gpkSueRAW3v ZoEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wNKSW70y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.47 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.47]) by mx.google.com with ESMTPS id q1si323287qkd.157.2019.06.07.03.30.05 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jun 2019 03:30:05 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.47 as permitted sender) client-ip=209.51.188.47; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wNKSW70y; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.47 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48042 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hZC8L-0005Ih-0N for patch@linaro.org; Fri, 07 Jun 2019 06:30:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50992) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hZBOM-0007e6-Ai for qemu-devel@nongnu.org; Fri, 07 Jun 2019 05:42:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hZBOK-0000p1-Ca for qemu-devel@nongnu.org; Fri, 07 Jun 2019 05:42:34 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:34618) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hZBOI-0000kf-U0 for qemu-devel@nongnu.org; Fri, 07 Jun 2019 05:42:32 -0400 Received: by mail-wr1-x432.google.com with SMTP id e16so1492158wrn.1 for ; Fri, 07 Jun 2019 02:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M703OVi/yb72s+8BEvwBG9PpAye08L3/Z+ktwqLhEVo=; b=wNKSW70yJe2qVnKuyi4yJa7cNgHDjmUiT7ihS42NXa/jcBMGZF9RNsn3LyGd02XuDH g6qyiQKRHbYaR1ya/1oPISQdEyQ3K/vvMrYTIE6eaBNSnsJ/97r/rOfhJdoijiwvVtcf vMbXAGlywIsQklNmpsgZunHpIJWsIRg9SWwYdJKihCtr59+6AKbH8Ct8fKWlZyybn6eQ gN0hZ8VXPxSiwmTFu94rD37h26li9k4/uWgwq5G8/qPBH1J8U9STlHOc4A7DksannE8j B6HBBDIrA9GEbbCA4ZObTzMhN4da56scBbdmFIWp5FgZ3nONaSTWWaM4LBCpyxT4gXzm f1mA== 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=M703OVi/yb72s+8BEvwBG9PpAye08L3/Z+ktwqLhEVo=; b=W0nQQbNvkukUlKEK1eTAVEXq39OaTCmnimJFZB9DrRPnpkOuNs/kzLMSjzRTJ/+9Nf TY5d4MByXqE7GLCt9dxxA8ARRBnB7U92A7V8E/lebWJj/lZW38OQa02d1Q3x0wa7cuAC xaQ6a4KIqlkO73WbJOOGKA66WuuG7zwH8SvUF7n9DqzrXjyey2kYxQ5TpS3/SeWjyFXF upF4qfDlsjF1+oPqfAAWtzQ83CfAvHFdAIDBmffb/x+SLbRgSw/GcyzWi9Q+rBLOeQ82 1JO7cYC1G6YKxfOfQSN6TiV38dLZdvqDWgy9cwDCcVnMoOddiYclwL3cVr5r6pQ2ny1A FVjw== X-Gm-Message-State: APjAAAXBoL0aKCGi1CgFxl7jY0/18zm30mQ+JV9TQs6vtRZ/5PGA1QG2 Rdlk8CemrRhwcEN75uQuTI5W7A== X-Received: by 2002:a5d:4acf:: with SMTP id y15mr19334842wrs.32.1559900549019; Fri, 07 Jun 2019 02:42:29 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id o14sm1409185wrp.77.2019.06.07.02.42.28 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 02:42:28 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id CF4C41FF91; Fri, 7 Jun 2019 10:05:55 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Fri, 7 Jun 2019 10:05:47 +0100 Message-Id: <20190607090552.12434-49-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190607090552.12434-1-alex.bennee@linaro.org> References: <20190607090552.12434-1-alex.bennee@linaro.org> 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::432 Subject: [Qemu-devel] [PULL 48/52] gdbstub: Implement v commands with new infra X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Jon Doron Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Jon Doron Signed-off-by: Jon Doron Message-Id: <20190529064148.19856-17-arilou@gmail.com> Signed-off-by: Alex Bennée -- 2.20.1 diff --git a/gdbstub.c b/gdbstub.c index 6fd276892a..5a4d10f1c0 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1818,6 +1818,106 @@ static void handle_step(GdbCmdContext *gdb_ctx, void *user_ctx) gdb_continue(gdb_ctx->s); } +static void handle_v_cont_query(GdbCmdContext *gdb_ctx, void *user_ctx) +{ + put_packet(gdb_ctx->s, "vCont;c;C;s;S"); +} + +static void handle_v_cont(GdbCmdContext *gdb_ctx, void *user_ctx) +{ + int res; + + if (!gdb_ctx->num_params) { + return; + } + + res = gdb_handle_vcont(gdb_ctx->s, gdb_ctx->params[0].data); + if ((res == -EINVAL) || (res == -ERANGE)) { + put_packet(gdb_ctx->s, "E22"); + } else if (res) { + put_packet(gdb_ctx->s, ""); + } +} + +static void handle_v_attach(GdbCmdContext *gdb_ctx, void *user_ctx) +{ + GDBProcess *process; + CPUState *cpu; + char thread_id[16]; + + pstrcpy(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "E22"); + if (!gdb_ctx->num_params) { + goto cleanup; + } + + process = gdb_get_process(gdb_ctx->s, gdb_ctx->params[0].val_ul); + if (!process) { + goto cleanup; + } + + cpu = get_first_cpu_in_process(gdb_ctx->s, process); + if (!cpu) { + goto cleanup; + } + + process->attached = true; + gdb_ctx->s->g_cpu = cpu; + gdb_ctx->s->c_cpu = cpu; + + gdb_fmt_thread_id(gdb_ctx->s, cpu, thread_id, sizeof(thread_id)); + snprintf(gdb_ctx->str_buf, sizeof(gdb_ctx->str_buf), "T%02xthread:%s;", + GDB_SIGNAL_TRAP, thread_id); +cleanup: + put_packet(gdb_ctx->s, gdb_ctx->str_buf); +} + +static void handle_v_kill(GdbCmdContext *gdb_ctx, void *user_ctx) +{ + /* Kill the target */ + put_packet(gdb_ctx->s, "OK"); + error_report("QEMU: Terminated via GDBstub"); + exit(0); +} + +static GdbCmdParseEntry gdb_v_commands_table[] = { + /* Order is important if has same prefix */ + { + .handler = handle_v_cont_query, + .cmd = "Cont?", + .cmd_startswith = 1 + }, + { + .handler = handle_v_cont, + .cmd = "Cont", + .cmd_startswith = 1, + .schema = "s0" + }, + { + .handler = handle_v_attach, + .cmd = "Attach;", + .cmd_startswith = 1, + .schema = "l0" + }, + { + .handler = handle_v_kill, + .cmd = "Kill;", + .cmd_startswith = 1 + }, +}; + +static void handle_v_commands(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_v_commands_table, + ARRAY_SIZE(gdb_v_commands_table))) { + put_packet(gdb_ctx->s, ""); + } +} + static int gdb_handle_packet(GDBState *s, const char *line_buf) { CPUState *cpu; @@ -1825,7 +1925,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) CPUClass *cc; const char *p; uint32_t pid, tid; - int ch, type, res; + int ch, type; uint8_t mem_buf[MAX_PACKET_LENGTH]; char buf[sizeof(mem_buf) + 1 /* trailing NUL */]; char thread_id[16]; @@ -1874,66 +1974,16 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) } break; case 'v': - if (strncmp(p, "Cont", 4) == 0) { - p += 4; - if (*p == '?') { - put_packet(s, "vCont;c;C;s;S"); - break; - } - - res = gdb_handle_vcont(s, p); - - if (res) { - if ((res == -EINVAL) || (res == -ERANGE)) { - put_packet(s, "E22"); - break; - } - goto unknown_command; - } - break; - } else if (strncmp(p, "Attach;", 7) == 0) { - unsigned long pid; - - p += 7; - - if (qemu_strtoul(p, &p, 16, &pid)) { - put_packet(s, "E22"); - break; - } - - process = gdb_get_process(s, pid); - - if (process == NULL) { - put_packet(s, "E22"); - break; - } - - cpu = get_first_cpu_in_process(s, process); - - if (cpu == NULL) { - /* Refuse to attach an empty process */ - put_packet(s, "E22"); - break; - } - - process->attached = true; - - s->g_cpu = cpu; - s->c_cpu = cpu; - - snprintf(buf, sizeof(buf), "T%02xthread:%s;", GDB_SIGNAL_TRAP, - gdb_fmt_thread_id(s, cpu, thread_id, sizeof(thread_id))); - - put_packet(s, buf); - break; - } else if (strncmp(p, "Kill;", 5) == 0) { - /* Kill the target */ - put_packet(s, "OK"); - error_report("QEMU: Terminated via GDBstub"); - exit(0); - } else { - goto unknown_command; + { + static const GdbCmdParseEntry v_cmd_desc = { + .handler = handle_v_commands, + .cmd = "v", + .cmd_startswith = 1, + .schema = "s0" + }; + cmd_parser = &v_cmd_desc; } + break; case 'k': /* Kill the target */ error_report("QEMU: Terminated via GDBstub");