* config/tc-mn10300.c (md_assemble): Copy size to real_size before
[deliverable/binutils-gdb.git] / gdb / target.c
CommitLineData
c906108c 1/* Select target systems and architectures at runtime for GDB.
d9fcf2fb 2 Copyright 1990, 1992-1995, 1998-2000 Free Software Foundation, Inc.
c906108c
SS
3 Contributed by Cygnus Support.
4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
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.
c906108c 11
c5aa993b
JM
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.
c906108c 16
c5aa993b
JM
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. */
c906108c
SS
21
22#include "defs.h"
23#include <errno.h>
24#include <ctype.h>
25#include "gdb_string.h"
26#include "target.h"
27#include "gdbcmd.h"
28#include "symtab.h"
29#include "inferior.h"
30#include "bfd.h"
31#include "symfile.h"
32#include "objfiles.h"
03f2053f 33#include "gdb_wait.h"
c906108c
SS
34#include <signal.h>
35
36extern int errno;
37
38static void
39target_info PARAMS ((char *, int));
40
41static void
42cleanup_target PARAMS ((struct target_ops *));
43
44static void
45maybe_kill_then_create_inferior PARAMS ((char *, char *, char **));
46
47static void
48default_clone_and_follow_inferior PARAMS ((int, int *));
49
50static void
51maybe_kill_then_attach PARAMS ((char *, int));
52
53static void
54kill_or_be_killed PARAMS ((int));
55
56static void
57default_terminal_info PARAMS ((char *, int));
58
59static int
60nosymbol PARAMS ((char *, CORE_ADDR *));
61
62static void
63tcomplain PARAMS ((void));
64
65static int
66nomemory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *));
67
68static int
69return_zero PARAMS ((void));
70
71static int
72return_one PARAMS ((void));
73
74void
75target_ignore PARAMS ((void));
76
77static void
78target_command PARAMS ((char *, int));
79
80static struct target_ops *
ed9a39eb 81find_default_run_target PARAMS ((char *));
c906108c
SS
82
83static void
84update_current_target PARAMS ((void));
85
392a587b
JM
86static void nosupport_runtime PARAMS ((void));
87
88static void normal_target_post_startup_inferior PARAMS ((int pid));
89
917317f4
JM
90/* Transfer LEN bytes between target address MEMADDR and GDB address
91 MYADDR. Returns 0 for success, errno code for failure (which
92 includes partial transfers -- if you want a more useful response to
93 partial transfers, try either target_read_memory_partial or
94 target_write_memory_partial). */
c906108c
SS
95
96static int
97target_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr, int len,
d4b2399a 98 int write));
c906108c
SS
99
100static void init_dummy_target PARAMS ((void));
101
102static void
103debug_to_open PARAMS ((char *, int));
104
105static void
106debug_to_close PARAMS ((int));
107
108static void
109debug_to_attach PARAMS ((char *, int));
110
111static void
112debug_to_detach PARAMS ((char *, int));
113
114static void
115debug_to_resume PARAMS ((int, int, enum target_signal));
116
117static int
118debug_to_wait PARAMS ((int, struct target_waitstatus *));
119
120static void
121debug_to_fetch_registers PARAMS ((int));
122
123static void
124debug_to_store_registers PARAMS ((int));
125
126static void
127debug_to_prepare_to_store PARAMS ((void));
128
129static int
130debug_to_xfer_memory PARAMS ((CORE_ADDR, char *, int, int, struct target_ops *));
131
132static void
133debug_to_files_info PARAMS ((struct target_ops *));
134
135static int
136debug_to_insert_breakpoint PARAMS ((CORE_ADDR, char *));
137
138static int
139debug_to_remove_breakpoint PARAMS ((CORE_ADDR, char *));
140
141static void
142debug_to_terminal_init PARAMS ((void));
143
144static void
145debug_to_terminal_inferior PARAMS ((void));
146
147static void
148debug_to_terminal_ours_for_output PARAMS ((void));
149
150static void
151debug_to_terminal_ours PARAMS ((void));
152
153static void
154debug_to_terminal_info PARAMS ((char *, int));
155
156static void
157debug_to_kill PARAMS ((void));
158
159static void
160debug_to_load PARAMS ((char *, int));
161
162static int
163debug_to_lookup_symbol PARAMS ((char *, CORE_ADDR *));
164
165static void
166debug_to_create_inferior PARAMS ((char *, char *, char **));
167
168static void
169debug_to_mourn_inferior PARAMS ((void));
170
171static int
172debug_to_can_run PARAMS ((void));
173
174static void
175debug_to_notice_signals PARAMS ((int));
176
177static int
178debug_to_thread_alive PARAMS ((int));
179
180static void
181debug_to_stop PARAMS ((void));
182
c5aa993b 183static int debug_to_query PARAMS ((int /*char */ , char *, char *, int *));
c906108c
SS
184
185/* Pointer to array of target architecture structures; the size of the
186 array; the current index into the array; the allocated size of the
187 array. */
188struct target_ops **target_structs;
189unsigned target_struct_size;
190unsigned target_struct_index;
191unsigned target_struct_allocsize;
192#define DEFAULT_ALLOCSIZE 10
193
194/* The initial current target, so that there is always a semi-valid
195 current target. */
196
197static struct target_ops dummy_target;
198
199/* Top of target stack. */
200
201struct target_stack_item *target_stack;
202
203/* The target structure we are currently using to talk to a process
204 or file or whatever "inferior" we have. */
205
206struct target_ops current_target;
207
208/* Command list for target. */
209
210static struct cmd_list_element *targetlist = NULL;
211
212/* Nonzero if we are debugging an attached outside process
213 rather than an inferior. */
214
215int attach_flag;
216
c906108c
SS
217/* Non-zero if we want to see trace of target level stuff. */
218
219static int targetdebug = 0;
220
221static void setup_target_debug PARAMS ((void));
222
c906108c
SS
223/* The user just typed 'target' without the name of a target. */
224
225/* ARGSUSED */
226static void
227target_command (arg, from_tty)
228 char *arg;
229 int from_tty;
230{
231 fputs_filtered ("Argument required (target name). Try `help target'\n",
232 gdb_stdout);
233}
234
235/* Add a possible target architecture to the list. */
236
237void
238add_target (t)
239 struct target_ops *t;
240{
241 if (!target_structs)
242 {
243 target_struct_allocsize = DEFAULT_ALLOCSIZE;
244 target_structs = (struct target_ops **) xmalloc
245 (target_struct_allocsize * sizeof (*target_structs));
246 }
247 if (target_struct_size >= target_struct_allocsize)
248 {
249 target_struct_allocsize *= 2;
250 target_structs = (struct target_ops **)
c5aa993b
JM
251 xrealloc ((char *) target_structs,
252 target_struct_allocsize * sizeof (*target_structs));
c906108c
SS
253 }
254 target_structs[target_struct_size++] = t;
c5aa993b 255/* cleanup_target (t); */
c906108c
SS
256
257 if (targetlist == NULL)
258 add_prefix_cmd ("target", class_run, target_command,
259 "Connect to a target machine or process.\n\
260The first argument is the type or protocol of the target machine.\n\
261Remaining arguments are interpreted by the target protocol. For more\n\
262information on the arguments for a particular protocol, type\n\
263`help target ' followed by the protocol name.",
264 &targetlist, "target ", 0, &cmdlist);
265 add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist);
266}
267
268/* Stub functions */
269
270void
271target_ignore ()
272{
273}
274
11cf8741
JM
275void
276target_load (char *arg, int from_tty)
277{
278 (*current_target.to_load) (arg, from_tty);
279}
280
c906108c
SS
281/* ARGSUSED */
282static int
283nomemory (memaddr, myaddr, len, write, t)
284 CORE_ADDR memaddr;
285 char *myaddr;
286 int len;
287 int write;
288 struct target_ops *t;
289{
c5aa993b
JM
290 errno = EIO; /* Can't read/write this location */
291 return 0; /* No bytes handled */
c906108c
SS
292}
293
294static void
295tcomplain ()
296{
297 error ("You can't do that when your target is `%s'",
298 current_target.to_shortname);
299}
300
301void
302noprocess ()
303{
304 error ("You can't do that without a process to debug.");
305}
306
307/* ARGSUSED */
308static int
309nosymbol (name, addrp)
310 char *name;
311 CORE_ADDR *addrp;
312{
c5aa993b 313 return 1; /* Symbol does not exist in target env */
c906108c
SS
314}
315
316/* ARGSUSED */
392a587b 317static void
c906108c
SS
318nosupport_runtime ()
319{
320 if (!inferior_pid)
321 noprocess ();
322 else
323 error ("No run-time support for this");
324}
325
326
327/* ARGSUSED */
328static void
329default_terminal_info (args, from_tty)
330 char *args;
331 int from_tty;
332{
c5aa993b 333 printf_unfiltered ("No saved terminal information.\n");
c906108c
SS
334}
335
336/* This is the default target_create_inferior and target_attach function.
337 If the current target is executing, it asks whether to kill it off.
338 If this function returns without calling error(), it has killed off
339 the target, and the operation should be attempted. */
340
341static void
342kill_or_be_killed (from_tty)
343 int from_tty;
344{
345 if (target_has_execution)
346 {
347 printf_unfiltered ("You are already running a program:\n");
348 target_files_info ();
c5aa993b
JM
349 if (query ("Kill it? "))
350 {
351 target_kill ();
352 if (target_has_execution)
353 error ("Killing the program did not help.");
354 return;
355 }
356 else
357 {
358 error ("Program not killed.");
359 }
c906108c 360 }
c5aa993b 361 tcomplain ();
c906108c
SS
362}
363
364static void
365maybe_kill_then_attach (args, from_tty)
366 char *args;
367 int from_tty;
368{
369 kill_or_be_killed (from_tty);
370 target_attach (args, from_tty);
371}
372
373static void
374maybe_kill_then_create_inferior (exec, args, env)
375 char *exec;
376 char *args;
377 char **env;
378{
379 kill_or_be_killed (0);
380 target_create_inferior (exec, args, env);
381}
382
383static void
384default_clone_and_follow_inferior (child_pid, followed_child)
c5aa993b
JM
385 int child_pid;
386 int *followed_child;
c906108c
SS
387{
388 target_clone_and_follow_inferior (child_pid, followed_child);
389}
390
391/* Clean up a target struct so it no longer has any zero pointers in it.
392 We default entries, at least to stubs that print error messages. */
393
394static void
395cleanup_target (t)
396 struct target_ops *t;
397{
398
399#define de_fault(field, value) \
0d06e24b
JM
400 if (!t->field) \
401 t->field = value
402
403 de_fault (to_open,
404 (void (*) (char *, int))
405 tcomplain);
406 de_fault (to_close,
407 (void (*) (int))
408 target_ignore);
409 de_fault (to_attach,
410 maybe_kill_then_attach);
411 de_fault (to_post_attach,
412 (void (*) (int))
413 target_ignore);
414 de_fault (to_require_attach,
415 maybe_kill_then_attach);
416 de_fault (to_detach,
417 (void (*) (char *, int))
418 target_ignore);
419 de_fault (to_require_detach,
420 (void (*) (int, char *, int))
421 target_ignore);
422 de_fault (to_resume,
423 (void (*) (int, int, enum target_signal))
424 noprocess);
425 de_fault (to_wait,
426 (int (*) (int, struct target_waitstatus *))
427 noprocess);
428 de_fault (to_post_wait,
429 (void (*) (int, int))
430 target_ignore);
431 de_fault (to_fetch_registers,
432 (void (*) (int))
433 target_ignore);
434 de_fault (to_store_registers,
435 (void (*) (int))
436 noprocess);
437 de_fault (to_prepare_to_store,
438 (void (*) (void))
439 noprocess);
440 de_fault (to_xfer_memory,
441 (int (*) (CORE_ADDR, char *, int, int, struct target_ops *))
442 nomemory);
443 de_fault (to_files_info,
444 (void (*) (struct target_ops *))
445 target_ignore);
446 de_fault (to_insert_breakpoint,
447 memory_insert_breakpoint);
448 de_fault (to_remove_breakpoint,
449 memory_remove_breakpoint);
450 de_fault (to_terminal_init,
451 (void (*) (void))
452 target_ignore);
453 de_fault (to_terminal_inferior,
454 (void (*) (void))
455 target_ignore);
456 de_fault (to_terminal_ours_for_output,
457 (void (*) (void))
458 target_ignore);
459 de_fault (to_terminal_ours,
460 (void (*) (void))
461 target_ignore);
462 de_fault (to_terminal_info,
463 default_terminal_info);
464 de_fault (to_kill,
465 (void (*) (void))
466 noprocess);
467 de_fault (to_load,
468 (void (*) (char *, int))
469 tcomplain);
470 de_fault (to_lookup_symbol,
471 (int (*) (char *, CORE_ADDR *))
472 nosymbol);
473 de_fault (to_create_inferior,
474 maybe_kill_then_create_inferior);
475 de_fault (to_post_startup_inferior,
476 (void (*) (int))
477 target_ignore);
478 de_fault (to_acknowledge_created_inferior,
479 (void (*) (int))
480 target_ignore);
481 de_fault (to_clone_and_follow_inferior,
482 default_clone_and_follow_inferior);
483 de_fault (to_post_follow_inferior_by_clone,
484 (void (*) (void))
485 target_ignore);
486 de_fault (to_insert_fork_catchpoint,
487 (int (*) (int))
488 tcomplain);
489 de_fault (to_remove_fork_catchpoint,
490 (int (*) (int))
491 tcomplain);
492 de_fault (to_insert_vfork_catchpoint,
493 (int (*) (int))
494 tcomplain);
495 de_fault (to_remove_vfork_catchpoint,
496 (int (*) (int))
497 tcomplain);
498 de_fault (to_has_forked,
499 (int (*) (int, int *))
500 return_zero);
501 de_fault (to_has_vforked,
502 (int (*) (int, int *))
503 return_zero);
504 de_fault (to_can_follow_vfork_prior_to_exec,
505 (int (*) (void))
506 return_zero);
507 de_fault (to_post_follow_vfork,
508 (void (*) (int, int, int, int))
509 target_ignore);
510 de_fault (to_insert_exec_catchpoint,
511 (int (*) (int))
512 tcomplain);
513 de_fault (to_remove_exec_catchpoint,
514 (int (*) (int))
515 tcomplain);
516 de_fault (to_has_execd,
517 (int (*) (int, char **))
518 return_zero);
519 de_fault (to_reported_exec_events_per_exec_call,
520 (int (*) (void))
521 return_one);
522 de_fault (to_has_syscall_event,
523 (int (*) (int, enum target_waitkind *, int *))
524 return_zero);
525 de_fault (to_has_exited,
526 (int (*) (int, int, int *))
527 return_zero);
528 de_fault (to_mourn_inferior,
529 (void (*) (void))
530 noprocess);
531 de_fault (to_can_run,
532 return_zero);
533 de_fault (to_notice_signals,
534 (void (*) (int))
535 target_ignore);
536 de_fault (to_thread_alive,
537 (int (*) (int))
538 return_zero);
539 de_fault (to_find_new_threads,
540 (void (*) (void))
541 target_ignore);
542 de_fault (to_extra_thread_info,
543 (char *(*) (struct thread_info *))
544 return_zero);
545 de_fault (to_stop,
546 (void (*) (void))
547 target_ignore);
548 de_fault (to_query,
549 (int (*) (int, char *, char *, int *))
550 return_zero);
551 de_fault (to_rcmd,
d9fcf2fb 552 (void (*) (char *, struct ui_file *))
0d06e24b
JM
553 tcomplain);
554 de_fault (to_enable_exception_callback,
555 (struct symtab_and_line * (*) (enum exception_event_kind, int))
556 nosupport_runtime);
557 de_fault (to_get_current_exception_event,
558 (struct exception_event_record * (*) (void))
559 nosupport_runtime);
560 de_fault (to_pid_to_exec_file,
561 (char *(*) (int))
562 return_zero);
563 de_fault (to_core_file_to_sym_file,
564 (char *(*) (char *))
565 return_zero);
566 de_fault (to_can_async_p,
567 (int (*) (void))
568 return_zero);
569 de_fault (to_is_async_p,
570 (int (*) (void))
571 return_zero);
572 de_fault (to_async,
573 (void (*) (void (*) (enum inferior_event_type, void*), void*))
574 tcomplain);
c906108c
SS
575#undef de_fault
576}
577
578/* Go through the target stack from top to bottom, copying over zero entries in
579 current_target. In effect, we are doing class inheritance through the
580 pushed target vectors. */
581
582static void
583update_current_target ()
584{
585 struct target_stack_item *item;
586 struct target_ops *t;
587
588 /* First, reset current_target */
589 memset (&current_target, 0, sizeof current_target);
590
591 for (item = target_stack; item; item = item->next)
592 {
593 t = item->target_ops;
594
595#define INHERIT(FIELD, TARGET) \
596 if (!current_target.FIELD) \
597 current_target.FIELD = TARGET->FIELD
598
599 INHERIT (to_shortname, t);
600 INHERIT (to_longname, t);
601 INHERIT (to_doc, t);
602 INHERIT (to_open, t);
603 INHERIT (to_close, t);
604 INHERIT (to_attach, t);
605 INHERIT (to_post_attach, t);
606 INHERIT (to_require_attach, t);
607 INHERIT (to_detach, t);
608 INHERIT (to_require_detach, t);
609 INHERIT (to_resume, t);
610 INHERIT (to_wait, t);
611 INHERIT (to_post_wait, t);
612 INHERIT (to_fetch_registers, t);
613 INHERIT (to_store_registers, t);
614 INHERIT (to_prepare_to_store, t);
615 INHERIT (to_xfer_memory, t);
616 INHERIT (to_files_info, t);
617 INHERIT (to_insert_breakpoint, t);
618 INHERIT (to_remove_breakpoint, t);
619 INHERIT (to_terminal_init, t);
620 INHERIT (to_terminal_inferior, t);
621 INHERIT (to_terminal_ours_for_output, t);
622 INHERIT (to_terminal_ours, t);
623 INHERIT (to_terminal_info, t);
624 INHERIT (to_kill, t);
625 INHERIT (to_load, t);
626 INHERIT (to_lookup_symbol, t);
627 INHERIT (to_create_inferior, t);
628 INHERIT (to_post_startup_inferior, t);
629 INHERIT (to_acknowledge_created_inferior, t);
630 INHERIT (to_clone_and_follow_inferior, t);
631 INHERIT (to_post_follow_inferior_by_clone, t);
632 INHERIT (to_insert_fork_catchpoint, t);
633 INHERIT (to_remove_fork_catchpoint, t);
634 INHERIT (to_insert_vfork_catchpoint, t);
635 INHERIT (to_remove_vfork_catchpoint, t);
636 INHERIT (to_has_forked, t);
637 INHERIT (to_has_vforked, t);
638 INHERIT (to_can_follow_vfork_prior_to_exec, t);
639 INHERIT (to_post_follow_vfork, t);
640 INHERIT (to_insert_exec_catchpoint, t);
641 INHERIT (to_remove_exec_catchpoint, t);
642 INHERIT (to_has_execd, t);
643 INHERIT (to_reported_exec_events_per_exec_call, t);
644 INHERIT (to_has_syscall_event, t);
645 INHERIT (to_has_exited, t);
646 INHERIT (to_mourn_inferior, t);
647 INHERIT (to_can_run, t);
648 INHERIT (to_notice_signals, t);
649 INHERIT (to_thread_alive, t);
b83266a0 650 INHERIT (to_find_new_threads, t);
ed9a39eb 651 INHERIT (to_pid_to_str, t);
0d06e24b 652 INHERIT (to_extra_thread_info, t);
c906108c
SS
653 INHERIT (to_stop, t);
654 INHERIT (to_query, t);
96baa820 655 INHERIT (to_rcmd, t);
c906108c
SS
656 INHERIT (to_enable_exception_callback, t);
657 INHERIT (to_get_current_exception_event, t);
658 INHERIT (to_pid_to_exec_file, t);
659 INHERIT (to_core_file_to_sym_file, t);
660 INHERIT (to_stratum, t);
661 INHERIT (DONT_USE, t);
662 INHERIT (to_has_all_memory, t);
663 INHERIT (to_has_memory, t);
664 INHERIT (to_has_stack, t);
665 INHERIT (to_has_registers, t);
666 INHERIT (to_has_execution, t);
667 INHERIT (to_has_thread_control, t);
668 INHERIT (to_sections, t);
669 INHERIT (to_sections_end, t);
6426a772
JM
670 INHERIT (to_can_async_p, t);
671 INHERIT (to_is_async_p, t);
672 INHERIT (to_async, t);
ed9a39eb 673 INHERIT (to_async_mask_value, t);
c906108c
SS
674 INHERIT (to_magic, t);
675
676#undef INHERIT
677 }
678}
679
680/* Push a new target type into the stack of the existing target accessors,
681 possibly superseding some of the existing accessors.
682
683 Result is zero if the pushed target ended up on top of the stack,
684 nonzero if at least one target is on top of it.
685
686 Rather than allow an empty stack, we always have the dummy target at
687 the bottom stratum, so we can call the function vectors without
688 checking them. */
689
690int
691push_target (t)
692 struct target_ops *t;
693{
694 struct target_stack_item *cur, *prev, *tmp;
695
696 /* Check magic number. If wrong, it probably means someone changed
697 the struct definition, but not all the places that initialize one. */
698 if (t->to_magic != OPS_MAGIC)
699 {
c5aa993b
JM
700 fprintf_unfiltered (gdb_stderr,
701 "Magic number of %s target struct wrong\n",
702 t->to_shortname);
703 abort ();
c906108c
SS
704 }
705
706 /* Find the proper stratum to install this target in. */
707
708 for (prev = NULL, cur = target_stack; cur; prev = cur, cur = cur->next)
709 {
c5aa993b 710 if ((int) (t->to_stratum) >= (int) (cur->target_ops->to_stratum))
c906108c
SS
711 break;
712 }
713
714 /* If there's already targets at this stratum, remove them. */
715
716 if (cur)
717 while (t->to_stratum == cur->target_ops->to_stratum)
718 {
719 /* There's already something on this stratum. Close it off. */
720 if (cur->target_ops->to_close)
721 (cur->target_ops->to_close) (0);
722 if (prev)
c5aa993b 723 prev->next = cur->next; /* Unchain old target_ops */
c906108c 724 else
c5aa993b 725 target_stack = cur->next; /* Unchain first on list */
c906108c
SS
726 tmp = cur->next;
727 free (cur);
728 cur = tmp;
729 }
730
731 /* We have removed all targets in our stratum, now add the new one. */
732
733 tmp = (struct target_stack_item *)
734 xmalloc (sizeof (struct target_stack_item));
735 tmp->next = cur;
736 tmp->target_ops = t;
737
738 if (prev)
739 prev->next = tmp;
740 else
741 target_stack = tmp;
742
743 update_current_target ();
744
c5aa993b 745 cleanup_target (&current_target); /* Fill in the gaps */
c906108c 746
c906108c
SS
747 if (targetdebug)
748 setup_target_debug ();
c906108c
SS
749
750 return prev != 0;
751}
752
753/* Remove a target_ops vector from the stack, wherever it may be.
754 Return how many times it was removed (0 or 1). */
755
756int
757unpush_target (t)
758 struct target_ops *t;
759{
760 struct target_stack_item *cur, *prev;
761
762 if (t->to_close)
763 t->to_close (0); /* Let it clean up */
764
765 /* Look for the specified target. Note that we assume that a target
766 can only occur once in the target stack. */
767
768 for (cur = target_stack, prev = NULL; cur; prev = cur, cur = cur->next)
769 if (cur->target_ops == t)
770 break;
771
772 if (!cur)
773 return 0; /* Didn't find target_ops, quit now */
774
775 /* Unchain the target */
776
777 if (!prev)
778 target_stack = cur->next;
779 else
780 prev->next = cur->next;
781
782 free (cur); /* Release the target_stack_item */
783
784 update_current_target ();
785 cleanup_target (&current_target);
786
787 return 1;
788}
789
790void
791pop_target ()
792{
c5aa993b 793 (current_target.to_close) (0); /* Let it clean up */
c906108c
SS
794 if (unpush_target (target_stack->target_ops) == 1)
795 return;
796
c5aa993b
JM
797 fprintf_unfiltered (gdb_stderr,
798 "pop_target couldn't find target %s\n",
799 current_target.to_shortname);
800 abort ();
c906108c
SS
801}
802
803#undef MIN
804#define MIN(A, B) (((A) <= (B)) ? (A) : (B))
805
806/* target_read_string -- read a null terminated string, up to LEN bytes,
807 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
808 Set *STRING to a pointer to malloc'd memory containing the data; the caller
809 is responsible for freeing it. Return the number of bytes successfully
810 read. */
811
812int
813target_read_string (memaddr, string, len, errnop)
814 CORE_ADDR memaddr;
815 char **string;
816 int len;
817 int *errnop;
818{
819 int tlen, origlen, offset, i;
820 char buf[4];
821 int errcode = 0;
822 char *buffer;
823 int buffer_allocated;
824 char *bufptr;
825 unsigned int nbytes_read = 0;
826
827 /* Small for testing. */
828 buffer_allocated = 4;
829 buffer = xmalloc (buffer_allocated);
830 bufptr = buffer;
831
832 origlen = len;
833
834 while (len > 0)
835 {
836 tlen = MIN (len, 4 - (memaddr & 3));
837 offset = memaddr & 3;
838
d4b2399a 839 errcode = target_xfer_memory (memaddr & ~3, buf, 4, 0);
c906108c
SS
840 if (errcode != 0)
841 {
842 /* The transfer request might have crossed the boundary to an
843 unallocated region of memory. Retry the transfer, requesting
844 a single byte. */
845 tlen = 1;
846 offset = 0;
d4b2399a 847 errcode = target_xfer_memory (memaddr, buf, 1, 0);
c906108c
SS
848 if (errcode != 0)
849 goto done;
850 }
851
852 if (bufptr - buffer + tlen > buffer_allocated)
853 {
854 unsigned int bytes;
855 bytes = bufptr - buffer;
856 buffer_allocated *= 2;
857 buffer = xrealloc (buffer, buffer_allocated);
858 bufptr = buffer + bytes;
859 }
860
861 for (i = 0; i < tlen; i++)
862 {
863 *bufptr++ = buf[i + offset];
864 if (buf[i + offset] == '\000')
865 {
866 nbytes_read += i + 1;
867 goto done;
868 }
869 }
870
871 memaddr += tlen;
872 len -= tlen;
873 nbytes_read += tlen;
874 }
c5aa993b 875done:
c906108c
SS
876 if (errnop != NULL)
877 *errnop = errcode;
878 if (string != NULL)
879 *string = buffer;
880 return nbytes_read;
881}
882
883/* Read LEN bytes of target memory at address MEMADDR, placing the results in
884 GDB's memory at MYADDR. Returns either 0 for success or an errno value
885 if any error occurs.
886
887 If an error occurs, no guarantee is made about the contents of the data at
888 MYADDR. In particular, the caller should not depend upon partial reads
889 filling the buffer with good data. There is no way for the caller to know
890 how much good data might have been transfered anyway. Callers that can
891 deal with partial reads should call target_read_memory_partial. */
892
893int
894target_read_memory (memaddr, myaddr, len)
895 CORE_ADDR memaddr;
896 char *myaddr;
897 int len;
898{
d4b2399a 899 return target_xfer_memory (memaddr, myaddr, len, 0);
c906108c
SS
900}
901
c906108c
SS
902int
903target_write_memory (memaddr, myaddr, len)
904 CORE_ADDR memaddr;
905 char *myaddr;
906 int len;
907{
d4b2399a 908 return target_xfer_memory (memaddr, myaddr, len, 1);
c906108c 909}
c5aa993b 910
c906108c
SS
911/* Move memory to or from the targets. Iterate until all of it has
912 been moved, if necessary. The top target gets priority; anything
913 it doesn't want, is offered to the next one down, etc. Note the
914 business with curlen: if an early target says "no, but I have a
915 boundary overlapping this xfer" then we shorten what we offer to
916 the subsequent targets so the early guy will get a chance at the
917 tail before the subsequent ones do.
918
919 Result is 0 or errno value. */
920
921static int
d4b2399a 922target_xfer_memory (memaddr, myaddr, len, write)
c906108c
SS
923 CORE_ADDR memaddr;
924 char *myaddr;
925 int len;
926 int write;
c906108c
SS
927{
928 int curlen;
929 int res;
930 struct target_ops *t;
931 struct target_stack_item *item;
932
933 /* Zero length requests are ok and require no work. */
934 if (len == 0)
935 return 0;
936
c906108c
SS
937 /* to_xfer_memory is not guaranteed to set errno, even when it returns
938 0. */
939 errno = 0;
940
941 /* The quick case is that the top target does it all. */
942 res = current_target.to_xfer_memory
c5aa993b 943 (memaddr, myaddr, len, write, &current_target);
c906108c
SS
944 if (res == len)
945 return 0;
946
947 if (res > 0)
948 goto bump;
949 /* If res <= 0 then we call it again in the loop. Ah well. */
950
951 for (; len > 0;)
952 {
953 curlen = len; /* Want to do it all */
954 for (item = target_stack; item; item = item->next)
955 {
956 t = item->target_ops;
957 if (!t->to_has_memory)
958 continue;
959
960 res = t->to_xfer_memory (memaddr, myaddr, curlen, write, t);
961 if (res > 0)
962 break; /* Handled all or part of xfer */
963 if (t->to_has_all_memory)
964 break;
965 }
966
967 if (res <= 0)
968 {
969 /* If this address is for nonexistent memory,
970 read zeros if reading, or do nothing if writing. Return error. */
971 if (!write)
972 memset (myaddr, 0, len);
973 if (errno == 0)
974 return EIO;
975 else
976 return errno;
977 }
c5aa993b 978 bump:
c906108c 979 memaddr += res;
c5aa993b
JM
980 myaddr += res;
981 len -= res;
c906108c
SS
982 }
983 return 0; /* We managed to cover it all somehow. */
984}
985
986
917317f4
JM
987/* Perform a partial memory transfer. */
988
989static int
990target_xfer_memory_partial (CORE_ADDR memaddr, char *buf, int len,
991 int write_p, int *err)
992{
993 int res;
994 int err_res;
995 int len_res;
996 struct target_ops *t;
997 struct target_stack_item *item;
998
999 /* Zero length requests are ok and require no work. */
1000 if (len == 0)
1001 {
1002 *err = 0;
1003 return 0;
1004 }
1005
1006 /* The quick case is that the top target does it all. */
1007 res = current_target.to_xfer_memory (memaddr, buf, len, write_p, &current_target);
1008 if (res > 0)
1009 {
1010 *err = 0;
1011 return res;
1012 }
1013
1014 /* xfer memory doesn't always reliably set errno. */
1015 errno = 0;
1016
1017 /* Try all levels of the target stack to see one can handle it. */
1018 for (item = target_stack; item; item = item->next)
1019 {
1020 t = item->target_ops;
1021 if (!t->to_has_memory)
1022 continue;
1023 res = t->to_xfer_memory (memaddr, buf, len, write_p, t);
1024 if (res > 0)
1025 {
1026 /* Handled all or part of xfer */
1027 *err = 0;
1028 return res;
1029 }
1030 if (t->to_has_all_memory)
1031 break;
1032 }
1033
1034 /* Total failure. Return error. */
1035 if (errno != 0)
1036 {
1037 *err = errno;
1038 return -1;
1039 }
1040 *err = EIO;
1041 return -1;
1042}
1043
1044int
1045target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1046{
1047 return target_xfer_memory_partial (memaddr, buf, len, 0, err);
1048}
1049
1050int
1051target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1052{
1053 return target_xfer_memory_partial (memaddr, buf, len, 1, err);
1054}
1055
c906108c
SS
1056/* ARGSUSED */
1057static void
1058target_info (args, from_tty)
1059 char *args;
1060 int from_tty;
1061{
1062 struct target_ops *t;
1063 struct target_stack_item *item;
1064 int has_all_mem = 0;
c5aa993b 1065
c906108c
SS
1066 if (symfile_objfile != NULL)
1067 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile->name);
1068
1069#ifdef FILES_INFO_HOOK
1070 if (FILES_INFO_HOOK ())
1071 return;
1072#endif
1073
1074 for (item = target_stack; item; item = item->next)
1075 {
1076 t = item->target_ops;
1077
1078 if (!t->to_has_memory)
1079 continue;
1080
c5aa993b 1081 if ((int) (t->to_stratum) <= (int) dummy_stratum)
c906108c
SS
1082 continue;
1083 if (has_all_mem)
c5aa993b
JM
1084 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1085 printf_unfiltered ("%s:\n", t->to_longname);
1086 (t->to_files_info) (t);
c906108c
SS
1087 has_all_mem = t->to_has_all_memory;
1088 }
1089}
1090
1091/* This is to be called by the open routine before it does
1092 anything. */
1093
1094void
1095target_preopen (from_tty)
1096 int from_tty;
1097{
c5aa993b 1098 dont_repeat ();
c906108c
SS
1099
1100 if (target_has_execution)
c5aa993b 1101 {
adf40b2e
JM
1102 if (!from_tty
1103 || query ("A program is being debugged already. Kill it? "))
c5aa993b 1104 target_kill ();
c906108c 1105 else
c5aa993b 1106 error ("Program not killed.");
c906108c
SS
1107 }
1108
1109 /* Calling target_kill may remove the target from the stack. But if
1110 it doesn't (which seems like a win for UDI), remove it now. */
1111
1112 if (target_has_execution)
1113 pop_target ();
1114}
1115
1116/* Detach a target after doing deferred register stores. */
1117
1118void
1119target_detach (args, from_tty)
1120 char *args;
1121 int from_tty;
1122{
1123 /* Handle any optimized stores to the inferior. */
1124#ifdef DO_DEFERRED_STORES
1125 DO_DEFERRED_STORES;
1126#endif
1127 (current_target.to_detach) (args, from_tty);
1128}
1129
1130void
1131target_link (modname, t_reloc)
1132 char *modname;
1133 CORE_ADDR *t_reloc;
1134{
c5aa993b 1135 if (STREQ (current_target.to_shortname, "rombug"))
c906108c
SS
1136 {
1137 (current_target.to_lookup_symbol) (modname, t_reloc);
1138 if (*t_reloc == 0)
c5aa993b 1139 error ("Unable to link to %s and get relocation in rombug", modname);
c906108c
SS
1140 }
1141 else
2acceee2 1142 *t_reloc = (CORE_ADDR) -1;
c906108c
SS
1143}
1144
ed9a39eb
JM
1145int
1146target_async_mask (int mask)
1147{
1148 int saved_async_masked_status = target_async_mask_value;
1149 target_async_mask_value = mask;
1150 return saved_async_masked_status;
1151}
1152
c906108c
SS
1153/* Look through the list of possible targets for a target that can
1154 execute a run or attach command without any other data. This is
1155 used to locate the default process stratum.
1156
1157 Result is always valid (error() is called for errors). */
1158
1159static struct target_ops *
1160find_default_run_target (do_mesg)
1161 char *do_mesg;
1162{
1163 struct target_ops **t;
1164 struct target_ops *runable = NULL;
1165 int count;
1166
1167 count = 0;
1168
1169 for (t = target_structs; t < target_structs + target_struct_size;
1170 ++t)
1171 {
c5aa993b 1172 if ((*t)->to_can_run && target_can_run (*t))
c906108c
SS
1173 {
1174 runable = *t;
1175 ++count;
1176 }
1177 }
1178
1179 if (count != 1)
1180 error ("Don't know how to %s. Try \"help target\".", do_mesg);
1181
1182 return runable;
1183}
1184
1185void
1186find_default_attach (args, from_tty)
1187 char *args;
1188 int from_tty;
1189{
1190 struct target_ops *t;
1191
c5aa993b 1192 t = find_default_run_target ("attach");
c906108c
SS
1193 (t->to_attach) (args, from_tty);
1194 return;
1195}
1196
1197void
1198find_default_require_attach (args, from_tty)
1199 char *args;
1200 int from_tty;
1201{
1202 struct target_ops *t;
1203
c5aa993b 1204 t = find_default_run_target ("require_attach");
c906108c
SS
1205 (t->to_require_attach) (args, from_tty);
1206 return;
1207}
1208
1209void
1210find_default_require_detach (pid, args, from_tty)
c5aa993b
JM
1211 int pid;
1212 char *args;
1213 int from_tty;
c906108c
SS
1214{
1215 struct target_ops *t;
1216
c5aa993b 1217 t = find_default_run_target ("require_detach");
c906108c
SS
1218 (t->to_require_detach) (pid, args, from_tty);
1219 return;
1220}
1221
1222void
1223find_default_create_inferior (exec_file, allargs, env)
1224 char *exec_file;
1225 char *allargs;
1226 char **env;
1227{
1228 struct target_ops *t;
1229
c5aa993b 1230 t = find_default_run_target ("run");
c906108c
SS
1231 (t->to_create_inferior) (exec_file, allargs, env);
1232 return;
1233}
1234
1235void
1236find_default_clone_and_follow_inferior (child_pid, followed_child)
c5aa993b
JM
1237 int child_pid;
1238 int *followed_child;
c906108c
SS
1239{
1240 struct target_ops *t;
1241
c5aa993b 1242 t = find_default_run_target ("run");
c906108c
SS
1243 (t->to_clone_and_follow_inferior) (child_pid, followed_child);
1244 return;
1245}
1246
1247static int
1248return_zero ()
1249{
1250 return 0;
1251}
1252
1253static int
1254return_one ()
1255{
1256 return 1;
1257}
1258
6426a772
JM
1259/*
1260 * Resize the to_sections pointer. Also make sure that anyone that
1261 * was holding on to an old value of it gets updated.
1262 * Returns the old size.
1263 */
1264
1265int
1266target_resize_to_sections (struct target_ops *target, int num_added)
1267{
1268 struct target_ops **t;
1269 struct section_table *old_value;
1270 int old_count;
1271
1272 old_value = target->to_sections;
1273
1274 if (target->to_sections)
1275 {
1276 old_count = target->to_sections_end - target->to_sections;
1277 target->to_sections = (struct section_table *)
1278 xrealloc ((char *) target->to_sections,
1279 (sizeof (struct section_table)) * (num_added + old_count));
1280 }
1281 else
1282 {
1283 old_count = 0;
1284 target->to_sections = (struct section_table *)
1285 xmalloc ((sizeof (struct section_table)) * num_added);
1286 }
1287 target->to_sections_end = target->to_sections + (num_added + old_count);
1288
1289 /* Check to see if anyone else was pointing to this structure.
1290 If old_value was null, then no one was. */
1291
1292 if (old_value)
1293 {
1294 for (t = target_structs; t < target_structs + target_struct_size;
1295 ++t)
1296 {
1297 if ((*t)->to_sections == old_value)
1298 {
1299 (*t)->to_sections = target->to_sections;
1300 (*t)->to_sections_end = target->to_sections_end;
1301 }
1302 }
1303 }
1304
1305 return old_count;
1306
1307}
1308
07cd4b97
JB
1309/* Remove all target sections taken from ABFD.
1310
1311 Scan the current target stack for targets whose section tables
1312 refer to sections from BFD, and remove those sections. We use this
1313 when we notice that the inferior has unloaded a shared object, for
1314 example. */
1315void
1316remove_target_sections (bfd *abfd)
1317{
1318 struct target_ops **t;
1319
1320 for (t = target_structs; t < target_structs + target_struct_size; t++)
1321 {
1322 struct section_table *src, *dest;
1323
1324 dest = (*t)->to_sections;
1325 for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++)
1326 if (src->bfd != abfd)
1327 {
1328 /* Keep this section. */
1329 if (dest < src) *dest = *src;
1330 dest++;
1331 }
1332
1333 /* If we've dropped any sections, resize the section table. */
1334 if (dest < src)
1335 target_resize_to_sections (*t, dest - src);
1336 }
1337}
1338
1339
1340
1341
7a292a7a
SS
1342/* Find a single runnable target in the stack and return it. If for
1343 some reason there is more than one, return NULL. */
1344
1345struct target_ops *
1346find_run_target ()
1347{
1348 struct target_ops **t;
1349 struct target_ops *runable = NULL;
1350 int count;
c5aa993b 1351
7a292a7a 1352 count = 0;
c5aa993b 1353
7a292a7a
SS
1354 for (t = target_structs; t < target_structs + target_struct_size; ++t)
1355 {
c5aa993b 1356 if ((*t)->to_can_run && target_can_run (*t))
7a292a7a
SS
1357 {
1358 runable = *t;
1359 ++count;
1360 }
1361 }
c5aa993b 1362
7a292a7a
SS
1363 return (count == 1 ? runable : NULL);
1364}
1365
ed9a39eb
JM
1366/* Find a single core_stratum target in the list of targets and return it.
1367 If for some reason there is more than one, return NULL. */
1368
c906108c
SS
1369struct target_ops *
1370find_core_target ()
1371{
1372 struct target_ops **t;
1373 struct target_ops *runable = NULL;
1374 int count;
c5aa993b 1375
c906108c 1376 count = 0;
c5aa993b 1377
c906108c
SS
1378 for (t = target_structs; t < target_structs + target_struct_size;
1379 ++t)
1380 {
1381 if ((*t)->to_stratum == core_stratum)
1382 {
1383 runable = *t;
1384 ++count;
1385 }
1386 }
c5aa993b
JM
1387
1388 return (count == 1 ? runable : NULL);
c906108c 1389}
ed9a39eb
JM
1390
1391/*
1392 * Find the next target down the stack from the specified target.
1393 */
1394
1395struct target_ops *
1396find_target_beneath (t)
1397 struct target_ops *t;
1398{
1399 struct target_stack_item *cur;
1400
1401 for (cur = target_stack; cur; cur = cur->next)
1402 if (cur->target_ops == t)
1403 break;
1404
1405 if (cur == NULL || cur->next == NULL)
1406 return NULL;
1407 else
1408 return cur->next->target_ops;
1409}
1410
c906108c
SS
1411\f
1412/* The inferior process has died. Long live the inferior! */
1413
1414void
1415generic_mourn_inferior ()
1416{
1417 extern int show_breakpoint_hit_counts;
1418
1419 inferior_pid = 0;
1420 attach_flag = 0;
1421 breakpoint_init_inferior (inf_exited);
1422 registers_changed ();
1423
1424#ifdef CLEAR_DEFERRED_STORES
1425 /* Delete any pending stores to the inferior... */
1426 CLEAR_DEFERRED_STORES;
1427#endif
1428
1429 reopen_exec_file ();
1430 reinit_frame_cache ();
1431
1432 /* It is confusing to the user for ignore counts to stick around
1433 from previous runs of the inferior. So clear them. */
1434 /* However, it is more confusing for the ignore counts to disappear when
1435 using hit counts. So don't clear them if we're counting hits. */
1436 if (!show_breakpoint_hit_counts)
1437 breakpoint_clear_ignore_counts ();
1438}
1439\f
1440/* This table must match in order and size the signals in enum target_signal
1441 in target.h. */
9846de1b 1442/* *INDENT-OFF* */
c906108c
SS
1443static struct {
1444 char *name;
1445 char *string;
1446 } signals [] =
1447{
1448 {"0", "Signal 0"},
1449 {"SIGHUP", "Hangup"},
1450 {"SIGINT", "Interrupt"},
1451 {"SIGQUIT", "Quit"},
1452 {"SIGILL", "Illegal instruction"},
1453 {"SIGTRAP", "Trace/breakpoint trap"},
1454 {"SIGABRT", "Aborted"},
1455 {"SIGEMT", "Emulation trap"},
1456 {"SIGFPE", "Arithmetic exception"},
1457 {"SIGKILL", "Killed"},
1458 {"SIGBUS", "Bus error"},
1459 {"SIGSEGV", "Segmentation fault"},
1460 {"SIGSYS", "Bad system call"},
1461 {"SIGPIPE", "Broken pipe"},
1462 {"SIGALRM", "Alarm clock"},
1463 {"SIGTERM", "Terminated"},
1464 {"SIGURG", "Urgent I/O condition"},
1465 {"SIGSTOP", "Stopped (signal)"},
1466 {"SIGTSTP", "Stopped (user)"},
1467 {"SIGCONT", "Continued"},
1468 {"SIGCHLD", "Child status changed"},
1469 {"SIGTTIN", "Stopped (tty input)"},
1470 {"SIGTTOU", "Stopped (tty output)"},
1471 {"SIGIO", "I/O possible"},
1472 {"SIGXCPU", "CPU time limit exceeded"},
1473 {"SIGXFSZ", "File size limit exceeded"},
1474 {"SIGVTALRM", "Virtual timer expired"},
1475 {"SIGPROF", "Profiling timer expired"},
1476 {"SIGWINCH", "Window size changed"},
1477 {"SIGLOST", "Resource lost"},
1478 {"SIGUSR1", "User defined signal 1"},
1479 {"SIGUSR2", "User defined signal 2"},
1480 {"SIGPWR", "Power fail/restart"},
1481 {"SIGPOLL", "Pollable event occurred"},
1482 {"SIGWIND", "SIGWIND"},
1483 {"SIGPHONE", "SIGPHONE"},
1484 {"SIGWAITING", "Process's LWPs are blocked"},
1485 {"SIGLWP", "Signal LWP"},
1486 {"SIGDANGER", "Swap space dangerously low"},
1487 {"SIGGRANT", "Monitor mode granted"},
1488 {"SIGRETRACT", "Need to relinquish monitor mode"},
1489 {"SIGMSG", "Monitor mode data available"},
1490 {"SIGSOUND", "Sound completed"},
1491 {"SIGSAK", "Secure attention"},
1492 {"SIGPRIO", "SIGPRIO"},
1493 {"SIG33", "Real-time event 33"},
1494 {"SIG34", "Real-time event 34"},
1495 {"SIG35", "Real-time event 35"},
1496 {"SIG36", "Real-time event 36"},
1497 {"SIG37", "Real-time event 37"},
1498 {"SIG38", "Real-time event 38"},
1499 {"SIG39", "Real-time event 39"},
1500 {"SIG40", "Real-time event 40"},
1501 {"SIG41", "Real-time event 41"},
1502 {"SIG42", "Real-time event 42"},
1503 {"SIG43", "Real-time event 43"},
1504 {"SIG44", "Real-time event 44"},
1505 {"SIG45", "Real-time event 45"},
1506 {"SIG46", "Real-time event 46"},
1507 {"SIG47", "Real-time event 47"},
1508 {"SIG48", "Real-time event 48"},
1509 {"SIG49", "Real-time event 49"},
1510 {"SIG50", "Real-time event 50"},
1511 {"SIG51", "Real-time event 51"},
1512 {"SIG52", "Real-time event 52"},
1513 {"SIG53", "Real-time event 53"},
1514 {"SIG54", "Real-time event 54"},
1515 {"SIG55", "Real-time event 55"},
1516 {"SIG56", "Real-time event 56"},
1517 {"SIG57", "Real-time event 57"},
1518 {"SIG58", "Real-time event 58"},
1519 {"SIG59", "Real-time event 59"},
1520 {"SIG60", "Real-time event 60"},
1521 {"SIG61", "Real-time event 61"},
1522 {"SIG62", "Real-time event 62"},
1523 {"SIG63", "Real-time event 63"},
cd0fc7c3 1524 {"SIGCANCEL", "LWP internal signal"},
d4f3574e 1525 {"SIG32", "Real-time event 32"},
c906108c
SS
1526
1527#if defined(MACH) || defined(__MACH__)
1528 /* Mach exceptions */
1529 {"EXC_BAD_ACCESS", "Could not access memory"},
1530 {"EXC_BAD_INSTRUCTION", "Illegal instruction/operand"},
1531 {"EXC_ARITHMETIC", "Arithmetic exception"},
1532 {"EXC_EMULATION", "Emulation instruction"},
1533 {"EXC_SOFTWARE", "Software generated exception"},
1534 {"EXC_BREAKPOINT", "Breakpoint"},
1535#endif
7a292a7a
SS
1536 {"SIGINFO", "Information request"},
1537
c906108c
SS
1538 {NULL, "Unknown signal"},
1539 {NULL, "Internal error: printing TARGET_SIGNAL_DEFAULT"},
1540
1541 /* Last entry, used to check whether the table is the right size. */
1542 {NULL, "TARGET_SIGNAL_MAGIC"}
1543};
9846de1b 1544/* *INDENT-ON* */
c906108c 1545
c5aa993b
JM
1546
1547
c906108c
SS
1548/* Return the string for a signal. */
1549char *
1550target_signal_to_string (sig)
1551 enum target_signal sig;
1552{
7a292a7a
SS
1553 if ((sig >= TARGET_SIGNAL_FIRST) && (sig <= TARGET_SIGNAL_LAST))
1554 return signals[sig].string;
1555 else
1556 return signals[TARGET_SIGNAL_UNKNOWN].string;
c906108c
SS
1557}
1558
1559/* Return the name for a signal. */
1560char *
1561target_signal_to_name (sig)
1562 enum target_signal sig;
1563{
1564 if (sig == TARGET_SIGNAL_UNKNOWN)
1565 /* I think the code which prints this will always print it along with
1566 the string, so no need to be verbose. */
1567 return "?";
1568 return signals[sig].name;
1569}
1570
1571/* Given a name, return its signal. */
1572enum target_signal
1573target_signal_from_name (name)
1574 char *name;
1575{
1576 enum target_signal sig;
1577
1578 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
1579 for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
1580 questionable; seems like by now people should call it SIGABRT
1581 instead. */
1582
1583 /* This ugly cast brought to you by the native VAX compiler. */
1584 for (sig = TARGET_SIGNAL_HUP;
1585 signals[sig].name != NULL;
c5aa993b 1586 sig = (enum target_signal) ((int) sig + 1))
c906108c
SS
1587 if (STREQ (name, signals[sig].name))
1588 return sig;
1589 return TARGET_SIGNAL_UNKNOWN;
1590}
1591\f
1592/* The following functions are to help certain targets deal
1593 with the signal/waitstatus stuff. They could just as well be in
1594 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
1595
1596/* Convert host signal to our signals. */
1597enum target_signal
1598target_signal_from_host (hostsig)
1599 int hostsig;
1600{
1601 /* A switch statement would make sense but would require special kludges
1602 to deal with the cases where more than one signal has the same number. */
1603
c5aa993b
JM
1604 if (hostsig == 0)
1605 return TARGET_SIGNAL_0;
c906108c
SS
1606
1607#if defined (SIGHUP)
c5aa993b
JM
1608 if (hostsig == SIGHUP)
1609 return TARGET_SIGNAL_HUP;
c906108c
SS
1610#endif
1611#if defined (SIGINT)
c5aa993b
JM
1612 if (hostsig == SIGINT)
1613 return TARGET_SIGNAL_INT;
c906108c
SS
1614#endif
1615#if defined (SIGQUIT)
c5aa993b
JM
1616 if (hostsig == SIGQUIT)
1617 return TARGET_SIGNAL_QUIT;
c906108c
SS
1618#endif
1619#if defined (SIGILL)
c5aa993b
JM
1620 if (hostsig == SIGILL)
1621 return TARGET_SIGNAL_ILL;
c906108c
SS
1622#endif
1623#if defined (SIGTRAP)
c5aa993b
JM
1624 if (hostsig == SIGTRAP)
1625 return TARGET_SIGNAL_TRAP;
c906108c
SS
1626#endif
1627#if defined (SIGABRT)
c5aa993b
JM
1628 if (hostsig == SIGABRT)
1629 return TARGET_SIGNAL_ABRT;
c906108c
SS
1630#endif
1631#if defined (SIGEMT)
c5aa993b
JM
1632 if (hostsig == SIGEMT)
1633 return TARGET_SIGNAL_EMT;
c906108c
SS
1634#endif
1635#if defined (SIGFPE)
c5aa993b
JM
1636 if (hostsig == SIGFPE)
1637 return TARGET_SIGNAL_FPE;
c906108c
SS
1638#endif
1639#if defined (SIGKILL)
c5aa993b
JM
1640 if (hostsig == SIGKILL)
1641 return TARGET_SIGNAL_KILL;
c906108c
SS
1642#endif
1643#if defined (SIGBUS)
c5aa993b
JM
1644 if (hostsig == SIGBUS)
1645 return TARGET_SIGNAL_BUS;
c906108c
SS
1646#endif
1647#if defined (SIGSEGV)
c5aa993b
JM
1648 if (hostsig == SIGSEGV)
1649 return TARGET_SIGNAL_SEGV;
c906108c
SS
1650#endif
1651#if defined (SIGSYS)
c5aa993b
JM
1652 if (hostsig == SIGSYS)
1653 return TARGET_SIGNAL_SYS;
c906108c
SS
1654#endif
1655#if defined (SIGPIPE)
c5aa993b
JM
1656 if (hostsig == SIGPIPE)
1657 return TARGET_SIGNAL_PIPE;
c906108c
SS
1658#endif
1659#if defined (SIGALRM)
c5aa993b
JM
1660 if (hostsig == SIGALRM)
1661 return TARGET_SIGNAL_ALRM;
c906108c
SS
1662#endif
1663#if defined (SIGTERM)
c5aa993b
JM
1664 if (hostsig == SIGTERM)
1665 return TARGET_SIGNAL_TERM;
c906108c
SS
1666#endif
1667#if defined (SIGUSR1)
c5aa993b
JM
1668 if (hostsig == SIGUSR1)
1669 return TARGET_SIGNAL_USR1;
c906108c
SS
1670#endif
1671#if defined (SIGUSR2)
c5aa993b
JM
1672 if (hostsig == SIGUSR2)
1673 return TARGET_SIGNAL_USR2;
c906108c
SS
1674#endif
1675#if defined (SIGCLD)
c5aa993b
JM
1676 if (hostsig == SIGCLD)
1677 return TARGET_SIGNAL_CHLD;
c906108c
SS
1678#endif
1679#if defined (SIGCHLD)
c5aa993b
JM
1680 if (hostsig == SIGCHLD)
1681 return TARGET_SIGNAL_CHLD;
c906108c
SS
1682#endif
1683#if defined (SIGPWR)
c5aa993b
JM
1684 if (hostsig == SIGPWR)
1685 return TARGET_SIGNAL_PWR;
c906108c
SS
1686#endif
1687#if defined (SIGWINCH)
c5aa993b
JM
1688 if (hostsig == SIGWINCH)
1689 return TARGET_SIGNAL_WINCH;
c906108c
SS
1690#endif
1691#if defined (SIGURG)
c5aa993b
JM
1692 if (hostsig == SIGURG)
1693 return TARGET_SIGNAL_URG;
c906108c
SS
1694#endif
1695#if defined (SIGIO)
c5aa993b
JM
1696 if (hostsig == SIGIO)
1697 return TARGET_SIGNAL_IO;
c906108c
SS
1698#endif
1699#if defined (SIGPOLL)
c5aa993b
JM
1700 if (hostsig == SIGPOLL)
1701 return TARGET_SIGNAL_POLL;
c906108c
SS
1702#endif
1703#if defined (SIGSTOP)
c5aa993b
JM
1704 if (hostsig == SIGSTOP)
1705 return TARGET_SIGNAL_STOP;
c906108c
SS
1706#endif
1707#if defined (SIGTSTP)
c5aa993b
JM
1708 if (hostsig == SIGTSTP)
1709 return TARGET_SIGNAL_TSTP;
c906108c
SS
1710#endif
1711#if defined (SIGCONT)
c5aa993b
JM
1712 if (hostsig == SIGCONT)
1713 return TARGET_SIGNAL_CONT;
c906108c
SS
1714#endif
1715#if defined (SIGTTIN)
c5aa993b
JM
1716 if (hostsig == SIGTTIN)
1717 return TARGET_SIGNAL_TTIN;
c906108c
SS
1718#endif
1719#if defined (SIGTTOU)
c5aa993b
JM
1720 if (hostsig == SIGTTOU)
1721 return TARGET_SIGNAL_TTOU;
c906108c
SS
1722#endif
1723#if defined (SIGVTALRM)
c5aa993b
JM
1724 if (hostsig == SIGVTALRM)
1725 return TARGET_SIGNAL_VTALRM;
c906108c
SS
1726#endif
1727#if defined (SIGPROF)
c5aa993b
JM
1728 if (hostsig == SIGPROF)
1729 return TARGET_SIGNAL_PROF;
c906108c
SS
1730#endif
1731#if defined (SIGXCPU)
c5aa993b
JM
1732 if (hostsig == SIGXCPU)
1733 return TARGET_SIGNAL_XCPU;
c906108c
SS
1734#endif
1735#if defined (SIGXFSZ)
c5aa993b
JM
1736 if (hostsig == SIGXFSZ)
1737 return TARGET_SIGNAL_XFSZ;
c906108c
SS
1738#endif
1739#if defined (SIGWIND)
c5aa993b
JM
1740 if (hostsig == SIGWIND)
1741 return TARGET_SIGNAL_WIND;
c906108c
SS
1742#endif
1743#if defined (SIGPHONE)
c5aa993b
JM
1744 if (hostsig == SIGPHONE)
1745 return TARGET_SIGNAL_PHONE;
c906108c
SS
1746#endif
1747#if defined (SIGLOST)
c5aa993b
JM
1748 if (hostsig == SIGLOST)
1749 return TARGET_SIGNAL_LOST;
c906108c
SS
1750#endif
1751#if defined (SIGWAITING)
c5aa993b
JM
1752 if (hostsig == SIGWAITING)
1753 return TARGET_SIGNAL_WAITING;
c906108c 1754#endif
cd0fc7c3 1755#if defined (SIGCANCEL)
c5aa993b
JM
1756 if (hostsig == SIGCANCEL)
1757 return TARGET_SIGNAL_CANCEL;
cd0fc7c3 1758#endif
c906108c 1759#if defined (SIGLWP)
c5aa993b
JM
1760 if (hostsig == SIGLWP)
1761 return TARGET_SIGNAL_LWP;
c906108c
SS
1762#endif
1763#if defined (SIGDANGER)
c5aa993b
JM
1764 if (hostsig == SIGDANGER)
1765 return TARGET_SIGNAL_DANGER;
c906108c
SS
1766#endif
1767#if defined (SIGGRANT)
c5aa993b
JM
1768 if (hostsig == SIGGRANT)
1769 return TARGET_SIGNAL_GRANT;
c906108c
SS
1770#endif
1771#if defined (SIGRETRACT)
c5aa993b
JM
1772 if (hostsig == SIGRETRACT)
1773 return TARGET_SIGNAL_RETRACT;
c906108c
SS
1774#endif
1775#if defined (SIGMSG)
c5aa993b
JM
1776 if (hostsig == SIGMSG)
1777 return TARGET_SIGNAL_MSG;
c906108c
SS
1778#endif
1779#if defined (SIGSOUND)
c5aa993b
JM
1780 if (hostsig == SIGSOUND)
1781 return TARGET_SIGNAL_SOUND;
c906108c
SS
1782#endif
1783#if defined (SIGSAK)
c5aa993b
JM
1784 if (hostsig == SIGSAK)
1785 return TARGET_SIGNAL_SAK;
c906108c
SS
1786#endif
1787#if defined (SIGPRIO)
c5aa993b
JM
1788 if (hostsig == SIGPRIO)
1789 return TARGET_SIGNAL_PRIO;
c906108c
SS
1790#endif
1791
1792 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1793#if defined (EXC_BAD_ACCESS) && defined (_NSIG)
c5aa993b
JM
1794 if (hostsig == _NSIG + EXC_BAD_ACCESS)
1795 return TARGET_EXC_BAD_ACCESS;
c906108c
SS
1796#endif
1797#if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
c5aa993b
JM
1798 if (hostsig == _NSIG + EXC_BAD_INSTRUCTION)
1799 return TARGET_EXC_BAD_INSTRUCTION;
c906108c
SS
1800#endif
1801#if defined (EXC_ARITHMETIC) && defined (_NSIG)
c5aa993b
JM
1802 if (hostsig == _NSIG + EXC_ARITHMETIC)
1803 return TARGET_EXC_ARITHMETIC;
c906108c
SS
1804#endif
1805#if defined (EXC_EMULATION) && defined (_NSIG)
c5aa993b
JM
1806 if (hostsig == _NSIG + EXC_EMULATION)
1807 return TARGET_EXC_EMULATION;
c906108c
SS
1808#endif
1809#if defined (EXC_SOFTWARE) && defined (_NSIG)
c5aa993b
JM
1810 if (hostsig == _NSIG + EXC_SOFTWARE)
1811 return TARGET_EXC_SOFTWARE;
c906108c
SS
1812#endif
1813#if defined (EXC_BREAKPOINT) && defined (_NSIG)
c5aa993b
JM
1814 if (hostsig == _NSIG + EXC_BREAKPOINT)
1815 return TARGET_EXC_BREAKPOINT;
c906108c
SS
1816#endif
1817
7a292a7a 1818#if defined (SIGINFO)
c5aa993b
JM
1819 if (hostsig == SIGINFO)
1820 return TARGET_SIGNAL_INFO;
7a292a7a
SS
1821#endif
1822
c906108c
SS
1823#if defined (REALTIME_LO)
1824 if (hostsig >= REALTIME_LO && hostsig < REALTIME_HI)
d4f3574e
SS
1825 {
1826 /* This block of TARGET_SIGNAL_REALTIME value is in order. */
1827 if (33 <= hostsig && hostsig <= 63)
1828 return (enum target_signal)
1829 (hostsig - 33 + (int) TARGET_SIGNAL_REALTIME_33);
1830 else if (hostsig == 32)
1831 return TARGET_SIGNAL_REALTIME_32;
1832 else
1833 error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
1834 }
c906108c
SS
1835#endif
1836 return TARGET_SIGNAL_UNKNOWN;
1837}
1838
c2d11a7d
JM
1839/* Convert a OURSIG (an enum target_signal) to the form used by the
1840 target operating system (refered to as the ``host'') or zero if the
1841 equivalent host signal is not available. Set/clear OURSIG_OK
1842 accordingly. */
1843
1844static int
1845do_target_signal_to_host (enum target_signal oursig,
1846 int *oursig_ok)
c906108c 1847{
c2d11a7d 1848 *oursig_ok = 1;
c906108c
SS
1849 switch (oursig)
1850 {
c5aa993b
JM
1851 case TARGET_SIGNAL_0:
1852 return 0;
c906108c
SS
1853
1854#if defined (SIGHUP)
c5aa993b
JM
1855 case TARGET_SIGNAL_HUP:
1856 return SIGHUP;
c906108c
SS
1857#endif
1858#if defined (SIGINT)
c5aa993b
JM
1859 case TARGET_SIGNAL_INT:
1860 return SIGINT;
c906108c
SS
1861#endif
1862#if defined (SIGQUIT)
c5aa993b
JM
1863 case TARGET_SIGNAL_QUIT:
1864 return SIGQUIT;
c906108c
SS
1865#endif
1866#if defined (SIGILL)
c5aa993b
JM
1867 case TARGET_SIGNAL_ILL:
1868 return SIGILL;
c906108c
SS
1869#endif
1870#if defined (SIGTRAP)
c5aa993b
JM
1871 case TARGET_SIGNAL_TRAP:
1872 return SIGTRAP;
c906108c
SS
1873#endif
1874#if defined (SIGABRT)
c5aa993b
JM
1875 case TARGET_SIGNAL_ABRT:
1876 return SIGABRT;
c906108c
SS
1877#endif
1878#if defined (SIGEMT)
c5aa993b
JM
1879 case TARGET_SIGNAL_EMT:
1880 return SIGEMT;
c906108c
SS
1881#endif
1882#if defined (SIGFPE)
c5aa993b
JM
1883 case TARGET_SIGNAL_FPE:
1884 return SIGFPE;
c906108c
SS
1885#endif
1886#if defined (SIGKILL)
c5aa993b
JM
1887 case TARGET_SIGNAL_KILL:
1888 return SIGKILL;
c906108c
SS
1889#endif
1890#if defined (SIGBUS)
c5aa993b
JM
1891 case TARGET_SIGNAL_BUS:
1892 return SIGBUS;
c906108c
SS
1893#endif
1894#if defined (SIGSEGV)
c5aa993b
JM
1895 case TARGET_SIGNAL_SEGV:
1896 return SIGSEGV;
c906108c
SS
1897#endif
1898#if defined (SIGSYS)
c5aa993b
JM
1899 case TARGET_SIGNAL_SYS:
1900 return SIGSYS;
c906108c
SS
1901#endif
1902#if defined (SIGPIPE)
c5aa993b
JM
1903 case TARGET_SIGNAL_PIPE:
1904 return SIGPIPE;
c906108c
SS
1905#endif
1906#if defined (SIGALRM)
c5aa993b
JM
1907 case TARGET_SIGNAL_ALRM:
1908 return SIGALRM;
c906108c
SS
1909#endif
1910#if defined (SIGTERM)
c5aa993b
JM
1911 case TARGET_SIGNAL_TERM:
1912 return SIGTERM;
c906108c
SS
1913#endif
1914#if defined (SIGUSR1)
c5aa993b
JM
1915 case TARGET_SIGNAL_USR1:
1916 return SIGUSR1;
c906108c
SS
1917#endif
1918#if defined (SIGUSR2)
c5aa993b
JM
1919 case TARGET_SIGNAL_USR2:
1920 return SIGUSR2;
c906108c
SS
1921#endif
1922#if defined (SIGCHLD) || defined (SIGCLD)
c5aa993b 1923 case TARGET_SIGNAL_CHLD:
c906108c
SS
1924#if defined (SIGCHLD)
1925 return SIGCHLD;
1926#else
1927 return SIGCLD;
1928#endif
1929#endif /* SIGCLD or SIGCHLD */
1930#if defined (SIGPWR)
c5aa993b
JM
1931 case TARGET_SIGNAL_PWR:
1932 return SIGPWR;
c906108c
SS
1933#endif
1934#if defined (SIGWINCH)
c5aa993b
JM
1935 case TARGET_SIGNAL_WINCH:
1936 return SIGWINCH;
c906108c
SS
1937#endif
1938#if defined (SIGURG)
c5aa993b
JM
1939 case TARGET_SIGNAL_URG:
1940 return SIGURG;
c906108c
SS
1941#endif
1942#if defined (SIGIO)
c5aa993b
JM
1943 case TARGET_SIGNAL_IO:
1944 return SIGIO;
c906108c
SS
1945#endif
1946#if defined (SIGPOLL)
c5aa993b
JM
1947 case TARGET_SIGNAL_POLL:
1948 return SIGPOLL;
c906108c
SS
1949#endif
1950#if defined (SIGSTOP)
c5aa993b
JM
1951 case TARGET_SIGNAL_STOP:
1952 return SIGSTOP;
c906108c
SS
1953#endif
1954#if defined (SIGTSTP)
c5aa993b
JM
1955 case TARGET_SIGNAL_TSTP:
1956 return SIGTSTP;
c906108c
SS
1957#endif
1958#if defined (SIGCONT)
c5aa993b
JM
1959 case TARGET_SIGNAL_CONT:
1960 return SIGCONT;
c906108c
SS
1961#endif
1962#if defined (SIGTTIN)
c5aa993b
JM
1963 case TARGET_SIGNAL_TTIN:
1964 return SIGTTIN;
c906108c
SS
1965#endif
1966#if defined (SIGTTOU)
c5aa993b
JM
1967 case TARGET_SIGNAL_TTOU:
1968 return SIGTTOU;
c906108c
SS
1969#endif
1970#if defined (SIGVTALRM)
c5aa993b
JM
1971 case TARGET_SIGNAL_VTALRM:
1972 return SIGVTALRM;
c906108c
SS
1973#endif
1974#if defined (SIGPROF)
c5aa993b
JM
1975 case TARGET_SIGNAL_PROF:
1976 return SIGPROF;
c906108c
SS
1977#endif
1978#if defined (SIGXCPU)
c5aa993b
JM
1979 case TARGET_SIGNAL_XCPU:
1980 return SIGXCPU;
c906108c
SS
1981#endif
1982#if defined (SIGXFSZ)
c5aa993b
JM
1983 case TARGET_SIGNAL_XFSZ:
1984 return SIGXFSZ;
c906108c
SS
1985#endif
1986#if defined (SIGWIND)
c5aa993b
JM
1987 case TARGET_SIGNAL_WIND:
1988 return SIGWIND;
c906108c
SS
1989#endif
1990#if defined (SIGPHONE)
c5aa993b
JM
1991 case TARGET_SIGNAL_PHONE:
1992 return SIGPHONE;
c906108c
SS
1993#endif
1994#if defined (SIGLOST)
c5aa993b
JM
1995 case TARGET_SIGNAL_LOST:
1996 return SIGLOST;
c906108c
SS
1997#endif
1998#if defined (SIGWAITING)
c5aa993b
JM
1999 case TARGET_SIGNAL_WAITING:
2000 return SIGWAITING;
c906108c 2001#endif
cd0fc7c3 2002#if defined (SIGCANCEL)
c5aa993b
JM
2003 case TARGET_SIGNAL_CANCEL:
2004 return SIGCANCEL;
cd0fc7c3 2005#endif
c906108c 2006#if defined (SIGLWP)
c5aa993b
JM
2007 case TARGET_SIGNAL_LWP:
2008 return SIGLWP;
c906108c
SS
2009#endif
2010#if defined (SIGDANGER)
c5aa993b
JM
2011 case TARGET_SIGNAL_DANGER:
2012 return SIGDANGER;
c906108c
SS
2013#endif
2014#if defined (SIGGRANT)
c5aa993b
JM
2015 case TARGET_SIGNAL_GRANT:
2016 return SIGGRANT;
c906108c
SS
2017#endif
2018#if defined (SIGRETRACT)
c5aa993b
JM
2019 case TARGET_SIGNAL_RETRACT:
2020 return SIGRETRACT;
c906108c
SS
2021#endif
2022#if defined (SIGMSG)
c5aa993b
JM
2023 case TARGET_SIGNAL_MSG:
2024 return SIGMSG;
c906108c
SS
2025#endif
2026#if defined (SIGSOUND)
c5aa993b
JM
2027 case TARGET_SIGNAL_SOUND:
2028 return SIGSOUND;
c906108c
SS
2029#endif
2030#if defined (SIGSAK)
c5aa993b
JM
2031 case TARGET_SIGNAL_SAK:
2032 return SIGSAK;
c906108c
SS
2033#endif
2034#if defined (SIGPRIO)
c5aa993b
JM
2035 case TARGET_SIGNAL_PRIO:
2036 return SIGPRIO;
c906108c
SS
2037#endif
2038
2039 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
2040#if defined (EXC_BAD_ACCESS) && defined (_NSIG)
c5aa993b
JM
2041 case TARGET_EXC_BAD_ACCESS:
2042 return _NSIG + EXC_BAD_ACCESS;
c906108c
SS
2043#endif
2044#if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
c5aa993b
JM
2045 case TARGET_EXC_BAD_INSTRUCTION:
2046 return _NSIG + EXC_BAD_INSTRUCTION;
c906108c
SS
2047#endif
2048#if defined (EXC_ARITHMETIC) && defined (_NSIG)
c5aa993b
JM
2049 case TARGET_EXC_ARITHMETIC:
2050 return _NSIG + EXC_ARITHMETIC;
c906108c
SS
2051#endif
2052#if defined (EXC_EMULATION) && defined (_NSIG)
c5aa993b
JM
2053 case TARGET_EXC_EMULATION:
2054 return _NSIG + EXC_EMULATION;
c906108c
SS
2055#endif
2056#if defined (EXC_SOFTWARE) && defined (_NSIG)
c5aa993b
JM
2057 case TARGET_EXC_SOFTWARE:
2058 return _NSIG + EXC_SOFTWARE;
c906108c
SS
2059#endif
2060#if defined (EXC_BREAKPOINT) && defined (_NSIG)
c5aa993b
JM
2061 case TARGET_EXC_BREAKPOINT:
2062 return _NSIG + EXC_BREAKPOINT;
c906108c
SS
2063#endif
2064
7a292a7a 2065#if defined (SIGINFO)
c5aa993b
JM
2066 case TARGET_SIGNAL_INFO:
2067 return SIGINFO;
7a292a7a
SS
2068#endif
2069
c906108c
SS
2070 default:
2071#if defined (REALTIME_LO)
2072 if (oursig >= TARGET_SIGNAL_REALTIME_33
2073 && oursig <= TARGET_SIGNAL_REALTIME_63)
2074 {
e95a43ad
MK
2075 /* This block of signals is continuous, and
2076 TARGET_SIGNAL_REALTIME_33 is 33 by definition. */
c906108c 2077 int retsig =
e95a43ad
MK
2078 (int) oursig - (int) TARGET_SIGNAL_REALTIME_33 + 33;
2079 if (retsig >= REALTIME_LO && retsig < REALTIME_HI)
c906108c
SS
2080 return retsig;
2081 }
e95a43ad
MK
2082#if (REALTIME_LO < 33)
2083 else if (oursig == TARGET_SIGNAL_REALTIME_32)
2084 {
2085 /* TARGET_SIGNAL_REALTIME_32 isn't contiguous with
2086 TARGET_SIGNAL_REALTIME_33. It is 32 by definition. */
2087 return 32;
2088 }
2089#endif
c906108c 2090#endif
c2d11a7d
JM
2091 *oursig_ok = 0;
2092 return 0;
2093 }
2094}
2095
2096int
2097target_signal_to_host_p (enum target_signal oursig)
2098{
2099 int oursig_ok;
2100 do_target_signal_to_host (oursig, &oursig_ok);
2101 return oursig_ok;
2102}
2103
2104int
2105target_signal_to_host (enum target_signal oursig)
2106{
2107 int oursig_ok;
2108 int targ_signo = do_target_signal_to_host (oursig, &oursig_ok);
2109 if (!oursig_ok)
2110 {
c906108c 2111 /* The user might be trying to do "signal SIGSAK" where this system
c5aa993b 2112 doesn't have SIGSAK. */
c906108c
SS
2113 warning ("Signal %s does not exist on this system.\n",
2114 target_signal_to_name (oursig));
2115 return 0;
2116 }
c2d11a7d
JM
2117 else
2118 return targ_signo;
c906108c
SS
2119}
2120
2121/* Helper function for child_wait and the Lynx derivatives of child_wait.
2122 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
2123 translation of that in OURSTATUS. */
2124void
2125store_waitstatus (ourstatus, hoststatus)
2126 struct target_waitstatus *ourstatus;
2127 int hoststatus;
2128{
2129#ifdef CHILD_SPECIAL_WAITSTATUS
2130 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
2131 if it wants to deal with hoststatus. */
2132 if (CHILD_SPECIAL_WAITSTATUS (ourstatus, hoststatus))
2133 return;
2134#endif
2135
2136 if (WIFEXITED (hoststatus))
2137 {
2138 ourstatus->kind = TARGET_WAITKIND_EXITED;
2139 ourstatus->value.integer = WEXITSTATUS (hoststatus);
2140 }
2141 else if (!WIFSTOPPED (hoststatus))
2142 {
2143 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
2144 ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus));
2145 }
2146 else
2147 {
2148 ourstatus->kind = TARGET_WAITKIND_STOPPED;
2149 ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus));
2150 }
2151}
2152\f
2153/* In some circumstances we allow a command to specify a numeric
2154 signal. The idea is to keep these circumstances limited so that
2155 users (and scripts) develop portable habits. For comparison,
2156 POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
2157 numeric signal at all is obscelescent. We are slightly more
2158 lenient and allow 1-15 which should match host signal numbers on
2159 most systems. Use of symbolic signal names is strongly encouraged. */
2160
2161enum target_signal
2162target_signal_from_command (num)
2163 int num;
2164{
2165 if (num >= 1 && num <= 15)
c5aa993b 2166 return (enum target_signal) num;
c906108c
SS
2167 error ("Only signals 1-15 are valid as numeric signals.\n\
2168Use \"info signals\" for a list of symbolic signals.");
2169}
2170\f
2171/* Returns zero to leave the inferior alone, one to interrupt it. */
2172int (*target_activity_function) PARAMS ((void));
2173int target_activity_fd;
2174\f
2175/* Convert a normal process ID to a string. Returns the string in a static
2176 buffer. */
2177
2178char *
2179normal_pid_to_str (pid)
2180 int pid;
2181{
2182 static char buf[30];
2183
2184 if (STREQ (current_target.to_shortname, "remote"))
104c1213 2185 sprintf (buf, "thread %d", pid);
c906108c 2186 else
104c1213 2187 sprintf (buf, "process %d", pid);
c906108c
SS
2188
2189 return buf;
2190}
2191
2192/* Some targets (such as ttrace-based HPUX) don't allow us to request
2193 notification of inferior events such as fork and vork immediately
2194 after the inferior is created. (This because of how gdb gets an
2195 inferior created via invoking a shell to do it. In such a scenario,
2196 if the shell init file has commands in it, the shell will fork and
2197 exec for each of those commands, and we will see each such fork
2198 event. Very bad.)
c5aa993b 2199
c906108c
SS
2200 This function is used by all targets that allow us to request
2201 notification of forks, etc at inferior creation time; e.g., in
2202 target_acknowledge_forked_child.
c5aa993b 2203 */
392a587b 2204static void
c906108c 2205normal_target_post_startup_inferior (pid)
c5aa993b 2206 int pid;
c906108c
SS
2207{
2208 /* This space intentionally left blank. */
2209}
2210
2211/* Set up the handful of non-empty slots needed by the dummy target
2212 vector. */
2213
2214static void
2215init_dummy_target ()
2216{
2217 dummy_target.to_shortname = "None";
2218 dummy_target.to_longname = "None";
2219 dummy_target.to_doc = "";
2220 dummy_target.to_attach = find_default_attach;
2221 dummy_target.to_require_attach = find_default_require_attach;
2222 dummy_target.to_require_detach = find_default_require_detach;
2223 dummy_target.to_create_inferior = find_default_create_inferior;
2224 dummy_target.to_clone_and_follow_inferior = find_default_clone_and_follow_inferior;
ed9a39eb 2225 dummy_target.to_pid_to_str = normal_pid_to_str;
c906108c
SS
2226 dummy_target.to_stratum = dummy_stratum;
2227 dummy_target.to_magic = OPS_MAGIC;
2228}
c906108c 2229\f
c5aa993b 2230
c906108c
SS
2231static struct target_ops debug_target;
2232
2233static void
2234debug_to_open (args, from_tty)
2235 char *args;
2236 int from_tty;
2237{
2238 debug_target.to_open (args, from_tty);
2239
96baa820 2240 fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty);
c906108c
SS
2241}
2242
2243static void
2244debug_to_close (quitting)
2245 int quitting;
2246{
2247 debug_target.to_close (quitting);
2248
96baa820 2249 fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting);
c906108c
SS
2250}
2251
2252static void
2253debug_to_attach (args, from_tty)
2254 char *args;
2255 int from_tty;
2256{
2257 debug_target.to_attach (args, from_tty);
2258
96baa820 2259 fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty);
c906108c
SS
2260}
2261
2262
2263static void
2264debug_to_post_attach (pid)
c5aa993b 2265 int pid;
c906108c
SS
2266{
2267 debug_target.to_post_attach (pid);
2268
96baa820 2269 fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid);
c906108c
SS
2270}
2271
2272static void
2273debug_to_require_attach (args, from_tty)
2274 char *args;
2275 int from_tty;
2276{
2277 debug_target.to_require_attach (args, from_tty);
2278
96baa820 2279 fprintf_unfiltered (gdb_stdlog,
c906108c
SS
2280 "target_require_attach (%s, %d)\n", args, from_tty);
2281}
2282
2283static void
2284debug_to_detach (args, from_tty)
2285 char *args;
2286 int from_tty;
2287{
2288 debug_target.to_detach (args, from_tty);
2289
96baa820 2290 fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty);
c906108c
SS
2291}
2292
2293static void
2294debug_to_require_detach (pid, args, from_tty)
c5aa993b
JM
2295 int pid;
2296 char *args;
2297 int from_tty;
c906108c
SS
2298{
2299 debug_target.to_require_detach (pid, args, from_tty);
2300
96baa820 2301 fprintf_unfiltered (gdb_stdlog,
c5aa993b 2302 "target_require_detach (%d, %s, %d)\n", pid, args, from_tty);
c906108c
SS
2303}
2304
2305static void
2306debug_to_resume (pid, step, siggnal)
2307 int pid;
2308 int step;
2309 enum target_signal siggnal;
2310{
2311 debug_target.to_resume (pid, step, siggnal);
2312
96baa820 2313 fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", pid,
c906108c
SS
2314 step ? "step" : "continue",
2315 target_signal_to_name (siggnal));
2316}
2317
2318static int
2319debug_to_wait (pid, status)
2320 int pid;
2321 struct target_waitstatus *status;
2322{
2323 int retval;
2324
2325 retval = debug_target.to_wait (pid, status);
2326
96baa820 2327 fprintf_unfiltered (gdb_stdlog,
c906108c 2328 "target_wait (%d, status) = %d, ", pid, retval);
96baa820 2329 fprintf_unfiltered (gdb_stdlog, "status->kind = ");
c906108c
SS
2330 switch (status->kind)
2331 {
2332 case TARGET_WAITKIND_EXITED:
96baa820 2333 fprintf_unfiltered (gdb_stdlog, "exited, status = %d\n",
c906108c
SS
2334 status->value.integer);
2335 break;
2336 case TARGET_WAITKIND_STOPPED:
96baa820 2337 fprintf_unfiltered (gdb_stdlog, "stopped, signal = %s\n",
c906108c
SS
2338 target_signal_to_name (status->value.sig));
2339 break;
2340 case TARGET_WAITKIND_SIGNALLED:
96baa820 2341 fprintf_unfiltered (gdb_stdlog, "signalled, signal = %s\n",
c906108c
SS
2342 target_signal_to_name (status->value.sig));
2343 break;
2344 case TARGET_WAITKIND_LOADED:
96baa820 2345 fprintf_unfiltered (gdb_stdlog, "loaded\n");
c906108c
SS
2346 break;
2347 case TARGET_WAITKIND_FORKED:
96baa820 2348 fprintf_unfiltered (gdb_stdlog, "forked\n");
c906108c
SS
2349 break;
2350 case TARGET_WAITKIND_VFORKED:
96baa820 2351 fprintf_unfiltered (gdb_stdlog, "vforked\n");
c906108c
SS
2352 break;
2353 case TARGET_WAITKIND_EXECD:
96baa820 2354 fprintf_unfiltered (gdb_stdlog, "execd\n");
c906108c
SS
2355 break;
2356 case TARGET_WAITKIND_SPURIOUS:
96baa820 2357 fprintf_unfiltered (gdb_stdlog, "spurious\n");
c906108c
SS
2358 break;
2359 default:
96baa820 2360 fprintf_unfiltered (gdb_stdlog, "unknown???\n");
c906108c
SS
2361 break;
2362 }
2363
2364 return retval;
2365}
2366
2367static void
2368debug_to_post_wait (pid, status)
c5aa993b
JM
2369 int pid;
2370 int status;
c906108c
SS
2371{
2372 debug_target.to_post_wait (pid, status);
2373
96baa820 2374 fprintf_unfiltered (gdb_stdlog, "target_post_wait (%d, %d)\n",
c906108c
SS
2375 pid, status);
2376}
2377
2378static void
2379debug_to_fetch_registers (regno)
2380 int regno;
2381{
2382 debug_target.to_fetch_registers (regno);
2383
96baa820 2384 fprintf_unfiltered (gdb_stdlog, "target_fetch_registers (%s)",
c906108c
SS
2385 regno != -1 ? REGISTER_NAME (regno) : "-1");
2386 if (regno != -1)
104c1213 2387 fprintf_unfiltered (gdb_stdlog, " = 0x%lx %ld",
c906108c 2388 (unsigned long) read_register (regno),
104c1213 2389 (unsigned long) read_register (regno));
96baa820 2390 fprintf_unfiltered (gdb_stdlog, "\n");
c906108c
SS
2391}
2392
2393static void
2394debug_to_store_registers (regno)
2395 int regno;
2396{
2397 debug_target.to_store_registers (regno);
2398
2399 if (regno >= 0 && regno < NUM_REGS)
104c1213 2400 fprintf_unfiltered (gdb_stdlog, "target_store_registers (%s) = 0x%lx %ld\n",
c906108c
SS
2401 REGISTER_NAME (regno),
2402 (unsigned long) read_register (regno),
2403 (unsigned long) read_register (regno));
2404 else
96baa820 2405 fprintf_unfiltered (gdb_stdlog, "target_store_registers (%d)\n", regno);
c906108c
SS
2406}
2407
2408static void
2409debug_to_prepare_to_store ()
2410{
2411 debug_target.to_prepare_to_store ();
2412
96baa820 2413 fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n");
c906108c
SS
2414}
2415
2416static int
2417debug_to_xfer_memory (memaddr, myaddr, len, write, target)
2418 CORE_ADDR memaddr;
2419 char *myaddr;
2420 int len;
2421 int write;
2422 struct target_ops *target;
2423{
2424 int retval;
2425
2426 retval = debug_target.to_xfer_memory (memaddr, myaddr, len, write, target);
2427
96baa820 2428 fprintf_unfiltered (gdb_stdlog,
c906108c 2429 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
c5aa993b 2430 (unsigned int) memaddr, /* possable truncate long long */
c906108c
SS
2431 len, write ? "write" : "read", retval);
2432
c5aa993b 2433
c906108c
SS
2434
2435 if (retval > 0)
2436 {
2437 int i;
2438
96baa820 2439 fputs_unfiltered (", bytes =", gdb_stdlog);
c906108c
SS
2440 for (i = 0; i < retval; i++)
2441 {
2442 if ((((long) &(myaddr[i])) & 0xf) == 0)
96baa820
JM
2443 fprintf_unfiltered (gdb_stdlog, "\n");
2444 fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff);
c906108c
SS
2445 }
2446 }
2447
96baa820 2448 fputc_unfiltered ('\n', gdb_stdlog);
c906108c
SS
2449
2450 return retval;
2451}
2452
2453static void
2454debug_to_files_info (target)
2455 struct target_ops *target;
2456{
2457 debug_target.to_files_info (target);
2458
96baa820 2459 fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n");
c906108c
SS
2460}
2461
2462static int
2463debug_to_insert_breakpoint (addr, save)
2464 CORE_ADDR addr;
2465 char *save;
2466{
2467 int retval;
2468
2469 retval = debug_target.to_insert_breakpoint (addr, save);
2470
96baa820 2471 fprintf_unfiltered (gdb_stdlog,
104c1213
JM
2472 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
2473 (unsigned long) addr,
2474 (unsigned long) retval);
c906108c
SS
2475 return retval;
2476}
2477
2478static int
2479debug_to_remove_breakpoint (addr, save)
2480 CORE_ADDR addr;
2481 char *save;
2482{
2483 int retval;
2484
2485 retval = debug_target.to_remove_breakpoint (addr, save);
2486
96baa820 2487 fprintf_unfiltered (gdb_stdlog,
104c1213
JM
2488 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
2489 (unsigned long) addr,
2490 (unsigned long) retval);
c906108c
SS
2491 return retval;
2492}
2493
2494static void
2495debug_to_terminal_init ()
2496{
2497 debug_target.to_terminal_init ();
2498
96baa820 2499 fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n");
c906108c
SS
2500}
2501
2502static void
2503debug_to_terminal_inferior ()
2504{
2505 debug_target.to_terminal_inferior ();
2506
96baa820 2507 fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n");
c906108c
SS
2508}
2509
2510static void
2511debug_to_terminal_ours_for_output ()
2512{
2513 debug_target.to_terminal_ours_for_output ();
2514
96baa820 2515 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n");
c906108c
SS
2516}
2517
2518static void
2519debug_to_terminal_ours ()
2520{
2521 debug_target.to_terminal_ours ();
2522
96baa820 2523 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n");
c906108c
SS
2524}
2525
2526static void
2527debug_to_terminal_info (arg, from_tty)
2528 char *arg;
2529 int from_tty;
2530{
2531 debug_target.to_terminal_info (arg, from_tty);
2532
96baa820 2533 fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg,
c906108c
SS
2534 from_tty);
2535}
2536
2537static void
2538debug_to_kill ()
2539{
2540 debug_target.to_kill ();
2541
96baa820 2542 fprintf_unfiltered (gdb_stdlog, "target_kill ()\n");
c906108c
SS
2543}
2544
2545static void
2546debug_to_load (args, from_tty)
2547 char *args;
2548 int from_tty;
2549{
2550 debug_target.to_load (args, from_tty);
2551
96baa820 2552 fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty);
c906108c
SS
2553}
2554
2555static int
2556debug_to_lookup_symbol (name, addrp)
2557 char *name;
2558 CORE_ADDR *addrp;
2559{
2560 int retval;
2561
2562 retval = debug_target.to_lookup_symbol (name, addrp);
2563
96baa820 2564 fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name);
c906108c
SS
2565
2566 return retval;
2567}
2568
2569static void
2570debug_to_create_inferior (exec_file, args, env)
2571 char *exec_file;
2572 char *args;
2573 char **env;
2574{
2575 debug_target.to_create_inferior (exec_file, args, env);
2576
96baa820 2577 fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx)\n",
c906108c
SS
2578 exec_file, args);
2579}
2580
2581static void
2582debug_to_post_startup_inferior (pid)
c5aa993b 2583 int pid;
c906108c
SS
2584{
2585 debug_target.to_post_startup_inferior (pid);
2586
96baa820 2587 fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n",
c906108c
SS
2588 pid);
2589}
2590
2591static void
2592debug_to_acknowledge_created_inferior (pid)
c5aa993b 2593 int pid;
c906108c
SS
2594{
2595 debug_target.to_acknowledge_created_inferior (pid);
2596
96baa820 2597 fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n",
c906108c
SS
2598 pid);
2599}
2600
2601static void
2602debug_to_clone_and_follow_inferior (child_pid, followed_child)
c5aa993b
JM
2603 int child_pid;
2604 int *followed_child;
c906108c
SS
2605{
2606 debug_target.to_clone_and_follow_inferior (child_pid, followed_child);
2607
96baa820 2608 fprintf_unfiltered (gdb_stdlog,
c906108c
SS
2609 "target_clone_and_follow_inferior (%d, %d)\n",
2610 child_pid, *followed_child);
2611}
2612
2613static void
2614debug_to_post_follow_inferior_by_clone ()
2615{
2616 debug_target.to_post_follow_inferior_by_clone ();
2617
96baa820 2618 fprintf_unfiltered (gdb_stdlog, "target_post_follow_inferior_by_clone ()\n");
c906108c
SS
2619}
2620
2621static int
2622debug_to_insert_fork_catchpoint (pid)
c5aa993b 2623 int pid;
c906108c 2624{
c5aa993b 2625 int retval;
c906108c
SS
2626
2627 retval = debug_target.to_insert_fork_catchpoint (pid);
2628
96baa820 2629 fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d) = %d\n",
c5aa993b 2630 pid, retval);
c906108c
SS
2631
2632 return retval;
2633}
2634
2635static int
2636debug_to_remove_fork_catchpoint (pid)
c5aa993b 2637 int pid;
c906108c 2638{
c5aa993b 2639 int retval;
c906108c
SS
2640
2641 retval = debug_target.to_remove_fork_catchpoint (pid);
2642
96baa820 2643 fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n",
c5aa993b 2644 pid, retval);
c906108c
SS
2645
2646 return retval;
2647}
2648
2649static int
2650debug_to_insert_vfork_catchpoint (pid)
c5aa993b 2651 int pid;
c906108c 2652{
c5aa993b 2653 int retval;
c906108c
SS
2654
2655 retval = debug_target.to_insert_vfork_catchpoint (pid);
2656
96baa820 2657 fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)= %d\n",
c5aa993b 2658 pid, retval);
c906108c
SS
2659
2660 return retval;
2661}
2662
2663static int
2664debug_to_remove_vfork_catchpoint (pid)
c5aa993b 2665 int pid;
c906108c 2666{
c5aa993b 2667 int retval;
c906108c
SS
2668
2669 retval = debug_target.to_remove_vfork_catchpoint (pid);
2670
96baa820 2671 fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n",
c5aa993b 2672 pid, retval);
c906108c
SS
2673
2674 return retval;
2675}
2676
2677static int
2678debug_to_has_forked (pid, child_pid)
c5aa993b
JM
2679 int pid;
2680 int *child_pid;
c906108c 2681{
c5aa993b 2682 int has_forked;
c906108c
SS
2683
2684 has_forked = debug_target.to_has_forked (pid, child_pid);
2685
96baa820 2686 fprintf_unfiltered (gdb_stdlog, "target_has_forked (%d, %d) = %d\n",
c5aa993b 2687 pid, *child_pid, has_forked);
c906108c
SS
2688
2689 return has_forked;
2690}
2691
2692static int
2693debug_to_has_vforked (pid, child_pid)
c5aa993b
JM
2694 int pid;
2695 int *child_pid;
c906108c 2696{
c5aa993b 2697 int has_vforked;
c906108c
SS
2698
2699 has_vforked = debug_target.to_has_vforked (pid, child_pid);
2700
96baa820 2701 fprintf_unfiltered (gdb_stdlog, "target_has_vforked (%d, %d) = %d\n",
c5aa993b 2702 pid, *child_pid, has_vforked);
c906108c
SS
2703
2704 return has_vforked;
2705}
2706
2707static int
2708debug_to_can_follow_vfork_prior_to_exec ()
2709{
c5aa993b 2710 int can_immediately_follow_vfork;
c906108c
SS
2711
2712 can_immediately_follow_vfork = debug_target.to_can_follow_vfork_prior_to_exec ();
2713
96baa820 2714 fprintf_unfiltered (gdb_stdlog, "target_can_follow_vfork_prior_to_exec () = %d\n",
c5aa993b 2715 can_immediately_follow_vfork);
c906108c
SS
2716
2717 return can_immediately_follow_vfork;
2718}
2719
2720static void
2721debug_to_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child)
c5aa993b
JM
2722 int parent_pid;
2723 int followed_parent;
2724 int child_pid;
2725 int followed_child;
c906108c
SS
2726{
2727 debug_target.to_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child);
2728
96baa820 2729 fprintf_unfiltered (gdb_stdlog,
c906108c 2730 "target_post_follow_vfork (%d, %d, %d, %d)\n",
c5aa993b 2731 parent_pid, followed_parent, child_pid, followed_child);
c906108c
SS
2732}
2733
2734static int
2735debug_to_insert_exec_catchpoint (pid)
c5aa993b 2736 int pid;
c906108c 2737{
c5aa993b 2738 int retval;
c906108c
SS
2739
2740 retval = debug_target.to_insert_exec_catchpoint (pid);
2741
96baa820 2742 fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d) = %d\n",
c5aa993b 2743 pid, retval);
c906108c
SS
2744
2745 return retval;
2746}
2747
2748static int
2749debug_to_remove_exec_catchpoint (pid)
c5aa993b 2750 int pid;
c906108c 2751{
c5aa993b 2752 int retval;
c906108c
SS
2753
2754 retval = debug_target.to_remove_exec_catchpoint (pid);
2755
96baa820 2756 fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n",
c5aa993b 2757 pid, retval);
c906108c
SS
2758
2759 return retval;
2760}
2761
2762static int
2763debug_to_has_execd (pid, execd_pathname)
c5aa993b
JM
2764 int pid;
2765 char **execd_pathname;
c906108c 2766{
c5aa993b 2767 int has_execd;
c906108c
SS
2768
2769 has_execd = debug_target.to_has_execd (pid, execd_pathname);
2770
96baa820 2771 fprintf_unfiltered (gdb_stdlog, "target_has_execd (%d, %s) = %d\n",
c5aa993b 2772 pid, (*execd_pathname ? *execd_pathname : "<NULL>"),
7a292a7a 2773 has_execd);
c906108c
SS
2774
2775 return has_execd;
2776}
2777
2778static int
2779debug_to_reported_exec_events_per_exec_call ()
2780{
c5aa993b 2781 int reported_exec_events;
c906108c
SS
2782
2783 reported_exec_events = debug_target.to_reported_exec_events_per_exec_call ();
2784
96baa820 2785 fprintf_unfiltered (gdb_stdlog,
c906108c 2786 "target_reported_exec_events_per_exec_call () = %d\n",
c5aa993b 2787 reported_exec_events);
c906108c
SS
2788
2789 return reported_exec_events;
2790}
2791
2792static int
2793debug_to_has_syscall_event (pid, kind, syscall_id)
c5aa993b
JM
2794 int pid;
2795 enum target_waitkind *kind;
2796 int *syscall_id;
c906108c 2797{
c5aa993b
JM
2798 int has_syscall_event;
2799 char *kind_spelling = "??";
c906108c
SS
2800
2801 has_syscall_event = debug_target.to_has_syscall_event (pid, kind, syscall_id);
2802 if (has_syscall_event)
2803 {
2804 switch (*kind)
c5aa993b
JM
2805 {
2806 case TARGET_WAITKIND_SYSCALL_ENTRY:
2807 kind_spelling = "SYSCALL_ENTRY";
2808 break;
2809 case TARGET_WAITKIND_SYSCALL_RETURN:
2810 kind_spelling = "SYSCALL_RETURN";
2811 break;
2812 default:
2813 break;
2814 }
c906108c
SS
2815 }
2816
96baa820 2817 fprintf_unfiltered (gdb_stdlog,
c906108c 2818 "target_has_syscall_event (%d, %s, %d) = %d\n",
c5aa993b 2819 pid, kind_spelling, *syscall_id, has_syscall_event);
c906108c
SS
2820
2821 return has_syscall_event;
2822}
2823
2824static int
2825debug_to_has_exited (pid, wait_status, exit_status)
c5aa993b
JM
2826 int pid;
2827 int wait_status;
2828 int *exit_status;
c906108c 2829{
c5aa993b 2830 int has_exited;
c906108c
SS
2831
2832 has_exited = debug_target.to_has_exited (pid, wait_status, exit_status);
2833
96baa820 2834 fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n",
c5aa993b 2835 pid, wait_status, *exit_status, has_exited);
c906108c
SS
2836
2837 return has_exited;
2838}
2839
2840static void
2841debug_to_mourn_inferior ()
2842{
2843 debug_target.to_mourn_inferior ();
2844
96baa820 2845 fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n");
c906108c
SS
2846}
2847
2848static int
2849debug_to_can_run ()
2850{
2851 int retval;
2852
2853 retval = debug_target.to_can_run ();
2854
96baa820 2855 fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval);
c906108c
SS
2856
2857 return retval;
2858}
2859
2860static void
2861debug_to_notice_signals (pid)
2862 int pid;
2863{
2864 debug_target.to_notice_signals (pid);
2865
96baa820 2866 fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n", pid);
c906108c
SS
2867}
2868
2869static int
2870debug_to_thread_alive (pid)
2871 int pid;
2872{
2873 int retval;
2874
2875 retval = debug_target.to_thread_alive (pid);
2876
96baa820 2877 fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n",
c906108c
SS
2878 pid, retval);
2879
2880 return retval;
2881}
2882
0d06e24b
JM
2883static void
2884debug_to_find_new_threads ()
2885{
2886 debug_target.to_find_new_threads ();
2887
2888 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog);
2889}
2890
c906108c
SS
2891static void
2892debug_to_stop ()
2893{
2894 debug_target.to_stop ();
2895
96baa820 2896 fprintf_unfiltered (gdb_stdlog, "target_stop ()\n");
c906108c
SS
2897}
2898
2899static int
2900debug_to_query (type, req, resp, siz)
c5aa993b
JM
2901 int type;
2902 char *req;
2903 char *resp;
2904 int *siz;
c906108c
SS
2905{
2906 int retval;
2907
2908 retval = debug_target.to_query (type, req, resp, siz);
2909
96baa820 2910 fprintf_unfiltered (gdb_stdlog, "target_query (%c, %s, %s, %d) = %d\n", type, req, resp, *siz, retval);
c906108c
SS
2911
2912 return retval;
2913}
2914
96baa820
JM
2915static void
2916debug_to_rcmd (char *command,
d9fcf2fb 2917 struct ui_file *outbuf)
96baa820
JM
2918{
2919 debug_target.to_rcmd (command, outbuf);
2920 fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command);
2921}
2922
c906108c
SS
2923static struct symtab_and_line *
2924debug_to_enable_exception_callback (kind, enable)
c5aa993b
JM
2925 enum exception_event_kind kind;
2926 int enable;
c906108c 2927{
7a292a7a
SS
2928 struct symtab_and_line *result;
2929 result = debug_target.to_enable_exception_callback (kind, enable);
96baa820 2930 fprintf_unfiltered (gdb_stdlog,
c906108c
SS
2931 "target get_exception_callback_sal (%d, %d)\n",
2932 kind, enable);
7a292a7a 2933 return result;
c906108c
SS
2934}
2935
2936static struct exception_event_record *
2937debug_to_get_current_exception_event ()
2938{
7a292a7a 2939 struct exception_event_record *result;
c5aa993b 2940 result = debug_target.to_get_current_exception_event ();
96baa820 2941 fprintf_unfiltered (gdb_stdlog, "target get_current_exception_event ()\n");
7a292a7a 2942 return result;
c906108c
SS
2943}
2944
2945static char *
2946debug_to_pid_to_exec_file (pid)
c5aa993b 2947 int pid;
c906108c 2948{
c5aa993b 2949 char *exec_file;
c906108c
SS
2950
2951 exec_file = debug_target.to_pid_to_exec_file (pid);
2952
96baa820 2953 fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n",
c5aa993b 2954 pid, exec_file);
c906108c
SS
2955
2956 return exec_file;
2957}
2958
2959static char *
2960debug_to_core_file_to_sym_file (core)
c5aa993b 2961 char *core;
c906108c 2962{
c5aa993b 2963 char *sym_file;
c906108c
SS
2964
2965 sym_file = debug_target.to_core_file_to_sym_file (core);
2966
96baa820 2967 fprintf_unfiltered (gdb_stdlog, "target_core_file_to_sym_file (%s) = %s\n",
c5aa993b 2968 core, sym_file);
c906108c
SS
2969
2970 return sym_file;
2971}
2972
2973static void
2974setup_target_debug ()
2975{
2976 memcpy (&debug_target, &current_target, sizeof debug_target);
2977
2978 current_target.to_open = debug_to_open;
2979 current_target.to_close = debug_to_close;
2980 current_target.to_attach = debug_to_attach;
2981 current_target.to_post_attach = debug_to_post_attach;
2982 current_target.to_require_attach = debug_to_require_attach;
2983 current_target.to_detach = debug_to_detach;
2984 current_target.to_require_detach = debug_to_require_detach;
2985 current_target.to_resume = debug_to_resume;
2986 current_target.to_wait = debug_to_wait;
2987 current_target.to_post_wait = debug_to_post_wait;
2988 current_target.to_fetch_registers = debug_to_fetch_registers;
2989 current_target.to_store_registers = debug_to_store_registers;
2990 current_target.to_prepare_to_store = debug_to_prepare_to_store;
2991 current_target.to_xfer_memory = debug_to_xfer_memory;
2992 current_target.to_files_info = debug_to_files_info;
2993 current_target.to_insert_breakpoint = debug_to_insert_breakpoint;
2994 current_target.to_remove_breakpoint = debug_to_remove_breakpoint;
2995 current_target.to_terminal_init = debug_to_terminal_init;
2996 current_target.to_terminal_inferior = debug_to_terminal_inferior;
2997 current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output;
2998 current_target.to_terminal_ours = debug_to_terminal_ours;
2999 current_target.to_terminal_info = debug_to_terminal_info;
3000 current_target.to_kill = debug_to_kill;
3001 current_target.to_load = debug_to_load;
3002 current_target.to_lookup_symbol = debug_to_lookup_symbol;
3003 current_target.to_create_inferior = debug_to_create_inferior;
3004 current_target.to_post_startup_inferior = debug_to_post_startup_inferior;
3005 current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior;
3006 current_target.to_clone_and_follow_inferior = debug_to_clone_and_follow_inferior;
3007 current_target.to_post_follow_inferior_by_clone = debug_to_post_follow_inferior_by_clone;
3008 current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint;
3009 current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
3010 current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
3011 current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint;
3012 current_target.to_has_forked = debug_to_has_forked;
3013 current_target.to_has_vforked = debug_to_has_vforked;
3014 current_target.to_can_follow_vfork_prior_to_exec = debug_to_can_follow_vfork_prior_to_exec;
3015 current_target.to_post_follow_vfork = debug_to_post_follow_vfork;
3016 current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint;
3017 current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
3018 current_target.to_has_execd = debug_to_has_execd;
3019 current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call;
3020 current_target.to_has_syscall_event = debug_to_has_syscall_event;
3021 current_target.to_has_exited = debug_to_has_exited;
3022 current_target.to_mourn_inferior = debug_to_mourn_inferior;
3023 current_target.to_can_run = debug_to_can_run;
3024 current_target.to_notice_signals = debug_to_notice_signals;
3025 current_target.to_thread_alive = debug_to_thread_alive;
0d06e24b 3026 current_target.to_find_new_threads = debug_to_find_new_threads;
c906108c
SS
3027 current_target.to_stop = debug_to_stop;
3028 current_target.to_query = debug_to_query;
96baa820 3029 current_target.to_rcmd = debug_to_rcmd;
c906108c
SS
3030 current_target.to_enable_exception_callback = debug_to_enable_exception_callback;
3031 current_target.to_get_current_exception_event = debug_to_get_current_exception_event;
3032 current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
3033 current_target.to_core_file_to_sym_file = debug_to_core_file_to_sym_file;
3034
3035}
c906108c 3036\f
c5aa993b
JM
3037
3038static char targ_desc[] =
3039"Names of targets and files being debugged.\n\
c906108c
SS
3040Shows the entire stack of targets currently in use (including the exec-file,\n\
3041core-file, and process, if any), as well as the symbol file name.";
3042
96baa820
JM
3043static void
3044do_monitor_command (char *cmd,
3045 int from_tty)
3046{
2b5fe715
AC
3047 if ((current_target.to_rcmd
3048 == (void (*) (char *, struct ui_file *)) tcomplain)
96baa820 3049 || (current_target.to_rcmd == debug_to_rcmd
2b5fe715
AC
3050 && (debug_target.to_rcmd
3051 == (void (*) (char *, struct ui_file *)) tcomplain)))
96baa820
JM
3052 {
3053 error ("\"monitor\" command not supported by this target.\n");
3054 }
3055 target_rcmd (cmd, gdb_stdtarg);
3056}
3057
c906108c
SS
3058void
3059initialize_targets ()
3060{
3061 init_dummy_target ();
3062 push_target (&dummy_target);
3063
3064 add_info ("target", target_info, targ_desc);
3065 add_info ("files", target_info, targ_desc);
3066
c906108c 3067 add_show_from_set (
5d161b24 3068 add_set_cmd ("target", class_maintenance, var_zinteger,
c5aa993b
JM
3069 (char *) &targetdebug,
3070 "Set target debugging.\n\
5d161b24
DB
3071When non-zero, target debugging is enabled.", &setdebuglist),
3072 &showdebuglist);
c906108c 3073
96baa820
JM
3074
3075 add_com ("monitor", class_obscure, do_monitor_command,
3076 "Send a command to the remote monitor (remote targets only).");
3077
c906108c
SS
3078 if (!STREQ (signals[TARGET_SIGNAL_LAST].string, "TARGET_SIGNAL_MAGIC"))
3079 abort ();
3080}
This page took 0.222543 seconds and 4 git commands to generate.