From patchwork Fri Jun 7 09:05:33 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: 166138 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp460531ili; Fri, 7 Jun 2019 03:35:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwB150ZBWFLc45TPOyZK0bzMtG8VOHGptElk+9isqXlUjrFVDywKyixrZpB8nXSUt1zaca0 X-Received: by 2002:aed:2667:: with SMTP id z94mr46403304qtc.2.1559903717903; Fri, 07 Jun 2019 03:35:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559903717; cv=none; d=google.com; s=arc-20160816; b=Y+nFg8XQBme6oxa0onArqbK1fGj9LIBJaKPjc5krgKfwT2JvjSAsA65Yn3tBH2SROL MnzZNZ0FAZliMtYyZcZZewKPc+2PvcrnVHDXeKA4RdPWr3VUEHnBkt7rlFHRomu4sCFh jPLOTVJRtlAHqDxw8FDMDKzvPfPO7JXILMiXtnx210lDtXY0fwMyVRI6ZoEdh7BxOi2J jrE59K/OcDFnbAhqUI9x5xymAQnOxgK38i/NpTmqKcZRMKmnqIqJQq7/7cccR5fepH23 60/zbX9FXANrFoi7fQYLJtr0Rwn6oLGUlk+VY5+FEEia8qy4oynKHjL/souEdm6+haKn E6Hw== 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=eS4ups5iSOxsrkjwkIPBvVdVBQzJoB39R+u5rhoVXoE=; b=cUWPJiKMAyD+xL9br31WxPaD81XbeU3gEMAUEW4KyoiuLJsbFawrE8N1RLCY2nVGt/ GNnqZeSFjvRdyGhdwWcGtColUuT9220E+pZ2qSvUutsB/B5LI4bu918hYIn58CMqvfV4 Fu7T0Ue9b0EhyY1p1mtwSN8kR+qCXBAD77lFh0WIHR5Sz81ZYUW0b0a1a093ZAl8NxLD n0JL3/1MgwIA03psj2dbUuaH9Ag0vdu7iboIHy7NIssYaIc7TRPWOYZeyEfoApTKa+OR +mWXB824GbqYZ1CrURZWL6Sc6WUOtZLZQS7IpChsQlWBybhc3v+PuK5oZdW+RRjEvR+B AN9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NBfYhjEe; 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 n32si910620qvd.214.2019.06.07.03.35.17 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jun 2019 03:35:17 -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=NBfYhjEe; 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]:48076 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hZCDN-0000Ql-Hk for patch@linaro.org; Fri, 07 Jun 2019 06:35:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45065) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hZB54-0008Il-7P for qemu-devel@nongnu.org; Fri, 07 Jun 2019 05:22:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hZB52-0005wa-Rc for qemu-devel@nongnu.org; Fri, 07 Jun 2019 05:22:38 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:50984) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hZB52-0005vD-L5 for qemu-devel@nongnu.org; Fri, 07 Jun 2019 05:22:36 -0400 Received: by mail-wm1-x332.google.com with SMTP id c66so1283302wmf.0 for ; Fri, 07 Jun 2019 02:22:36 -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=eS4ups5iSOxsrkjwkIPBvVdVBQzJoB39R+u5rhoVXoE=; b=NBfYhjEeUJfiDur2FFm6EDzUu5k9zDTNrQJ6FpxY6Nd/rI4pv+zbhCJCLBX8hF2wCe 39IKy50tnzNg7Hs5yDM6BiWRYcFNqSd86jxZTRDnH70G9HismS/7ZJQxImnnhHolAnJP JC3kiUMJXQojcQlXYMnv6qOd58ekELKshmQjuvPmLLlesO3ugG3jw5FkHJ/o+YbuvhbK 2379wgUdSw1PXnlhbiw+hreF1z+bTcu3xrfhDx76xObY4sBZe/3rDgBg1zIjFIdAHUHu pRD5uRnO7Cg1vPwL7L8GzPFaEcbwPo7FQiQBeJP0jiDo4iYQdXvCBygyFgUJXT+j4zC1 whlQ== 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=eS4ups5iSOxsrkjwkIPBvVdVBQzJoB39R+u5rhoVXoE=; b=HIj+TwG/KKmOEkltH9A5ShxTAjyhsy5bYfy7ZHtPMpFXl7rokMMQnAr9I0PmEa819S MNdj9GSABXuu9b6KJyXWaYfWIT+y1Et89t1eEtCdKglmc1IuYKfReXPN0o+Gad9M5ZYN AvybXW6ayjLAJkJNo/IEkZoOhfzpFavcMap4ZehXOcBrFbT+GWxj3oZtqqQl4vRwDTxH CYrSHryUI82/VeVXk+arTPUU8eHKDC3vh00Bpd16yt/sqrZujRo3ObhYLIp0NpSj5vub ZZkKCIHx5BQ+JISOIm/F8Rc4rwxUgiRYqcWfRHqi3jtiSTsSeu4d8XaiqW7SXQkVCTke YYQg== X-Gm-Message-State: APjAAAXfF/NikmNn/2aBJKdDeipP6p4h7mvR98BPFadAZJWm7UjUH2zr xsqf3fXZXGbQQ2RGfZT70S2NuA== X-Received: by 2002:a7b:cae9:: with SMTP id t9mr2900174wml.126.1559899355465; Fri, 07 Jun 2019 02:22:35 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id w185sm1405942wma.39.2019.06.07.02.22.28 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 07 Jun 2019 02:22:30 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id BA75C1FFBA; Fri, 7 Jun 2019 10:05:54 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Fri, 7 Jun 2019 10:05:33 +0100 Message-Id: <20190607090552.12434-35-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::332 Subject: [Qemu-devel] [PULL 34/52] gdbstub: Implement deatch (D pkt) 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-3-arilou@gmail.com> Reviewed-by: Alex Bennée Signed-off-by: Alex Bennée -- 2.20.1 diff --git a/gdbstub.c b/gdbstub.c index 09fe5a4b99..120e52f5d2 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1413,11 +1413,6 @@ static inline int startswith(const char *string, const char *pattern) return !strncmp(string, pattern, strlen(pattern)); } -static int process_string_cmd( - GDBState *s, void *user_ctx, const char *data, - const GdbCmdParseEntry *cmds, int num_cmds) - __attribute__((unused)); - static int process_string_cmd(GDBState *s, void *user_ctx, const char *data, const GdbCmdParseEntry *cmds, int num_cmds) { @@ -1463,6 +1458,55 @@ static int process_string_cmd(GDBState *s, void *user_ctx, const char *data, return -1; } +static void run_cmd_parser(GDBState *s, const char *data, + const GdbCmdParseEntry *cmd) +{ + if (!data) { + return; + } + + /* In case there was an error during the command parsing we must + * send a NULL packet to indicate the command is not supported */ + if (process_string_cmd(s, NULL, data, cmd, 1)) { + put_packet(s, ""); + } +} + +static void handle_detach(GdbCmdContext *gdb_ctx, void *user_ctx) +{ + GDBProcess *process; + GDBState *s = gdb_ctx->s; + uint32_t pid = 1; + + if (s->multiprocess) { + if (!gdb_ctx->num_params) { + put_packet(s, "E22"); + return; + } + + pid = gdb_ctx->params[0].val_ul; + } + + process = gdb_get_process(s, pid); + gdb_process_breakpoint_remove_all(s, process); + process->attached = false; + + if (pid == gdb_get_cpu_pid(s, s->c_cpu)) { + s->c_cpu = gdb_first_attached_cpu(s); + } + + if (pid == gdb_get_cpu_pid(s, s->g_cpu)) { + s->g_cpu = gdb_first_attached_cpu(s); + } + + if (!s->c_cpu) { + /* No more process attached */ + gdb_syscall_mode = GDB_SYS_DISABLED; + gdb_continue(s); + } + put_packet(s, "OK"); +} + static int gdb_handle_packet(GDBState *s, const char *line_buf) { CPUState *cpu; @@ -1477,6 +1521,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) uint8_t *registers; target_ulong addr, len; GDBThreadIdKind thread_kind; + const GdbCmdParseEntry *cmd_parser = NULL; trace_gdbstub_io_command(line_buf); @@ -1577,42 +1622,15 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) error_report("QEMU: Terminated via GDBstub"); exit(0); case 'D': - /* Detach packet */ - pid = 1; - - if (s->multiprocess) { - unsigned long lpid; - if (*p != ';') { - put_packet(s, "E22"); - break; - } - - if (qemu_strtoul(p + 1, &p, 16, &lpid)) { - put_packet(s, "E22"); - break; - } - - pid = lpid; - } - - process = gdb_get_process(s, pid); - gdb_process_breakpoint_remove_all(s, process); - process->attached = false; - - if (pid == gdb_get_cpu_pid(s, s->c_cpu)) { - s->c_cpu = gdb_first_attached_cpu(s); - } - - if (pid == gdb_get_cpu_pid(s, s->g_cpu)) { - s->g_cpu = gdb_first_attached_cpu(s); - } - - if (s->c_cpu == NULL) { - /* No more process attached */ - gdb_syscall_mode = GDB_SYS_DISABLED; - gdb_continue(s); + { + static const GdbCmdParseEntry detach_cmd_desc = { + .handler = handle_detach, + .cmd = "D", + .cmd_startswith = 1, + .schema = "?.l0" + }; + cmd_parser = &detach_cmd_desc; } - put_packet(s, "OK"); break; case 's': if (*p != '\0') { @@ -1985,6 +2003,9 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) put_packet(s, buf); break; } + + run_cmd_parser(s, line_buf, cmd_parser); + return RS_IDLE; }