From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yQo7Gjr8Amr8WjMAWB0awg (envelope-from ) for ; Tue, 12 May 2026 06:08:58 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VYkID4Xr; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 6370B1E0C3; Tue, 12 May 2026 06:08:58 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.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,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED 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 D216C1E093 for ; Tue, 12 May 2026 06:08:56 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 054304BAD179 for ; Tue, 12 May 2026 10:08:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 054304BAD179 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VYkID4Xr Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 279224BAE7CD for ; Tue, 12 May 2026 10:07:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 279224BAE7CD Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 279224BAE7CD Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778580460; cv=none; b=FKzUe+BdpcXPe8QjjTYbSLRLY0JJ471w7/xBUQ2EqlYw1aG1KFcpepL42HxYi2zXZ50Yrn/chYbG1BGwo6UH1RZtQ0MeZKfEzYeZV+0B+RaWgv05ebb2jCjOh3S5aFPXWr5ygcbJdpZsu/bbe4rPvDsXWwqGli2I7jpjW2l43Go= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778580460; c=relaxed/simple; bh=kh4b6jc0a0BI5kz+iT5K2ficyPyk0Fsu9q7IHaMJdrk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=bZ3QFwHfHnXEILeuvVqI6Q+jauSculWfLZUUv38Zf3JNypkmA8nzTab/0zQfjpMXy/uqP6BoPB0TgVb5nljowNRjQEuPzl4hIT18QycnWg3vPR0MQGTR7kCC/xnHX8MtZ+h2AVqCIx+t8iilvefkTHuICkV2kE5zxY+wihUkSiE= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VYkID4Xr DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 279224BAE7CD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778580459; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U26qAJKeMDs3tpfU6ZvfGbYPMmHAYjK4iB2aTkatlV8=; b=VYkID4Xr0x+B0KWtNwj7v5FS37dqPeNyZlrPMg+/8zSJogCbhtmLqMn8MDXKS+12J+7Xvz 4sRnHBeXkiLZY/0PO2zeA3K4hQRuR7XsQ6wASpIKtt0ig+aNREEkauwtSbmXWLc++C2DKf fflJN7ibx1jsOv9cFRongTyY+IDSKMc= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-345-WTz7rgziP0Gf6rR_nPH5pA-1; Tue, 12 May 2026 06:07:38 -0400 X-MC-Unique: WTz7rgziP0Gf6rR_nPH5pA-1 X-Mimecast-MFC-AGG-ID: WTz7rgziP0Gf6rR_nPH5pA_1778580457 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-441243ba35fso4306583f8f.0 for ; Tue, 12 May 2026 03:07:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778580457; x=1779185257; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=U26qAJKeMDs3tpfU6ZvfGbYPMmHAYjK4iB2aTkatlV8=; b=CQuYzfCwHP2EF9NOrk/1Um+ZfPe4SngdFKwbdaDsNYJZMtNnFsaaqKvX3d8AkvsQ7D 5ssevjxzd1b9Kv0+altpIxAMk4N9LBlZULsPNcaHkFKxMW2X3TlPr4Gmj78hcx1CfEdU 4LZtTrVbXXMui/GPvsfly0REbDvH5jcppg6qrVyg+HS8MNOarYZ01T/QfD1Tg8aX2tQy vOgnibreuSTDX0zqsCfpB2iR+qWRSytFmjjVCp6JzsIzkZOe9p28mHgIwxCShM2Lb5gM 70kLXLFyb/q0Ewd2zFWDRYZvGIFKL5JAYnrgB+UMvt194fZUIhSZjgOmR2J9YDyCoLqO /1bw== X-Gm-Message-State: AOJu0YzsbJsXUqD1DcuOVRY9VDjB4jXHFNljaLdh6hGpp0VUlALtfhyV EykExC1VJ9m5Sd0Vzd+nlc7iX4wqF9lG6jm2jHFC+0uPH9FfOQx1BimOSKRKOQd3eLGd53Ke58G AmkLaz38F9q97OzzhXcleUc1O2Nh6/2fRa+8cq36hmcroFeKebAX5xpFjMw77DTRNf50ePYdZXg 1GG0V/yUFQ58xeUOwWw+wm2GXHHSS4X2E0WBw2IcalntQnalE= X-Gm-Gg: Acq92OFnawGwzEYnhSi5URzxs+VCQnEDLsG6x4XXwbP0FYV5leBwFAR8gVsqPIKkfZS nF2Q6+gnkru74Z4SPvpG4oklIr08jm4lxHNW9ykl+z63CG9TLhFUkVhu5ce4IejoUnCwgRcPkgG 5SaY+HG0+ZQwe4/AvvHoLSd26HQwWnR2gi9XrP4BU0aYBTXSYkGJH7LJt/yciSkRg/06W5yAYDH rpI6XAHC/XC0FZARmbCaLzfpBBVE+HNP1lKZVD9Hc/oVlNYhVL90Bw/KBpxRJ2Yi5bLPnZil9ej Igok4GyQVUt3K+PIByBk9II3xcm6Z4c0LpqG/vyl+2TYa1qY5UbuXb3McXDPS/Exhbw/Nw0ptGk gwuNpGG91C8tZDoam X-Received: by 2002:a05:600c:8010:b0:48a:5339:ef0e with SMTP id 5b1f17b1804b1-48e70687eabmr206641765e9.3.1778580456560; Tue, 12 May 2026 03:07:36 -0700 (PDT) X-Received: by 2002:a05:600c:8010:b0:48a:5339:ef0e with SMTP id 5b1f17b1804b1-48e70687eabmr206641235e9.3.1778580455925; Tue, 12 May 2026 03:07:35 -0700 (PDT) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e908cb834sm35307165e9.11.2026.05.12.03.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 03:07:35 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/6] gdb: use TARGET_CHAR_BIT more in dwarf2/expr.c Date: Tue, 12 May 2026 11:07:23 +0100 Message-Id: <7865aefc9044e187b325f71ed2443f1ccf43c30e.1778579473.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: lgvxuMVlvzEXXlEYPGBFPtwmIGcciNW50VbnGU5_3Gw_1778580457 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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 A later commit in this series touches some code in dwarf2/expr.c that used "8 * some_byte_count" to convert to a bit count. It seemed natural to change this to "TARGET_CHAR_BIT * some_byte_count", but when I started looking I realised there's a lot of places in dwarf2/expr.c that use "8" instead of "TARGET_CHAR_BIT". So I split out this commit to change all of the uses of "8" to "TARGET_CHAR_BIT". I believe everywhere I've changed really is doing conversions between bits and bytes, so this change is appropriate. There should be no user visible changes after this commit. --- gdb/dwarf2/expr.c | 84 ++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 38b77f31741..af39ec08385 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -168,24 +168,24 @@ rw_pieced_value (value *v, value *from, bool check_optimized) from_contents = nullptr; } - ULONGEST bits_to_skip = 8 * v->offset (); + ULONGEST bits_to_skip = TARGET_CHAR_BIT * v->offset (); if (v->bitsize ()) { - bits_to_skip += (8 * v->parent ()->offset () + bits_to_skip += (TARGET_CHAR_BIT * v->parent ()->offset () + v->bitpos ()); if (from != nullptr && (type_byte_order (from->type ()) == BFD_ENDIAN_BIG)) { /* Use the least significant bits of FROM. */ - max_offset = 8 * from->type ()->length (); + max_offset = TARGET_CHAR_BIT * from->type ()->length (); offset = max_offset - v->bitsize (); } else max_offset = v->bitsize (); } else - max_offset = 8 * v->type ()->length (); + max_offset = TARGET_CHAR_BIT * v->type ()->length (); /* Advance to the first non-skipped piece. */ for (i = 0; i < c->pieces.size () && bits_to_skip >= c->pieces[i].size; i++) @@ -208,7 +208,7 @@ rw_pieced_value (value *v, value *from, bool check_optimized) = get_next_frame_sentinel_okay (frame_find_by_id (c->frame_id)); gdbarch *arch = frame_unwind_arch (next_frame); int gdb_regnum = dwarf_reg_to_regnum_or_error (arch, p->v.regno); - ULONGEST reg_bits = 8 * register_size (arch, gdb_regnum); + ULONGEST reg_bits = TARGET_CHAR_BIT * register_size (arch, gdb_regnum); bool optim, unavail; if (p->offset + p->size < reg_bits) @@ -222,9 +222,11 @@ rw_pieced_value (value *v, value *from, bool check_optimized) /* If the piece is located in a register, but does not occupy the entire register, the placement of the piece within that register is defined by the ABI. */ + ULONGEST piece_bytes = p->size / TARGET_CHAR_BIT; bits_to_skip - += 8 * gdbarch_dwarf2_reg_piece_offset (arch, gdb_regnum, - p->size / 8); + += (TARGET_CHAR_BIT + * gdbarch_dwarf2_reg_piece_offset (arch, gdb_regnum, + piece_bytes)); } else if (p->op == DW_OP_bit_piece) { @@ -246,8 +248,8 @@ rw_pieced_value (value *v, value *from, bool check_optimized) { /* Read mode. */ if (!get_frame_register_bytes (next_frame, gdb_regnum, - bits_to_skip / 8, buffer, - &optim, &unavail)) + bits_to_skip / TARGET_CHAR_BIT, + buffer, &optim, &unavail)) { if (optim) { @@ -264,19 +266,20 @@ rw_pieced_value (value *v, value *from, bool check_optimized) if (!check_optimized) copy_bitwise (v_contents, offset, - buffer.data (), bits_to_skip % 8, + buffer.data (), bits_to_skip % TARGET_CHAR_BIT, this_size_bits, bits_big_endian); } else { /* Write mode. */ - if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0) + if (bits_to_skip % TARGET_CHAR_BIT != 0 + || this_size_bits % TARGET_CHAR_BIT != 0) { /* Data is copied non-byte-aligned into the register. Need some bits from original register value. */ get_frame_register_bytes (next_frame, gdb_regnum, - bits_to_skip / 8, buffer, &optim, - &unavail); + bits_to_skip / TARGET_CHAR_BIT, + buffer, &optim, &unavail); if (optim) throw_error (OPTIMIZED_OUT_ERROR, _("Can't do read-modify-write to " @@ -289,11 +292,12 @@ rw_pieced_value (value *v, value *from, bool check_optimized) "is unavailable")); } - copy_bitwise (buffer.data (), bits_to_skip % 8, + copy_bitwise (buffer.data (), bits_to_skip % TARGET_CHAR_BIT, from_contents, offset, this_size_bits, bits_big_endian); put_frame_register_bytes (next_frame, gdb_regnum, - bits_to_skip / 8, buffer); + bits_to_skip / TARGET_CHAR_BIT, + buffer); } } break; @@ -305,23 +309,27 @@ rw_pieced_value (value *v, value *from, bool check_optimized) bits_to_skip += p->offset; - CORE_ADDR start_addr = p->v.mem.addr + bits_to_skip / 8; + CORE_ADDR start_addr = (p->v.mem.addr + + bits_to_skip / TARGET_CHAR_BIT); - if (bits_to_skip % 8 == 0 && this_size_bits % 8 == 0 - && offset % 8 == 0) + if (bits_to_skip % TARGET_CHAR_BIT == 0 + && this_size_bits % TARGET_CHAR_BIT == 0 + && offset % TARGET_CHAR_BIT == 0) { /* Everything is byte-aligned; no buffer needed. */ if (from != nullptr) write_memory_with_notification (start_addr, (from_contents - + offset / 8), - this_size_bits / 8); + + offset / TARGET_CHAR_BIT), + (this_size_bits + / TARGET_CHAR_BIT)); else read_value_memory (v, offset, p->v.mem.in_stack_memory, - p->v.mem.addr + bits_to_skip / 8, - v_contents + offset / 8, - this_size_bits / 8); + (p->v.mem.addr + + bits_to_skip / TARGET_CHAR_BIT), + v_contents + offset / TARGET_CHAR_BIT, + this_size_bits / TARGET_CHAR_BIT); break; } @@ -333,16 +341,18 @@ rw_pieced_value (value *v, value *from, bool check_optimized) /* Read mode. */ read_value_memory (v, offset, p->v.mem.in_stack_memory, - p->v.mem.addr + bits_to_skip / 8, + (p->v.mem.addr + + bits_to_skip / TARGET_CHAR_BIT), buffer.data (), this_size); copy_bitwise (v_contents, offset, - buffer.data (), bits_to_skip % 8, + buffer.data (), bits_to_skip % TARGET_CHAR_BIT, this_size_bits, bits_big_endian); } else { /* Write mode. */ - if (bits_to_skip % 8 != 0 || this_size_bits % 8 != 0) + if (bits_to_skip % TARGET_CHAR_BIT != 0 + || this_size_bits % TARGET_CHAR_BIT != 0) { if (this_size <= 8) { @@ -360,7 +370,7 @@ rw_pieced_value (value *v, value *from, bool check_optimized) } } - copy_bitwise (buffer.data (), bits_to_skip % 8, + copy_bitwise (buffer.data (), bits_to_skip % TARGET_CHAR_BIT, from_contents, offset, this_size_bits, bits_big_endian); write_memory_with_notification (start_addr, @@ -383,7 +393,7 @@ rw_pieced_value (value *v, value *from, bool check_optimized) gdbarch *objfile_gdbarch = c->per_objfile->objfile->arch (); ULONGEST stack_value_size_bits - = 8 * p->v.value->type ()->length (); + = TARGET_CHAR_BIT * p->v.value->type ()->length (); /* Use zeroes if piece reaches beyond stack value. */ if (p->offset + p->size > stack_value_size_bits) @@ -413,7 +423,7 @@ rw_pieced_value (value *v, value *from, bool check_optimized) break; } - ULONGEST literal_size_bits = 8 * p->v.literal.length; + ULONGEST literal_size_bits = TARGET_CHAR_BIT * p->v.literal.length; size_t n = this_size_bits; /* Cut off at the end of the implicit value. */ @@ -492,7 +502,7 @@ check_pieced_synthetic_pointer (const value *value, LONGEST bit_offset, piece_closure *c = (piece_closure *) value->computed_closure (); int i; - bit_offset += 8 * value->offset (); + bit_offset += TARGET_CHAR_BIT * value->offset (); if (value->bitsize ()) bit_offset += value->bitpos (); @@ -537,8 +547,8 @@ indirect_pieced_value (value *value) if (type->code () != TYPE_CODE_PTR) return NULL; - int bit_length = 8 * type->length (); - LONGEST bit_offset = 8 * value->offset (); + int bit_length = TARGET_CHAR_BIT * type->length (); + LONGEST bit_offset = TARGET_CHAR_BIT * value->offset (); if (value->bitsize ()) bit_offset += value->bitpos (); @@ -720,13 +730,13 @@ dwarf_expr_context::address_type () const ndx = 2; else error (_("Unsupported address size in DWARF expressions: %d bits"), - 8 * this->m_addr_size); + TARGET_CHAR_BIT * this->m_addr_size); if (types->dw_types[ndx] == NULL) { type_allocator alloc (arch); types->dw_types[ndx] - = init_integer_type (alloc, 8 * this->m_addr_size, + = init_integer_type (alloc, TARGET_CHAR_BIT * this->m_addr_size, 0, ""); } @@ -977,7 +987,7 @@ dwarf_expr_context::fetch_result (struct type *type, struct type *subobj_type, bit_size += piece.size; /* Complain if the expression is larger than the size of the outer type. */ - if (bit_size > 8 * type->length ()) + if (bit_size > TARGET_CHAR_BIT * type->length ()) invalid_synthetic_pointer (); piece_closure *c @@ -2235,7 +2245,7 @@ dwarf_expr_context::execute_stack_op (gdb::array_view expr) /* Record the piece. */ op_ptr = safe_read_uleb128 (op_ptr, op_end, &size); - add_piece (8 * size, 0, op); + add_piece (TARGET_CHAR_BIT * size, 0, op); /* Pop off the address/regnum, and reset the location type. */ @@ -2477,7 +2487,7 @@ dwarf_expr_context::execute_stack_op (gdb::array_view expr) pointer, then make a pieced value. This is ok because we can't have implicit pointers in contexts where pieces are invalid. */ if (this->m_location == DWARF_VALUE_IMPLICIT_POINTER) - add_piece (8 * this->m_addr_size, 0, DW_OP_implicit_pointer); + add_piece (TARGET_CHAR_BIT * this->m_addr_size, 0, DW_OP_implicit_pointer); this->m_recursion_depth--; gdb_assert (this->m_recursion_depth >= 0); -- 2.25.4