From patchwork Tue Apr 16 14:07:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 88541 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C345F384772F for ; Tue, 16 Apr 2024 14:08:26 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 5A6D43858D39 for ; Tue, 16 Apr 2024 14:07:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A6D43858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5A6D43858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::433 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276476; cv=none; b=Gz/B8WRjbs6ZXXTQCdCWvULTG8wKz21caDV3HUMpRIM2kbs8MYOQ9emcr9pJGkeo1GS1RrAYV/+aiImW/IpdLATzh5Yt7elAmDLiGgb7fEGE+6WgJdHtrl4ZEQ2UkRq+H6JHm0SIUN22jwqpzO0LOmnEpTarqlLaIt7YO6ODJn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276476; c=relaxed/simple; bh=zn4DbmTot8VHmhi87qT4JPigPp9gYVtGLVN1Tzseteg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=GWdWRQHSSmLlRYoxol+I5pAb0/jE5Urw9g5IcJyZjkSN2gzqV8pw81gJZj9z/CD4+7gRudfp6XTdPvX84Iz52sNFG5tL3X+YJmBN8e5Tu69okCEwN7tibg9nt6sG+sLi1V0+RbCdyySsgFmQp6cT2LgQs9kbgxldUOMB01xHBZU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6eff2be3b33so2173416b3a.2 for ; Tue, 16 Apr 2024 07:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713276465; x=1713881265; darn=sourceware.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=tYCk/P1xjalYBJuMqLUvPVXaT9Bbd2Fw6xG3npnM6gg=; b=mbGmm4iGXeQ8j4pVCaXCuRgO93GJA7IMwhe2Ib/PJ3Tzm+hwhvfRq4UC4+1XE+TE/E 9QryPUmQPubEbBBX9aM2hVDHjJl4YITVZTRCs2NCMBFMWUiSO8/9p0nOuZ6HmQKaeecV Df+yGcEvVZLWEhHpu2gUYzJLrlb4fpBNl9CEd9oaJiQyUxlz4+QBQNDOqu/ajdxWQsAe Ikqvk8iog3Oca/BQ7Dpmebsu3vWaZFMmqlSX4ufSQCzoE1Xu206sekCsq/h/KiY7P5V3 g0YOamRUBwLfGQz/GPwsCQG7t4ren8J2BaUcBuwXkXjw71q+1syXDUpU3uOBf3cF0cm2 Sj4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713276465; x=1713881265; 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=tYCk/P1xjalYBJuMqLUvPVXaT9Bbd2Fw6xG3npnM6gg=; b=hUre2dZKwsZ+qiVpiHNxyRkkeIzaGZsOj/6xNNLhWBk0bwEi6op8ALDRLG/komNtN2 1NGbrJtAHLb79tOclMG5qgfISzVGGCjatPF+GushMEgItqOu/4joLjgK8fO4sYEWpfJz 7s33EtlK7hktsRksQHtq0ZRzYn8CefsRDp+Kso3H96gO5VN6IiD/oc4dtCJdWwmfg9FX 9yhDdJQL9Igbgpz9Bv+xMJUJn2hAclMtScEkFGzY+XILHQy5QsggtRcG6E/k4FGWyGAV vT0IawxZ6Y9YU2FZWC+z4uUhNUEXhbtFwQkgMCEM5G6SUh2V4K4RnKOSbnqL2bAsfyeg p5SQ== X-Gm-Message-State: AOJu0YxJDJSuR+ER2S2MSzjMUs54Tcsk0w24bedsFENwixiZEYdBb+kd ZOvf2GWo2S3JH5yLIxlsYr8v1kB0Srdx41j/tLrLfZ56yg07rgB4ElGYw/TIfxnkfa0GbxdPiLl RNLE= X-Google-Smtp-Source: AGHT+IGdCTsare5CbQpKG6YLt8mrf5yYQY8g971S5gSGnIJNQlOlX4Aq/tEOC2i4dh/wyr8r1KWCcg== X-Received: by 2002:a05:6a20:d487:b0:1a9:c3ac:be77 with SMTP id im7-20020a056a20d48700b001a9c3acbe77mr11997225pzb.1.1713276464760; Tue, 16 Apr 2024 07:07:44 -0700 (PDT) Received: from amd.. ([2804:7f0:b403:ad57:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id o3-20020a63e343000000b005f3d54c0a57sm8937473pgj.49.2024.04.16.07.07.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 07:07:44 -0700 (PDT) From: Gustavo Romero To: gdb-patches@sourceware.org Cc: luis.machado@arm.com, thiago.bauermann@linaro.org, eliz@gnu.org, tom@tromey.com, gustavo.romero@linaro.org Subject: [PATCH v4 1/8] gdb: aarch64: Remove MTE address checking from get_memtag Date: Tue, 16 Apr 2024 14:07:21 +0000 Message-Id: <20240416140728.198163-2-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416140728.198163-1-gustavo.romero@linaro.org> References: <20240416140728.198163-1-gustavo.romero@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This commit removes aarch64_linux_tagged_address_p from aarch64_linux_get_memtag. aarch64_linux_tagged_address_p checks if an address is tagged (MTE) or not. The check is redundant because aarch64_linux_get_memtag is always called from the upper layers (i.e. from printcmd.c via gdbarch hook gdbarch_get_memtag) after either gdbarch_tagged_address_p (that already points to aarch64_linux_tagged_address_p) has been called or after should_validate_memtags (that calls gdbarch_tagged_address_p at the end) has been called, so the address is already checked. Hence: a) in print_command_1, aarch64_linux_get_memtag (via gdbarch_get_memtag hook) is called but only after should_validate_memtags, which calls gdbarch_tagged_address_p; b) in do_examine, aarch64_linux_get_memtag is also called only after gdbarch_tagged_address_p is directly called; c) in memory_tag_check_command, gdbarch_get_memtag is called -- tags matching or not -- after the initial check via direct call to gdbarch_tagged_address_p; d) in memory_tag_print_tag_command, address is checked directly via gdbarch_tagged_address_p before gdbarch_get_memtag is called. Also, because after this change the address checking only happens at the upper layer it now allows the address checking to be specialized easily per target, via a target hook. Signed-off-by: Gustavo Romero Reviewed-by: Thiago Jung Bauermann Approved-By: Luis Machado Tested-By: Luis Machado --- gdb/aarch64-linux-tdep.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 0b9784f38e4..50055ac3f48 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -2575,10 +2575,6 @@ aarch64_linux_get_memtag (struct gdbarch *gdbarch, struct value *address, tag = aarch64_mte_get_ltag (addr); else { - /* Make sure we are dealing with a tagged address to begin with. */ - if (!aarch64_linux_tagged_address_p (gdbarch, address)) - return nullptr; - /* Remove the top byte. */ addr = gdbarch_remove_non_address_bits (gdbarch, addr); std::optional atag = aarch64_mte_get_atag (addr); From patchwork Tue Apr 16 14:07:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 88542 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0BC4A3849AF2 for ; Tue, 16 Apr 2024 14:08:52 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by sourceware.org (Postfix) with ESMTPS id D7A5D3858D3C for ; Tue, 16 Apr 2024 14:07:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D7A5D3858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D7A5D3858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276479; cv=none; b=mhQCNn+g097GsT12BAKpTs8mm/Je4p4jsmW+goza1rZbKIqtKi9wSfVOeAx6Mll+0LGcL3BT0kactNxSYCmNUKaTZ28lJhdnk8h/IBP5n/iWbMNf2a1oZcaqvZ2nE7C7Jj4HI5hMPhZkS1ankA0iMkV5e/P9489hwZ7QC3Wf2aI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276479; c=relaxed/simple; bh=3wFYPzMpcsYUfRIUjgt4vWvnnR5nfM+xAA2QmOtJ+aU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=P3VDItNUXkuZq6cLW5NL3+ugY/s0UrwPw9GXMKMxL8Ma/VsCp4/lBznBUgSFeVmCPP0Wim6b0ZISldDNMfOTM9jsiA49bEE2L0fMi9iScPlzTx7+rK8WoWVvpGiIsLyabQlGMuG+ZY5X3fzkk4TL4qUZZ8ZflG4LB27lI5zeuMA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-5d8ddbac4fbso3055133a12.0 for ; Tue, 16 Apr 2024 07:07:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713276467; x=1713881267; darn=sourceware.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=XYxbCVl1FXv3gDOM6iOdkdM2eKMXrox+2an/RLVCH9s=; b=FIO7FaZF6UO5C2+cVkpnC+502A525ZFM3bm0j8APSeSLkHY8oevoktLv4QLm/6ksls MW6WCt1d+OmS4B3vbNhhnmsbmka/VTF5dud+DGmpoEqQzh3RYw7WZ7wJCBRfe+oP7O4A eCjmcEFKf1hi3SqP54wowZtSzeBEwSd635AnMQI72avEaisWG/TEAyS0D+slvnumCFrr B9kvuwB2tBNOLm6bSEn6dVVPsojZPEcgLQp/mxsHpJGrHdXxThMh6hEQ5NRbkqWakv48 9bWb5eDG8zSITj5OIOerTMSjSwx4/Yp4MvuKrNKW3WduGzWarQJWXgogcR2u7coXBEn5 3NdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713276467; x=1713881267; 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=XYxbCVl1FXv3gDOM6iOdkdM2eKMXrox+2an/RLVCH9s=; b=Bzy7jxImCZ85Dvrzd3LepIy0oLKav71xDZnNhDyVIKpDtGpgjITcnf/0QnZ8fdKdSZ zUuHutO/9li+50T88scqJ9HMsHffiO9Gbyx1gCEaFiDNk52NUH5s4rhfl75bwYG+EVOf FuIAyTxy76CI77qKOlGCR02ESZll2zBMVZO5rB6xu9f2urKwPKh5fzgHuY2urfCBoho1 +mdg+R/clRcKtOnr27fxSJzxA6xYrco5jzDLMowXXo/cQK66zVu4O+Ze/o891tWUGEef khvgPrHyhYhYHZ6AJhWfS+V/HSTCjiUVXd7twA1qUhV4jWAD7iBWVOopSQAh4SAyCyst ghYA== X-Gm-Message-State: AOJu0YyOP5UHhGO1nOaUNLbKbcCSuh/4JBH6HiqorZncvqbzbk85GZUg sMSsRw3xihbYs8xga8H/QWAxoK45/9joWzEYz/dNbGLcxgrHePBVG26M7WRWtLEUHdYtxJxummp crX4= X-Google-Smtp-Source: AGHT+IEB79xZ9njzk2ApemxDY3hAGJA1AI+06qREaBoh4FflGLZMQtFUxgGpysjWGCrYZNfpdL9cDA== X-Received: by 2002:a05:6a21:1644:b0:1a9:c3e2:65bb with SMTP id no4-20020a056a21164400b001a9c3e265bbmr15276020pzb.14.1713276467290; Tue, 16 Apr 2024 07:07:47 -0700 (PDT) Received: from amd.. ([2804:7f0:b403:ad57:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id o3-20020a63e343000000b005f3d54c0a57sm8937473pgj.49.2024.04.16.07.07.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 07:07:46 -0700 (PDT) From: Gustavo Romero To: gdb-patches@sourceware.org Cc: luis.machado@arm.com, thiago.bauermann@linaro.org, eliz@gnu.org, tom@tromey.com, gustavo.romero@linaro.org Subject: [PATCH v4 2/8] gdb: aarch64: Move MTE address check out of set_memtag Date: Tue, 16 Apr 2024 14:07:22 +0000 Message-Id: <20240416140728.198163-3-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416140728.198163-1-gustavo.romero@linaro.org> References: <20240416140728.198163-1-gustavo.romero@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Remove check in parse_set_allocation_tag_input as it is redundant: currently the check happens at the end of parse_set_allocation_tag_input and also in set_memtag (called after parse_set_allocation_tag_input). After it, move MTE address check out of set_memtag and add this check to the upper layer, before set_memtag is called. This is a preparation for using a target hook instead of a gdbarch hook on MTE address checks. Signed-off-by: Gustavo Romero --- gdb/aarch64-linux-tdep.c | 4 ---- gdb/printcmd.c | 10 +++++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 50055ac3f48..8e6e63d4dcb 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -2525,10 +2525,6 @@ aarch64_linux_set_memtags (struct gdbarch *gdbarch, struct value *address, /* Remove the top byte. */ addr = gdbarch_remove_non_address_bits (gdbarch, addr); - /* Make sure we are dealing with a tagged address to begin with. */ - if (!aarch64_linux_tagged_address_p (gdbarch, address)) - return false; - /* With G being the number of tag granules and N the number of tags passed in, we can have the following cases: diff --git a/gdb/printcmd.c b/gdb/printcmd.c index cb0d32aa4bc..5635f605314 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -3101,11 +3101,6 @@ parse_set_allocation_tag_input (const char *args, struct value **val, error (_("Error parsing tags argument. Tags should be 2 digits per byte.")); tags = hex2bin (tags_string.c_str ()); - - /* If the address is not in a region memory mapped with a memory tagging - flag, it is no use trying to access/manipulate its allocation tag. */ - if (!gdbarch_tagged_address_p (current_inferior ()->arch (), *val)) - show_addr_not_tagged (value_as_address (*val)); } /* Implement the "memory-tag set-allocation-tag" command. @@ -3127,6 +3122,11 @@ memory_tag_set_allocation_tag_command (const char *args, int from_tty) /* Parse the input. */ parse_set_allocation_tag_input (args, &val, &length, tags); + /* If the address is not in a region memory-mapped with a memory tagging + flag, it is no use trying to manipulate its allocation tag. */ + if (!gdbarch_tagged_address_p (current_inferior ()->arch (), val)) + show_addr_not_tagged (value_as_address (val)); + if (!gdbarch_set_memtags (current_inferior ()->arch (), val, length, tags, memtag_type::allocation)) gdb_printf (_("Could not update the allocation tag(s).\n")); From patchwork Tue Apr 16 14:07:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 88543 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 78377384641E for ; Tue, 16 Apr 2024 14:09:02 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id BDA933858CDA for ; Tue, 16 Apr 2024 14:07:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BDA933858CDA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BDA933858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276477; cv=none; b=yEUva6kbmDF73cw/rY46oz+8ecvMLK3HWzpgtAK5mcY1PeWU5v/loxE9RvN6puEV2bTHFX6DiDabm62MuL/o756dXCqi4dV46WsB8zDxfVkWdwrw1dJlWeJQmrLe1hsX1dXuPLfslh6L5vIW2tZtAyVdxxI8ne9VqJIs8P+/SjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276477; c=relaxed/simple; bh=WxhGoGvDUNyHMS4tOjdoth41+fxv5hm536NHqm7b6zY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=TrIhqZ1W4G2wEeqhPrfKXmi0sWedQN1GDJqP2YTN5CGfM3uJlgLy1cTyrY7T4soBZe+Uq4Qmt04yRX7X9Eh3K+sxcS2F8msp4b1/gl3TQS+lgGAWl/+PaOOriD4u2FuPPQgff58ecQb+SJTo+2+ahA0w+17q7lmckbsIwDOFwVM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6ecf3943040so3515803b3a.0 for ; Tue, 16 Apr 2024 07:07:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713276469; x=1713881269; darn=sourceware.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=k4t/OkSdqXOFOVdbmZG+QDE0aaiWd592cOChHpmR15U=; b=dNFdL19de/q8RksWV8R0X0vx/ia9BRg7pSYUGSwEDMN2b6cnjaIIbq/DOq+736ibvr 3biDpcmSaM9BeQCe/CSlTJ2QebgM1MbjWVoh0X+3n28oyia/PtQFoonYExw6wp5QRU8p rvXiPc+ckyXvSpdG/9jdIjZJQlkEkyvpo3cuidVCqBUc3utsaTfGP5Y+91pTjPyqTO1/ F4CM3GyrQ9XJwX6IB/CMFoS/4KKCoBeuZY7c1PxF63avkBtBRKMoWk3S8s8LVC4iY1wK n4IsMXUi8FbgxuUUAND3hWvxRt9B86069nVSXmYzs7NzSECb4gk3BdnV/UHKSSGLVZBz TAmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713276469; x=1713881269; 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=k4t/OkSdqXOFOVdbmZG+QDE0aaiWd592cOChHpmR15U=; b=nQ1XcTUO/2xnpIXSTJvEXzrv70EOjJPnED/CRFkCgmZQA8LXW6b29jbVzfK3gLb+tD sWyW7REmqzK/JIPTtRB6JOJAD/DwdRkPK5L8m8bacDDrxCEggR1BbeF9MFvtaPnCohhi G/8JWluzaASEicTJgOR65x/dVgPD5kvkplcpcX9jratVg30tTik6ohhwWj8bVqwmHoXX fj5yAfkBGjuUOY7EXteMMPA0uxkWOM67HKRaqpJmQbIbE3rTSUl2z4A/S5mJhXlNSOeh eJ0Jsdoz0K8S7iGimukZaVtb5n9pmeLJEnNgQEKYfkth5zcnTbs1nmyYyvO7BQ2uiFAM Oqrw== X-Gm-Message-State: AOJu0Yxf3uZYfaoItmYBZKTkAwjQqmR5j9o8ByQdGJg6XlgVw/vuyTI6 pXan2VAhmKwfKBEcmRe+2eS9sfPjK+l1b3gL7iSBL0nzzqCjzgomTESNdpmHnZjAPJKH7ubQ57B B51I= X-Google-Smtp-Source: AGHT+IFBhYDZN1aLqAHbMaavxFFmTClRHvaDRke67+ZnQ/YNC23VrFXFTkUcBkDsnTeMol0GltrUcA== X-Received: by 2002:a05:6300:630e:b0:1a7:a21b:66f9 with SMTP id jn14-20020a056300630e00b001a7a21b66f9mr10310191pzc.43.1713276469439; Tue, 16 Apr 2024 07:07:49 -0700 (PDT) Received: from amd.. ([2804:7f0:b403:ad57:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id o3-20020a63e343000000b005f3d54c0a57sm8937473pgj.49.2024.04.16.07.07.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 07:07:49 -0700 (PDT) From: Gustavo Romero To: gdb-patches@sourceware.org Cc: luis.machado@arm.com, thiago.bauermann@linaro.org, eliz@gnu.org, tom@tromey.com, gustavo.romero@linaro.org Subject: [PATCH v4 3/8] gdb: aarch64: Remove MTE address checking from memtag_matches_p Date: Tue, 16 Apr 2024 14:07:23 +0000 Message-Id: <20240416140728.198163-4-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416140728.198163-1-gustavo.romero@linaro.org> References: <20240416140728.198163-1-gustavo.romero@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This commit removes aarch64_linux_tagged_address_p from aarch64_linux_memtag_matches_p. aarch64_linux_tagged_address_p checks if an address is tagged (MTE) or not. The check is redundant because aarch64_linux_memtag_matches_p is always called from the upper layers (i.e. from printcmd.c via gdbarch hook gdbarch_memtag_matches_p) after either gdbarch_tagged_address_p (that already points to aarch64_linux_tagged_address_p) has been called or after should_validate_memtags (that calls gdbarch_tagged_address_p at the end) has been called, so the address is already checked. Hence: a) in print_command_1, gdbarch_memtag_matches_p is called only after should_validate_memtags is called, which checks the address at its end; b) in memory_tag_check_command, gdbarch_memtag_matches_p is called only after gdbarch_tagged_address_p is called directly. Also, because after this change the address checking only happens at the upper layer it now allows the address checking to be specialized easily per target, via a target hook. Signed-off-by: Gustavo Romero Approved-By: Luis Machado Tested-By: Luis Machado --- gdb/aarch64-linux-tdep.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 8e6e63d4dcb..fc60e602748 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -2476,10 +2476,6 @@ aarch64_linux_memtag_matches_p (struct gdbarch *gdbarch, { gdb_assert (address != nullptr); - /* Make sure we are dealing with a tagged address to begin with. */ - if (!aarch64_linux_tagged_address_p (gdbarch, address)) - return true; - CORE_ADDR addr = value_as_address (address); /* Fetch the allocation tag for ADDRESS. */ From patchwork Tue Apr 16 14:07:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 88547 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E24FF3849AFA for ; Tue, 16 Apr 2024 14:09:38 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 01F103858D37 for ; Tue, 16 Apr 2024 14:07:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 01F103858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 01F103858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276487; cv=none; b=Lijd5vq1ClNb8H1+lj3nWAvrZYBsMNYemx9ziHe/o2Ya8Of4LTd+Xf6KkPpUQmJ3jnS/ccfcnNA055rONPWCXevCn1vzvofDkkf6It0ohQcOzVanQU3LN3A+yH3agVhPTwWJuiV5JR3x+79o34LvKui/2/BKLVI6kzjftvQdSJg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276487; c=relaxed/simple; bh=5sDr5g7U2ywTRYm1e6GUiteL43TzBcSbyiTAO8R27Z8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Cs6cA7JSiR/p3+fTc2AjAX7kxvElbvOUf5rzcCyMus07Si2hKPn+OPlhq6N5HZJHeWCjVHVmfVkbZeM+yLSz1K8ufjdn7H2W7qjiW0MXDoMH+NfZDph85S52bRMIKiOoFfGVAEqEfD4aNRTx4X8btyXWOlnRIISWEZQZCUmqnkc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6ecf1bb7f38so4049169b3a.0 for ; Tue, 16 Apr 2024 07:07:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713276471; x=1713881271; darn=sourceware.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=+Udz0sOQRKXAm5kiKFSTNh5JUUjk+Jni+c5SH40tgmE=; b=VvmZsVm1kxcTn3RoWQk3gxw7w2kS280W/KuyR4q4+jQH7faleB9NFwmia1VlRGIIQp y6Iup/NtHRyWffHdHheGLe/uegTTDUmFqohLtU/6jQV8e9uVwJCqxUQxd48d2lmALKwU Hv+SvmgYLdJ7ruBQEoedib5X9sMUbFmpDbyw8axSyBabIiBbN1oxSnqUldWul/ubIgw9 FcbhSz6a68WYNw0OQr6xZXmMkl6hQvi9yfjC13gUtDCLVpzOlzezCPYD15cbelfgb+4f KlWXguZg0p187IG4Kgv4/MVzwTN61WzriDbWHIDxQLlI+ND16WwhVO2pJixXTVjGdMwI wYLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713276471; x=1713881271; 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=+Udz0sOQRKXAm5kiKFSTNh5JUUjk+Jni+c5SH40tgmE=; b=vroSjCwSmlikCAP7p8EoEzsXO/n49856EivtlwMAoGhkout2M3ROOf5n0Zsk2JBVg+ xq+unBsaJ5USzpSR/apHOvRtIpsCa+CarIevW6BLnsff8wy0SbQ+d9i3AnbwWWgDmg0I ATqP7bKPkpunwkr4Uzym77HlG/oNUYtJlfm9B6c87S5sB1N7luEMK2ZPujsq7U6FQ9ED lWpVXFcNoL1vlhY+IGaoB/5elMbRtTeY/rWR7SB/74q7uS7HCZpto4j19P0iyTkSTIgC KqzbcH83eDrNaxegjTmsMWmw9pNEj4hHBAI5KIGPj1C+pcMBK3yP2Kwtom1lZdrPz+v7 a7hA== X-Gm-Message-State: AOJu0Yy52lF3T/r8Pw5Tlp5hu+2CAk6urPxwHu/t5wqxT+1DnWWCObb4 WNLFtZER+Avwq4D+wChsa1M7ShxdiLIB8ziuutPzufltEfDVYCir8pGA56/6D0AuLGLMw8SnVXp dozY= X-Google-Smtp-Source: AGHT+IFdnkR+Z3JVyEHwjLEokMq5p2msGq0lSvpj0iqDv5dKVv17/x4U6jmKCh0y8OGBt1Ucf1T1/w== X-Received: by 2002:a05:6a20:9f4d:b0:1aa:584f:31b1 with SMTP id ml13-20020a056a209f4d00b001aa584f31b1mr1245938pzb.17.1713276471674; Tue, 16 Apr 2024 07:07:51 -0700 (PDT) Received: from amd.. ([2804:7f0:b403:ad57:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id o3-20020a63e343000000b005f3d54c0a57sm8937473pgj.49.2024.04.16.07.07.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 07:07:51 -0700 (PDT) From: Gustavo Romero To: gdb-patches@sourceware.org Cc: luis.machado@arm.com, thiago.bauermann@linaro.org, eliz@gnu.org, tom@tromey.com, gustavo.romero@linaro.org Subject: [PATCH v4 4/8] gdb: Use passed gdbarch instead of calling current_inferior Date: Tue, 16 Apr 2024 14:07:24 +0000 Message-Id: <20240416140728.198163-5-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416140728.198163-1-gustavo.romero@linaro.org> References: <20240416140728.198163-1-gustavo.romero@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org In do_examine function, use passed gdbarch when checking if an address is tagged instead of calling current_inferior()->arch() to make the code more localized and help modularity by not calling a current_* function, which disguises the use of a global state/variable. There is no change in the code behavior. Signed-off-by: Gustavo Romero Suggested-by: Thiago Jung Bauermann Approved-By: Luis Machado Tested-By: Luis Machado --- gdb/printcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 5635f605314..4edbd458e4d 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1132,7 +1132,7 @@ do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr) = value_from_ulongest (builtin_type (gdbarch)->builtin_data_ptr, tag_laddr); - if (gdbarch_tagged_address_p (current_inferior ()->arch (), v_addr)) + if (gdbarch_tagged_address_p (gdbarch, v_addr)) { /* Fetch the allocation tag. */ struct value *tag From patchwork Tue Apr 16 14:07:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 88544 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9F9AA3846400 for ; Tue, 16 Apr 2024 14:09:12 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id AF4383858C41 for ; Tue, 16 Apr 2024 14:07:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF4383858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AF4383858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::429 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276487; cv=none; b=qFWCSfTSpl+5B8f8dod8mzA4iyN3dsznw/Cs+UDMQH6BYPd5d6lPTrmXBLuuH6V6WcRXWa2RHlT7cBT+GJgPitih5yigBOHvTpAFUymdYif4qIkXUz7R/Fi+BtMLOEep83EWJjhp02PT8pMEEXw8HhW0yczg+yPZcTpAGC9RWDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276487; c=relaxed/simple; bh=51B5/EI/7jtA3901Pcuu6dGcpb8jwhnMTJA0+QgWymc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=AXJKAatxqik7Jc8fLx/CjV8a0bX6TFHDJpXLsBUsmDjFL6CrgE9AExrLviFrqb63Av48mb1OSz78mIxlG+jpG6nK+JG+uiAyGznO5y6w4eUROis8Qf7eNogMAHVCc11gHuvTrLHjAZ01MJt1+5I3lHEUg3Ux5PJTpPkqYrP3Bhg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6ecf05fd12fso4190811b3a.2 for ; Tue, 16 Apr 2024 07:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713276474; x=1713881274; darn=sourceware.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=aDxb/zg901wOzEIXVG9yopQliPwokB/YWickkC1tTt0=; b=Sm54WnVuiAaVqERv92dzdAGJbwQhN2DeeqtP3TAln0LmkeJ/YZGWgiqVcb29leAHJ+ hjATLQ6sjnSH7zAtzM6cBC/J9i5WMLA18lhnbaeauLA+2vS9TdvKp9kftFImQ23CFFG8 xMpUvSwsM5dUwXA5nYURwlbi4lNb9EGntxF0om6Q+RcXVN3g2Vcg/6mi0xymABC/xWXY ZZp7/4xrUnalvdyt8wlw9LCo5lqGyPtEfFbP1yeekRivxh/ujVaPscpN2B3qNV1ORPp2 uczOYsAdA8Swlu4jXFaI7B3p7gK+wX936lND9RxG/k0fYyGTuzRyTO7RRZNYY87KDMFK 76jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713276474; x=1713881274; 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=aDxb/zg901wOzEIXVG9yopQliPwokB/YWickkC1tTt0=; b=RJNTzwjcO40hTxCgiCvWBV9J6sLA+ej2FhHI8iitKT3gP+e0glfIMhjpg2/Dvlp+Ky U4d9Z6BykQz2B21oJtdlL+gHi5XcMpmhHWcUofaAOdhPAodZIHVNn3ZlUOtQe44ZOLwY soJuCTqTYqMh479Fw15Mjr2vI0QfRVT93S0h9ZiAOPsrgqvDb3MoeWRJmQMnadwZ06PL 2HlJezO2DD0/qbVxOEdKi8H+asEa7Lh2fb4D4JzaPISk8OKiMZ5n/QM4/ijgX2QFrGy5 ZOE+uu0HQc7NNUski7CA3dfyKaPUnhNVEf7V4nKr++7GxyzlaJHSPpZFTK9EqsAzXyGt fnzg== X-Gm-Message-State: AOJu0Yz0Pq83Z4Y4CRExV06J10FrHvgcSuKFofgzmTVtYackH+jefeC7 XswNP+cvchVF1RxnD70cBrV5kyhafmhGvoAVNsio05iDZDrMs+ZhI/bx0LafgAcSxwun/eGIDzz AsKQ= X-Google-Smtp-Source: AGHT+IGP8HV5go/e5NlvTY3Jg4Sp8YGJEgTYY3+7Ki/RbQOWbijEi8hAntY8wbHL61NWXhvLTPeBwg== X-Received: by 2002:a05:6a21:32a7:b0:1a3:b155:1cd2 with SMTP id yt39-20020a056a2132a700b001a3b1551cd2mr18677697pzb.10.1713276474131; Tue, 16 Apr 2024 07:07:54 -0700 (PDT) Received: from amd.. ([2804:7f0:b403:ad57:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id o3-20020a63e343000000b005f3d54c0a57sm8937473pgj.49.2024.04.16.07.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 07:07:53 -0700 (PDT) From: Gustavo Romero To: gdb-patches@sourceware.org Cc: luis.machado@arm.com, thiago.bauermann@linaro.org, eliz@gnu.org, tom@tromey.com, gustavo.romero@linaro.org Subject: [PATCH v4 5/8] gdb: Introduce is_address_tagged target hook Date: Tue, 16 Apr 2024 14:07:25 +0000 Message-Id: <20240416140728.198163-6-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416140728.198163-1-gustavo.romero@linaro.org> References: <20240416140728.198163-1-gustavo.romero@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This commit introduces a new target hook, target_is_address_tagged, which is used instead of the gdbarch_tagged_address_p gdbarch hook in the upper layer (printcmd.c). This change enables easy specialization of memory tagging address check per target in the future. As target_is_address_tagged continues to utilize the gdbarch_tagged_address_p hook, there is no change in behavior for all the targets that use the new target hook (i.e., the remote.c, aarch64-linux-nat.c, and corelow.c targets). Just the gdbarch_tagged_address_p signature is changed for convenience, since target_is_address_tagged takes the address to be checked as a CORE_ADDR type. Signed-off-by: Gustavo Romero Tested-By: Luis Machado --- gdb/aarch64-linux-nat.c | 15 +++++++++++++++ gdb/aarch64-linux-tdep.c | 10 +++------- gdb/arch-utils.c | 2 +- gdb/arch-utils.h | 2 +- gdb/corelow.c | 10 ++++++++++ gdb/gdbarch-gen.h | 4 ++-- gdb/gdbarch.c | 2 +- gdb/gdbarch_components.py | 2 +- gdb/printcmd.c | 26 ++++++++++++++------------ gdb/remote.c | 10 ++++++++++ gdb/target-delegates.c | 30 ++++++++++++++++++++++++++++++ gdb/target.c | 6 ++++++ gdb/target.h | 6 ++++++ 13 files changed, 100 insertions(+), 25 deletions(-) diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index 3face34ce79..297f56cdbf1 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -110,6 +110,8 @@ class aarch64_linux_nat_target final /* Write allocation tags to memory via PTRACE. */ bool store_memtags (CORE_ADDR address, size_t len, const gdb::byte_vector &tags, int type) override; + /* Check if an address is tagged. */ + bool is_address_tagged (gdbarch *gdbarch, CORE_ADDR address) override; }; static aarch64_linux_nat_target the_aarch64_linux_nat_target; @@ -1071,6 +1073,19 @@ aarch64_linux_nat_target::store_memtags (CORE_ADDR address, size_t len, return false; } +bool +aarch64_linux_nat_target::is_address_tagged (gdbarch *gdbarch, CORE_ADDR address) +{ + /* Here we take a detour going to linux-tdep layer to read the smaps file, + because currently there isn't a better way to get that information to + check if a given address is tagged or not. + + In the future, if this check is made, for instance, available via PTRACE, + it will be possible to drop the smaps path in favor of a PTRACE one for + this check. */ + return gdbarch_tagged_address_p (gdbarch, address); +} + void _initialize_aarch64_linux_nat (); void _initialize_aarch64_linux_nat () diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index fc60e602748..35979875907 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -2451,17 +2451,13 @@ aarch64_mte_get_atag (CORE_ADDR address) /* Implement the tagged_address_p gdbarch method. */ static bool -aarch64_linux_tagged_address_p (struct gdbarch *gdbarch, struct value *address) +aarch64_linux_tagged_address_p (struct gdbarch *gdbarch, CORE_ADDR address) { - gdb_assert (address != nullptr); - - CORE_ADDR addr = value_as_address (address); - /* Remove the top byte for the memory range check. */ - addr = gdbarch_remove_non_address_bits (gdbarch, addr); + address = gdbarch_remove_non_address_bits (gdbarch, address); /* Check if the page that contains ADDRESS is mapped with PROT_MTE. */ - if (!linux_address_in_memtag_page (addr)) + if (!linux_address_in_memtag_page (address)) return false; /* We have a valid tag in the top byte of the 64-bit address. */ diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index 456bfe971ff..cb149c36bc9 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -102,7 +102,7 @@ default_memtag_to_string (struct gdbarch *gdbarch, struct value *tag) /* See arch-utils.h */ bool -default_tagged_address_p (struct gdbarch *gdbarch, struct value *address) +default_tagged_address_p (struct gdbarch *gdbarch, CORE_ADDR address) { /* By default, assume the address is untagged. */ return false; diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h index 2dcd8f6dc53..467be40c688 100644 --- a/gdb/arch-utils.h +++ b/gdb/arch-utils.h @@ -141,7 +141,7 @@ extern std::string default_memtag_to_string (struct gdbarch *gdbarch, struct value *tag); /* Default implementation of gdbarch_tagged_address_p. */ -bool default_tagged_address_p (struct gdbarch *gdbarch, struct value *address); +bool default_tagged_address_p (struct gdbarch *gdbarch, CORE_ADDR address); /* Default implementation of gdbarch_memtag_matches_p. */ extern bool default_memtag_matches_p (struct gdbarch *gdbarch, diff --git a/gdb/corelow.c b/gdb/corelow.c index f4e8273d962..bdda742ef59 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -109,6 +109,10 @@ class core_target final : public process_stratum_target bool fetch_memtags (CORE_ADDR address, size_t len, gdb::byte_vector &tags, int type) override; + /* If the architecture supports it, check if ADDRESS is within a memory range + mapped with tags. For example, MTE tags for AArch64. */ + bool is_address_tagged (gdbarch *gdbarch, CORE_ADDR address) override; + x86_xsave_layout fetch_x86_xsave_layout () override; /* A few helpers. */ @@ -1410,6 +1414,12 @@ core_target::fetch_memtags (CORE_ADDR address, size_t len, return false; } +bool +core_target::is_address_tagged (gdbarch *gdbarch, CORE_ADDR address) +{ + return gdbarch_tagged_address_p (gdbarch, address); +} + /* Implementation of the "fetch_x86_xsave_layout" target_ops method. */ x86_xsave_layout diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index ebcff80bb9e..63fab26987f 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -707,8 +707,8 @@ extern void set_gdbarch_memtag_to_string (struct gdbarch *gdbarch, gdbarch_memta /* Return true if ADDRESS contains a tag and false otherwise. ADDRESS must be either a pointer or a reference type. */ -typedef bool (gdbarch_tagged_address_p_ftype) (struct gdbarch *gdbarch, struct value *address); -extern bool gdbarch_tagged_address_p (struct gdbarch *gdbarch, struct value *address); +typedef bool (gdbarch_tagged_address_p_ftype) (struct gdbarch *gdbarch, CORE_ADDR address); +extern bool gdbarch_tagged_address_p (struct gdbarch *gdbarch, CORE_ADDR address); extern void set_gdbarch_tagged_address_p (struct gdbarch *gdbarch, gdbarch_tagged_address_p_ftype *tagged_address_p); /* Return true if the tag from ADDRESS matches the memory tag for that diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 9319571deba..2d92f604c49 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -3232,7 +3232,7 @@ set_gdbarch_memtag_to_string (struct gdbarch *gdbarch, } bool -gdbarch_tagged_address_p (struct gdbarch *gdbarch, struct value *address) +gdbarch_tagged_address_p (struct gdbarch *gdbarch, CORE_ADDR address) { gdb_assert (gdbarch != NULL); gdb_assert (gdbarch->tagged_address_p != NULL); diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py index 7d913ade621..24e979431b6 100644 --- a/gdb/gdbarch_components.py +++ b/gdb/gdbarch_components.py @@ -1267,7 +1267,7 @@ must be either a pointer or a reference type. """, type="bool", name="tagged_address_p", - params=[("struct value *", "address")], + params=[("CORE_ADDR", "address")], predefault="default_tagged_address_p", invalid=False, ) diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 4edbd458e4d..c9689a29f74 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1132,7 +1132,7 @@ do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr) = value_from_ulongest (builtin_type (gdbarch)->builtin_data_ptr, tag_laddr); - if (gdbarch_tagged_address_p (gdbarch, v_addr)) + if (target_is_address_tagged (gdbarch, value_as_address (v_addr))) { /* Fetch the allocation tag. */ struct value *tag @@ -1268,7 +1268,7 @@ print_value (value *val, const value_print_options &opts) /* Returns true if memory tags should be validated. False otherwise. */ static bool -should_validate_memtags (struct value *value) +should_validate_memtags (gdbarch *gdbarch, struct value *value) { gdb_assert (value != nullptr && value->type () != nullptr); @@ -1289,7 +1289,7 @@ should_validate_memtags (struct value *value) return false; /* We do. Check whether it includes any tags. */ - return gdbarch_tagged_address_p (current_inferior ()->arch (), value); + return target_is_address_tagged (gdbarch, value_as_address (value)); } /* Helper for parsing arguments for print_command_1. */ @@ -1346,7 +1346,7 @@ print_command_1 (const char *args, int voidprint) { gdbarch *arch = current_inferior ()->arch (); - if (should_validate_memtags (val) + if (should_validate_memtags (arch, val) && !gdbarch_memtag_matches_p (arch, val)) { /* Fetch the logical tag. */ @@ -2946,9 +2946,10 @@ memory_tag_print_tag_command (const char *args, enum memtag_type tag_type) flag, it is no use trying to access/manipulate its allocation tag. It is OK to manipulate the logical tag though. */ + CORE_ADDR addr = value_as_address (val); if (tag_type == memtag_type::allocation - && !gdbarch_tagged_address_p (arch, val)) - show_addr_not_tagged (value_as_address (val)); + && !target_is_address_tagged (arch, addr)) + show_addr_not_tagged (addr); value *tag_value = gdbarch_get_memtag (arch, val, tag_type); std::string tag = gdbarch_memtag_to_string (arch, tag_value); @@ -3124,8 +3125,9 @@ memory_tag_set_allocation_tag_command (const char *args, int from_tty) /* If the address is not in a region memory-mapped with a memory tagging flag, it is no use trying to manipulate its allocation tag. */ - if (!gdbarch_tagged_address_p (current_inferior ()->arch (), val)) - show_addr_not_tagged (value_as_address (val)); + CORE_ADDR addr = value_as_address (val); + if (!target_is_address_tagged (current_inferior ()-> arch(), addr)) + show_addr_not_tagged (addr); if (!gdbarch_set_memtags (current_inferior ()->arch (), val, length, tags, memtag_type::allocation)) @@ -3152,12 +3154,12 @@ memory_tag_check_command (const char *args, int from_tty) struct value *val = process_print_command_args (args, &print_opts, true); gdbarch *arch = current_inferior ()->arch (); + CORE_ADDR addr = value_as_address (val); + /* If the address is not in a region memory mapped with a memory tagging flag, it is no use trying to access/manipulate its allocation tag. */ - if (!gdbarch_tagged_address_p (arch, val)) - show_addr_not_tagged (value_as_address (val)); - - CORE_ADDR addr = value_as_address (val); + if (!target_is_address_tagged (current_inferior ()->arch (), addr)) + show_addr_not_tagged (addr); /* Check if the tag is valid. */ if (!gdbarch_memtag_matches_p (arch, val)) diff --git a/gdb/remote.c b/gdb/remote.c index e278711df7b..9717db55e27 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1084,6 +1084,8 @@ class remote_target : public process_stratum_target bool store_memtags (CORE_ADDR address, size_t len, const gdb::byte_vector &tags, int type) override; + bool is_address_tagged (gdbarch *gdbarch, CORE_ADDR address) override; + public: /* Remote specific methods. */ void remote_download_command_source (int num, ULONGEST addr, @@ -15573,6 +15575,14 @@ remote_target::store_memtags (CORE_ADDR address, size_t len, return packet_check_result (rs->buf).status () == PACKET_OK; } +/* Implement the "is_address_tagged" target_ops method. */ + +bool +remote_target::is_address_tagged (gdbarch *gdbarch, CORE_ADDR address) +{ + return gdbarch_tagged_address_p (gdbarch, address); +} + /* Return true if remote target T is non-stop. */ bool diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index 59ea70458ad..e322bbbe481 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -197,6 +197,7 @@ struct dummy_target : public target_ops bool supports_memory_tagging () override; bool fetch_memtags (CORE_ADDR arg0, size_t arg1, gdb::byte_vector &arg2, int arg3) override; bool store_memtags (CORE_ADDR arg0, size_t arg1, const gdb::byte_vector &arg2, int arg3) override; + bool is_address_tagged (gdbarch *arg0, CORE_ADDR arg1) override; x86_xsave_layout fetch_x86_xsave_layout () override; }; @@ -373,6 +374,7 @@ struct debug_target : public target_ops bool supports_memory_tagging () override; bool fetch_memtags (CORE_ADDR arg0, size_t arg1, gdb::byte_vector &arg2, int arg3) override; bool store_memtags (CORE_ADDR arg0, size_t arg1, const gdb::byte_vector &arg2, int arg3) override; + bool is_address_tagged (gdbarch *arg0, CORE_ADDR arg1) override; x86_xsave_layout fetch_x86_xsave_layout () override; }; @@ -4562,6 +4564,34 @@ debug_target::store_memtags (CORE_ADDR arg0, size_t arg1, const gdb::byte_vector return result; } +bool +target_ops::is_address_tagged (gdbarch *arg0, CORE_ADDR arg1) +{ + return this->beneath ()->is_address_tagged (arg0, arg1); +} + +bool +dummy_target::is_address_tagged (gdbarch *arg0, CORE_ADDR arg1) +{ + tcomplain (); +} + +bool +debug_target::is_address_tagged (gdbarch *arg0, CORE_ADDR arg1) +{ + gdb_printf (gdb_stdlog, "-> %s->is_address_tagged (...)\n", this->beneath ()->shortname ()); + bool result + = this->beneath ()->is_address_tagged (arg0, arg1); + gdb_printf (gdb_stdlog, "<- %s->is_address_tagged (", this->beneath ()->shortname ()); + target_debug_print_gdbarch_p (arg0); + gdb_puts (", ", gdb_stdlog); + target_debug_print_CORE_ADDR (arg1); + gdb_puts (") = ", gdb_stdlog); + target_debug_print_bool (result); + gdb_puts ("\n", gdb_stdlog); + return result; +} + x86_xsave_layout target_ops::fetch_x86_xsave_layout () { diff --git a/gdb/target.c b/gdb/target.c index 107a84b3ca1..5c3c1a57dbd 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -796,6 +796,12 @@ target_store_memtags (CORE_ADDR address, size_t len, return current_inferior ()->top_target ()->store_memtags (address, len, tags, type); } +bool +target_is_address_tagged (gdbarch *gdbarch, CORE_ADDR address) +{ + return current_inferior ()->top_target ()->is_address_tagged (gdbarch, address); +} + x86_xsave_layout target_fetch_x86_xsave_layout () { diff --git a/gdb/target.h b/gdb/target.h index c9eaff16346..486a0a687b0 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -1334,6 +1334,10 @@ struct target_ops const gdb::byte_vector &tags, int type) TARGET_DEFAULT_NORETURN (tcomplain ()); + /* Returns true if ADDRESS is tagged, otherwise returns false. */ + virtual bool is_address_tagged (gdbarch *gdbarch, CORE_ADDR address) + TARGET_DEFAULT_NORETURN (tcomplain ()); + /* Return the x86 XSAVE extended state area layout. */ virtual x86_xsave_layout fetch_x86_xsave_layout () TARGET_DEFAULT_RETURN (x86_xsave_layout ()); @@ -2317,6 +2321,8 @@ extern bool target_fetch_memtags (CORE_ADDR address, size_t len, extern bool target_store_memtags (CORE_ADDR address, size_t len, const gdb::byte_vector &tags, int type); +extern bool target_is_address_tagged (gdbarch *gdbarch, CORE_ADDR address); + extern x86_xsave_layout target_fetch_x86_xsave_layout (); /* Command logging facility. */ From patchwork Tue Apr 16 14:07:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 88545 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ACC8B384640C for ; Tue, 16 Apr 2024 14:09:29 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id D5F793849AFA for ; Tue, 16 Apr 2024 14:07:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D5F793849AFA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D5F793849AFA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276487; cv=none; b=kIfjXYcuI2NxAwmArwTnHfc8IyaGD1Wh0Zg080YWUwFeu6uAK51+599+tlmd9jz8l2O4IdJWbNlqNQMmsBz+tc1wtWbbyWR37QjKLV5Io2NH5mF2TDP85GFG1otOw6HxnPpgNuaMyNz3dlThnls8fEtXo0HnEmm3bCtWl1leznE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276487; c=relaxed/simple; bh=9dATnzdtLBuIf7cSORFIle5NqSWdcLdnfiAuPirjwGc=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=LiDT7/0iZO88RIIXPlyamV7Vte9CP2U2jVaECyLT5DZr4vnI5iTvfVGY8DwP7hDfrW7zh/r3GcdD2qbPz+3XZE5P3vdBlLVg6TniTsyb2csuUb1pVQIId9IfOfdDVRGv2kKLEnA+t1v74teA4hjIZIUjH2M5cPVliOI46Kaw/l4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6ed9fc77bbfso3439273b3a.1 for ; Tue, 16 Apr 2024 07:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713276477; x=1713881277; darn=sourceware.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=IgkGCOXuapG92Mycu6x1TKV6pdZxvFEkfcXywD93fz4=; b=riITQXr5Zjk3HqNGE6a4QIJ9p6ioaeuxms4UqPCnsHki4r/y3r9zIxAXputp+W4b8M PSGGmsttyB+cHdhXXgHH2pnsAG5N5FNa6fiOGoNx7aEef4GvmMM+RpxL4LTZ2iQvO+fh CMLI3YoPWCEAVoQxrX0U0Ic7LvyshIWkFJIRQQCmGVJR4gAmzIk2PuDq5TQuFpcCOlUi bfSzsQsytXjwsjjiiys/JivCGHLyDvY1DP9Pc8zEOrBZnJNFg7GuHQPTDdqkHV8HtXJp gGrGAJ8jcxQa188PaN+/0rwELI3bi6hOMMAnwxXI2FQ/1Qyt2066VvIM+iDN6Fqm9Lkc 0lrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713276477; x=1713881277; 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=IgkGCOXuapG92Mycu6x1TKV6pdZxvFEkfcXywD93fz4=; b=CHyJ+CSy/XxGNE/79XQeP6l8QEOIXlSyhIZ3ER1ezs4adAF8x1HyBOsiG3sdJk3FJ4 igUrt6IuwtOuayXL4fbJRN+WyOlmJztGpXp/aEC9QdGSH/lJUj36qRpwjSL6bGdUI/V4 Zu8SeWXcCfDn1v0WIRRvZzaXkL0rAtY4H40Lkpjnxp2dr6Vgwt7QHzoybj5ExNboe7Lp m0xW5sfDK6TqchRoPhPTm0PAlfeYpzhT8D8R28rk6lM5lwT7RfLq5wlQGdGYjlKG/jnA hEn+r0UYM/5nEfZU3zd4KBAeT8ajoLNRfOKPcOr2dzwJMK9tZxW+SUQ3P2Ls9WylYzkN 10IA== X-Gm-Message-State: AOJu0Yz3krF75fAw2NnSs/MA3SYxiXK2+gNMTE+9dhx7ydTLh2mZws6X 6KwZ6OKg25G8U2Z5cbO+i4U4GmcD9A+zD2+rL9EdYMQcAsL32R3iU++txAgCZ0hNjV47uUiTXZI LZVs= X-Google-Smtp-Source: AGHT+IGQ+aJ3dznh/o0PwVEiWRcE6zEYr/jVTJIJJNSto4MHCpFgkGEmKAm0PkIMMXuOKyZItv3hag== X-Received: by 2002:a05:6a00:845:b0:6e7:e6b:2ead with SMTP id q5-20020a056a00084500b006e70e6b2eadmr15250278pfk.28.1713276476327; Tue, 16 Apr 2024 07:07:56 -0700 (PDT) Received: from amd.. ([2804:7f0:b403:ad57:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id o3-20020a63e343000000b005f3d54c0a57sm8937473pgj.49.2024.04.16.07.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 07:07:56 -0700 (PDT) From: Gustavo Romero To: gdb-patches@sourceware.org Cc: luis.machado@arm.com, thiago.bauermann@linaro.org, eliz@gnu.org, tom@tromey.com, gustavo.romero@linaro.org Subject: [PATCH v4 6/8] gdb: Add qIsAddressTagged packet Date: Tue, 16 Apr 2024 14:07:26 +0000 Message-Id: <20240416140728.198163-7-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416140728.198163-1-gustavo.romero@linaro.org> References: <20240416140728.198163-1-gustavo.romero@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This commit adds a new packet, qIsAddressTagged, allowing GDB remote targets to use it to query the stub if a given address is tagged. Currently, the memory tagging address check is done via a read query, where the contents of /proc//smaps is read and the flags are inspected for memory tagging-related flags that indicate the address is in a memory tagged region. This is not ideal, for example, for QEMU stub and other cases, such as on bare-metal, where there is no notion of an OS file like 'smaps.' Hence, the introduction of qIsAddressTagged packet allows checking if an address is tagged in an agnostic way. The is_address_tagged target hook in remote.c attempts to use the qIsAddressTagged packet first for checking if an address is tagged and if the stub does not support such a packet (reply is empty) it falls back to using the current mechanism that reads the contents of /proc//smaps via vFile requests. Signed-off-by: Gustavo Romero --- gdb/remote.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/gdb/remote.c b/gdb/remote.c index 9717db55e27..63799ac5e3f 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -15534,6 +15534,40 @@ create_store_memtags_request (gdb::char_vector &packet, CORE_ADDR address, strcpy (packet.data (), request.c_str ()); } +static void +create_is_address_tagged_request (gdbarch *gdbarch, gdb::char_vector &packet, + CORE_ADDR address) +{ + int addr_size; + std::string request; + + addr_size = gdbarch_addr_bit (gdbarch) / 8; + request = string_printf ("qIsAddressTagged:%s", phex_nz (address, addr_size)); + + if (packet.size () < request.length () + 1) + error (_("Contents too big for packet qIsAddressTagged.")); + + strcpy (packet.data (), request.c_str ()); +} + +static bool +check_is_address_tagged_reply (gdb::char_vector &packet, bool *tagged) +{ + if (packet_check_result (packet).status () != PACKET_OK) + return false; + + gdb_byte reply; + /* Convert only 2 hex digits, i.e. 1 byte in hex format. */ + hex2bin (packet.data (), &reply, 1); + + if (reply == 0x00 || reply == 0x01) { + *tagged = !!reply; + return true; + } + + return false; +} + /* Implement the "fetch_memtags" target_ops method. */ bool @@ -15580,6 +15614,21 @@ remote_target::store_memtags (CORE_ADDR address, size_t len, bool remote_target::is_address_tagged (gdbarch *gdbarch, CORE_ADDR address) { + struct remote_state *rs = get_remote_state (); + bool is_addr_tagged; + + /* Firstly, attempt to check the address using the qIsAddressTagged + packet. */ + create_is_address_tagged_request (gdbarch, rs->buf, address); + + putpkt (rs->buf); + getpkt (&rs->buf); + + if (check_is_address_tagged_reply (rs->buf, &is_addr_tagged)) + return is_addr_tagged; + + /* Fallback to arch-specific method of checking whether an address is tagged + if qIsAddressTagged fails. */ return gdbarch_tagged_address_p (gdbarch, address); } From patchwork Tue Apr 16 14:07:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 88546 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AEFDF3846424 for ; Tue, 16 Apr 2024 14:09:33 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 525FA3858C78 for ; Tue, 16 Apr 2024 14:08:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 525FA3858C78 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 525FA3858C78 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276487; cv=none; b=JCQpvdyZI6vzwBwoqkbYBPC0ux5TqrtSvfptk0L+4hTq32z2/HoOurbNpcfk10m4evYT1bgPOqXeu+ml8SFIQmC926622ae7t7wAhLBdctdIRzkuVZJhBM7NRuLKchqHKBmYTQIu6lWVk+TWdT1vqVsvCys1vBBGGsyTtsMBJPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276487; c=relaxed/simple; bh=5JUNK7JchaPtTy/5e/gDv204PBOvA9bZ2y/G1rG+BjE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=I0wafVUjeAIN6DkwNiS7LwbVQb9jvjIeEHkIUSOP8WPhkxtiGZ2vjguHYLRzEB6LVhqwxSbiifNzcrk3BjrszmfkXHIJsg8H5pOGlwbOnNt1NwEA3yB3oW2Q36icYDaPE/6a0dp4YvkVWOejchNbG3kbvy5QlWWCqWIOjJ2K9rY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6ed0e9ccca1so4046574b3a.0 for ; Tue, 16 Apr 2024 07:08:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713276479; x=1713881279; darn=sourceware.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=NIecbHfd61PBTmQ06xkZ27ONlrNYswqO8NJqiIAjj3Q=; b=KzhTpixFzQmo5Hri7y8aqI7gtIdfHNcCbhwDn7p9xeTWbBfd1PE+JO3Bj5vg9ORtjE GPULT4A+sTKhoLaUnUN0AUbZJYpV5cfUHCyCt/cA9PEuIBUyoOd5zDBGuWFJ864fTnRc Pz5JYgSFy/Jk4DbA+qTNV0sUlhNdKdi8Br+SyhKUmKlLRtc1AP+GrojlxCiZF7g3b81V XHVDJBypMSmU6J35LvgIxlsFBIbG/CNUCPf9Ufs02HpMqRf4Q6JdCgWoBQ0q3T3Q2PVb iuhgQtY0RHL04rX4f81MuWrDlM8SJrYU2jGALqDf8LapgBYi6NjGTJ+A/b18UndF3Vgn D+ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713276479; x=1713881279; 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=NIecbHfd61PBTmQ06xkZ27ONlrNYswqO8NJqiIAjj3Q=; b=XfkJWOFDldrJuxuUISnFjbdP9onXIWA6db8It15Frx7VtFRhK6JoWIUPAnIqPQ1rjZ GghIgZjZVzJt0mln7pp6DOd7U8k1wmF2jGqXUjrafi5lVPeGLFWcIyIf1YL4nCQAt/6/ hwDBRBQNc0WdytcLhQIFU9mS9JX8XmxbnOsNkEjUaK/Cjj9ada9pYNIbepAEfKoSUxQl gN6ZA4fh7iKOYRmD3s7gzywFPDAwQ3azZxg8hWoS2pInZu0Gr1fXANnoT53uSMAwvLX0 lvP+YTc9Ro3irubFmcpo9eSHRJP+Ye7aJ1OuijUCzBThfQuAPrIT8eYYDTpwmFpA1Bw3 1LIA== X-Gm-Message-State: AOJu0YzLt8SXq3GEZD6CrneX6F/+fTwtyNOsMaRyH43cmKA2lCh4NH/w qHITXnkBFK72v5GbgzzkiTCSvZFopNs8QX+2bnYBf+B3EvbsYpxQu0k7G+8RraGpXnHpxduG5yo LGp4= X-Google-Smtp-Source: AGHT+IF5AlyQCyHJjyrt1/kH7x2FN+XvoK/jyDuHEtiKHyFWWU2oHeiAyxuEqxDDiQTIwgw+dgyCJA== X-Received: by 2002:a05:6a21:35c2:b0:1a7:a564:14db with SMTP id ba2-20020a056a2135c200b001a7a56414dbmr11693441pzc.24.1713276478578; Tue, 16 Apr 2024 07:07:58 -0700 (PDT) Received: from amd.. ([2804:7f0:b403:ad57:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id o3-20020a63e343000000b005f3d54c0a57sm8937473pgj.49.2024.04.16.07.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 07:07:58 -0700 (PDT) From: Gustavo Romero To: gdb-patches@sourceware.org Cc: luis.machado@arm.com, thiago.bauermann@linaro.org, eliz@gnu.org, tom@tromey.com, gustavo.romero@linaro.org Subject: [PATCH v4 7/8] gdb/testsuite: Add unittest for qIsAddressTagged packet Date: Tue, 16 Apr 2024 14:07:27 +0000 Message-Id: <20240416140728.198163-8-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416140728.198163-1-gustavo.romero@linaro.org> References: <20240416140728.198163-1-gustavo.romero@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Add unittests for testing qIsAddressTagged packet request creation and reply checks. Signed-off-by: Gustavo Romero --- gdb/remote.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/gdb/remote.c b/gdb/remote.c index 63799ac5e3f..42f34a03c95 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -15658,6 +15658,8 @@ test_memory_tagging_functions () scoped_restore restore_memtag_support_ = make_scoped_restore (&config->support); + struct gdbarch *gdbarch = current_inferior ()->arch (); + /* Test memory tagging packet support. */ config->support = PACKET_SUPPORT_UNKNOWN; SELF_CHECK (remote.supports_memory_tagging () == false); @@ -15724,6 +15726,46 @@ test_memory_tagging_functions () create_store_memtags_request (packet, 0xdeadbeef, 255, 1, tags); SELF_CHECK (memcmp (packet.data (), expected.c_str (), expected.length ()) == 0); + + /* Test creating a qIsAddressTagged request. */ + expected = "qIsAddressTagged:deadbeef"; + create_is_address_tagged_request (gdbarch, packet, 0xdeadbeef); + SELF_CHECK (strcmp (packet.data (), expected.c_str ()) == 0); + + /* Test empty reply on qIsAddressTagged request. */ + reply = "E00"; + /* is_tagged must not changed, hence it's tested too. */ + bool is_tagged = false; + strcpy (packet.data (), reply.c_str ()); + SELF_CHECK (check_is_address_tagged_reply (packet, &is_tagged) == false); + SELF_CHECK (is_tagged == false); + + /* Test if only the first byte (01) is correctly extracted from a long + numerical reply, with remaining garbage. */ + reply = "0104A590001234006mC0fe"; + /* Because the first byte is 01, is_tagged should be set to true. */ + is_tagged = false; + strcpy (packet.data (), reply.c_str ()); + SELF_CHECK (check_is_address_tagged_reply (packet, &is_tagged) == true); + SELF_CHECK (is_tagged == true); + + /* Test if only the first byte (00) is correctly extracted from a long + numerical reply, with remaining garbage. */ + reply = "0004A590001234006mC0fe"; + /* Because the first byte is 00, is_tagged should be set to false. */ + is_tagged = true; + strcpy (packet.data (), reply.c_str ()); + SELF_CHECK (check_is_address_tagged_reply (packet, &is_tagged) == true); + SELF_CHECK (is_tagged == false); + + /* Test if only the first byte, 04, is correctly extracted and recognized + as invalid (only 00 and 01 are valid replies). */ + reply = "0404A590001234006mC0fe"; + /* Because the first byte is invalid is_tagged must not change. */ + is_tagged = false; + strcpy (packet.data (), reply.c_str ()); + SELF_CHECK (check_is_address_tagged_reply (packet, &is_tagged) == false); + SELF_CHECK (is_tagged == false); } static void From patchwork Tue Apr 16 14:07:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 88548 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0AB0C3858CDA for ; Tue, 16 Apr 2024 14:09:58 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 4381E3858431 for ; Tue, 16 Apr 2024 14:08:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4381E3858431 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4381E3858431 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276495; cv=none; b=BjgTNInB51tZMYavJ7jQzk657h9G9J4Jh/AeINXtL6byUlT6xbiNbhVlZdULUvqB/ESZiMgwJT+XYizQd+qIE28UjzMlU6HL+I5ZJIH4e71QVbk9b85AmCyfFxmC85QzH3ega9PjIZqtnNw1U7oq6BJIMIuXoKqintXpbAgm910= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276495; c=relaxed/simple; bh=uX7XlHxVf0V1WMrVHD1NCj+jz5ubqQflYFbXbd+PMaQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=aTw/DuUJ+uUoxaUYws2QigN82oSStYsvweI3KXcJPduvd1fjBsOr9Q2hjLrXSPRCoIZ8DepSj/6FMH15X2tG+C2kGro6a9yz1/+4nmtpNJLI//PdhcZuoHHCHlE2KDpHcWM1b8+xaf7fyLz9bF2bE0/NLTB71+/5CdKYGHdPlCk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6ee12766586so2928792b3a.0 for ; Tue, 16 Apr 2024 07:08:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713276481; x=1713881281; darn=sourceware.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=TySCtsAV9w2OFUsPqDtQ4yT0bercISlHKAJQghi98fU=; b=P2iwK47dYWVDxK1VHobPzCcHYA6eKPKn0m+/pDnOJVp86eETHmehVZvP5y+YK0JoCz pOd1fan35zSy+IueN8vM8AgdnIx+FyKlsDsFwPM+pO0JkFYEhVW87NrHdEG0kARPk9a0 f0pkcem/iEQIrrDUUyIulLvo31eDf6sfRQKbXuN0A0cQKagVmLCox9SWKZA6IX1vHgiO M1iCV/LQQNqgPQxvyUAomKoGEyZW0qSumTG+fjVwj6PrAfGESKf/iuW8NZ5ek8pD4W/s zhq9Zo9MFO8ifh5vLDxvMQ1NWILyFHVmyMGFN53SVSWVT3XNkXBJSUZld8UGEQzjQLFU l3Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713276481; x=1713881281; 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=TySCtsAV9w2OFUsPqDtQ4yT0bercISlHKAJQghi98fU=; b=jdTOVmZowjERqhAFos54gq6SwpLIf7+k485TxInWIlY1NBjRbsNlkEZZ8apwnmzrB0 dj0UcBsuGNbSwhK+TgFnTeL6L42Kox5NVNSt07nvuOa/YvkuxbSdvBnunNyTAC4gpL1p WAQgW9Up3xrJ4oQ60ZIxJQnFaSw1Mc3pQOgwCMSnYJvnd1KmmVjdHsXlQC4SJAlel6L8 34Bw4AdP/BlZjg0hKU7an+nUi5CJ9VMAkwdyRRfioYywJ8JX5Zq5X7Fb0pyQ6YrC5bj1 EIywP/JrRGigU6L4WdrK8znnIf0K+67gs/2Vk4k0Fg8k7VURRU11wCTlocOEd2mOnG58 Tqtg== X-Gm-Message-State: AOJu0YxDA9+PKol1SHabW6xpQ4C2rhNEm3TMm9Kcqme2t6s0G/7yk6pz 2TU5Wi1zJDxAVQSzMflBCZP9spVUVocfKIQwHU8aEOGx+lfcoF3sQ261433wGQqODnBL2v5P5wv ET5w= X-Google-Smtp-Source: AGHT+IFezyAQbeugK7rq6pHS5fAuE/PQxylzooV5ZBOLOEgbg8HRLSVyQjircaBzw0yassmNfnJpMQ== X-Received: by 2002:a05:6a20:3d86:b0:1aa:3ee3:8d5d with SMTP id s6-20020a056a203d8600b001aa3ee38d5dmr3101796pzi.14.1713276480816; Tue, 16 Apr 2024 07:08:00 -0700 (PDT) Received: from amd.. ([2804:7f0:b403:ad57:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id o3-20020a63e343000000b005f3d54c0a57sm8937473pgj.49.2024.04.16.07.07.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 07:08:00 -0700 (PDT) From: Gustavo Romero To: gdb-patches@sourceware.org Cc: luis.machado@arm.com, thiago.bauermann@linaro.org, eliz@gnu.org, tom@tromey.com, gustavo.romero@linaro.org Subject: [PATCH v4 8/8] gdb: Document qIsAddressTagged packet Date: Tue, 16 Apr 2024 14:07:28 +0000 Message-Id: <20240416140728.198163-9-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416140728.198163-1-gustavo.romero@linaro.org> References: <20240416140728.198163-1-gustavo.romero@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This commit documents the qIsAddressTagged packet. Signed-off-by: Gustavo Romero Reviewed-by: Eli Zaretskii Reviewed-By: Eli Zaretskii --- gdb/NEWS | 10 ++++++++++ gdb/doc/gdb.texinfo | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index feb3a37393a..1693a7a15f8 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -192,6 +192,16 @@ QThreadOptions in qSupported QThreadOptions packet, and the qSupported response can contain the set of thread options the remote stub supports. +qIsAddressTagged + This new packet allows GDB to query the stub about a given address to check + if it is tagged or not. Many memory tagging-related GDB commands need to + perform this check before they read/write the allocation tag related to an + address. Currently, however, this is done through a 'vFile' request to read + the file /proc//smaps and check if the address is in a region reported + as memory tagged. Since not all targets have a notion of what the smaps + file is about, this new packet provides a more generic way to perform such + a check. + *** Changes in GDB 14 * GDB now supports the AArch64 Scalable Matrix Extension 2 (SME2), which diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 82a617e9ad3..cb6033bbbee 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -44093,6 +44093,35 @@ although this should not happen given @value{GDBN} will only send this packet if the stub has advertised support for memory tagging via @samp{qSupported}. @end table +@item qIsAddressTagged:@var{address} +@cindex check if a given address is in a memory tagged region. +@cindex @samp{qIsAddressTagged} packet +@anchor {qIsAddressTagged} +Check if address @var{address} is in a memory tagged region; if it is, it's +said to be tagged. The target is responsible for checking it, as this is +architecture-specific. + +@var{address} is the address to be checked. + +Reply: +@table @samp +Replies to this packet should all be in two hex digit format, as follows: + +@item @var{01} +Address @var{address} is tagged. + +@item @var{00} +Address @var{address} is not tagged. + +@item E @var{nn} +An error occurred. This means that address could not be checked for some +reason. + +@item @w{} +An empty reply indicates that @samp{qIsAddressTagged} is not supported by the +stub. +@end table + @item QMemTags:@var{start address},@var{length}:@var{type}:@var{tag bytes} @anchor{QMemTags} @cindex store memory tags @@ -45141,9 +45170,11 @@ The remote stub supports and implements the required memory tagging functionality and understands the @samp{qMemTags} (@pxref{qMemTags}) and @samp{QMemTags} (@pxref{QMemTags}) packets. -For AArch64 GNU/Linux systems, this feature also requires access to the -@file{/proc/@var{pid}/smaps} file so memory mapping page flags can be inspected. -This is done via the @samp{vFile} requests. +For AArch64 GNU/Linux systems, this feature can require access to the +@file{/proc/@var{pid}/smaps} file so memory mapping page flags can be +inspected, if @samp{qIsAddressTagged} (@pxref{qIsAddressTagged}) packet +is not supported by the stub. Access to the @file{/proc/@var{pid}/smaps} +file is done via @samp{vFile} requests. @end table