From nobody Sun Nov 24 22:48:38 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=1719552109; cv=none; d=zohomail.com; s=zohoarc; b=HyumMca3WtslVsfZMUy0Aaj0qU/K5Ms5oS/dgcCoK1IQn6VFzkAK+3EVrV7ojHCw166RhaJeHXl17wxJiNLiBjJ8/sraWprdF03K556tlplaw33pKAUkQfK2fIEd8Q0hUxQQIECNhKyOvajkBZ3Fcb0njJE4FfvqsJn1q213D44= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719552109; 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=PsonJ1zRH/+YC/a6OR7EHJ04b9L1NQ9IXkQt5iZNFyk=; b=R1tI2QEGvzVrcwdaBABwJ+nGWv/LneC9Q0992gjcpV+KFVad2FKLCvRQIwsjd9lmGmT2bQ+xufVxM+Fvw3PamLiFORRA/dQMZjA6oV5U5M4ubCfOME3WtT+EfcZ4rdJ+N/BIfYcSGUtZpiaRSeWK0gIhLeCjBNvFeHk29AUsLMU= 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 1719552109881269.51078822066006; Thu, 27 Jun 2024 22:21:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN42n-0003FV-Ab; Fri, 28 Jun 2024 01:21:09 -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 1sN42h-0003Eg-Ta for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:03 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN42d-0008CT-Rz for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:03 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-707f9c3bd02so239873b3a.0 for ; Thu, 27 Jun 2024 22:20:59 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:391e:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6b2a16cdsm423932a12.46.2024.06.27.22.20.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 22:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719552058; x=1720156858; 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=PsonJ1zRH/+YC/a6OR7EHJ04b9L1NQ9IXkQt5iZNFyk=; b=Yk+X0SJZ8gg4IjA8xDZY56fUkAluveEEGPZm7kjqrU7TCV42AHggUObH/vPvyukBp+ fn7bOCThaC2ubnv99YPfczpKsUhBaVtdDsaw40jQk4OM6W8pZwTdKUqYCIfOc9LlADWu 5KA2CjovvZRcRrBvEuIJGMk1w9geWAumSgOSHmrOiZjCKkr+Ng5CuIv++ufg/+R/hXgX EPv8Yo8ecbE/ObwqX2MmJ3mbggxC0oVMSMC92Z/b8bc9bOnISO96z9048wQAGWv8OalC hKlMedGBS0e7RHp0Eedm9/RrhwpY4L93ZhDo7eRJbcfTv5ZwehUnQVBbKL6cYLGgkRxT hGww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719552058; x=1720156858; 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=PsonJ1zRH/+YC/a6OR7EHJ04b9L1NQ9IXkQt5iZNFyk=; b=SZ/s6hVJHnOk3j5Z/VQG5YW5J874KQvZXvXvyLg0w2VsNlWe5USMn4irW+I8cVQMsv 8qk1drsmYzzQZ+gNjHPe1AUUhzUedO2Jzow2X4csXrKshzhv36BK8bRaPUHcVOerQB9K XJPG69C3DV4Z0B27Ji+aecIDaI7njDmAuMGs3AdtH6tmzrk40ltZz4sQUJDP/Qayto1z WhFc+xIGjKPfHAxK/g4npq/b1q7xD2MBLjl4xFrI+XOlzEXteY694KqQBZaggorD65jL 218rakME+olLGp3fZmW3H9WrbWeDCE+OeN2f/LBx3fWpQysi5AWEgAFaH2i44POCRt2x rPnQ== X-Gm-Message-State: AOJu0Yxh+w18065FjBCdtFgfdlawJnwRUxaZh8TRE0YvIqJhueoaG4lG rOpVEcPG0YX/J+7ZHfHkd/Gp/00U6ljmGMHc8+i8ooy8xtkp+2tqiyYbj71tkhj15zeVveeLh0K I X-Google-Smtp-Source: AGHT+IHF6TofqLcfU9lrsrf6x37kfacHRbrczUyiLO7ioUNUnl78ge1JEe3UICEn2XjlV0Srkp1lOw== X-Received: by 2002:a05:6a00:3e1b:b0:705:cade:1f40 with SMTP id d2e1a72fcca58-70674593833mr16412176b3a.11.1719552057744; Thu, 27 Jun 2024 22:20:57 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v6 01/11] gdbstub: Clean up process_string_cmd Date: Fri, 28 Jun 2024 05:08:40 +0000 Message-Id: <20240628050850.536447-2-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628050850.536447-1-gustavo.romero@linaro.org> References: <20240628050850.536447-1-gustavo.romero@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=2607:f8b0:4864:20::42f; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x42f.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: 1719552111335100003 Change 'process_string_cmd' to return true on success and false on failure, instead of 0 and -1. Signed-off-by: Gustavo Romero Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- gdbstub/gdbstub.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index b3574997ea..37314b92e5 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -962,14 +962,14 @@ static inline int startswith(const char *string, cons= t char *pattern) return !strncmp(string, pattern, strlen(pattern)); } =20 -static int process_string_cmd(const char *data, - const GdbCmdParseEntry *cmds, int num_cmds) +static bool process_string_cmd(const char *data, + const GdbCmdParseEntry *cmds, int num_cmds) { int i; g_autoptr(GArray) params =3D g_array_new(false, true, sizeof(GdbCmdVar= iant)); =20 if (!cmds) { - return -1; + return false; } =20 for (i =3D 0; i < num_cmds; i++) { @@ -984,16 +984,16 @@ static int process_string_cmd(const char *data, if (cmd->schema) { if (cmd_parse_params(&data[strlen(cmd->cmd)], cmd->schema, params)) { - return -1; + return false; } } =20 gdbserver_state.allow_stop_reply =3D cmd->allow_stop_reply; cmd->handler(params, NULL); - return 0; + return true; } =20 - return -1; + return false; } =20 static void run_cmd_parser(const char *data, const GdbCmdParseEntry *cmd) @@ -1007,7 +1007,7 @@ static void run_cmd_parser(const char *data, const Gd= bCmdParseEntry *cmd) =20 /* 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(data, cmd, 1)) { + if (!process_string_cmd(data, cmd, 1)) { gdb_put_packet(""); } } @@ -1523,9 +1523,9 @@ static void handle_v_commands(GArray *params, void *u= ser_ctx) return; } =20 - if (process_string_cmd(get_param(params, 0)->data, - gdb_v_commands_table, - ARRAY_SIZE(gdb_v_commands_table))) { + if (!process_string_cmd(get_param(params, 0)->data, + gdb_v_commands_table, + ARRAY_SIZE(gdb_v_commands_table))) { gdb_put_packet(""); } } @@ -1889,15 +1889,15 @@ static void handle_gen_query(GArray *params, void *= user_ctx) return; } =20 - if (!process_string_cmd(get_param(params, 0)->data, - gdb_gen_query_set_common_table, - ARRAY_SIZE(gdb_gen_query_set_common_table))) { + if (process_string_cmd(get_param(params, 0)->data, + gdb_gen_query_set_common_table, + ARRAY_SIZE(gdb_gen_query_set_common_table))) { return; } =20 - if (process_string_cmd(get_param(params, 0)->data, - gdb_gen_query_table, - ARRAY_SIZE(gdb_gen_query_table))) { + if (!process_string_cmd(get_param(params, 0)->data, + gdb_gen_query_table, + ARRAY_SIZE(gdb_gen_query_table))) { gdb_put_packet(""); } } @@ -1908,13 +1908,13 @@ static void handle_gen_set(GArray *params, void *us= er_ctx) return; } =20 - if (!process_string_cmd(get_param(params, 0)->data, - gdb_gen_query_set_common_table, - ARRAY_SIZE(gdb_gen_query_set_common_table))) { + if (process_string_cmd(get_param(params, 0)->data, + gdb_gen_query_set_common_table, + ARRAY_SIZE(gdb_gen_query_set_common_table))) { return; } =20 - if (process_string_cmd(get_param(params, 0)->data, + if (!process_string_cmd(get_param(params, 0)->data, gdb_gen_set_table, ARRAY_SIZE(gdb_gen_set_table))) { gdb_put_packet(""); --=20 2.34.1 From nobody Sun Nov 24 22:48:38 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=1719552139; cv=none; d=zohomail.com; s=zohoarc; b=XzDDnsbgYm+jaD8ARxjnyelQPGv0a4gtfdWeRwkR+E1CW6Ze9LGG4833+My1cctape7S3KxOFbyKspD5T/65EPmXwITr5YOg+JKa8tdwY6NTVA6KV6tR+3ZlPcFgOldaQsVhjxzi3XsEO8YiX8DocLyauQ0P/TzX9L5a7I+Mnvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719552139; 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=vGtlSativWuALTsAtF8iqUXP3Q4aaI+FbaPsTHzhTaY=; b=lKBr9yW+Sb7IrV+MSJ0yvFOc/72xJIYOFCfngsW893klYAh4RIfqtzQu7oW2+gsS3c0iyJaXOR7Vd6ZgUEkbdxmV9tDjH9BqhRWI79OQ939iL+UjjhUEKOr+8u/mGPQ+rwnr/ek+YatO7w5CH5882WGQsULgkh/xPEI7fZMOunI= 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 1719552139573591.1597125742433; Thu, 27 Jun 2024 22:22:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN42p-0003GG-Dd; Fri, 28 Jun 2024 01:21:11 -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 1sN42n-0003Fn-KS for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:09 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN42h-0008Cj-Ta for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:08 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-7067a2e9607so196671b3a.3 for ; Thu, 27 Jun 2024 22:21:02 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:391e:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6b2a16cdsm423932a12.46.2024.06.27.22.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 22:20:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719552060; x=1720156860; 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=vGtlSativWuALTsAtF8iqUXP3Q4aaI+FbaPsTHzhTaY=; b=LcV15F05d91h+t9uEfbAy0kL0t1D5g5G13iRRVj52jl18WHxCGKXWL6gPsN2DyVAQr OSmLT3MjnVpZ8eImqHnK43a9mQyn40o9A5LBcCxeL1sla7pOTgZEiKi2vEyv6pMAFP6G w4FYKu8EWvPSHQwfNnPHr89BVbnSDsV+0EydawW21a186wyq0X7uY4KigDnm1mO9D+Dz cNXOZPUXHhvCknYWWfyjnP09Df82tcZTlRLyvp0xD6/B6a7snzeHEru+ZFaGrVF67r1C j+f5c6+ZKNpG7uL1oFXhk0Xorf8z4M4SWvRr64L7KaSp3NpZZCSTQrMZxdBULsDOqdWE ZaYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719552060; x=1720156860; 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=vGtlSativWuALTsAtF8iqUXP3Q4aaI+FbaPsTHzhTaY=; b=FNgYnVP9eAI55zWDHNLcWgOqkOxo5axLcZevQUxnosoTs9xXIdjLqzIJVzLun8iro6 TmzRLNMnr76tX3lMJ2Z1agO6ZUSXC5fmWa9O6iiCQjjH4d1v0zlK5iylGaQPqft5wJGA 17s25/VHa0X0rTAdPScVuGYr+0owK1KJgL8mqF0ZvU1L82vQnZmtKBXo9qJAlUWsZqrE lA6yiw19XNCyySj3vQQGjSmK0ezCTVeroxD0O4xBm8s/nIwh+7zKND2lrSUcwT+k3RAZ tkQqiv2OwqQKHrprFhRneXGSeD26mFvLs5SxvH3CC3F4d5z1Og/ymTIwQYm3ZddbWRfs GbIg== X-Gm-Message-State: AOJu0YzPDtlkbth73d5IJtPXJkmxaN2/mphYK8CMvoxkWtD9ki9iKMgz AJio46nIdMqRJSPA1BJze4T4pVwbZHyhwaOLEGQ7tL8pAXSeWD5r2X89sWVfxNMhgGgWDYKN78I V X-Google-Smtp-Source: AGHT+IElM0mJhHteiEVQ+64NY+8xYAc6vFmINmR69dcrPbVrpTpB15ZX59hjQLT8vjIPnqDBW+p4LQ== X-Received: by 2002:a62:b609:0:b0:706:4889:960d with SMTP id d2e1a72fcca58-70670ee7812mr16064325b3a.16.1719552060271; Thu, 27 Jun 2024 22:21:00 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v6 02/11] gdbstub: Move GdbCmdParseEntry into a new header file Date: Fri, 28 Jun 2024 05:08:41 +0000 Message-Id: <20240628050850.536447-3-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628050850.536447-1-gustavo.romero@linaro.org> References: <20240628050850.536447-1-gustavo.romero@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=2607:f8b0:4864:20::42d; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x42d.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: 1719552141423100003 Move GdbCmdParseEntry and its associated types into a separate header file to allow the use of GdbCmdParseEntry and other gdbstub command functions outside of gdbstub.c. Since GdbCmdParseEntry and get_param are now public, kdoc GdbCmdParseEntry and rename get_param to gdb_get_cmd_param. This commit also makes gdb_put_packet public since is used in gdbstub command handling. Signed-off-by: Gustavo Romero Reviewed-by: Alex Benn=C3=A9e --- gdbstub/gdbstub.c | 134 ++++++++++++++----------------------- gdbstub/internals.h | 22 ------ gdbstub/syscalls.c | 7 +- gdbstub/system.c | 7 +- gdbstub/user-target.c | 25 +++---- gdbstub/user.c | 7 +- include/gdbstub/commands.h | 72 ++++++++++++++++++++ 7 files changed, 146 insertions(+), 128 deletions(-) create mode 100644 include/gdbstub/commands.h diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 37314b92e5..9ff2f4177d 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -30,6 +30,7 @@ #include "qemu/error-report.h" #include "trace.h" #include "exec/gdbstub.h" +#include "gdbstub/commands.h" #include "gdbstub/syscalls.h" #ifdef CONFIG_USER_ONLY #include "accel/tcg/vcpu-state.h" @@ -920,43 +921,6 @@ static int cmd_parse_params(const char *data, const ch= ar *schema, return 0; } =20 -typedef void (*GdbCmdHandler)(GArray *params, void *user_ctx); - -/* - * cmd_startswith -> cmd is compared using startswith - * - * allow_stop_reply -> true iff the gdbstub can respond to this command wi= th a - * "stop reply" packet. The list of commands that accept such response is - * defined at the GDB Remote Serial Protocol documentation. see: - * https://sourceware.org/gdb/onlinedocs/gdb/Stop-Reply-Packets.html#Sto= p-Reply-Packets. - * - * schema definitions: - * Each schema parameter entry consists of 2 chars, - * the first char represents the parameter type handling - * the second char represents the delimiter for the next parameter - * - * Currently supported schema types: - * 'l' -> unsigned long (stored in .val_ul) - * 'L' -> unsigned long long (stored in .val_ull) - * 's' -> string (stored in .data) - * 'o' -> single char (stored in .opcode) - * 't' -> thread id (stored in .thread_id) - * '?' -> skip according to delimiter - * - * Currently supported delimiters: - * '?' -> Stop at any delimiter (",;:=3D\0") - * '0' -> Stop at "\0" - * '.' -> Skip 1 char unless reached "\0" - * Any other value is treated as the delimiter value itself - */ -typedef struct GdbCmdParseEntry { - GdbCmdHandler handler; - const char *cmd; - bool cmd_startswith; - const char *schema; - bool allow_stop_reply; -} GdbCmdParseEntry; - static inline int startswith(const char *string, const char *pattern) { return !strncmp(string, pattern, strlen(pattern)); @@ -1023,7 +987,7 @@ static void handle_detach(GArray *params, void *user_c= tx) return; } =20 - pid =3D get_param(params, 0)->val_ul; + pid =3D gdb_get_cmd_param(params, 0)->val_ul; } =20 #ifdef CONFIG_USER_ONLY @@ -1061,13 +1025,13 @@ static void handle_thread_alive(GArray *params, voi= d *user_ctx) return; } =20 - if (get_param(params, 0)->thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { + if (gdb_get_cmd_param(params, 0)->thread_id.kind =3D=3D GDB_READ_THREA= D_ERR) { gdb_put_packet("E22"); return; } =20 - cpu =3D gdb_get_cpu(get_param(params, 0)->thread_id.pid, - get_param(params, 0)->thread_id.tid); + cpu =3D gdb_get_cpu(gdb_get_cmd_param(params, 0)->thread_id.pid, + gdb_get_cmd_param(params, 0)->thread_id.tid); if (!cpu) { gdb_put_packet("E22"); return; @@ -1079,7 +1043,7 @@ static void handle_thread_alive(GArray *params, void = *user_ctx) static void handle_continue(GArray *params, void *user_ctx) { if (params->len) { - gdb_set_cpu_pc(get_param(params, 0)->val_ull); + gdb_set_cpu_pc(gdb_get_cmd_param(params, 0)->val_ull); } =20 gdbserver_state.signal =3D 0; @@ -1095,7 +1059,7 @@ static void handle_cont_with_sig(GArray *params, void= *user_ctx) * omit the addr parameter */ if (params->len) { - signal =3D get_param(params, 0)->val_ul; + signal =3D gdb_get_cmd_param(params, 0)->val_ul; } =20 gdbserver_state.signal =3D gdb_signal_to_target(signal); @@ -1115,18 +1079,18 @@ static void handle_set_thread(GArray *params, void = *user_ctx) return; } =20 - if (get_param(params, 1)->thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { + if (gdb_get_cmd_param(params, 1)->thread_id.kind =3D=3D GDB_READ_THREA= D_ERR) { gdb_put_packet("E22"); return; } =20 - if (get_param(params, 1)->thread_id.kind !=3D GDB_ONE_THREAD) { + if (gdb_get_cmd_param(params, 1)->thread_id.kind !=3D GDB_ONE_THREAD) { gdb_put_packet("OK"); return; } =20 - pid =3D get_param(params, 1)->thread_id.pid; - tid =3D get_param(params, 1)->thread_id.tid; + pid =3D gdb_get_cmd_param(params, 1)->thread_id.pid; + tid =3D gdb_get_cmd_param(params, 1)->thread_id.tid; #ifdef CONFIG_USER_ONLY if (gdb_handle_set_thread_user(pid, tid)) { return; @@ -1142,7 +1106,7 @@ static void handle_set_thread(GArray *params, void *u= ser_ctx) * Note: This command is deprecated and modern gdb's will be using the * vCont command instead. */ - switch (get_param(params, 0)->opcode) { + switch (gdb_get_cmd_param(params, 0)->opcode) { case 'c': gdbserver_state.c_cpu =3D cpu; gdb_put_packet("OK"); @@ -1167,9 +1131,9 @@ static void handle_insert_bp(GArray *params, void *us= er_ctx) } =20 res =3D gdb_breakpoint_insert(gdbserver_state.c_cpu, - get_param(params, 0)->val_ul, - get_param(params, 1)->val_ull, - get_param(params, 2)->val_ull); + gdb_get_cmd_param(params, 0)->val_ul, + gdb_get_cmd_param(params, 1)->val_ull, + gdb_get_cmd_param(params, 2)->val_ull); if (res >=3D 0) { gdb_put_packet("OK"); return; @@ -1191,9 +1155,9 @@ static void handle_remove_bp(GArray *params, void *us= er_ctx) } =20 res =3D gdb_breakpoint_remove(gdbserver_state.c_cpu, - get_param(params, 0)->val_ul, - get_param(params, 1)->val_ull, - get_param(params, 2)->val_ull); + gdb_get_cmd_param(params, 0)->val_ul, + gdb_get_cmd_param(params, 1)->val_ull, + gdb_get_cmd_param(params, 2)->val_ull); if (res >=3D 0) { gdb_put_packet("OK"); return; @@ -1225,10 +1189,10 @@ static void handle_set_reg(GArray *params, void *us= er_ctx) return; } =20 - reg_size =3D strlen(get_param(params, 1)->data) / 2; - gdb_hextomem(gdbserver_state.mem_buf, get_param(params, 1)->data, reg_= size); + reg_size =3D strlen(gdb_get_cmd_param(params, 1)->data) / 2; + gdb_hextomem(gdbserver_state.mem_buf, gdb_get_cmd_param(params, 1)->da= ta, reg_size); gdb_write_register(gdbserver_state.g_cpu, gdbserver_state.mem_buf->dat= a, - get_param(params, 0)->val_ull); + gdb_get_cmd_param(params, 0)->val_ull); gdb_put_packet("OK"); } =20 @@ -1243,7 +1207,7 @@ static void handle_get_reg(GArray *params, void *user= _ctx) =20 reg_size =3D gdb_read_register(gdbserver_state.g_cpu, gdbserver_state.mem_buf, - get_param(params, 0)->val_ull); + gdb_get_cmd_param(params, 0)->val_ull); if (!reg_size) { gdb_put_packet("E14"); return; @@ -1264,16 +1228,16 @@ static void handle_write_mem(GArray *params, void *= user_ctx) } =20 /* gdb_hextomem() reads 2*len bytes */ - if (get_param(params, 1)->val_ull > - strlen(get_param(params, 2)->data) / 2) { + if (gdb_get_cmd_param(params, 1)->val_ull > + strlen(gdb_get_cmd_param(params, 2)->data) / 2) { gdb_put_packet("E22"); return; } =20 - gdb_hextomem(gdbserver_state.mem_buf, get_param(params, 2)->data, - get_param(params, 1)->val_ull); + gdb_hextomem(gdbserver_state.mem_buf, gdb_get_cmd_param(params, 2)->da= ta, + gdb_get_cmd_param(params, 1)->val_ull); if (gdb_target_memory_rw_debug(gdbserver_state.g_cpu, - get_param(params, 0)->val_ull, + gdb_get_cmd_param(params, 0)->val_ull, gdbserver_state.mem_buf->data, gdbserver_state.mem_buf->len, true)) { gdb_put_packet("E14"); @@ -1291,16 +1255,16 @@ static void handle_read_mem(GArray *params, void *u= ser_ctx) } =20 /* gdb_memtohex() doubles the required space */ - if (get_param(params, 1)->val_ull > MAX_PACKET_LENGTH / 2) { + if (gdb_get_cmd_param(params, 1)->val_ull > MAX_PACKET_LENGTH / 2) { gdb_put_packet("E22"); return; } =20 g_byte_array_set_size(gdbserver_state.mem_buf, - get_param(params, 1)->val_ull); + gdb_get_cmd_param(params, 1)->val_ull); =20 if (gdb_target_memory_rw_debug(gdbserver_state.g_cpu, - get_param(params, 0)->val_ull, + gdb_get_cmd_param(params, 0)->val_ull, gdbserver_state.mem_buf->data, gdbserver_state.mem_buf->len, false)) { gdb_put_packet("E14"); @@ -1324,8 +1288,8 @@ static void handle_write_all_regs(GArray *params, voi= d *user_ctx) } =20 cpu_synchronize_state(gdbserver_state.g_cpu); - len =3D strlen(get_param(params, 0)->data) / 2; - gdb_hextomem(gdbserver_state.mem_buf, get_param(params, 0)->data, len); + len =3D strlen(gdb_get_cmd_param(params, 0)->data) / 2; + gdb_hextomem(gdbserver_state.mem_buf, gdb_get_cmd_param(params, 0)->da= ta, len); registers =3D gdbserver_state.mem_buf->data; for (reg_id =3D 0; reg_id < gdbserver_state.g_cpu->gdb_num_g_regs && len > 0; @@ -1360,7 +1324,7 @@ static void handle_read_all_regs(GArray *params, void= *user_ctx) static void handle_step(GArray *params, void *user_ctx) { if (params->len) { - gdb_set_cpu_pc(get_param(params, 0)->val_ull); + gdb_set_cpu_pc(gdb_get_cmd_param(params, 0)->val_ull); } =20 cpu_single_step(gdbserver_state.c_cpu, gdbserver_state.sstep_flags); @@ -1373,7 +1337,7 @@ static void handle_backward(GArray *params, void *use= r_ctx) gdb_put_packet("E22"); } if (params->len =3D=3D 1) { - switch (get_param(params, 0)->opcode) { + switch (gdb_get_cmd_param(params, 0)->opcode) { case 's': if (replay_reverse_step()) { gdb_continue(); @@ -1408,7 +1372,7 @@ static void handle_v_cont(GArray *params, void *user_= ctx) return; } =20 - res =3D gdb_handle_vcont(get_param(params, 0)->data); + res =3D gdb_handle_vcont(gdb_get_cmd_param(params, 0)->data); if ((res =3D=3D -EINVAL) || (res =3D=3D -ERANGE)) { gdb_put_packet("E22"); } else if (res) { @@ -1426,7 +1390,7 @@ static void handle_v_attach(GArray *params, void *use= r_ctx) goto cleanup; } =20 - process =3D gdb_get_process(get_param(params, 0)->val_ul); + process =3D gdb_get_process(gdb_get_cmd_param(params, 0)->val_ul); if (!process) { goto cleanup; } @@ -1523,7 +1487,7 @@ static void handle_v_commands(GArray *params, void *u= ser_ctx) return; } =20 - if (!process_string_cmd(get_param(params, 0)->data, + if (!process_string_cmd(gdb_get_cmd_param(params, 0)->data, gdb_v_commands_table, ARRAY_SIZE(gdb_v_commands_table))) { gdb_put_packet(""); @@ -1555,7 +1519,7 @@ static void handle_set_qemu_sstep(GArray *params, voi= d *user_ctx) return; } =20 - new_sstep_flags =3D get_param(params, 0)->val_ul; + new_sstep_flags =3D gdb_get_cmd_param(params, 0)->val_ul; =20 if (new_sstep_flags & ~gdbserver_state.supported_sstep_flags) { gdb_put_packet("E22"); @@ -1615,13 +1579,13 @@ static void handle_query_thread_extra(GArray *param= s, void *user_ctx) CPUState *cpu; =20 if (!params->len || - get_param(params, 0)->thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { + gdb_get_cmd_param(params, 0)->thread_id.kind =3D=3D GDB_READ_THREA= D_ERR) { gdb_put_packet("E22"); return; } =20 - cpu =3D gdb_get_cpu(get_param(params, 0)->thread_id.pid, - get_param(params, 0)->thread_id.tid); + cpu =3D gdb_get_cpu(gdb_get_cmd_param(params, 0)->thread_id.pid, + gdb_get_cmd_param(params, 0)->thread_id.tid); if (!cpu) { return; } @@ -1673,7 +1637,7 @@ static void handle_query_supported(GArray *params, vo= id *user_ctx) #endif =20 if (params->len) { - const char *gdb_supported =3D get_param(params, 0)->data; + const char *gdb_supported =3D gdb_get_cmd_param(params, 0)->data; =20 if (strstr(gdb_supported, "multiprocess+")) { gdbserver_state.multiprocess =3D true; @@ -1707,15 +1671,15 @@ static void handle_query_xfer_features(GArray *para= ms, void *user_ctx) return; } =20 - p =3D get_param(params, 0)->data; + p =3D gdb_get_cmd_param(params, 0)->data; xml =3D get_feature_xml(p, &p, process); if (!xml) { gdb_put_packet("E00"); return; } =20 - addr =3D get_param(params, 1)->val_ul; - len =3D get_param(params, 2)->val_ul; + addr =3D gdb_get_cmd_param(params, 1)->val_ul; + len =3D gdb_get_cmd_param(params, 2)->val_ul; total_len =3D strlen(xml); if (addr > total_len) { gdb_put_packet("E00"); @@ -1889,13 +1853,13 @@ static void handle_gen_query(GArray *params, void *= user_ctx) return; } =20 - if (process_string_cmd(get_param(params, 0)->data, + if (process_string_cmd(gdb_get_cmd_param(params, 0)->data, gdb_gen_query_set_common_table, ARRAY_SIZE(gdb_gen_query_set_common_table))) { return; } =20 - if (!process_string_cmd(get_param(params, 0)->data, + if (!process_string_cmd(gdb_get_cmd_param(params, 0)->data, gdb_gen_query_table, ARRAY_SIZE(gdb_gen_query_table))) { gdb_put_packet(""); @@ -1908,13 +1872,13 @@ static void handle_gen_set(GArray *params, void *us= er_ctx) return; } =20 - if (process_string_cmd(get_param(params, 0)->data, + if (process_string_cmd(gdb_get_cmd_param(params, 0)->data, gdb_gen_query_set_common_table, ARRAY_SIZE(gdb_gen_query_set_common_table))) { return; } =20 - if (!process_string_cmd(get_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(""); diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 32f9f63297..34121dc61a 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -106,7 +106,6 @@ static inline int tohex(int v) */ =20 void gdb_put_strbuf(void); -int gdb_put_packet(const char *buf); int gdb_put_packet_binary(const char *buf, int len, bool dump); void gdb_hextomem(GByteArray *mem, const char *buf, int len); void gdb_memtohex(GString *buf, const uint8_t *mem, int len); @@ -166,27 +165,6 @@ void gdb_put_buffer(const uint8_t *buf, int len); */ void gdb_init_gdbserver_state(void); =20 -typedef enum GDBThreadIdKind { - GDB_ONE_THREAD =3D 0, - GDB_ALL_THREADS, /* One process, all threads */ - GDB_ALL_PROCESSES, - GDB_READ_THREAD_ERR -} GDBThreadIdKind; - -typedef union GdbCmdVariant { - const char *data; - uint8_t opcode; - unsigned long val_ul; - unsigned long long val_ull; - struct { - GDBThreadIdKind kind; - uint32_t pid; - uint32_t tid; - } thread_id; -} GdbCmdVariant; - -#define get_param(p, i) (&g_array_index(p, GdbCmdVariant, i)) - void gdb_handle_query_rcmd(GArray *params, void *ctx); /* system */ void gdb_handle_query_offsets(GArray *params, void *user_ctx); /* user */ void gdb_handle_query_xfer_auxv(GArray *params, void *user_ctx); /*user */ diff --git a/gdbstub/syscalls.c b/gdbstub/syscalls.c index 02e3a8f74c..4e1295b782 100644 --- a/gdbstub/syscalls.c +++ b/gdbstub/syscalls.c @@ -16,6 +16,7 @@ #include "sysemu/runstate.h" #include "gdbstub/user.h" #include "gdbstub/syscalls.h" +#include "gdbstub/commands.h" #include "trace.h" #include "internals.h" =20 @@ -154,9 +155,9 @@ void gdb_handle_file_io(GArray *params, void *user_ctx) uint64_t ret; int err; =20 - ret =3D get_param(params, 0)->val_ull; + ret =3D gdb_get_cmd_param(params, 0)->val_ull; if (params->len >=3D 2) { - err =3D get_param(params, 1)->val_ull; + err =3D gdb_get_cmd_param(params, 1)->val_ull; } else { err =3D 0; } @@ -196,7 +197,7 @@ void gdb_handle_file_io(GArray *params, void *user_ctx) gdbserver_syscall_state.current_syscall_cb =3D NULL; } =20 - if (params->len >=3D 3 && get_param(params, 2)->opcode =3D=3D (uint8_t= )'C') { + if (params->len >=3D 3 && gdb_get_cmd_param(params, 2)->opcode =3D=3D = (uint8_t)'C') { gdb_put_packet("T02"); return; } diff --git a/gdbstub/system.c b/gdbstub/system.c index d235403855..1ad87fe7fd 100644 --- a/gdbstub/system.c +++ b/gdbstub/system.c @@ -16,6 +16,7 @@ #include "qemu/cutils.h" #include "exec/gdbstub.h" #include "gdbstub/syscalls.h" +#include "gdbstub/commands.h" #include "exec/hwaddr.h" #include "exec/tb-flush.h" #include "sysemu/cpus.h" @@ -501,7 +502,7 @@ void gdb_handle_set_qemu_phy_mem_mode(GArray *params, v= oid *ctx) return; } =20 - if (!get_param(params, 0)->val_ul) { + if (!gdb_get_cmd_param(params, 0)->val_ul) { phy_memory_mode =3D 0; } else { phy_memory_mode =3D 1; @@ -519,7 +520,7 @@ void gdb_handle_query_rcmd(GArray *params, void *ctx) return; } =20 - len =3D strlen(get_param(params, 0)->data); + len =3D strlen(gdb_get_cmd_param(params, 0)->data); if (len % 2) { gdb_put_packet("E01"); return; @@ -527,7 +528,7 @@ void gdb_handle_query_rcmd(GArray *params, void *ctx) =20 g_assert(gdbserver_state.mem_buf->len =3D=3D 0); len =3D len / 2; - gdb_hextomem(gdbserver_state.mem_buf, get_param(params, 0)->data, len); + gdb_hextomem(gdbserver_state.mem_buf, gdb_get_cmd_param(params, 0)->da= ta, len); g_byte_array_append(gdbserver_state.mem_buf, &zero, 1); qemu_chr_be_write(gdbserver_system_state.mon_chr, gdbserver_state.mem_buf->data, diff --git a/gdbstub/user-target.c b/gdbstub/user-target.c index a9c6c64512..b5e01fd8b0 100644 --- a/gdbstub/user-target.c +++ b/gdbstub/user-target.c @@ -9,6 +9,7 @@ =20 #include "qemu/osdep.h" #include "exec/gdbstub.h" +#include "gdbstub/commands.h" #include "qemu.h" #include "internals.h" #ifdef CONFIG_LINUX @@ -250,8 +251,8 @@ void gdb_handle_query_xfer_auxv(GArray *params, void *u= ser_ctx) return; } =20 - offset =3D get_param(params, 0)->val_ul; - len =3D get_param(params, 1)->val_ul; + offset =3D gdb_get_cmd_param(params, 0)->val_ul; + len =3D gdb_get_cmd_param(params, 1)->val_ul; ts =3D get_task_state(gdbserver_state.c_cpu); saved_auxv =3D ts->info->saved_auxv; auxv_len =3D ts->info->auxv_len; @@ -288,7 +289,7 @@ void gdb_handle_query_xfer_auxv(GArray *params, void *u= ser_ctx) =20 static const char *get_filename_param(GArray *params, int i) { - const char *hex_filename =3D get_param(params, i)->data; + const char *hex_filename =3D gdb_get_cmd_param(params, i)->data; gdb_hextomem(gdbserver_state.mem_buf, hex_filename, strlen(hex_filename) / 2); g_byte_array_append(gdbserver_state.mem_buf, (const guint8 *)"", 1); @@ -306,8 +307,8 @@ static void hostio_reply_with_data(const void *buf, siz= e_t n) void gdb_handle_v_file_open(GArray *params, void *user_ctx) { const char *filename =3D get_filename_param(params, 0); - uint64_t flags =3D get_param(params, 1)->val_ull; - uint64_t mode =3D get_param(params, 2)->val_ull; + uint64_t flags =3D gdb_get_cmd_param(params, 1)->val_ull; + uint64_t mode =3D gdb_get_cmd_param(params, 2)->val_ull; =20 #ifdef CONFIG_LINUX int fd =3D do_guest_openat(cpu_env(gdbserver_state.g_cpu), 0, filename, @@ -325,7 +326,7 @@ void gdb_handle_v_file_open(GArray *params, void *user_= ctx) =20 void gdb_handle_v_file_close(GArray *params, void *user_ctx) { - int fd =3D get_param(params, 0)->val_ul; + int fd =3D gdb_get_cmd_param(params, 0)->val_ul; =20 if (close(fd) =3D=3D -1) { g_string_printf(gdbserver_state.str_buf, "F-1,%d", errno); @@ -338,9 +339,9 @@ void gdb_handle_v_file_close(GArray *params, void *user= _ctx) =20 void gdb_handle_v_file_pread(GArray *params, void *user_ctx) { - int fd =3D get_param(params, 0)->val_ul; - size_t count =3D get_param(params, 1)->val_ull; - off_t offset =3D get_param(params, 2)->val_ull; + int fd =3D gdb_get_cmd_param(params, 0)->val_ul; + size_t count =3D gdb_get_cmd_param(params, 1)->val_ull; + off_t offset =3D gdb_get_cmd_param(params, 2)->val_ull; =20 size_t bufsiz =3D MIN(count, BUFSIZ); g_autofree char *buf =3D g_try_malloc(bufsiz); @@ -383,9 +384,9 @@ void gdb_handle_v_file_readlink(GArray *params, void *u= ser_ctx) =20 void gdb_handle_query_xfer_exec_file(GArray *params, void *user_ctx) { - uint32_t pid =3D get_param(params, 0)->val_ul; - uint32_t offset =3D get_param(params, 1)->val_ul; - uint32_t length =3D get_param(params, 2)->val_ul; + uint32_t pid =3D gdb_get_cmd_param(params, 0)->val_ul; + uint32_t offset =3D gdb_get_cmd_param(params, 1)->val_ul; + uint32_t length =3D gdb_get_cmd_param(params, 2)->val_ul; =20 GDBProcess *process =3D gdb_get_process(pid); if (!process) { diff --git a/gdbstub/user.c b/gdbstub/user.c index e34b58b407..b36033bc7a 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -16,6 +16,7 @@ #include "exec/hwaddr.h" #include "exec/tb-flush.h" #include "exec/gdbstub.h" +#include "gdbstub/commands.h" #include "gdbstub/syscalls.h" #include "gdbstub/user.h" #include "gdbstub/enums.h" @@ -793,7 +794,7 @@ void gdb_syscall_return(CPUState *cs, int num) =20 void gdb_handle_set_catch_syscalls(GArray *params, void *user_ctx) { - const char *param =3D get_param(params, 0)->data; + const char *param =3D gdb_get_cmd_param(params, 0)->data; GDBSyscallsMask catch_syscalls_mask; bool catch_all_syscalls; unsigned int num; @@ -858,8 +859,8 @@ void gdb_handle_query_xfer_siginfo(GArray *params, void= *user_ctx) unsigned long offset, len; uint8_t *siginfo_offset; =20 - offset =3D get_param(params, 0)->val_ul; - len =3D get_param(params, 1)->val_ul; + offset =3D gdb_get_cmd_param(params, 0)->val_ul; + len =3D gdb_get_cmd_param(params, 1)->val_ul; =20 if (offset + len > gdbserver_user_state.siginfo_len) { /* Invalid offset and/or requested length. */ diff --git a/include/gdbstub/commands.h b/include/gdbstub/commands.h new file mode 100644 index 0000000000..639257493e --- /dev/null +++ b/include/gdbstub/commands.h @@ -0,0 +1,72 @@ +#ifndef GDBSTUB_COMMANDS_H +#define GDBSTUB + +typedef void (*GdbCmdHandler)(GArray *params, void *user_ctx); + +typedef enum GDBThreadIdKind { + GDB_ONE_THREAD =3D 0, + GDB_ALL_THREADS, /* One process, all threads */ + GDB_ALL_PROCESSES, + GDB_READ_THREAD_ERR +} GDBThreadIdKind; + +typedef union GdbCmdVariant { + const char *data; + uint8_t opcode; + unsigned long val_ul; + unsigned long long val_ull; + struct { + GDBThreadIdKind kind; + uint32_t pid; + uint32_t tid; + } thread_id; +} GdbCmdVariant; + +#define gdb_get_cmd_param(p, i) (&g_array_index(p, GdbCmdVariant, i)) + +/** + * typedef GdbCmdParseEntry - gdb command parser + * + * This structure keeps the information necessary to match a gdb command, + * parse it (extract its parameters), and select the correct handler for i= t. + * + * @cmd: The command to be matched + * @cmd_startswith: If true, @cmd is compared using startswith + * @schema: Each schema for the command parameter entry consists of 2 char= s, + * the first char represents the parameter type handling the second char + * represents the delimiter for the next parameter. + * + * Currently supported schema types: + * 'l' -> unsigned long (stored in .val_ul) + * 'L' -> unsigned long long (stored in .val_ull) + * 's' -> string (stored in .data) + * 'o' -> single char (stored in .opcode) + * 't' -> thread id (stored in .thread_id) + * '?' -> skip according to delimiter + * + * Currently supported delimiters: + * '?' -> Stop at any delimiter (",;:=3D\0") + * '0' -> Stop at "\0" + * '.' -> Skip 1 char unless reached "\0" + * Any other value is treated as the delimiter value itself + * + * @allow_stop_reply: True iff the gdbstub can respond to this command wit= h a + * "stop reply" packet. The list of commands that accept such response is + * defined at the GDB Remote Serial Protocol documentation. See: + * https://sourceware.org/gdb/onlinedocs/gdb/Stop-Reply-Packets.html#Stop-= Reply-Packets. + */ +typedef struct GdbCmdParseEntry { + GdbCmdHandler handler; + const char *cmd; + bool cmd_startswith; + const char *schema; + bool allow_stop_reply; +} GdbCmdParseEntry; + +/** + * gdb_put_packet() - put string into gdb server's buffer so it is sent + * to the client + */ +int gdb_put_packet(const char *buf); + +#endif /* GDBSTUB_COMMANDS_H */ --=20 2.34.1 From nobody Sun Nov 24 22:48:38 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=1719552132; cv=none; d=zohomail.com; s=zohoarc; b=HSQWvj1svn/IFZM1l2fNGFmMrR4byKiK5VxpT9hx/BKi3wkWhLDADu6LEEZlpEuMQ4W+Cf6J8bwO08Mrh6eTghwym2nr6dgg3esVfohPDhUepVuY5o9cOielgLy/zjnPXZfIQc+nkbqhN+ao8qINuwR85YKGNQlYck0HwMqIQsQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719552132; 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=b2VaaTPgTAEqVDnMnsMoaFor8kxb0lDdN/vBY1aKTbA=; b=ZZiw+05iNFRziwh3r4aaPB3/Wxzu/9wCSCnLLeWaUIWGImcTWXXjvGDydotelMS8MlqvXTwLPWgJfYVBS3Nw3A7E3ryrBF0YpUwSGqn9OvA5B/zr87aQS5nDzkMl0bxj+NMiKn65rqZehDUp0J7ZoBwEgXaCo19B6unKCrlKQPo= 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 1719552132849254.9345546507377; Thu, 27 Jun 2024 22:22:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN42p-0003GN-Ou; Fri, 28 Jun 2024 01:21:11 -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 1sN42n-0003Fo-L6 for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:09 -0400 Received: from mail-yb1-xb32.google.com ([2607:f8b0:4864:20::b32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN42j-0008D1-J4 for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:08 -0400 Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-dfe1aa7cce2so172438276.1 for ; Thu, 27 Jun 2024 22:21:04 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:391e:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6b2a16cdsm423932a12.46.2024.06.27.22.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 22:21:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719552063; x=1720156863; 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=b2VaaTPgTAEqVDnMnsMoaFor8kxb0lDdN/vBY1aKTbA=; b=Zpqpyd9GANdO52FqkUpEfRHNys0KPEIugrJOZJoffk5h4RaeCeIGEnl8+U0W0QH0xF yh9PVbreyuhZrSv8maC0DKJhOknrFhhktUbHGonP9mOkA5jPvT36IyJ9lI/aPHvNOZhY Eq+hX1hG0vA2DTsI8xlFwd30EjwRwv2uAAisOgDh89ThIN9mhx8kwNHX4NKPafO4Uo7/ Z/N1Os7IVpN5zlXMOSLOKf/08KmBiGOgUYa8w9iWrEF4gVKKNXipJhdF9AwZyT7s8Gib b2sxCeoVCDEArMT4voHvLiZNY645lcn+8qxzzNxhh3+nxfiy8zwLxBRWIb1swG4LyOMz P2kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719552063; x=1720156863; 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=b2VaaTPgTAEqVDnMnsMoaFor8kxb0lDdN/vBY1aKTbA=; b=LAH2pg9YlMUcvndCC4tUQuRoecLlURfZMFiHecXMDeOI9Ddmxy7mft1yjYad+QV5ru BrcNCTguBgV8oO1dyiP21yLoRzxYS8UuAMX3gAiwOYf2WEDghcQYlIlCRpn550Hx/lhE eDp9BDCAez0+uTREgmIJZmhiEmagl+35f8eKMeLryvVGBpr/9OUlJkEKk3HMYSGZJT1W birlxjdk0H9y+Vq+esEV188hYJt4Z9+KWkJddlOS/dGP3cHIvQZZP8pDGP7+0NqfZC0b OOANRlwwHBeph//UlbYP1/1kjBnY4g0OXarMXXOvm/AlrPXUXkGLbE0HD/LjdrCAUfVt TFNw== X-Gm-Message-State: AOJu0YwVqtOsp304le4ew0M1VmbEfAbAM/iCJf9h/kBaLdGI+jfEQLsU vNHzUhRcch5ChNWDrKnV9Hr+kg+iVVmoEzpyx45Lc4joSlW+oM4HND+Xa4HKx1BMcBcMI5Ix539 p X-Google-Smtp-Source: AGHT+IHmVd4TSU/Cus/+uUhm1HcQxj1gEAoz+2jAba0C3dCdCHlUlKl6o+XNsDJhneycS/JH7O57WQ== X-Received: by 2002:a25:b10f:0:b0:e03:6023:ef75 with SMTP id 3f1490d57ef6-e036023f83dmr91679276.38.1719552062687; Thu, 27 Jun 2024 22:21:02 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v6 03/11] gdbstub: Add support for target-specific stubs Date: Fri, 28 Jun 2024 05:08:42 +0000 Message-Id: <20240628050850.536447-4-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628050850.536447-1-gustavo.romero@linaro.org> References: <20240628050850.536447-1-gustavo.romero@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=2607:f8b0:4864:20::b32; envelope-from=gustavo.romero@linaro.org; helo=mail-yb1-xb32.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: 1719552133405100003 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 --- gdbstub/gdbstub.c | 102 ++++++++++++++++++++++++++++++++++--- include/gdbstub/commands.h | 22 ++++++++ 2 files changed, 118 insertions(+), 6 deletions(-) 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) 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 */ --=20 2.34.1 From nobody Sun Nov 24 22:48:38 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=1719552152; cv=none; d=zohomail.com; s=zohoarc; b=E/vWu4vtEVSps9VjaQE3ClFfPwgghGvBrFUZcInMxYEyEMS1m+52AVHd36hf2Dj7QqnHTwl6CdVybdB95FTIrcWA2ZonfjFyEA0BIF7E44mfG1H0ImtfEgwQ9Qbeihx52DN6f25trJLLn8ScQuXOT7a975o3+pc28J0W33YD0WY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719552152; 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=4TUFa5RFEE0mlvWgiU9FcmbW/faCfrest43wgdD9lPk=; b=Tv/AAULFUk07n8dZhGCyuaFwEwy3z9089/hAq8QhBqb0cXJV5k7a/tCBvm/Q0otA3+9qm1o2i6fqPtQICmJDScI1a1fvJJiGYlOQp5rKMaFfX3h7jR+1ALqrKeWuGs6o4lIBh1qVIqnpTeEnDlB9DnFiAOwQiwoxk5MDpM+pTGg= 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 171955215297365.49072594519566; Thu, 27 Jun 2024 22:22:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN42p-0003GH-H7; Fri, 28 Jun 2024 01:21:11 -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 1sN42o-0003G5-Rv for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:10 -0400 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN42l-0008D7-He for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:10 -0400 Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-375f5c3ddb1so1121485ab.1 for ; Thu, 27 Jun 2024 22:21:07 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:391e:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6b2a16cdsm423932a12.46.2024.06.27.22.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 22:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719552065; x=1720156865; 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=4TUFa5RFEE0mlvWgiU9FcmbW/faCfrest43wgdD9lPk=; b=VNQHBiuON1gUNpJRthIe+yg9Qt0QjasWUew7+7eGsGOssBNzF8IDHCF/Gam3GtzlIs 1zQWm8EEh0DKTh7MsB588YwZ56fuTAWMdYuQV4xCKXnq9ln8A6ncRZ0qQo0GxEjyxTnZ MyqCliQiMcnp1ODcrEVtB/GdYU0CWqKFXa8jx2OiUvsWj8G665GxlpOTLnHgavPHr5GJ OJnhAYhDwYYcbVsJEDataLzZm7medSjn7SfPJqZt/2JZWsHiwUUduI1iYiH4eMX+otO0 3FbBE0rDd8VZcFUP+dUIa36AGgquqGZgNyTZuNBAcKBvWZhTEWMr1cJzm4WR6bpgDKtY nFSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719552065; x=1720156865; 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=4TUFa5RFEE0mlvWgiU9FcmbW/faCfrest43wgdD9lPk=; b=HDtE8iNYIfxEt48KHTaoQRAzzeSWsH2XMmdFKSfqCI084iji5IlgXBx9esK9lcydT7 kJiSB1ARg8G4K91adJnLhM6k8GgSmxVt4Sihv0sLfqVacBIbH1tiMOxeLxLqYNGmGoVi gnyhpiw09/kcVyF8hMWKLb0xVXxEHNBT8TAKEcFkATT6bvxk4gxvN6PDZgTd+i1OCxSp mncGlzlJZVhWrjOkccHCSk9+YDDcmAOzH7aj3nkfeYGAQIzG3SEevIXkNTZOx8GAuBVU SJhNwxzUT0uYoMCkyYpPP9pAISbQ34N7rJG+PZ1RR9qGzQw5DPnaMhP8Ih5pjhNvaEDi RZ5A== X-Gm-Message-State: AOJu0Yx43gXeeJKBTZVw8hzEhDZ5V+l0dNO08cFfvAlda7q1j1D/OHS3 nmuvrgqjIPjMfe6YnKU7QZyubjAUO61JHk4PXHbjWwuGLhgvuONJTr1nRUqgTavhor9mEqbmMsv t X-Google-Smtp-Source: AGHT+IHHohAaRvLevTIU6/cePEw518cQy/YAEQTTIZEzqIR70ZQRu12gAwy0Nd7hiLazaipBsMfOHQ== X-Received: by 2002:a92:c54c:0:b0:379:86a8:e42e with SMTP id e9e14a558f8ab-37986a8e56amr51904945ab.0.1719552065546; Thu, 27 Jun 2024 22:21:05 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v6 04/11] target/arm: Fix exception case in allocation_tag_mem_probe Date: Fri, 28 Jun 2024 05:08:43 +0000 Message-Id: <20240628050850.536447-5-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628050850.536447-1-gustavo.romero@linaro.org> References: <20240628050850.536447-1-gustavo.romero@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=2607:f8b0:4864:20::130; envelope-from=gustavo.romero@linaro.org; helo=mail-il1-x130.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: 1719552153422100001 If page in 'ptr_access' is inaccessible and probe is 'true' allocation_tag_mem_probe should not throw an exception, but currently it does, so fix it. Signed-off-by: Gustavo Romero Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- target/arm/tcg/mte_helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c index 037ac6dd60..a50d576294 100644 --- a/target/arm/tcg/mte_helper.c +++ b/target/arm/tcg/mte_helper.c @@ -96,6 +96,9 @@ static uint8_t *allocation_tag_mem_probe(CPUARMState *env= , int ptr_mmu_idx, assert(!(probe && ra)); =20 if (!(flags & (ptr_access =3D=3D MMU_DATA_STORE ? PAGE_WRITE_ORG : PAG= E_READ))) { + if (probe) { + return NULL; + } cpu_loop_exit_sigsegv(env_cpu(env), ptr, ptr_access, !(flags & PAGE_VALID), ra); } --=20 2.34.1 From nobody Sun Nov 24 22:48:38 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=1719552136; cv=none; d=zohomail.com; s=zohoarc; b=NwFWbDnpnyP3k9kfNvX+bbuQ0AdHXsnN6veSempySFT3YMC+tiB8GnKt7D3V+ZCkz+u2CqST4xikRe1zgk6VYRdk6fhc71hnY2SoH8O3W9/IcP0Oy95VMFdy7zv3xW7pBMf6JjXFQjf3RoXO/Esoc6DQUlshwi7RLyFNovIQ/Qc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719552136; 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=iNGHLZ6SUmkXQCpzg0N2HSo1zlyebo9gy5r+WIIkQrU=; b=dIxjDQMtTUl+VM1ZfAR7yk9v3r5rQEkAu1IqSWm1w+Zoc/kWTOi7qIcOj4AXyt4KlL/IK5PRNNVdUrF7cbmMN5CTcVB0Yc0/lGKoBQs0cSnqmriPqU+8tSDoWzHd3tY3y3/sLB1MQDNkqHf5qVQAcYlWa3ibbGNSnpRDFwPBe/E= 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 1719552136859503.6605001751012; Thu, 27 Jun 2024 22:22:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN42s-0003Hl-H5; Fri, 28 Jun 2024 01:21:14 -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 1sN42q-0003HB-Td for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:12 -0400 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN42o-0008DW-Tf for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:12 -0400 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-701f9fb9483so140353a34.1 for ; Thu, 27 Jun 2024 22:21:10 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:391e:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6b2a16cdsm423932a12.46.2024.06.27.22.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 22:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719552069; x=1720156869; 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=iNGHLZ6SUmkXQCpzg0N2HSo1zlyebo9gy5r+WIIkQrU=; b=WLqVvAUD6sBfoVE7YMegGq8BsoFUW11o0aW9w1WdPXnrrj1QHfHE9Lea8gfnxiosKu AYB98uy3GUV/KyUDQRlmgumSePeh78NAByGQYIkh5H9Ddb9bgqQR6cqacFiu0hOf3s9I RzwtLh5WbT7eVIQewTbCBS5L1vhQ02BvNEfCkICVhEpczc4gM/oykQ1kHb5xbbhfFZES ubdRB01/taIgpdU6+yGXkVP+gYQJCNAI5lEnWLlaHhh+dNimaIvbjuX4qk64oYpo7NI/ 99oI5MYnjzLxj4Di5b9HsuaQdVXlNCc7ZieU5bRLqHgYnvBKNdTQGZAELMnwu3Ot7Vit +uuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719552069; x=1720156869; 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=iNGHLZ6SUmkXQCpzg0N2HSo1zlyebo9gy5r+WIIkQrU=; b=UbrOZ9pf2GEfOzvRpzkLE521p7eBUUwGlwC4fdpnr+GSdSXH0qUF2EVcbJwmFZnr2d mMeG28UF5aultIbr5j9AhsMBfwAQQ70yf25gFK5NhCrJAbkoHA0dyK5vvaK/JgX6VCd5 pMh5xKuzCpPtnuzHJ4RrIS62OHRo1Sx9of6EidIAYUkwobSuxCUGYI/Lp45prJq8lPbv WQA7Ky5x9YHAaeIlsXlwXof96XDCfr6Yk3vnk0QMZPyJBJiO/2TdZFFPDwomox57dOhP 3pU3/FR5idhkxubEE0t7HZ/iPU6d0iCBLPeE4b4gd3gO3AM/ZEgZCEPoHwgk9LiQ3PkJ Jr+g== X-Gm-Message-State: AOJu0YwIXuvTuRH9nKF6Ur6lTVJCeS1bvjWKP1fqmqp0Pmq/Vn1s2KVQ xzvSAOV5+BJjOYjq0mKdtBnfgTOXfYUokTIIXZ+d6/vTziaEfOoyEiUd0GiT1snvscQ97IjA2hx 9 X-Google-Smtp-Source: AGHT+IGl7B2C5M3TIVp6fCWHXjk6PMBdWhepYrHRI2A8nCAsrhhToN6T3mBhUlhkvtboWDhvhZQEjQ== X-Received: by 2002:a05:6870:c1d2:b0:254:a8ec:306f with SMTP id 586e51a60fabf-25d0191bef2mr15450620fac.43.1719552068490; Thu, 27 Jun 2024 22:21:08 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v6 05/11] target/arm: Make some MTE helpers widely available Date: Fri, 28 Jun 2024 05:08:44 +0000 Message-Id: <20240628050850.536447-6-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628050850.536447-1-gustavo.romero@linaro.org> References: <20240628050850.536447-1-gustavo.romero@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=2607:f8b0:4864:20::330; envelope-from=gustavo.romero@linaro.org; helo=mail-ot1-x330.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: 1719552137627100005 Make the MTE helpers allocation_tag_mem_probe, load_tag1, and store_tag1 available to other subsystems. Signed-off-by: Gustavo Romero Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- target/arm/tcg/mte_helper.c | 45 ++++--------------------- target/arm/tcg/mte_helper.h | 66 +++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 38 deletions(-) create mode 100644 target/arm/tcg/mte_helper.h diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c index a50d576294..9d2ba287ee 100644 --- a/target/arm/tcg/mte_helper.c +++ b/target/arm/tcg/mte_helper.c @@ -29,6 +29,7 @@ #include "hw/core/tcg-cpu-ops.h" #include "qapi/error.h" #include "qemu/guest-random.h" +#include "mte_helper.h" =20 =20 static int choose_nonexcluded_tag(int tag, int offset, uint16_t exclude) @@ -50,42 +51,10 @@ static int choose_nonexcluded_tag(int tag, int offset, = uint16_t exclude) return tag; } =20 -/** - * allocation_tag_mem_probe: - * @env: the cpu environment - * @ptr_mmu_idx: the addressing regime to use for the virtual address - * @ptr: the virtual address for which to look up tag memory - * @ptr_access: the access to use for the virtual address - * @ptr_size: the number of bytes in the normal memory access - * @tag_access: the access to use for the tag memory - * @probe: true to merely probe, never taking an exception - * @ra: the return address for exception handling - * - * Our tag memory is formatted as a sequence of little-endian nibbles. - * That is, the byte at (addr >> (LOG2_TAG_GRANULE + 1)) contains two - * tags, with the tag at [3:0] for the lower addr and the tag at [7:4] - * for the higher addr. - * - * Here, resolve the physical address from the virtual address, and return - * a pointer to the corresponding tag byte. - * - * If there is no tag storage corresponding to @ptr, return NULL. - * - * If the page is inaccessible for @ptr_access, or has a watchpoint, there= are - * three options: - * (1) probe =3D true, ra =3D 0 : pure probe -- we return NULL if the page= is not - * accessible, and do not take watchpoint traps. The calling code must - * handle those cases in the right priority compared to MTE traps. - * (2) probe =3D false, ra =3D 0 : probe, no fault expected -- the caller = guarantees - * that the page is going to be accessible. We will take watchpoint tr= aps. - * (3) probe =3D false, ra !=3D 0 : non-probe -- we will take both memory = access - * traps and watchpoint traps. - * (probe =3D true, ra !=3D 0 is invalid and will assert.) - */ -static uint8_t *allocation_tag_mem_probe(CPUARMState *env, int ptr_mmu_idx, - uint64_t ptr, MMUAccessType ptr_a= ccess, - int ptr_size, MMUAccessType tag_a= ccess, - bool probe, uintptr_t ra) +uint8_t *allocation_tag_mem_probe(CPUARMState *env, int ptr_mmu_idx, + uint64_t ptr, MMUAccessType ptr_access, + int ptr_size, MMUAccessType tag_access, + bool probe, uintptr_t ra) { #ifdef CONFIG_USER_ONLY uint64_t clean_ptr =3D useronly_clean_ptr(ptr); @@ -287,7 +256,7 @@ uint64_t HELPER(addsubg)(CPUARMState *env, uint64_t ptr, return address_with_allocation_tag(ptr + offset, rtag); } =20 -static int load_tag1(uint64_t ptr, uint8_t *mem) +int load_tag1(uint64_t ptr, uint8_t *mem) { int ofs =3D extract32(ptr, LOG2_TAG_GRANULE, 1) * 4; return extract32(*mem, ofs, 4); @@ -321,7 +290,7 @@ static void check_tag_aligned(CPUARMState *env, uint64_= t ptr, uintptr_t ra) } =20 /* For use in a non-parallel context, store to the given nibble. */ -static void store_tag1(uint64_t ptr, uint8_t *mem, int tag) +void store_tag1(uint64_t ptr, uint8_t *mem, int tag) { int ofs =3D extract32(ptr, LOG2_TAG_GRANULE, 1) * 4; *mem =3D deposit32(*mem, ofs, 4, tag); diff --git a/target/arm/tcg/mte_helper.h b/target/arm/tcg/mte_helper.h new file mode 100644 index 0000000000..1f471fb69b --- /dev/null +++ b/target/arm/tcg/mte_helper.h @@ -0,0 +1,66 @@ +/* + * ARM MemTag operation helpers. + * + * This code is licensed under the GNU GPL v2 or later. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#ifndef TARGET_ARM_MTE_H +#define TARGET_ARM_MTE_H + +#include "exec/mmu-access-type.h" + +/** + * allocation_tag_mem_probe: + * @env: the cpu environment + * @ptr_mmu_idx: the addressing regime to use for the virtual address + * @ptr: the virtual address for which to look up tag memory + * @ptr_access: the access to use for the virtual address + * @ptr_size: the number of bytes in the normal memory access + * @tag_access: the access to use for the tag memory + * @probe: true to merely probe, never taking an exception + * @ra: the return address for exception handling + * + * Our tag memory is formatted as a sequence of little-endian nibbles. + * That is, the byte at (addr >> (LOG2_TAG_GRANULE + 1)) contains two + * tags, with the tag at [3:0] for the lower addr and the tag at [7:4] + * for the higher addr. + * + * Here, resolve the physical address from the virtual address, and return + * a pointer to the corresponding tag byte. + * + * If there is no tag storage corresponding to @ptr, return NULL. + * + * If the page is inaccessible for @ptr_access, or has a watchpoint, there= are + * three options: + * (1) probe =3D true, ra =3D 0 : pure probe -- we return NULL if the page= is not + * accessible, and do not take watchpoint traps. The calling code must + * handle those cases in the right priority compared to MTE traps. + * (2) probe =3D false, ra =3D 0 : probe, no fault expected -- the caller = guarantees + * that the page is going to be accessible. We will take watchpoint tr= aps. + * (3) probe =3D false, ra !=3D 0 : non-probe -- we will take both memory = access + * traps and watchpoint traps. + * (probe =3D true, ra !=3D 0 is invalid and will assert.) + */ +uint8_t *allocation_tag_mem_probe(CPUARMState *env, int ptr_mmu_idx, + uint64_t ptr, MMUAccessType ptr_access, + int ptr_size, MMUAccessType tag_access, + bool probe, uintptr_t ra); + +/** + * load_tag1 - Load 1 tag (nibble) from byte + * @ptr: The tagged address + * @mem: The tag address (packed, 2 tags in byte) + */ +int load_tag1(uint64_t ptr, uint8_t *mem); + +/** + * store_tag1 - Store 1 tag (nibble) into byte + * @ptr: The tagged address + * @mem: The tag address (packed, 2 tags in byte) + * @tag: The tag to be stored in the nibble + */ +void store_tag1(uint64_t ptr, uint8_t *mem, int tag); + +#endif /* TARGET_ARM_MTE_H */ --=20 2.34.1 From nobody Sun Nov 24 22:48:38 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=1719552103; cv=none; d=zohomail.com; s=zohoarc; b=U2JM1KBKosTrZjMAVFVtXcu8CLxir/LQ54mHkl/VgOgsJ8UQ4C8r0WfC0ADyz+IdzNtXUUQW7D8k5w4W26Yuu+gQp/GvOOFnz3WNiit5uNG/Hb9XiAOrnK44MSJlp827FDALfq1mnmZCFVOTcs98d5WjYexMEgZlTi8CMCaqB90= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719552103; h=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=yzx9s/7tqo4YbR/masBSAAi0+ITK6Y2yWNbJ1lluZfs=; b=WN+2d3zut7ePPsS3l5lcQINwaiZ5tvs+AbNcjOiUHmePTXao+L+1syZTYgBQSeIEECEDxUyShaHfn03KlEDSG6Penuc8QsCq3EN1093NAQB7Mvrclsxn3LVgl3UDVsrxKsE7nMCjwY4QS0JRHklJc2kT7ODxUZi2n+nbO/IJOPE= 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 17195521037471013.413615564882; Thu, 27 Jun 2024 22:21:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN42u-0003IA-4T; Fri, 28 Jun 2024 01:21:16 -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 1sN42t-0003Ho-4M for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:15 -0400 Received: from mail-il1-x135.google.com ([2607:f8b0:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN42r-0008EH-85 for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:14 -0400 Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-376069031c7so1010535ab.0 for ; Thu, 27 Jun 2024 22:21:12 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:391e:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6b2a16cdsm423932a12.46.2024.06.27.22.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 22:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719552071; x=1720156871; 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=yzx9s/7tqo4YbR/masBSAAi0+ITK6Y2yWNbJ1lluZfs=; b=UixxqV6CXuedhc/nA47FrFX7TBR7AikBuPxRT6OTneXpM0HenYwM0EFFPUZ7IK0nON iu65h2mOSs4nRgtQ8+Ejz5C0bDhrhDWw1H7g9aG0vPcTm8ofIqi8ue+soj27X+Z3eL3r xtslxYh8Y9YkRQhAo9IoD4j7FQ5p8VGXPdPSuNl6PWhhgTSoYlkN5e/Z5/u7LlCugjjE B18czyX8a/HVl/z2EF+IYTyE5+X3C1GhCu0PyzgizdlFC/cIN9ftfNRBl6KMxMlIjKDN scXVvXHcLJ2FFHnktez+v74BFnMTmyv2x8jm6XcqWZn8RHqJYedYinlzYT3meCBCoPH0 aMkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719552071; x=1720156871; 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=yzx9s/7tqo4YbR/masBSAAi0+ITK6Y2yWNbJ1lluZfs=; b=hHQR+klX8oYnH7pNvGCYoC1natcAe7hN6ZZ1+onDtJMDSkWSJHNyPFg/B8SyN7ttQE 9jnGIgIHKVmtRv/L16Y4kNq1jGNonwaWvJtlMv1zrSEDuUrZYqU7Ww8tlgq5t9qGGbto 27MbFPrdhZIOrFKkA45RxXvO0Nx1wMNpp25TdJI0Wu03ZTrsdY+rbG/j5yETGraYDvfj Y0d1b5LGVK9cOekuOo0i5RGSA//vLMa4I4m9n1YZ1EgQp5dFS71AemSoeqUSU7BL2S0J 3UuzDk3hM+BH1VoJ6Yh8BoVpKE6C81BL9H9VGSPi45pSsCoaZBYzrrbTn1LmHPo9CSa7 8Paw== X-Gm-Message-State: AOJu0YxnIdyvRXCtYYmgVXyZOuY5jhMjMfCcmywEjr+VX9Yx3dOrRhYV tn2jLkTq6WsPxQDj58LeKozJxBoqIT5mITLZh3r4AWIcsLrb8dbKxqlji4ZKqysqHSbqUh3Su/n A X-Google-Smtp-Source: AGHT+IGtNc4lmd3qRbsGnwqqKYVf7z+F/y+KbJNlqwnGVkQS0HR70scpB6GH9YRDYCmlpajV99Z/XA== X-Received: by 2002:a05:6e02:1c8c:b0:376:2934:f570 with SMTP id e9e14a558f8ab-3763df8d464mr207671565ab.9.1719552071437; Thu, 27 Jun 2024 22:21:11 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v6 06/11] target/arm: Factor out code for setting MTE TCF0 field Date: Fri, 28 Jun 2024 05:08:45 +0000 Message-Id: <20240628050850.536447-7-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628050850.536447-1-gustavo.romero@linaro.org> References: <20240628050850.536447-1-gustavo.romero@linaro.org> MIME-Version: 1.0 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=2607:f8b0:4864:20::135; envelope-from=gustavo.romero@linaro.org; helo=mail-il1-x135.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: 1719552105483100003 Content-Type: text/plain; charset="utf-8" Factor out the code used for setting the MTE TCF0 field from the prctl code into a convenient function. Other subsystems, like gdbstub, need to set this field as well, so keep it as a separate function to avoid duplication and ensure consistency in how this field is set across the board. Signed-off-by: Gustavo Romero Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- linux-user/aarch64/meson.build | 2 ++ linux-user/aarch64/mte_user_helper.c | 34 ++++++++++++++++++++++++++++ linux-user/aarch64/mte_user_helper.h | 25 ++++++++++++++++++++ linux-user/aarch64/target_prctl.h | 22 ++---------------- 4 files changed, 63 insertions(+), 20 deletions(-) create mode 100644 linux-user/aarch64/mte_user_helper.c create mode 100644 linux-user/aarch64/mte_user_helper.h diff --git a/linux-user/aarch64/meson.build b/linux-user/aarch64/meson.build index 248c578d15..f75bb3cd75 100644 --- a/linux-user/aarch64/meson.build +++ b/linux-user/aarch64/meson.build @@ -9,3 +9,5 @@ vdso_le_inc =3D gen_vdso.process('vdso-le.so', extra_args: ['-r', '__kernel_rt_sigreturn']) =20 linux_user_ss.add(when: 'TARGET_AARCH64', if_true: [vdso_be_inc, vdso_le_i= nc]) + +linux_user_ss.add(when: 'TARGET_AARCH64', if_true: [files('mte_user_helper= .c')]) diff --git a/linux-user/aarch64/mte_user_helper.c b/linux-user/aarch64/mte_= user_helper.c new file mode 100644 index 0000000000..8be6deaf03 --- /dev/null +++ b/linux-user/aarch64/mte_user_helper.c @@ -0,0 +1,34 @@ +/* + * ARM MemTag convenience functions. + * + * This code is licensed under the GNU GPL v2 or later. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include +#include "mte_user_helper.h" + +void arm_set_mte_tcf0(CPUArchState *env, abi_long value) +{ + /* + * Write PR_MTE_TCF to SCTLR_EL1[TCF0]. + * + * The kernel has a per-cpu configuration for the sysadmin, + * /sys/devices/system/cpu/cpu/mte_tcf_preferred, + * which qemu does not implement. + * + * Because there is no performance difference between the modes, and + * because SYNC is most useful for debugging MTE errors, choose SYNC + * as the preferred mode. With this preference, and the way the API + * uses only two bits, there is no way for the program to select + * ASYMM mode. + */ + unsigned tcf =3D 0; + if (value & PR_MTE_TCF_SYNC) { + tcf =3D 1; + } else if (value & PR_MTE_TCF_ASYNC) { + tcf =3D 2; + } + env->cp15.sctlr_el[1] =3D deposit64(env->cp15.sctlr_el[1], 38, 2, tcf); +} diff --git a/linux-user/aarch64/mte_user_helper.h b/linux-user/aarch64/mte_= user_helper.h new file mode 100644 index 0000000000..ee3f6b190a --- /dev/null +++ b/linux-user/aarch64/mte_user_helper.h @@ -0,0 +1,25 @@ +/* + * ARM MemTag convenience functions. + * + * This code is licensed under the GNU GPL v2 or later. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#ifndef AARCH64_MTE_USER_HELPER_H +#define AARCH64_MTE USER_HELPER_H + +#include "qemu/osdep.h" +#include "qemu.h" + +/** + * arm_set_mte_tcf0 - Set TCF0 field in SCTLR_EL1 register + * @env: The CPU environment + * @value: The value to be set for the Tag Check Fault in EL0 field. + * + * Only SYNC and ASYNC modes can be selected. If ASYMM mode is given, the = SYNC + * mode is selected instead. So, there is no way to set the ASYMM mode. + */ +void arm_set_mte_tcf0(CPUArchState *env, abi_long value); + +#endif /* AARCH64_MTE_USER_HELPER_H */ diff --git a/linux-user/aarch64/target_prctl.h b/linux-user/aarch64/target_= prctl.h index aa8e203c15..ed75b9e4b5 100644 --- a/linux-user/aarch64/target_prctl.h +++ b/linux-user/aarch64/target_prctl.h @@ -7,6 +7,7 @@ #define AARCH64_TARGET_PRCTL_H =20 #include "target/arm/cpu-features.h" +#include "mte_user_helper.h" =20 static abi_long do_prctl_sve_get_vl(CPUArchState *env) { @@ -173,26 +174,7 @@ static abi_long do_prctl_set_tagged_addr_ctrl(CPUArchS= tate *env, abi_long arg2) env->tagged_addr_enable =3D arg2 & PR_TAGGED_ADDR_ENABLE; =20 if (cpu_isar_feature(aa64_mte, cpu)) { - /* - * Write PR_MTE_TCF to SCTLR_EL1[TCF0]. - * - * The kernel has a per-cpu configuration for the sysadmin, - * /sys/devices/system/cpu/cpu/mte_tcf_preferred, - * which qemu does not implement. - * - * Because there is no performance difference between the modes, a= nd - * because SYNC is most useful for debugging MTE errors, choose SY= NC - * as the preferred mode. With this preference, and the way the A= PI - * uses only two bits, there is no way for the program to select - * ASYMM mode. - */ - unsigned tcf =3D 0; - if (arg2 & PR_MTE_TCF_SYNC) { - tcf =3D 1; - } else if (arg2 & PR_MTE_TCF_ASYNC) { - tcf =3D 2; - } - env->cp15.sctlr_el[1] =3D deposit64(env->cp15.sctlr_el[1], 38, 2, = tcf); + arm_set_mte_tcf0(env, arg2); =20 /* * Write PR_MTE_TAG to GCR_EL1[Exclude]. --=20 2.34.1 From nobody Sun Nov 24 22:48:38 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=1719552145; cv=none; d=zohomail.com; s=zohoarc; b=BwWeCrbjnWnSZ/DblrVqkYKE96S12FziYO5nL9oyuvUwW84K4jW4bs3k2SHHnkDbaS9TzkLTtiLjyd/GKPN4pHVw11AAPgwI4jMcvH3wS01KcUhzDp/DCbOzNQ/YKR1rCPg7Qov+/rUlg+lDB/UWIM0VFP0f8ySGGCALgbyWRTU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719552145; h=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=i7+5Sk6k3Qdhdd1bPl+/zET47DgJiYeK1rga8DTRerY=; b=BdhChxzmtUMJZyzEq2MRTaP7OGawryx9kct1Ou4ftm/VMLs8L7eGmKRsyj4Rj812K3IxLjzhgbOjRvHap70u0bAFAvwyqcETIvpt/guy6xzbAAZtMD2avOd3NbetsrPh5OhwnLYwAOf83gWbmFhDoHekukPcU6i4vo9vc9gKSWg= 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 1719552145056912.000103105651; Thu, 27 Jun 2024 22:22:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN42x-0003Ir-H1; Fri, 28 Jun 2024 01:21:19 -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 1sN42v-0003IX-Pj for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:17 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN42u-0008En-7b for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:17 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-706b53ee183so985082b3a.1 for ; Thu, 27 Jun 2024 22:21:15 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:391e:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6b2a16cdsm423932a12.46.2024.06.27.22.21.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 22:21:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719552074; x=1720156874; 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=i7+5Sk6k3Qdhdd1bPl+/zET47DgJiYeK1rga8DTRerY=; b=YNDYs3y8fjqsDlhEnDOdiPGD2r9jC4MZ1fFsDmri/kR0Rr3pPww+jIhS0IXT2zSB7h yIhaCvaaGr47YZZjkeZstnAfOfcqITw7ficzMW+mu89+D7XJob8Hm26Djml8VIn4SWXd xRdimOIvBNFZm2rynHVr5aXGjPt9gxf1TCvBeR1r0KcpnBOW2ukWiT/EHt4y1dufbwfi Uc8tZK9UCUTTOg0WsAeAkOH+9fG4mczaBdlyxIHWfqWA7J9/ezFuMCcmPXfdl0OCxorJ CSbEpg8zq8L5M4pZgKChQbO4T9MJkAc40sLHdAsnPWut6eg2kfMEPa8XKZqlxZFi4EP+ rEJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719552074; x=1720156874; 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=i7+5Sk6k3Qdhdd1bPl+/zET47DgJiYeK1rga8DTRerY=; b=fG6S4IAZKqS3zB83XG13Z9/+UlGZuFQgXhaPdqFWCUILofaST9cc2PoGz8L2TItNcu t3DokVdooBrO1PRCdqkzt4cGE79uXKHTA9JbBm2XzjJf1Rmwtm6nylgUiQtu/uSe9eR7 Gc/KgYIrrrpAshRJX8gDwow5qyeJjELgSBoTTOBw9mSOV0Jl1VmcH7bEzlac0fuuTp/u TSeFahEGWt/aWCuLhFZvV9jJpy4sKEX1/VGHcGQ2uTv0cbSE/8oT3W3L+m0vOYQYh51X JMOj2diblfi69hUsdxUDEOGwFBn9F1hY4Lpjase5r3WKhIBob3sCTs9otxcB8KoHYWxQ IpsQ== X-Gm-Message-State: AOJu0YzHV7+U0/cLUL9QBrg229b18pL3Ulh9b0jbRaeaUCWrVGG2LSr4 F+iPkaYr5WY77zgYZppvp5Mz4pxwv0bBNE69XbdSqoluLg9diN8piLP1UTK4RPS1+YBYnXTdbyt + X-Google-Smtp-Source: AGHT+IHEjHD/Ea2vSOOYlS/c5GY8gJci2bY8gPJcHu8Fs83LIx0vC/o2icRWynl9XXYzUlUA2fNuIQ== X-Received: by 2002:a05:6a20:a10f:b0:1bc:bd60:e7fa with SMTP id adf61e73a8af0-1bee48ff465mr1158861637.2.1719552074375; Thu, 27 Jun 2024 22:21:14 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v6 07/11] gdbstub: Make hex conversion function non-internal Date: Fri, 28 Jun 2024 05:08:46 +0000 Message-Id: <20240628050850.536447-8-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628050850.536447-1-gustavo.romero@linaro.org> References: <20240628050850.536447-1-gustavo.romero@linaro.org> MIME-Version: 1.0 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=2607:f8b0:4864:20::429; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x429.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: 1719552145394100001 Content-Type: text/plain; charset="utf-8" Make gdb_hextomem non-internal so it's not confined to use only in gdbstub.c. Signed-off-by: Gustavo Romero Reviewed-by: Richard Henderson --- gdbstub/internals.h | 1 - include/gdbstub/commands.h | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/gdbstub/internals.h b/gdbstub/internals.h index 34121dc61a..bf5a5c6302 100644 --- a/gdbstub/internals.h +++ b/gdbstub/internals.h @@ -107,7 +107,6 @@ static inline int tohex(int v) =20 void gdb_put_strbuf(void); int gdb_put_packet_binary(const char *buf, int len, bool dump); -void gdb_hextomem(GByteArray *mem, const char *buf, int len); void gdb_memtohex(GString *buf, const uint8_t *mem, int len); void gdb_memtox(GString *buf, const char *mem, int len); void gdb_read_byte(uint8_t ch); diff --git a/include/gdbstub/commands.h b/include/gdbstub/commands.h index 306dfdef97..e51f276b40 100644 --- a/include/gdbstub/commands.h +++ b/include/gdbstub/commands.h @@ -91,4 +91,10 @@ void gdb_extend_set_table(GdbCmdParseEntry *table, int s= ize); */ void gdb_extend_qsupported_features(char *qsupported_features); =20 +/** + * Convert a hex string to bytes. Conversion is done per byte, so 2 hex di= gits + * are converted to 1 byte. Invalid hex digits are treated as 0 digits. + */ +void gdb_hextomem(GByteArray *mem, const char *buf, int len); + #endif /* GDBSTUB_COMMANDS_H */ --=20 2.34.1 From nobody Sun Nov 24 22:48:38 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=1719552159; cv=none; d=zohomail.com; s=zohoarc; b=J2VRFOhTUNY7k/IlkwhH+x+b8uF6PPF/8wpCCxgCZE/LmE0PraPMUNBRPWjFObURpAuB0dZapGr4MU6gkaFH6p3Pq/RRtBVxC9dsSqT4cD/6pwHekqypGzB7F0oUp1+kswE5JUJTnzR9gB4JJaAmG8Z4qXbjU6uqwjJpzB3QESM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719552159; 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=XGUVEgkOZ1Z9CgRBWiCr397XSqS24XQydg1qjtX54Dk=; b=iTaN3d389prveYMHkOqJ5lcKT1rC0b5Mjcg897bNrH9TCNrXdZ/Obdp22/tgNISqdJOtT55dPDeSR+cHeQOc59znLIid+sWGWE3ZWAqTz1f6uEG8iO8sewDqjFG8vKg9yjbejtTVobTpG95OJB8j+nEA3CMJB6E6P9PfdRvkf2E= 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 1719552159409833.9011019540125; Thu, 27 Jun 2024 22:22:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN430-0003JR-70; Fri, 28 Jun 2024 01:21: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 1sN42z-0003J9-4g for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:21 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN42x-0008F3-CZ for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:20 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-706b539fcaeso962959b3a.0 for ; Thu, 27 Jun 2024 22:21:18 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:391e:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6b2a16cdsm423932a12.46.2024.06.27.22.21.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 22:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719552077; x=1720156877; 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=XGUVEgkOZ1Z9CgRBWiCr397XSqS24XQydg1qjtX54Dk=; b=XojL8uT9AorwwpFZt46x1rmnnQFHbdKTwt91GJnfO0SGAbpDzRbvrdESZzVjgVM5XH hMZ8MzdK26LRBDNfZgnKkHQ3rWFxAx5XvtAogqRai5DwVnDQJQf5aOUtarH+QxsApM6d CyDq4UQse9VUgodORjdX1cDAVH4BvVQYAgtr5yoLgjTRzSxvWt9dBX0fdzbUSkCvKcww ozjNlGx+ngkHsp/Lr49KfsfhrCkBWSsbFKj73LH+ItZQC+VIg0yWH5qH8GChgGKyEpwW pv+lWi7LlBBbKaiz9Xb4mXcbkrWIBJocKS9mN1aW3+0lH95xirq1Xnqj59UwRXlLGoxh TEiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719552077; x=1720156877; 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=XGUVEgkOZ1Z9CgRBWiCr397XSqS24XQydg1qjtX54Dk=; b=wWFlH5+KfDSmxpmoavNk2oVsBeaIUlNVTpVcRzpvceppjLnrFG2SkSOp/QfDiD9V72 iQH999MiJXMMRcTZjHPum75wDodmRnWFJrEBWA37ZUnNSU2saOQdBllvdqehj84CvFli icqtnRWbOw/8TEaeLjSKuBD+TlsCVlxeXYj3LXT6k8qlTJN7OSIqKLnPl1HWBgqO3NeZ zDjyZe3wi282kG6vE3IkaszfKFiKf6XMFeNcsQY/3h4SSYnaFgAGxAs8jUwBXquLXiAa Et7fSAwg4wiQubBPCQv8rOGg7HVdHr5bakV11URj7jV1yrNQyLf6JmqyPqnuUU8rA36a mTmQ== X-Gm-Message-State: AOJu0Yxy+m6vvrELqF6IRQCIUXFGSUOyFHQJC4/70hjGT6sjanwUMfD7 cLxeVD0CIg+BGH5MxQlgi7QFicO2Ep1Jk6KnRsGKAnnq9rBXQzBniSt8dIKzAgWQNbvWkwriAAR d X-Google-Smtp-Source: AGHT+IFZULnETnfSGnOWwoTK+dDuN0O484NOA+L2o9juqbeAB07d9F52kVpPr7R5az1JXc3+tfgAtg== X-Received: by 2002:a05:6a20:3d89:b0:1bd:2aaf:4764 with SMTP id adf61e73a8af0-1bee47d4c9fmr1396826637.0.1719552077307; Thu, 27 Jun 2024 22:21:17 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v6 08/11] gdbstub: Pass CPU context to command handler Date: Fri, 28 Jun 2024 05:08:47 +0000 Message-Id: <20240628050850.536447-9-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628050850.536447-1-gustavo.romero@linaro.org> References: <20240628050850.536447-1-gustavo.romero@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=2607:f8b0:4864:20::435; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x435.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: 1719552161459100003 Allow passing the current CPU context to command handlers via user_ctx when the handler requires it. Signed-off-by: Alex Benn=C3=A9e Signed-off-by: Gustavo Romero --- gdbstub/gdbstub.c | 7 ++++++- include/gdbstub/commands.h | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index b1ca253f97..5c1612ed2a 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -938,6 +938,7 @@ static bool process_string_cmd(const char *data, =20 for (i =3D 0; i < num_cmds; i++) { const GdbCmdParseEntry *cmd =3D &cmds[i]; + void *user_ctx =3D NULL; g_assert(cmd->handler && cmd->cmd); =20 if ((cmd->cmd_startswith && !startswith(data, cmd->cmd)) || @@ -952,8 +953,12 @@ static bool process_string_cmd(const char *data, } } =20 + if (cmd->need_cpu_context) { + user_ctx =3D (void *)gdbserver_state.g_cpu; + } + gdbserver_state.allow_stop_reply =3D cmd->allow_stop_reply; - cmd->handler(params, NULL); + cmd->handler(params, user_ctx); return true; } =20 diff --git a/include/gdbstub/commands.h b/include/gdbstub/commands.h index e51f276b40..f3058f9dda 100644 --- a/include/gdbstub/commands.h +++ b/include/gdbstub/commands.h @@ -54,6 +54,8 @@ typedef union GdbCmdVariant { * "stop reply" packet. The list of commands that accept such response is * defined at the GDB Remote Serial Protocol documentation. See: * https://sourceware.org/gdb/onlinedocs/gdb/Stop-Reply-Packets.html#Stop-= Reply-Packets. + * + * @need_cpu_context: Pass current CPU context to command handler via user= _ctx. */ typedef struct GdbCmdParseEntry { GdbCmdHandler handler; @@ -61,6 +63,7 @@ typedef struct GdbCmdParseEntry { bool cmd_startswith; const char *schema; bool allow_stop_reply; + bool need_cpu_context; } GdbCmdParseEntry; =20 /** --=20 2.34.1 From nobody Sun Nov 24 22:48:38 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=1719552135; cv=none; d=zohomail.com; s=zohoarc; b=VoZPdW7rpT3c7w3bpfHT8wOnBjsTtk8tmJPe20UQqbwzwRiD9yd9x2M+6wEImcJq0aWif8cJvBj7l95bj0T2QXmGOWBkUFd4u9p64Mi1wwkTn56XYtFBlbyapUsEeArhcP0hoEoESDQFecekEl6j3CwV9HeoK5qFOVi/nA8D1cM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719552135; h=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=o3gvu6OQ0lTozaroxzspcc5vQ9JngNtD70BqjIlE6nA=; b=f2Kxxc6u7K4ESHnFM2KpRvxx2VqFyhjCWF3YW6drEwhSZEcnSrEnICWe5pfhuxPWzlWO5yFActGafFO+XnEgojNpsqHZmksrj7PVZuvYwl9lJlVgfFLT/AsvEQCVQc3naV3reGtyPU/TAk6bOYYh8ZemV2jgugl2NPkGzY+owrg= 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 1719552135354607.8294471276289; Thu, 27 Jun 2024 22:22:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN433-0003K4-AN; Fri, 28 Jun 2024 01:21:25 -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 1sN431-0003Jl-UW for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:23 -0400 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN42z-0008FD-Ue for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:23 -0400 Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-6f8d0a1e500so180432a34.3 for ; Thu, 27 Jun 2024 22:21:21 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:391e:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6b2a16cdsm423932a12.46.2024.06.27.22.21.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 22:21:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719552080; x=1720156880; 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=o3gvu6OQ0lTozaroxzspcc5vQ9JngNtD70BqjIlE6nA=; b=Ehwp394Ik4S43iFkkFMBP5vSTf8JYBn4a1F4Xtj9XvJisqhy25wII/hkr2a772SnL9 0JckTtLGW+sfHYprkbgvqFWaHL6hmadN6PG8XJLVBYUvHBGh1ug43wgAawYlpOx0DMtr q0fbvuqvTedRrF1rPfUHayiM8EbvpfD5OU5Efx2ny5QryAPUEFCDbK/fdC1Hz8U8MGtp bEEEUeF0CtpPtrmCx77/eVGneA0ZdMb56H3m3euZtW6XEddbck7AsTx+OI9UudEpjCU/ 91ub0FagcSPrZMpbSkIX+rPeFi8SOcQ1K9cwPqOnitw9qar6dFmjK0w3PVWv8pMX9qpK aVaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719552080; x=1720156880; 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=o3gvu6OQ0lTozaroxzspcc5vQ9JngNtD70BqjIlE6nA=; b=NUF8cOmtl6GBl3kGMUenUaW+pUuW4nJW+7Her2ALIo+DbyCP4ReHH0uiZUKVP7RgTn Qb1UCYLvjHkJYDxY9A9NmvEgntUxchNouzBhdcRoCX5rYETAY5ZZDnuyXgR0KskuMTDD gBSCZRBQBgclMhuQ4QLI8rR6J7MoNzkUFo56I8BPWumMmJyqo4wL/IekWj1HGuDqmIO3 ezBhscsZO9MKmWTUeCkpMuEnIBUKp+piF09A1ZQeP7gsr5nF+f4IuaRlPv9d6tKM5GcN tOqIOrlq+1WdHf3ZPDzoc+Lz1sB0wsmSL1Qfvy/ZTbom9JnyybCo7Dc5xJ2+U8fj08tk DLvw== X-Gm-Message-State: AOJu0YzXKlGgl9qdJfCu4D3ytI8fl5q1X74y3kbvgpUHMzcIDC3qJoNi /z36mHfcDDMxOw3/xpF1ChTDPh+QMTVF1ocgjP6XaS0VN+wP/gTanC30Q74sbajJe1+v16vP8hz n X-Google-Smtp-Source: AGHT+IGUhPIlPwIb1cuSRswv7LZCDqa2Jv05k5I9jPRJZjM12wqNeOmKGAlCW8jdapXczJec6OFYjA== X-Received: by 2002:a05:6830:168c:b0:6f9:8c58:712a with SMTP id 46e09a7af769-700b11f55cemr15872617a34.15.1719552080287; Thu, 27 Jun 2024 22:21:20 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v6 09/11] gdbstub: Use true to set cmd_startswith Date: Fri, 28 Jun 2024 05:08:48 +0000 Message-Id: <20240628050850.536447-10-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628050850.536447-1-gustavo.romero@linaro.org> References: <20240628050850.536447-1-gustavo.romero@linaro.org> MIME-Version: 1.0 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=2607:f8b0:4864:20::336; envelope-from=gustavo.romero@linaro.org; helo=mail-ot1-x336.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: 1719552137669100006 Content-Type: text/plain; charset="utf-8" cmd_startswith is a boolean so use 'true' to set it instead of 1. Signed-off-by: Gustavo Romero --- gdbstub/gdbstub.c | 80 +++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 5c1612ed2a..b9ad0a063e 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -1433,26 +1433,26 @@ static const GdbCmdParseEntry gdb_v_commands_table[= ] =3D { { .handler =3D handle_v_cont_query, .cmd =3D "Cont?", - .cmd_startswith =3D 1 + .cmd_startswith =3D true }, { .handler =3D handle_v_cont, .cmd =3D "Cont", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .allow_stop_reply =3D true, .schema =3D "s0" }, { .handler =3D handle_v_attach, .cmd =3D "Attach;", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .allow_stop_reply =3D true, .schema =3D "l0" }, { .handler =3D handle_v_kill, .cmd =3D "Kill;", - .cmd_startswith =3D 1 + .cmd_startswith =3D true }, #ifdef CONFIG_USER_ONLY /* @@ -1462,25 +1462,25 @@ static const GdbCmdParseEntry gdb_v_commands_table[= ] =3D { { .handler =3D gdb_handle_v_file_open, .cmd =3D "File:open:", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "s,L,L0" }, { .handler =3D gdb_handle_v_file_close, .cmd =3D "File:close:", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "l0" }, { .handler =3D gdb_handle_v_file_pread, .cmd =3D "File:pread:", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "l,L,L0" }, { .handler =3D gdb_handle_v_file_readlink, .cmd =3D "File:readlink:", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "s0" }, #endif @@ -1748,7 +1748,7 @@ static const GdbCmdParseEntry gdb_gen_query_set_commo= n_table[] =3D { { .handler =3D handle_set_qemu_sstep, .cmd =3D "qemu.sstep=3D", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "l0" }, }; @@ -1804,7 +1804,7 @@ static const GdbCmdParseEntry gdb_gen_query_table[] = =3D { { .handler =3D handle_query_thread_extra, .cmd =3D "ThreadExtraInfo,", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "t0" }, #ifdef CONFIG_USER_ONLY @@ -1816,14 +1816,14 @@ static const GdbCmdParseEntry gdb_gen_query_table[]= =3D { { .handler =3D gdb_handle_query_rcmd, .cmd =3D "Rcmd,", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "s0" }, #endif { .handler =3D handle_query_supported, .cmd =3D "Supported:", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "s0" }, { @@ -1834,7 +1834,7 @@ static const GdbCmdParseEntry gdb_gen_query_table[] = =3D { { .handler =3D handle_query_xfer_features, .cmd =3D "Xfer:features:read:", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "s:l,l0" }, #if defined(CONFIG_USER_ONLY) @@ -1842,27 +1842,27 @@ static const GdbCmdParseEntry gdb_gen_query_table[]= =3D { { .handler =3D gdb_handle_query_xfer_auxv, .cmd =3D "Xfer:auxv:read::", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "l,l0" }, { .handler =3D gdb_handle_query_xfer_siginfo, .cmd =3D "Xfer:siginfo:read::", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "l,l0" }, #endif { .handler =3D gdb_handle_query_xfer_exec_file, .cmd =3D "Xfer:exec-file:read:", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "l:l,l0" }, #endif { .handler =3D gdb_handle_query_attached, .cmd =3D "Attached:", - .cmd_startswith =3D 1 + .cmd_startswith =3D true }, { .handler =3D gdb_handle_query_attached, @@ -1901,14 +1901,14 @@ static const GdbCmdParseEntry gdb_gen_set_table[] = =3D { { .handler =3D handle_set_qemu_sstep, .cmd =3D "qemu.sstep:", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "l0" }, #ifndef CONFIG_USER_ONLY { .handler =3D gdb_handle_set_qemu_phy_mem_mode, .cmd =3D "qemu.PhyMemMode:", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "l0" }, #endif @@ -1916,7 +1916,7 @@ static const GdbCmdParseEntry gdb_gen_set_table[] =3D= { { .handler =3D gdb_handle_set_catch_syscalls, .cmd =3D "CatchSyscalls:", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "s0", }, #endif @@ -2012,7 +2012,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry target_halted_cmd_desc =3D { .handler =3D handle_target_halt, .cmd =3D "?", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .allow_stop_reply =3D true, }; cmd_parser =3D &target_halted_cmd_desc; @@ -2023,7 +2023,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry continue_cmd_desc =3D { .handler =3D handle_continue, .cmd =3D "c", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .allow_stop_reply =3D true, .schema =3D "L0" }; @@ -2035,7 +2035,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry cont_with_sig_cmd_desc =3D { .handler =3D handle_cont_with_sig, .cmd =3D "C", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .allow_stop_reply =3D true, .schema =3D "l0" }; @@ -2047,7 +2047,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry v_cmd_desc =3D { .handler =3D handle_v_commands, .cmd =3D "v", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "s0" }; cmd_parser =3D &v_cmd_desc; @@ -2064,7 +2064,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry detach_cmd_desc =3D { .handler =3D handle_detach, .cmd =3D "D", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "?.l0" }; cmd_parser =3D &detach_cmd_desc; @@ -2075,7 +2075,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry step_cmd_desc =3D { .handler =3D handle_step, .cmd =3D "s", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .allow_stop_reply =3D true, .schema =3D "L0" }; @@ -2087,7 +2087,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry backward_cmd_desc =3D { .handler =3D handle_backward, .cmd =3D "b", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .allow_stop_reply =3D true, .schema =3D "o0" }; @@ -2099,7 +2099,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry file_io_cmd_desc =3D { .handler =3D gdb_handle_file_io, .cmd =3D "F", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "L,L,o0" }; cmd_parser =3D &file_io_cmd_desc; @@ -2110,7 +2110,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry read_all_regs_cmd_desc =3D { .handler =3D handle_read_all_regs, .cmd =3D "g", - .cmd_startswith =3D 1 + .cmd_startswith =3D true }; cmd_parser =3D &read_all_regs_cmd_desc; } @@ -2120,7 +2120,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry write_all_regs_cmd_desc =3D { .handler =3D handle_write_all_regs, .cmd =3D "G", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "s0" }; cmd_parser =3D &write_all_regs_cmd_desc; @@ -2131,7 +2131,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry read_mem_cmd_desc =3D { .handler =3D handle_read_mem, .cmd =3D "m", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "L,L0" }; cmd_parser =3D &read_mem_cmd_desc; @@ -2142,7 +2142,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry write_mem_cmd_desc =3D { .handler =3D handle_write_mem, .cmd =3D "M", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "L,L:s0" }; cmd_parser =3D &write_mem_cmd_desc; @@ -2153,7 +2153,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry get_reg_cmd_desc =3D { .handler =3D handle_get_reg, .cmd =3D "p", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "L0" }; cmd_parser =3D &get_reg_cmd_desc; @@ -2164,7 +2164,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry set_reg_cmd_desc =3D { .handler =3D handle_set_reg, .cmd =3D "P", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "L?s0" }; cmd_parser =3D &set_reg_cmd_desc; @@ -2175,7 +2175,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry insert_bp_cmd_desc =3D { .handler =3D handle_insert_bp, .cmd =3D "Z", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "l?L?L0" }; cmd_parser =3D &insert_bp_cmd_desc; @@ -2186,7 +2186,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry remove_bp_cmd_desc =3D { .handler =3D handle_remove_bp, .cmd =3D "z", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "l?L?L0" }; cmd_parser =3D &remove_bp_cmd_desc; @@ -2197,7 +2197,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry set_thread_cmd_desc =3D { .handler =3D handle_set_thread, .cmd =3D "H", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "o.t0" }; cmd_parser =3D &set_thread_cmd_desc; @@ -2208,7 +2208,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry thread_alive_cmd_desc =3D { .handler =3D handle_thread_alive, .cmd =3D "T", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "t0" }; cmd_parser =3D &thread_alive_cmd_desc; @@ -2219,7 +2219,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry gen_query_cmd_desc =3D { .handler =3D handle_gen_query, .cmd =3D "q", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "s0" }; cmd_parser =3D &gen_query_cmd_desc; @@ -2230,7 +2230,7 @@ static int gdb_handle_packet(const char *line_buf) static const GdbCmdParseEntry gen_set_cmd_desc =3D { .handler =3D handle_gen_set, .cmd =3D "Q", - .cmd_startswith =3D 1, + .cmd_startswith =3D true, .schema =3D "s0" }; cmd_parser =3D &gen_set_cmd_desc; --=20 2.34.1 From nobody Sun Nov 24 22:48:38 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=1719552161; cv=none; d=zohomail.com; s=zohoarc; b=k2CNpL+VYLQ1NRI3hlDN+bGC92tOeyIJ/j4h8015FfT+8rzuHJBgrUhPRsXoGer9OWrpbh1EfLb0zKqhXgMg0xdoF8+ighWo6RS7Gm2Ks+kjNI3X54o55IuNcFX1Xg41Su3d6aGPFvl3vbOq9mQ6c4yleoYP2IlH6/NW1mHXUco= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719552161; h=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=iZT6BjdHhM0XdF9YTqRtBuRMtjA3/M/ng5tTzxuf0g8=; b=j1iUnPtBiod1FdKpva8324bJaP01z0IxRV5xsQwBzV/MuDlctHUZL70mXs8iXx60FfNpqXxAMqV4UT+0aa0XMMrXTL1MUDY3YahZ+YV6i+Yad0LvzHmrHV6LzBDYbY1ErNHTveK3YcUPAnjaGjqxo42Mc7hkhli0S00ucFC9g7Q= 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 1719552161485296.77389834625967; Thu, 27 Jun 2024 22:22:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN43A-0003ZU-MN; Fri, 28 Jun 2024 01:21:33 -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 1sN435-0003Td-NW for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:27 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN433-0008FQ-Ao for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:27 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-706b14044cbso200238b3a.2 for ; Thu, 27 Jun 2024 22:21:24 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:391e:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6b2a16cdsm423932a12.46.2024.06.27.22.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 22:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719552083; x=1720156883; 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=iZT6BjdHhM0XdF9YTqRtBuRMtjA3/M/ng5tTzxuf0g8=; b=JkkqfMXWqzzGavQb5Tc3rDr/bMAXHRv+DTaojF+KHMqWc/OFHskZIbX2/UQooUlQLy ibxDm7OkFZwLnEXAFbhvLLrCb9Vq3Kp+Ii/gHvUnLlTd75kw8/nfcruwBpUaXGQpiqsv kO5Q4gbQMKwA+6yWY1Ee9PvDZIbM5gLvAC0hsINTjNmT/gpRgosFn9U1FruwiTb3M8iU VpsgA0kineFX4zqqqIQgBXOKjLWavU0a/VG+OYzpfLG17RBF9PfsAU1jJG03L+gwe5nm D5aN8lQUQvmd0L4It6BnxYkMxctdVHw4jDOub5Zn1aOPrK2ER76IT/oJ181JZhz4FVLf efJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719552083; x=1720156883; 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=iZT6BjdHhM0XdF9YTqRtBuRMtjA3/M/ng5tTzxuf0g8=; b=CspcJLjHgi3AJxBdQLWMjoadNbeHJlGTZiOxjJqahfPRsukPtRSLQKPv9DdASE1nXo 27SKSoBrdU7Am5tgYl6Rl1pCOwkbC/6XS0rnFXP69M9IiX0v3XvFELCfnwXUALirECYU Lpsjki1+ehT4uGnNh+1zpctQmoTi1JFB5JoxwDM+woVwzmdpRZQxYlEQW8bCjslO64QA 715QMSdQHEykfek0m6Bq0hzmeD+A8eET5iyzlP8nd6b1TZC+IT+8a5W12gVqELTAN+rn N2DWiQcW3v82a4UsksLxUvwoxmDYBkvNtP8mcOtAUhWKqBYloRf6xEnuRXR0BxgOvfar qIgA== X-Gm-Message-State: AOJu0YxsDNRY7d2Kthkp9KEzSwvGAHuvIMkMy5B801iOhxKLzNc13ew8 lAa8KA9Ci3O9neKD78J+sND43FBTBEp1i+G8c7RIQ7FvgedymWPpeevjQr/7PYkyx4+BJYRRafa / X-Google-Smtp-Source: AGHT+IHdmLlLaNJy9lkPLu27htjJ6Vx+W3pDSVIY3nUEC7+rdrGr9iF7wFuSWX2+DPaT5pXqxc9i+Q== X-Received: by 2002:a05:6a00:80d5:b0:706:3329:5533 with SMTP id d2e1a72fcca58-7067469450amr13823003b3a.24.1719552083070; Thu, 27 Jun 2024 22:21:23 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v6 10/11] gdbstub: Add support for MTE in user mode Date: Fri, 28 Jun 2024 05:08:49 +0000 Message-Id: <20240628050850.536447-11-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628050850.536447-1-gustavo.romero@linaro.org> References: <20240628050850.536447-1-gustavo.romero@linaro.org> MIME-Version: 1.0 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=2607:f8b0:4864:20::433; envelope-from=gustavo.romero@linaro.org; helo=mail-pf1-x433.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: 1719552163516100007 Content-Type: text/plain; charset="utf-8" This commit implements the stubs to handle the qIsAddressTagged, qMemTag, and QMemTag GDB packets, allowing all GDB 'memory-tag' subcommands to work with QEMU gdbstub on aarch64 user mode. It also implements the get/set functions for the special GDB MTE register 'tag_ctl', used to control the MTE fault type at runtime. Signed-off-by: Gustavo Romero --- configs/targets/aarch64-linux-user.mak | 2 +- gdb-xml/aarch64-mte.xml | 11 ++ target/arm/cpu.c | 1 + target/arm/gdbstub.c | 46 +++++ target/arm/gdbstub64.c | 223 +++++++++++++++++++++++++ target/arm/internals.h | 6 + 6 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 gdb-xml/aarch64-mte.xml diff --git a/configs/targets/aarch64-linux-user.mak b/configs/targets/aarch= 64-linux-user.mak index ba8bc5fe3f..8f0ed21d76 100644 --- a/configs/targets/aarch64-linux-user.mak +++ b/configs/targets/aarch64-linux-user.mak @@ -1,6 +1,6 @@ TARGET_ARCH=3Daarch64 TARGET_BASE_ARCH=3Darm -TARGET_XML_FILES=3D gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-x= ml/aarch64-pauth.xml +TARGET_XML_FILES=3D gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml gdb-x= ml/aarch64-pauth.xml gdb-xml/aarch64-mte.xml TARGET_HAS_BFLT=3Dy CONFIG_SEMIHOSTING=3Dy CONFIG_ARM_COMPATIBLE_SEMIHOSTING=3Dy diff --git a/gdb-xml/aarch64-mte.xml b/gdb-xml/aarch64-mte.xml new file mode 100644 index 0000000000..4b70b4f17a --- /dev/null +++ b/gdb-xml/aarch64-mte.xml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 35fa281f1b..14d4eca127 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -2518,6 +2518,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error= **errp) =20 register_cp_regs_for_features(cpu); arm_cpu_register_gdb_regs_for_features(cpu); + arm_cpu_register_gdb_commands(cpu); =20 init_cpreg_list(cpu); =20 diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c index a3bb73cfa7..c3a9b5eb1e 100644 --- a/target/arm/gdbstub.c +++ b/target/arm/gdbstub.c @@ -21,6 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" #include "gdbstub/helpers.h" +#include "gdbstub/commands.h" #include "sysemu/tcg.h" #include "internals.h" #include "cpu-features.h" @@ -474,6 +475,41 @@ static GDBFeature *arm_gen_dynamic_m_secextreg_feature= (CPUState *cs, #endif #endif /* CONFIG_TCG */ =20 +void arm_cpu_register_gdb_commands(ARMCPU *cpu) +{ + GArray *query_table =3D + g_array_new(FALSE, FALSE, sizeof(GdbCmdParseEntry)); + GArray *set_table =3D + g_array_new(FALSE, FALSE, sizeof(GdbCmdParseEntry)); + GString *qsupported_features =3D g_string_new(NULL); + + if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { + #ifdef TARGET_AARCH64 + aarch64_cpu_register_gdb_commands(cpu, qsupported_features, query_= table, + set_table); + #endif + } + + /* Set arch-specific handlers for 'q' commands. */ + if (query_table->len) { + gdb_extend_query_table(&g_array_index(query_table, + GdbCmdParseEntry, 0), + query_table->len); + } + + /* Set arch-specific handlers for 'Q' commands. */ + if (set_table->len) { + gdb_extend_set_table(&g_array_index(set_table, + GdbCmdParseEntry, 0), + set_table->len); + } + + /* Set arch-specific qSupported feature. */ + if (qsupported_features->len) { + gdb_extend_qsupported_features(qsupported_features->str); + } +} + void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) { CPUState *cs =3D CPU(cpu); @@ -507,6 +543,16 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cp= u) gdb_find_static_feature("aarch64-paut= h.xml"), 0); } + +#ifdef CONFIG_USER_ONLY + /* Memory Tagging Extension (MTE) 'tag_ctl' pseudo-register. */ + if (cpu_isar_feature(aa64_mte, cpu)) { + gdb_register_coprocessor(cs, aarch64_gdb_get_tag_ctl_reg, + aarch64_gdb_set_tag_ctl_reg, + gdb_find_static_feature("aarch64-mte.= xml"), + 0); + } +#endif #endif } else { if (arm_feature(env, ARM_FEATURE_NEON)) { diff --git a/target/arm/gdbstub64.c b/target/arm/gdbstub64.c index caa31ff3fa..2e2bc2700b 100644 --- a/target/arm/gdbstub64.c +++ b/target/arm/gdbstub64.c @@ -21,6 +21,12 @@ #include "cpu.h" #include "internals.h" #include "gdbstub/helpers.h" +#include "gdbstub/commands.h" +#include "tcg/mte_helper.h" +#if defined(CONFIG_USER_ONLY) && defined(CONFIG_LINUX) +#include +#include "mte_user_helper.h" +#endif =20 int aarch64_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) { @@ -381,3 +387,220 @@ GDBFeature *arm_gen_dynamic_svereg_feature(CPUState *= cs, int base_reg) =20 return &cpu->dyn_svereg_feature.desc; } + +#ifdef CONFIG_USER_ONLY +int aarch64_gdb_get_tag_ctl_reg(CPUState *cs, GByteArray *buf, int reg) +{ + ARMCPU *cpu =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; + uint64_t tcf0; + + assert(reg =3D=3D 0); + + tcf0 =3D extract64(env->cp15.sctlr_el[1], 38, 2); + + return gdb_get_reg64(buf, tcf0); +} + +int aarch64_gdb_set_tag_ctl_reg(CPUState *cs, uint8_t *buf, int reg) +{ + ARMCPU *cpu =3D ARM_CPU(cs); + CPUARMState *env =3D &cpu->env; + + uint8_t tcf; + + assert(reg =3D=3D 0); + + tcf =3D *buf << PR_MTE_TCF_SHIFT; + + if (!tcf) { + return 0; + } + + /* + * 'tag_ctl' register is actually a "pseudo-register" provided by GDB = to + * expose options regarding the type of MTE fault that can be controll= ed at + * runtime. + */ + arm_set_mte_tcf0(env, tcf); + + return 1; +} + +static void handle_q_memtag(GArray *params, void *user_ctx) +{ + ARMCPU *cpu =3D ARM_CPU(user_ctx); + CPUARMState *env =3D &cpu->env; + + uint64_t addr =3D gdb_get_cmd_param(params, 0)->val_ull; + uint64_t len =3D gdb_get_cmd_param(params, 1)->val_ul; + int type =3D gdb_get_cmd_param(params, 2)->val_ul; + + uint8_t *tags; + uint8_t addr_tag; + + g_autoptr(GString) str_buf =3D g_string_new(NULL); + + /* + * GDB does not query multiple tags for a memory range on remote targe= ts, so + * that's not supported either by gdbstub. + */ + if (len !=3D 1) { + gdb_put_packet("E02"); + } + + /* GDB never queries a tag different from an allocation tag (type 1). = */ + if (type !=3D 1) { + gdb_put_packet("E03"); + } + + /* Note that tags are packed here (2 tags packed in one byte). */ + tags =3D allocation_tag_mem_probe(env, 0, addr, MMU_DATA_LOAD, 8 /* 64= -bit */, + MMU_DATA_LOAD, true, 0); + if (!tags) { + /* Address is not in a tagged region. */ + gdb_put_packet("E04"); + return; + } + + /* Unpack tag from byte. */ + addr_tag =3D load_tag1(addr, tags); + g_string_printf(str_buf, "m%.2x", addr_tag); + + gdb_put_packet(str_buf->str); +} + +static void handle_q_isaddresstagged(GArray *params, void *user_ctx) +{ + ARMCPU *cpu =3D ARM_CPU(user_ctx); + CPUARMState *env =3D &cpu->env; + + uint64_t addr =3D gdb_get_cmd_param(params, 0)->val_ull; + + uint8_t *tags; + const char *reply; + + tags =3D allocation_tag_mem_probe(env, 0, addr, MMU_DATA_LOAD, 8 /* 64= -bit */, + MMU_DATA_LOAD, true, 0); + reply =3D tags ? "01" : "00"; + + gdb_put_packet(reply); +} + +static void handle_Q_memtag(GArray *params, void *user_ctx) +{ + ARMCPU *cpu =3D ARM_CPU(user_ctx); + CPUARMState *env =3D &cpu->env; + + uint64_t start_addr =3D gdb_get_cmd_param(params, 0)->val_ull; + uint64_t len =3D gdb_get_cmd_param(params, 1)->val_ul; + int type =3D gdb_get_cmd_param(params, 2)->val_ul; + char const *new_tags_str =3D gdb_get_cmd_param(params, 3)->data; + + uint64_t end_addr; + + int num_new_tags; + uint8_t *tags; + + g_autoptr(GByteArray) new_tags =3D g_byte_array_new(); + + /* + * Only the allocation tag (i.e. type 1) can be set at the stub side. + */ + if (type !=3D 1) { + gdb_put_packet("E02"); + return; + } + + end_addr =3D start_addr + (len - 1); /* 'len' is always >=3D 1 */ + /* Check if request's memory range does not cross page boundaries. */ + if ((start_addr ^ end_addr) & TARGET_PAGE_MASK) { + gdb_put_packet("E03"); + return; + } + + /* + * Get all tags in the page starting from the tag of the start address. + * Note that there are two tags packed into a single byte here. + */ + tags =3D allocation_tag_mem_probe(env, 0, start_addr, MMU_DATA_STORE, + 8 /* 64-bit */, MMU_DATA_STORE, true, = 0); + if (!tags) { + /* Address is not in a tagged region. */ + gdb_put_packet("E04"); + return; + } + + /* Convert tags provided by GDB, 2 hex digits per tag. */ + num_new_tags =3D strlen(new_tags_str) / 2; + gdb_hextomem(new_tags, new_tags_str, num_new_tags); + + uint64_t address =3D start_addr; + int new_tag_index =3D 0; + while (address <=3D end_addr) { + uint8_t new_tag; + int packed_index; + + /* + * Find packed tag index from unpacked tag index. There are two ta= gs + * in one packed index (one tag per nibble). + */ + packed_index =3D new_tag_index / 2; + + new_tag =3D new_tags->data[new_tag_index % num_new_tags]; + store_tag1(address, tags + packed_index, new_tag); + + address +=3D TAG_GRANULE; + new_tag_index++; + } + + gdb_put_packet("OK"); +} + +enum Command { + qMemTags, + qIsAddressTagged, + QMemTags, + NUM_CMDS +}; + +static GdbCmdParseEntry cmd_handler_table[NUM_CMDS] =3D { + [qMemTags] =3D { + .handler =3D handle_q_memtag, + .cmd_startswith =3D true, + .cmd =3D "MemTags:", + .schema =3D "L,l:l0", + .need_cpu_context =3D true + }, + [qIsAddressTagged] =3D { + .handler =3D handle_q_isaddresstagged, + .cmd_startswith =3D true, + .cmd =3D "IsAddressTagged:", + .schema =3D "L0", + .need_cpu_context =3D true + }, + [QMemTags] =3D { + .handler =3D handle_Q_memtag, + .cmd_startswith =3D true, + .cmd =3D "MemTags:", + .schema =3D "L,l:l:s0", + .need_cpu_context =3D true + }, +}; +#endif /* CONFIG_USER_ONLY */ + +void aarch64_cpu_register_gdb_commands(ARMCPU *cpu, GString *qsupported, + GArray *qtable, GArray *stable) +{ +#ifdef CONFIG_USER_ONLY + /* MTE */ + if (cpu_isar_feature(aa64_mte, cpu)) { + g_string_append(qsupported, ";memory-tagging+"); + + g_array_append_val(qtable, cmd_handler_table[qMemTags]); + g_array_append_val(qtable, cmd_handler_table[qIsAddressTagged]); + + g_array_append_val(stable, cmd_handler_table[QMemTags]); + } +#endif +} diff --git a/target/arm/internals.h b/target/arm/internals.h index 11b5da2562..e1aa1a63b9 100644 --- a/target/arm/internals.h +++ b/target/arm/internals.h @@ -358,6 +358,10 @@ void init_cpreg_list(ARMCPU *cpu); void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu); void arm_translate_init(void); =20 +void arm_cpu_register_gdb_commands(ARMCPU *cpu); +void aarch64_cpu_register_gdb_commands(ARMCPU *cpu, GString *, GArray *, + GArray *); + void arm_restore_state_to_opc(CPUState *cs, const TranslationBlock *tb, const uint64_t *data); @@ -1640,6 +1644,8 @@ int aarch64_gdb_get_fpu_reg(CPUState *cs, GByteArray = *buf, int reg); int aarch64_gdb_set_fpu_reg(CPUState *cs, uint8_t *buf, int reg); int aarch64_gdb_get_pauth_reg(CPUState *cs, GByteArray *buf, int reg); int aarch64_gdb_set_pauth_reg(CPUState *cs, uint8_t *buf, int reg); +int aarch64_gdb_get_tag_ctl_reg(CPUState *cs, GByteArray *buf, int reg); +int aarch64_gdb_set_tag_ctl_reg(CPUState *cs, uint8_t *buf, int reg); void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp); void arm_cpu_sme_finalize(ARMCPU *cpu, Error **errp); void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp); --=20 2.34.1 From nobody Sun Nov 24 22:48:38 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=1719552122; cv=none; d=zohomail.com; s=zohoarc; b=KN1Z2o/vOz6ouROC8vF9tqEQR7UUaZIgcgC86xCt5XvZkT/5Gm2QV3Yz99dP6DKY7ziltm4jd5AXBA3SJ4gfb0NU+GfKrhQpsjkvn+/3Wq1RV+TNoXAV5EdMQQkY3s1MJr8ivhbnQS8v/4C9Q+WlSxYRVN/82PZc6YG99UyOSAY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719552122; h=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=2tvR2Y7+nSn3Pxo3Fbwom110b8uxg9pDh1mqZBzCXAo=; b=aZ6ltn9hO/AoiMmF9mEZGAoOsyTO2cPHVu++NZ5mp04I/VYDc9IeQwh0jWXB/HNmdlg+WDHcreNd6N+fnV8x4WTaXjROZ3ZPCJGXCF1j+uYL3GDT4eSKZYLaBPydwIswVuCZ+wPERBk3+HWh69O/rjKMDVBbnV0HoNDA7pLPdQI= 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 171955212290517.717212260571273; Thu, 27 Jun 2024 22:22:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sN43G-0003f0-4k; Fri, 28 Jun 2024 01:21:38 -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 1sN438-0003Yb-Br for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:30 -0400 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sN435-0008Fl-P1 for qemu-devel@nongnu.org; Fri, 28 Jun 2024 01:21:29 -0400 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-5b53bb4bebaso107192eaf.0 for ; Thu, 27 Jun 2024 22:21:27 -0700 (PDT) Received: from amd.. ([2804:7f0:b401:391e:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-72c6b2a16cdsm423932a12.46.2024.06.27.22.21.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 22:21:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719552086; x=1720156886; 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=2tvR2Y7+nSn3Pxo3Fbwom110b8uxg9pDh1mqZBzCXAo=; b=oUcs4mv6PC11vG1jgfVs+QKrKlARK8Ac+sjocM2xiHV60dEQ6PJgZvw4l/deZM0pmY CjoMwh+fL3U8h53ImqO+FD62M8R0HioVsYyQfRuP4nXWSkRT7fYcjYEin0AcJexYHB5R Zcx2GjGD1QtyDfXC6kgyn5H8p0St4W1v21wqmGCUMT6UWmUI6S0GqSNZDD5oZLnAFzyk cIR+IUAbFL9MkxSbi7aVzXW5hWiIUPPkBxsrHIQG1ngF2mQNqpjxqlp4LdzaV9Gl9cRB ya1s/4fnBuc+OMCQMd7+xByW9Tqs6avv9B9n28CWkHbtFaMQkcgEPv4p88UHyVPmT55e xnjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719552086; x=1720156886; 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=2tvR2Y7+nSn3Pxo3Fbwom110b8uxg9pDh1mqZBzCXAo=; b=cj7rj49LvWZ06hw9LSKL6FkLA9gYXFVEQsolAJA8V+nwjscrYqKwd9mCysdCzhwS+l eZWfmPEJsQaghBz2LeP+N1xSXPsXvdQqadINrriIYwDBLbpkQKRNbgGuvyEr/0/x7G3O +Hn3dc3/VYPah+5KQYXyHgBV8Ap54/JACjTQu6imKREtTFZR8g1hI7epySFlGp+U4tFA 31WawnQ9lxDOqJcf+C9YzTNOfMbrpOK8Qsa2bSxDDAHs7MxOuhgg75IznTiLTC7JqDN8 WxWtHnetX3p8QLVa7qlYYzgio7khuTSTJF/U56xZUtZmt4S9LUeRWd4g3c75PV2Sbg86 KYxw== X-Gm-Message-State: AOJu0YzUx4ia33BGfjEvhU09icANZRow1F5dWbVioohflCnORQLb7U3T 9nWt5KB0QVO0BZTJsLkSgRVzAu4gFKjdz75uSFGe0vu53/1cVYvETyY7fMVRY4EdpHQX7haP+Gp m X-Google-Smtp-Source: AGHT+IGgcCrb27iSwGo5zXxX+Dn6cxbZsxOQ2hLbbExcKTbI3lEvRDQdyH1MWTl/M1A95rgo8GJFfQ== X-Received: by 2002:a05:6870:a70b:b0:24f:c31a:5c29 with SMTP id 586e51a60fabf-25cfcf2f0bbmr16793223fac.43.1719552085682; Thu, 27 Jun 2024 22:21:25 -0700 (PDT) From: Gustavo Romero To: qemu-devel@nongnu.org, philmd@linaro.org, alex.bennee@linaro.org, richard.henderson@linaro.org Cc: peter.maydell@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v6 11/11] tests/tcg/aarch64: Add MTE gdbstub tests Date: Fri, 28 Jun 2024 05:08:50 +0000 Message-Id: <20240628050850.536447-12-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240628050850.536447-1-gustavo.romero@linaro.org> References: <20240628050850.536447-1-gustavo.romero@linaro.org> MIME-Version: 1.0 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=2607:f8b0:4864:20::c2b; envelope-from=gustavo.romero@linaro.org; helo=mail-oo1-xc2b.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: 1719552123368100004 Content-Type: text/plain; charset="utf-8" Add tests to exercise the MTE stubs. The tests will only run if a version of GDB that supports MTE is available in the test environment. Signed-off-by: Gustavo Romero --- configure | 4 ++ tests/tcg/aarch64/Makefile.target | 14 +++- tests/tcg/aarch64/gdbstub/test-mte.py | 86 +++++++++++++++++++++++ tests/tcg/aarch64/mte-8.c | 98 +++++++++++++++++++++++++++ 4 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/aarch64/gdbstub/test-mte.py create mode 100644 tests/tcg/aarch64/mte-8.c diff --git a/configure b/configure index 5ad1674ca5..10f7e1259a 100755 --- a/configure +++ b/configure @@ -1673,6 +1673,10 @@ for target in $target_list; do echo "GDB=3D$gdb_bin" >> $config_target_mak fi =20 + if test "${arch}" =3D "aarch64" && version_ge ${gdb_version##* } 15.= 0; then + echo "GDB_HAS_MTE=3Dy" >> $config_target_mak + fi + echo "run-tcg-tests-$target: $qemu\$(EXESUF)" >> Makefile.prereqs tcg_tests_targets=3D"$tcg_tests_targets $target" fi diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile= .target index 70d728ae9a..f306e3d257 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -62,7 +62,7 @@ AARCH64_TESTS +=3D bti-2 =20 # MTE Tests ifneq ($(CROSS_CC_HAS_ARMV8_MTE),) -AARCH64_TESTS +=3D mte-1 mte-2 mte-3 mte-4 mte-5 mte-6 mte-7 +AARCH64_TESTS +=3D mte-1 mte-2 mte-3 mte-4 mte-5 mte-6 mte-7 mte-8 mte-%: CFLAGS +=3D -march=3Darmv8.5-a+memtag endif =20 @@ -128,6 +128,18 @@ run-gdbstub-sve-ioctls: sve-ioctls basic gdbstub SVE ZLEN support) =20 EXTRA_RUNS +=3D run-gdbstub-sysregs run-gdbstub-sve-ioctls + +ifeq ($(GDB_HAS_MTE),y) +run-gdbstub-mte: mte-8 + $(call run-test, $@, $(GDB_SCRIPT) \ + --gdb $(GDB) \ + --qemu $(QEMU) --qargs "$(QEMU_OPTS)" \ + --bin $< --test $(AARCH64_SRC)/gdbstub/test-mte.py, \ + gdbstub MTE support) + +EXTRA_RUNS +=3D run-gdbstub-mte +endif + endif endif =20 diff --git a/tests/tcg/aarch64/gdbstub/test-mte.py b/tests/tcg/aarch64/gdbs= tub/test-mte.py new file mode 100644 index 0000000000..2db0663c1a --- /dev/null +++ b/tests/tcg/aarch64/gdbstub/test-mte.py @@ -0,0 +1,86 @@ +from __future__ import print_function +# +# Test GDB memory-tag commands that exercise the stubs for the qIsAddressT= agged, +# qMemTag, and QMemTag packets. Logical tag-only commands rely on local +# operations, hence don't exercise any stub. +# +# The test consists in breaking just after a atag() call (which sets the +# allocation tag -- see mte-8.c for details) and setting/getting tags in +# different memory locations and ranges starting at the address of the arr= ay +# 'a'. +# +# This is launched via tests/guest-debug/run-test.py +# + + +import gdb +import re +from test_gdbstub import main, report + + +PATTERN_0 =3D "Memory tags for address 0x[0-9a-f]+ match \(0x[0-9a-f]+\)." +PATTERN_1 =3D ".*(0x[0-9a-f]+)" + + +def run_test(): + gdb.execute("break 95", False, True) + gdb.execute("continue", False, True) + try: + # Test if we can check correctly that the allocation tag for + # array 'a' matches the logical tag after atag() is called. + co =3D gdb.execute("memory-tag check a", False, True) + tags_match =3D re.findall(PATTERN_0, co, re.MULTILINE) + if tags_match: + report(True, f"{tags_match[0]}") + else: + report(False, "Logical and allocation tags don't match!") + + # Test allocation tag 'set and print' commands. Commands on logical + # tags rely on local operation and so don't exercise any stub. + + # Set the allocation tag for the first granule (16 bytes) of + # address starting at 'a' address to a known value, i.e. 0x04. + gdb.execute("memory-tag set-allocation-tag a 1 04", False, True) + + # Then set the allocation tag for the second granule to a known + # value, i.e. 0x06. This tests that contiguous tag granules are + # set correct and don't run over each other. + gdb.execute("memory-tag set-allocation-tag a+16 1 06", False, True) + + # Read the known values back and check if they remain the same. + + co =3D gdb.execute("memory-tag print-allocation-tag a", False, Tru= e) + first_tag =3D re.match(PATTERN_1, co)[1] + + co =3D gdb.execute("memory-tag print-allocation-tag a+16", False, = True) + second_tag =3D re.match(PATTERN_1, co)[1] + + if first_tag =3D=3D "0x4" and second_tag =3D=3D "0x6": + report(True, "Allocation tags are correctly set/printed.") + else: + report(False, "Can't set/print allocation tags!") + + # Now test fill pattern by setting a whole page with a pattern. + gdb.execute("memory-tag set-allocation-tag a 4096 0a0b", False, Tr= ue) + + # And read back the tags of the last two granules in page so + # we also test if the pattern is set correctly up to the end of + # the page. + co =3D gdb.execute("memory-tag print-allocation-tag a+4096-32", Fa= lse, True) + tag =3D re.match(PATTERN_1, co)[1] + + co =3D gdb.execute("memory-tag print-allocation-tag a+4096-16", Fa= lse, True) + last_tag =3D re.match(PATTERN_1, co)[1] + + if tag =3D=3D "0xa" and last_tag =3D=3D "0xb": + report(True, "Fill pattern is ok.") + else: + report(False, "Fill pattern failed!") + + except gdb.error: + # This usually happens because a GDB version that does not + # support memory tagging was used to run the test. + report(False, "'memory-tag' command failed!") + + +main(run_test, expected_arch=3D"aarch64") diff --git a/tests/tcg/aarch64/mte-8.c b/tests/tcg/aarch64/mte-8.c new file mode 100644 index 0000000000..9fffd7b737 --- /dev/null +++ b/tests/tcg/aarch64/mte-8.c @@ -0,0 +1,98 @@ +/* + * To be compiled with -march=3Darmv8.5-a+memtag + * + * This test is adapted from a Linux test. Please see: + * + * https://www.kernel.org/doc/html/next/arch/arm64/memory-tagging-extensio= n.html#example-of-correct-usage + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* + * From arch/arm64/include/uapi/asm/hwcap.h + */ +#define HWCAP2_MTE (1 << 18) + +/* + * From arch/arm64/include/uapi/asm/mman.h + */ +#define PROT_MTE 0x20 + +/* + * Insert a random logical tag into the given pointer. + */ +#define insert_random_tag(ptr) ({ \ + uint64_t __val; \ + asm("irg %0, %1" : "=3Dr" (__val) : "r" (ptr)); \ + __val; \ +}) + +/* + * Set the allocation tag on the destination address. + */ +#define set_tag(tagged_addr) do { \ + asm volatile("stg %0, [%0]" : : "r" (tagged_addr) : "memory"); \ +} while (0) + + +int main(int argc, char *argv[]) +{ + unsigned char *a; + unsigned long page_sz =3D sysconf(_SC_PAGESIZE); + unsigned long hwcap2 =3D getauxval(AT_HWCAP2); + + /* check if MTE is present */ + if (!(hwcap2 & HWCAP2_MTE)) + return EXIT_FAILURE; + + /* + * Enable the tagged address ABI, synchronous or asynchronous MTE + * tag check faults (based on per-CPU preference) and allow all + * non-zero tags in the randomly generated set. + */ + if (prctl(PR_SET_TAGGED_ADDR_CTRL, + PR_TAGGED_ADDR_ENABLE | PR_MTE_TCF_SYNC | PR_MTE_TCF_ASYNC | + (0xfffe << PR_MTE_TAG_SHIFT), + 0, 0, 0)) { + perror("prctl() failed"); + return EXIT_FAILURE; + } + + a =3D mmap(0, page_sz, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (a =3D=3D MAP_FAILED) { + perror("mmap() failed"); + return EXIT_FAILURE; + } + + printf("a[] address is %p\n", a); + + /* + * Enable MTE on the above anonymous mmap. The flag could be passed + * directly to mmap() and skip this step. + */ + if (mprotect(a, page_sz, PROT_READ | PROT_WRITE | PROT_MTE)) { + perror("mprotect() failed"); + return EXIT_FAILURE; + } + + /* access with the default tag (0) */ + a[0] =3D 1; + a[1] =3D 2; + + printf("a[0] =3D %hhu a[1] =3D %hhu\n", a[0], a[1]); + + /* set the logical and allocation tags */ + a =3D (unsigned char *)insert_random_tag(a); + set_tag(a); + + printf("%p\n", a); + + return 0; +} --=20 2.34.1