From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id abTmFWP8Amr8WjMAWB0awg (envelope-from ) for ; Tue, 12 May 2026 06:09:39 -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=JbLsT5Wf; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 52C341E0C3; Tue, 12 May 2026 06:09:39 -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 36BFE1E093 for ; Tue, 12 May 2026 06:09:38 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B05284BAE7DF for ; Tue, 12 May 2026 10:09:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B05284BAE7DF 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=JbLsT5Wf 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 9AE6A4BA23F8 for ; Tue, 12 May 2026 10:07:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9AE6A4BA23F8 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 9AE6A4BA23F8 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=1778580463; cv=none; b=A8EqHxKOcvaL23ej10VINMujFOEZOela0dp65BY3vJs4R37+xmCJGiId41Aop4ZM738r2lEQuIBKSVlf8GOQoqmST4NQZO9GXzPt3lLG860RMzGGAnuK9tI+3aKs+qeyTq92Z2RKK7FIAlcT7/fO0bAyFOKSOjr9h90fsMnDAAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778580463; c=relaxed/simple; bh=7pj7THup4vwlBsSRA6G1hOQ0ufgJPW1kP7Pj/ThLzSY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=KT2ewUNtvDV0dvSCEzEd+9d53Yu2BPXYrbZi/QiCIn3mYmHW3Og8NctIJnYBqc6S8K9TblxXqpPFurKIEO7hL6OsxlsIzUWz0lX73QU4eA8XxmJZLvAD8v6e23YQh7pH9Eui/fwZHD+mmZ+54Fowl9rhjtSlDTupcqyVX7mFqHU= 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=JbLsT5Wf DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9AE6A4BA23F8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778580463; 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=LdagnKWNzT5j6qb1/lbpfHFrjdbOHco6R2cH8c/qgCA=; b=JbLsT5WfSsinH843FIZv8c4bdTeS0QEAX7h+l5+1mVurJ26/i60d09S0/oq5pn7zSSJr/S t7b5gJEc+HbiZsSr6iLTys/ojS896BBwrxIjl4ilILCLO1AkMqXova65iLiurKZfQktAsM ysByE20kYzFLo0effLrbI+Rz1hN4o8g= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-451-6FeIf4kPO9OCZpuGUKBCkQ-1; Tue, 12 May 2026 06:07:42 -0400 X-MC-Unique: 6FeIf4kPO9OCZpuGUKBCkQ-1 X-Mimecast-MFC-AGG-ID: 6FeIf4kPO9OCZpuGUKBCkQ_1778580461 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-48d05e7b117so42199225e9.0 for ; Tue, 12 May 2026 03:07:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778580460; x=1779185260; 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=LdagnKWNzT5j6qb1/lbpfHFrjdbOHco6R2cH8c/qgCA=; b=A3OeU0jNM3GkOH39lrEgheLaeLgjk1mUcMXVZ6swG7K0U32KQmM+ryJGHPVPUgFAb8 p44SWNI5DKXGQNitYtew16a63PjA8pUcluNR3T6GQ7/3Gch+7pyY9XG73bxG48gedD7Q HbbayGHjXT7DKHnpSh1gyHurROVEbqPvckAlToiXbTPGQ1pqUMGIOYtZN8IQEfgVfu9K +8sMUyeSAmoEfm6hoipUmBiilfGF9xyrgdqqrSaiwqwIIZcEtpx+PR4gqJLG5J7mcplX zesB59aJr6xc3aVyswiOY4838NYAiEj5XBKCDHlnaG9DSXU5Dxv9+Ky/r2sfE00wK/b7 j6FQ== X-Gm-Message-State: AOJu0YyqZoy1MrItppkrvSC7JSAl6L0VCeBacpbNFsvWnXSCndOTf6xZ VgoQhOMuvl+QYXdaB4V8KNEH7kI1iiOhpnqBdbJqGOav3pA5C4w66wxzqsBVQ2D2y3jlR3kl8VR FJ0Ebp9rgzWzOgjDH5OIRI6zc4wEp14uog6vxtm/7dzPWD89ASYvXCmP/HCgjcmYBO6rdWEu5fA qy8Xh2v4Ezcs6YhJzW7xZgdRSlrMZ109AekAe35JB+uJXtW1s= X-Gm-Gg: Acq92OG3vIcFHc4nWcX3vi8JQxL7qY13j6DwkAxKi7kqeaWv092lTdD2a6Bd/JzSgGx hLgm4W/UHMVpD6lpETxWYIwo8ZcxSAD610z3+3VfNqKouAOu81LLGDk6tPhyH1wNacbayNw2gxu BxQzjUqQa7iS1B1l0bstAS+vqVGgJZRLwq+mFGD/FBPQwO0A8OrkJOcNDR6jPLhqt9CD51m5YXn QMhS4FO82vVZoVIndbLBmwvS4wEBP9jB+cuQqIRbPRiZIPBcX2s3ODvMivHivIoki/0TvYE4ZQR LsPUACrucV5a9ZdE1Q0Px5ZdfKmMM+ihjOxiP4CoNLrv/5T0sAMdRoUDkbeREaA0eWnAJIIvblB pi2mMNbAV5X15cshg X-Received: by 2002:a05:600c:3ba7:b0:48a:7772:c26b with SMTP id 5b1f17b1804b1-48e51f40884mr486869215e9.26.1778580460020; Tue, 12 May 2026 03:07:40 -0700 (PDT) X-Received: by 2002:a05:600c:3ba7:b0:48a:7772:c26b with SMTP id 5b1f17b1804b1-48e51f40884mr486868595e9.26.1778580459463; Tue, 12 May 2026 03:07:39 -0700 (PDT) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e8f410558sm26267175e9.5.2026.05.12.03.07.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 03:07:37 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 4/6] gdb: rename argument in valprint_check_validity Date: Tue, 12 May 2026 11:07:25 +0100 Message-Id: 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: daWl_erx-05jmg_eSAaQ2Kd8XB_gT96Yq2UPwMjF1B0_1778580461 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 To understand the motivation for this commit you'll need to look ahead two commits in this series for an upcoming bug fix. Look at coerce_pieced_ref in dwarf2/expr.c, and this call: if (value->bits_synthetic_pointer (value->embedded_offset (), TARGET_CHAR_BIT * type->length ())) { ... } This passes the result from value::embedded_offset as the first argument. Though it's not clear from value.h, the number returned by value::embedded_offset is a byte offset. The value::bits_synthetic_pointer call can end up calling check_pieced_synthetic_pointer, with the first argument to value::bits_synthetic_pointer becoming the second argument to check_pieced_synthetic_pointer. The second argument to check_pieced_synthetic_pointer is called BIT_OFFSET, a value in bits. Looking at how this argument is used confirms that it is expected to be a value in bits, not bytes. The fix should be easy, multiply the embedded offset by TARGET_CHAR_BIT, but I think things are a little more complex than this. I started looking at how value::bits_synthetic_pointer is used, there are only 7 uses, and they can be grouped as follows: gdb/dwarf2/expr.c gdb/valops.c These call value::embedded_offset directly within the call to value::bits_synthetic_pointer. gdb/opencl-lang.c This function is used as a wrapper that implements a lval_funcs::check_synthetic_pointer callback, it adjusts the arguments and then calls value::bits_synthetic_pointer. As such we'd not expect to see embedded offset mentioned here as that would (we assume) be handled by the caller. gdb/valprint.c (in generic_val_print_ref) This call passes an argument called 'embedded_offset', but the function generic_val_print_ref is only used in one place, and the embedded_offset is always passed as zero. gdb/valprint.c (in valprint_check_validity) This call also passes an argument called 'embedded_offset'. This function is used in two places. In common_val_print the embedded_offset is always passed as zero, but in valprint_check_validity (in cp-valprint.c) the embedded_offset being passed is the offset of a field within the value, not the value's embedded_offset within some larger value. gdb/cp-valprint.c gdb/p-valprint.c As with the call to valprint_check_validity in cp-valprint.c, these two direct calls to value::bits_synthetic_pointer pass the offset of a field within the value, rather than the value's embedded_offset. What I see in the above is some confusion. In some places we are passing the value::embedded_offset, while in other places we are passing the offset of a field within the value itself. If we consider the direct call to value::bits_synthetic_pointer in gdb/cp-valprint.c, where a field offset is passed, then it should be possible, that if we can create an object with a non-zero embedded_offset (which isn't accounted for in this code path), then we should see some bugs in GDB, and indeed, this is what I do see. My plan for fixing this is to have the offset passed to value::bits_synthetic_pointer always be a field offset within the value, the value::embedded_offset will then be handled directly within the various value::bits_synthetic_pointer implementations. This commit is a small refactor in preparation for this fix. I believe part of the confusion here is that we have functions that take arguments called embedded_offset, when the value they should accept is no longer the embedded offset. So in this commit I propose renaming the embedded_offset argument to field_byte_offset in valprint_check_validity. This is purely a mechanical rename, there should be no user visible changes after this commit. --- gdb/valprint.c | 8 ++++---- gdb/valprint.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gdb/valprint.c b/gdb/valprint.c index 9801f195d13..ca4a064a7c5 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -318,7 +318,7 @@ val_print_scalar_or_string_type_p (struct type *type, bool valprint_check_validity (struct ui_file *stream, struct type *type, - LONGEST embedded_offset, + LONGEST field_byte_offset, const struct value *val) { type = check_typedef (type); @@ -339,14 +339,14 @@ valprint_check_validity (struct ui_file *stream, && type->code () != TYPE_CODE_STRUCT && type->code () != TYPE_CODE_ARRAY) { - if (val->bits_any_optimized_out (TARGET_CHAR_BIT * embedded_offset, + if (val->bits_any_optimized_out (TARGET_CHAR_BIT * field_byte_offset, TARGET_CHAR_BIT * type->length ())) { val_print_optimized_out (val, stream); return false; } - if (val->bits_synthetic_pointer (TARGET_CHAR_BIT * embedded_offset, + if (val->bits_synthetic_pointer (TARGET_CHAR_BIT * field_byte_offset, TARGET_CHAR_BIT * type->length ())) { const bool is_ref = type->code () == TYPE_CODE_REF; @@ -368,7 +368,7 @@ valprint_check_validity (struct ui_file *stream, return is_ref; } - if (!val->bytes_available (embedded_offset, type->length ())) + if (!val->bytes_available (field_byte_offset, type->length ())) { val_print_unavailable (stream); return false; diff --git a/gdb/valprint.h b/gdb/valprint.h index c8f4bd52286..146a24d174f 100644 --- a/gdb/valprint.h +++ b/gdb/valprint.h @@ -199,12 +199,12 @@ extern void print_function_pointer_address (const struct value_print_options *op If TYPE represents some aggregate type (e.g., a structure), return true. - For non-aggregate TYPEs, if any of the bytes starting at EMBEDDED_OFFSET + For non-aggregate TYPEs, if any of the bytes starting at FIELD_BYTE_OFFSET and extending for TYPE->length () bytes are invalid, print a message to STREAM and return false. Otherwise, return true. */ extern bool valprint_check_validity (struct ui_file *stream, struct type *type, - LONGEST embedded_offset, + LONGEST field_byte_offset, const struct value *val); extern void val_print_optimized_out (const struct value *val, -- 2.25.4