From patchwork Fri Dec 1 16:27:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 81134 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 600963860C0B for ; Fri, 1 Dec 2023 16:28:09 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id B8EB5385AE43 for ; Fri, 1 Dec 2023 16:27:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B8EB5385AE43 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B8EB5385AE43 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701448076; cv=none; b=K3uugBRaTSdSr8a//LyEBHh81yxosc21oNQ7a2CqFMGoFLM0EQTEhKtdBI8Iz+gH5qocG+pVbWT+cSfDBva6Z2xqry4WbyyplLA0F6P2htAfBvr3i+nbeLfWM19WeJ6yo2s58cmdvpnC92+TEcNJQyhv766cJZpJ3KxSOUfu7xI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701448076; c=relaxed/simple; bh=spuC8vhQgZpJBPyror/PrWsTQXfb4UhG+AgpuUkz7+g=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=NuqHLfO0jXsTah5rfMFt2+RcAKPxIlY6qN6oUUusJcoXzrlVycqsaGpKxfQMa4smcPt5AlZJny5o7Gf/W48HMn7/rckObgKP2m+ZwyOz7ynpB7kS7BgcrbcgAhDao6LrYQfeImPPQOD29IWxv8dKJavnJ80bLcMownjDyEpPKso= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smarchi-efficios.internal.efficios.com (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 20D821E11B; Fri, 1 Dec 2023 11:27:54 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Luis Machado , John Baldwin , "Aktemur, Tankut Baris" , Simon Marchi , John Baldwin Subject: [PATCH 03/24] gdb: make store_integer take an array_view Date: Fri, 1 Dec 2023 11:27:16 -0500 Message-ID: <20231201162751.741751-4-simon.marchi@efficios.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231201162751.741751-1-simon.marchi@efficios.com> References: <20231201162751.741751-1-simon.marchi@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3496.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE 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 New in v3: - Fix type of store_unsigned_integer parameter, LONGEST -> ULONGEST Change store_integer, store_signed_integer and store_unsigned_integer to accept an array_view. Add some backwards compatibility overloads to avoid changing all callers at once. Change-Id: Ibb1381228ab1cb65fc7e2e4b92cf9ab1047cdc03 Reviewed-By: John Baldwin --- gdb/defs.h | 39 +++++++++++++++++++++++++++++++-------- gdb/findvar.c | 16 +++++++--------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/gdb/defs.h b/gdb/defs.h index bcce4f4c3e43..e20143b8146a 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -495,21 +495,44 @@ extern CORE_ADDR extract_typed_address (const gdb_byte *buf, target-format integer at ADDR which is LEN bytes long. */ template> -extern void store_integer (gdb_byte *addr, int len, enum bfd_endian byte_order, - T val); +extern void store_integer (gdb::array_view dst, + bfd_endian byte_order, T val); + +template +static inline void +store_integer (gdb_byte *addr, int len, bfd_endian byte_order, T val) +{ + return store_integer (gdb::make_array_view (addr, len), byte_order, val); +} + +static inline void +store_signed_integer (gdb::array_view dst, bfd_endian byte_order, + LONGEST val) +{ + return store_integer (dst, byte_order, val); +} + +static inline void +store_signed_integer (gdb_byte *addr, int len, bfd_endian byte_order, + LONGEST val) +{ + return store_signed_integer (gdb::make_array_view (addr, len), byte_order, + val); +} static inline void -store_signed_integer (gdb_byte *addr, int len, - enum bfd_endian byte_order, LONGEST val) +store_unsigned_integer (gdb::array_view dst, bfd_endian byte_order, + ULONGEST val) { - return store_integer (addr, len, byte_order, val); + return store_integer (dst, byte_order, val); } static inline void -store_unsigned_integer (gdb_byte *addr, int len, - enum bfd_endian byte_order, ULONGEST val) +store_unsigned_integer (gdb_byte *addr, int len, bfd_endian byte_order, + ULONGEST val) { - return store_integer (addr, len, byte_order, val); + return store_unsigned_integer (gdb::make_array_view (addr, len), byte_order, + val); } extern void store_typed_address (gdb_byte *buf, struct type *type, diff --git a/gdb/findvar.c b/gdb/findvar.c index 952ec20c0b73..c7a681f8a890 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -159,12 +159,12 @@ extract_typed_address (const gdb_byte *buf, struct type *type) target-format integer at ADDR which is LEN bytes long. */ template void -store_integer (gdb_byte *addr, int len, enum bfd_endian byte_order, +store_integer (gdb::array_view dst, enum bfd_endian byte_order, T val) { gdb_byte *p; - gdb_byte *startaddr = addr; - gdb_byte *endaddr = startaddr + len; + gdb_byte *startaddr = dst.data (); + gdb_byte *endaddr = startaddr + dst.size (); /* Start at the least significant end of the integer, and work towards the most significant. */ @@ -187,13 +187,11 @@ store_integer (gdb_byte *addr, int len, enum bfd_endian byte_order, } /* Explicit instantiations. */ -template void store_integer (gdb_byte *addr, int len, - enum bfd_endian byte_order, - LONGEST val); +template void store_integer (gdb::array_view dst, + bfd_endian byte_order, LONGEST val); -template void store_integer (gdb_byte *addr, int len, - enum bfd_endian byte_order, - ULONGEST val); +template void store_integer (gdb::array_view dst, + bfd_endian byte_order, ULONGEST val); /* Store the address ADDR as a pointer of type TYPE at BUF, in target form. */