1 /* Select target systems and architectures at runtime for GDB.
3 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
6 Contributed by Cygnus Support.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
27 #include "gdb_string.h"
42 static void target_info (char *, int);
44 static void maybe_kill_then_create_inferior (char *, char *, char **);
46 static void maybe_kill_then_attach (char *, int);
48 static void kill_or_be_killed (int);
50 static void default_terminal_info (char *, int);
52 static int default_region_size_ok_for_hw_watchpoint (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 static int return_minus_one (void);
66 void target_ignore (void);
68 static void target_command (char *, int);
70 static struct target_ops
*find_default_run_target (char *);
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). */
82 static int target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
,
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_disconnect (char *, int);
97 static void debug_to_resume (ptid_t
, int, enum target_signal
);
99 static ptid_t
debug_to_wait (ptid_t
, struct target_waitstatus
*);
101 static void debug_to_fetch_registers (int);
103 static void debug_to_store_registers (int);
105 static void debug_to_prepare_to_store (void);
107 static int debug_to_xfer_memory (CORE_ADDR
, char *, int, int,
108 struct mem_attrib
*, 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 int debug_to_can_use_hw_breakpoint (int, int, int);
118 static int debug_to_insert_hw_breakpoint (CORE_ADDR
, char *);
120 static int debug_to_remove_hw_breakpoint (CORE_ADDR
, char *);
122 static int debug_to_insert_watchpoint (CORE_ADDR
, int, int);
124 static int debug_to_remove_watchpoint (CORE_ADDR
, int, int);
126 static int debug_to_stopped_by_watchpoint (void);
128 static CORE_ADDR
debug_to_stopped_data_address (void);
130 static int debug_to_region_size_ok_for_hw_watchpoint (int);
132 static void debug_to_terminal_init (void);
134 static void debug_to_terminal_inferior (void);
136 static void debug_to_terminal_ours_for_output (void);
138 static void debug_to_terminal_save_ours (void);
140 static void debug_to_terminal_ours (void);
142 static void debug_to_terminal_info (char *, int);
144 static void debug_to_kill (void);
146 static void debug_to_load (char *, int);
148 static int debug_to_lookup_symbol (char *, CORE_ADDR
*);
150 static void debug_to_create_inferior (char *, char *, char **);
152 static void debug_to_mourn_inferior (void);
154 static int debug_to_can_run (void);
156 static void debug_to_notice_signals (ptid_t
);
158 static int debug_to_thread_alive (ptid_t
);
160 static void debug_to_stop (void);
162 static int debug_to_query (int /*char */ , char *, char *, int *);
164 /* Pointer to array of target architecture structures; the size of the
165 array; the current index into the array; the allocated size of the
167 struct target_ops
**target_structs
;
168 unsigned target_struct_size
;
169 unsigned target_struct_index
;
170 unsigned target_struct_allocsize
;
171 #define DEFAULT_ALLOCSIZE 10
173 /* The initial current target, so that there is always a semi-valid
176 static struct target_ops dummy_target
;
178 /* Top of target stack. */
180 static struct target_ops
*target_stack
;
182 /* The target structure we are currently using to talk to a process
183 or file or whatever "inferior" we have. */
185 struct target_ops current_target
;
187 /* Command list for target. */
189 static struct cmd_list_element
*targetlist
= NULL
;
191 /* Nonzero if we are debugging an attached outside process
192 rather than an inferior. */
196 /* Non-zero if we want to see trace of target level stuff. */
198 static int targetdebug
= 0;
200 static void setup_target_debug (void);
202 DCACHE
*target_dcache
;
204 /* The user just typed 'target' without the name of a target. */
207 target_command (char *arg
, int from_tty
)
209 fputs_filtered ("Argument required (target name). Try `help target'\n",
213 /* Add a possible target architecture to the list. */
216 add_target (struct target_ops
*t
)
220 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
221 target_structs
= (struct target_ops
**) xmalloc
222 (target_struct_allocsize
* sizeof (*target_structs
));
224 if (target_struct_size
>= target_struct_allocsize
)
226 target_struct_allocsize
*= 2;
227 target_structs
= (struct target_ops
**)
228 xrealloc ((char *) target_structs
,
229 target_struct_allocsize
* sizeof (*target_structs
));
231 target_structs
[target_struct_size
++] = t
;
233 if (targetlist
== NULL
)
234 add_prefix_cmd ("target", class_run
, target_command
,
235 "Connect to a target machine or process.\n\
236 The first argument is the type or protocol of the target machine.\n\
237 Remaining arguments are interpreted by the target protocol. For more\n\
238 information on the arguments for a particular protocol, type\n\
239 `help target ' followed by the protocol name.",
240 &targetlist
, "target ", 0, &cmdlist
);
241 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
252 target_load (char *arg
, int from_tty
)
254 dcache_invalidate (target_dcache
);
255 (*current_target
.to_load
) (arg
, from_tty
);
259 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
260 struct target_ops
*t
)
262 errno
= EIO
; /* Can't read/write this location */
263 return 0; /* No bytes handled */
269 error ("You can't do that when your target is `%s'",
270 current_target
.to_shortname
);
276 error ("You can't do that without a process to debug.");
280 nosymbol (char *name
, CORE_ADDR
*addrp
)
282 return 1; /* Symbol does not exist in target env */
286 nosupport_runtime (void)
288 if (ptid_equal (inferior_ptid
, null_ptid
))
291 error ("No run-time support for this");
296 default_terminal_info (char *args
, int from_tty
)
298 printf_unfiltered ("No saved terminal information.\n");
301 /* This is the default target_create_inferior and target_attach function.
302 If the current target is executing, it asks whether to kill it off.
303 If this function returns without calling error(), it has killed off
304 the target, and the operation should be attempted. */
307 kill_or_be_killed (int from_tty
)
309 if (target_has_execution
)
311 printf_unfiltered ("You are already running a program:\n");
312 target_files_info ();
313 if (query ("Kill it? "))
316 if (target_has_execution
)
317 error ("Killing the program did not help.");
322 error ("Program not killed.");
329 maybe_kill_then_attach (char *args
, int from_tty
)
331 kill_or_be_killed (from_tty
);
332 target_attach (args
, from_tty
);
336 maybe_kill_then_create_inferior (char *exec
, char *args
, char **env
)
338 kill_or_be_killed (0);
339 target_create_inferior (exec
, args
, env
);
342 /* Go through the target stack from top to bottom, copying over zero
343 entries in current_target, then filling in still empty entries. In
344 effect, we are doing class inheritance through the pushed target
347 NOTE: cagney/2003-10-17: The problem with this inheritance, as it
348 is currently implemented, is that it discards any knowledge of
349 which target an inherited method originally belonged to.
350 Consequently, new new target methods should instead explicitly and
351 locally search the target stack for the target that can handle the
355 update_current_target (void)
357 struct target_ops
*t
;
359 /* First, reset curren'ts contents. */
360 memset (¤t_target
, 0, sizeof (current_target
));
362 #define INHERIT(FIELD, TARGET) \
363 if (!current_target.FIELD) \
364 current_target.FIELD = (TARGET)->FIELD
366 for (t
= target_stack
; t
; t
= t
->beneath
)
368 INHERIT (to_shortname
, t
);
369 INHERIT (to_longname
, t
);
371 INHERIT (to_open
, t
);
372 INHERIT (to_close
, t
);
373 INHERIT (to_attach
, t
);
374 INHERIT (to_post_attach
, t
);
375 INHERIT (to_detach
, t
);
376 INHERIT (to_disconnect
, t
);
377 INHERIT (to_resume
, t
);
378 INHERIT (to_wait
, t
);
379 INHERIT (to_post_wait
, t
);
380 INHERIT (to_fetch_registers
, t
);
381 INHERIT (to_store_registers
, t
);
382 INHERIT (to_prepare_to_store
, t
);
383 INHERIT (to_xfer_memory
, t
);
384 INHERIT (to_files_info
, t
);
385 INHERIT (to_insert_breakpoint
, t
);
386 INHERIT (to_remove_breakpoint
, t
);
387 INHERIT (to_can_use_hw_breakpoint
, t
);
388 INHERIT (to_insert_hw_breakpoint
, t
);
389 INHERIT (to_remove_hw_breakpoint
, t
);
390 INHERIT (to_insert_watchpoint
, t
);
391 INHERIT (to_remove_watchpoint
, t
);
392 INHERIT (to_stopped_data_address
, t
);
393 INHERIT (to_stopped_by_watchpoint
, t
);
394 INHERIT (to_have_continuable_watchpoint
, t
);
395 INHERIT (to_region_size_ok_for_hw_watchpoint
, t
);
396 INHERIT (to_terminal_init
, t
);
397 INHERIT (to_terminal_inferior
, t
);
398 INHERIT (to_terminal_ours_for_output
, t
);
399 INHERIT (to_terminal_ours
, t
);
400 INHERIT (to_terminal_save_ours
, t
);
401 INHERIT (to_terminal_info
, t
);
402 INHERIT (to_kill
, t
);
403 INHERIT (to_load
, t
);
404 INHERIT (to_lookup_symbol
, t
);
405 INHERIT (to_create_inferior
, t
);
406 INHERIT (to_post_startup_inferior
, t
);
407 INHERIT (to_acknowledge_created_inferior
, t
);
408 INHERIT (to_insert_fork_catchpoint
, t
);
409 INHERIT (to_remove_fork_catchpoint
, t
);
410 INHERIT (to_insert_vfork_catchpoint
, t
);
411 INHERIT (to_remove_vfork_catchpoint
, t
);
412 INHERIT (to_follow_fork
, t
);
413 INHERIT (to_insert_exec_catchpoint
, t
);
414 INHERIT (to_remove_exec_catchpoint
, t
);
415 INHERIT (to_reported_exec_events_per_exec_call
, t
);
416 INHERIT (to_has_exited
, t
);
417 INHERIT (to_mourn_inferior
, t
);
418 INHERIT (to_can_run
, t
);
419 INHERIT (to_notice_signals
, t
);
420 INHERIT (to_thread_alive
, t
);
421 INHERIT (to_find_new_threads
, t
);
422 INHERIT (to_pid_to_str
, t
);
423 INHERIT (to_extra_thread_info
, t
);
424 INHERIT (to_stop
, t
);
425 INHERIT (to_query
, t
);
426 INHERIT (to_rcmd
, t
);
427 INHERIT (to_enable_exception_callback
, t
);
428 INHERIT (to_get_current_exception_event
, t
);
429 INHERIT (to_pid_to_exec_file
, t
);
430 INHERIT (to_stratum
, t
);
431 INHERIT (to_has_all_memory
, t
);
432 INHERIT (to_has_memory
, t
);
433 INHERIT (to_has_stack
, t
);
434 INHERIT (to_has_registers
, t
);
435 INHERIT (to_has_execution
, t
);
436 INHERIT (to_has_thread_control
, t
);
437 INHERIT (to_sections
, t
);
438 INHERIT (to_sections_end
, t
);
439 INHERIT (to_can_async_p
, t
);
440 INHERIT (to_is_async_p
, t
);
441 INHERIT (to_async
, t
);
442 INHERIT (to_async_mask_value
, t
);
443 INHERIT (to_find_memory_regions
, t
);
444 INHERIT (to_make_corefile_notes
, t
);
445 INHERIT (to_get_thread_local_address
, t
);
446 INHERIT (to_magic
, t
);
450 /* Clean up a target struct so it no longer has any zero pointers in
451 it. We default entries, at least to stubs that print error
454 #define de_fault(field, value) \
455 if (!current_target.field) \
456 current_target.field = value
459 (void (*) (char *, int))
465 maybe_kill_then_attach
);
466 de_fault (to_post_attach
,
470 (void (*) (char *, int))
472 de_fault (to_disconnect
,
473 (void (*) (char *, int))
476 (void (*) (ptid_t
, int, enum target_signal
))
479 (ptid_t (*) (ptid_t
, struct target_waitstatus
*))
481 de_fault (to_post_wait
,
482 (void (*) (ptid_t
, int))
484 de_fault (to_fetch_registers
,
487 de_fault (to_store_registers
,
490 de_fault (to_prepare_to_store
,
493 de_fault (to_xfer_memory
,
494 (int (*) (CORE_ADDR
, char *, int, int, struct mem_attrib
*, struct target_ops
*))
496 de_fault (to_files_info
,
497 (void (*) (struct target_ops
*))
499 de_fault (to_insert_breakpoint
,
500 memory_insert_breakpoint
);
501 de_fault (to_remove_breakpoint
,
502 memory_remove_breakpoint
);
503 de_fault (to_can_use_hw_breakpoint
,
504 (int (*) (int, int, int))
506 de_fault (to_insert_hw_breakpoint
,
507 (int (*) (CORE_ADDR
, char *))
509 de_fault (to_remove_hw_breakpoint
,
510 (int (*) (CORE_ADDR
, char *))
512 de_fault (to_insert_watchpoint
,
513 (int (*) (CORE_ADDR
, int, int))
515 de_fault (to_remove_watchpoint
,
516 (int (*) (CORE_ADDR
, int, int))
518 de_fault (to_stopped_by_watchpoint
,
521 de_fault (to_stopped_data_address
,
522 (CORE_ADDR (*) (void))
524 de_fault (to_region_size_ok_for_hw_watchpoint
,
525 default_region_size_ok_for_hw_watchpoint
);
526 de_fault (to_terminal_init
,
529 de_fault (to_terminal_inferior
,
532 de_fault (to_terminal_ours_for_output
,
535 de_fault (to_terminal_ours
,
538 de_fault (to_terminal_save_ours
,
541 de_fault (to_terminal_info
,
542 default_terminal_info
);
547 (void (*) (char *, int))
549 de_fault (to_lookup_symbol
,
550 (int (*) (char *, CORE_ADDR
*))
552 de_fault (to_create_inferior
,
553 maybe_kill_then_create_inferior
);
554 de_fault (to_post_startup_inferior
,
557 de_fault (to_acknowledge_created_inferior
,
560 de_fault (to_insert_fork_catchpoint
,
563 de_fault (to_remove_fork_catchpoint
,
566 de_fault (to_insert_vfork_catchpoint
,
569 de_fault (to_remove_vfork_catchpoint
,
572 de_fault (to_follow_fork
,
575 de_fault (to_insert_exec_catchpoint
,
578 de_fault (to_remove_exec_catchpoint
,
581 de_fault (to_reported_exec_events_per_exec_call
,
584 de_fault (to_has_exited
,
585 (int (*) (int, int, int *))
587 de_fault (to_mourn_inferior
,
590 de_fault (to_can_run
,
592 de_fault (to_notice_signals
,
595 de_fault (to_thread_alive
,
598 de_fault (to_find_new_threads
,
601 de_fault (to_extra_thread_info
,
602 (char *(*) (struct thread_info
*))
608 (void (*) (char *, struct ui_file
*))
610 de_fault (to_enable_exception_callback
,
611 (struct symtab_and_line
* (*) (enum exception_event_kind
, int))
613 de_fault (to_get_current_exception_event
,
614 (struct exception_event_record
* (*) (void))
616 de_fault (to_pid_to_exec_file
,
619 de_fault (to_can_async_p
,
622 de_fault (to_is_async_p
,
626 (void (*) (void (*) (enum inferior_event_type
, void*), void*))
630 /* Finally, position the target-stack beneath the squashed
631 "current_target". That way code looking for a non-inherited
632 target method can quickly and simply find it. */
633 current_target
.beneath
= target_stack
;
636 /* Push a new target type into the stack of the existing target accessors,
637 possibly superseding some of the existing accessors.
639 Result is zero if the pushed target ended up on top of the stack,
640 nonzero if at least one target is on top of it.
642 Rather than allow an empty stack, we always have the dummy target at
643 the bottom stratum, so we can call the function vectors without
647 push_target (struct target_ops
*t
)
649 struct target_ops
**cur
;
651 /* Check magic number. If wrong, it probably means someone changed
652 the struct definition, but not all the places that initialize one. */
653 if (t
->to_magic
!= OPS_MAGIC
)
655 fprintf_unfiltered (gdb_stderr
,
656 "Magic number of %s target struct wrong\n",
658 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
661 /* Find the proper stratum to install this target in. */
662 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
664 if ((int) (t
->to_stratum
) >= (int) (*cur
)->to_stratum
)
668 /* If there's already targets at this stratum, remove them. */
669 /* FIXME: cagney/2003-10-15: I think this should be poping all
670 targets to CUR, and not just those at this stratum level. */
671 while ((*cur
) != NULL
&& t
->to_stratum
== (*cur
)->to_stratum
)
673 /* There's already something at this stratum level. Close it,
674 and un-hook it from the stack. */
675 struct target_ops
*tmp
= (*cur
);
676 (*cur
) = (*cur
)->beneath
;
682 /* We have removed all targets in our stratum, now add the new one. */
686 update_current_target ();
689 setup_target_debug ();
692 return (t
!= target_stack
);
695 /* Remove a target_ops vector from the stack, wherever it may be.
696 Return how many times it was removed (0 or 1). */
699 unpush_target (struct target_ops
*t
)
701 struct target_ops
**cur
;
702 struct target_ops
*tmp
;
705 t
->to_close (0); /* Let it clean up */
707 /* Look for the specified target. Note that we assume that a target
708 can only occur once in the target stack. */
710 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
717 return 0; /* Didn't find target_ops, quit now */
719 /* Unchain the target */
721 (*cur
) = (*cur
)->beneath
;
724 update_current_target ();
732 (current_target
.to_close
) (0); /* Let it clean up */
733 if (unpush_target (target_stack
) == 1)
736 fprintf_unfiltered (gdb_stderr
,
737 "pop_target couldn't find target %s\n",
738 current_target
.to_shortname
);
739 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
743 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
745 /* target_read_string -- read a null terminated string, up to LEN bytes,
746 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
747 Set *STRING to a pointer to malloc'd memory containing the data; the caller
748 is responsible for freeing it. Return the number of bytes successfully
752 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
754 int tlen
, origlen
, offset
, i
;
758 int buffer_allocated
;
760 unsigned int nbytes_read
= 0;
762 /* Small for testing. */
763 buffer_allocated
= 4;
764 buffer
= xmalloc (buffer_allocated
);
771 tlen
= MIN (len
, 4 - (memaddr
& 3));
772 offset
= memaddr
& 3;
774 errcode
= target_xfer_memory (memaddr
& ~3, buf
, 4, 0);
777 /* The transfer request might have crossed the boundary to an
778 unallocated region of memory. Retry the transfer, requesting
782 errcode
= target_xfer_memory (memaddr
, buf
, 1, 0);
787 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
790 bytes
= bufptr
- buffer
;
791 buffer_allocated
*= 2;
792 buffer
= xrealloc (buffer
, buffer_allocated
);
793 bufptr
= buffer
+ bytes
;
796 for (i
= 0; i
< tlen
; i
++)
798 *bufptr
++ = buf
[i
+ offset
];
799 if (buf
[i
+ offset
] == '\000')
801 nbytes_read
+= i
+ 1;
818 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
819 GDB's memory at MYADDR. Returns either 0 for success or an errno value
822 If an error occurs, no guarantee is made about the contents of the data at
823 MYADDR. In particular, the caller should not depend upon partial reads
824 filling the buffer with good data. There is no way for the caller to know
825 how much good data might have been transfered anyway. Callers that can
826 deal with partial reads should call target_read_memory_partial. */
829 target_read_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
831 return target_xfer_memory (memaddr
, myaddr
, len
, 0);
835 target_write_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
837 return target_xfer_memory (memaddr
, myaddr
, len
, 1);
840 static int trust_readonly
= 0;
842 /* Move memory to or from the targets. The top target gets priority;
843 if it cannot handle it, it is offered to the next one down, etc.
845 Result is -1 on error, or the number of bytes transfered. */
848 do_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
849 struct mem_attrib
*attrib
)
853 struct target_ops
*t
;
855 /* Zero length requests are ok and require no work. */
859 /* to_xfer_memory is not guaranteed to set errno, even when it returns
863 if (!write
&& trust_readonly
)
865 /* User-settable option, "trust-readonly-sections". If true,
866 then memory from any SEC_READONLY bfd section may be read
867 directly from the bfd file. */
869 struct section_table
*secp
;
871 for (secp
= current_target
.to_sections
;
872 secp
< current_target
.to_sections_end
;
875 if (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
877 if (memaddr
>= secp
->addr
&& memaddr
< secp
->endaddr
)
878 return xfer_memory (memaddr
, myaddr
, len
, 0,
879 attrib
, ¤t_target
);
883 /* The quick case is that the top target can handle the transfer. */
884 res
= current_target
.to_xfer_memory
885 (memaddr
, myaddr
, len
, write
, attrib
, ¤t_target
);
887 /* If res <= 0 then we call it again in the loop. Ah well. */
890 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
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
);
1060 target_info (char *args
, int from_tty
)
1062 struct target_ops
*t
;
1063 int has_all_mem
= 0;
1065 if (symfile_objfile
!= NULL
)
1066 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
1068 #ifdef FILES_INFO_HOOK
1069 if (FILES_INFO_HOOK ())
1073 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
1075 if (!t
->to_has_memory
)
1078 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
1081 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1082 printf_unfiltered ("%s:\n", t
->to_longname
);
1083 (t
->to_files_info
) (t
);
1084 has_all_mem
= t
->to_has_all_memory
;
1088 /* This is to be called by the open routine before it does
1092 target_preopen (int from_tty
)
1096 if (target_has_execution
)
1099 || query ("A program is being debugged already. Kill it? "))
1102 error ("Program not killed.");
1105 /* Calling target_kill may remove the target from the stack. But if
1106 it doesn't (which seems like a win for UDI), remove it now. */
1108 if (target_has_execution
)
1112 /* Detach a target after doing deferred register stores. */
1115 target_detach (char *args
, int from_tty
)
1117 /* Handle any optimized stores to the inferior. */
1118 #ifdef DO_DEFERRED_STORES
1121 (current_target
.to_detach
) (args
, from_tty
);
1125 target_disconnect (char *args
, int from_tty
)
1127 /* Handle any optimized stores to the inferior. */
1128 #ifdef DO_DEFERRED_STORES
1131 (current_target
.to_disconnect
) (args
, from_tty
);
1135 target_link (char *modname
, CORE_ADDR
*t_reloc
)
1137 if (STREQ (current_target
.to_shortname
, "rombug"))
1139 (current_target
.to_lookup_symbol
) (modname
, t_reloc
);
1141 error ("Unable to link to %s and get relocation in rombug", modname
);
1144 *t_reloc
= (CORE_ADDR
) -1;
1148 target_async_mask (int mask
)
1150 int saved_async_masked_status
= target_async_mask_value
;
1151 target_async_mask_value
= mask
;
1152 return saved_async_masked_status
;
1155 /* Look through the list of possible targets for a target that can
1156 execute a run or attach command without any other data. This is
1157 used to locate the default process stratum.
1159 Result is always valid (error() is called for errors). */
1161 static struct target_ops
*
1162 find_default_run_target (char *do_mesg
)
1164 struct target_ops
**t
;
1165 struct target_ops
*runable
= NULL
;
1170 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1173 if ((*t
)->to_can_run
&& target_can_run (*t
))
1181 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
1187 find_default_attach (char *args
, int from_tty
)
1189 struct target_ops
*t
;
1191 t
= find_default_run_target ("attach");
1192 (t
->to_attach
) (args
, from_tty
);
1197 find_default_create_inferior (char *exec_file
, char *allargs
, char **env
)
1199 struct target_ops
*t
;
1201 t
= find_default_run_target ("run");
1202 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
1207 default_region_size_ok_for_hw_watchpoint (int byte_count
)
1209 return (byte_count
<= DEPRECATED_REGISTER_SIZE
);
1225 return_minus_one (void)
1231 * Resize the to_sections pointer. Also make sure that anyone that
1232 * was holding on to an old value of it gets updated.
1233 * Returns the old size.
1237 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1239 struct target_ops
**t
;
1240 struct section_table
*old_value
;
1243 old_value
= target
->to_sections
;
1245 if (target
->to_sections
)
1247 old_count
= target
->to_sections_end
- target
->to_sections
;
1248 target
->to_sections
= (struct section_table
*)
1249 xrealloc ((char *) target
->to_sections
,
1250 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1255 target
->to_sections
= (struct section_table
*)
1256 xmalloc ((sizeof (struct section_table
)) * num_added
);
1258 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1260 /* Check to see if anyone else was pointing to this structure.
1261 If old_value was null, then no one was. */
1265 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1268 if ((*t
)->to_sections
== old_value
)
1270 (*t
)->to_sections
= target
->to_sections
;
1271 (*t
)->to_sections_end
= target
->to_sections_end
;
1280 /* Remove all target sections taken from ABFD.
1282 Scan the current target stack for targets whose section tables
1283 refer to sections from BFD, and remove those sections. We use this
1284 when we notice that the inferior has unloaded a shared object, for
1287 remove_target_sections (bfd
*abfd
)
1289 struct target_ops
**t
;
1291 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; t
++)
1293 struct section_table
*src
, *dest
;
1295 dest
= (*t
)->to_sections
;
1296 for (src
= (*t
)->to_sections
; src
< (*t
)->to_sections_end
; src
++)
1297 if (src
->bfd
!= abfd
)
1299 /* Keep this section. */
1300 if (dest
< src
) *dest
= *src
;
1304 /* If we've dropped any sections, resize the section table. */
1306 target_resize_to_sections (*t
, dest
- src
);
1313 /* Find a single runnable target in the stack and return it. If for
1314 some reason there is more than one, return NULL. */
1317 find_run_target (void)
1319 struct target_ops
**t
;
1320 struct target_ops
*runable
= NULL
;
1325 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1327 if ((*t
)->to_can_run
&& target_can_run (*t
))
1334 return (count
== 1 ? runable
: NULL
);
1337 /* Find a single core_stratum target in the list of targets and return it.
1338 If for some reason there is more than one, return NULL. */
1341 find_core_target (void)
1343 struct target_ops
**t
;
1344 struct target_ops
*runable
= NULL
;
1349 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1352 if ((*t
)->to_stratum
== core_stratum
)
1359 return (count
== 1 ? runable
: NULL
);
1363 * Find the next target down the stack from the specified target.
1367 find_target_beneath (struct target_ops
*t
)
1373 /* The inferior process has died. Long live the inferior! */
1376 generic_mourn_inferior (void)
1378 extern int show_breakpoint_hit_counts
;
1380 inferior_ptid
= null_ptid
;
1382 breakpoint_init_inferior (inf_exited
);
1383 registers_changed ();
1385 #ifdef CLEAR_DEFERRED_STORES
1386 /* Delete any pending stores to the inferior... */
1387 CLEAR_DEFERRED_STORES
;
1390 reopen_exec_file ();
1391 reinit_frame_cache ();
1393 /* It is confusing to the user for ignore counts to stick around
1394 from previous runs of the inferior. So clear them. */
1395 /* However, it is more confusing for the ignore counts to disappear when
1396 using hit counts. So don't clear them if we're counting hits. */
1397 if (!show_breakpoint_hit_counts
)
1398 breakpoint_clear_ignore_counts ();
1404 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1405 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1406 translation of that in OURSTATUS. */
1408 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
1410 #ifdef CHILD_SPECIAL_WAITSTATUS
1411 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1412 if it wants to deal with hoststatus. */
1413 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
1417 if (WIFEXITED (hoststatus
))
1419 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1420 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
1422 else if (!WIFSTOPPED (hoststatus
))
1424 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1425 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
1429 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
1430 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
1434 /* Returns zero to leave the inferior alone, one to interrupt it. */
1435 int (*target_activity_function
) (void);
1436 int target_activity_fd
;
1438 /* Convert a normal process ID to a string. Returns the string in a static
1442 normal_pid_to_str (ptid_t ptid
)
1444 static char buf
[30];
1446 sprintf (buf
, "process %d", PIDGET (ptid
));
1450 /* Some targets (such as ttrace-based HPUX) don't allow us to request
1451 notification of inferior events such as fork and vork immediately
1452 after the inferior is created. (This because of how gdb gets an
1453 inferior created via invoking a shell to do it. In such a scenario,
1454 if the shell init file has commands in it, the shell will fork and
1455 exec for each of those commands, and we will see each such fork
1458 This function is used by all targets that allow us to request
1459 notification of forks, etc at inferior creation time; e.g., in
1460 target_acknowledge_forked_child.
1463 normal_target_post_startup_inferior (ptid_t ptid
)
1465 /* This space intentionally left blank. */
1468 /* Error-catcher for target_find_memory_regions */
1469 static int dummy_find_memory_regions (int (*ignore1
) (), void *ignore2
)
1471 error ("No target.");
1475 /* Error-catcher for target_make_corefile_notes */
1476 static char * dummy_make_corefile_notes (bfd
*ignore1
, int *ignore2
)
1478 error ("No target.");
1482 /* Set up the handful of non-empty slots needed by the dummy target
1486 init_dummy_target (void)
1488 dummy_target
.to_shortname
= "None";
1489 dummy_target
.to_longname
= "None";
1490 dummy_target
.to_doc
= "";
1491 dummy_target
.to_attach
= find_default_attach
;
1492 dummy_target
.to_create_inferior
= find_default_create_inferior
;
1493 dummy_target
.to_pid_to_str
= normal_pid_to_str
;
1494 dummy_target
.to_stratum
= dummy_stratum
;
1495 dummy_target
.to_find_memory_regions
= dummy_find_memory_regions
;
1496 dummy_target
.to_make_corefile_notes
= dummy_make_corefile_notes
;
1497 dummy_target
.to_magic
= OPS_MAGIC
;
1501 static struct target_ops debug_target
;
1504 debug_to_open (char *args
, int from_tty
)
1506 debug_target
.to_open (args
, from_tty
);
1508 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
1512 debug_to_close (int quitting
)
1514 debug_target
.to_close (quitting
);
1516 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
1520 debug_to_attach (char *args
, int from_tty
)
1522 debug_target
.to_attach (args
, from_tty
);
1524 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
1529 debug_to_post_attach (int pid
)
1531 debug_target
.to_post_attach (pid
);
1533 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
1537 debug_to_detach (char *args
, int from_tty
)
1539 debug_target
.to_detach (args
, from_tty
);
1541 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
1545 debug_to_disconnect (char *args
, int from_tty
)
1547 debug_target
.to_disconnect (args
, from_tty
);
1549 fprintf_unfiltered (gdb_stdlog
, "target_disconnect (%s, %d)\n",
1554 debug_to_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
1556 debug_target
.to_resume (ptid
, step
, siggnal
);
1558 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", PIDGET (ptid
),
1559 step
? "step" : "continue",
1560 target_signal_to_name (siggnal
));
1564 debug_to_wait (ptid_t ptid
, struct target_waitstatus
*status
)
1568 retval
= debug_target
.to_wait (ptid
, status
);
1570 fprintf_unfiltered (gdb_stdlog
,
1571 "target_wait (%d, status) = %d, ", PIDGET (ptid
),
1573 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
1574 switch (status
->kind
)
1576 case TARGET_WAITKIND_EXITED
:
1577 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
1578 status
->value
.integer
);
1580 case TARGET_WAITKIND_STOPPED
:
1581 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
1582 target_signal_to_name (status
->value
.sig
));
1584 case TARGET_WAITKIND_SIGNALLED
:
1585 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
1586 target_signal_to_name (status
->value
.sig
));
1588 case TARGET_WAITKIND_LOADED
:
1589 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
1591 case TARGET_WAITKIND_FORKED
:
1592 fprintf_unfiltered (gdb_stdlog
, "forked\n");
1594 case TARGET_WAITKIND_VFORKED
:
1595 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
1597 case TARGET_WAITKIND_EXECD
:
1598 fprintf_unfiltered (gdb_stdlog
, "execd\n");
1600 case TARGET_WAITKIND_SPURIOUS
:
1601 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
1604 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
1612 debug_to_post_wait (ptid_t ptid
, int status
)
1614 debug_target
.to_post_wait (ptid
, status
);
1616 fprintf_unfiltered (gdb_stdlog
, "target_post_wait (%d, %d)\n",
1617 PIDGET (ptid
), status
);
1621 debug_print_register (const char * func
, int regno
)
1623 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
1624 if (regno
>= 0 && regno
< NUM_REGS
+ NUM_PSEUDO_REGS
1625 && REGISTER_NAME (regno
) != NULL
&& REGISTER_NAME (regno
)[0] != '\0')
1626 fprintf_unfiltered (gdb_stdlog
, "(%s)", REGISTER_NAME (regno
));
1628 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
1632 unsigned char buf
[MAX_REGISTER_SIZE
];
1633 deprecated_read_register_gen (regno
, buf
);
1634 fprintf_unfiltered (gdb_stdlog
, " = ");
1635 for (i
= 0; i
< DEPRECATED_REGISTER_RAW_SIZE (regno
); i
++)
1637 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
1639 if (DEPRECATED_REGISTER_RAW_SIZE (regno
) <= sizeof (LONGEST
))
1641 fprintf_unfiltered (gdb_stdlog
, " 0x%s %s",
1642 paddr_nz (read_register (regno
)),
1643 paddr_d (read_register (regno
)));
1646 fprintf_unfiltered (gdb_stdlog
, "\n");
1650 debug_to_fetch_registers (int regno
)
1652 debug_target
.to_fetch_registers (regno
);
1653 debug_print_register ("target_fetch_registers", regno
);
1657 debug_to_store_registers (int regno
)
1659 debug_target
.to_store_registers (regno
);
1660 debug_print_register ("target_store_registers", regno
);
1661 fprintf_unfiltered (gdb_stdlog
, "\n");
1665 debug_to_prepare_to_store (void)
1667 debug_target
.to_prepare_to_store ();
1669 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
1673 debug_to_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
1674 struct mem_attrib
*attrib
,
1675 struct target_ops
*target
)
1679 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
,
1682 fprintf_unfiltered (gdb_stdlog
,
1683 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
1684 (unsigned int) memaddr
, /* possable truncate long long */
1685 len
, write
? "write" : "read", retval
);
1693 fputs_unfiltered (", bytes =", gdb_stdlog
);
1694 for (i
= 0; i
< retval
; i
++)
1696 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
1697 fprintf_unfiltered (gdb_stdlog
, "\n");
1698 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1702 fputc_unfiltered ('\n', gdb_stdlog
);
1708 debug_to_files_info (struct target_ops
*target
)
1710 debug_target
.to_files_info (target
);
1712 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
1716 debug_to_insert_breakpoint (CORE_ADDR addr
, char *save
)
1720 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
1722 fprintf_unfiltered (gdb_stdlog
,
1723 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
1724 (unsigned long) addr
,
1725 (unsigned long) retval
);
1730 debug_to_remove_breakpoint (CORE_ADDR addr
, char *save
)
1734 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
1736 fprintf_unfiltered (gdb_stdlog
,
1737 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
1738 (unsigned long) addr
,
1739 (unsigned long) retval
);
1744 debug_to_can_use_hw_breakpoint (int type
, int cnt
, int from_tty
)
1748 retval
= debug_target
.to_can_use_hw_breakpoint (type
, cnt
, from_tty
);
1750 fprintf_unfiltered (gdb_stdlog
,
1751 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
1752 (unsigned long) type
,
1753 (unsigned long) cnt
,
1754 (unsigned long) from_tty
,
1755 (unsigned long) retval
);
1760 debug_to_region_size_ok_for_hw_watchpoint (int byte_count
)
1764 retval
= debug_target
.to_region_size_ok_for_hw_watchpoint (byte_count
);
1766 fprintf_unfiltered (gdb_stdlog
,
1767 "TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT (%ld) = 0x%lx\n",
1768 (unsigned long) byte_count
,
1769 (unsigned long) retval
);
1774 debug_to_stopped_by_watchpoint (void)
1778 retval
= debug_target
.to_stopped_by_watchpoint ();
1780 fprintf_unfiltered (gdb_stdlog
,
1781 "STOPPED_BY_WATCHPOINT () = %ld\n",
1782 (unsigned long) retval
);
1787 debug_to_stopped_data_address (void)
1791 retval
= debug_target
.to_stopped_data_address ();
1793 fprintf_unfiltered (gdb_stdlog
,
1794 "target_stopped_data_address () = 0x%lx\n",
1795 (unsigned long) retval
);
1800 debug_to_insert_hw_breakpoint (CORE_ADDR addr
, char *save
)
1804 retval
= debug_target
.to_insert_hw_breakpoint (addr
, save
);
1806 fprintf_unfiltered (gdb_stdlog
,
1807 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
1808 (unsigned long) addr
,
1809 (unsigned long) retval
);
1814 debug_to_remove_hw_breakpoint (CORE_ADDR addr
, char *save
)
1818 retval
= debug_target
.to_remove_hw_breakpoint (addr
, save
);
1820 fprintf_unfiltered (gdb_stdlog
,
1821 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
1822 (unsigned long) addr
,
1823 (unsigned long) retval
);
1828 debug_to_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
1832 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
1834 fprintf_unfiltered (gdb_stdlog
,
1835 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1836 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
1841 debug_to_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
1845 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
1847 fprintf_unfiltered (gdb_stdlog
,
1848 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1849 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
1854 debug_to_terminal_init (void)
1856 debug_target
.to_terminal_init ();
1858 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
1862 debug_to_terminal_inferior (void)
1864 debug_target
.to_terminal_inferior ();
1866 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
1870 debug_to_terminal_ours_for_output (void)
1872 debug_target
.to_terminal_ours_for_output ();
1874 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
1878 debug_to_terminal_ours (void)
1880 debug_target
.to_terminal_ours ();
1882 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
1886 debug_to_terminal_save_ours (void)
1888 debug_target
.to_terminal_save_ours ();
1890 fprintf_unfiltered (gdb_stdlog
, "target_terminal_save_ours ()\n");
1894 debug_to_terminal_info (char *arg
, int from_tty
)
1896 debug_target
.to_terminal_info (arg
, from_tty
);
1898 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
1903 debug_to_kill (void)
1905 debug_target
.to_kill ();
1907 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
1911 debug_to_load (char *args
, int from_tty
)
1913 debug_target
.to_load (args
, from_tty
);
1915 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
1919 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
1923 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
1925 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
1931 debug_to_create_inferior (char *exec_file
, char *args
, char **env
)
1933 debug_target
.to_create_inferior (exec_file
, args
, env
);
1935 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx)\n",
1940 debug_to_post_startup_inferior (ptid_t ptid
)
1942 debug_target
.to_post_startup_inferior (ptid
);
1944 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
1949 debug_to_acknowledge_created_inferior (int pid
)
1951 debug_target
.to_acknowledge_created_inferior (pid
);
1953 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
1958 debug_to_insert_fork_catchpoint (int pid
)
1962 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
1964 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
1971 debug_to_remove_fork_catchpoint (int pid
)
1975 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
1977 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
1984 debug_to_insert_vfork_catchpoint (int pid
)
1988 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
1990 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)= %d\n",
1997 debug_to_remove_vfork_catchpoint (int pid
)
2001 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
2003 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
2010 debug_to_follow_fork (int follow_child
)
2012 int retval
= debug_target
.to_follow_fork (follow_child
);
2014 fprintf_unfiltered (gdb_stdlog
, "target_follow_fork (%d) = %d\n",
2015 follow_child
, retval
);
2021 debug_to_insert_exec_catchpoint (int pid
)
2025 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
2027 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
2034 debug_to_remove_exec_catchpoint (int pid
)
2038 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
2040 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2047 debug_to_reported_exec_events_per_exec_call (void)
2049 int reported_exec_events
;
2051 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2053 fprintf_unfiltered (gdb_stdlog
,
2054 "target_reported_exec_events_per_exec_call () = %d\n",
2055 reported_exec_events
);
2057 return reported_exec_events
;
2061 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
2065 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2067 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2068 pid
, wait_status
, *exit_status
, has_exited
);
2074 debug_to_mourn_inferior (void)
2076 debug_target
.to_mourn_inferior ();
2078 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2082 debug_to_can_run (void)
2086 retval
= debug_target
.to_can_run ();
2088 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2094 debug_to_notice_signals (ptid_t ptid
)
2096 debug_target
.to_notice_signals (ptid
);
2098 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n",
2103 debug_to_thread_alive (ptid_t ptid
)
2107 retval
= debug_target
.to_thread_alive (ptid
);
2109 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2110 PIDGET (ptid
), retval
);
2116 debug_to_find_new_threads (void)
2118 debug_target
.to_find_new_threads ();
2120 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog
);
2124 debug_to_stop (void)
2126 debug_target
.to_stop ();
2128 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2132 debug_to_query (int type
, char *req
, char *resp
, int *siz
)
2136 retval
= debug_target
.to_query (type
, req
, resp
, siz
);
2138 fprintf_unfiltered (gdb_stdlog
, "target_query (%c, %s, %s, %d) = %d\n", type
, req
, resp
, *siz
, retval
);
2144 debug_to_rcmd (char *command
,
2145 struct ui_file
*outbuf
)
2147 debug_target
.to_rcmd (command
, outbuf
);
2148 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2151 static struct symtab_and_line
*
2152 debug_to_enable_exception_callback (enum exception_event_kind kind
, int enable
)
2154 struct symtab_and_line
*result
;
2155 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2156 fprintf_unfiltered (gdb_stdlog
,
2157 "target get_exception_callback_sal (%d, %d)\n",
2162 static struct exception_event_record
*
2163 debug_to_get_current_exception_event (void)
2165 struct exception_event_record
*result
;
2166 result
= debug_target
.to_get_current_exception_event ();
2167 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2172 debug_to_pid_to_exec_file (int pid
)
2176 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2178 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2185 setup_target_debug (void)
2187 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2189 current_target
.to_open
= debug_to_open
;
2190 current_target
.to_close
= debug_to_close
;
2191 current_target
.to_attach
= debug_to_attach
;
2192 current_target
.to_post_attach
= debug_to_post_attach
;
2193 current_target
.to_detach
= debug_to_detach
;
2194 current_target
.to_disconnect
= debug_to_disconnect
;
2195 current_target
.to_resume
= debug_to_resume
;
2196 current_target
.to_wait
= debug_to_wait
;
2197 current_target
.to_post_wait
= debug_to_post_wait
;
2198 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2199 current_target
.to_store_registers
= debug_to_store_registers
;
2200 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2201 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2202 current_target
.to_files_info
= debug_to_files_info
;
2203 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2204 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2205 current_target
.to_can_use_hw_breakpoint
= debug_to_can_use_hw_breakpoint
;
2206 current_target
.to_insert_hw_breakpoint
= debug_to_insert_hw_breakpoint
;
2207 current_target
.to_remove_hw_breakpoint
= debug_to_remove_hw_breakpoint
;
2208 current_target
.to_insert_watchpoint
= debug_to_insert_watchpoint
;
2209 current_target
.to_remove_watchpoint
= debug_to_remove_watchpoint
;
2210 current_target
.to_stopped_by_watchpoint
= debug_to_stopped_by_watchpoint
;
2211 current_target
.to_stopped_data_address
= debug_to_stopped_data_address
;
2212 current_target
.to_region_size_ok_for_hw_watchpoint
= debug_to_region_size_ok_for_hw_watchpoint
;
2213 current_target
.to_terminal_init
= debug_to_terminal_init
;
2214 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2215 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2216 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2217 current_target
.to_terminal_save_ours
= debug_to_terminal_save_ours
;
2218 current_target
.to_terminal_info
= debug_to_terminal_info
;
2219 current_target
.to_kill
= debug_to_kill
;
2220 current_target
.to_load
= debug_to_load
;
2221 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2222 current_target
.to_create_inferior
= debug_to_create_inferior
;
2223 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2224 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2225 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2226 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2227 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2228 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2229 current_target
.to_follow_fork
= debug_to_follow_fork
;
2230 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2231 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2232 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2233 current_target
.to_has_exited
= debug_to_has_exited
;
2234 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2235 current_target
.to_can_run
= debug_to_can_run
;
2236 current_target
.to_notice_signals
= debug_to_notice_signals
;
2237 current_target
.to_thread_alive
= debug_to_thread_alive
;
2238 current_target
.to_find_new_threads
= debug_to_find_new_threads
;
2239 current_target
.to_stop
= debug_to_stop
;
2240 current_target
.to_query
= debug_to_query
;
2241 current_target
.to_rcmd
= debug_to_rcmd
;
2242 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
2243 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
2244 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2249 static char targ_desc
[] =
2250 "Names of targets and files being debugged.\n\
2251 Shows the entire stack of targets currently in use (including the exec-file,\n\
2252 core-file, and process, if any), as well as the symbol file name.";
2255 do_monitor_command (char *cmd
,
2258 if ((current_target
.to_rcmd
2259 == (void (*) (char *, struct ui_file
*)) tcomplain
)
2260 || (current_target
.to_rcmd
== debug_to_rcmd
2261 && (debug_target
.to_rcmd
2262 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
2264 error ("\"monitor\" command not supported by this target.\n");
2266 target_rcmd (cmd
, gdb_stdtarg
);
2270 initialize_targets (void)
2272 init_dummy_target ();
2273 push_target (&dummy_target
);
2275 add_info ("target", target_info
, targ_desc
);
2276 add_info ("files", target_info
, targ_desc
);
2279 (add_set_cmd ("target", class_maintenance
, var_zinteger
,
2280 (char *) &targetdebug
,
2281 "Set target debugging.\n\
2282 When non-zero, target debugging is enabled.", &setdebuglist
),
2285 add_setshow_boolean_cmd ("trust-readonly-sections", class_support
,
2287 Set mode for reading from readonly sections.\n\
2288 When this mode is on, memory reads from readonly sections (such as .text)\n\
2289 will be read from the object file instead of from the target. This will\n\
2290 result in significant performance improvement for remote targets.", "\
2291 Show mode for reading from readonly sections.\n",
2293 &setlist
, &showlist
);
2295 add_com ("monitor", class_obscure
, do_monitor_command
,
2296 "Send a command to the remote monitor (remote targets only).");
2298 target_dcache
= dcache_init ();