1 /* Register support routines for the remote server for GDB.
2 Copyright (C) 2001, 2002, 2004, 2005, 2007, 2008
3 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
26 /* The private data for the register cache. Note that we have one
27 per inferior; this is primarily for simplicity, as the performance
28 benefit is minimal. */
30 struct inferior_regcache_data
33 unsigned char *registers
;
36 static int register_bytes
;
38 static struct reg
*reg_defs
;
39 static int num_registers
;
41 const char **gdbserver_expedite_regs
;
43 static struct inferior_regcache_data
*
44 get_regcache (struct thread_info
*inf
, int fetch
)
46 struct inferior_regcache_data
*regcache
;
48 regcache
= (struct inferior_regcache_data
*) inferior_regcache_data (inf
);
51 fatal ("no register cache");
53 /* FIXME - fetch registers for INF */
54 if (fetch
&& regcache
->registers_valid
== 0)
56 fetch_inferior_registers (0);
57 regcache
->registers_valid
= 1;
64 regcache_invalidate_one (struct inferior_list_entry
*entry
)
66 struct thread_info
*thread
= (struct thread_info
*) entry
;
67 struct inferior_regcache_data
*regcache
;
69 regcache
= (struct inferior_regcache_data
*) inferior_regcache_data (thread
);
71 if (regcache
->registers_valid
)
73 struct thread_info
*saved_inferior
= current_inferior
;
75 current_inferior
= thread
;
76 store_inferior_registers (-1);
77 current_inferior
= saved_inferior
;
80 regcache
->registers_valid
= 0;
84 regcache_invalidate ()
86 for_each_inferior (&all_threads
, regcache_invalidate_one
);
90 registers_length (void)
92 return 2 * register_bytes
;
96 new_register_cache (void)
98 struct inferior_regcache_data
*regcache
;
100 regcache
= malloc (sizeof (*regcache
));
102 /* Make sure to zero-initialize the register cache when it is created,
103 in case there are registers the target never fetches. This way they'll
104 read as zero instead of garbage. */
105 regcache
->registers
= calloc (1, register_bytes
);
106 if (regcache
->registers
== NULL
)
107 fatal ("Could not allocate register cache.");
109 regcache
->registers_valid
= 0;
115 free_register_cache (void *regcache_p
)
117 struct inferior_regcache_data
*regcache
118 = (struct inferior_regcache_data
*) regcache_p
;
120 free (regcache
->registers
);
125 realloc_register_cache (struct inferior_list_entry
*thread_p
)
127 struct thread_info
*thread
= (struct thread_info
*) thread_p
;
129 free_register_cache (inferior_regcache_data (thread
));
130 set_inferior_regcache_data (thread
, new_register_cache ());
134 set_register_cache (struct reg
*regs
, int n
)
142 for (i
= 0; i
< n
; i
++)
144 regs
[i
].offset
= offset
;
145 offset
+= regs
[i
].size
;
148 register_bytes
= offset
/ 8;
150 /* Re-allocate all pre-existing register caches. */
151 for_each_inferior (&all_threads
, realloc_register_cache
);
155 registers_to_string (char *buf
)
157 unsigned char *registers
= get_regcache (current_inferior
, 1)->registers
;
159 convert_int_to_ascii (registers
, buf
, register_bytes
);
163 registers_from_string (char *buf
)
165 int len
= strlen (buf
);
166 unsigned char *registers
= get_regcache (current_inferior
, 1)->registers
;
168 if (len
!= register_bytes
* 2)
170 warning ("Wrong sized register packet (expected %d bytes, got %d)", 2*register_bytes
, len
);
171 if (len
> register_bytes
* 2)
172 len
= register_bytes
* 2;
174 convert_ascii_to_int (buf
, registers
, len
/ 2);
178 find_register_by_name (const char *name
)
182 for (i
= 0; i
< num_registers
; i
++)
183 if (!strcmp (name
, reg_defs
[i
].name
))
185 fatal ("Unknown register %s requested", name
);
190 find_regno (const char *name
)
194 for (i
= 0; i
< num_registers
; i
++)
195 if (!strcmp (name
, reg_defs
[i
].name
))
197 fatal ("Unknown register %s requested", name
);
202 find_register_by_number (int n
)
208 register_size (int n
)
210 return reg_defs
[n
].size
/ 8;
213 static unsigned char *
214 register_data (int n
, int fetch
)
216 unsigned char *registers
217 = get_regcache (current_inferior
, fetch
)->registers
;
219 return registers
+ (reg_defs
[n
].offset
/ 8);
223 supply_register (int n
, const void *buf
)
225 memcpy (register_data (n
, 0), buf
, register_size (n
));
229 supply_register_by_name (const char *name
, const void *buf
)
231 supply_register (find_regno (name
), buf
);
235 collect_register (int n
, void *buf
)
237 memcpy (buf
, register_data (n
, 1), register_size (n
));
241 collect_register_as_string (int n
, char *buf
)
243 convert_int_to_ascii (register_data (n
, 1), buf
, register_size (n
));
247 collect_register_by_name (const char *name
, void *buf
)
249 collect_register (find_regno (name
), buf
);
This page took 0.037359 seconds and 5 git commands to generate.