From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id CDBAD3858D39 for ; Sat, 24 Jul 2021 11:16:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CDBAD3858D39 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 16OBGBu2020385 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 24 Jul 2021 07:16:16 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 16OBGBu2020385 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id C4E5B1E4A3; Sat, 24 Jul 2021 07:16:10 -0400 (EDT) Subject: Re: [PATCH v2] gdb: Fix numerical field extraction for target description "flags" To: Shahab Vahedi , gdb-patches@sourceware.org Cc: Shahab Vahedi , Simon Marchi , Joel Brobecker References: <20210723123830.16536-1-shahab.vahedi@gmail.com> From: Simon Marchi Message-ID: <7c003060-8c48-9fa7-07eb-4733ef7f30e1@polymtl.ca> Date: Sat, 24 Jul 2021 07:16:10 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sat, 24 Jul 2021 11:16:11 +0000 X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Jul 2021 11:16:25 -0000 Hi Joel, Shahab expressed (on IRC) the desire to merge this patch in the GDB 11 branch. That sounds reasonable to me, does it to you? Simon On 2021-07-23 9:26 a.m., Simon Marchi via Gdb-patches wrote: > On 2021-07-23 8:38 a.m., Shahab Vahedi via Gdb-patches wrote: >> From: Shahab Vahedi >> >> v2 (This section will be removed when checking the patch in): >> 1. There are no lines in the commit message starting with "---". >> 2. Joined 2 lines together that now fit under character limits. >> 3. Added the unit-test "test_print_flags" as proposed by Simon. >> >> The "val_print_type_code_flags ()" function is responsible for >> extraction of fields for "flags" data type. These data types are >> used when describing a custom register type in a target description >> XML. The logic used for the extraction though is not sound: >> >> unsigned field_len = TYPE_FIELD_BITSIZE (type, field); >> ULONGEST field_val >> = val >> (TYPE_FIELD_BITPOS (type, field) - field_len + 1); >> >> TYPE_FIELD_BITSIZE: The bit length of the field to be extracted. >> TYPE_FIELD_BITPOS: The starting position of the field; 0 is LSB. >> val: The register value. >> >> Imagine you have a field that starts at position 1 and its length >> is 4 bits. According to the third line of the code snippet the >> shifting right would become "val >> -2", or "val >> 0xfff...fe" >> to be precise. That will result in a "field_val" of 0. >> >> The correct extraction should be: >> >> ULONGEST field_val = val >> TYPE_FIELD_BITPOS (type, field); >> >> The rest of the algorithm that masks out the higher bits is OK. >> >> Co-Authored-By: Simon Marchi > > LGTM, thanks. > > Simon >