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