From patchwork Thu Apr 4 06:48:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Romero X-Patchwork-Id: 785812 Delivered-To: patch@linaro.org Received: by 2002:adf:f001:0:b0:33e:7753:30bd with SMTP id j1csp684736wro; Wed, 3 Apr 2024 23:49:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWbIbTattTpxuFhfajxMWUToeLSWU9MRu2c7fDAsWPalGAyuL7ztgME8DYxB1ugw6IJJGUPHYqeHmWyUnpvhExO X-Google-Smtp-Source: AGHT+IF+fCy7V3gSxJG1hCXJPy+XzErwO6mEFLeU1/vEBmWzAIjUdTaar7GimqGlb15/8YeUNdPv X-Received: by 2002:a05:620a:5dc2:b0:78c:79ff:ded8 with SMTP id xy2-20020a05620a5dc200b0078c79ffded8mr1524113qkn.53.1712213396013; Wed, 03 Apr 2024 23:49:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712213396; cv=pass; d=google.com; s=arc-20160816; b=YxOnIKdVdQOPIhXy9otGY+jNE0jTvLS52fOj69bLCcnivozYDExqZENmQAw3HTIbHq lPBUJ3YDgeAjsCLA91e8i4yZmRTmwKrlaF3bOx6DsgZ1K2MRX+vxXZWrQQqw3of7brjV /3MEWwuiD9+kRZ6nM2hgIaDEYdln4+adk4my9a9DCtX5/Tnsv7Uoqf42g9h8LwZ1MdAM Qr9T5aS18DbyhKNvvdKpR89GbMswtbuNg6T1k6slKCAGqFEayAyEW2XmWNMXrvlTR5XJ IE9AbUtH/XVg8B/MrSwAIhomKecWPkBnJl9W5cpCgTpElf0jrTqVQsk5vs+BsUxs4uxQ 7LSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=y5RxHf8Te57ZG0LVVGGa3lEh2+B6GPPEi9wprQMp6Zg=; fh=ip7+QkkM488k9wyzFaZPu3h7BUQARzj44zdeG2KNIXU=; b=OTHE0ydBsAP74xYf+/GXiocqp8cTtSlrnjhNYJFvKfmWr+gqOl1vvz+cwRHExT9YjK jakpLo70zUmirbXh+1CDqMphBRGmfHtRcYZIWVZ1G/mwsgaI9D4J0QfbrFD6bM+9Rdeq yIvsAsMD6lDTX2L1leHyiCHoMrk2t1Bl2mZcH6kg2gCnUTJVxvGE0ZJQQfemVT2EjF4Z YurNzylrQ1K7pUs1KmQhME+Cn4PKZORoC/TCjDLZFWrc6fslI5lwNKSbIgQDyEmkqlSd DK10CrhvhDVtLny639c51XtxX8EJ9vY1+Oy+gvtz+HgQP67BNQKHX0Hrnd2KSvF8Lu+4 tXNg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wOFgm2Qh; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e19-20020a05620a209300b00789e55e913bsi16249699qka.252.2024.04.03.23.49.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 23:49:55 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wOFgm2Qh; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A0D85384646C for ; Thu, 4 Apr 2024 06:49:55 +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 314E73858431 for ; Thu, 4 Apr 2024 06:48:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 314E73858431 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 314E73858431 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=1712213340; cv=none; b=qcO3d4a/0yEO/1AE0wItjROt0cuyUDfha34W9acjDsnTDdK4sEFy1+qZcUPdPFA30r8fDFiaLv6z7rbrkjdR/Mn2v0BNJusfziCvUCg5ak8SbORJ8JzZBIJHlYMXQZ94bqVOeVI/B1M3WtTbR9ZvBdjA9iAQg6FXEPtK4+e8Rh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712213340; c=relaxed/simple; bh=GkPm58lENjYBRJ/Pccx/Ww0JCKlD9pYQWA6CfG5H0I8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=tyURkoJZx5DzDSqDJ2wLRsgxE0flNERGh/CEY64maBAb7KOfVK2HYkEtCkL4F9DByglDFj4A29gAwu2twQl5qsPKuy3VOvhLSqahSn1tO2fL3GMuePnZ5IVriZk5ePfxa6UfBtYftF4K4BelGTRiwwdTPtW0NpuVNBBfoXgt7HQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6e6fb9a494aso581899b3a.0 for ; Wed, 03 Apr 2024 23:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712213335; x=1712818135; 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=y5RxHf8Te57ZG0LVVGGa3lEh2+B6GPPEi9wprQMp6Zg=; b=wOFgm2QhIJz8luPDa9QcoluhksY10QbVbYuPtC+9uqJc1A+u+/5PHbym7OsUwo8nC+ AdqtkmUNqSItyq+JIamNZH9ug4DuaGpMhdrFiu8obppjlUW8AWSNR0OpxFiiPn3GhsTh ImpciKU9QzBiF3Fm8Bv3dF9fBi4xjMgRG5EvBonD9ky0n8HmvPh0M2Ac4hQeqHst/yKF OAaFGyajVp7qRp3bITiCfELAXESgjvw39vFkMiCo4+p77nXZ2NJ5RZeLJOOpA97x4U4q Np6iOeDD2kUWwCdh+zXH6c3zjUJaL4bp2Cgpbt7t5YjYWNbGfhEqLE8sM0Reywm6PGEj Ulbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712213335; x=1712818135; 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=y5RxHf8Te57ZG0LVVGGa3lEh2+B6GPPEi9wprQMp6Zg=; b=SG064VbXHYUvLBRhiOENq5RG+f6789gpPi6cSjYFv/HLfGyaCWaTnEd7+GD9VC2FMf DYswQbkQQFuEg+IFWrif+tInnpKKvdBVaXW7Z+GPJ+g4zlL4ioCfPi9dN8CB15QKJZQx wO8oYQXQPK5GFp6k2QVq5eTGmcPJ4q+kUvmNev5eGTU1RlWpbGqymtRTyFaGxGNCjYG4 uMb9zC9cD8UvsjbvmdTpNUhFCnz8kIiB42BqAcA/vrZqHyqaK6GHe7HsAdNs1xGbvTuT eWiBVAakN1V4fJTC/l4kgv8eMnPCIIjCyNVr2QLtSCw/cOj3RH5JdLF1zBmUxYgrfqm0 6DZQ== X-Gm-Message-State: AOJu0Yx4YJtCoBTxR6s0UOrzC0ZsUbArFU522pgNqNYyug0EuCGDPG0J D7FQtbZs2Ay88SFmop8KQkIMw/HmA7u8m83CcfHR/2IsXZUUDuqLfX9xZiBQx+gQMXWfLGCoLeF K X-Received: by 2002:a05:6a00:6902:b0:6ec:f094:753b with SMTP id hs2-20020a056a00690200b006ecf094753bmr370722pfb.24.1712213334579; Wed, 03 Apr 2024 23:48:54 -0700 (PDT) Received: from amd.. ([2804:7f0:b402:d0dc:3e7c:3fff:fe7a:e83b]) by smtp.gmail.com with ESMTPSA id n16-20020aa79850000000b006e64ddfa71asm13218899pfq.170.2024.04.03.23.48.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 23:48:54 -0700 (PDT) From: Gustavo Romero To: gdb-patches@sourceware.org Cc: luis.machado@arm.com, thiago.bauermann@linaro.org, gustavo.romero@linaro.org Subject: [PATCH v3 5/7] gdb: Introduce is_address_tagged target hook Date: Thu, 4 Apr 2024 06:48:17 +0000 Message-Id: <20240404064819.2848899-6-gustavo.romero@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240404064819.2848899-1-gustavo.romero@linaro.org> References: <20240404064819.2848899-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+patch=linaro.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 allows the memory tagging address checking to be specialized easily per target in the future. Since target_is_address_tagged continues to use the gdbarch_tagged_address_p hook there is no change in behavior for the targets using the new target hook (the remote.c, aarch64-linux-nat.c, and corelow.c targets). 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 --- gdb/aarch64-linux-nat.c | 8 ++++++++ gdb/aarch64-linux-tdep.c | 10 ++++------ gdb/arch-utils.c | 2 +- gdb/arch-utils.h | 2 +- gdb/corelow.c | 8 ++++++++ gdb/gdbarch-gen.h | 4 ++-- gdb/gdbarch.c | 2 +- gdb/gdbarch_components.py | 2 +- gdb/printcmd.c | 31 +++++++++++++++++-------------- gdb/remote.c | 10 ++++++++++ gdb/target-delegates.c | 30 ++++++++++++++++++++++++++++++ gdb/target.c | 6 ++++++ gdb/target.h | 6 ++++++ 13 files changed, 95 insertions(+), 26 deletions(-) diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index 3face34ce79..19c099832a5 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,12 @@ 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) +{ + 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..2a47c3f0845 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -2451,17 +2451,15 @@ 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); + gdb_assert (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..b13d0124471 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -109,6 +109,8 @@ class core_target final : public process_stratum_target bool fetch_memtags (CORE_ADDR address, size_t len, gdb::byte_vector &tags, int type) override; + bool is_address_tagged (gdbarch *gdbarch, CORE_ADDR address) override; + x86_xsave_layout fetch_x86_xsave_layout () override; /* A few helpers. */ @@ -1410,6 +1412,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 62fbcb98cfb..24eac7c8421 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); @@ -3104,8 +3105,9 @@ parse_set_allocation_tag_input (const char *args, struct value **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 (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); } /* Implement the "memory-tag set-allocation-tag" command. @@ -3129,8 +3131,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)) @@ -3157,12 +3160,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. */