Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Select target systems and architectures at runtime for GDB. |
7998dfc3 | 2 | |
6aba47ca | 3 | Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
9b254dd1 | 4 | 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
f6519ebc | 5 | Free Software Foundation, Inc. |
7998dfc3 | 6 | |
c906108c SS |
7 | Contributed by Cygnus Support. |
8 | ||
c5aa993b | 9 | This file is part of GDB. |
c906108c | 10 | |
c5aa993b JM |
11 | This program is free software; you can redistribute it and/or modify |
12 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 13 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 14 | (at your option) any later version. |
c906108c | 15 | |
c5aa993b JM |
16 | This program is distributed in the hope that it will be useful, |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
c906108c | 20 | |
c5aa993b | 21 | You should have received a copy of the GNU General Public License |
a9762ec7 | 22 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
23 | |
24 | #include "defs.h" | |
25 | #include <errno.h> | |
c906108c SS |
26 | #include "gdb_string.h" |
27 | #include "target.h" | |
28 | #include "gdbcmd.h" | |
29 | #include "symtab.h" | |
30 | #include "inferior.h" | |
31 | #include "bfd.h" | |
32 | #include "symfile.h" | |
33 | #include "objfiles.h" | |
03f2053f | 34 | #include "gdb_wait.h" |
4930751a | 35 | #include "dcache.h" |
c906108c | 36 | #include <signal.h> |
4e052eda | 37 | #include "regcache.h" |
0088c768 | 38 | #include "gdb_assert.h" |
b6591e8b | 39 | #include "gdbcore.h" |
9e35dae4 | 40 | #include "exceptions.h" |
424163ea | 41 | #include "target-descriptions.h" |
8defab1a | 42 | #include "gdb_stdint.h" |
c906108c | 43 | |
a14ed312 | 44 | static void target_info (char *, int); |
c906108c | 45 | |
a14ed312 | 46 | static void maybe_kill_then_attach (char *, int); |
c906108c | 47 | |
a14ed312 | 48 | static void kill_or_be_killed (int); |
c906108c | 49 | |
a14ed312 | 50 | static void default_terminal_info (char *, int); |
c906108c | 51 | |
e0d24f8d WZ |
52 | static int default_region_ok_for_hw_watchpoint (CORE_ADDR, int); |
53 | ||
a14ed312 | 54 | static int nosymbol (char *, CORE_ADDR *); |
c906108c | 55 | |
4ecb6f27 | 56 | static void tcomplain (void) ATTR_NORETURN; |
c906108c | 57 | |
a14ed312 | 58 | static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *); |
c906108c | 59 | |
a14ed312 | 60 | static int return_zero (void); |
c906108c | 61 | |
a14ed312 | 62 | static int return_one (void); |
c906108c | 63 | |
ccaa32c7 GS |
64 | static int return_minus_one (void); |
65 | ||
a14ed312 | 66 | void target_ignore (void); |
c906108c | 67 | |
a14ed312 | 68 | static void target_command (char *, int); |
c906108c | 69 | |
a14ed312 | 70 | static struct target_ops *find_default_run_target (char *); |
c906108c | 71 | |
a14ed312 | 72 | static void nosupport_runtime (void); |
392a587b | 73 | |
4b8a223f | 74 | static LONGEST default_xfer_partial (struct target_ops *ops, |
0088c768 | 75 | enum target_object object, |
1b0ba102 AC |
76 | const char *annex, gdb_byte *readbuf, |
77 | const gdb_byte *writebuf, | |
8aa91c1e | 78 | ULONGEST offset, LONGEST len); |
0088c768 | 79 | |
cf7a04e8 DJ |
80 | static LONGEST current_xfer_partial (struct target_ops *ops, |
81 | enum target_object object, | |
82 | const char *annex, gdb_byte *readbuf, | |
83 | const gdb_byte *writebuf, | |
84 | ULONGEST offset, LONGEST len); | |
c906108c | 85 | |
cf7a04e8 DJ |
86 | static LONGEST target_xfer_partial (struct target_ops *ops, |
87 | enum target_object object, | |
88 | const char *annex, | |
89 | void *readbuf, const void *writebuf, | |
90 | ULONGEST offset, LONGEST len); | |
c906108c | 91 | |
a14ed312 | 92 | static void init_dummy_target (void); |
c906108c | 93 | |
aa869812 AC |
94 | static struct target_ops debug_target; |
95 | ||
a14ed312 | 96 | static void debug_to_open (char *, int); |
c906108c | 97 | |
a14ed312 | 98 | static void debug_to_close (int); |
c906108c | 99 | |
a14ed312 | 100 | static void debug_to_attach (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static void debug_to_detach (char *, int); |
c906108c | 103 | |
39f77062 | 104 | static void debug_to_resume (ptid_t, int, enum target_signal); |
c906108c | 105 | |
39f77062 | 106 | static ptid_t debug_to_wait (ptid_t, struct target_waitstatus *); |
c906108c | 107 | |
56be3814 | 108 | static void debug_to_fetch_registers (struct regcache *, int); |
c906108c | 109 | |
56be3814 | 110 | static void debug_to_store_registers (struct regcache *, int); |
c906108c | 111 | |
316f2060 | 112 | static void debug_to_prepare_to_store (struct regcache *); |
c906108c | 113 | |
a14ed312 | 114 | static void debug_to_files_info (struct target_ops *); |
c906108c | 115 | |
8181d85f | 116 | static int debug_to_insert_breakpoint (struct bp_target_info *); |
c906108c | 117 | |
8181d85f | 118 | static int debug_to_remove_breakpoint (struct bp_target_info *); |
c906108c | 119 | |
ccaa32c7 GS |
120 | static int debug_to_can_use_hw_breakpoint (int, int, int); |
121 | ||
8181d85f | 122 | static int debug_to_insert_hw_breakpoint (struct bp_target_info *); |
ccaa32c7 | 123 | |
8181d85f | 124 | static int debug_to_remove_hw_breakpoint (struct bp_target_info *); |
ccaa32c7 GS |
125 | |
126 | static int debug_to_insert_watchpoint (CORE_ADDR, int, int); | |
127 | ||
128 | static int debug_to_remove_watchpoint (CORE_ADDR, int, int); | |
129 | ||
130 | static int debug_to_stopped_by_watchpoint (void); | |
131 | ||
4aa7a7f5 | 132 | static int debug_to_stopped_data_address (struct target_ops *, CORE_ADDR *); |
ccaa32c7 | 133 | |
e0d24f8d WZ |
134 | static int debug_to_region_ok_for_hw_watchpoint (CORE_ADDR, int); |
135 | ||
a14ed312 | 136 | static void debug_to_terminal_init (void); |
c906108c | 137 | |
a14ed312 | 138 | static void debug_to_terminal_inferior (void); |
c906108c | 139 | |
a14ed312 | 140 | static void debug_to_terminal_ours_for_output (void); |
c906108c | 141 | |
a790ad35 SC |
142 | static void debug_to_terminal_save_ours (void); |
143 | ||
a14ed312 | 144 | static void debug_to_terminal_ours (void); |
c906108c | 145 | |
a14ed312 | 146 | static void debug_to_terminal_info (char *, int); |
c906108c | 147 | |
a14ed312 | 148 | static void debug_to_kill (void); |
c906108c | 149 | |
a14ed312 | 150 | static void debug_to_load (char *, int); |
c906108c | 151 | |
a14ed312 | 152 | static int debug_to_lookup_symbol (char *, CORE_ADDR *); |
c906108c | 153 | |
a14ed312 | 154 | static void debug_to_mourn_inferior (void); |
c906108c | 155 | |
a14ed312 | 156 | static int debug_to_can_run (void); |
c906108c | 157 | |
39f77062 | 158 | static void debug_to_notice_signals (ptid_t); |
c906108c | 159 | |
39f77062 | 160 | static int debug_to_thread_alive (ptid_t); |
c906108c | 161 | |
a14ed312 | 162 | static void debug_to_stop (void); |
c906108c | 163 | |
5ac10fd1 AC |
164 | /* NOTE: cagney/2004-09-29: Many targets reference this variable in |
165 | wierd and mysterious ways. Putting the variable here lets those | |
166 | wierd and mysterious ways keep building while they are being | |
167 | converted to the inferior inheritance structure. */ | |
1df84f13 | 168 | struct target_ops deprecated_child_ops; |
5ac10fd1 | 169 | |
c906108c | 170 | /* Pointer to array of target architecture structures; the size of the |
2bc416ba | 171 | array; the current index into the array; the allocated size of the |
c906108c SS |
172 | array. */ |
173 | struct target_ops **target_structs; | |
174 | unsigned target_struct_size; | |
175 | unsigned target_struct_index; | |
176 | unsigned target_struct_allocsize; | |
177 | #define DEFAULT_ALLOCSIZE 10 | |
178 | ||
179 | /* The initial current target, so that there is always a semi-valid | |
180 | current target. */ | |
181 | ||
182 | static struct target_ops dummy_target; | |
183 | ||
184 | /* Top of target stack. */ | |
185 | ||
258b763a | 186 | static struct target_ops *target_stack; |
c906108c SS |
187 | |
188 | /* The target structure we are currently using to talk to a process | |
189 | or file or whatever "inferior" we have. */ | |
190 | ||
191 | struct target_ops current_target; | |
192 | ||
193 | /* Command list for target. */ | |
194 | ||
195 | static struct cmd_list_element *targetlist = NULL; | |
196 | ||
197 | /* Nonzero if we are debugging an attached outside process | |
198 | rather than an inferior. */ | |
199 | ||
200 | int attach_flag; | |
201 | ||
cf7a04e8 DJ |
202 | /* Nonzero if we should trust readonly sections from the |
203 | executable when reading memory. */ | |
204 | ||
205 | static int trust_readonly = 0; | |
206 | ||
8defab1a DJ |
207 | /* Nonzero if we should show true memory content including |
208 | memory breakpoint inserted by gdb. */ | |
209 | ||
210 | static int show_memory_breakpoints = 0; | |
211 | ||
c906108c SS |
212 | /* Non-zero if we want to see trace of target level stuff. */ |
213 | ||
214 | static int targetdebug = 0; | |
920d2a44 AC |
215 | static void |
216 | show_targetdebug (struct ui_file *file, int from_tty, | |
217 | struct cmd_list_element *c, const char *value) | |
218 | { | |
219 | fprintf_filtered (file, _("Target debugging is %s.\n"), value); | |
220 | } | |
c906108c | 221 | |
a14ed312 | 222 | static void setup_target_debug (void); |
c906108c | 223 | |
4930751a C |
224 | DCACHE *target_dcache; |
225 | ||
c906108c SS |
226 | /* The user just typed 'target' without the name of a target. */ |
227 | ||
c906108c | 228 | static void |
fba45db2 | 229 | target_command (char *arg, int from_tty) |
c906108c SS |
230 | { |
231 | fputs_filtered ("Argument required (target name). Try `help target'\n", | |
232 | gdb_stdout); | |
233 | } | |
234 | ||
235 | /* Add a possible target architecture to the list. */ | |
236 | ||
237 | void | |
fba45db2 | 238 | add_target (struct target_ops *t) |
c906108c | 239 | { |
0088c768 | 240 | /* Provide default values for all "must have" methods. */ |
0b603eba AC |
241 | if (t->to_xfer_partial == NULL) |
242 | t->to_xfer_partial = default_xfer_partial; | |
0088c768 | 243 | |
c906108c SS |
244 | if (!target_structs) |
245 | { | |
246 | target_struct_allocsize = DEFAULT_ALLOCSIZE; | |
247 | target_structs = (struct target_ops **) xmalloc | |
248 | (target_struct_allocsize * sizeof (*target_structs)); | |
249 | } | |
250 | if (target_struct_size >= target_struct_allocsize) | |
251 | { | |
252 | target_struct_allocsize *= 2; | |
253 | target_structs = (struct target_ops **) | |
c5aa993b JM |
254 | xrealloc ((char *) target_structs, |
255 | target_struct_allocsize * sizeof (*target_structs)); | |
c906108c SS |
256 | } |
257 | target_structs[target_struct_size++] = t; | |
c906108c SS |
258 | |
259 | if (targetlist == NULL) | |
1bedd215 AC |
260 | add_prefix_cmd ("target", class_run, target_command, _("\ |
261 | Connect to a target machine or process.\n\ | |
c906108c SS |
262 | The first argument is the type or protocol of the target machine.\n\ |
263 | Remaining arguments are interpreted by the target protocol. For more\n\ | |
264 | information on the arguments for a particular protocol, type\n\ | |
1bedd215 | 265 | `help target ' followed by the protocol name."), |
c906108c SS |
266 | &targetlist, "target ", 0, &cmdlist); |
267 | add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist); | |
268 | } | |
269 | ||
270 | /* Stub functions */ | |
271 | ||
272 | void | |
fba45db2 | 273 | target_ignore (void) |
c906108c SS |
274 | { |
275 | } | |
276 | ||
11cf8741 JM |
277 | void |
278 | target_load (char *arg, int from_tty) | |
279 | { | |
4930751a | 280 | dcache_invalidate (target_dcache); |
11cf8741 JM |
281 | (*current_target.to_load) (arg, from_tty); |
282 | } | |
283 | ||
c906108c | 284 | static int |
fba45db2 KB |
285 | nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write, |
286 | struct target_ops *t) | |
c906108c | 287 | { |
c5aa993b JM |
288 | errno = EIO; /* Can't read/write this location */ |
289 | return 0; /* No bytes handled */ | |
c906108c SS |
290 | } |
291 | ||
292 | static void | |
fba45db2 | 293 | tcomplain (void) |
c906108c | 294 | { |
8a3fe4f8 | 295 | error (_("You can't do that when your target is `%s'"), |
c906108c SS |
296 | current_target.to_shortname); |
297 | } | |
298 | ||
299 | void | |
fba45db2 | 300 | noprocess (void) |
c906108c | 301 | { |
8a3fe4f8 | 302 | error (_("You can't do that without a process to debug.")); |
c906108c SS |
303 | } |
304 | ||
c906108c | 305 | static int |
fba45db2 | 306 | nosymbol (char *name, CORE_ADDR *addrp) |
c906108c | 307 | { |
c5aa993b | 308 | return 1; /* Symbol does not exist in target env */ |
c906108c SS |
309 | } |
310 | ||
392a587b | 311 | static void |
fba45db2 | 312 | nosupport_runtime (void) |
c906108c | 313 | { |
39f77062 | 314 | if (ptid_equal (inferior_ptid, null_ptid)) |
c906108c SS |
315 | noprocess (); |
316 | else | |
8a3fe4f8 | 317 | error (_("No run-time support for this")); |
c906108c SS |
318 | } |
319 | ||
320 | ||
c906108c | 321 | static void |
fba45db2 | 322 | default_terminal_info (char *args, int from_tty) |
c906108c | 323 | { |
a3f17187 | 324 | printf_unfiltered (_("No saved terminal information.\n")); |
c906108c SS |
325 | } |
326 | ||
327 | /* This is the default target_create_inferior and target_attach function. | |
328 | If the current target is executing, it asks whether to kill it off. | |
329 | If this function returns without calling error(), it has killed off | |
330 | the target, and the operation should be attempted. */ | |
331 | ||
332 | static void | |
fba45db2 | 333 | kill_or_be_killed (int from_tty) |
c906108c SS |
334 | { |
335 | if (target_has_execution) | |
336 | { | |
a3f17187 | 337 | printf_unfiltered (_("You are already running a program:\n")); |
c906108c | 338 | target_files_info (); |
c5aa993b JM |
339 | if (query ("Kill it? ")) |
340 | { | |
341 | target_kill (); | |
342 | if (target_has_execution) | |
8a3fe4f8 | 343 | error (_("Killing the program did not help.")); |
c5aa993b JM |
344 | return; |
345 | } | |
346 | else | |
347 | { | |
8a3fe4f8 | 348 | error (_("Program not killed.")); |
c5aa993b | 349 | } |
c906108c | 350 | } |
c5aa993b | 351 | tcomplain (); |
c906108c SS |
352 | } |
353 | ||
354 | static void | |
fba45db2 | 355 | maybe_kill_then_attach (char *args, int from_tty) |
c906108c SS |
356 | { |
357 | kill_or_be_killed (from_tty); | |
358 | target_attach (args, from_tty); | |
359 | } | |
360 | ||
361 | static void | |
c27cda74 AC |
362 | maybe_kill_then_create_inferior (char *exec, char *args, char **env, |
363 | int from_tty) | |
c906108c SS |
364 | { |
365 | kill_or_be_killed (0); | |
c27cda74 | 366 | target_create_inferior (exec, args, env, from_tty); |
c906108c SS |
367 | } |
368 | ||
7998dfc3 AC |
369 | /* Go through the target stack from top to bottom, copying over zero |
370 | entries in current_target, then filling in still empty entries. In | |
371 | effect, we are doing class inheritance through the pushed target | |
372 | vectors. | |
373 | ||
374 | NOTE: cagney/2003-10-17: The problem with this inheritance, as it | |
375 | is currently implemented, is that it discards any knowledge of | |
376 | which target an inherited method originally belonged to. | |
377 | Consequently, new new target methods should instead explicitly and | |
378 | locally search the target stack for the target that can handle the | |
379 | request. */ | |
c906108c SS |
380 | |
381 | static void | |
7998dfc3 | 382 | update_current_target (void) |
c906108c | 383 | { |
7998dfc3 AC |
384 | struct target_ops *t; |
385 | ||
08d8bcd7 | 386 | /* First, reset current's contents. */ |
7998dfc3 AC |
387 | memset (¤t_target, 0, sizeof (current_target)); |
388 | ||
389 | #define INHERIT(FIELD, TARGET) \ | |
390 | if (!current_target.FIELD) \ | |
391 | current_target.FIELD = (TARGET)->FIELD | |
392 | ||
393 | for (t = target_stack; t; t = t->beneath) | |
394 | { | |
395 | INHERIT (to_shortname, t); | |
396 | INHERIT (to_longname, t); | |
397 | INHERIT (to_doc, t); | |
398 | INHERIT (to_open, t); | |
399 | INHERIT (to_close, t); | |
400 | INHERIT (to_attach, t); | |
401 | INHERIT (to_post_attach, t); | |
402 | INHERIT (to_detach, t); | |
597320e7 | 403 | /* Do not inherit to_disconnect. */ |
7998dfc3 AC |
404 | INHERIT (to_resume, t); |
405 | INHERIT (to_wait, t); | |
7998dfc3 AC |
406 | INHERIT (to_fetch_registers, t); |
407 | INHERIT (to_store_registers, t); | |
408 | INHERIT (to_prepare_to_store, t); | |
c8e73a31 | 409 | INHERIT (deprecated_xfer_memory, t); |
7998dfc3 AC |
410 | INHERIT (to_files_info, t); |
411 | INHERIT (to_insert_breakpoint, t); | |
412 | INHERIT (to_remove_breakpoint, t); | |
413 | INHERIT (to_can_use_hw_breakpoint, t); | |
414 | INHERIT (to_insert_hw_breakpoint, t); | |
415 | INHERIT (to_remove_hw_breakpoint, t); | |
416 | INHERIT (to_insert_watchpoint, t); | |
417 | INHERIT (to_remove_watchpoint, t); | |
418 | INHERIT (to_stopped_data_address, t); | |
419 | INHERIT (to_stopped_by_watchpoint, t); | |
74174d2e | 420 | INHERIT (to_have_steppable_watchpoint, t); |
7998dfc3 | 421 | INHERIT (to_have_continuable_watchpoint, t); |
e0d24f8d | 422 | INHERIT (to_region_ok_for_hw_watchpoint, t); |
7998dfc3 AC |
423 | INHERIT (to_terminal_init, t); |
424 | INHERIT (to_terminal_inferior, t); | |
425 | INHERIT (to_terminal_ours_for_output, t); | |
426 | INHERIT (to_terminal_ours, t); | |
427 | INHERIT (to_terminal_save_ours, t); | |
428 | INHERIT (to_terminal_info, t); | |
429 | INHERIT (to_kill, t); | |
430 | INHERIT (to_load, t); | |
431 | INHERIT (to_lookup_symbol, t); | |
432 | INHERIT (to_create_inferior, t); | |
433 | INHERIT (to_post_startup_inferior, t); | |
434 | INHERIT (to_acknowledge_created_inferior, t); | |
435 | INHERIT (to_insert_fork_catchpoint, t); | |
436 | INHERIT (to_remove_fork_catchpoint, t); | |
437 | INHERIT (to_insert_vfork_catchpoint, t); | |
438 | INHERIT (to_remove_vfork_catchpoint, t); | |
ee057212 | 439 | /* Do not inherit to_follow_fork. */ |
7998dfc3 AC |
440 | INHERIT (to_insert_exec_catchpoint, t); |
441 | INHERIT (to_remove_exec_catchpoint, t); | |
442 | INHERIT (to_reported_exec_events_per_exec_call, t); | |
443 | INHERIT (to_has_exited, t); | |
444 | INHERIT (to_mourn_inferior, t); | |
445 | INHERIT (to_can_run, t); | |
446 | INHERIT (to_notice_signals, t); | |
447 | INHERIT (to_thread_alive, t); | |
448 | INHERIT (to_find_new_threads, t); | |
449 | INHERIT (to_pid_to_str, t); | |
450 | INHERIT (to_extra_thread_info, t); | |
451 | INHERIT (to_stop, t); | |
4b8a223f | 452 | /* Do not inherit to_xfer_partial. */ |
7998dfc3 | 453 | INHERIT (to_rcmd, t); |
7998dfc3 | 454 | INHERIT (to_pid_to_exec_file, t); |
49d03eab | 455 | INHERIT (to_log_command, t); |
7998dfc3 AC |
456 | INHERIT (to_stratum, t); |
457 | INHERIT (to_has_all_memory, t); | |
458 | INHERIT (to_has_memory, t); | |
459 | INHERIT (to_has_stack, t); | |
460 | INHERIT (to_has_registers, t); | |
461 | INHERIT (to_has_execution, t); | |
462 | INHERIT (to_has_thread_control, t); | |
463 | INHERIT (to_sections, t); | |
464 | INHERIT (to_sections_end, t); | |
465 | INHERIT (to_can_async_p, t); | |
466 | INHERIT (to_is_async_p, t); | |
467 | INHERIT (to_async, t); | |
468 | INHERIT (to_async_mask_value, t); | |
469 | INHERIT (to_find_memory_regions, t); | |
470 | INHERIT (to_make_corefile_notes, t); | |
471 | INHERIT (to_get_thread_local_address, t); | |
424163ea | 472 | /* Do not inherit to_read_description. */ |
7998dfc3 | 473 | INHERIT (to_magic, t); |
fd79ecee | 474 | /* Do not inherit to_memory_map. */ |
a76d924d DJ |
475 | /* Do not inherit to_flash_erase. */ |
476 | /* Do not inherit to_flash_done. */ | |
7998dfc3 AC |
477 | } |
478 | #undef INHERIT | |
479 | ||
480 | /* Clean up a target struct so it no longer has any zero pointers in | |
0088c768 AC |
481 | it. Some entries are defaulted to a method that print an error, |
482 | others are hard-wired to a standard recursive default. */ | |
c906108c SS |
483 | |
484 | #define de_fault(field, value) \ | |
7998dfc3 AC |
485 | if (!current_target.field) \ |
486 | current_target.field = value | |
0d06e24b | 487 | |
2bc416ba DJ |
488 | de_fault (to_open, |
489 | (void (*) (char *, int)) | |
0d06e24b | 490 | tcomplain); |
2bc416ba DJ |
491 | de_fault (to_close, |
492 | (void (*) (int)) | |
0d06e24b | 493 | target_ignore); |
2bc416ba | 494 | de_fault (to_attach, |
0d06e24b | 495 | maybe_kill_then_attach); |
2bc416ba DJ |
496 | de_fault (to_post_attach, |
497 | (void (*) (int)) | |
0d06e24b | 498 | target_ignore); |
2bc416ba DJ |
499 | de_fault (to_detach, |
500 | (void (*) (char *, int)) | |
0d06e24b | 501 | target_ignore); |
2bc416ba DJ |
502 | de_fault (to_resume, |
503 | (void (*) (ptid_t, int, enum target_signal)) | |
0d06e24b | 504 | noprocess); |
2bc416ba DJ |
505 | de_fault (to_wait, |
506 | (ptid_t (*) (ptid_t, struct target_waitstatus *)) | |
0d06e24b | 507 | noprocess); |
2bc416ba | 508 | de_fault (to_fetch_registers, |
56be3814 | 509 | (void (*) (struct regcache *, int)) |
0d06e24b | 510 | target_ignore); |
2bc416ba | 511 | de_fault (to_store_registers, |
56be3814 | 512 | (void (*) (struct regcache *, int)) |
0d06e24b | 513 | noprocess); |
2bc416ba | 514 | de_fault (to_prepare_to_store, |
316f2060 | 515 | (void (*) (struct regcache *)) |
0d06e24b | 516 | noprocess); |
2bc416ba DJ |
517 | de_fault (deprecated_xfer_memory, |
518 | (int (*) (CORE_ADDR, gdb_byte *, int, int, struct mem_attrib *, struct target_ops *)) | |
0d06e24b | 519 | nomemory); |
2bc416ba DJ |
520 | de_fault (to_files_info, |
521 | (void (*) (struct target_ops *)) | |
0d06e24b | 522 | target_ignore); |
2bc416ba | 523 | de_fault (to_insert_breakpoint, |
0d06e24b | 524 | memory_insert_breakpoint); |
2bc416ba | 525 | de_fault (to_remove_breakpoint, |
0d06e24b | 526 | memory_remove_breakpoint); |
ccaa32c7 GS |
527 | de_fault (to_can_use_hw_breakpoint, |
528 | (int (*) (int, int, int)) | |
529 | return_zero); | |
530 | de_fault (to_insert_hw_breakpoint, | |
8181d85f | 531 | (int (*) (struct bp_target_info *)) |
ccaa32c7 GS |
532 | return_minus_one); |
533 | de_fault (to_remove_hw_breakpoint, | |
8181d85f | 534 | (int (*) (struct bp_target_info *)) |
ccaa32c7 GS |
535 | return_minus_one); |
536 | de_fault (to_insert_watchpoint, | |
537 | (int (*) (CORE_ADDR, int, int)) | |
538 | return_minus_one); | |
539 | de_fault (to_remove_watchpoint, | |
540 | (int (*) (CORE_ADDR, int, int)) | |
541 | return_minus_one); | |
542 | de_fault (to_stopped_by_watchpoint, | |
543 | (int (*) (void)) | |
544 | return_zero); | |
545 | de_fault (to_stopped_data_address, | |
4aa7a7f5 | 546 | (int (*) (struct target_ops *, CORE_ADDR *)) |
ccaa32c7 | 547 | return_zero); |
e0d24f8d WZ |
548 | de_fault (to_region_ok_for_hw_watchpoint, |
549 | default_region_ok_for_hw_watchpoint); | |
2bc416ba DJ |
550 | de_fault (to_terminal_init, |
551 | (void (*) (void)) | |
0d06e24b | 552 | target_ignore); |
2bc416ba DJ |
553 | de_fault (to_terminal_inferior, |
554 | (void (*) (void)) | |
0d06e24b | 555 | target_ignore); |
2bc416ba DJ |
556 | de_fault (to_terminal_ours_for_output, |
557 | (void (*) (void)) | |
0d06e24b | 558 | target_ignore); |
2bc416ba DJ |
559 | de_fault (to_terminal_ours, |
560 | (void (*) (void)) | |
0d06e24b | 561 | target_ignore); |
2bc416ba DJ |
562 | de_fault (to_terminal_save_ours, |
563 | (void (*) (void)) | |
a790ad35 | 564 | target_ignore); |
2bc416ba | 565 | de_fault (to_terminal_info, |
0d06e24b | 566 | default_terminal_info); |
2bc416ba DJ |
567 | de_fault (to_kill, |
568 | (void (*) (void)) | |
0d06e24b | 569 | noprocess); |
2bc416ba DJ |
570 | de_fault (to_load, |
571 | (void (*) (char *, int)) | |
0d06e24b | 572 | tcomplain); |
2bc416ba DJ |
573 | de_fault (to_lookup_symbol, |
574 | (int (*) (char *, CORE_ADDR *)) | |
0d06e24b | 575 | nosymbol); |
2bc416ba | 576 | de_fault (to_create_inferior, |
0d06e24b | 577 | maybe_kill_then_create_inferior); |
2bc416ba DJ |
578 | de_fault (to_post_startup_inferior, |
579 | (void (*) (ptid_t)) | |
0d06e24b | 580 | target_ignore); |
2bc416ba DJ |
581 | de_fault (to_acknowledge_created_inferior, |
582 | (void (*) (int)) | |
0d06e24b | 583 | target_ignore); |
2bc416ba DJ |
584 | de_fault (to_insert_fork_catchpoint, |
585 | (void (*) (int)) | |
0d06e24b | 586 | tcomplain); |
2bc416ba DJ |
587 | de_fault (to_remove_fork_catchpoint, |
588 | (int (*) (int)) | |
0d06e24b | 589 | tcomplain); |
2bc416ba DJ |
590 | de_fault (to_insert_vfork_catchpoint, |
591 | (void (*) (int)) | |
0d06e24b | 592 | tcomplain); |
2bc416ba DJ |
593 | de_fault (to_remove_vfork_catchpoint, |
594 | (int (*) (int)) | |
0d06e24b | 595 | tcomplain); |
2bc416ba DJ |
596 | de_fault (to_insert_exec_catchpoint, |
597 | (void (*) (int)) | |
0d06e24b | 598 | tcomplain); |
2bc416ba DJ |
599 | de_fault (to_remove_exec_catchpoint, |
600 | (int (*) (int)) | |
0d06e24b | 601 | tcomplain); |
2bc416ba DJ |
602 | de_fault (to_reported_exec_events_per_exec_call, |
603 | (int (*) (void)) | |
0d06e24b | 604 | return_one); |
2bc416ba DJ |
605 | de_fault (to_has_exited, |
606 | (int (*) (int, int, int *)) | |
0d06e24b | 607 | return_zero); |
2bc416ba DJ |
608 | de_fault (to_mourn_inferior, |
609 | (void (*) (void)) | |
0d06e24b | 610 | noprocess); |
2bc416ba | 611 | de_fault (to_can_run, |
0d06e24b | 612 | return_zero); |
2bc416ba DJ |
613 | de_fault (to_notice_signals, |
614 | (void (*) (ptid_t)) | |
0d06e24b | 615 | target_ignore); |
2bc416ba DJ |
616 | de_fault (to_thread_alive, |
617 | (int (*) (ptid_t)) | |
0d06e24b | 618 | return_zero); |
2bc416ba DJ |
619 | de_fault (to_find_new_threads, |
620 | (void (*) (void)) | |
0d06e24b | 621 | target_ignore); |
2bc416ba DJ |
622 | de_fault (to_extra_thread_info, |
623 | (char *(*) (struct thread_info *)) | |
0d06e24b | 624 | return_zero); |
2bc416ba DJ |
625 | de_fault (to_stop, |
626 | (void (*) (void)) | |
0d06e24b | 627 | target_ignore); |
cf7a04e8 | 628 | current_target.to_xfer_partial = current_xfer_partial; |
2bc416ba DJ |
629 | de_fault (to_rcmd, |
630 | (void (*) (char *, struct ui_file *)) | |
0d06e24b | 631 | tcomplain); |
2bc416ba DJ |
632 | de_fault (to_pid_to_exec_file, |
633 | (char *(*) (int)) | |
0d06e24b | 634 | return_zero); |
2bc416ba DJ |
635 | de_fault (to_can_async_p, |
636 | (int (*) (void)) | |
0d06e24b | 637 | return_zero); |
2bc416ba DJ |
638 | de_fault (to_is_async_p, |
639 | (int (*) (void)) | |
0d06e24b | 640 | return_zero); |
2bc416ba DJ |
641 | de_fault (to_async, |
642 | (void (*) (void (*) (enum inferior_event_type, void*), void*)) | |
0d06e24b | 643 | tcomplain); |
424163ea | 644 | current_target.to_read_description = NULL; |
c906108c | 645 | #undef de_fault |
c906108c | 646 | |
7998dfc3 AC |
647 | /* Finally, position the target-stack beneath the squashed |
648 | "current_target". That way code looking for a non-inherited | |
649 | target method can quickly and simply find it. */ | |
650 | current_target.beneath = target_stack; | |
b4b61fdb DJ |
651 | |
652 | if (targetdebug) | |
653 | setup_target_debug (); | |
c906108c SS |
654 | } |
655 | ||
52bb452f DJ |
656 | /* Mark OPS as a running target. This reverses the effect |
657 | of target_mark_exited. */ | |
658 | ||
659 | void | |
660 | target_mark_running (struct target_ops *ops) | |
661 | { | |
662 | struct target_ops *t; | |
663 | ||
664 | for (t = target_stack; t != NULL; t = t->beneath) | |
665 | if (t == ops) | |
666 | break; | |
667 | if (t == NULL) | |
668 | internal_error (__FILE__, __LINE__, | |
669 | "Attempted to mark unpushed target \"%s\" as running", | |
670 | ops->to_shortname); | |
671 | ||
672 | ops->to_has_execution = 1; | |
673 | ops->to_has_all_memory = 1; | |
674 | ops->to_has_memory = 1; | |
675 | ops->to_has_stack = 1; | |
676 | ops->to_has_registers = 1; | |
677 | ||
678 | update_current_target (); | |
679 | } | |
680 | ||
681 | /* Mark OPS as a non-running target. This reverses the effect | |
682 | of target_mark_running. */ | |
683 | ||
684 | void | |
685 | target_mark_exited (struct target_ops *ops) | |
686 | { | |
687 | struct target_ops *t; | |
688 | ||
689 | for (t = target_stack; t != NULL; t = t->beneath) | |
690 | if (t == ops) | |
691 | break; | |
692 | if (t == NULL) | |
693 | internal_error (__FILE__, __LINE__, | |
694 | "Attempted to mark unpushed target \"%s\" as running", | |
695 | ops->to_shortname); | |
696 | ||
697 | ops->to_has_execution = 0; | |
698 | ops->to_has_all_memory = 0; | |
699 | ops->to_has_memory = 0; | |
700 | ops->to_has_stack = 0; | |
701 | ops->to_has_registers = 0; | |
702 | ||
703 | update_current_target (); | |
704 | } | |
705 | ||
c906108c SS |
706 | /* Push a new target type into the stack of the existing target accessors, |
707 | possibly superseding some of the existing accessors. | |
708 | ||
709 | Result is zero if the pushed target ended up on top of the stack, | |
710 | nonzero if at least one target is on top of it. | |
711 | ||
712 | Rather than allow an empty stack, we always have the dummy target at | |
713 | the bottom stratum, so we can call the function vectors without | |
714 | checking them. */ | |
715 | ||
716 | int | |
fba45db2 | 717 | push_target (struct target_ops *t) |
c906108c | 718 | { |
258b763a | 719 | struct target_ops **cur; |
c906108c SS |
720 | |
721 | /* Check magic number. If wrong, it probably means someone changed | |
722 | the struct definition, but not all the places that initialize one. */ | |
723 | if (t->to_magic != OPS_MAGIC) | |
724 | { | |
c5aa993b JM |
725 | fprintf_unfiltered (gdb_stderr, |
726 | "Magic number of %s target struct wrong\n", | |
727 | t->to_shortname); | |
e2e0b3e5 | 728 | internal_error (__FILE__, __LINE__, _("failed internal consistency check")); |
c906108c SS |
729 | } |
730 | ||
258b763a AC |
731 | /* Find the proper stratum to install this target in. */ |
732 | for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath) | |
c906108c | 733 | { |
258b763a | 734 | if ((int) (t->to_stratum) >= (int) (*cur)->to_stratum) |
c906108c SS |
735 | break; |
736 | } | |
737 | ||
258b763a | 738 | /* If there's already targets at this stratum, remove them. */ |
88c231eb | 739 | /* FIXME: cagney/2003-10-15: I think this should be popping all |
258b763a AC |
740 | targets to CUR, and not just those at this stratum level. */ |
741 | while ((*cur) != NULL && t->to_stratum == (*cur)->to_stratum) | |
742 | { | |
743 | /* There's already something at this stratum level. Close it, | |
744 | and un-hook it from the stack. */ | |
745 | struct target_ops *tmp = (*cur); | |
746 | (*cur) = (*cur)->beneath; | |
747 | tmp->beneath = NULL; | |
f1c07ab0 | 748 | target_close (tmp, 0); |
258b763a | 749 | } |
c906108c SS |
750 | |
751 | /* We have removed all targets in our stratum, now add the new one. */ | |
258b763a AC |
752 | t->beneath = (*cur); |
753 | (*cur) = t; | |
c906108c SS |
754 | |
755 | update_current_target (); | |
756 | ||
258b763a AC |
757 | /* Not on top? */ |
758 | return (t != target_stack); | |
c906108c SS |
759 | } |
760 | ||
2bc416ba | 761 | /* Remove a target_ops vector from the stack, wherever it may be. |
c906108c SS |
762 | Return how many times it was removed (0 or 1). */ |
763 | ||
764 | int | |
fba45db2 | 765 | unpush_target (struct target_ops *t) |
c906108c | 766 | { |
258b763a AC |
767 | struct target_ops **cur; |
768 | struct target_ops *tmp; | |
c906108c | 769 | |
c906108c SS |
770 | /* Look for the specified target. Note that we assume that a target |
771 | can only occur once in the target stack. */ | |
772 | ||
258b763a AC |
773 | for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath) |
774 | { | |
775 | if ((*cur) == t) | |
776 | break; | |
777 | } | |
c906108c | 778 | |
258b763a | 779 | if ((*cur) == NULL) |
c906108c SS |
780 | return 0; /* Didn't find target_ops, quit now */ |
781 | ||
5269965e AC |
782 | /* NOTE: cagney/2003-12-06: In '94 the close call was made |
783 | unconditional by moving it to before the above check that the | |
784 | target was in the target stack (something about "Change the way | |
785 | pushing and popping of targets work to support target overlays | |
786 | and inheritance"). This doesn't make much sense - only open | |
787 | targets should be closed. */ | |
788 | target_close (t, 0); | |
789 | ||
c906108c | 790 | /* Unchain the target */ |
258b763a AC |
791 | tmp = (*cur); |
792 | (*cur) = (*cur)->beneath; | |
793 | tmp->beneath = NULL; | |
c906108c SS |
794 | |
795 | update_current_target (); | |
c906108c SS |
796 | |
797 | return 1; | |
798 | } | |
799 | ||
800 | void | |
fba45db2 | 801 | pop_target (void) |
c906108c | 802 | { |
f1c07ab0 | 803 | target_close (¤t_target, 0); /* Let it clean up */ |
258b763a | 804 | if (unpush_target (target_stack) == 1) |
c906108c SS |
805 | return; |
806 | ||
c5aa993b JM |
807 | fprintf_unfiltered (gdb_stderr, |
808 | "pop_target couldn't find target %s\n", | |
809 | current_target.to_shortname); | |
e2e0b3e5 | 810 | internal_error (__FILE__, __LINE__, _("failed internal consistency check")); |
c906108c SS |
811 | } |
812 | ||
72f5cf0e | 813 | /* Using the objfile specified in OBJFILE, find the address for the |
9e35dae4 DJ |
814 | current thread's thread-local storage with offset OFFSET. */ |
815 | CORE_ADDR | |
816 | target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset) | |
817 | { | |
818 | volatile CORE_ADDR addr = 0; | |
819 | ||
820 | if (target_get_thread_local_address_p () | |
821 | && gdbarch_fetch_tls_load_module_address_p (current_gdbarch)) | |
822 | { | |
823 | ptid_t ptid = inferior_ptid; | |
824 | volatile struct gdb_exception ex; | |
825 | ||
826 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
827 | { | |
828 | CORE_ADDR lm_addr; | |
829 | ||
830 | /* Fetch the load module address for this objfile. */ | |
831 | lm_addr = gdbarch_fetch_tls_load_module_address (current_gdbarch, | |
832 | objfile); | |
833 | /* If it's 0, throw the appropriate exception. */ | |
834 | if (lm_addr == 0) | |
835 | throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR, | |
836 | _("TLS load module not found")); | |
837 | ||
838 | addr = target_get_thread_local_address (ptid, lm_addr, offset); | |
839 | } | |
840 | /* If an error occurred, print TLS related messages here. Otherwise, | |
841 | throw the error to some higher catcher. */ | |
842 | if (ex.reason < 0) | |
843 | { | |
844 | int objfile_is_library = (objfile->flags & OBJF_SHARED); | |
845 | ||
846 | switch (ex.error) | |
847 | { | |
848 | case TLS_NO_LIBRARY_SUPPORT_ERROR: | |
849 | error (_("Cannot find thread-local variables in this thread library.")); | |
850 | break; | |
851 | case TLS_LOAD_MODULE_NOT_FOUND_ERROR: | |
852 | if (objfile_is_library) | |
853 | error (_("Cannot find shared library `%s' in dynamic" | |
854 | " linker's load module list"), objfile->name); | |
855 | else | |
856 | error (_("Cannot find executable file `%s' in dynamic" | |
857 | " linker's load module list"), objfile->name); | |
858 | break; | |
859 | case TLS_NOT_ALLOCATED_YET_ERROR: | |
860 | if (objfile_is_library) | |
861 | error (_("The inferior has not yet allocated storage for" | |
862 | " thread-local variables in\n" | |
863 | "the shared library `%s'\n" | |
864 | "for %s"), | |
865 | objfile->name, target_pid_to_str (ptid)); | |
866 | else | |
867 | error (_("The inferior has not yet allocated storage for" | |
868 | " thread-local variables in\n" | |
869 | "the executable `%s'\n" | |
870 | "for %s"), | |
871 | objfile->name, target_pid_to_str (ptid)); | |
872 | break; | |
873 | case TLS_GENERIC_ERROR: | |
874 | if (objfile_is_library) | |
875 | error (_("Cannot find thread-local storage for %s, " | |
876 | "shared library %s:\n%s"), | |
877 | target_pid_to_str (ptid), | |
878 | objfile->name, ex.message); | |
879 | else | |
880 | error (_("Cannot find thread-local storage for %s, " | |
881 | "executable file %s:\n%s"), | |
882 | target_pid_to_str (ptid), | |
883 | objfile->name, ex.message); | |
884 | break; | |
885 | default: | |
886 | throw_exception (ex); | |
887 | break; | |
888 | } | |
889 | } | |
890 | } | |
891 | /* It wouldn't be wrong here to try a gdbarch method, too; finding | |
892 | TLS is an ABI-specific thing. But we don't do that yet. */ | |
893 | else | |
894 | error (_("Cannot find thread-local variables on this target")); | |
895 | ||
896 | return addr; | |
897 | } | |
898 | ||
c906108c SS |
899 | #undef MIN |
900 | #define MIN(A, B) (((A) <= (B)) ? (A) : (B)) | |
901 | ||
902 | /* target_read_string -- read a null terminated string, up to LEN bytes, | |
903 | from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful. | |
904 | Set *STRING to a pointer to malloc'd memory containing the data; the caller | |
905 | is responsible for freeing it. Return the number of bytes successfully | |
906 | read. */ | |
907 | ||
908 | int | |
fba45db2 | 909 | target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop) |
c906108c SS |
910 | { |
911 | int tlen, origlen, offset, i; | |
1b0ba102 | 912 | gdb_byte buf[4]; |
c906108c SS |
913 | int errcode = 0; |
914 | char *buffer; | |
915 | int buffer_allocated; | |
916 | char *bufptr; | |
917 | unsigned int nbytes_read = 0; | |
918 | ||
6217bf3e MS |
919 | gdb_assert (string); |
920 | ||
c906108c SS |
921 | /* Small for testing. */ |
922 | buffer_allocated = 4; | |
923 | buffer = xmalloc (buffer_allocated); | |
924 | bufptr = buffer; | |
925 | ||
926 | origlen = len; | |
927 | ||
928 | while (len > 0) | |
929 | { | |
930 | tlen = MIN (len, 4 - (memaddr & 3)); | |
931 | offset = memaddr & 3; | |
932 | ||
1b0ba102 | 933 | errcode = target_read_memory (memaddr & ~3, buf, sizeof buf); |
c906108c SS |
934 | if (errcode != 0) |
935 | { | |
936 | /* The transfer request might have crossed the boundary to an | |
937 | unallocated region of memory. Retry the transfer, requesting | |
938 | a single byte. */ | |
939 | tlen = 1; | |
940 | offset = 0; | |
b8eb5af0 | 941 | errcode = target_read_memory (memaddr, buf, 1); |
c906108c SS |
942 | if (errcode != 0) |
943 | goto done; | |
944 | } | |
945 | ||
946 | if (bufptr - buffer + tlen > buffer_allocated) | |
947 | { | |
948 | unsigned int bytes; | |
949 | bytes = bufptr - buffer; | |
950 | buffer_allocated *= 2; | |
951 | buffer = xrealloc (buffer, buffer_allocated); | |
952 | bufptr = buffer + bytes; | |
953 | } | |
954 | ||
955 | for (i = 0; i < tlen; i++) | |
956 | { | |
957 | *bufptr++ = buf[i + offset]; | |
958 | if (buf[i + offset] == '\000') | |
959 | { | |
960 | nbytes_read += i + 1; | |
961 | goto done; | |
962 | } | |
963 | } | |
964 | ||
965 | memaddr += tlen; | |
966 | len -= tlen; | |
967 | nbytes_read += tlen; | |
968 | } | |
c5aa993b | 969 | done: |
6217bf3e | 970 | *string = buffer; |
c906108c SS |
971 | if (errnop != NULL) |
972 | *errnop = errcode; | |
c906108c SS |
973 | return nbytes_read; |
974 | } | |
975 | ||
8db32d44 AC |
976 | /* Find a section containing ADDR. */ |
977 | struct section_table * | |
978 | target_section_by_addr (struct target_ops *target, CORE_ADDR addr) | |
979 | { | |
980 | struct section_table *secp; | |
981 | for (secp = target->to_sections; | |
982 | secp < target->to_sections_end; | |
983 | secp++) | |
984 | { | |
985 | if (addr >= secp->addr && addr < secp->endaddr) | |
986 | return secp; | |
987 | } | |
988 | return NULL; | |
989 | } | |
990 | ||
cf7a04e8 DJ |
991 | /* Perform a partial memory transfer. The arguments and return |
992 | value are just as for target_xfer_partial. */ | |
993 | ||
994 | static LONGEST | |
995 | memory_xfer_partial (struct target_ops *ops, void *readbuf, const void *writebuf, | |
996 | ULONGEST memaddr, LONGEST len) | |
0779438d | 997 | { |
cf7a04e8 DJ |
998 | LONGEST res; |
999 | int reg_len; | |
1000 | struct mem_region *region; | |
1001 | ||
1002 | /* Zero length requests are ok and require no work. */ | |
1003 | if (len == 0) | |
1004 | return 0; | |
1005 | ||
1006 | /* Try the executable file, if "trust-readonly-sections" is set. */ | |
1007 | if (readbuf != NULL && trust_readonly) | |
1008 | { | |
1009 | struct section_table *secp; | |
1010 | ||
1011 | secp = target_section_by_addr (ops, memaddr); | |
1012 | if (secp != NULL | |
1013 | && (bfd_get_section_flags (secp->bfd, secp->the_bfd_section) | |
1014 | & SEC_READONLY)) | |
1015 | return xfer_memory (memaddr, readbuf, len, 0, NULL, ops); | |
1016 | } | |
1017 | ||
98646950 UW |
1018 | /* Likewise for accesses to unmapped overlay sections. */ |
1019 | if (readbuf != NULL && overlay_debugging) | |
1020 | { | |
1021 | asection *section = find_pc_overlay (memaddr); | |
1022 | if (pc_in_unmapped_range (memaddr, section)) | |
1023 | return xfer_memory (memaddr, readbuf, len, 0, NULL, ops); | |
1024 | } | |
1025 | ||
cf7a04e8 DJ |
1026 | /* Try GDB's internal data cache. */ |
1027 | region = lookup_mem_region (memaddr); | |
4b5752d0 VP |
1028 | /* region->hi == 0 means there's no upper bound. */ |
1029 | if (memaddr + len < region->hi || region->hi == 0) | |
cf7a04e8 DJ |
1030 | reg_len = len; |
1031 | else | |
1032 | reg_len = region->hi - memaddr; | |
1033 | ||
1034 | switch (region->attrib.mode) | |
1035 | { | |
1036 | case MEM_RO: | |
1037 | if (writebuf != NULL) | |
1038 | return -1; | |
1039 | break; | |
1040 | ||
1041 | case MEM_WO: | |
1042 | if (readbuf != NULL) | |
1043 | return -1; | |
1044 | break; | |
a76d924d DJ |
1045 | |
1046 | case MEM_FLASH: | |
1047 | /* We only support writing to flash during "load" for now. */ | |
1048 | if (writebuf != NULL) | |
1049 | error (_("Writing to flash memory forbidden in this context")); | |
1050 | break; | |
4b5752d0 VP |
1051 | |
1052 | case MEM_NONE: | |
1053 | return -1; | |
cf7a04e8 DJ |
1054 | } |
1055 | ||
1056 | if (region->attrib.cache) | |
1057 | { | |
1058 | /* FIXME drow/2006-08-09: This call discards OPS, so the raw | |
1059 | memory request will start back at current_target. */ | |
1060 | if (readbuf != NULL) | |
1061 | res = dcache_xfer_memory (target_dcache, memaddr, readbuf, | |
1062 | reg_len, 0); | |
1063 | else | |
1064 | /* FIXME drow/2006-08-09: If we're going to preserve const | |
1065 | correctness dcache_xfer_memory should take readbuf and | |
1066 | writebuf. */ | |
1067 | res = dcache_xfer_memory (target_dcache, memaddr, | |
1068 | (void *) writebuf, | |
1069 | reg_len, 1); | |
1070 | if (res <= 0) | |
1071 | return -1; | |
1072 | else | |
8defab1a DJ |
1073 | { |
1074 | if (readbuf && !show_memory_breakpoints) | |
1075 | breakpoint_restore_shadows (readbuf, memaddr, reg_len); | |
1076 | return res; | |
1077 | } | |
cf7a04e8 DJ |
1078 | } |
1079 | ||
1080 | /* If none of those methods found the memory we wanted, fall back | |
1081 | to a target partial transfer. Normally a single call to | |
1082 | to_xfer_partial is enough; if it doesn't recognize an object | |
1083 | it will call the to_xfer_partial of the next target down. | |
1084 | But for memory this won't do. Memory is the only target | |
1085 | object which can be read from more than one valid target. | |
1086 | A core file, for instance, could have some of memory but | |
1087 | delegate other bits to the target below it. So, we must | |
1088 | manually try all targets. */ | |
1089 | ||
1090 | do | |
1091 | { | |
1092 | res = ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL, | |
4b5752d0 | 1093 | readbuf, writebuf, memaddr, reg_len); |
cf7a04e8 | 1094 | if (res > 0) |
8defab1a | 1095 | break; |
cf7a04e8 | 1096 | |
5ad3a4ca DJ |
1097 | /* We want to continue past core files to executables, but not |
1098 | past a running target's memory. */ | |
1099 | if (ops->to_has_all_memory) | |
8defab1a | 1100 | break; |
5ad3a4ca | 1101 | |
cf7a04e8 DJ |
1102 | ops = ops->beneath; |
1103 | } | |
1104 | while (ops != NULL); | |
1105 | ||
8defab1a DJ |
1106 | if (readbuf && !show_memory_breakpoints) |
1107 | breakpoint_restore_shadows (readbuf, memaddr, reg_len); | |
1108 | ||
cf7a04e8 DJ |
1109 | /* If we still haven't got anything, return the last error. We |
1110 | give up. */ | |
1111 | return res; | |
0779438d AC |
1112 | } |
1113 | ||
8defab1a DJ |
1114 | static void |
1115 | restore_show_memory_breakpoints (void *arg) | |
1116 | { | |
1117 | show_memory_breakpoints = (uintptr_t) arg; | |
1118 | } | |
1119 | ||
1120 | struct cleanup * | |
1121 | make_show_memory_breakpoints_cleanup (int show) | |
1122 | { | |
1123 | int current = show_memory_breakpoints; | |
1124 | show_memory_breakpoints = show; | |
1125 | ||
1126 | return make_cleanup (restore_show_memory_breakpoints, | |
1127 | (void *) (uintptr_t) current); | |
1128 | } | |
1129 | ||
27394598 AC |
1130 | static LONGEST |
1131 | target_xfer_partial (struct target_ops *ops, | |
1132 | enum target_object object, const char *annex, | |
1133 | void *readbuf, const void *writebuf, | |
1134 | ULONGEST offset, LONGEST len) | |
1135 | { | |
1136 | LONGEST retval; | |
1137 | ||
1138 | gdb_assert (ops->to_xfer_partial != NULL); | |
cf7a04e8 DJ |
1139 | |
1140 | /* If this is a memory transfer, let the memory-specific code | |
1141 | have a look at it instead. Memory transfers are more | |
1142 | complicated. */ | |
1143 | if (object == TARGET_OBJECT_MEMORY) | |
1144 | retval = memory_xfer_partial (ops, readbuf, writebuf, offset, len); | |
1145 | else | |
1146 | { | |
1147 | enum target_object raw_object = object; | |
1148 | ||
1149 | /* If this is a raw memory transfer, request the normal | |
1150 | memory object from other layers. */ | |
1151 | if (raw_object == TARGET_OBJECT_RAW_MEMORY) | |
1152 | raw_object = TARGET_OBJECT_MEMORY; | |
1153 | ||
1154 | retval = ops->to_xfer_partial (ops, raw_object, annex, readbuf, | |
1155 | writebuf, offset, len); | |
1156 | } | |
1157 | ||
27394598 AC |
1158 | if (targetdebug) |
1159 | { | |
1160 | const unsigned char *myaddr = NULL; | |
1161 | ||
1162 | fprintf_unfiltered (gdb_stdlog, | |
1163 | "%s:target_xfer_partial (%d, %s, 0x%lx, 0x%lx, 0x%s, %s) = %s", | |
1164 | ops->to_shortname, | |
1165 | (int) object, | |
1166 | (annex ? annex : "(null)"), | |
1167 | (long) readbuf, (long) writebuf, | |
1168 | paddr_nz (offset), paddr_d (len), paddr_d (retval)); | |
1169 | ||
1170 | if (readbuf) | |
1171 | myaddr = readbuf; | |
1172 | if (writebuf) | |
1173 | myaddr = writebuf; | |
1174 | if (retval > 0 && myaddr != NULL) | |
1175 | { | |
1176 | int i; | |
2bc416ba | 1177 | |
27394598 AC |
1178 | fputs_unfiltered (", bytes =", gdb_stdlog); |
1179 | for (i = 0; i < retval; i++) | |
1180 | { | |
1181 | if ((((long) &(myaddr[i])) & 0xf) == 0) | |
1182 | { | |
1183 | if (targetdebug < 2 && i > 0) | |
1184 | { | |
1185 | fprintf_unfiltered (gdb_stdlog, " ..."); | |
1186 | break; | |
1187 | } | |
1188 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
1189 | } | |
2bc416ba | 1190 | |
27394598 AC |
1191 | fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff); |
1192 | } | |
1193 | } | |
2bc416ba | 1194 | |
27394598 AC |
1195 | fputc_unfiltered ('\n', gdb_stdlog); |
1196 | } | |
1197 | return retval; | |
1198 | } | |
1199 | ||
c906108c SS |
1200 | /* Read LEN bytes of target memory at address MEMADDR, placing the results in |
1201 | GDB's memory at MYADDR. Returns either 0 for success or an errno value | |
1202 | if any error occurs. | |
1203 | ||
1204 | If an error occurs, no guarantee is made about the contents of the data at | |
1205 | MYADDR. In particular, the caller should not depend upon partial reads | |
1206 | filling the buffer with good data. There is no way for the caller to know | |
1207 | how much good data might have been transfered anyway. Callers that can | |
cf7a04e8 DJ |
1208 | deal with partial reads should call target_read (which will retry until |
1209 | it makes no progress, and then return how much was transferred). */ | |
c906108c SS |
1210 | |
1211 | int | |
fc1a4b47 | 1212 | target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len) |
c906108c | 1213 | { |
cf7a04e8 DJ |
1214 | if (target_read (¤t_target, TARGET_OBJECT_MEMORY, NULL, |
1215 | myaddr, memaddr, len) == len) | |
1216 | return 0; | |
0779438d | 1217 | else |
cf7a04e8 | 1218 | return EIO; |
c906108c SS |
1219 | } |
1220 | ||
c906108c | 1221 | int |
fc1a4b47 | 1222 | target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, int len) |
c906108c | 1223 | { |
cf7a04e8 DJ |
1224 | if (target_write (¤t_target, TARGET_OBJECT_MEMORY, NULL, |
1225 | myaddr, memaddr, len) == len) | |
1226 | return 0; | |
0779438d | 1227 | else |
cf7a04e8 | 1228 | return EIO; |
c906108c | 1229 | } |
c5aa993b | 1230 | |
fd79ecee DJ |
1231 | /* Fetch the target's memory map. */ |
1232 | ||
1233 | VEC(mem_region_s) * | |
1234 | target_memory_map (void) | |
1235 | { | |
1236 | VEC(mem_region_s) *result; | |
1237 | struct mem_region *last_one, *this_one; | |
1238 | int ix; | |
1239 | struct target_ops *t; | |
1240 | ||
1241 | if (targetdebug) | |
1242 | fprintf_unfiltered (gdb_stdlog, "target_memory_map ()\n"); | |
1243 | ||
1244 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
1245 | if (t->to_memory_map != NULL) | |
1246 | break; | |
1247 | ||
1248 | if (t == NULL) | |
1249 | return NULL; | |
1250 | ||
1251 | result = t->to_memory_map (t); | |
1252 | if (result == NULL) | |
1253 | return NULL; | |
1254 | ||
1255 | qsort (VEC_address (mem_region_s, result), | |
1256 | VEC_length (mem_region_s, result), | |
1257 | sizeof (struct mem_region), mem_region_cmp); | |
1258 | ||
1259 | /* Check that regions do not overlap. Simultaneously assign | |
1260 | a numbering for the "mem" commands to use to refer to | |
1261 | each region. */ | |
1262 | last_one = NULL; | |
1263 | for (ix = 0; VEC_iterate (mem_region_s, result, ix, this_one); ix++) | |
1264 | { | |
1265 | this_one->number = ix; | |
1266 | ||
1267 | if (last_one && last_one->hi > this_one->lo) | |
1268 | { | |
1269 | warning (_("Overlapping regions in memory map: ignoring")); | |
1270 | VEC_free (mem_region_s, result); | |
1271 | return NULL; | |
1272 | } | |
1273 | last_one = this_one; | |
1274 | } | |
1275 | ||
1276 | return result; | |
1277 | } | |
1278 | ||
a76d924d DJ |
1279 | void |
1280 | target_flash_erase (ULONGEST address, LONGEST length) | |
1281 | { | |
1282 | struct target_ops *t; | |
1283 | ||
1284 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
1285 | if (t->to_flash_erase != NULL) | |
1286 | { | |
1287 | if (targetdebug) | |
1288 | fprintf_unfiltered (gdb_stdlog, "target_flash_erase (%s, %s)\n", | |
1289 | paddr (address), phex (length, 0)); | |
8944021f DJ |
1290 | t->to_flash_erase (t, address, length); |
1291 | return; | |
a76d924d DJ |
1292 | } |
1293 | ||
1294 | tcomplain (); | |
1295 | } | |
1296 | ||
1297 | void | |
1298 | target_flash_done (void) | |
1299 | { | |
1300 | struct target_ops *t; | |
1301 | ||
1302 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
1303 | if (t->to_flash_done != NULL) | |
1304 | { | |
1305 | if (targetdebug) | |
1306 | fprintf_unfiltered (gdb_stdlog, "target_flash_done\n"); | |
8944021f DJ |
1307 | t->to_flash_done (t); |
1308 | return; | |
a76d924d DJ |
1309 | } |
1310 | ||
1311 | tcomplain (); | |
1312 | } | |
1313 | ||
4aa7a7f5 JJ |
1314 | #ifndef target_stopped_data_address_p |
1315 | int | |
1316 | target_stopped_data_address_p (struct target_ops *target) | |
1317 | { | |
aa869812 AC |
1318 | if (target->to_stopped_data_address |
1319 | == (int (*) (struct target_ops *, CORE_ADDR *)) return_zero) | |
4aa7a7f5 | 1320 | return 0; |
aa869812 AC |
1321 | if (target->to_stopped_data_address == debug_to_stopped_data_address |
1322 | && (debug_target.to_stopped_data_address | |
1323 | == (int (*) (struct target_ops *, CORE_ADDR *)) return_zero)) | |
1324 | return 0; | |
1325 | return 1; | |
4aa7a7f5 JJ |
1326 | } |
1327 | #endif | |
1328 | ||
920d2a44 AC |
1329 | static void |
1330 | show_trust_readonly (struct ui_file *file, int from_tty, | |
1331 | struct cmd_list_element *c, const char *value) | |
1332 | { | |
1333 | fprintf_filtered (file, _("\ | |
1334 | Mode for reading from readonly sections is %s.\n"), | |
1335 | value); | |
1336 | } | |
3a11626d | 1337 | |
1e3ff5ad AC |
1338 | /* More generic transfers. */ |
1339 | ||
0088c768 | 1340 | static LONGEST |
8aa91c1e | 1341 | default_xfer_partial (struct target_ops *ops, enum target_object object, |
2bc416ba | 1342 | const char *annex, gdb_byte *readbuf, |
1b0ba102 | 1343 | const gdb_byte *writebuf, ULONGEST offset, LONGEST len) |
0088c768 AC |
1344 | { |
1345 | if (object == TARGET_OBJECT_MEMORY | |
c8e73a31 AC |
1346 | && ops->deprecated_xfer_memory != NULL) |
1347 | /* If available, fall back to the target's | |
1348 | "deprecated_xfer_memory" method. */ | |
0088c768 | 1349 | { |
4b8a223f | 1350 | int xfered = -1; |
0088c768 | 1351 | errno = 0; |
4b8a223f AC |
1352 | if (writebuf != NULL) |
1353 | { | |
1354 | void *buffer = xmalloc (len); | |
1355 | struct cleanup *cleanup = make_cleanup (xfree, buffer); | |
1356 | memcpy (buffer, writebuf, len); | |
c8e73a31 AC |
1357 | xfered = ops->deprecated_xfer_memory (offset, buffer, len, |
1358 | 1/*write*/, NULL, ops); | |
4b8a223f AC |
1359 | do_cleanups (cleanup); |
1360 | } | |
1361 | if (readbuf != NULL) | |
244e85c8 MS |
1362 | xfered = ops->deprecated_xfer_memory (offset, readbuf, len, |
1363 | 0/*read*/, NULL, ops); | |
0088c768 AC |
1364 | if (xfered > 0) |
1365 | return xfered; | |
1366 | else if (xfered == 0 && errno == 0) | |
c8e73a31 AC |
1367 | /* "deprecated_xfer_memory" uses 0, cross checked against |
1368 | ERRNO as one indication of an error. */ | |
0088c768 AC |
1369 | return 0; |
1370 | else | |
1371 | return -1; | |
1372 | } | |
1373 | else if (ops->beneath != NULL) | |
cf7a04e8 DJ |
1374 | return ops->beneath->to_xfer_partial (ops->beneath, object, annex, |
1375 | readbuf, writebuf, offset, len); | |
1376 | else | |
1377 | return -1; | |
1378 | } | |
1379 | ||
1380 | /* The xfer_partial handler for the topmost target. Unlike the default, | |
1381 | it does not need to handle memory specially; it just passes all | |
1382 | requests down the stack. */ | |
1383 | ||
1384 | static LONGEST | |
1385 | current_xfer_partial (struct target_ops *ops, enum target_object object, | |
1386 | const char *annex, gdb_byte *readbuf, | |
1387 | const gdb_byte *writebuf, ULONGEST offset, LONGEST len) | |
1388 | { | |
1389 | if (ops->beneath != NULL) | |
1390 | return ops->beneath->to_xfer_partial (ops->beneath, object, annex, | |
1391 | readbuf, writebuf, offset, len); | |
0088c768 AC |
1392 | else |
1393 | return -1; | |
1394 | } | |
1395 | ||
1396 | /* Target vector read/write partial wrapper functions. | |
1397 | ||
1398 | NOTE: cagney/2003-10-21: I wonder if having "to_xfer_partial | |
1399 | (inbuf, outbuf)", instead of separate read/write methods, make life | |
1400 | easier. */ | |
1401 | ||
13547ab6 | 1402 | static LONGEST |
1e3ff5ad AC |
1403 | target_read_partial (struct target_ops *ops, |
1404 | enum target_object object, | |
1b0ba102 | 1405 | const char *annex, gdb_byte *buf, |
1e3ff5ad AC |
1406 | ULONGEST offset, LONGEST len) |
1407 | { | |
27394598 | 1408 | return target_xfer_partial (ops, object, annex, buf, NULL, offset, len); |
1e3ff5ad AC |
1409 | } |
1410 | ||
13547ab6 | 1411 | static LONGEST |
1e3ff5ad AC |
1412 | target_write_partial (struct target_ops *ops, |
1413 | enum target_object object, | |
1b0ba102 | 1414 | const char *annex, const gdb_byte *buf, |
1e3ff5ad AC |
1415 | ULONGEST offset, LONGEST len) |
1416 | { | |
27394598 | 1417 | return target_xfer_partial (ops, object, annex, NULL, buf, offset, len); |
1e3ff5ad AC |
1418 | } |
1419 | ||
1420 | /* Wrappers to perform the full transfer. */ | |
1421 | LONGEST | |
1422 | target_read (struct target_ops *ops, | |
1423 | enum target_object object, | |
1b0ba102 | 1424 | const char *annex, gdb_byte *buf, |
1e3ff5ad AC |
1425 | ULONGEST offset, LONGEST len) |
1426 | { | |
1427 | LONGEST xfered = 0; | |
1428 | while (xfered < len) | |
1429 | { | |
0088c768 | 1430 | LONGEST xfer = target_read_partial (ops, object, annex, |
fc1a4b47 | 1431 | (gdb_byte *) buf + xfered, |
0088c768 | 1432 | offset + xfered, len - xfered); |
1e3ff5ad | 1433 | /* Call an observer, notifying them of the xfer progress? */ |
13547ab6 DJ |
1434 | if (xfer == 0) |
1435 | return xfered; | |
1436 | if (xfer < 0) | |
0088c768 | 1437 | return -1; |
1e3ff5ad AC |
1438 | xfered += xfer; |
1439 | QUIT; | |
1440 | } | |
1441 | return len; | |
1442 | } | |
1443 | ||
cf7a04e8 DJ |
1444 | /* An alternative to target_write with progress callbacks. */ |
1445 | ||
1e3ff5ad | 1446 | LONGEST |
cf7a04e8 DJ |
1447 | target_write_with_progress (struct target_ops *ops, |
1448 | enum target_object object, | |
1449 | const char *annex, const gdb_byte *buf, | |
1450 | ULONGEST offset, LONGEST len, | |
1451 | void (*progress) (ULONGEST, void *), void *baton) | |
1e3ff5ad AC |
1452 | { |
1453 | LONGEST xfered = 0; | |
a76d924d DJ |
1454 | |
1455 | /* Give the progress callback a chance to set up. */ | |
1456 | if (progress) | |
1457 | (*progress) (0, baton); | |
1458 | ||
1e3ff5ad AC |
1459 | while (xfered < len) |
1460 | { | |
1461 | LONGEST xfer = target_write_partial (ops, object, annex, | |
fc1a4b47 | 1462 | (gdb_byte *) buf + xfered, |
1e3ff5ad | 1463 | offset + xfered, len - xfered); |
cf7a04e8 | 1464 | |
13547ab6 DJ |
1465 | if (xfer == 0) |
1466 | return xfered; | |
1467 | if (xfer < 0) | |
0088c768 | 1468 | return -1; |
cf7a04e8 DJ |
1469 | |
1470 | if (progress) | |
1471 | (*progress) (xfer, baton); | |
1472 | ||
1e3ff5ad AC |
1473 | xfered += xfer; |
1474 | QUIT; | |
1475 | } | |
1476 | return len; | |
1477 | } | |
1478 | ||
cf7a04e8 DJ |
1479 | LONGEST |
1480 | target_write (struct target_ops *ops, | |
1481 | enum target_object object, | |
1482 | const char *annex, const gdb_byte *buf, | |
1483 | ULONGEST offset, LONGEST len) | |
1484 | { | |
1485 | return target_write_with_progress (ops, object, annex, buf, offset, len, | |
1486 | NULL, NULL); | |
1487 | } | |
1488 | ||
159f81f3 DJ |
1489 | /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return |
1490 | the size of the transferred data. PADDING additional bytes are | |
1491 | available in *BUF_P. This is a helper function for | |
1492 | target_read_alloc; see the declaration of that function for more | |
1493 | information. */ | |
13547ab6 | 1494 | |
159f81f3 DJ |
1495 | static LONGEST |
1496 | target_read_alloc_1 (struct target_ops *ops, enum target_object object, | |
1497 | const char *annex, gdb_byte **buf_p, int padding) | |
13547ab6 DJ |
1498 | { |
1499 | size_t buf_alloc, buf_pos; | |
1500 | gdb_byte *buf; | |
1501 | LONGEST n; | |
1502 | ||
1503 | /* This function does not have a length parameter; it reads the | |
1504 | entire OBJECT). Also, it doesn't support objects fetched partly | |
1505 | from one target and partly from another (in a different stratum, | |
1506 | e.g. a core file and an executable). Both reasons make it | |
1507 | unsuitable for reading memory. */ | |
1508 | gdb_assert (object != TARGET_OBJECT_MEMORY); | |
1509 | ||
1510 | /* Start by reading up to 4K at a time. The target will throttle | |
1511 | this number down if necessary. */ | |
1512 | buf_alloc = 4096; | |
1513 | buf = xmalloc (buf_alloc); | |
1514 | buf_pos = 0; | |
1515 | while (1) | |
1516 | { | |
1517 | n = target_read_partial (ops, object, annex, &buf[buf_pos], | |
159f81f3 | 1518 | buf_pos, buf_alloc - buf_pos - padding); |
13547ab6 DJ |
1519 | if (n < 0) |
1520 | { | |
1521 | /* An error occurred. */ | |
1522 | xfree (buf); | |
1523 | return -1; | |
1524 | } | |
1525 | else if (n == 0) | |
1526 | { | |
1527 | /* Read all there was. */ | |
1528 | if (buf_pos == 0) | |
1529 | xfree (buf); | |
1530 | else | |
1531 | *buf_p = buf; | |
1532 | return buf_pos; | |
1533 | } | |
1534 | ||
1535 | buf_pos += n; | |
1536 | ||
1537 | /* If the buffer is filling up, expand it. */ | |
1538 | if (buf_alloc < buf_pos * 2) | |
1539 | { | |
1540 | buf_alloc *= 2; | |
1541 | buf = xrealloc (buf, buf_alloc); | |
1542 | } | |
1543 | ||
1544 | QUIT; | |
1545 | } | |
1546 | } | |
1547 | ||
159f81f3 DJ |
1548 | /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return |
1549 | the size of the transferred data. See the declaration in "target.h" | |
1550 | function for more information about the return value. */ | |
1551 | ||
1552 | LONGEST | |
1553 | target_read_alloc (struct target_ops *ops, enum target_object object, | |
1554 | const char *annex, gdb_byte **buf_p) | |
1555 | { | |
1556 | return target_read_alloc_1 (ops, object, annex, buf_p, 0); | |
1557 | } | |
1558 | ||
1559 | /* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and | |
1560 | returned as a string, allocated using xmalloc. If an error occurs | |
1561 | or the transfer is unsupported, NULL is returned. Empty objects | |
1562 | are returned as allocated but empty strings. A warning is issued | |
1563 | if the result contains any embedded NUL bytes. */ | |
1564 | ||
1565 | char * | |
1566 | target_read_stralloc (struct target_ops *ops, enum target_object object, | |
1567 | const char *annex) | |
1568 | { | |
1569 | gdb_byte *buffer; | |
1570 | LONGEST transferred; | |
1571 | ||
1572 | transferred = target_read_alloc_1 (ops, object, annex, &buffer, 1); | |
1573 | ||
1574 | if (transferred < 0) | |
1575 | return NULL; | |
1576 | ||
1577 | if (transferred == 0) | |
1578 | return xstrdup (""); | |
1579 | ||
1580 | buffer[transferred] = 0; | |
1581 | if (strlen (buffer) < transferred) | |
1582 | warning (_("target object %d, annex %s, " | |
1583 | "contained unexpected null characters"), | |
1584 | (int) object, annex ? annex : "(none)"); | |
1585 | ||
1586 | return (char *) buffer; | |
1587 | } | |
1588 | ||
b6591e8b AC |
1589 | /* Memory transfer methods. */ |
1590 | ||
1591 | void | |
1b0ba102 | 1592 | get_target_memory (struct target_ops *ops, CORE_ADDR addr, gdb_byte *buf, |
b6591e8b AC |
1593 | LONGEST len) |
1594 | { | |
1595 | if (target_read (ops, TARGET_OBJECT_MEMORY, NULL, buf, addr, len) | |
1596 | != len) | |
1597 | memory_error (EIO, addr); | |
1598 | } | |
1599 | ||
1600 | ULONGEST | |
1601 | get_target_memory_unsigned (struct target_ops *ops, | |
1602 | CORE_ADDR addr, int len) | |
1603 | { | |
f6519ebc | 1604 | gdb_byte buf[sizeof (ULONGEST)]; |
b6591e8b AC |
1605 | |
1606 | gdb_assert (len <= sizeof (buf)); | |
1607 | get_target_memory (ops, addr, buf, len); | |
1608 | return extract_unsigned_integer (buf, len); | |
1609 | } | |
1610 | ||
c906108c | 1611 | static void |
fba45db2 | 1612 | target_info (char *args, int from_tty) |
c906108c SS |
1613 | { |
1614 | struct target_ops *t; | |
c906108c | 1615 | int has_all_mem = 0; |
c5aa993b | 1616 | |
c906108c | 1617 | if (symfile_objfile != NULL) |
a3f17187 | 1618 | printf_unfiltered (_("Symbols from \"%s\".\n"), symfile_objfile->name); |
c906108c | 1619 | |
258b763a | 1620 | for (t = target_stack; t != NULL; t = t->beneath) |
c906108c | 1621 | { |
c906108c SS |
1622 | if (!t->to_has_memory) |
1623 | continue; | |
1624 | ||
c5aa993b | 1625 | if ((int) (t->to_stratum) <= (int) dummy_stratum) |
c906108c SS |
1626 | continue; |
1627 | if (has_all_mem) | |
a3f17187 | 1628 | printf_unfiltered (_("\tWhile running this, GDB does not access memory from...\n")); |
c5aa993b JM |
1629 | printf_unfiltered ("%s:\n", t->to_longname); |
1630 | (t->to_files_info) (t); | |
c906108c SS |
1631 | has_all_mem = t->to_has_all_memory; |
1632 | } | |
1633 | } | |
1634 | ||
fd79ecee DJ |
1635 | /* This function is called before any new inferior is created, e.g. |
1636 | by running a program, attaching, or connecting to a target. | |
1637 | It cleans up any state from previous invocations which might | |
1638 | change between runs. This is a subset of what target_preopen | |
1639 | resets (things which might change between targets). */ | |
1640 | ||
1641 | void | |
1642 | target_pre_inferior (int from_tty) | |
1643 | { | |
1644 | invalidate_target_mem_regions (); | |
424163ea DJ |
1645 | |
1646 | target_clear_description (); | |
fd79ecee DJ |
1647 | } |
1648 | ||
c906108c SS |
1649 | /* This is to be called by the open routine before it does |
1650 | anything. */ | |
1651 | ||
1652 | void | |
fba45db2 | 1653 | target_preopen (int from_tty) |
c906108c | 1654 | { |
c5aa993b | 1655 | dont_repeat (); |
c906108c SS |
1656 | |
1657 | if (target_has_execution) | |
c5aa993b | 1658 | { |
adf40b2e | 1659 | if (!from_tty |
e2e0b3e5 | 1660 | || query (_("A program is being debugged already. Kill it? "))) |
c5aa993b | 1661 | target_kill (); |
c906108c | 1662 | else |
8a3fe4f8 | 1663 | error (_("Program not killed.")); |
c906108c SS |
1664 | } |
1665 | ||
1666 | /* Calling target_kill may remove the target from the stack. But if | |
1667 | it doesn't (which seems like a win for UDI), remove it now. */ | |
1668 | ||
1669 | if (target_has_execution) | |
1670 | pop_target (); | |
fd79ecee DJ |
1671 | |
1672 | target_pre_inferior (from_tty); | |
c906108c SS |
1673 | } |
1674 | ||
1675 | /* Detach a target after doing deferred register stores. */ | |
1676 | ||
1677 | void | |
fba45db2 | 1678 | target_detach (char *args, int from_tty) |
c906108c | 1679 | { |
c906108c SS |
1680 | (current_target.to_detach) (args, from_tty); |
1681 | } | |
1682 | ||
6ad8ae5c DJ |
1683 | void |
1684 | target_disconnect (char *args, int from_tty) | |
1685 | { | |
597320e7 DJ |
1686 | struct target_ops *t; |
1687 | ||
1688 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
1689 | if (t->to_disconnect != NULL) | |
1690 | { | |
1691 | if (targetdebug) | |
1692 | fprintf_unfiltered (gdb_stdlog, "target_disconnect (%s, %d)\n", | |
1693 | args, from_tty); | |
1694 | t->to_disconnect (t, args, from_tty); | |
1695 | return; | |
1696 | } | |
1697 | ||
1698 | tcomplain (); | |
6ad8ae5c DJ |
1699 | } |
1700 | ||
ed9a39eb JM |
1701 | int |
1702 | target_async_mask (int mask) | |
1703 | { | |
1704 | int saved_async_masked_status = target_async_mask_value; | |
1705 | target_async_mask_value = mask; | |
1706 | return saved_async_masked_status; | |
1707 | } | |
1708 | ||
ee057212 DJ |
1709 | /* Look through the list of possible targets for a target that can |
1710 | follow forks. */ | |
1711 | ||
1712 | int | |
1713 | target_follow_fork (int follow_child) | |
1714 | { | |
1715 | struct target_ops *t; | |
1716 | ||
1717 | for (t = current_target.beneath; t != NULL; t = t->beneath) | |
1718 | { | |
1719 | if (t->to_follow_fork != NULL) | |
1720 | { | |
1721 | int retval = t->to_follow_fork (t, follow_child); | |
1722 | if (targetdebug) | |
1723 | fprintf_unfiltered (gdb_stdlog, "target_follow_fork (%d) = %d\n", | |
1724 | follow_child, retval); | |
1725 | return retval; | |
1726 | } | |
1727 | } | |
1728 | ||
1729 | /* Some target returned a fork event, but did not know how to follow it. */ | |
1730 | internal_error (__FILE__, __LINE__, | |
1731 | "could not find a target to follow fork"); | |
1732 | } | |
1733 | ||
424163ea DJ |
1734 | /* Look for a target which can describe architectural features, starting |
1735 | from TARGET. If we find one, return its description. */ | |
1736 | ||
1737 | const struct target_desc * | |
1738 | target_read_description (struct target_ops *target) | |
1739 | { | |
1740 | struct target_ops *t; | |
1741 | ||
1742 | for (t = target; t != NULL; t = t->beneath) | |
1743 | if (t->to_read_description != NULL) | |
1744 | { | |
1745 | const struct target_desc *tdesc; | |
1746 | ||
1747 | tdesc = t->to_read_description (t); | |
1748 | if (tdesc) | |
1749 | return tdesc; | |
1750 | } | |
1751 | ||
1752 | return NULL; | |
1753 | } | |
1754 | ||
8edfe269 DJ |
1755 | /* Look through the currently pushed targets. If none of them will |
1756 | be able to restart the currently running process, issue an error | |
1757 | message. */ | |
1758 | ||
1759 | void | |
1760 | target_require_runnable (void) | |
1761 | { | |
1762 | struct target_ops *t; | |
1763 | ||
1764 | for (t = target_stack; t != NULL; t = t->beneath) | |
1765 | { | |
1766 | /* If this target knows how to create a new program, then | |
1767 | assume we will still be able to after killing the current | |
1768 | one. Either killing and mourning will not pop T, or else | |
1769 | find_default_run_target will find it again. */ | |
1770 | if (t->to_create_inferior != NULL) | |
1771 | return; | |
1772 | ||
1773 | /* Do not worry about thread_stratum targets that can not | |
1774 | create inferiors. Assume they will be pushed again if | |
1775 | necessary, and continue to the process_stratum. */ | |
1776 | if (t->to_stratum == thread_stratum) | |
1777 | continue; | |
1778 | ||
1779 | error (_("\ | |
1780 | The \"%s\" target does not support \"run\". Try \"help target\" or \"continue\"."), | |
1781 | t->to_shortname); | |
1782 | } | |
1783 | ||
1784 | /* This function is only called if the target is running. In that | |
1785 | case there should have been a process_stratum target and it | |
1786 | should either know how to create inferiors, or not... */ | |
1787 | internal_error (__FILE__, __LINE__, "No targets found"); | |
1788 | } | |
1789 | ||
c906108c SS |
1790 | /* Look through the list of possible targets for a target that can |
1791 | execute a run or attach command without any other data. This is | |
1792 | used to locate the default process stratum. | |
1793 | ||
1794 | Result is always valid (error() is called for errors). */ | |
1795 | ||
1796 | static struct target_ops * | |
fba45db2 | 1797 | find_default_run_target (char *do_mesg) |
c906108c SS |
1798 | { |
1799 | struct target_ops **t; | |
1800 | struct target_ops *runable = NULL; | |
1801 | int count; | |
1802 | ||
1803 | count = 0; | |
1804 | ||
1805 | for (t = target_structs; t < target_structs + target_struct_size; | |
1806 | ++t) | |
1807 | { | |
c5aa993b | 1808 | if ((*t)->to_can_run && target_can_run (*t)) |
c906108c SS |
1809 | { |
1810 | runable = *t; | |
1811 | ++count; | |
1812 | } | |
1813 | } | |
1814 | ||
1815 | if (count != 1) | |
8a3fe4f8 | 1816 | error (_("Don't know how to %s. Try \"help target\"."), do_mesg); |
c906108c SS |
1817 | |
1818 | return runable; | |
1819 | } | |
1820 | ||
1821 | void | |
fba45db2 | 1822 | find_default_attach (char *args, int from_tty) |
c906108c SS |
1823 | { |
1824 | struct target_ops *t; | |
1825 | ||
c5aa993b | 1826 | t = find_default_run_target ("attach"); |
c906108c SS |
1827 | (t->to_attach) (args, from_tty); |
1828 | return; | |
1829 | } | |
1830 | ||
c906108c | 1831 | void |
c27cda74 AC |
1832 | find_default_create_inferior (char *exec_file, char *allargs, char **env, |
1833 | int from_tty) | |
c906108c SS |
1834 | { |
1835 | struct target_ops *t; | |
1836 | ||
c5aa993b | 1837 | t = find_default_run_target ("run"); |
c27cda74 | 1838 | (t->to_create_inferior) (exec_file, allargs, env, from_tty); |
c906108c SS |
1839 | return; |
1840 | } | |
1841 | ||
e0d24f8d WZ |
1842 | static int |
1843 | default_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len) | |
1844 | { | |
2a3cdf79 | 1845 | return (len <= TYPE_LENGTH (builtin_type_void_data_ptr)); |
ccaa32c7 GS |
1846 | } |
1847 | ||
c906108c | 1848 | static int |
fba45db2 | 1849 | return_zero (void) |
c906108c SS |
1850 | { |
1851 | return 0; | |
1852 | } | |
1853 | ||
1854 | static int | |
fba45db2 | 1855 | return_one (void) |
c906108c SS |
1856 | { |
1857 | return 1; | |
1858 | } | |
1859 | ||
ccaa32c7 GS |
1860 | static int |
1861 | return_minus_one (void) | |
1862 | { | |
1863 | return -1; | |
1864 | } | |
1865 | ||
6426a772 JM |
1866 | /* |
1867 | * Resize the to_sections pointer. Also make sure that anyone that | |
1868 | * was holding on to an old value of it gets updated. | |
1869 | * Returns the old size. | |
1870 | */ | |
1871 | ||
1872 | int | |
1873 | target_resize_to_sections (struct target_ops *target, int num_added) | |
1874 | { | |
1875 | struct target_ops **t; | |
1876 | struct section_table *old_value; | |
1877 | int old_count; | |
1878 | ||
1879 | old_value = target->to_sections; | |
1880 | ||
1881 | if (target->to_sections) | |
1882 | { | |
1883 | old_count = target->to_sections_end - target->to_sections; | |
1884 | target->to_sections = (struct section_table *) | |
1885 | xrealloc ((char *) target->to_sections, | |
1886 | (sizeof (struct section_table)) * (num_added + old_count)); | |
1887 | } | |
1888 | else | |
1889 | { | |
1890 | old_count = 0; | |
1891 | target->to_sections = (struct section_table *) | |
1892 | xmalloc ((sizeof (struct section_table)) * num_added); | |
1893 | } | |
1894 | target->to_sections_end = target->to_sections + (num_added + old_count); | |
1895 | ||
1896 | /* Check to see if anyone else was pointing to this structure. | |
1897 | If old_value was null, then no one was. */ | |
2bc416ba | 1898 | |
6426a772 JM |
1899 | if (old_value) |
1900 | { | |
1901 | for (t = target_structs; t < target_structs + target_struct_size; | |
1902 | ++t) | |
1903 | { | |
1904 | if ((*t)->to_sections == old_value) | |
1905 | { | |
1906 | (*t)->to_sections = target->to_sections; | |
1907 | (*t)->to_sections_end = target->to_sections_end; | |
1908 | } | |
1909 | } | |
e354df01 NW |
1910 | /* There is a flattened view of the target stack in current_target, |
1911 | so its to_sections pointer might also need updating. */ | |
1912 | if (current_target.to_sections == old_value) | |
1913 | { | |
1914 | current_target.to_sections = target->to_sections; | |
1915 | current_target.to_sections_end = target->to_sections_end; | |
1916 | } | |
6426a772 | 1917 | } |
2bc416ba | 1918 | |
6426a772 JM |
1919 | return old_count; |
1920 | ||
1921 | } | |
1922 | ||
07cd4b97 JB |
1923 | /* Remove all target sections taken from ABFD. |
1924 | ||
1925 | Scan the current target stack for targets whose section tables | |
1926 | refer to sections from BFD, and remove those sections. We use this | |
1927 | when we notice that the inferior has unloaded a shared object, for | |
1928 | example. */ | |
1929 | void | |
1930 | remove_target_sections (bfd *abfd) | |
1931 | { | |
1932 | struct target_ops **t; | |
1933 | ||
1934 | for (t = target_structs; t < target_structs + target_struct_size; t++) | |
1935 | { | |
1936 | struct section_table *src, *dest; | |
1937 | ||
1938 | dest = (*t)->to_sections; | |
1939 | for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++) | |
1940 | if (src->bfd != abfd) | |
1941 | { | |
1942 | /* Keep this section. */ | |
1943 | if (dest < src) *dest = *src; | |
1944 | dest++; | |
1945 | } | |
1946 | ||
1947 | /* If we've dropped any sections, resize the section table. */ | |
1948 | if (dest < src) | |
1949 | target_resize_to_sections (*t, dest - src); | |
1950 | } | |
1951 | } | |
1952 | ||
1953 | ||
1954 | ||
1955 | ||
7a292a7a SS |
1956 | /* Find a single runnable target in the stack and return it. If for |
1957 | some reason there is more than one, return NULL. */ | |
1958 | ||
1959 | struct target_ops * | |
fba45db2 | 1960 | find_run_target (void) |
7a292a7a SS |
1961 | { |
1962 | struct target_ops **t; | |
1963 | struct target_ops *runable = NULL; | |
1964 | int count; | |
c5aa993b | 1965 | |
7a292a7a | 1966 | count = 0; |
c5aa993b | 1967 | |
7a292a7a SS |
1968 | for (t = target_structs; t < target_structs + target_struct_size; ++t) |
1969 | { | |
c5aa993b | 1970 | if ((*t)->to_can_run && target_can_run (*t)) |
7a292a7a SS |
1971 | { |
1972 | runable = *t; | |
1973 | ++count; | |
1974 | } | |
1975 | } | |
c5aa993b | 1976 | |
7a292a7a SS |
1977 | return (count == 1 ? runable : NULL); |
1978 | } | |
1979 | ||
ed9a39eb JM |
1980 | /* Find a single core_stratum target in the list of targets and return it. |
1981 | If for some reason there is more than one, return NULL. */ | |
1982 | ||
c906108c | 1983 | struct target_ops * |
fba45db2 | 1984 | find_core_target (void) |
c906108c SS |
1985 | { |
1986 | struct target_ops **t; | |
1987 | struct target_ops *runable = NULL; | |
1988 | int count; | |
c5aa993b | 1989 | |
c906108c | 1990 | count = 0; |
c5aa993b | 1991 | |
c906108c SS |
1992 | for (t = target_structs; t < target_structs + target_struct_size; |
1993 | ++t) | |
1994 | { | |
1995 | if ((*t)->to_stratum == core_stratum) | |
1996 | { | |
1997 | runable = *t; | |
1998 | ++count; | |
1999 | } | |
2000 | } | |
c5aa993b JM |
2001 | |
2002 | return (count == 1 ? runable : NULL); | |
c906108c | 2003 | } |
ed9a39eb JM |
2004 | |
2005 | /* | |
2006 | * Find the next target down the stack from the specified target. | |
2007 | */ | |
2008 | ||
2009 | struct target_ops * | |
fba45db2 | 2010 | find_target_beneath (struct target_ops *t) |
ed9a39eb | 2011 | { |
258b763a | 2012 | return t->beneath; |
ed9a39eb JM |
2013 | } |
2014 | ||
c906108c SS |
2015 | \f |
2016 | /* The inferior process has died. Long live the inferior! */ | |
2017 | ||
2018 | void | |
fba45db2 | 2019 | generic_mourn_inferior (void) |
c906108c SS |
2020 | { |
2021 | extern int show_breakpoint_hit_counts; | |
2022 | ||
39f77062 | 2023 | inferior_ptid = null_ptid; |
c906108c SS |
2024 | attach_flag = 0; |
2025 | breakpoint_init_inferior (inf_exited); | |
2026 | registers_changed (); | |
2027 | ||
c906108c SS |
2028 | reopen_exec_file (); |
2029 | reinit_frame_cache (); | |
2030 | ||
2031 | /* It is confusing to the user for ignore counts to stick around | |
2032 | from previous runs of the inferior. So clear them. */ | |
2033 | /* However, it is more confusing for the ignore counts to disappear when | |
2034 | using hit counts. So don't clear them if we're counting hits. */ | |
2035 | if (!show_breakpoint_hit_counts) | |
2036 | breakpoint_clear_ignore_counts (); | |
c5b739b5 | 2037 | |
9a4105ab AC |
2038 | if (deprecated_detach_hook) |
2039 | deprecated_detach_hook (); | |
c906108c SS |
2040 | } |
2041 | \f | |
8807d78b | 2042 | /* Helper function for child_wait and the derivatives of child_wait. |
c906108c SS |
2043 | HOSTSTATUS is the waitstatus from wait() or the equivalent; store our |
2044 | translation of that in OURSTATUS. */ | |
2045 | void | |
fba45db2 | 2046 | store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus) |
c906108c | 2047 | { |
c906108c SS |
2048 | if (WIFEXITED (hoststatus)) |
2049 | { | |
2050 | ourstatus->kind = TARGET_WAITKIND_EXITED; | |
2051 | ourstatus->value.integer = WEXITSTATUS (hoststatus); | |
2052 | } | |
2053 | else if (!WIFSTOPPED (hoststatus)) | |
2054 | { | |
2055 | ourstatus->kind = TARGET_WAITKIND_SIGNALLED; | |
2056 | ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus)); | |
2057 | } | |
2058 | else | |
2059 | { | |
2060 | ourstatus->kind = TARGET_WAITKIND_STOPPED; | |
2061 | ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus)); | |
2062 | } | |
2063 | } | |
2064 | \f | |
c906108c | 2065 | /* Returns zero to leave the inferior alone, one to interrupt it. */ |
507f3c78 | 2066 | int (*target_activity_function) (void); |
c906108c SS |
2067 | int target_activity_fd; |
2068 | \f | |
fd0a2a6f MK |
2069 | /* Convert a normal process ID to a string. Returns the string in a |
2070 | static buffer. */ | |
c906108c SS |
2071 | |
2072 | char * | |
39f77062 | 2073 | normal_pid_to_str (ptid_t ptid) |
c906108c | 2074 | { |
fd0a2a6f | 2075 | static char buf[32]; |
c906108c | 2076 | |
5fff8fc0 | 2077 | xsnprintf (buf, sizeof buf, "process %d", ptid_get_pid (ptid)); |
c906108c SS |
2078 | return buf; |
2079 | } | |
2080 | ||
be4d1333 | 2081 | /* Error-catcher for target_find_memory_regions */ |
be4d1333 MS |
2082 | static int dummy_find_memory_regions (int (*ignore1) (), void *ignore2) |
2083 | { | |
8a3fe4f8 | 2084 | error (_("No target.")); |
be4d1333 MS |
2085 | return 0; |
2086 | } | |
2087 | ||
2088 | /* Error-catcher for target_make_corefile_notes */ | |
be4d1333 MS |
2089 | static char * dummy_make_corefile_notes (bfd *ignore1, int *ignore2) |
2090 | { | |
8a3fe4f8 | 2091 | error (_("No target.")); |
be4d1333 MS |
2092 | return NULL; |
2093 | } | |
2094 | ||
c906108c SS |
2095 | /* Set up the handful of non-empty slots needed by the dummy target |
2096 | vector. */ | |
2097 | ||
2098 | static void | |
fba45db2 | 2099 | init_dummy_target (void) |
c906108c SS |
2100 | { |
2101 | dummy_target.to_shortname = "None"; | |
2102 | dummy_target.to_longname = "None"; | |
2103 | dummy_target.to_doc = ""; | |
2104 | dummy_target.to_attach = find_default_attach; | |
c906108c | 2105 | dummy_target.to_create_inferior = find_default_create_inferior; |
ed9a39eb | 2106 | dummy_target.to_pid_to_str = normal_pid_to_str; |
c906108c | 2107 | dummy_target.to_stratum = dummy_stratum; |
be4d1333 MS |
2108 | dummy_target.to_find_memory_regions = dummy_find_memory_regions; |
2109 | dummy_target.to_make_corefile_notes = dummy_make_corefile_notes; | |
0b603eba | 2110 | dummy_target.to_xfer_partial = default_xfer_partial; |
c906108c SS |
2111 | dummy_target.to_magic = OPS_MAGIC; |
2112 | } | |
c906108c | 2113 | \f |
c906108c | 2114 | static void |
fba45db2 | 2115 | debug_to_open (char *args, int from_tty) |
c906108c SS |
2116 | { |
2117 | debug_target.to_open (args, from_tty); | |
2118 | ||
96baa820 | 2119 | fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty); |
c906108c SS |
2120 | } |
2121 | ||
2122 | static void | |
fba45db2 | 2123 | debug_to_close (int quitting) |
c906108c | 2124 | { |
f1c07ab0 | 2125 | target_close (&debug_target, quitting); |
96baa820 | 2126 | fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting); |
c906108c SS |
2127 | } |
2128 | ||
f1c07ab0 AC |
2129 | void |
2130 | target_close (struct target_ops *targ, int quitting) | |
2131 | { | |
2132 | if (targ->to_xclose != NULL) | |
2133 | targ->to_xclose (targ, quitting); | |
2134 | else if (targ->to_close != NULL) | |
2135 | targ->to_close (quitting); | |
2136 | } | |
2137 | ||
c906108c | 2138 | static void |
fba45db2 | 2139 | debug_to_attach (char *args, int from_tty) |
c906108c SS |
2140 | { |
2141 | debug_target.to_attach (args, from_tty); | |
2142 | ||
96baa820 | 2143 | fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty); |
c906108c SS |
2144 | } |
2145 | ||
2146 | ||
2147 | static void | |
fba45db2 | 2148 | debug_to_post_attach (int pid) |
c906108c SS |
2149 | { |
2150 | debug_target.to_post_attach (pid); | |
2151 | ||
96baa820 | 2152 | fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid); |
c906108c SS |
2153 | } |
2154 | ||
c906108c | 2155 | static void |
fba45db2 | 2156 | debug_to_detach (char *args, int from_tty) |
c906108c SS |
2157 | { |
2158 | debug_target.to_detach (args, from_tty); | |
2159 | ||
96baa820 | 2160 | fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty); |
c906108c SS |
2161 | } |
2162 | ||
c906108c | 2163 | static void |
39f77062 | 2164 | debug_to_resume (ptid_t ptid, int step, enum target_signal siggnal) |
c906108c | 2165 | { |
39f77062 | 2166 | debug_target.to_resume (ptid, step, siggnal); |
c906108c | 2167 | |
39f77062 | 2168 | fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", PIDGET (ptid), |
c906108c SS |
2169 | step ? "step" : "continue", |
2170 | target_signal_to_name (siggnal)); | |
2171 | } | |
2172 | ||
39f77062 KB |
2173 | static ptid_t |
2174 | debug_to_wait (ptid_t ptid, struct target_waitstatus *status) | |
c906108c | 2175 | { |
39f77062 | 2176 | ptid_t retval; |
c906108c | 2177 | |
39f77062 | 2178 | retval = debug_target.to_wait (ptid, status); |
c906108c | 2179 | |
96baa820 | 2180 | fprintf_unfiltered (gdb_stdlog, |
39f77062 KB |
2181 | "target_wait (%d, status) = %d, ", PIDGET (ptid), |
2182 | PIDGET (retval)); | |
96baa820 | 2183 | fprintf_unfiltered (gdb_stdlog, "status->kind = "); |
c906108c SS |
2184 | switch (status->kind) |
2185 | { | |
2186 | case TARGET_WAITKIND_EXITED: | |
96baa820 | 2187 | fprintf_unfiltered (gdb_stdlog, "exited, status = %d\n", |
c906108c SS |
2188 | status->value.integer); |
2189 | break; | |
2190 | case TARGET_WAITKIND_STOPPED: | |
96baa820 | 2191 | fprintf_unfiltered (gdb_stdlog, "stopped, signal = %s\n", |
c906108c SS |
2192 | target_signal_to_name (status->value.sig)); |
2193 | break; | |
2194 | case TARGET_WAITKIND_SIGNALLED: | |
96baa820 | 2195 | fprintf_unfiltered (gdb_stdlog, "signalled, signal = %s\n", |
c906108c SS |
2196 | target_signal_to_name (status->value.sig)); |
2197 | break; | |
2198 | case TARGET_WAITKIND_LOADED: | |
96baa820 | 2199 | fprintf_unfiltered (gdb_stdlog, "loaded\n"); |
c906108c SS |
2200 | break; |
2201 | case TARGET_WAITKIND_FORKED: | |
96baa820 | 2202 | fprintf_unfiltered (gdb_stdlog, "forked\n"); |
c906108c SS |
2203 | break; |
2204 | case TARGET_WAITKIND_VFORKED: | |
96baa820 | 2205 | fprintf_unfiltered (gdb_stdlog, "vforked\n"); |
c906108c SS |
2206 | break; |
2207 | case TARGET_WAITKIND_EXECD: | |
96baa820 | 2208 | fprintf_unfiltered (gdb_stdlog, "execd\n"); |
c906108c SS |
2209 | break; |
2210 | case TARGET_WAITKIND_SPURIOUS: | |
96baa820 | 2211 | fprintf_unfiltered (gdb_stdlog, "spurious\n"); |
c906108c SS |
2212 | break; |
2213 | default: | |
96baa820 | 2214 | fprintf_unfiltered (gdb_stdlog, "unknown???\n"); |
c906108c SS |
2215 | break; |
2216 | } | |
2217 | ||
2218 | return retval; | |
2219 | } | |
2220 | ||
bf0c5130 | 2221 | static void |
56be3814 UW |
2222 | debug_print_register (const char * func, |
2223 | struct regcache *regcache, int regno) | |
bf0c5130 | 2224 | { |
f8d29908 | 2225 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
bf0c5130 | 2226 | fprintf_unfiltered (gdb_stdlog, "%s ", func); |
f8d29908 UW |
2227 | if (regno >= 0 && regno < gdbarch_num_regs (gdbarch) |
2228 | + gdbarch_num_pseudo_regs (gdbarch) | |
2229 | && gdbarch_register_name (gdbarch, regno) != NULL | |
2230 | && gdbarch_register_name (gdbarch, regno)[0] != '\0') | |
2231 | fprintf_unfiltered (gdb_stdlog, "(%s)", | |
2232 | gdbarch_register_name (gdbarch, regno)); | |
bf0c5130 AC |
2233 | else |
2234 | fprintf_unfiltered (gdb_stdlog, "(%d)", regno); | |
2235 | if (regno >= 0) | |
2236 | { | |
f8d29908 | 2237 | int i, size = register_size (gdbarch, regno); |
d9d9c31f | 2238 | unsigned char buf[MAX_REGISTER_SIZE]; |
56be3814 | 2239 | regcache_cooked_read (regcache, regno, buf); |
bf0c5130 | 2240 | fprintf_unfiltered (gdb_stdlog, " = "); |
81c4a259 | 2241 | for (i = 0; i < size; i++) |
bf0c5130 AC |
2242 | { |
2243 | fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]); | |
2244 | } | |
81c4a259 | 2245 | if (size <= sizeof (LONGEST)) |
bf0c5130 | 2246 | { |
81c4a259 | 2247 | ULONGEST val = extract_unsigned_integer (buf, size); |
bf0c5130 | 2248 | fprintf_unfiltered (gdb_stdlog, " 0x%s %s", |
81c4a259 | 2249 | paddr_nz (val), paddr_d (val)); |
bf0c5130 AC |
2250 | } |
2251 | } | |
2252 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
2253 | } | |
2254 | ||
c906108c | 2255 | static void |
56be3814 | 2256 | debug_to_fetch_registers (struct regcache *regcache, int regno) |
c906108c | 2257 | { |
56be3814 UW |
2258 | debug_target.to_fetch_registers (regcache, regno); |
2259 | debug_print_register ("target_fetch_registers", regcache, regno); | |
c906108c SS |
2260 | } |
2261 | ||
2262 | static void | |
56be3814 | 2263 | debug_to_store_registers (struct regcache *regcache, int regno) |
c906108c | 2264 | { |
56be3814 UW |
2265 | debug_target.to_store_registers (regcache, regno); |
2266 | debug_print_register ("target_store_registers", regcache, regno); | |
bf0c5130 | 2267 | fprintf_unfiltered (gdb_stdlog, "\n"); |
c906108c SS |
2268 | } |
2269 | ||
2270 | static void | |
316f2060 | 2271 | debug_to_prepare_to_store (struct regcache *regcache) |
c906108c | 2272 | { |
316f2060 | 2273 | debug_target.to_prepare_to_store (regcache); |
c906108c | 2274 | |
96baa820 | 2275 | fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n"); |
c906108c SS |
2276 | } |
2277 | ||
2278 | static int | |
961cb7b5 | 2279 | deprecated_debug_xfer_memory (CORE_ADDR memaddr, bfd_byte *myaddr, int len, |
c8e73a31 AC |
2280 | int write, struct mem_attrib *attrib, |
2281 | struct target_ops *target) | |
c906108c SS |
2282 | { |
2283 | int retval; | |
2284 | ||
c8e73a31 AC |
2285 | retval = debug_target.deprecated_xfer_memory (memaddr, myaddr, len, write, |
2286 | attrib, target); | |
c906108c | 2287 | |
96baa820 | 2288 | fprintf_unfiltered (gdb_stdlog, |
c906108c | 2289 | "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d", |
c5aa993b | 2290 | (unsigned int) memaddr, /* possable truncate long long */ |
c906108c SS |
2291 | len, write ? "write" : "read", retval); |
2292 | ||
c906108c SS |
2293 | if (retval > 0) |
2294 | { | |
2295 | int i; | |
2296 | ||
96baa820 | 2297 | fputs_unfiltered (", bytes =", gdb_stdlog); |
c906108c SS |
2298 | for (i = 0; i < retval; i++) |
2299 | { | |
2300 | if ((((long) &(myaddr[i])) & 0xf) == 0) | |
333dabeb DJ |
2301 | { |
2302 | if (targetdebug < 2 && i > 0) | |
2303 | { | |
2304 | fprintf_unfiltered (gdb_stdlog, " ..."); | |
2305 | break; | |
2306 | } | |
2307 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
2308 | } | |
2bc416ba | 2309 | |
96baa820 | 2310 | fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff); |
c906108c SS |
2311 | } |
2312 | } | |
2313 | ||
96baa820 | 2314 | fputc_unfiltered ('\n', gdb_stdlog); |
c906108c SS |
2315 | |
2316 | return retval; | |
2317 | } | |
2318 | ||
2319 | static void | |
fba45db2 | 2320 | debug_to_files_info (struct target_ops *target) |
c906108c SS |
2321 | { |
2322 | debug_target.to_files_info (target); | |
2323 | ||
96baa820 | 2324 | fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n"); |
c906108c SS |
2325 | } |
2326 | ||
2327 | static int | |
8181d85f | 2328 | debug_to_insert_breakpoint (struct bp_target_info *bp_tgt) |
c906108c SS |
2329 | { |
2330 | int retval; | |
2331 | ||
8181d85f | 2332 | retval = debug_target.to_insert_breakpoint (bp_tgt); |
c906108c | 2333 | |
96baa820 | 2334 | fprintf_unfiltered (gdb_stdlog, |
104c1213 | 2335 | "target_insert_breakpoint (0x%lx, xxx) = %ld\n", |
8181d85f | 2336 | (unsigned long) bp_tgt->placed_address, |
104c1213 | 2337 | (unsigned long) retval); |
c906108c SS |
2338 | return retval; |
2339 | } | |
2340 | ||
2341 | static int | |
8181d85f | 2342 | debug_to_remove_breakpoint (struct bp_target_info *bp_tgt) |
c906108c SS |
2343 | { |
2344 | int retval; | |
2345 | ||
8181d85f | 2346 | retval = debug_target.to_remove_breakpoint (bp_tgt); |
c906108c | 2347 | |
96baa820 | 2348 | fprintf_unfiltered (gdb_stdlog, |
104c1213 | 2349 | "target_remove_breakpoint (0x%lx, xxx) = %ld\n", |
8181d85f | 2350 | (unsigned long) bp_tgt->placed_address, |
104c1213 | 2351 | (unsigned long) retval); |
c906108c SS |
2352 | return retval; |
2353 | } | |
2354 | ||
ccaa32c7 GS |
2355 | static int |
2356 | debug_to_can_use_hw_breakpoint (int type, int cnt, int from_tty) | |
2357 | { | |
2358 | int retval; | |
2359 | ||
2360 | retval = debug_target.to_can_use_hw_breakpoint (type, cnt, from_tty); | |
2361 | ||
2362 | fprintf_unfiltered (gdb_stdlog, | |
2363 | "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n", | |
2364 | (unsigned long) type, | |
2365 | (unsigned long) cnt, | |
2366 | (unsigned long) from_tty, | |
2367 | (unsigned long) retval); | |
2368 | return retval; | |
2369 | } | |
2370 | ||
e0d24f8d WZ |
2371 | static int |
2372 | debug_to_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len) | |
2373 | { | |
2374 | CORE_ADDR retval; | |
2375 | ||
2376 | retval = debug_target.to_region_ok_for_hw_watchpoint (addr, len); | |
2377 | ||
2378 | fprintf_unfiltered (gdb_stdlog, | |
2379 | "TARGET_REGION_OK_FOR_HW_WATCHPOINT (%ld, %ld) = 0x%lx\n", | |
2380 | (unsigned long) addr, | |
2381 | (unsigned long) len, | |
2382 | (unsigned long) retval); | |
2383 | return retval; | |
2384 | } | |
2385 | ||
ccaa32c7 GS |
2386 | static int |
2387 | debug_to_stopped_by_watchpoint (void) | |
2388 | { | |
2389 | int retval; | |
2390 | ||
2391 | retval = debug_target.to_stopped_by_watchpoint (); | |
2392 | ||
2393 | fprintf_unfiltered (gdb_stdlog, | |
2394 | "STOPPED_BY_WATCHPOINT () = %ld\n", | |
2395 | (unsigned long) retval); | |
2396 | return retval; | |
2397 | } | |
2398 | ||
4aa7a7f5 JJ |
2399 | static int |
2400 | debug_to_stopped_data_address (struct target_ops *target, CORE_ADDR *addr) | |
ccaa32c7 | 2401 | { |
4aa7a7f5 | 2402 | int retval; |
ccaa32c7 | 2403 | |
4aa7a7f5 | 2404 | retval = debug_target.to_stopped_data_address (target, addr); |
ccaa32c7 GS |
2405 | |
2406 | fprintf_unfiltered (gdb_stdlog, | |
4aa7a7f5 JJ |
2407 | "target_stopped_data_address ([0x%lx]) = %ld\n", |
2408 | (unsigned long)*addr, | |
2409 | (unsigned long)retval); | |
ccaa32c7 GS |
2410 | return retval; |
2411 | } | |
2412 | ||
2413 | static int | |
8181d85f | 2414 | debug_to_insert_hw_breakpoint (struct bp_target_info *bp_tgt) |
ccaa32c7 GS |
2415 | { |
2416 | int retval; | |
2417 | ||
8181d85f | 2418 | retval = debug_target.to_insert_hw_breakpoint (bp_tgt); |
ccaa32c7 GS |
2419 | |
2420 | fprintf_unfiltered (gdb_stdlog, | |
2421 | "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n", | |
8181d85f | 2422 | (unsigned long) bp_tgt->placed_address, |
ccaa32c7 GS |
2423 | (unsigned long) retval); |
2424 | return retval; | |
2425 | } | |
2426 | ||
2427 | static int | |
8181d85f | 2428 | debug_to_remove_hw_breakpoint (struct bp_target_info *bp_tgt) |
ccaa32c7 GS |
2429 | { |
2430 | int retval; | |
2431 | ||
8181d85f | 2432 | retval = debug_target.to_remove_hw_breakpoint (bp_tgt); |
ccaa32c7 GS |
2433 | |
2434 | fprintf_unfiltered (gdb_stdlog, | |
2435 | "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n", | |
8181d85f | 2436 | (unsigned long) bp_tgt->placed_address, |
ccaa32c7 GS |
2437 | (unsigned long) retval); |
2438 | return retval; | |
2439 | } | |
2440 | ||
2441 | static int | |
2442 | debug_to_insert_watchpoint (CORE_ADDR addr, int len, int type) | |
2443 | { | |
2444 | int retval; | |
2445 | ||
2446 | retval = debug_target.to_insert_watchpoint (addr, len, type); | |
2447 | ||
2448 | fprintf_unfiltered (gdb_stdlog, | |
2449 | "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n", | |
2450 | (unsigned long) addr, len, type, (unsigned long) retval); | |
2451 | return retval; | |
2452 | } | |
2453 | ||
2454 | static int | |
2455 | debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type) | |
2456 | { | |
2457 | int retval; | |
2458 | ||
ecde4882 | 2459 | retval = debug_target.to_remove_watchpoint (addr, len, type); |
ccaa32c7 GS |
2460 | |
2461 | fprintf_unfiltered (gdb_stdlog, | |
ecde4882 | 2462 | "target_remove_watchpoint (0x%lx, %d, %d) = %ld\n", |
ccaa32c7 GS |
2463 | (unsigned long) addr, len, type, (unsigned long) retval); |
2464 | return retval; | |
2465 | } | |
2466 | ||
c906108c | 2467 | static void |
fba45db2 | 2468 | debug_to_terminal_init (void) |
c906108c SS |
2469 | { |
2470 | debug_target.to_terminal_init (); | |
2471 | ||
96baa820 | 2472 | fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n"); |
c906108c SS |
2473 | } |
2474 | ||
2475 | static void | |
fba45db2 | 2476 | debug_to_terminal_inferior (void) |
c906108c SS |
2477 | { |
2478 | debug_target.to_terminal_inferior (); | |
2479 | ||
96baa820 | 2480 | fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n"); |
c906108c SS |
2481 | } |
2482 | ||
2483 | static void | |
fba45db2 | 2484 | debug_to_terminal_ours_for_output (void) |
c906108c SS |
2485 | { |
2486 | debug_target.to_terminal_ours_for_output (); | |
2487 | ||
96baa820 | 2488 | fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n"); |
c906108c SS |
2489 | } |
2490 | ||
2491 | static void | |
fba45db2 | 2492 | debug_to_terminal_ours (void) |
c906108c SS |
2493 | { |
2494 | debug_target.to_terminal_ours (); | |
2495 | ||
96baa820 | 2496 | fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n"); |
c906108c SS |
2497 | } |
2498 | ||
a790ad35 SC |
2499 | static void |
2500 | debug_to_terminal_save_ours (void) | |
2501 | { | |
2502 | debug_target.to_terminal_save_ours (); | |
2503 | ||
2504 | fprintf_unfiltered (gdb_stdlog, "target_terminal_save_ours ()\n"); | |
2505 | } | |
2506 | ||
c906108c | 2507 | static void |
fba45db2 | 2508 | debug_to_terminal_info (char *arg, int from_tty) |
c906108c SS |
2509 | { |
2510 | debug_target.to_terminal_info (arg, from_tty); | |
2511 | ||
96baa820 | 2512 | fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg, |
c906108c SS |
2513 | from_tty); |
2514 | } | |
2515 | ||
2516 | static void | |
fba45db2 | 2517 | debug_to_kill (void) |
c906108c SS |
2518 | { |
2519 | debug_target.to_kill (); | |
2520 | ||
96baa820 | 2521 | fprintf_unfiltered (gdb_stdlog, "target_kill ()\n"); |
c906108c SS |
2522 | } |
2523 | ||
2524 | static void | |
fba45db2 | 2525 | debug_to_load (char *args, int from_tty) |
c906108c SS |
2526 | { |
2527 | debug_target.to_load (args, from_tty); | |
2528 | ||
96baa820 | 2529 | fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty); |
c906108c SS |
2530 | } |
2531 | ||
2532 | static int | |
fba45db2 | 2533 | debug_to_lookup_symbol (char *name, CORE_ADDR *addrp) |
c906108c SS |
2534 | { |
2535 | int retval; | |
2536 | ||
2537 | retval = debug_target.to_lookup_symbol (name, addrp); | |
2538 | ||
96baa820 | 2539 | fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name); |
c906108c SS |
2540 | |
2541 | return retval; | |
2542 | } | |
2543 | ||
2544 | static void | |
c27cda74 AC |
2545 | debug_to_create_inferior (char *exec_file, char *args, char **env, |
2546 | int from_tty) | |
c906108c | 2547 | { |
c27cda74 | 2548 | debug_target.to_create_inferior (exec_file, args, env, from_tty); |
c906108c | 2549 | |
c27cda74 AC |
2550 | fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx, %d)\n", |
2551 | exec_file, args, from_tty); | |
c906108c SS |
2552 | } |
2553 | ||
2554 | static void | |
39f77062 | 2555 | debug_to_post_startup_inferior (ptid_t ptid) |
c906108c | 2556 | { |
39f77062 | 2557 | debug_target.to_post_startup_inferior (ptid); |
c906108c | 2558 | |
96baa820 | 2559 | fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n", |
39f77062 | 2560 | PIDGET (ptid)); |
c906108c SS |
2561 | } |
2562 | ||
2563 | static void | |
fba45db2 | 2564 | debug_to_acknowledge_created_inferior (int pid) |
c906108c SS |
2565 | { |
2566 | debug_target.to_acknowledge_created_inferior (pid); | |
2567 | ||
96baa820 | 2568 | fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n", |
c906108c SS |
2569 | pid); |
2570 | } | |
2571 | ||
fa113d1a | 2572 | static void |
fba45db2 | 2573 | debug_to_insert_fork_catchpoint (int pid) |
c906108c | 2574 | { |
fa113d1a | 2575 | debug_target.to_insert_fork_catchpoint (pid); |
c906108c | 2576 | |
fa113d1a AC |
2577 | fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d)\n", |
2578 | pid); | |
c906108c SS |
2579 | } |
2580 | ||
2581 | static int | |
fba45db2 | 2582 | debug_to_remove_fork_catchpoint (int pid) |
c906108c | 2583 | { |
c5aa993b | 2584 | int retval; |
c906108c SS |
2585 | |
2586 | retval = debug_target.to_remove_fork_catchpoint (pid); | |
2587 | ||
96baa820 | 2588 | fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n", |
c5aa993b | 2589 | pid, retval); |
c906108c SS |
2590 | |
2591 | return retval; | |
2592 | } | |
2593 | ||
fa113d1a | 2594 | static void |
fba45db2 | 2595 | debug_to_insert_vfork_catchpoint (int pid) |
c906108c | 2596 | { |
fa113d1a | 2597 | debug_target.to_insert_vfork_catchpoint (pid); |
c906108c | 2598 | |
fa113d1a AC |
2599 | fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)\n", |
2600 | pid); | |
c906108c SS |
2601 | } |
2602 | ||
2603 | static int | |
fba45db2 | 2604 | debug_to_remove_vfork_catchpoint (int pid) |
c906108c | 2605 | { |
c5aa993b | 2606 | int retval; |
c906108c SS |
2607 | |
2608 | retval = debug_target.to_remove_vfork_catchpoint (pid); | |
2609 | ||
96baa820 | 2610 | fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n", |
c5aa993b | 2611 | pid, retval); |
c906108c SS |
2612 | |
2613 | return retval; | |
2614 | } | |
2615 | ||
fa113d1a | 2616 | static void |
fba45db2 | 2617 | debug_to_insert_exec_catchpoint (int pid) |
c906108c | 2618 | { |
fa113d1a | 2619 | debug_target.to_insert_exec_catchpoint (pid); |
c906108c | 2620 | |
fa113d1a AC |
2621 | fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d)\n", |
2622 | pid); | |
c906108c SS |
2623 | } |
2624 | ||
2625 | static int | |
fba45db2 | 2626 | debug_to_remove_exec_catchpoint (int pid) |
c906108c | 2627 | { |
c5aa993b | 2628 | int retval; |
c906108c SS |
2629 | |
2630 | retval = debug_target.to_remove_exec_catchpoint (pid); | |
2631 | ||
96baa820 | 2632 | fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n", |
c5aa993b | 2633 | pid, retval); |
c906108c SS |
2634 | |
2635 | return retval; | |
2636 | } | |
2637 | ||
c906108c | 2638 | static int |
fba45db2 | 2639 | debug_to_reported_exec_events_per_exec_call (void) |
c906108c | 2640 | { |
c5aa993b | 2641 | int reported_exec_events; |
c906108c SS |
2642 | |
2643 | reported_exec_events = debug_target.to_reported_exec_events_per_exec_call (); | |
2644 | ||
96baa820 | 2645 | fprintf_unfiltered (gdb_stdlog, |
c906108c | 2646 | "target_reported_exec_events_per_exec_call () = %d\n", |
c5aa993b | 2647 | reported_exec_events); |
c906108c SS |
2648 | |
2649 | return reported_exec_events; | |
2650 | } | |
2651 | ||
c906108c | 2652 | static int |
fba45db2 | 2653 | debug_to_has_exited (int pid, int wait_status, int *exit_status) |
c906108c | 2654 | { |
c5aa993b | 2655 | int has_exited; |
c906108c SS |
2656 | |
2657 | has_exited = debug_target.to_has_exited (pid, wait_status, exit_status); | |
2658 | ||
96baa820 | 2659 | fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n", |
c5aa993b | 2660 | pid, wait_status, *exit_status, has_exited); |
c906108c SS |
2661 | |
2662 | return has_exited; | |
2663 | } | |
2664 | ||
2665 | static void | |
fba45db2 | 2666 | debug_to_mourn_inferior (void) |
c906108c SS |
2667 | { |
2668 | debug_target.to_mourn_inferior (); | |
2669 | ||
96baa820 | 2670 | fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n"); |
c906108c SS |
2671 | } |
2672 | ||
2673 | static int | |
fba45db2 | 2674 | debug_to_can_run (void) |
c906108c SS |
2675 | { |
2676 | int retval; | |
2677 | ||
2678 | retval = debug_target.to_can_run (); | |
2679 | ||
96baa820 | 2680 | fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval); |
c906108c SS |
2681 | |
2682 | return retval; | |
2683 | } | |
2684 | ||
2685 | static void | |
39f77062 | 2686 | debug_to_notice_signals (ptid_t ptid) |
c906108c | 2687 | { |
39f77062 | 2688 | debug_target.to_notice_signals (ptid); |
c906108c | 2689 | |
39f77062 KB |
2690 | fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n", |
2691 | PIDGET (ptid)); | |
c906108c SS |
2692 | } |
2693 | ||
2694 | static int | |
39f77062 | 2695 | debug_to_thread_alive (ptid_t ptid) |
c906108c SS |
2696 | { |
2697 | int retval; | |
2698 | ||
39f77062 | 2699 | retval = debug_target.to_thread_alive (ptid); |
c906108c | 2700 | |
96baa820 | 2701 | fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n", |
39f77062 | 2702 | PIDGET (ptid), retval); |
c906108c SS |
2703 | |
2704 | return retval; | |
2705 | } | |
2706 | ||
0d06e24b | 2707 | static void |
fba45db2 | 2708 | debug_to_find_new_threads (void) |
0d06e24b JM |
2709 | { |
2710 | debug_target.to_find_new_threads (); | |
2711 | ||
2712 | fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog); | |
2713 | } | |
2714 | ||
c906108c | 2715 | static void |
fba45db2 | 2716 | debug_to_stop (void) |
c906108c SS |
2717 | { |
2718 | debug_target.to_stop (); | |
2719 | ||
96baa820 | 2720 | fprintf_unfiltered (gdb_stdlog, "target_stop ()\n"); |
c906108c SS |
2721 | } |
2722 | ||
96baa820 JM |
2723 | static void |
2724 | debug_to_rcmd (char *command, | |
d9fcf2fb | 2725 | struct ui_file *outbuf) |
96baa820 JM |
2726 | { |
2727 | debug_target.to_rcmd (command, outbuf); | |
2728 | fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command); | |
2729 | } | |
2730 | ||
c906108c | 2731 | static char * |
fba45db2 | 2732 | debug_to_pid_to_exec_file (int pid) |
c906108c | 2733 | { |
c5aa993b | 2734 | char *exec_file; |
c906108c SS |
2735 | |
2736 | exec_file = debug_target.to_pid_to_exec_file (pid); | |
2737 | ||
96baa820 | 2738 | fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n", |
c5aa993b | 2739 | pid, exec_file); |
c906108c SS |
2740 | |
2741 | return exec_file; | |
2742 | } | |
2743 | ||
c906108c | 2744 | static void |
fba45db2 | 2745 | setup_target_debug (void) |
c906108c SS |
2746 | { |
2747 | memcpy (&debug_target, ¤t_target, sizeof debug_target); | |
2748 | ||
2749 | current_target.to_open = debug_to_open; | |
2750 | current_target.to_close = debug_to_close; | |
2751 | current_target.to_attach = debug_to_attach; | |
2752 | current_target.to_post_attach = debug_to_post_attach; | |
c906108c | 2753 | current_target.to_detach = debug_to_detach; |
c906108c SS |
2754 | current_target.to_resume = debug_to_resume; |
2755 | current_target.to_wait = debug_to_wait; | |
c906108c SS |
2756 | current_target.to_fetch_registers = debug_to_fetch_registers; |
2757 | current_target.to_store_registers = debug_to_store_registers; | |
2758 | current_target.to_prepare_to_store = debug_to_prepare_to_store; | |
c8e73a31 | 2759 | current_target.deprecated_xfer_memory = deprecated_debug_xfer_memory; |
c906108c SS |
2760 | current_target.to_files_info = debug_to_files_info; |
2761 | current_target.to_insert_breakpoint = debug_to_insert_breakpoint; | |
2762 | current_target.to_remove_breakpoint = debug_to_remove_breakpoint; | |
ccaa32c7 GS |
2763 | current_target.to_can_use_hw_breakpoint = debug_to_can_use_hw_breakpoint; |
2764 | current_target.to_insert_hw_breakpoint = debug_to_insert_hw_breakpoint; | |
2765 | current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint; | |
2766 | current_target.to_insert_watchpoint = debug_to_insert_watchpoint; | |
2767 | current_target.to_remove_watchpoint = debug_to_remove_watchpoint; | |
2768 | current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint; | |
2769 | current_target.to_stopped_data_address = debug_to_stopped_data_address; | |
e0d24f8d | 2770 | current_target.to_region_ok_for_hw_watchpoint = debug_to_region_ok_for_hw_watchpoint; |
c906108c SS |
2771 | current_target.to_terminal_init = debug_to_terminal_init; |
2772 | current_target.to_terminal_inferior = debug_to_terminal_inferior; | |
2773 | current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output; | |
2774 | current_target.to_terminal_ours = debug_to_terminal_ours; | |
a790ad35 | 2775 | current_target.to_terminal_save_ours = debug_to_terminal_save_ours; |
c906108c SS |
2776 | current_target.to_terminal_info = debug_to_terminal_info; |
2777 | current_target.to_kill = debug_to_kill; | |
2778 | current_target.to_load = debug_to_load; | |
2779 | current_target.to_lookup_symbol = debug_to_lookup_symbol; | |
2780 | current_target.to_create_inferior = debug_to_create_inferior; | |
2781 | current_target.to_post_startup_inferior = debug_to_post_startup_inferior; | |
2782 | current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior; | |
c906108c SS |
2783 | current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint; |
2784 | current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint; | |
2785 | current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint; | |
2786 | current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint; | |
c906108c SS |
2787 | current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint; |
2788 | current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint; | |
c906108c | 2789 | current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call; |
c906108c SS |
2790 | current_target.to_has_exited = debug_to_has_exited; |
2791 | current_target.to_mourn_inferior = debug_to_mourn_inferior; | |
2792 | current_target.to_can_run = debug_to_can_run; | |
2793 | current_target.to_notice_signals = debug_to_notice_signals; | |
2794 | current_target.to_thread_alive = debug_to_thread_alive; | |
0d06e24b | 2795 | current_target.to_find_new_threads = debug_to_find_new_threads; |
c906108c | 2796 | current_target.to_stop = debug_to_stop; |
96baa820 | 2797 | current_target.to_rcmd = debug_to_rcmd; |
c906108c | 2798 | current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file; |
c906108c | 2799 | } |
c906108c | 2800 | \f |
c5aa993b JM |
2801 | |
2802 | static char targ_desc[] = | |
2803 | "Names of targets and files being debugged.\n\ | |
c906108c SS |
2804 | Shows the entire stack of targets currently in use (including the exec-file,\n\ |
2805 | core-file, and process, if any), as well as the symbol file name."; | |
2806 | ||
96baa820 JM |
2807 | static void |
2808 | do_monitor_command (char *cmd, | |
2809 | int from_tty) | |
2810 | { | |
2b5fe715 AC |
2811 | if ((current_target.to_rcmd |
2812 | == (void (*) (char *, struct ui_file *)) tcomplain) | |
96baa820 | 2813 | || (current_target.to_rcmd == debug_to_rcmd |
2b5fe715 AC |
2814 | && (debug_target.to_rcmd |
2815 | == (void (*) (char *, struct ui_file *)) tcomplain))) | |
8a3fe4f8 | 2816 | error (_("\"monitor\" command not supported by this target.")); |
96baa820 JM |
2817 | target_rcmd (cmd, gdb_stdtarg); |
2818 | } | |
2819 | ||
87680a14 JB |
2820 | /* Print the name of each layers of our target stack. */ |
2821 | ||
2822 | static void | |
2823 | maintenance_print_target_stack (char *cmd, int from_tty) | |
2824 | { | |
2825 | struct target_ops *t; | |
2826 | ||
2827 | printf_filtered (_("The current target stack is:\n")); | |
2828 | ||
2829 | for (t = target_stack; t != NULL; t = t->beneath) | |
2830 | { | |
2831 | printf_filtered (" - %s (%s)\n", t->to_shortname, t->to_longname); | |
2832 | } | |
2833 | } | |
2834 | ||
c906108c | 2835 | void |
fba45db2 | 2836 | initialize_targets (void) |
c906108c SS |
2837 | { |
2838 | init_dummy_target (); | |
2839 | push_target (&dummy_target); | |
2840 | ||
2841 | add_info ("target", target_info, targ_desc); | |
2842 | add_info ("files", target_info, targ_desc); | |
2843 | ||
85c07804 AC |
2844 | add_setshow_zinteger_cmd ("target", class_maintenance, &targetdebug, _("\ |
2845 | Set target debugging."), _("\ | |
2846 | Show target debugging."), _("\ | |
333dabeb DJ |
2847 | When non-zero, target debugging is enabled. Higher numbers are more\n\ |
2848 | verbose. Changes do not take effect until the next \"run\" or \"target\"\n\ | |
85c07804 AC |
2849 | command."), |
2850 | NULL, | |
920d2a44 | 2851 | show_targetdebug, |
85c07804 | 2852 | &setdebuglist, &showdebuglist); |
3a11626d | 2853 | |
2bc416ba | 2854 | add_setshow_boolean_cmd ("trust-readonly-sections", class_support, |
7915a72c AC |
2855 | &trust_readonly, _("\ |
2856 | Set mode for reading from readonly sections."), _("\ | |
2857 | Show mode for reading from readonly sections."), _("\ | |
3a11626d MS |
2858 | When this mode is on, memory reads from readonly sections (such as .text)\n\ |
2859 | will be read from the object file instead of from the target. This will\n\ | |
7915a72c | 2860 | result in significant performance improvement for remote targets."), |
2c5b56ce | 2861 | NULL, |
920d2a44 | 2862 | show_trust_readonly, |
e707bbc2 | 2863 | &setlist, &showlist); |
96baa820 JM |
2864 | |
2865 | add_com ("monitor", class_obscure, do_monitor_command, | |
1bedd215 | 2866 | _("Send a command to the remote monitor (remote targets only).")); |
96baa820 | 2867 | |
87680a14 JB |
2868 | add_cmd ("target-stack", class_maintenance, maintenance_print_target_stack, |
2869 | _("Print the name of each layer of the internal target stack."), | |
2870 | &maintenanceprintlist); | |
2871 | ||
8add0441 | 2872 | target_dcache = dcache_init (); |
c906108c | 2873 | } |