1 /* Select target systems and architectures at runtime for GDB.
2 Copyright 1990, 1992-1995, 1998-2000 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include "gdb_string.h"
39 static void target_info (char *, int);
41 static void cleanup_target (struct target_ops
*);
43 static void maybe_kill_then_create_inferior (char *, char *, char **);
45 static void default_clone_and_follow_inferior (int, int *);
47 static void maybe_kill_then_attach (char *, int);
49 static void kill_or_be_killed (int);
51 static void default_terminal_info (char *, int);
53 static int nosymbol (char *, CORE_ADDR
*);
55 static void tcomplain (void);
57 static int nomemory (CORE_ADDR
, char *, int, int, struct target_ops
*);
59 static int return_zero (void);
61 static int return_one (void);
63 void target_ignore (void);
65 static void target_command (char *, int);
67 static struct target_ops
*find_default_run_target (char *);
69 static void update_current_target (void);
71 static void nosupport_runtime (void);
73 static void normal_target_post_startup_inferior (int pid
);
75 /* Transfer LEN bytes between target address MEMADDR and GDB address
76 MYADDR. Returns 0 for success, errno code for failure (which
77 includes partial transfers -- if you want a more useful response to
78 partial transfers, try either target_read_memory_partial or
79 target_write_memory_partial). */
82 target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
);
84 static void init_dummy_target (void);
86 static void debug_to_open (char *, int);
88 static void debug_to_close (int);
90 static void debug_to_attach (char *, int);
92 static void debug_to_detach (char *, int);
94 static void debug_to_resume (int, int, enum target_signal
);
96 static int debug_to_wait (int, struct target_waitstatus
*);
98 static void debug_to_fetch_registers (int);
100 static void debug_to_store_registers (int);
102 static void debug_to_prepare_to_store (void);
105 debug_to_xfer_memory (CORE_ADDR
, char *, int, int, struct target_ops
*);
107 static void debug_to_files_info (struct target_ops
*);
109 static int debug_to_insert_breakpoint (CORE_ADDR
, char *);
111 static int debug_to_remove_breakpoint (CORE_ADDR
, char *);
113 static void debug_to_terminal_init (void);
115 static void debug_to_terminal_inferior (void);
117 static void debug_to_terminal_ours_for_output (void);
119 static void debug_to_terminal_ours (void);
121 static void debug_to_terminal_info (char *, int);
123 static void debug_to_kill (void);
125 static void debug_to_load (char *, int);
127 static int debug_to_lookup_symbol (char *, CORE_ADDR
*);
129 static void debug_to_create_inferior (char *, char *, char **);
131 static void debug_to_mourn_inferior (void);
133 static int debug_to_can_run (void);
135 static void debug_to_notice_signals (int);
137 static int debug_to_thread_alive (int);
139 static void debug_to_stop (void);
141 static int debug_to_query (int /*char */ , char *, char *, int *);
143 /* Pointer to array of target architecture structures; the size of the
144 array; the current index into the array; the allocated size of the
146 struct target_ops
**target_structs
;
147 unsigned target_struct_size
;
148 unsigned target_struct_index
;
149 unsigned target_struct_allocsize
;
150 #define DEFAULT_ALLOCSIZE 10
152 /* The initial current target, so that there is always a semi-valid
155 static struct target_ops dummy_target
;
157 /* Top of target stack. */
159 struct target_stack_item
*target_stack
;
161 /* The target structure we are currently using to talk to a process
162 or file or whatever "inferior" we have. */
164 struct target_ops current_target
;
166 /* Command list for target. */
168 static struct cmd_list_element
*targetlist
= NULL
;
170 /* Nonzero if we are debugging an attached outside process
171 rather than an inferior. */
175 /* Non-zero if we want to see trace of target level stuff. */
177 static int targetdebug
= 0;
179 static void setup_target_debug (void);
181 DCACHE
*target_dcache
;
183 /* The user just typed 'target' without the name of a target. */
187 target_command (char *arg
, int from_tty
)
189 fputs_filtered ("Argument required (target name). Try `help target'\n",
193 /* Add a possible target architecture to the list. */
196 add_target (struct target_ops
*t
)
200 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
201 target_structs
= (struct target_ops
**) xmalloc
202 (target_struct_allocsize
* sizeof (*target_structs
));
204 if (target_struct_size
>= target_struct_allocsize
)
206 target_struct_allocsize
*= 2;
207 target_structs
= (struct target_ops
**)
208 xrealloc ((char *) target_structs
,
209 target_struct_allocsize
* sizeof (*target_structs
));
211 target_structs
[target_struct_size
++] = t
;
212 /* cleanup_target (t); */
214 if (targetlist
== NULL
)
215 add_prefix_cmd ("target", class_run
, target_command
,
216 "Connect to a target machine or process.\n\
217 The first argument is the type or protocol of the target machine.\n\
218 Remaining arguments are interpreted by the target protocol. For more\n\
219 information on the arguments for a particular protocol, type\n\
220 `help target ' followed by the protocol name.",
221 &targetlist
, "target ", 0, &cmdlist
);
222 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
233 target_load (char *arg
, int from_tty
)
235 dcache_invalidate (target_dcache
);
236 (*current_target
.to_load
) (arg
, from_tty
);
241 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
242 struct target_ops
*t
)
244 errno
= EIO
; /* Can't read/write this location */
245 return 0; /* No bytes handled */
251 error ("You can't do that when your target is `%s'",
252 current_target
.to_shortname
);
258 error ("You can't do that without a process to debug.");
263 nosymbol (char *name
, CORE_ADDR
*addrp
)
265 return 1; /* Symbol does not exist in target env */
270 nosupport_runtime (void)
275 error ("No run-time support for this");
281 default_terminal_info (char *args
, int from_tty
)
283 printf_unfiltered ("No saved terminal information.\n");
286 /* This is the default target_create_inferior and target_attach function.
287 If the current target is executing, it asks whether to kill it off.
288 If this function returns without calling error(), it has killed off
289 the target, and the operation should be attempted. */
292 kill_or_be_killed (int from_tty
)
294 if (target_has_execution
)
296 printf_unfiltered ("You are already running a program:\n");
297 target_files_info ();
298 if (query ("Kill it? "))
301 if (target_has_execution
)
302 error ("Killing the program did not help.");
307 error ("Program not killed.");
314 maybe_kill_then_attach (char *args
, int from_tty
)
316 kill_or_be_killed (from_tty
);
317 target_attach (args
, from_tty
);
321 maybe_kill_then_create_inferior (char *exec
, char *args
, char **env
)
323 kill_or_be_killed (0);
324 target_create_inferior (exec
, args
, env
);
328 default_clone_and_follow_inferior (int child_pid
, int *followed_child
)
330 target_clone_and_follow_inferior (child_pid
, followed_child
);
333 /* Clean up a target struct so it no longer has any zero pointers in it.
334 We default entries, at least to stubs that print error messages. */
337 cleanup_target (struct target_ops
*t
)
340 #define de_fault(field, value) \
345 (void (*) (char *, int))
351 maybe_kill_then_attach
);
352 de_fault (to_post_attach
,
355 de_fault (to_require_attach
,
356 maybe_kill_then_attach
);
358 (void (*) (char *, int))
360 de_fault (to_require_detach
,
361 (void (*) (int, char *, int))
364 (void (*) (int, int, enum target_signal
))
367 (int (*) (int, struct target_waitstatus
*))
369 de_fault (to_post_wait
,
370 (void (*) (int, int))
372 de_fault (to_fetch_registers
,
375 de_fault (to_store_registers
,
378 de_fault (to_prepare_to_store
,
381 de_fault (to_xfer_memory
,
382 (int (*) (CORE_ADDR
, char *, int, int, struct target_ops
*))
384 de_fault (to_files_info
,
385 (void (*) (struct target_ops
*))
387 de_fault (to_insert_breakpoint
,
388 memory_insert_breakpoint
);
389 de_fault (to_remove_breakpoint
,
390 memory_remove_breakpoint
);
391 de_fault (to_terminal_init
,
394 de_fault (to_terminal_inferior
,
397 de_fault (to_terminal_ours_for_output
,
400 de_fault (to_terminal_ours
,
403 de_fault (to_terminal_info
,
404 default_terminal_info
);
409 (void (*) (char *, int))
411 de_fault (to_lookup_symbol
,
412 (int (*) (char *, CORE_ADDR
*))
414 de_fault (to_create_inferior
,
415 maybe_kill_then_create_inferior
);
416 de_fault (to_post_startup_inferior
,
419 de_fault (to_acknowledge_created_inferior
,
422 de_fault (to_clone_and_follow_inferior
,
423 default_clone_and_follow_inferior
);
424 de_fault (to_post_follow_inferior_by_clone
,
427 de_fault (to_insert_fork_catchpoint
,
430 de_fault (to_remove_fork_catchpoint
,
433 de_fault (to_insert_vfork_catchpoint
,
436 de_fault (to_remove_vfork_catchpoint
,
439 de_fault (to_has_forked
,
440 (int (*) (int, int *))
442 de_fault (to_has_vforked
,
443 (int (*) (int, int *))
445 de_fault (to_can_follow_vfork_prior_to_exec
,
448 de_fault (to_post_follow_vfork
,
449 (void (*) (int, int, int, int))
451 de_fault (to_insert_exec_catchpoint
,
454 de_fault (to_remove_exec_catchpoint
,
457 de_fault (to_has_execd
,
458 (int (*) (int, char **))
460 de_fault (to_reported_exec_events_per_exec_call
,
463 de_fault (to_has_syscall_event
,
464 (int (*) (int, enum target_waitkind
*, int *))
466 de_fault (to_has_exited
,
467 (int (*) (int, int, int *))
469 de_fault (to_mourn_inferior
,
472 de_fault (to_can_run
,
474 de_fault (to_notice_signals
,
477 de_fault (to_thread_alive
,
480 de_fault (to_find_new_threads
,
483 de_fault (to_extra_thread_info
,
484 (char *(*) (struct thread_info
*))
490 (int (*) (int, char *, char *, int *))
493 (void (*) (char *, struct ui_file
*))
495 de_fault (to_enable_exception_callback
,
496 (struct symtab_and_line
* (*) (enum exception_event_kind
, int))
498 de_fault (to_get_current_exception_event
,
499 (struct exception_event_record
* (*) (void))
501 de_fault (to_pid_to_exec_file
,
504 de_fault (to_core_file_to_sym_file
,
507 de_fault (to_can_async_p
,
510 de_fault (to_is_async_p
,
514 (void (*) (void (*) (enum inferior_event_type
, void*), void*))
519 /* Go through the target stack from top to bottom, copying over zero entries in
520 current_target. In effect, we are doing class inheritance through the
521 pushed target vectors. */
524 update_current_target (void)
526 struct target_stack_item
*item
;
527 struct target_ops
*t
;
529 /* First, reset current_target */
530 memset (¤t_target
, 0, sizeof current_target
);
532 for (item
= target_stack
; item
; item
= item
->next
)
534 t
= item
->target_ops
;
536 #define INHERIT(FIELD, TARGET) \
537 if (!current_target.FIELD) \
538 current_target.FIELD = TARGET->FIELD
540 INHERIT (to_shortname
, t
);
541 INHERIT (to_longname
, t
);
543 INHERIT (to_open
, t
);
544 INHERIT (to_close
, t
);
545 INHERIT (to_attach
, t
);
546 INHERIT (to_post_attach
, t
);
547 INHERIT (to_require_attach
, t
);
548 INHERIT (to_detach
, t
);
549 INHERIT (to_require_detach
, t
);
550 INHERIT (to_resume
, t
);
551 INHERIT (to_wait
, t
);
552 INHERIT (to_post_wait
, t
);
553 INHERIT (to_fetch_registers
, t
);
554 INHERIT (to_store_registers
, t
);
555 INHERIT (to_prepare_to_store
, t
);
556 INHERIT (to_xfer_memory
, t
);
557 INHERIT (to_files_info
, t
);
558 INHERIT (to_insert_breakpoint
, t
);
559 INHERIT (to_remove_breakpoint
, t
);
560 INHERIT (to_terminal_init
, t
);
561 INHERIT (to_terminal_inferior
, t
);
562 INHERIT (to_terminal_ours_for_output
, t
);
563 INHERIT (to_terminal_ours
, t
);
564 INHERIT (to_terminal_info
, t
);
565 INHERIT (to_kill
, t
);
566 INHERIT (to_load
, t
);
567 INHERIT (to_lookup_symbol
, t
);
568 INHERIT (to_create_inferior
, t
);
569 INHERIT (to_post_startup_inferior
, t
);
570 INHERIT (to_acknowledge_created_inferior
, t
);
571 INHERIT (to_clone_and_follow_inferior
, t
);
572 INHERIT (to_post_follow_inferior_by_clone
, t
);
573 INHERIT (to_insert_fork_catchpoint
, t
);
574 INHERIT (to_remove_fork_catchpoint
, t
);
575 INHERIT (to_insert_vfork_catchpoint
, t
);
576 INHERIT (to_remove_vfork_catchpoint
, t
);
577 INHERIT (to_has_forked
, t
);
578 INHERIT (to_has_vforked
, t
);
579 INHERIT (to_can_follow_vfork_prior_to_exec
, t
);
580 INHERIT (to_post_follow_vfork
, t
);
581 INHERIT (to_insert_exec_catchpoint
, t
);
582 INHERIT (to_remove_exec_catchpoint
, t
);
583 INHERIT (to_has_execd
, t
);
584 INHERIT (to_reported_exec_events_per_exec_call
, t
);
585 INHERIT (to_has_syscall_event
, t
);
586 INHERIT (to_has_exited
, t
);
587 INHERIT (to_mourn_inferior
, t
);
588 INHERIT (to_can_run
, t
);
589 INHERIT (to_notice_signals
, t
);
590 INHERIT (to_thread_alive
, t
);
591 INHERIT (to_find_new_threads
, t
);
592 INHERIT (to_pid_to_str
, t
);
593 INHERIT (to_extra_thread_info
, t
);
594 INHERIT (to_stop
, t
);
595 INHERIT (to_query
, t
);
596 INHERIT (to_rcmd
, t
);
597 INHERIT (to_enable_exception_callback
, t
);
598 INHERIT (to_get_current_exception_event
, t
);
599 INHERIT (to_pid_to_exec_file
, t
);
600 INHERIT (to_core_file_to_sym_file
, t
);
601 INHERIT (to_stratum
, t
);
602 INHERIT (DONT_USE
, t
);
603 INHERIT (to_has_all_memory
, t
);
604 INHERIT (to_has_memory
, t
);
605 INHERIT (to_has_stack
, t
);
606 INHERIT (to_has_registers
, t
);
607 INHERIT (to_has_execution
, t
);
608 INHERIT (to_has_thread_control
, t
);
609 INHERIT (to_sections
, t
);
610 INHERIT (to_sections_end
, t
);
611 INHERIT (to_can_async_p
, t
);
612 INHERIT (to_is_async_p
, t
);
613 INHERIT (to_async
, t
);
614 INHERIT (to_async_mask_value
, t
);
615 INHERIT (to_magic
, t
);
621 /* Push a new target type into the stack of the existing target accessors,
622 possibly superseding some of the existing accessors.
624 Result is zero if the pushed target ended up on top of the stack,
625 nonzero if at least one target is on top of it.
627 Rather than allow an empty stack, we always have the dummy target at
628 the bottom stratum, so we can call the function vectors without
632 push_target (struct target_ops
*t
)
634 struct target_stack_item
*cur
, *prev
, *tmp
;
636 /* Check magic number. If wrong, it probably means someone changed
637 the struct definition, but not all the places that initialize one. */
638 if (t
->to_magic
!= OPS_MAGIC
)
640 fprintf_unfiltered (gdb_stderr
,
641 "Magic number of %s target struct wrong\n",
646 /* Find the proper stratum to install this target in. */
648 for (prev
= NULL
, cur
= target_stack
; cur
; prev
= cur
, cur
= cur
->next
)
650 if ((int) (t
->to_stratum
) >= (int) (cur
->target_ops
->to_stratum
))
654 /* If there's already targets at this stratum, remove them. */
657 while (t
->to_stratum
== cur
->target_ops
->to_stratum
)
659 /* There's already something on this stratum. Close it off. */
660 if (cur
->target_ops
->to_close
)
661 (cur
->target_ops
->to_close
) (0);
663 prev
->next
= cur
->next
; /* Unchain old target_ops */
665 target_stack
= cur
->next
; /* Unchain first on list */
671 /* We have removed all targets in our stratum, now add the new one. */
673 tmp
= (struct target_stack_item
*)
674 xmalloc (sizeof (struct target_stack_item
));
683 update_current_target ();
685 cleanup_target (¤t_target
); /* Fill in the gaps */
688 setup_target_debug ();
693 /* Remove a target_ops vector from the stack, wherever it may be.
694 Return how many times it was removed (0 or 1). */
697 unpush_target (struct target_ops
*t
)
699 struct target_stack_item
*cur
, *prev
;
702 t
->to_close (0); /* Let it clean up */
704 /* Look for the specified target. Note that we assume that a target
705 can only occur once in the target stack. */
707 for (cur
= target_stack
, prev
= NULL
; cur
; prev
= cur
, cur
= cur
->next
)
708 if (cur
->target_ops
== t
)
712 return 0; /* Didn't find target_ops, quit now */
714 /* Unchain the target */
717 target_stack
= cur
->next
;
719 prev
->next
= cur
->next
;
721 free (cur
); /* Release the target_stack_item */
723 update_current_target ();
724 cleanup_target (¤t_target
);
732 (current_target
.to_close
) (0); /* Let it clean up */
733 if (unpush_target (target_stack
->target_ops
) == 1)
736 fprintf_unfiltered (gdb_stderr
,
737 "pop_target couldn't find target %s\n",
738 current_target
.to_shortname
);
743 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
745 /* target_read_string -- read a null terminated string, up to LEN bytes,
746 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
747 Set *STRING to a pointer to malloc'd memory containing the data; the caller
748 is responsible for freeing it. Return the number of bytes successfully
752 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
754 int tlen
, origlen
, offset
, i
;
758 int buffer_allocated
;
760 unsigned int nbytes_read
= 0;
762 /* Small for testing. */
763 buffer_allocated
= 4;
764 buffer
= xmalloc (buffer_allocated
);
771 tlen
= MIN (len
, 4 - (memaddr
& 3));
772 offset
= memaddr
& 3;
774 errcode
= target_xfer_memory (memaddr
& ~3, buf
, 4, 0);
777 /* The transfer request might have crossed the boundary to an
778 unallocated region of memory. Retry the transfer, requesting
782 errcode
= target_xfer_memory (memaddr
, buf
, 1, 0);
787 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
790 bytes
= bufptr
- buffer
;
791 buffer_allocated
*= 2;
792 buffer
= xrealloc (buffer
, buffer_allocated
);
793 bufptr
= buffer
+ bytes
;
796 for (i
= 0; i
< tlen
; i
++)
798 *bufptr
++ = buf
[i
+ offset
];
799 if (buf
[i
+ offset
] == '\000')
801 nbytes_read
+= i
+ 1;
818 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
819 GDB's memory at MYADDR. Returns either 0 for success or an errno value
822 If an error occurs, no guarantee is made about the contents of the data at
823 MYADDR. In particular, the caller should not depend upon partial reads
824 filling the buffer with good data. There is no way for the caller to know
825 how much good data might have been transfered anyway. Callers that can
826 deal with partial reads should call target_read_memory_partial. */
829 target_read_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
831 return target_xfer_memory (memaddr
, myaddr
, len
, 0);
835 target_write_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
837 return target_xfer_memory (memaddr
, myaddr
, len
, 1);
840 /* Move memory to or from the targets. Iterate until all of it has
841 been moved, if necessary. The top target gets priority; anything
842 it doesn't want, is offered to the next one down, etc. Note the
843 business with curlen: if an early target says "no, but I have a
844 boundary overlapping this xfer" then we shorten what we offer to
845 the subsequent targets so the early guy will get a chance at the
846 tail before the subsequent ones do.
848 Result is 0 or errno value. */
851 do_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
)
855 struct target_ops
*t
;
856 struct target_stack_item
*item
;
858 /* Zero length requests are ok and require no work. */
862 /* to_xfer_memory is not guaranteed to set errno, even when it returns
866 /* The quick case is that the top target does it all. */
867 res
= current_target
.to_xfer_memory
868 (memaddr
, myaddr
, len
, write
, ¤t_target
);
874 /* If res <= 0 then we call it again in the loop. Ah well. */
878 for (item
= target_stack
; item
; item
= item
->next
)
880 t
= item
->target_ops
;
881 if (!t
->to_has_memory
)
884 res
= t
->to_xfer_memory (memaddr
, myaddr
, len
, write
, t
);
886 break; /* Handled all or part of xfer */
887 if (t
->to_has_all_memory
)
906 target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
)
910 /* Zero length requests are ok and require no work. */
918 res
= dcache_xfer_memory(target_dcache
, memaddr
, myaddr
, len
, write
);
921 /* If this address is for nonexistent memory,
922 read zeros if reading, or do nothing if writing. Return error. */
924 memset (myaddr
, 0, len
);
936 return 0; /* We managed to cover it all somehow. */
940 /* Perform a partial memory transfer. */
943 target_xfer_memory_partial (CORE_ADDR memaddr
, char *myaddr
, int len
,
944 int write_p
, int *err
)
949 struct target_ops
*t
;
950 struct target_stack_item
*item
;
952 /* Zero length requests are ok and require no work. */
959 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
, len
, write_p
);
975 target_read_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
977 return target_xfer_memory_partial (memaddr
, buf
, len
, 0, err
);
981 target_write_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
983 return target_xfer_memory_partial (memaddr
, buf
, len
, 1, err
);
988 target_info (char *args
, int from_tty
)
990 struct target_ops
*t
;
991 struct target_stack_item
*item
;
994 if (symfile_objfile
!= NULL
)
995 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
997 #ifdef FILES_INFO_HOOK
998 if (FILES_INFO_HOOK ())
1002 for (item
= target_stack
; item
; item
= item
->next
)
1004 t
= item
->target_ops
;
1006 if (!t
->to_has_memory
)
1009 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
1012 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1013 printf_unfiltered ("%s:\n", t
->to_longname
);
1014 (t
->to_files_info
) (t
);
1015 has_all_mem
= t
->to_has_all_memory
;
1019 /* This is to be called by the open routine before it does
1023 target_preopen (int from_tty
)
1027 if (target_has_execution
)
1030 || query ("A program is being debugged already. Kill it? "))
1033 error ("Program not killed.");
1036 /* Calling target_kill may remove the target from the stack. But if
1037 it doesn't (which seems like a win for UDI), remove it now. */
1039 if (target_has_execution
)
1043 /* Detach a target after doing deferred register stores. */
1046 target_detach (char *args
, int from_tty
)
1048 /* Handle any optimized stores to the inferior. */
1049 #ifdef DO_DEFERRED_STORES
1052 (current_target
.to_detach
) (args
, from_tty
);
1056 target_link (char *modname
, CORE_ADDR
*t_reloc
)
1058 if (STREQ (current_target
.to_shortname
, "rombug"))
1060 (current_target
.to_lookup_symbol
) (modname
, t_reloc
);
1062 error ("Unable to link to %s and get relocation in rombug", modname
);
1065 *t_reloc
= (CORE_ADDR
) -1;
1069 target_async_mask (int mask
)
1071 int saved_async_masked_status
= target_async_mask_value
;
1072 target_async_mask_value
= mask
;
1073 return saved_async_masked_status
;
1076 /* Look through the list of possible targets for a target that can
1077 execute a run or attach command without any other data. This is
1078 used to locate the default process stratum.
1080 Result is always valid (error() is called for errors). */
1082 static struct target_ops
*
1083 find_default_run_target (char *do_mesg
)
1085 struct target_ops
**t
;
1086 struct target_ops
*runable
= NULL
;
1091 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1094 if ((*t
)->to_can_run
&& target_can_run (*t
))
1102 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
1108 find_default_attach (char *args
, int from_tty
)
1110 struct target_ops
*t
;
1112 t
= find_default_run_target ("attach");
1113 (t
->to_attach
) (args
, from_tty
);
1118 find_default_require_attach (char *args
, int from_tty
)
1120 struct target_ops
*t
;
1122 t
= find_default_run_target ("require_attach");
1123 (t
->to_require_attach
) (args
, from_tty
);
1128 find_default_require_detach (int pid
, char *args
, int from_tty
)
1130 struct target_ops
*t
;
1132 t
= find_default_run_target ("require_detach");
1133 (t
->to_require_detach
) (pid
, args
, from_tty
);
1138 find_default_create_inferior (char *exec_file
, char *allargs
, char **env
)
1140 struct target_ops
*t
;
1142 t
= find_default_run_target ("run");
1143 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
1148 find_default_clone_and_follow_inferior (int child_pid
, int *followed_child
)
1150 struct target_ops
*t
;
1152 t
= find_default_run_target ("run");
1153 (t
->to_clone_and_follow_inferior
) (child_pid
, followed_child
);
1170 * Resize the to_sections pointer. Also make sure that anyone that
1171 * was holding on to an old value of it gets updated.
1172 * Returns the old size.
1176 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1178 struct target_ops
**t
;
1179 struct section_table
*old_value
;
1182 old_value
= target
->to_sections
;
1184 if (target
->to_sections
)
1186 old_count
= target
->to_sections_end
- target
->to_sections
;
1187 target
->to_sections
= (struct section_table
*)
1188 xrealloc ((char *) target
->to_sections
,
1189 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1194 target
->to_sections
= (struct section_table
*)
1195 xmalloc ((sizeof (struct section_table
)) * num_added
);
1197 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1199 /* Check to see if anyone else was pointing to this structure.
1200 If old_value was null, then no one was. */
1204 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1207 if ((*t
)->to_sections
== old_value
)
1209 (*t
)->to_sections
= target
->to_sections
;
1210 (*t
)->to_sections_end
= target
->to_sections_end
;
1219 /* Remove all target sections taken from ABFD.
1221 Scan the current target stack for targets whose section tables
1222 refer to sections from BFD, and remove those sections. We use this
1223 when we notice that the inferior has unloaded a shared object, for
1226 remove_target_sections (bfd
*abfd
)
1228 struct target_ops
**t
;
1230 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; t
++)
1232 struct section_table
*src
, *dest
;
1234 dest
= (*t
)->to_sections
;
1235 for (src
= (*t
)->to_sections
; src
< (*t
)->to_sections_end
; src
++)
1236 if (src
->bfd
!= abfd
)
1238 /* Keep this section. */
1239 if (dest
< src
) *dest
= *src
;
1243 /* If we've dropped any sections, resize the section table. */
1245 target_resize_to_sections (*t
, dest
- src
);
1252 /* Find a single runnable target in the stack and return it. If for
1253 some reason there is more than one, return NULL. */
1256 find_run_target (void)
1258 struct target_ops
**t
;
1259 struct target_ops
*runable
= NULL
;
1264 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1266 if ((*t
)->to_can_run
&& target_can_run (*t
))
1273 return (count
== 1 ? runable
: NULL
);
1276 /* Find a single core_stratum target in the list of targets and return it.
1277 If for some reason there is more than one, return NULL. */
1280 find_core_target (void)
1282 struct target_ops
**t
;
1283 struct target_ops
*runable
= NULL
;
1288 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1291 if ((*t
)->to_stratum
== core_stratum
)
1298 return (count
== 1 ? runable
: NULL
);
1302 * Find the next target down the stack from the specified target.
1306 find_target_beneath (struct target_ops
*t
)
1308 struct target_stack_item
*cur
;
1310 for (cur
= target_stack
; cur
; cur
= cur
->next
)
1311 if (cur
->target_ops
== t
)
1314 if (cur
== NULL
|| cur
->next
== NULL
)
1317 return cur
->next
->target_ops
;
1321 /* The inferior process has died. Long live the inferior! */
1324 generic_mourn_inferior (void)
1326 extern int show_breakpoint_hit_counts
;
1330 breakpoint_init_inferior (inf_exited
);
1331 registers_changed ();
1333 #ifdef CLEAR_DEFERRED_STORES
1334 /* Delete any pending stores to the inferior... */
1335 CLEAR_DEFERRED_STORES
;
1338 reopen_exec_file ();
1339 reinit_frame_cache ();
1341 /* It is confusing to the user for ignore counts to stick around
1342 from previous runs of the inferior. So clear them. */
1343 /* However, it is more confusing for the ignore counts to disappear when
1344 using hit counts. So don't clear them if we're counting hits. */
1345 if (!show_breakpoint_hit_counts
)
1346 breakpoint_clear_ignore_counts ();
1352 /* This table must match in order and size the signals in enum target_signal
1361 {"SIGHUP", "Hangup"},
1362 {"SIGINT", "Interrupt"},
1363 {"SIGQUIT", "Quit"},
1364 {"SIGILL", "Illegal instruction"},
1365 {"SIGTRAP", "Trace/breakpoint trap"},
1366 {"SIGABRT", "Aborted"},
1367 {"SIGEMT", "Emulation trap"},
1368 {"SIGFPE", "Arithmetic exception"},
1369 {"SIGKILL", "Killed"},
1370 {"SIGBUS", "Bus error"},
1371 {"SIGSEGV", "Segmentation fault"},
1372 {"SIGSYS", "Bad system call"},
1373 {"SIGPIPE", "Broken pipe"},
1374 {"SIGALRM", "Alarm clock"},
1375 {"SIGTERM", "Terminated"},
1376 {"SIGURG", "Urgent I/O condition"},
1377 {"SIGSTOP", "Stopped (signal)"},
1378 {"SIGTSTP", "Stopped (user)"},
1379 {"SIGCONT", "Continued"},
1380 {"SIGCHLD", "Child status changed"},
1381 {"SIGTTIN", "Stopped (tty input)"},
1382 {"SIGTTOU", "Stopped (tty output)"},
1383 {"SIGIO", "I/O possible"},
1384 {"SIGXCPU", "CPU time limit exceeded"},
1385 {"SIGXFSZ", "File size limit exceeded"},
1386 {"SIGVTALRM", "Virtual timer expired"},
1387 {"SIGPROF", "Profiling timer expired"},
1388 {"SIGWINCH", "Window size changed"},
1389 {"SIGLOST", "Resource lost"},
1390 {"SIGUSR1", "User defined signal 1"},
1391 {"SIGUSR2", "User defined signal 2"},
1392 {"SIGPWR", "Power fail/restart"},
1393 {"SIGPOLL", "Pollable event occurred"},
1394 {"SIGWIND", "SIGWIND"},
1395 {"SIGPHONE", "SIGPHONE"},
1396 {"SIGWAITING", "Process's LWPs are blocked"},
1397 {"SIGLWP", "Signal LWP"},
1398 {"SIGDANGER", "Swap space dangerously low"},
1399 {"SIGGRANT", "Monitor mode granted"},
1400 {"SIGRETRACT", "Need to relinquish monitor mode"},
1401 {"SIGMSG", "Monitor mode data available"},
1402 {"SIGSOUND", "Sound completed"},
1403 {"SIGSAK", "Secure attention"},
1404 {"SIGPRIO", "SIGPRIO"},
1405 {"SIG33", "Real-time event 33"},
1406 {"SIG34", "Real-time event 34"},
1407 {"SIG35", "Real-time event 35"},
1408 {"SIG36", "Real-time event 36"},
1409 {"SIG37", "Real-time event 37"},
1410 {"SIG38", "Real-time event 38"},
1411 {"SIG39", "Real-time event 39"},
1412 {"SIG40", "Real-time event 40"},
1413 {"SIG41", "Real-time event 41"},
1414 {"SIG42", "Real-time event 42"},
1415 {"SIG43", "Real-time event 43"},
1416 {"SIG44", "Real-time event 44"},
1417 {"SIG45", "Real-time event 45"},
1418 {"SIG46", "Real-time event 46"},
1419 {"SIG47", "Real-time event 47"},
1420 {"SIG48", "Real-time event 48"},
1421 {"SIG49", "Real-time event 49"},
1422 {"SIG50", "Real-time event 50"},
1423 {"SIG51", "Real-time event 51"},
1424 {"SIG52", "Real-time event 52"},
1425 {"SIG53", "Real-time event 53"},
1426 {"SIG54", "Real-time event 54"},
1427 {"SIG55", "Real-time event 55"},
1428 {"SIG56", "Real-time event 56"},
1429 {"SIG57", "Real-time event 57"},
1430 {"SIG58", "Real-time event 58"},
1431 {"SIG59", "Real-time event 59"},
1432 {"SIG60", "Real-time event 60"},
1433 {"SIG61", "Real-time event 61"},
1434 {"SIG62", "Real-time event 62"},
1435 {"SIG63", "Real-time event 63"},
1436 {"SIGCANCEL", "LWP internal signal"},
1437 {"SIG32", "Real-time event 32"},
1439 #if defined(MACH) || defined(__MACH__)
1440 /* Mach exceptions */
1441 {"EXC_BAD_ACCESS", "Could not access memory"},
1442 {"EXC_BAD_INSTRUCTION", "Illegal instruction/operand"},
1443 {"EXC_ARITHMETIC", "Arithmetic exception"},
1444 {"EXC_EMULATION", "Emulation instruction"},
1445 {"EXC_SOFTWARE", "Software generated exception"},
1446 {"EXC_BREAKPOINT", "Breakpoint"},
1448 {"SIGINFO", "Information request"},
1450 {NULL
, "Unknown signal"},
1451 {NULL
, "Internal error: printing TARGET_SIGNAL_DEFAULT"},
1453 /* Last entry, used to check whether the table is the right size. */
1454 {NULL
, "TARGET_SIGNAL_MAGIC"}
1460 /* Return the string for a signal. */
1462 target_signal_to_string (enum target_signal sig
)
1464 if ((sig
>= TARGET_SIGNAL_FIRST
) && (sig
<= TARGET_SIGNAL_LAST
))
1465 return signals
[sig
].string
;
1467 return signals
[TARGET_SIGNAL_UNKNOWN
].string
;
1470 /* Return the name for a signal. */
1472 target_signal_to_name (enum target_signal sig
)
1474 if (sig
== TARGET_SIGNAL_UNKNOWN
)
1475 /* I think the code which prints this will always print it along with
1476 the string, so no need to be verbose. */
1478 return signals
[sig
].name
;
1481 /* Given a name, return its signal. */
1483 target_signal_from_name (char *name
)
1485 enum target_signal sig
;
1487 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
1488 for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
1489 questionable; seems like by now people should call it SIGABRT
1492 /* This ugly cast brought to you by the native VAX compiler. */
1493 for (sig
= TARGET_SIGNAL_HUP
;
1494 signals
[sig
].name
!= NULL
;
1495 sig
= (enum target_signal
) ((int) sig
+ 1))
1496 if (STREQ (name
, signals
[sig
].name
))
1498 return TARGET_SIGNAL_UNKNOWN
;
1501 /* The following functions are to help certain targets deal
1502 with the signal/waitstatus stuff. They could just as well be in
1503 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
1505 /* Convert host signal to our signals. */
1507 target_signal_from_host (int hostsig
)
1509 /* A switch statement would make sense but would require special kludges
1510 to deal with the cases where more than one signal has the same number. */
1513 return TARGET_SIGNAL_0
;
1515 #if defined (SIGHUP)
1516 if (hostsig
== SIGHUP
)
1517 return TARGET_SIGNAL_HUP
;
1519 #if defined (SIGINT)
1520 if (hostsig
== SIGINT
)
1521 return TARGET_SIGNAL_INT
;
1523 #if defined (SIGQUIT)
1524 if (hostsig
== SIGQUIT
)
1525 return TARGET_SIGNAL_QUIT
;
1527 #if defined (SIGILL)
1528 if (hostsig
== SIGILL
)
1529 return TARGET_SIGNAL_ILL
;
1531 #if defined (SIGTRAP)
1532 if (hostsig
== SIGTRAP
)
1533 return TARGET_SIGNAL_TRAP
;
1535 #if defined (SIGABRT)
1536 if (hostsig
== SIGABRT
)
1537 return TARGET_SIGNAL_ABRT
;
1539 #if defined (SIGEMT)
1540 if (hostsig
== SIGEMT
)
1541 return TARGET_SIGNAL_EMT
;
1543 #if defined (SIGFPE)
1544 if (hostsig
== SIGFPE
)
1545 return TARGET_SIGNAL_FPE
;
1547 #if defined (SIGKILL)
1548 if (hostsig
== SIGKILL
)
1549 return TARGET_SIGNAL_KILL
;
1551 #if defined (SIGBUS)
1552 if (hostsig
== SIGBUS
)
1553 return TARGET_SIGNAL_BUS
;
1555 #if defined (SIGSEGV)
1556 if (hostsig
== SIGSEGV
)
1557 return TARGET_SIGNAL_SEGV
;
1559 #if defined (SIGSYS)
1560 if (hostsig
== SIGSYS
)
1561 return TARGET_SIGNAL_SYS
;
1563 #if defined (SIGPIPE)
1564 if (hostsig
== SIGPIPE
)
1565 return TARGET_SIGNAL_PIPE
;
1567 #if defined (SIGALRM)
1568 if (hostsig
== SIGALRM
)
1569 return TARGET_SIGNAL_ALRM
;
1571 #if defined (SIGTERM)
1572 if (hostsig
== SIGTERM
)
1573 return TARGET_SIGNAL_TERM
;
1575 #if defined (SIGUSR1)
1576 if (hostsig
== SIGUSR1
)
1577 return TARGET_SIGNAL_USR1
;
1579 #if defined (SIGUSR2)
1580 if (hostsig
== SIGUSR2
)
1581 return TARGET_SIGNAL_USR2
;
1583 #if defined (SIGCLD)
1584 if (hostsig
== SIGCLD
)
1585 return TARGET_SIGNAL_CHLD
;
1587 #if defined (SIGCHLD)
1588 if (hostsig
== SIGCHLD
)
1589 return TARGET_SIGNAL_CHLD
;
1591 #if defined (SIGPWR)
1592 if (hostsig
== SIGPWR
)
1593 return TARGET_SIGNAL_PWR
;
1595 #if defined (SIGWINCH)
1596 if (hostsig
== SIGWINCH
)
1597 return TARGET_SIGNAL_WINCH
;
1599 #if defined (SIGURG)
1600 if (hostsig
== SIGURG
)
1601 return TARGET_SIGNAL_URG
;
1604 if (hostsig
== SIGIO
)
1605 return TARGET_SIGNAL_IO
;
1607 #if defined (SIGPOLL)
1608 if (hostsig
== SIGPOLL
)
1609 return TARGET_SIGNAL_POLL
;
1611 #if defined (SIGSTOP)
1612 if (hostsig
== SIGSTOP
)
1613 return TARGET_SIGNAL_STOP
;
1615 #if defined (SIGTSTP)
1616 if (hostsig
== SIGTSTP
)
1617 return TARGET_SIGNAL_TSTP
;
1619 #if defined (SIGCONT)
1620 if (hostsig
== SIGCONT
)
1621 return TARGET_SIGNAL_CONT
;
1623 #if defined (SIGTTIN)
1624 if (hostsig
== SIGTTIN
)
1625 return TARGET_SIGNAL_TTIN
;
1627 #if defined (SIGTTOU)
1628 if (hostsig
== SIGTTOU
)
1629 return TARGET_SIGNAL_TTOU
;
1631 #if defined (SIGVTALRM)
1632 if (hostsig
== SIGVTALRM
)
1633 return TARGET_SIGNAL_VTALRM
;
1635 #if defined (SIGPROF)
1636 if (hostsig
== SIGPROF
)
1637 return TARGET_SIGNAL_PROF
;
1639 #if defined (SIGXCPU)
1640 if (hostsig
== SIGXCPU
)
1641 return TARGET_SIGNAL_XCPU
;
1643 #if defined (SIGXFSZ)
1644 if (hostsig
== SIGXFSZ
)
1645 return TARGET_SIGNAL_XFSZ
;
1647 #if defined (SIGWIND)
1648 if (hostsig
== SIGWIND
)
1649 return TARGET_SIGNAL_WIND
;
1651 #if defined (SIGPHONE)
1652 if (hostsig
== SIGPHONE
)
1653 return TARGET_SIGNAL_PHONE
;
1655 #if defined (SIGLOST)
1656 if (hostsig
== SIGLOST
)
1657 return TARGET_SIGNAL_LOST
;
1659 #if defined (SIGWAITING)
1660 if (hostsig
== SIGWAITING
)
1661 return TARGET_SIGNAL_WAITING
;
1663 #if defined (SIGCANCEL)
1664 if (hostsig
== SIGCANCEL
)
1665 return TARGET_SIGNAL_CANCEL
;
1667 #if defined (SIGLWP)
1668 if (hostsig
== SIGLWP
)
1669 return TARGET_SIGNAL_LWP
;
1671 #if defined (SIGDANGER)
1672 if (hostsig
== SIGDANGER
)
1673 return TARGET_SIGNAL_DANGER
;
1675 #if defined (SIGGRANT)
1676 if (hostsig
== SIGGRANT
)
1677 return TARGET_SIGNAL_GRANT
;
1679 #if defined (SIGRETRACT)
1680 if (hostsig
== SIGRETRACT
)
1681 return TARGET_SIGNAL_RETRACT
;
1683 #if defined (SIGMSG)
1684 if (hostsig
== SIGMSG
)
1685 return TARGET_SIGNAL_MSG
;
1687 #if defined (SIGSOUND)
1688 if (hostsig
== SIGSOUND
)
1689 return TARGET_SIGNAL_SOUND
;
1691 #if defined (SIGSAK)
1692 if (hostsig
== SIGSAK
)
1693 return TARGET_SIGNAL_SAK
;
1695 #if defined (SIGPRIO)
1696 if (hostsig
== SIGPRIO
)
1697 return TARGET_SIGNAL_PRIO
;
1700 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1701 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1702 if (hostsig
== _NSIG
+ EXC_BAD_ACCESS
)
1703 return TARGET_EXC_BAD_ACCESS
;
1705 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1706 if (hostsig
== _NSIG
+ EXC_BAD_INSTRUCTION
)
1707 return TARGET_EXC_BAD_INSTRUCTION
;
1709 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1710 if (hostsig
== _NSIG
+ EXC_ARITHMETIC
)
1711 return TARGET_EXC_ARITHMETIC
;
1713 #if defined (EXC_EMULATION) && defined (_NSIG)
1714 if (hostsig
== _NSIG
+ EXC_EMULATION
)
1715 return TARGET_EXC_EMULATION
;
1717 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1718 if (hostsig
== _NSIG
+ EXC_SOFTWARE
)
1719 return TARGET_EXC_SOFTWARE
;
1721 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1722 if (hostsig
== _NSIG
+ EXC_BREAKPOINT
)
1723 return TARGET_EXC_BREAKPOINT
;
1726 #if defined (SIGINFO)
1727 if (hostsig
== SIGINFO
)
1728 return TARGET_SIGNAL_INFO
;
1731 #if defined (REALTIME_LO)
1732 if (hostsig
>= REALTIME_LO
&& hostsig
< REALTIME_HI
)
1734 /* This block of TARGET_SIGNAL_REALTIME value is in order. */
1735 if (33 <= hostsig
&& hostsig
<= 63)
1736 return (enum target_signal
)
1737 (hostsig
- 33 + (int) TARGET_SIGNAL_REALTIME_33
);
1738 else if (hostsig
== 32)
1739 return TARGET_SIGNAL_REALTIME_32
;
1741 error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
1745 #if defined (SIGRTMIN)
1746 if (hostsig
>= SIGRTMIN
&& hostsig
<= SIGRTMAX
)
1748 /* This block of TARGET_SIGNAL_REALTIME value is in order. */
1749 if (33 <= hostsig
&& hostsig
<= 63)
1750 return (enum target_signal
)
1751 (hostsig
- 33 + (int) TARGET_SIGNAL_REALTIME_33
);
1753 error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
1756 return TARGET_SIGNAL_UNKNOWN
;
1759 /* Convert a OURSIG (an enum target_signal) to the form used by the
1760 target operating system (refered to as the ``host'') or zero if the
1761 equivalent host signal is not available. Set/clear OURSIG_OK
1765 do_target_signal_to_host (enum target_signal oursig
,
1771 case TARGET_SIGNAL_0
:
1774 #if defined (SIGHUP)
1775 case TARGET_SIGNAL_HUP
:
1778 #if defined (SIGINT)
1779 case TARGET_SIGNAL_INT
:
1782 #if defined (SIGQUIT)
1783 case TARGET_SIGNAL_QUIT
:
1786 #if defined (SIGILL)
1787 case TARGET_SIGNAL_ILL
:
1790 #if defined (SIGTRAP)
1791 case TARGET_SIGNAL_TRAP
:
1794 #if defined (SIGABRT)
1795 case TARGET_SIGNAL_ABRT
:
1798 #if defined (SIGEMT)
1799 case TARGET_SIGNAL_EMT
:
1802 #if defined (SIGFPE)
1803 case TARGET_SIGNAL_FPE
:
1806 #if defined (SIGKILL)
1807 case TARGET_SIGNAL_KILL
:
1810 #if defined (SIGBUS)
1811 case TARGET_SIGNAL_BUS
:
1814 #if defined (SIGSEGV)
1815 case TARGET_SIGNAL_SEGV
:
1818 #if defined (SIGSYS)
1819 case TARGET_SIGNAL_SYS
:
1822 #if defined (SIGPIPE)
1823 case TARGET_SIGNAL_PIPE
:
1826 #if defined (SIGALRM)
1827 case TARGET_SIGNAL_ALRM
:
1830 #if defined (SIGTERM)
1831 case TARGET_SIGNAL_TERM
:
1834 #if defined (SIGUSR1)
1835 case TARGET_SIGNAL_USR1
:
1838 #if defined (SIGUSR2)
1839 case TARGET_SIGNAL_USR2
:
1842 #if defined (SIGCHLD) || defined (SIGCLD)
1843 case TARGET_SIGNAL_CHLD
:
1844 #if defined (SIGCHLD)
1849 #endif /* SIGCLD or SIGCHLD */
1850 #if defined (SIGPWR)
1851 case TARGET_SIGNAL_PWR
:
1854 #if defined (SIGWINCH)
1855 case TARGET_SIGNAL_WINCH
:
1858 #if defined (SIGURG)
1859 case TARGET_SIGNAL_URG
:
1863 case TARGET_SIGNAL_IO
:
1866 #if defined (SIGPOLL)
1867 case TARGET_SIGNAL_POLL
:
1870 #if defined (SIGSTOP)
1871 case TARGET_SIGNAL_STOP
:
1874 #if defined (SIGTSTP)
1875 case TARGET_SIGNAL_TSTP
:
1878 #if defined (SIGCONT)
1879 case TARGET_SIGNAL_CONT
:
1882 #if defined (SIGTTIN)
1883 case TARGET_SIGNAL_TTIN
:
1886 #if defined (SIGTTOU)
1887 case TARGET_SIGNAL_TTOU
:
1890 #if defined (SIGVTALRM)
1891 case TARGET_SIGNAL_VTALRM
:
1894 #if defined (SIGPROF)
1895 case TARGET_SIGNAL_PROF
:
1898 #if defined (SIGXCPU)
1899 case TARGET_SIGNAL_XCPU
:
1902 #if defined (SIGXFSZ)
1903 case TARGET_SIGNAL_XFSZ
:
1906 #if defined (SIGWIND)
1907 case TARGET_SIGNAL_WIND
:
1910 #if defined (SIGPHONE)
1911 case TARGET_SIGNAL_PHONE
:
1914 #if defined (SIGLOST)
1915 case TARGET_SIGNAL_LOST
:
1918 #if defined (SIGWAITING)
1919 case TARGET_SIGNAL_WAITING
:
1922 #if defined (SIGCANCEL)
1923 case TARGET_SIGNAL_CANCEL
:
1926 #if defined (SIGLWP)
1927 case TARGET_SIGNAL_LWP
:
1930 #if defined (SIGDANGER)
1931 case TARGET_SIGNAL_DANGER
:
1934 #if defined (SIGGRANT)
1935 case TARGET_SIGNAL_GRANT
:
1938 #if defined (SIGRETRACT)
1939 case TARGET_SIGNAL_RETRACT
:
1942 #if defined (SIGMSG)
1943 case TARGET_SIGNAL_MSG
:
1946 #if defined (SIGSOUND)
1947 case TARGET_SIGNAL_SOUND
:
1950 #if defined (SIGSAK)
1951 case TARGET_SIGNAL_SAK
:
1954 #if defined (SIGPRIO)
1955 case TARGET_SIGNAL_PRIO
:
1959 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1960 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1961 case TARGET_EXC_BAD_ACCESS
:
1962 return _NSIG
+ EXC_BAD_ACCESS
;
1964 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1965 case TARGET_EXC_BAD_INSTRUCTION
:
1966 return _NSIG
+ EXC_BAD_INSTRUCTION
;
1968 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1969 case TARGET_EXC_ARITHMETIC
:
1970 return _NSIG
+ EXC_ARITHMETIC
;
1972 #if defined (EXC_EMULATION) && defined (_NSIG)
1973 case TARGET_EXC_EMULATION
:
1974 return _NSIG
+ EXC_EMULATION
;
1976 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1977 case TARGET_EXC_SOFTWARE
:
1978 return _NSIG
+ EXC_SOFTWARE
;
1980 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1981 case TARGET_EXC_BREAKPOINT
:
1982 return _NSIG
+ EXC_BREAKPOINT
;
1985 #if defined (SIGINFO)
1986 case TARGET_SIGNAL_INFO
:
1991 #if defined (REALTIME_LO)
1992 if (oursig
>= TARGET_SIGNAL_REALTIME_33
1993 && oursig
<= TARGET_SIGNAL_REALTIME_63
)
1995 /* This block of signals is continuous, and
1996 TARGET_SIGNAL_REALTIME_33 is 33 by definition. */
1998 (int) oursig
- (int) TARGET_SIGNAL_REALTIME_33
+ 33;
1999 if (retsig
>= REALTIME_LO
&& retsig
< REALTIME_HI
)
2002 #if (REALTIME_LO < 33)
2003 else if (oursig
== TARGET_SIGNAL_REALTIME_32
)
2005 /* TARGET_SIGNAL_REALTIME_32 isn't contiguous with
2006 TARGET_SIGNAL_REALTIME_33. It is 32 by definition. */
2012 #if defined (SIGRTMIN)
2013 if (oursig
>= TARGET_SIGNAL_REALTIME_33
2014 && oursig
<= TARGET_SIGNAL_REALTIME_63
)
2016 /* This block of signals is continuous, and
2017 TARGET_SIGNAL_REALTIME_33 is 33 by definition. */
2019 (int) oursig
- (int) TARGET_SIGNAL_REALTIME_33
+ 33;
2020 if (retsig
>= SIGRTMIN
&& retsig
<= SIGRTMAX
)
2030 target_signal_to_host_p (enum target_signal oursig
)
2033 do_target_signal_to_host (oursig
, &oursig_ok
);
2038 target_signal_to_host (enum target_signal oursig
)
2041 int targ_signo
= do_target_signal_to_host (oursig
, &oursig_ok
);
2044 /* The user might be trying to do "signal SIGSAK" where this system
2045 doesn't have SIGSAK. */
2046 warning ("Signal %s does not exist on this system.\n",
2047 target_signal_to_name (oursig
));
2054 /* Helper function for child_wait and the Lynx derivatives of child_wait.
2055 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
2056 translation of that in OURSTATUS. */
2058 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
2060 #ifdef CHILD_SPECIAL_WAITSTATUS
2061 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
2062 if it wants to deal with hoststatus. */
2063 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
2067 if (WIFEXITED (hoststatus
))
2069 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
2070 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
2072 else if (!WIFSTOPPED (hoststatus
))
2074 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
2075 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
2079 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
2080 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
2084 /* In some circumstances we allow a command to specify a numeric
2085 signal. The idea is to keep these circumstances limited so that
2086 users (and scripts) develop portable habits. For comparison,
2087 POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
2088 numeric signal at all is obsolescent. We are slightly more
2089 lenient and allow 1-15 which should match host signal numbers on
2090 most systems. Use of symbolic signal names is strongly encouraged. */
2093 target_signal_from_command (int num
)
2095 if (num
>= 1 && num
<= 15)
2096 return (enum target_signal
) num
;
2097 error ("Only signals 1-15 are valid as numeric signals.\n\
2098 Use \"info signals\" for a list of symbolic signals.");
2101 /* Returns zero to leave the inferior alone, one to interrupt it. */
2102 int (*target_activity_function
) (void);
2103 int target_activity_fd
;
2105 /* Convert a normal process ID to a string. Returns the string in a static
2109 normal_pid_to_str (int pid
)
2111 static char buf
[30];
2113 if (STREQ (current_target
.to_shortname
, "remote"))
2114 sprintf (buf
, "thread %d", pid
);
2116 sprintf (buf
, "process %d", pid
);
2121 /* Some targets (such as ttrace-based HPUX) don't allow us to request
2122 notification of inferior events such as fork and vork immediately
2123 after the inferior is created. (This because of how gdb gets an
2124 inferior created via invoking a shell to do it. In such a scenario,
2125 if the shell init file has commands in it, the shell will fork and
2126 exec for each of those commands, and we will see each such fork
2129 This function is used by all targets that allow us to request
2130 notification of forks, etc at inferior creation time; e.g., in
2131 target_acknowledge_forked_child.
2134 normal_target_post_startup_inferior (int pid
)
2136 /* This space intentionally left blank. */
2139 /* Set up the handful of non-empty slots needed by the dummy target
2143 init_dummy_target (void)
2145 dummy_target
.to_shortname
= "None";
2146 dummy_target
.to_longname
= "None";
2147 dummy_target
.to_doc
= "";
2148 dummy_target
.to_attach
= find_default_attach
;
2149 dummy_target
.to_require_attach
= find_default_require_attach
;
2150 dummy_target
.to_require_detach
= find_default_require_detach
;
2151 dummy_target
.to_create_inferior
= find_default_create_inferior
;
2152 dummy_target
.to_clone_and_follow_inferior
= find_default_clone_and_follow_inferior
;
2153 dummy_target
.to_pid_to_str
= normal_pid_to_str
;
2154 dummy_target
.to_stratum
= dummy_stratum
;
2155 dummy_target
.to_magic
= OPS_MAGIC
;
2159 static struct target_ops debug_target
;
2162 debug_to_open (char *args
, int from_tty
)
2164 debug_target
.to_open (args
, from_tty
);
2166 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
2170 debug_to_close (int quitting
)
2172 debug_target
.to_close (quitting
);
2174 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
2178 debug_to_attach (char *args
, int from_tty
)
2180 debug_target
.to_attach (args
, from_tty
);
2182 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
2187 debug_to_post_attach (int pid
)
2189 debug_target
.to_post_attach (pid
);
2191 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
2195 debug_to_require_attach (char *args
, int from_tty
)
2197 debug_target
.to_require_attach (args
, from_tty
);
2199 fprintf_unfiltered (gdb_stdlog
,
2200 "target_require_attach (%s, %d)\n", args
, from_tty
);
2204 debug_to_detach (char *args
, int from_tty
)
2206 debug_target
.to_detach (args
, from_tty
);
2208 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
2212 debug_to_require_detach (int pid
, char *args
, int from_tty
)
2214 debug_target
.to_require_detach (pid
, args
, from_tty
);
2216 fprintf_unfiltered (gdb_stdlog
,
2217 "target_require_detach (%d, %s, %d)\n", pid
, args
, from_tty
);
2221 debug_to_resume (int pid
, int step
, enum target_signal siggnal
)
2223 debug_target
.to_resume (pid
, step
, siggnal
);
2225 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", pid
,
2226 step
? "step" : "continue",
2227 target_signal_to_name (siggnal
));
2231 debug_to_wait (int pid
, struct target_waitstatus
*status
)
2235 retval
= debug_target
.to_wait (pid
, status
);
2237 fprintf_unfiltered (gdb_stdlog
,
2238 "target_wait (%d, status) = %d, ", pid
, retval
);
2239 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
2240 switch (status
->kind
)
2242 case TARGET_WAITKIND_EXITED
:
2243 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
2244 status
->value
.integer
);
2246 case TARGET_WAITKIND_STOPPED
:
2247 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
2248 target_signal_to_name (status
->value
.sig
));
2250 case TARGET_WAITKIND_SIGNALLED
:
2251 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
2252 target_signal_to_name (status
->value
.sig
));
2254 case TARGET_WAITKIND_LOADED
:
2255 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
2257 case TARGET_WAITKIND_FORKED
:
2258 fprintf_unfiltered (gdb_stdlog
, "forked\n");
2260 case TARGET_WAITKIND_VFORKED
:
2261 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
2263 case TARGET_WAITKIND_EXECD
:
2264 fprintf_unfiltered (gdb_stdlog
, "execd\n");
2266 case TARGET_WAITKIND_SPURIOUS
:
2267 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
2270 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
2278 debug_to_post_wait (int pid
, int status
)
2280 debug_target
.to_post_wait (pid
, status
);
2282 fprintf_unfiltered (gdb_stdlog
, "target_post_wait (%d, %d)\n",
2287 debug_to_fetch_registers (int regno
)
2289 debug_target
.to_fetch_registers (regno
);
2291 fprintf_unfiltered (gdb_stdlog
, "target_fetch_registers (%s)",
2292 regno
!= -1 ? REGISTER_NAME (regno
) : "-1");
2294 fprintf_unfiltered (gdb_stdlog
, " = 0x%lx %ld",
2295 (unsigned long) read_register (regno
),
2296 (unsigned long) read_register (regno
));
2297 fprintf_unfiltered (gdb_stdlog
, "\n");
2301 debug_to_store_registers (int regno
)
2303 debug_target
.to_store_registers (regno
);
2305 if (regno
>= 0 && regno
< NUM_REGS
)
2306 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%s) = 0x%lx %ld\n",
2307 REGISTER_NAME (regno
),
2308 (unsigned long) read_register (regno
),
2309 (unsigned long) read_register (regno
));
2311 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%d)\n", regno
);
2315 debug_to_prepare_to_store (void)
2317 debug_target
.to_prepare_to_store ();
2319 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
2323 debug_to_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
2324 struct target_ops
*target
)
2328 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
, target
);
2330 fprintf_unfiltered (gdb_stdlog
,
2331 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
2332 (unsigned int) memaddr
, /* possable truncate long long */
2333 len
, write
? "write" : "read", retval
);
2341 fputs_unfiltered (", bytes =", gdb_stdlog
);
2342 for (i
= 0; i
< retval
; i
++)
2344 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
2345 fprintf_unfiltered (gdb_stdlog
, "\n");
2346 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
2350 fputc_unfiltered ('\n', gdb_stdlog
);
2356 debug_to_files_info (struct target_ops
*target
)
2358 debug_target
.to_files_info (target
);
2360 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
2364 debug_to_insert_breakpoint (CORE_ADDR addr
, char *save
)
2368 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
2370 fprintf_unfiltered (gdb_stdlog
,
2371 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
2372 (unsigned long) addr
,
2373 (unsigned long) retval
);
2378 debug_to_remove_breakpoint (CORE_ADDR addr
, char *save
)
2382 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
2384 fprintf_unfiltered (gdb_stdlog
,
2385 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
2386 (unsigned long) addr
,
2387 (unsigned long) retval
);
2392 debug_to_terminal_init (void)
2394 debug_target
.to_terminal_init ();
2396 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
2400 debug_to_terminal_inferior (void)
2402 debug_target
.to_terminal_inferior ();
2404 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
2408 debug_to_terminal_ours_for_output (void)
2410 debug_target
.to_terminal_ours_for_output ();
2412 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
2416 debug_to_terminal_ours (void)
2418 debug_target
.to_terminal_ours ();
2420 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
2424 debug_to_terminal_info (char *arg
, int from_tty
)
2426 debug_target
.to_terminal_info (arg
, from_tty
);
2428 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
2433 debug_to_kill (void)
2435 debug_target
.to_kill ();
2437 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
2441 debug_to_load (char *args
, int from_tty
)
2443 debug_target
.to_load (args
, from_tty
);
2445 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
2449 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
2453 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
2455 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
2461 debug_to_create_inferior (char *exec_file
, char *args
, char **env
)
2463 debug_target
.to_create_inferior (exec_file
, args
, env
);
2465 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx)\n",
2470 debug_to_post_startup_inferior (int pid
)
2472 debug_target
.to_post_startup_inferior (pid
);
2474 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
2479 debug_to_acknowledge_created_inferior (int pid
)
2481 debug_target
.to_acknowledge_created_inferior (pid
);
2483 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
2488 debug_to_clone_and_follow_inferior (int child_pid
, int *followed_child
)
2490 debug_target
.to_clone_and_follow_inferior (child_pid
, followed_child
);
2492 fprintf_unfiltered (gdb_stdlog
,
2493 "target_clone_and_follow_inferior (%d, %d)\n",
2494 child_pid
, *followed_child
);
2498 debug_to_post_follow_inferior_by_clone (void)
2500 debug_target
.to_post_follow_inferior_by_clone ();
2502 fprintf_unfiltered (gdb_stdlog
, "target_post_follow_inferior_by_clone ()\n");
2506 debug_to_insert_fork_catchpoint (int pid
)
2510 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
2512 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
2519 debug_to_remove_fork_catchpoint (int pid
)
2523 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
2525 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
2532 debug_to_insert_vfork_catchpoint (int pid
)
2536 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
2538 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)= %d\n",
2545 debug_to_remove_vfork_catchpoint (int pid
)
2549 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
2551 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
2558 debug_to_has_forked (int pid
, int *child_pid
)
2562 has_forked
= debug_target
.to_has_forked (pid
, child_pid
);
2564 fprintf_unfiltered (gdb_stdlog
, "target_has_forked (%d, %d) = %d\n",
2565 pid
, *child_pid
, has_forked
);
2571 debug_to_has_vforked (int pid
, int *child_pid
)
2575 has_vforked
= debug_target
.to_has_vforked (pid
, child_pid
);
2577 fprintf_unfiltered (gdb_stdlog
, "target_has_vforked (%d, %d) = %d\n",
2578 pid
, *child_pid
, has_vforked
);
2584 debug_to_can_follow_vfork_prior_to_exec (void)
2586 int can_immediately_follow_vfork
;
2588 can_immediately_follow_vfork
= debug_target
.to_can_follow_vfork_prior_to_exec ();
2590 fprintf_unfiltered (gdb_stdlog
, "target_can_follow_vfork_prior_to_exec () = %d\n",
2591 can_immediately_follow_vfork
);
2593 return can_immediately_follow_vfork
;
2597 debug_to_post_follow_vfork (int parent_pid
, int followed_parent
, int child_pid
,
2600 debug_target
.to_post_follow_vfork (parent_pid
, followed_parent
, child_pid
, followed_child
);
2602 fprintf_unfiltered (gdb_stdlog
,
2603 "target_post_follow_vfork (%d, %d, %d, %d)\n",
2604 parent_pid
, followed_parent
, child_pid
, followed_child
);
2608 debug_to_insert_exec_catchpoint (int pid
)
2612 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
2614 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
2621 debug_to_remove_exec_catchpoint (int pid
)
2625 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
2627 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2634 debug_to_has_execd (int pid
, char **execd_pathname
)
2638 has_execd
= debug_target
.to_has_execd (pid
, execd_pathname
);
2640 fprintf_unfiltered (gdb_stdlog
, "target_has_execd (%d, %s) = %d\n",
2641 pid
, (*execd_pathname
? *execd_pathname
: "<NULL>"),
2648 debug_to_reported_exec_events_per_exec_call (void)
2650 int reported_exec_events
;
2652 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2654 fprintf_unfiltered (gdb_stdlog
,
2655 "target_reported_exec_events_per_exec_call () = %d\n",
2656 reported_exec_events
);
2658 return reported_exec_events
;
2662 debug_to_has_syscall_event (int pid
, enum target_waitkind
*kind
,
2665 int has_syscall_event
;
2666 char *kind_spelling
= "??";
2668 has_syscall_event
= debug_target
.to_has_syscall_event (pid
, kind
, syscall_id
);
2669 if (has_syscall_event
)
2673 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2674 kind_spelling
= "SYSCALL_ENTRY";
2676 case TARGET_WAITKIND_SYSCALL_RETURN
:
2677 kind_spelling
= "SYSCALL_RETURN";
2684 fprintf_unfiltered (gdb_stdlog
,
2685 "target_has_syscall_event (%d, %s, %d) = %d\n",
2686 pid
, kind_spelling
, *syscall_id
, has_syscall_event
);
2688 return has_syscall_event
;
2692 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
2696 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2698 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2699 pid
, wait_status
, *exit_status
, has_exited
);
2705 debug_to_mourn_inferior (void)
2707 debug_target
.to_mourn_inferior ();
2709 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2713 debug_to_can_run (void)
2717 retval
= debug_target
.to_can_run ();
2719 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2725 debug_to_notice_signals (int pid
)
2727 debug_target
.to_notice_signals (pid
);
2729 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n", pid
);
2733 debug_to_thread_alive (int pid
)
2737 retval
= debug_target
.to_thread_alive (pid
);
2739 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2746 debug_to_find_new_threads (void)
2748 debug_target
.to_find_new_threads ();
2750 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog
);
2754 debug_to_stop (void)
2756 debug_target
.to_stop ();
2758 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2762 debug_to_query (int type
, char *req
, char *resp
, int *siz
)
2766 retval
= debug_target
.to_query (type
, req
, resp
, siz
);
2768 fprintf_unfiltered (gdb_stdlog
, "target_query (%c, %s, %s, %d) = %d\n", type
, req
, resp
, *siz
, retval
);
2774 debug_to_rcmd (char *command
,
2775 struct ui_file
*outbuf
)
2777 debug_target
.to_rcmd (command
, outbuf
);
2778 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2781 static struct symtab_and_line
*
2782 debug_to_enable_exception_callback (enum exception_event_kind kind
, int enable
)
2784 struct symtab_and_line
*result
;
2785 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2786 fprintf_unfiltered (gdb_stdlog
,
2787 "target get_exception_callback_sal (%d, %d)\n",
2792 static struct exception_event_record
*
2793 debug_to_get_current_exception_event (void)
2795 struct exception_event_record
*result
;
2796 result
= debug_target
.to_get_current_exception_event ();
2797 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2802 debug_to_pid_to_exec_file (int pid
)
2806 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2808 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2815 debug_to_core_file_to_sym_file (char *core
)
2819 sym_file
= debug_target
.to_core_file_to_sym_file (core
);
2821 fprintf_unfiltered (gdb_stdlog
, "target_core_file_to_sym_file (%s) = %s\n",
2828 setup_target_debug (void)
2830 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2832 current_target
.to_open
= debug_to_open
;
2833 current_target
.to_close
= debug_to_close
;
2834 current_target
.to_attach
= debug_to_attach
;
2835 current_target
.to_post_attach
= debug_to_post_attach
;
2836 current_target
.to_require_attach
= debug_to_require_attach
;
2837 current_target
.to_detach
= debug_to_detach
;
2838 current_target
.to_require_detach
= debug_to_require_detach
;
2839 current_target
.to_resume
= debug_to_resume
;
2840 current_target
.to_wait
= debug_to_wait
;
2841 current_target
.to_post_wait
= debug_to_post_wait
;
2842 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2843 current_target
.to_store_registers
= debug_to_store_registers
;
2844 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2845 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2846 current_target
.to_files_info
= debug_to_files_info
;
2847 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2848 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2849 current_target
.to_terminal_init
= debug_to_terminal_init
;
2850 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2851 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2852 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2853 current_target
.to_terminal_info
= debug_to_terminal_info
;
2854 current_target
.to_kill
= debug_to_kill
;
2855 current_target
.to_load
= debug_to_load
;
2856 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2857 current_target
.to_create_inferior
= debug_to_create_inferior
;
2858 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2859 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2860 current_target
.to_clone_and_follow_inferior
= debug_to_clone_and_follow_inferior
;
2861 current_target
.to_post_follow_inferior_by_clone
= debug_to_post_follow_inferior_by_clone
;
2862 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2863 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2864 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2865 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2866 current_target
.to_has_forked
= debug_to_has_forked
;
2867 current_target
.to_has_vforked
= debug_to_has_vforked
;
2868 current_target
.to_can_follow_vfork_prior_to_exec
= debug_to_can_follow_vfork_prior_to_exec
;
2869 current_target
.to_post_follow_vfork
= debug_to_post_follow_vfork
;
2870 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2871 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2872 current_target
.to_has_execd
= debug_to_has_execd
;
2873 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2874 current_target
.to_has_syscall_event
= debug_to_has_syscall_event
;
2875 current_target
.to_has_exited
= debug_to_has_exited
;
2876 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2877 current_target
.to_can_run
= debug_to_can_run
;
2878 current_target
.to_notice_signals
= debug_to_notice_signals
;
2879 current_target
.to_thread_alive
= debug_to_thread_alive
;
2880 current_target
.to_find_new_threads
= debug_to_find_new_threads
;
2881 current_target
.to_stop
= debug_to_stop
;
2882 current_target
.to_query
= debug_to_query
;
2883 current_target
.to_rcmd
= debug_to_rcmd
;
2884 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
2885 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
2886 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2887 current_target
.to_core_file_to_sym_file
= debug_to_core_file_to_sym_file
;
2892 static char targ_desc
[] =
2893 "Names of targets and files being debugged.\n\
2894 Shows the entire stack of targets currently in use (including the exec-file,\n\
2895 core-file, and process, if any), as well as the symbol file name.";
2898 do_monitor_command (char *cmd
,
2901 if ((current_target
.to_rcmd
2902 == (void (*) (char *, struct ui_file
*)) tcomplain
)
2903 || (current_target
.to_rcmd
== debug_to_rcmd
2904 && (debug_target
.to_rcmd
2905 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
2907 error ("\"monitor\" command not supported by this target.\n");
2909 target_rcmd (cmd
, gdb_stdtarg
);
2913 initialize_targets (void)
2915 init_dummy_target ();
2916 push_target (&dummy_target
);
2918 add_info ("target", target_info
, targ_desc
);
2919 add_info ("files", target_info
, targ_desc
);
2922 add_set_cmd ("target", class_maintenance
, var_zinteger
,
2923 (char *) &targetdebug
,
2924 "Set target debugging.\n\
2925 When non-zero, target debugging is enabled.", &setdebuglist
),
2929 add_com ("monitor", class_obscure
, do_monitor_command
,
2930 "Send a command to the remote monitor (remote targets only).");
2932 target_dcache
= dcache_init();
2934 if (!STREQ (signals
[TARGET_SIGNAL_LAST
].string
, "TARGET_SIGNAL_MAGIC"))