1 /* Register support routines for the remote server for GDB.
2 Copyright (C) 2001, 2002, 2004, 2005, 2007 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
27 /* The private data for the register cache. Note that we have one
28 per inferior; this is primarily for simplicity, as the performance
29 benefit is minimal. */
31 struct inferior_regcache_data
34 unsigned char *registers
;
37 static int register_bytes
;
39 static struct reg
*reg_defs
;
40 static int num_registers
;
42 const char **gdbserver_expedite_regs
;
44 static struct inferior_regcache_data
*
45 get_regcache (struct thread_info
*inf
, int fetch
)
47 struct inferior_regcache_data
*regcache
;
49 regcache
= (struct inferior_regcache_data
*) inferior_regcache_data (inf
);
52 fatal ("no register cache");
54 /* FIXME - fetch registers for INF */
55 if (fetch
&& regcache
->registers_valid
== 0)
57 fetch_inferior_registers (0);
58 regcache
->registers_valid
= 1;
65 regcache_invalidate_one (struct inferior_list_entry
*entry
)
67 struct thread_info
*thread
= (struct thread_info
*) entry
;
68 struct inferior_regcache_data
*regcache
;
70 regcache
= (struct inferior_regcache_data
*) inferior_regcache_data (thread
);
72 if (regcache
->registers_valid
)
74 struct thread_info
*saved_inferior
= current_inferior
;
76 current_inferior
= thread
;
77 store_inferior_registers (-1);
78 current_inferior
= saved_inferior
;
81 regcache
->registers_valid
= 0;
85 regcache_invalidate ()
87 for_each_inferior (&all_threads
, regcache_invalidate_one
);
91 registers_length (void)
93 return 2 * register_bytes
;
97 new_register_cache (void)
99 struct inferior_regcache_data
*regcache
;
101 regcache
= malloc (sizeof (*regcache
));
103 /* Make sure to zero-initialize the register cache when it is created,
104 in case there are registers the target never fetches. This way they'll
105 read as zero instead of garbage. */
106 regcache
->registers
= calloc (1, register_bytes
);
107 if (regcache
->registers
== NULL
)
108 fatal ("Could not allocate register cache.");
110 regcache
->registers_valid
= 0;
116 free_register_cache (void *regcache_p
)
118 struct inferior_regcache_data
*regcache
119 = (struct inferior_regcache_data
*) regcache_p
;
121 free (regcache
->registers
);
126 set_register_cache (struct reg
*regs
, int n
)
134 for (i
= 0; i
< n
; i
++)
136 regs
[i
].offset
= offset
;
137 offset
+= regs
[i
].size
;
140 register_bytes
= offset
/ 8;
144 registers_to_string (char *buf
)
146 unsigned char *registers
= get_regcache (current_inferior
, 1)->registers
;
148 convert_int_to_ascii (registers
, buf
, register_bytes
);
152 registers_from_string (char *buf
)
154 int len
= strlen (buf
);
155 unsigned char *registers
= get_regcache (current_inferior
, 1)->registers
;
157 if (len
!= register_bytes
* 2)
159 warning ("Wrong sized register packet (expected %d bytes, got %d)", 2*register_bytes
, len
);
160 if (len
> register_bytes
* 2)
161 len
= register_bytes
* 2;
163 convert_ascii_to_int (buf
, registers
, len
/ 2);
167 find_register_by_name (const char *name
)
171 for (i
= 0; i
< num_registers
; i
++)
172 if (!strcmp (name
, reg_defs
[i
].name
))
174 fatal ("Unknown register %s requested", name
);
179 find_regno (const char *name
)
183 for (i
= 0; i
< num_registers
; i
++)
184 if (!strcmp (name
, reg_defs
[i
].name
))
186 fatal ("Unknown register %s requested", name
);
191 find_register_by_number (int n
)
197 register_size (int n
)
199 return reg_defs
[n
].size
/ 8;
202 static unsigned char *
203 register_data (int n
, int fetch
)
205 unsigned char *registers
206 = get_regcache (current_inferior
, fetch
)->registers
;
208 return registers
+ (reg_defs
[n
].offset
/ 8);
212 supply_register (int n
, const void *buf
)
214 memcpy (register_data (n
, 0), buf
, register_size (n
));
218 supply_register_by_name (const char *name
, const void *buf
)
220 supply_register (find_regno (name
), buf
);
224 collect_register (int n
, void *buf
)
226 memcpy (buf
, register_data (n
, 1), register_size (n
));
230 collect_register_as_string (int n
, char *buf
)
232 convert_int_to_ascii (register_data (n
, 1), buf
, register_size (n
));
236 collect_register_by_name (const char *name
, void *buf
)
238 collect_register (find_regno (name
), buf
);
This page took 0.034229 seconds and 4 git commands to generate.