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