1 /* Select target systems and architectures at runtime for GDB.
2 Copyright 1990, 1992-1995, 1998, 1999 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, Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
38 target_info PARAMS ((char *, int));
41 cleanup_target PARAMS ((struct target_ops *));
44 maybe_kill_then_create_inferior PARAMS ((char *, char *, char **));
47 default_clone_and_follow_inferior PARAMS ((int, int *));
50 maybe_kill_then_attach PARAMS ((char *, int));
53 kill_or_be_killed PARAMS ((int));
56 default_terminal_info PARAMS ((char *, int));
59 nosymbol PARAMS ((char *, CORE_ADDR *));
62 tcomplain PARAMS ((void));
65 nomemory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *));
68 return_zero PARAMS ((void));
71 return_one PARAMS ((void));
74 target_ignore PARAMS ((void));
77 target_command PARAMS ((char *, int));
79 static struct target_ops *
80 find_default_run_target PARAMS ((char *));
83 update_current_target PARAMS ((void));
85 /* Transfer LEN bytes between target address MEMADDR and GDB address MYADDR.
86 Returns 0 for success, errno code for failure (which includes partial
87 transfers--if you want a more useful response to partial transfers, try
88 target_read_memory_partial). */
91 target_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr, int len,
92 int write, asection *bfd_section));
94 static void init_dummy_target PARAMS ((void));
97 debug_to_open PARAMS ((char *, int));
100 debug_to_close PARAMS ((int));
103 debug_to_attach PARAMS ((char *, int));
106 debug_to_detach PARAMS ((char *, int));
109 debug_to_resume PARAMS ((int, int, enum target_signal));
112 debug_to_wait PARAMS ((int, struct target_waitstatus *));
115 debug_to_fetch_registers PARAMS ((int));
118 debug_to_store_registers PARAMS ((int));
121 debug_to_prepare_to_store PARAMS ((void));
124 debug_to_xfer_memory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *));
127 debug_to_files_info PARAMS ((struct target_ops *));
130 debug_to_insert_breakpoint PARAMS ((CORE_ADDR, char *));
133 debug_to_remove_breakpoint PARAMS ((CORE_ADDR, char *));
136 debug_to_terminal_init PARAMS ((void));
139 debug_to_terminal_inferior PARAMS ((void));
142 debug_to_terminal_ours_for_output PARAMS ((void));
145 debug_to_terminal_ours PARAMS ((void));
148 debug_to_terminal_info PARAMS ((char *, int));
151 debug_to_kill PARAMS ((void));
154 debug_to_load PARAMS ((char *, int));
157 debug_to_lookup_symbol PARAMS ((char *, CORE_ADDR *));
160 debug_to_create_inferior PARAMS ((char *, char *, char **));
163 debug_to_mourn_inferior PARAMS ((void));
166 debug_to_can_run PARAMS ((void));
169 debug_to_notice_signals PARAMS ((int));
172 debug_to_thread_alive PARAMS ((int));
175 debug_to_stop PARAMS ((void));
177 static int debug_to_query PARAMS ((int/*char*/, char *, char *, int *));
179 /* Pointer to array of target architecture structures; the size of the
180 array; the current index into the array; the allocated size of the
182 struct target_ops **target_structs;
183 unsigned target_struct_size;
184 unsigned target_struct_index;
185 unsigned target_struct_allocsize;
186 #define DEFAULT_ALLOCSIZE 10
188 /* The initial current target, so that there is always a semi-valid
191 static struct target_ops dummy_target;
193 /* Top of target stack. */
195 struct target_stack_item *target_stack;
197 /* The target structure we are currently using to talk to a process
198 or file or whatever "inferior" we have. */
200 struct target_ops current_target;
202 /* Command list for target. */
204 static struct cmd_list_element *targetlist = NULL;
206 /* Nonzero if we are debugging an attached outside process
207 rather than an inferior. */
211 #ifdef MAINTENANCE_CMDS
212 /* Non-zero if we want to see trace of target level stuff. */
214 static int targetdebug = 0;
216 static void setup_target_debug PARAMS ((void));
220 /* The user just typed 'target' without the name of a target. */
224 target_command (arg, from_tty)
228 fputs_filtered ("Argument required (target name). Try `help target'\n",
232 /* Add a possible target architecture to the list. */
236 struct target_ops *t;
240 target_struct_allocsize = DEFAULT_ALLOCSIZE;
241 target_structs = (struct target_ops **) xmalloc
242 (target_struct_allocsize * sizeof (*target_structs));
244 if (target_struct_size >= target_struct_allocsize)
246 target_struct_allocsize *= 2;
247 target_structs = (struct target_ops **)
248 xrealloc ((char *) target_structs,
249 target_struct_allocsize * sizeof (*target_structs));
251 target_structs[target_struct_size++] = t;
252 /* cleanup_target (t);*/
254 if (targetlist == NULL)
255 add_prefix_cmd ("target", class_run, target_command,
256 "Connect to a target machine or process.\n\
257 The first argument is the type or protocol of the target machine.\n\
258 Remaining arguments are interpreted by the target protocol. For more\n\
259 information on the arguments for a particular protocol, type\n\
260 `help target ' followed by the protocol name.",
261 &targetlist, "target ", 0, &cmdlist);
262 add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist);
274 nomemory (memaddr, myaddr, len, write, t)
279 struct target_ops *t;
281 errno = EIO; /* Can't read/write this location */
282 return 0; /* No bytes handled */
288 error ("You can't do that when your target is `%s'",
289 current_target.to_shortname);
295 error ("You can't do that without a process to debug.");
300 nosymbol (name, addrp)
304 return 1; /* Symbol does not exist in target env */
314 error ("No run-time support for this");
320 default_terminal_info (args, from_tty)
324 printf_unfiltered("No saved terminal information.\n");
327 /* This is the default target_create_inferior and target_attach function.
328 If the current target is executing, it asks whether to kill it off.
329 If this function returns without calling error(), it has killed off
330 the target, and the operation should be attempted. */
333 kill_or_be_killed (from_tty)
336 if (target_has_execution)
338 printf_unfiltered ("You are already running a program:\n");
339 target_files_info ();
340 if (query ("Kill it? ")) {
342 if (target_has_execution)
343 error ("Killing the program did not help.");
346 error ("Program not killed.");
353 maybe_kill_then_attach (args, from_tty)
357 kill_or_be_killed (from_tty);
358 target_attach (args, from_tty);
362 maybe_kill_then_create_inferior (exec, args, env)
367 kill_or_be_killed (0);
368 target_create_inferior (exec, args, env);
372 default_clone_and_follow_inferior (child_pid, followed_child)
376 target_clone_and_follow_inferior (child_pid, followed_child);
379 /* Clean up a target struct so it no longer has any zero pointers in it.
380 We default entries, at least to stubs that print error messages. */
384 struct target_ops *t;
387 #define de_fault(field, value) \
388 if (!t->field) t->field = value
390 /* FIELD DEFAULT VALUE */
392 de_fault (to_open, (void (*) PARAMS((char *, int))) tcomplain);
393 de_fault (to_close, (void (*) PARAMS((int))) target_ignore);
394 de_fault (to_attach, maybe_kill_then_attach);
395 de_fault (to_post_attach, (void (*) PARAMS ((int))) target_ignore);
396 de_fault (to_require_attach, maybe_kill_then_attach);
397 de_fault (to_detach, (void (*) PARAMS((char *, int))) target_ignore);
398 de_fault (to_require_detach, (void (*) PARAMS((int, char *, int))) target_ignore);
399 de_fault (to_resume, (void (*) PARAMS((int, int, enum target_signal))) noprocess);
400 de_fault (to_wait, (int (*) PARAMS((int, struct target_waitstatus *))) noprocess);
401 de_fault (to_post_wait, (void (*) PARAMS ((int, int))) target_ignore);
402 de_fault (to_fetch_registers, (void (*) PARAMS((int))) target_ignore);
403 de_fault (to_store_registers, (void (*) PARAMS((int))) noprocess);
404 de_fault (to_prepare_to_store, (void (*) PARAMS((void))) noprocess);
405 de_fault (to_xfer_memory, (int (*) PARAMS((CORE_ADDR, char *, int, int, struct target_ops *))) nomemory);
406 de_fault (to_files_info, (void (*) PARAMS((struct target_ops *))) target_ignore);
407 de_fault (to_insert_breakpoint, memory_insert_breakpoint);
408 de_fault (to_remove_breakpoint, memory_remove_breakpoint);
409 de_fault (to_terminal_init, (void (*) PARAMS((void))) target_ignore);
410 de_fault (to_terminal_inferior, (void (*) PARAMS ((void))) target_ignore);
411 de_fault (to_terminal_ours_for_output,(void (*) PARAMS ((void))) target_ignore);
412 de_fault (to_terminal_ours, (void (*) PARAMS ((void))) target_ignore);
413 de_fault (to_terminal_info, default_terminal_info);
414 de_fault (to_kill, (void (*) PARAMS((void))) noprocess);
415 de_fault (to_load, (void (*) PARAMS((char *, int))) tcomplain);
416 de_fault (to_lookup_symbol, (int (*) PARAMS ((char *, CORE_ADDR *))) nosymbol);
417 de_fault (to_create_inferior, maybe_kill_then_create_inferior);
418 de_fault (to_post_startup_inferior, (void (*) PARAMS ((int))) target_ignore);
419 de_fault (to_acknowledge_created_inferior, (void (*) PARAMS((int))) target_ignore);
420 de_fault (to_clone_and_follow_inferior, default_clone_and_follow_inferior);
421 de_fault (to_post_follow_inferior_by_clone, (void (*) PARAMS ((void))) target_ignore);
422 de_fault (to_insert_fork_catchpoint, (int (*) PARAMS ((int))) tcomplain);
423 de_fault (to_remove_fork_catchpoint, (int (*) PARAMS ((int))) tcomplain);
424 de_fault (to_insert_vfork_catchpoint, (int (*) PARAMS ((int))) tcomplain);
425 de_fault (to_remove_vfork_catchpoint, (int (*) PARAMS ((int))) tcomplain);
426 de_fault (to_has_forked, (int (*) PARAMS ((int, int *))) return_zero);
427 de_fault (to_has_vforked, (int (*) PARAMS ((int, int *))) return_zero);
428 de_fault (to_can_follow_vfork_prior_to_exec, (int (*) PARAMS ((void ))) return_zero);
429 de_fault (to_post_follow_vfork, (void (*) PARAMS ((int, int, int, int))) target_ignore);
430 de_fault (to_insert_exec_catchpoint, (int (*) PARAMS ((int))) tcomplain);
431 de_fault (to_remove_exec_catchpoint, (int (*) PARAMS ((int))) tcomplain);
432 de_fault (to_has_execd, (int (*) PARAMS ((int, char **))) return_zero);
433 de_fault (to_reported_exec_events_per_exec_call, (int (*) PARAMS ((void))) return_one);
434 de_fault (to_has_syscall_event, (int (*) PARAMS ((int, enum target_waitkind *, int *))) return_zero);
435 de_fault (to_has_exited, (int (*) PARAMS ((int, int, int *))) return_zero);
436 de_fault (to_mourn_inferior, (void (*) PARAMS ((void))) noprocess);
437 de_fault (to_can_run, return_zero);
438 de_fault (to_notice_signals, (void (*) PARAMS((int))) target_ignore);
439 de_fault (to_thread_alive, (int (*) PARAMS((int))) target_ignore);
440 de_fault (to_stop, (void (*) PARAMS((void))) target_ignore);
441 de_fault (to_query, (int (*) PARAMS((int/*char*/, char*, char *, int *))) target_ignore);
442 de_fault (to_enable_exception_callback, (struct symtab_and_line * (*) PARAMS((enum exception_event_kind, int))) nosupport_runtime);
443 de_fault (to_get_current_exception_event, (struct exception_event_record * (*) PARAMS((void))) nosupport_runtime);
445 de_fault (to_pid_to_exec_file, (char* (*) PARAMS((int))) return_zero);
446 de_fault (to_core_file_to_sym_file, (char* (*) PARAMS ((char *))) return_zero);
450 /* Go through the target stack from top to bottom, copying over zero entries in
451 current_target. In effect, we are doing class inheritance through the
452 pushed target vectors. */
455 update_current_target ()
457 struct target_stack_item *item;
458 struct target_ops *t;
460 /* First, reset current_target */
461 memset (¤t_target, 0, sizeof current_target);
463 for (item = target_stack; item; item = item->next)
465 t = item->target_ops;
467 #define INHERIT(FIELD, TARGET) \
468 if (!current_target.FIELD) \
469 current_target.FIELD = TARGET->FIELD
471 INHERIT (to_shortname, t);
472 INHERIT (to_longname, t);
474 INHERIT (to_open, t);
475 INHERIT (to_close, t);
476 INHERIT (to_attach, t);
477 INHERIT (to_post_attach, t);
478 INHERIT (to_require_attach, t);
479 INHERIT (to_detach, t);
480 INHERIT (to_require_detach, t);
481 INHERIT (to_resume, t);
482 INHERIT (to_wait, t);
483 INHERIT (to_post_wait, t);
484 INHERIT (to_fetch_registers, t);
485 INHERIT (to_store_registers, t);
486 INHERIT (to_prepare_to_store, t);
487 INHERIT (to_xfer_memory, t);
488 INHERIT (to_files_info, t);
489 INHERIT (to_insert_breakpoint, t);
490 INHERIT (to_remove_breakpoint, t);
491 INHERIT (to_terminal_init, t);
492 INHERIT (to_terminal_inferior, t);
493 INHERIT (to_terminal_ours_for_output, t);
494 INHERIT (to_terminal_ours, t);
495 INHERIT (to_terminal_info, t);
496 INHERIT (to_kill, t);
497 INHERIT (to_load, t);
498 INHERIT (to_lookup_symbol, t);
499 INHERIT (to_create_inferior, t);
500 INHERIT (to_post_startup_inferior, t);
501 INHERIT (to_acknowledge_created_inferior, t);
502 INHERIT (to_clone_and_follow_inferior, t);
503 INHERIT (to_post_follow_inferior_by_clone, t);
504 INHERIT (to_insert_fork_catchpoint, t);
505 INHERIT (to_remove_fork_catchpoint, t);
506 INHERIT (to_insert_vfork_catchpoint, t);
507 INHERIT (to_remove_vfork_catchpoint, t);
508 INHERIT (to_has_forked, t);
509 INHERIT (to_has_vforked, t);
510 INHERIT (to_can_follow_vfork_prior_to_exec, t);
511 INHERIT (to_post_follow_vfork, t);
512 INHERIT (to_insert_exec_catchpoint, t);
513 INHERIT (to_remove_exec_catchpoint, t);
514 INHERIT (to_has_execd, t);
515 INHERIT (to_reported_exec_events_per_exec_call, t);
516 INHERIT (to_has_syscall_event, t);
517 INHERIT (to_has_exited, t);
518 INHERIT (to_mourn_inferior, t);
519 INHERIT (to_can_run, t);
520 INHERIT (to_notice_signals, t);
521 INHERIT (to_thread_alive, t);
522 INHERIT (to_stop, t);
523 INHERIT (to_query, t);
524 INHERIT (to_enable_exception_callback, t);
525 INHERIT (to_get_current_exception_event, t);
526 INHERIT (to_pid_to_exec_file, t);
527 INHERIT (to_core_file_to_sym_file, t);
528 INHERIT (to_stratum, t);
529 INHERIT (DONT_USE, t);
530 INHERIT (to_has_all_memory, t);
531 INHERIT (to_has_memory, t);
532 INHERIT (to_has_stack, t);
533 INHERIT (to_has_registers, t);
534 INHERIT (to_has_execution, t);
535 INHERIT (to_has_thread_control, t);
536 INHERIT (to_sections, t);
537 INHERIT (to_sections_end, t);
538 INHERIT (to_magic, t);
544 /* Push a new target type into the stack of the existing target accessors,
545 possibly superseding some of the existing accessors.
547 Result is zero if the pushed target ended up on top of the stack,
548 nonzero if at least one target is on top of it.
550 Rather than allow an empty stack, we always have the dummy target at
551 the bottom stratum, so we can call the function vectors without
556 struct target_ops *t;
558 struct target_stack_item *cur, *prev, *tmp;
560 /* Check magic number. If wrong, it probably means someone changed
561 the struct definition, but not all the places that initialize one. */
562 if (t->to_magic != OPS_MAGIC)
564 fprintf_unfiltered(gdb_stderr,
565 "Magic number of %s target struct wrong\n",
570 /* Find the proper stratum to install this target in. */
572 for (prev = NULL, cur = target_stack; cur; prev = cur, cur = cur->next)
574 if ((int)(t->to_stratum) >= (int)(cur->target_ops->to_stratum))
578 /* If there's already targets at this stratum, remove them. */
581 while (t->to_stratum == cur->target_ops->to_stratum)
583 /* There's already something on this stratum. Close it off. */
584 if (cur->target_ops->to_close)
585 (cur->target_ops->to_close) (0);
587 prev->next = cur->next; /* Unchain old target_ops */
589 target_stack = cur->next; /* Unchain first on list */
595 /* We have removed all targets in our stratum, now add the new one. */
597 tmp = (struct target_stack_item *)
598 xmalloc (sizeof (struct target_stack_item));
607 update_current_target ();
609 cleanup_target (¤t_target); /* Fill in the gaps */
611 #ifdef MAINTENANCE_CMDS
613 setup_target_debug ();
619 /* Remove a target_ops vector from the stack, wherever it may be.
620 Return how many times it was removed (0 or 1). */
624 struct target_ops *t;
626 struct target_stack_item *cur, *prev;
629 t->to_close (0); /* Let it clean up */
631 /* Look for the specified target. Note that we assume that a target
632 can only occur once in the target stack. */
634 for (cur = target_stack, prev = NULL; cur; prev = cur, cur = cur->next)
635 if (cur->target_ops == t)
639 return 0; /* Didn't find target_ops, quit now */
641 /* Unchain the target */
644 target_stack = cur->next;
646 prev->next = cur->next;
648 free (cur); /* Release the target_stack_item */
650 update_current_target ();
651 cleanup_target (¤t_target);
659 (current_target.to_close)(0); /* Let it clean up */
660 if (unpush_target (target_stack->target_ops) == 1)
663 fprintf_unfiltered(gdb_stderr,
664 "pop_target couldn't find target %s\n",
665 current_target.to_shortname);
670 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
672 /* target_read_string -- read a null terminated string, up to LEN bytes,
673 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
674 Set *STRING to a pointer to malloc'd memory containing the data; the caller
675 is responsible for freeing it. Return the number of bytes successfully
679 target_read_string (memaddr, string, len, errnop)
685 int tlen, origlen, offset, i;
689 int buffer_allocated;
691 unsigned int nbytes_read = 0;
693 /* Small for testing. */
694 buffer_allocated = 4;
695 buffer = xmalloc (buffer_allocated);
702 tlen = MIN (len, 4 - (memaddr & 3));
703 offset = memaddr & 3;
705 errcode = target_xfer_memory (memaddr & ~3, buf, 4, 0, NULL);
708 /* The transfer request might have crossed the boundary to an
709 unallocated region of memory. Retry the transfer, requesting
713 errcode = target_xfer_memory (memaddr, buf, 1, 0, NULL);
718 if (bufptr - buffer + tlen > buffer_allocated)
721 bytes = bufptr - buffer;
722 buffer_allocated *= 2;
723 buffer = xrealloc (buffer, buffer_allocated);
724 bufptr = buffer + bytes;
727 for (i = 0; i < tlen; i++)
729 *bufptr++ = buf[i + offset];
730 if (buf[i + offset] == '\000')
732 nbytes_read += i + 1;
749 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
750 GDB's memory at MYADDR. Returns either 0 for success or an errno value
753 If an error occurs, no guarantee is made about the contents of the data at
754 MYADDR. In particular, the caller should not depend upon partial reads
755 filling the buffer with good data. There is no way for the caller to know
756 how much good data might have been transfered anyway. Callers that can
757 deal with partial reads should call target_read_memory_partial. */
760 target_read_memory (memaddr, myaddr, len)
765 return target_xfer_memory (memaddr, myaddr, len, 0, NULL);
769 target_read_memory_section (memaddr, myaddr, len, bfd_section)
773 asection *bfd_section;
775 return target_xfer_memory (memaddr, myaddr, len, 0, bfd_section);
778 /* Read LEN bytes of target memory at address MEMADDR, placing the results
779 in GDB's memory at MYADDR. Returns a count of the bytes actually read,
780 and optionally an errno value in the location pointed to by ERRNOPTR
781 if ERRNOPTR is non-null. */
784 target_read_memory_partial (memaddr, myaddr, len, errnoptr)
790 int nread; /* Number of bytes actually read. */
791 int errcode; /* Error from last read. */
793 /* First try a complete read. */
794 errcode = target_xfer_memory (memaddr, myaddr, len, 0, NULL);
802 /* Loop, reading one byte at a time until we get as much as we can. */
803 for (errcode = 0, nread = 0; len > 0 && errcode == 0; nread++, len--)
805 errcode = target_xfer_memory (memaddr++, myaddr++, 1, 0, NULL);
807 /* If an error, the last read was unsuccessful, so adjust count. */
813 if (errnoptr != NULL)
821 target_write_memory (memaddr, myaddr, len)
826 return target_xfer_memory (memaddr, myaddr, len, 1, NULL);
829 /* This variable is used to pass section information down to targets. This
830 *should* be done by adding an argument to the target_xfer_memory function
831 of all the targets, but I didn't feel like changing 50+ files. */
833 asection *target_memory_bfd_section = NULL;
835 /* Move memory to or from the targets. Iterate until all of it has
836 been moved, if necessary. The top target gets priority; anything
837 it doesn't want, is offered to the next one down, etc. Note the
838 business with curlen: if an early target says "no, but I have a
839 boundary overlapping this xfer" then we shorten what we offer to
840 the subsequent targets so the early guy will get a chance at the
841 tail before the subsequent ones do.
843 Result is 0 or errno value. */
846 target_xfer_memory (memaddr, myaddr, len, write, bfd_section)
851 asection *bfd_section;
855 struct target_ops *t;
856 struct target_stack_item *item;
858 /* Zero length requests are ok and require no work. */
862 target_memory_bfd_section = bfd_section;
864 /* to_xfer_memory is not guaranteed to set errno, even when it returns
868 /* The quick case is that the top target does it all. */
869 res = current_target.to_xfer_memory
870 (memaddr, myaddr, len, write, ¤t_target);
876 /* If res <= 0 then we call it again in the loop. Ah well. */
880 curlen = len; /* Want to do it all */
881 for (item = target_stack; item; item = item->next)
883 t = item->target_ops;
884 if (!t->to_has_memory)
887 res = t->to_xfer_memory (memaddr, myaddr, curlen, write, t);
889 break; /* Handled all or part of xfer */
890 if (t->to_has_all_memory)
896 /* If this address is for nonexistent memory,
897 read zeros if reading, or do nothing if writing. Return error. */
899 memset (myaddr, 0, len);
910 return 0; /* We managed to cover it all somehow. */
916 target_info (args, from_tty)
920 struct target_ops *t;
921 struct target_stack_item *item;
924 if (symfile_objfile != NULL)
925 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile->name);
927 #ifdef FILES_INFO_HOOK
928 if (FILES_INFO_HOOK ())
932 for (item = target_stack; item; item = item->next)
934 t = item->target_ops;
936 if (!t->to_has_memory)
939 if ((int)(t->to_stratum) <= (int)dummy_stratum)
942 printf_unfiltered("\tWhile running this, GDB does not access memory from...\n");
943 printf_unfiltered("%s:\n", t->to_longname);
944 (t->to_files_info)(t);
945 has_all_mem = t->to_has_all_memory;
949 /* This is to be called by the open routine before it does
953 target_preopen (from_tty)
958 if (target_has_execution)
960 if (query ("A program is being debugged already. Kill it? "))
963 error ("Program not killed.");
966 /* Calling target_kill may remove the target from the stack. But if
967 it doesn't (which seems like a win for UDI), remove it now. */
969 if (target_has_execution)
973 /* Detach a target after doing deferred register stores. */
976 target_detach (args, from_tty)
980 /* Handle any optimized stores to the inferior. */
981 #ifdef DO_DEFERRED_STORES
984 (current_target.to_detach) (args, from_tty);
988 target_link (modname, t_reloc)
992 if (STREQ(current_target.to_shortname, "rombug"))
994 (current_target.to_lookup_symbol) (modname, t_reloc);
996 error("Unable to link to %s and get relocation in rombug", modname);
999 *t_reloc = (CORE_ADDR)-1;
1002 /* Look through the list of possible targets for a target that can
1003 execute a run or attach command without any other data. This is
1004 used to locate the default process stratum.
1006 Result is always valid (error() is called for errors). */
1008 static struct target_ops *
1009 find_default_run_target (do_mesg)
1012 struct target_ops **t;
1013 struct target_ops *runable = NULL;
1018 for (t = target_structs; t < target_structs + target_struct_size;
1021 if ((*t)->to_can_run && target_can_run(*t))
1029 error ("Don't know how to %s. Try \"help target\".", do_mesg);
1035 find_default_attach (args, from_tty)
1039 struct target_ops *t;
1041 t = find_default_run_target("attach");
1042 (t->to_attach) (args, from_tty);
1047 find_default_require_attach (args, from_tty)
1051 struct target_ops *t;
1053 t = find_default_run_target("require_attach");
1054 (t->to_require_attach) (args, from_tty);
1059 find_default_require_detach (pid, args, from_tty)
1064 struct target_ops *t;
1066 t = find_default_run_target("require_detach");
1067 (t->to_require_detach) (pid, args, from_tty);
1072 find_default_create_inferior (exec_file, allargs, env)
1077 struct target_ops *t;
1079 t = find_default_run_target("run");
1080 (t->to_create_inferior) (exec_file, allargs, env);
1085 find_default_clone_and_follow_inferior (child_pid, followed_child)
1087 int *followed_child;
1089 struct target_ops *t;
1091 t = find_default_run_target("run");
1092 (t->to_clone_and_follow_inferior) (child_pid, followed_child);
1111 struct target_ops **t;
1112 struct target_ops *runable = NULL;
1117 for (t = target_structs; t < target_structs + target_struct_size;
1120 if ((*t)->to_stratum == core_stratum)
1127 return(count == 1 ? runable : NULL);
1130 /* The inferior process has died. Long live the inferior! */
1133 generic_mourn_inferior ()
1135 extern int show_breakpoint_hit_counts;
1139 breakpoint_init_inferior (inf_exited);
1140 registers_changed ();
1142 #ifdef CLEAR_DEFERRED_STORES
1143 /* Delete any pending stores to the inferior... */
1144 CLEAR_DEFERRED_STORES;
1147 reopen_exec_file ();
1148 reinit_frame_cache ();
1150 /* It is confusing to the user for ignore counts to stick around
1151 from previous runs of the inferior. So clear them. */
1152 /* However, it is more confusing for the ignore counts to disappear when
1153 using hit counts. So don't clear them if we're counting hits. */
1154 if (!show_breakpoint_hit_counts)
1155 breakpoint_clear_ignore_counts ();
1158 /* This table must match in order and size the signals in enum target_signal
1166 {"SIGHUP", "Hangup"},
1167 {"SIGINT", "Interrupt"},
1168 {"SIGQUIT", "Quit"},
1169 {"SIGILL", "Illegal instruction"},
1170 {"SIGTRAP", "Trace/breakpoint trap"},
1171 {"SIGABRT", "Aborted"},
1172 {"SIGEMT", "Emulation trap"},
1173 {"SIGFPE", "Arithmetic exception"},
1174 {"SIGKILL", "Killed"},
1175 {"SIGBUS", "Bus error"},
1176 {"SIGSEGV", "Segmentation fault"},
1177 {"SIGSYS", "Bad system call"},
1178 {"SIGPIPE", "Broken pipe"},
1179 {"SIGALRM", "Alarm clock"},
1180 {"SIGTERM", "Terminated"},
1181 {"SIGURG", "Urgent I/O condition"},
1182 {"SIGSTOP", "Stopped (signal)"},
1183 {"SIGTSTP", "Stopped (user)"},
1184 {"SIGCONT", "Continued"},
1185 {"SIGCHLD", "Child status changed"},
1186 {"SIGTTIN", "Stopped (tty input)"},
1187 {"SIGTTOU", "Stopped (tty output)"},
1188 {"SIGIO", "I/O possible"},
1189 {"SIGXCPU", "CPU time limit exceeded"},
1190 {"SIGXFSZ", "File size limit exceeded"},
1191 {"SIGVTALRM", "Virtual timer expired"},
1192 {"SIGPROF", "Profiling timer expired"},
1193 {"SIGWINCH", "Window size changed"},
1194 {"SIGLOST", "Resource lost"},
1195 {"SIGUSR1", "User defined signal 1"},
1196 {"SIGUSR2", "User defined signal 2"},
1197 {"SIGPWR", "Power fail/restart"},
1198 {"SIGPOLL", "Pollable event occurred"},
1199 {"SIGWIND", "SIGWIND"},
1200 {"SIGPHONE", "SIGPHONE"},
1201 {"SIGWAITING", "Process's LWPs are blocked"},
1202 {"SIGLWP", "Signal LWP"},
1203 {"SIGDANGER", "Swap space dangerously low"},
1204 {"SIGGRANT", "Monitor mode granted"},
1205 {"SIGRETRACT", "Need to relinquish monitor mode"},
1206 {"SIGMSG", "Monitor mode data available"},
1207 {"SIGSOUND", "Sound completed"},
1208 {"SIGSAK", "Secure attention"},
1209 {"SIGPRIO", "SIGPRIO"},
1210 {"SIG33", "Real-time event 33"},
1211 {"SIG34", "Real-time event 34"},
1212 {"SIG35", "Real-time event 35"},
1213 {"SIG36", "Real-time event 36"},
1214 {"SIG37", "Real-time event 37"},
1215 {"SIG38", "Real-time event 38"},
1216 {"SIG39", "Real-time event 39"},
1217 {"SIG40", "Real-time event 40"},
1218 {"SIG41", "Real-time event 41"},
1219 {"SIG42", "Real-time event 42"},
1220 {"SIG43", "Real-time event 43"},
1221 {"SIG44", "Real-time event 44"},
1222 {"SIG45", "Real-time event 45"},
1223 {"SIG46", "Real-time event 46"},
1224 {"SIG47", "Real-time event 47"},
1225 {"SIG48", "Real-time event 48"},
1226 {"SIG49", "Real-time event 49"},
1227 {"SIG50", "Real-time event 50"},
1228 {"SIG51", "Real-time event 51"},
1229 {"SIG52", "Real-time event 52"},
1230 {"SIG53", "Real-time event 53"},
1231 {"SIG54", "Real-time event 54"},
1232 {"SIG55", "Real-time event 55"},
1233 {"SIG56", "Real-time event 56"},
1234 {"SIG57", "Real-time event 57"},
1235 {"SIG58", "Real-time event 58"},
1236 {"SIG59", "Real-time event 59"},
1237 {"SIG60", "Real-time event 60"},
1238 {"SIG61", "Real-time event 61"},
1239 {"SIG62", "Real-time event 62"},
1240 {"SIG63", "Real-time event 63"},
1242 #if defined(MACH) || defined(__MACH__)
1243 /* Mach exceptions */
1244 {"EXC_BAD_ACCESS", "Could not access memory"},
1245 {"EXC_BAD_INSTRUCTION", "Illegal instruction/operand"},
1246 {"EXC_ARITHMETIC", "Arithmetic exception"},
1247 {"EXC_EMULATION", "Emulation instruction"},
1248 {"EXC_SOFTWARE", "Software generated exception"},
1249 {"EXC_BREAKPOINT", "Breakpoint"},
1251 {NULL, "Unknown signal"},
1252 {NULL, "Internal error: printing TARGET_SIGNAL_DEFAULT"},
1254 /* Last entry, used to check whether the table is the right size. */
1255 {NULL, "TARGET_SIGNAL_MAGIC"}
1258 /* Return the string for a signal. */
1260 target_signal_to_string (sig)
1261 enum target_signal sig;
1263 return signals[sig].string;
1266 /* Return the name for a signal. */
1268 target_signal_to_name (sig)
1269 enum target_signal sig;
1271 if (sig == TARGET_SIGNAL_UNKNOWN)
1272 /* I think the code which prints this will always print it along with
1273 the string, so no need to be verbose. */
1275 return signals[sig].name;
1278 /* Given a name, return its signal. */
1280 target_signal_from_name (name)
1283 enum target_signal sig;
1285 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
1286 for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
1287 questionable; seems like by now people should call it SIGABRT
1290 /* This ugly cast brought to you by the native VAX compiler. */
1291 for (sig = TARGET_SIGNAL_HUP;
1292 signals[sig].name != NULL;
1293 sig = (enum target_signal)((int)sig + 1))
1294 if (STREQ (name, signals[sig].name))
1296 return TARGET_SIGNAL_UNKNOWN;
1299 /* The following functions are to help certain targets deal
1300 with the signal/waitstatus stuff. They could just as well be in
1301 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
1303 /* Convert host signal to our signals. */
1305 target_signal_from_host (hostsig)
1308 /* A switch statement would make sense but would require special kludges
1309 to deal with the cases where more than one signal has the same number. */
1311 if (hostsig == 0) return TARGET_SIGNAL_0;
1313 #if defined (SIGHUP)
1314 if (hostsig == SIGHUP) return TARGET_SIGNAL_HUP;
1316 #if defined (SIGINT)
1317 if (hostsig == SIGINT) return TARGET_SIGNAL_INT;
1319 #if defined (SIGQUIT)
1320 if (hostsig == SIGQUIT) return TARGET_SIGNAL_QUIT;
1322 #if defined (SIGILL)
1323 if (hostsig == SIGILL) return TARGET_SIGNAL_ILL;
1325 #if defined (SIGTRAP)
1326 if (hostsig == SIGTRAP) return TARGET_SIGNAL_TRAP;
1328 #if defined (SIGABRT)
1329 if (hostsig == SIGABRT) return TARGET_SIGNAL_ABRT;
1331 #if defined (SIGEMT)
1332 if (hostsig == SIGEMT) return TARGET_SIGNAL_EMT;
1334 #if defined (SIGFPE)
1335 if (hostsig == SIGFPE) return TARGET_SIGNAL_FPE;
1337 #if defined (SIGKILL)
1338 if (hostsig == SIGKILL) return TARGET_SIGNAL_KILL;
1340 #if defined (SIGBUS)
1341 if (hostsig == SIGBUS) return TARGET_SIGNAL_BUS;
1343 #if defined (SIGSEGV)
1344 if (hostsig == SIGSEGV) return TARGET_SIGNAL_SEGV;
1346 #if defined (SIGSYS)
1347 if (hostsig == SIGSYS) return TARGET_SIGNAL_SYS;
1349 #if defined (SIGPIPE)
1350 if (hostsig == SIGPIPE) return TARGET_SIGNAL_PIPE;
1352 #if defined (SIGALRM)
1353 if (hostsig == SIGALRM) return TARGET_SIGNAL_ALRM;
1355 #if defined (SIGTERM)
1356 if (hostsig == SIGTERM) return TARGET_SIGNAL_TERM;
1358 #if defined (SIGUSR1)
1359 if (hostsig == SIGUSR1) return TARGET_SIGNAL_USR1;
1361 #if defined (SIGUSR2)
1362 if (hostsig == SIGUSR2) return TARGET_SIGNAL_USR2;
1364 #if defined (SIGCLD)
1365 if (hostsig == SIGCLD) return TARGET_SIGNAL_CHLD;
1367 #if defined (SIGCHLD)
1368 if (hostsig == SIGCHLD) return TARGET_SIGNAL_CHLD;
1370 #if defined (SIGPWR)
1371 if (hostsig == SIGPWR) return TARGET_SIGNAL_PWR;
1373 #if defined (SIGWINCH)
1374 if (hostsig == SIGWINCH) return TARGET_SIGNAL_WINCH;
1376 #if defined (SIGURG)
1377 if (hostsig == SIGURG) return TARGET_SIGNAL_URG;
1380 if (hostsig == SIGIO) return TARGET_SIGNAL_IO;
1382 #if defined (SIGPOLL)
1383 if (hostsig == SIGPOLL) return TARGET_SIGNAL_POLL;
1385 #if defined (SIGSTOP)
1386 if (hostsig == SIGSTOP) return TARGET_SIGNAL_STOP;
1388 #if defined (SIGTSTP)
1389 if (hostsig == SIGTSTP) return TARGET_SIGNAL_TSTP;
1391 #if defined (SIGCONT)
1392 if (hostsig == SIGCONT) return TARGET_SIGNAL_CONT;
1394 #if defined (SIGTTIN)
1395 if (hostsig == SIGTTIN) return TARGET_SIGNAL_TTIN;
1397 #if defined (SIGTTOU)
1398 if (hostsig == SIGTTOU) return TARGET_SIGNAL_TTOU;
1400 #if defined (SIGVTALRM)
1401 if (hostsig == SIGVTALRM) return TARGET_SIGNAL_VTALRM;
1403 #if defined (SIGPROF)
1404 if (hostsig == SIGPROF) return TARGET_SIGNAL_PROF;
1406 #if defined (SIGXCPU)
1407 if (hostsig == SIGXCPU) return TARGET_SIGNAL_XCPU;
1409 #if defined (SIGXFSZ)
1410 if (hostsig == SIGXFSZ) return TARGET_SIGNAL_XFSZ;
1412 #if defined (SIGWIND)
1413 if (hostsig == SIGWIND) return TARGET_SIGNAL_WIND;
1415 #if defined (SIGPHONE)
1416 if (hostsig == SIGPHONE) return TARGET_SIGNAL_PHONE;
1418 #if defined (SIGLOST)
1419 if (hostsig == SIGLOST) return TARGET_SIGNAL_LOST;
1421 #if defined (SIGWAITING)
1422 if (hostsig == SIGWAITING) return TARGET_SIGNAL_WAITING;
1424 #if defined (SIGLWP)
1425 if (hostsig == SIGLWP) return TARGET_SIGNAL_LWP;
1427 #if defined (SIGDANGER)
1428 if (hostsig == SIGDANGER) return TARGET_SIGNAL_DANGER;
1430 #if defined (SIGGRANT)
1431 if (hostsig == SIGGRANT) return TARGET_SIGNAL_GRANT;
1433 #if defined (SIGRETRACT)
1434 if (hostsig == SIGRETRACT) return TARGET_SIGNAL_RETRACT;
1436 #if defined (SIGMSG)
1437 if (hostsig == SIGMSG) return TARGET_SIGNAL_MSG;
1439 #if defined (SIGSOUND)
1440 if (hostsig == SIGSOUND) return TARGET_SIGNAL_SOUND;
1442 #if defined (SIGSAK)
1443 if (hostsig == SIGSAK) return TARGET_SIGNAL_SAK;
1445 #if defined (SIGPRIO)
1446 if (hostsig == SIGPRIO) return TARGET_SIGNAL_PRIO;
1449 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1450 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1451 if (hostsig == _NSIG + EXC_BAD_ACCESS) return TARGET_EXC_BAD_ACCESS;
1453 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1454 if (hostsig == _NSIG + EXC_BAD_INSTRUCTION) return TARGET_EXC_BAD_INSTRUCTION;
1456 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1457 if (hostsig == _NSIG + EXC_ARITHMETIC) return TARGET_EXC_ARITHMETIC;
1459 #if defined (EXC_EMULATION) && defined (_NSIG)
1460 if (hostsig == _NSIG + EXC_EMULATION) return TARGET_EXC_EMULATION;
1462 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1463 if (hostsig == _NSIG + EXC_SOFTWARE) return TARGET_EXC_SOFTWARE;
1465 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1466 if (hostsig == _NSIG + EXC_BREAKPOINT) return TARGET_EXC_BREAKPOINT;
1469 #if defined (REALTIME_LO)
1470 if (hostsig >= REALTIME_LO && hostsig < REALTIME_HI)
1471 return (enum target_signal)
1472 (hostsig - 33 + (int) TARGET_SIGNAL_REALTIME_33);
1474 return TARGET_SIGNAL_UNKNOWN;
1478 target_signal_to_host (oursig)
1479 enum target_signal oursig;
1483 case TARGET_SIGNAL_0: return 0;
1485 #if defined (SIGHUP)
1486 case TARGET_SIGNAL_HUP: return SIGHUP;
1488 #if defined (SIGINT)
1489 case TARGET_SIGNAL_INT: return SIGINT;
1491 #if defined (SIGQUIT)
1492 case TARGET_SIGNAL_QUIT: return SIGQUIT;
1494 #if defined (SIGILL)
1495 case TARGET_SIGNAL_ILL: return SIGILL;
1497 #if defined (SIGTRAP)
1498 case TARGET_SIGNAL_TRAP: return SIGTRAP;
1500 #if defined (SIGABRT)
1501 case TARGET_SIGNAL_ABRT: return SIGABRT;
1503 #if defined (SIGEMT)
1504 case TARGET_SIGNAL_EMT: return SIGEMT;
1506 #if defined (SIGFPE)
1507 case TARGET_SIGNAL_FPE: return SIGFPE;
1509 #if defined (SIGKILL)
1510 case TARGET_SIGNAL_KILL: return SIGKILL;
1512 #if defined (SIGBUS)
1513 case TARGET_SIGNAL_BUS: return SIGBUS;
1515 #if defined (SIGSEGV)
1516 case TARGET_SIGNAL_SEGV: return SIGSEGV;
1518 #if defined (SIGSYS)
1519 case TARGET_SIGNAL_SYS: return SIGSYS;
1521 #if defined (SIGPIPE)
1522 case TARGET_SIGNAL_PIPE: return SIGPIPE;
1524 #if defined (SIGALRM)
1525 case TARGET_SIGNAL_ALRM: return SIGALRM;
1527 #if defined (SIGTERM)
1528 case TARGET_SIGNAL_TERM: return SIGTERM;
1530 #if defined (SIGUSR1)
1531 case TARGET_SIGNAL_USR1: return SIGUSR1;
1533 #if defined (SIGUSR2)
1534 case TARGET_SIGNAL_USR2: return SIGUSR2;
1536 #if defined (SIGCHLD) || defined (SIGCLD)
1537 case TARGET_SIGNAL_CHLD:
1538 #if defined (SIGCHLD)
1543 #endif /* SIGCLD or SIGCHLD */
1544 #if defined (SIGPWR)
1545 case TARGET_SIGNAL_PWR: return SIGPWR;
1547 #if defined (SIGWINCH)
1548 case TARGET_SIGNAL_WINCH: return SIGWINCH;
1550 #if defined (SIGURG)
1551 case TARGET_SIGNAL_URG: return SIGURG;
1554 case TARGET_SIGNAL_IO: return SIGIO;
1556 #if defined (SIGPOLL)
1557 case TARGET_SIGNAL_POLL: return SIGPOLL;
1559 #if defined (SIGSTOP)
1560 case TARGET_SIGNAL_STOP: return SIGSTOP;
1562 #if defined (SIGTSTP)
1563 case TARGET_SIGNAL_TSTP: return SIGTSTP;
1565 #if defined (SIGCONT)
1566 case TARGET_SIGNAL_CONT: return SIGCONT;
1568 #if defined (SIGTTIN)
1569 case TARGET_SIGNAL_TTIN: return SIGTTIN;
1571 #if defined (SIGTTOU)
1572 case TARGET_SIGNAL_TTOU: return SIGTTOU;
1574 #if defined (SIGVTALRM)
1575 case TARGET_SIGNAL_VTALRM: return SIGVTALRM;
1577 #if defined (SIGPROF)
1578 case TARGET_SIGNAL_PROF: return SIGPROF;
1580 #if defined (SIGXCPU)
1581 case TARGET_SIGNAL_XCPU: return SIGXCPU;
1583 #if defined (SIGXFSZ)
1584 case TARGET_SIGNAL_XFSZ: return SIGXFSZ;
1586 #if defined (SIGWIND)
1587 case TARGET_SIGNAL_WIND: return SIGWIND;
1589 #if defined (SIGPHONE)
1590 case TARGET_SIGNAL_PHONE: return SIGPHONE;
1592 #if defined (SIGLOST)
1593 case TARGET_SIGNAL_LOST: return SIGLOST;
1595 #if defined (SIGWAITING)
1596 case TARGET_SIGNAL_WAITING: return SIGWAITING;
1598 #if defined (SIGLWP)
1599 case TARGET_SIGNAL_LWP: return SIGLWP;
1601 #if defined (SIGDANGER)
1602 case TARGET_SIGNAL_DANGER: return SIGDANGER;
1604 #if defined (SIGGRANT)
1605 case TARGET_SIGNAL_GRANT: return SIGGRANT;
1607 #if defined (SIGRETRACT)
1608 case TARGET_SIGNAL_RETRACT: return SIGRETRACT;
1610 #if defined (SIGMSG)
1611 case TARGET_SIGNAL_MSG: return SIGMSG;
1613 #if defined (SIGSOUND)
1614 case TARGET_SIGNAL_SOUND: return SIGSOUND;
1616 #if defined (SIGSAK)
1617 case TARGET_SIGNAL_SAK: return SIGSAK;
1619 #if defined (SIGPRIO)
1620 case TARGET_SIGNAL_PRIO: return SIGPRIO;
1623 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1624 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1625 case TARGET_EXC_BAD_ACCESS: return _NSIG + EXC_BAD_ACCESS;
1627 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1628 case TARGET_EXC_BAD_INSTRUCTION: return _NSIG + EXC_BAD_INSTRUCTION;
1630 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1631 case TARGET_EXC_ARITHMETIC: return _NSIG + EXC_ARITHMETIC;
1633 #if defined (EXC_EMULATION) && defined (_NSIG)
1634 case TARGET_EXC_EMULATION: return _NSIG + EXC_EMULATION;
1636 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1637 case TARGET_EXC_SOFTWARE: return _NSIG + EXC_SOFTWARE;
1639 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1640 case TARGET_EXC_BREAKPOINT: return _NSIG + EXC_BREAKPOINT;
1644 #if defined (REALTIME_LO)
1645 if (oursig >= TARGET_SIGNAL_REALTIME_33
1646 && oursig <= TARGET_SIGNAL_REALTIME_63)
1649 (int)oursig - (int)TARGET_SIGNAL_REALTIME_33 + REALTIME_LO;
1650 if (retsig < REALTIME_HI)
1654 /* The user might be trying to do "signal SIGSAK" where this system
1655 doesn't have SIGSAK. */
1656 warning ("Signal %s does not exist on this system.\n",
1657 target_signal_to_name (oursig));
1662 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1663 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1664 translation of that in OURSTATUS. */
1666 store_waitstatus (ourstatus, hoststatus)
1667 struct target_waitstatus *ourstatus;
1670 #ifdef CHILD_SPECIAL_WAITSTATUS
1671 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1672 if it wants to deal with hoststatus. */
1673 if (CHILD_SPECIAL_WAITSTATUS (ourstatus, hoststatus))
1677 if (WIFEXITED (hoststatus))
1679 ourstatus->kind = TARGET_WAITKIND_EXITED;
1680 ourstatus->value.integer = WEXITSTATUS (hoststatus);
1682 else if (!WIFSTOPPED (hoststatus))
1684 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
1685 ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus));
1689 ourstatus->kind = TARGET_WAITKIND_STOPPED;
1690 ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus));
1694 /* In some circumstances we allow a command to specify a numeric
1695 signal. The idea is to keep these circumstances limited so that
1696 users (and scripts) develop portable habits. For comparison,
1697 POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
1698 numeric signal at all is obscelescent. We are slightly more
1699 lenient and allow 1-15 which should match host signal numbers on
1700 most systems. Use of symbolic signal names is strongly encouraged. */
1703 target_signal_from_command (num)
1706 if (num >= 1 && num <= 15)
1707 return (enum target_signal)num;
1708 error ("Only signals 1-15 are valid as numeric signals.\n\
1709 Use \"info signals\" for a list of symbolic signals.");
1712 /* Returns zero to leave the inferior alone, one to interrupt it. */
1713 int (*target_activity_function) PARAMS ((void));
1714 int target_activity_fd;
1716 /* Convert a normal process ID to a string. Returns the string in a static
1720 normal_pid_to_str (pid)
1723 static char buf[30];
1725 if (STREQ (current_target.to_shortname, "remote"))
1726 sprintf (buf, "thread %d\0", pid);
1728 sprintf (buf, "process %d\0", pid);
1733 /* Some targets (such as ttrace-based HPUX) don't allow us to request
1734 notification of inferior events such as fork and vork immediately
1735 after the inferior is created. (This because of how gdb gets an
1736 inferior created via invoking a shell to do it. In such a scenario,
1737 if the shell init file has commands in it, the shell will fork and
1738 exec for each of those commands, and we will see each such fork
1741 This function is used by all targets that allow us to request
1742 notification of forks, etc at inferior creation time; e.g., in
1743 target_acknowledge_forked_child.
1746 normal_target_post_startup_inferior (pid)
1749 /* This space intentionally left blank. */
1752 /* Set up the handful of non-empty slots needed by the dummy target
1756 init_dummy_target ()
1758 dummy_target.to_shortname = "None";
1759 dummy_target.to_longname = "None";
1760 dummy_target.to_doc = "";
1761 dummy_target.to_attach = find_default_attach;
1762 dummy_target.to_require_attach = find_default_require_attach;
1763 dummy_target.to_require_detach = find_default_require_detach;
1764 dummy_target.to_create_inferior = find_default_create_inferior;
1765 dummy_target.to_clone_and_follow_inferior = find_default_clone_and_follow_inferior;
1766 dummy_target.to_stratum = dummy_stratum;
1767 dummy_target.to_magic = OPS_MAGIC;
1771 #ifdef MAINTENANCE_CMDS
1772 static struct target_ops debug_target;
1775 debug_to_open (args, from_tty)
1779 debug_target.to_open (args, from_tty);
1781 fprintf_unfiltered (gdb_stderr, "target_open (%s, %d)\n", args, from_tty);
1785 debug_to_close (quitting)
1788 debug_target.to_close (quitting);
1790 fprintf_unfiltered (gdb_stderr, "target_close (%d)\n", quitting);
1794 debug_to_attach (args, from_tty)
1798 debug_target.to_attach (args, from_tty);
1800 fprintf_unfiltered (gdb_stderr, "target_attach (%s, %d)\n", args, from_tty);
1805 debug_to_post_attach (pid)
1808 debug_target.to_post_attach (pid);
1810 fprintf_unfiltered (gdb_stderr, "target_post_attach (%d)\n", pid);
1814 debug_to_require_attach (args, from_tty)
1818 debug_target.to_require_attach (args, from_tty);
1820 fprintf_unfiltered (gdb_stderr,
1821 "target_require_attach (%s, %d)\n", args, from_tty);
1825 debug_to_detach (args, from_tty)
1829 debug_target.to_detach (args, from_tty);
1831 fprintf_unfiltered (gdb_stderr, "target_detach (%s, %d)\n", args, from_tty);
1835 debug_to_require_detach (pid, args, from_tty)
1840 debug_target.to_require_detach (pid, args, from_tty);
1842 fprintf_unfiltered (gdb_stderr,
1843 "target_require_detach (%d, %s, %d)\n", pid, args, from_tty);
1847 debug_to_resume (pid, step, siggnal)
1850 enum target_signal siggnal;
1852 debug_target.to_resume (pid, step, siggnal);
1854 fprintf_unfiltered (gdb_stderr, "target_resume (%d, %s, %s)\n", pid,
1855 step ? "step" : "continue",
1856 target_signal_to_name (siggnal));
1860 debug_to_wait (pid, status)
1862 struct target_waitstatus *status;
1866 retval = debug_target.to_wait (pid, status);
1868 fprintf_unfiltered (gdb_stderr,
1869 "target_wait (%d, status) = %d, ", pid, retval);
1870 fprintf_unfiltered (gdb_stderr, "status->kind = ");
1871 switch (status->kind)
1873 case TARGET_WAITKIND_EXITED:
1874 fprintf_unfiltered (gdb_stderr, "exited, status = %d\n",
1875 status->value.integer);
1877 case TARGET_WAITKIND_STOPPED:
1878 fprintf_unfiltered (gdb_stderr, "stopped, signal = %s\n",
1879 target_signal_to_name (status->value.sig));
1881 case TARGET_WAITKIND_SIGNALLED:
1882 fprintf_unfiltered (gdb_stderr, "signalled, signal = %s\n",
1883 target_signal_to_name (status->value.sig));
1885 case TARGET_WAITKIND_LOADED:
1886 fprintf_unfiltered (gdb_stderr, "loaded\n");
1888 case TARGET_WAITKIND_FORKED:
1889 fprintf_unfiltered (gdb_stderr, "forked\n");
1891 case TARGET_WAITKIND_VFORKED:
1892 fprintf_unfiltered (gdb_stderr, "vforked\n");
1894 case TARGET_WAITKIND_EXECD:
1895 fprintf_unfiltered (gdb_stderr, "execd\n");
1897 case TARGET_WAITKIND_SPURIOUS:
1898 fprintf_unfiltered (gdb_stderr, "spurious\n");
1901 fprintf_unfiltered (gdb_stderr, "unknown???\n");
1909 debug_to_post_wait (pid, status)
1913 debug_target.to_post_wait (pid, status);
1915 fprintf_unfiltered (gdb_stderr, "target_post_wait (%d, %d)\n",
1920 debug_to_fetch_registers (regno)
1923 debug_target.to_fetch_registers (regno);
1925 fprintf_unfiltered (gdb_stderr, "target_fetch_registers (%s)",
1926 regno != -1 ? REGISTER_NAME (regno) : "-1");
1928 fprintf_unfiltered (gdb_stderr, " = 0x%x %d",
1929 (unsigned long) read_register (regno),
1930 read_register (regno));
1931 fprintf_unfiltered (gdb_stderr, "\n");
1935 debug_to_store_registers (regno)
1938 debug_target.to_store_registers (regno);
1940 if (regno >= 0 && regno < NUM_REGS)
1941 fprintf_unfiltered (gdb_stderr, "target_store_registers (%s) = 0x%x %d\n",
1942 REGISTER_NAME (regno),
1943 (unsigned long) read_register (regno),
1944 (unsigned long) read_register (regno));
1946 fprintf_unfiltered (gdb_stderr, "target_store_registers (%d)\n", regno);
1950 debug_to_prepare_to_store ()
1952 debug_target.to_prepare_to_store ();
1954 fprintf_unfiltered (gdb_stderr, "target_prepare_to_store ()\n");
1958 debug_to_xfer_memory (memaddr, myaddr, len, write, target)
1963 struct target_ops *target;
1967 retval = debug_target.to_xfer_memory (memaddr, myaddr, len, write, target);
1969 fprintf_unfiltered (gdb_stderr,
1970 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
1971 (unsigned int) memaddr, /* possable truncate long long */
1972 len, write ? "write" : "read", retval);
1980 fputs_unfiltered (", bytes =", gdb_stderr);
1981 for (i = 0; i < retval; i++)
1983 if ((((long) &(myaddr[i])) & 0xf) == 0)
1984 fprintf_unfiltered (gdb_stderr, "\n");
1985 fprintf_unfiltered (gdb_stderr, " %02x", myaddr[i] & 0xff);
1989 fputc_unfiltered ('\n', gdb_stderr);
1995 debug_to_files_info (target)
1996 struct target_ops *target;
1998 debug_target.to_files_info (target);
2000 fprintf_unfiltered (gdb_stderr, "target_files_info (xxx)\n");
2004 debug_to_insert_breakpoint (addr, save)
2010 retval = debug_target.to_insert_breakpoint (addr, save);
2012 fprintf_unfiltered (gdb_stderr,
2013 "target_insert_breakpoint (0x%x, xxx) = %d\n",
2014 (unsigned long) addr, retval);
2019 debug_to_remove_breakpoint (addr, save)
2025 retval = debug_target.to_remove_breakpoint (addr, save);
2027 fprintf_unfiltered (gdb_stderr,
2028 "target_remove_breakpoint (0x%x, xxx) = %d\n",
2029 (unsigned long)addr, retval);
2034 debug_to_terminal_init ()
2036 debug_target.to_terminal_init ();
2038 fprintf_unfiltered (gdb_stderr, "target_terminal_init ()\n");
2042 debug_to_terminal_inferior ()
2044 debug_target.to_terminal_inferior ();
2046 fprintf_unfiltered (gdb_stderr, "target_terminal_inferior ()\n");
2050 debug_to_terminal_ours_for_output ()
2052 debug_target.to_terminal_ours_for_output ();
2054 fprintf_unfiltered (gdb_stderr, "target_terminal_ours_for_output ()\n");
2058 debug_to_terminal_ours ()
2060 debug_target.to_terminal_ours ();
2062 fprintf_unfiltered (gdb_stderr, "target_terminal_ours ()\n");
2066 debug_to_terminal_info (arg, from_tty)
2070 debug_target.to_terminal_info (arg, from_tty);
2072 fprintf_unfiltered (gdb_stderr, "target_terminal_info (%s, %d)\n", arg,
2079 debug_target.to_kill ();
2081 fprintf_unfiltered (gdb_stderr, "target_kill ()\n");
2085 debug_to_load (args, from_tty)
2089 debug_target.to_load (args, from_tty);
2091 fprintf_unfiltered (gdb_stderr, "target_load (%s, %d)\n", args, from_tty);
2095 debug_to_lookup_symbol (name, addrp)
2101 retval = debug_target.to_lookup_symbol (name, addrp);
2103 fprintf_unfiltered (gdb_stderr, "target_lookup_symbol (%s, xxx)\n", name);
2109 debug_to_create_inferior (exec_file, args, env)
2114 debug_target.to_create_inferior (exec_file, args, env);
2116 fprintf_unfiltered (gdb_stderr, "target_create_inferior (%s, %s, xxx)\n",
2121 debug_to_post_startup_inferior (pid)
2124 debug_target.to_post_startup_inferior (pid);
2126 fprintf_unfiltered (gdb_stderr, "target_post_startup_inferior (%d)\n",
2131 debug_to_acknowledge_created_inferior (pid)
2134 debug_target.to_acknowledge_created_inferior (pid);
2136 fprintf_unfiltered (gdb_stderr, "target_acknowledge_created_inferior (%d)\n",
2141 debug_to_clone_and_follow_inferior (child_pid, followed_child)
2143 int *followed_child;
2145 debug_target.to_clone_and_follow_inferior (child_pid, followed_child);
2147 fprintf_unfiltered (gdb_stderr,
2148 "target_clone_and_follow_inferior (%d, %d)\n",
2149 child_pid, *followed_child);
2153 debug_to_post_follow_inferior_by_clone ()
2155 debug_target.to_post_follow_inferior_by_clone ();
2157 fprintf_unfiltered (gdb_stderr, "target_post_follow_inferior_by_clone ()\n");
2161 debug_to_insert_fork_catchpoint (pid)
2166 retval = debug_target.to_insert_fork_catchpoint (pid);
2168 fprintf_unfiltered (gdb_stderr, "target_insert_fork_catchpoint (%d) = %d\n",
2175 debug_to_remove_fork_catchpoint (pid)
2180 retval = debug_target.to_remove_fork_catchpoint (pid);
2182 fprintf_unfiltered (gdb_stderr, "target_remove_fork_catchpoint (%d) = %d\n",
2189 debug_to_insert_vfork_catchpoint (pid)
2194 retval = debug_target.to_insert_vfork_catchpoint (pid);
2196 fprintf_unfiltered (gdb_stderr, "target_insert_vfork_catchpoint (%d)= %d\n",
2203 debug_to_remove_vfork_catchpoint (pid)
2208 retval = debug_target.to_remove_vfork_catchpoint (pid);
2210 fprintf_unfiltered (gdb_stderr, "target_remove_vfork_catchpoint (%d) = %d\n",
2217 debug_to_has_forked (pid, child_pid)
2223 has_forked = debug_target.to_has_forked (pid, child_pid);
2225 fprintf_unfiltered (gdb_stderr, "target_has_forked (%d, %d) = %d\n",
2226 pid, *child_pid, has_forked);
2232 debug_to_has_vforked (pid, child_pid)
2238 has_vforked = debug_target.to_has_vforked (pid, child_pid);
2240 fprintf_unfiltered (gdb_stderr, "target_has_vforked (%d, %d) = %d\n",
2241 pid, *child_pid, has_vforked);
2247 debug_to_can_follow_vfork_prior_to_exec ()
2249 int can_immediately_follow_vfork;
2251 can_immediately_follow_vfork = debug_target.to_can_follow_vfork_prior_to_exec ();
2253 fprintf_unfiltered (gdb_stderr, "target_can_follow_vfork_prior_to_exec () = %d\n",
2254 can_immediately_follow_vfork);
2256 return can_immediately_follow_vfork;
2260 debug_to_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child)
2262 int followed_parent;
2266 debug_target.to_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child);
2268 fprintf_unfiltered (gdb_stderr,
2269 "target_post_follow_vfork (%d, %d, %d, %d)\n",
2270 parent_pid, followed_parent, child_pid, followed_child);
2274 debug_to_insert_exec_catchpoint (pid)
2279 retval = debug_target.to_insert_exec_catchpoint (pid);
2281 fprintf_unfiltered (gdb_stderr, "target_insert_exec_catchpoint (%d) = %d\n",
2288 debug_to_remove_exec_catchpoint (pid)
2293 retval = debug_target.to_remove_exec_catchpoint (pid);
2295 fprintf_unfiltered (gdb_stderr, "target_remove_exec_catchpoint (%d) = %d\n",
2302 debug_to_has_execd (pid, execd_pathname)
2304 char ** execd_pathname;
2308 has_execd = debug_target.to_has_execd (pid, execd_pathname);
2310 fprintf_unfiltered (gdb_stderr, "target_has_execd (%d, %s) = %d\n",
2311 pid, *execd_pathname, has_execd);
2317 debug_to_reported_exec_events_per_exec_call ()
2319 int reported_exec_events;
2321 reported_exec_events = debug_target.to_reported_exec_events_per_exec_call ();
2323 fprintf_unfiltered (gdb_stderr,
2324 "target_reported_exec_events_per_exec_call () = %d\n",
2325 reported_exec_events);
2327 return reported_exec_events;
2331 debug_to_has_syscall_event (pid, kind, syscall_id)
2333 enum target_waitkind * kind;
2336 int has_syscall_event;
2337 char * kind_spelling = "??";
2339 has_syscall_event = debug_target.to_has_syscall_event (pid, kind, syscall_id);
2340 if (has_syscall_event)
2344 case TARGET_WAITKIND_SYSCALL_ENTRY:
2345 kind_spelling = "SYSCALL_ENTRY";
2347 case TARGET_WAITKIND_SYSCALL_RETURN:
2348 kind_spelling = "SYSCALL_RETURN";
2355 fprintf_unfiltered (gdb_stderr,
2356 "target_has_syscall_event (%d, %s, %d) = %d\n",
2357 pid, kind_spelling, *syscall_id, has_syscall_event);
2359 return has_syscall_event;
2363 debug_to_has_exited (pid, wait_status, exit_status)
2370 has_exited = debug_target.to_has_exited (pid, wait_status, exit_status);
2372 fprintf_unfiltered (gdb_stderr, "target_has_exited (%d, %d, %d) = %d\n",
2373 pid, wait_status, *exit_status, has_exited);
2379 debug_to_mourn_inferior ()
2381 debug_target.to_mourn_inferior ();
2383 fprintf_unfiltered (gdb_stderr, "target_mourn_inferior ()\n");
2391 retval = debug_target.to_can_run ();
2393 fprintf_unfiltered (gdb_stderr, "target_can_run () = %d\n", retval);
2399 debug_to_notice_signals (pid)
2402 debug_target.to_notice_signals (pid);
2404 fprintf_unfiltered (gdb_stderr, "target_notice_signals (%d)\n", pid);
2408 debug_to_thread_alive (pid)
2413 retval = debug_target.to_thread_alive (pid);
2415 fprintf_unfiltered (gdb_stderr, "target_thread_alive (%d) = %d\n",
2424 debug_target.to_stop ();
2426 fprintf_unfiltered (gdb_stderr, "target_stop ()\n");
2430 debug_to_query (type, req, resp, siz)
2438 retval = debug_target.to_query (type, req, resp, siz);
2440 fprintf_unfiltered (gdb_stderr, "target_query (%c, %s, %s, %d) = %d\n", type, req, resp, *siz, retval);
2445 static struct symtab_and_line *
2446 debug_to_enable_exception_callback (kind, enable)
2447 enum exception_event_kind kind;
2450 debug_target.to_enable_exception_callback (kind, enable);
2452 fprintf_unfiltered (gdb_stderr,
2453 "target get_exception_callback_sal (%d, %d)\n",
2457 static struct exception_event_record *
2458 debug_to_get_current_exception_event ()
2460 debug_target.to_get_current_exception_event();
2462 fprintf_unfiltered (gdb_stderr, "target get_current_exception_event ()\n");
2466 debug_to_pid_to_exec_file (pid)
2471 exec_file = debug_target.to_pid_to_exec_file (pid);
2473 fprintf_unfiltered (gdb_stderr, "target_pid_to_exec_file (%d) = %s\n",
2480 debug_to_core_file_to_sym_file (core)
2485 sym_file = debug_target.to_core_file_to_sym_file (core);
2487 fprintf_unfiltered (gdb_stderr, "target_core_file_to_sym_file (%s) = %s\n",
2494 setup_target_debug ()
2496 memcpy (&debug_target, ¤t_target, sizeof debug_target);
2498 current_target.to_open = debug_to_open;
2499 current_target.to_close = debug_to_close;
2500 current_target.to_attach = debug_to_attach;
2501 current_target.to_post_attach = debug_to_post_attach;
2502 current_target.to_require_attach = debug_to_require_attach;
2503 current_target.to_detach = debug_to_detach;
2504 current_target.to_require_detach = debug_to_require_detach;
2505 current_target.to_resume = debug_to_resume;
2506 current_target.to_wait = debug_to_wait;
2507 current_target.to_post_wait = debug_to_post_wait;
2508 current_target.to_fetch_registers = debug_to_fetch_registers;
2509 current_target.to_store_registers = debug_to_store_registers;
2510 current_target.to_prepare_to_store = debug_to_prepare_to_store;
2511 current_target.to_xfer_memory = debug_to_xfer_memory;
2512 current_target.to_files_info = debug_to_files_info;
2513 current_target.to_insert_breakpoint = debug_to_insert_breakpoint;
2514 current_target.to_remove_breakpoint = debug_to_remove_breakpoint;
2515 current_target.to_terminal_init = debug_to_terminal_init;
2516 current_target.to_terminal_inferior = debug_to_terminal_inferior;
2517 current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output;
2518 current_target.to_terminal_ours = debug_to_terminal_ours;
2519 current_target.to_terminal_info = debug_to_terminal_info;
2520 current_target.to_kill = debug_to_kill;
2521 current_target.to_load = debug_to_load;
2522 current_target.to_lookup_symbol = debug_to_lookup_symbol;
2523 current_target.to_create_inferior = debug_to_create_inferior;
2524 current_target.to_post_startup_inferior = debug_to_post_startup_inferior;
2525 current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior;
2526 current_target.to_clone_and_follow_inferior = debug_to_clone_and_follow_inferior;
2527 current_target.to_post_follow_inferior_by_clone = debug_to_post_follow_inferior_by_clone;
2528 current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint;
2529 current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
2530 current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
2531 current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint;
2532 current_target.to_has_forked = debug_to_has_forked;
2533 current_target.to_has_vforked = debug_to_has_vforked;
2534 current_target.to_can_follow_vfork_prior_to_exec = debug_to_can_follow_vfork_prior_to_exec;
2535 current_target.to_post_follow_vfork = debug_to_post_follow_vfork;
2536 current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint;
2537 current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
2538 current_target.to_has_execd = debug_to_has_execd;
2539 current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call;
2540 current_target.to_has_syscall_event = debug_to_has_syscall_event;
2541 current_target.to_has_exited = debug_to_has_exited;
2542 current_target.to_mourn_inferior = debug_to_mourn_inferior;
2543 current_target.to_can_run = debug_to_can_run;
2544 current_target.to_notice_signals = debug_to_notice_signals;
2545 current_target.to_thread_alive = debug_to_thread_alive;
2546 current_target.to_stop = debug_to_stop;
2547 current_target.to_query = debug_to_query;
2548 current_target.to_enable_exception_callback = debug_to_enable_exception_callback;
2549 current_target.to_get_current_exception_event = debug_to_get_current_exception_event;
2550 current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
2551 current_target.to_core_file_to_sym_file = debug_to_core_file_to_sym_file;
2554 #endif /* MAINTENANCE_CMDS */
2556 static char targ_desc[] =
2557 "Names of targets and files being debugged.\n\
2558 Shows the entire stack of targets currently in use (including the exec-file,\n\
2559 core-file, and process, if any), as well as the symbol file name.";
2562 initialize_targets ()
2564 init_dummy_target ();
2565 push_target (&dummy_target);
2567 add_info ("target", target_info, targ_desc);
2568 add_info ("files", target_info, targ_desc);
2570 #ifdef MAINTENANCE_CMDS
2572 add_set_cmd ("targetdebug", class_maintenance, var_zinteger,
2573 (char *)&targetdebug,
2574 "Set target debugging.\n\
2575 When non-zero, target debugging is enabled.", &setlist),
2579 if (!STREQ (signals[TARGET_SIGNAL_LAST].string, "TARGET_SIGNAL_MAGIC"))