public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Shahab Vahedi <shahab.vahedi@gmail.com>, gdb-patches@sourceware.org
Cc: Shahab Vahedi <shahab@synopsys.com>,
	Simon Marchi <simon.marchi@efficios.com>
Subject: Re: [PATCH v2] gdb: Fix numerical field extraction for target description "flags"
Date: Fri, 23 Jul 2021 09:26:16 -0400	[thread overview]
Message-ID: <ed7039a7-f77f-f213-d892-882c6f29ecb6@polymtl.ca> (raw)
In-Reply-To: <20210723123830.16536-1-shahab.vahedi@gmail.com>

On 2021-07-23 8:38 a.m., Shahab Vahedi via Gdb-patches wrote:
> From: Shahab Vahedi <shahab@synopsys.com>
> 
> 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 <simon.marchi@efficios.com>

LGTM, thanks.

Simon

  reply	other threads:[~2021-07-23 13:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-23 12:38 Shahab Vahedi
2021-07-23 13:26 ` Simon Marchi [this message]
2021-07-24 11:16   ` Simon Marchi
2021-07-24 13:50     ` Joel Brobecker
2021-07-26 13:33       ` Shahab Vahedi
2021-07-26 13:51         ` Simon Marchi
2021-07-26 13:17 ` [PUSHED master] " Shahab Vahedi
2021-07-26 13:17 ` [PUSHED gdb-11-branch] " Shahab Vahedi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ed7039a7-f77f-f213-d892-882c6f29ecb6@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=shahab.vahedi@gmail.com \
    --cc=shahab@synopsys.com \
    --cc=simon.marchi@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).