1 /* Select target systems and architectures at runtime for GDB.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 Free Software Foundation, Inc.
5 Contributed by Cygnus Support.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
26 #include "gdb_string.h"
41 static void target_info (char *, int);
43 static void cleanup_target (struct target_ops
*);
45 static void maybe_kill_then_create_inferior (char *, char *, char **);
47 static void default_clone_and_follow_inferior (int, int *);
49 static void maybe_kill_then_attach (char *, int);
51 static void kill_or_be_killed (int);
53 static void default_terminal_info (char *, int);
55 static int nosymbol (char *, CORE_ADDR
*);
57 static void tcomplain (void);
59 static int nomemory (CORE_ADDR
, char *, int, int, struct target_ops
*);
61 static int return_zero (void);
63 static int return_one (void);
65 void target_ignore (void);
67 static void target_command (char *, int);
69 static struct target_ops
*find_default_run_target (char *);
71 static void update_current_target (void);
73 static void nosupport_runtime (void);
75 static void normal_target_post_startup_inferior (ptid_t ptid
);
77 /* Transfer LEN bytes between target address MEMADDR and GDB address
78 MYADDR. Returns 0 for success, errno code for failure (which
79 includes partial transfers -- if you want a more useful response to
80 partial transfers, try either target_read_memory_partial or
81 target_write_memory_partial). */
84 target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
);
86 static void init_dummy_target (void);
88 static void debug_to_open (char *, int);
90 static void debug_to_close (int);
92 static void debug_to_attach (char *, int);
94 static void debug_to_detach (char *, int);
96 static void debug_to_resume (ptid_t
, int, enum target_signal
);
98 static ptid_t
debug_to_wait (ptid_t
, struct target_waitstatus
*);
100 static void debug_to_fetch_registers (int);
102 static void debug_to_store_registers (int);
104 static void debug_to_prepare_to_store (void);
107 debug_to_xfer_memory (CORE_ADDR
, char *, int, int, struct mem_attrib
*,
108 struct target_ops
*);
110 static void debug_to_files_info (struct target_ops
*);
112 static int debug_to_insert_breakpoint (CORE_ADDR
, char *);
114 static int debug_to_remove_breakpoint (CORE_ADDR
, char *);
116 static void debug_to_terminal_init (void);
118 static void debug_to_terminal_inferior (void);
120 static void debug_to_terminal_ours_for_output (void);
122 static void debug_to_terminal_ours (void);
124 static void debug_to_terminal_info (char *, int);
126 static void debug_to_kill (void);
128 static void debug_to_load (char *, int);
130 static int debug_to_lookup_symbol (char *, CORE_ADDR
*);
132 static void debug_to_create_inferior (char *, char *, char **);
134 static void debug_to_mourn_inferior (void);
136 static int debug_to_can_run (void);
138 static void debug_to_notice_signals (ptid_t
);
140 static int debug_to_thread_alive (ptid_t
);
142 static void debug_to_stop (void);
144 static int debug_to_query (int /*char */ , char *, char *, int *);
146 /* Pointer to array of target architecture structures; the size of the
147 array; the current index into the array; the allocated size of the
149 struct target_ops
**target_structs
;
150 unsigned target_struct_size
;
151 unsigned target_struct_index
;
152 unsigned target_struct_allocsize
;
153 #define DEFAULT_ALLOCSIZE 10
155 /* The initial current target, so that there is always a semi-valid
158 static struct target_ops dummy_target
;
160 /* Top of target stack. */
162 struct target_stack_item
*target_stack
;
164 /* The target structure we are currently using to talk to a process
165 or file or whatever "inferior" we have. */
167 struct target_ops current_target
;
169 /* Command list for target. */
171 static struct cmd_list_element
*targetlist
= NULL
;
173 /* Nonzero if we are debugging an attached outside process
174 rather than an inferior. */
178 /* Non-zero if we want to see trace of target level stuff. */
180 static int targetdebug
= 0;
182 static void setup_target_debug (void);
184 DCACHE
*target_dcache
;
186 /* The user just typed 'target' without the name of a target. */
190 target_command (char *arg
, int from_tty
)
192 fputs_filtered ("Argument required (target name). Try `help target'\n",
196 /* Add a possible target architecture to the list. */
199 add_target (struct target_ops
*t
)
203 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
204 target_structs
= (struct target_ops
**) xmalloc
205 (target_struct_allocsize
* sizeof (*target_structs
));
207 if (target_struct_size
>= target_struct_allocsize
)
209 target_struct_allocsize
*= 2;
210 target_structs
= (struct target_ops
**)
211 xrealloc ((char *) target_structs
,
212 target_struct_allocsize
* sizeof (*target_structs
));
214 target_structs
[target_struct_size
++] = t
;
215 /* cleanup_target (t); */
217 if (targetlist
== NULL
)
218 add_prefix_cmd ("target", class_run
, target_command
,
219 "Connect to a target machine or process.\n\
220 The first argument is the type or protocol of the target machine.\n\
221 Remaining arguments are interpreted by the target protocol. For more\n\
222 information on the arguments for a particular protocol, type\n\
223 `help target ' followed by the protocol name.",
224 &targetlist
, "target ", 0, &cmdlist
);
225 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
236 target_load (char *arg
, int from_tty
)
238 dcache_invalidate (target_dcache
);
239 (*current_target
.to_load
) (arg
, from_tty
);
244 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
245 struct target_ops
*t
)
247 errno
= EIO
; /* Can't read/write this location */
248 return 0; /* No bytes handled */
254 error ("You can't do that when your target is `%s'",
255 current_target
.to_shortname
);
261 error ("You can't do that without a process to debug.");
266 nosymbol (char *name
, CORE_ADDR
*addrp
)
268 return 1; /* Symbol does not exist in target env */
273 nosupport_runtime (void)
275 if (ptid_equal (inferior_ptid
, null_ptid
))
278 error ("No run-time support for this");
284 default_terminal_info (char *args
, int from_tty
)
286 printf_unfiltered ("No saved terminal information.\n");
289 /* This is the default target_create_inferior and target_attach function.
290 If the current target is executing, it asks whether to kill it off.
291 If this function returns without calling error(), it has killed off
292 the target, and the operation should be attempted. */
295 kill_or_be_killed (int from_tty
)
297 if (target_has_execution
)
299 printf_unfiltered ("You are already running a program:\n");
300 target_files_info ();
301 if (query ("Kill it? "))
304 if (target_has_execution
)
305 error ("Killing the program did not help.");
310 error ("Program not killed.");
317 maybe_kill_then_attach (char *args
, int from_tty
)
319 kill_or_be_killed (from_tty
);
320 target_attach (args
, from_tty
);
324 maybe_kill_then_create_inferior (char *exec
, char *args
, char **env
)
326 kill_or_be_killed (0);
327 target_create_inferior (exec
, args
, env
);
331 default_clone_and_follow_inferior (int child_pid
, int *followed_child
)
333 target_clone_and_follow_inferior (child_pid
, followed_child
);
336 /* Clean up a target struct so it no longer has any zero pointers in it.
337 We default entries, at least to stubs that print error messages. */
340 cleanup_target (struct target_ops
*t
)
343 #define de_fault(field, value) \
348 (void (*) (char *, int))
354 maybe_kill_then_attach
);
355 de_fault (to_post_attach
,
358 de_fault (to_require_attach
,
359 maybe_kill_then_attach
);
361 (void (*) (char *, int))
363 de_fault (to_require_detach
,
364 (void (*) (int, char *, int))
367 (void (*) (ptid_t
, int, enum target_signal
))
370 (ptid_t (*) (ptid_t
, struct target_waitstatus
*))
372 de_fault (to_post_wait
,
373 (void (*) (ptid_t
, int))
375 de_fault (to_fetch_registers
,
378 de_fault (to_store_registers
,
381 de_fault (to_prepare_to_store
,
384 de_fault (to_xfer_memory
,
385 (int (*) (CORE_ADDR
, char *, int, int, struct mem_attrib
*, struct target_ops
*))
387 de_fault (to_files_info
,
388 (void (*) (struct target_ops
*))
390 de_fault (to_insert_breakpoint
,
391 memory_insert_breakpoint
);
392 de_fault (to_remove_breakpoint
,
393 memory_remove_breakpoint
);
394 de_fault (to_terminal_init
,
397 de_fault (to_terminal_inferior
,
400 de_fault (to_terminal_ours_for_output
,
403 de_fault (to_terminal_ours
,
406 de_fault (to_terminal_info
,
407 default_terminal_info
);
412 (void (*) (char *, int))
414 de_fault (to_lookup_symbol
,
415 (int (*) (char *, CORE_ADDR
*))
417 de_fault (to_create_inferior
,
418 maybe_kill_then_create_inferior
);
419 de_fault (to_post_startup_inferior
,
422 de_fault (to_acknowledge_created_inferior
,
425 de_fault (to_clone_and_follow_inferior
,
426 default_clone_and_follow_inferior
);
427 de_fault (to_post_follow_inferior_by_clone
,
430 de_fault (to_insert_fork_catchpoint
,
433 de_fault (to_remove_fork_catchpoint
,
436 de_fault (to_insert_vfork_catchpoint
,
439 de_fault (to_remove_vfork_catchpoint
,
442 de_fault (to_has_forked
,
443 (int (*) (int, int *))
445 de_fault (to_has_vforked
,
446 (int (*) (int, int *))
448 de_fault (to_can_follow_vfork_prior_to_exec
,
451 de_fault (to_post_follow_vfork
,
452 (void (*) (int, int, int, int))
454 de_fault (to_insert_exec_catchpoint
,
457 de_fault (to_remove_exec_catchpoint
,
460 de_fault (to_has_execd
,
461 (int (*) (int, char **))
463 de_fault (to_reported_exec_events_per_exec_call
,
466 de_fault (to_has_syscall_event
,
467 (int (*) (int, enum target_waitkind
*, int *))
469 de_fault (to_has_exited
,
470 (int (*) (int, int, int *))
472 de_fault (to_mourn_inferior
,
475 de_fault (to_can_run
,
477 de_fault (to_notice_signals
,
480 de_fault (to_thread_alive
,
483 de_fault (to_find_new_threads
,
486 de_fault (to_extra_thread_info
,
487 (char *(*) (struct thread_info
*))
493 (void (*) (char *, struct ui_file
*))
495 de_fault (to_enable_exception_callback
,
496 (struct symtab_and_line
* (*) (enum exception_event_kind
, int))
498 de_fault (to_get_current_exception_event
,
499 (struct exception_event_record
* (*) (void))
501 de_fault (to_pid_to_exec_file
,
504 de_fault (to_can_async_p
,
507 de_fault (to_is_async_p
,
511 (void (*) (void (*) (enum inferior_event_type
, void*), void*))
516 /* Go through the target stack from top to bottom, copying over zero entries in
517 current_target. In effect, we are doing class inheritance through the
518 pushed target vectors. */
521 update_current_target (void)
523 struct target_stack_item
*item
;
524 struct target_ops
*t
;
526 /* First, reset current_target */
527 memset (¤t_target
, 0, sizeof current_target
);
529 for (item
= target_stack
; item
; item
= item
->next
)
531 t
= item
->target_ops
;
533 #define INHERIT(FIELD, TARGET) \
534 if (!current_target.FIELD) \
535 current_target.FIELD = TARGET->FIELD
537 INHERIT (to_shortname
, t
);
538 INHERIT (to_longname
, t
);
540 INHERIT (to_open
, t
);
541 INHERIT (to_close
, t
);
542 INHERIT (to_attach
, t
);
543 INHERIT (to_post_attach
, t
);
544 INHERIT (to_require_attach
, t
);
545 INHERIT (to_detach
, t
);
546 INHERIT (to_require_detach
, t
);
547 INHERIT (to_resume
, t
);
548 INHERIT (to_wait
, t
);
549 INHERIT (to_post_wait
, t
);
550 INHERIT (to_fetch_registers
, t
);
551 INHERIT (to_store_registers
, t
);
552 INHERIT (to_prepare_to_store
, t
);
553 INHERIT (to_xfer_memory
, t
);
554 INHERIT (to_files_info
, t
);
555 INHERIT (to_insert_breakpoint
, t
);
556 INHERIT (to_remove_breakpoint
, t
);
557 INHERIT (to_terminal_init
, t
);
558 INHERIT (to_terminal_inferior
, t
);
559 INHERIT (to_terminal_ours_for_output
, t
);
560 INHERIT (to_terminal_ours
, t
);
561 INHERIT (to_terminal_info
, t
);
562 INHERIT (to_kill
, t
);
563 INHERIT (to_load
, t
);
564 INHERIT (to_lookup_symbol
, t
);
565 INHERIT (to_create_inferior
, t
);
566 INHERIT (to_post_startup_inferior
, t
);
567 INHERIT (to_acknowledge_created_inferior
, t
);
568 INHERIT (to_clone_and_follow_inferior
, t
);
569 INHERIT (to_post_follow_inferior_by_clone
, t
);
570 INHERIT (to_insert_fork_catchpoint
, t
);
571 INHERIT (to_remove_fork_catchpoint
, t
);
572 INHERIT (to_insert_vfork_catchpoint
, t
);
573 INHERIT (to_remove_vfork_catchpoint
, t
);
574 INHERIT (to_has_forked
, t
);
575 INHERIT (to_has_vforked
, t
);
576 INHERIT (to_can_follow_vfork_prior_to_exec
, t
);
577 INHERIT (to_post_follow_vfork
, t
);
578 INHERIT (to_insert_exec_catchpoint
, t
);
579 INHERIT (to_remove_exec_catchpoint
, t
);
580 INHERIT (to_has_execd
, t
);
581 INHERIT (to_reported_exec_events_per_exec_call
, t
);
582 INHERIT (to_has_syscall_event
, t
);
583 INHERIT (to_has_exited
, t
);
584 INHERIT (to_mourn_inferior
, t
);
585 INHERIT (to_can_run
, t
);
586 INHERIT (to_notice_signals
, t
);
587 INHERIT (to_thread_alive
, t
);
588 INHERIT (to_find_new_threads
, t
);
589 INHERIT (to_pid_to_str
, t
);
590 INHERIT (to_extra_thread_info
, t
);
591 INHERIT (to_stop
, t
);
592 INHERIT (to_query
, t
);
593 INHERIT (to_rcmd
, t
);
594 INHERIT (to_enable_exception_callback
, t
);
595 INHERIT (to_get_current_exception_event
, t
);
596 INHERIT (to_pid_to_exec_file
, t
);
597 INHERIT (to_stratum
, t
);
598 INHERIT (DONT_USE
, t
);
599 INHERIT (to_has_all_memory
, t
);
600 INHERIT (to_has_memory
, t
);
601 INHERIT (to_has_stack
, t
);
602 INHERIT (to_has_registers
, t
);
603 INHERIT (to_has_execution
, t
);
604 INHERIT (to_has_thread_control
, t
);
605 INHERIT (to_sections
, t
);
606 INHERIT (to_sections_end
, t
);
607 INHERIT (to_can_async_p
, t
);
608 INHERIT (to_is_async_p
, t
);
609 INHERIT (to_async
, t
);
610 INHERIT (to_async_mask_value
, t
);
611 INHERIT (to_find_memory_regions
, t
);
612 INHERIT (to_make_corefile_notes
, 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 static int trust_readonly
= 0;
840 /* Move memory to or from the targets. The top target gets priority;
841 if it cannot handle it, it is offered to the next one down, etc.
843 Result is -1 on error, or the number of bytes transfered. */
846 do_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
847 struct mem_attrib
*attrib
)
851 struct target_ops
*t
;
852 struct target_stack_item
*item
;
854 /* Zero length requests are ok and require no work. */
858 /* to_xfer_memory is not guaranteed to set errno, even when it returns
862 if (!write
&& trust_readonly
)
864 /* User-settable option, "trust-readonly". If true, then
865 memory from any SEC_READONLY bfd section may be read
866 directly from the bfd file. */
868 struct section_table
*secp
;
870 for (secp
= current_target
.to_sections
;
871 secp
< current_target
.to_sections_end
;
874 if (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
876 if (memaddr
>= secp
->addr
&& memaddr
< secp
->endaddr
)
877 return xfer_memory (memaddr
, myaddr
, len
, 0,
878 attrib
, ¤t_target
);
882 /* The quick case is that the top target can handle the transfer. */
883 res
= current_target
.to_xfer_memory
884 (memaddr
, myaddr
, len
, write
, attrib
, ¤t_target
);
886 /* If res <= 0 then we call it again in the loop. Ah well. */
889 for (item
= target_stack
; item
; item
= item
->next
)
891 t
= item
->target_ops
;
892 if (!t
->to_has_memory
)
895 res
= t
->to_xfer_memory (memaddr
, myaddr
, len
, write
, attrib
, t
);
897 break; /* Handled all or part of xfer */
898 if (t
->to_has_all_memory
)
910 /* Perform a memory transfer. Iterate until the entire region has
913 Result is 0 or errno value. */
916 target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
)
920 struct mem_region
*region
;
922 /* Zero length requests are ok and require no work. */
930 region
= lookup_mem_region(memaddr
);
931 if (memaddr
+ len
< region
->hi
)
934 reg_len
= region
->hi
- memaddr
;
936 switch (region
->attrib
.mode
)
951 if (region
->attrib
.cache
)
952 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
,
955 res
= do_xfer_memory (memaddr
, myaddr
, reg_len
, write
,
960 /* If this address is for nonexistent memory, read zeros
961 if reading, or do nothing if writing. Return
964 memset (myaddr
, 0, len
);
978 return 0; /* We managed to cover it all somehow. */
982 /* Perform a partial memory transfer.
984 Result is -1 on error, or the number of bytes transfered. */
987 target_xfer_memory_partial (CORE_ADDR memaddr
, char *myaddr
, int len
,
988 int write_p
, int *err
)
992 struct mem_region
*region
;
994 /* Zero length requests are ok and require no work. */
1001 region
= lookup_mem_region(memaddr
);
1002 if (memaddr
+ len
< region
->hi
)
1005 reg_len
= region
->hi
- memaddr
;
1007 switch (region
->attrib
.mode
)
1026 if (region
->attrib
.cache
)
1027 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
,
1030 res
= do_xfer_memory (memaddr
, myaddr
, reg_len
, write_p
,
1048 target_read_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1050 return target_xfer_memory_partial (memaddr
, buf
, len
, 0, err
);
1054 target_write_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1056 return target_xfer_memory_partial (memaddr
, buf
, len
, 1, err
);
1061 target_info (char *args
, int from_tty
)
1063 struct target_ops
*t
;
1064 struct target_stack_item
*item
;
1065 int has_all_mem
= 0;
1067 if (symfile_objfile
!= NULL
)
1068 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
1070 #ifdef FILES_INFO_HOOK
1071 if (FILES_INFO_HOOK ())
1075 for (item
= target_stack
; item
; item
= item
->next
)
1077 t
= item
->target_ops
;
1079 if (!t
->to_has_memory
)
1082 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
1085 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1086 printf_unfiltered ("%s:\n", t
->to_longname
);
1087 (t
->to_files_info
) (t
);
1088 has_all_mem
= t
->to_has_all_memory
;
1092 /* This is to be called by the open routine before it does
1096 target_preopen (int from_tty
)
1100 if (target_has_execution
)
1103 || query ("A program is being debugged already. Kill it? "))
1106 error ("Program not killed.");
1109 /* Calling target_kill may remove the target from the stack. But if
1110 it doesn't (which seems like a win for UDI), remove it now. */
1112 if (target_has_execution
)
1116 /* Detach a target after doing deferred register stores. */
1119 target_detach (char *args
, int from_tty
)
1121 /* Handle any optimized stores to the inferior. */
1122 #ifdef DO_DEFERRED_STORES
1125 (current_target
.to_detach
) (args
, from_tty
);
1129 target_link (char *modname
, CORE_ADDR
*t_reloc
)
1131 if (STREQ (current_target
.to_shortname
, "rombug"))
1133 (current_target
.to_lookup_symbol
) (modname
, t_reloc
);
1135 error ("Unable to link to %s and get relocation in rombug", modname
);
1138 *t_reloc
= (CORE_ADDR
) -1;
1142 target_async_mask (int mask
)
1144 int saved_async_masked_status
= target_async_mask_value
;
1145 target_async_mask_value
= mask
;
1146 return saved_async_masked_status
;
1149 /* Look through the list of possible targets for a target that can
1150 execute a run or attach command without any other data. This is
1151 used to locate the default process stratum.
1153 Result is always valid (error() is called for errors). */
1155 static struct target_ops
*
1156 find_default_run_target (char *do_mesg
)
1158 struct target_ops
**t
;
1159 struct target_ops
*runable
= NULL
;
1164 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1167 if ((*t
)->to_can_run
&& target_can_run (*t
))
1175 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
1181 find_default_attach (char *args
, int from_tty
)
1183 struct target_ops
*t
;
1185 t
= find_default_run_target ("attach");
1186 (t
->to_attach
) (args
, from_tty
);
1191 find_default_require_attach (char *args
, int from_tty
)
1193 struct target_ops
*t
;
1195 t
= find_default_run_target ("require_attach");
1196 (t
->to_require_attach
) (args
, from_tty
);
1201 find_default_require_detach (int pid
, char *args
, int from_tty
)
1203 struct target_ops
*t
;
1205 t
= find_default_run_target ("require_detach");
1206 (t
->to_require_detach
) (pid
, args
, from_tty
);
1211 find_default_create_inferior (char *exec_file
, char *allargs
, char **env
)
1213 struct target_ops
*t
;
1215 t
= find_default_run_target ("run");
1216 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
1221 find_default_clone_and_follow_inferior (int child_pid
, int *followed_child
)
1223 struct target_ops
*t
;
1225 t
= find_default_run_target ("run");
1226 (t
->to_clone_and_follow_inferior
) (child_pid
, followed_child
);
1243 * Resize the to_sections pointer. Also make sure that anyone that
1244 * was holding on to an old value of it gets updated.
1245 * Returns the old size.
1249 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1251 struct target_ops
**t
;
1252 struct section_table
*old_value
;
1255 old_value
= target
->to_sections
;
1257 if (target
->to_sections
)
1259 old_count
= target
->to_sections_end
- target
->to_sections
;
1260 target
->to_sections
= (struct section_table
*)
1261 xrealloc ((char *) target
->to_sections
,
1262 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1267 target
->to_sections
= (struct section_table
*)
1268 xmalloc ((sizeof (struct section_table
)) * num_added
);
1270 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1272 /* Check to see if anyone else was pointing to this structure.
1273 If old_value was null, then no one was. */
1277 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1280 if ((*t
)->to_sections
== old_value
)
1282 (*t
)->to_sections
= target
->to_sections
;
1283 (*t
)->to_sections_end
= target
->to_sections_end
;
1292 /* Remove all target sections taken from ABFD.
1294 Scan the current target stack for targets whose section tables
1295 refer to sections from BFD, and remove those sections. We use this
1296 when we notice that the inferior has unloaded a shared object, for
1299 remove_target_sections (bfd
*abfd
)
1301 struct target_ops
**t
;
1303 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; t
++)
1305 struct section_table
*src
, *dest
;
1307 dest
= (*t
)->to_sections
;
1308 for (src
= (*t
)->to_sections
; src
< (*t
)->to_sections_end
; src
++)
1309 if (src
->bfd
!= abfd
)
1311 /* Keep this section. */
1312 if (dest
< src
) *dest
= *src
;
1316 /* If we've dropped any sections, resize the section table. */
1318 target_resize_to_sections (*t
, dest
- src
);
1325 /* Find a single runnable target in the stack and return it. If for
1326 some reason there is more than one, return NULL. */
1329 find_run_target (void)
1331 struct target_ops
**t
;
1332 struct target_ops
*runable
= NULL
;
1337 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1339 if ((*t
)->to_can_run
&& target_can_run (*t
))
1346 return (count
== 1 ? runable
: NULL
);
1349 /* Find a single core_stratum target in the list of targets and return it.
1350 If for some reason there is more than one, return NULL. */
1353 find_core_target (void)
1355 struct target_ops
**t
;
1356 struct target_ops
*runable
= NULL
;
1361 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1364 if ((*t
)->to_stratum
== core_stratum
)
1371 return (count
== 1 ? runable
: NULL
);
1375 * Find the next target down the stack from the specified target.
1379 find_target_beneath (struct target_ops
*t
)
1381 struct target_stack_item
*cur
;
1383 for (cur
= target_stack
; cur
; cur
= cur
->next
)
1384 if (cur
->target_ops
== t
)
1387 if (cur
== NULL
|| cur
->next
== NULL
)
1390 return cur
->next
->target_ops
;
1394 /* The inferior process has died. Long live the inferior! */
1397 generic_mourn_inferior (void)
1399 extern int show_breakpoint_hit_counts
;
1401 inferior_ptid
= null_ptid
;
1403 breakpoint_init_inferior (inf_exited
);
1404 registers_changed ();
1406 #ifdef CLEAR_DEFERRED_STORES
1407 /* Delete any pending stores to the inferior... */
1408 CLEAR_DEFERRED_STORES
;
1411 reopen_exec_file ();
1412 reinit_frame_cache ();
1414 /* It is confusing to the user for ignore counts to stick around
1415 from previous runs of the inferior. So clear them. */
1416 /* However, it is more confusing for the ignore counts to disappear when
1417 using hit counts. So don't clear them if we're counting hits. */
1418 if (!show_breakpoint_hit_counts
)
1419 breakpoint_clear_ignore_counts ();
1425 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1426 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1427 translation of that in OURSTATUS. */
1429 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
1431 #ifdef CHILD_SPECIAL_WAITSTATUS
1432 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1433 if it wants to deal with hoststatus. */
1434 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
1438 if (WIFEXITED (hoststatus
))
1440 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1441 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
1443 else if (!WIFSTOPPED (hoststatus
))
1445 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1446 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
1450 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
1451 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
1455 /* Returns zero to leave the inferior alone, one to interrupt it. */
1456 int (*target_activity_function
) (void);
1457 int target_activity_fd
;
1459 /* Convert a normal process ID to a string. Returns the string in a static
1463 normal_pid_to_str (ptid_t ptid
)
1465 static char buf
[30];
1467 sprintf (buf
, "process %d", PIDGET (ptid
));
1471 /* Some targets (such as ttrace-based HPUX) don't allow us to request
1472 notification of inferior events such as fork and vork immediately
1473 after the inferior is created. (This because of how gdb gets an
1474 inferior created via invoking a shell to do it. In such a scenario,
1475 if the shell init file has commands in it, the shell will fork and
1476 exec for each of those commands, and we will see each such fork
1479 This function is used by all targets that allow us to request
1480 notification of forks, etc at inferior creation time; e.g., in
1481 target_acknowledge_forked_child.
1484 normal_target_post_startup_inferior (ptid_t ptid
)
1486 /* This space intentionally left blank. */
1489 /* Error-catcher for target_find_memory_regions */
1491 static int dummy_find_memory_regions (int (*ignore1
) (), void *ignore2
)
1493 error ("No target.");
1497 /* Error-catcher for target_make_corefile_notes */
1499 static char * dummy_make_corefile_notes (bfd
*ignore1
, int *ignore2
)
1501 error ("No target.");
1505 /* Set up the handful of non-empty slots needed by the dummy target
1509 init_dummy_target (void)
1511 dummy_target
.to_shortname
= "None";
1512 dummy_target
.to_longname
= "None";
1513 dummy_target
.to_doc
= "";
1514 dummy_target
.to_attach
= find_default_attach
;
1515 dummy_target
.to_require_attach
= find_default_require_attach
;
1516 dummy_target
.to_require_detach
= find_default_require_detach
;
1517 dummy_target
.to_create_inferior
= find_default_create_inferior
;
1518 dummy_target
.to_clone_and_follow_inferior
= find_default_clone_and_follow_inferior
;
1519 dummy_target
.to_pid_to_str
= normal_pid_to_str
;
1520 dummy_target
.to_stratum
= dummy_stratum
;
1521 dummy_target
.to_find_memory_regions
= dummy_find_memory_regions
;
1522 dummy_target
.to_make_corefile_notes
= dummy_make_corefile_notes
;
1523 dummy_target
.to_magic
= OPS_MAGIC
;
1527 static struct target_ops debug_target
;
1530 debug_to_open (char *args
, int from_tty
)
1532 debug_target
.to_open (args
, from_tty
);
1534 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
1538 debug_to_close (int quitting
)
1540 debug_target
.to_close (quitting
);
1542 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
1546 debug_to_attach (char *args
, int from_tty
)
1548 debug_target
.to_attach (args
, from_tty
);
1550 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
1555 debug_to_post_attach (int pid
)
1557 debug_target
.to_post_attach (pid
);
1559 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
1563 debug_to_require_attach (char *args
, int from_tty
)
1565 debug_target
.to_require_attach (args
, from_tty
);
1567 fprintf_unfiltered (gdb_stdlog
,
1568 "target_require_attach (%s, %d)\n", args
, from_tty
);
1572 debug_to_detach (char *args
, int from_tty
)
1574 debug_target
.to_detach (args
, from_tty
);
1576 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
1580 debug_to_require_detach (int pid
, char *args
, int from_tty
)
1582 debug_target
.to_require_detach (pid
, args
, from_tty
);
1584 fprintf_unfiltered (gdb_stdlog
,
1585 "target_require_detach (%d, %s, %d)\n", pid
, args
, from_tty
);
1589 debug_to_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
1591 debug_target
.to_resume (ptid
, step
, siggnal
);
1593 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", PIDGET (ptid
),
1594 step
? "step" : "continue",
1595 target_signal_to_name (siggnal
));
1599 debug_to_wait (ptid_t ptid
, struct target_waitstatus
*status
)
1603 retval
= debug_target
.to_wait (ptid
, status
);
1605 fprintf_unfiltered (gdb_stdlog
,
1606 "target_wait (%d, status) = %d, ", PIDGET (ptid
),
1608 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
1609 switch (status
->kind
)
1611 case TARGET_WAITKIND_EXITED
:
1612 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
1613 status
->value
.integer
);
1615 case TARGET_WAITKIND_STOPPED
:
1616 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
1617 target_signal_to_name (status
->value
.sig
));
1619 case TARGET_WAITKIND_SIGNALLED
:
1620 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
1621 target_signal_to_name (status
->value
.sig
));
1623 case TARGET_WAITKIND_LOADED
:
1624 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
1626 case TARGET_WAITKIND_FORKED
:
1627 fprintf_unfiltered (gdb_stdlog
, "forked\n");
1629 case TARGET_WAITKIND_VFORKED
:
1630 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
1632 case TARGET_WAITKIND_EXECD
:
1633 fprintf_unfiltered (gdb_stdlog
, "execd\n");
1635 case TARGET_WAITKIND_SPURIOUS
:
1636 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
1639 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
1647 debug_to_post_wait (ptid_t ptid
, int status
)
1649 debug_target
.to_post_wait (ptid
, status
);
1651 fprintf_unfiltered (gdb_stdlog
, "target_post_wait (%d, %d)\n",
1652 PIDGET (ptid
), status
);
1656 debug_to_fetch_registers (int regno
)
1658 debug_target
.to_fetch_registers (regno
);
1660 fprintf_unfiltered (gdb_stdlog
, "target_fetch_registers (%s)",
1661 regno
!= -1 ? REGISTER_NAME (regno
) : "-1");
1663 fprintf_unfiltered (gdb_stdlog
, " = 0x%lx %ld",
1664 (unsigned long) read_register (regno
),
1665 (unsigned long) read_register (regno
));
1666 fprintf_unfiltered (gdb_stdlog
, "\n");
1670 debug_to_store_registers (int regno
)
1672 debug_target
.to_store_registers (regno
);
1674 if (regno
>= 0 && regno
< NUM_REGS
)
1675 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%s) = 0x%lx %ld\n",
1676 REGISTER_NAME (regno
),
1677 (unsigned long) read_register (regno
),
1678 (unsigned long) read_register (regno
));
1680 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%d)\n", regno
);
1684 debug_to_prepare_to_store (void)
1686 debug_target
.to_prepare_to_store ();
1688 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
1692 debug_to_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
1693 struct mem_attrib
*attrib
,
1694 struct target_ops
*target
)
1698 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
,
1701 fprintf_unfiltered (gdb_stdlog
,
1702 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
1703 (unsigned int) memaddr
, /* possable truncate long long */
1704 len
, write
? "write" : "read", retval
);
1712 fputs_unfiltered (", bytes =", gdb_stdlog
);
1713 for (i
= 0; i
< retval
; i
++)
1715 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
1716 fprintf_unfiltered (gdb_stdlog
, "\n");
1717 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1721 fputc_unfiltered ('\n', gdb_stdlog
);
1727 debug_to_files_info (struct target_ops
*target
)
1729 debug_target
.to_files_info (target
);
1731 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
1735 debug_to_insert_breakpoint (CORE_ADDR addr
, char *save
)
1739 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
1741 fprintf_unfiltered (gdb_stdlog
,
1742 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
1743 (unsigned long) addr
,
1744 (unsigned long) retval
);
1749 debug_to_remove_breakpoint (CORE_ADDR addr
, char *save
)
1753 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
1755 fprintf_unfiltered (gdb_stdlog
,
1756 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
1757 (unsigned long) addr
,
1758 (unsigned long) retval
);
1763 debug_to_terminal_init (void)
1765 debug_target
.to_terminal_init ();
1767 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
1771 debug_to_terminal_inferior (void)
1773 debug_target
.to_terminal_inferior ();
1775 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
1779 debug_to_terminal_ours_for_output (void)
1781 debug_target
.to_terminal_ours_for_output ();
1783 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
1787 debug_to_terminal_ours (void)
1789 debug_target
.to_terminal_ours ();
1791 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
1795 debug_to_terminal_info (char *arg
, int from_tty
)
1797 debug_target
.to_terminal_info (arg
, from_tty
);
1799 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
1804 debug_to_kill (void)
1806 debug_target
.to_kill ();
1808 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
1812 debug_to_load (char *args
, int from_tty
)
1814 debug_target
.to_load (args
, from_tty
);
1816 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
1820 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
1824 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
1826 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
1832 debug_to_create_inferior (char *exec_file
, char *args
, char **env
)
1834 debug_target
.to_create_inferior (exec_file
, args
, env
);
1836 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx)\n",
1841 debug_to_post_startup_inferior (ptid_t ptid
)
1843 debug_target
.to_post_startup_inferior (ptid
);
1845 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
1850 debug_to_acknowledge_created_inferior (int pid
)
1852 debug_target
.to_acknowledge_created_inferior (pid
);
1854 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
1859 debug_to_clone_and_follow_inferior (int child_pid
, int *followed_child
)
1861 debug_target
.to_clone_and_follow_inferior (child_pid
, followed_child
);
1863 fprintf_unfiltered (gdb_stdlog
,
1864 "target_clone_and_follow_inferior (%d, %d)\n",
1865 child_pid
, *followed_child
);
1869 debug_to_post_follow_inferior_by_clone (void)
1871 debug_target
.to_post_follow_inferior_by_clone ();
1873 fprintf_unfiltered (gdb_stdlog
, "target_post_follow_inferior_by_clone ()\n");
1877 debug_to_insert_fork_catchpoint (int pid
)
1881 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
1883 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
1890 debug_to_remove_fork_catchpoint (int pid
)
1894 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
1896 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
1903 debug_to_insert_vfork_catchpoint (int pid
)
1907 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
1909 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)= %d\n",
1916 debug_to_remove_vfork_catchpoint (int pid
)
1920 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
1922 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
1929 debug_to_has_forked (int pid
, int *child_pid
)
1933 has_forked
= debug_target
.to_has_forked (pid
, child_pid
);
1935 fprintf_unfiltered (gdb_stdlog
, "target_has_forked (%d, %d) = %d\n",
1936 pid
, *child_pid
, has_forked
);
1942 debug_to_has_vforked (int pid
, int *child_pid
)
1946 has_vforked
= debug_target
.to_has_vforked (pid
, child_pid
);
1948 fprintf_unfiltered (gdb_stdlog
, "target_has_vforked (%d, %d) = %d\n",
1949 pid
, *child_pid
, has_vforked
);
1955 debug_to_can_follow_vfork_prior_to_exec (void)
1957 int can_immediately_follow_vfork
;
1959 can_immediately_follow_vfork
= debug_target
.to_can_follow_vfork_prior_to_exec ();
1961 fprintf_unfiltered (gdb_stdlog
, "target_can_follow_vfork_prior_to_exec () = %d\n",
1962 can_immediately_follow_vfork
);
1964 return can_immediately_follow_vfork
;
1968 debug_to_post_follow_vfork (int parent_pid
, int followed_parent
, int child_pid
,
1971 debug_target
.to_post_follow_vfork (parent_pid
, followed_parent
, child_pid
, followed_child
);
1973 fprintf_unfiltered (gdb_stdlog
,
1974 "target_post_follow_vfork (%d, %d, %d, %d)\n",
1975 parent_pid
, followed_parent
, child_pid
, followed_child
);
1979 debug_to_insert_exec_catchpoint (int pid
)
1983 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
1985 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
1992 debug_to_remove_exec_catchpoint (int pid
)
1996 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
1998 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2005 debug_to_has_execd (int pid
, char **execd_pathname
)
2009 has_execd
= debug_target
.to_has_execd (pid
, execd_pathname
);
2011 fprintf_unfiltered (gdb_stdlog
, "target_has_execd (%d, %s) = %d\n",
2012 pid
, (*execd_pathname
? *execd_pathname
: "<NULL>"),
2019 debug_to_reported_exec_events_per_exec_call (void)
2021 int reported_exec_events
;
2023 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2025 fprintf_unfiltered (gdb_stdlog
,
2026 "target_reported_exec_events_per_exec_call () = %d\n",
2027 reported_exec_events
);
2029 return reported_exec_events
;
2033 debug_to_has_syscall_event (int pid
, enum target_waitkind
*kind
,
2036 int has_syscall_event
;
2037 char *kind_spelling
= "??";
2039 has_syscall_event
= debug_target
.to_has_syscall_event (pid
, kind
, syscall_id
);
2040 if (has_syscall_event
)
2044 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2045 kind_spelling
= "SYSCALL_ENTRY";
2047 case TARGET_WAITKIND_SYSCALL_RETURN
:
2048 kind_spelling
= "SYSCALL_RETURN";
2055 fprintf_unfiltered (gdb_stdlog
,
2056 "target_has_syscall_event (%d, %s, %d) = %d\n",
2057 pid
, kind_spelling
, *syscall_id
, has_syscall_event
);
2059 return has_syscall_event
;
2063 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
2067 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2069 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2070 pid
, wait_status
, *exit_status
, has_exited
);
2076 debug_to_mourn_inferior (void)
2078 debug_target
.to_mourn_inferior ();
2080 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2084 debug_to_can_run (void)
2088 retval
= debug_target
.to_can_run ();
2090 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2096 debug_to_notice_signals (ptid_t ptid
)
2098 debug_target
.to_notice_signals (ptid
);
2100 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n",
2105 debug_to_thread_alive (ptid_t ptid
)
2109 retval
= debug_target
.to_thread_alive (ptid
);
2111 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2112 PIDGET (ptid
), retval
);
2118 debug_to_find_new_threads (void)
2120 debug_target
.to_find_new_threads ();
2122 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog
);
2126 debug_to_stop (void)
2128 debug_target
.to_stop ();
2130 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2134 debug_to_query (int type
, char *req
, char *resp
, int *siz
)
2138 retval
= debug_target
.to_query (type
, req
, resp
, siz
);
2140 fprintf_unfiltered (gdb_stdlog
, "target_query (%c, %s, %s, %d) = %d\n", type
, req
, resp
, *siz
, retval
);
2146 debug_to_rcmd (char *command
,
2147 struct ui_file
*outbuf
)
2149 debug_target
.to_rcmd (command
, outbuf
);
2150 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2153 static struct symtab_and_line
*
2154 debug_to_enable_exception_callback (enum exception_event_kind kind
, int enable
)
2156 struct symtab_and_line
*result
;
2157 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2158 fprintf_unfiltered (gdb_stdlog
,
2159 "target get_exception_callback_sal (%d, %d)\n",
2164 static struct exception_event_record
*
2165 debug_to_get_current_exception_event (void)
2167 struct exception_event_record
*result
;
2168 result
= debug_target
.to_get_current_exception_event ();
2169 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2174 debug_to_pid_to_exec_file (int pid
)
2178 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2180 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2187 setup_target_debug (void)
2189 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2191 current_target
.to_open
= debug_to_open
;
2192 current_target
.to_close
= debug_to_close
;
2193 current_target
.to_attach
= debug_to_attach
;
2194 current_target
.to_post_attach
= debug_to_post_attach
;
2195 current_target
.to_require_attach
= debug_to_require_attach
;
2196 current_target
.to_detach
= debug_to_detach
;
2197 current_target
.to_require_detach
= debug_to_require_detach
;
2198 current_target
.to_resume
= debug_to_resume
;
2199 current_target
.to_wait
= debug_to_wait
;
2200 current_target
.to_post_wait
= debug_to_post_wait
;
2201 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2202 current_target
.to_store_registers
= debug_to_store_registers
;
2203 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2204 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2205 current_target
.to_files_info
= debug_to_files_info
;
2206 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2207 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2208 current_target
.to_terminal_init
= debug_to_terminal_init
;
2209 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2210 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2211 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2212 current_target
.to_terminal_info
= debug_to_terminal_info
;
2213 current_target
.to_kill
= debug_to_kill
;
2214 current_target
.to_load
= debug_to_load
;
2215 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2216 current_target
.to_create_inferior
= debug_to_create_inferior
;
2217 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2218 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2219 current_target
.to_clone_and_follow_inferior
= debug_to_clone_and_follow_inferior
;
2220 current_target
.to_post_follow_inferior_by_clone
= debug_to_post_follow_inferior_by_clone
;
2221 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2222 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2223 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2224 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2225 current_target
.to_has_forked
= debug_to_has_forked
;
2226 current_target
.to_has_vforked
= debug_to_has_vforked
;
2227 current_target
.to_can_follow_vfork_prior_to_exec
= debug_to_can_follow_vfork_prior_to_exec
;
2228 current_target
.to_post_follow_vfork
= debug_to_post_follow_vfork
;
2229 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2230 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2231 current_target
.to_has_execd
= debug_to_has_execd
;
2232 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2233 current_target
.to_has_syscall_event
= debug_to_has_syscall_event
;
2234 current_target
.to_has_exited
= debug_to_has_exited
;
2235 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2236 current_target
.to_can_run
= debug_to_can_run
;
2237 current_target
.to_notice_signals
= debug_to_notice_signals
;
2238 current_target
.to_thread_alive
= debug_to_thread_alive
;
2239 current_target
.to_find_new_threads
= debug_to_find_new_threads
;
2240 current_target
.to_stop
= debug_to_stop
;
2241 current_target
.to_query
= debug_to_query
;
2242 current_target
.to_rcmd
= debug_to_rcmd
;
2243 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
2244 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
2245 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2250 static char targ_desc
[] =
2251 "Names of targets and files being debugged.\n\
2252 Shows the entire stack of targets currently in use (including the exec-file,\n\
2253 core-file, and process, if any), as well as the symbol file name.";
2256 do_monitor_command (char *cmd
,
2259 if ((current_target
.to_rcmd
2260 == (void (*) (char *, struct ui_file
*)) tcomplain
)
2261 || (current_target
.to_rcmd
== debug_to_rcmd
2262 && (debug_target
.to_rcmd
2263 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
2265 error ("\"monitor\" command not supported by this target.\n");
2267 target_rcmd (cmd
, gdb_stdtarg
);
2271 initialize_targets (void)
2273 init_dummy_target ();
2274 push_target (&dummy_target
);
2276 add_info ("target", target_info
, targ_desc
);
2277 add_info ("files", target_info
, targ_desc
);
2280 (add_set_cmd ("target", class_maintenance
, var_zinteger
,
2281 (char *) &targetdebug
,
2282 "Set target debugging.\n\
2283 When non-zero, target debugging is enabled.", &setdebuglist
),
2287 (add_set_boolean_cmd
2288 ("trust-readonly-sections", class_support
,
2290 "Set mode for reading from readonly sections.\n\
2291 When this mode is on, memory reads from readonly sections (such as .text)\n\
2292 will be read from the object file instead of from the target. This will\n\
2293 result in significant performance improvement for remote targets.",
2297 add_com ("monitor", class_obscure
, do_monitor_command
,
2298 "Send a command to the remote monitor (remote targets only).");
2300 target_dcache
= dcache_init ();