1 /* Select target systems and architectures at runtime for GDB.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001 Free Software Foundation, Inc.
4 Contributed by Cygnus Support.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
26 #include "gdb_string.h"
41 static void target_info (char *, int);
43 static void cleanup_target (struct target_ops
*);
45 static void maybe_kill_then_create_inferior (char *, char *, char **);
47 static void default_clone_and_follow_inferior (int, int *);
49 static void maybe_kill_then_attach (char *, int);
51 static void kill_or_be_killed (int);
53 static void default_terminal_info (char *, int);
55 static int nosymbol (char *, CORE_ADDR
*);
57 static void tcomplain (void);
59 static int nomemory (CORE_ADDR
, char *, int, int, struct target_ops
*);
61 static int return_zero (void);
63 static int return_one (void);
65 void target_ignore (void);
67 static void target_command (char *, int);
69 static struct target_ops
*find_default_run_target (char *);
71 static void update_current_target (void);
73 static void nosupport_runtime (void);
75 static void normal_target_post_startup_inferior (int pid
);
77 /* Transfer LEN bytes between target address MEMADDR and GDB address
78 MYADDR. Returns 0 for success, errno code for failure (which
79 includes partial transfers -- if you want a more useful response to
80 partial transfers, try either target_read_memory_partial or
81 target_write_memory_partial). */
84 target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
);
86 static void init_dummy_target (void);
88 static void debug_to_open (char *, int);
90 static void debug_to_close (int);
92 static void debug_to_attach (char *, int);
94 static void debug_to_detach (char *, int);
96 static void debug_to_resume (int, int, enum target_signal
);
98 static int debug_to_wait (int, struct target_waitstatus
*);
100 static void debug_to_fetch_registers (int);
102 static void debug_to_store_registers (int);
104 static void debug_to_prepare_to_store (void);
107 debug_to_xfer_memory (CORE_ADDR
, char *, int, int, struct mem_attrib
*,
108 struct target_ops
*);
110 static void debug_to_files_info (struct target_ops
*);
112 static int debug_to_insert_breakpoint (CORE_ADDR
, char *);
114 static int debug_to_remove_breakpoint (CORE_ADDR
, char *);
116 static void debug_to_terminal_init (void);
118 static void debug_to_terminal_inferior (void);
120 static void debug_to_terminal_ours_for_output (void);
122 static void debug_to_terminal_ours (void);
124 static void debug_to_terminal_info (char *, int);
126 static void debug_to_kill (void);
128 static void debug_to_load (char *, int);
130 static int debug_to_lookup_symbol (char *, CORE_ADDR
*);
132 static void debug_to_create_inferior (char *, char *, char **);
134 static void debug_to_mourn_inferior (void);
136 static int debug_to_can_run (void);
138 static void debug_to_notice_signals (int);
140 static int debug_to_thread_alive (int);
142 static void debug_to_stop (void);
144 static int debug_to_query (int /*char */ , char *, char *, int *);
146 /* Pointer to array of target architecture structures; the size of the
147 array; the current index into the array; the allocated size of the
149 struct target_ops
**target_structs
;
150 unsigned target_struct_size
;
151 unsigned target_struct_index
;
152 unsigned target_struct_allocsize
;
153 #define DEFAULT_ALLOCSIZE 10
155 /* The initial current target, so that there is always a semi-valid
158 static struct target_ops dummy_target
;
160 /* Top of target stack. */
162 struct target_stack_item
*target_stack
;
164 /* The target structure we are currently using to talk to a process
165 or file or whatever "inferior" we have. */
167 struct target_ops current_target
;
169 /* Command list for target. */
171 static struct cmd_list_element
*targetlist
= NULL
;
173 /* Nonzero if we are debugging an attached outside process
174 rather than an inferior. */
178 /* Non-zero if we want to see trace of target level stuff. */
180 static int targetdebug
= 0;
182 static void setup_target_debug (void);
184 DCACHE
*target_dcache
;
186 /* The user just typed 'target' without the name of a target. */
190 target_command (char *arg
, int from_tty
)
192 fputs_filtered ("Argument required (target name). Try `help target'\n",
196 /* Add a possible target architecture to the list. */
199 add_target (struct target_ops
*t
)
203 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
204 target_structs
= (struct target_ops
**) xmalloc
205 (target_struct_allocsize
* sizeof (*target_structs
));
207 if (target_struct_size
>= target_struct_allocsize
)
209 target_struct_allocsize
*= 2;
210 target_structs
= (struct target_ops
**)
211 xrealloc ((char *) target_structs
,
212 target_struct_allocsize
* sizeof (*target_structs
));
214 target_structs
[target_struct_size
++] = t
;
215 /* cleanup_target (t); */
217 if (targetlist
== NULL
)
218 add_prefix_cmd ("target", class_run
, target_command
,
219 "Connect to a target machine or process.\n\
220 The first argument is the type or protocol of the target machine.\n\
221 Remaining arguments are interpreted by the target protocol. For more\n\
222 information on the arguments for a particular protocol, type\n\
223 `help target ' followed by the protocol name.",
224 &targetlist
, "target ", 0, &cmdlist
);
225 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
236 target_load (char *arg
, int from_tty
)
238 dcache_invalidate (target_dcache
);
239 (*current_target
.to_load
) (arg
, from_tty
);
244 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
245 struct target_ops
*t
)
247 errno
= EIO
; /* Can't read/write this location */
248 return 0; /* No bytes handled */
254 error ("You can't do that when your target is `%s'",
255 current_target
.to_shortname
);
261 error ("You can't do that without a process to debug.");
266 nosymbol (char *name
, CORE_ADDR
*addrp
)
268 return 1; /* Symbol does not exist in target env */
273 nosupport_runtime (void)
278 error ("No run-time support for this");
284 default_terminal_info (char *args
, int from_tty
)
286 printf_unfiltered ("No saved terminal information.\n");
289 /* This is the default target_create_inferior and target_attach function.
290 If the current target is executing, it asks whether to kill it off.
291 If this function returns without calling error(), it has killed off
292 the target, and the operation should be attempted. */
295 kill_or_be_killed (int from_tty
)
297 if (target_has_execution
)
299 printf_unfiltered ("You are already running a program:\n");
300 target_files_info ();
301 if (query ("Kill it? "))
304 if (target_has_execution
)
305 error ("Killing the program did not help.");
310 error ("Program not killed.");
317 maybe_kill_then_attach (char *args
, int from_tty
)
319 kill_or_be_killed (from_tty
);
320 target_attach (args
, from_tty
);
324 maybe_kill_then_create_inferior (char *exec
, char *args
, char **env
)
326 kill_or_be_killed (0);
327 target_create_inferior (exec
, args
, env
);
331 default_clone_and_follow_inferior (int child_pid
, int *followed_child
)
333 target_clone_and_follow_inferior (child_pid
, followed_child
);
336 /* Clean up a target struct so it no longer has any zero pointers in it.
337 We default entries, at least to stubs that print error messages. */
340 cleanup_target (struct target_ops
*t
)
343 #define de_fault(field, value) \
348 (void (*) (char *, int))
354 maybe_kill_then_attach
);
355 de_fault (to_post_attach
,
358 de_fault (to_require_attach
,
359 maybe_kill_then_attach
);
361 (void (*) (char *, int))
363 de_fault (to_require_detach
,
364 (void (*) (int, char *, int))
367 (void (*) (int, int, enum target_signal
))
370 (int (*) (int, struct target_waitstatus
*))
372 de_fault (to_post_wait
,
373 (void (*) (int, int))
375 de_fault (to_fetch_registers
,
378 de_fault (to_store_registers
,
381 de_fault (to_prepare_to_store
,
384 de_fault (to_xfer_memory
,
385 (int (*) (CORE_ADDR
, char *, int, int, struct mem_attrib
*, struct target_ops
*))
387 de_fault (to_files_info
,
388 (void (*) (struct target_ops
*))
390 de_fault (to_insert_breakpoint
,
391 memory_insert_breakpoint
);
392 de_fault (to_remove_breakpoint
,
393 memory_remove_breakpoint
);
394 de_fault (to_terminal_init
,
397 de_fault (to_terminal_inferior
,
400 de_fault (to_terminal_ours_for_output
,
403 de_fault (to_terminal_ours
,
406 de_fault (to_terminal_info
,
407 default_terminal_info
);
412 (void (*) (char *, int))
414 de_fault (to_lookup_symbol
,
415 (int (*) (char *, CORE_ADDR
*))
417 de_fault (to_create_inferior
,
418 maybe_kill_then_create_inferior
);
419 de_fault (to_post_startup_inferior
,
422 de_fault (to_acknowledge_created_inferior
,
425 de_fault (to_clone_and_follow_inferior
,
426 default_clone_and_follow_inferior
);
427 de_fault (to_post_follow_inferior_by_clone
,
430 de_fault (to_insert_fork_catchpoint
,
433 de_fault (to_remove_fork_catchpoint
,
436 de_fault (to_insert_vfork_catchpoint
,
439 de_fault (to_remove_vfork_catchpoint
,
442 de_fault (to_has_forked
,
443 (int (*) (int, int *))
445 de_fault (to_has_vforked
,
446 (int (*) (int, int *))
448 de_fault (to_can_follow_vfork_prior_to_exec
,
451 de_fault (to_post_follow_vfork
,
452 (void (*) (int, int, int, int))
454 de_fault (to_insert_exec_catchpoint
,
457 de_fault (to_remove_exec_catchpoint
,
460 de_fault (to_has_execd
,
461 (int (*) (int, char **))
463 de_fault (to_reported_exec_events_per_exec_call
,
466 de_fault (to_has_syscall_event
,
467 (int (*) (int, enum target_waitkind
*, int *))
469 de_fault (to_has_exited
,
470 (int (*) (int, int, int *))
472 de_fault (to_mourn_inferior
,
475 de_fault (to_can_run
,
477 de_fault (to_notice_signals
,
480 de_fault (to_thread_alive
,
483 de_fault (to_find_new_threads
,
486 de_fault (to_extra_thread_info
,
487 (char *(*) (struct thread_info
*))
493 (int (*) (int, char *, char *, int *))
496 (void (*) (char *, struct ui_file
*))
498 de_fault (to_enable_exception_callback
,
499 (struct symtab_and_line
* (*) (enum exception_event_kind
, int))
501 de_fault (to_get_current_exception_event
,
502 (struct exception_event_record
* (*) (void))
504 de_fault (to_pid_to_exec_file
,
507 de_fault (to_core_file_to_sym_file
,
510 de_fault (to_can_async_p
,
513 de_fault (to_is_async_p
,
517 (void (*) (void (*) (enum inferior_event_type
, void*), void*))
522 /* Go through the target stack from top to bottom, copying over zero entries in
523 current_target. In effect, we are doing class inheritance through the
524 pushed target vectors. */
527 update_current_target (void)
529 struct target_stack_item
*item
;
530 struct target_ops
*t
;
532 /* First, reset current_target */
533 memset (¤t_target
, 0, sizeof current_target
);
535 for (item
= target_stack
; item
; item
= item
->next
)
537 t
= item
->target_ops
;
539 #define INHERIT(FIELD, TARGET) \
540 if (!current_target.FIELD) \
541 current_target.FIELD = TARGET->FIELD
543 INHERIT (to_shortname
, t
);
544 INHERIT (to_longname
, t
);
546 INHERIT (to_open
, t
);
547 INHERIT (to_close
, t
);
548 INHERIT (to_attach
, t
);
549 INHERIT (to_post_attach
, t
);
550 INHERIT (to_require_attach
, t
);
551 INHERIT (to_detach
, t
);
552 INHERIT (to_require_detach
, t
);
553 INHERIT (to_resume
, t
);
554 INHERIT (to_wait
, t
);
555 INHERIT (to_post_wait
, t
);
556 INHERIT (to_fetch_registers
, t
);
557 INHERIT (to_store_registers
, t
);
558 INHERIT (to_prepare_to_store
, t
);
559 INHERIT (to_xfer_memory
, t
);
560 INHERIT (to_files_info
, t
);
561 INHERIT (to_insert_breakpoint
, t
);
562 INHERIT (to_remove_breakpoint
, t
);
563 INHERIT (to_terminal_init
, t
);
564 INHERIT (to_terminal_inferior
, t
);
565 INHERIT (to_terminal_ours_for_output
, t
);
566 INHERIT (to_terminal_ours
, t
);
567 INHERIT (to_terminal_info
, t
);
568 INHERIT (to_kill
, t
);
569 INHERIT (to_load
, t
);
570 INHERIT (to_lookup_symbol
, t
);
571 INHERIT (to_create_inferior
, t
);
572 INHERIT (to_post_startup_inferior
, t
);
573 INHERIT (to_acknowledge_created_inferior
, t
);
574 INHERIT (to_clone_and_follow_inferior
, t
);
575 INHERIT (to_post_follow_inferior_by_clone
, t
);
576 INHERIT (to_insert_fork_catchpoint
, t
);
577 INHERIT (to_remove_fork_catchpoint
, t
);
578 INHERIT (to_insert_vfork_catchpoint
, t
);
579 INHERIT (to_remove_vfork_catchpoint
, t
);
580 INHERIT (to_has_forked
, t
);
581 INHERIT (to_has_vforked
, t
);
582 INHERIT (to_can_follow_vfork_prior_to_exec
, t
);
583 INHERIT (to_post_follow_vfork
, t
);
584 INHERIT (to_insert_exec_catchpoint
, t
);
585 INHERIT (to_remove_exec_catchpoint
, t
);
586 INHERIT (to_has_execd
, t
);
587 INHERIT (to_reported_exec_events_per_exec_call
, t
);
588 INHERIT (to_has_syscall_event
, t
);
589 INHERIT (to_has_exited
, t
);
590 INHERIT (to_mourn_inferior
, t
);
591 INHERIT (to_can_run
, t
);
592 INHERIT (to_notice_signals
, t
);
593 INHERIT (to_thread_alive
, t
);
594 INHERIT (to_find_new_threads
, t
);
595 INHERIT (to_pid_to_str
, t
);
596 INHERIT (to_extra_thread_info
, t
);
597 INHERIT (to_stop
, t
);
598 INHERIT (to_query
, t
);
599 INHERIT (to_rcmd
, t
);
600 INHERIT (to_enable_exception_callback
, t
);
601 INHERIT (to_get_current_exception_event
, t
);
602 INHERIT (to_pid_to_exec_file
, t
);
603 INHERIT (to_core_file_to_sym_file
, t
);
604 INHERIT (to_stratum
, t
);
605 INHERIT (DONT_USE
, t
);
606 INHERIT (to_has_all_memory
, t
);
607 INHERIT (to_has_memory
, t
);
608 INHERIT (to_has_stack
, t
);
609 INHERIT (to_has_registers
, t
);
610 INHERIT (to_has_execution
, t
);
611 INHERIT (to_has_thread_control
, t
);
612 INHERIT (to_sections
, t
);
613 INHERIT (to_sections_end
, t
);
614 INHERIT (to_can_async_p
, t
);
615 INHERIT (to_is_async_p
, t
);
616 INHERIT (to_async
, t
);
617 INHERIT (to_async_mask_value
, t
);
618 INHERIT (to_magic
, t
);
624 /* Push a new target type into the stack of the existing target accessors,
625 possibly superseding some of the existing accessors.
627 Result is zero if the pushed target ended up on top of the stack,
628 nonzero if at least one target is on top of it.
630 Rather than allow an empty stack, we always have the dummy target at
631 the bottom stratum, so we can call the function vectors without
635 push_target (struct target_ops
*t
)
637 struct target_stack_item
*cur
, *prev
, *tmp
;
639 /* Check magic number. If wrong, it probably means someone changed
640 the struct definition, but not all the places that initialize one. */
641 if (t
->to_magic
!= OPS_MAGIC
)
643 fprintf_unfiltered (gdb_stderr
,
644 "Magic number of %s target struct wrong\n",
646 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
649 /* Find the proper stratum to install this target in. */
651 for (prev
= NULL
, cur
= target_stack
; cur
; prev
= cur
, cur
= cur
->next
)
653 if ((int) (t
->to_stratum
) >= (int) (cur
->target_ops
->to_stratum
))
657 /* If there's already targets at this stratum, remove them. */
660 while (t
->to_stratum
== cur
->target_ops
->to_stratum
)
662 /* There's already something on this stratum. Close it off. */
663 if (cur
->target_ops
->to_close
)
664 (cur
->target_ops
->to_close
) (0);
666 prev
->next
= cur
->next
; /* Unchain old target_ops */
668 target_stack
= cur
->next
; /* Unchain first on list */
674 /* We have removed all targets in our stratum, now add the new one. */
676 tmp
= (struct target_stack_item
*)
677 xmalloc (sizeof (struct target_stack_item
));
686 update_current_target ();
688 cleanup_target (¤t_target
); /* Fill in the gaps */
691 setup_target_debug ();
696 /* Remove a target_ops vector from the stack, wherever it may be.
697 Return how many times it was removed (0 or 1). */
700 unpush_target (struct target_ops
*t
)
702 struct target_stack_item
*cur
, *prev
;
705 t
->to_close (0); /* Let it clean up */
707 /* Look for the specified target. Note that we assume that a target
708 can only occur once in the target stack. */
710 for (cur
= target_stack
, prev
= NULL
; cur
; prev
= cur
, cur
= cur
->next
)
711 if (cur
->target_ops
== t
)
715 return 0; /* Didn't find target_ops, quit now */
717 /* Unchain the target */
720 target_stack
= cur
->next
;
722 prev
->next
= cur
->next
;
724 xfree (cur
); /* Release the target_stack_item */
726 update_current_target ();
727 cleanup_target (¤t_target
);
735 (current_target
.to_close
) (0); /* Let it clean up */
736 if (unpush_target (target_stack
->target_ops
) == 1)
739 fprintf_unfiltered (gdb_stderr
,
740 "pop_target couldn't find target %s\n",
741 current_target
.to_shortname
);
742 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
746 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
748 /* target_read_string -- read a null terminated string, up to LEN bytes,
749 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
750 Set *STRING to a pointer to malloc'd memory containing the data; the caller
751 is responsible for freeing it. Return the number of bytes successfully
755 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
757 int tlen
, origlen
, offset
, i
;
761 int buffer_allocated
;
763 unsigned int nbytes_read
= 0;
765 /* Small for testing. */
766 buffer_allocated
= 4;
767 buffer
= xmalloc (buffer_allocated
);
774 tlen
= MIN (len
, 4 - (memaddr
& 3));
775 offset
= memaddr
& 3;
777 errcode
= target_xfer_memory (memaddr
& ~3, buf
, 4, 0);
780 /* The transfer request might have crossed the boundary to an
781 unallocated region of memory. Retry the transfer, requesting
785 errcode
= target_xfer_memory (memaddr
, buf
, 1, 0);
790 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
793 bytes
= bufptr
- buffer
;
794 buffer_allocated
*= 2;
795 buffer
= xrealloc (buffer
, buffer_allocated
);
796 bufptr
= buffer
+ bytes
;
799 for (i
= 0; i
< tlen
; i
++)
801 *bufptr
++ = buf
[i
+ offset
];
802 if (buf
[i
+ offset
] == '\000')
804 nbytes_read
+= i
+ 1;
821 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
822 GDB's memory at MYADDR. Returns either 0 for success or an errno value
825 If an error occurs, no guarantee is made about the contents of the data at
826 MYADDR. In particular, the caller should not depend upon partial reads
827 filling the buffer with good data. There is no way for the caller to know
828 how much good data might have been transfered anyway. Callers that can
829 deal with partial reads should call target_read_memory_partial. */
832 target_read_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
834 return target_xfer_memory (memaddr
, myaddr
, len
, 0);
838 target_write_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
840 return target_xfer_memory (memaddr
, myaddr
, len
, 1);
843 /* Move memory to or from the targets. The top target gets priority;
844 if it cannot handle it, it is offered to the next one down, etc.
846 Result is -1 on error, or the number of bytes transfered. */
849 do_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
850 struct mem_attrib
*attrib
)
854 struct target_ops
*t
;
855 struct target_stack_item
*item
;
857 /* Zero length requests are ok and require no work. */
861 /* to_xfer_memory is not guaranteed to set errno, even when it returns
865 /* The quick case is that the top target can handle the transfer. */
866 res
= current_target
.to_xfer_memory
867 (memaddr
, myaddr
, len
, write
, attrib
, ¤t_target
);
869 /* If res <= 0 then we call it again in the loop. Ah well. */
872 for (item
= target_stack
; item
; item
= item
->next
)
874 t
= item
->target_ops
;
875 if (!t
->to_has_memory
)
878 res
= t
->to_xfer_memory (memaddr
, myaddr
, len
, write
, attrib
, t
);
880 break; /* Handled all or part of xfer */
881 if (t
->to_has_all_memory
)
893 /* Perform a memory transfer. Iterate until the entire region has
896 Result is 0 or errno value. */
899 target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
)
903 struct mem_region
*region
;
905 /* Zero length requests are ok and require no work. */
913 region
= lookup_mem_region(memaddr
);
914 if (memaddr
+ len
< region
->hi
)
917 reg_len
= region
->hi
- memaddr
;
919 switch (region
->attrib
.mode
)
934 if (region
->attrib
.cache
)
935 res
= dcache_xfer_memory(target_dcache
, memaddr
, myaddr
,
938 res
= do_xfer_memory(memaddr
, myaddr
, reg_len
, write
,
943 /* If this address is for nonexistent memory, read zeros
944 if reading, or do nothing if writing. Return
947 memset (myaddr
, 0, len
);
961 return 0; /* We managed to cover it all somehow. */
965 /* Perform a partial memory transfer.
967 Result is -1 on error, or the number of bytes transfered. */
970 target_xfer_memory_partial (CORE_ADDR memaddr
, char *myaddr
, int len
,
971 int write_p
, int *err
)
975 struct mem_region
*region
;
977 /* Zero length requests are ok and require no work. */
984 region
= lookup_mem_region(memaddr
);
985 if (memaddr
+ len
< region
->hi
)
988 reg_len
= region
->hi
- memaddr
;
990 switch (region
->attrib
.mode
)
1009 if (region
->attrib
.cache
)
1010 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
,
1013 res
= do_xfer_memory (memaddr
, myaddr
, reg_len
, write_p
,
1031 target_read_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1033 return target_xfer_memory_partial (memaddr
, buf
, len
, 0, err
);
1037 target_write_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1039 return target_xfer_memory_partial (memaddr
, buf
, len
, 1, err
);
1044 target_info (char *args
, int from_tty
)
1046 struct target_ops
*t
;
1047 struct target_stack_item
*item
;
1048 int has_all_mem
= 0;
1050 if (symfile_objfile
!= NULL
)
1051 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
1053 #ifdef FILES_INFO_HOOK
1054 if (FILES_INFO_HOOK ())
1058 for (item
= target_stack
; item
; item
= item
->next
)
1060 t
= item
->target_ops
;
1062 if (!t
->to_has_memory
)
1065 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
1068 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1069 printf_unfiltered ("%s:\n", t
->to_longname
);
1070 (t
->to_files_info
) (t
);
1071 has_all_mem
= t
->to_has_all_memory
;
1075 /* This is to be called by the open routine before it does
1079 target_preopen (int from_tty
)
1083 if (target_has_execution
)
1086 || query ("A program is being debugged already. Kill it? "))
1089 error ("Program not killed.");
1092 /* Calling target_kill may remove the target from the stack. But if
1093 it doesn't (which seems like a win for UDI), remove it now. */
1095 if (target_has_execution
)
1099 /* Detach a target after doing deferred register stores. */
1102 target_detach (char *args
, int from_tty
)
1104 /* Handle any optimized stores to the inferior. */
1105 #ifdef DO_DEFERRED_STORES
1108 (current_target
.to_detach
) (args
, from_tty
);
1112 target_link (char *modname
, CORE_ADDR
*t_reloc
)
1114 if (STREQ (current_target
.to_shortname
, "rombug"))
1116 (current_target
.to_lookup_symbol
) (modname
, t_reloc
);
1118 error ("Unable to link to %s and get relocation in rombug", modname
);
1121 *t_reloc
= (CORE_ADDR
) -1;
1125 target_async_mask (int mask
)
1127 int saved_async_masked_status
= target_async_mask_value
;
1128 target_async_mask_value
= mask
;
1129 return saved_async_masked_status
;
1132 /* Look through the list of possible targets for a target that can
1133 execute a run or attach command without any other data. This is
1134 used to locate the default process stratum.
1136 Result is always valid (error() is called for errors). */
1138 static struct target_ops
*
1139 find_default_run_target (char *do_mesg
)
1141 struct target_ops
**t
;
1142 struct target_ops
*runable
= NULL
;
1147 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1150 if ((*t
)->to_can_run
&& target_can_run (*t
))
1158 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
1164 find_default_attach (char *args
, int from_tty
)
1166 struct target_ops
*t
;
1168 t
= find_default_run_target ("attach");
1169 (t
->to_attach
) (args
, from_tty
);
1174 find_default_require_attach (char *args
, int from_tty
)
1176 struct target_ops
*t
;
1178 t
= find_default_run_target ("require_attach");
1179 (t
->to_require_attach
) (args
, from_tty
);
1184 find_default_require_detach (int pid
, char *args
, int from_tty
)
1186 struct target_ops
*t
;
1188 t
= find_default_run_target ("require_detach");
1189 (t
->to_require_detach
) (pid
, args
, from_tty
);
1194 find_default_create_inferior (char *exec_file
, char *allargs
, char **env
)
1196 struct target_ops
*t
;
1198 t
= find_default_run_target ("run");
1199 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
1204 find_default_clone_and_follow_inferior (int child_pid
, int *followed_child
)
1206 struct target_ops
*t
;
1208 t
= find_default_run_target ("run");
1209 (t
->to_clone_and_follow_inferior
) (child_pid
, followed_child
);
1226 * Resize the to_sections pointer. Also make sure that anyone that
1227 * was holding on to an old value of it gets updated.
1228 * Returns the old size.
1232 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1234 struct target_ops
**t
;
1235 struct section_table
*old_value
;
1238 old_value
= target
->to_sections
;
1240 if (target
->to_sections
)
1242 old_count
= target
->to_sections_end
- target
->to_sections
;
1243 target
->to_sections
= (struct section_table
*)
1244 xrealloc ((char *) target
->to_sections
,
1245 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1250 target
->to_sections
= (struct section_table
*)
1251 xmalloc ((sizeof (struct section_table
)) * num_added
);
1253 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1255 /* Check to see if anyone else was pointing to this structure.
1256 If old_value was null, then no one was. */
1260 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1263 if ((*t
)->to_sections
== old_value
)
1265 (*t
)->to_sections
= target
->to_sections
;
1266 (*t
)->to_sections_end
= target
->to_sections_end
;
1275 /* Remove all target sections taken from ABFD.
1277 Scan the current target stack for targets whose section tables
1278 refer to sections from BFD, and remove those sections. We use this
1279 when we notice that the inferior has unloaded a shared object, for
1282 remove_target_sections (bfd
*abfd
)
1284 struct target_ops
**t
;
1286 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; t
++)
1288 struct section_table
*src
, *dest
;
1290 dest
= (*t
)->to_sections
;
1291 for (src
= (*t
)->to_sections
; src
< (*t
)->to_sections_end
; src
++)
1292 if (src
->bfd
!= abfd
)
1294 /* Keep this section. */
1295 if (dest
< src
) *dest
= *src
;
1299 /* If we've dropped any sections, resize the section table. */
1301 target_resize_to_sections (*t
, dest
- src
);
1308 /* Find a single runnable target in the stack and return it. If for
1309 some reason there is more than one, return NULL. */
1312 find_run_target (void)
1314 struct target_ops
**t
;
1315 struct target_ops
*runable
= NULL
;
1320 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1322 if ((*t
)->to_can_run
&& target_can_run (*t
))
1329 return (count
== 1 ? runable
: NULL
);
1332 /* Find a single core_stratum target in the list of targets and return it.
1333 If for some reason there is more than one, return NULL. */
1336 find_core_target (void)
1338 struct target_ops
**t
;
1339 struct target_ops
*runable
= NULL
;
1344 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1347 if ((*t
)->to_stratum
== core_stratum
)
1354 return (count
== 1 ? runable
: NULL
);
1358 * Find the next target down the stack from the specified target.
1362 find_target_beneath (struct target_ops
*t
)
1364 struct target_stack_item
*cur
;
1366 for (cur
= target_stack
; cur
; cur
= cur
->next
)
1367 if (cur
->target_ops
== t
)
1370 if (cur
== NULL
|| cur
->next
== NULL
)
1373 return cur
->next
->target_ops
;
1377 /* The inferior process has died. Long live the inferior! */
1380 generic_mourn_inferior (void)
1382 extern int show_breakpoint_hit_counts
;
1386 breakpoint_init_inferior (inf_exited
);
1387 registers_changed ();
1389 #ifdef CLEAR_DEFERRED_STORES
1390 /* Delete any pending stores to the inferior... */
1391 CLEAR_DEFERRED_STORES
;
1394 reopen_exec_file ();
1395 reinit_frame_cache ();
1397 /* It is confusing to the user for ignore counts to stick around
1398 from previous runs of the inferior. So clear them. */
1399 /* However, it is more confusing for the ignore counts to disappear when
1400 using hit counts. So don't clear them if we're counting hits. */
1401 if (!show_breakpoint_hit_counts
)
1402 breakpoint_clear_ignore_counts ();
1408 /* This table must match in order and size the signals in enum target_signal
1417 {"SIGHUP", "Hangup"},
1418 {"SIGINT", "Interrupt"},
1419 {"SIGQUIT", "Quit"},
1420 {"SIGILL", "Illegal instruction"},
1421 {"SIGTRAP", "Trace/breakpoint trap"},
1422 {"SIGABRT", "Aborted"},
1423 {"SIGEMT", "Emulation trap"},
1424 {"SIGFPE", "Arithmetic exception"},
1425 {"SIGKILL", "Killed"},
1426 {"SIGBUS", "Bus error"},
1427 {"SIGSEGV", "Segmentation fault"},
1428 {"SIGSYS", "Bad system call"},
1429 {"SIGPIPE", "Broken pipe"},
1430 {"SIGALRM", "Alarm clock"},
1431 {"SIGTERM", "Terminated"},
1432 {"SIGURG", "Urgent I/O condition"},
1433 {"SIGSTOP", "Stopped (signal)"},
1434 {"SIGTSTP", "Stopped (user)"},
1435 {"SIGCONT", "Continued"},
1436 {"SIGCHLD", "Child status changed"},
1437 {"SIGTTIN", "Stopped (tty input)"},
1438 {"SIGTTOU", "Stopped (tty output)"},
1439 {"SIGIO", "I/O possible"},
1440 {"SIGXCPU", "CPU time limit exceeded"},
1441 {"SIGXFSZ", "File size limit exceeded"},
1442 {"SIGVTALRM", "Virtual timer expired"},
1443 {"SIGPROF", "Profiling timer expired"},
1444 {"SIGWINCH", "Window size changed"},
1445 {"SIGLOST", "Resource lost"},
1446 {"SIGUSR1", "User defined signal 1"},
1447 {"SIGUSR2", "User defined signal 2"},
1448 {"SIGPWR", "Power fail/restart"},
1449 {"SIGPOLL", "Pollable event occurred"},
1450 {"SIGWIND", "SIGWIND"},
1451 {"SIGPHONE", "SIGPHONE"},
1452 {"SIGWAITING", "Process's LWPs are blocked"},
1453 {"SIGLWP", "Signal LWP"},
1454 {"SIGDANGER", "Swap space dangerously low"},
1455 {"SIGGRANT", "Monitor mode granted"},
1456 {"SIGRETRACT", "Need to relinquish monitor mode"},
1457 {"SIGMSG", "Monitor mode data available"},
1458 {"SIGSOUND", "Sound completed"},
1459 {"SIGSAK", "Secure attention"},
1460 {"SIGPRIO", "SIGPRIO"},
1461 {"SIG33", "Real-time event 33"},
1462 {"SIG34", "Real-time event 34"},
1463 {"SIG35", "Real-time event 35"},
1464 {"SIG36", "Real-time event 36"},
1465 {"SIG37", "Real-time event 37"},
1466 {"SIG38", "Real-time event 38"},
1467 {"SIG39", "Real-time event 39"},
1468 {"SIG40", "Real-time event 40"},
1469 {"SIG41", "Real-time event 41"},
1470 {"SIG42", "Real-time event 42"},
1471 {"SIG43", "Real-time event 43"},
1472 {"SIG44", "Real-time event 44"},
1473 {"SIG45", "Real-time event 45"},
1474 {"SIG46", "Real-time event 46"},
1475 {"SIG47", "Real-time event 47"},
1476 {"SIG48", "Real-time event 48"},
1477 {"SIG49", "Real-time event 49"},
1478 {"SIG50", "Real-time event 50"},
1479 {"SIG51", "Real-time event 51"},
1480 {"SIG52", "Real-time event 52"},
1481 {"SIG53", "Real-time event 53"},
1482 {"SIG54", "Real-time event 54"},
1483 {"SIG55", "Real-time event 55"},
1484 {"SIG56", "Real-time event 56"},
1485 {"SIG57", "Real-time event 57"},
1486 {"SIG58", "Real-time event 58"},
1487 {"SIG59", "Real-time event 59"},
1488 {"SIG60", "Real-time event 60"},
1489 {"SIG61", "Real-time event 61"},
1490 {"SIG62", "Real-time event 62"},
1491 {"SIG63", "Real-time event 63"},
1492 {"SIGCANCEL", "LWP internal signal"},
1493 {"SIG32", "Real-time event 32"},
1494 {"SIG64", "Real-time event 64"},
1496 #if defined(MACH) || defined(__MACH__)
1497 /* Mach exceptions */
1498 {"EXC_BAD_ACCESS", "Could not access memory"},
1499 {"EXC_BAD_INSTRUCTION", "Illegal instruction/operand"},
1500 {"EXC_ARITHMETIC", "Arithmetic exception"},
1501 {"EXC_EMULATION", "Emulation instruction"},
1502 {"EXC_SOFTWARE", "Software generated exception"},
1503 {"EXC_BREAKPOINT", "Breakpoint"},
1505 {"SIGINFO", "Information request"},
1507 {NULL
, "Unknown signal"},
1508 {NULL
, "Internal error: printing TARGET_SIGNAL_DEFAULT"},
1510 /* Last entry, used to check whether the table is the right size. */
1511 {NULL
, "TARGET_SIGNAL_MAGIC"}
1517 /* Return the string for a signal. */
1519 target_signal_to_string (enum target_signal sig
)
1521 if ((sig
>= TARGET_SIGNAL_FIRST
) && (sig
<= TARGET_SIGNAL_LAST
))
1522 return signals
[sig
].string
;
1524 return signals
[TARGET_SIGNAL_UNKNOWN
].string
;
1527 /* Return the name for a signal. */
1529 target_signal_to_name (enum target_signal sig
)
1531 if (sig
== TARGET_SIGNAL_UNKNOWN
)
1532 /* I think the code which prints this will always print it along with
1533 the string, so no need to be verbose. */
1535 return signals
[sig
].name
;
1538 /* Given a name, return its signal. */
1540 target_signal_from_name (char *name
)
1542 enum target_signal sig
;
1544 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
1545 for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
1546 questionable; seems like by now people should call it SIGABRT
1549 /* This ugly cast brought to you by the native VAX compiler. */
1550 for (sig
= TARGET_SIGNAL_HUP
;
1551 signals
[sig
].name
!= NULL
;
1552 sig
= (enum target_signal
) ((int) sig
+ 1))
1553 if (STREQ (name
, signals
[sig
].name
))
1555 return TARGET_SIGNAL_UNKNOWN
;
1558 /* The following functions are to help certain targets deal
1559 with the signal/waitstatus stuff. They could just as well be in
1560 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
1562 /* Convert host signal to our signals. */
1564 target_signal_from_host (int hostsig
)
1566 /* A switch statement would make sense but would require special kludges
1567 to deal with the cases where more than one signal has the same number. */
1570 return TARGET_SIGNAL_0
;
1572 #if defined (SIGHUP)
1573 if (hostsig
== SIGHUP
)
1574 return TARGET_SIGNAL_HUP
;
1576 #if defined (SIGINT)
1577 if (hostsig
== SIGINT
)
1578 return TARGET_SIGNAL_INT
;
1580 #if defined (SIGQUIT)
1581 if (hostsig
== SIGQUIT
)
1582 return TARGET_SIGNAL_QUIT
;
1584 #if defined (SIGILL)
1585 if (hostsig
== SIGILL
)
1586 return TARGET_SIGNAL_ILL
;
1588 #if defined (SIGTRAP)
1589 if (hostsig
== SIGTRAP
)
1590 return TARGET_SIGNAL_TRAP
;
1592 #if defined (SIGABRT)
1593 if (hostsig
== SIGABRT
)
1594 return TARGET_SIGNAL_ABRT
;
1596 #if defined (SIGEMT)
1597 if (hostsig
== SIGEMT
)
1598 return TARGET_SIGNAL_EMT
;
1600 #if defined (SIGFPE)
1601 if (hostsig
== SIGFPE
)
1602 return TARGET_SIGNAL_FPE
;
1604 #if defined (SIGKILL)
1605 if (hostsig
== SIGKILL
)
1606 return TARGET_SIGNAL_KILL
;
1608 #if defined (SIGBUS)
1609 if (hostsig
== SIGBUS
)
1610 return TARGET_SIGNAL_BUS
;
1612 #if defined (SIGSEGV)
1613 if (hostsig
== SIGSEGV
)
1614 return TARGET_SIGNAL_SEGV
;
1616 #if defined (SIGSYS)
1617 if (hostsig
== SIGSYS
)
1618 return TARGET_SIGNAL_SYS
;
1620 #if defined (SIGPIPE)
1621 if (hostsig
== SIGPIPE
)
1622 return TARGET_SIGNAL_PIPE
;
1624 #if defined (SIGALRM)
1625 if (hostsig
== SIGALRM
)
1626 return TARGET_SIGNAL_ALRM
;
1628 #if defined (SIGTERM)
1629 if (hostsig
== SIGTERM
)
1630 return TARGET_SIGNAL_TERM
;
1632 #if defined (SIGUSR1)
1633 if (hostsig
== SIGUSR1
)
1634 return TARGET_SIGNAL_USR1
;
1636 #if defined (SIGUSR2)
1637 if (hostsig
== SIGUSR2
)
1638 return TARGET_SIGNAL_USR2
;
1640 #if defined (SIGCLD)
1641 if (hostsig
== SIGCLD
)
1642 return TARGET_SIGNAL_CHLD
;
1644 #if defined (SIGCHLD)
1645 if (hostsig
== SIGCHLD
)
1646 return TARGET_SIGNAL_CHLD
;
1648 #if defined (SIGPWR)
1649 if (hostsig
== SIGPWR
)
1650 return TARGET_SIGNAL_PWR
;
1652 #if defined (SIGWINCH)
1653 if (hostsig
== SIGWINCH
)
1654 return TARGET_SIGNAL_WINCH
;
1656 #if defined (SIGURG)
1657 if (hostsig
== SIGURG
)
1658 return TARGET_SIGNAL_URG
;
1661 if (hostsig
== SIGIO
)
1662 return TARGET_SIGNAL_IO
;
1664 #if defined (SIGPOLL)
1665 if (hostsig
== SIGPOLL
)
1666 return TARGET_SIGNAL_POLL
;
1668 #if defined (SIGSTOP)
1669 if (hostsig
== SIGSTOP
)
1670 return TARGET_SIGNAL_STOP
;
1672 #if defined (SIGTSTP)
1673 if (hostsig
== SIGTSTP
)
1674 return TARGET_SIGNAL_TSTP
;
1676 #if defined (SIGCONT)
1677 if (hostsig
== SIGCONT
)
1678 return TARGET_SIGNAL_CONT
;
1680 #if defined (SIGTTIN)
1681 if (hostsig
== SIGTTIN
)
1682 return TARGET_SIGNAL_TTIN
;
1684 #if defined (SIGTTOU)
1685 if (hostsig
== SIGTTOU
)
1686 return TARGET_SIGNAL_TTOU
;
1688 #if defined (SIGVTALRM)
1689 if (hostsig
== SIGVTALRM
)
1690 return TARGET_SIGNAL_VTALRM
;
1692 #if defined (SIGPROF)
1693 if (hostsig
== SIGPROF
)
1694 return TARGET_SIGNAL_PROF
;
1696 #if defined (SIGXCPU)
1697 if (hostsig
== SIGXCPU
)
1698 return TARGET_SIGNAL_XCPU
;
1700 #if defined (SIGXFSZ)
1701 if (hostsig
== SIGXFSZ
)
1702 return TARGET_SIGNAL_XFSZ
;
1704 #if defined (SIGWIND)
1705 if (hostsig
== SIGWIND
)
1706 return TARGET_SIGNAL_WIND
;
1708 #if defined (SIGPHONE)
1709 if (hostsig
== SIGPHONE
)
1710 return TARGET_SIGNAL_PHONE
;
1712 #if defined (SIGLOST)
1713 if (hostsig
== SIGLOST
)
1714 return TARGET_SIGNAL_LOST
;
1716 #if defined (SIGWAITING)
1717 if (hostsig
== SIGWAITING
)
1718 return TARGET_SIGNAL_WAITING
;
1720 #if defined (SIGCANCEL)
1721 if (hostsig
== SIGCANCEL
)
1722 return TARGET_SIGNAL_CANCEL
;
1724 #if defined (SIGLWP)
1725 if (hostsig
== SIGLWP
)
1726 return TARGET_SIGNAL_LWP
;
1728 #if defined (SIGDANGER)
1729 if (hostsig
== SIGDANGER
)
1730 return TARGET_SIGNAL_DANGER
;
1732 #if defined (SIGGRANT)
1733 if (hostsig
== SIGGRANT
)
1734 return TARGET_SIGNAL_GRANT
;
1736 #if defined (SIGRETRACT)
1737 if (hostsig
== SIGRETRACT
)
1738 return TARGET_SIGNAL_RETRACT
;
1740 #if defined (SIGMSG)
1741 if (hostsig
== SIGMSG
)
1742 return TARGET_SIGNAL_MSG
;
1744 #if defined (SIGSOUND)
1745 if (hostsig
== SIGSOUND
)
1746 return TARGET_SIGNAL_SOUND
;
1748 #if defined (SIGSAK)
1749 if (hostsig
== SIGSAK
)
1750 return TARGET_SIGNAL_SAK
;
1752 #if defined (SIGPRIO)
1753 if (hostsig
== SIGPRIO
)
1754 return TARGET_SIGNAL_PRIO
;
1757 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1758 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1759 if (hostsig
== _NSIG
+ EXC_BAD_ACCESS
)
1760 return TARGET_EXC_BAD_ACCESS
;
1762 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1763 if (hostsig
== _NSIG
+ EXC_BAD_INSTRUCTION
)
1764 return TARGET_EXC_BAD_INSTRUCTION
;
1766 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1767 if (hostsig
== _NSIG
+ EXC_ARITHMETIC
)
1768 return TARGET_EXC_ARITHMETIC
;
1770 #if defined (EXC_EMULATION) && defined (_NSIG)
1771 if (hostsig
== _NSIG
+ EXC_EMULATION
)
1772 return TARGET_EXC_EMULATION
;
1774 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1775 if (hostsig
== _NSIG
+ EXC_SOFTWARE
)
1776 return TARGET_EXC_SOFTWARE
;
1778 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1779 if (hostsig
== _NSIG
+ EXC_BREAKPOINT
)
1780 return TARGET_EXC_BREAKPOINT
;
1783 #if defined (SIGINFO)
1784 if (hostsig
== SIGINFO
)
1785 return TARGET_SIGNAL_INFO
;
1788 #if defined (REALTIME_LO)
1789 if (hostsig
>= REALTIME_LO
&& hostsig
< REALTIME_HI
)
1791 /* This block of TARGET_SIGNAL_REALTIME value is in order. */
1792 if (33 <= hostsig
&& hostsig
<= 63)
1793 return (enum target_signal
)
1794 (hostsig
- 33 + (int) TARGET_SIGNAL_REALTIME_33
);
1795 else if (hostsig
== 32)
1796 return TARGET_SIGNAL_REALTIME_32
;
1798 error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
1802 #if defined (SIGRTMIN)
1803 if (hostsig
>= SIGRTMIN
&& hostsig
<= SIGRTMAX
)
1805 /* This block of TARGET_SIGNAL_REALTIME value is in order. */
1806 if (33 <= hostsig
&& hostsig
<= 63)
1807 return (enum target_signal
)
1808 (hostsig
- 33 + (int) TARGET_SIGNAL_REALTIME_33
);
1809 else if (hostsig
== 64)
1810 return TARGET_SIGNAL_REALTIME_64
;
1812 error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
1815 return TARGET_SIGNAL_UNKNOWN
;
1818 /* Convert a OURSIG (an enum target_signal) to the form used by the
1819 target operating system (refered to as the ``host'') or zero if the
1820 equivalent host signal is not available. Set/clear OURSIG_OK
1824 do_target_signal_to_host (enum target_signal oursig
,
1830 case TARGET_SIGNAL_0
:
1833 #if defined (SIGHUP)
1834 case TARGET_SIGNAL_HUP
:
1837 #if defined (SIGINT)
1838 case TARGET_SIGNAL_INT
:
1841 #if defined (SIGQUIT)
1842 case TARGET_SIGNAL_QUIT
:
1845 #if defined (SIGILL)
1846 case TARGET_SIGNAL_ILL
:
1849 #if defined (SIGTRAP)
1850 case TARGET_SIGNAL_TRAP
:
1853 #if defined (SIGABRT)
1854 case TARGET_SIGNAL_ABRT
:
1857 #if defined (SIGEMT)
1858 case TARGET_SIGNAL_EMT
:
1861 #if defined (SIGFPE)
1862 case TARGET_SIGNAL_FPE
:
1865 #if defined (SIGKILL)
1866 case TARGET_SIGNAL_KILL
:
1869 #if defined (SIGBUS)
1870 case TARGET_SIGNAL_BUS
:
1873 #if defined (SIGSEGV)
1874 case TARGET_SIGNAL_SEGV
:
1877 #if defined (SIGSYS)
1878 case TARGET_SIGNAL_SYS
:
1881 #if defined (SIGPIPE)
1882 case TARGET_SIGNAL_PIPE
:
1885 #if defined (SIGALRM)
1886 case TARGET_SIGNAL_ALRM
:
1889 #if defined (SIGTERM)
1890 case TARGET_SIGNAL_TERM
:
1893 #if defined (SIGUSR1)
1894 case TARGET_SIGNAL_USR1
:
1897 #if defined (SIGUSR2)
1898 case TARGET_SIGNAL_USR2
:
1901 #if defined (SIGCHLD) || defined (SIGCLD)
1902 case TARGET_SIGNAL_CHLD
:
1903 #if defined (SIGCHLD)
1908 #endif /* SIGCLD or SIGCHLD */
1909 #if defined (SIGPWR)
1910 case TARGET_SIGNAL_PWR
:
1913 #if defined (SIGWINCH)
1914 case TARGET_SIGNAL_WINCH
:
1917 #if defined (SIGURG)
1918 case TARGET_SIGNAL_URG
:
1922 case TARGET_SIGNAL_IO
:
1925 #if defined (SIGPOLL)
1926 case TARGET_SIGNAL_POLL
:
1929 #if defined (SIGSTOP)
1930 case TARGET_SIGNAL_STOP
:
1933 #if defined (SIGTSTP)
1934 case TARGET_SIGNAL_TSTP
:
1937 #if defined (SIGCONT)
1938 case TARGET_SIGNAL_CONT
:
1941 #if defined (SIGTTIN)
1942 case TARGET_SIGNAL_TTIN
:
1945 #if defined (SIGTTOU)
1946 case TARGET_SIGNAL_TTOU
:
1949 #if defined (SIGVTALRM)
1950 case TARGET_SIGNAL_VTALRM
:
1953 #if defined (SIGPROF)
1954 case TARGET_SIGNAL_PROF
:
1957 #if defined (SIGXCPU)
1958 case TARGET_SIGNAL_XCPU
:
1961 #if defined (SIGXFSZ)
1962 case TARGET_SIGNAL_XFSZ
:
1965 #if defined (SIGWIND)
1966 case TARGET_SIGNAL_WIND
:
1969 #if defined (SIGPHONE)
1970 case TARGET_SIGNAL_PHONE
:
1973 #if defined (SIGLOST)
1974 case TARGET_SIGNAL_LOST
:
1977 #if defined (SIGWAITING)
1978 case TARGET_SIGNAL_WAITING
:
1981 #if defined (SIGCANCEL)
1982 case TARGET_SIGNAL_CANCEL
:
1985 #if defined (SIGLWP)
1986 case TARGET_SIGNAL_LWP
:
1989 #if defined (SIGDANGER)
1990 case TARGET_SIGNAL_DANGER
:
1993 #if defined (SIGGRANT)
1994 case TARGET_SIGNAL_GRANT
:
1997 #if defined (SIGRETRACT)
1998 case TARGET_SIGNAL_RETRACT
:
2001 #if defined (SIGMSG)
2002 case TARGET_SIGNAL_MSG
:
2005 #if defined (SIGSOUND)
2006 case TARGET_SIGNAL_SOUND
:
2009 #if defined (SIGSAK)
2010 case TARGET_SIGNAL_SAK
:
2013 #if defined (SIGPRIO)
2014 case TARGET_SIGNAL_PRIO
:
2018 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
2019 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
2020 case TARGET_EXC_BAD_ACCESS
:
2021 return _NSIG
+ EXC_BAD_ACCESS
;
2023 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
2024 case TARGET_EXC_BAD_INSTRUCTION
:
2025 return _NSIG
+ EXC_BAD_INSTRUCTION
;
2027 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
2028 case TARGET_EXC_ARITHMETIC
:
2029 return _NSIG
+ EXC_ARITHMETIC
;
2031 #if defined (EXC_EMULATION) && defined (_NSIG)
2032 case TARGET_EXC_EMULATION
:
2033 return _NSIG
+ EXC_EMULATION
;
2035 #if defined (EXC_SOFTWARE) && defined (_NSIG)
2036 case TARGET_EXC_SOFTWARE
:
2037 return _NSIG
+ EXC_SOFTWARE
;
2039 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
2040 case TARGET_EXC_BREAKPOINT
:
2041 return _NSIG
+ EXC_BREAKPOINT
;
2044 #if defined (SIGINFO)
2045 case TARGET_SIGNAL_INFO
:
2050 #if defined (REALTIME_LO)
2051 if (oursig
>= TARGET_SIGNAL_REALTIME_33
2052 && oursig
<= TARGET_SIGNAL_REALTIME_63
)
2054 /* This block of signals is continuous, and
2055 TARGET_SIGNAL_REALTIME_33 is 33 by definition. */
2057 (int) oursig
- (int) TARGET_SIGNAL_REALTIME_33
+ 33;
2058 if (retsig
>= REALTIME_LO
&& retsig
< REALTIME_HI
)
2061 #if (REALTIME_LO < 33)
2062 else if (oursig
== TARGET_SIGNAL_REALTIME_32
)
2064 /* TARGET_SIGNAL_REALTIME_32 isn't contiguous with
2065 TARGET_SIGNAL_REALTIME_33. It is 32 by definition. */
2071 #if defined (SIGRTMIN)
2072 if (oursig
>= TARGET_SIGNAL_REALTIME_33
2073 && oursig
<= TARGET_SIGNAL_REALTIME_63
)
2075 /* This block of signals is continuous, and
2076 TARGET_SIGNAL_REALTIME_33 is 33 by definition. */
2078 (int) oursig
- (int) TARGET_SIGNAL_REALTIME_33
+ 33;
2079 if (retsig
>= SIGRTMIN
&& retsig
<= SIGRTMAX
)
2082 else if (oursig
== TARGET_SIGNAL_REALTIME_64
)
2091 target_signal_to_host_p (enum target_signal oursig
)
2094 do_target_signal_to_host (oursig
, &oursig_ok
);
2099 target_signal_to_host (enum target_signal oursig
)
2102 int targ_signo
= do_target_signal_to_host (oursig
, &oursig_ok
);
2105 /* The user might be trying to do "signal SIGSAK" where this system
2106 doesn't have SIGSAK. */
2107 warning ("Signal %s does not exist on this system.\n",
2108 target_signal_to_name (oursig
));
2115 /* Helper function for child_wait and the Lynx derivatives of child_wait.
2116 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
2117 translation of that in OURSTATUS. */
2119 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
2121 #ifdef CHILD_SPECIAL_WAITSTATUS
2122 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
2123 if it wants to deal with hoststatus. */
2124 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
2128 if (WIFEXITED (hoststatus
))
2130 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
2131 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
2133 else if (!WIFSTOPPED (hoststatus
))
2135 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
2136 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
2140 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
2141 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
2145 /* In some circumstances we allow a command to specify a numeric
2146 signal. The idea is to keep these circumstances limited so that
2147 users (and scripts) develop portable habits. For comparison,
2148 POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
2149 numeric signal at all is obsolescent. We are slightly more
2150 lenient and allow 1-15 which should match host signal numbers on
2151 most systems. Use of symbolic signal names is strongly encouraged. */
2154 target_signal_from_command (int num
)
2156 if (num
>= 1 && num
<= 15)
2157 return (enum target_signal
) num
;
2158 error ("Only signals 1-15 are valid as numeric signals.\n\
2159 Use \"info signals\" for a list of symbolic signals.");
2162 /* Returns zero to leave the inferior alone, one to interrupt it. */
2163 int (*target_activity_function
) (void);
2164 int target_activity_fd
;
2166 /* Convert a normal process ID to a string. Returns the string in a static
2170 normal_pid_to_str (int pid
)
2172 static char buf
[30];
2174 if (STREQ (current_target
.to_shortname
, "remote"))
2175 sprintf (buf
, "thread %d", pid
);
2177 sprintf (buf
, "process %d", pid
);
2182 /* Some targets (such as ttrace-based HPUX) don't allow us to request
2183 notification of inferior events such as fork and vork immediately
2184 after the inferior is created. (This because of how gdb gets an
2185 inferior created via invoking a shell to do it. In such a scenario,
2186 if the shell init file has commands in it, the shell will fork and
2187 exec for each of those commands, and we will see each such fork
2190 This function is used by all targets that allow us to request
2191 notification of forks, etc at inferior creation time; e.g., in
2192 target_acknowledge_forked_child.
2195 normal_target_post_startup_inferior (int pid
)
2197 /* This space intentionally left blank. */
2200 /* Set up the handful of non-empty slots needed by the dummy target
2204 init_dummy_target (void)
2206 dummy_target
.to_shortname
= "None";
2207 dummy_target
.to_longname
= "None";
2208 dummy_target
.to_doc
= "";
2209 dummy_target
.to_attach
= find_default_attach
;
2210 dummy_target
.to_require_attach
= find_default_require_attach
;
2211 dummy_target
.to_require_detach
= find_default_require_detach
;
2212 dummy_target
.to_create_inferior
= find_default_create_inferior
;
2213 dummy_target
.to_clone_and_follow_inferior
= find_default_clone_and_follow_inferior
;
2214 dummy_target
.to_pid_to_str
= normal_pid_to_str
;
2215 dummy_target
.to_stratum
= dummy_stratum
;
2216 dummy_target
.to_magic
= OPS_MAGIC
;
2220 static struct target_ops debug_target
;
2223 debug_to_open (char *args
, int from_tty
)
2225 debug_target
.to_open (args
, from_tty
);
2227 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
2231 debug_to_close (int quitting
)
2233 debug_target
.to_close (quitting
);
2235 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
2239 debug_to_attach (char *args
, int from_tty
)
2241 debug_target
.to_attach (args
, from_tty
);
2243 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
2248 debug_to_post_attach (int pid
)
2250 debug_target
.to_post_attach (pid
);
2252 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
2256 debug_to_require_attach (char *args
, int from_tty
)
2258 debug_target
.to_require_attach (args
, from_tty
);
2260 fprintf_unfiltered (gdb_stdlog
,
2261 "target_require_attach (%s, %d)\n", args
, from_tty
);
2265 debug_to_detach (char *args
, int from_tty
)
2267 debug_target
.to_detach (args
, from_tty
);
2269 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
2273 debug_to_require_detach (int pid
, char *args
, int from_tty
)
2275 debug_target
.to_require_detach (pid
, args
, from_tty
);
2277 fprintf_unfiltered (gdb_stdlog
,
2278 "target_require_detach (%d, %s, %d)\n", pid
, args
, from_tty
);
2282 debug_to_resume (int pid
, int step
, enum target_signal siggnal
)
2284 debug_target
.to_resume (pid
, step
, siggnal
);
2286 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", pid
,
2287 step
? "step" : "continue",
2288 target_signal_to_name (siggnal
));
2292 debug_to_wait (int pid
, struct target_waitstatus
*status
)
2296 retval
= debug_target
.to_wait (pid
, status
);
2298 fprintf_unfiltered (gdb_stdlog
,
2299 "target_wait (%d, status) = %d, ", pid
, retval
);
2300 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
2301 switch (status
->kind
)
2303 case TARGET_WAITKIND_EXITED
:
2304 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
2305 status
->value
.integer
);
2307 case TARGET_WAITKIND_STOPPED
:
2308 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
2309 target_signal_to_name (status
->value
.sig
));
2311 case TARGET_WAITKIND_SIGNALLED
:
2312 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
2313 target_signal_to_name (status
->value
.sig
));
2315 case TARGET_WAITKIND_LOADED
:
2316 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
2318 case TARGET_WAITKIND_FORKED
:
2319 fprintf_unfiltered (gdb_stdlog
, "forked\n");
2321 case TARGET_WAITKIND_VFORKED
:
2322 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
2324 case TARGET_WAITKIND_EXECD
:
2325 fprintf_unfiltered (gdb_stdlog
, "execd\n");
2327 case TARGET_WAITKIND_SPURIOUS
:
2328 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
2331 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
2339 debug_to_post_wait (int pid
, int status
)
2341 debug_target
.to_post_wait (pid
, status
);
2343 fprintf_unfiltered (gdb_stdlog
, "target_post_wait (%d, %d)\n",
2348 debug_to_fetch_registers (int regno
)
2350 debug_target
.to_fetch_registers (regno
);
2352 fprintf_unfiltered (gdb_stdlog
, "target_fetch_registers (%s)",
2353 regno
!= -1 ? REGISTER_NAME (regno
) : "-1");
2355 fprintf_unfiltered (gdb_stdlog
, " = 0x%lx %ld",
2356 (unsigned long) read_register (regno
),
2357 (unsigned long) read_register (regno
));
2358 fprintf_unfiltered (gdb_stdlog
, "\n");
2362 debug_to_store_registers (int regno
)
2364 debug_target
.to_store_registers (regno
);
2366 if (regno
>= 0 && regno
< NUM_REGS
)
2367 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%s) = 0x%lx %ld\n",
2368 REGISTER_NAME (regno
),
2369 (unsigned long) read_register (regno
),
2370 (unsigned long) read_register (regno
));
2372 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%d)\n", regno
);
2376 debug_to_prepare_to_store (void)
2378 debug_target
.to_prepare_to_store ();
2380 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
2384 debug_to_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
2385 struct mem_attrib
*attrib
,
2386 struct target_ops
*target
)
2390 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
,
2393 fprintf_unfiltered (gdb_stdlog
,
2394 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
2395 (unsigned int) memaddr
, /* possable truncate long long */
2396 len
, write
? "write" : "read", retval
);
2404 fputs_unfiltered (", bytes =", gdb_stdlog
);
2405 for (i
= 0; i
< retval
; i
++)
2407 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
2408 fprintf_unfiltered (gdb_stdlog
, "\n");
2409 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
2413 fputc_unfiltered ('\n', gdb_stdlog
);
2419 debug_to_files_info (struct target_ops
*target
)
2421 debug_target
.to_files_info (target
);
2423 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
2427 debug_to_insert_breakpoint (CORE_ADDR addr
, char *save
)
2431 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
2433 fprintf_unfiltered (gdb_stdlog
,
2434 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
2435 (unsigned long) addr
,
2436 (unsigned long) retval
);
2441 debug_to_remove_breakpoint (CORE_ADDR addr
, char *save
)
2445 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
2447 fprintf_unfiltered (gdb_stdlog
,
2448 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
2449 (unsigned long) addr
,
2450 (unsigned long) retval
);
2455 debug_to_terminal_init (void)
2457 debug_target
.to_terminal_init ();
2459 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
2463 debug_to_terminal_inferior (void)
2465 debug_target
.to_terminal_inferior ();
2467 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
2471 debug_to_terminal_ours_for_output (void)
2473 debug_target
.to_terminal_ours_for_output ();
2475 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
2479 debug_to_terminal_ours (void)
2481 debug_target
.to_terminal_ours ();
2483 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
2487 debug_to_terminal_info (char *arg
, int from_tty
)
2489 debug_target
.to_terminal_info (arg
, from_tty
);
2491 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
2496 debug_to_kill (void)
2498 debug_target
.to_kill ();
2500 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
2504 debug_to_load (char *args
, int from_tty
)
2506 debug_target
.to_load (args
, from_tty
);
2508 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
2512 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
2516 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
2518 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
2524 debug_to_create_inferior (char *exec_file
, char *args
, char **env
)
2526 debug_target
.to_create_inferior (exec_file
, args
, env
);
2528 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx)\n",
2533 debug_to_post_startup_inferior (int pid
)
2535 debug_target
.to_post_startup_inferior (pid
);
2537 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
2542 debug_to_acknowledge_created_inferior (int pid
)
2544 debug_target
.to_acknowledge_created_inferior (pid
);
2546 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
2551 debug_to_clone_and_follow_inferior (int child_pid
, int *followed_child
)
2553 debug_target
.to_clone_and_follow_inferior (child_pid
, followed_child
);
2555 fprintf_unfiltered (gdb_stdlog
,
2556 "target_clone_and_follow_inferior (%d, %d)\n",
2557 child_pid
, *followed_child
);
2561 debug_to_post_follow_inferior_by_clone (void)
2563 debug_target
.to_post_follow_inferior_by_clone ();
2565 fprintf_unfiltered (gdb_stdlog
, "target_post_follow_inferior_by_clone ()\n");
2569 debug_to_insert_fork_catchpoint (int pid
)
2573 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
2575 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
2582 debug_to_remove_fork_catchpoint (int pid
)
2586 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
2588 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
2595 debug_to_insert_vfork_catchpoint (int pid
)
2599 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
2601 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)= %d\n",
2608 debug_to_remove_vfork_catchpoint (int pid
)
2612 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
2614 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
2621 debug_to_has_forked (int pid
, int *child_pid
)
2625 has_forked
= debug_target
.to_has_forked (pid
, child_pid
);
2627 fprintf_unfiltered (gdb_stdlog
, "target_has_forked (%d, %d) = %d\n",
2628 pid
, *child_pid
, has_forked
);
2634 debug_to_has_vforked (int pid
, int *child_pid
)
2638 has_vforked
= debug_target
.to_has_vforked (pid
, child_pid
);
2640 fprintf_unfiltered (gdb_stdlog
, "target_has_vforked (%d, %d) = %d\n",
2641 pid
, *child_pid
, has_vforked
);
2647 debug_to_can_follow_vfork_prior_to_exec (void)
2649 int can_immediately_follow_vfork
;
2651 can_immediately_follow_vfork
= debug_target
.to_can_follow_vfork_prior_to_exec ();
2653 fprintf_unfiltered (gdb_stdlog
, "target_can_follow_vfork_prior_to_exec () = %d\n",
2654 can_immediately_follow_vfork
);
2656 return can_immediately_follow_vfork
;
2660 debug_to_post_follow_vfork (int parent_pid
, int followed_parent
, int child_pid
,
2663 debug_target
.to_post_follow_vfork (parent_pid
, followed_parent
, child_pid
, followed_child
);
2665 fprintf_unfiltered (gdb_stdlog
,
2666 "target_post_follow_vfork (%d, %d, %d, %d)\n",
2667 parent_pid
, followed_parent
, child_pid
, followed_child
);
2671 debug_to_insert_exec_catchpoint (int pid
)
2675 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
2677 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
2684 debug_to_remove_exec_catchpoint (int pid
)
2688 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
2690 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2697 debug_to_has_execd (int pid
, char **execd_pathname
)
2701 has_execd
= debug_target
.to_has_execd (pid
, execd_pathname
);
2703 fprintf_unfiltered (gdb_stdlog
, "target_has_execd (%d, %s) = %d\n",
2704 pid
, (*execd_pathname
? *execd_pathname
: "<NULL>"),
2711 debug_to_reported_exec_events_per_exec_call (void)
2713 int reported_exec_events
;
2715 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2717 fprintf_unfiltered (gdb_stdlog
,
2718 "target_reported_exec_events_per_exec_call () = %d\n",
2719 reported_exec_events
);
2721 return reported_exec_events
;
2725 debug_to_has_syscall_event (int pid
, enum target_waitkind
*kind
,
2728 int has_syscall_event
;
2729 char *kind_spelling
= "??";
2731 has_syscall_event
= debug_target
.to_has_syscall_event (pid
, kind
, syscall_id
);
2732 if (has_syscall_event
)
2736 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2737 kind_spelling
= "SYSCALL_ENTRY";
2739 case TARGET_WAITKIND_SYSCALL_RETURN
:
2740 kind_spelling
= "SYSCALL_RETURN";
2747 fprintf_unfiltered (gdb_stdlog
,
2748 "target_has_syscall_event (%d, %s, %d) = %d\n",
2749 pid
, kind_spelling
, *syscall_id
, has_syscall_event
);
2751 return has_syscall_event
;
2755 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
2759 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2761 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2762 pid
, wait_status
, *exit_status
, has_exited
);
2768 debug_to_mourn_inferior (void)
2770 debug_target
.to_mourn_inferior ();
2772 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2776 debug_to_can_run (void)
2780 retval
= debug_target
.to_can_run ();
2782 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2788 debug_to_notice_signals (int pid
)
2790 debug_target
.to_notice_signals (pid
);
2792 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n", pid
);
2796 debug_to_thread_alive (int pid
)
2800 retval
= debug_target
.to_thread_alive (pid
);
2802 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2809 debug_to_find_new_threads (void)
2811 debug_target
.to_find_new_threads ();
2813 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog
);
2817 debug_to_stop (void)
2819 debug_target
.to_stop ();
2821 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2825 debug_to_query (int type
, char *req
, char *resp
, int *siz
)
2829 retval
= debug_target
.to_query (type
, req
, resp
, siz
);
2831 fprintf_unfiltered (gdb_stdlog
, "target_query (%c, %s, %s, %d) = %d\n", type
, req
, resp
, *siz
, retval
);
2837 debug_to_rcmd (char *command
,
2838 struct ui_file
*outbuf
)
2840 debug_target
.to_rcmd (command
, outbuf
);
2841 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2844 static struct symtab_and_line
*
2845 debug_to_enable_exception_callback (enum exception_event_kind kind
, int enable
)
2847 struct symtab_and_line
*result
;
2848 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2849 fprintf_unfiltered (gdb_stdlog
,
2850 "target get_exception_callback_sal (%d, %d)\n",
2855 static struct exception_event_record
*
2856 debug_to_get_current_exception_event (void)
2858 struct exception_event_record
*result
;
2859 result
= debug_target
.to_get_current_exception_event ();
2860 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2865 debug_to_pid_to_exec_file (int pid
)
2869 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2871 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2878 debug_to_core_file_to_sym_file (char *core
)
2882 sym_file
= debug_target
.to_core_file_to_sym_file (core
);
2884 fprintf_unfiltered (gdb_stdlog
, "target_core_file_to_sym_file (%s) = %s\n",
2891 setup_target_debug (void)
2893 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2895 current_target
.to_open
= debug_to_open
;
2896 current_target
.to_close
= debug_to_close
;
2897 current_target
.to_attach
= debug_to_attach
;
2898 current_target
.to_post_attach
= debug_to_post_attach
;
2899 current_target
.to_require_attach
= debug_to_require_attach
;
2900 current_target
.to_detach
= debug_to_detach
;
2901 current_target
.to_require_detach
= debug_to_require_detach
;
2902 current_target
.to_resume
= debug_to_resume
;
2903 current_target
.to_wait
= debug_to_wait
;
2904 current_target
.to_post_wait
= debug_to_post_wait
;
2905 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2906 current_target
.to_store_registers
= debug_to_store_registers
;
2907 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2908 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2909 current_target
.to_files_info
= debug_to_files_info
;
2910 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2911 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2912 current_target
.to_terminal_init
= debug_to_terminal_init
;
2913 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2914 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2915 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2916 current_target
.to_terminal_info
= debug_to_terminal_info
;
2917 current_target
.to_kill
= debug_to_kill
;
2918 current_target
.to_load
= debug_to_load
;
2919 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2920 current_target
.to_create_inferior
= debug_to_create_inferior
;
2921 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2922 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2923 current_target
.to_clone_and_follow_inferior
= debug_to_clone_and_follow_inferior
;
2924 current_target
.to_post_follow_inferior_by_clone
= debug_to_post_follow_inferior_by_clone
;
2925 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2926 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2927 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2928 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2929 current_target
.to_has_forked
= debug_to_has_forked
;
2930 current_target
.to_has_vforked
= debug_to_has_vforked
;
2931 current_target
.to_can_follow_vfork_prior_to_exec
= debug_to_can_follow_vfork_prior_to_exec
;
2932 current_target
.to_post_follow_vfork
= debug_to_post_follow_vfork
;
2933 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2934 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2935 current_target
.to_has_execd
= debug_to_has_execd
;
2936 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2937 current_target
.to_has_syscall_event
= debug_to_has_syscall_event
;
2938 current_target
.to_has_exited
= debug_to_has_exited
;
2939 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2940 current_target
.to_can_run
= debug_to_can_run
;
2941 current_target
.to_notice_signals
= debug_to_notice_signals
;
2942 current_target
.to_thread_alive
= debug_to_thread_alive
;
2943 current_target
.to_find_new_threads
= debug_to_find_new_threads
;
2944 current_target
.to_stop
= debug_to_stop
;
2945 current_target
.to_query
= debug_to_query
;
2946 current_target
.to_rcmd
= debug_to_rcmd
;
2947 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
2948 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
2949 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2950 current_target
.to_core_file_to_sym_file
= debug_to_core_file_to_sym_file
;
2955 static char targ_desc
[] =
2956 "Names of targets and files being debugged.\n\
2957 Shows the entire stack of targets currently in use (including the exec-file,\n\
2958 core-file, and process, if any), as well as the symbol file name.";
2961 do_monitor_command (char *cmd
,
2964 if ((current_target
.to_rcmd
2965 == (void (*) (char *, struct ui_file
*)) tcomplain
)
2966 || (current_target
.to_rcmd
== debug_to_rcmd
2967 && (debug_target
.to_rcmd
2968 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
2970 error ("\"monitor\" command not supported by this target.\n");
2972 target_rcmd (cmd
, gdb_stdtarg
);
2976 initialize_targets (void)
2978 init_dummy_target ();
2979 push_target (&dummy_target
);
2981 add_info ("target", target_info
, targ_desc
);
2982 add_info ("files", target_info
, targ_desc
);
2985 add_set_cmd ("target", class_maintenance
, var_zinteger
,
2986 (char *) &targetdebug
,
2987 "Set target debugging.\n\
2988 When non-zero, target debugging is enabled.", &setdebuglist
),
2992 add_com ("monitor", class_obscure
, do_monitor_command
,
2993 "Send a command to the remote monitor (remote targets only).");
2995 target_dcache
= dcache_init();
2997 if (!STREQ (signals
[TARGET_SIGNAL_LAST
].string
, "TARGET_SIGNAL_MAGIC"))
2998 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");