1 /* Register support routines for the remote server for GDB.
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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
28 /* The private data for the register cache. Note that we have one
29 per inferior; this is primarily for simplicity, as the performance
30 benefit is minimal. */
32 struct inferior_regcache_data
38 static int register_bytes
;
40 static struct reg
*reg_defs
;
41 static int num_registers
;
43 const char **gdbserver_expedite_regs
;
45 static struct inferior_regcache_data
*
46 get_regcache (struct thread_info
*inf
, int fetch
)
48 struct inferior_regcache_data
*regcache
;
50 regcache
= (struct inferior_regcache_data
*) inferior_regcache_data (inf
);
53 fatal ("no register cache");
55 /* FIXME - fetch registers for INF */
56 if (fetch
&& regcache
->registers_valid
== 0)
58 fetch_inferior_registers (0);
59 regcache
->registers_valid
= 1;
66 regcache_invalidate_one (struct inferior_list_entry
*entry
)
68 struct thread_info
*thread
= (struct thread_info
*) entry
;
69 struct inferior_regcache_data
*regcache
;
71 regcache
= (struct inferior_regcache_data
*) inferior_regcache_data (thread
);
73 if (regcache
->registers_valid
)
75 struct thread_info
*saved_inferior
= current_inferior
;
77 current_inferior
= thread
;
78 store_inferior_registers (-1);
79 current_inferior
= saved_inferior
;
82 regcache
->registers_valid
= 0;
86 regcache_invalidate ()
88 for_each_inferior (&all_threads
, regcache_invalidate_one
);
92 registers_length (void)
94 return 2 * register_bytes
;
98 new_register_cache (void)
100 struct inferior_regcache_data
*regcache
;
102 regcache
= malloc (sizeof (*regcache
));
104 regcache
->registers
= malloc (register_bytes
);
105 if (regcache
->registers
== NULL
)
106 fatal ("Could not allocate register cache.");
108 regcache
->registers_valid
= 0;
114 free_register_cache (void *regcache_p
)
116 struct inferior_regcache_data
*regcache
117 = (struct inferior_regcache_data
*) regcache_p
;
119 free (regcache
->registers
);
124 set_register_cache (struct reg
*regs
, int n
)
132 for (i
= 0; i
< n
; i
++)
134 regs
[i
].offset
= offset
;
135 offset
+= regs
[i
].size
;
138 register_bytes
= offset
/ 8;
142 registers_to_string (char *buf
)
144 char *registers
= get_regcache (current_inferior
, 1)->registers
;
146 convert_int_to_ascii (registers
, buf
, register_bytes
);
150 registers_from_string (char *buf
)
152 int len
= strlen (buf
);
153 char *registers
= get_regcache (current_inferior
, 1)->registers
;
155 if (len
!= register_bytes
* 2)
157 warning ("Wrong sized register packet (expected %d bytes, got %d)", 2*register_bytes
, len
);
158 if (len
> register_bytes
* 2)
159 len
= register_bytes
* 2;
161 convert_ascii_to_int (buf
, registers
, len
/ 2);
165 find_register_by_name (const char *name
)
169 for (i
= 0; i
< num_registers
; i
++)
170 if (!strcmp (name
, reg_defs
[i
].name
))
172 fatal ("Unknown register %s requested", name
);
177 find_regno (const char *name
)
181 for (i
= 0; i
< num_registers
; i
++)
182 if (!strcmp (name
, reg_defs
[i
].name
))
184 fatal ("Unknown register %s requested", name
);
189 find_register_by_number (int n
)
195 register_size (int n
)
197 return reg_defs
[n
].size
/ 8;
201 register_data (int n
, int fetch
)
203 char *registers
= get_regcache (current_inferior
, fetch
)->registers
;
205 return registers
+ (reg_defs
[n
].offset
/ 8);
209 supply_register (int n
, const void *buf
)
211 memcpy (register_data (n
, 0), buf
, register_size (n
));
215 supply_register_by_name (const char *name
, const void *buf
)
217 supply_register (find_regno (name
), buf
);
221 collect_register (int n
, void *buf
)
223 memcpy (buf
, register_data (n
, 1), register_size (n
));
227 collect_register_as_string (int n
, char *buf
)
229 convert_int_to_ascii (register_data (n
, 1), buf
, register_size (n
));
233 collect_register_by_name (const char *name
, void *buf
)
235 collect_register (find_regno (name
), buf
);
This page took 0.034771 seconds and 4 git commands to generate.