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. */
25 #include "gdb_string.h"
40 static void target_info (char *, int);
42 static void cleanup_target (struct target_ops
*);
44 static void maybe_kill_then_create_inferior (char *, char *, char **);
46 static void default_clone_and_follow_inferior (int, int *);
48 static void maybe_kill_then_attach (char *, int);
50 static void kill_or_be_killed (int);
52 static void default_terminal_info (char *, int);
54 static int nosymbol (char *, CORE_ADDR
*);
56 static void tcomplain (void);
58 static int nomemory (CORE_ADDR
, char *, int, int, struct target_ops
*);
60 static int return_zero (void);
62 static int return_one (void);
64 void target_ignore (void);
66 static void target_command (char *, int);
68 static struct target_ops
*find_default_run_target (char *);
70 static void update_current_target (void);
72 static void nosupport_runtime (void);
74 static void normal_target_post_startup_inferior (ptid_t ptid
);
76 /* Transfer LEN bytes between target address MEMADDR and GDB address
77 MYADDR. Returns 0 for success, errno code for failure (which
78 includes partial transfers -- if you want a more useful response to
79 partial transfers, try either target_read_memory_partial or
80 target_write_memory_partial). */
83 target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
);
85 static void init_dummy_target (void);
87 static void debug_to_open (char *, int);
89 static void debug_to_close (int);
91 static void debug_to_attach (char *, int);
93 static void debug_to_detach (char *, int);
95 static void debug_to_resume (ptid_t
, int, enum target_signal
);
97 static ptid_t
debug_to_wait (ptid_t
, struct target_waitstatus
*);
99 static void debug_to_fetch_registers (int);
101 static void debug_to_store_registers (int);
103 static void debug_to_prepare_to_store (void);
106 debug_to_xfer_memory (CORE_ADDR
, char *, int, int, struct mem_attrib
*,
107 struct target_ops
*);
109 static void debug_to_files_info (struct target_ops
*);
111 static int debug_to_insert_breakpoint (CORE_ADDR
, char *);
113 static int debug_to_remove_breakpoint (CORE_ADDR
, char *);
115 static void debug_to_terminal_init (void);
117 static void debug_to_terminal_inferior (void);
119 static void debug_to_terminal_ours_for_output (void);
121 static void debug_to_terminal_ours (void);
123 static void debug_to_terminal_info (char *, int);
125 static void debug_to_kill (void);
127 static void debug_to_load (char *, int);
129 static int debug_to_lookup_symbol (char *, CORE_ADDR
*);
131 static void debug_to_create_inferior (char *, char *, char **);
133 static void debug_to_mourn_inferior (void);
135 static int debug_to_can_run (void);
137 static void debug_to_notice_signals (ptid_t
);
139 static int debug_to_thread_alive (ptid_t
);
141 static void debug_to_stop (void);
143 static int debug_to_query (int /*char */ , char *, char *, int *);
145 /* Pointer to array of target architecture structures; the size of the
146 array; the current index into the array; the allocated size of the
148 struct target_ops
**target_structs
;
149 unsigned target_struct_size
;
150 unsigned target_struct_index
;
151 unsigned target_struct_allocsize
;
152 #define DEFAULT_ALLOCSIZE 10
154 /* The initial current target, so that there is always a semi-valid
157 static struct target_ops dummy_target
;
159 /* Top of target stack. */
161 struct target_stack_item
*target_stack
;
163 /* The target structure we are currently using to talk to a process
164 or file or whatever "inferior" we have. */
166 struct target_ops current_target
;
168 /* Command list for target. */
170 static struct cmd_list_element
*targetlist
= NULL
;
172 /* Nonzero if we are debugging an attached outside process
173 rather than an inferior. */
177 /* Non-zero if we want to see trace of target level stuff. */
179 static int targetdebug
= 0;
181 static void setup_target_debug (void);
183 DCACHE
*target_dcache
;
185 /* The user just typed 'target' without the name of a target. */
189 target_command (char *arg
, int from_tty
)
191 fputs_filtered ("Argument required (target name). Try `help target'\n",
195 /* Add a possible target architecture to the list. */
198 add_target (struct target_ops
*t
)
202 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
203 target_structs
= (struct target_ops
**) xmalloc
204 (target_struct_allocsize
* sizeof (*target_structs
));
206 if (target_struct_size
>= target_struct_allocsize
)
208 target_struct_allocsize
*= 2;
209 target_structs
= (struct target_ops
**)
210 xrealloc ((char *) target_structs
,
211 target_struct_allocsize
* sizeof (*target_structs
));
213 target_structs
[target_struct_size
++] = t
;
214 /* cleanup_target (t); */
216 if (targetlist
== NULL
)
217 add_prefix_cmd ("target", class_run
, target_command
,
218 "Connect to a target machine or process.\n\
219 The first argument is the type or protocol of the target machine.\n\
220 Remaining arguments are interpreted by the target protocol. For more\n\
221 information on the arguments for a particular protocol, type\n\
222 `help target ' followed by the protocol name.",
223 &targetlist
, "target ", 0, &cmdlist
);
224 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
235 target_load (char *arg
, int from_tty
)
237 dcache_invalidate (target_dcache
);
238 (*current_target
.to_load
) (arg
, from_tty
);
243 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
244 struct target_ops
*t
)
246 errno
= EIO
; /* Can't read/write this location */
247 return 0; /* No bytes handled */
253 error ("You can't do that when your target is `%s'",
254 current_target
.to_shortname
);
260 error ("You can't do that without a process to debug.");
265 nosymbol (char *name
, CORE_ADDR
*addrp
)
267 return 1; /* Symbol does not exist in target env */
272 nosupport_runtime (void)
274 if (ptid_equal (inferior_ptid
, null_ptid
))
277 error ("No run-time support for this");
283 default_terminal_info (char *args
, int from_tty
)
285 printf_unfiltered ("No saved terminal information.\n");
288 /* This is the default target_create_inferior and target_attach function.
289 If the current target is executing, it asks whether to kill it off.
290 If this function returns without calling error(), it has killed off
291 the target, and the operation should be attempted. */
294 kill_or_be_killed (int from_tty
)
296 if (target_has_execution
)
298 printf_unfiltered ("You are already running a program:\n");
299 target_files_info ();
300 if (query ("Kill it? "))
303 if (target_has_execution
)
304 error ("Killing the program did not help.");
309 error ("Program not killed.");
316 maybe_kill_then_attach (char *args
, int from_tty
)
318 kill_or_be_killed (from_tty
);
319 target_attach (args
, from_tty
);
323 maybe_kill_then_create_inferior (char *exec
, char *args
, char **env
)
325 kill_or_be_killed (0);
326 target_create_inferior (exec
, args
, env
);
330 default_clone_and_follow_inferior (int child_pid
, int *followed_child
)
332 target_clone_and_follow_inferior (child_pid
, followed_child
);
335 /* Clean up a target struct so it no longer has any zero pointers in it.
336 We default entries, at least to stubs that print error messages. */
339 cleanup_target (struct target_ops
*t
)
342 #define de_fault(field, value) \
347 (void (*) (char *, int))
353 maybe_kill_then_attach
);
354 de_fault (to_post_attach
,
357 de_fault (to_require_attach
,
358 maybe_kill_then_attach
);
360 (void (*) (char *, int))
362 de_fault (to_require_detach
,
363 (void (*) (int, char *, int))
366 (void (*) (ptid_t
, int, enum target_signal
))
369 (ptid_t (*) (ptid_t
, struct target_waitstatus
*))
371 de_fault (to_post_wait
,
372 (void (*) (ptid_t
, int))
374 de_fault (to_fetch_registers
,
377 de_fault (to_store_registers
,
380 de_fault (to_prepare_to_store
,
383 de_fault (to_xfer_memory
,
384 (int (*) (CORE_ADDR
, char *, int, int, struct mem_attrib
*, struct target_ops
*))
386 de_fault (to_files_info
,
387 (void (*) (struct target_ops
*))
389 de_fault (to_insert_breakpoint
,
390 memory_insert_breakpoint
);
391 de_fault (to_remove_breakpoint
,
392 memory_remove_breakpoint
);
393 de_fault (to_terminal_init
,
396 de_fault (to_terminal_inferior
,
399 de_fault (to_terminal_ours_for_output
,
402 de_fault (to_terminal_ours
,
405 de_fault (to_terminal_info
,
406 default_terminal_info
);
411 (void (*) (char *, int))
413 de_fault (to_lookup_symbol
,
414 (int (*) (char *, CORE_ADDR
*))
416 de_fault (to_create_inferior
,
417 maybe_kill_then_create_inferior
);
418 de_fault (to_post_startup_inferior
,
421 de_fault (to_acknowledge_created_inferior
,
424 de_fault (to_clone_and_follow_inferior
,
425 default_clone_and_follow_inferior
);
426 de_fault (to_post_follow_inferior_by_clone
,
429 de_fault (to_insert_fork_catchpoint
,
432 de_fault (to_remove_fork_catchpoint
,
435 de_fault (to_insert_vfork_catchpoint
,
438 de_fault (to_remove_vfork_catchpoint
,
441 de_fault (to_has_forked
,
442 (int (*) (int, int *))
444 de_fault (to_has_vforked
,
445 (int (*) (int, int *))
447 de_fault (to_can_follow_vfork_prior_to_exec
,
450 de_fault (to_post_follow_vfork
,
451 (void (*) (int, int, int, int))
453 de_fault (to_insert_exec_catchpoint
,
456 de_fault (to_remove_exec_catchpoint
,
459 de_fault (to_has_execd
,
460 (int (*) (int, char **))
462 de_fault (to_reported_exec_events_per_exec_call
,
465 de_fault (to_has_syscall_event
,
466 (int (*) (int, enum target_waitkind
*, int *))
468 de_fault (to_has_exited
,
469 (int (*) (int, int, int *))
471 de_fault (to_mourn_inferior
,
474 de_fault (to_can_run
,
476 de_fault (to_notice_signals
,
479 de_fault (to_thread_alive
,
482 de_fault (to_find_new_threads
,
485 de_fault (to_extra_thread_info
,
486 (char *(*) (struct thread_info
*))
492 (int (*) (int, char *, char *, int *))
495 (void (*) (char *, struct ui_file
*))
497 de_fault (to_enable_exception_callback
,
498 (struct symtab_and_line
* (*) (enum exception_event_kind
, int))
500 de_fault (to_get_current_exception_event
,
501 (struct exception_event_record
* (*) (void))
503 de_fault (to_pid_to_exec_file
,
506 de_fault (to_can_async_p
,
509 de_fault (to_is_async_p
,
513 (void (*) (void (*) (enum inferior_event_type
, void*), void*))
518 /* Go through the target stack from top to bottom, copying over zero entries in
519 current_target. In effect, we are doing class inheritance through the
520 pushed target vectors. */
523 update_current_target (void)
525 struct target_stack_item
*item
;
526 struct target_ops
*t
;
528 /* First, reset current_target */
529 memset (¤t_target
, 0, sizeof current_target
);
531 for (item
= target_stack
; item
; item
= item
->next
)
533 t
= item
->target_ops
;
535 #define INHERIT(FIELD, TARGET) \
536 if (!current_target.FIELD) \
537 current_target.FIELD = TARGET->FIELD
539 INHERIT (to_shortname
, t
);
540 INHERIT (to_longname
, t
);
542 INHERIT (to_open
, t
);
543 INHERIT (to_close
, t
);
544 INHERIT (to_attach
, t
);
545 INHERIT (to_post_attach
, t
);
546 INHERIT (to_require_attach
, t
);
547 INHERIT (to_detach
, t
);
548 INHERIT (to_require_detach
, t
);
549 INHERIT (to_resume
, t
);
550 INHERIT (to_wait
, t
);
551 INHERIT (to_post_wait
, t
);
552 INHERIT (to_fetch_registers
, t
);
553 INHERIT (to_store_registers
, t
);
554 INHERIT (to_prepare_to_store
, t
);
555 INHERIT (to_xfer_memory
, t
);
556 INHERIT (to_files_info
, t
);
557 INHERIT (to_insert_breakpoint
, t
);
558 INHERIT (to_remove_breakpoint
, t
);
559 INHERIT (to_terminal_init
, t
);
560 INHERIT (to_terminal_inferior
, t
);
561 INHERIT (to_terminal_ours_for_output
, t
);
562 INHERIT (to_terminal_ours
, t
);
563 INHERIT (to_terminal_info
, t
);
564 INHERIT (to_kill
, t
);
565 INHERIT (to_load
, t
);
566 INHERIT (to_lookup_symbol
, t
);
567 INHERIT (to_create_inferior
, t
);
568 INHERIT (to_post_startup_inferior
, t
);
569 INHERIT (to_acknowledge_created_inferior
, t
);
570 INHERIT (to_clone_and_follow_inferior
, t
);
571 INHERIT (to_post_follow_inferior_by_clone
, t
);
572 INHERIT (to_insert_fork_catchpoint
, t
);
573 INHERIT (to_remove_fork_catchpoint
, t
);
574 INHERIT (to_insert_vfork_catchpoint
, t
);
575 INHERIT (to_remove_vfork_catchpoint
, t
);
576 INHERIT (to_has_forked
, t
);
577 INHERIT (to_has_vforked
, t
);
578 INHERIT (to_can_follow_vfork_prior_to_exec
, t
);
579 INHERIT (to_post_follow_vfork
, t
);
580 INHERIT (to_insert_exec_catchpoint
, t
);
581 INHERIT (to_remove_exec_catchpoint
, t
);
582 INHERIT (to_has_execd
, t
);
583 INHERIT (to_reported_exec_events_per_exec_call
, t
);
584 INHERIT (to_has_syscall_event
, t
);
585 INHERIT (to_has_exited
, t
);
586 INHERIT (to_mourn_inferior
, t
);
587 INHERIT (to_can_run
, t
);
588 INHERIT (to_notice_signals
, t
);
589 INHERIT (to_thread_alive
, t
);
590 INHERIT (to_find_new_threads
, t
);
591 INHERIT (to_pid_to_str
, t
);
592 INHERIT (to_extra_thread_info
, t
);
593 INHERIT (to_stop
, t
);
594 INHERIT (to_query
, t
);
595 INHERIT (to_rcmd
, t
);
596 INHERIT (to_enable_exception_callback
, t
);
597 INHERIT (to_get_current_exception_event
, t
);
598 INHERIT (to_pid_to_exec_file
, t
);
599 INHERIT (to_stratum
, t
);
600 INHERIT (DONT_USE
, t
);
601 INHERIT (to_has_all_memory
, t
);
602 INHERIT (to_has_memory
, t
);
603 INHERIT (to_has_stack
, t
);
604 INHERIT (to_has_registers
, t
);
605 INHERIT (to_has_execution
, t
);
606 INHERIT (to_has_thread_control
, t
);
607 INHERIT (to_sections
, t
);
608 INHERIT (to_sections_end
, t
);
609 INHERIT (to_can_async_p
, t
);
610 INHERIT (to_is_async_p
, t
);
611 INHERIT (to_async
, t
);
612 INHERIT (to_async_mask_value
, t
);
613 INHERIT (to_magic
, t
);
619 /* Push a new target type into the stack of the existing target accessors,
620 possibly superseding some of the existing accessors.
622 Result is zero if the pushed target ended up on top of the stack,
623 nonzero if at least one target is on top of it.
625 Rather than allow an empty stack, we always have the dummy target at
626 the bottom stratum, so we can call the function vectors without
630 push_target (struct target_ops
*t
)
632 struct target_stack_item
*cur
, *prev
, *tmp
;
634 /* Check magic number. If wrong, it probably means someone changed
635 the struct definition, but not all the places that initialize one. */
636 if (t
->to_magic
!= OPS_MAGIC
)
638 fprintf_unfiltered (gdb_stderr
,
639 "Magic number of %s target struct wrong\n",
641 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
644 /* Find the proper stratum to install this target in. */
646 for (prev
= NULL
, cur
= target_stack
; cur
; prev
= cur
, cur
= cur
->next
)
648 if ((int) (t
->to_stratum
) >= (int) (cur
->target_ops
->to_stratum
))
652 /* If there's already targets at this stratum, remove them. */
655 while (t
->to_stratum
== cur
->target_ops
->to_stratum
)
657 /* There's already something on this stratum. Close it off. */
658 if (cur
->target_ops
->to_close
)
659 (cur
->target_ops
->to_close
) (0);
661 prev
->next
= cur
->next
; /* Unchain old target_ops */
663 target_stack
= cur
->next
; /* Unchain first on list */
669 /* We have removed all targets in our stratum, now add the new one. */
671 tmp
= (struct target_stack_item
*)
672 xmalloc (sizeof (struct target_stack_item
));
681 update_current_target ();
683 cleanup_target (¤t_target
); /* Fill in the gaps */
686 setup_target_debug ();
691 /* Remove a target_ops vector from the stack, wherever it may be.
692 Return how many times it was removed (0 or 1). */
695 unpush_target (struct target_ops
*t
)
697 struct target_stack_item
*cur
, *prev
;
700 t
->to_close (0); /* Let it clean up */
702 /* Look for the specified target. Note that we assume that a target
703 can only occur once in the target stack. */
705 for (cur
= target_stack
, prev
= NULL
; cur
; prev
= cur
, cur
= cur
->next
)
706 if (cur
->target_ops
== t
)
710 return 0; /* Didn't find target_ops, quit now */
712 /* Unchain the target */
715 target_stack
= cur
->next
;
717 prev
->next
= cur
->next
;
719 xfree (cur
); /* Release the target_stack_item */
721 update_current_target ();
722 cleanup_target (¤t_target
);
730 (current_target
.to_close
) (0); /* Let it clean up */
731 if (unpush_target (target_stack
->target_ops
) == 1)
734 fprintf_unfiltered (gdb_stderr
,
735 "pop_target couldn't find target %s\n",
736 current_target
.to_shortname
);
737 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
741 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
743 /* target_read_string -- read a null terminated string, up to LEN bytes,
744 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
745 Set *STRING to a pointer to malloc'd memory containing the data; the caller
746 is responsible for freeing it. Return the number of bytes successfully
750 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
752 int tlen
, origlen
, offset
, i
;
756 int buffer_allocated
;
758 unsigned int nbytes_read
= 0;
760 /* Small for testing. */
761 buffer_allocated
= 4;
762 buffer
= xmalloc (buffer_allocated
);
769 tlen
= MIN (len
, 4 - (memaddr
& 3));
770 offset
= memaddr
& 3;
772 errcode
= target_xfer_memory (memaddr
& ~3, buf
, 4, 0);
775 /* The transfer request might have crossed the boundary to an
776 unallocated region of memory. Retry the transfer, requesting
780 errcode
= target_xfer_memory (memaddr
, buf
, 1, 0);
785 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
788 bytes
= bufptr
- buffer
;
789 buffer_allocated
*= 2;
790 buffer
= xrealloc (buffer
, buffer_allocated
);
791 bufptr
= buffer
+ bytes
;
794 for (i
= 0; i
< tlen
; i
++)
796 *bufptr
++ = buf
[i
+ offset
];
797 if (buf
[i
+ offset
] == '\000')
799 nbytes_read
+= i
+ 1;
816 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
817 GDB's memory at MYADDR. Returns either 0 for success or an errno value
820 If an error occurs, no guarantee is made about the contents of the data at
821 MYADDR. In particular, the caller should not depend upon partial reads
822 filling the buffer with good data. There is no way for the caller to know
823 how much good data might have been transfered anyway. Callers that can
824 deal with partial reads should call target_read_memory_partial. */
827 target_read_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
829 return target_xfer_memory (memaddr
, myaddr
, len
, 0);
833 target_write_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
835 return target_xfer_memory (memaddr
, myaddr
, len
, 1);
838 /* Move memory to or from the targets. The top target gets priority;
839 if it cannot handle it, it is offered to the next one down, etc.
841 Result is -1 on error, or the number of bytes transfered. */
844 do_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
845 struct mem_attrib
*attrib
)
849 struct target_ops
*t
;
850 struct target_stack_item
*item
;
852 /* Zero length requests are ok and require no work. */
856 /* to_xfer_memory is not guaranteed to set errno, even when it returns
860 /* The quick case is that the top target can handle the transfer. */
861 res
= current_target
.to_xfer_memory
862 (memaddr
, myaddr
, len
, write
, attrib
, ¤t_target
);
864 /* If res <= 0 then we call it again in the loop. Ah well. */
867 for (item
= target_stack
; item
; item
= item
->next
)
869 t
= item
->target_ops
;
870 if (!t
->to_has_memory
)
873 res
= t
->to_xfer_memory (memaddr
, myaddr
, len
, write
, attrib
, t
);
875 break; /* Handled all or part of xfer */
876 if (t
->to_has_all_memory
)
888 /* Perform a memory transfer. Iterate until the entire region has
891 Result is 0 or errno value. */
894 target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
)
898 struct mem_region
*region
;
900 /* Zero length requests are ok and require no work. */
908 region
= lookup_mem_region(memaddr
);
909 if (memaddr
+ len
< region
->hi
)
912 reg_len
= region
->hi
- memaddr
;
914 switch (region
->attrib
.mode
)
929 if (region
->attrib
.cache
)
930 res
= dcache_xfer_memory(target_dcache
, memaddr
, myaddr
,
933 res
= do_xfer_memory(memaddr
, myaddr
, reg_len
, write
,
938 /* If this address is for nonexistent memory, read zeros
939 if reading, or do nothing if writing. Return
942 memset (myaddr
, 0, len
);
956 return 0; /* We managed to cover it all somehow. */
960 /* Perform a partial memory transfer.
962 Result is -1 on error, or the number of bytes transfered. */
965 target_xfer_memory_partial (CORE_ADDR memaddr
, char *myaddr
, int len
,
966 int write_p
, int *err
)
970 struct mem_region
*region
;
972 /* Zero length requests are ok and require no work. */
979 region
= lookup_mem_region(memaddr
);
980 if (memaddr
+ len
< region
->hi
)
983 reg_len
= region
->hi
- memaddr
;
985 switch (region
->attrib
.mode
)
1004 if (region
->attrib
.cache
)
1005 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
,
1008 res
= do_xfer_memory (memaddr
, myaddr
, reg_len
, write_p
,
1026 target_read_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1028 return target_xfer_memory_partial (memaddr
, buf
, len
, 0, err
);
1032 target_write_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1034 return target_xfer_memory_partial (memaddr
, buf
, len
, 1, err
);
1039 target_info (char *args
, int from_tty
)
1041 struct target_ops
*t
;
1042 struct target_stack_item
*item
;
1043 int has_all_mem
= 0;
1045 if (symfile_objfile
!= NULL
)
1046 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
1048 #ifdef FILES_INFO_HOOK
1049 if (FILES_INFO_HOOK ())
1053 for (item
= target_stack
; item
; item
= item
->next
)
1055 t
= item
->target_ops
;
1057 if (!t
->to_has_memory
)
1060 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
1063 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1064 printf_unfiltered ("%s:\n", t
->to_longname
);
1065 (t
->to_files_info
) (t
);
1066 has_all_mem
= t
->to_has_all_memory
;
1070 /* This is to be called by the open routine before it does
1074 target_preopen (int from_tty
)
1078 if (target_has_execution
)
1081 || query ("A program is being debugged already. Kill it? "))
1084 error ("Program not killed.");
1087 /* Calling target_kill may remove the target from the stack. But if
1088 it doesn't (which seems like a win for UDI), remove it now. */
1090 if (target_has_execution
)
1094 /* Detach a target after doing deferred register stores. */
1097 target_detach (char *args
, int from_tty
)
1099 /* Handle any optimized stores to the inferior. */
1100 #ifdef DO_DEFERRED_STORES
1103 (current_target
.to_detach
) (args
, from_tty
);
1107 target_link (char *modname
, CORE_ADDR
*t_reloc
)
1109 if (STREQ (current_target
.to_shortname
, "rombug"))
1111 (current_target
.to_lookup_symbol
) (modname
, t_reloc
);
1113 error ("Unable to link to %s and get relocation in rombug", modname
);
1116 *t_reloc
= (CORE_ADDR
) -1;
1120 target_async_mask (int mask
)
1122 int saved_async_masked_status
= target_async_mask_value
;
1123 target_async_mask_value
= mask
;
1124 return saved_async_masked_status
;
1127 /* Look through the list of possible targets for a target that can
1128 execute a run or attach command without any other data. This is
1129 used to locate the default process stratum.
1131 Result is always valid (error() is called for errors). */
1133 static struct target_ops
*
1134 find_default_run_target (char *do_mesg
)
1136 struct target_ops
**t
;
1137 struct target_ops
*runable
= NULL
;
1142 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1145 if ((*t
)->to_can_run
&& target_can_run (*t
))
1153 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
1159 find_default_attach (char *args
, int from_tty
)
1161 struct target_ops
*t
;
1163 t
= find_default_run_target ("attach");
1164 (t
->to_attach
) (args
, from_tty
);
1169 find_default_require_attach (char *args
, int from_tty
)
1171 struct target_ops
*t
;
1173 t
= find_default_run_target ("require_attach");
1174 (t
->to_require_attach
) (args
, from_tty
);
1179 find_default_require_detach (int pid
, char *args
, int from_tty
)
1181 struct target_ops
*t
;
1183 t
= find_default_run_target ("require_detach");
1184 (t
->to_require_detach
) (pid
, args
, from_tty
);
1189 find_default_create_inferior (char *exec_file
, char *allargs
, char **env
)
1191 struct target_ops
*t
;
1193 t
= find_default_run_target ("run");
1194 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
1199 find_default_clone_and_follow_inferior (int child_pid
, int *followed_child
)
1201 struct target_ops
*t
;
1203 t
= find_default_run_target ("run");
1204 (t
->to_clone_and_follow_inferior
) (child_pid
, followed_child
);
1221 * Resize the to_sections pointer. Also make sure that anyone that
1222 * was holding on to an old value of it gets updated.
1223 * Returns the old size.
1227 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1229 struct target_ops
**t
;
1230 struct section_table
*old_value
;
1233 old_value
= target
->to_sections
;
1235 if (target
->to_sections
)
1237 old_count
= target
->to_sections_end
- target
->to_sections
;
1238 target
->to_sections
= (struct section_table
*)
1239 xrealloc ((char *) target
->to_sections
,
1240 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1245 target
->to_sections
= (struct section_table
*)
1246 xmalloc ((sizeof (struct section_table
)) * num_added
);
1248 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1250 /* Check to see if anyone else was pointing to this structure.
1251 If old_value was null, then no one was. */
1255 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1258 if ((*t
)->to_sections
== old_value
)
1260 (*t
)->to_sections
= target
->to_sections
;
1261 (*t
)->to_sections_end
= target
->to_sections_end
;
1270 /* Remove all target sections taken from ABFD.
1272 Scan the current target stack for targets whose section tables
1273 refer to sections from BFD, and remove those sections. We use this
1274 when we notice that the inferior has unloaded a shared object, for
1277 remove_target_sections (bfd
*abfd
)
1279 struct target_ops
**t
;
1281 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; t
++)
1283 struct section_table
*src
, *dest
;
1285 dest
= (*t
)->to_sections
;
1286 for (src
= (*t
)->to_sections
; src
< (*t
)->to_sections_end
; src
++)
1287 if (src
->bfd
!= abfd
)
1289 /* Keep this section. */
1290 if (dest
< src
) *dest
= *src
;
1294 /* If we've dropped any sections, resize the section table. */
1296 target_resize_to_sections (*t
, dest
- src
);
1303 /* Find a single runnable target in the stack and return it. If for
1304 some reason there is more than one, return NULL. */
1307 find_run_target (void)
1309 struct target_ops
**t
;
1310 struct target_ops
*runable
= NULL
;
1315 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1317 if ((*t
)->to_can_run
&& target_can_run (*t
))
1324 return (count
== 1 ? runable
: NULL
);
1327 /* Find a single core_stratum target in the list of targets and return it.
1328 If for some reason there is more than one, return NULL. */
1331 find_core_target (void)
1333 struct target_ops
**t
;
1334 struct target_ops
*runable
= NULL
;
1339 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1342 if ((*t
)->to_stratum
== core_stratum
)
1349 return (count
== 1 ? runable
: NULL
);
1353 * Find the next target down the stack from the specified target.
1357 find_target_beneath (struct target_ops
*t
)
1359 struct target_stack_item
*cur
;
1361 for (cur
= target_stack
; cur
; cur
= cur
->next
)
1362 if (cur
->target_ops
== t
)
1365 if (cur
== NULL
|| cur
->next
== NULL
)
1368 return cur
->next
->target_ops
;
1372 /* The inferior process has died. Long live the inferior! */
1375 generic_mourn_inferior (void)
1377 extern int show_breakpoint_hit_counts
;
1379 inferior_ptid
= null_ptid
;
1381 breakpoint_init_inferior (inf_exited
);
1382 registers_changed ();
1384 #ifdef CLEAR_DEFERRED_STORES
1385 /* Delete any pending stores to the inferior... */
1386 CLEAR_DEFERRED_STORES
;
1389 reopen_exec_file ();
1390 reinit_frame_cache ();
1392 /* It is confusing to the user for ignore counts to stick around
1393 from previous runs of the inferior. So clear them. */
1394 /* However, it is more confusing for the ignore counts to disappear when
1395 using hit counts. So don't clear them if we're counting hits. */
1396 if (!show_breakpoint_hit_counts
)
1397 breakpoint_clear_ignore_counts ();
1403 /* This table must match in order and size the signals in enum target_signal
1412 {"SIGHUP", "Hangup"},
1413 {"SIGINT", "Interrupt"},
1414 {"SIGQUIT", "Quit"},
1415 {"SIGILL", "Illegal instruction"},
1416 {"SIGTRAP", "Trace/breakpoint trap"},
1417 {"SIGABRT", "Aborted"},
1418 {"SIGEMT", "Emulation trap"},
1419 {"SIGFPE", "Arithmetic exception"},
1420 {"SIGKILL", "Killed"},
1421 {"SIGBUS", "Bus error"},
1422 {"SIGSEGV", "Segmentation fault"},
1423 {"SIGSYS", "Bad system call"},
1424 {"SIGPIPE", "Broken pipe"},
1425 {"SIGALRM", "Alarm clock"},
1426 {"SIGTERM", "Terminated"},
1427 {"SIGURG", "Urgent I/O condition"},
1428 {"SIGSTOP", "Stopped (signal)"},
1429 {"SIGTSTP", "Stopped (user)"},
1430 {"SIGCONT", "Continued"},
1431 {"SIGCHLD", "Child status changed"},
1432 {"SIGTTIN", "Stopped (tty input)"},
1433 {"SIGTTOU", "Stopped (tty output)"},
1434 {"SIGIO", "I/O possible"},
1435 {"SIGXCPU", "CPU time limit exceeded"},
1436 {"SIGXFSZ", "File size limit exceeded"},
1437 {"SIGVTALRM", "Virtual timer expired"},
1438 {"SIGPROF", "Profiling timer expired"},
1439 {"SIGWINCH", "Window size changed"},
1440 {"SIGLOST", "Resource lost"},
1441 {"SIGUSR1", "User defined signal 1"},
1442 {"SIGUSR2", "User defined signal 2"},
1443 {"SIGPWR", "Power fail/restart"},
1444 {"SIGPOLL", "Pollable event occurred"},
1445 {"SIGWIND", "SIGWIND"},
1446 {"SIGPHONE", "SIGPHONE"},
1447 {"SIGWAITING", "Process's LWPs are blocked"},
1448 {"SIGLWP", "Signal LWP"},
1449 {"SIGDANGER", "Swap space dangerously low"},
1450 {"SIGGRANT", "Monitor mode granted"},
1451 {"SIGRETRACT", "Need to relinquish monitor mode"},
1452 {"SIGMSG", "Monitor mode data available"},
1453 {"SIGSOUND", "Sound completed"},
1454 {"SIGSAK", "Secure attention"},
1455 {"SIGPRIO", "SIGPRIO"},
1456 {"SIG33", "Real-time event 33"},
1457 {"SIG34", "Real-time event 34"},
1458 {"SIG35", "Real-time event 35"},
1459 {"SIG36", "Real-time event 36"},
1460 {"SIG37", "Real-time event 37"},
1461 {"SIG38", "Real-time event 38"},
1462 {"SIG39", "Real-time event 39"},
1463 {"SIG40", "Real-time event 40"},
1464 {"SIG41", "Real-time event 41"},
1465 {"SIG42", "Real-time event 42"},
1466 {"SIG43", "Real-time event 43"},
1467 {"SIG44", "Real-time event 44"},
1468 {"SIG45", "Real-time event 45"},
1469 {"SIG46", "Real-time event 46"},
1470 {"SIG47", "Real-time event 47"},
1471 {"SIG48", "Real-time event 48"},
1472 {"SIG49", "Real-time event 49"},
1473 {"SIG50", "Real-time event 50"},
1474 {"SIG51", "Real-time event 51"},
1475 {"SIG52", "Real-time event 52"},
1476 {"SIG53", "Real-time event 53"},
1477 {"SIG54", "Real-time event 54"},
1478 {"SIG55", "Real-time event 55"},
1479 {"SIG56", "Real-time event 56"},
1480 {"SIG57", "Real-time event 57"},
1481 {"SIG58", "Real-time event 58"},
1482 {"SIG59", "Real-time event 59"},
1483 {"SIG60", "Real-time event 60"},
1484 {"SIG61", "Real-time event 61"},
1485 {"SIG62", "Real-time event 62"},
1486 {"SIG63", "Real-time event 63"},
1487 {"SIGCANCEL", "LWP internal signal"},
1488 {"SIG32", "Real-time event 32"},
1489 {"SIG64", "Real-time event 64"},
1490 {"SIG65", "Real-time event 65"},
1491 {"SIG66", "Real-time event 66"},
1492 {"SIG67", "Real-time event 67"},
1493 {"SIG68", "Real-time event 68"},
1494 {"SIG69", "Real-time event 69"},
1495 {"SIG70", "Real-time event 70"},
1496 {"SIG71", "Real-time event 71"},
1497 {"SIG72", "Real-time event 72"},
1498 {"SIG73", "Real-time event 73"},
1499 {"SIG74", "Real-time event 74"},
1500 {"SIG75", "Real-time event 75"},
1501 {"SIG76", "Real-time event 76"},
1502 {"SIG77", "Real-time event 77"},
1503 {"SIG78", "Real-time event 78"},
1504 {"SIG79", "Real-time event 79"},
1505 {"SIG80", "Real-time event 80"},
1506 {"SIG81", "Real-time event 81"},
1507 {"SIG82", "Real-time event 82"},
1508 {"SIG83", "Real-time event 83"},
1509 {"SIG84", "Real-time event 84"},
1510 {"SIG85", "Real-time event 85"},
1511 {"SIG86", "Real-time event 86"},
1512 {"SIG87", "Real-time event 87"},
1513 {"SIG88", "Real-time event 88"},
1514 {"SIG89", "Real-time event 89"},
1515 {"SIG90", "Real-time event 90"},
1516 {"SIG91", "Real-time event 91"},
1517 {"SIG92", "Real-time event 92"},
1518 {"SIG93", "Real-time event 93"},
1519 {"SIG94", "Real-time event 94"},
1520 {"SIG95", "Real-time event 95"},
1521 {"SIG96", "Real-time event 96"},
1522 {"SIG97", "Real-time event 97"},
1523 {"SIG98", "Real-time event 98"},
1524 {"SIG99", "Real-time event 99"},
1525 {"SIG100", "Real-time event 100"},
1526 {"SIG101", "Real-time event 101"},
1527 {"SIG102", "Real-time event 102"},
1528 {"SIG103", "Real-time event 103"},
1529 {"SIG104", "Real-time event 104"},
1530 {"SIG105", "Real-time event 105"},
1531 {"SIG106", "Real-time event 106"},
1532 {"SIG107", "Real-time event 107"},
1533 {"SIG108", "Real-time event 108"},
1534 {"SIG109", "Real-time event 109"},
1535 {"SIG110", "Real-time event 110"},
1536 {"SIG111", "Real-time event 111"},
1537 {"SIG112", "Real-time event 112"},
1538 {"SIG113", "Real-time event 113"},
1539 {"SIG114", "Real-time event 114"},
1540 {"SIG115", "Real-time event 115"},
1541 {"SIG116", "Real-time event 116"},
1542 {"SIG117", "Real-time event 117"},
1543 {"SIG118", "Real-time event 118"},
1544 {"SIG119", "Real-time event 119"},
1545 {"SIG120", "Real-time event 120"},
1546 {"SIG121", "Real-time event 121"},
1547 {"SIG122", "Real-time event 122"},
1548 {"SIG123", "Real-time event 123"},
1549 {"SIG124", "Real-time event 124"},
1550 {"SIG125", "Real-time event 125"},
1551 {"SIG126", "Real-time event 126"},
1552 {"SIG127", "Real-time event 127"},
1554 #if defined(MACH) || defined(__MACH__)
1555 /* Mach exceptions */
1556 {"EXC_BAD_ACCESS", "Could not access memory"},
1557 {"EXC_BAD_INSTRUCTION", "Illegal instruction/operand"},
1558 {"EXC_ARITHMETIC", "Arithmetic exception"},
1559 {"EXC_EMULATION", "Emulation instruction"},
1560 {"EXC_SOFTWARE", "Software generated exception"},
1561 {"EXC_BREAKPOINT", "Breakpoint"},
1563 {"SIGINFO", "Information request"},
1565 {NULL
, "Unknown signal"},
1566 {NULL
, "Internal error: printing TARGET_SIGNAL_DEFAULT"},
1568 /* Last entry, used to check whether the table is the right size. */
1569 {NULL
, "TARGET_SIGNAL_MAGIC"}
1575 /* Return the string for a signal. */
1577 target_signal_to_string (enum target_signal sig
)
1579 if ((sig
>= TARGET_SIGNAL_FIRST
) && (sig
<= TARGET_SIGNAL_LAST
))
1580 return signals
[sig
].string
;
1582 return signals
[TARGET_SIGNAL_UNKNOWN
].string
;
1585 /* Return the name for a signal. */
1587 target_signal_to_name (enum target_signal sig
)
1589 if (sig
== TARGET_SIGNAL_UNKNOWN
)
1590 /* I think the code which prints this will always print it along with
1591 the string, so no need to be verbose. */
1593 return signals
[sig
].name
;
1596 /* Given a name, return its signal. */
1598 target_signal_from_name (char *name
)
1600 enum target_signal sig
;
1602 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
1603 for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
1604 questionable; seems like by now people should call it SIGABRT
1607 /* This ugly cast brought to you by the native VAX compiler. */
1608 for (sig
= TARGET_SIGNAL_HUP
;
1609 signals
[sig
].name
!= NULL
;
1610 sig
= (enum target_signal
) ((int) sig
+ 1))
1611 if (STREQ (name
, signals
[sig
].name
))
1613 return TARGET_SIGNAL_UNKNOWN
;
1616 /* The following functions are to help certain targets deal
1617 with the signal/waitstatus stuff. They could just as well be in
1618 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
1620 /* Convert host signal to our signals. */
1622 target_signal_from_host (int hostsig
)
1624 /* A switch statement would make sense but would require special kludges
1625 to deal with the cases where more than one signal has the same number. */
1628 return TARGET_SIGNAL_0
;
1630 #if defined (SIGHUP)
1631 if (hostsig
== SIGHUP
)
1632 return TARGET_SIGNAL_HUP
;
1634 #if defined (SIGINT)
1635 if (hostsig
== SIGINT
)
1636 return TARGET_SIGNAL_INT
;
1638 #if defined (SIGQUIT)
1639 if (hostsig
== SIGQUIT
)
1640 return TARGET_SIGNAL_QUIT
;
1642 #if defined (SIGILL)
1643 if (hostsig
== SIGILL
)
1644 return TARGET_SIGNAL_ILL
;
1646 #if defined (SIGTRAP)
1647 if (hostsig
== SIGTRAP
)
1648 return TARGET_SIGNAL_TRAP
;
1650 #if defined (SIGABRT)
1651 if (hostsig
== SIGABRT
)
1652 return TARGET_SIGNAL_ABRT
;
1654 #if defined (SIGEMT)
1655 if (hostsig
== SIGEMT
)
1656 return TARGET_SIGNAL_EMT
;
1658 #if defined (SIGFPE)
1659 if (hostsig
== SIGFPE
)
1660 return TARGET_SIGNAL_FPE
;
1662 #if defined (SIGKILL)
1663 if (hostsig
== SIGKILL
)
1664 return TARGET_SIGNAL_KILL
;
1666 #if defined (SIGBUS)
1667 if (hostsig
== SIGBUS
)
1668 return TARGET_SIGNAL_BUS
;
1670 #if defined (SIGSEGV)
1671 if (hostsig
== SIGSEGV
)
1672 return TARGET_SIGNAL_SEGV
;
1674 #if defined (SIGSYS)
1675 if (hostsig
== SIGSYS
)
1676 return TARGET_SIGNAL_SYS
;
1678 #if defined (SIGPIPE)
1679 if (hostsig
== SIGPIPE
)
1680 return TARGET_SIGNAL_PIPE
;
1682 #if defined (SIGALRM)
1683 if (hostsig
== SIGALRM
)
1684 return TARGET_SIGNAL_ALRM
;
1686 #if defined (SIGTERM)
1687 if (hostsig
== SIGTERM
)
1688 return TARGET_SIGNAL_TERM
;
1690 #if defined (SIGUSR1)
1691 if (hostsig
== SIGUSR1
)
1692 return TARGET_SIGNAL_USR1
;
1694 #if defined (SIGUSR2)
1695 if (hostsig
== SIGUSR2
)
1696 return TARGET_SIGNAL_USR2
;
1698 #if defined (SIGCLD)
1699 if (hostsig
== SIGCLD
)
1700 return TARGET_SIGNAL_CHLD
;
1702 #if defined (SIGCHLD)
1703 if (hostsig
== SIGCHLD
)
1704 return TARGET_SIGNAL_CHLD
;
1706 #if defined (SIGPWR)
1707 if (hostsig
== SIGPWR
)
1708 return TARGET_SIGNAL_PWR
;
1710 #if defined (SIGWINCH)
1711 if (hostsig
== SIGWINCH
)
1712 return TARGET_SIGNAL_WINCH
;
1714 #if defined (SIGURG)
1715 if (hostsig
== SIGURG
)
1716 return TARGET_SIGNAL_URG
;
1719 if (hostsig
== SIGIO
)
1720 return TARGET_SIGNAL_IO
;
1722 #if defined (SIGPOLL)
1723 if (hostsig
== SIGPOLL
)
1724 return TARGET_SIGNAL_POLL
;
1726 #if defined (SIGSTOP)
1727 if (hostsig
== SIGSTOP
)
1728 return TARGET_SIGNAL_STOP
;
1730 #if defined (SIGTSTP)
1731 if (hostsig
== SIGTSTP
)
1732 return TARGET_SIGNAL_TSTP
;
1734 #if defined (SIGCONT)
1735 if (hostsig
== SIGCONT
)
1736 return TARGET_SIGNAL_CONT
;
1738 #if defined (SIGTTIN)
1739 if (hostsig
== SIGTTIN
)
1740 return TARGET_SIGNAL_TTIN
;
1742 #if defined (SIGTTOU)
1743 if (hostsig
== SIGTTOU
)
1744 return TARGET_SIGNAL_TTOU
;
1746 #if defined (SIGVTALRM)
1747 if (hostsig
== SIGVTALRM
)
1748 return TARGET_SIGNAL_VTALRM
;
1750 #if defined (SIGPROF)
1751 if (hostsig
== SIGPROF
)
1752 return TARGET_SIGNAL_PROF
;
1754 #if defined (SIGXCPU)
1755 if (hostsig
== SIGXCPU
)
1756 return TARGET_SIGNAL_XCPU
;
1758 #if defined (SIGXFSZ)
1759 if (hostsig
== SIGXFSZ
)
1760 return TARGET_SIGNAL_XFSZ
;
1762 #if defined (SIGWIND)
1763 if (hostsig
== SIGWIND
)
1764 return TARGET_SIGNAL_WIND
;
1766 #if defined (SIGPHONE)
1767 if (hostsig
== SIGPHONE
)
1768 return TARGET_SIGNAL_PHONE
;
1770 #if defined (SIGLOST)
1771 if (hostsig
== SIGLOST
)
1772 return TARGET_SIGNAL_LOST
;
1774 #if defined (SIGWAITING)
1775 if (hostsig
== SIGWAITING
)
1776 return TARGET_SIGNAL_WAITING
;
1778 #if defined (SIGCANCEL)
1779 if (hostsig
== SIGCANCEL
)
1780 return TARGET_SIGNAL_CANCEL
;
1782 #if defined (SIGLWP)
1783 if (hostsig
== SIGLWP
)
1784 return TARGET_SIGNAL_LWP
;
1786 #if defined (SIGDANGER)
1787 if (hostsig
== SIGDANGER
)
1788 return TARGET_SIGNAL_DANGER
;
1790 #if defined (SIGGRANT)
1791 if (hostsig
== SIGGRANT
)
1792 return TARGET_SIGNAL_GRANT
;
1794 #if defined (SIGRETRACT)
1795 if (hostsig
== SIGRETRACT
)
1796 return TARGET_SIGNAL_RETRACT
;
1798 #if defined (SIGMSG)
1799 if (hostsig
== SIGMSG
)
1800 return TARGET_SIGNAL_MSG
;
1802 #if defined (SIGSOUND)
1803 if (hostsig
== SIGSOUND
)
1804 return TARGET_SIGNAL_SOUND
;
1806 #if defined (SIGSAK)
1807 if (hostsig
== SIGSAK
)
1808 return TARGET_SIGNAL_SAK
;
1810 #if defined (SIGPRIO)
1811 if (hostsig
== SIGPRIO
)
1812 return TARGET_SIGNAL_PRIO
;
1815 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1816 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1817 if (hostsig
== _NSIG
+ EXC_BAD_ACCESS
)
1818 return TARGET_EXC_BAD_ACCESS
;
1820 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1821 if (hostsig
== _NSIG
+ EXC_BAD_INSTRUCTION
)
1822 return TARGET_EXC_BAD_INSTRUCTION
;
1824 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1825 if (hostsig
== _NSIG
+ EXC_ARITHMETIC
)
1826 return TARGET_EXC_ARITHMETIC
;
1828 #if defined (EXC_EMULATION) && defined (_NSIG)
1829 if (hostsig
== _NSIG
+ EXC_EMULATION
)
1830 return TARGET_EXC_EMULATION
;
1832 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1833 if (hostsig
== _NSIG
+ EXC_SOFTWARE
)
1834 return TARGET_EXC_SOFTWARE
;
1836 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1837 if (hostsig
== _NSIG
+ EXC_BREAKPOINT
)
1838 return TARGET_EXC_BREAKPOINT
;
1841 #if defined (SIGINFO)
1842 if (hostsig
== SIGINFO
)
1843 return TARGET_SIGNAL_INFO
;
1846 #if defined (REALTIME_LO)
1847 if (hostsig
>= REALTIME_LO
&& hostsig
< REALTIME_HI
)
1849 /* This block of TARGET_SIGNAL_REALTIME value is in order. */
1850 if (33 <= hostsig
&& hostsig
<= 63)
1851 return (enum target_signal
)
1852 (hostsig
- 33 + (int) TARGET_SIGNAL_REALTIME_33
);
1853 else if (hostsig
== 32)
1854 return TARGET_SIGNAL_REALTIME_32
;
1855 else if (64 <= hostsig
&& hostsig
<= 127)
1856 return (enum target_signal
)
1857 (hostsig
- 64 + (int) TARGET_SIGNAL_REALTIME_64
);
1859 error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
1863 #if defined (SIGRTMIN)
1864 if (hostsig
>= SIGRTMIN
&& hostsig
<= SIGRTMAX
)
1866 /* This block of TARGET_SIGNAL_REALTIME value is in order. */
1867 if (33 <= hostsig
&& hostsig
<= 63)
1868 return (enum target_signal
)
1869 (hostsig
- 33 + (int) TARGET_SIGNAL_REALTIME_33
);
1870 else if (hostsig
== 64)
1871 return TARGET_SIGNAL_REALTIME_64
;
1873 error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
1876 return TARGET_SIGNAL_UNKNOWN
;
1879 /* Convert a OURSIG (an enum target_signal) to the form used by the
1880 target operating system (refered to as the ``host'') or zero if the
1881 equivalent host signal is not available. Set/clear OURSIG_OK
1885 do_target_signal_to_host (enum target_signal oursig
,
1891 case TARGET_SIGNAL_0
:
1894 #if defined (SIGHUP)
1895 case TARGET_SIGNAL_HUP
:
1898 #if defined (SIGINT)
1899 case TARGET_SIGNAL_INT
:
1902 #if defined (SIGQUIT)
1903 case TARGET_SIGNAL_QUIT
:
1906 #if defined (SIGILL)
1907 case TARGET_SIGNAL_ILL
:
1910 #if defined (SIGTRAP)
1911 case TARGET_SIGNAL_TRAP
:
1914 #if defined (SIGABRT)
1915 case TARGET_SIGNAL_ABRT
:
1918 #if defined (SIGEMT)
1919 case TARGET_SIGNAL_EMT
:
1922 #if defined (SIGFPE)
1923 case TARGET_SIGNAL_FPE
:
1926 #if defined (SIGKILL)
1927 case TARGET_SIGNAL_KILL
:
1930 #if defined (SIGBUS)
1931 case TARGET_SIGNAL_BUS
:
1934 #if defined (SIGSEGV)
1935 case TARGET_SIGNAL_SEGV
:
1938 #if defined (SIGSYS)
1939 case TARGET_SIGNAL_SYS
:
1942 #if defined (SIGPIPE)
1943 case TARGET_SIGNAL_PIPE
:
1946 #if defined (SIGALRM)
1947 case TARGET_SIGNAL_ALRM
:
1950 #if defined (SIGTERM)
1951 case TARGET_SIGNAL_TERM
:
1954 #if defined (SIGUSR1)
1955 case TARGET_SIGNAL_USR1
:
1958 #if defined (SIGUSR2)
1959 case TARGET_SIGNAL_USR2
:
1962 #if defined (SIGCHLD) || defined (SIGCLD)
1963 case TARGET_SIGNAL_CHLD
:
1964 #if defined (SIGCHLD)
1969 #endif /* SIGCLD or SIGCHLD */
1970 #if defined (SIGPWR)
1971 case TARGET_SIGNAL_PWR
:
1974 #if defined (SIGWINCH)
1975 case TARGET_SIGNAL_WINCH
:
1978 #if defined (SIGURG)
1979 case TARGET_SIGNAL_URG
:
1983 case TARGET_SIGNAL_IO
:
1986 #if defined (SIGPOLL)
1987 case TARGET_SIGNAL_POLL
:
1990 #if defined (SIGSTOP)
1991 case TARGET_SIGNAL_STOP
:
1994 #if defined (SIGTSTP)
1995 case TARGET_SIGNAL_TSTP
:
1998 #if defined (SIGCONT)
1999 case TARGET_SIGNAL_CONT
:
2002 #if defined (SIGTTIN)
2003 case TARGET_SIGNAL_TTIN
:
2006 #if defined (SIGTTOU)
2007 case TARGET_SIGNAL_TTOU
:
2010 #if defined (SIGVTALRM)
2011 case TARGET_SIGNAL_VTALRM
:
2014 #if defined (SIGPROF)
2015 case TARGET_SIGNAL_PROF
:
2018 #if defined (SIGXCPU)
2019 case TARGET_SIGNAL_XCPU
:
2022 #if defined (SIGXFSZ)
2023 case TARGET_SIGNAL_XFSZ
:
2026 #if defined (SIGWIND)
2027 case TARGET_SIGNAL_WIND
:
2030 #if defined (SIGPHONE)
2031 case TARGET_SIGNAL_PHONE
:
2034 #if defined (SIGLOST)
2035 case TARGET_SIGNAL_LOST
:
2038 #if defined (SIGWAITING)
2039 case TARGET_SIGNAL_WAITING
:
2042 #if defined (SIGCANCEL)
2043 case TARGET_SIGNAL_CANCEL
:
2046 #if defined (SIGLWP)
2047 case TARGET_SIGNAL_LWP
:
2050 #if defined (SIGDANGER)
2051 case TARGET_SIGNAL_DANGER
:
2054 #if defined (SIGGRANT)
2055 case TARGET_SIGNAL_GRANT
:
2058 #if defined (SIGRETRACT)
2059 case TARGET_SIGNAL_RETRACT
:
2062 #if defined (SIGMSG)
2063 case TARGET_SIGNAL_MSG
:
2066 #if defined (SIGSOUND)
2067 case TARGET_SIGNAL_SOUND
:
2070 #if defined (SIGSAK)
2071 case TARGET_SIGNAL_SAK
:
2074 #if defined (SIGPRIO)
2075 case TARGET_SIGNAL_PRIO
:
2079 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
2080 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
2081 case TARGET_EXC_BAD_ACCESS
:
2082 return _NSIG
+ EXC_BAD_ACCESS
;
2084 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
2085 case TARGET_EXC_BAD_INSTRUCTION
:
2086 return _NSIG
+ EXC_BAD_INSTRUCTION
;
2088 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
2089 case TARGET_EXC_ARITHMETIC
:
2090 return _NSIG
+ EXC_ARITHMETIC
;
2092 #if defined (EXC_EMULATION) && defined (_NSIG)
2093 case TARGET_EXC_EMULATION
:
2094 return _NSIG
+ EXC_EMULATION
;
2096 #if defined (EXC_SOFTWARE) && defined (_NSIG)
2097 case TARGET_EXC_SOFTWARE
:
2098 return _NSIG
+ EXC_SOFTWARE
;
2100 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
2101 case TARGET_EXC_BREAKPOINT
:
2102 return _NSIG
+ EXC_BREAKPOINT
;
2105 #if defined (SIGINFO)
2106 case TARGET_SIGNAL_INFO
:
2111 #if defined (REALTIME_LO)
2112 if (oursig
>= TARGET_SIGNAL_REALTIME_33
2113 && oursig
<= TARGET_SIGNAL_REALTIME_63
)
2115 /* This block of signals is continuous, and
2116 TARGET_SIGNAL_REALTIME_33 is 33 by definition. */
2118 (int) oursig
- (int) TARGET_SIGNAL_REALTIME_33
+ 33;
2119 if (retsig
>= REALTIME_LO
&& retsig
< REALTIME_HI
)
2122 #if (REALTIME_LO < 33)
2123 else if (oursig
== TARGET_SIGNAL_REALTIME_32
)
2125 /* TARGET_SIGNAL_REALTIME_32 isn't contiguous with
2126 TARGET_SIGNAL_REALTIME_33. It is 32 by definition. */
2130 #if (REALTIME_HI > 64)
2131 if (oursig
>= TARGET_SIGNAL_REALTIME_64
2132 && oursig
<= TARGET_SIGNAL_REALTIME_127
)
2134 /* This block of signals is continuous, and
2135 TARGET_SIGNAL_REALTIME_64 is 64 by definition. */
2137 (int) oursig
- (int) TARGET_SIGNAL_REALTIME_64
+ 64;
2138 if (retsig
>= REALTIME_LO
&& retsig
< REALTIME_HI
)
2145 #if defined (SIGRTMIN)
2146 if (oursig
>= TARGET_SIGNAL_REALTIME_33
2147 && oursig
<= TARGET_SIGNAL_REALTIME_63
)
2149 /* This block of signals is continuous, and
2150 TARGET_SIGNAL_REALTIME_33 is 33 by definition. */
2152 (int) oursig
- (int) TARGET_SIGNAL_REALTIME_33
+ 33;
2153 if (retsig
>= SIGRTMIN
&& retsig
<= SIGRTMAX
)
2156 else if (oursig
== TARGET_SIGNAL_REALTIME_64
)
2165 target_signal_to_host_p (enum target_signal oursig
)
2168 do_target_signal_to_host (oursig
, &oursig_ok
);
2173 target_signal_to_host (enum target_signal oursig
)
2176 int targ_signo
= do_target_signal_to_host (oursig
, &oursig_ok
);
2179 /* The user might be trying to do "signal SIGSAK" where this system
2180 doesn't have SIGSAK. */
2181 warning ("Signal %s does not exist on this system.\n",
2182 target_signal_to_name (oursig
));
2189 /* Helper function for child_wait and the Lynx derivatives of child_wait.
2190 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
2191 translation of that in OURSTATUS. */
2193 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
2195 #ifdef CHILD_SPECIAL_WAITSTATUS
2196 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
2197 if it wants to deal with hoststatus. */
2198 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
2202 if (WIFEXITED (hoststatus
))
2204 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
2205 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
2207 else if (!WIFSTOPPED (hoststatus
))
2209 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
2210 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
2214 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
2215 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
2219 /* In some circumstances we allow a command to specify a numeric
2220 signal. The idea is to keep these circumstances limited so that
2221 users (and scripts) develop portable habits. For comparison,
2222 POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
2223 numeric signal at all is obsolescent. We are slightly more
2224 lenient and allow 1-15 which should match host signal numbers on
2225 most systems. Use of symbolic signal names is strongly encouraged. */
2228 target_signal_from_command (int num
)
2230 if (num
>= 1 && num
<= 15)
2231 return (enum target_signal
) num
;
2232 error ("Only signals 1-15 are valid as numeric signals.\n\
2233 Use \"info signals\" for a list of symbolic signals.");
2236 /* Returns zero to leave the inferior alone, one to interrupt it. */
2237 int (*target_activity_function
) (void);
2238 int target_activity_fd
;
2240 /* Convert a normal process ID to a string. Returns the string in a static
2244 normal_pid_to_str (ptid_t ptid
)
2246 static char buf
[30];
2248 sprintf (buf
, "process %d", PIDGET (ptid
));
2252 /* Some targets (such as ttrace-based HPUX) don't allow us to request
2253 notification of inferior events such as fork and vork immediately
2254 after the inferior is created. (This because of how gdb gets an
2255 inferior created via invoking a shell to do it. In such a scenario,
2256 if the shell init file has commands in it, the shell will fork and
2257 exec for each of those commands, and we will see each such fork
2260 This function is used by all targets that allow us to request
2261 notification of forks, etc at inferior creation time; e.g., in
2262 target_acknowledge_forked_child.
2265 normal_target_post_startup_inferior (ptid_t ptid
)
2267 /* This space intentionally left blank. */
2270 /* Set up the handful of non-empty slots needed by the dummy target
2274 init_dummy_target (void)
2276 dummy_target
.to_shortname
= "None";
2277 dummy_target
.to_longname
= "None";
2278 dummy_target
.to_doc
= "";
2279 dummy_target
.to_attach
= find_default_attach
;
2280 dummy_target
.to_require_attach
= find_default_require_attach
;
2281 dummy_target
.to_require_detach
= find_default_require_detach
;
2282 dummy_target
.to_create_inferior
= find_default_create_inferior
;
2283 dummy_target
.to_clone_and_follow_inferior
= find_default_clone_and_follow_inferior
;
2284 dummy_target
.to_pid_to_str
= normal_pid_to_str
;
2285 dummy_target
.to_stratum
= dummy_stratum
;
2286 dummy_target
.to_magic
= OPS_MAGIC
;
2290 static struct target_ops debug_target
;
2293 debug_to_open (char *args
, int from_tty
)
2295 debug_target
.to_open (args
, from_tty
);
2297 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
2301 debug_to_close (int quitting
)
2303 debug_target
.to_close (quitting
);
2305 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
2309 debug_to_attach (char *args
, int from_tty
)
2311 debug_target
.to_attach (args
, from_tty
);
2313 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
2318 debug_to_post_attach (int pid
)
2320 debug_target
.to_post_attach (pid
);
2322 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
2326 debug_to_require_attach (char *args
, int from_tty
)
2328 debug_target
.to_require_attach (args
, from_tty
);
2330 fprintf_unfiltered (gdb_stdlog
,
2331 "target_require_attach (%s, %d)\n", args
, from_tty
);
2335 debug_to_detach (char *args
, int from_tty
)
2337 debug_target
.to_detach (args
, from_tty
);
2339 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
2343 debug_to_require_detach (int pid
, char *args
, int from_tty
)
2345 debug_target
.to_require_detach (pid
, args
, from_tty
);
2347 fprintf_unfiltered (gdb_stdlog
,
2348 "target_require_detach (%d, %s, %d)\n", pid
, args
, from_tty
);
2352 debug_to_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
2354 debug_target
.to_resume (ptid
, step
, siggnal
);
2356 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", PIDGET (ptid
),
2357 step
? "step" : "continue",
2358 target_signal_to_name (siggnal
));
2362 debug_to_wait (ptid_t ptid
, struct target_waitstatus
*status
)
2366 retval
= debug_target
.to_wait (ptid
, status
);
2368 fprintf_unfiltered (gdb_stdlog
,
2369 "target_wait (%d, status) = %d, ", PIDGET (ptid
),
2371 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
2372 switch (status
->kind
)
2374 case TARGET_WAITKIND_EXITED
:
2375 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
2376 status
->value
.integer
);
2378 case TARGET_WAITKIND_STOPPED
:
2379 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
2380 target_signal_to_name (status
->value
.sig
));
2382 case TARGET_WAITKIND_SIGNALLED
:
2383 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
2384 target_signal_to_name (status
->value
.sig
));
2386 case TARGET_WAITKIND_LOADED
:
2387 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
2389 case TARGET_WAITKIND_FORKED
:
2390 fprintf_unfiltered (gdb_stdlog
, "forked\n");
2392 case TARGET_WAITKIND_VFORKED
:
2393 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
2395 case TARGET_WAITKIND_EXECD
:
2396 fprintf_unfiltered (gdb_stdlog
, "execd\n");
2398 case TARGET_WAITKIND_SPURIOUS
:
2399 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
2402 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
2410 debug_to_post_wait (ptid_t ptid
, int status
)
2412 debug_target
.to_post_wait (ptid
, status
);
2414 fprintf_unfiltered (gdb_stdlog
, "target_post_wait (%d, %d)\n",
2415 PIDGET (ptid
), status
);
2419 debug_to_fetch_registers (int regno
)
2421 debug_target
.to_fetch_registers (regno
);
2423 fprintf_unfiltered (gdb_stdlog
, "target_fetch_registers (%s)",
2424 regno
!= -1 ? REGISTER_NAME (regno
) : "-1");
2426 fprintf_unfiltered (gdb_stdlog
, " = 0x%lx %ld",
2427 (unsigned long) read_register (regno
),
2428 (unsigned long) read_register (regno
));
2429 fprintf_unfiltered (gdb_stdlog
, "\n");
2433 debug_to_store_registers (int regno
)
2435 debug_target
.to_store_registers (regno
);
2437 if (regno
>= 0 && regno
< NUM_REGS
)
2438 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%s) = 0x%lx %ld\n",
2439 REGISTER_NAME (regno
),
2440 (unsigned long) read_register (regno
),
2441 (unsigned long) read_register (regno
));
2443 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%d)\n", regno
);
2447 debug_to_prepare_to_store (void)
2449 debug_target
.to_prepare_to_store ();
2451 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
2455 debug_to_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
2456 struct mem_attrib
*attrib
,
2457 struct target_ops
*target
)
2461 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
,
2464 fprintf_unfiltered (gdb_stdlog
,
2465 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
2466 (unsigned int) memaddr
, /* possable truncate long long */
2467 len
, write
? "write" : "read", retval
);
2475 fputs_unfiltered (", bytes =", gdb_stdlog
);
2476 for (i
= 0; i
< retval
; i
++)
2478 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
2479 fprintf_unfiltered (gdb_stdlog
, "\n");
2480 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
2484 fputc_unfiltered ('\n', gdb_stdlog
);
2490 debug_to_files_info (struct target_ops
*target
)
2492 debug_target
.to_files_info (target
);
2494 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
2498 debug_to_insert_breakpoint (CORE_ADDR addr
, char *save
)
2502 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
2504 fprintf_unfiltered (gdb_stdlog
,
2505 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
2506 (unsigned long) addr
,
2507 (unsigned long) retval
);
2512 debug_to_remove_breakpoint (CORE_ADDR addr
, char *save
)
2516 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
2518 fprintf_unfiltered (gdb_stdlog
,
2519 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
2520 (unsigned long) addr
,
2521 (unsigned long) retval
);
2526 debug_to_terminal_init (void)
2528 debug_target
.to_terminal_init ();
2530 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
2534 debug_to_terminal_inferior (void)
2536 debug_target
.to_terminal_inferior ();
2538 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
2542 debug_to_terminal_ours_for_output (void)
2544 debug_target
.to_terminal_ours_for_output ();
2546 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
2550 debug_to_terminal_ours (void)
2552 debug_target
.to_terminal_ours ();
2554 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
2558 debug_to_terminal_info (char *arg
, int from_tty
)
2560 debug_target
.to_terminal_info (arg
, from_tty
);
2562 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
2567 debug_to_kill (void)
2569 debug_target
.to_kill ();
2571 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
2575 debug_to_load (char *args
, int from_tty
)
2577 debug_target
.to_load (args
, from_tty
);
2579 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
2583 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
2587 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
2589 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
2595 debug_to_create_inferior (char *exec_file
, char *args
, char **env
)
2597 debug_target
.to_create_inferior (exec_file
, args
, env
);
2599 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx)\n",
2604 debug_to_post_startup_inferior (ptid_t ptid
)
2606 debug_target
.to_post_startup_inferior (ptid
);
2608 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
2613 debug_to_acknowledge_created_inferior (int pid
)
2615 debug_target
.to_acknowledge_created_inferior (pid
);
2617 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
2622 debug_to_clone_and_follow_inferior (int child_pid
, int *followed_child
)
2624 debug_target
.to_clone_and_follow_inferior (child_pid
, followed_child
);
2626 fprintf_unfiltered (gdb_stdlog
,
2627 "target_clone_and_follow_inferior (%d, %d)\n",
2628 child_pid
, *followed_child
);
2632 debug_to_post_follow_inferior_by_clone (void)
2634 debug_target
.to_post_follow_inferior_by_clone ();
2636 fprintf_unfiltered (gdb_stdlog
, "target_post_follow_inferior_by_clone ()\n");
2640 debug_to_insert_fork_catchpoint (int pid
)
2644 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
2646 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
2653 debug_to_remove_fork_catchpoint (int pid
)
2657 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
2659 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
2666 debug_to_insert_vfork_catchpoint (int pid
)
2670 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
2672 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)= %d\n",
2679 debug_to_remove_vfork_catchpoint (int pid
)
2683 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
2685 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
2692 debug_to_has_forked (int pid
, int *child_pid
)
2696 has_forked
= debug_target
.to_has_forked (pid
, child_pid
);
2698 fprintf_unfiltered (gdb_stdlog
, "target_has_forked (%d, %d) = %d\n",
2699 pid
, *child_pid
, has_forked
);
2705 debug_to_has_vforked (int pid
, int *child_pid
)
2709 has_vforked
= debug_target
.to_has_vforked (pid
, child_pid
);
2711 fprintf_unfiltered (gdb_stdlog
, "target_has_vforked (%d, %d) = %d\n",
2712 pid
, *child_pid
, has_vforked
);
2718 debug_to_can_follow_vfork_prior_to_exec (void)
2720 int can_immediately_follow_vfork
;
2722 can_immediately_follow_vfork
= debug_target
.to_can_follow_vfork_prior_to_exec ();
2724 fprintf_unfiltered (gdb_stdlog
, "target_can_follow_vfork_prior_to_exec () = %d\n",
2725 can_immediately_follow_vfork
);
2727 return can_immediately_follow_vfork
;
2731 debug_to_post_follow_vfork (int parent_pid
, int followed_parent
, int child_pid
,
2734 debug_target
.to_post_follow_vfork (parent_pid
, followed_parent
, child_pid
, followed_child
);
2736 fprintf_unfiltered (gdb_stdlog
,
2737 "target_post_follow_vfork (%d, %d, %d, %d)\n",
2738 parent_pid
, followed_parent
, child_pid
, followed_child
);
2742 debug_to_insert_exec_catchpoint (int pid
)
2746 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
2748 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
2755 debug_to_remove_exec_catchpoint (int pid
)
2759 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
2761 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2768 debug_to_has_execd (int pid
, char **execd_pathname
)
2772 has_execd
= debug_target
.to_has_execd (pid
, execd_pathname
);
2774 fprintf_unfiltered (gdb_stdlog
, "target_has_execd (%d, %s) = %d\n",
2775 pid
, (*execd_pathname
? *execd_pathname
: "<NULL>"),
2782 debug_to_reported_exec_events_per_exec_call (void)
2784 int reported_exec_events
;
2786 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2788 fprintf_unfiltered (gdb_stdlog
,
2789 "target_reported_exec_events_per_exec_call () = %d\n",
2790 reported_exec_events
);
2792 return reported_exec_events
;
2796 debug_to_has_syscall_event (int pid
, enum target_waitkind
*kind
,
2799 int has_syscall_event
;
2800 char *kind_spelling
= "??";
2802 has_syscall_event
= debug_target
.to_has_syscall_event (pid
, kind
, syscall_id
);
2803 if (has_syscall_event
)
2807 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2808 kind_spelling
= "SYSCALL_ENTRY";
2810 case TARGET_WAITKIND_SYSCALL_RETURN
:
2811 kind_spelling
= "SYSCALL_RETURN";
2818 fprintf_unfiltered (gdb_stdlog
,
2819 "target_has_syscall_event (%d, %s, %d) = %d\n",
2820 pid
, kind_spelling
, *syscall_id
, has_syscall_event
);
2822 return has_syscall_event
;
2826 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
2830 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2832 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2833 pid
, wait_status
, *exit_status
, has_exited
);
2839 debug_to_mourn_inferior (void)
2841 debug_target
.to_mourn_inferior ();
2843 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2847 debug_to_can_run (void)
2851 retval
= debug_target
.to_can_run ();
2853 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2859 debug_to_notice_signals (ptid_t ptid
)
2861 debug_target
.to_notice_signals (ptid
);
2863 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n",
2868 debug_to_thread_alive (ptid_t ptid
)
2872 retval
= debug_target
.to_thread_alive (ptid
);
2874 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2875 PIDGET (ptid
), retval
);
2881 debug_to_find_new_threads (void)
2883 debug_target
.to_find_new_threads ();
2885 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog
);
2889 debug_to_stop (void)
2891 debug_target
.to_stop ();
2893 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2897 debug_to_query (int type
, char *req
, char *resp
, int *siz
)
2901 retval
= debug_target
.to_query (type
, req
, resp
, siz
);
2903 fprintf_unfiltered (gdb_stdlog
, "target_query (%c, %s, %s, %d) = %d\n", type
, req
, resp
, *siz
, retval
);
2909 debug_to_rcmd (char *command
,
2910 struct ui_file
*outbuf
)
2912 debug_target
.to_rcmd (command
, outbuf
);
2913 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2916 static struct symtab_and_line
*
2917 debug_to_enable_exception_callback (enum exception_event_kind kind
, int enable
)
2919 struct symtab_and_line
*result
;
2920 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2921 fprintf_unfiltered (gdb_stdlog
,
2922 "target get_exception_callback_sal (%d, %d)\n",
2927 static struct exception_event_record
*
2928 debug_to_get_current_exception_event (void)
2930 struct exception_event_record
*result
;
2931 result
= debug_target
.to_get_current_exception_event ();
2932 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2937 debug_to_pid_to_exec_file (int pid
)
2941 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2943 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2950 setup_target_debug (void)
2952 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2954 current_target
.to_open
= debug_to_open
;
2955 current_target
.to_close
= debug_to_close
;
2956 current_target
.to_attach
= debug_to_attach
;
2957 current_target
.to_post_attach
= debug_to_post_attach
;
2958 current_target
.to_require_attach
= debug_to_require_attach
;
2959 current_target
.to_detach
= debug_to_detach
;
2960 current_target
.to_require_detach
= debug_to_require_detach
;
2961 current_target
.to_resume
= debug_to_resume
;
2962 current_target
.to_wait
= debug_to_wait
;
2963 current_target
.to_post_wait
= debug_to_post_wait
;
2964 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2965 current_target
.to_store_registers
= debug_to_store_registers
;
2966 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2967 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2968 current_target
.to_files_info
= debug_to_files_info
;
2969 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2970 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2971 current_target
.to_terminal_init
= debug_to_terminal_init
;
2972 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2973 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2974 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2975 current_target
.to_terminal_info
= debug_to_terminal_info
;
2976 current_target
.to_kill
= debug_to_kill
;
2977 current_target
.to_load
= debug_to_load
;
2978 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2979 current_target
.to_create_inferior
= debug_to_create_inferior
;
2980 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2981 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2982 current_target
.to_clone_and_follow_inferior
= debug_to_clone_and_follow_inferior
;
2983 current_target
.to_post_follow_inferior_by_clone
= debug_to_post_follow_inferior_by_clone
;
2984 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2985 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2986 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2987 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2988 current_target
.to_has_forked
= debug_to_has_forked
;
2989 current_target
.to_has_vforked
= debug_to_has_vforked
;
2990 current_target
.to_can_follow_vfork_prior_to_exec
= debug_to_can_follow_vfork_prior_to_exec
;
2991 current_target
.to_post_follow_vfork
= debug_to_post_follow_vfork
;
2992 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2993 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2994 current_target
.to_has_execd
= debug_to_has_execd
;
2995 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2996 current_target
.to_has_syscall_event
= debug_to_has_syscall_event
;
2997 current_target
.to_has_exited
= debug_to_has_exited
;
2998 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2999 current_target
.to_can_run
= debug_to_can_run
;
3000 current_target
.to_notice_signals
= debug_to_notice_signals
;
3001 current_target
.to_thread_alive
= debug_to_thread_alive
;
3002 current_target
.to_find_new_threads
= debug_to_find_new_threads
;
3003 current_target
.to_stop
= debug_to_stop
;
3004 current_target
.to_query
= debug_to_query
;
3005 current_target
.to_rcmd
= debug_to_rcmd
;
3006 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
3007 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
3008 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
3013 static char targ_desc
[] =
3014 "Names of targets and files being debugged.\n\
3015 Shows the entire stack of targets currently in use (including the exec-file,\n\
3016 core-file, and process, if any), as well as the symbol file name.";
3019 do_monitor_command (char *cmd
,
3022 if ((current_target
.to_rcmd
3023 == (void (*) (char *, struct ui_file
*)) tcomplain
)
3024 || (current_target
.to_rcmd
== debug_to_rcmd
3025 && (debug_target
.to_rcmd
3026 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
3028 error ("\"monitor\" command not supported by this target.\n");
3030 target_rcmd (cmd
, gdb_stdtarg
);
3034 initialize_targets (void)
3036 init_dummy_target ();
3037 push_target (&dummy_target
);
3039 add_info ("target", target_info
, targ_desc
);
3040 add_info ("files", target_info
, targ_desc
);
3043 add_set_cmd ("target", class_maintenance
, var_zinteger
,
3044 (char *) &targetdebug
,
3045 "Set target debugging.\n\
3046 When non-zero, target debugging is enabled.", &setdebuglist
),
3050 add_com ("monitor", class_obscure
, do_monitor_command
,
3051 "Send a command to the remote monitor (remote targets only).");
3053 target_dcache
= dcache_init();
3055 if (!STREQ (signals
[TARGET_SIGNAL_LAST
].string
, "TARGET_SIGNAL_MAGIC"))
3056 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");