From nobody Sun Nov 24 22:39:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1720193966; cv=none; d=zohomail.com; s=zohoarc; b=C5VT5S1OrAIKpYsFLR+qIpzaAELJFOjDgQZyitzGDilTG+0lukjiGgCfrJPbRkrSZlaGJsicg2uAZuYVh+fTTGqApZzYIzVcOHEK7YgSydlXTESFprCMu3mH+nIse0uv49ELeu53qj2Qm4H7ebFhHuv4AtuDROyXfsfiabfdO+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720193966; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lGm+/MmwdTtSAKsTNDRWVhRbZjOTbAPKkLzVOV/KGSY=; b=ZUriMYnbezx8q3lik/3B38/d8UWWbMFNCmfUWXoRTZQBtrlnk/PenOrOlt/H0IBEdMjaRzKGKaZRpBqIUSvE4aEONzusmvpbdWhV75YgY0ia2H5hRhCycUN29r34HpkSfAtVUHCq7GjgTtGMlHLV6ffJpgztfN9gIKaal3TLBtU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1720193966358796.0544182852202; Fri, 5 Jul 2024 08:39:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sPkzy-0002cR-MS; Fri, 05 Jul 2024 11:37:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sPkzs-0002aN-S4 for qemu-devel@nongnu.org; Fri, 05 Jul 2024 11:37:16 -0400 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sPkzp-0001GW-Sd for qemu-devel@nongnu.org; Fri, 05 Jul 2024 11:37:16 -0400 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-a77cb7c106dso101813466b.1 for ; Fri, 05 Jul 2024 08:37:13 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72aaf18b15sm695108466b.19.2024.07.05.08.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 08:37:10 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 111EB62159; Fri, 5 Jul 2024 16:30:56 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720193832; x=1720798632; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lGm+/MmwdTtSAKsTNDRWVhRbZjOTbAPKkLzVOV/KGSY=; b=wxiuwlqCHnlo6uuUJwH+iKHQivApWutRw8572fMHIIPR0Wyqnvo6PWltXoDUZmUy85 EKC5oERrM3SwpUjc0A+rpyYb6wml+i/+f4pMl70LAbZ98WBda6m6r3wSoLdUpU83E45B YDNTqEOy/VgbT3H05NFt+gHfCJVptfEBZZRJiOOmgoy+2U5hcY4clmVbc1K+4JLUGAuW Ez4/7XubNxikalv7yMU9PDT1BsFh1rRjDqqn63sF+TVW3LDWp9xaboFtrgeiORfDPos7 vSYP0eeGT13mQ9HS+07xn0MR6FJv9KO1t1TARPb2yfUM2N3afbtvy4nN9Q9L9/01J+j8 CTMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720193832; x=1720798632; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lGm+/MmwdTtSAKsTNDRWVhRbZjOTbAPKkLzVOV/KGSY=; b=RdYtToVVCWmgFieh3W9fs7QJShFwJjfhQeJEm5wnE4xWNks9+mPPysiH83G10q85Hv LhMCeGC9jKAEMvlRGvFW19fNOqxeROQz1668AnRUNyN1VVlqU77Al/q1znr8JleiElx0 pHAsq47xFdCd4algaAZ6F5ZCtc5yFvcqM3Pc/qIeRw/qjTANzexmjo/kD0h/UJuWHcuF j8N+7vmGjgdgZacy6T8dEsejb2Noc3rdIwt8Tg23JzNDq8d/tQoE5wyHSqP6OqoT2cLu gYLM3xcjCKIlQCwrVEMSdL9IEJN3w+BZTu6rx6dbMdw+ePowUFBEhEHzCx2+ufGY1bQw TVcQ== X-Gm-Message-State: AOJu0Yy/9cXQRYr7zJDeRh3gSsjveXCF8MhkTAgBpvlvke5dj3GlAN4y 4JXYwWCD8TlSLkT73H2eyE8G1MaFIR5AsI/Tgr+qpH6nx41iWzwReqnYuiWeVNs= X-Google-Smtp-Source: AGHT+IH6K+pQ1zE7PlWuxWNm0MtWef5JmGo/9WKQPv5JIE1A69uUXfbzr6fLC7vBMmBjP3WkL+pQEg== X-Received: by 2002:a17:906:b809:b0:a77:dbf0:d25 with SMTP id a640c23a62f3a-a77dbf00e74mr66622966b.33.1720193831981; Fri, 05 Jul 2024 08:37:11 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Gustavo Romero , =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 32/40] gdbstub: Add support for target-specific stubs Date: Fri, 5 Jul 2024 16:30:44 +0100 Message-Id: <20240705153052.1219696-33-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240705153052.1219696-1-alex.bennee@linaro.org> References: <20240705153052.1219696-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2a00:1450:4864:20::635; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1720193967639100001 From: Gustavo Romero Currently, it's not possible to have stubs specific to a given target, even though there are GDB features which are target-specific, like, for instance, memory tagging. This commit introduces gdb_extend_qsupported_features, gdb_extend_query_table, and gdb_extend_set_table functions as interfaces to extend the qSupported string, the query handler table, and the set handler table, allowing target-specific stub implementations. Signed-off-by: Gustavo Romero Reviewed-by: Alex Benn=C3=A9e Message-Id: <20240628050850.536447-4-gustavo.romero@linaro.org> Signed-off-by: Alex Benn=C3=A9e Message-Id: <20240705084047.857176-33-alex.bennee@linaro.org> diff --git a/include/gdbstub/commands.h b/include/gdbstub/commands.h index 639257493e..306dfdef97 100644 --- a/include/gdbstub/commands.h +++ b/include/gdbstub/commands.h @@ -69,4 +69,26 @@ typedef struct GdbCmdParseEntry { */ int gdb_put_packet(const char *buf); =20 +/** + * gdb_extend_query_table() - Extend query table. + * @table: The table with the additional query packet handlers. + * @size: The number of handlers to be added. + */ +void gdb_extend_query_table(GdbCmdParseEntry *table, int size); + +/** + * gdb_extend_set_table() - Extend set table. + * @table: The table with the additional set packet handlers. + * @size: The number of handlers to be added. + */ +void gdb_extend_set_table(GdbCmdParseEntry *table, int size); + +/** + * gdb_extend_qsupported_features() - Extend the qSupported features strin= g. + * @qsupported_features: The additional qSupported feature(s) string. The = string + * should start with a semicolon and, if there are more than one feature, = the + * features should be separate by a semiocolon. + */ +void gdb_extend_qsupported_features(char *qsupported_features); + #endif /* GDBSTUB_COMMANDS_H */ diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 9ff2f4177d..b1ca253f97 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -1609,6 +1609,20 @@ static void handle_query_thread_extra(GArray *params= , void *user_ctx) gdb_put_strbuf(); } =20 +static char *extended_qsupported_features; +void gdb_extend_qsupported_features(char *qsupported_features) +{ + /* + * We don't support different sets of CPU gdb features on different CP= Us yet + * so assert the feature strings are the same on all CPUs, or is set o= nly + * once (1 CPU). + */ + g_assert(extended_qsupported_features =3D=3D NULL || + g_strcmp0(extended_qsupported_features, qsupported_features) = =3D=3D 0); + + extended_qsupported_features =3D qsupported_features; +} + static void handle_query_supported(GArray *params, void *user_ctx) { CPUClass *cc; @@ -1648,6 +1662,11 @@ static void handle_query_supported(GArray *params, v= oid *user_ctx) } =20 g_string_append(gdbserver_state.str_buf, ";vContSupported+;multiproces= s+"); + + if (extended_qsupported_features) { + g_string_append(gdbserver_state.str_buf, extended_qsupported_featu= res); + } + gdb_put_strbuf(); } =20 @@ -1729,6 +1748,41 @@ static const GdbCmdParseEntry gdb_gen_query_set_comm= on_table[] =3D { }, }; =20 +/* Compares if a set of command parsers is equal to another set of parsers= . */ +static bool cmp_cmds(GdbCmdParseEntry *c, GdbCmdParseEntry *d, int size) +{ + for (int i =3D 0; i < size; i++) { + if (!(c[i].handler =3D=3D d[i].handler && + g_strcmp0(c[i].cmd, d[i].cmd) =3D=3D 0 && + c[i].cmd_startswith =3D=3D d[i].cmd_startswith && + g_strcmp0(c[i].schema, d[i].schema) =3D=3D 0)) { + + /* Sets are different. */ + return false; + } + } + + /* Sets are equal, i.e. contain the same command parsers. */ + return true; +} + +static GdbCmdParseEntry *extended_query_table; +static int extended_query_table_size; +void gdb_extend_query_table(GdbCmdParseEntry *table, int size) +{ + /* + * We don't support different sets of CPU gdb features on different CP= Us yet + * so assert query table is the same on all CPUs, or is set only once + * (1 CPU). + */ + g_assert(extended_query_table =3D=3D NULL || + (extended_query_table_size =3D=3D size && + cmp_cmds(extended_query_table, table, size))); + + extended_query_table =3D table; + extended_query_table_size =3D size; +} + static const GdbCmdParseEntry gdb_gen_query_table[] =3D { { .handler =3D handle_query_curr_tid, @@ -1821,6 +1875,22 @@ static const GdbCmdParseEntry gdb_gen_query_table[] = =3D { #endif }; =20 +static GdbCmdParseEntry *extended_set_table; +static int extended_set_table_size; +void gdb_extend_set_table(GdbCmdParseEntry *table, int size) +{ + /* + * We don't support different sets of CPU gdb features on different CP= Us yet + * so assert set table is the same on all CPUs, or is set only once (1= CPU). + */ + g_assert(extended_set_table =3D=3D NULL || + (extended_set_table_size =3D=3D size && + cmp_cmds(extended_set_table, table, size))); + + extended_set_table =3D table; + extended_set_table_size =3D size; +} + static const GdbCmdParseEntry gdb_gen_set_table[] =3D { /* Order is important if has same prefix */ { @@ -1859,11 +1929,21 @@ static void handle_gen_query(GArray *params, void *= user_ctx) return; } =20 - if (!process_string_cmd(gdb_get_cmd_param(params, 0)->data, - gdb_gen_query_table, - ARRAY_SIZE(gdb_gen_query_table))) { - gdb_put_packet(""); + if (process_string_cmd(gdb_get_cmd_param(params, 0)->data, + gdb_gen_query_table, + ARRAY_SIZE(gdb_gen_query_table))) { + return; + } + + if (extended_query_table && + process_string_cmd(gdb_get_cmd_param(params, 0)->data, + extended_query_table, + extended_query_table_size)) { + return; } + + /* Can't handle query, return Empty response. */ + gdb_put_packet(""); } =20 static void handle_gen_set(GArray *params, void *user_ctx) @@ -1878,11 +1958,21 @@ static void handle_gen_set(GArray *params, void *us= er_ctx) return; } =20 - if (!process_string_cmd(gdb_get_cmd_param(params, 0)->data, + if (process_string_cmd(gdb_get_cmd_param(params, 0)->data, gdb_gen_set_table, ARRAY_SIZE(gdb_gen_set_table))) { - gdb_put_packet(""); + return; } + + if (extended_set_table && + process_string_cmd(gdb_get_cmd_param(params, 0)->data, + extended_set_table, + extended_set_table_size)) { + return; + } + + /* Can't handle set, return Empty response. */ + gdb_put_packet(""); } =20 static void handle_target_halt(GArray *params, void *user_ctx) --=20 2.39.2