From: Yao Qi <qiyaoltc@gmail.com>
To: Alan Hayward <Alan.Hayward@arm.com>
Cc: "gdb-patches\@sourceware.org" <gdb-patches@sourceware.org>,
nd <nd@arm.com>
Subject: Re: [PATCH 3/11] Add MIPS_MAX_REGISTER_SIZE (2/4)
Date: Fri, 12 May 2017 08:53:00 -0000 [thread overview]
Message-ID: <867f1m8nhm.fsf@gmail.com> (raw)
In-Reply-To: <806B436F-EFA1-4200-AC54-9036D166C9B9@arm.com> (Alan Hayward's message of "Fri, 5 May 2017 08:04:04 +0000")
Alan Hayward <Alan.Hayward@arm.com> writes:
> }
>
> +/* Supply register REGNUM, whose contents are stored in signed VAL, to
> + REGCACHE. */
> +
> +void
> +regcache::raw_supply_signed (int regnum, LONGEST val)
The unsigned version of this function is also needed, because I see such
pattern also exists,
store_unsigned_integer (buf, 8, byte_order, sp + offset);
regcache_raw_supply (regcache, AMD64_RSP_REGNUM, buf);
this leads me thinking we need to use function template to define
functions for both LONGEST and ULONGEST.
Secondly, this method can be named as raw_supply.
> +{
> + enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
> + gdb_byte *regbuf;
> + size_t size;
> +
> + gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
> + gdb_assert (!m_readonly_p);
> +
> + regbuf = register_buffer (regnum);
> + size = m_descr->sizeof_register[regnum];
> +
> + store_signed_integer (regbuf, size, byte_order, val);
> + m_register_status[regnum] = REG_VALID;
> +}
> +
> /* Collect register REGNUM from REGCACHE and store its contents in BUF. */
>
> void
> @@ -1251,6 +1271,23 @@ regcache::raw_collect (int regnum, void *buf) const
> memcpy (buf, regbuf, size);
> }
>
> +/* Collect register REGNUM from REGCACHE and extract its contents into a signed
This line is too long.
> + LONGEST. */
> +
> +LONGEST
> +regcache::raw_collect_signed (int regnum) const
We can define this method like this,
template<typename T>
using LongType = typename std::enable_if<(std::is_same<T, LONGEST>::value
|| std::is_same<T, ULONGEST>::value),
T>::type;
template<typename T>
LongType<T> raw_collect (int regnum) const
{
....
if (std::is_signed<T>::value)
return extract_signed_integer (regbuf, size, byte_order);
else
return extract_unsigned_integer (regbuf, size, byte_order);
}
> +{
> + enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
> + const gdb_byte *regbuf;
> + size_t size;
> +
> + gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
> +
> + regbuf = register_buffer (regnum);
> + size = m_descr->sizeof_register[regnum];
> + return extract_signed_integer (regbuf, size, byte_order);
> +}
If you want, we can add a function template for extract_signed_integer
and extract_unsigned_integer.
template<typename T>
LongType<T>
extract_integer (const gdb_byte *addr, int len, enum bfd_endian byte_order)
{
T retval;
...
if (std::is_signed<T>::value)
{
...
}
else
{
...
}
return retval;
}
so, the raw_collect above becomes,
template<typename T>
LongType<T> raw_collect (int regnum) const
{
....
return extract_integer<T> (regbuf, size, byte_order);
}
and raw_read_{signed,unsigned}, cooked_read_{signed,unsigned} can be
merged as function template too.
--
Yao (齐尧)
next prev parent reply other threads:[~2017-05-12 8:53 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-04 10:12 [PATCH 3/11] Add MIPS_MAX_REGISTER_SIZE Alan Hayward
2017-04-04 17:19 ` John Baldwin
2017-04-05 10:27 ` Alan Hayward
2017-04-11 15:37 ` Yao Qi
2017-05-05 8:03 ` [PATCH 3/11] Add MIPS_MAX_REGISTER_SIZE (1/4) Alan Hayward
2017-05-05 21:44 ` Yao Qi
2017-05-05 8:04 ` [PATCH 3/11] Add MIPS_MAX_REGISTER_SIZE (4/4) Alan Hayward
2017-06-07 8:31 ` Alan Hayward
2017-06-08 20:27 ` Maciej W. Rozycki
2017-06-09 10:31 ` Alan Hayward
2017-06-09 11:03 ` Pedro Alves
2017-06-09 11:48 ` Maciej W. Rozycki
2017-06-09 12:05 ` Pedro Alves
2017-06-09 13:23 ` Maciej W. Rozycki
2017-06-09 14:29 ` Pedro Alves
2017-06-12 9:09 ` Alan Hayward
2017-06-12 18:11 ` Pedro Alves
2017-06-12 14:29 ` Maciej W. Rozycki
2017-05-05 8:04 ` [PATCH 3/11] Add MIPS_MAX_REGISTER_SIZE (3/4) Alan Hayward
2017-05-05 21:54 ` Yao Qi
2017-05-05 8:04 ` [PATCH 3/11] Add MIPS_MAX_REGISTER_SIZE (2/4) Alan Hayward
2017-05-05 19:51 ` John Baldwin
2017-05-12 8:53 ` Yao Qi [this message]
2017-05-16 11:16 ` Alan Hayward
2017-05-22 12:07 ` Yao Qi
2017-05-22 16:05 ` Alan Hayward
2017-05-22 17:15 ` Pedro Alves
2017-05-23 17:49 ` Alan Hayward
2017-05-23 18:30 ` Pedro Alves
2017-05-24 9:08 ` Alan Hayward
2017-05-24 9:20 ` Pedro Alves
2017-05-24 10:20 ` Alan Hayward
2017-05-24 11:07 ` Pedro Alves
2017-05-24 19:45 ` Alan Hayward
2017-05-25 10:46 ` Pedro Alves
2017-05-25 11:43 ` Yao Qi
2017-05-25 11:48 ` Pedro Alves
2017-05-26 8:54 ` Alan Hayward
2017-05-26 10:26 ` Pedro Alves
2017-05-26 15:30 ` Alan Hayward
2017-05-26 15:49 ` Pedro Alves
2017-05-26 16:18 ` Alan Hayward
2017-05-26 16:00 ` John Baldwin
2017-05-24 9:29 ` Pedro Alves
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=867f1m8nhm.fsf@gmail.com \
--to=qiyaoltc@gmail.com \
--cc=Alan.Hayward@arm.com \
--cc=gdb-patches@sourceware.org \
--cc=nd@arm.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).