Home | History | Annotate | Line # | Download | only in gdb
      1 /* Copyright (C) 1986-2024 Free Software Foundation, Inc.
      2 
      3    This file is part of GDB.
      4 
      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.
      9 
     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.
     14 
     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/>.  */
     17 
     18 #ifndef GDB_EXTRACT_STORE_INTEGER_H
     19 #define GDB_EXTRACT_STORE_INTEGER_H
     20 
     21 #include "gdbsupport/traits.h"
     22 
     23 template<typename T, typename = RequireLongest<T>>
     24 T extract_integer (gdb::array_view<const gdb_byte>, enum bfd_endian byte_order);
     25 
     26 static inline LONGEST
     27 extract_signed_integer (gdb::array_view<const gdb_byte> buf,
     28 			enum bfd_endian byte_order)
     29 {
     30   return extract_integer<LONGEST> (buf, byte_order);
     31 }
     32 
     33 static inline LONGEST
     34 extract_signed_integer (const gdb_byte *addr, int len,
     35 			enum bfd_endian byte_order)
     36 {
     37   return extract_signed_integer (gdb::array_view<const gdb_byte> (addr, len),
     38 				 byte_order);
     39 }
     40 
     41 static inline ULONGEST
     42 extract_unsigned_integer (gdb::array_view<const gdb_byte> buf,
     43 			  enum bfd_endian byte_order)
     44 {
     45   return extract_integer<ULONGEST> (buf, byte_order);
     46 }
     47 
     48 static inline ULONGEST
     49 extract_unsigned_integer (const gdb_byte *addr, int len,
     50 			  enum bfd_endian byte_order)
     51 {
     52   return extract_unsigned_integer (gdb::array_view<const gdb_byte> (addr, len),
     53 				   byte_order);
     54 }
     55 
     56 extern int extract_long_unsigned_integer (const gdb_byte *, int,
     57 					  enum bfd_endian, LONGEST *);
     58 
     59 extern CORE_ADDR extract_typed_address (const gdb_byte *buf,
     60 					struct type *type);
     61 
     62 /* All 'store' functions accept a host-format integer and store a
     63    target-format integer at ADDR which is LEN bytes long.  */
     64 
     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);
     68 
     69 template<typename T>
     70 static inline void
     71 store_integer (gdb_byte *addr, int len, bfd_endian byte_order, T val)
     72 {
     73   return store_integer (gdb::make_array_view (addr, len), byte_order, val);
     74 }
     75 
     76 static inline void
     77 store_signed_integer (gdb::array_view<gdb_byte> dst, bfd_endian byte_order,
     78 		      LONGEST val)
     79 {
     80   return store_integer (dst, byte_order, val);
     81 }
     82 
     83 static inline void
     84 store_signed_integer (gdb_byte *addr, int len, bfd_endian byte_order,
     85 		      LONGEST val)
     86 {
     87   return store_signed_integer (gdb::make_array_view (addr, len), byte_order,
     88 			       val);
     89 }
     90 
     91 static inline void
     92 store_unsigned_integer (gdb::array_view<gdb_byte> dst, bfd_endian byte_order,
     93 			ULONGEST val)
     94 {
     95   return store_integer (dst, byte_order, val);
     96 }
     97 
     98 static inline void
     99 store_unsigned_integer (gdb_byte *addr, int len, bfd_endian byte_order,
    100 			ULONGEST val)
    101 {
    102   return store_unsigned_integer (gdb::make_array_view (addr, len), byte_order,
    103 				 val);
    104 }
    105 
    106 extern void store_typed_address (gdb_byte *buf, struct type *type,
    107 				 CORE_ADDR addr);
    108 
    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);
    112 
    113 #endif /* GDB_EXTRACT_STORE_INTEGER_H */
    114