diff options
author | Yao Qi <yao.qi@linaro.org> | 2017-06-16 15:38:42 +0100 |
---|---|---|
committer | Yao Qi <yao.qi@linaro.org> | 2017-06-16 15:38:42 +0100 |
commit | 6f98355cda4ac718855d247fd942553b1706549b (patch) | |
tree | 060aa7cfb453b4fb17d91c615fa15a30739013f5 /gdb/defs.h | |
parent | e197589b72e7b7b2db95c63acd58abb574b4249c (diff) | |
download | fsf-binutils-gdb-6f98355cda4ac718855d247fd942553b1706549b.zip fsf-binutils-gdb-6f98355cda4ac718855d247fd942553b1706549b.tar.gz fsf-binutils-gdb-6f98355cda4ac718855d247fd942553b1706549b.tar.bz2 |
extract/store integer function template
This patch converts functions extract_{unsigned,signed}_integer
to a function template extract_integer, which has two instantiations. It
also does the similar changes to store__{unsigned,signed}_integer,
regcache::raw_read_{unsigned,signed}, regcache::raw_write_{unsigned,signed},
regcache::cooked_read_{unsigned,signed},
regcache::cooked_write_{unsigned,signed}.
This patch was posted here
https://sourceware.org/ml/gdb-patches/2017-05/msg00492.html but the
problem was fixed in a different way. However, I think the patch is still
useful to shorten the code.
gdb:
2017-06-16 Alan Hayward <alan.hayward@arm.com>
Pedro Alves <palves@redhat.com>
Yao Qi <yao.qi@linaro.org>
* defs.h (RequireLongest): New.
(extract_integer): Declare function template.
(extract_signed_integer): Remove the declaration, but define it
static inline.
(extract_unsigned_integer): Likewise.
(store_integer): Declare function template.
(store_signed_integer): Remove the declaration, but define it
static inline.
(store_unsigned_integer): Likewise.
* findvar.c (extract_integer): New function template.
(extract_signed_integer): Remove.
(extract_unsigned_integer): Remove.
(extract_integer<LONGEST>, extract_integer<ULONGEST>): Explicit
instantiations.
(store_integer): New function template.
(store_signed_integer): Remove.
(store_unsigned_integer): Remove.
(store_integer): Explicit instantiations.
* regcache.c (regcache_raw_read_signed): Update.
(regcache::raw_read): New function.
(regcache::raw_read_signed): Remove.
(regcache::raw_read_unsigned): Remove.
(regcache_raw_read_unsigned): Update.
(regcache_raw_write_unsigned): Update.
(regcache::raw_write_signed): Remove.
(regcache::raw_write): New function.
(regcache_cooked_read_signed): Update.
(regcache::raw_write_unsigned): Remove.
(regcache::cooked_read_signed): Remove.
(regcache_cooked_read_unsigned): Update.
(regcache::cooked_read_unsigned): Remove.
(regcache_cooked_write_signed): Update.
(regcache_cooked_write_unsigned): Update.
* regcache.h (regcache) <raw_read_signed>: Remove.
<raw_write_signed, raw_read_unsigned, raw_write_unsigned>: Remove.
<raw_read, raw_write>: New.
<cooked_read_signed, cooked_write_signed>: Remove.
<cooked_write_unsigned, cooked_read_unsigned>: Remove.
<cooked_read, cooked_write>: New.
* sh64-tdep.c (sh64_pseudo_register_read): Update.
(sh64_pseudo_register_write): Update.
Diffstat (limited to 'gdb/defs.h')
-rw-r--r-- | gdb/defs.h | 47 |
1 files changed, 39 insertions, 8 deletions
@@ -82,6 +82,11 @@ enum compile_i_scope_types COMPILE_I_PRINT_VALUE_SCOPE, }; + +template<typename T> +using RequireLongest = gdb::Requires<gdb::Or<std::is_same<T, LONGEST>, + std::is_same<T, ULONGEST>>>; + /* Just in case they're not defined in stdio.h. */ #ifndef SEEK_SET @@ -637,11 +642,22 @@ enum { MAX_REGISTER_SIZE = 64 }; /* In findvar.c. */ -extern LONGEST extract_signed_integer (const gdb_byte *, int, - enum bfd_endian); +template<typename T, typename = RequireLongest<T>> +T extract_integer (const gdb_byte *addr, int len, enum bfd_endian byte_order); -extern ULONGEST extract_unsigned_integer (const gdb_byte *, int, - enum bfd_endian); +static inline LONGEST +extract_signed_integer (const gdb_byte *addr, int len, + enum bfd_endian byte_order) +{ + return extract_integer<LONGEST> (addr, len, byte_order); +} + +static inline ULONGEST +extract_unsigned_integer (const gdb_byte *addr, int len, + enum bfd_endian byte_order) +{ + return extract_integer<ULONGEST> (addr, len, byte_order); +} extern int extract_long_unsigned_integer (const gdb_byte *, int, enum bfd_endian, LONGEST *); @@ -649,11 +665,26 @@ extern int extract_long_unsigned_integer (const gdb_byte *, int, extern CORE_ADDR extract_typed_address (const gdb_byte *buf, struct type *type); -extern void store_signed_integer (gdb_byte *, int, - enum bfd_endian, LONGEST); +/* All 'store' functions accept a host-format integer and store a + target-format integer at ADDR which is LEN bytes long. */ -extern void store_unsigned_integer (gdb_byte *, int, - enum bfd_endian, ULONGEST); +template<typename T, typename = RequireLongest<T>> +extern void store_integer (gdb_byte *addr, int len, enum bfd_endian byte_order, + T val); + +static inline void +store_signed_integer (gdb_byte *addr, int len, + enum bfd_endian byte_order, LONGEST val) +{ + return store_integer (addr, len, byte_order, val); +} + +static inline void +store_unsigned_integer (gdb_byte *addr, int len, + enum bfd_endian byte_order, ULONGEST val) +{ + return store_integer (addr, len, byte_order, val); +} extern void store_typed_address (gdb_byte *buf, struct type *type, CORE_ADDR addr); |