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 "gdbsupport/traits.h"
23 template<typename T
, typename
= RequireLongest
<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 int extract_long_unsigned_integer (const gdb_byte
*, int,
57 enum bfd_endian
, LONGEST
*);
59 extern CORE_ADDR
extract_typed_address (const gdb_byte
*buf
,
62 /* All 'store' functions accept a host-format integer and store a
63 target-format integer at ADDR which is LEN bytes long. */
65 template<typename T
, typename
= RequireLongest
<T
>>
66 extern void store_integer (gdb::array_view
<gdb_byte
> dst
,
67 bfd_endian byte_order
, T val
);
71 store_integer (gdb_byte
*addr
, int len
, bfd_endian byte_order
, T val
)
73 return store_integer (gdb::make_array_view (addr
, len
), byte_order
, val
);
77 store_signed_integer (gdb::array_view
<gdb_byte
> dst
, bfd_endian byte_order
,
80 return store_integer (dst
, byte_order
, val
);
84 store_signed_integer (gdb_byte
*addr
, int len
, bfd_endian byte_order
,
87 return store_signed_integer (gdb::make_array_view (addr
, len
), byte_order
,
92 store_unsigned_integer (gdb::array_view
<gdb_byte
> dst
, bfd_endian byte_order
,
95 return store_integer (dst
, byte_order
, val
);
99 store_unsigned_integer (gdb_byte
*addr
, int len
, bfd_endian byte_order
,
102 return store_unsigned_integer (gdb::make_array_view (addr
, len
), byte_order
,
106 extern void store_typed_address (gdb_byte
*buf
, struct type
*type
,
109 extern void copy_integer_to_size (gdb_byte
*dest
, int dest_size
,
110 const gdb_byte
*source
, int source_size
,
111 bool is_signed
, enum bfd_endian byte_order
);
113 #endif /* GDB_EXTRACT_STORE_INTEGER_H */