GNU Binutils with patches for OS216
Revision | ca47aa93d4a13e676e771041eb7372ff2cdb1487 (tree) |
---|---|
Zeit | 2016-02-11 21:14:02 |
Autor | Pedro Alves <palves@redh...> |
Commiter | Pedro Alves |
Move store/extract ... integer routines to gdb/common/
In preparation for gdbserver using them as well.
gdb/ChangeLog:
2016-02-11 Pedro Alves <palves@redhat.com>
* Makefile.in (SFILES): Add common/gdb-byteswap.c.
(HFILES_NO_SRCDIR): Add common/gdb-byteswap.h.
(COMMON_OBS): Add common/gdb-byteswap.o.
(gdb-byteswap.o): New rule.
* common/common-types.h: Include bfd-types.h.
* common/gdb-byteswap.c: New file.
* common/gdb-byteswap.h: New file.
* defs.h (extract_signed_integer, extract_unsigned_integer)
(extract_long_unsigned_integer, extract_typed_address)
(store_signed_integer, store_unsigned_integer): Moved to
common/gdb-byteswap.h.
* findvar.c (extract_signed_integer, extract_unsigned_integer)
(extract_long_unsigned_integer, extract_typed_address)
(store_signed_integer, store_unsigned_integer): Moved to
common/gdb-byteswap.c.
@@ -896,6 +896,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \ | ||
896 | 896 | target/waitstatus.c common/print-utils.c common/rsp-low.c \ |
897 | 897 | common/errors.c common/common-debug.c common/common-exceptions.c \ |
898 | 898 | common/btrace-common.c common/fileio.c common/common-regcache.c \ |
899 | + common/gdb-byteswap.c \ | |
899 | 900 | $(SUBDIR_GCC_COMPILE_SRCS) |
900 | 901 | |
901 | 902 | LINTFILES = $(SFILES) $(YYFILES) $(CONFIG_SRCS) init.c |
@@ -988,7 +989,9 @@ common/common-exceptions.h target/target.h common/symbol.h \ | ||
988 | 989 | common/common-regcache.h fbsd-tdep.h nat/linux-personality.h \ |
989 | 990 | common/fileio.h nat/x86-linux.h nat/x86-linux-dregs.h nat/amd64-linux-siginfo.h\ |
990 | 991 | nat/linux-namespaces.h arch/arm.h common/gdb_sys_time.h arch/aarch64-insn.h \ |
991 | -tid-parse.h | |
992 | +tid-parse.h \ | |
993 | +common/gdb-byteswap.h | |
994 | + | |
992 | 995 | |
993 | 996 | # Header files that already have srcdir in them, or which are in objdir. |
994 | 997 |
@@ -1087,7 +1090,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \ | ||
1087 | 1090 | format.o registry.o btrace.o record-btrace.o waitstatus.o \ |
1088 | 1091 | print-utils.o rsp-low.o errors.o common-debug.o debug.o \ |
1089 | 1092 | common-exceptions.o btrace-common.o fileio.o \ |
1090 | - common-regcache.o \ | |
1093 | + common-regcache.o gdb-byteswap.o \ | |
1091 | 1094 | $(SUBDIR_GCC_COMPILE_OBS) |
1092 | 1095 | |
1093 | 1096 | TSOBS = inflow.o |
@@ -2275,6 +2278,10 @@ common-regcache.o: ${srcdir}/common/common-regcache.c | ||
2275 | 2278 | $(COMPILE) $(srcdir)/common/common-regcache.c |
2276 | 2279 | $(POSTCOMPILE) |
2277 | 2280 | |
2281 | +gdb-byteswap.o: ${srcdir}/common/gdb-byteswap.c | |
2282 | + $(COMPILE) $(srcdir)/common/gdb-byteswap.c | |
2283 | + $(POSTCOMPILE) | |
2284 | + | |
2278 | 2285 | # |
2279 | 2286 | # gdb/target/ dependencies |
2280 | 2287 | # |
@@ -20,6 +20,10 @@ | ||
20 | 20 | #ifndef COMMON_TYPES_H |
21 | 21 | #define COMMON_TYPES_H |
22 | 22 | |
23 | +/* This header is always available, even when BFD is not | |
24 | + configured. */ | |
25 | +#include "bfd-types.h" | |
26 | + | |
23 | 27 | #ifdef GDBSERVER |
24 | 28 | |
25 | 29 | /* * A byte from the program being debugged. */ |
@@ -0,0 +1,201 @@ | ||
1 | +/* Basic byte-swapping routines, for GDB, the GNU debugger. | |
2 | + | |
3 | + Copyright (C) 1986-2016 Free Software Foundation, Inc. | |
4 | + | |
5 | + This file is part of GDB. | |
6 | + | |
7 | + This program is free software; you can redistribute it and/or modify | |
8 | + it under the terms of the GNU General Public License as published by | |
9 | + the Free Software Foundation; either version 3 of the License, or | |
10 | + (at your option) any later version. | |
11 | + | |
12 | + This program is distributed in the hope that it will be useful, | |
13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | + GNU General Public License for more details. | |
16 | + | |
17 | + You should have received a copy of the GNU General Public License | |
18 | + along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | + | |
20 | +#include "common-defs.h" | |
21 | +#include "gdb-byteswap.h" | |
22 | +#include "host-defs.h" | |
23 | + | |
24 | +/* See gdb-byteswap.h. */ | |
25 | + | |
26 | +LONGEST | |
27 | +extract_signed_integer (const gdb_byte *addr, int len, | |
28 | + enum bfd_endian byte_order) | |
29 | +{ | |
30 | + LONGEST retval; | |
31 | + const unsigned char *p; | |
32 | + const unsigned char *startaddr = addr; | |
33 | + const unsigned char *endaddr = startaddr + len; | |
34 | + | |
35 | + if (len > (int) sizeof (LONGEST)) | |
36 | + error (_("\ | |
37 | +That operation is not available on integers of more than %d bytes."), | |
38 | + (int) sizeof (LONGEST)); | |
39 | + | |
40 | + /* Start at the most significant end of the integer, and work towards | |
41 | + the least significant. */ | |
42 | + if (byte_order == BFD_ENDIAN_BIG) | |
43 | + { | |
44 | + p = startaddr; | |
45 | + /* Do the sign extension once at the start. */ | |
46 | + retval = ((LONGEST) * p ^ 0x80) - 0x80; | |
47 | + for (++p; p < endaddr; ++p) | |
48 | + retval = (retval << 8) | *p; | |
49 | + } | |
50 | + else | |
51 | + { | |
52 | + p = endaddr - 1; | |
53 | + /* Do the sign extension once at the start. */ | |
54 | + retval = ((LONGEST) * p ^ 0x80) - 0x80; | |
55 | + for (--p; p >= startaddr; --p) | |
56 | + retval = (retval << 8) | *p; | |
57 | + } | |
58 | + return retval; | |
59 | +} | |
60 | + | |
61 | +/* See gdb-byteswap.h. */ | |
62 | + | |
63 | +ULONGEST | |
64 | +extract_unsigned_integer (const gdb_byte *addr, int len, | |
65 | + enum bfd_endian byte_order) | |
66 | +{ | |
67 | + ULONGEST retval; | |
68 | + const unsigned char *p; | |
69 | + const unsigned char *startaddr = addr; | |
70 | + const unsigned char *endaddr = startaddr + len; | |
71 | + | |
72 | + if (len > (int) sizeof (ULONGEST)) | |
73 | + error (_("\ | |
74 | +That operation is not available on integers of more than %d bytes."), | |
75 | + (int) sizeof (ULONGEST)); | |
76 | + | |
77 | + /* Start at the most significant end of the integer, and work towards | |
78 | + the least significant. */ | |
79 | + retval = 0; | |
80 | + if (byte_order == BFD_ENDIAN_BIG) | |
81 | + { | |
82 | + for (p = startaddr; p < endaddr; ++p) | |
83 | + retval = (retval << 8) | *p; | |
84 | + } | |
85 | + else | |
86 | + { | |
87 | + for (p = endaddr - 1; p >= startaddr; --p) | |
88 | + retval = (retval << 8) | *p; | |
89 | + } | |
90 | + return retval; | |
91 | +} | |
92 | + | |
93 | +/* See gdb_byteswap.h. */ | |
94 | + | |
95 | +int | |
96 | +extract_long_unsigned_integer (const gdb_byte *addr, int orig_len, | |
97 | + enum bfd_endian byte_order, LONGEST *pval) | |
98 | +{ | |
99 | + const gdb_byte *p; | |
100 | + const gdb_byte *first_addr; | |
101 | + int len; | |
102 | + | |
103 | + len = orig_len; | |
104 | + if (byte_order == BFD_ENDIAN_BIG) | |
105 | + { | |
106 | + for (p = addr; | |
107 | + len > (int) sizeof (LONGEST) && p < addr + orig_len; | |
108 | + p++) | |
109 | + { | |
110 | + if (*p == 0) | |
111 | + len--; | |
112 | + else | |
113 | + break; | |
114 | + } | |
115 | + first_addr = p; | |
116 | + } | |
117 | + else | |
118 | + { | |
119 | + first_addr = addr; | |
120 | + for (p = addr + orig_len - 1; | |
121 | + len > (int) sizeof (LONGEST) && p >= addr; | |
122 | + p--) | |
123 | + { | |
124 | + if (*p == 0) | |
125 | + len--; | |
126 | + else | |
127 | + break; | |
128 | + } | |
129 | + } | |
130 | + | |
131 | + if (len <= (int) sizeof (LONGEST)) | |
132 | + { | |
133 | + *pval = (LONGEST) extract_unsigned_integer (first_addr, | |
134 | + sizeof (LONGEST), | |
135 | + byte_order); | |
136 | + return 1; | |
137 | + } | |
138 | + | |
139 | + return 0; | |
140 | +} | |
141 | + | |
142 | + | |
143 | +/* See gdb-byteswap.h. */ | |
144 | + | |
145 | +void | |
146 | +store_signed_integer (gdb_byte *addr, int len, | |
147 | + enum bfd_endian byte_order, LONGEST val) | |
148 | +{ | |
149 | + gdb_byte *p; | |
150 | + gdb_byte *startaddr = addr; | |
151 | + gdb_byte *endaddr = startaddr + len; | |
152 | + | |
153 | + /* Start at the least significant end of the integer, and work towards | |
154 | + the most significant. */ | |
155 | + if (byte_order == BFD_ENDIAN_BIG) | |
156 | + { | |
157 | + for (p = endaddr - 1; p >= startaddr; --p) | |
158 | + { | |
159 | + *p = val & 0xff; | |
160 | + val >>= 8; | |
161 | + } | |
162 | + } | |
163 | + else | |
164 | + { | |
165 | + for (p = startaddr; p < endaddr; ++p) | |
166 | + { | |
167 | + *p = val & 0xff; | |
168 | + val >>= 8; | |
169 | + } | |
170 | + } | |
171 | +} | |
172 | + | |
173 | +/* See gdb-byteswap.h. */ | |
174 | + | |
175 | +void | |
176 | +store_unsigned_integer (gdb_byte *addr, int len, | |
177 | + enum bfd_endian byte_order, ULONGEST val) | |
178 | +{ | |
179 | + unsigned char *p; | |
180 | + unsigned char *startaddr = (unsigned char *) addr; | |
181 | + unsigned char *endaddr = startaddr + len; | |
182 | + | |
183 | + /* Start at the least significant end of the integer, and work towards | |
184 | + the most significant. */ | |
185 | + if (byte_order == BFD_ENDIAN_BIG) | |
186 | + { | |
187 | + for (p = endaddr - 1; p >= startaddr; --p) | |
188 | + { | |
189 | + *p = val & 0xff; | |
190 | + val >>= 8; | |
191 | + } | |
192 | + } | |
193 | + else | |
194 | + { | |
195 | + for (p = startaddr; p < endaddr; ++p) | |
196 | + { | |
197 | + *p = val & 0xff; | |
198 | + val >>= 8; | |
199 | + } | |
200 | + } | |
201 | +} |
@@ -0,0 +1,49 @@ | ||
1 | +/* Basic byte-swapping routines, for GDB, the GNU debugger. | |
2 | + | |
3 | + Copyright (C) 2009-2016 Free Software Foundation, Inc. | |
4 | + | |
5 | + This file is part of GDB. | |
6 | + | |
7 | + This program is free software; you can redistribute it and/or modify | |
8 | + it under the terms of the GNU General Public License as published by | |
9 | + the Free Software Foundation; either version 3 of the License, or | |
10 | + (at your option) any later version. | |
11 | + | |
12 | + This program is distributed in the hope that it will be useful, | |
13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | + GNU General Public License for more details. | |
16 | + | |
17 | + You should have received a copy of the GNU General Public License | |
18 | + along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | + | |
20 | +#ifndef GDB_BYTESWAP_H | |
21 | +#define GDB_BYTESWAP_H 1 | |
22 | + | |
23 | +/* All 'extract' functions return a host-format integer from a | |
24 | + target-format integer at ADDR which is LEN bytes long. */ | |
25 | + | |
26 | +extern LONGEST extract_signed_integer (const gdb_byte *, int, | |
27 | + enum bfd_endian); | |
28 | + | |
29 | +extern ULONGEST extract_unsigned_integer (const gdb_byte *, int, | |
30 | + enum bfd_endian); | |
31 | + | |
32 | +/* Sometimes a long long unsigned integer can be extracted as a | |
33 | + LONGEST value. This is done so that we can print these values | |
34 | + better. If this integer can be converted to a LONGEST, this | |
35 | + function returns 1 and sets *PVAL. Otherwise it returns 0. */ | |
36 | + | |
37 | +extern int extract_long_unsigned_integer (const gdb_byte *, int, | |
38 | + enum bfd_endian, LONGEST *); | |
39 | + | |
40 | +/* All 'store' functions accept a host-format integer and store a | |
41 | + target-format integer at ADDR which is LEN bytes long. */ | |
42 | + | |
43 | +extern void store_signed_integer (gdb_byte *, int, | |
44 | + enum bfd_endian, LONGEST); | |
45 | + | |
46 | +extern void store_unsigned_integer (gdb_byte *, int, | |
47 | + enum bfd_endian, ULONGEST); | |
48 | + | |
49 | +#endif |
@@ -594,26 +594,13 @@ extern double atof (const char *); /* X3.159-1989 4.10.1.1 */ | ||
594 | 594 | |
595 | 595 | enum { MAX_REGISTER_SIZE = 64 }; |
596 | 596 | |
597 | -/* In findvar.c. */ | |
598 | - | |
599 | -extern LONGEST extract_signed_integer (const gdb_byte *, int, | |
600 | - enum bfd_endian); | |
601 | - | |
602 | -extern ULONGEST extract_unsigned_integer (const gdb_byte *, int, | |
603 | - enum bfd_endian); | |
597 | +#include "gdb-byteswap.h" | |
604 | 598 | |
605 | -extern int extract_long_unsigned_integer (const gdb_byte *, int, | |
606 | - enum bfd_endian, LONGEST *); | |
599 | +/* In findvar.c. */ | |
607 | 600 | |
608 | 601 | extern CORE_ADDR extract_typed_address (const gdb_byte *buf, |
609 | 602 | struct type *type); |
610 | 603 | |
611 | -extern void store_signed_integer (gdb_byte *, int, | |
612 | - enum bfd_endian, LONGEST); | |
613 | - | |
614 | -extern void store_unsigned_integer (gdb_byte *, int, | |
615 | - enum bfd_endian, ULONGEST); | |
616 | - | |
617 | 604 | extern void store_typed_address (gdb_byte *buf, struct type *type, |
618 | 605 | CORE_ADDR addr); |
619 | 606 |
@@ -34,136 +34,6 @@ | ||
34 | 34 | #include "language.h" |
35 | 35 | #include "dwarf2loc.h" |
36 | 36 | |
37 | -/* Basic byte-swapping routines. All 'extract' functions return a | |
38 | - host-format integer from a target-format integer at ADDR which is | |
39 | - LEN bytes long. */ | |
40 | - | |
41 | -#if TARGET_CHAR_BIT != 8 || HOST_CHAR_BIT != 8 | |
42 | - /* 8 bit characters are a pretty safe assumption these days, so we | |
43 | - assume it throughout all these swapping routines. If we had to deal with | |
44 | - 9 bit characters, we would need to make len be in bits and would have | |
45 | - to re-write these routines... */ | |
46 | -you lose | |
47 | -#endif | |
48 | - | |
49 | -LONGEST | |
50 | -extract_signed_integer (const gdb_byte *addr, int len, | |
51 | - enum bfd_endian byte_order) | |
52 | -{ | |
53 | - LONGEST retval; | |
54 | - const unsigned char *p; | |
55 | - const unsigned char *startaddr = addr; | |
56 | - const unsigned char *endaddr = startaddr + len; | |
57 | - | |
58 | - if (len > (int) sizeof (LONGEST)) | |
59 | - error (_("\ | |
60 | -That operation is not available on integers of more than %d bytes."), | |
61 | - (int) sizeof (LONGEST)); | |
62 | - | |
63 | - /* Start at the most significant end of the integer, and work towards | |
64 | - the least significant. */ | |
65 | - if (byte_order == BFD_ENDIAN_BIG) | |
66 | - { | |
67 | - p = startaddr; | |
68 | - /* Do the sign extension once at the start. */ | |
69 | - retval = ((LONGEST) * p ^ 0x80) - 0x80; | |
70 | - for (++p; p < endaddr; ++p) | |
71 | - retval = (retval << 8) | *p; | |
72 | - } | |
73 | - else | |
74 | - { | |
75 | - p = endaddr - 1; | |
76 | - /* Do the sign extension once at the start. */ | |
77 | - retval = ((LONGEST) * p ^ 0x80) - 0x80; | |
78 | - for (--p; p >= startaddr; --p) | |
79 | - retval = (retval << 8) | *p; | |
80 | - } | |
81 | - return retval; | |
82 | -} | |
83 | - | |
84 | -ULONGEST | |
85 | -extract_unsigned_integer (const gdb_byte *addr, int len, | |
86 | - enum bfd_endian byte_order) | |
87 | -{ | |
88 | - ULONGEST retval; | |
89 | - const unsigned char *p; | |
90 | - const unsigned char *startaddr = addr; | |
91 | - const unsigned char *endaddr = startaddr + len; | |
92 | - | |
93 | - if (len > (int) sizeof (ULONGEST)) | |
94 | - error (_("\ | |
95 | -That operation is not available on integers of more than %d bytes."), | |
96 | - (int) sizeof (ULONGEST)); | |
97 | - | |
98 | - /* Start at the most significant end of the integer, and work towards | |
99 | - the least significant. */ | |
100 | - retval = 0; | |
101 | - if (byte_order == BFD_ENDIAN_BIG) | |
102 | - { | |
103 | - for (p = startaddr; p < endaddr; ++p) | |
104 | - retval = (retval << 8) | *p; | |
105 | - } | |
106 | - else | |
107 | - { | |
108 | - for (p = endaddr - 1; p >= startaddr; --p) | |
109 | - retval = (retval << 8) | *p; | |
110 | - } | |
111 | - return retval; | |
112 | -} | |
113 | - | |
114 | -/* Sometimes a long long unsigned integer can be extracted as a | |
115 | - LONGEST value. This is done so that we can print these values | |
116 | - better. If this integer can be converted to a LONGEST, this | |
117 | - function returns 1 and sets *PVAL. Otherwise it returns 0. */ | |
118 | - | |
119 | -int | |
120 | -extract_long_unsigned_integer (const gdb_byte *addr, int orig_len, | |
121 | - enum bfd_endian byte_order, LONGEST *pval) | |
122 | -{ | |
123 | - const gdb_byte *p; | |
124 | - const gdb_byte *first_addr; | |
125 | - int len; | |
126 | - | |
127 | - len = orig_len; | |
128 | - if (byte_order == BFD_ENDIAN_BIG) | |
129 | - { | |
130 | - for (p = addr; | |
131 | - len > (int) sizeof (LONGEST) && p < addr + orig_len; | |
132 | - p++) | |
133 | - { | |
134 | - if (*p == 0) | |
135 | - len--; | |
136 | - else | |
137 | - break; | |
138 | - } | |
139 | - first_addr = p; | |
140 | - } | |
141 | - else | |
142 | - { | |
143 | - first_addr = addr; | |
144 | - for (p = addr + orig_len - 1; | |
145 | - len > (int) sizeof (LONGEST) && p >= addr; | |
146 | - p--) | |
147 | - { | |
148 | - if (*p == 0) | |
149 | - len--; | |
150 | - else | |
151 | - break; | |
152 | - } | |
153 | - } | |
154 | - | |
155 | - if (len <= (int) sizeof (LONGEST)) | |
156 | - { | |
157 | - *pval = (LONGEST) extract_unsigned_integer (first_addr, | |
158 | - sizeof (LONGEST), | |
159 | - byte_order); | |
160 | - return 1; | |
161 | - } | |
162 | - | |
163 | - return 0; | |
164 | -} | |
165 | - | |
166 | - | |
167 | 37 | /* Treat the bytes at BUF as a pointer of type TYPE, and return the |
168 | 38 | address it represents. */ |
169 | 39 | CORE_ADDR |
@@ -178,65 +48,6 @@ extract_typed_address (const gdb_byte *buf, struct type *type) | ||
178 | 48 | return gdbarch_pointer_to_address (get_type_arch (type), type, buf); |
179 | 49 | } |
180 | 50 | |
181 | -/* All 'store' functions accept a host-format integer and store a | |
182 | - target-format integer at ADDR which is LEN bytes long. */ | |
183 | - | |
184 | -void | |
185 | -store_signed_integer (gdb_byte *addr, int len, | |
186 | - enum bfd_endian byte_order, LONGEST val) | |
187 | -{ | |
188 | - gdb_byte *p; | |
189 | - gdb_byte *startaddr = addr; | |
190 | - gdb_byte *endaddr = startaddr + len; | |
191 | - | |
192 | - /* Start at the least significant end of the integer, and work towards | |
193 | - the most significant. */ | |
194 | - if (byte_order == BFD_ENDIAN_BIG) | |
195 | - { | |
196 | - for (p = endaddr - 1; p >= startaddr; --p) | |
197 | - { | |
198 | - *p = val & 0xff; | |
199 | - val >>= 8; | |
200 | - } | |
201 | - } | |
202 | - else | |
203 | - { | |
204 | - for (p = startaddr; p < endaddr; ++p) | |
205 | - { | |
206 | - *p = val & 0xff; | |
207 | - val >>= 8; | |
208 | - } | |
209 | - } | |
210 | -} | |
211 | - | |
212 | -void | |
213 | -store_unsigned_integer (gdb_byte *addr, int len, | |
214 | - enum bfd_endian byte_order, ULONGEST val) | |
215 | -{ | |
216 | - unsigned char *p; | |
217 | - unsigned char *startaddr = (unsigned char *) addr; | |
218 | - unsigned char *endaddr = startaddr + len; | |
219 | - | |
220 | - /* Start at the least significant end of the integer, and work towards | |
221 | - the most significant. */ | |
222 | - if (byte_order == BFD_ENDIAN_BIG) | |
223 | - { | |
224 | - for (p = endaddr - 1; p >= startaddr; --p) | |
225 | - { | |
226 | - *p = val & 0xff; | |
227 | - val >>= 8; | |
228 | - } | |
229 | - } | |
230 | - else | |
231 | - { | |
232 | - for (p = startaddr; p < endaddr; ++p) | |
233 | - { | |
234 | - *p = val & 0xff; | |
235 | - val >>= 8; | |
236 | - } | |
237 | - } | |
238 | -} | |
239 | - | |
240 | 51 | /* Store the address ADDR as a pointer of type TYPE at BUF, in target |
241 | 52 | form. */ |
242 | 53 | void |