Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Select target systems and architectures at runtime for GDB. |
7998dfc3 AC |
2 | |
3 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, | |
4 | 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. | |
5 | ||
c906108c SS |
6 | Contributed by Cygnus Support. |
7 | ||
c5aa993b | 8 | This file is part of GDB. |
c906108c | 9 | |
c5aa993b JM |
10 | This program is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
c906108c | 14 | |
c5aa993b JM |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
c906108c | 19 | |
c5aa993b JM |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software | |
22 | Foundation, Inc., 59 Temple Place - Suite 330, | |
23 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
24 | |
25 | #include "defs.h" | |
26 | #include <errno.h> | |
c906108c SS |
27 | #include "gdb_string.h" |
28 | #include "target.h" | |
29 | #include "gdbcmd.h" | |
30 | #include "symtab.h" | |
31 | #include "inferior.h" | |
32 | #include "bfd.h" | |
33 | #include "symfile.h" | |
34 | #include "objfiles.h" | |
03f2053f | 35 | #include "gdb_wait.h" |
4930751a | 36 | #include "dcache.h" |
c906108c | 37 | #include <signal.h> |
4e052eda | 38 | #include "regcache.h" |
c906108c SS |
39 | |
40 | extern int errno; | |
41 | ||
a14ed312 | 42 | static void target_info (char *, int); |
c906108c | 43 | |
a14ed312 | 44 | static void maybe_kill_then_create_inferior (char *, char *, char **); |
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 | |
ccaa32c7 GS |
52 | static int default_region_size_ok_for_hw_watchpoint (int); |
53 | ||
a14ed312 | 54 | static int nosymbol (char *, CORE_ADDR *); |
c906108c | 55 | |
a14ed312 | 56 | static void tcomplain (void); |
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 | |
39f77062 | 74 | static void normal_target_post_startup_inferior (ptid_t ptid); |
392a587b | 75 | |
917317f4 JM |
76 | /* Transfer LEN bytes between target address MEMADDR and GDB address |
77 | MYADDR. Returns 0 for success, errno code for failure (which | |
78 | includes partial transfers -- if you want a more useful response to | |
79 | partial transfers, try either target_read_memory_partial or | |
80 | target_write_memory_partial). */ | |
c906108c | 81 | |
570b8f7c AC |
82 | static int target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, |
83 | int write); | |
c906108c | 84 | |
a14ed312 | 85 | static void init_dummy_target (void); |
c906108c | 86 | |
a14ed312 | 87 | static void debug_to_open (char *, int); |
c906108c | 88 | |
a14ed312 | 89 | static void debug_to_close (int); |
c906108c | 90 | |
a14ed312 | 91 | static void debug_to_attach (char *, int); |
c906108c | 92 | |
a14ed312 | 93 | static void debug_to_detach (char *, int); |
c906108c | 94 | |
6ad8ae5c DJ |
95 | static void debug_to_disconnect (char *, int); |
96 | ||
39f77062 | 97 | static void debug_to_resume (ptid_t, int, enum target_signal); |
c906108c | 98 | |
39f77062 | 99 | static ptid_t debug_to_wait (ptid_t, struct target_waitstatus *); |
c906108c | 100 | |
a14ed312 | 101 | static void debug_to_fetch_registers (int); |
c906108c | 102 | |
a14ed312 | 103 | static void debug_to_store_registers (int); |
c906108c | 104 | |
a14ed312 | 105 | static void debug_to_prepare_to_store (void); |
c906108c | 106 | |
5ae5f592 AC |
107 | static int debug_to_xfer_memory (CORE_ADDR, char *, int, int, |
108 | struct mem_attrib *, struct target_ops *); | |
c906108c | 109 | |
a14ed312 | 110 | static void debug_to_files_info (struct target_ops *); |
c906108c | 111 | |
a14ed312 | 112 | static int debug_to_insert_breakpoint (CORE_ADDR, char *); |
c906108c | 113 | |
a14ed312 | 114 | static int debug_to_remove_breakpoint (CORE_ADDR, char *); |
c906108c | 115 | |
ccaa32c7 GS |
116 | static int debug_to_can_use_hw_breakpoint (int, int, int); |
117 | ||
118 | static int debug_to_insert_hw_breakpoint (CORE_ADDR, char *); | |
119 | ||
120 | static int debug_to_remove_hw_breakpoint (CORE_ADDR, char *); | |
121 | ||
122 | static int debug_to_insert_watchpoint (CORE_ADDR, int, int); | |
123 | ||
124 | static int debug_to_remove_watchpoint (CORE_ADDR, int, int); | |
125 | ||
126 | static int debug_to_stopped_by_watchpoint (void); | |
127 | ||
128 | static CORE_ADDR debug_to_stopped_data_address (void); | |
129 | ||
130 | static int debug_to_region_size_ok_for_hw_watchpoint (int); | |
131 | ||
a14ed312 | 132 | static void debug_to_terminal_init (void); |
c906108c | 133 | |
a14ed312 | 134 | static void debug_to_terminal_inferior (void); |
c906108c | 135 | |
a14ed312 | 136 | static void debug_to_terminal_ours_for_output (void); |
c906108c | 137 | |
a790ad35 SC |
138 | static void debug_to_terminal_save_ours (void); |
139 | ||
a14ed312 | 140 | static void debug_to_terminal_ours (void); |
c906108c | 141 | |
a14ed312 | 142 | static void debug_to_terminal_info (char *, int); |
c906108c | 143 | |
a14ed312 | 144 | static void debug_to_kill (void); |
c906108c | 145 | |
a14ed312 | 146 | static void debug_to_load (char *, int); |
c906108c | 147 | |
a14ed312 | 148 | static int debug_to_lookup_symbol (char *, CORE_ADDR *); |
c906108c | 149 | |
a14ed312 | 150 | static void debug_to_create_inferior (char *, char *, char **); |
c906108c | 151 | |
a14ed312 | 152 | static void debug_to_mourn_inferior (void); |
c906108c | 153 | |
a14ed312 | 154 | static int debug_to_can_run (void); |
c906108c | 155 | |
39f77062 | 156 | static void debug_to_notice_signals (ptid_t); |
c906108c | 157 | |
39f77062 | 158 | static int debug_to_thread_alive (ptid_t); |
c906108c | 159 | |
a14ed312 | 160 | static void debug_to_stop (void); |
c906108c | 161 | |
c906108c SS |
162 | /* Pointer to array of target architecture structures; the size of the |
163 | array; the current index into the array; the allocated size of the | |
164 | array. */ | |
165 | struct target_ops **target_structs; | |
166 | unsigned target_struct_size; | |
167 | unsigned target_struct_index; | |
168 | unsigned target_struct_allocsize; | |
169 | #define DEFAULT_ALLOCSIZE 10 | |
170 | ||
171 | /* The initial current target, so that there is always a semi-valid | |
172 | current target. */ | |
173 | ||
174 | static struct target_ops dummy_target; | |
175 | ||
176 | /* Top of target stack. */ | |
177 | ||
258b763a | 178 | static struct target_ops *target_stack; |
c906108c SS |
179 | |
180 | /* The target structure we are currently using to talk to a process | |
181 | or file or whatever "inferior" we have. */ | |
182 | ||
183 | struct target_ops current_target; | |
184 | ||
185 | /* Command list for target. */ | |
186 | ||
187 | static struct cmd_list_element *targetlist = NULL; | |
188 | ||
189 | /* Nonzero if we are debugging an attached outside process | |
190 | rather than an inferior. */ | |
191 | ||
192 | int attach_flag; | |
193 | ||
c906108c SS |
194 | /* Non-zero if we want to see trace of target level stuff. */ |
195 | ||
196 | static int targetdebug = 0; | |
197 | ||
a14ed312 | 198 | static void setup_target_debug (void); |
c906108c | 199 | |
4930751a C |
200 | DCACHE *target_dcache; |
201 | ||
c906108c SS |
202 | /* The user just typed 'target' without the name of a target. */ |
203 | ||
c906108c | 204 | static void |
fba45db2 | 205 | target_command (char *arg, int from_tty) |
c906108c SS |
206 | { |
207 | fputs_filtered ("Argument required (target name). Try `help target'\n", | |
208 | gdb_stdout); | |
209 | } | |
210 | ||
211 | /* Add a possible target architecture to the list. */ | |
212 | ||
213 | void | |
fba45db2 | 214 | add_target (struct target_ops *t) |
c906108c SS |
215 | { |
216 | if (!target_structs) | |
217 | { | |
218 | target_struct_allocsize = DEFAULT_ALLOCSIZE; | |
219 | target_structs = (struct target_ops **) xmalloc | |
220 | (target_struct_allocsize * sizeof (*target_structs)); | |
221 | } | |
222 | if (target_struct_size >= target_struct_allocsize) | |
223 | { | |
224 | target_struct_allocsize *= 2; | |
225 | target_structs = (struct target_ops **) | |
c5aa993b JM |
226 | xrealloc ((char *) target_structs, |
227 | target_struct_allocsize * sizeof (*target_structs)); | |
c906108c SS |
228 | } |
229 | target_structs[target_struct_size++] = t; | |
c906108c SS |
230 | |
231 | if (targetlist == NULL) | |
232 | add_prefix_cmd ("target", class_run, target_command, | |
233 | "Connect to a target machine or process.\n\ | |
234 | The first argument is the type or protocol of the target machine.\n\ | |
235 | Remaining arguments are interpreted by the target protocol. For more\n\ | |
236 | information on the arguments for a particular protocol, type\n\ | |
237 | `help target ' followed by the protocol name.", | |
238 | &targetlist, "target ", 0, &cmdlist); | |
239 | add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist); | |
240 | } | |
241 | ||
242 | /* Stub functions */ | |
243 | ||
244 | void | |
fba45db2 | 245 | target_ignore (void) |
c906108c SS |
246 | { |
247 | } | |
248 | ||
11cf8741 JM |
249 | void |
250 | target_load (char *arg, int from_tty) | |
251 | { | |
4930751a | 252 | dcache_invalidate (target_dcache); |
11cf8741 JM |
253 | (*current_target.to_load) (arg, from_tty); |
254 | } | |
255 | ||
c906108c | 256 | static int |
fba45db2 KB |
257 | nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write, |
258 | struct target_ops *t) | |
c906108c | 259 | { |
c5aa993b JM |
260 | errno = EIO; /* Can't read/write this location */ |
261 | return 0; /* No bytes handled */ | |
c906108c SS |
262 | } |
263 | ||
264 | static void | |
fba45db2 | 265 | tcomplain (void) |
c906108c SS |
266 | { |
267 | error ("You can't do that when your target is `%s'", | |
268 | current_target.to_shortname); | |
269 | } | |
270 | ||
271 | void | |
fba45db2 | 272 | noprocess (void) |
c906108c SS |
273 | { |
274 | error ("You can't do that without a process to debug."); | |
275 | } | |
276 | ||
c906108c | 277 | static int |
fba45db2 | 278 | nosymbol (char *name, CORE_ADDR *addrp) |
c906108c | 279 | { |
c5aa993b | 280 | return 1; /* Symbol does not exist in target env */ |
c906108c SS |
281 | } |
282 | ||
392a587b | 283 | static void |
fba45db2 | 284 | nosupport_runtime (void) |
c906108c | 285 | { |
39f77062 | 286 | if (ptid_equal (inferior_ptid, null_ptid)) |
c906108c SS |
287 | noprocess (); |
288 | else | |
289 | error ("No run-time support for this"); | |
290 | } | |
291 | ||
292 | ||
c906108c | 293 | static void |
fba45db2 | 294 | default_terminal_info (char *args, int from_tty) |
c906108c | 295 | { |
c5aa993b | 296 | printf_unfiltered ("No saved terminal information.\n"); |
c906108c SS |
297 | } |
298 | ||
299 | /* This is the default target_create_inferior and target_attach function. | |
300 | If the current target is executing, it asks whether to kill it off. | |
301 | If this function returns without calling error(), it has killed off | |
302 | the target, and the operation should be attempted. */ | |
303 | ||
304 | static void | |
fba45db2 | 305 | kill_or_be_killed (int from_tty) |
c906108c SS |
306 | { |
307 | if (target_has_execution) | |
308 | { | |
309 | printf_unfiltered ("You are already running a program:\n"); | |
310 | target_files_info (); | |
c5aa993b JM |
311 | if (query ("Kill it? ")) |
312 | { | |
313 | target_kill (); | |
314 | if (target_has_execution) | |
315 | error ("Killing the program did not help."); | |
316 | return; | |
317 | } | |
318 | else | |
319 | { | |
320 | error ("Program not killed."); | |
321 | } | |
c906108c | 322 | } |
c5aa993b | 323 | tcomplain (); |
c906108c SS |
324 | } |
325 | ||
326 | static void | |
fba45db2 | 327 | maybe_kill_then_attach (char *args, int from_tty) |
c906108c SS |
328 | { |
329 | kill_or_be_killed (from_tty); | |
330 | target_attach (args, from_tty); | |
331 | } | |
332 | ||
333 | static void | |
fba45db2 | 334 | maybe_kill_then_create_inferior (char *exec, char *args, char **env) |
c906108c SS |
335 | { |
336 | kill_or_be_killed (0); | |
337 | target_create_inferior (exec, args, env); | |
338 | } | |
339 | ||
7998dfc3 AC |
340 | /* Go through the target stack from top to bottom, copying over zero |
341 | entries in current_target, then filling in still empty entries. In | |
342 | effect, we are doing class inheritance through the pushed target | |
343 | vectors. | |
344 | ||
345 | NOTE: cagney/2003-10-17: The problem with this inheritance, as it | |
346 | is currently implemented, is that it discards any knowledge of | |
347 | which target an inherited method originally belonged to. | |
348 | Consequently, new new target methods should instead explicitly and | |
349 | locally search the target stack for the target that can handle the | |
350 | request. */ | |
c906108c SS |
351 | |
352 | static void | |
7998dfc3 | 353 | update_current_target (void) |
c906108c | 354 | { |
7998dfc3 AC |
355 | struct target_ops *t; |
356 | ||
357 | /* First, reset curren'ts contents. */ | |
358 | memset (¤t_target, 0, sizeof (current_target)); | |
359 | ||
360 | #define INHERIT(FIELD, TARGET) \ | |
361 | if (!current_target.FIELD) \ | |
362 | current_target.FIELD = (TARGET)->FIELD | |
363 | ||
364 | for (t = target_stack; t; t = t->beneath) | |
365 | { | |
366 | INHERIT (to_shortname, t); | |
367 | INHERIT (to_longname, t); | |
368 | INHERIT (to_doc, t); | |
369 | INHERIT (to_open, t); | |
370 | INHERIT (to_close, t); | |
371 | INHERIT (to_attach, t); | |
372 | INHERIT (to_post_attach, t); | |
373 | INHERIT (to_detach, t); | |
374 | INHERIT (to_disconnect, t); | |
375 | INHERIT (to_resume, t); | |
376 | INHERIT (to_wait, t); | |
377 | INHERIT (to_post_wait, t); | |
378 | INHERIT (to_fetch_registers, t); | |
379 | INHERIT (to_store_registers, t); | |
380 | INHERIT (to_prepare_to_store, t); | |
381 | INHERIT (to_xfer_memory, t); | |
382 | INHERIT (to_files_info, t); | |
383 | INHERIT (to_insert_breakpoint, t); | |
384 | INHERIT (to_remove_breakpoint, t); | |
385 | INHERIT (to_can_use_hw_breakpoint, t); | |
386 | INHERIT (to_insert_hw_breakpoint, t); | |
387 | INHERIT (to_remove_hw_breakpoint, t); | |
388 | INHERIT (to_insert_watchpoint, t); | |
389 | INHERIT (to_remove_watchpoint, t); | |
390 | INHERIT (to_stopped_data_address, t); | |
391 | INHERIT (to_stopped_by_watchpoint, t); | |
392 | INHERIT (to_have_continuable_watchpoint, t); | |
393 | INHERIT (to_region_size_ok_for_hw_watchpoint, t); | |
394 | INHERIT (to_terminal_init, t); | |
395 | INHERIT (to_terminal_inferior, t); | |
396 | INHERIT (to_terminal_ours_for_output, t); | |
397 | INHERIT (to_terminal_ours, t); | |
398 | INHERIT (to_terminal_save_ours, t); | |
399 | INHERIT (to_terminal_info, t); | |
400 | INHERIT (to_kill, t); | |
401 | INHERIT (to_load, t); | |
402 | INHERIT (to_lookup_symbol, t); | |
403 | INHERIT (to_create_inferior, t); | |
404 | INHERIT (to_post_startup_inferior, t); | |
405 | INHERIT (to_acknowledge_created_inferior, t); | |
406 | INHERIT (to_insert_fork_catchpoint, t); | |
407 | INHERIT (to_remove_fork_catchpoint, t); | |
408 | INHERIT (to_insert_vfork_catchpoint, t); | |
409 | INHERIT (to_remove_vfork_catchpoint, t); | |
410 | INHERIT (to_follow_fork, t); | |
411 | INHERIT (to_insert_exec_catchpoint, t); | |
412 | INHERIT (to_remove_exec_catchpoint, t); | |
413 | INHERIT (to_reported_exec_events_per_exec_call, t); | |
414 | INHERIT (to_has_exited, t); | |
415 | INHERIT (to_mourn_inferior, t); | |
416 | INHERIT (to_can_run, t); | |
417 | INHERIT (to_notice_signals, t); | |
418 | INHERIT (to_thread_alive, t); | |
419 | INHERIT (to_find_new_threads, t); | |
420 | INHERIT (to_pid_to_str, t); | |
421 | INHERIT (to_extra_thread_info, t); | |
422 | INHERIT (to_stop, t); | |
1e3ff5ad AC |
423 | /* Do not inherit to_read_partial. */ |
424 | /* Do not inherit to_write_partial. */ | |
7998dfc3 AC |
425 | INHERIT (to_rcmd, t); |
426 | INHERIT (to_enable_exception_callback, t); | |
427 | INHERIT (to_get_current_exception_event, t); | |
428 | INHERIT (to_pid_to_exec_file, t); | |
429 | INHERIT (to_stratum, t); | |
430 | INHERIT (to_has_all_memory, t); | |
431 | INHERIT (to_has_memory, t); | |
432 | INHERIT (to_has_stack, t); | |
433 | INHERIT (to_has_registers, t); | |
434 | INHERIT (to_has_execution, t); | |
435 | INHERIT (to_has_thread_control, t); | |
436 | INHERIT (to_sections, t); | |
437 | INHERIT (to_sections_end, t); | |
438 | INHERIT (to_can_async_p, t); | |
439 | INHERIT (to_is_async_p, t); | |
440 | INHERIT (to_async, t); | |
441 | INHERIT (to_async_mask_value, t); | |
442 | INHERIT (to_find_memory_regions, t); | |
443 | INHERIT (to_make_corefile_notes, t); | |
444 | INHERIT (to_get_thread_local_address, t); | |
445 | INHERIT (to_magic, t); | |
446 | } | |
447 | #undef INHERIT | |
448 | ||
449 | /* Clean up a target struct so it no longer has any zero pointers in | |
450 | it. We default entries, at least to stubs that print error | |
451 | messages. */ | |
c906108c SS |
452 | |
453 | #define de_fault(field, value) \ | |
7998dfc3 AC |
454 | if (!current_target.field) \ |
455 | current_target.field = value | |
0d06e24b JM |
456 | |
457 | de_fault (to_open, | |
458 | (void (*) (char *, int)) | |
459 | tcomplain); | |
460 | de_fault (to_close, | |
461 | (void (*) (int)) | |
462 | target_ignore); | |
463 | de_fault (to_attach, | |
464 | maybe_kill_then_attach); | |
465 | de_fault (to_post_attach, | |
466 | (void (*) (int)) | |
467 | target_ignore); | |
0d06e24b JM |
468 | de_fault (to_detach, |
469 | (void (*) (char *, int)) | |
470 | target_ignore); | |
6ad8ae5c DJ |
471 | de_fault (to_disconnect, |
472 | (void (*) (char *, int)) | |
473 | tcomplain); | |
0d06e24b | 474 | de_fault (to_resume, |
39f77062 | 475 | (void (*) (ptid_t, int, enum target_signal)) |
0d06e24b JM |
476 | noprocess); |
477 | de_fault (to_wait, | |
39f77062 | 478 | (ptid_t (*) (ptid_t, struct target_waitstatus *)) |
0d06e24b JM |
479 | noprocess); |
480 | de_fault (to_post_wait, | |
39f77062 | 481 | (void (*) (ptid_t, int)) |
0d06e24b JM |
482 | target_ignore); |
483 | de_fault (to_fetch_registers, | |
484 | (void (*) (int)) | |
485 | target_ignore); | |
486 | de_fault (to_store_registers, | |
487 | (void (*) (int)) | |
488 | noprocess); | |
489 | de_fault (to_prepare_to_store, | |
490 | (void (*) (void)) | |
491 | noprocess); | |
492 | de_fault (to_xfer_memory, | |
29e57380 | 493 | (int (*) (CORE_ADDR, char *, int, int, struct mem_attrib *, struct target_ops *)) |
0d06e24b JM |
494 | nomemory); |
495 | de_fault (to_files_info, | |
496 | (void (*) (struct target_ops *)) | |
497 | target_ignore); | |
498 | de_fault (to_insert_breakpoint, | |
499 | memory_insert_breakpoint); | |
500 | de_fault (to_remove_breakpoint, | |
501 | memory_remove_breakpoint); | |
ccaa32c7 GS |
502 | de_fault (to_can_use_hw_breakpoint, |
503 | (int (*) (int, int, int)) | |
504 | return_zero); | |
505 | de_fault (to_insert_hw_breakpoint, | |
506 | (int (*) (CORE_ADDR, char *)) | |
507 | return_minus_one); | |
508 | de_fault (to_remove_hw_breakpoint, | |
509 | (int (*) (CORE_ADDR, char *)) | |
510 | return_minus_one); | |
511 | de_fault (to_insert_watchpoint, | |
512 | (int (*) (CORE_ADDR, int, int)) | |
513 | return_minus_one); | |
514 | de_fault (to_remove_watchpoint, | |
515 | (int (*) (CORE_ADDR, int, int)) | |
516 | return_minus_one); | |
517 | de_fault (to_stopped_by_watchpoint, | |
518 | (int (*) (void)) | |
519 | return_zero); | |
520 | de_fault (to_stopped_data_address, | |
521 | (CORE_ADDR (*) (void)) | |
522 | return_zero); | |
523 | de_fault (to_region_size_ok_for_hw_watchpoint, | |
524 | default_region_size_ok_for_hw_watchpoint); | |
0d06e24b JM |
525 | de_fault (to_terminal_init, |
526 | (void (*) (void)) | |
527 | target_ignore); | |
528 | de_fault (to_terminal_inferior, | |
529 | (void (*) (void)) | |
530 | target_ignore); | |
531 | de_fault (to_terminal_ours_for_output, | |
532 | (void (*) (void)) | |
533 | target_ignore); | |
534 | de_fault (to_terminal_ours, | |
535 | (void (*) (void)) | |
536 | target_ignore); | |
a790ad35 SC |
537 | de_fault (to_terminal_save_ours, |
538 | (void (*) (void)) | |
539 | target_ignore); | |
0d06e24b JM |
540 | de_fault (to_terminal_info, |
541 | default_terminal_info); | |
542 | de_fault (to_kill, | |
543 | (void (*) (void)) | |
544 | noprocess); | |
545 | de_fault (to_load, | |
546 | (void (*) (char *, int)) | |
547 | tcomplain); | |
548 | de_fault (to_lookup_symbol, | |
549 | (int (*) (char *, CORE_ADDR *)) | |
550 | nosymbol); | |
551 | de_fault (to_create_inferior, | |
552 | maybe_kill_then_create_inferior); | |
553 | de_fault (to_post_startup_inferior, | |
39f77062 | 554 | (void (*) (ptid_t)) |
0d06e24b JM |
555 | target_ignore); |
556 | de_fault (to_acknowledge_created_inferior, | |
557 | (void (*) (int)) | |
558 | target_ignore); | |
0d06e24b JM |
559 | de_fault (to_insert_fork_catchpoint, |
560 | (int (*) (int)) | |
561 | tcomplain); | |
562 | de_fault (to_remove_fork_catchpoint, | |
563 | (int (*) (int)) | |
564 | tcomplain); | |
565 | de_fault (to_insert_vfork_catchpoint, | |
566 | (int (*) (int)) | |
567 | tcomplain); | |
568 | de_fault (to_remove_vfork_catchpoint, | |
569 | (int (*) (int)) | |
570 | tcomplain); | |
4c9ba7e0 | 571 | de_fault (to_follow_fork, |
6604731b | 572 | (int (*) (int)) |
0d06e24b JM |
573 | target_ignore); |
574 | de_fault (to_insert_exec_catchpoint, | |
575 | (int (*) (int)) | |
576 | tcomplain); | |
577 | de_fault (to_remove_exec_catchpoint, | |
578 | (int (*) (int)) | |
579 | tcomplain); | |
0d06e24b JM |
580 | de_fault (to_reported_exec_events_per_exec_call, |
581 | (int (*) (void)) | |
582 | return_one); | |
0d06e24b JM |
583 | de_fault (to_has_exited, |
584 | (int (*) (int, int, int *)) | |
585 | return_zero); | |
586 | de_fault (to_mourn_inferior, | |
587 | (void (*) (void)) | |
588 | noprocess); | |
589 | de_fault (to_can_run, | |
590 | return_zero); | |
591 | de_fault (to_notice_signals, | |
39f77062 | 592 | (void (*) (ptid_t)) |
0d06e24b JM |
593 | target_ignore); |
594 | de_fault (to_thread_alive, | |
39f77062 | 595 | (int (*) (ptid_t)) |
0d06e24b JM |
596 | return_zero); |
597 | de_fault (to_find_new_threads, | |
598 | (void (*) (void)) | |
599 | target_ignore); | |
600 | de_fault (to_extra_thread_info, | |
601 | (char *(*) (struct thread_info *)) | |
602 | return_zero); | |
603 | de_fault (to_stop, | |
604 | (void (*) (void)) | |
605 | target_ignore); | |
0d06e24b | 606 | de_fault (to_rcmd, |
d9fcf2fb | 607 | (void (*) (char *, struct ui_file *)) |
0d06e24b JM |
608 | tcomplain); |
609 | de_fault (to_enable_exception_callback, | |
610 | (struct symtab_and_line * (*) (enum exception_event_kind, int)) | |
611 | nosupport_runtime); | |
612 | de_fault (to_get_current_exception_event, | |
613 | (struct exception_event_record * (*) (void)) | |
614 | nosupport_runtime); | |
615 | de_fault (to_pid_to_exec_file, | |
616 | (char *(*) (int)) | |
617 | return_zero); | |
0d06e24b JM |
618 | de_fault (to_can_async_p, |
619 | (int (*) (void)) | |
620 | return_zero); | |
621 | de_fault (to_is_async_p, | |
622 | (int (*) (void)) | |
623 | return_zero); | |
624 | de_fault (to_async, | |
625 | (void (*) (void (*) (enum inferior_event_type, void*), void*)) | |
626 | tcomplain); | |
c906108c | 627 | #undef de_fault |
c906108c | 628 | |
7998dfc3 AC |
629 | /* Finally, position the target-stack beneath the squashed |
630 | "current_target". That way code looking for a non-inherited | |
631 | target method can quickly and simply find it. */ | |
632 | current_target.beneath = target_stack; | |
c906108c SS |
633 | } |
634 | ||
635 | /* Push a new target type into the stack of the existing target accessors, | |
636 | possibly superseding some of the existing accessors. | |
637 | ||
638 | Result is zero if the pushed target ended up on top of the stack, | |
639 | nonzero if at least one target is on top of it. | |
640 | ||
641 | Rather than allow an empty stack, we always have the dummy target at | |
642 | the bottom stratum, so we can call the function vectors without | |
643 | checking them. */ | |
644 | ||
645 | int | |
fba45db2 | 646 | push_target (struct target_ops *t) |
c906108c | 647 | { |
258b763a | 648 | struct target_ops **cur; |
c906108c SS |
649 | |
650 | /* Check magic number. If wrong, it probably means someone changed | |
651 | the struct definition, but not all the places that initialize one. */ | |
652 | if (t->to_magic != OPS_MAGIC) | |
653 | { | |
c5aa993b JM |
654 | fprintf_unfiltered (gdb_stderr, |
655 | "Magic number of %s target struct wrong\n", | |
656 | t->to_shortname); | |
e1e9e218 | 657 | internal_error (__FILE__, __LINE__, "failed internal consistency check"); |
c906108c SS |
658 | } |
659 | ||
258b763a AC |
660 | /* Find the proper stratum to install this target in. */ |
661 | for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath) | |
c906108c | 662 | { |
258b763a | 663 | if ((int) (t->to_stratum) >= (int) (*cur)->to_stratum) |
c906108c SS |
664 | break; |
665 | } | |
666 | ||
258b763a AC |
667 | /* If there's already targets at this stratum, remove them. */ |
668 | /* FIXME: cagney/2003-10-15: I think this should be poping all | |
669 | targets to CUR, and not just those at this stratum level. */ | |
670 | while ((*cur) != NULL && t->to_stratum == (*cur)->to_stratum) | |
671 | { | |
672 | /* There's already something at this stratum level. Close it, | |
673 | and un-hook it from the stack. */ | |
674 | struct target_ops *tmp = (*cur); | |
675 | (*cur) = (*cur)->beneath; | |
676 | tmp->beneath = NULL; | |
677 | if (tmp->to_close) | |
678 | (tmp->to_close) (0); | |
679 | } | |
c906108c SS |
680 | |
681 | /* We have removed all targets in our stratum, now add the new one. */ | |
258b763a AC |
682 | t->beneath = (*cur); |
683 | (*cur) = t; | |
c906108c SS |
684 | |
685 | update_current_target (); | |
686 | ||
c906108c SS |
687 | if (targetdebug) |
688 | setup_target_debug (); | |
c906108c | 689 | |
258b763a AC |
690 | /* Not on top? */ |
691 | return (t != target_stack); | |
c906108c SS |
692 | } |
693 | ||
694 | /* Remove a target_ops vector from the stack, wherever it may be. | |
695 | Return how many times it was removed (0 or 1). */ | |
696 | ||
697 | int | |
fba45db2 | 698 | unpush_target (struct target_ops *t) |
c906108c | 699 | { |
258b763a AC |
700 | struct target_ops **cur; |
701 | struct target_ops *tmp; | |
c906108c SS |
702 | |
703 | if (t->to_close) | |
704 | t->to_close (0); /* Let it clean up */ | |
705 | ||
706 | /* Look for the specified target. Note that we assume that a target | |
707 | can only occur once in the target stack. */ | |
708 | ||
258b763a AC |
709 | for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath) |
710 | { | |
711 | if ((*cur) == t) | |
712 | break; | |
713 | } | |
c906108c | 714 | |
258b763a | 715 | if ((*cur) == NULL) |
c906108c SS |
716 | return 0; /* Didn't find target_ops, quit now */ |
717 | ||
718 | /* Unchain the target */ | |
258b763a AC |
719 | tmp = (*cur); |
720 | (*cur) = (*cur)->beneath; | |
721 | tmp->beneath = NULL; | |
c906108c SS |
722 | |
723 | update_current_target (); | |
c906108c SS |
724 | |
725 | return 1; | |
726 | } | |
727 | ||
728 | void | |
fba45db2 | 729 | pop_target (void) |
c906108c | 730 | { |
c5aa993b | 731 | (current_target.to_close) (0); /* Let it clean up */ |
258b763a | 732 | if (unpush_target (target_stack) == 1) |
c906108c SS |
733 | return; |
734 | ||
c5aa993b JM |
735 | fprintf_unfiltered (gdb_stderr, |
736 | "pop_target couldn't find target %s\n", | |
737 | current_target.to_shortname); | |
e1e9e218 | 738 | internal_error (__FILE__, __LINE__, "failed internal consistency check"); |
c906108c SS |
739 | } |
740 | ||
741 | #undef MIN | |
742 | #define MIN(A, B) (((A) <= (B)) ? (A) : (B)) | |
743 | ||
744 | /* target_read_string -- read a null terminated string, up to LEN bytes, | |
745 | from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful. | |
746 | Set *STRING to a pointer to malloc'd memory containing the data; the caller | |
747 | is responsible for freeing it. Return the number of bytes successfully | |
748 | read. */ | |
749 | ||
750 | int | |
fba45db2 | 751 | target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop) |
c906108c SS |
752 | { |
753 | int tlen, origlen, offset, i; | |
754 | char buf[4]; | |
755 | int errcode = 0; | |
756 | char *buffer; | |
757 | int buffer_allocated; | |
758 | char *bufptr; | |
759 | unsigned int nbytes_read = 0; | |
760 | ||
761 | /* Small for testing. */ | |
762 | buffer_allocated = 4; | |
763 | buffer = xmalloc (buffer_allocated); | |
764 | bufptr = buffer; | |
765 | ||
766 | origlen = len; | |
767 | ||
768 | while (len > 0) | |
769 | { | |
770 | tlen = MIN (len, 4 - (memaddr & 3)); | |
771 | offset = memaddr & 3; | |
772 | ||
d4b2399a | 773 | errcode = target_xfer_memory (memaddr & ~3, buf, 4, 0); |
c906108c SS |
774 | if (errcode != 0) |
775 | { | |
776 | /* The transfer request might have crossed the boundary to an | |
777 | unallocated region of memory. Retry the transfer, requesting | |
778 | a single byte. */ | |
779 | tlen = 1; | |
780 | offset = 0; | |
d4b2399a | 781 | errcode = target_xfer_memory (memaddr, buf, 1, 0); |
c906108c SS |
782 | if (errcode != 0) |
783 | goto done; | |
784 | } | |
785 | ||
786 | if (bufptr - buffer + tlen > buffer_allocated) | |
787 | { | |
788 | unsigned int bytes; | |
789 | bytes = bufptr - buffer; | |
790 | buffer_allocated *= 2; | |
791 | buffer = xrealloc (buffer, buffer_allocated); | |
792 | bufptr = buffer + bytes; | |
793 | } | |
794 | ||
795 | for (i = 0; i < tlen; i++) | |
796 | { | |
797 | *bufptr++ = buf[i + offset]; | |
798 | if (buf[i + offset] == '\000') | |
799 | { | |
800 | nbytes_read += i + 1; | |
801 | goto done; | |
802 | } | |
803 | } | |
804 | ||
805 | memaddr += tlen; | |
806 | len -= tlen; | |
807 | nbytes_read += tlen; | |
808 | } | |
c5aa993b | 809 | done: |
c906108c SS |
810 | if (errnop != NULL) |
811 | *errnop = errcode; | |
812 | if (string != NULL) | |
813 | *string = buffer; | |
814 | return nbytes_read; | |
815 | } | |
816 | ||
8db32d44 AC |
817 | /* Find a section containing ADDR. */ |
818 | struct section_table * | |
819 | target_section_by_addr (struct target_ops *target, CORE_ADDR addr) | |
820 | { | |
821 | struct section_table *secp; | |
822 | for (secp = target->to_sections; | |
823 | secp < target->to_sections_end; | |
824 | secp++) | |
825 | { | |
826 | if (addr >= secp->addr && addr < secp->endaddr) | |
827 | return secp; | |
828 | } | |
829 | return NULL; | |
830 | } | |
831 | ||
c906108c SS |
832 | /* Read LEN bytes of target memory at address MEMADDR, placing the results in |
833 | GDB's memory at MYADDR. Returns either 0 for success or an errno value | |
834 | if any error occurs. | |
835 | ||
836 | If an error occurs, no guarantee is made about the contents of the data at | |
837 | MYADDR. In particular, the caller should not depend upon partial reads | |
838 | filling the buffer with good data. There is no way for the caller to know | |
839 | how much good data might have been transfered anyway. Callers that can | |
840 | deal with partial reads should call target_read_memory_partial. */ | |
841 | ||
842 | int | |
fba45db2 | 843 | target_read_memory (CORE_ADDR memaddr, char *myaddr, int len) |
c906108c | 844 | { |
d4b2399a | 845 | return target_xfer_memory (memaddr, myaddr, len, 0); |
c906108c SS |
846 | } |
847 | ||
c906108c | 848 | int |
fba45db2 | 849 | target_write_memory (CORE_ADDR memaddr, char *myaddr, int len) |
c906108c | 850 | { |
d4b2399a | 851 | return target_xfer_memory (memaddr, myaddr, len, 1); |
c906108c | 852 | } |
c5aa993b | 853 | |
3a11626d MS |
854 | static int trust_readonly = 0; |
855 | ||
67e0617e C |
856 | /* Move memory to or from the targets. The top target gets priority; |
857 | if it cannot handle it, it is offered to the next one down, etc. | |
c906108c | 858 | |
67e0617e | 859 | Result is -1 on error, or the number of bytes transfered. */ |
c906108c | 860 | |
4930751a | 861 | int |
29e57380 C |
862 | do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write, |
863 | struct mem_attrib *attrib) | |
c906108c | 864 | { |
c906108c | 865 | int res; |
4930751a | 866 | int done = 0; |
c906108c | 867 | struct target_ops *t; |
c906108c SS |
868 | |
869 | /* Zero length requests are ok and require no work. */ | |
870 | if (len == 0) | |
871 | return 0; | |
872 | ||
c906108c SS |
873 | /* to_xfer_memory is not guaranteed to set errno, even when it returns |
874 | 0. */ | |
875 | errno = 0; | |
876 | ||
3a11626d MS |
877 | if (!write && trust_readonly) |
878 | { | |
8db32d44 | 879 | struct section_table *secp; |
2ceb85d0 BE |
880 | /* User-settable option, "trust-readonly-sections". If true, |
881 | then memory from any SEC_READONLY bfd section may be read | |
8db32d44 AC |
882 | directly from the bfd file. */ |
883 | secp = target_section_by_addr (¤t_target, memaddr); | |
884 | if (secp != NULL | |
885 | && (bfd_get_section_flags (secp->bfd, secp->the_bfd_section) | |
886 | & SEC_READONLY)) | |
887 | return xfer_memory (memaddr, myaddr, len, 0, attrib, ¤t_target); | |
3a11626d MS |
888 | } |
889 | ||
67e0617e | 890 | /* The quick case is that the top target can handle the transfer. */ |
c906108c | 891 | res = current_target.to_xfer_memory |
29e57380 | 892 | (memaddr, myaddr, len, write, attrib, ¤t_target); |
c906108c | 893 | |
67e0617e C |
894 | /* If res <= 0 then we call it again in the loop. Ah well. */ |
895 | if (res <= 0) | |
c906108c | 896 | { |
258b763a | 897 | for (t = target_stack; t != NULL; t = t->beneath) |
c906108c | 898 | { |
c906108c SS |
899 | if (!t->to_has_memory) |
900 | continue; | |
901 | ||
29e57380 | 902 | res = t->to_xfer_memory (memaddr, myaddr, len, write, attrib, t); |
c906108c SS |
903 | if (res > 0) |
904 | break; /* Handled all or part of xfer */ | |
905 | if (t->to_has_all_memory) | |
906 | break; | |
907 | } | |
908 | ||
4930751a | 909 | if (res <= 0) |
67e0617e | 910 | return -1; |
4930751a | 911 | } |
67e0617e C |
912 | |
913 | return res; | |
4930751a C |
914 | } |
915 | ||
67e0617e C |
916 | |
917 | /* Perform a memory transfer. Iterate until the entire region has | |
918 | been transfered. | |
919 | ||
920 | Result is 0 or errno value. */ | |
921 | ||
4930751a C |
922 | static int |
923 | target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write) | |
924 | { | |
925 | int res; | |
29e57380 C |
926 | int reg_len; |
927 | struct mem_region *region; | |
4930751a C |
928 | |
929 | /* Zero length requests are ok and require no work. */ | |
930 | if (len == 0) | |
931 | { | |
932 | return 0; | |
933 | } | |
934 | ||
935 | while (len > 0) | |
936 | { | |
29e57380 C |
937 | region = lookup_mem_region(memaddr); |
938 | if (memaddr + len < region->hi) | |
939 | reg_len = len; | |
940 | else | |
941 | reg_len = region->hi - memaddr; | |
942 | ||
943 | switch (region->attrib.mode) | |
c906108c | 944 | { |
29e57380 C |
945 | case MEM_RO: |
946 | if (write) | |
947 | return EIO; | |
948 | break; | |
949 | ||
950 | case MEM_WO: | |
c906108c | 951 | if (!write) |
c906108c | 952 | return EIO; |
29e57380 | 953 | break; |
c906108c | 954 | } |
4930751a | 955 | |
29e57380 C |
956 | while (reg_len > 0) |
957 | { | |
958 | if (region->attrib.cache) | |
8add0441 | 959 | res = dcache_xfer_memory (target_dcache, memaddr, myaddr, |
29e57380 C |
960 | reg_len, write); |
961 | else | |
8add0441 | 962 | res = do_xfer_memory (memaddr, myaddr, reg_len, write, |
29e57380 C |
963 | ®ion->attrib); |
964 | ||
965 | if (res <= 0) | |
966 | { | |
967 | /* If this address is for nonexistent memory, read zeros | |
968 | if reading, or do nothing if writing. Return | |
969 | error. */ | |
970 | if (!write) | |
971 | memset (myaddr, 0, len); | |
972 | if (errno == 0) | |
973 | return EIO; | |
974 | else | |
975 | return errno; | |
976 | } | |
977 | ||
978 | memaddr += res; | |
979 | myaddr += res; | |
980 | len -= res; | |
981 | reg_len -= res; | |
982 | } | |
c906108c | 983 | } |
4930751a | 984 | |
c906108c SS |
985 | return 0; /* We managed to cover it all somehow. */ |
986 | } | |
987 | ||
988 | ||
67e0617e C |
989 | /* Perform a partial memory transfer. |
990 | ||
991 | Result is -1 on error, or the number of bytes transfered. */ | |
917317f4 JM |
992 | |
993 | static int | |
4930751a | 994 | target_xfer_memory_partial (CORE_ADDR memaddr, char *myaddr, int len, |
917317f4 JM |
995 | int write_p, int *err) |
996 | { | |
997 | int res; | |
29e57380 C |
998 | int reg_len; |
999 | struct mem_region *region; | |
917317f4 JM |
1000 | |
1001 | /* Zero length requests are ok and require no work. */ | |
1002 | if (len == 0) | |
1003 | { | |
1004 | *err = 0; | |
1005 | return 0; | |
1006 | } | |
1007 | ||
29e57380 C |
1008 | region = lookup_mem_region(memaddr); |
1009 | if (memaddr + len < region->hi) | |
1010 | reg_len = len; | |
1011 | else | |
1012 | reg_len = region->hi - memaddr; | |
1013 | ||
1014 | switch (region->attrib.mode) | |
1015 | { | |
1016 | case MEM_RO: | |
1017 | if (write_p) | |
1018 | { | |
1019 | *err = EIO; | |
873406a6 | 1020 | return -1; |
29e57380 C |
1021 | } |
1022 | break; | |
1023 | ||
1024 | case MEM_WO: | |
1025 | if (write_p) | |
1026 | { | |
1027 | *err = EIO; | |
873406a6 | 1028 | return -1; |
29e57380 C |
1029 | } |
1030 | break; | |
1031 | } | |
1032 | ||
1033 | if (region->attrib.cache) | |
1034 | res = dcache_xfer_memory (target_dcache, memaddr, myaddr, | |
1035 | reg_len, write_p); | |
1036 | else | |
1037 | res = do_xfer_memory (memaddr, myaddr, reg_len, write_p, | |
1038 | ®ion->attrib); | |
1039 | ||
4930751a | 1040 | if (res <= 0) |
917317f4 | 1041 | { |
4930751a C |
1042 | if (errno != 0) |
1043 | *err = errno; | |
1044 | else | |
1045 | *err = EIO; | |
917317f4 | 1046 | |
4930751a | 1047 | return -1; |
917317f4 JM |
1048 | } |
1049 | ||
4930751a | 1050 | *err = 0; |
67e0617e | 1051 | return res; |
917317f4 JM |
1052 | } |
1053 | ||
1054 | int | |
1055 | target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err) | |
1056 | { | |
1057 | return target_xfer_memory_partial (memaddr, buf, len, 0, err); | |
1058 | } | |
1059 | ||
1060 | int | |
1061 | target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err) | |
1062 | { | |
1063 | return target_xfer_memory_partial (memaddr, buf, len, 1, err); | |
1064 | } | |
1065 | ||
1e3ff5ad AC |
1066 | /* More generic transfers. */ |
1067 | ||
1068 | LONGEST | |
1069 | target_read_partial (struct target_ops *ops, | |
1070 | enum target_object object, | |
1071 | const char *annex, void *buf, | |
1072 | ULONGEST offset, LONGEST len) | |
1073 | { | |
1074 | struct target_ops *op; | |
1075 | ||
1076 | /* Find the first target stratum that can handle the request. */ | |
1077 | for (op = ops; | |
1078 | op != NULL && op->to_read_partial == NULL; | |
1079 | op = op->beneath) | |
1080 | ; | |
1081 | if (op == NULL) | |
1082 | return -1; | |
1083 | ||
1084 | /* Now apply the operation at that level. */ | |
1085 | return op->to_read_partial (op, object, annex, buf, offset, len); | |
1086 | } | |
1087 | ||
1088 | LONGEST | |
1089 | target_write_partial (struct target_ops *ops, | |
1090 | enum target_object object, | |
1091 | const char *annex, const void *buf, | |
1092 | ULONGEST offset, LONGEST len) | |
1093 | { | |
1094 | struct target_ops *op; | |
1095 | ||
1096 | /* Find the first target stratum that can handle the request. */ | |
1097 | for (op = ops; | |
1098 | op != NULL && op->to_write_partial == NULL; | |
1099 | op = op->beneath) | |
1100 | ; | |
1101 | if (op == NULL) | |
1102 | return -1; | |
1103 | ||
1104 | return op->to_write_partial (op, object, annex, buf, offset, len); | |
1105 | } | |
1106 | ||
1107 | /* Wrappers to perform the full transfer. */ | |
1108 | LONGEST | |
1109 | target_read (struct target_ops *ops, | |
1110 | enum target_object object, | |
1111 | const char *annex, void *buf, | |
1112 | ULONGEST offset, LONGEST len) | |
1113 | { | |
1114 | LONGEST xfered = 0; | |
1115 | while (xfered < len) | |
1116 | { | |
1117 | LONGEST xfer = target_write_partial (ops, object, annex, | |
1118 | (bfd_byte *) buf + xfered, | |
1119 | offset + xfered, len - xfered); | |
1120 | /* Call an observer, notifying them of the xfer progress? */ | |
1121 | if (xfer < 0) | |
1122 | return xfer; | |
1123 | xfered += xfer; | |
1124 | QUIT; | |
1125 | } | |
1126 | return len; | |
1127 | } | |
1128 | ||
1129 | LONGEST | |
1130 | target_write (struct target_ops *ops, | |
1131 | enum target_object object, | |
1132 | const char *annex, const void *buf, | |
1133 | ULONGEST offset, LONGEST len) | |
1134 | { | |
1135 | LONGEST xfered = 0; | |
1136 | while (xfered < len) | |
1137 | { | |
1138 | LONGEST xfer = target_write_partial (ops, object, annex, | |
1139 | (bfd_byte *) buf + xfered, | |
1140 | offset + xfered, len - xfered); | |
1141 | /* Call an observer, notifying them of the xfer progress? */ | |
1142 | if (xfer < 0) | |
1143 | return xfer; | |
1144 | xfered += xfer; | |
1145 | QUIT; | |
1146 | } | |
1147 | return len; | |
1148 | } | |
1149 | ||
c906108c | 1150 | static void |
fba45db2 | 1151 | target_info (char *args, int from_tty) |
c906108c SS |
1152 | { |
1153 | struct target_ops *t; | |
c906108c | 1154 | int has_all_mem = 0; |
c5aa993b | 1155 | |
c906108c SS |
1156 | if (symfile_objfile != NULL) |
1157 | printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile->name); | |
1158 | ||
1159 | #ifdef FILES_INFO_HOOK | |
1160 | if (FILES_INFO_HOOK ()) | |
1161 | return; | |
1162 | #endif | |
1163 | ||
258b763a | 1164 | for (t = target_stack; t != NULL; t = t->beneath) |
c906108c | 1165 | { |
c906108c SS |
1166 | if (!t->to_has_memory) |
1167 | continue; | |
1168 | ||
c5aa993b | 1169 | if ((int) (t->to_stratum) <= (int) dummy_stratum) |
c906108c SS |
1170 | continue; |
1171 | if (has_all_mem) | |
c5aa993b JM |
1172 | printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n"); |
1173 | printf_unfiltered ("%s:\n", t->to_longname); | |
1174 | (t->to_files_info) (t); | |
c906108c SS |
1175 | has_all_mem = t->to_has_all_memory; |
1176 | } | |
1177 | } | |
1178 | ||
1179 | /* This is to be called by the open routine before it does | |
1180 | anything. */ | |
1181 | ||
1182 | void | |
fba45db2 | 1183 | target_preopen (int from_tty) |
c906108c | 1184 | { |
c5aa993b | 1185 | dont_repeat (); |
c906108c SS |
1186 | |
1187 | if (target_has_execution) | |
c5aa993b | 1188 | { |
adf40b2e JM |
1189 | if (!from_tty |
1190 | || query ("A program is being debugged already. Kill it? ")) | |
c5aa993b | 1191 | target_kill (); |
c906108c | 1192 | else |
c5aa993b | 1193 | error ("Program not killed."); |
c906108c SS |
1194 | } |
1195 | ||
1196 | /* Calling target_kill may remove the target from the stack. But if | |
1197 | it doesn't (which seems like a win for UDI), remove it now. */ | |
1198 | ||
1199 | if (target_has_execution) | |
1200 | pop_target (); | |
1201 | } | |
1202 | ||
1203 | /* Detach a target after doing deferred register stores. */ | |
1204 | ||
1205 | void | |
fba45db2 | 1206 | target_detach (char *args, int from_tty) |
c906108c SS |
1207 | { |
1208 | /* Handle any optimized stores to the inferior. */ | |
1209 | #ifdef DO_DEFERRED_STORES | |
1210 | DO_DEFERRED_STORES; | |
1211 | #endif | |
1212 | (current_target.to_detach) (args, from_tty); | |
1213 | } | |
1214 | ||
6ad8ae5c DJ |
1215 | void |
1216 | target_disconnect (char *args, int from_tty) | |
1217 | { | |
1218 | /* Handle any optimized stores to the inferior. */ | |
1219 | #ifdef DO_DEFERRED_STORES | |
1220 | DO_DEFERRED_STORES; | |
1221 | #endif | |
1222 | (current_target.to_disconnect) (args, from_tty); | |
1223 | } | |
1224 | ||
c906108c | 1225 | void |
fba45db2 | 1226 | target_link (char *modname, CORE_ADDR *t_reloc) |
c906108c | 1227 | { |
c5aa993b | 1228 | if (STREQ (current_target.to_shortname, "rombug")) |
c906108c SS |
1229 | { |
1230 | (current_target.to_lookup_symbol) (modname, t_reloc); | |
1231 | if (*t_reloc == 0) | |
c5aa993b | 1232 | error ("Unable to link to %s and get relocation in rombug", modname); |
c906108c SS |
1233 | } |
1234 | else | |
2acceee2 | 1235 | *t_reloc = (CORE_ADDR) -1; |
c906108c SS |
1236 | } |
1237 | ||
ed9a39eb JM |
1238 | int |
1239 | target_async_mask (int mask) | |
1240 | { | |
1241 | int saved_async_masked_status = target_async_mask_value; | |
1242 | target_async_mask_value = mask; | |
1243 | return saved_async_masked_status; | |
1244 | } | |
1245 | ||
c906108c SS |
1246 | /* Look through the list of possible targets for a target that can |
1247 | execute a run or attach command without any other data. This is | |
1248 | used to locate the default process stratum. | |
1249 | ||
1250 | Result is always valid (error() is called for errors). */ | |
1251 | ||
1252 | static struct target_ops * | |
fba45db2 | 1253 | find_default_run_target (char *do_mesg) |
c906108c SS |
1254 | { |
1255 | struct target_ops **t; | |
1256 | struct target_ops *runable = NULL; | |
1257 | int count; | |
1258 | ||
1259 | count = 0; | |
1260 | ||
1261 | for (t = target_structs; t < target_structs + target_struct_size; | |
1262 | ++t) | |
1263 | { | |
c5aa993b | 1264 | if ((*t)->to_can_run && target_can_run (*t)) |
c906108c SS |
1265 | { |
1266 | runable = *t; | |
1267 | ++count; | |
1268 | } | |
1269 | } | |
1270 | ||
1271 | if (count != 1) | |
1272 | error ("Don't know how to %s. Try \"help target\".", do_mesg); | |
1273 | ||
1274 | return runable; | |
1275 | } | |
1276 | ||
1277 | void | |
fba45db2 | 1278 | find_default_attach (char *args, int from_tty) |
c906108c SS |
1279 | { |
1280 | struct target_ops *t; | |
1281 | ||
c5aa993b | 1282 | t = find_default_run_target ("attach"); |
c906108c SS |
1283 | (t->to_attach) (args, from_tty); |
1284 | return; | |
1285 | } | |
1286 | ||
c906108c | 1287 | void |
fba45db2 | 1288 | find_default_create_inferior (char *exec_file, char *allargs, char **env) |
c906108c SS |
1289 | { |
1290 | struct target_ops *t; | |
1291 | ||
c5aa993b | 1292 | t = find_default_run_target ("run"); |
c906108c SS |
1293 | (t->to_create_inferior) (exec_file, allargs, env); |
1294 | return; | |
1295 | } | |
1296 | ||
ccaa32c7 GS |
1297 | static int |
1298 | default_region_size_ok_for_hw_watchpoint (int byte_count) | |
1299 | { | |
b1e29e33 | 1300 | return (byte_count <= DEPRECATED_REGISTER_SIZE); |
ccaa32c7 GS |
1301 | } |
1302 | ||
c906108c | 1303 | static int |
fba45db2 | 1304 | return_zero (void) |
c906108c SS |
1305 | { |
1306 | return 0; | |
1307 | } | |
1308 | ||
1309 | static int | |
fba45db2 | 1310 | return_one (void) |
c906108c SS |
1311 | { |
1312 | return 1; | |
1313 | } | |
1314 | ||
ccaa32c7 GS |
1315 | static int |
1316 | return_minus_one (void) | |
1317 | { | |
1318 | return -1; | |
1319 | } | |
1320 | ||
6426a772 JM |
1321 | /* |
1322 | * Resize the to_sections pointer. Also make sure that anyone that | |
1323 | * was holding on to an old value of it gets updated. | |
1324 | * Returns the old size. | |
1325 | */ | |
1326 | ||
1327 | int | |
1328 | target_resize_to_sections (struct target_ops *target, int num_added) | |
1329 | { | |
1330 | struct target_ops **t; | |
1331 | struct section_table *old_value; | |
1332 | int old_count; | |
1333 | ||
1334 | old_value = target->to_sections; | |
1335 | ||
1336 | if (target->to_sections) | |
1337 | { | |
1338 | old_count = target->to_sections_end - target->to_sections; | |
1339 | target->to_sections = (struct section_table *) | |
1340 | xrealloc ((char *) target->to_sections, | |
1341 | (sizeof (struct section_table)) * (num_added + old_count)); | |
1342 | } | |
1343 | else | |
1344 | { | |
1345 | old_count = 0; | |
1346 | target->to_sections = (struct section_table *) | |
1347 | xmalloc ((sizeof (struct section_table)) * num_added); | |
1348 | } | |
1349 | target->to_sections_end = target->to_sections + (num_added + old_count); | |
1350 | ||
1351 | /* Check to see if anyone else was pointing to this structure. | |
1352 | If old_value was null, then no one was. */ | |
1353 | ||
1354 | if (old_value) | |
1355 | { | |
1356 | for (t = target_structs; t < target_structs + target_struct_size; | |
1357 | ++t) | |
1358 | { | |
1359 | if ((*t)->to_sections == old_value) | |
1360 | { | |
1361 | (*t)->to_sections = target->to_sections; | |
1362 | (*t)->to_sections_end = target->to_sections_end; | |
1363 | } | |
1364 | } | |
1365 | } | |
1366 | ||
1367 | return old_count; | |
1368 | ||
1369 | } | |
1370 | ||
07cd4b97 JB |
1371 | /* Remove all target sections taken from ABFD. |
1372 | ||
1373 | Scan the current target stack for targets whose section tables | |
1374 | refer to sections from BFD, and remove those sections. We use this | |
1375 | when we notice that the inferior has unloaded a shared object, for | |
1376 | example. */ | |
1377 | void | |
1378 | remove_target_sections (bfd *abfd) | |
1379 | { | |
1380 | struct target_ops **t; | |
1381 | ||
1382 | for (t = target_structs; t < target_structs + target_struct_size; t++) | |
1383 | { | |
1384 | struct section_table *src, *dest; | |
1385 | ||
1386 | dest = (*t)->to_sections; | |
1387 | for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++) | |
1388 | if (src->bfd != abfd) | |
1389 | { | |
1390 | /* Keep this section. */ | |
1391 | if (dest < src) *dest = *src; | |
1392 | dest++; | |
1393 | } | |
1394 | ||
1395 | /* If we've dropped any sections, resize the section table. */ | |
1396 | if (dest < src) | |
1397 | target_resize_to_sections (*t, dest - src); | |
1398 | } | |
1399 | } | |
1400 | ||
1401 | ||
1402 | ||
1403 | ||
7a292a7a SS |
1404 | /* Find a single runnable target in the stack and return it. If for |
1405 | some reason there is more than one, return NULL. */ | |
1406 | ||
1407 | struct target_ops * | |
fba45db2 | 1408 | find_run_target (void) |
7a292a7a SS |
1409 | { |
1410 | struct target_ops **t; | |
1411 | struct target_ops *runable = NULL; | |
1412 | int count; | |
c5aa993b | 1413 | |
7a292a7a | 1414 | count = 0; |
c5aa993b | 1415 | |
7a292a7a SS |
1416 | for (t = target_structs; t < target_structs + target_struct_size; ++t) |
1417 | { | |
c5aa993b | 1418 | if ((*t)->to_can_run && target_can_run (*t)) |
7a292a7a SS |
1419 | { |
1420 | runable = *t; | |
1421 | ++count; | |
1422 | } | |
1423 | } | |
c5aa993b | 1424 | |
7a292a7a SS |
1425 | return (count == 1 ? runable : NULL); |
1426 | } | |
1427 | ||
ed9a39eb JM |
1428 | /* Find a single core_stratum target in the list of targets and return it. |
1429 | If for some reason there is more than one, return NULL. */ | |
1430 | ||
c906108c | 1431 | struct target_ops * |
fba45db2 | 1432 | find_core_target (void) |
c906108c SS |
1433 | { |
1434 | struct target_ops **t; | |
1435 | struct target_ops *runable = NULL; | |
1436 | int count; | |
c5aa993b | 1437 | |
c906108c | 1438 | count = 0; |
c5aa993b | 1439 | |
c906108c SS |
1440 | for (t = target_structs; t < target_structs + target_struct_size; |
1441 | ++t) | |
1442 | { | |
1443 | if ((*t)->to_stratum == core_stratum) | |
1444 | { | |
1445 | runable = *t; | |
1446 | ++count; | |
1447 | } | |
1448 | } | |
c5aa993b JM |
1449 | |
1450 | return (count == 1 ? runable : NULL); | |
c906108c | 1451 | } |
ed9a39eb JM |
1452 | |
1453 | /* | |
1454 | * Find the next target down the stack from the specified target. | |
1455 | */ | |
1456 | ||
1457 | struct target_ops * | |
fba45db2 | 1458 | find_target_beneath (struct target_ops *t) |
ed9a39eb | 1459 | { |
258b763a | 1460 | return t->beneath; |
ed9a39eb JM |
1461 | } |
1462 | ||
c906108c SS |
1463 | \f |
1464 | /* The inferior process has died. Long live the inferior! */ | |
1465 | ||
1466 | void | |
fba45db2 | 1467 | generic_mourn_inferior (void) |
c906108c SS |
1468 | { |
1469 | extern int show_breakpoint_hit_counts; | |
1470 | ||
39f77062 | 1471 | inferior_ptid = null_ptid; |
c906108c SS |
1472 | attach_flag = 0; |
1473 | breakpoint_init_inferior (inf_exited); | |
1474 | registers_changed (); | |
1475 | ||
1476 | #ifdef CLEAR_DEFERRED_STORES | |
1477 | /* Delete any pending stores to the inferior... */ | |
1478 | CLEAR_DEFERRED_STORES; | |
1479 | #endif | |
1480 | ||
1481 | reopen_exec_file (); | |
1482 | reinit_frame_cache (); | |
1483 | ||
1484 | /* It is confusing to the user for ignore counts to stick around | |
1485 | from previous runs of the inferior. So clear them. */ | |
1486 | /* However, it is more confusing for the ignore counts to disappear when | |
1487 | using hit counts. So don't clear them if we're counting hits. */ | |
1488 | if (!show_breakpoint_hit_counts) | |
1489 | breakpoint_clear_ignore_counts (); | |
c5b739b5 FN |
1490 | |
1491 | if (detach_hook) | |
1492 | detach_hook (); | |
c906108c SS |
1493 | } |
1494 | \f | |
c906108c SS |
1495 | /* Helper function for child_wait and the Lynx derivatives of child_wait. |
1496 | HOSTSTATUS is the waitstatus from wait() or the equivalent; store our | |
1497 | translation of that in OURSTATUS. */ | |
1498 | void | |
fba45db2 | 1499 | store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus) |
c906108c SS |
1500 | { |
1501 | #ifdef CHILD_SPECIAL_WAITSTATUS | |
1502 | /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS | |
1503 | if it wants to deal with hoststatus. */ | |
1504 | if (CHILD_SPECIAL_WAITSTATUS (ourstatus, hoststatus)) | |
1505 | return; | |
1506 | #endif | |
1507 | ||
1508 | if (WIFEXITED (hoststatus)) | |
1509 | { | |
1510 | ourstatus->kind = TARGET_WAITKIND_EXITED; | |
1511 | ourstatus->value.integer = WEXITSTATUS (hoststatus); | |
1512 | } | |
1513 | else if (!WIFSTOPPED (hoststatus)) | |
1514 | { | |
1515 | ourstatus->kind = TARGET_WAITKIND_SIGNALLED; | |
1516 | ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus)); | |
1517 | } | |
1518 | else | |
1519 | { | |
1520 | ourstatus->kind = TARGET_WAITKIND_STOPPED; | |
1521 | ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus)); | |
1522 | } | |
1523 | } | |
1524 | \f | |
c906108c | 1525 | /* Returns zero to leave the inferior alone, one to interrupt it. */ |
507f3c78 | 1526 | int (*target_activity_function) (void); |
c906108c SS |
1527 | int target_activity_fd; |
1528 | \f | |
1529 | /* Convert a normal process ID to a string. Returns the string in a static | |
1530 | buffer. */ | |
1531 | ||
1532 | char * | |
39f77062 | 1533 | normal_pid_to_str (ptid_t ptid) |
c906108c SS |
1534 | { |
1535 | static char buf[30]; | |
1536 | ||
39f77062 | 1537 | sprintf (buf, "process %d", PIDGET (ptid)); |
c906108c SS |
1538 | return buf; |
1539 | } | |
1540 | ||
1541 | /* Some targets (such as ttrace-based HPUX) don't allow us to request | |
1542 | notification of inferior events such as fork and vork immediately | |
1543 | after the inferior is created. (This because of how gdb gets an | |
1544 | inferior created via invoking a shell to do it. In such a scenario, | |
1545 | if the shell init file has commands in it, the shell will fork and | |
1546 | exec for each of those commands, and we will see each such fork | |
1547 | event. Very bad.) | |
c5aa993b | 1548 | |
c906108c SS |
1549 | This function is used by all targets that allow us to request |
1550 | notification of forks, etc at inferior creation time; e.g., in | |
1551 | target_acknowledge_forked_child. | |
c5aa993b | 1552 | */ |
392a587b | 1553 | static void |
39f77062 | 1554 | normal_target_post_startup_inferior (ptid_t ptid) |
c906108c SS |
1555 | { |
1556 | /* This space intentionally left blank. */ | |
1557 | } | |
1558 | ||
be4d1333 | 1559 | /* Error-catcher for target_find_memory_regions */ |
be4d1333 MS |
1560 | static int dummy_find_memory_regions (int (*ignore1) (), void *ignore2) |
1561 | { | |
1562 | error ("No target."); | |
1563 | return 0; | |
1564 | } | |
1565 | ||
1566 | /* Error-catcher for target_make_corefile_notes */ | |
be4d1333 MS |
1567 | static char * dummy_make_corefile_notes (bfd *ignore1, int *ignore2) |
1568 | { | |
1569 | error ("No target."); | |
1570 | return NULL; | |
1571 | } | |
1572 | ||
c906108c SS |
1573 | /* Set up the handful of non-empty slots needed by the dummy target |
1574 | vector. */ | |
1575 | ||
1576 | static void | |
fba45db2 | 1577 | init_dummy_target (void) |
c906108c SS |
1578 | { |
1579 | dummy_target.to_shortname = "None"; | |
1580 | dummy_target.to_longname = "None"; | |
1581 | dummy_target.to_doc = ""; | |
1582 | dummy_target.to_attach = find_default_attach; | |
c906108c | 1583 | dummy_target.to_create_inferior = find_default_create_inferior; |
ed9a39eb | 1584 | dummy_target.to_pid_to_str = normal_pid_to_str; |
c906108c | 1585 | dummy_target.to_stratum = dummy_stratum; |
be4d1333 MS |
1586 | dummy_target.to_find_memory_regions = dummy_find_memory_regions; |
1587 | dummy_target.to_make_corefile_notes = dummy_make_corefile_notes; | |
c906108c SS |
1588 | dummy_target.to_magic = OPS_MAGIC; |
1589 | } | |
c906108c | 1590 | \f |
c5aa993b | 1591 | |
c906108c SS |
1592 | static struct target_ops debug_target; |
1593 | ||
1594 | static void | |
fba45db2 | 1595 | debug_to_open (char *args, int from_tty) |
c906108c SS |
1596 | { |
1597 | debug_target.to_open (args, from_tty); | |
1598 | ||
96baa820 | 1599 | fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty); |
c906108c SS |
1600 | } |
1601 | ||
1602 | static void | |
fba45db2 | 1603 | debug_to_close (int quitting) |
c906108c SS |
1604 | { |
1605 | debug_target.to_close (quitting); | |
1606 | ||
96baa820 | 1607 | fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting); |
c906108c SS |
1608 | } |
1609 | ||
1610 | static void | |
fba45db2 | 1611 | debug_to_attach (char *args, int from_tty) |
c906108c SS |
1612 | { |
1613 | debug_target.to_attach (args, from_tty); | |
1614 | ||
96baa820 | 1615 | fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty); |
c906108c SS |
1616 | } |
1617 | ||
1618 | ||
1619 | static void | |
fba45db2 | 1620 | debug_to_post_attach (int pid) |
c906108c SS |
1621 | { |
1622 | debug_target.to_post_attach (pid); | |
1623 | ||
96baa820 | 1624 | fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid); |
c906108c SS |
1625 | } |
1626 | ||
c906108c | 1627 | static void |
fba45db2 | 1628 | debug_to_detach (char *args, int from_tty) |
c906108c SS |
1629 | { |
1630 | debug_target.to_detach (args, from_tty); | |
1631 | ||
96baa820 | 1632 | fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty); |
c906108c SS |
1633 | } |
1634 | ||
6ad8ae5c DJ |
1635 | static void |
1636 | debug_to_disconnect (char *args, int from_tty) | |
1637 | { | |
1638 | debug_target.to_disconnect (args, from_tty); | |
1639 | ||
1640 | fprintf_unfiltered (gdb_stdlog, "target_disconnect (%s, %d)\n", | |
1641 | args, from_tty); | |
1642 | } | |
1643 | ||
c906108c | 1644 | static void |
39f77062 | 1645 | debug_to_resume (ptid_t ptid, int step, enum target_signal siggnal) |
c906108c | 1646 | { |
39f77062 | 1647 | debug_target.to_resume (ptid, step, siggnal); |
c906108c | 1648 | |
39f77062 | 1649 | fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", PIDGET (ptid), |
c906108c SS |
1650 | step ? "step" : "continue", |
1651 | target_signal_to_name (siggnal)); | |
1652 | } | |
1653 | ||
39f77062 KB |
1654 | static ptid_t |
1655 | debug_to_wait (ptid_t ptid, struct target_waitstatus *status) | |
c906108c | 1656 | { |
39f77062 | 1657 | ptid_t retval; |
c906108c | 1658 | |
39f77062 | 1659 | retval = debug_target.to_wait (ptid, status); |
c906108c | 1660 | |
96baa820 | 1661 | fprintf_unfiltered (gdb_stdlog, |
39f77062 KB |
1662 | "target_wait (%d, status) = %d, ", PIDGET (ptid), |
1663 | PIDGET (retval)); | |
96baa820 | 1664 | fprintf_unfiltered (gdb_stdlog, "status->kind = "); |
c906108c SS |
1665 | switch (status->kind) |
1666 | { | |
1667 | case TARGET_WAITKIND_EXITED: | |
96baa820 | 1668 | fprintf_unfiltered (gdb_stdlog, "exited, status = %d\n", |
c906108c SS |
1669 | status->value.integer); |
1670 | break; | |
1671 | case TARGET_WAITKIND_STOPPED: | |
96baa820 | 1672 | fprintf_unfiltered (gdb_stdlog, "stopped, signal = %s\n", |
c906108c SS |
1673 | target_signal_to_name (status->value.sig)); |
1674 | break; | |
1675 | case TARGET_WAITKIND_SIGNALLED: | |
96baa820 | 1676 | fprintf_unfiltered (gdb_stdlog, "signalled, signal = %s\n", |
c906108c SS |
1677 | target_signal_to_name (status->value.sig)); |
1678 | break; | |
1679 | case TARGET_WAITKIND_LOADED: | |
96baa820 | 1680 | fprintf_unfiltered (gdb_stdlog, "loaded\n"); |
c906108c SS |
1681 | break; |
1682 | case TARGET_WAITKIND_FORKED: | |
96baa820 | 1683 | fprintf_unfiltered (gdb_stdlog, "forked\n"); |
c906108c SS |
1684 | break; |
1685 | case TARGET_WAITKIND_VFORKED: | |
96baa820 | 1686 | fprintf_unfiltered (gdb_stdlog, "vforked\n"); |
c906108c SS |
1687 | break; |
1688 | case TARGET_WAITKIND_EXECD: | |
96baa820 | 1689 | fprintf_unfiltered (gdb_stdlog, "execd\n"); |
c906108c SS |
1690 | break; |
1691 | case TARGET_WAITKIND_SPURIOUS: | |
96baa820 | 1692 | fprintf_unfiltered (gdb_stdlog, "spurious\n"); |
c906108c SS |
1693 | break; |
1694 | default: | |
96baa820 | 1695 | fprintf_unfiltered (gdb_stdlog, "unknown???\n"); |
c906108c SS |
1696 | break; |
1697 | } | |
1698 | ||
1699 | return retval; | |
1700 | } | |
1701 | ||
1702 | static void | |
39f77062 | 1703 | debug_to_post_wait (ptid_t ptid, int status) |
c906108c | 1704 | { |
39f77062 | 1705 | debug_target.to_post_wait (ptid, status); |
c906108c | 1706 | |
96baa820 | 1707 | fprintf_unfiltered (gdb_stdlog, "target_post_wait (%d, %d)\n", |
39f77062 | 1708 | PIDGET (ptid), status); |
c906108c SS |
1709 | } |
1710 | ||
bf0c5130 AC |
1711 | static void |
1712 | debug_print_register (const char * func, int regno) | |
1713 | { | |
1714 | fprintf_unfiltered (gdb_stdlog, "%s ", func); | |
1715 | if (regno >= 0 && regno < NUM_REGS + NUM_PSEUDO_REGS | |
1716 | && REGISTER_NAME (regno) != NULL && REGISTER_NAME (regno)[0] != '\0') | |
1717 | fprintf_unfiltered (gdb_stdlog, "(%s)", REGISTER_NAME (regno)); | |
1718 | else | |
1719 | fprintf_unfiltered (gdb_stdlog, "(%d)", regno); | |
1720 | if (regno >= 0) | |
1721 | { | |
1722 | int i; | |
d9d9c31f | 1723 | unsigned char buf[MAX_REGISTER_SIZE]; |
4caf0990 | 1724 | deprecated_read_register_gen (regno, buf); |
bf0c5130 | 1725 | fprintf_unfiltered (gdb_stdlog, " = "); |
12c266ea | 1726 | for (i = 0; i < DEPRECATED_REGISTER_RAW_SIZE (regno); i++) |
bf0c5130 AC |
1727 | { |
1728 | fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]); | |
1729 | } | |
12c266ea | 1730 | if (DEPRECATED_REGISTER_RAW_SIZE (regno) <= sizeof (LONGEST)) |
bf0c5130 AC |
1731 | { |
1732 | fprintf_unfiltered (gdb_stdlog, " 0x%s %s", | |
1733 | paddr_nz (read_register (regno)), | |
1734 | paddr_d (read_register (regno))); | |
1735 | } | |
1736 | } | |
1737 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
1738 | } | |
1739 | ||
c906108c | 1740 | static void |
fba45db2 | 1741 | debug_to_fetch_registers (int regno) |
c906108c SS |
1742 | { |
1743 | debug_target.to_fetch_registers (regno); | |
bf0c5130 | 1744 | debug_print_register ("target_fetch_registers", regno); |
c906108c SS |
1745 | } |
1746 | ||
1747 | static void | |
fba45db2 | 1748 | debug_to_store_registers (int regno) |
c906108c SS |
1749 | { |
1750 | debug_target.to_store_registers (regno); | |
bf0c5130 AC |
1751 | debug_print_register ("target_store_registers", regno); |
1752 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
c906108c SS |
1753 | } |
1754 | ||
1755 | static void | |
fba45db2 | 1756 | debug_to_prepare_to_store (void) |
c906108c SS |
1757 | { |
1758 | debug_target.to_prepare_to_store (); | |
1759 | ||
96baa820 | 1760 | fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n"); |
c906108c SS |
1761 | } |
1762 | ||
1763 | static int | |
fba45db2 | 1764 | debug_to_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write, |
29e57380 | 1765 | struct mem_attrib *attrib, |
fba45db2 | 1766 | struct target_ops *target) |
c906108c SS |
1767 | { |
1768 | int retval; | |
1769 | ||
29e57380 C |
1770 | retval = debug_target.to_xfer_memory (memaddr, myaddr, len, write, |
1771 | attrib, target); | |
c906108c | 1772 | |
96baa820 | 1773 | fprintf_unfiltered (gdb_stdlog, |
c906108c | 1774 | "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d", |
c5aa993b | 1775 | (unsigned int) memaddr, /* possable truncate long long */ |
c906108c SS |
1776 | len, write ? "write" : "read", retval); |
1777 | ||
c5aa993b | 1778 | |
c906108c SS |
1779 | |
1780 | if (retval > 0) | |
1781 | { | |
1782 | int i; | |
1783 | ||
96baa820 | 1784 | fputs_unfiltered (", bytes =", gdb_stdlog); |
c906108c SS |
1785 | for (i = 0; i < retval; i++) |
1786 | { | |
1787 | if ((((long) &(myaddr[i])) & 0xf) == 0) | |
96baa820 JM |
1788 | fprintf_unfiltered (gdb_stdlog, "\n"); |
1789 | fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff); | |
c906108c SS |
1790 | } |
1791 | } | |
1792 | ||
96baa820 | 1793 | fputc_unfiltered ('\n', gdb_stdlog); |
c906108c SS |
1794 | |
1795 | return retval; | |
1796 | } | |
1797 | ||
1798 | static void | |
fba45db2 | 1799 | debug_to_files_info (struct target_ops *target) |
c906108c SS |
1800 | { |
1801 | debug_target.to_files_info (target); | |
1802 | ||
96baa820 | 1803 | fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n"); |
c906108c SS |
1804 | } |
1805 | ||
1806 | static int | |
fba45db2 | 1807 | debug_to_insert_breakpoint (CORE_ADDR addr, char *save) |
c906108c SS |
1808 | { |
1809 | int retval; | |
1810 | ||
1811 | retval = debug_target.to_insert_breakpoint (addr, save); | |
1812 | ||
96baa820 | 1813 | fprintf_unfiltered (gdb_stdlog, |
104c1213 JM |
1814 | "target_insert_breakpoint (0x%lx, xxx) = %ld\n", |
1815 | (unsigned long) addr, | |
1816 | (unsigned long) retval); | |
c906108c SS |
1817 | return retval; |
1818 | } | |
1819 | ||
1820 | static int | |
fba45db2 | 1821 | debug_to_remove_breakpoint (CORE_ADDR addr, char *save) |
c906108c SS |
1822 | { |
1823 | int retval; | |
1824 | ||
1825 | retval = debug_target.to_remove_breakpoint (addr, save); | |
1826 | ||
96baa820 | 1827 | fprintf_unfiltered (gdb_stdlog, |
104c1213 JM |
1828 | "target_remove_breakpoint (0x%lx, xxx) = %ld\n", |
1829 | (unsigned long) addr, | |
1830 | (unsigned long) retval); | |
c906108c SS |
1831 | return retval; |
1832 | } | |
1833 | ||
ccaa32c7 GS |
1834 | static int |
1835 | debug_to_can_use_hw_breakpoint (int type, int cnt, int from_tty) | |
1836 | { | |
1837 | int retval; | |
1838 | ||
1839 | retval = debug_target.to_can_use_hw_breakpoint (type, cnt, from_tty); | |
1840 | ||
1841 | fprintf_unfiltered (gdb_stdlog, | |
1842 | "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n", | |
1843 | (unsigned long) type, | |
1844 | (unsigned long) cnt, | |
1845 | (unsigned long) from_tty, | |
1846 | (unsigned long) retval); | |
1847 | return retval; | |
1848 | } | |
1849 | ||
1850 | static int | |
1851 | debug_to_region_size_ok_for_hw_watchpoint (int byte_count) | |
1852 | { | |
1853 | CORE_ADDR retval; | |
1854 | ||
1855 | retval = debug_target.to_region_size_ok_for_hw_watchpoint (byte_count); | |
1856 | ||
1857 | fprintf_unfiltered (gdb_stdlog, | |
1858 | "TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT (%ld) = 0x%lx\n", | |
1859 | (unsigned long) byte_count, | |
1860 | (unsigned long) retval); | |
1861 | return retval; | |
1862 | } | |
1863 | ||
1864 | static int | |
1865 | debug_to_stopped_by_watchpoint (void) | |
1866 | { | |
1867 | int retval; | |
1868 | ||
1869 | retval = debug_target.to_stopped_by_watchpoint (); | |
1870 | ||
1871 | fprintf_unfiltered (gdb_stdlog, | |
1872 | "STOPPED_BY_WATCHPOINT () = %ld\n", | |
1873 | (unsigned long) retval); | |
1874 | return retval; | |
1875 | } | |
1876 | ||
1877 | static CORE_ADDR | |
1878 | debug_to_stopped_data_address (void) | |
1879 | { | |
1880 | CORE_ADDR retval; | |
1881 | ||
1882 | retval = debug_target.to_stopped_data_address (); | |
1883 | ||
1884 | fprintf_unfiltered (gdb_stdlog, | |
1885 | "target_stopped_data_address () = 0x%lx\n", | |
1886 | (unsigned long) retval); | |
1887 | return retval; | |
1888 | } | |
1889 | ||
1890 | static int | |
1891 | debug_to_insert_hw_breakpoint (CORE_ADDR addr, char *save) | |
1892 | { | |
1893 | int retval; | |
1894 | ||
1895 | retval = debug_target.to_insert_hw_breakpoint (addr, save); | |
1896 | ||
1897 | fprintf_unfiltered (gdb_stdlog, | |
1898 | "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n", | |
1899 | (unsigned long) addr, | |
1900 | (unsigned long) retval); | |
1901 | return retval; | |
1902 | } | |
1903 | ||
1904 | static int | |
1905 | debug_to_remove_hw_breakpoint (CORE_ADDR addr, char *save) | |
1906 | { | |
1907 | int retval; | |
1908 | ||
1909 | retval = debug_target.to_remove_hw_breakpoint (addr, save); | |
1910 | ||
1911 | fprintf_unfiltered (gdb_stdlog, | |
1912 | "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n", | |
1913 | (unsigned long) addr, | |
1914 | (unsigned long) retval); | |
1915 | return retval; | |
1916 | } | |
1917 | ||
1918 | static int | |
1919 | debug_to_insert_watchpoint (CORE_ADDR addr, int len, int type) | |
1920 | { | |
1921 | int retval; | |
1922 | ||
1923 | retval = debug_target.to_insert_watchpoint (addr, len, type); | |
1924 | ||
1925 | fprintf_unfiltered (gdb_stdlog, | |
1926 | "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n", | |
1927 | (unsigned long) addr, len, type, (unsigned long) retval); | |
1928 | return retval; | |
1929 | } | |
1930 | ||
1931 | static int | |
1932 | debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type) | |
1933 | { | |
1934 | int retval; | |
1935 | ||
1936 | retval = debug_target.to_insert_watchpoint (addr, len, type); | |
1937 | ||
1938 | fprintf_unfiltered (gdb_stdlog, | |
1939 | "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n", | |
1940 | (unsigned long) addr, len, type, (unsigned long) retval); | |
1941 | return retval; | |
1942 | } | |
1943 | ||
c906108c | 1944 | static void |
fba45db2 | 1945 | debug_to_terminal_init (void) |
c906108c SS |
1946 | { |
1947 | debug_target.to_terminal_init (); | |
1948 | ||
96baa820 | 1949 | fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n"); |
c906108c SS |
1950 | } |
1951 | ||
1952 | static void | |
fba45db2 | 1953 | debug_to_terminal_inferior (void) |
c906108c SS |
1954 | { |
1955 | debug_target.to_terminal_inferior (); | |
1956 | ||
96baa820 | 1957 | fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n"); |
c906108c SS |
1958 | } |
1959 | ||
1960 | static void | |
fba45db2 | 1961 | debug_to_terminal_ours_for_output (void) |
c906108c SS |
1962 | { |
1963 | debug_target.to_terminal_ours_for_output (); | |
1964 | ||
96baa820 | 1965 | fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n"); |
c906108c SS |
1966 | } |
1967 | ||
1968 | static void | |
fba45db2 | 1969 | debug_to_terminal_ours (void) |
c906108c SS |
1970 | { |
1971 | debug_target.to_terminal_ours (); | |
1972 | ||
96baa820 | 1973 | fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n"); |
c906108c SS |
1974 | } |
1975 | ||
a790ad35 SC |
1976 | static void |
1977 | debug_to_terminal_save_ours (void) | |
1978 | { | |
1979 | debug_target.to_terminal_save_ours (); | |
1980 | ||
1981 | fprintf_unfiltered (gdb_stdlog, "target_terminal_save_ours ()\n"); | |
1982 | } | |
1983 | ||
c906108c | 1984 | static void |
fba45db2 | 1985 | debug_to_terminal_info (char *arg, int from_tty) |
c906108c SS |
1986 | { |
1987 | debug_target.to_terminal_info (arg, from_tty); | |
1988 | ||
96baa820 | 1989 | fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg, |
c906108c SS |
1990 | from_tty); |
1991 | } | |
1992 | ||
1993 | static void | |
fba45db2 | 1994 | debug_to_kill (void) |
c906108c SS |
1995 | { |
1996 | debug_target.to_kill (); | |
1997 | ||
96baa820 | 1998 | fprintf_unfiltered (gdb_stdlog, "target_kill ()\n"); |
c906108c SS |
1999 | } |
2000 | ||
2001 | static void | |
fba45db2 | 2002 | debug_to_load (char *args, int from_tty) |
c906108c SS |
2003 | { |
2004 | debug_target.to_load (args, from_tty); | |
2005 | ||
96baa820 | 2006 | fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty); |
c906108c SS |
2007 | } |
2008 | ||
2009 | static int | |
fba45db2 | 2010 | debug_to_lookup_symbol (char *name, CORE_ADDR *addrp) |
c906108c SS |
2011 | { |
2012 | int retval; | |
2013 | ||
2014 | retval = debug_target.to_lookup_symbol (name, addrp); | |
2015 | ||
96baa820 | 2016 | fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name); |
c906108c SS |
2017 | |
2018 | return retval; | |
2019 | } | |
2020 | ||
2021 | static void | |
fba45db2 | 2022 | debug_to_create_inferior (char *exec_file, char *args, char **env) |
c906108c SS |
2023 | { |
2024 | debug_target.to_create_inferior (exec_file, args, env); | |
2025 | ||
96baa820 | 2026 | fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx)\n", |
c906108c SS |
2027 | exec_file, args); |
2028 | } | |
2029 | ||
2030 | static void | |
39f77062 | 2031 | debug_to_post_startup_inferior (ptid_t ptid) |
c906108c | 2032 | { |
39f77062 | 2033 | debug_target.to_post_startup_inferior (ptid); |
c906108c | 2034 | |
96baa820 | 2035 | fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n", |
39f77062 | 2036 | PIDGET (ptid)); |
c906108c SS |
2037 | } |
2038 | ||
2039 | static void | |
fba45db2 | 2040 | debug_to_acknowledge_created_inferior (int pid) |
c906108c SS |
2041 | { |
2042 | debug_target.to_acknowledge_created_inferior (pid); | |
2043 | ||
96baa820 | 2044 | fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n", |
c906108c SS |
2045 | pid); |
2046 | } | |
2047 | ||
c906108c | 2048 | static int |
fba45db2 | 2049 | debug_to_insert_fork_catchpoint (int pid) |
c906108c | 2050 | { |
c5aa993b | 2051 | int retval; |
c906108c SS |
2052 | |
2053 | retval = debug_target.to_insert_fork_catchpoint (pid); | |
2054 | ||
96baa820 | 2055 | fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d) = %d\n", |
c5aa993b | 2056 | pid, retval); |
c906108c SS |
2057 | |
2058 | return retval; | |
2059 | } | |
2060 | ||
2061 | static int | |
fba45db2 | 2062 | debug_to_remove_fork_catchpoint (int pid) |
c906108c | 2063 | { |
c5aa993b | 2064 | int retval; |
c906108c SS |
2065 | |
2066 | retval = debug_target.to_remove_fork_catchpoint (pid); | |
2067 | ||
96baa820 | 2068 | fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n", |
c5aa993b | 2069 | pid, retval); |
c906108c SS |
2070 | |
2071 | return retval; | |
2072 | } | |
2073 | ||
2074 | static int | |
fba45db2 | 2075 | debug_to_insert_vfork_catchpoint (int pid) |
c906108c | 2076 | { |
c5aa993b | 2077 | int retval; |
c906108c SS |
2078 | |
2079 | retval = debug_target.to_insert_vfork_catchpoint (pid); | |
2080 | ||
96baa820 | 2081 | fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)= %d\n", |
c5aa993b | 2082 | pid, retval); |
c906108c SS |
2083 | |
2084 | return retval; | |
2085 | } | |
2086 | ||
2087 | static int | |
fba45db2 | 2088 | debug_to_remove_vfork_catchpoint (int pid) |
c906108c | 2089 | { |
c5aa993b | 2090 | int retval; |
c906108c SS |
2091 | |
2092 | retval = debug_target.to_remove_vfork_catchpoint (pid); | |
2093 | ||
96baa820 | 2094 | fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n", |
c5aa993b | 2095 | pid, retval); |
c906108c SS |
2096 | |
2097 | return retval; | |
2098 | } | |
2099 | ||
6604731b DJ |
2100 | static int |
2101 | debug_to_follow_fork (int follow_child) | |
c906108c | 2102 | { |
6604731b | 2103 | int retval = debug_target.to_follow_fork (follow_child); |
c906108c | 2104 | |
6604731b DJ |
2105 | fprintf_unfiltered (gdb_stdlog, "target_follow_fork (%d) = %d\n", |
2106 | follow_child, retval); | |
2107 | ||
2108 | return retval; | |
c906108c SS |
2109 | } |
2110 | ||
2111 | static int | |
fba45db2 | 2112 | debug_to_insert_exec_catchpoint (int pid) |
c906108c | 2113 | { |
c5aa993b | 2114 | int retval; |
c906108c SS |
2115 | |
2116 | retval = debug_target.to_insert_exec_catchpoint (pid); | |
2117 | ||
96baa820 | 2118 | fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d) = %d\n", |
c5aa993b | 2119 | pid, retval); |
c906108c SS |
2120 | |
2121 | return retval; | |
2122 | } | |
2123 | ||
2124 | static int | |
fba45db2 | 2125 | debug_to_remove_exec_catchpoint (int pid) |
c906108c | 2126 | { |
c5aa993b | 2127 | int retval; |
c906108c SS |
2128 | |
2129 | retval = debug_target.to_remove_exec_catchpoint (pid); | |
2130 | ||
96baa820 | 2131 | fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n", |
c5aa993b | 2132 | pid, retval); |
c906108c SS |
2133 | |
2134 | return retval; | |
2135 | } | |
2136 | ||
c906108c | 2137 | static int |
fba45db2 | 2138 | debug_to_reported_exec_events_per_exec_call (void) |
c906108c | 2139 | { |
c5aa993b | 2140 | int reported_exec_events; |
c906108c SS |
2141 | |
2142 | reported_exec_events = debug_target.to_reported_exec_events_per_exec_call (); | |
2143 | ||
96baa820 | 2144 | fprintf_unfiltered (gdb_stdlog, |
c906108c | 2145 | "target_reported_exec_events_per_exec_call () = %d\n", |
c5aa993b | 2146 | reported_exec_events); |
c906108c SS |
2147 | |
2148 | return reported_exec_events; | |
2149 | } | |
2150 | ||
c906108c | 2151 | static int |
fba45db2 | 2152 | debug_to_has_exited (int pid, int wait_status, int *exit_status) |
c906108c | 2153 | { |
c5aa993b | 2154 | int has_exited; |
c906108c SS |
2155 | |
2156 | has_exited = debug_target.to_has_exited (pid, wait_status, exit_status); | |
2157 | ||
96baa820 | 2158 | fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n", |
c5aa993b | 2159 | pid, wait_status, *exit_status, has_exited); |
c906108c SS |
2160 | |
2161 | return has_exited; | |
2162 | } | |
2163 | ||
2164 | static void | |
fba45db2 | 2165 | debug_to_mourn_inferior (void) |
c906108c SS |
2166 | { |
2167 | debug_target.to_mourn_inferior (); | |
2168 | ||
96baa820 | 2169 | fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n"); |
c906108c SS |
2170 | } |
2171 | ||
2172 | static int | |
fba45db2 | 2173 | debug_to_can_run (void) |
c906108c SS |
2174 | { |
2175 | int retval; | |
2176 | ||
2177 | retval = debug_target.to_can_run (); | |
2178 | ||
96baa820 | 2179 | fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval); |
c906108c SS |
2180 | |
2181 | return retval; | |
2182 | } | |
2183 | ||
2184 | static void | |
39f77062 | 2185 | debug_to_notice_signals (ptid_t ptid) |
c906108c | 2186 | { |
39f77062 | 2187 | debug_target.to_notice_signals (ptid); |
c906108c | 2188 | |
39f77062 KB |
2189 | fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n", |
2190 | PIDGET (ptid)); | |
c906108c SS |
2191 | } |
2192 | ||
2193 | static int | |
39f77062 | 2194 | debug_to_thread_alive (ptid_t ptid) |
c906108c SS |
2195 | { |
2196 | int retval; | |
2197 | ||
39f77062 | 2198 | retval = debug_target.to_thread_alive (ptid); |
c906108c | 2199 | |
96baa820 | 2200 | fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n", |
39f77062 | 2201 | PIDGET (ptid), retval); |
c906108c SS |
2202 | |
2203 | return retval; | |
2204 | } | |
2205 | ||
0d06e24b | 2206 | static void |
fba45db2 | 2207 | debug_to_find_new_threads (void) |
0d06e24b JM |
2208 | { |
2209 | debug_target.to_find_new_threads (); | |
2210 | ||
2211 | fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog); | |
2212 | } | |
2213 | ||
c906108c | 2214 | static void |
fba45db2 | 2215 | debug_to_stop (void) |
c906108c SS |
2216 | { |
2217 | debug_target.to_stop (); | |
2218 | ||
96baa820 | 2219 | fprintf_unfiltered (gdb_stdlog, "target_stop ()\n"); |
c906108c SS |
2220 | } |
2221 | ||
1e3ff5ad AC |
2222 | static LONGEST |
2223 | debug_to_read_partial (struct target_ops *ops, | |
2224 | enum target_object object, | |
2225 | const char *annex, void *buf, | |
2226 | ULONGEST offset, LONGEST len) | |
c906108c | 2227 | { |
1e3ff5ad AC |
2228 | LONGEST retval; |
2229 | ||
2230 | retval = target_read_partial (&debug_target, object, annex, buf, offset, | |
2231 | len); | |
c906108c | 2232 | |
1e3ff5ad AC |
2233 | fprintf_unfiltered (gdb_stdlog, |
2234 | "target_read_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n", | |
2235 | (int) object, (annex ? annex : "(null)"), | |
2236 | (long) buf, paddr_nz (offset), | |
2237 | paddr_d (len), paddr_d (retval)); | |
2238 | ||
2239 | return retval; | |
2240 | } | |
c906108c | 2241 | |
1e3ff5ad AC |
2242 | static LONGEST |
2243 | debug_to_write_partial (struct target_ops *ops, | |
2244 | enum target_object object, | |
2245 | const char *annex, const void *buf, | |
2246 | ULONGEST offset, LONGEST len) | |
2247 | { | |
2248 | LONGEST retval; | |
2249 | ||
2250 | retval = target_write_partial (&debug_target, object, annex, buf, offset, | |
2251 | len); | |
2252 | ||
2253 | fprintf_unfiltered (gdb_stdlog, | |
2254 | "target_write_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n", | |
2255 | (int) object, (annex ? annex : "(null)"), | |
2256 | (long) buf, paddr_nz (offset), | |
2257 | paddr_d (len), paddr_d (retval)); | |
c906108c SS |
2258 | |
2259 | return retval; | |
2260 | } | |
2261 | ||
96baa820 JM |
2262 | static void |
2263 | debug_to_rcmd (char *command, | |
d9fcf2fb | 2264 | struct ui_file *outbuf) |
96baa820 JM |
2265 | { |
2266 | debug_target.to_rcmd (command, outbuf); | |
2267 | fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command); | |
2268 | } | |
2269 | ||
c906108c | 2270 | static struct symtab_and_line * |
fba45db2 | 2271 | debug_to_enable_exception_callback (enum exception_event_kind kind, int enable) |
c906108c | 2272 | { |
7a292a7a SS |
2273 | struct symtab_and_line *result; |
2274 | result = debug_target.to_enable_exception_callback (kind, enable); | |
96baa820 | 2275 | fprintf_unfiltered (gdb_stdlog, |
c906108c SS |
2276 | "target get_exception_callback_sal (%d, %d)\n", |
2277 | kind, enable); | |
7a292a7a | 2278 | return result; |
c906108c SS |
2279 | } |
2280 | ||
2281 | static struct exception_event_record * | |
fba45db2 | 2282 | debug_to_get_current_exception_event (void) |
c906108c | 2283 | { |
7a292a7a | 2284 | struct exception_event_record *result; |
c5aa993b | 2285 | result = debug_target.to_get_current_exception_event (); |
96baa820 | 2286 | fprintf_unfiltered (gdb_stdlog, "target get_current_exception_event ()\n"); |
7a292a7a | 2287 | return result; |
c906108c SS |
2288 | } |
2289 | ||
2290 | static char * | |
fba45db2 | 2291 | debug_to_pid_to_exec_file (int pid) |
c906108c | 2292 | { |
c5aa993b | 2293 | char *exec_file; |
c906108c SS |
2294 | |
2295 | exec_file = debug_target.to_pid_to_exec_file (pid); | |
2296 | ||
96baa820 | 2297 | fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n", |
c5aa993b | 2298 | pid, exec_file); |
c906108c SS |
2299 | |
2300 | return exec_file; | |
2301 | } | |
2302 | ||
c906108c | 2303 | static void |
fba45db2 | 2304 | setup_target_debug (void) |
c906108c SS |
2305 | { |
2306 | memcpy (&debug_target, ¤t_target, sizeof debug_target); | |
2307 | ||
2308 | current_target.to_open = debug_to_open; | |
2309 | current_target.to_close = debug_to_close; | |
2310 | current_target.to_attach = debug_to_attach; | |
2311 | current_target.to_post_attach = debug_to_post_attach; | |
c906108c | 2312 | current_target.to_detach = debug_to_detach; |
6ad8ae5c | 2313 | current_target.to_disconnect = debug_to_disconnect; |
c906108c SS |
2314 | current_target.to_resume = debug_to_resume; |
2315 | current_target.to_wait = debug_to_wait; | |
2316 | current_target.to_post_wait = debug_to_post_wait; | |
2317 | current_target.to_fetch_registers = debug_to_fetch_registers; | |
2318 | current_target.to_store_registers = debug_to_store_registers; | |
2319 | current_target.to_prepare_to_store = debug_to_prepare_to_store; | |
2320 | current_target.to_xfer_memory = debug_to_xfer_memory; | |
2321 | current_target.to_files_info = debug_to_files_info; | |
2322 | current_target.to_insert_breakpoint = debug_to_insert_breakpoint; | |
2323 | current_target.to_remove_breakpoint = debug_to_remove_breakpoint; | |
ccaa32c7 GS |
2324 | current_target.to_can_use_hw_breakpoint = debug_to_can_use_hw_breakpoint; |
2325 | current_target.to_insert_hw_breakpoint = debug_to_insert_hw_breakpoint; | |
2326 | current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint; | |
2327 | current_target.to_insert_watchpoint = debug_to_insert_watchpoint; | |
2328 | current_target.to_remove_watchpoint = debug_to_remove_watchpoint; | |
2329 | current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint; | |
2330 | current_target.to_stopped_data_address = debug_to_stopped_data_address; | |
2331 | current_target.to_region_size_ok_for_hw_watchpoint = debug_to_region_size_ok_for_hw_watchpoint; | |
c906108c SS |
2332 | current_target.to_terminal_init = debug_to_terminal_init; |
2333 | current_target.to_terminal_inferior = debug_to_terminal_inferior; | |
2334 | current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output; | |
2335 | current_target.to_terminal_ours = debug_to_terminal_ours; | |
a790ad35 | 2336 | current_target.to_terminal_save_ours = debug_to_terminal_save_ours; |
c906108c SS |
2337 | current_target.to_terminal_info = debug_to_terminal_info; |
2338 | current_target.to_kill = debug_to_kill; | |
2339 | current_target.to_load = debug_to_load; | |
2340 | current_target.to_lookup_symbol = debug_to_lookup_symbol; | |
2341 | current_target.to_create_inferior = debug_to_create_inferior; | |
2342 | current_target.to_post_startup_inferior = debug_to_post_startup_inferior; | |
2343 | current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior; | |
c906108c SS |
2344 | current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint; |
2345 | current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint; | |
2346 | current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint; | |
2347 | current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint; | |
6604731b | 2348 | current_target.to_follow_fork = debug_to_follow_fork; |
c906108c SS |
2349 | current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint; |
2350 | current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint; | |
c906108c | 2351 | current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call; |
c906108c SS |
2352 | current_target.to_has_exited = debug_to_has_exited; |
2353 | current_target.to_mourn_inferior = debug_to_mourn_inferior; | |
2354 | current_target.to_can_run = debug_to_can_run; | |
2355 | current_target.to_notice_signals = debug_to_notice_signals; | |
2356 | current_target.to_thread_alive = debug_to_thread_alive; | |
0d06e24b | 2357 | current_target.to_find_new_threads = debug_to_find_new_threads; |
c906108c | 2358 | current_target.to_stop = debug_to_stop; |
1e3ff5ad AC |
2359 | current_target.to_read_partial = debug_to_read_partial; |
2360 | current_target.to_write_partial = debug_to_write_partial; | |
96baa820 | 2361 | current_target.to_rcmd = debug_to_rcmd; |
c906108c SS |
2362 | current_target.to_enable_exception_callback = debug_to_enable_exception_callback; |
2363 | current_target.to_get_current_exception_event = debug_to_get_current_exception_event; | |
2364 | current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file; | |
c906108c SS |
2365 | |
2366 | } | |
c906108c | 2367 | \f |
c5aa993b JM |
2368 | |
2369 | static char targ_desc[] = | |
2370 | "Names of targets and files being debugged.\n\ | |
c906108c SS |
2371 | Shows the entire stack of targets currently in use (including the exec-file,\n\ |
2372 | core-file, and process, if any), as well as the symbol file name."; | |
2373 | ||
96baa820 JM |
2374 | static void |
2375 | do_monitor_command (char *cmd, | |
2376 | int from_tty) | |
2377 | { | |
2b5fe715 AC |
2378 | if ((current_target.to_rcmd |
2379 | == (void (*) (char *, struct ui_file *)) tcomplain) | |
96baa820 | 2380 | || (current_target.to_rcmd == debug_to_rcmd |
2b5fe715 AC |
2381 | && (debug_target.to_rcmd |
2382 | == (void (*) (char *, struct ui_file *)) tcomplain))) | |
96baa820 JM |
2383 | { |
2384 | error ("\"monitor\" command not supported by this target.\n"); | |
2385 | } | |
2386 | target_rcmd (cmd, gdb_stdtarg); | |
2387 | } | |
2388 | ||
c906108c | 2389 | void |
fba45db2 | 2390 | initialize_targets (void) |
c906108c SS |
2391 | { |
2392 | init_dummy_target (); | |
2393 | push_target (&dummy_target); | |
2394 | ||
2395 | add_info ("target", target_info, targ_desc); | |
2396 | add_info ("files", target_info, targ_desc); | |
2397 | ||
3a11626d MS |
2398 | add_show_from_set |
2399 | (add_set_cmd ("target", class_maintenance, var_zinteger, | |
2400 | (char *) &targetdebug, | |
2401 | "Set target debugging.\n\ | |
5d161b24 | 2402 | When non-zero, target debugging is enabled.", &setdebuglist), |
3a11626d MS |
2403 | &showdebuglist); |
2404 | ||
e707bbc2 AC |
2405 | add_setshow_boolean_cmd ("trust-readonly-sections", class_support, |
2406 | &trust_readonly, "\ | |
2407 | Set mode for reading from readonly sections.\n\ | |
3a11626d MS |
2408 | When this mode is on, memory reads from readonly sections (such as .text)\n\ |
2409 | will be read from the object file instead of from the target. This will\n\ | |
e707bbc2 | 2410 | result in significant performance improvement for remote targets.", "\ |
c0e624e7 | 2411 | Show mode for reading from readonly sections.\n", |
e707bbc2 AC |
2412 | NULL, NULL, |
2413 | &setlist, &showlist); | |
96baa820 JM |
2414 | |
2415 | add_com ("monitor", class_obscure, do_monitor_command, | |
2416 | "Send a command to the remote monitor (remote targets only)."); | |
2417 | ||
8add0441 | 2418 | target_dcache = dcache_init (); |
c906108c | 2419 | } |