From patchwork Fri Jul 5 08:40:39 2024 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: 810382 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp1509539wru; Fri, 5 Jul 2024 01:49:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVNkxnY5Gin/HQBh2EUzXNUVQoLB+mC37zzGa3oOEiaSZyOJvyX4X++Yrey7yTcLq+Tv6GFJZjD4UoGf5P7rySB X-Google-Smtp-Source: AGHT+IHbJtiKvYoVNS3/uQe32VIInGVZGj4XSGHFUxr3DI6/0BBk2CqJTB/ZpgxsBtdvlgrj2HPZ X-Received: by 2002:a2e:a58a:0:b0:2ec:5a13:e19c with SMTP id 38308e7fff4ca-2ee8ed933e0mr39711301fa.17.1720169357938; Fri, 05 Jul 2024 01:49:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720169357; cv=none; d=google.com; s=arc-20160816; b=mCZ/9di4AMeOUTi30gd1l3tmBWW3scn0f5Sshlq1sjzIF6IWVUKaoEj0gY5/dtECL7 aN5ZhIxqgN053vOUHxcgTa/Gw883RNzK5JPcPaJ0/5VCAJ+ajPRtjUnLz8hV/bwbhUSp nWWP2W1OtIVw5mXNQyiuGLnpLLpG0mz/3GHEogpB7R4BZBekYiG4OzuhDXqsrGG1QvI8 NvOGP6F+Ih+oXihvEpTAusf3Q7EQP06IHhx3l/okquwntGxBX+YcFIRrOeYQGmdrokru xphDVXsyH66d5IKrsY891pzhYjgZr6ewnFSAI34e3A8fofUWLHhNiMxKQEPcq3OtCydK Miuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nwVSmZAL2EMRgtufrZz5eEfwgUoJxg5fsgWWCXA8eHs=; fh=CmSyVYIEcjWAsoiANsGVn2Fd1yxvvkujSIjgup/cCF4=; b=BZDwE5bRJVoFIOb1mEYWzMkYduwHtPzerdiY5G8dql2c1eoi99988rhEJPDrWBRqiy quzb/HhC6zxUWc9j8pTh8RW0MDdIZ2VjHnxNxugQSUQoIUth+b35H1EiZwzA93wYT3gT yarMXoiusP9RUNGzM3Yf/So80wxiC6w1YidClHzEjWYODOLOq0bsVSx3n0+9YhItyfVM QRroNnIyK0ppLIQezLJ66cDlF+6Jrfsz6mGjk8G9ARVjywPsTcXdDEEIwmeOEX4xF9U6 CMoE3UIZ2JO9j2J3lWjO98Tp4t8EFkrTmCX9htJq9blP9w2VV8kdgMNYiQ0gPAYasHiY 5ggQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DzTgHPdI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 5b1f17b1804b1-4264a23d728si18802215e9.179.2024.07.05.01.49.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 05 Jul 2024 01:49:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DzTgHPdI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sPebk-0001GP-Ou; Fri, 05 Jul 2024 04:47:57 -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 1sPebM-0000wo-Pu for qemu-devel@nongnu.org; Fri, 05 Jul 2024 04:47:33 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sPeb9-0004Bq-0f for qemu-devel@nongnu.org; Fri, 05 Jul 2024 04:47:32 -0400 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a7527afa23cso166209666b.2 for ; Fri, 05 Jul 2024 01:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720169237; x=1720774037; 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=nwVSmZAL2EMRgtufrZz5eEfwgUoJxg5fsgWWCXA8eHs=; b=DzTgHPdI6MBQ00F3bRh+gkd8b3RzOzD+hz63FZfJB1h7SkU7I1OkmPfxcybXvEke2M 0+Bmu0TdbAzK/UZs6INdIbT9M1p2w9f0LGZuSqZv6g4Z4eemJ09UMWndzegJhDQHC0X/ U2tg/2gMXNj872lxwtYd9Jsr6F9GxC1/9xQX8FIVpXJA6gP4C8ADqspfcbKtRdOvwfYP PuYmwtSrTL4iZNo+YXl2LrYMe1xxKXCaPAwNcW1CWq2Zb6ji1RDUDfZhZvghp6re8beW riwsd6QSYAidHv5APhdMQspIXpEBgcvcTAMRJYGclep3eE1gHqqlIWrF5tHduCX4qpxC q5eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720169237; x=1720774037; 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=nwVSmZAL2EMRgtufrZz5eEfwgUoJxg5fsgWWCXA8eHs=; b=pJM6QKJNmPGcSga/Z+OCMsbaqvnW67jW6fONb2gTDbp3MJvmdywDBeToYcTO8xpnk0 XQVvzJx+GDFR7duOIygi5yCn1lO75SncZucI/QBj77ItWnJBBiRJtMeqd7MXxIKmK6KG IaokOXNxc+mMYtNSf9dmOVzrKvUt5TQl+IqTDssa5ypCi16LkNVddp1FhT21WudSCE6n SXUh1fH1MhEPBstRbPMcArQp1xoLeW78zUcuNcJdntOH/aRwG7DiAwv0hy6t7eEtMpHW EyYbiQi26Ojv4y2ZQ1QfiO2OgK2kVdZHuaFYO7Vs7MCIkMg7Uf26/cmiRQX39netDleg b2mw== X-Gm-Message-State: AOJu0YyqlD5nltQ1NOMN5imwZ/6Zjj34Ke+2PxbfbmICqzWk6rIi92vM LWYbNATtXbeceBxtZ24zXA0C8IeKPUS9mTsPJjGawCHtgY6l3WYtoZJxCuX7yQ8= X-Received: by 2002:a17:906:88f:b0:a6f:b0d0:1beb with SMTP id a640c23a62f3a-a77ba46e0bamr307099466b.24.1720169237237; Fri, 05 Jul 2024 01:47:17 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72ab0652d8sm667329766b.98.2024.07.05.01.47.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 01:47:16 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id CEFF46216F; Fri, 5 Jul 2024 09:40:50 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Wainer dos Santos Moschetta , Beraldo Leal , David Hildenbrand , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Alexandre Iooss , Thomas Huth , Mahmoud Mandour , Peter Maydell , qemu-arm@nongnu.org, Aleksandar Rikalo , Mads Ynddal , Yanan Wang , Eduardo Habkost , Peter Xu , Richard Henderson , Marcel Apfelbaum , Paul Burton , Stefan Hajnoczi , =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier , Gustavo Romero Subject: [PATCH v2 32/40] gdbstub: Add support for target-specific stubs Date: Fri, 5 Jul 2024 09:40:39 +0100 Message-Id: <20240705084047.857176-33-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240705084047.857176-1-alex.bennee@linaro.org> References: <20240705084047.857176-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x62a.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=unavailable 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée Signed-off-by: Alex Bennée Message-Id: <20240628050850.536447-4-gustavo.romero@linaro.org> --- include/gdbstub/commands.h | 22 ++++++++ gdbstub/gdbstub.c | 102 ++++++++++++++++++++++++++++++++++--- 2 files changed, 118 insertions(+), 6 deletions(-) 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); +/** + * 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 string. + * @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(); } +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 CPUs yet + * so assert the feature strings are the same on all CPUs, or is set only + * once (1 CPU). + */ + g_assert(extended_qsupported_features == NULL || + g_strcmp0(extended_qsupported_features, qsupported_features) == 0); + + extended_qsupported_features = 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, void *user_ctx) } g_string_append(gdbserver_state.str_buf, ";vContSupported+;multiprocess+"); + + if (extended_qsupported_features) { + g_string_append(gdbserver_state.str_buf, extended_qsupported_features); + } + gdb_put_strbuf(); } @@ -1729,6 +1748,41 @@ static const GdbCmdParseEntry gdb_gen_query_set_common_table[] = { }, }; +/* 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 = 0; i < size; i++) { + if (!(c[i].handler == d[i].handler && + g_strcmp0(c[i].cmd, d[i].cmd) == 0 && + c[i].cmd_startswith == d[i].cmd_startswith && + g_strcmp0(c[i].schema, d[i].schema) == 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 CPUs yet + * so assert query table is the same on all CPUs, or is set only once + * (1 CPU). + */ + g_assert(extended_query_table == NULL || + (extended_query_table_size == size && + cmp_cmds(extended_query_table, table, size))); + + extended_query_table = table; + extended_query_table_size = size; +} + static const GdbCmdParseEntry gdb_gen_query_table[] = { { .handler = handle_query_curr_tid, @@ -1821,6 +1875,22 @@ static const GdbCmdParseEntry gdb_gen_query_table[] = { #endif }; +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 CPUs yet + * so assert set table is the same on all CPUs, or is set only once (1 CPU). + */ + g_assert(extended_set_table == NULL || + (extended_set_table_size == size && + cmp_cmds(extended_set_table, table, size))); + + extended_set_table = table; + extended_set_table_size = size; +} + static const GdbCmdParseEntry gdb_gen_set_table[] = { /* Order is important if has same prefix */ { @@ -1859,11 +1929,21 @@ static void handle_gen_query(GArray *params, void *user_ctx) return; } - 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(""); } static void handle_gen_set(GArray *params, void *user_ctx) @@ -1878,11 +1958,21 @@ static void handle_gen_set(GArray *params, void *user_ctx) return; } - 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(""); } static void handle_target_halt(GArray *params, void *user_ctx)