1 /* Select target systems and architectures at runtime for GDB.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 Free Software Foundation, Inc.
5 Contributed by Cygnus Support.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
26 #include "gdb_string.h"
41 static void target_info (char *, int);
43 static void cleanup_target (struct target_ops *);
45 static void maybe_kill_then_create_inferior (char *, char *, char **);
47 static void default_clone_and_follow_inferior (int, int *);
49 static void maybe_kill_then_attach (char *, int);
51 static void kill_or_be_killed (int);
53 static void default_terminal_info (char *, int);
55 static int default_region_size_ok_for_hw_watchpoint (int);
57 static int nosymbol (char *, CORE_ADDR *);
59 static void tcomplain (void);
61 static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *);
63 static int return_zero (void);
65 static int return_one (void);
67 static int return_minus_one (void);
69 void target_ignore (void);
71 static void target_command (char *, int);
73 static struct target_ops *find_default_run_target (char *);
75 static void update_current_target (void);
77 static void nosupport_runtime (void);
79 static void normal_target_post_startup_inferior (ptid_t ptid);
81 /* Transfer LEN bytes between target address MEMADDR and GDB address
82 MYADDR. Returns 0 for success, errno code for failure (which
83 includes partial transfers -- if you want a more useful response to
84 partial transfers, try either target_read_memory_partial or
85 target_write_memory_partial). */
88 target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write);
90 static void init_dummy_target (void);
92 static void debug_to_open (char *, int);
94 static void debug_to_close (int);
96 static void debug_to_attach (char *, int);
98 static void debug_to_detach (char *, int);
100 static void debug_to_resume (ptid_t, int, enum target_signal);
102 static ptid_t debug_to_wait (ptid_t, struct target_waitstatus *);
104 static void debug_to_fetch_registers (int);
106 static void debug_to_store_registers (int);
108 static void debug_to_prepare_to_store (void);
110 static int debug_to_xfer_memory (CORE_ADDR, char *, int, int,
111 struct mem_attrib *, struct target_ops *);
113 static void debug_to_files_info (struct target_ops *);
115 static int debug_to_insert_breakpoint (CORE_ADDR, char *);
117 static int debug_to_remove_breakpoint (CORE_ADDR, char *);
119 static int debug_to_can_use_hw_breakpoint (int, int, int);
121 static int debug_to_insert_hw_breakpoint (CORE_ADDR, char *);
123 static int debug_to_remove_hw_breakpoint (CORE_ADDR, char *);
125 static int debug_to_insert_watchpoint (CORE_ADDR, int, int);
127 static int debug_to_remove_watchpoint (CORE_ADDR, int, int);
129 static int debug_to_stopped_by_watchpoint (void);
131 static CORE_ADDR debug_to_stopped_data_address (void);
133 static int debug_to_region_size_ok_for_hw_watchpoint (int);
135 static void debug_to_terminal_init (void);
137 static void debug_to_terminal_inferior (void);
139 static void debug_to_terminal_ours_for_output (void);
141 static void debug_to_terminal_save_ours (void);
143 static void debug_to_terminal_ours (void);
145 static void debug_to_terminal_info (char *, int);
147 static void debug_to_kill (void);
149 static void debug_to_load (char *, int);
151 static int debug_to_lookup_symbol (char *, CORE_ADDR *);
153 static void debug_to_create_inferior (char *, char *, char **);
155 static void debug_to_mourn_inferior (void);
157 static int debug_to_can_run (void);
159 static void debug_to_notice_signals (ptid_t);
161 static int debug_to_thread_alive (ptid_t);
163 static void debug_to_stop (void);
165 static int debug_to_query (int /*char */ , char *, char *, int *);
167 /* Pointer to array of target architecture structures; the size of the
168 array; the current index into the array; the allocated size of the
170 struct target_ops **target_structs;
171 unsigned target_struct_size;
172 unsigned target_struct_index;
173 unsigned target_struct_allocsize;
174 #define DEFAULT_ALLOCSIZE 10
176 /* The initial current target, so that there is always a semi-valid
179 static struct target_ops dummy_target;
181 /* Top of target stack. */
183 struct target_stack_item *target_stack;
185 /* The target structure we are currently using to talk to a process
186 or file or whatever "inferior" we have. */
188 struct target_ops current_target;
190 /* Command list for target. */
192 static struct cmd_list_element *targetlist = NULL;
194 /* Nonzero if we are debugging an attached outside process
195 rather than an inferior. */
199 /* Non-zero if we want to see trace of target level stuff. */
201 static int targetdebug = 0;
203 static void setup_target_debug (void);
205 DCACHE *target_dcache;
207 /* The user just typed 'target' without the name of a target. */
211 target_command (char *arg, int from_tty)
213 fputs_filtered ("Argument required (target name). Try `help target'\n",
217 /* Add a possible target architecture to the list. */
220 add_target (struct target_ops *t)
224 target_struct_allocsize = DEFAULT_ALLOCSIZE;
225 target_structs = (struct target_ops **) xmalloc
226 (target_struct_allocsize * sizeof (*target_structs));
228 if (target_struct_size >= target_struct_allocsize)
230 target_struct_allocsize *= 2;
231 target_structs = (struct target_ops **)
232 xrealloc ((char *) target_structs,
233 target_struct_allocsize * sizeof (*target_structs));
235 target_structs[target_struct_size++] = t;
236 /* cleanup_target (t); */
238 if (targetlist == NULL)
239 add_prefix_cmd ("target", class_run, target_command,
240 "Connect to a target machine or process.\n\
241 The first argument is the type or protocol of the target machine.\n\
242 Remaining arguments are interpreted by the target protocol. For more\n\
243 information on the arguments for a particular protocol, type\n\
244 `help target ' followed by the protocol name.",
245 &targetlist, "target ", 0, &cmdlist);
246 add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist);
257 target_load (char *arg, int from_tty)
259 dcache_invalidate (target_dcache);
260 (*current_target.to_load) (arg, from_tty);
265 nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write,
266 struct target_ops *t)
268 errno = EIO; /* Can't read/write this location */
269 return 0; /* No bytes handled */
275 error ("You can't do that when your target is `%s'",
276 current_target.to_shortname);
282 error ("You can't do that without a process to debug.");
287 nosymbol (char *name, CORE_ADDR *addrp)
289 return 1; /* Symbol does not exist in target env */
294 nosupport_runtime (void)
296 if (ptid_equal (inferior_ptid, null_ptid))
299 error ("No run-time support for this");
305 default_terminal_info (char *args, int from_tty)
307 printf_unfiltered ("No saved terminal information.\n");
310 /* This is the default target_create_inferior and target_attach function.
311 If the current target is executing, it asks whether to kill it off.
312 If this function returns without calling error(), it has killed off
313 the target, and the operation should be attempted. */
316 kill_or_be_killed (int from_tty)
318 if (target_has_execution)
320 printf_unfiltered ("You are already running a program:\n");
321 target_files_info ();
322 if (query ("Kill it? "))
325 if (target_has_execution)
326 error ("Killing the program did not help.");
331 error ("Program not killed.");
338 maybe_kill_then_attach (char *args, int from_tty)
340 kill_or_be_killed (from_tty);
341 target_attach (args, from_tty);
345 maybe_kill_then_create_inferior (char *exec, char *args, char **env)
347 kill_or_be_killed (0);
348 target_create_inferior (exec, args, env);
352 default_clone_and_follow_inferior (int child_pid, int *followed_child)
354 target_clone_and_follow_inferior (child_pid, followed_child);
357 /* Clean up a target struct so it no longer has any zero pointers in it.
358 We default entries, at least to stubs that print error messages. */
361 cleanup_target (struct target_ops *t)
364 #define de_fault(field, value) \
369 (void (*) (char *, int))
375 maybe_kill_then_attach);
376 de_fault (to_post_attach,
379 de_fault (to_require_attach,
380 maybe_kill_then_attach);
382 (void (*) (char *, int))
384 de_fault (to_require_detach,
385 (void (*) (int, char *, int))
388 (void (*) (ptid_t, int, enum target_signal))
391 (ptid_t (*) (ptid_t, struct target_waitstatus *))
393 de_fault (to_post_wait,
394 (void (*) (ptid_t, int))
396 de_fault (to_fetch_registers,
399 de_fault (to_store_registers,
402 de_fault (to_prepare_to_store,
405 de_fault (to_xfer_memory,
406 (int (*) (CORE_ADDR, char *, int, int, struct mem_attrib *, struct target_ops *))
408 de_fault (to_files_info,
409 (void (*) (struct target_ops *))
411 de_fault (to_insert_breakpoint,
412 memory_insert_breakpoint);
413 de_fault (to_remove_breakpoint,
414 memory_remove_breakpoint);
415 de_fault (to_can_use_hw_breakpoint,
416 (int (*) (int, int, int))
418 de_fault (to_insert_hw_breakpoint,
419 (int (*) (CORE_ADDR, char *))
421 de_fault (to_remove_hw_breakpoint,
422 (int (*) (CORE_ADDR, char *))
424 de_fault (to_insert_watchpoint,
425 (int (*) (CORE_ADDR, int, int))
427 de_fault (to_remove_watchpoint,
428 (int (*) (CORE_ADDR, int, int))
430 de_fault (to_stopped_by_watchpoint,
433 de_fault (to_stopped_data_address,
434 (CORE_ADDR (*) (void))
436 de_fault (to_region_size_ok_for_hw_watchpoint,
437 default_region_size_ok_for_hw_watchpoint);
438 de_fault (to_terminal_init,
441 de_fault (to_terminal_inferior,
444 de_fault (to_terminal_ours_for_output,
447 de_fault (to_terminal_ours,
450 de_fault (to_terminal_save_ours,
453 de_fault (to_terminal_info,
454 default_terminal_info);
459 (void (*) (char *, int))
461 de_fault (to_lookup_symbol,
462 (int (*) (char *, CORE_ADDR *))
464 de_fault (to_create_inferior,
465 maybe_kill_then_create_inferior);
466 de_fault (to_post_startup_inferior,
469 de_fault (to_acknowledge_created_inferior,
472 de_fault (to_clone_and_follow_inferior,
473 default_clone_and_follow_inferior);
474 de_fault (to_post_follow_inferior_by_clone,
477 de_fault (to_insert_fork_catchpoint,
480 de_fault (to_remove_fork_catchpoint,
483 de_fault (to_insert_vfork_catchpoint,
486 de_fault (to_remove_vfork_catchpoint,
489 de_fault (to_has_forked,
490 (int (*) (int, int *))
492 de_fault (to_has_vforked,
493 (int (*) (int, int *))
495 de_fault (to_can_follow_vfork_prior_to_exec,
498 de_fault (to_post_follow_vfork,
499 (void (*) (int, int, int, int))
501 de_fault (to_insert_exec_catchpoint,
504 de_fault (to_remove_exec_catchpoint,
507 de_fault (to_has_execd,
508 (int (*) (int, char **))
510 de_fault (to_reported_exec_events_per_exec_call,
513 de_fault (to_has_syscall_event,
514 (int (*) (int, enum target_waitkind *, int *))
516 de_fault (to_has_exited,
517 (int (*) (int, int, int *))
519 de_fault (to_mourn_inferior,
522 de_fault (to_can_run,
524 de_fault (to_notice_signals,
527 de_fault (to_thread_alive,
530 de_fault (to_find_new_threads,
533 de_fault (to_extra_thread_info,
534 (char *(*) (struct thread_info *))
540 (void (*) (char *, struct ui_file *))
542 de_fault (to_enable_exception_callback,
543 (struct symtab_and_line * (*) (enum exception_event_kind, int))
545 de_fault (to_get_current_exception_event,
546 (struct exception_event_record * (*) (void))
548 de_fault (to_pid_to_exec_file,
551 de_fault (to_can_async_p,
554 de_fault (to_is_async_p,
558 (void (*) (void (*) (enum inferior_event_type, void*), void*))
563 /* Go through the target stack from top to bottom, copying over zero entries in
564 current_target. In effect, we are doing class inheritance through the
565 pushed target vectors. */
568 update_current_target (void)
570 struct target_stack_item *item;
571 struct target_ops *t;
573 /* First, reset current_target */
574 memset (¤t_target, 0, sizeof current_target);
576 for (item = target_stack; item; item = item->next)
578 t = item->target_ops;
580 #define INHERIT(FIELD, TARGET) \
581 if (!current_target.FIELD) \
582 current_target.FIELD = TARGET->FIELD
584 INHERIT (to_shortname, t);
585 INHERIT (to_longname, t);
587 INHERIT (to_open, t);
588 INHERIT (to_close, t);
589 INHERIT (to_attach, t);
590 INHERIT (to_post_attach, t);
591 INHERIT (to_require_attach, t);
592 INHERIT (to_detach, t);
593 INHERIT (to_require_detach, t);
594 INHERIT (to_resume, t);
595 INHERIT (to_wait, t);
596 INHERIT (to_post_wait, t);
597 INHERIT (to_fetch_registers, t);
598 INHERIT (to_store_registers, t);
599 INHERIT (to_prepare_to_store, t);
600 INHERIT (to_xfer_memory, t);
601 INHERIT (to_files_info, t);
602 INHERIT (to_insert_breakpoint, t);
603 INHERIT (to_remove_breakpoint, t);
604 INHERIT (to_can_use_hw_breakpoint, t);
605 INHERIT (to_insert_hw_breakpoint, t);
606 INHERIT (to_remove_hw_breakpoint, t);
607 INHERIT (to_insert_watchpoint, t);
608 INHERIT (to_remove_watchpoint, t);
609 INHERIT (to_stopped_data_address, t);
610 INHERIT (to_stopped_by_watchpoint, t);
611 INHERIT (to_region_size_ok_for_hw_watchpoint, t);
612 INHERIT (to_terminal_init, t);
613 INHERIT (to_terminal_inferior, t);
614 INHERIT (to_terminal_ours_for_output, t);
615 INHERIT (to_terminal_ours, t);
616 INHERIT (to_terminal_save_ours, t);
617 INHERIT (to_terminal_info, t);
618 INHERIT (to_kill, t);
619 INHERIT (to_load, t);
620 INHERIT (to_lookup_symbol, t);
621 INHERIT (to_create_inferior, t);
622 INHERIT (to_post_startup_inferior, t);
623 INHERIT (to_acknowledge_created_inferior, t);
624 INHERIT (to_clone_and_follow_inferior, t);
625 INHERIT (to_post_follow_inferior_by_clone, t);
626 INHERIT (to_insert_fork_catchpoint, t);
627 INHERIT (to_remove_fork_catchpoint, t);
628 INHERIT (to_insert_vfork_catchpoint, t);
629 INHERIT (to_remove_vfork_catchpoint, t);
630 INHERIT (to_has_forked, t);
631 INHERIT (to_has_vforked, t);
632 INHERIT (to_can_follow_vfork_prior_to_exec, t);
633 INHERIT (to_post_follow_vfork, t);
634 INHERIT (to_insert_exec_catchpoint, t);
635 INHERIT (to_remove_exec_catchpoint, t);
636 INHERIT (to_has_execd, t);
637 INHERIT (to_reported_exec_events_per_exec_call, t);
638 INHERIT (to_has_syscall_event, t);
639 INHERIT (to_has_exited, t);
640 INHERIT (to_mourn_inferior, t);
641 INHERIT (to_can_run, t);
642 INHERIT (to_notice_signals, t);
643 INHERIT (to_thread_alive, t);
644 INHERIT (to_find_new_threads, t);
645 INHERIT (to_pid_to_str, t);
646 INHERIT (to_extra_thread_info, t);
647 INHERIT (to_stop, t);
648 INHERIT (to_query, t);
649 INHERIT (to_rcmd, t);
650 INHERIT (to_enable_exception_callback, t);
651 INHERIT (to_get_current_exception_event, t);
652 INHERIT (to_pid_to_exec_file, t);
653 INHERIT (to_stratum, t);
654 INHERIT (DONT_USE, t);
655 INHERIT (to_has_all_memory, t);
656 INHERIT (to_has_memory, t);
657 INHERIT (to_has_stack, t);
658 INHERIT (to_has_registers, t);
659 INHERIT (to_has_execution, t);
660 INHERIT (to_has_thread_control, t);
661 INHERIT (to_sections, t);
662 INHERIT (to_sections_end, t);
663 INHERIT (to_can_async_p, t);
664 INHERIT (to_is_async_p, t);
665 INHERIT (to_async, t);
666 INHERIT (to_async_mask_value, t);
667 INHERIT (to_find_memory_regions, t);
668 INHERIT (to_make_corefile_notes, t);
669 INHERIT (to_magic, t);
675 /* Push a new target type into the stack of the existing target accessors,
676 possibly superseding some of the existing accessors.
678 Result is zero if the pushed target ended up on top of the stack,
679 nonzero if at least one target is on top of it.
681 Rather than allow an empty stack, we always have the dummy target at
682 the bottom stratum, so we can call the function vectors without
686 push_target (struct target_ops *t)
688 struct target_stack_item *cur, *prev, *tmp;
690 /* Check magic number. If wrong, it probably means someone changed
691 the struct definition, but not all the places that initialize one. */
692 if (t->to_magic != OPS_MAGIC)
694 fprintf_unfiltered (gdb_stderr,
695 "Magic number of %s target struct wrong\n",
697 internal_error (__FILE__, __LINE__, "failed internal consistency check");
700 /* Find the proper stratum to install this target in. */
702 for (prev = NULL, cur = target_stack; cur; prev = cur, cur = cur->next)
704 if ((int) (t->to_stratum) >= (int) (cur->target_ops->to_stratum))
708 /* If there's already targets at this stratum, remove them. */
711 while (t->to_stratum == cur->target_ops->to_stratum)
713 /* There's already something on this stratum. Close it off. */
714 if (cur->target_ops->to_close)
715 (cur->target_ops->to_close) (0);
717 prev->next = cur->next; /* Unchain old target_ops */
719 target_stack = cur->next; /* Unchain first on list */
725 /* We have removed all targets in our stratum, now add the new one. */
727 tmp = (struct target_stack_item *)
728 xmalloc (sizeof (struct target_stack_item));
737 update_current_target ();
739 cleanup_target (¤t_target); /* Fill in the gaps */
742 setup_target_debug ();
747 /* Remove a target_ops vector from the stack, wherever it may be.
748 Return how many times it was removed (0 or 1). */
751 unpush_target (struct target_ops *t)
753 struct target_stack_item *cur, *prev;
756 t->to_close (0); /* Let it clean up */
758 /* Look for the specified target. Note that we assume that a target
759 can only occur once in the target stack. */
761 for (cur = target_stack, prev = NULL; cur; prev = cur, cur = cur->next)
762 if (cur->target_ops == t)
766 return 0; /* Didn't find target_ops, quit now */
768 /* Unchain the target */
771 target_stack = cur->next;
773 prev->next = cur->next;
775 xfree (cur); /* Release the target_stack_item */
777 update_current_target ();
778 cleanup_target (¤t_target);
786 (current_target.to_close) (0); /* Let it clean up */
787 if (unpush_target (target_stack->target_ops) == 1)
790 fprintf_unfiltered (gdb_stderr,
791 "pop_target couldn't find target %s\n",
792 current_target.to_shortname);
793 internal_error (__FILE__, __LINE__, "failed internal consistency check");
797 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
799 /* target_read_string -- read a null terminated string, up to LEN bytes,
800 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
801 Set *STRING to a pointer to malloc'd memory containing the data; the caller
802 is responsible for freeing it. Return the number of bytes successfully
806 target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop)
808 int tlen, origlen, offset, i;
812 int buffer_allocated;
814 unsigned int nbytes_read = 0;
816 /* Small for testing. */
817 buffer_allocated = 4;
818 buffer = xmalloc (buffer_allocated);
825 tlen = MIN (len, 4 - (memaddr & 3));
826 offset = memaddr & 3;
828 errcode = target_xfer_memory (memaddr & ~3, buf, 4, 0);
831 /* The transfer request might have crossed the boundary to an
832 unallocated region of memory. Retry the transfer, requesting
836 errcode = target_xfer_memory (memaddr, buf, 1, 0);
841 if (bufptr - buffer + tlen > buffer_allocated)
844 bytes = bufptr - buffer;
845 buffer_allocated *= 2;
846 buffer = xrealloc (buffer, buffer_allocated);
847 bufptr = buffer + bytes;
850 for (i = 0; i < tlen; i++)
852 *bufptr++ = buf[i + offset];
853 if (buf[i + offset] == '\000')
855 nbytes_read += i + 1;
872 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
873 GDB's memory at MYADDR. Returns either 0 for success or an errno value
876 If an error occurs, no guarantee is made about the contents of the data at
877 MYADDR. In particular, the caller should not depend upon partial reads
878 filling the buffer with good data. There is no way for the caller to know
879 how much good data might have been transfered anyway. Callers that can
880 deal with partial reads should call target_read_memory_partial. */
883 target_read_memory (CORE_ADDR memaddr, char *myaddr, int len)
885 return target_xfer_memory (memaddr, myaddr, len, 0);
889 target_write_memory (CORE_ADDR memaddr, char *myaddr, int len)
891 return target_xfer_memory (memaddr, myaddr, len, 1);
894 static int trust_readonly = 0;
896 /* Move memory to or from the targets. The top target gets priority;
897 if it cannot handle it, it is offered to the next one down, etc.
899 Result is -1 on error, or the number of bytes transfered. */
902 do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
903 struct mem_attrib *attrib)
907 struct target_ops *t;
908 struct target_stack_item *item;
910 /* Zero length requests are ok and require no work. */
914 /* to_xfer_memory is not guaranteed to set errno, even when it returns
918 if (!write && trust_readonly)
920 /* User-settable option, "trust-readonly-sections". If true,
921 then memory from any SEC_READONLY bfd section may be read
922 directly from the bfd file. */
924 struct section_table *secp;
926 for (secp = current_target.to_sections;
927 secp < current_target.to_sections_end;
930 if (bfd_get_section_flags (secp->bfd, secp->the_bfd_section)
932 if (memaddr >= secp->addr && memaddr < secp->endaddr)
933 return xfer_memory (memaddr, myaddr, len, 0,
934 attrib, ¤t_target);
938 /* The quick case is that the top target can handle the transfer. */
939 res = current_target.to_xfer_memory
940 (memaddr, myaddr, len, write, attrib, ¤t_target);
942 /* If res <= 0 then we call it again in the loop. Ah well. */
945 for (item = target_stack; item; item = item->next)
947 t = item->target_ops;
948 if (!t->to_has_memory)
951 res = t->to_xfer_memory (memaddr, myaddr, len, write, attrib, t);
953 break; /* Handled all or part of xfer */
954 if (t->to_has_all_memory)
966 /* Perform a memory transfer. Iterate until the entire region has
969 Result is 0 or errno value. */
972 target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write)
976 struct mem_region *region;
978 /* Zero length requests are ok and require no work. */
986 region = lookup_mem_region(memaddr);
987 if (memaddr + len < region->hi)
990 reg_len = region->hi - memaddr;
992 switch (region->attrib.mode)
1007 if (region->attrib.cache)
1008 res = dcache_xfer_memory (target_dcache, memaddr, myaddr,
1011 res = do_xfer_memory (memaddr, myaddr, reg_len, write,
1016 /* If this address is for nonexistent memory, read zeros
1017 if reading, or do nothing if writing. Return
1020 memset (myaddr, 0, len);
1034 return 0; /* We managed to cover it all somehow. */
1038 /* Perform a partial memory transfer.
1040 Result is -1 on error, or the number of bytes transfered. */
1043 target_xfer_memory_partial (CORE_ADDR memaddr, char *myaddr, int len,
1044 int write_p, int *err)
1048 struct mem_region *region;
1050 /* Zero length requests are ok and require no work. */
1057 region = lookup_mem_region(memaddr);
1058 if (memaddr + len < region->hi)
1061 reg_len = region->hi - memaddr;
1063 switch (region->attrib.mode)
1082 if (region->attrib.cache)
1083 res = dcache_xfer_memory (target_dcache, memaddr, myaddr,
1086 res = do_xfer_memory (memaddr, myaddr, reg_len, write_p,
1104 target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1106 return target_xfer_memory_partial (memaddr, buf, len, 0, err);
1110 target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1112 return target_xfer_memory_partial (memaddr, buf, len, 1, err);
1117 target_info (char *args, int from_tty)
1119 struct target_ops *t;
1120 struct target_stack_item *item;
1121 int has_all_mem = 0;
1123 if (symfile_objfile != NULL)
1124 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile->name);
1126 #ifdef FILES_INFO_HOOK
1127 if (FILES_INFO_HOOK ())
1131 for (item = target_stack; item; item = item->next)
1133 t = item->target_ops;
1135 if (!t->to_has_memory)
1138 if ((int) (t->to_stratum) <= (int) dummy_stratum)
1141 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1142 printf_unfiltered ("%s:\n", t->to_longname);
1143 (t->to_files_info) (t);
1144 has_all_mem = t->to_has_all_memory;
1148 /* This is to be called by the open routine before it does
1152 target_preopen (int from_tty)
1156 if (target_has_execution)
1159 || query ("A program is being debugged already. Kill it? "))
1162 error ("Program not killed.");
1165 /* Calling target_kill may remove the target from the stack. But if
1166 it doesn't (which seems like a win for UDI), remove it now. */
1168 if (target_has_execution)
1172 /* Detach a target after doing deferred register stores. */
1175 target_detach (char *args, int from_tty)
1177 /* Handle any optimized stores to the inferior. */
1178 #ifdef DO_DEFERRED_STORES
1181 (current_target.to_detach) (args, from_tty);
1185 target_link (char *modname, CORE_ADDR *t_reloc)
1187 if (STREQ (current_target.to_shortname, "rombug"))
1189 (current_target.to_lookup_symbol) (modname, t_reloc);
1191 error ("Unable to link to %s and get relocation in rombug", modname);
1194 *t_reloc = (CORE_ADDR) -1;
1198 target_async_mask (int mask)
1200 int saved_async_masked_status = target_async_mask_value;
1201 target_async_mask_value = mask;
1202 return saved_async_masked_status;
1205 /* Look through the list of possible targets for a target that can
1206 execute a run or attach command without any other data. This is
1207 used to locate the default process stratum.
1209 Result is always valid (error() is called for errors). */
1211 static struct target_ops *
1212 find_default_run_target (char *do_mesg)
1214 struct target_ops **t;
1215 struct target_ops *runable = NULL;
1220 for (t = target_structs; t < target_structs + target_struct_size;
1223 if ((*t)->to_can_run && target_can_run (*t))
1231 error ("Don't know how to %s. Try \"help target\".", do_mesg);
1237 find_default_attach (char *args, int from_tty)
1239 struct target_ops *t;
1241 t = find_default_run_target ("attach");
1242 (t->to_attach) (args, from_tty);
1247 find_default_require_attach (char *args, int from_tty)
1249 struct target_ops *t;
1251 t = find_default_run_target ("require_attach");
1252 (t->to_require_attach) (args, from_tty);
1257 find_default_require_detach (int pid, char *args, int from_tty)
1259 struct target_ops *t;
1261 t = find_default_run_target ("require_detach");
1262 (t->to_require_detach) (pid, args, from_tty);
1267 find_default_create_inferior (char *exec_file, char *allargs, char **env)
1269 struct target_ops *t;
1271 t = find_default_run_target ("run");
1272 (t->to_create_inferior) (exec_file, allargs, env);
1277 find_default_clone_and_follow_inferior (int child_pid, int *followed_child)
1279 struct target_ops *t;
1281 t = find_default_run_target ("run");
1282 (t->to_clone_and_follow_inferior) (child_pid, followed_child);
1287 default_region_size_ok_for_hw_watchpoint (int byte_count)
1289 return (byte_count <= REGISTER_SIZE);
1305 return_minus_one (void)
1311 * Resize the to_sections pointer. Also make sure that anyone that
1312 * was holding on to an old value of it gets updated.
1313 * Returns the old size.
1317 target_resize_to_sections (struct target_ops *target, int num_added)
1319 struct target_ops **t;
1320 struct section_table *old_value;
1323 old_value = target->to_sections;
1325 if (target->to_sections)
1327 old_count = target->to_sections_end - target->to_sections;
1328 target->to_sections = (struct section_table *)
1329 xrealloc ((char *) target->to_sections,
1330 (sizeof (struct section_table)) * (num_added + old_count));
1335 target->to_sections = (struct section_table *)
1336 xmalloc ((sizeof (struct section_table)) * num_added);
1338 target->to_sections_end = target->to_sections + (num_added + old_count);
1340 /* Check to see if anyone else was pointing to this structure.
1341 If old_value was null, then no one was. */
1345 for (t = target_structs; t < target_structs + target_struct_size;
1348 if ((*t)->to_sections == old_value)
1350 (*t)->to_sections = target->to_sections;
1351 (*t)->to_sections_end = target->to_sections_end;
1360 /* Remove all target sections taken from ABFD.
1362 Scan the current target stack for targets whose section tables
1363 refer to sections from BFD, and remove those sections. We use this
1364 when we notice that the inferior has unloaded a shared object, for
1367 remove_target_sections (bfd *abfd)
1369 struct target_ops **t;
1371 for (t = target_structs; t < target_structs + target_struct_size; t++)
1373 struct section_table *src, *dest;
1375 dest = (*t)->to_sections;
1376 for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++)
1377 if (src->bfd != abfd)
1379 /* Keep this section. */
1380 if (dest < src) *dest = *src;
1384 /* If we've dropped any sections, resize the section table. */
1386 target_resize_to_sections (*t, dest - src);
1393 /* Find a single runnable target in the stack and return it. If for
1394 some reason there is more than one, return NULL. */
1397 find_run_target (void)
1399 struct target_ops **t;
1400 struct target_ops *runable = NULL;
1405 for (t = target_structs; t < target_structs + target_struct_size; ++t)
1407 if ((*t)->to_can_run && target_can_run (*t))
1414 return (count == 1 ? runable : NULL);
1417 /* Find a single core_stratum target in the list of targets and return it.
1418 If for some reason there is more than one, return NULL. */
1421 find_core_target (void)
1423 struct target_ops **t;
1424 struct target_ops *runable = NULL;
1429 for (t = target_structs; t < target_structs + target_struct_size;
1432 if ((*t)->to_stratum == core_stratum)
1439 return (count == 1 ? runable : NULL);
1443 * Find the next target down the stack from the specified target.
1447 find_target_beneath (struct target_ops *t)
1449 struct target_stack_item *cur;
1451 for (cur = target_stack; cur; cur = cur->next)
1452 if (cur->target_ops == t)
1455 if (cur == NULL || cur->next == NULL)
1458 return cur->next->target_ops;
1462 /* The inferior process has died. Long live the inferior! */
1465 generic_mourn_inferior (void)
1467 extern int show_breakpoint_hit_counts;
1469 inferior_ptid = null_ptid;
1471 breakpoint_init_inferior (inf_exited);
1472 registers_changed ();
1474 #ifdef CLEAR_DEFERRED_STORES
1475 /* Delete any pending stores to the inferior... */
1476 CLEAR_DEFERRED_STORES;
1479 reopen_exec_file ();
1480 reinit_frame_cache ();
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 ();
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. */
1497 store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus)
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))
1506 if (WIFEXITED (hoststatus))
1508 ourstatus->kind = TARGET_WAITKIND_EXITED;
1509 ourstatus->value.integer = WEXITSTATUS (hoststatus);
1511 else if (!WIFSTOPPED (hoststatus))
1513 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
1514 ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus));
1518 ourstatus->kind = TARGET_WAITKIND_STOPPED;
1519 ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus));
1523 /* Returns zero to leave the inferior alone, one to interrupt it. */
1524 int (*target_activity_function) (void);
1525 int target_activity_fd;
1527 /* Convert a normal process ID to a string. Returns the string in a static
1531 normal_pid_to_str (ptid_t ptid)
1533 static char buf[30];
1535 sprintf (buf, "process %d", PIDGET (ptid));
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
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.
1552 normal_target_post_startup_inferior (ptid_t ptid)
1554 /* This space intentionally left blank. */
1557 /* Error-catcher for target_find_memory_regions */
1559 static int dummy_find_memory_regions (int (*ignore1) (), void *ignore2)
1561 error ("No target.");
1565 /* Error-catcher for target_make_corefile_notes */
1567 static char * dummy_make_corefile_notes (bfd *ignore1, int *ignore2)
1569 error ("No target.");
1573 /* Set up the handful of non-empty slots needed by the dummy target
1577 init_dummy_target (void)
1579 dummy_target.to_shortname = "None";
1580 dummy_target.to_longname = "None";
1581 dummy_target.to_doc = "";
1582 dummy_target.to_attach = find_default_attach;
1583 dummy_target.to_require_attach = find_default_require_attach;
1584 dummy_target.to_require_detach = find_default_require_detach;
1585 dummy_target.to_create_inferior = find_default_create_inferior;
1586 dummy_target.to_clone_and_follow_inferior = find_default_clone_and_follow_inferior;
1587 dummy_target.to_pid_to_str = normal_pid_to_str;
1588 dummy_target.to_stratum = dummy_stratum;
1589 dummy_target.to_find_memory_regions = dummy_find_memory_regions;
1590 dummy_target.to_make_corefile_notes = dummy_make_corefile_notes;
1591 dummy_target.to_magic = OPS_MAGIC;
1595 static struct target_ops debug_target;
1598 debug_to_open (char *args, int from_tty)
1600 debug_target.to_open (args, from_tty);
1602 fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty);
1606 debug_to_close (int quitting)
1608 debug_target.to_close (quitting);
1610 fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting);
1614 debug_to_attach (char *args, int from_tty)
1616 debug_target.to_attach (args, from_tty);
1618 fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty);
1623 debug_to_post_attach (int pid)
1625 debug_target.to_post_attach (pid);
1627 fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid);
1631 debug_to_require_attach (char *args, int from_tty)
1633 debug_target.to_require_attach (args, from_tty);
1635 fprintf_unfiltered (gdb_stdlog,
1636 "target_require_attach (%s, %d)\n", args, from_tty);
1640 debug_to_detach (char *args, int from_tty)
1642 debug_target.to_detach (args, from_tty);
1644 fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty);
1648 debug_to_require_detach (int pid, char *args, int from_tty)
1650 debug_target.to_require_detach (pid, args, from_tty);
1652 fprintf_unfiltered (gdb_stdlog,
1653 "target_require_detach (%d, %s, %d)\n", pid, args, from_tty);
1657 debug_to_resume (ptid_t ptid, int step, enum target_signal siggnal)
1659 debug_target.to_resume (ptid, step, siggnal);
1661 fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", PIDGET (ptid),
1662 step ? "step" : "continue",
1663 target_signal_to_name (siggnal));
1667 debug_to_wait (ptid_t ptid, struct target_waitstatus *status)
1671 retval = debug_target.to_wait (ptid, status);
1673 fprintf_unfiltered (gdb_stdlog,
1674 "target_wait (%d, status) = %d, ", PIDGET (ptid),
1676 fprintf_unfiltered (gdb_stdlog, "status->kind = ");
1677 switch (status->kind)
1679 case TARGET_WAITKIND_EXITED:
1680 fprintf_unfiltered (gdb_stdlog, "exited, status = %d\n",
1681 status->value.integer);
1683 case TARGET_WAITKIND_STOPPED:
1684 fprintf_unfiltered (gdb_stdlog, "stopped, signal = %s\n",
1685 target_signal_to_name (status->value.sig));
1687 case TARGET_WAITKIND_SIGNALLED:
1688 fprintf_unfiltered (gdb_stdlog, "signalled, signal = %s\n",
1689 target_signal_to_name (status->value.sig));
1691 case TARGET_WAITKIND_LOADED:
1692 fprintf_unfiltered (gdb_stdlog, "loaded\n");
1694 case TARGET_WAITKIND_FORKED:
1695 fprintf_unfiltered (gdb_stdlog, "forked\n");
1697 case TARGET_WAITKIND_VFORKED:
1698 fprintf_unfiltered (gdb_stdlog, "vforked\n");
1700 case TARGET_WAITKIND_EXECD:
1701 fprintf_unfiltered (gdb_stdlog, "execd\n");
1703 case TARGET_WAITKIND_SPURIOUS:
1704 fprintf_unfiltered (gdb_stdlog, "spurious\n");
1707 fprintf_unfiltered (gdb_stdlog, "unknown???\n");
1715 debug_to_post_wait (ptid_t ptid, int status)
1717 debug_target.to_post_wait (ptid, status);
1719 fprintf_unfiltered (gdb_stdlog, "target_post_wait (%d, %d)\n",
1720 PIDGET (ptid), status);
1724 debug_print_register (const char * func, int regno)
1726 fprintf_unfiltered (gdb_stdlog, "%s ", func);
1727 if (regno >= 0 && regno < NUM_REGS + NUM_PSEUDO_REGS
1728 && REGISTER_NAME (regno) != NULL && REGISTER_NAME (regno)[0] != '\0')
1729 fprintf_unfiltered (gdb_stdlog, "(%s)", REGISTER_NAME (regno));
1731 fprintf_unfiltered (gdb_stdlog, "(%d)", regno);
1735 unsigned char *buf = alloca (MAX_REGISTER_RAW_SIZE);
1736 deprecated_read_register_gen (regno, buf);
1737 fprintf_unfiltered (gdb_stdlog, " = ");
1738 for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
1740 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
1742 if (REGISTER_RAW_SIZE (regno) <= sizeof (LONGEST))
1744 fprintf_unfiltered (gdb_stdlog, " 0x%s %s",
1745 paddr_nz (read_register (regno)),
1746 paddr_d (read_register (regno)));
1749 fprintf_unfiltered (gdb_stdlog, "\n");
1753 debug_to_fetch_registers (int regno)
1755 debug_target.to_fetch_registers (regno);
1756 debug_print_register ("target_fetch_registers", regno);
1760 debug_to_store_registers (int regno)
1762 debug_target.to_store_registers (regno);
1763 debug_print_register ("target_store_registers", regno);
1764 fprintf_unfiltered (gdb_stdlog, "\n");
1768 debug_to_prepare_to_store (void)
1770 debug_target.to_prepare_to_store ();
1772 fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n");
1776 debug_to_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
1777 struct mem_attrib *attrib,
1778 struct target_ops *target)
1782 retval = debug_target.to_xfer_memory (memaddr, myaddr, len, write,
1785 fprintf_unfiltered (gdb_stdlog,
1786 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
1787 (unsigned int) memaddr, /* possable truncate long long */
1788 len, write ? "write" : "read", retval);
1796 fputs_unfiltered (", bytes =", gdb_stdlog);
1797 for (i = 0; i < retval; i++)
1799 if ((((long) &(myaddr[i])) & 0xf) == 0)
1800 fprintf_unfiltered (gdb_stdlog, "\n");
1801 fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff);
1805 fputc_unfiltered ('\n', gdb_stdlog);
1811 debug_to_files_info (struct target_ops *target)
1813 debug_target.to_files_info (target);
1815 fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n");
1819 debug_to_insert_breakpoint (CORE_ADDR addr, char *save)
1823 retval = debug_target.to_insert_breakpoint (addr, save);
1825 fprintf_unfiltered (gdb_stdlog,
1826 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
1827 (unsigned long) addr,
1828 (unsigned long) retval);
1833 debug_to_remove_breakpoint (CORE_ADDR addr, char *save)
1837 retval = debug_target.to_remove_breakpoint (addr, save);
1839 fprintf_unfiltered (gdb_stdlog,
1840 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
1841 (unsigned long) addr,
1842 (unsigned long) retval);
1847 debug_to_can_use_hw_breakpoint (int type, int cnt, int from_tty)
1851 retval = debug_target.to_can_use_hw_breakpoint (type, cnt, from_tty);
1853 fprintf_unfiltered (gdb_stdlog,
1854 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
1855 (unsigned long) type,
1856 (unsigned long) cnt,
1857 (unsigned long) from_tty,
1858 (unsigned long) retval);
1863 debug_to_region_size_ok_for_hw_watchpoint (int byte_count)
1867 retval = debug_target.to_region_size_ok_for_hw_watchpoint (byte_count);
1869 fprintf_unfiltered (gdb_stdlog,
1870 "TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT (%ld) = 0x%lx\n",
1871 (unsigned long) byte_count,
1872 (unsigned long) retval);
1877 debug_to_stopped_by_watchpoint (void)
1881 retval = debug_target.to_stopped_by_watchpoint ();
1883 fprintf_unfiltered (gdb_stdlog,
1884 "STOPPED_BY_WATCHPOINT () = %ld\n",
1885 (unsigned long) retval);
1890 debug_to_stopped_data_address (void)
1894 retval = debug_target.to_stopped_data_address ();
1896 fprintf_unfiltered (gdb_stdlog,
1897 "target_stopped_data_address () = 0x%lx\n",
1898 (unsigned long) retval);
1903 debug_to_insert_hw_breakpoint (CORE_ADDR addr, char *save)
1907 retval = debug_target.to_insert_hw_breakpoint (addr, save);
1909 fprintf_unfiltered (gdb_stdlog,
1910 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
1911 (unsigned long) addr,
1912 (unsigned long) retval);
1917 debug_to_remove_hw_breakpoint (CORE_ADDR addr, char *save)
1921 retval = debug_target.to_remove_hw_breakpoint (addr, save);
1923 fprintf_unfiltered (gdb_stdlog,
1924 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
1925 (unsigned long) addr,
1926 (unsigned long) retval);
1931 debug_to_insert_watchpoint (CORE_ADDR addr, int len, int type)
1935 retval = debug_target.to_insert_watchpoint (addr, len, type);
1937 fprintf_unfiltered (gdb_stdlog,
1938 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1939 (unsigned long) addr, len, type, (unsigned long) retval);
1944 debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type)
1948 retval = debug_target.to_insert_watchpoint (addr, len, type);
1950 fprintf_unfiltered (gdb_stdlog,
1951 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1952 (unsigned long) addr, len, type, (unsigned long) retval);
1957 debug_to_terminal_init (void)
1959 debug_target.to_terminal_init ();
1961 fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n");
1965 debug_to_terminal_inferior (void)
1967 debug_target.to_terminal_inferior ();
1969 fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n");
1973 debug_to_terminal_ours_for_output (void)
1975 debug_target.to_terminal_ours_for_output ();
1977 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n");
1981 debug_to_terminal_ours (void)
1983 debug_target.to_terminal_ours ();
1985 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n");
1989 debug_to_terminal_save_ours (void)
1991 debug_target.to_terminal_save_ours ();
1993 fprintf_unfiltered (gdb_stdlog, "target_terminal_save_ours ()\n");
1997 debug_to_terminal_info (char *arg, int from_tty)
1999 debug_target.to_terminal_info (arg, from_tty);
2001 fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg,
2006 debug_to_kill (void)
2008 debug_target.to_kill ();
2010 fprintf_unfiltered (gdb_stdlog, "target_kill ()\n");
2014 debug_to_load (char *args, int from_tty)
2016 debug_target.to_load (args, from_tty);
2018 fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty);
2022 debug_to_lookup_symbol (char *name, CORE_ADDR *addrp)
2026 retval = debug_target.to_lookup_symbol (name, addrp);
2028 fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name);
2034 debug_to_create_inferior (char *exec_file, char *args, char **env)
2036 debug_target.to_create_inferior (exec_file, args, env);
2038 fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx)\n",
2043 debug_to_post_startup_inferior (ptid_t ptid)
2045 debug_target.to_post_startup_inferior (ptid);
2047 fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n",
2052 debug_to_acknowledge_created_inferior (int pid)
2054 debug_target.to_acknowledge_created_inferior (pid);
2056 fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n",
2061 debug_to_clone_and_follow_inferior (int child_pid, int *followed_child)
2063 debug_target.to_clone_and_follow_inferior (child_pid, followed_child);
2065 fprintf_unfiltered (gdb_stdlog,
2066 "target_clone_and_follow_inferior (%d, %d)\n",
2067 child_pid, *followed_child);
2071 debug_to_post_follow_inferior_by_clone (void)
2073 debug_target.to_post_follow_inferior_by_clone ();
2075 fprintf_unfiltered (gdb_stdlog, "target_post_follow_inferior_by_clone ()\n");
2079 debug_to_insert_fork_catchpoint (int pid)
2083 retval = debug_target.to_insert_fork_catchpoint (pid);
2085 fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d) = %d\n",
2092 debug_to_remove_fork_catchpoint (int pid)
2096 retval = debug_target.to_remove_fork_catchpoint (pid);
2098 fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n",
2105 debug_to_insert_vfork_catchpoint (int pid)
2109 retval = debug_target.to_insert_vfork_catchpoint (pid);
2111 fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)= %d\n",
2118 debug_to_remove_vfork_catchpoint (int pid)
2122 retval = debug_target.to_remove_vfork_catchpoint (pid);
2124 fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n",
2131 debug_to_has_forked (int pid, int *child_pid)
2135 has_forked = debug_target.to_has_forked (pid, child_pid);
2137 fprintf_unfiltered (gdb_stdlog, "target_has_forked (%d, %d) = %d\n",
2138 pid, *child_pid, has_forked);
2144 debug_to_has_vforked (int pid, int *child_pid)
2148 has_vforked = debug_target.to_has_vforked (pid, child_pid);
2150 fprintf_unfiltered (gdb_stdlog, "target_has_vforked (%d, %d) = %d\n",
2151 pid, *child_pid, has_vforked);
2157 debug_to_can_follow_vfork_prior_to_exec (void)
2159 int can_immediately_follow_vfork;
2161 can_immediately_follow_vfork = debug_target.to_can_follow_vfork_prior_to_exec ();
2163 fprintf_unfiltered (gdb_stdlog, "target_can_follow_vfork_prior_to_exec () = %d\n",
2164 can_immediately_follow_vfork);
2166 return can_immediately_follow_vfork;
2170 debug_to_post_follow_vfork (int parent_pid, int followed_parent, int child_pid,
2173 debug_target.to_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child);
2175 fprintf_unfiltered (gdb_stdlog,
2176 "target_post_follow_vfork (%d, %d, %d, %d)\n",
2177 parent_pid, followed_parent, child_pid, followed_child);
2181 debug_to_insert_exec_catchpoint (int pid)
2185 retval = debug_target.to_insert_exec_catchpoint (pid);
2187 fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d) = %d\n",
2194 debug_to_remove_exec_catchpoint (int pid)
2198 retval = debug_target.to_remove_exec_catchpoint (pid);
2200 fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n",
2207 debug_to_has_execd (int pid, char **execd_pathname)
2211 has_execd = debug_target.to_has_execd (pid, execd_pathname);
2213 fprintf_unfiltered (gdb_stdlog, "target_has_execd (%d, %s) = %d\n",
2214 pid, (*execd_pathname ? *execd_pathname : "<NULL>"),
2221 debug_to_reported_exec_events_per_exec_call (void)
2223 int reported_exec_events;
2225 reported_exec_events = debug_target.to_reported_exec_events_per_exec_call ();
2227 fprintf_unfiltered (gdb_stdlog,
2228 "target_reported_exec_events_per_exec_call () = %d\n",
2229 reported_exec_events);
2231 return reported_exec_events;
2235 debug_to_has_syscall_event (int pid, enum target_waitkind *kind,
2238 int has_syscall_event;
2239 char *kind_spelling = "??";
2241 has_syscall_event = debug_target.to_has_syscall_event (pid, kind, syscall_id);
2242 if (has_syscall_event)
2246 case TARGET_WAITKIND_SYSCALL_ENTRY:
2247 kind_spelling = "SYSCALL_ENTRY";
2249 case TARGET_WAITKIND_SYSCALL_RETURN:
2250 kind_spelling = "SYSCALL_RETURN";
2257 fprintf_unfiltered (gdb_stdlog,
2258 "target_has_syscall_event (%d, %s, %d) = %d\n",
2259 pid, kind_spelling, *syscall_id, has_syscall_event);
2261 return has_syscall_event;
2265 debug_to_has_exited (int pid, int wait_status, int *exit_status)
2269 has_exited = debug_target.to_has_exited (pid, wait_status, exit_status);
2271 fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n",
2272 pid, wait_status, *exit_status, has_exited);
2278 debug_to_mourn_inferior (void)
2280 debug_target.to_mourn_inferior ();
2282 fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n");
2286 debug_to_can_run (void)
2290 retval = debug_target.to_can_run ();
2292 fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval);
2298 debug_to_notice_signals (ptid_t ptid)
2300 debug_target.to_notice_signals (ptid);
2302 fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n",
2307 debug_to_thread_alive (ptid_t ptid)
2311 retval = debug_target.to_thread_alive (ptid);
2313 fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n",
2314 PIDGET (ptid), retval);
2320 debug_to_find_new_threads (void)
2322 debug_target.to_find_new_threads ();
2324 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog);
2328 debug_to_stop (void)
2330 debug_target.to_stop ();
2332 fprintf_unfiltered (gdb_stdlog, "target_stop ()\n");
2336 debug_to_query (int type, char *req, char *resp, int *siz)
2340 retval = debug_target.to_query (type, req, resp, siz);
2342 fprintf_unfiltered (gdb_stdlog, "target_query (%c, %s, %s, %d) = %d\n", type, req, resp, *siz, retval);
2348 debug_to_rcmd (char *command,
2349 struct ui_file *outbuf)
2351 debug_target.to_rcmd (command, outbuf);
2352 fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command);
2355 static struct symtab_and_line *
2356 debug_to_enable_exception_callback (enum exception_event_kind kind, int enable)
2358 struct symtab_and_line *result;
2359 result = debug_target.to_enable_exception_callback (kind, enable);
2360 fprintf_unfiltered (gdb_stdlog,
2361 "target get_exception_callback_sal (%d, %d)\n",
2366 static struct exception_event_record *
2367 debug_to_get_current_exception_event (void)
2369 struct exception_event_record *result;
2370 result = debug_target.to_get_current_exception_event ();
2371 fprintf_unfiltered (gdb_stdlog, "target get_current_exception_event ()\n");
2376 debug_to_pid_to_exec_file (int pid)
2380 exec_file = debug_target.to_pid_to_exec_file (pid);
2382 fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n",
2389 setup_target_debug (void)
2391 memcpy (&debug_target, ¤t_target, sizeof debug_target);
2393 current_target.to_open = debug_to_open;
2394 current_target.to_close = debug_to_close;
2395 current_target.to_attach = debug_to_attach;
2396 current_target.to_post_attach = debug_to_post_attach;
2397 current_target.to_require_attach = debug_to_require_attach;
2398 current_target.to_detach = debug_to_detach;
2399 current_target.to_require_detach = debug_to_require_detach;
2400 current_target.to_resume = debug_to_resume;
2401 current_target.to_wait = debug_to_wait;
2402 current_target.to_post_wait = debug_to_post_wait;
2403 current_target.to_fetch_registers = debug_to_fetch_registers;
2404 current_target.to_store_registers = debug_to_store_registers;
2405 current_target.to_prepare_to_store = debug_to_prepare_to_store;
2406 current_target.to_xfer_memory = debug_to_xfer_memory;
2407 current_target.to_files_info = debug_to_files_info;
2408 current_target.to_insert_breakpoint = debug_to_insert_breakpoint;
2409 current_target.to_remove_breakpoint = debug_to_remove_breakpoint;
2410 current_target.to_can_use_hw_breakpoint = debug_to_can_use_hw_breakpoint;
2411 current_target.to_insert_hw_breakpoint = debug_to_insert_hw_breakpoint;
2412 current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint;
2413 current_target.to_insert_watchpoint = debug_to_insert_watchpoint;
2414 current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
2415 current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
2416 current_target.to_stopped_data_address = debug_to_stopped_data_address;
2417 current_target.to_region_size_ok_for_hw_watchpoint = debug_to_region_size_ok_for_hw_watchpoint;
2418 current_target.to_terminal_init = debug_to_terminal_init;
2419 current_target.to_terminal_inferior = debug_to_terminal_inferior;
2420 current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output;
2421 current_target.to_terminal_ours = debug_to_terminal_ours;
2422 current_target.to_terminal_save_ours = debug_to_terminal_save_ours;
2423 current_target.to_terminal_info = debug_to_terminal_info;
2424 current_target.to_kill = debug_to_kill;
2425 current_target.to_load = debug_to_load;
2426 current_target.to_lookup_symbol = debug_to_lookup_symbol;
2427 current_target.to_create_inferior = debug_to_create_inferior;
2428 current_target.to_post_startup_inferior = debug_to_post_startup_inferior;
2429 current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior;
2430 current_target.to_clone_and_follow_inferior = debug_to_clone_and_follow_inferior;
2431 current_target.to_post_follow_inferior_by_clone = debug_to_post_follow_inferior_by_clone;
2432 current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint;
2433 current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
2434 current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
2435 current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint;
2436 current_target.to_has_forked = debug_to_has_forked;
2437 current_target.to_has_vforked = debug_to_has_vforked;
2438 current_target.to_can_follow_vfork_prior_to_exec = debug_to_can_follow_vfork_prior_to_exec;
2439 current_target.to_post_follow_vfork = debug_to_post_follow_vfork;
2440 current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint;
2441 current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
2442 current_target.to_has_execd = debug_to_has_execd;
2443 current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call;
2444 current_target.to_has_syscall_event = debug_to_has_syscall_event;
2445 current_target.to_has_exited = debug_to_has_exited;
2446 current_target.to_mourn_inferior = debug_to_mourn_inferior;
2447 current_target.to_can_run = debug_to_can_run;
2448 current_target.to_notice_signals = debug_to_notice_signals;
2449 current_target.to_thread_alive = debug_to_thread_alive;
2450 current_target.to_find_new_threads = debug_to_find_new_threads;
2451 current_target.to_stop = debug_to_stop;
2452 current_target.to_query = debug_to_query;
2453 current_target.to_rcmd = debug_to_rcmd;
2454 current_target.to_enable_exception_callback = debug_to_enable_exception_callback;
2455 current_target.to_get_current_exception_event = debug_to_get_current_exception_event;
2456 current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
2461 static char targ_desc[] =
2462 "Names of targets and files being debugged.\n\
2463 Shows the entire stack of targets currently in use (including the exec-file,\n\
2464 core-file, and process, if any), as well as the symbol file name.";
2467 do_monitor_command (char *cmd,
2470 if ((current_target.to_rcmd
2471 == (void (*) (char *, struct ui_file *)) tcomplain)
2472 || (current_target.to_rcmd == debug_to_rcmd
2473 && (debug_target.to_rcmd
2474 == (void (*) (char *, struct ui_file *)) tcomplain)))
2476 error ("\"monitor\" command not supported by this target.\n");
2478 target_rcmd (cmd, gdb_stdtarg);
2482 initialize_targets (void)
2484 init_dummy_target ();
2485 push_target (&dummy_target);
2487 add_info ("target", target_info, targ_desc);
2488 add_info ("files", target_info, targ_desc);
2491 (add_set_cmd ("target", class_maintenance, var_zinteger,
2492 (char *) &targetdebug,
2493 "Set target debugging.\n\
2494 When non-zero, target debugging is enabled.", &setdebuglist),
2497 add_setshow_boolean_cmd ("trust-readonly-sections", class_support,
2499 Set mode for reading from readonly sections.\n\
2500 When this mode is on, memory reads from readonly sections (such as .text)\n\
2501 will be read from the object file instead of from the target. This will\n\
2502 result in significant performance improvement for remote targets.", "\
2503 Show mode for reading from readonly sections.\n",
2505 &setlist, &showlist);
2507 add_com ("monitor", class_obscure, do_monitor_command,
2508 "Send a command to the remote monitor (remote targets only).");
2510 target_dcache = dcache_init ();