1 /* Copyright (C) 1986-2024 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #ifndef GDB_EXTRACT_STORE_INTEGER_H
19 #define GDB_EXTRACT_STORE_INTEGER_H
21 #include <type_traits>
23 template<typename T
, typename
= std::is_integral
<T
>>
24 T
extract_integer (gdb::array_view
<const gdb_byte
>, enum bfd_endian byte_order
);
27 extract_signed_integer (gdb::array_view
<const gdb_byte
> buf
,
28 enum bfd_endian byte_order
)
30 return extract_integer
<LONGEST
> (buf
, byte_order
);
34 extract_signed_integer (const gdb_byte
*addr
, int len
,
35 enum bfd_endian byte_order
)
37 return extract_signed_integer (gdb::array_view
<const gdb_byte
> (addr
, len
),
41 static inline ULONGEST
42 extract_unsigned_integer (gdb::array_view
<const gdb_byte
> buf
,
43 enum bfd_endian byte_order
)
45 return extract_integer
<ULONGEST
> (buf
, byte_order
);
48 static inline ULONGEST
49 extract_unsigned_integer (const gdb_byte
*addr
, int len
,
50 enum bfd_endian byte_order
)
52 return extract_unsigned_integer (gdb::array_view
<const gdb_byte
> (addr
, len
),
56 extern CORE_ADDR
extract_typed_address (const gdb_byte
*buf
,
59 /* All 'store' functions accept a host-format integer and store a
60 target-format integer at ADDR which is LEN bytes long. */
62 template<typename T
, typename
= RequireLongest
<T
>>
63 extern void store_integer (gdb::array_view
<gdb_byte
> dst
,
64 bfd_endian byte_order
, T val
);
68 store_integer (gdb_byte
*addr
, int len
, bfd_endian byte_order
, T val
)
70 return store_integer (gdb::make_array_view (addr
, len
), byte_order
, val
);
74 store_signed_integer (gdb::array_view
<gdb_byte
> dst
, bfd_endian byte_order
,
77 return store_integer (dst
, byte_order
, val
);
81 store_signed_integer (gdb_byte
*addr
, int len
, bfd_endian byte_order
,
84 return store_signed_integer (gdb::make_array_view (addr
, len
), byte_order
,
89 store_unsigned_integer (gdb::array_view
<gdb_byte
> dst
, bfd_endian byte_order
,
92 return store_integer (dst
, byte_order
, val
);
96 store_unsigned_integer (gdb_byte
*addr
, int len
, bfd_endian byte_order
,
99 return store_unsigned_integer (gdb::make_array_view (addr
, len
), byte_order
,
103 extern void store_typed_address (gdb_byte
*buf
, struct type
*type
,
106 extern void copy_integer_to_size (gdb_byte
*dest
, int dest_size
,
107 const gdb_byte
*source
, int source_size
,
108 bool is_signed
, enum bfd_endian byte_order
);
110 #endif /* GDB_EXTRACT_STORE_INTEGER_H */