1 /* Select target systems and architectures at runtime for GDB.
2 Copyright 1990, 1992, 1993, 1994 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
37 target_info
PARAMS ((char *, int));
40 cleanup_target
PARAMS ((struct target_ops
*));
43 maybe_kill_then_create_inferior
PARAMS ((char *, char *, char **));
46 maybe_kill_then_attach
PARAMS ((char *, int));
49 kill_or_be_killed
PARAMS ((int));
52 default_terminal_info
PARAMS ((char *, int));
55 nosymbol
PARAMS ((char *, CORE_ADDR
*));
58 tcomplain
PARAMS ((void));
61 nomemory
PARAMS ((CORE_ADDR
, char *, int, int));
64 return_zero
PARAMS ((void));
67 ignore
PARAMS ((void));
70 target_command
PARAMS ((char *, int));
72 static struct target_ops
*
73 find_default_run_target
PARAMS ((char *));
75 /* Pointer to array of target architecture structures; the size of the
76 array; the current index into the array; the allocated size of the
78 struct target_ops
**target_structs
;
79 unsigned target_struct_size
;
80 unsigned target_struct_index
;
81 unsigned target_struct_allocsize
;
82 #define DEFAULT_ALLOCSIZE 10
84 /* The initial current target, so that there is always a semi-valid
87 struct target_ops dummy_target
= {"None", "None", "",
88 0, 0, /* open, close */
89 find_default_attach
, 0, /* attach, detach */
90 0, 0, /* resume, wait */
91 0, 0, 0, /* registers */
94 0, 0, 0, 0, 0, /* terminal */
95 0, 0, /* kill, load */
96 0, /* lookup_symbol */
97 find_default_create_inferior
, /* create_inferior */
98 0, /* mourn_inferior */
100 0, /* notice_signals */
101 dummy_stratum
, 0, /* stratum, next */
102 0, 0, 0, 0, 0, /* all mem, mem, stack, regs, exec */
103 0, 0, /* section pointers */
107 /* The target structure we are currently using to talk to a process
108 or file or whatever "inferior" we have. */
110 struct target_ops
*current_target
;
112 /* The stack of target structures that have been pushed. */
114 struct target_ops
**current_target_stack
;
116 /* Command list for target. */
118 static struct cmd_list_element
*targetlist
= NULL
;
120 /* Nonzero if we are debugging an attached outside process
121 rather than an inferior. */
125 /* The user just typed 'target' without the name of a target. */
129 target_command (arg
, from_tty
)
133 fputs_filtered ("Argument required (target name). Try `help target'\n",
137 /* Add a possible target architecture to the list. */
141 struct target_ops
*t
;
143 if (t
->to_magic
!= OPS_MAGIC
)
145 fprintf_unfiltered(gdb_stderr
, "Magic number of %s target struct wrong\n",
152 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
153 target_structs
= (struct target_ops
**) xmalloc
154 (target_struct_allocsize
* sizeof (*target_structs
));
156 if (target_struct_size
>= target_struct_allocsize
)
158 target_struct_allocsize
*= 2;
159 target_structs
= (struct target_ops
**)
160 xrealloc ((char *) target_structs
,
161 target_struct_allocsize
* sizeof (*target_structs
));
163 target_structs
[target_struct_size
++] = t
;
166 if (targetlist
== NULL
)
167 add_prefix_cmd ("target", class_run
, target_command
,
168 "Connect to a target machine or process.\n\
169 The first argument is the type or protocol of the target machine.\n\
170 Remaining arguments are interpreted by the target protocol. For more\n\
171 information on the arguments for a particular protocol, type\n\
172 `help target ' followed by the protocol name.",
173 &targetlist
, "target ", 0, &cmdlist
);
174 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
186 nomemory (memaddr
, myaddr
, len
, write
)
192 errno
= EIO
; /* Can't read/write this location */
193 return 0; /* No bytes handled */
199 error ("You can't do that when your target is `%s'",
200 current_target
->to_shortname
);
206 error ("You can't do that without a process to debug");
211 nosymbol (name
, addrp
)
215 return 1; /* Symbol does not exist in target env */
220 default_terminal_info (args
, from_tty
)
224 printf_unfiltered("No saved terminal information.\n");
228 /* With strata, this function is no longer needed. FIXME. */
229 /* This is the default target_create_inferior function. It looks up
230 the stack for some target that cares to create inferiors, then
231 calls it -- or complains if not found. */
234 upstack_create_inferior (exec
, args
, env
)
239 struct target_ops
*t
;
241 for (t
= current_target
;
245 if (t
->to_create_inferior
!= upstack_create_inferior
)
247 t
->to_create_inferior (exec
, args
, env
);
256 /* This is the default target_create_inferior and target_attach function.
257 If the current target is executing, it asks whether to kill it off.
258 If this function returns without calling error(), it has killed off
259 the target, and the operation should be attempted. */
262 kill_or_be_killed (from_tty
)
265 if (target_has_execution
)
267 printf_unfiltered ("You are already running a program:\n");
268 target_files_info ();
269 if (query ("Kill it? ")) {
271 if (target_has_execution
)
272 error ("Killing the program did not help.");
275 error ("Program not killed.");
282 maybe_kill_then_attach (args
, from_tty
)
286 kill_or_be_killed (from_tty
);
287 target_attach (args
, from_tty
);
291 maybe_kill_then_create_inferior (exec
, args
, env
)
296 kill_or_be_killed (0);
297 target_create_inferior (exec
, args
, env
);
300 /* Clean up a target struct so it no longer has any zero pointers in it.
301 We default entries, at least to stubs that print error messages. */
305 struct target_ops
*t
;
308 /* Check magic number. If wrong, it probably means someone changed
309 the struct definition, but not all the places that initialize one. */
310 if (t
->to_magic
!= OPS_MAGIC
)
312 fprintf_unfiltered(gdb_stderr
, "Magic number of %s target struct wrong\n",
317 #define de_fault(field, value) \
318 if (!t->field) t->field = value
320 /* FIELD DEFAULT VALUE */
322 de_fault (to_open
, (void (*)())tcomplain
);
323 de_fault (to_close
, (void (*)())ignore
);
324 de_fault (to_attach
, maybe_kill_then_attach
);
325 de_fault (to_detach
, (void (*)())ignore
);
326 de_fault (to_resume
, (void (*)())noprocess
);
327 de_fault (to_wait
, (int (*)())noprocess
);
328 de_fault (to_fetch_registers
, (void (*)())ignore
);
329 de_fault (to_store_registers
, (void (*)())noprocess
);
330 de_fault (to_prepare_to_store
, (void (*)())noprocess
);
331 de_fault (to_xfer_memory
, (int (*)())nomemory
);
332 de_fault (to_files_info
, (void (*)())ignore
);
333 de_fault (to_insert_breakpoint
, memory_insert_breakpoint
);
334 de_fault (to_remove_breakpoint
, memory_remove_breakpoint
);
335 de_fault (to_terminal_init
, ignore
);
336 de_fault (to_terminal_inferior
, ignore
);
337 de_fault (to_terminal_ours_for_output
,ignore
);
338 de_fault (to_terminal_ours
, ignore
);
339 de_fault (to_terminal_info
, default_terminal_info
);
340 de_fault (to_kill
, (void (*)())noprocess
);
341 de_fault (to_load
, (void (*)())tcomplain
);
342 de_fault (to_lookup_symbol
, nosymbol
);
343 de_fault (to_create_inferior
, maybe_kill_then_create_inferior
);
344 de_fault (to_mourn_inferior
, (void (*)())noprocess
);
345 de_fault (to_can_run
, return_zero
);
346 de_fault (to_notice_signals
, (void (*)())ignore
);
347 de_fault (to_next
, 0);
348 de_fault (to_has_all_memory
, 0);
349 de_fault (to_has_memory
, 0);
350 de_fault (to_has_stack
, 0);
351 de_fault (to_has_registers
, 0);
352 de_fault (to_has_execution
, 0);
357 /* Push a new target type into the stack of the existing target accessors,
358 possibly superseding some of the existing accessors.
360 Result is zero if the pushed target ended up on top of the stack,
361 nonzero if at least one target is on top of it.
363 Rather than allow an empty stack, we always have the dummy target at
364 the bottom stratum, so we can call the function vectors without
369 struct target_ops
*t
;
371 struct target_ops
*st
, *prev
;
373 for (prev
= 0, st
= current_target
;
375 prev
= st
, st
= st
->to_next
) {
376 if ((int)(t
->to_stratum
) >= (int)(st
->to_stratum
))
380 while (t
->to_stratum
== st
->to_stratum
) {
381 /* There's already something on this stratum. Close it off. */
384 prev
->to_next
= st
->to_next
; /* Unchain old target_ops */
386 current_target
= st
->to_next
; /* Unchain first on list */
390 /* We have removed all targets in our stratum, now add ourself. */
397 cleanup_target (current_target
);
401 /* Remove a target_ops vector from the stack, wherever it may be.
402 Return how many times it was removed (0 or 1 unless bug). */
406 struct target_ops
*t
;
408 struct target_ops
*u
, *v
;
411 for (u
= current_target
, v
= 0;
413 v
= u
, u
= u
->to_next
)
417 pop_target(); /* unchain top copy */
419 (t
->to_close
)(0); /* Let it clean up */
420 v
->to_next
= t
->to_next
; /* unchain middle copy */
430 (current_target
->to_close
)(0); /* Let it clean up */
431 current_target
= current_target
->to_next
;
433 /* This will dump core if ever called--push_target expects current_target
434 to be non-NULL. But I don't think it's needed; I don't see how the
435 dummy_target could ever be removed from the stack. */
436 if (!current_target
) /* At bottom, push dummy. */
437 push_target (&dummy_target
);
442 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
444 /* target_read_string -- read a null terminated string, up to LEN bytes,
445 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
446 Set *STRING to a pointer to malloc'd memory containing the data; the caller
447 is responsible for freeing it. Return the number of bytes successfully
451 target_read_string (memaddr
, string
, len
, errnop
)
457 int tlen
, origlen
, offset
, i
;
461 int buffer_allocated
;
463 unsigned int nbytes_read
= 0;
465 /* Small for testing. */
466 buffer_allocated
= 4;
467 buffer
= xmalloc (buffer_allocated
);
474 tlen
= MIN (len
, 4 - (memaddr
& 3));
475 offset
= memaddr
& 3;
477 errcode
= target_xfer_memory (memaddr
& ~3, buf
, 4, 0);
481 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
484 bytes
= bufptr
- buffer
;
485 buffer_allocated
*= 2;
486 buffer
= xrealloc (buffer
, buffer_allocated
);
487 bufptr
= buffer
+ bytes
;
490 for (i
= 0; i
< tlen
; i
++)
492 *bufptr
++ = buf
[i
+ offset
];
493 if (buf
[i
+ offset
] == '\000')
495 nbytes_read
+= i
+ 1;
512 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
513 GDB's memory at MYADDR. Returns either 0 for success or an errno value
516 If an error occurs, no guarantee is made about the contents of the data at
517 MYADDR. In particular, the caller should not depend upon partial reads
518 filling the buffer with good data. There is no way for the caller to know
519 how much good data might have been transfered anyway. Callers that can
520 deal with partial reads should call target_read_memory_partial. */
523 target_read_memory (memaddr
, myaddr
, len
)
528 return target_xfer_memory (memaddr
, myaddr
, len
, 0);
531 /* Read LEN bytes of target memory at address MEMADDR, placing the results
532 in GDB's memory at MYADDR. Returns a count of the bytes actually read,
533 and optionally an errno value in the location pointed to by ERRNOPTR
534 if ERRNOPTR is non-null. */
537 target_read_memory_partial (memaddr
, myaddr
, len
, errnoptr
)
543 int nread
; /* Number of bytes actually read. */
544 int errcode
; /* Error from last read. */
546 /* First try a complete read. */
547 errcode
= target_xfer_memory (memaddr
, myaddr
, len
, 0);
555 /* Loop, reading one byte at a time until we get as much as we can. */
556 for (errcode
= 0, nread
= 0; len
> 0 && errcode
== 0; nread
++, len
--)
558 errcode
= target_xfer_memory (memaddr
++, myaddr
++, 1, 0);
560 /* If an error, the last read was unsuccessful, so adjust count. */
566 if (errnoptr
!= NULL
)
574 target_write_memory (memaddr
, myaddr
, len
)
579 return target_xfer_memory (memaddr
, myaddr
, len
, 1);
582 /* Move memory to or from the targets. Iterate until all of it has
583 been moved, if necessary. The top target gets priority; anything
584 it doesn't want, is offered to the next one down, etc. Note the
585 business with curlen: if an early target says "no, but I have a
586 boundary overlapping this xfer" then we shorten what we offer to
587 the subsequent targets so the early guy will get a chance at the
588 tail before the subsequent ones do.
590 Result is 0 or errno value. */
593 target_xfer_memory (memaddr
, myaddr
, len
, write
)
601 struct target_ops
*t
;
603 /* to_xfer_memory is not guaranteed to set errno, even when it returns
607 /* The quick case is that the top target does it all. */
608 res
= current_target
->to_xfer_memory
609 (memaddr
, myaddr
, len
, write
, current_target
);
615 /* If res <= 0 then we call it again in the loop. Ah well. */
619 curlen
= len
; /* Want to do it all */
620 for (t
= current_target
;
622 t
= t
->to_has_all_memory
? 0: t
->to_next
)
624 res
= t
->to_xfer_memory(memaddr
, myaddr
, curlen
, write
, t
);
625 if (res
> 0) break; /* Handled all or part of xfer */
626 if (res
== 0) continue; /* Handled none */
627 curlen
= -res
; /* Could handle once we get past res bytes */
631 /* If this address is for nonexistent memory,
632 read zeros if reading, or do nothing if writing. Return error. */
634 memset (myaddr
, 0, len
);
645 return 0; /* We managed to cover it all somehow. */
651 target_info (args
, from_tty
)
655 struct target_ops
*t
;
658 if (symfile_objfile
!= NULL
)
659 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
661 #ifdef FILES_INFO_HOOK
662 if (FILES_INFO_HOOK ())
666 for (t
= current_target
;
670 if ((int)(t
->to_stratum
) <= (int)dummy_stratum
)
673 printf_unfiltered("\tWhile running this, gdb does not access memory from...\n");
674 printf_unfiltered("%s:\n", t
->to_longname
);
675 (t
->to_files_info
)(t
);
676 has_all_mem
= t
->to_has_all_memory
;
680 /* This is to be called by the open routine before it does
684 target_preopen (from_tty
)
689 if (target_has_execution
)
691 if (query ("A program is being debugged already. Kill it? "))
694 error ("Program not killed.");
697 /* Calling target_kill may remove the target from the stack. But if
698 it doesn't (which seems like a win for UDI), remove it now. */
700 if (target_has_execution
)
704 /* Detach a target after doing deferred register stores. */
707 target_detach (args
, from_tty
)
711 /* Handle any optimized stores to the inferior. */
712 #ifdef DO_DEFERRED_STORES
715 (current_target
->to_detach
) (args
, from_tty
);
719 target_link (modname
, t_reloc
)
723 if (STREQ(current_target
->to_shortname
, "rombug"))
725 (current_target
->to_lookup_symbol
) (modname
, t_reloc
);
727 error("Unable to link to %s and get relocation in rombug", modname
);
730 *t_reloc
= (CORE_ADDR
)-1;
733 /* Look through the list of possible targets for a target that can
734 execute a run or attach command without any other data. This is
735 used to locate the default process stratum.
737 Result is always valid (error() is called for errors). */
739 static struct target_ops
*
740 find_default_run_target (do_mesg
)
743 struct target_ops
**t
;
744 struct target_ops
*runable
= NULL
;
749 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
752 if (target_can_run(*t
))
760 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
766 find_default_attach (args
, from_tty
)
770 struct target_ops
*t
;
772 t
= find_default_run_target("attach");
773 (t
->to_attach
) (args
, from_tty
);
778 find_default_create_inferior (exec_file
, allargs
, env
)
783 struct target_ops
*t
;
785 t
= find_default_run_target("run");
786 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
799 struct target_ops
**t
;
800 struct target_ops
*runable
= NULL
;
805 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
808 if ((*t
)->to_stratum
== core_stratum
)
815 return(count
== 1 ? runable
: NULL
);
818 /* The inferior process has died. Long live the inferior! */
821 generic_mourn_inferior ()
825 breakpoint_init_inferior ();
826 registers_changed ();
828 #ifdef CLEAR_DEFERRED_STORES
829 /* Delete any pending stores to the inferior... */
830 CLEAR_DEFERRED_STORES
;
834 reinit_frame_cache ();
836 /* It is confusing to the user for ignore counts to stick around
837 from previous runs of the inferior. So clear them. */
838 breakpoint_clear_ignore_counts ();
841 /* This table must match in order and size the signals in enum target_signal
849 {"SIGHUP", "Hangup"},
850 {"SIGINT", "Interrupt"},
852 {"SIGILL", "Illegal instruction"},
853 {"SIGTRAP", "Trace/breakpoint trap"},
854 {"SIGABRT", "Aborted"},
855 {"SIGEMT", "Emulation trap"},
856 {"SIGFPE", "Arithmetic exception"},
857 {"SIGKILL", "Killed"},
858 {"SIGBUS", "Bus error"},
859 {"SIGSEGV", "Segmentation fault"},
860 {"SIGSYS", "Bad system call"},
861 {"SIGPIPE", "Broken pipe"},
862 {"SIGALRM", "Alarm clock"},
863 {"SIGTERM", "Terminated"},
864 {"SIGURG", "Urgent I/O condition"},
865 {"SIGSTOP", "Stopped (signal)"},
866 {"SIGTSTP", "Stopped (user)"},
867 {"SIGCONT", "Continued"},
868 {"SIGCHLD", "Child status changed"},
869 {"SIGTTIN", "Stopped (tty input)"},
870 {"SIGTTOU", "Stopped (tty output)"},
871 {"SIGIO", "I/O possible"},
872 {"SIGXCPU", "CPU time limit exceeded"},
873 {"SIGXFSZ", "File size limit exceeded"},
874 {"SIGVTALRM", "Virtual timer expired"},
875 {"SIGPROF", "Profiling timer expired"},
876 {"SIGWINCH", "Window size changed"},
877 {"SIGLOST", "Resource lost"},
878 {"SIGUSR1", "User defined signal 1"},
879 {"SIGUSR2", "User defined signal 2"},
880 {"SIGPWR", "Power fail/restart"},
881 {"SIGPOLL", "Pollable event occurred"},
882 {"SIGWIND", "SIGWIND"},
883 {"SIGPHONE", "SIGPHONE"},
884 {"SIGWAITING", "Process's LWPs are blocked"},
885 {"SIGLWP", "Signal LWP"},
886 {"SIGDANGER", "Swap space dangerously low"},
887 {"SIGGRANT", "Monitor mode granted"},
888 {"SIGRETRACT", "Need to relinguish monitor mode"},
889 {"SIGMSG", "Monitor mode data available"},
890 {"SIGSOUND", "Sound completed"},
891 {"SIGSAK", "Secure attention"},
892 {NULL
, "Unknown signal"},
893 {NULL
, "Internal error: printing TARGET_SIGNAL_DEFAULT"},
895 /* Last entry, used to check whether the table is the right size. */
896 {NULL
, "TARGET_SIGNAL_MAGIC"}
899 /* Return the string for a signal. */
901 target_signal_to_string (sig
)
902 enum target_signal sig
;
904 return signals
[sig
].string
;
907 /* Return the name for a signal. */
909 target_signal_to_name (sig
)
910 enum target_signal sig
;
912 if (sig
== TARGET_SIGNAL_UNKNOWN
)
913 /* I think the code which prints this will always print it along with
914 the string, so no need to be verbose. */
916 return signals
[sig
].name
;
919 /* Given a name, return its signal. */
921 target_signal_from_name (name
)
924 enum target_signal sig
;
926 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
927 for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
928 questionable; seems like by now people should call it SIGABRT
931 /* This ugly cast brought to you by the native VAX compiler. */
932 for (sig
= TARGET_SIGNAL_HUP
;
933 signals
[sig
].name
!= NULL
;
934 sig
= (enum target_signal
)((int)sig
+ 1))
935 if (STREQ (name
, signals
[sig
].name
))
937 return TARGET_SIGNAL_UNKNOWN
;
940 /* The following functions are to help certain targets deal
941 with the signal/waitstatus stuff. They could just as well be in
942 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
944 /* Convert host signal to our signals. */
946 target_signal_from_host (hostsig
)
949 /* A switch statement would make sense but would require special kludges
950 to deal with the cases where more than one signal has the same number. */
952 if (hostsig
== 0) return TARGET_SIGNAL_0
;
955 if (hostsig
== SIGHUP
) return TARGET_SIGNAL_HUP
;
958 if (hostsig
== SIGINT
) return TARGET_SIGNAL_INT
;
960 #if defined (SIGQUIT)
961 if (hostsig
== SIGQUIT
) return TARGET_SIGNAL_QUIT
;
964 if (hostsig
== SIGILL
) return TARGET_SIGNAL_ILL
;
966 #if defined (SIGTRAP)
967 if (hostsig
== SIGTRAP
) return TARGET_SIGNAL_TRAP
;
969 #if defined (SIGABRT)
970 if (hostsig
== SIGABRT
) return TARGET_SIGNAL_ABRT
;
973 if (hostsig
== SIGEMT
) return TARGET_SIGNAL_EMT
;
976 if (hostsig
== SIGFPE
) return TARGET_SIGNAL_FPE
;
978 #if defined (SIGKILL)
979 if (hostsig
== SIGKILL
) return TARGET_SIGNAL_KILL
;
982 if (hostsig
== SIGBUS
) return TARGET_SIGNAL_BUS
;
984 #if defined (SIGSEGV)
985 if (hostsig
== SIGSEGV
) return TARGET_SIGNAL_SEGV
;
988 if (hostsig
== SIGSYS
) return TARGET_SIGNAL_SYS
;
990 #if defined (SIGPIPE)
991 if (hostsig
== SIGPIPE
) return TARGET_SIGNAL_PIPE
;
993 #if defined (SIGALRM)
994 if (hostsig
== SIGALRM
) return TARGET_SIGNAL_ALRM
;
996 #if defined (SIGTERM)
997 if (hostsig
== SIGTERM
) return TARGET_SIGNAL_TERM
;
999 #if defined (SIGUSR1)
1000 if (hostsig
== SIGUSR1
) return TARGET_SIGNAL_USR1
;
1002 #if defined (SIGUSR2)
1003 if (hostsig
== SIGUSR2
) return TARGET_SIGNAL_USR2
;
1005 #if defined (SIGCLD)
1006 if (hostsig
== SIGCLD
) return TARGET_SIGNAL_CHLD
;
1008 #if defined (SIGCHLD)
1009 if (hostsig
== SIGCHLD
) return TARGET_SIGNAL_CHLD
;
1011 #if defined (SIGPWR)
1012 if (hostsig
== SIGPWR
) return TARGET_SIGNAL_PWR
;
1014 #if defined (SIGWINCH)
1015 if (hostsig
== SIGWINCH
) return TARGET_SIGNAL_WINCH
;
1017 #if defined (SIGURG)
1018 if (hostsig
== SIGURG
) return TARGET_SIGNAL_URG
;
1021 if (hostsig
== SIGIO
) return TARGET_SIGNAL_IO
;
1023 #if defined (SIGPOLL)
1024 if (hostsig
== SIGPOLL
) return TARGET_SIGNAL_POLL
;
1026 #if defined (SIGSTOP)
1027 if (hostsig
== SIGSTOP
) return TARGET_SIGNAL_STOP
;
1029 #if defined (SIGTSTP)
1030 if (hostsig
== SIGTSTP
) return TARGET_SIGNAL_TSTP
;
1032 #if defined (SIGCONT)
1033 if (hostsig
== SIGCONT
) return TARGET_SIGNAL_CONT
;
1035 #if defined (SIGTTIN)
1036 if (hostsig
== SIGTTIN
) return TARGET_SIGNAL_TTIN
;
1038 #if defined (SIGTTOU)
1039 if (hostsig
== SIGTTOU
) return TARGET_SIGNAL_TTOU
;
1041 #if defined (SIGVTALRM)
1042 if (hostsig
== SIGVTALRM
) return TARGET_SIGNAL_VTALRM
;
1044 #if defined (SIGPROF)
1045 if (hostsig
== SIGPROF
) return TARGET_SIGNAL_PROF
;
1047 #if defined (SIGXCPU)
1048 if (hostsig
== SIGXCPU
) return TARGET_SIGNAL_XCPU
;
1050 #if defined (SIGXFSZ)
1051 if (hostsig
== SIGXFSZ
) return TARGET_SIGNAL_XFSZ
;
1053 #if defined (SIGWIND)
1054 if (hostsig
== SIGWIND
) return TARGET_SIGNAL_WIND
;
1056 #if defined (SIGPHONE)
1057 if (hostsig
== SIGPHONE
) return TARGET_SIGNAL_PHONE
;
1059 #if defined (SIGLOST)
1060 if (hostsig
== SIGLOST
) return TARGET_SIGNAL_LOST
;
1062 #if defined (SIGWAITING)
1063 if (hostsig
== SIGWAITING
) return TARGET_SIGNAL_WAITING
;
1065 #if defined (SIGLWP)
1066 if (hostsig
== SIGLWP
) return TARGET_SIGNAL_LWP
;
1068 #if defined (SIGDANGER)
1069 if (hostsig
== SIGDANGER
) return TARGET_SIGNAL_DANGER
;
1071 #if defined (SIGGRANT)
1072 if (hostsig
== SIGGRANT
) return TARGET_SIGNAL_GRANT
;
1074 #if defined (SIGRETRACT)
1075 if (hostsig
== SIGRETRACT
) return TARGET_SIGNAL_RETRACT
;
1077 #if defined (SIGMSG)
1078 if (hostsig
== SIGMSG
) return TARGET_SIGNAL_MSG
;
1080 #if defined (SIGSOUND)
1081 if (hostsig
== SIGSOUND
) return TARGET_SIGNAL_SOUND
;
1083 #if defined (SIGSAK)
1084 if (hostsig
== SIGSAK
) return TARGET_SIGNAL_SAK
;
1086 return TARGET_SIGNAL_UNKNOWN
;
1090 target_signal_to_host (oursig
)
1091 enum target_signal oursig
;
1095 case TARGET_SIGNAL_0
: return 0;
1097 #if defined (SIGHUP)
1098 case TARGET_SIGNAL_HUP
: return SIGHUP
;
1100 #if defined (SIGINT)
1101 case TARGET_SIGNAL_INT
: return SIGINT
;
1103 #if defined (SIGQUIT)
1104 case TARGET_SIGNAL_QUIT
: return SIGQUIT
;
1106 #if defined (SIGILL)
1107 case TARGET_SIGNAL_ILL
: return SIGILL
;
1109 #if defined (SIGTRAP)
1110 case TARGET_SIGNAL_TRAP
: return SIGTRAP
;
1112 #if defined (SIGABRT)
1113 case TARGET_SIGNAL_ABRT
: return SIGABRT
;
1115 #if defined (SIGEMT)
1116 case TARGET_SIGNAL_EMT
: return SIGEMT
;
1118 #if defined (SIGFPE)
1119 case TARGET_SIGNAL_FPE
: return SIGFPE
;
1121 #if defined (SIGKILL)
1122 case TARGET_SIGNAL_KILL
: return SIGKILL
;
1124 #if defined (SIGBUS)
1125 case TARGET_SIGNAL_BUS
: return SIGBUS
;
1127 #if defined (SIGSEGV)
1128 case TARGET_SIGNAL_SEGV
: return SIGSEGV
;
1130 #if defined (SIGSYS)
1131 case TARGET_SIGNAL_SYS
: return SIGSYS
;
1133 #if defined (SIGPIPE)
1134 case TARGET_SIGNAL_PIPE
: return SIGPIPE
;
1136 #if defined (SIGALRM)
1137 case TARGET_SIGNAL_ALRM
: return SIGALRM
;
1139 #if defined (SIGTERM)
1140 case TARGET_SIGNAL_TERM
: return SIGTERM
;
1142 #if defined (SIGUSR1)
1143 case TARGET_SIGNAL_USR1
: return SIGUSR1
;
1145 #if defined (SIGUSR2)
1146 case TARGET_SIGNAL_USR2
: return SIGUSR2
;
1148 #if defined (SIGCHLD) || defined (SIGCLD)
1149 case TARGET_SIGNAL_CHLD
:
1150 #if defined (SIGCHLD)
1155 #endif /* SIGCLD or SIGCHLD */
1156 #if defined (SIGPWR)
1157 case TARGET_SIGNAL_PWR
: return SIGPWR
;
1159 #if defined (SIGWINCH)
1160 case TARGET_SIGNAL_WINCH
: return SIGWINCH
;
1162 #if defined (SIGURG)
1163 case TARGET_SIGNAL_URG
: return SIGURG
;
1166 case TARGET_SIGNAL_IO
: return SIGIO
;
1168 #if defined (SIGPOLL)
1169 case TARGET_SIGNAL_POLL
: return SIGPOLL
;
1171 #if defined (SIGSTOP)
1172 case TARGET_SIGNAL_STOP
: return SIGSTOP
;
1174 #if defined (SIGTSTP)
1175 case TARGET_SIGNAL_TSTP
: return SIGTSTP
;
1177 #if defined (SIGCONT)
1178 case TARGET_SIGNAL_CONT
: return SIGCONT
;
1180 #if defined (SIGTTIN)
1181 case TARGET_SIGNAL_TTIN
: return SIGTTIN
;
1183 #if defined (SIGTTOU)
1184 case TARGET_SIGNAL_TTOU
: return SIGTTOU
;
1186 #if defined (SIGVTALRM)
1187 case TARGET_SIGNAL_VTALRM
: return SIGVTALRM
;
1189 #if defined (SIGPROF)
1190 case TARGET_SIGNAL_PROF
: return SIGPROF
;
1192 #if defined (SIGXCPU)
1193 case TARGET_SIGNAL_XCPU
: return SIGXCPU
;
1195 #if defined (SIGXFSZ)
1196 case TARGET_SIGNAL_XFSZ
: return SIGXFSZ
;
1198 #if defined (SIGWIND)
1199 case TARGET_SIGNAL_WIND
: return SIGWIND
;
1201 #if defined (SIGPHONE)
1202 case TARGET_SIGNAL_PHONE
: return SIGPHONE
;
1204 #if defined (SIGLOST)
1205 case TARGET_SIGNAL_LOST
: return SIGLOST
;
1207 #if defined (SIGWAITING)
1208 case TARGET_SIGNAL_WAITING
: return SIGWAITING
;
1210 #if defined (SIGLWP)
1211 case TARGET_SIGNAL_LWP
: return SIGLWP
;
1213 #if defined (SIGDANGER)
1214 case TARGET_SIGNAL_DANGER
: return SIGDANGER
;
1216 #if defined (SIGGRANT)
1217 case TARGET_SIGNAL_GRANT
: return SIGGRANT
;
1219 #if defined (SIGRETRACT)
1220 case TARGET_SIGNAL_RETRACT
: return SIGRETRACT
;
1222 #if defined (SIGMSG)
1223 case TARGET_SIGNAL_MSG
: return SIGMSG
;
1225 #if defined (SIGSOUND)
1226 case TARGET_SIGNAL_SOUND
: return SIGSOUND
;
1228 #if defined (SIGSAK)
1229 case TARGET_SIGNAL_SAK
: return SIGSAK
;
1232 /* The user might be trying to do "signal SIGSAK" where this system
1233 doesn't have SIGSAK. */
1234 warning ("Signal %s does not exist on this system.\n",
1235 target_signal_to_name (oursig
));
1240 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1241 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1242 translation of that in OURSTATUS. */
1244 store_waitstatus (ourstatus
, hoststatus
)
1245 struct target_waitstatus
*ourstatus
;
1248 #ifdef CHILD_SPECIAL_WAITSTATUS
1249 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1250 if it wants to deal with hoststatus. */
1251 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
1255 if (WIFEXITED (hoststatus
))
1257 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1258 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
1260 else if (!WIFSTOPPED (hoststatus
))
1262 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1263 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
1267 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
1268 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
1273 /* Convert a normal process ID to a string. Returns the string in a static
1277 normal_pid_to_str (pid
)
1280 static char buf
[30];
1282 sprintf (buf
, "process %d", pid
);
1287 static char targ_desc
[] =
1288 "Names of targets and files being debugged.\n\
1289 Shows the entire stack of targets currently in use (including the exec-file,\n\
1290 core-file, and process, if any), as well as the symbol file name.";
1293 _initialize_targets ()
1295 current_target
= &dummy_target
;
1296 cleanup_target (current_target
);
1298 add_info ("target", target_info
, targ_desc
);
1299 add_info ("files", target_info
, targ_desc
);
1301 if (!STREQ (signals
[TARGET_SIGNAL_LAST
].string
, "TARGET_SIGNAL_MAGIC"))