delete stray changelog
[deliverable/binutils-gdb.git] / gdb / gdbserver / regcache.c
CommitLineData
0a30fbc4
DJ
1/* Register support routines for the remote server for GDB.
2 Copyright 2001, 2002
3 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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22#include "server.h"
23#include "regdef.h"
24
25#include <stdlib.h>
26#include <string.h>
27
a7f48742
DJ
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. */
31
c04a1aa8
DJ
32struct inferior_regcache_data
33{
0d62e5e8 34 int registers_valid;
c04a1aa8
DJ
35 char *registers;
36};
37
0a30fbc4
DJ
38static int register_bytes;
39
40static struct reg *reg_defs;
41static int num_registers;
42
43const char **gdbserver_expedite_regs;
44
c04a1aa8 45static struct inferior_regcache_data *
0d62e5e8 46get_regcache (struct thread_info *inf, int fetch)
c04a1aa8
DJ
47{
48 struct inferior_regcache_data *regcache;
49
50 regcache = (struct inferior_regcache_data *) inferior_regcache_data (inf);
51
52 if (regcache == NULL)
53 fatal ("no register cache");
54
0d62e5e8
DJ
55 /* FIXME - fetch registers for INF */
56 if (fetch && regcache->registers_valid == 0)
57 {
58 fetch_inferior_registers (0);
59 regcache->registers_valid = 1;
60 }
61
c04a1aa8
DJ
62 return regcache;
63}
64
0d62e5e8
DJ
65void
66regcache_invalidate_one (struct inferior_list_entry *entry)
67{
68 struct thread_info *thread = (struct thread_info *) entry;
69 struct inferior_regcache_data *regcache;
70
71 regcache = (struct inferior_regcache_data *) inferior_regcache_data (thread);
72
73 if (regcache->registers_valid)
74 {
75 struct thread_info *saved_inferior = current_inferior;
76
77 current_inferior = thread;
78 store_inferior_registers (-1);
79 current_inferior = saved_inferior;
80 }
81
82 regcache->registers_valid = 0;
83}
84
85void
86regcache_invalidate ()
87{
88 for_each_inferior (&all_threads, regcache_invalidate_one);
89}
90
0a30fbc4
DJ
91int
92registers_length (void)
93{
94 return 2 * register_bytes;
95}
96
0d62e5e8
DJ
97void *
98new_register_cache (void)
c04a1aa8
DJ
99{
100 struct inferior_regcache_data *regcache;
101
102 regcache = malloc (sizeof (*regcache));
103
104 regcache->registers = malloc (register_bytes);
105 if (regcache->registers == NULL)
106 fatal ("Could not allocate register cache.");
107
0d62e5e8
DJ
108 regcache->registers_valid = 0;
109
110 return regcache;
c04a1aa8
DJ
111}
112
113void
0d62e5e8 114free_register_cache (void *regcache_p)
c04a1aa8 115{
0d62e5e8
DJ
116 struct inferior_regcache_data *regcache
117 = (struct inferior_regcache_data *) regcache_p;
118
119 free (regcache->registers);
120 free (regcache);
c04a1aa8
DJ
121}
122
0a30fbc4
DJ
123void
124set_register_cache (struct reg *regs, int n)
125{
126 int offset, i;
127
128 reg_defs = regs;
129 num_registers = n;
130
131 offset = 0;
132 for (i = 0; i < n; i++)
133 {
134 regs[i].offset = offset;
135 offset += regs[i].size;
136 }
137
138 register_bytes = offset / 8;
0a30fbc4
DJ
139}
140
141void
142registers_to_string (char *buf)
143{
0d62e5e8 144 char *registers = get_regcache (current_inferior, 1)->registers;
c04a1aa8 145
0a30fbc4
DJ
146 convert_int_to_ascii (registers, buf, register_bytes);
147}
148
149void
150registers_from_string (char *buf)
151{
152 int len = strlen (buf);
0d62e5e8 153 char *registers = get_regcache (current_inferior, 1)->registers;
0a30fbc4
DJ
154
155 if (len != register_bytes * 2)
156 {
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;
160 }
161 convert_ascii_to_int (buf, registers, len / 2);
162}
163
164struct reg *
165find_register_by_name (const char *name)
166{
167 int i;
168
169 for (i = 0; i < num_registers; i++)
170 if (!strcmp (name, reg_defs[i].name))
171 return &reg_defs[i];
172 fatal ("Unknown register %s requested", name);
173 return 0;
174}
175
176int
177find_regno (const char *name)
178{
179 int i;
180
181 for (i = 0; i < num_registers; i++)
182 if (!strcmp (name, reg_defs[i].name))
183 return i;
184 fatal ("Unknown register %s requested", name);
185 return -1;
186}
187
188struct reg *
189find_register_by_number (int n)
190{
191 return &reg_defs[n];
192}
193
194int
195register_size (int n)
196{
197 return reg_defs[n].size / 8;
198}
199
0d62e5e8
DJ
200static char *
201register_data (int n, int fetch)
0a30fbc4 202{
0d62e5e8 203 char *registers = get_regcache (current_inferior, fetch)->registers;
c04a1aa8 204
0a30fbc4
DJ
205 return registers + (reg_defs[n].offset / 8);
206}
207
58caa3dc 208void
0729219d 209supply_register (int n, const void *buf)
58caa3dc 210{
0d62e5e8 211 memcpy (register_data (n, 0), buf, register_size (n));
58caa3dc
DJ
212}
213
214void
0729219d 215supply_register_by_name (const char *name, const void *buf)
58caa3dc
DJ
216{
217 supply_register (find_regno (name), buf);
218}
219
220void
0729219d 221collect_register (int n, void *buf)
58caa3dc 222{
0d62e5e8
DJ
223 memcpy (buf, register_data (n, 1), register_size (n));
224}
225
226void
227collect_register_as_string (int n, char *buf)
228{
229 convert_int_to_ascii (register_data (n, 1), buf, register_size (n));
58caa3dc
DJ
230}
231
232void
0729219d 233collect_register_by_name (const char *name, void *buf)
58caa3dc
DJ
234{
235 collect_register (find_regno (name), buf);
236}
This page took 0.156035 seconds and 4 git commands to generate.