From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iXKkJK11fGpIlCAAWB0awg (envelope-from ) for ; Wed, 12 Aug 2026 09:31:25 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=iIx3C02m; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8C74D1E09E; Wed, 12 Aug 2026 09:31:25 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 ESMTPS id 2B4A71E09E for ; Wed, 12 Aug 2026 09:31:24 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 663814B97004 for ; Wed, 12 Aug 2026 13:31:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 663814B97004 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=iIx3C02m Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by sourceware.org (Postfix) with ESMTPS id 7A5674BB24DF for ; Wed, 12 Aug 2026 13:28:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A5674BB24DF Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7A5674BB24DF Authentication-Results: sourceware.org; arc=none smtp.remote-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786541314; cv=none; b=tT4VbswmpcPG3ef5NEYYehFEQNucHWhgEf77QWtBnti5cTV5g7OwC5okpO0zs3yR8ibKruBLQDUpRMPdLG2JXUa53y7VB1FnG2S7L25GEgcsTdDgFwYIMcJZ8OkqH75jQGX3uq+xIj+9vU4x+pPNMdvgmvdQp1G8KDh68zDj9oA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786541314; c=relaxed/simple; bh=Io8WOuMB685oQytGNw39ljZhiQ7Z3MPQEuszUdZuoxo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xay54Zdyg6kjN91ruy/f7of6xlOo2fw7Mx9XYxLDGkLxC0H/l0iGnViNOgKHZ9qdrzqlqIm2uhDKdg9yZe0No3sl2/OZtgk6uMhfh21t0Iurj5je+eLNmoHnqTpbVlFISc44poDOx4YxIGcqCyJoqFiZryvVF+NljyhMU4RVbXY= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=iIx3C02m DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A5674BB24DF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1786541315; x=1818077315; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Io8WOuMB685oQytGNw39ljZhiQ7Z3MPQEuszUdZuoxo=; b=iIx3C02mPVSizLV6WkbHEgeoBCkK5qmlFGIdGWGMdlSSwb0+sHMyjI3L YVBwkNoQyQPH8vhIkGmYBOpvNSFnaAzkuvE6DtsvAZSEd3u+lJxM1vhXG smcSFHSr4Nt6ZMM9pRx9oSVyhsZVXLG0aryc+9GQCOcK6JQkPq033a42Q 9cbrCCam40Ir8zLvAsLEPAAazenZlXqtbmcRrLQkmsvlupMI+kgE8LUyC EXX56577OwLw5IlbR9k8QkVNDnXNoFpKyrYpvnk5oyon7g/JUA9sWeMnp 1F4nSwS3ST+0XboL0wqwjiAE8Wr6IiNts+taHQGuF8RbLEJG4i+NA1eM2 A==; X-CSE-ConnectionGUID: 71ORwvHfTBSy9qNbEJ4YUQ== X-CSE-MsgGUID: 6LwJeOMfSrascQN6vAlEAA== X-IronPort-AV: E=McAfee;i="6800,10657,11872"; a="98457649" X-IronPort-AV: E=Sophos;i="6.25,219,1779174000"; d="scan'208";a="98457649" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2026 06:28:34 -0700 X-CSE-ConnectionGUID: QfK/PfjYQTmcJecsa0kjzA== X-CSE-MsgGUID: FYMEsq1dTnS+uJVHYSwfaw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,219,1779174000"; d="scan'208";a="267509914" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Aug 2026 06:28:33 -0700 From: Markus Metzger To: gdb-patches@sourceware.org Cc: Tankut Baris Aktemur Subject: [PATCH v4 08/44] gdb: add a new extract_integer variant that takes two array_views Date: Wed, 12 Aug 2026 15:27:28 +0200 Message-ID: <20260812132805.380163-9-markus.t.metzger@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260812132805.380163-1-markus.t.metzger@intel.com> References: <20260812132805.380163-1-markus.t.metzger@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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~public-inbox=simark.ca@sourceware.org From: Tankut Baris Aktemur Add a new variant of extract integer that takes both the source and the destination values as array_view parameter. The existing templated extract_integer then becomes a wrapper around the new variant. The new variant gives flexibility and ease of use in cases where the destination buffer and length are runtime values. --- gdb/extract-store-integer.c | 53 ++++++++++++++++++++++++------------- gdb/extract-store-integer.h | 8 ++++++ 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/gdb/extract-store-integer.c b/gdb/extract-store-integer.c index 67e4534a27d..41116d6cd3c 100644 --- a/gdb/extract-store-integer.c +++ b/gdb/extract-store-integer.c @@ -20,26 +20,27 @@ #include "gdbarch.h" #include "gdbsupport/selftest.h" -template -T -extract_integer (gdb::array_view buf, enum bfd_endian byte_order) -{ - typename std::make_unsigned::type retval = 0; +/* See extract-store-integer.h. */ - /* It is ok if BUF is wider than T, but only if the value is +void +extract_integer (gdb::array_view dst, + gdb::array_view buf, + enum bfd_endian byte_order, + bool is_signed) +{ + /* It is ok if BUF is wider than DST, but only if the value is representable. */ bool bad_repr = false; - if (buf.size () > (int) sizeof (T)) + if (buf.size () > dst.size ()) { - const size_t end = buf.size () - sizeof (T); + const size_t end = buf.size () - dst.size (); if (byte_order == BFD_ENDIAN_BIG) { for (size_t i = 0; i < end; ++i) { /* High bytes == 0 are always ok, and high bytes == 0xff are ok when the type is signed. */ - if ((buf[i] == 0 - || (std::is_signed::value && buf[i] == 0xff)) + if ((buf[i] == 0 || (is_signed && buf[i] == 0xff)) /* All the high bytes must be the same, no alternating 0 and 0xff. */ && (i == 0 || buf[i - 1] == buf[i])) @@ -61,8 +62,7 @@ extract_integer (gdb::array_view buf, enum bfd_endian byte_order { /* High bytes == 0 are always ok, and high bytes == 0xff are ok when the type is signed. */ - if ((buf[i] == 0 - || (std::is_signed::value && buf[i] == 0xff)) + if ((buf[i] == 0 || (is_signed && buf[i] == 0xff)) /* All the high bytes must be the same, no alternating 0 and 0xff. */ && (i == bufsz || buf[i] == buf[i + 1])) @@ -81,7 +81,7 @@ extract_integer (gdb::array_view buf, enum bfd_endian byte_order if (bad_repr) error (_("Value cannot be represented as integer of %d bytes."), - (int) sizeof (T)); + (int) dst.size ()); /* Start at the most significant end of the integer, and work towards the least significant. */ @@ -89,28 +89,43 @@ extract_integer (gdb::array_view buf, enum bfd_endian byte_order { size_t i = 0; - if (std::is_signed::value) + if (is_signed) { /* Do the sign extension once at the start. */ - retval = ((LONGEST) buf[i] ^ 0x80) - 0x80; + dst[buf.size () - 1] = ((LONGEST) buf[i] ^ 0x80) - 0x80; ++i; } for (; i < buf.size (); ++i) - retval = (retval << 8) | buf[i]; + dst[buf.size () - 1 - i] = buf[i]; } else { ssize_t i = buf.size () - 1; - if (std::is_signed::value) + if (is_signed) { /* Do the sign extension once at the start. */ - retval = ((LONGEST) buf[i] ^ 0x80) - 0x80; + dst[i] = ((LONGEST) buf[i] ^ 0x80) - 0x80; --i; } for (; i >= 0; --i) - retval = (retval << 8) | buf[i]; + dst[i] = buf[i]; } + + /* Extend the upper bytes when DST is wider than BUF. */ + if (is_signed && (dst[buf.size () - 1] & 0x80) != 0) + for (size_t i = buf.size (); i < dst.size (); ++i) + dst[i] = 0xff; +} + +template +T +extract_integer (gdb::array_view buf, enum bfd_endian byte_order) +{ + typename std::make_unsigned::type retval = 0; + gdb::array_view dst ((gdb_byte *) &retval, sizeof (T)); + extract_integer (dst, buf, byte_order, std::is_signed::value); + return retval; } diff --git a/gdb/extract-store-integer.h b/gdb/extract-store-integer.h index b6f734d23a7..5d9d95e7036 100644 --- a/gdb/extract-store-integer.h +++ b/gdb/extract-store-integer.h @@ -20,6 +20,14 @@ #include +/* Convert the target-format buffer SRC into the host-format buffer + DST, according to BYTE_ORDER and taking IS_SIGNED into account. */ + +void extract_integer (gdb::array_view dst, + gdb::array_view src, + enum bfd_endian byte_order, + bool is_signed); + template> T extract_integer (gdb::array_view, enum bfd_endian byte_order); -- 2.43.0 ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.