1 /* Register support routines for the remote server for GDB.
2 Copyright (C) 2001, 2002, 2004, 2005, 2007, 2008, 2009, 2010
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 static int register_bytes
;
28 static struct reg
*reg_defs
;
29 static int num_registers
;
31 const char **gdbserver_expedite_regs
;
34 get_thread_regcache (struct thread_info
*thread
, int fetch
)
36 struct regcache
*regcache
;
38 regcache
= (struct regcache
*) inferior_regcache_data (thread
);
41 fatal ("no register cache");
43 if (fetch
&& regcache
->registers_valid
== 0)
45 struct thread_info
*saved_inferior
= current_inferior
;
47 current_inferior
= thread
;
48 fetch_inferior_registers (regcache
, -1);
49 current_inferior
= saved_inferior
;
50 regcache
->registers_valid
= 1;
57 regcache_invalidate_one (struct inferior_list_entry
*entry
)
59 struct thread_info
*thread
= (struct thread_info
*) entry
;
60 struct regcache
*regcache
;
62 regcache
= (struct regcache
*) inferior_regcache_data (thread
);
64 if (regcache
->registers_valid
)
66 struct thread_info
*saved_inferior
= current_inferior
;
68 current_inferior
= thread
;
69 store_inferior_registers (regcache
, -1);
70 current_inferior
= saved_inferior
;
73 regcache
->registers_valid
= 0;
77 regcache_invalidate (void)
79 for_each_inferior (&all_threads
, regcache_invalidate_one
);
83 new_register_cache (void)
85 struct regcache
*regcache
;
87 if (register_bytes
== 0)
88 return NULL
; /* The architecture hasn't been initialized yet. */
90 regcache
= xmalloc (sizeof (*regcache
));
92 /* Make sure to zero-initialize the register cache when it is
93 created, in case there are registers the target never
94 fetches. This way they'll read as zero instead of
96 regcache
->registers
= xcalloc (1, register_bytes
);
98 regcache
->registers_valid
= 0;
104 free_register_cache (struct regcache
*regcache
)
108 free (regcache
->registers
);
114 realloc_register_cache (struct inferior_list_entry
*thread_p
)
116 struct thread_info
*thread
= (struct thread_info
*) thread_p
;
117 struct regcache
*regcache
118 = (struct regcache
*) inferior_regcache_data (thread
);
120 free_register_cache (regcache
);
121 set_inferior_regcache_data (thread
, new_register_cache ());
125 set_register_cache (struct reg
*regs
, int n
)
133 for (i
= 0; i
< n
; i
++)
135 regs
[i
].offset
= offset
;
136 offset
+= regs
[i
].size
;
139 register_bytes
= offset
/ 8;
141 /* Make sure PBUFSIZ is large enough to hold a full register packet. */
142 if (2 * register_bytes
+ 32 > PBUFSIZ
)
143 fatal ("Register packet size exceeds PBUFSIZ.");
145 /* Re-allocate all pre-existing register caches. */
146 for_each_inferior (&all_threads
, realloc_register_cache
);
150 registers_to_string (struct regcache
*regcache
, char *buf
)
152 unsigned char *registers
= regcache
->registers
;
154 convert_int_to_ascii (registers
, buf
, register_bytes
);
158 registers_from_string (struct regcache
*regcache
, char *buf
)
160 int len
= strlen (buf
);
161 unsigned char *registers
= regcache
->registers
;
163 if (len
!= register_bytes
* 2)
165 warning ("Wrong sized register packet (expected %d bytes, got %d)",
166 2*register_bytes
, len
);
167 if (len
> register_bytes
* 2)
168 len
= register_bytes
* 2;
170 convert_ascii_to_int (buf
, registers
, len
/ 2);
174 find_register_by_name (const char *name
)
178 for (i
= 0; i
< num_registers
; i
++)
179 if (!strcmp (name
, reg_defs
[i
].name
))
181 fatal ("Unknown register %s requested", name
);
186 find_regno (const char *name
)
190 for (i
= 0; i
< num_registers
; i
++)
191 if (!strcmp (name
, reg_defs
[i
].name
))
193 fatal ("Unknown register %s requested", name
);
198 find_register_by_number (int n
)
204 register_size (int n
)
206 return reg_defs
[n
].size
/ 8;
209 static unsigned char *
210 register_data (struct regcache
*regcache
, int n
, int fetch
)
212 return regcache
->registers
+ (reg_defs
[n
].offset
/ 8);
216 supply_register (struct regcache
*regcache
, int n
, const void *buf
)
219 memcpy (register_data (regcache
, n
, 0), buf
, register_size (n
));
221 memset (register_data (regcache
, n
, 0), 0, register_size (n
));
225 supply_register_by_name (struct regcache
*regcache
,
226 const char *name
, const void *buf
)
228 supply_register (regcache
, find_regno (name
), buf
);
232 collect_register (struct regcache
*regcache
, int n
, void *buf
)
234 memcpy (buf
, register_data (regcache
, n
, 1), register_size (n
));
238 collect_register_as_string (struct regcache
*regcache
, int n
, char *buf
)
240 convert_int_to_ascii (register_data (regcache
, n
, 1),
241 buf
, register_size (n
));
245 collect_register_by_name (struct regcache
*regcache
,
246 const char *name
, void *buf
)
248 collect_register (regcache
, find_regno (name
), buf
);
This page took 0.035194 seconds and 5 git commands to generate.