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 (void (*) (char *, struct ui_file
*))
494 de_fault (to_enable_exception_callback
,
495 (struct symtab_and_line
* (*) (enum exception_event_kind
, int))
497 de_fault (to_get_current_exception_event
,
498 (struct exception_event_record
* (*) (void))
500 de_fault (to_pid_to_exec_file
,
503 de_fault (to_can_async_p
,
506 de_fault (to_is_async_p
,
510 (void (*) (void (*) (enum inferior_event_type
, void*), void*))
515 /* Go through the target stack from top to bottom, copying over zero entries in
516 current_target. In effect, we are doing class inheritance through the
517 pushed target vectors. */
520 update_current_target (void)
522 struct target_stack_item
*item
;
523 struct target_ops
*t
;
525 /* First, reset current_target */
526 memset (¤t_target
, 0, sizeof current_target
);
528 for (item
= target_stack
; item
; item
= item
->next
)
530 t
= item
->target_ops
;
532 #define INHERIT(FIELD, TARGET) \
533 if (!current_target.FIELD) \
534 current_target.FIELD = TARGET->FIELD
536 INHERIT (to_shortname
, t
);
537 INHERIT (to_longname
, t
);
539 INHERIT (to_open
, t
);
540 INHERIT (to_close
, t
);
541 INHERIT (to_attach
, t
);
542 INHERIT (to_post_attach
, t
);
543 INHERIT (to_require_attach
, t
);
544 INHERIT (to_detach
, t
);
545 INHERIT (to_require_detach
, t
);
546 INHERIT (to_resume
, t
);
547 INHERIT (to_wait
, t
);
548 INHERIT (to_post_wait
, t
);
549 INHERIT (to_fetch_registers
, t
);
550 INHERIT (to_store_registers
, t
);
551 INHERIT (to_prepare_to_store
, t
);
552 INHERIT (to_xfer_memory
, t
);
553 INHERIT (to_files_info
, t
);
554 INHERIT (to_insert_breakpoint
, t
);
555 INHERIT (to_remove_breakpoint
, t
);
556 INHERIT (to_terminal_init
, t
);
557 INHERIT (to_terminal_inferior
, t
);
558 INHERIT (to_terminal_ours_for_output
, t
);
559 INHERIT (to_terminal_ours
, t
);
560 INHERIT (to_terminal_info
, t
);
561 INHERIT (to_kill
, t
);
562 INHERIT (to_load
, t
);
563 INHERIT (to_lookup_symbol
, t
);
564 INHERIT (to_create_inferior
, t
);
565 INHERIT (to_post_startup_inferior
, t
);
566 INHERIT (to_acknowledge_created_inferior
, t
);
567 INHERIT (to_clone_and_follow_inferior
, t
);
568 INHERIT (to_post_follow_inferior_by_clone
, t
);
569 INHERIT (to_insert_fork_catchpoint
, t
);
570 INHERIT (to_remove_fork_catchpoint
, t
);
571 INHERIT (to_insert_vfork_catchpoint
, t
);
572 INHERIT (to_remove_vfork_catchpoint
, t
);
573 INHERIT (to_has_forked
, t
);
574 INHERIT (to_has_vforked
, t
);
575 INHERIT (to_can_follow_vfork_prior_to_exec
, t
);
576 INHERIT (to_post_follow_vfork
, t
);
577 INHERIT (to_insert_exec_catchpoint
, t
);
578 INHERIT (to_remove_exec_catchpoint
, t
);
579 INHERIT (to_has_execd
, t
);
580 INHERIT (to_reported_exec_events_per_exec_call
, t
);
581 INHERIT (to_has_syscall_event
, t
);
582 INHERIT (to_has_exited
, t
);
583 INHERIT (to_mourn_inferior
, t
);
584 INHERIT (to_can_run
, t
);
585 INHERIT (to_notice_signals
, t
);
586 INHERIT (to_thread_alive
, t
);
587 INHERIT (to_find_new_threads
, t
);
588 INHERIT (to_pid_to_str
, t
);
589 INHERIT (to_extra_thread_info
, t
);
590 INHERIT (to_stop
, t
);
591 INHERIT (to_query
, t
);
592 INHERIT (to_rcmd
, t
);
593 INHERIT (to_enable_exception_callback
, t
);
594 INHERIT (to_get_current_exception_event
, t
);
595 INHERIT (to_pid_to_exec_file
, t
);
596 INHERIT (to_stratum
, t
);
597 INHERIT (DONT_USE
, t
);
598 INHERIT (to_has_all_memory
, t
);
599 INHERIT (to_has_memory
, t
);
600 INHERIT (to_has_stack
, t
);
601 INHERIT (to_has_registers
, t
);
602 INHERIT (to_has_execution
, t
);
603 INHERIT (to_has_thread_control
, t
);
604 INHERIT (to_sections
, t
);
605 INHERIT (to_sections_end
, t
);
606 INHERIT (to_can_async_p
, t
);
607 INHERIT (to_is_async_p
, t
);
608 INHERIT (to_async
, t
);
609 INHERIT (to_async_mask_value
, t
);
610 INHERIT (to_magic
, t
);
616 /* Push a new target type into the stack of the existing target accessors,
617 possibly superseding some of the existing accessors.
619 Result is zero if the pushed target ended up on top of the stack,
620 nonzero if at least one target is on top of it.
622 Rather than allow an empty stack, we always have the dummy target at
623 the bottom stratum, so we can call the function vectors without
627 push_target (struct target_ops
*t
)
629 struct target_stack_item
*cur
, *prev
, *tmp
;
631 /* Check magic number. If wrong, it probably means someone changed
632 the struct definition, but not all the places that initialize one. */
633 if (t
->to_magic
!= OPS_MAGIC
)
635 fprintf_unfiltered (gdb_stderr
,
636 "Magic number of %s target struct wrong\n",
638 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
641 /* Find the proper stratum to install this target in. */
643 for (prev
= NULL
, cur
= target_stack
; cur
; prev
= cur
, cur
= cur
->next
)
645 if ((int) (t
->to_stratum
) >= (int) (cur
->target_ops
->to_stratum
))
649 /* If there's already targets at this stratum, remove them. */
652 while (t
->to_stratum
== cur
->target_ops
->to_stratum
)
654 /* There's already something on this stratum. Close it off. */
655 if (cur
->target_ops
->to_close
)
656 (cur
->target_ops
->to_close
) (0);
658 prev
->next
= cur
->next
; /* Unchain old target_ops */
660 target_stack
= cur
->next
; /* Unchain first on list */
666 /* We have removed all targets in our stratum, now add the new one. */
668 tmp
= (struct target_stack_item
*)
669 xmalloc (sizeof (struct target_stack_item
));
678 update_current_target ();
680 cleanup_target (¤t_target
); /* Fill in the gaps */
683 setup_target_debug ();
688 /* Remove a target_ops vector from the stack, wherever it may be.
689 Return how many times it was removed (0 or 1). */
692 unpush_target (struct target_ops
*t
)
694 struct target_stack_item
*cur
, *prev
;
697 t
->to_close (0); /* Let it clean up */
699 /* Look for the specified target. Note that we assume that a target
700 can only occur once in the target stack. */
702 for (cur
= target_stack
, prev
= NULL
; cur
; prev
= cur
, cur
= cur
->next
)
703 if (cur
->target_ops
== t
)
707 return 0; /* Didn't find target_ops, quit now */
709 /* Unchain the target */
712 target_stack
= cur
->next
;
714 prev
->next
= cur
->next
;
716 xfree (cur
); /* Release the target_stack_item */
718 update_current_target ();
719 cleanup_target (¤t_target
);
727 (current_target
.to_close
) (0); /* Let it clean up */
728 if (unpush_target (target_stack
->target_ops
) == 1)
731 fprintf_unfiltered (gdb_stderr
,
732 "pop_target couldn't find target %s\n",
733 current_target
.to_shortname
);
734 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
738 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
740 /* target_read_string -- read a null terminated string, up to LEN bytes,
741 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
742 Set *STRING to a pointer to malloc'd memory containing the data; the caller
743 is responsible for freeing it. Return the number of bytes successfully
747 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
749 int tlen
, origlen
, offset
, i
;
753 int buffer_allocated
;
755 unsigned int nbytes_read
= 0;
757 /* Small for testing. */
758 buffer_allocated
= 4;
759 buffer
= xmalloc (buffer_allocated
);
766 tlen
= MIN (len
, 4 - (memaddr
& 3));
767 offset
= memaddr
& 3;
769 errcode
= target_xfer_memory (memaddr
& ~3, buf
, 4, 0);
772 /* The transfer request might have crossed the boundary to an
773 unallocated region of memory. Retry the transfer, requesting
777 errcode
= target_xfer_memory (memaddr
, buf
, 1, 0);
782 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
785 bytes
= bufptr
- buffer
;
786 buffer_allocated
*= 2;
787 buffer
= xrealloc (buffer
, buffer_allocated
);
788 bufptr
= buffer
+ bytes
;
791 for (i
= 0; i
< tlen
; i
++)
793 *bufptr
++ = buf
[i
+ offset
];
794 if (buf
[i
+ offset
] == '\000')
796 nbytes_read
+= i
+ 1;
813 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
814 GDB's memory at MYADDR. Returns either 0 for success or an errno value
817 If an error occurs, no guarantee is made about the contents of the data at
818 MYADDR. In particular, the caller should not depend upon partial reads
819 filling the buffer with good data. There is no way for the caller to know
820 how much good data might have been transfered anyway. Callers that can
821 deal with partial reads should call target_read_memory_partial. */
824 target_read_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
826 return target_xfer_memory (memaddr
, myaddr
, len
, 0);
830 target_write_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
832 return target_xfer_memory (memaddr
, myaddr
, len
, 1);
835 /* Move memory to or from the targets. The top target gets priority;
836 if it cannot handle it, it is offered to the next one down, etc.
838 Result is -1 on error, or the number of bytes transfered. */
841 do_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
842 struct mem_attrib
*attrib
)
846 struct target_ops
*t
;
847 struct target_stack_item
*item
;
849 /* Zero length requests are ok and require no work. */
853 /* to_xfer_memory is not guaranteed to set errno, even when it returns
857 /* The quick case is that the top target can handle the transfer. */
858 res
= current_target
.to_xfer_memory
859 (memaddr
, myaddr
, len
, write
, attrib
, ¤t_target
);
861 /* If res <= 0 then we call it again in the loop. Ah well. */
864 for (item
= target_stack
; item
; item
= item
->next
)
866 t
= item
->target_ops
;
867 if (!t
->to_has_memory
)
870 res
= t
->to_xfer_memory (memaddr
, myaddr
, len
, write
, attrib
, t
);
872 break; /* Handled all or part of xfer */
873 if (t
->to_has_all_memory
)
885 /* Perform a memory transfer. Iterate until the entire region has
888 Result is 0 or errno value. */
891 target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
)
895 struct mem_region
*region
;
897 /* Zero length requests are ok and require no work. */
905 region
= lookup_mem_region(memaddr
);
906 if (memaddr
+ len
< region
->hi
)
909 reg_len
= region
->hi
- memaddr
;
911 switch (region
->attrib
.mode
)
926 if (region
->attrib
.cache
)
927 res
= dcache_xfer_memory(target_dcache
, memaddr
, myaddr
,
930 res
= do_xfer_memory(memaddr
, myaddr
, reg_len
, write
,
935 /* If this address is for nonexistent memory, read zeros
936 if reading, or do nothing if writing. Return
939 memset (myaddr
, 0, len
);
953 return 0; /* We managed to cover it all somehow. */
957 /* Perform a partial memory transfer.
959 Result is -1 on error, or the number of bytes transfered. */
962 target_xfer_memory_partial (CORE_ADDR memaddr
, char *myaddr
, int len
,
963 int write_p
, int *err
)
967 struct mem_region
*region
;
969 /* Zero length requests are ok and require no work. */
976 region
= lookup_mem_region(memaddr
);
977 if (memaddr
+ len
< region
->hi
)
980 reg_len
= region
->hi
- memaddr
;
982 switch (region
->attrib
.mode
)
1001 if (region
->attrib
.cache
)
1002 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
,
1005 res
= do_xfer_memory (memaddr
, myaddr
, reg_len
, write_p
,
1023 target_read_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1025 return target_xfer_memory_partial (memaddr
, buf
, len
, 0, err
);
1029 target_write_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1031 return target_xfer_memory_partial (memaddr
, buf
, len
, 1, err
);
1036 target_info (char *args
, int from_tty
)
1038 struct target_ops
*t
;
1039 struct target_stack_item
*item
;
1040 int has_all_mem
= 0;
1042 if (symfile_objfile
!= NULL
)
1043 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
1045 #ifdef FILES_INFO_HOOK
1046 if (FILES_INFO_HOOK ())
1050 for (item
= target_stack
; item
; item
= item
->next
)
1052 t
= item
->target_ops
;
1054 if (!t
->to_has_memory
)
1057 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
1060 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1061 printf_unfiltered ("%s:\n", t
->to_longname
);
1062 (t
->to_files_info
) (t
);
1063 has_all_mem
= t
->to_has_all_memory
;
1067 /* This is to be called by the open routine before it does
1071 target_preopen (int from_tty
)
1075 if (target_has_execution
)
1078 || query ("A program is being debugged already. Kill it? "))
1081 error ("Program not killed.");
1084 /* Calling target_kill may remove the target from the stack. But if
1085 it doesn't (which seems like a win for UDI), remove it now. */
1087 if (target_has_execution
)
1091 /* Detach a target after doing deferred register stores. */
1094 target_detach (char *args
, int from_tty
)
1096 /* Handle any optimized stores to the inferior. */
1097 #ifdef DO_DEFERRED_STORES
1100 (current_target
.to_detach
) (args
, from_tty
);
1104 target_link (char *modname
, CORE_ADDR
*t_reloc
)
1106 if (STREQ (current_target
.to_shortname
, "rombug"))
1108 (current_target
.to_lookup_symbol
) (modname
, t_reloc
);
1110 error ("Unable to link to %s and get relocation in rombug", modname
);
1113 *t_reloc
= (CORE_ADDR
) -1;
1117 target_async_mask (int mask
)
1119 int saved_async_masked_status
= target_async_mask_value
;
1120 target_async_mask_value
= mask
;
1121 return saved_async_masked_status
;
1124 /* Look through the list of possible targets for a target that can
1125 execute a run or attach command without any other data. This is
1126 used to locate the default process stratum.
1128 Result is always valid (error() is called for errors). */
1130 static struct target_ops
*
1131 find_default_run_target (char *do_mesg
)
1133 struct target_ops
**t
;
1134 struct target_ops
*runable
= NULL
;
1139 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1142 if ((*t
)->to_can_run
&& target_can_run (*t
))
1150 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
1156 find_default_attach (char *args
, int from_tty
)
1158 struct target_ops
*t
;
1160 t
= find_default_run_target ("attach");
1161 (t
->to_attach
) (args
, from_tty
);
1166 find_default_require_attach (char *args
, int from_tty
)
1168 struct target_ops
*t
;
1170 t
= find_default_run_target ("require_attach");
1171 (t
->to_require_attach
) (args
, from_tty
);
1176 find_default_require_detach (int pid
, char *args
, int from_tty
)
1178 struct target_ops
*t
;
1180 t
= find_default_run_target ("require_detach");
1181 (t
->to_require_detach
) (pid
, args
, from_tty
);
1186 find_default_create_inferior (char *exec_file
, char *allargs
, char **env
)
1188 struct target_ops
*t
;
1190 t
= find_default_run_target ("run");
1191 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
1196 find_default_clone_and_follow_inferior (int child_pid
, int *followed_child
)
1198 struct target_ops
*t
;
1200 t
= find_default_run_target ("run");
1201 (t
->to_clone_and_follow_inferior
) (child_pid
, followed_child
);
1218 * Resize the to_sections pointer. Also make sure that anyone that
1219 * was holding on to an old value of it gets updated.
1220 * Returns the old size.
1224 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1226 struct target_ops
**t
;
1227 struct section_table
*old_value
;
1230 old_value
= target
->to_sections
;
1232 if (target
->to_sections
)
1234 old_count
= target
->to_sections_end
- target
->to_sections
;
1235 target
->to_sections
= (struct section_table
*)
1236 xrealloc ((char *) target
->to_sections
,
1237 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1242 target
->to_sections
= (struct section_table
*)
1243 xmalloc ((sizeof (struct section_table
)) * num_added
);
1245 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1247 /* Check to see if anyone else was pointing to this structure.
1248 If old_value was null, then no one was. */
1252 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1255 if ((*t
)->to_sections
== old_value
)
1257 (*t
)->to_sections
= target
->to_sections
;
1258 (*t
)->to_sections_end
= target
->to_sections_end
;
1267 /* Remove all target sections taken from ABFD.
1269 Scan the current target stack for targets whose section tables
1270 refer to sections from BFD, and remove those sections. We use this
1271 when we notice that the inferior has unloaded a shared object, for
1274 remove_target_sections (bfd
*abfd
)
1276 struct target_ops
**t
;
1278 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; t
++)
1280 struct section_table
*src
, *dest
;
1282 dest
= (*t
)->to_sections
;
1283 for (src
= (*t
)->to_sections
; src
< (*t
)->to_sections_end
; src
++)
1284 if (src
->bfd
!= abfd
)
1286 /* Keep this section. */
1287 if (dest
< src
) *dest
= *src
;
1291 /* If we've dropped any sections, resize the section table. */
1293 target_resize_to_sections (*t
, dest
- src
);
1300 /* Find a single runnable target in the stack and return it. If for
1301 some reason there is more than one, return NULL. */
1304 find_run_target (void)
1306 struct target_ops
**t
;
1307 struct target_ops
*runable
= NULL
;
1312 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1314 if ((*t
)->to_can_run
&& target_can_run (*t
))
1321 return (count
== 1 ? runable
: NULL
);
1324 /* Find a single core_stratum target in the list of targets and return it.
1325 If for some reason there is more than one, return NULL. */
1328 find_core_target (void)
1330 struct target_ops
**t
;
1331 struct target_ops
*runable
= NULL
;
1336 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1339 if ((*t
)->to_stratum
== core_stratum
)
1346 return (count
== 1 ? runable
: NULL
);
1350 * Find the next target down the stack from the specified target.
1354 find_target_beneath (struct target_ops
*t
)
1356 struct target_stack_item
*cur
;
1358 for (cur
= target_stack
; cur
; cur
= cur
->next
)
1359 if (cur
->target_ops
== t
)
1362 if (cur
== NULL
|| cur
->next
== NULL
)
1365 return cur
->next
->target_ops
;
1369 /* The inferior process has died. Long live the inferior! */
1372 generic_mourn_inferior (void)
1374 extern int show_breakpoint_hit_counts
;
1376 inferior_ptid
= null_ptid
;
1378 breakpoint_init_inferior (inf_exited
);
1379 registers_changed ();
1381 #ifdef CLEAR_DEFERRED_STORES
1382 /* Delete any pending stores to the inferior... */
1383 CLEAR_DEFERRED_STORES
;
1386 reopen_exec_file ();
1387 reinit_frame_cache ();
1389 /* It is confusing to the user for ignore counts to stick around
1390 from previous runs of the inferior. So clear them. */
1391 /* However, it is more confusing for the ignore counts to disappear when
1392 using hit counts. So don't clear them if we're counting hits. */
1393 if (!show_breakpoint_hit_counts
)
1394 breakpoint_clear_ignore_counts ();
1400 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1401 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1402 translation of that in OURSTATUS. */
1404 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
1406 #ifdef CHILD_SPECIAL_WAITSTATUS
1407 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1408 if it wants to deal with hoststatus. */
1409 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
1413 if (WIFEXITED (hoststatus
))
1415 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1416 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
1418 else if (!WIFSTOPPED (hoststatus
))
1420 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1421 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
1425 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
1426 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
1430 /* Returns zero to leave the inferior alone, one to interrupt it. */
1431 int (*target_activity_function
) (void);
1432 int target_activity_fd
;
1434 /* Convert a normal process ID to a string. Returns the string in a static
1438 normal_pid_to_str (ptid_t ptid
)
1440 static char buf
[30];
1442 sprintf (buf
, "process %d", PIDGET (ptid
));
1446 /* Some targets (such as ttrace-based HPUX) don't allow us to request
1447 notification of inferior events such as fork and vork immediately
1448 after the inferior is created. (This because of how gdb gets an
1449 inferior created via invoking a shell to do it. In such a scenario,
1450 if the shell init file has commands in it, the shell will fork and
1451 exec for each of those commands, and we will see each such fork
1454 This function is used by all targets that allow us to request
1455 notification of forks, etc at inferior creation time; e.g., in
1456 target_acknowledge_forked_child.
1459 normal_target_post_startup_inferior (ptid_t ptid
)
1461 /* This space intentionally left blank. */
1464 /* Set up the handful of non-empty slots needed by the dummy target
1468 init_dummy_target (void)
1470 dummy_target
.to_shortname
= "None";
1471 dummy_target
.to_longname
= "None";
1472 dummy_target
.to_doc
= "";
1473 dummy_target
.to_attach
= find_default_attach
;
1474 dummy_target
.to_require_attach
= find_default_require_attach
;
1475 dummy_target
.to_require_detach
= find_default_require_detach
;
1476 dummy_target
.to_create_inferior
= find_default_create_inferior
;
1477 dummy_target
.to_clone_and_follow_inferior
= find_default_clone_and_follow_inferior
;
1478 dummy_target
.to_pid_to_str
= normal_pid_to_str
;
1479 dummy_target
.to_stratum
= dummy_stratum
;
1480 dummy_target
.to_magic
= OPS_MAGIC
;
1484 static struct target_ops debug_target
;
1487 debug_to_open (char *args
, int from_tty
)
1489 debug_target
.to_open (args
, from_tty
);
1491 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
1495 debug_to_close (int quitting
)
1497 debug_target
.to_close (quitting
);
1499 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
1503 debug_to_attach (char *args
, int from_tty
)
1505 debug_target
.to_attach (args
, from_tty
);
1507 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
1512 debug_to_post_attach (int pid
)
1514 debug_target
.to_post_attach (pid
);
1516 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
1520 debug_to_require_attach (char *args
, int from_tty
)
1522 debug_target
.to_require_attach (args
, from_tty
);
1524 fprintf_unfiltered (gdb_stdlog
,
1525 "target_require_attach (%s, %d)\n", args
, from_tty
);
1529 debug_to_detach (char *args
, int from_tty
)
1531 debug_target
.to_detach (args
, from_tty
);
1533 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
1537 debug_to_require_detach (int pid
, char *args
, int from_tty
)
1539 debug_target
.to_require_detach (pid
, args
, from_tty
);
1541 fprintf_unfiltered (gdb_stdlog
,
1542 "target_require_detach (%d, %s, %d)\n", pid
, args
, from_tty
);
1546 debug_to_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
1548 debug_target
.to_resume (ptid
, step
, siggnal
);
1550 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", PIDGET (ptid
),
1551 step
? "step" : "continue",
1552 target_signal_to_name (siggnal
));
1556 debug_to_wait (ptid_t ptid
, struct target_waitstatus
*status
)
1560 retval
= debug_target
.to_wait (ptid
, status
);
1562 fprintf_unfiltered (gdb_stdlog
,
1563 "target_wait (%d, status) = %d, ", PIDGET (ptid
),
1565 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
1566 switch (status
->kind
)
1568 case TARGET_WAITKIND_EXITED
:
1569 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
1570 status
->value
.integer
);
1572 case TARGET_WAITKIND_STOPPED
:
1573 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
1574 target_signal_to_name (status
->value
.sig
));
1576 case TARGET_WAITKIND_SIGNALLED
:
1577 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
1578 target_signal_to_name (status
->value
.sig
));
1580 case TARGET_WAITKIND_LOADED
:
1581 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
1583 case TARGET_WAITKIND_FORKED
:
1584 fprintf_unfiltered (gdb_stdlog
, "forked\n");
1586 case TARGET_WAITKIND_VFORKED
:
1587 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
1589 case TARGET_WAITKIND_EXECD
:
1590 fprintf_unfiltered (gdb_stdlog
, "execd\n");
1592 case TARGET_WAITKIND_SPURIOUS
:
1593 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
1596 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
1604 debug_to_post_wait (ptid_t ptid
, int status
)
1606 debug_target
.to_post_wait (ptid
, status
);
1608 fprintf_unfiltered (gdb_stdlog
, "target_post_wait (%d, %d)\n",
1609 PIDGET (ptid
), status
);
1613 debug_to_fetch_registers (int regno
)
1615 debug_target
.to_fetch_registers (regno
);
1617 fprintf_unfiltered (gdb_stdlog
, "target_fetch_registers (%s)",
1618 regno
!= -1 ? REGISTER_NAME (regno
) : "-1");
1620 fprintf_unfiltered (gdb_stdlog
, " = 0x%lx %ld",
1621 (unsigned long) read_register (regno
),
1622 (unsigned long) read_register (regno
));
1623 fprintf_unfiltered (gdb_stdlog
, "\n");
1627 debug_to_store_registers (int regno
)
1629 debug_target
.to_store_registers (regno
);
1631 if (regno
>= 0 && regno
< NUM_REGS
)
1632 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%s) = 0x%lx %ld\n",
1633 REGISTER_NAME (regno
),
1634 (unsigned long) read_register (regno
),
1635 (unsigned long) read_register (regno
));
1637 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%d)\n", regno
);
1641 debug_to_prepare_to_store (void)
1643 debug_target
.to_prepare_to_store ();
1645 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
1649 debug_to_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
1650 struct mem_attrib
*attrib
,
1651 struct target_ops
*target
)
1655 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
,
1658 fprintf_unfiltered (gdb_stdlog
,
1659 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
1660 (unsigned int) memaddr
, /* possable truncate long long */
1661 len
, write
? "write" : "read", retval
);
1669 fputs_unfiltered (", bytes =", gdb_stdlog
);
1670 for (i
= 0; i
< retval
; i
++)
1672 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
1673 fprintf_unfiltered (gdb_stdlog
, "\n");
1674 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1678 fputc_unfiltered ('\n', gdb_stdlog
);
1684 debug_to_files_info (struct target_ops
*target
)
1686 debug_target
.to_files_info (target
);
1688 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
1692 debug_to_insert_breakpoint (CORE_ADDR addr
, char *save
)
1696 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
1698 fprintf_unfiltered (gdb_stdlog
,
1699 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
1700 (unsigned long) addr
,
1701 (unsigned long) retval
);
1706 debug_to_remove_breakpoint (CORE_ADDR addr
, char *save
)
1710 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
1712 fprintf_unfiltered (gdb_stdlog
,
1713 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
1714 (unsigned long) addr
,
1715 (unsigned long) retval
);
1720 debug_to_terminal_init (void)
1722 debug_target
.to_terminal_init ();
1724 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
1728 debug_to_terminal_inferior (void)
1730 debug_target
.to_terminal_inferior ();
1732 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
1736 debug_to_terminal_ours_for_output (void)
1738 debug_target
.to_terminal_ours_for_output ();
1740 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
1744 debug_to_terminal_ours (void)
1746 debug_target
.to_terminal_ours ();
1748 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
1752 debug_to_terminal_info (char *arg
, int from_tty
)
1754 debug_target
.to_terminal_info (arg
, from_tty
);
1756 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
1761 debug_to_kill (void)
1763 debug_target
.to_kill ();
1765 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
1769 debug_to_load (char *args
, int from_tty
)
1771 debug_target
.to_load (args
, from_tty
);
1773 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
1777 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
1781 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
1783 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
1789 debug_to_create_inferior (char *exec_file
, char *args
, char **env
)
1791 debug_target
.to_create_inferior (exec_file
, args
, env
);
1793 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx)\n",
1798 debug_to_post_startup_inferior (ptid_t ptid
)
1800 debug_target
.to_post_startup_inferior (ptid
);
1802 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
1807 debug_to_acknowledge_created_inferior (int pid
)
1809 debug_target
.to_acknowledge_created_inferior (pid
);
1811 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
1816 debug_to_clone_and_follow_inferior (int child_pid
, int *followed_child
)
1818 debug_target
.to_clone_and_follow_inferior (child_pid
, followed_child
);
1820 fprintf_unfiltered (gdb_stdlog
,
1821 "target_clone_and_follow_inferior (%d, %d)\n",
1822 child_pid
, *followed_child
);
1826 debug_to_post_follow_inferior_by_clone (void)
1828 debug_target
.to_post_follow_inferior_by_clone ();
1830 fprintf_unfiltered (gdb_stdlog
, "target_post_follow_inferior_by_clone ()\n");
1834 debug_to_insert_fork_catchpoint (int pid
)
1838 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
1840 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
1847 debug_to_remove_fork_catchpoint (int pid
)
1851 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
1853 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
1860 debug_to_insert_vfork_catchpoint (int pid
)
1864 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
1866 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)= %d\n",
1873 debug_to_remove_vfork_catchpoint (int pid
)
1877 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
1879 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
1886 debug_to_has_forked (int pid
, int *child_pid
)
1890 has_forked
= debug_target
.to_has_forked (pid
, child_pid
);
1892 fprintf_unfiltered (gdb_stdlog
, "target_has_forked (%d, %d) = %d\n",
1893 pid
, *child_pid
, has_forked
);
1899 debug_to_has_vforked (int pid
, int *child_pid
)
1903 has_vforked
= debug_target
.to_has_vforked (pid
, child_pid
);
1905 fprintf_unfiltered (gdb_stdlog
, "target_has_vforked (%d, %d) = %d\n",
1906 pid
, *child_pid
, has_vforked
);
1912 debug_to_can_follow_vfork_prior_to_exec (void)
1914 int can_immediately_follow_vfork
;
1916 can_immediately_follow_vfork
= debug_target
.to_can_follow_vfork_prior_to_exec ();
1918 fprintf_unfiltered (gdb_stdlog
, "target_can_follow_vfork_prior_to_exec () = %d\n",
1919 can_immediately_follow_vfork
);
1921 return can_immediately_follow_vfork
;
1925 debug_to_post_follow_vfork (int parent_pid
, int followed_parent
, int child_pid
,
1928 debug_target
.to_post_follow_vfork (parent_pid
, followed_parent
, child_pid
, followed_child
);
1930 fprintf_unfiltered (gdb_stdlog
,
1931 "target_post_follow_vfork (%d, %d, %d, %d)\n",
1932 parent_pid
, followed_parent
, child_pid
, followed_child
);
1936 debug_to_insert_exec_catchpoint (int pid
)
1940 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
1942 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
1949 debug_to_remove_exec_catchpoint (int pid
)
1953 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
1955 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
1962 debug_to_has_execd (int pid
, char **execd_pathname
)
1966 has_execd
= debug_target
.to_has_execd (pid
, execd_pathname
);
1968 fprintf_unfiltered (gdb_stdlog
, "target_has_execd (%d, %s) = %d\n",
1969 pid
, (*execd_pathname
? *execd_pathname
: "<NULL>"),
1976 debug_to_reported_exec_events_per_exec_call (void)
1978 int reported_exec_events
;
1980 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
1982 fprintf_unfiltered (gdb_stdlog
,
1983 "target_reported_exec_events_per_exec_call () = %d\n",
1984 reported_exec_events
);
1986 return reported_exec_events
;
1990 debug_to_has_syscall_event (int pid
, enum target_waitkind
*kind
,
1993 int has_syscall_event
;
1994 char *kind_spelling
= "??";
1996 has_syscall_event
= debug_target
.to_has_syscall_event (pid
, kind
, syscall_id
);
1997 if (has_syscall_event
)
2001 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2002 kind_spelling
= "SYSCALL_ENTRY";
2004 case TARGET_WAITKIND_SYSCALL_RETURN
:
2005 kind_spelling
= "SYSCALL_RETURN";
2012 fprintf_unfiltered (gdb_stdlog
,
2013 "target_has_syscall_event (%d, %s, %d) = %d\n",
2014 pid
, kind_spelling
, *syscall_id
, has_syscall_event
);
2016 return has_syscall_event
;
2020 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
2024 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2026 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2027 pid
, wait_status
, *exit_status
, has_exited
);
2033 debug_to_mourn_inferior (void)
2035 debug_target
.to_mourn_inferior ();
2037 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2041 debug_to_can_run (void)
2045 retval
= debug_target
.to_can_run ();
2047 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2053 debug_to_notice_signals (ptid_t ptid
)
2055 debug_target
.to_notice_signals (ptid
);
2057 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n",
2062 debug_to_thread_alive (ptid_t ptid
)
2066 retval
= debug_target
.to_thread_alive (ptid
);
2068 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2069 PIDGET (ptid
), retval
);
2075 debug_to_find_new_threads (void)
2077 debug_target
.to_find_new_threads ();
2079 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog
);
2083 debug_to_stop (void)
2085 debug_target
.to_stop ();
2087 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2091 debug_to_query (int type
, char *req
, char *resp
, int *siz
)
2095 retval
= debug_target
.to_query (type
, req
, resp
, siz
);
2097 fprintf_unfiltered (gdb_stdlog
, "target_query (%c, %s, %s, %d) = %d\n", type
, req
, resp
, *siz
, retval
);
2103 debug_to_rcmd (char *command
,
2104 struct ui_file
*outbuf
)
2106 debug_target
.to_rcmd (command
, outbuf
);
2107 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2110 static struct symtab_and_line
*
2111 debug_to_enable_exception_callback (enum exception_event_kind kind
, int enable
)
2113 struct symtab_and_line
*result
;
2114 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2115 fprintf_unfiltered (gdb_stdlog
,
2116 "target get_exception_callback_sal (%d, %d)\n",
2121 static struct exception_event_record
*
2122 debug_to_get_current_exception_event (void)
2124 struct exception_event_record
*result
;
2125 result
= debug_target
.to_get_current_exception_event ();
2126 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2131 debug_to_pid_to_exec_file (int pid
)
2135 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2137 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2144 setup_target_debug (void)
2146 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2148 current_target
.to_open
= debug_to_open
;
2149 current_target
.to_close
= debug_to_close
;
2150 current_target
.to_attach
= debug_to_attach
;
2151 current_target
.to_post_attach
= debug_to_post_attach
;
2152 current_target
.to_require_attach
= debug_to_require_attach
;
2153 current_target
.to_detach
= debug_to_detach
;
2154 current_target
.to_require_detach
= debug_to_require_detach
;
2155 current_target
.to_resume
= debug_to_resume
;
2156 current_target
.to_wait
= debug_to_wait
;
2157 current_target
.to_post_wait
= debug_to_post_wait
;
2158 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2159 current_target
.to_store_registers
= debug_to_store_registers
;
2160 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2161 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2162 current_target
.to_files_info
= debug_to_files_info
;
2163 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2164 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2165 current_target
.to_terminal_init
= debug_to_terminal_init
;
2166 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2167 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2168 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2169 current_target
.to_terminal_info
= debug_to_terminal_info
;
2170 current_target
.to_kill
= debug_to_kill
;
2171 current_target
.to_load
= debug_to_load
;
2172 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2173 current_target
.to_create_inferior
= debug_to_create_inferior
;
2174 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2175 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2176 current_target
.to_clone_and_follow_inferior
= debug_to_clone_and_follow_inferior
;
2177 current_target
.to_post_follow_inferior_by_clone
= debug_to_post_follow_inferior_by_clone
;
2178 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2179 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2180 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2181 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2182 current_target
.to_has_forked
= debug_to_has_forked
;
2183 current_target
.to_has_vforked
= debug_to_has_vforked
;
2184 current_target
.to_can_follow_vfork_prior_to_exec
= debug_to_can_follow_vfork_prior_to_exec
;
2185 current_target
.to_post_follow_vfork
= debug_to_post_follow_vfork
;
2186 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2187 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2188 current_target
.to_has_execd
= debug_to_has_execd
;
2189 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2190 current_target
.to_has_syscall_event
= debug_to_has_syscall_event
;
2191 current_target
.to_has_exited
= debug_to_has_exited
;
2192 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2193 current_target
.to_can_run
= debug_to_can_run
;
2194 current_target
.to_notice_signals
= debug_to_notice_signals
;
2195 current_target
.to_thread_alive
= debug_to_thread_alive
;
2196 current_target
.to_find_new_threads
= debug_to_find_new_threads
;
2197 current_target
.to_stop
= debug_to_stop
;
2198 current_target
.to_query
= debug_to_query
;
2199 current_target
.to_rcmd
= debug_to_rcmd
;
2200 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
2201 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
2202 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2207 static char targ_desc
[] =
2208 "Names of targets and files being debugged.\n\
2209 Shows the entire stack of targets currently in use (including the exec-file,\n\
2210 core-file, and process, if any), as well as the symbol file name.";
2213 do_monitor_command (char *cmd
,
2216 if ((current_target
.to_rcmd
2217 == (void (*) (char *, struct ui_file
*)) tcomplain
)
2218 || (current_target
.to_rcmd
== debug_to_rcmd
2219 && (debug_target
.to_rcmd
2220 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
2222 error ("\"monitor\" command not supported by this target.\n");
2224 target_rcmd (cmd
, gdb_stdtarg
);
2228 initialize_targets (void)
2230 init_dummy_target ();
2231 push_target (&dummy_target
);
2233 add_info ("target", target_info
, targ_desc
);
2234 add_info ("files", target_info
, targ_desc
);
2237 add_set_cmd ("target", class_maintenance
, var_zinteger
,
2238 (char *) &targetdebug
,
2239 "Set target debugging.\n\
2240 When non-zero, target debugging is enabled.", &setdebuglist
),
2244 add_com ("monitor", class_obscure
, do_monitor_command
,
2245 "Send a command to the remote monitor (remote targets only).");
2247 target_dcache
= dcache_init();