2003-10-21 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 if (tmp->to_close)
676 (tmp->to_close) (0);
677 }
678
679 /* We have removed all targets in our stratum, now add the new one. */
680 t->beneath = (*cur);
681 (*cur) = t;
682
683 update_current_target ();
684
685 if (targetdebug)
686 setup_target_debug ();
687
688 /* Not on top? */
689 return (t != target_stack);
690 }
691
692 /* Remove a target_ops vector from the stack, wherever it may be.
693 Return how many times it was removed (0 or 1). */
694
695 int
696 unpush_target (struct target_ops *t)
697 {
698 struct target_ops **cur;
699 struct target_ops *tmp;
700
701 if (t->to_close)
702 t->to_close (0); /* Let it clean up */
703
704 /* Look for the specified target. Note that we assume that a target
705 can only occur once in the target stack. */
706
707 for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
708 {
709 if ((*cur) == t)
710 break;
711 }
712
713 if ((*cur) == NULL)
714 return 0; /* Didn't find target_ops, quit now */
715
716 /* Unchain the target */
717 tmp = (*cur);
718 (*cur) = (*cur)->beneath;
719 tmp->beneath = NULL;
720
721 update_current_target ();
722
723 return 1;
724 }
725
726 void
727 pop_target (void)
728 {
729 (current_target.to_close) (0); /* Let it clean up */
730 if (unpush_target (target_stack) == 1)
731 return;
732
733 fprintf_unfiltered (gdb_stderr,
734 "pop_target couldn't find target %s\n",
735 current_target.to_shortname);
736 internal_error (__FILE__, __LINE__, "failed internal consistency check");
737 }
738
739 #undef MIN
740 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
741
742 /* target_read_string -- read a null terminated string, up to LEN bytes,
743 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
744 Set *STRING to a pointer to malloc'd memory containing the data; the caller
745 is responsible for freeing it. Return the number of bytes successfully
746 read. */
747
748 int
749 target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop)
750 {
751 int tlen, origlen, offset, i;
752 char buf[4];
753 int errcode = 0;
754 char *buffer;
755 int buffer_allocated;
756 char *bufptr;
757 unsigned int nbytes_read = 0;
758
759 /* Small for testing. */
760 buffer_allocated = 4;
761 buffer = xmalloc (buffer_allocated);
762 bufptr = buffer;
763
764 origlen = len;
765
766 while (len > 0)
767 {
768 tlen = MIN (len, 4 - (memaddr & 3));
769 offset = memaddr & 3;
770
771 errcode = target_xfer_memory (memaddr & ~3, buf, 4, 0);
772 if (errcode != 0)
773 {
774 /* The transfer request might have crossed the boundary to an
775 unallocated region of memory. Retry the transfer, requesting
776 a single byte. */
777 tlen = 1;
778 offset = 0;
779 errcode = target_xfer_memory (memaddr, buf, 1, 0);
780 if (errcode != 0)
781 goto done;
782 }
783
784 if (bufptr - buffer + tlen > buffer_allocated)
785 {
786 unsigned int bytes;
787 bytes = bufptr - buffer;
788 buffer_allocated *= 2;
789 buffer = xrealloc (buffer, buffer_allocated);
790 bufptr = buffer + bytes;
791 }
792
793 for (i = 0; i < tlen; i++)
794 {
795 *bufptr++ = buf[i + offset];
796 if (buf[i + offset] == '\000')
797 {
798 nbytes_read += i + 1;
799 goto done;
800 }
801 }
802
803 memaddr += tlen;
804 len -= tlen;
805 nbytes_read += tlen;
806 }
807 done:
808 if (errnop != NULL)
809 *errnop = errcode;
810 if (string != NULL)
811 *string = buffer;
812 return nbytes_read;
813 }
814
815 /* Find a section containing ADDR. */
816 struct section_table *
817 target_section_by_addr (struct target_ops *target, CORE_ADDR addr)
818 {
819 struct section_table *secp;
820 for (secp = target->to_sections;
821 secp < target->to_sections_end;
822 secp++)
823 {
824 if (addr >= secp->addr && addr < secp->endaddr)
825 return secp;
826 }
827 return NULL;
828 }
829
830 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
831 GDB's memory at MYADDR. Returns either 0 for success or an errno value
832 if any error occurs.
833
834 If an error occurs, no guarantee is made about the contents of the data at
835 MYADDR. In particular, the caller should not depend upon partial reads
836 filling the buffer with good data. There is no way for the caller to know
837 how much good data might have been transfered anyway. Callers that can
838 deal with partial reads should call target_read_memory_partial. */
839
840 int
841 target_read_memory (CORE_ADDR memaddr, char *myaddr, int len)
842 {
843 return target_xfer_memory (memaddr, myaddr, len, 0);
844 }
845
846 int
847 target_write_memory (CORE_ADDR memaddr, char *myaddr, int len)
848 {
849 return target_xfer_memory (memaddr, myaddr, len, 1);
850 }
851
852 static int trust_readonly = 0;
853
854 /* Move memory to or from the targets. The top target gets priority;
855 if it cannot handle it, it is offered to the next one down, etc.
856
857 Result is -1 on error, or the number of bytes transfered. */
858
859 int
860 do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
861 struct mem_attrib *attrib)
862 {
863 int res;
864 int done = 0;
865 struct target_ops *t;
866
867 /* Zero length requests are ok and require no work. */
868 if (len == 0)
869 return 0;
870
871 /* to_xfer_memory is not guaranteed to set errno, even when it returns
872 0. */
873 errno = 0;
874
875 if (!write && trust_readonly)
876 {
877 struct section_table *secp;
878 /* User-settable option, "trust-readonly-sections". If true,
879 then memory from any SEC_READONLY bfd section may be read
880 directly from the bfd file. */
881 secp = target_section_by_addr (&current_target, memaddr);
882 if (secp != NULL
883 && (bfd_get_section_flags (secp->bfd, secp->the_bfd_section)
884 & SEC_READONLY))
885 return xfer_memory (memaddr, myaddr, len, 0, attrib, &current_target);
886 }
887
888 /* The quick case is that the top target can handle the transfer. */
889 res = current_target.to_xfer_memory
890 (memaddr, myaddr, len, write, attrib, &current_target);
891
892 /* If res <= 0 then we call it again in the loop. Ah well. */
893 if (res <= 0)
894 {
895 for (t = target_stack; t != NULL; t = t->beneath)
896 {
897 if (!t->to_has_memory)
898 continue;
899
900 res = t->to_xfer_memory (memaddr, myaddr, len, write, attrib, t);
901 if (res > 0)
902 break; /* Handled all or part of xfer */
903 if (t->to_has_all_memory)
904 break;
905 }
906
907 if (res <= 0)
908 return -1;
909 }
910
911 return res;
912 }
913
914
915 /* Perform a memory transfer. Iterate until the entire region has
916 been transfered.
917
918 Result is 0 or errno value. */
919
920 static int
921 target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write)
922 {
923 int res;
924 int reg_len;
925 struct mem_region *region;
926
927 /* Zero length requests are ok and require no work. */
928 if (len == 0)
929 {
930 return 0;
931 }
932
933 while (len > 0)
934 {
935 region = lookup_mem_region(memaddr);
936 if (memaddr + len < region->hi)
937 reg_len = len;
938 else
939 reg_len = region->hi - memaddr;
940
941 switch (region->attrib.mode)
942 {
943 case MEM_RO:
944 if (write)
945 return EIO;
946 break;
947
948 case MEM_WO:
949 if (!write)
950 return EIO;
951 break;
952 }
953
954 while (reg_len > 0)
955 {
956 if (region->attrib.cache)
957 res = dcache_xfer_memory (target_dcache, memaddr, myaddr,
958 reg_len, write);
959 else
960 res = do_xfer_memory (memaddr, myaddr, reg_len, write,
961 &region->attrib);
962
963 if (res <= 0)
964 {
965 /* If this address is for nonexistent memory, read zeros
966 if reading, or do nothing if writing. Return
967 error. */
968 if (!write)
969 memset (myaddr, 0, len);
970 if (errno == 0)
971 return EIO;
972 else
973 return errno;
974 }
975
976 memaddr += res;
977 myaddr += res;
978 len -= res;
979 reg_len -= res;
980 }
981 }
982
983 return 0; /* We managed to cover it all somehow. */
984 }
985
986
987 /* Perform a partial memory transfer.
988
989 Result is -1 on error, or the number of bytes transfered. */
990
991 static int
992 target_xfer_memory_partial (CORE_ADDR memaddr, char *myaddr, int len,
993 int write_p, int *err)
994 {
995 int res;
996 int reg_len;
997 struct mem_region *region;
998
999 /* Zero length requests are ok and require no work. */
1000 if (len == 0)
1001 {
1002 *err = 0;
1003 return 0;
1004 }
1005
1006 region = lookup_mem_region(memaddr);
1007 if (memaddr + len < region->hi)
1008 reg_len = len;
1009 else
1010 reg_len = region->hi - memaddr;
1011
1012 switch (region->attrib.mode)
1013 {
1014 case MEM_RO:
1015 if (write_p)
1016 {
1017 *err = EIO;
1018 return -1;
1019 }
1020 break;
1021
1022 case MEM_WO:
1023 if (write_p)
1024 {
1025 *err = EIO;
1026 return -1;
1027 }
1028 break;
1029 }
1030
1031 if (region->attrib.cache)
1032 res = dcache_xfer_memory (target_dcache, memaddr, myaddr,
1033 reg_len, write_p);
1034 else
1035 res = do_xfer_memory (memaddr, myaddr, reg_len, write_p,
1036 &region->attrib);
1037
1038 if (res <= 0)
1039 {
1040 if (errno != 0)
1041 *err = errno;
1042 else
1043 *err = EIO;
1044
1045 return -1;
1046 }
1047
1048 *err = 0;
1049 return res;
1050 }
1051
1052 int
1053 target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1054 {
1055 return target_xfer_memory_partial (memaddr, buf, len, 0, err);
1056 }
1057
1058 int
1059 target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1060 {
1061 return target_xfer_memory_partial (memaddr, buf, len, 1, err);
1062 }
1063
1064 /* More generic transfers. */
1065
1066 LONGEST
1067 target_read_partial (struct target_ops *ops,
1068 enum target_object object,
1069 const char *annex, void *buf,
1070 ULONGEST offset, LONGEST len)
1071 {
1072 struct target_ops *op;
1073
1074 /* Find the first target stratum that can handle the request. */
1075 for (op = ops;
1076 op != NULL && op->to_read_partial == NULL;
1077 op = op->beneath)
1078 ;
1079 if (op == NULL)
1080 return -1;
1081
1082 /* Now apply the operation at that level. */
1083 return op->to_read_partial (op, object, annex, buf, offset, len);
1084 }
1085
1086 LONGEST
1087 target_write_partial (struct target_ops *ops,
1088 enum target_object object,
1089 const char *annex, const void *buf,
1090 ULONGEST offset, LONGEST len)
1091 {
1092 struct target_ops *op;
1093
1094 /* Find the first target stratum that can handle the request. */
1095 for (op = ops;
1096 op != NULL && op->to_write_partial == NULL;
1097 op = op->beneath)
1098 ;
1099 if (op == NULL)
1100 return -1;
1101
1102 return op->to_write_partial (op, object, annex, buf, offset, len);
1103 }
1104
1105 /* Wrappers to perform the full transfer. */
1106 LONGEST
1107 target_read (struct target_ops *ops,
1108 enum target_object object,
1109 const char *annex, void *buf,
1110 ULONGEST offset, LONGEST len)
1111 {
1112 LONGEST xfered = 0;
1113 while (xfered < len)
1114 {
1115 LONGEST xfer = target_write_partial (ops, object, annex,
1116 (bfd_byte *) buf + xfered,
1117 offset + xfered, len - xfered);
1118 /* Call an observer, notifying them of the xfer progress? */
1119 if (xfer < 0)
1120 return xfer;
1121 xfered += xfer;
1122 QUIT;
1123 }
1124 return len;
1125 }
1126
1127 LONGEST
1128 target_write (struct target_ops *ops,
1129 enum target_object object,
1130 const char *annex, const void *buf,
1131 ULONGEST offset, LONGEST len)
1132 {
1133 LONGEST xfered = 0;
1134 while (xfered < len)
1135 {
1136 LONGEST xfer = target_write_partial (ops, object, annex,
1137 (bfd_byte *) buf + xfered,
1138 offset + xfered, len - xfered);
1139 /* Call an observer, notifying them of the xfer progress? */
1140 if (xfer < 0)
1141 return xfer;
1142 xfered += xfer;
1143 QUIT;
1144 }
1145 return len;
1146 }
1147
1148 static void
1149 target_info (char *args, int from_tty)
1150 {
1151 struct target_ops *t;
1152 int has_all_mem = 0;
1153
1154 if (symfile_objfile != NULL)
1155 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile->name);
1156
1157 #ifdef FILES_INFO_HOOK
1158 if (FILES_INFO_HOOK ())
1159 return;
1160 #endif
1161
1162 for (t = target_stack; t != NULL; t = t->beneath)
1163 {
1164 if (!t->to_has_memory)
1165 continue;
1166
1167 if ((int) (t->to_stratum) <= (int) dummy_stratum)
1168 continue;
1169 if (has_all_mem)
1170 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1171 printf_unfiltered ("%s:\n", t->to_longname);
1172 (t->to_files_info) (t);
1173 has_all_mem = t->to_has_all_memory;
1174 }
1175 }
1176
1177 /* This is to be called by the open routine before it does
1178 anything. */
1179
1180 void
1181 target_preopen (int from_tty)
1182 {
1183 dont_repeat ();
1184
1185 if (target_has_execution)
1186 {
1187 if (!from_tty
1188 || query ("A program is being debugged already. Kill it? "))
1189 target_kill ();
1190 else
1191 error ("Program not killed.");
1192 }
1193
1194 /* Calling target_kill may remove the target from the stack. But if
1195 it doesn't (which seems like a win for UDI), remove it now. */
1196
1197 if (target_has_execution)
1198 pop_target ();
1199 }
1200
1201 /* Detach a target after doing deferred register stores. */
1202
1203 void
1204 target_detach (char *args, int from_tty)
1205 {
1206 /* Handle any optimized stores to the inferior. */
1207 #ifdef DO_DEFERRED_STORES
1208 DO_DEFERRED_STORES;
1209 #endif
1210 (current_target.to_detach) (args, from_tty);
1211 }
1212
1213 void
1214 target_disconnect (char *args, int from_tty)
1215 {
1216 /* Handle any optimized stores to the inferior. */
1217 #ifdef DO_DEFERRED_STORES
1218 DO_DEFERRED_STORES;
1219 #endif
1220 (current_target.to_disconnect) (args, from_tty);
1221 }
1222
1223 void
1224 target_link (char *modname, CORE_ADDR *t_reloc)
1225 {
1226 if (STREQ (current_target.to_shortname, "rombug"))
1227 {
1228 (current_target.to_lookup_symbol) (modname, t_reloc);
1229 if (*t_reloc == 0)
1230 error ("Unable to link to %s and get relocation in rombug", modname);
1231 }
1232 else
1233 *t_reloc = (CORE_ADDR) -1;
1234 }
1235
1236 int
1237 target_async_mask (int mask)
1238 {
1239 int saved_async_masked_status = target_async_mask_value;
1240 target_async_mask_value = mask;
1241 return saved_async_masked_status;
1242 }
1243
1244 /* Look through the list of possible targets for a target that can
1245 execute a run or attach command without any other data. This is
1246 used to locate the default process stratum.
1247
1248 Result is always valid (error() is called for errors). */
1249
1250 static struct target_ops *
1251 find_default_run_target (char *do_mesg)
1252 {
1253 struct target_ops **t;
1254 struct target_ops *runable = NULL;
1255 int count;
1256
1257 count = 0;
1258
1259 for (t = target_structs; t < target_structs + target_struct_size;
1260 ++t)
1261 {
1262 if ((*t)->to_can_run && target_can_run (*t))
1263 {
1264 runable = *t;
1265 ++count;
1266 }
1267 }
1268
1269 if (count != 1)
1270 error ("Don't know how to %s. Try \"help target\".", do_mesg);
1271
1272 return runable;
1273 }
1274
1275 void
1276 find_default_attach (char *args, int from_tty)
1277 {
1278 struct target_ops *t;
1279
1280 t = find_default_run_target ("attach");
1281 (t->to_attach) (args, from_tty);
1282 return;
1283 }
1284
1285 void
1286 find_default_create_inferior (char *exec_file, char *allargs, char **env)
1287 {
1288 struct target_ops *t;
1289
1290 t = find_default_run_target ("run");
1291 (t->to_create_inferior) (exec_file, allargs, env);
1292 return;
1293 }
1294
1295 static int
1296 default_region_size_ok_for_hw_watchpoint (int byte_count)
1297 {
1298 return (byte_count <= DEPRECATED_REGISTER_SIZE);
1299 }
1300
1301 static int
1302 return_zero (void)
1303 {
1304 return 0;
1305 }
1306
1307 static int
1308 return_one (void)
1309 {
1310 return 1;
1311 }
1312
1313 static int
1314 return_minus_one (void)
1315 {
1316 return -1;
1317 }
1318
1319 /*
1320 * Resize the to_sections pointer. Also make sure that anyone that
1321 * was holding on to an old value of it gets updated.
1322 * Returns the old size.
1323 */
1324
1325 int
1326 target_resize_to_sections (struct target_ops *target, int num_added)
1327 {
1328 struct target_ops **t;
1329 struct section_table *old_value;
1330 int old_count;
1331
1332 old_value = target->to_sections;
1333
1334 if (target->to_sections)
1335 {
1336 old_count = target->to_sections_end - target->to_sections;
1337 target->to_sections = (struct section_table *)
1338 xrealloc ((char *) target->to_sections,
1339 (sizeof (struct section_table)) * (num_added + old_count));
1340 }
1341 else
1342 {
1343 old_count = 0;
1344 target->to_sections = (struct section_table *)
1345 xmalloc ((sizeof (struct section_table)) * num_added);
1346 }
1347 target->to_sections_end = target->to_sections + (num_added + old_count);
1348
1349 /* Check to see if anyone else was pointing to this structure.
1350 If old_value was null, then no one was. */
1351
1352 if (old_value)
1353 {
1354 for (t = target_structs; t < target_structs + target_struct_size;
1355 ++t)
1356 {
1357 if ((*t)->to_sections == old_value)
1358 {
1359 (*t)->to_sections = target->to_sections;
1360 (*t)->to_sections_end = target->to_sections_end;
1361 }
1362 }
1363 }
1364
1365 return old_count;
1366
1367 }
1368
1369 /* Remove all target sections taken from ABFD.
1370
1371 Scan the current target stack for targets whose section tables
1372 refer to sections from BFD, and remove those sections. We use this
1373 when we notice that the inferior has unloaded a shared object, for
1374 example. */
1375 void
1376 remove_target_sections (bfd *abfd)
1377 {
1378 struct target_ops **t;
1379
1380 for (t = target_structs; t < target_structs + target_struct_size; t++)
1381 {
1382 struct section_table *src, *dest;
1383
1384 dest = (*t)->to_sections;
1385 for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++)
1386 if (src->bfd != abfd)
1387 {
1388 /* Keep this section. */
1389 if (dest < src) *dest = *src;
1390 dest++;
1391 }
1392
1393 /* If we've dropped any sections, resize the section table. */
1394 if (dest < src)
1395 target_resize_to_sections (*t, dest - src);
1396 }
1397 }
1398
1399
1400
1401
1402 /* Find a single runnable target in the stack and return it. If for
1403 some reason there is more than one, return NULL. */
1404
1405 struct target_ops *
1406 find_run_target (void)
1407 {
1408 struct target_ops **t;
1409 struct target_ops *runable = NULL;
1410 int count;
1411
1412 count = 0;
1413
1414 for (t = target_structs; t < target_structs + target_struct_size; ++t)
1415 {
1416 if ((*t)->to_can_run && target_can_run (*t))
1417 {
1418 runable = *t;
1419 ++count;
1420 }
1421 }
1422
1423 return (count == 1 ? runable : NULL);
1424 }
1425
1426 /* Find a single core_stratum target in the list of targets and return it.
1427 If for some reason there is more than one, return NULL. */
1428
1429 struct target_ops *
1430 find_core_target (void)
1431 {
1432 struct target_ops **t;
1433 struct target_ops *runable = NULL;
1434 int count;
1435
1436 count = 0;
1437
1438 for (t = target_structs; t < target_structs + target_struct_size;
1439 ++t)
1440 {
1441 if ((*t)->to_stratum == core_stratum)
1442 {
1443 runable = *t;
1444 ++count;
1445 }
1446 }
1447
1448 return (count == 1 ? runable : NULL);
1449 }
1450
1451 /*
1452 * Find the next target down the stack from the specified target.
1453 */
1454
1455 struct target_ops *
1456 find_target_beneath (struct target_ops *t)
1457 {
1458 return t->beneath;
1459 }
1460
1461 \f
1462 /* The inferior process has died. Long live the inferior! */
1463
1464 void
1465 generic_mourn_inferior (void)
1466 {
1467 extern int show_breakpoint_hit_counts;
1468
1469 inferior_ptid = null_ptid;
1470 attach_flag = 0;
1471 breakpoint_init_inferior (inf_exited);
1472 registers_changed ();
1473
1474 #ifdef CLEAR_DEFERRED_STORES
1475 /* Delete any pending stores to the inferior... */
1476 CLEAR_DEFERRED_STORES;
1477 #endif
1478
1479 reopen_exec_file ();
1480 reinit_frame_cache ();
1481
1482 /* It is confusing to the user for ignore counts to stick around
1483 from previous runs of the inferior. So clear them. */
1484 /* However, it is more confusing for the ignore counts to disappear when
1485 using hit counts. So don't clear them if we're counting hits. */
1486 if (!show_breakpoint_hit_counts)
1487 breakpoint_clear_ignore_counts ();
1488
1489 if (detach_hook)
1490 detach_hook ();
1491 }
1492 \f
1493 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1494 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1495 translation of that in OURSTATUS. */
1496 void
1497 store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus)
1498 {
1499 #ifdef CHILD_SPECIAL_WAITSTATUS
1500 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1501 if it wants to deal with hoststatus. */
1502 if (CHILD_SPECIAL_WAITSTATUS (ourstatus, hoststatus))
1503 return;
1504 #endif
1505
1506 if (WIFEXITED (hoststatus))
1507 {
1508 ourstatus->kind = TARGET_WAITKIND_EXITED;
1509 ourstatus->value.integer = WEXITSTATUS (hoststatus);
1510 }
1511 else if (!WIFSTOPPED (hoststatus))
1512 {
1513 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
1514 ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus));
1515 }
1516 else
1517 {
1518 ourstatus->kind = TARGET_WAITKIND_STOPPED;
1519 ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus));
1520 }
1521 }
1522 \f
1523 /* Returns zero to leave the inferior alone, one to interrupt it. */
1524 int (*target_activity_function) (void);
1525 int target_activity_fd;
1526 \f
1527 /* Convert a normal process ID to a string. Returns the string in a static
1528 buffer. */
1529
1530 char *
1531 normal_pid_to_str (ptid_t ptid)
1532 {
1533 static char buf[30];
1534
1535 sprintf (buf, "process %d", PIDGET (ptid));
1536 return buf;
1537 }
1538
1539 /* Some targets (such as ttrace-based HPUX) don't allow us to request
1540 notification of inferior events such as fork and vork immediately
1541 after the inferior is created. (This because of how gdb gets an
1542 inferior created via invoking a shell to do it. In such a scenario,
1543 if the shell init file has commands in it, the shell will fork and
1544 exec for each of those commands, and we will see each such fork
1545 event. Very bad.)
1546
1547 This function is used by all targets that allow us to request
1548 notification of forks, etc at inferior creation time; e.g., in
1549 target_acknowledge_forked_child.
1550 */
1551 static void
1552 normal_target_post_startup_inferior (ptid_t ptid)
1553 {
1554 /* This space intentionally left blank. */
1555 }
1556
1557 /* Error-catcher for target_find_memory_regions */
1558 static int dummy_find_memory_regions (int (*ignore1) (), void *ignore2)
1559 {
1560 error ("No target.");
1561 return 0;
1562 }
1563
1564 /* Error-catcher for target_make_corefile_notes */
1565 static char * dummy_make_corefile_notes (bfd *ignore1, int *ignore2)
1566 {
1567 error ("No target.");
1568 return NULL;
1569 }
1570
1571 /* Set up the handful of non-empty slots needed by the dummy target
1572 vector. */
1573
1574 static void
1575 init_dummy_target (void)
1576 {
1577 dummy_target.to_shortname = "None";
1578 dummy_target.to_longname = "None";
1579 dummy_target.to_doc = "";
1580 dummy_target.to_attach = find_default_attach;
1581 dummy_target.to_create_inferior = find_default_create_inferior;
1582 dummy_target.to_pid_to_str = normal_pid_to_str;
1583 dummy_target.to_stratum = dummy_stratum;
1584 dummy_target.to_find_memory_regions = dummy_find_memory_regions;
1585 dummy_target.to_make_corefile_notes = dummy_make_corefile_notes;
1586 dummy_target.to_magic = OPS_MAGIC;
1587 }
1588 \f
1589
1590 static struct target_ops debug_target;
1591
1592 static void
1593 debug_to_open (char *args, int from_tty)
1594 {
1595 debug_target.to_open (args, from_tty);
1596
1597 fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty);
1598 }
1599
1600 static void
1601 debug_to_close (int quitting)
1602 {
1603 debug_target.to_close (quitting);
1604
1605 fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting);
1606 }
1607
1608 static void
1609 debug_to_attach (char *args, int from_tty)
1610 {
1611 debug_target.to_attach (args, from_tty);
1612
1613 fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty);
1614 }
1615
1616
1617 static void
1618 debug_to_post_attach (int pid)
1619 {
1620 debug_target.to_post_attach (pid);
1621
1622 fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid);
1623 }
1624
1625 static void
1626 debug_to_detach (char *args, int from_tty)
1627 {
1628 debug_target.to_detach (args, from_tty);
1629
1630 fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty);
1631 }
1632
1633 static void
1634 debug_to_disconnect (char *args, int from_tty)
1635 {
1636 debug_target.to_disconnect (args, from_tty);
1637
1638 fprintf_unfiltered (gdb_stdlog, "target_disconnect (%s, %d)\n",
1639 args, from_tty);
1640 }
1641
1642 static void
1643 debug_to_resume (ptid_t ptid, int step, enum target_signal siggnal)
1644 {
1645 debug_target.to_resume (ptid, step, siggnal);
1646
1647 fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", PIDGET (ptid),
1648 step ? "step" : "continue",
1649 target_signal_to_name (siggnal));
1650 }
1651
1652 static ptid_t
1653 debug_to_wait (ptid_t ptid, struct target_waitstatus *status)
1654 {
1655 ptid_t retval;
1656
1657 retval = debug_target.to_wait (ptid, status);
1658
1659 fprintf_unfiltered (gdb_stdlog,
1660 "target_wait (%d, status) = %d, ", PIDGET (ptid),
1661 PIDGET (retval));
1662 fprintf_unfiltered (gdb_stdlog, "status->kind = ");
1663 switch (status->kind)
1664 {
1665 case TARGET_WAITKIND_EXITED:
1666 fprintf_unfiltered (gdb_stdlog, "exited, status = %d\n",
1667 status->value.integer);
1668 break;
1669 case TARGET_WAITKIND_STOPPED:
1670 fprintf_unfiltered (gdb_stdlog, "stopped, signal = %s\n",
1671 target_signal_to_name (status->value.sig));
1672 break;
1673 case TARGET_WAITKIND_SIGNALLED:
1674 fprintf_unfiltered (gdb_stdlog, "signalled, signal = %s\n",
1675 target_signal_to_name (status->value.sig));
1676 break;
1677 case TARGET_WAITKIND_LOADED:
1678 fprintf_unfiltered (gdb_stdlog, "loaded\n");
1679 break;
1680 case TARGET_WAITKIND_FORKED:
1681 fprintf_unfiltered (gdb_stdlog, "forked\n");
1682 break;
1683 case TARGET_WAITKIND_VFORKED:
1684 fprintf_unfiltered (gdb_stdlog, "vforked\n");
1685 break;
1686 case TARGET_WAITKIND_EXECD:
1687 fprintf_unfiltered (gdb_stdlog, "execd\n");
1688 break;
1689 case TARGET_WAITKIND_SPURIOUS:
1690 fprintf_unfiltered (gdb_stdlog, "spurious\n");
1691 break;
1692 default:
1693 fprintf_unfiltered (gdb_stdlog, "unknown???\n");
1694 break;
1695 }
1696
1697 return retval;
1698 }
1699
1700 static void
1701 debug_to_post_wait (ptid_t ptid, int status)
1702 {
1703 debug_target.to_post_wait (ptid, status);
1704
1705 fprintf_unfiltered (gdb_stdlog, "target_post_wait (%d, %d)\n",
1706 PIDGET (ptid), status);
1707 }
1708
1709 static void
1710 debug_print_register (const char * func, int regno)
1711 {
1712 fprintf_unfiltered (gdb_stdlog, "%s ", func);
1713 if (regno >= 0 && regno < NUM_REGS + NUM_PSEUDO_REGS
1714 && REGISTER_NAME (regno) != NULL && REGISTER_NAME (regno)[0] != '\0')
1715 fprintf_unfiltered (gdb_stdlog, "(%s)", REGISTER_NAME (regno));
1716 else
1717 fprintf_unfiltered (gdb_stdlog, "(%d)", regno);
1718 if (regno >= 0)
1719 {
1720 int i;
1721 unsigned char buf[MAX_REGISTER_SIZE];
1722 deprecated_read_register_gen (regno, buf);
1723 fprintf_unfiltered (gdb_stdlog, " = ");
1724 for (i = 0; i < DEPRECATED_REGISTER_RAW_SIZE (regno); i++)
1725 {
1726 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
1727 }
1728 if (DEPRECATED_REGISTER_RAW_SIZE (regno) <= sizeof (LONGEST))
1729 {
1730 fprintf_unfiltered (gdb_stdlog, " 0x%s %s",
1731 paddr_nz (read_register (regno)),
1732 paddr_d (read_register (regno)));
1733 }
1734 }
1735 fprintf_unfiltered (gdb_stdlog, "\n");
1736 }
1737
1738 static void
1739 debug_to_fetch_registers (int regno)
1740 {
1741 debug_target.to_fetch_registers (regno);
1742 debug_print_register ("target_fetch_registers", regno);
1743 }
1744
1745 static void
1746 debug_to_store_registers (int regno)
1747 {
1748 debug_target.to_store_registers (regno);
1749 debug_print_register ("target_store_registers", regno);
1750 fprintf_unfiltered (gdb_stdlog, "\n");
1751 }
1752
1753 static void
1754 debug_to_prepare_to_store (void)
1755 {
1756 debug_target.to_prepare_to_store ();
1757
1758 fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n");
1759 }
1760
1761 static int
1762 debug_to_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
1763 struct mem_attrib *attrib,
1764 struct target_ops *target)
1765 {
1766 int retval;
1767
1768 retval = debug_target.to_xfer_memory (memaddr, myaddr, len, write,
1769 attrib, target);
1770
1771 fprintf_unfiltered (gdb_stdlog,
1772 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
1773 (unsigned int) memaddr, /* possable truncate long long */
1774 len, write ? "write" : "read", retval);
1775
1776
1777
1778 if (retval > 0)
1779 {
1780 int i;
1781
1782 fputs_unfiltered (", bytes =", gdb_stdlog);
1783 for (i = 0; i < retval; i++)
1784 {
1785 if ((((long) &(myaddr[i])) & 0xf) == 0)
1786 fprintf_unfiltered (gdb_stdlog, "\n");
1787 fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff);
1788 }
1789 }
1790
1791 fputc_unfiltered ('\n', gdb_stdlog);
1792
1793 return retval;
1794 }
1795
1796 static void
1797 debug_to_files_info (struct target_ops *target)
1798 {
1799 debug_target.to_files_info (target);
1800
1801 fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n");
1802 }
1803
1804 static int
1805 debug_to_insert_breakpoint (CORE_ADDR addr, char *save)
1806 {
1807 int retval;
1808
1809 retval = debug_target.to_insert_breakpoint (addr, save);
1810
1811 fprintf_unfiltered (gdb_stdlog,
1812 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
1813 (unsigned long) addr,
1814 (unsigned long) retval);
1815 return retval;
1816 }
1817
1818 static int
1819 debug_to_remove_breakpoint (CORE_ADDR addr, char *save)
1820 {
1821 int retval;
1822
1823 retval = debug_target.to_remove_breakpoint (addr, save);
1824
1825 fprintf_unfiltered (gdb_stdlog,
1826 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
1827 (unsigned long) addr,
1828 (unsigned long) retval);
1829 return retval;
1830 }
1831
1832 static int
1833 debug_to_can_use_hw_breakpoint (int type, int cnt, int from_tty)
1834 {
1835 int retval;
1836
1837 retval = debug_target.to_can_use_hw_breakpoint (type, cnt, from_tty);
1838
1839 fprintf_unfiltered (gdb_stdlog,
1840 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
1841 (unsigned long) type,
1842 (unsigned long) cnt,
1843 (unsigned long) from_tty,
1844 (unsigned long) retval);
1845 return retval;
1846 }
1847
1848 static int
1849 debug_to_region_size_ok_for_hw_watchpoint (int byte_count)
1850 {
1851 CORE_ADDR retval;
1852
1853 retval = debug_target.to_region_size_ok_for_hw_watchpoint (byte_count);
1854
1855 fprintf_unfiltered (gdb_stdlog,
1856 "TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT (%ld) = 0x%lx\n",
1857 (unsigned long) byte_count,
1858 (unsigned long) retval);
1859 return retval;
1860 }
1861
1862 static int
1863 debug_to_stopped_by_watchpoint (void)
1864 {
1865 int retval;
1866
1867 retval = debug_target.to_stopped_by_watchpoint ();
1868
1869 fprintf_unfiltered (gdb_stdlog,
1870 "STOPPED_BY_WATCHPOINT () = %ld\n",
1871 (unsigned long) retval);
1872 return retval;
1873 }
1874
1875 static CORE_ADDR
1876 debug_to_stopped_data_address (void)
1877 {
1878 CORE_ADDR retval;
1879
1880 retval = debug_target.to_stopped_data_address ();
1881
1882 fprintf_unfiltered (gdb_stdlog,
1883 "target_stopped_data_address () = 0x%lx\n",
1884 (unsigned long) retval);
1885 return retval;
1886 }
1887
1888 static int
1889 debug_to_insert_hw_breakpoint (CORE_ADDR addr, char *save)
1890 {
1891 int retval;
1892
1893 retval = debug_target.to_insert_hw_breakpoint (addr, save);
1894
1895 fprintf_unfiltered (gdb_stdlog,
1896 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
1897 (unsigned long) addr,
1898 (unsigned long) retval);
1899 return retval;
1900 }
1901
1902 static int
1903 debug_to_remove_hw_breakpoint (CORE_ADDR addr, char *save)
1904 {
1905 int retval;
1906
1907 retval = debug_target.to_remove_hw_breakpoint (addr, save);
1908
1909 fprintf_unfiltered (gdb_stdlog,
1910 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
1911 (unsigned long) addr,
1912 (unsigned long) retval);
1913 return retval;
1914 }
1915
1916 static int
1917 debug_to_insert_watchpoint (CORE_ADDR addr, int len, int type)
1918 {
1919 int retval;
1920
1921 retval = debug_target.to_insert_watchpoint (addr, len, type);
1922
1923 fprintf_unfiltered (gdb_stdlog,
1924 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1925 (unsigned long) addr, len, type, (unsigned long) retval);
1926 return retval;
1927 }
1928
1929 static int
1930 debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type)
1931 {
1932 int retval;
1933
1934 retval = debug_target.to_insert_watchpoint (addr, len, type);
1935
1936 fprintf_unfiltered (gdb_stdlog,
1937 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1938 (unsigned long) addr, len, type, (unsigned long) retval);
1939 return retval;
1940 }
1941
1942 static void
1943 debug_to_terminal_init (void)
1944 {
1945 debug_target.to_terminal_init ();
1946
1947 fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n");
1948 }
1949
1950 static void
1951 debug_to_terminal_inferior (void)
1952 {
1953 debug_target.to_terminal_inferior ();
1954
1955 fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n");
1956 }
1957
1958 static void
1959 debug_to_terminal_ours_for_output (void)
1960 {
1961 debug_target.to_terminal_ours_for_output ();
1962
1963 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n");
1964 }
1965
1966 static void
1967 debug_to_terminal_ours (void)
1968 {
1969 debug_target.to_terminal_ours ();
1970
1971 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n");
1972 }
1973
1974 static void
1975 debug_to_terminal_save_ours (void)
1976 {
1977 debug_target.to_terminal_save_ours ();
1978
1979 fprintf_unfiltered (gdb_stdlog, "target_terminal_save_ours ()\n");
1980 }
1981
1982 static void
1983 debug_to_terminal_info (char *arg, int from_tty)
1984 {
1985 debug_target.to_terminal_info (arg, from_tty);
1986
1987 fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg,
1988 from_tty);
1989 }
1990
1991 static void
1992 debug_to_kill (void)
1993 {
1994 debug_target.to_kill ();
1995
1996 fprintf_unfiltered (gdb_stdlog, "target_kill ()\n");
1997 }
1998
1999 static void
2000 debug_to_load (char *args, int from_tty)
2001 {
2002 debug_target.to_load (args, from_tty);
2003
2004 fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty);
2005 }
2006
2007 static int
2008 debug_to_lookup_symbol (char *name, CORE_ADDR *addrp)
2009 {
2010 int retval;
2011
2012 retval = debug_target.to_lookup_symbol (name, addrp);
2013
2014 fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name);
2015
2016 return retval;
2017 }
2018
2019 static void
2020 debug_to_create_inferior (char *exec_file, char *args, char **env)
2021 {
2022 debug_target.to_create_inferior (exec_file, args, env);
2023
2024 fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx)\n",
2025 exec_file, args);
2026 }
2027
2028 static void
2029 debug_to_post_startup_inferior (ptid_t ptid)
2030 {
2031 debug_target.to_post_startup_inferior (ptid);
2032
2033 fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n",
2034 PIDGET (ptid));
2035 }
2036
2037 static void
2038 debug_to_acknowledge_created_inferior (int pid)
2039 {
2040 debug_target.to_acknowledge_created_inferior (pid);
2041
2042 fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n",
2043 pid);
2044 }
2045
2046 static int
2047 debug_to_insert_fork_catchpoint (int pid)
2048 {
2049 int retval;
2050
2051 retval = debug_target.to_insert_fork_catchpoint (pid);
2052
2053 fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d) = %d\n",
2054 pid, retval);
2055
2056 return retval;
2057 }
2058
2059 static int
2060 debug_to_remove_fork_catchpoint (int pid)
2061 {
2062 int retval;
2063
2064 retval = debug_target.to_remove_fork_catchpoint (pid);
2065
2066 fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n",
2067 pid, retval);
2068
2069 return retval;
2070 }
2071
2072 static int
2073 debug_to_insert_vfork_catchpoint (int pid)
2074 {
2075 int retval;
2076
2077 retval = debug_target.to_insert_vfork_catchpoint (pid);
2078
2079 fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)= %d\n",
2080 pid, retval);
2081
2082 return retval;
2083 }
2084
2085 static int
2086 debug_to_remove_vfork_catchpoint (int pid)
2087 {
2088 int retval;
2089
2090 retval = debug_target.to_remove_vfork_catchpoint (pid);
2091
2092 fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n",
2093 pid, retval);
2094
2095 return retval;
2096 }
2097
2098 static int
2099 debug_to_follow_fork (int follow_child)
2100 {
2101 int retval = debug_target.to_follow_fork (follow_child);
2102
2103 fprintf_unfiltered (gdb_stdlog, "target_follow_fork (%d) = %d\n",
2104 follow_child, retval);
2105
2106 return retval;
2107 }
2108
2109 static int
2110 debug_to_insert_exec_catchpoint (int pid)
2111 {
2112 int retval;
2113
2114 retval = debug_target.to_insert_exec_catchpoint (pid);
2115
2116 fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d) = %d\n",
2117 pid, retval);
2118
2119 return retval;
2120 }
2121
2122 static int
2123 debug_to_remove_exec_catchpoint (int pid)
2124 {
2125 int retval;
2126
2127 retval = debug_target.to_remove_exec_catchpoint (pid);
2128
2129 fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n",
2130 pid, retval);
2131
2132 return retval;
2133 }
2134
2135 static int
2136 debug_to_reported_exec_events_per_exec_call (void)
2137 {
2138 int reported_exec_events;
2139
2140 reported_exec_events = debug_target.to_reported_exec_events_per_exec_call ();
2141
2142 fprintf_unfiltered (gdb_stdlog,
2143 "target_reported_exec_events_per_exec_call () = %d\n",
2144 reported_exec_events);
2145
2146 return reported_exec_events;
2147 }
2148
2149 static int
2150 debug_to_has_exited (int pid, int wait_status, int *exit_status)
2151 {
2152 int has_exited;
2153
2154 has_exited = debug_target.to_has_exited (pid, wait_status, exit_status);
2155
2156 fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n",
2157 pid, wait_status, *exit_status, has_exited);
2158
2159 return has_exited;
2160 }
2161
2162 static void
2163 debug_to_mourn_inferior (void)
2164 {
2165 debug_target.to_mourn_inferior ();
2166
2167 fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n");
2168 }
2169
2170 static int
2171 debug_to_can_run (void)
2172 {
2173 int retval;
2174
2175 retval = debug_target.to_can_run ();
2176
2177 fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval);
2178
2179 return retval;
2180 }
2181
2182 static void
2183 debug_to_notice_signals (ptid_t ptid)
2184 {
2185 debug_target.to_notice_signals (ptid);
2186
2187 fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n",
2188 PIDGET (ptid));
2189 }
2190
2191 static int
2192 debug_to_thread_alive (ptid_t ptid)
2193 {
2194 int retval;
2195
2196 retval = debug_target.to_thread_alive (ptid);
2197
2198 fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n",
2199 PIDGET (ptid), retval);
2200
2201 return retval;
2202 }
2203
2204 static void
2205 debug_to_find_new_threads (void)
2206 {
2207 debug_target.to_find_new_threads ();
2208
2209 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog);
2210 }
2211
2212 static void
2213 debug_to_stop (void)
2214 {
2215 debug_target.to_stop ();
2216
2217 fprintf_unfiltered (gdb_stdlog, "target_stop ()\n");
2218 }
2219
2220 static LONGEST
2221 debug_to_read_partial (struct target_ops *ops,
2222 enum target_object object,
2223 const char *annex, void *buf,
2224 ULONGEST offset, LONGEST len)
2225 {
2226 LONGEST retval;
2227
2228 retval = target_read_partial (&debug_target, object, annex, buf, offset,
2229 len);
2230
2231 fprintf_unfiltered (gdb_stdlog,
2232 "target_read_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n",
2233 (int) object, (annex ? annex : "(null)"),
2234 (long) buf, paddr_nz (offset),
2235 paddr_d (len), paddr_d (retval));
2236
2237 return retval;
2238 }
2239
2240 static LONGEST
2241 debug_to_write_partial (struct target_ops *ops,
2242 enum target_object object,
2243 const char *annex, const void *buf,
2244 ULONGEST offset, LONGEST len)
2245 {
2246 LONGEST retval;
2247
2248 retval = target_write_partial (&debug_target, object, annex, buf, offset,
2249 len);
2250
2251 fprintf_unfiltered (gdb_stdlog,
2252 "target_write_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n",
2253 (int) object, (annex ? annex : "(null)"),
2254 (long) buf, paddr_nz (offset),
2255 paddr_d (len), paddr_d (retval));
2256
2257 return retval;
2258 }
2259
2260 static void
2261 debug_to_rcmd (char *command,
2262 struct ui_file *outbuf)
2263 {
2264 debug_target.to_rcmd (command, outbuf);
2265 fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command);
2266 }
2267
2268 static struct symtab_and_line *
2269 debug_to_enable_exception_callback (enum exception_event_kind kind, int enable)
2270 {
2271 struct symtab_and_line *result;
2272 result = debug_target.to_enable_exception_callback (kind, enable);
2273 fprintf_unfiltered (gdb_stdlog,
2274 "target get_exception_callback_sal (%d, %d)\n",
2275 kind, enable);
2276 return result;
2277 }
2278
2279 static struct exception_event_record *
2280 debug_to_get_current_exception_event (void)
2281 {
2282 struct exception_event_record *result;
2283 result = debug_target.to_get_current_exception_event ();
2284 fprintf_unfiltered (gdb_stdlog, "target get_current_exception_event ()\n");
2285 return result;
2286 }
2287
2288 static char *
2289 debug_to_pid_to_exec_file (int pid)
2290 {
2291 char *exec_file;
2292
2293 exec_file = debug_target.to_pid_to_exec_file (pid);
2294
2295 fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n",
2296 pid, exec_file);
2297
2298 return exec_file;
2299 }
2300
2301 static void
2302 setup_target_debug (void)
2303 {
2304 memcpy (&debug_target, &current_target, sizeof debug_target);
2305
2306 current_target.to_open = debug_to_open;
2307 current_target.to_close = debug_to_close;
2308 current_target.to_attach = debug_to_attach;
2309 current_target.to_post_attach = debug_to_post_attach;
2310 current_target.to_detach = debug_to_detach;
2311 current_target.to_disconnect = debug_to_disconnect;
2312 current_target.to_resume = debug_to_resume;
2313 current_target.to_wait = debug_to_wait;
2314 current_target.to_post_wait = debug_to_post_wait;
2315 current_target.to_fetch_registers = debug_to_fetch_registers;
2316 current_target.to_store_registers = debug_to_store_registers;
2317 current_target.to_prepare_to_store = debug_to_prepare_to_store;
2318 current_target.to_xfer_memory = debug_to_xfer_memory;
2319 current_target.to_files_info = debug_to_files_info;
2320 current_target.to_insert_breakpoint = debug_to_insert_breakpoint;
2321 current_target.to_remove_breakpoint = debug_to_remove_breakpoint;
2322 current_target.to_can_use_hw_breakpoint = debug_to_can_use_hw_breakpoint;
2323 current_target.to_insert_hw_breakpoint = debug_to_insert_hw_breakpoint;
2324 current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint;
2325 current_target.to_insert_watchpoint = debug_to_insert_watchpoint;
2326 current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
2327 current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
2328 current_target.to_stopped_data_address = debug_to_stopped_data_address;
2329 current_target.to_region_size_ok_for_hw_watchpoint = debug_to_region_size_ok_for_hw_watchpoint;
2330 current_target.to_terminal_init = debug_to_terminal_init;
2331 current_target.to_terminal_inferior = debug_to_terminal_inferior;
2332 current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output;
2333 current_target.to_terminal_ours = debug_to_terminal_ours;
2334 current_target.to_terminal_save_ours = debug_to_terminal_save_ours;
2335 current_target.to_terminal_info = debug_to_terminal_info;
2336 current_target.to_kill = debug_to_kill;
2337 current_target.to_load = debug_to_load;
2338 current_target.to_lookup_symbol = debug_to_lookup_symbol;
2339 current_target.to_create_inferior = debug_to_create_inferior;
2340 current_target.to_post_startup_inferior = debug_to_post_startup_inferior;
2341 current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior;
2342 current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint;
2343 current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
2344 current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
2345 current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint;
2346 current_target.to_follow_fork = debug_to_follow_fork;
2347 current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint;
2348 current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
2349 current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call;
2350 current_target.to_has_exited = debug_to_has_exited;
2351 current_target.to_mourn_inferior = debug_to_mourn_inferior;
2352 current_target.to_can_run = debug_to_can_run;
2353 current_target.to_notice_signals = debug_to_notice_signals;
2354 current_target.to_thread_alive = debug_to_thread_alive;
2355 current_target.to_find_new_threads = debug_to_find_new_threads;
2356 current_target.to_stop = debug_to_stop;
2357 current_target.to_read_partial = debug_to_read_partial;
2358 current_target.to_write_partial = debug_to_write_partial;
2359 current_target.to_rcmd = debug_to_rcmd;
2360 current_target.to_enable_exception_callback = debug_to_enable_exception_callback;
2361 current_target.to_get_current_exception_event = debug_to_get_current_exception_event;
2362 current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
2363
2364 }
2365 \f
2366
2367 static char targ_desc[] =
2368 "Names of targets and files being debugged.\n\
2369 Shows the entire stack of targets currently in use (including the exec-file,\n\
2370 core-file, and process, if any), as well as the symbol file name.";
2371
2372 static void
2373 do_monitor_command (char *cmd,
2374 int from_tty)
2375 {
2376 if ((current_target.to_rcmd
2377 == (void (*) (char *, struct ui_file *)) tcomplain)
2378 || (current_target.to_rcmd == debug_to_rcmd
2379 && (debug_target.to_rcmd
2380 == (void (*) (char *, struct ui_file *)) tcomplain)))
2381 {
2382 error ("\"monitor\" command not supported by this target.\n");
2383 }
2384 target_rcmd (cmd, gdb_stdtarg);
2385 }
2386
2387 void
2388 initialize_targets (void)
2389 {
2390 init_dummy_target ();
2391 push_target (&dummy_target);
2392
2393 add_info ("target", target_info, targ_desc);
2394 add_info ("files", target_info, targ_desc);
2395
2396 add_show_from_set
2397 (add_set_cmd ("target", class_maintenance, var_zinteger,
2398 (char *) &targetdebug,
2399 "Set target debugging.\n\
2400 When non-zero, target debugging is enabled.", &setdebuglist),
2401 &showdebuglist);
2402
2403 add_setshow_boolean_cmd ("trust-readonly-sections", class_support,
2404 &trust_readonly, "\
2405 Set mode for reading from readonly sections.\n\
2406 When this mode is on, memory reads from readonly sections (such as .text)\n\
2407 will be read from the object file instead of from the target. This will\n\
2408 result in significant performance improvement for remote targets.", "\
2409 Show mode for reading from readonly sections.\n",
2410 NULL, NULL,
2411 &setlist, &showlist);
2412
2413 add_com ("monitor", class_obscure, do_monitor_command,
2414 "Send a command to the remote monitor (remote targets only).");
2415
2416 target_dcache = dcache_init ();
2417 }