1 /* Select target systems and architectures at runtime for GDB.
2 Copyright 1990, 1992-1995, 1998-2000, 2001 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include "gdb_string.h"
39 static void target_info (char *, int);
41 static void cleanup_target (struct target_ops *);
43 static void maybe_kill_then_create_inferior (char *, char *, char **);
45 static void default_clone_and_follow_inferior (int, int *);
47 static void maybe_kill_then_attach (char *, int);
49 static void kill_or_be_killed (int);
51 static void default_terminal_info (char *, int);
53 static int nosymbol (char *, CORE_ADDR *);
55 static void tcomplain (void);
57 static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *);
59 static int return_zero (void);
61 static int return_one (void);
63 void target_ignore (void);
65 static void target_command (char *, int);
67 static struct target_ops *find_default_run_target (char *);
69 static void update_current_target (void);
71 static void nosupport_runtime (void);
73 static void normal_target_post_startup_inferior (int pid);
75 /* Transfer LEN bytes between target address MEMADDR and GDB address
76 MYADDR. Returns 0 for success, errno code for failure (which
77 includes partial transfers -- if you want a more useful response to
78 partial transfers, try either target_read_memory_partial or
79 target_write_memory_partial). */
82 target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write);
84 static void init_dummy_target (void);
86 static void debug_to_open (char *, int);
88 static void debug_to_close (int);
90 static void debug_to_attach (char *, int);
92 static void debug_to_detach (char *, int);
94 static void debug_to_resume (int, int, enum target_signal);
96 static int debug_to_wait (int, struct target_waitstatus *);
98 static void debug_to_fetch_registers (int);
100 static void debug_to_store_registers (int);
102 static void debug_to_prepare_to_store (void);
105 debug_to_xfer_memory (CORE_ADDR, char *, int, int, struct mem_attrib *,
106 struct target_ops *);
108 static void debug_to_files_info (struct target_ops *);
110 static int debug_to_insert_breakpoint (CORE_ADDR, char *);
112 static int debug_to_remove_breakpoint (CORE_ADDR, char *);
114 static void debug_to_terminal_init (void);
116 static void debug_to_terminal_inferior (void);
118 static void debug_to_terminal_ours_for_output (void);
120 static void debug_to_terminal_ours (void);
122 static void debug_to_terminal_info (char *, int);
124 static void debug_to_kill (void);
126 static void debug_to_load (char *, int);
128 static int debug_to_lookup_symbol (char *, CORE_ADDR *);
130 static void debug_to_create_inferior (char *, char *, char **);
132 static void debug_to_mourn_inferior (void);
134 static int debug_to_can_run (void);
136 static void debug_to_notice_signals (int);
138 static int debug_to_thread_alive (int);
140 static void debug_to_stop (void);
142 static int debug_to_query (int /*char */ , char *, char *, int *);
144 /* Pointer to array of target architecture structures; the size of the
145 array; the current index into the array; the allocated size of the
147 struct target_ops **target_structs;
148 unsigned target_struct_size;
149 unsigned target_struct_index;
150 unsigned target_struct_allocsize;
151 #define DEFAULT_ALLOCSIZE 10
153 /* The initial current target, so that there is always a semi-valid
156 static struct target_ops dummy_target;
158 /* Top of target stack. */
160 struct target_stack_item *target_stack;
162 /* The target structure we are currently using to talk to a process
163 or file or whatever "inferior" we have. */
165 struct target_ops current_target;
167 /* Command list for target. */
169 static struct cmd_list_element *targetlist = NULL;
171 /* Nonzero if we are debugging an attached outside process
172 rather than an inferior. */
176 /* Non-zero if we want to see trace of target level stuff. */
178 static int targetdebug = 0;
180 static void setup_target_debug (void);
182 DCACHE *target_dcache;
184 /* The user just typed 'target' without the name of a target. */
188 target_command (char *arg, int from_tty)
190 fputs_filtered ("Argument required (target name). Try `help target'\n",
194 /* Add a possible target architecture to the list. */
197 add_target (struct target_ops *t)
201 target_struct_allocsize = DEFAULT_ALLOCSIZE;
202 target_structs = (struct target_ops **) xmalloc
203 (target_struct_allocsize * sizeof (*target_structs));
205 if (target_struct_size >= target_struct_allocsize)
207 target_struct_allocsize *= 2;
208 target_structs = (struct target_ops **)
209 xrealloc ((char *) target_structs,
210 target_struct_allocsize * sizeof (*target_structs));
212 target_structs[target_struct_size++] = t;
213 /* cleanup_target (t); */
215 if (targetlist == NULL)
216 add_prefix_cmd ("target", class_run, target_command,
217 "Connect to a target machine or process.\n\
218 The first argument is the type or protocol of the target machine.\n\
219 Remaining arguments are interpreted by the target protocol. For more\n\
220 information on the arguments for a particular protocol, type\n\
221 `help target ' followed by the protocol name.",
222 &targetlist, "target ", 0, &cmdlist);
223 add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist);
234 target_load (char *arg, int from_tty)
236 dcache_invalidate (target_dcache);
237 (*current_target.to_load) (arg, from_tty);
242 nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write,
243 struct target_ops *t)
245 errno = EIO; /* Can't read/write this location */
246 return 0; /* No bytes handled */
252 error ("You can't do that when your target is `%s'",
253 current_target.to_shortname);
259 error ("You can't do that without a process to debug.");
264 nosymbol (char *name, CORE_ADDR *addrp)
266 return 1; /* Symbol does not exist in target env */
271 nosupport_runtime (void)
276 error ("No run-time support for this");
282 default_terminal_info (char *args, int from_tty)
284 printf_unfiltered ("No saved terminal information.\n");
287 /* This is the default target_create_inferior and target_attach function.
288 If the current target is executing, it asks whether to kill it off.
289 If this function returns without calling error(), it has killed off
290 the target, and the operation should be attempted. */
293 kill_or_be_killed (int from_tty)
295 if (target_has_execution)
297 printf_unfiltered ("You are already running a program:\n");
298 target_files_info ();
299 if (query ("Kill it? "))
302 if (target_has_execution)
303 error ("Killing the program did not help.");
308 error ("Program not killed.");
315 maybe_kill_then_attach (char *args, int from_tty)
317 kill_or_be_killed (from_tty);
318 target_attach (args, from_tty);
322 maybe_kill_then_create_inferior (char *exec, char *args, char **env)
324 kill_or_be_killed (0);
325 target_create_inferior (exec, args, env);
329 default_clone_and_follow_inferior (int child_pid, int *followed_child)
331 target_clone_and_follow_inferior (child_pid, followed_child);
334 /* Clean up a target struct so it no longer has any zero pointers in it.
335 We default entries, at least to stubs that print error messages. */
338 cleanup_target (struct target_ops *t)
341 #define de_fault(field, value) \
346 (void (*) (char *, int))
352 maybe_kill_then_attach);
353 de_fault (to_post_attach,
356 de_fault (to_require_attach,
357 maybe_kill_then_attach);
359 (void (*) (char *, int))
361 de_fault (to_require_detach,
362 (void (*) (int, char *, int))
365 (void (*) (int, int, enum target_signal))
368 (int (*) (int, struct target_waitstatus *))
370 de_fault (to_post_wait,
371 (void (*) (int, int))
373 de_fault (to_fetch_registers,
376 de_fault (to_store_registers,
379 de_fault (to_prepare_to_store,
382 de_fault (to_xfer_memory,
383 (int (*) (CORE_ADDR, char *, int, int, struct mem_attrib *, struct target_ops *))
385 de_fault (to_files_info,
386 (void (*) (struct target_ops *))
388 de_fault (to_insert_breakpoint,
389 memory_insert_breakpoint);
390 de_fault (to_remove_breakpoint,
391 memory_remove_breakpoint);
392 de_fault (to_terminal_init,
395 de_fault (to_terminal_inferior,
398 de_fault (to_terminal_ours_for_output,
401 de_fault (to_terminal_ours,
404 de_fault (to_terminal_info,
405 default_terminal_info);
410 (void (*) (char *, int))
412 de_fault (to_lookup_symbol,
413 (int (*) (char *, CORE_ADDR *))
415 de_fault (to_create_inferior,
416 maybe_kill_then_create_inferior);
417 de_fault (to_post_startup_inferior,
420 de_fault (to_acknowledge_created_inferior,
423 de_fault (to_clone_and_follow_inferior,
424 default_clone_and_follow_inferior);
425 de_fault (to_post_follow_inferior_by_clone,
428 de_fault (to_insert_fork_catchpoint,
431 de_fault (to_remove_fork_catchpoint,
434 de_fault (to_insert_vfork_catchpoint,
437 de_fault (to_remove_vfork_catchpoint,
440 de_fault (to_has_forked,
441 (int (*) (int, int *))
443 de_fault (to_has_vforked,
444 (int (*) (int, int *))
446 de_fault (to_can_follow_vfork_prior_to_exec,
449 de_fault (to_post_follow_vfork,
450 (void (*) (int, int, int, int))
452 de_fault (to_insert_exec_catchpoint,
455 de_fault (to_remove_exec_catchpoint,
458 de_fault (to_has_execd,
459 (int (*) (int, char **))
461 de_fault (to_reported_exec_events_per_exec_call,
464 de_fault (to_has_syscall_event,
465 (int (*) (int, enum target_waitkind *, int *))
467 de_fault (to_has_exited,
468 (int (*) (int, int, int *))
470 de_fault (to_mourn_inferior,
473 de_fault (to_can_run,
475 de_fault (to_notice_signals,
478 de_fault (to_thread_alive,
481 de_fault (to_find_new_threads,
484 de_fault (to_extra_thread_info,
485 (char *(*) (struct thread_info *))
491 (int (*) (int, char *, char *, int *))
494 (void (*) (char *, struct ui_file *))
496 de_fault (to_enable_exception_callback,
497 (struct symtab_and_line * (*) (enum exception_event_kind, int))
499 de_fault (to_get_current_exception_event,
500 (struct exception_event_record * (*) (void))
502 de_fault (to_pid_to_exec_file,
505 de_fault (to_core_file_to_sym_file,
508 de_fault (to_can_async_p,
511 de_fault (to_is_async_p,
515 (void (*) (void (*) (enum inferior_event_type, void*), void*))
520 /* Go through the target stack from top to bottom, copying over zero entries in
521 current_target. In effect, we are doing class inheritance through the
522 pushed target vectors. */
525 update_current_target (void)
527 struct target_stack_item *item;
528 struct target_ops *t;
530 /* First, reset current_target */
531 memset (¤t_target, 0, sizeof current_target);
533 for (item = target_stack; item; item = item->next)
535 t = item->target_ops;
537 #define INHERIT(FIELD, TARGET) \
538 if (!current_target.FIELD) \
539 current_target.FIELD = TARGET->FIELD
541 INHERIT (to_shortname, t);
542 INHERIT (to_longname, t);
544 INHERIT (to_open, t);
545 INHERIT (to_close, t);
546 INHERIT (to_attach, t);
547 INHERIT (to_post_attach, t);
548 INHERIT (to_require_attach, t);
549 INHERIT (to_detach, t);
550 INHERIT (to_require_detach, t);
551 INHERIT (to_resume, t);
552 INHERIT (to_wait, t);
553 INHERIT (to_post_wait, t);
554 INHERIT (to_fetch_registers, t);
555 INHERIT (to_store_registers, t);
556 INHERIT (to_prepare_to_store, t);
557 INHERIT (to_xfer_memory, t);
558 INHERIT (to_files_info, t);
559 INHERIT (to_insert_breakpoint, t);
560 INHERIT (to_remove_breakpoint, t);
561 INHERIT (to_terminal_init, t);
562 INHERIT (to_terminal_inferior, t);
563 INHERIT (to_terminal_ours_for_output, t);
564 INHERIT (to_terminal_ours, t);
565 INHERIT (to_terminal_info, t);
566 INHERIT (to_kill, t);
567 INHERIT (to_load, t);
568 INHERIT (to_lookup_symbol, t);
569 INHERIT (to_create_inferior, t);
570 INHERIT (to_post_startup_inferior, t);
571 INHERIT (to_acknowledge_created_inferior, t);
572 INHERIT (to_clone_and_follow_inferior, t);
573 INHERIT (to_post_follow_inferior_by_clone, t);
574 INHERIT (to_insert_fork_catchpoint, t);
575 INHERIT (to_remove_fork_catchpoint, t);
576 INHERIT (to_insert_vfork_catchpoint, t);
577 INHERIT (to_remove_vfork_catchpoint, t);
578 INHERIT (to_has_forked, t);
579 INHERIT (to_has_vforked, t);
580 INHERIT (to_can_follow_vfork_prior_to_exec, t);
581 INHERIT (to_post_follow_vfork, t);
582 INHERIT (to_insert_exec_catchpoint, t);
583 INHERIT (to_remove_exec_catchpoint, t);
584 INHERIT (to_has_execd, t);
585 INHERIT (to_reported_exec_events_per_exec_call, t);
586 INHERIT (to_has_syscall_event, t);
587 INHERIT (to_has_exited, t);
588 INHERIT (to_mourn_inferior, t);
589 INHERIT (to_can_run, t);
590 INHERIT (to_notice_signals, t);
591 INHERIT (to_thread_alive, t);
592 INHERIT (to_find_new_threads, t);
593 INHERIT (to_pid_to_str, t);
594 INHERIT (to_extra_thread_info, t);
595 INHERIT (to_stop, t);
596 INHERIT (to_query, t);
597 INHERIT (to_rcmd, t);
598 INHERIT (to_enable_exception_callback, t);
599 INHERIT (to_get_current_exception_event, t);
600 INHERIT (to_pid_to_exec_file, t);
601 INHERIT (to_core_file_to_sym_file, t);
602 INHERIT (to_stratum, t);
603 INHERIT (DONT_USE, t);
604 INHERIT (to_has_all_memory, t);
605 INHERIT (to_has_memory, t);
606 INHERIT (to_has_stack, t);
607 INHERIT (to_has_registers, t);
608 INHERIT (to_has_execution, t);
609 INHERIT (to_has_thread_control, t);
610 INHERIT (to_sections, t);
611 INHERIT (to_sections_end, t);
612 INHERIT (to_can_async_p, t);
613 INHERIT (to_is_async_p, t);
614 INHERIT (to_async, t);
615 INHERIT (to_async_mask_value, t);
616 INHERIT (to_magic, t);
622 /* Push a new target type into the stack of the existing target accessors,
623 possibly superseding some of the existing accessors.
625 Result is zero if the pushed target ended up on top of the stack,
626 nonzero if at least one target is on top of it.
628 Rather than allow an empty stack, we always have the dummy target at
629 the bottom stratum, so we can call the function vectors without
633 push_target (struct target_ops *t)
635 struct target_stack_item *cur, *prev, *tmp;
637 /* Check magic number. If wrong, it probably means someone changed
638 the struct definition, but not all the places that initialize one. */
639 if (t->to_magic != OPS_MAGIC)
641 fprintf_unfiltered (gdb_stderr,
642 "Magic number of %s target struct wrong\n",
647 /* Find the proper stratum to install this target in. */
649 for (prev = NULL, cur = target_stack; cur; prev = cur, cur = cur->next)
651 if ((int) (t->to_stratum) >= (int) (cur->target_ops->to_stratum))
655 /* If there's already targets at this stratum, remove them. */
658 while (t->to_stratum == cur->target_ops->to_stratum)
660 /* There's already something on this stratum. Close it off. */
661 if (cur->target_ops->to_close)
662 (cur->target_ops->to_close) (0);
664 prev->next = cur->next; /* Unchain old target_ops */
666 target_stack = cur->next; /* Unchain first on list */
672 /* We have removed all targets in our stratum, now add the new one. */
674 tmp = (struct target_stack_item *)
675 xmalloc (sizeof (struct target_stack_item));
684 update_current_target ();
686 cleanup_target (¤t_target); /* Fill in the gaps */
689 setup_target_debug ();
694 /* Remove a target_ops vector from the stack, wherever it may be.
695 Return how many times it was removed (0 or 1). */
698 unpush_target (struct target_ops *t)
700 struct target_stack_item *cur, *prev;
703 t->to_close (0); /* Let it clean up */
705 /* Look for the specified target. Note that we assume that a target
706 can only occur once in the target stack. */
708 for (cur = target_stack, prev = NULL; cur; prev = cur, cur = cur->next)
709 if (cur->target_ops == t)
713 return 0; /* Didn't find target_ops, quit now */
715 /* Unchain the target */
718 target_stack = cur->next;
720 prev->next = cur->next;
722 xfree (cur); /* Release the target_stack_item */
724 update_current_target ();
725 cleanup_target (¤t_target);
733 (current_target.to_close) (0); /* Let it clean up */
734 if (unpush_target (target_stack->target_ops) == 1)
737 fprintf_unfiltered (gdb_stderr,
738 "pop_target couldn't find target %s\n",
739 current_target.to_shortname);
744 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
746 /* target_read_string -- read a null terminated string, up to LEN bytes,
747 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
748 Set *STRING to a pointer to malloc'd memory containing the data; the caller
749 is responsible for freeing it. Return the number of bytes successfully
753 target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop)
755 int tlen, origlen, offset, i;
759 int buffer_allocated;
761 unsigned int nbytes_read = 0;
763 /* Small for testing. */
764 buffer_allocated = 4;
765 buffer = xmalloc (buffer_allocated);
772 tlen = MIN (len, 4 - (memaddr & 3));
773 offset = memaddr & 3;
775 errcode = target_xfer_memory (memaddr & ~3, buf, 4, 0);
778 /* The transfer request might have crossed the boundary to an
779 unallocated region of memory. Retry the transfer, requesting
783 errcode = target_xfer_memory (memaddr, buf, 1, 0);
788 if (bufptr - buffer + tlen > buffer_allocated)
791 bytes = bufptr - buffer;
792 buffer_allocated *= 2;
793 buffer = xrealloc (buffer, buffer_allocated);
794 bufptr = buffer + bytes;
797 for (i = 0; i < tlen; i++)
799 *bufptr++ = buf[i + offset];
800 if (buf[i + offset] == '\000')
802 nbytes_read += i + 1;
819 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
820 GDB's memory at MYADDR. Returns either 0 for success or an errno value
823 If an error occurs, no guarantee is made about the contents of the data at
824 MYADDR. In particular, the caller should not depend upon partial reads
825 filling the buffer with good data. There is no way for the caller to know
826 how much good data might have been transfered anyway. Callers that can
827 deal with partial reads should call target_read_memory_partial. */
830 target_read_memory (CORE_ADDR memaddr, char *myaddr, int len)
832 return target_xfer_memory (memaddr, myaddr, len, 0);
836 target_write_memory (CORE_ADDR memaddr, char *myaddr, int len)
838 return target_xfer_memory (memaddr, myaddr, len, 1);
841 /* Move memory to or from the targets. The top target gets priority;
842 if it cannot handle it, it is offered to the next one down, etc.
844 Result is -1 on error, or the number of bytes transfered. */
847 do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
848 struct mem_attrib *attrib)
852 struct target_ops *t;
853 struct target_stack_item *item;
855 /* Zero length requests are ok and require no work. */
859 /* to_xfer_memory is not guaranteed to set errno, even when it returns
863 /* The quick case is that the top target can handle the transfer. */
864 res = current_target.to_xfer_memory
865 (memaddr, myaddr, len, write, attrib, ¤t_target);
867 /* If res <= 0 then we call it again in the loop. Ah well. */
870 for (item = target_stack; item; item = item->next)
872 t = item->target_ops;
873 if (!t->to_has_memory)
876 res = t->to_xfer_memory (memaddr, myaddr, len, write, attrib, t);
878 break; /* Handled all or part of xfer */
879 if (t->to_has_all_memory)
891 /* Perform a memory transfer. Iterate until the entire region has
894 Result is 0 or errno value. */
897 target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write)
901 struct mem_region *region;
903 /* Zero length requests are ok and require no work. */
911 region = lookup_mem_region(memaddr);
912 if (memaddr + len < region->hi)
915 reg_len = region->hi - memaddr;
917 switch (region->attrib.mode)
932 if (region->attrib.cache)
933 res = dcache_xfer_memory(target_dcache, memaddr, myaddr,
936 res = do_xfer_memory(memaddr, myaddr, reg_len, write,
941 /* If this address is for nonexistent memory, read zeros
942 if reading, or do nothing if writing. Return
945 memset (myaddr, 0, len);
959 return 0; /* We managed to cover it all somehow. */
963 /* Perform a partial memory transfer.
965 Result is -1 on error, or the number of bytes transfered. */
968 target_xfer_memory_partial (CORE_ADDR memaddr, char *myaddr, int len,
969 int write_p, int *err)
973 struct mem_region *region;
975 /* Zero length requests are ok and require no work. */
982 region = lookup_mem_region(memaddr);
983 if (memaddr + len < region->hi)
986 reg_len = region->hi - memaddr;
988 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_p,
1029 target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1031 return target_xfer_memory_partial (memaddr, buf, len, 0, err);
1035 target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1037 return target_xfer_memory_partial (memaddr, buf, len, 1, err);
1042 target_info (char *args, int from_tty)
1044 struct target_ops *t;
1045 struct target_stack_item *item;
1046 int has_all_mem = 0;
1048 if (symfile_objfile != NULL)
1049 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile->name);
1051 #ifdef FILES_INFO_HOOK
1052 if (FILES_INFO_HOOK ())
1056 for (item = target_stack; item; item = item->next)
1058 t = item->target_ops;
1060 if (!t->to_has_memory)
1063 if ((int) (t->to_stratum) <= (int) dummy_stratum)
1066 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1067 printf_unfiltered ("%s:\n", t->to_longname);
1068 (t->to_files_info) (t);
1069 has_all_mem = t->to_has_all_memory;
1073 /* This is to be called by the open routine before it does
1077 target_preopen (int from_tty)
1081 if (target_has_execution)
1084 || query ("A program is being debugged already. Kill it? "))
1087 error ("Program not killed.");
1090 /* Calling target_kill may remove the target from the stack. But if
1091 it doesn't (which seems like a win for UDI), remove it now. */
1093 if (target_has_execution)
1097 /* Detach a target after doing deferred register stores. */
1100 target_detach (char *args, int from_tty)
1102 /* Handle any optimized stores to the inferior. */
1103 #ifdef DO_DEFERRED_STORES
1106 (current_target.to_detach) (args, from_tty);
1110 target_link (char *modname, CORE_ADDR *t_reloc)
1112 if (STREQ (current_target.to_shortname, "rombug"))
1114 (current_target.to_lookup_symbol) (modname, t_reloc);
1116 error ("Unable to link to %s and get relocation in rombug", modname);
1119 *t_reloc = (CORE_ADDR) -1;
1123 target_async_mask (int mask)
1125 int saved_async_masked_status = target_async_mask_value;
1126 target_async_mask_value = mask;
1127 return saved_async_masked_status;
1130 /* Look through the list of possible targets for a target that can
1131 execute a run or attach command without any other data. This is
1132 used to locate the default process stratum.
1134 Result is always valid (error() is called for errors). */
1136 static struct target_ops *
1137 find_default_run_target (char *do_mesg)
1139 struct target_ops **t;
1140 struct target_ops *runable = NULL;
1145 for (t = target_structs; t < target_structs + target_struct_size;
1148 if ((*t)->to_can_run && target_can_run (*t))
1156 error ("Don't know how to %s. Try \"help target\".", do_mesg);
1162 find_default_attach (char *args, int from_tty)
1164 struct target_ops *t;
1166 t = find_default_run_target ("attach");
1167 (t->to_attach) (args, from_tty);
1172 find_default_require_attach (char *args, int from_tty)
1174 struct target_ops *t;
1176 t = find_default_run_target ("require_attach");
1177 (t->to_require_attach) (args, from_tty);
1182 find_default_require_detach (int pid, char *args, int from_tty)
1184 struct target_ops *t;
1186 t = find_default_run_target ("require_detach");
1187 (t->to_require_detach) (pid, args, from_tty);
1192 find_default_create_inferior (char *exec_file, char *allargs, char **env)
1194 struct target_ops *t;
1196 t = find_default_run_target ("run");
1197 (t->to_create_inferior) (exec_file, allargs, env);
1202 find_default_clone_and_follow_inferior (int child_pid, int *followed_child)
1204 struct target_ops *t;
1206 t = find_default_run_target ("run");
1207 (t->to_clone_and_follow_inferior) (child_pid, followed_child);
1224 * Resize the to_sections pointer. Also make sure that anyone that
1225 * was holding on to an old value of it gets updated.
1226 * Returns the old size.
1230 target_resize_to_sections (struct target_ops *target, int num_added)
1232 struct target_ops **t;
1233 struct section_table *old_value;
1236 old_value = target->to_sections;
1238 if (target->to_sections)
1240 old_count = target->to_sections_end - target->to_sections;
1241 target->to_sections = (struct section_table *)
1242 xrealloc ((char *) target->to_sections,
1243 (sizeof (struct section_table)) * (num_added + old_count));
1248 target->to_sections = (struct section_table *)
1249 xmalloc ((sizeof (struct section_table)) * num_added);
1251 target->to_sections_end = target->to_sections + (num_added + old_count);
1253 /* Check to see if anyone else was pointing to this structure.
1254 If old_value was null, then no one was. */
1258 for (t = target_structs; t < target_structs + target_struct_size;
1261 if ((*t)->to_sections == old_value)
1263 (*t)->to_sections = target->to_sections;
1264 (*t)->to_sections_end = target->to_sections_end;
1273 /* Remove all target sections taken from ABFD.
1275 Scan the current target stack for targets whose section tables
1276 refer to sections from BFD, and remove those sections. We use this
1277 when we notice that the inferior has unloaded a shared object, for
1280 remove_target_sections (bfd *abfd)
1282 struct target_ops **t;
1284 for (t = target_structs; t < target_structs + target_struct_size; t++)
1286 struct section_table *src, *dest;
1288 dest = (*t)->to_sections;
1289 for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++)
1290 if (src->bfd != abfd)
1292 /* Keep this section. */
1293 if (dest < src) *dest = *src;
1297 /* If we've dropped any sections, resize the section table. */
1299 target_resize_to_sections (*t, dest - src);
1306 /* Find a single runnable target in the stack and return it. If for
1307 some reason there is more than one, return NULL. */
1310 find_run_target (void)
1312 struct target_ops **t;
1313 struct target_ops *runable = NULL;
1318 for (t = target_structs; t < target_structs + target_struct_size; ++t)
1320 if ((*t)->to_can_run && target_can_run (*t))
1327 return (count == 1 ? runable : NULL);
1330 /* Find a single core_stratum target in the list of targets and return it.
1331 If for some reason there is more than one, return NULL. */
1334 find_core_target (void)
1336 struct target_ops **t;
1337 struct target_ops *runable = NULL;
1342 for (t = target_structs; t < target_structs + target_struct_size;
1345 if ((*t)->to_stratum == core_stratum)
1352 return (count == 1 ? runable : NULL);
1356 * Find the next target down the stack from the specified target.
1360 find_target_beneath (struct target_ops *t)
1362 struct target_stack_item *cur;
1364 for (cur = target_stack; cur; cur = cur->next)
1365 if (cur->target_ops == t)
1368 if (cur == NULL || cur->next == NULL)
1371 return cur->next->target_ops;
1375 /* The inferior process has died. Long live the inferior! */
1378 generic_mourn_inferior (void)
1380 extern int show_breakpoint_hit_counts;
1384 breakpoint_init_inferior (inf_exited);
1385 registers_changed ();
1387 #ifdef CLEAR_DEFERRED_STORES
1388 /* Delete any pending stores to the inferior... */
1389 CLEAR_DEFERRED_STORES;
1392 reopen_exec_file ();
1393 reinit_frame_cache ();
1395 /* It is confusing to the user for ignore counts to stick around
1396 from previous runs of the inferior. So clear them. */
1397 /* However, it is more confusing for the ignore counts to disappear when
1398 using hit counts. So don't clear them if we're counting hits. */
1399 if (!show_breakpoint_hit_counts)
1400 breakpoint_clear_ignore_counts ();
1406 /* This table must match in order and size the signals in enum target_signal
1415 {"SIGHUP", "Hangup"},
1416 {"SIGINT", "Interrupt"},
1417 {"SIGQUIT", "Quit"},
1418 {"SIGILL", "Illegal instruction"},
1419 {"SIGTRAP", "Trace/breakpoint trap"},
1420 {"SIGABRT", "Aborted"},
1421 {"SIGEMT", "Emulation trap"},
1422 {"SIGFPE", "Arithmetic exception"},
1423 {"SIGKILL", "Killed"},
1424 {"SIGBUS", "Bus error"},
1425 {"SIGSEGV", "Segmentation fault"},
1426 {"SIGSYS", "Bad system call"},
1427 {"SIGPIPE", "Broken pipe"},
1428 {"SIGALRM", "Alarm clock"},
1429 {"SIGTERM", "Terminated"},
1430 {"SIGURG", "Urgent I/O condition"},
1431 {"SIGSTOP", "Stopped (signal)"},
1432 {"SIGTSTP", "Stopped (user)"},
1433 {"SIGCONT", "Continued"},
1434 {"SIGCHLD", "Child status changed"},
1435 {"SIGTTIN", "Stopped (tty input)"},
1436 {"SIGTTOU", "Stopped (tty output)"},
1437 {"SIGIO", "I/O possible"},
1438 {"SIGXCPU", "CPU time limit exceeded"},
1439 {"SIGXFSZ", "File size limit exceeded"},
1440 {"SIGVTALRM", "Virtual timer expired"},
1441 {"SIGPROF", "Profiling timer expired"},
1442 {"SIGWINCH", "Window size changed"},
1443 {"SIGLOST", "Resource lost"},
1444 {"SIGUSR1", "User defined signal 1"},
1445 {"SIGUSR2", "User defined signal 2"},
1446 {"SIGPWR", "Power fail/restart"},
1447 {"SIGPOLL", "Pollable event occurred"},
1448 {"SIGWIND", "SIGWIND"},
1449 {"SIGPHONE", "SIGPHONE"},
1450 {"SIGWAITING", "Process's LWPs are blocked"},
1451 {"SIGLWP", "Signal LWP"},
1452 {"SIGDANGER", "Swap space dangerously low"},
1453 {"SIGGRANT", "Monitor mode granted"},
1454 {"SIGRETRACT", "Need to relinquish monitor mode"},
1455 {"SIGMSG", "Monitor mode data available"},
1456 {"SIGSOUND", "Sound completed"},
1457 {"SIGSAK", "Secure attention"},
1458 {"SIGPRIO", "SIGPRIO"},
1459 {"SIG33", "Real-time event 33"},
1460 {"SIG34", "Real-time event 34"},
1461 {"SIG35", "Real-time event 35"},
1462 {"SIG36", "Real-time event 36"},
1463 {"SIG37", "Real-time event 37"},
1464 {"SIG38", "Real-time event 38"},
1465 {"SIG39", "Real-time event 39"},
1466 {"SIG40", "Real-time event 40"},
1467 {"SIG41", "Real-time event 41"},
1468 {"SIG42", "Real-time event 42"},
1469 {"SIG43", "Real-time event 43"},
1470 {"SIG44", "Real-time event 44"},
1471 {"SIG45", "Real-time event 45"},
1472 {"SIG46", "Real-time event 46"},
1473 {"SIG47", "Real-time event 47"},
1474 {"SIG48", "Real-time event 48"},
1475 {"SIG49", "Real-time event 49"},
1476 {"SIG50", "Real-time event 50"},
1477 {"SIG51", "Real-time event 51"},
1478 {"SIG52", "Real-time event 52"},
1479 {"SIG53", "Real-time event 53"},
1480 {"SIG54", "Real-time event 54"},
1481 {"SIG55", "Real-time event 55"},
1482 {"SIG56", "Real-time event 56"},
1483 {"SIG57", "Real-time event 57"},
1484 {"SIG58", "Real-time event 58"},
1485 {"SIG59", "Real-time event 59"},
1486 {"SIG60", "Real-time event 60"},
1487 {"SIG61", "Real-time event 61"},
1488 {"SIG62", "Real-time event 62"},
1489 {"SIG63", "Real-time event 63"},
1490 {"SIGCANCEL", "LWP internal signal"},
1491 {"SIG32", "Real-time event 32"},
1492 {"SIG64", "Real-time event 64"},
1494 #if defined(MACH) || defined(__MACH__)
1495 /* Mach exceptions */
1496 {"EXC_BAD_ACCESS", "Could not access memory"},
1497 {"EXC_BAD_INSTRUCTION", "Illegal instruction/operand"},
1498 {"EXC_ARITHMETIC", "Arithmetic exception"},
1499 {"EXC_EMULATION", "Emulation instruction"},
1500 {"EXC_SOFTWARE", "Software generated exception"},
1501 {"EXC_BREAKPOINT", "Breakpoint"},
1503 {"SIGINFO", "Information request"},
1505 {NULL, "Unknown signal"},
1506 {NULL, "Internal error: printing TARGET_SIGNAL_DEFAULT"},
1508 /* Last entry, used to check whether the table is the right size. */
1509 {NULL, "TARGET_SIGNAL_MAGIC"}
1515 /* Return the string for a signal. */
1517 target_signal_to_string (enum target_signal sig)
1519 if ((sig >= TARGET_SIGNAL_FIRST) && (sig <= TARGET_SIGNAL_LAST))
1520 return signals[sig].string;
1522 return signals[TARGET_SIGNAL_UNKNOWN].string;
1525 /* Return the name for a signal. */
1527 target_signal_to_name (enum target_signal sig)
1529 if (sig == TARGET_SIGNAL_UNKNOWN)
1530 /* I think the code which prints this will always print it along with
1531 the string, so no need to be verbose. */
1533 return signals[sig].name;
1536 /* Given a name, return its signal. */
1538 target_signal_from_name (char *name)
1540 enum target_signal sig;
1542 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
1543 for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
1544 questionable; seems like by now people should call it SIGABRT
1547 /* This ugly cast brought to you by the native VAX compiler. */
1548 for (sig = TARGET_SIGNAL_HUP;
1549 signals[sig].name != NULL;
1550 sig = (enum target_signal) ((int) sig + 1))
1551 if (STREQ (name, signals[sig].name))
1553 return TARGET_SIGNAL_UNKNOWN;
1556 /* The following functions are to help certain targets deal
1557 with the signal/waitstatus stuff. They could just as well be in
1558 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
1560 /* Convert host signal to our signals. */
1562 target_signal_from_host (int hostsig)
1564 /* A switch statement would make sense but would require special kludges
1565 to deal with the cases where more than one signal has the same number. */
1568 return TARGET_SIGNAL_0;
1570 #if defined (SIGHUP)
1571 if (hostsig == SIGHUP)
1572 return TARGET_SIGNAL_HUP;
1574 #if defined (SIGINT)
1575 if (hostsig == SIGINT)
1576 return TARGET_SIGNAL_INT;
1578 #if defined (SIGQUIT)
1579 if (hostsig == SIGQUIT)
1580 return TARGET_SIGNAL_QUIT;
1582 #if defined (SIGILL)
1583 if (hostsig == SIGILL)
1584 return TARGET_SIGNAL_ILL;
1586 #if defined (SIGTRAP)
1587 if (hostsig == SIGTRAP)
1588 return TARGET_SIGNAL_TRAP;
1590 #if defined (SIGABRT)
1591 if (hostsig == SIGABRT)
1592 return TARGET_SIGNAL_ABRT;
1594 #if defined (SIGEMT)
1595 if (hostsig == SIGEMT)
1596 return TARGET_SIGNAL_EMT;
1598 #if defined (SIGFPE)
1599 if (hostsig == SIGFPE)
1600 return TARGET_SIGNAL_FPE;
1602 #if defined (SIGKILL)
1603 if (hostsig == SIGKILL)
1604 return TARGET_SIGNAL_KILL;
1606 #if defined (SIGBUS)
1607 if (hostsig == SIGBUS)
1608 return TARGET_SIGNAL_BUS;
1610 #if defined (SIGSEGV)
1611 if (hostsig == SIGSEGV)
1612 return TARGET_SIGNAL_SEGV;
1614 #if defined (SIGSYS)
1615 if (hostsig == SIGSYS)
1616 return TARGET_SIGNAL_SYS;
1618 #if defined (SIGPIPE)
1619 if (hostsig == SIGPIPE)
1620 return TARGET_SIGNAL_PIPE;
1622 #if defined (SIGALRM)
1623 if (hostsig == SIGALRM)
1624 return TARGET_SIGNAL_ALRM;
1626 #if defined (SIGTERM)
1627 if (hostsig == SIGTERM)
1628 return TARGET_SIGNAL_TERM;
1630 #if defined (SIGUSR1)
1631 if (hostsig == SIGUSR1)
1632 return TARGET_SIGNAL_USR1;
1634 #if defined (SIGUSR2)
1635 if (hostsig == SIGUSR2)
1636 return TARGET_SIGNAL_USR2;
1638 #if defined (SIGCLD)
1639 if (hostsig == SIGCLD)
1640 return TARGET_SIGNAL_CHLD;
1642 #if defined (SIGCHLD)
1643 if (hostsig == SIGCHLD)
1644 return TARGET_SIGNAL_CHLD;
1646 #if defined (SIGPWR)
1647 if (hostsig == SIGPWR)
1648 return TARGET_SIGNAL_PWR;
1650 #if defined (SIGWINCH)
1651 if (hostsig == SIGWINCH)
1652 return TARGET_SIGNAL_WINCH;
1654 #if defined (SIGURG)
1655 if (hostsig == SIGURG)
1656 return TARGET_SIGNAL_URG;
1659 if (hostsig == SIGIO)
1660 return TARGET_SIGNAL_IO;
1662 #if defined (SIGPOLL)
1663 if (hostsig == SIGPOLL)
1664 return TARGET_SIGNAL_POLL;
1666 #if defined (SIGSTOP)
1667 if (hostsig == SIGSTOP)
1668 return TARGET_SIGNAL_STOP;
1670 #if defined (SIGTSTP)
1671 if (hostsig == SIGTSTP)
1672 return TARGET_SIGNAL_TSTP;
1674 #if defined (SIGCONT)
1675 if (hostsig == SIGCONT)
1676 return TARGET_SIGNAL_CONT;
1678 #if defined (SIGTTIN)
1679 if (hostsig == SIGTTIN)
1680 return TARGET_SIGNAL_TTIN;
1682 #if defined (SIGTTOU)
1683 if (hostsig == SIGTTOU)
1684 return TARGET_SIGNAL_TTOU;
1686 #if defined (SIGVTALRM)
1687 if (hostsig == SIGVTALRM)
1688 return TARGET_SIGNAL_VTALRM;
1690 #if defined (SIGPROF)
1691 if (hostsig == SIGPROF)
1692 return TARGET_SIGNAL_PROF;
1694 #if defined (SIGXCPU)
1695 if (hostsig == SIGXCPU)
1696 return TARGET_SIGNAL_XCPU;
1698 #if defined (SIGXFSZ)
1699 if (hostsig == SIGXFSZ)
1700 return TARGET_SIGNAL_XFSZ;
1702 #if defined (SIGWIND)
1703 if (hostsig == SIGWIND)
1704 return TARGET_SIGNAL_WIND;
1706 #if defined (SIGPHONE)
1707 if (hostsig == SIGPHONE)
1708 return TARGET_SIGNAL_PHONE;
1710 #if defined (SIGLOST)
1711 if (hostsig == SIGLOST)
1712 return TARGET_SIGNAL_LOST;
1714 #if defined (SIGWAITING)
1715 if (hostsig == SIGWAITING)
1716 return TARGET_SIGNAL_WAITING;
1718 #if defined (SIGCANCEL)
1719 if (hostsig == SIGCANCEL)
1720 return TARGET_SIGNAL_CANCEL;
1722 #if defined (SIGLWP)
1723 if (hostsig == SIGLWP)
1724 return TARGET_SIGNAL_LWP;
1726 #if defined (SIGDANGER)
1727 if (hostsig == SIGDANGER)
1728 return TARGET_SIGNAL_DANGER;
1730 #if defined (SIGGRANT)
1731 if (hostsig == SIGGRANT)
1732 return TARGET_SIGNAL_GRANT;
1734 #if defined (SIGRETRACT)
1735 if (hostsig == SIGRETRACT)
1736 return TARGET_SIGNAL_RETRACT;
1738 #if defined (SIGMSG)
1739 if (hostsig == SIGMSG)
1740 return TARGET_SIGNAL_MSG;
1742 #if defined (SIGSOUND)
1743 if (hostsig == SIGSOUND)
1744 return TARGET_SIGNAL_SOUND;
1746 #if defined (SIGSAK)
1747 if (hostsig == SIGSAK)
1748 return TARGET_SIGNAL_SAK;
1750 #if defined (SIGPRIO)
1751 if (hostsig == SIGPRIO)
1752 return TARGET_SIGNAL_PRIO;
1755 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1756 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1757 if (hostsig == _NSIG + EXC_BAD_ACCESS)
1758 return TARGET_EXC_BAD_ACCESS;
1760 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1761 if (hostsig == _NSIG + EXC_BAD_INSTRUCTION)
1762 return TARGET_EXC_BAD_INSTRUCTION;
1764 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1765 if (hostsig == _NSIG + EXC_ARITHMETIC)
1766 return TARGET_EXC_ARITHMETIC;
1768 #if defined (EXC_EMULATION) && defined (_NSIG)
1769 if (hostsig == _NSIG + EXC_EMULATION)
1770 return TARGET_EXC_EMULATION;
1772 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1773 if (hostsig == _NSIG + EXC_SOFTWARE)
1774 return TARGET_EXC_SOFTWARE;
1776 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1777 if (hostsig == _NSIG + EXC_BREAKPOINT)
1778 return TARGET_EXC_BREAKPOINT;
1781 #if defined (SIGINFO)
1782 if (hostsig == SIGINFO)
1783 return TARGET_SIGNAL_INFO;
1786 #if defined (REALTIME_LO)
1787 if (hostsig >= REALTIME_LO && hostsig < REALTIME_HI)
1789 /* This block of TARGET_SIGNAL_REALTIME value is in order. */
1790 if (33 <= hostsig && hostsig <= 63)
1791 return (enum target_signal)
1792 (hostsig - 33 + (int) TARGET_SIGNAL_REALTIME_33);
1793 else if (hostsig == 32)
1794 return TARGET_SIGNAL_REALTIME_32;
1796 error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
1800 #if defined (SIGRTMIN)
1801 if (hostsig >= SIGRTMIN && hostsig <= SIGRTMAX)
1803 /* This block of TARGET_SIGNAL_REALTIME value is in order. */
1804 if (33 <= hostsig && hostsig <= 63)
1805 return (enum target_signal)
1806 (hostsig - 33 + (int) TARGET_SIGNAL_REALTIME_33);
1807 else if (hostsig == 64)
1808 return TARGET_SIGNAL_REALTIME_64;
1810 error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
1813 return TARGET_SIGNAL_UNKNOWN;
1816 /* Convert a OURSIG (an enum target_signal) to the form used by the
1817 target operating system (refered to as the ``host'') or zero if the
1818 equivalent host signal is not available. Set/clear OURSIG_OK
1822 do_target_signal_to_host (enum target_signal oursig,
1828 case TARGET_SIGNAL_0:
1831 #if defined (SIGHUP)
1832 case TARGET_SIGNAL_HUP:
1835 #if defined (SIGINT)
1836 case TARGET_SIGNAL_INT:
1839 #if defined (SIGQUIT)
1840 case TARGET_SIGNAL_QUIT:
1843 #if defined (SIGILL)
1844 case TARGET_SIGNAL_ILL:
1847 #if defined (SIGTRAP)
1848 case TARGET_SIGNAL_TRAP:
1851 #if defined (SIGABRT)
1852 case TARGET_SIGNAL_ABRT:
1855 #if defined (SIGEMT)
1856 case TARGET_SIGNAL_EMT:
1859 #if defined (SIGFPE)
1860 case TARGET_SIGNAL_FPE:
1863 #if defined (SIGKILL)
1864 case TARGET_SIGNAL_KILL:
1867 #if defined (SIGBUS)
1868 case TARGET_SIGNAL_BUS:
1871 #if defined (SIGSEGV)
1872 case TARGET_SIGNAL_SEGV:
1875 #if defined (SIGSYS)
1876 case TARGET_SIGNAL_SYS:
1879 #if defined (SIGPIPE)
1880 case TARGET_SIGNAL_PIPE:
1883 #if defined (SIGALRM)
1884 case TARGET_SIGNAL_ALRM:
1887 #if defined (SIGTERM)
1888 case TARGET_SIGNAL_TERM:
1891 #if defined (SIGUSR1)
1892 case TARGET_SIGNAL_USR1:
1895 #if defined (SIGUSR2)
1896 case TARGET_SIGNAL_USR2:
1899 #if defined (SIGCHLD) || defined (SIGCLD)
1900 case TARGET_SIGNAL_CHLD:
1901 #if defined (SIGCHLD)
1906 #endif /* SIGCLD or SIGCHLD */
1907 #if defined (SIGPWR)
1908 case TARGET_SIGNAL_PWR:
1911 #if defined (SIGWINCH)
1912 case TARGET_SIGNAL_WINCH:
1915 #if defined (SIGURG)
1916 case TARGET_SIGNAL_URG:
1920 case TARGET_SIGNAL_IO:
1923 #if defined (SIGPOLL)
1924 case TARGET_SIGNAL_POLL:
1927 #if defined (SIGSTOP)
1928 case TARGET_SIGNAL_STOP:
1931 #if defined (SIGTSTP)
1932 case TARGET_SIGNAL_TSTP:
1935 #if defined (SIGCONT)
1936 case TARGET_SIGNAL_CONT:
1939 #if defined (SIGTTIN)
1940 case TARGET_SIGNAL_TTIN:
1943 #if defined (SIGTTOU)
1944 case TARGET_SIGNAL_TTOU:
1947 #if defined (SIGVTALRM)
1948 case TARGET_SIGNAL_VTALRM:
1951 #if defined (SIGPROF)
1952 case TARGET_SIGNAL_PROF:
1955 #if defined (SIGXCPU)
1956 case TARGET_SIGNAL_XCPU:
1959 #if defined (SIGXFSZ)
1960 case TARGET_SIGNAL_XFSZ:
1963 #if defined (SIGWIND)
1964 case TARGET_SIGNAL_WIND:
1967 #if defined (SIGPHONE)
1968 case TARGET_SIGNAL_PHONE:
1971 #if defined (SIGLOST)
1972 case TARGET_SIGNAL_LOST:
1975 #if defined (SIGWAITING)
1976 case TARGET_SIGNAL_WAITING:
1979 #if defined (SIGCANCEL)
1980 case TARGET_SIGNAL_CANCEL:
1983 #if defined (SIGLWP)
1984 case TARGET_SIGNAL_LWP:
1987 #if defined (SIGDANGER)
1988 case TARGET_SIGNAL_DANGER:
1991 #if defined (SIGGRANT)
1992 case TARGET_SIGNAL_GRANT:
1995 #if defined (SIGRETRACT)
1996 case TARGET_SIGNAL_RETRACT:
1999 #if defined (SIGMSG)
2000 case TARGET_SIGNAL_MSG:
2003 #if defined (SIGSOUND)
2004 case TARGET_SIGNAL_SOUND:
2007 #if defined (SIGSAK)
2008 case TARGET_SIGNAL_SAK:
2011 #if defined (SIGPRIO)
2012 case TARGET_SIGNAL_PRIO:
2016 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
2017 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
2018 case TARGET_EXC_BAD_ACCESS:
2019 return _NSIG + EXC_BAD_ACCESS;
2021 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
2022 case TARGET_EXC_BAD_INSTRUCTION:
2023 return _NSIG + EXC_BAD_INSTRUCTION;
2025 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
2026 case TARGET_EXC_ARITHMETIC:
2027 return _NSIG + EXC_ARITHMETIC;
2029 #if defined (EXC_EMULATION) && defined (_NSIG)
2030 case TARGET_EXC_EMULATION:
2031 return _NSIG + EXC_EMULATION;
2033 #if defined (EXC_SOFTWARE) && defined (_NSIG)
2034 case TARGET_EXC_SOFTWARE:
2035 return _NSIG + EXC_SOFTWARE;
2037 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
2038 case TARGET_EXC_BREAKPOINT:
2039 return _NSIG + EXC_BREAKPOINT;
2042 #if defined (SIGINFO)
2043 case TARGET_SIGNAL_INFO:
2048 #if defined (REALTIME_LO)
2049 if (oursig >= TARGET_SIGNAL_REALTIME_33
2050 && oursig <= TARGET_SIGNAL_REALTIME_63)
2052 /* This block of signals is continuous, and
2053 TARGET_SIGNAL_REALTIME_33 is 33 by definition. */
2055 (int) oursig - (int) TARGET_SIGNAL_REALTIME_33 + 33;
2056 if (retsig >= REALTIME_LO && retsig < REALTIME_HI)
2059 #if (REALTIME_LO < 33)
2060 else if (oursig == TARGET_SIGNAL_REALTIME_32)
2062 /* TARGET_SIGNAL_REALTIME_32 isn't contiguous with
2063 TARGET_SIGNAL_REALTIME_33. It is 32 by definition. */
2069 #if defined (SIGRTMIN)
2070 if (oursig >= TARGET_SIGNAL_REALTIME_33
2071 && oursig <= TARGET_SIGNAL_REALTIME_63)
2073 /* This block of signals is continuous, and
2074 TARGET_SIGNAL_REALTIME_33 is 33 by definition. */
2076 (int) oursig - (int) TARGET_SIGNAL_REALTIME_33 + 33;
2077 if (retsig >= SIGRTMIN && retsig <= SIGRTMAX)
2080 else if (oursig == TARGET_SIGNAL_REALTIME_64)
2089 target_signal_to_host_p (enum target_signal oursig)
2092 do_target_signal_to_host (oursig, &oursig_ok);
2097 target_signal_to_host (enum target_signal oursig)
2100 int targ_signo = do_target_signal_to_host (oursig, &oursig_ok);
2103 /* The user might be trying to do "signal SIGSAK" where this system
2104 doesn't have SIGSAK. */
2105 warning ("Signal %s does not exist on this system.\n",
2106 target_signal_to_name (oursig));
2113 /* Helper function for child_wait and the Lynx derivatives of child_wait.
2114 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
2115 translation of that in OURSTATUS. */
2117 store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus)
2119 #ifdef CHILD_SPECIAL_WAITSTATUS
2120 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
2121 if it wants to deal with hoststatus. */
2122 if (CHILD_SPECIAL_WAITSTATUS (ourstatus, hoststatus))
2126 if (WIFEXITED (hoststatus))
2128 ourstatus->kind = TARGET_WAITKIND_EXITED;
2129 ourstatus->value.integer = WEXITSTATUS (hoststatus);
2131 else if (!WIFSTOPPED (hoststatus))
2133 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
2134 ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus));
2138 ourstatus->kind = TARGET_WAITKIND_STOPPED;
2139 ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus));
2143 /* In some circumstances we allow a command to specify a numeric
2144 signal. The idea is to keep these circumstances limited so that
2145 users (and scripts) develop portable habits. For comparison,
2146 POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
2147 numeric signal at all is obsolescent. We are slightly more
2148 lenient and allow 1-15 which should match host signal numbers on
2149 most systems. Use of symbolic signal names is strongly encouraged. */
2152 target_signal_from_command (int num)
2154 if (num >= 1 && num <= 15)
2155 return (enum target_signal) num;
2156 error ("Only signals 1-15 are valid as numeric signals.\n\
2157 Use \"info signals\" for a list of symbolic signals.");
2160 /* Returns zero to leave the inferior alone, one to interrupt it. */
2161 int (*target_activity_function) (void);
2162 int target_activity_fd;
2164 /* Convert a normal process ID to a string. Returns the string in a static
2168 normal_pid_to_str (int pid)
2170 static char buf[30];
2172 if (STREQ (current_target.to_shortname, "remote"))
2173 sprintf (buf, "thread %d", pid);
2175 sprintf (buf, "process %d", pid);
2180 /* Some targets (such as ttrace-based HPUX) don't allow us to request
2181 notification of inferior events such as fork and vork immediately
2182 after the inferior is created. (This because of how gdb gets an
2183 inferior created via invoking a shell to do it. In such a scenario,
2184 if the shell init file has commands in it, the shell will fork and
2185 exec for each of those commands, and we will see each such fork
2188 This function is used by all targets that allow us to request
2189 notification of forks, etc at inferior creation time; e.g., in
2190 target_acknowledge_forked_child.
2193 normal_target_post_startup_inferior (int pid)
2195 /* This space intentionally left blank. */
2198 /* Set up the handful of non-empty slots needed by the dummy target
2202 init_dummy_target (void)
2204 dummy_target.to_shortname = "None";
2205 dummy_target.to_longname = "None";
2206 dummy_target.to_doc = "";
2207 dummy_target.to_attach = find_default_attach;
2208 dummy_target.to_require_attach = find_default_require_attach;
2209 dummy_target.to_require_detach = find_default_require_detach;
2210 dummy_target.to_create_inferior = find_default_create_inferior;
2211 dummy_target.to_clone_and_follow_inferior = find_default_clone_and_follow_inferior;
2212 dummy_target.to_pid_to_str = normal_pid_to_str;
2213 dummy_target.to_stratum = dummy_stratum;
2214 dummy_target.to_magic = OPS_MAGIC;
2218 static struct target_ops debug_target;
2221 debug_to_open (char *args, int from_tty)
2223 debug_target.to_open (args, from_tty);
2225 fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty);
2229 debug_to_close (int quitting)
2231 debug_target.to_close (quitting);
2233 fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting);
2237 debug_to_attach (char *args, int from_tty)
2239 debug_target.to_attach (args, from_tty);
2241 fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty);
2246 debug_to_post_attach (int pid)
2248 debug_target.to_post_attach (pid);
2250 fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid);
2254 debug_to_require_attach (char *args, int from_tty)
2256 debug_target.to_require_attach (args, from_tty);
2258 fprintf_unfiltered (gdb_stdlog,
2259 "target_require_attach (%s, %d)\n", args, from_tty);
2263 debug_to_detach (char *args, int from_tty)
2265 debug_target.to_detach (args, from_tty);
2267 fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty);
2271 debug_to_require_detach (int pid, char *args, int from_tty)
2273 debug_target.to_require_detach (pid, args, from_tty);
2275 fprintf_unfiltered (gdb_stdlog,
2276 "target_require_detach (%d, %s, %d)\n", pid, args, from_tty);
2280 debug_to_resume (int pid, int step, enum target_signal siggnal)
2282 debug_target.to_resume (pid, step, siggnal);
2284 fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", pid,
2285 step ? "step" : "continue",
2286 target_signal_to_name (siggnal));
2290 debug_to_wait (int pid, struct target_waitstatus *status)
2294 retval = debug_target.to_wait (pid, status);
2296 fprintf_unfiltered (gdb_stdlog,
2297 "target_wait (%d, status) = %d, ", pid, retval);
2298 fprintf_unfiltered (gdb_stdlog, "status->kind = ");
2299 switch (status->kind)
2301 case TARGET_WAITKIND_EXITED:
2302 fprintf_unfiltered (gdb_stdlog, "exited, status = %d\n",
2303 status->value.integer);
2305 case TARGET_WAITKIND_STOPPED:
2306 fprintf_unfiltered (gdb_stdlog, "stopped, signal = %s\n",
2307 target_signal_to_name (status->value.sig));
2309 case TARGET_WAITKIND_SIGNALLED:
2310 fprintf_unfiltered (gdb_stdlog, "signalled, signal = %s\n",
2311 target_signal_to_name (status->value.sig));
2313 case TARGET_WAITKIND_LOADED:
2314 fprintf_unfiltered (gdb_stdlog, "loaded\n");
2316 case TARGET_WAITKIND_FORKED:
2317 fprintf_unfiltered (gdb_stdlog, "forked\n");
2319 case TARGET_WAITKIND_VFORKED:
2320 fprintf_unfiltered (gdb_stdlog, "vforked\n");
2322 case TARGET_WAITKIND_EXECD:
2323 fprintf_unfiltered (gdb_stdlog, "execd\n");
2325 case TARGET_WAITKIND_SPURIOUS:
2326 fprintf_unfiltered (gdb_stdlog, "spurious\n");
2329 fprintf_unfiltered (gdb_stdlog, "unknown???\n");
2337 debug_to_post_wait (int pid, int status)
2339 debug_target.to_post_wait (pid, status);
2341 fprintf_unfiltered (gdb_stdlog, "target_post_wait (%d, %d)\n",
2346 debug_to_fetch_registers (int regno)
2348 debug_target.to_fetch_registers (regno);
2350 fprintf_unfiltered (gdb_stdlog, "target_fetch_registers (%s)",
2351 regno != -1 ? REGISTER_NAME (regno) : "-1");
2353 fprintf_unfiltered (gdb_stdlog, " = 0x%lx %ld",
2354 (unsigned long) read_register (regno),
2355 (unsigned long) read_register (regno));
2356 fprintf_unfiltered (gdb_stdlog, "\n");
2360 debug_to_store_registers (int regno)
2362 debug_target.to_store_registers (regno);
2364 if (regno >= 0 && regno < NUM_REGS)
2365 fprintf_unfiltered (gdb_stdlog, "target_store_registers (%s) = 0x%lx %ld\n",
2366 REGISTER_NAME (regno),
2367 (unsigned long) read_register (regno),
2368 (unsigned long) read_register (regno));
2370 fprintf_unfiltered (gdb_stdlog, "target_store_registers (%d)\n", regno);
2374 debug_to_prepare_to_store (void)
2376 debug_target.to_prepare_to_store ();
2378 fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n");
2382 debug_to_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
2383 struct mem_attrib *attrib,
2384 struct target_ops *target)
2388 retval = debug_target.to_xfer_memory (memaddr, myaddr, len, write,
2391 fprintf_unfiltered (gdb_stdlog,
2392 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
2393 (unsigned int) memaddr, /* possable truncate long long */
2394 len, write ? "write" : "read", retval);
2402 fputs_unfiltered (", bytes =", gdb_stdlog);
2403 for (i = 0; i < retval; i++)
2405 if ((((long) &(myaddr[i])) & 0xf) == 0)
2406 fprintf_unfiltered (gdb_stdlog, "\n");
2407 fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff);
2411 fputc_unfiltered ('\n', gdb_stdlog);
2417 debug_to_files_info (struct target_ops *target)
2419 debug_target.to_files_info (target);
2421 fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n");
2425 debug_to_insert_breakpoint (CORE_ADDR addr, char *save)
2429 retval = debug_target.to_insert_breakpoint (addr, save);
2431 fprintf_unfiltered (gdb_stdlog,
2432 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
2433 (unsigned long) addr,
2434 (unsigned long) retval);
2439 debug_to_remove_breakpoint (CORE_ADDR addr, char *save)
2443 retval = debug_target.to_remove_breakpoint (addr, save);
2445 fprintf_unfiltered (gdb_stdlog,
2446 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
2447 (unsigned long) addr,
2448 (unsigned long) retval);
2453 debug_to_terminal_init (void)
2455 debug_target.to_terminal_init ();
2457 fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n");
2461 debug_to_terminal_inferior (void)
2463 debug_target.to_terminal_inferior ();
2465 fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n");
2469 debug_to_terminal_ours_for_output (void)
2471 debug_target.to_terminal_ours_for_output ();
2473 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n");
2477 debug_to_terminal_ours (void)
2479 debug_target.to_terminal_ours ();
2481 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n");
2485 debug_to_terminal_info (char *arg, int from_tty)
2487 debug_target.to_terminal_info (arg, from_tty);
2489 fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg,
2494 debug_to_kill (void)
2496 debug_target.to_kill ();
2498 fprintf_unfiltered (gdb_stdlog, "target_kill ()\n");
2502 debug_to_load (char *args, int from_tty)
2504 debug_target.to_load (args, from_tty);
2506 fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty);
2510 debug_to_lookup_symbol (char *name, CORE_ADDR *addrp)
2514 retval = debug_target.to_lookup_symbol (name, addrp);
2516 fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name);
2522 debug_to_create_inferior (char *exec_file, char *args, char **env)
2524 debug_target.to_create_inferior (exec_file, args, env);
2526 fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx)\n",
2531 debug_to_post_startup_inferior (int pid)
2533 debug_target.to_post_startup_inferior (pid);
2535 fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n",
2540 debug_to_acknowledge_created_inferior (int pid)
2542 debug_target.to_acknowledge_created_inferior (pid);
2544 fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n",
2549 debug_to_clone_and_follow_inferior (int child_pid, int *followed_child)
2551 debug_target.to_clone_and_follow_inferior (child_pid, followed_child);
2553 fprintf_unfiltered (gdb_stdlog,
2554 "target_clone_and_follow_inferior (%d, %d)\n",
2555 child_pid, *followed_child);
2559 debug_to_post_follow_inferior_by_clone (void)
2561 debug_target.to_post_follow_inferior_by_clone ();
2563 fprintf_unfiltered (gdb_stdlog, "target_post_follow_inferior_by_clone ()\n");
2567 debug_to_insert_fork_catchpoint (int pid)
2571 retval = debug_target.to_insert_fork_catchpoint (pid);
2573 fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d) = %d\n",
2580 debug_to_remove_fork_catchpoint (int pid)
2584 retval = debug_target.to_remove_fork_catchpoint (pid);
2586 fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n",
2593 debug_to_insert_vfork_catchpoint (int pid)
2597 retval = debug_target.to_insert_vfork_catchpoint (pid);
2599 fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)= %d\n",
2606 debug_to_remove_vfork_catchpoint (int pid)
2610 retval = debug_target.to_remove_vfork_catchpoint (pid);
2612 fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n",
2619 debug_to_has_forked (int pid, int *child_pid)
2623 has_forked = debug_target.to_has_forked (pid, child_pid);
2625 fprintf_unfiltered (gdb_stdlog, "target_has_forked (%d, %d) = %d\n",
2626 pid, *child_pid, has_forked);
2632 debug_to_has_vforked (int pid, int *child_pid)
2636 has_vforked = debug_target.to_has_vforked (pid, child_pid);
2638 fprintf_unfiltered (gdb_stdlog, "target_has_vforked (%d, %d) = %d\n",
2639 pid, *child_pid, has_vforked);
2645 debug_to_can_follow_vfork_prior_to_exec (void)
2647 int can_immediately_follow_vfork;
2649 can_immediately_follow_vfork = debug_target.to_can_follow_vfork_prior_to_exec ();
2651 fprintf_unfiltered (gdb_stdlog, "target_can_follow_vfork_prior_to_exec () = %d\n",
2652 can_immediately_follow_vfork);
2654 return can_immediately_follow_vfork;
2658 debug_to_post_follow_vfork (int parent_pid, int followed_parent, int child_pid,
2661 debug_target.to_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child);
2663 fprintf_unfiltered (gdb_stdlog,
2664 "target_post_follow_vfork (%d, %d, %d, %d)\n",
2665 parent_pid, followed_parent, child_pid, followed_child);
2669 debug_to_insert_exec_catchpoint (int pid)
2673 retval = debug_target.to_insert_exec_catchpoint (pid);
2675 fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d) = %d\n",
2682 debug_to_remove_exec_catchpoint (int pid)
2686 retval = debug_target.to_remove_exec_catchpoint (pid);
2688 fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n",
2695 debug_to_has_execd (int pid, char **execd_pathname)
2699 has_execd = debug_target.to_has_execd (pid, execd_pathname);
2701 fprintf_unfiltered (gdb_stdlog, "target_has_execd (%d, %s) = %d\n",
2702 pid, (*execd_pathname ? *execd_pathname : "<NULL>"),
2709 debug_to_reported_exec_events_per_exec_call (void)
2711 int reported_exec_events;
2713 reported_exec_events = debug_target.to_reported_exec_events_per_exec_call ();
2715 fprintf_unfiltered (gdb_stdlog,
2716 "target_reported_exec_events_per_exec_call () = %d\n",
2717 reported_exec_events);
2719 return reported_exec_events;
2723 debug_to_has_syscall_event (int pid, enum target_waitkind *kind,
2726 int has_syscall_event;
2727 char *kind_spelling = "??";
2729 has_syscall_event = debug_target.to_has_syscall_event (pid, kind, syscall_id);
2730 if (has_syscall_event)
2734 case TARGET_WAITKIND_SYSCALL_ENTRY:
2735 kind_spelling = "SYSCALL_ENTRY";
2737 case TARGET_WAITKIND_SYSCALL_RETURN:
2738 kind_spelling = "SYSCALL_RETURN";
2745 fprintf_unfiltered (gdb_stdlog,
2746 "target_has_syscall_event (%d, %s, %d) = %d\n",
2747 pid, kind_spelling, *syscall_id, has_syscall_event);
2749 return has_syscall_event;
2753 debug_to_has_exited (int pid, int wait_status, int *exit_status)
2757 has_exited = debug_target.to_has_exited (pid, wait_status, exit_status);
2759 fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n",
2760 pid, wait_status, *exit_status, has_exited);
2766 debug_to_mourn_inferior (void)
2768 debug_target.to_mourn_inferior ();
2770 fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n");
2774 debug_to_can_run (void)
2778 retval = debug_target.to_can_run ();
2780 fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval);
2786 debug_to_notice_signals (int pid)
2788 debug_target.to_notice_signals (pid);
2790 fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n", pid);
2794 debug_to_thread_alive (int pid)
2798 retval = debug_target.to_thread_alive (pid);
2800 fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n",
2807 debug_to_find_new_threads (void)
2809 debug_target.to_find_new_threads ();
2811 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog);
2815 debug_to_stop (void)
2817 debug_target.to_stop ();
2819 fprintf_unfiltered (gdb_stdlog, "target_stop ()\n");
2823 debug_to_query (int type, char *req, char *resp, int *siz)
2827 retval = debug_target.to_query (type, req, resp, siz);
2829 fprintf_unfiltered (gdb_stdlog, "target_query (%c, %s, %s, %d) = %d\n", type, req, resp, *siz, retval);
2835 debug_to_rcmd (char *command,
2836 struct ui_file *outbuf)
2838 debug_target.to_rcmd (command, outbuf);
2839 fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command);
2842 static struct symtab_and_line *
2843 debug_to_enable_exception_callback (enum exception_event_kind kind, int enable)
2845 struct symtab_and_line *result;
2846 result = debug_target.to_enable_exception_callback (kind, enable);
2847 fprintf_unfiltered (gdb_stdlog,
2848 "target get_exception_callback_sal (%d, %d)\n",
2853 static struct exception_event_record *
2854 debug_to_get_current_exception_event (void)
2856 struct exception_event_record *result;
2857 result = debug_target.to_get_current_exception_event ();
2858 fprintf_unfiltered (gdb_stdlog, "target get_current_exception_event ()\n");
2863 debug_to_pid_to_exec_file (int pid)
2867 exec_file = debug_target.to_pid_to_exec_file (pid);
2869 fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n",
2876 debug_to_core_file_to_sym_file (char *core)
2880 sym_file = debug_target.to_core_file_to_sym_file (core);
2882 fprintf_unfiltered (gdb_stdlog, "target_core_file_to_sym_file (%s) = %s\n",
2889 setup_target_debug (void)
2891 memcpy (&debug_target, ¤t_target, sizeof debug_target);
2893 current_target.to_open = debug_to_open;
2894 current_target.to_close = debug_to_close;
2895 current_target.to_attach = debug_to_attach;
2896 current_target.to_post_attach = debug_to_post_attach;
2897 current_target.to_require_attach = debug_to_require_attach;
2898 current_target.to_detach = debug_to_detach;
2899 current_target.to_require_detach = debug_to_require_detach;
2900 current_target.to_resume = debug_to_resume;
2901 current_target.to_wait = debug_to_wait;
2902 current_target.to_post_wait = debug_to_post_wait;
2903 current_target.to_fetch_registers = debug_to_fetch_registers;
2904 current_target.to_store_registers = debug_to_store_registers;
2905 current_target.to_prepare_to_store = debug_to_prepare_to_store;
2906 current_target.to_xfer_memory = debug_to_xfer_memory;
2907 current_target.to_files_info = debug_to_files_info;
2908 current_target.to_insert_breakpoint = debug_to_insert_breakpoint;
2909 current_target.to_remove_breakpoint = debug_to_remove_breakpoint;
2910 current_target.to_terminal_init = debug_to_terminal_init;
2911 current_target.to_terminal_inferior = debug_to_terminal_inferior;
2912 current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output;
2913 current_target.to_terminal_ours = debug_to_terminal_ours;
2914 current_target.to_terminal_info = debug_to_terminal_info;
2915 current_target.to_kill = debug_to_kill;
2916 current_target.to_load = debug_to_load;
2917 current_target.to_lookup_symbol = debug_to_lookup_symbol;
2918 current_target.to_create_inferior = debug_to_create_inferior;
2919 current_target.to_post_startup_inferior = debug_to_post_startup_inferior;
2920 current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior;
2921 current_target.to_clone_and_follow_inferior = debug_to_clone_and_follow_inferior;
2922 current_target.to_post_follow_inferior_by_clone = debug_to_post_follow_inferior_by_clone;
2923 current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint;
2924 current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
2925 current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
2926 current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint;
2927 current_target.to_has_forked = debug_to_has_forked;
2928 current_target.to_has_vforked = debug_to_has_vforked;
2929 current_target.to_can_follow_vfork_prior_to_exec = debug_to_can_follow_vfork_prior_to_exec;
2930 current_target.to_post_follow_vfork = debug_to_post_follow_vfork;
2931 current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint;
2932 current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
2933 current_target.to_has_execd = debug_to_has_execd;
2934 current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call;
2935 current_target.to_has_syscall_event = debug_to_has_syscall_event;
2936 current_target.to_has_exited = debug_to_has_exited;
2937 current_target.to_mourn_inferior = debug_to_mourn_inferior;
2938 current_target.to_can_run = debug_to_can_run;
2939 current_target.to_notice_signals = debug_to_notice_signals;
2940 current_target.to_thread_alive = debug_to_thread_alive;
2941 current_target.to_find_new_threads = debug_to_find_new_threads;
2942 current_target.to_stop = debug_to_stop;
2943 current_target.to_query = debug_to_query;
2944 current_target.to_rcmd = debug_to_rcmd;
2945 current_target.to_enable_exception_callback = debug_to_enable_exception_callback;
2946 current_target.to_get_current_exception_event = debug_to_get_current_exception_event;
2947 current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
2948 current_target.to_core_file_to_sym_file = debug_to_core_file_to_sym_file;
2953 static char targ_desc[] =
2954 "Names of targets and files being debugged.\n\
2955 Shows the entire stack of targets currently in use (including the exec-file,\n\
2956 core-file, and process, if any), as well as the symbol file name.";
2959 do_monitor_command (char *cmd,
2962 if ((current_target.to_rcmd
2963 == (void (*) (char *, struct ui_file *)) tcomplain)
2964 || (current_target.to_rcmd == debug_to_rcmd
2965 && (debug_target.to_rcmd
2966 == (void (*) (char *, struct ui_file *)) tcomplain)))
2968 error ("\"monitor\" command not supported by this target.\n");
2970 target_rcmd (cmd, gdb_stdtarg);
2974 initialize_targets (void)
2976 init_dummy_target ();
2977 push_target (&dummy_target);
2979 add_info ("target", target_info, targ_desc);
2980 add_info ("files", target_info, targ_desc);
2983 add_set_cmd ("target", class_maintenance, var_zinteger,
2984 (char *) &targetdebug,
2985 "Set target debugging.\n\
2986 When non-zero, target debugging is enabled.", &setdebuglist),
2990 add_com ("monitor", class_obscure, do_monitor_command,
2991 "Send a command to the remote monitor (remote targets only).");
2993 target_dcache = dcache_init();
2995 if (!STREQ (signals[TARGET_SIGNAL_LAST].string, "TARGET_SIGNAL_MAGIC"))