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 maybe_kill_then_attach (char *, int);
49 static void kill_or_be_killed (int);
51 static void default_terminal_info (char *, int);
53 static int default_region_size_ok_for_hw_watchpoint (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 static int return_minus_one (void);
67 void target_ignore (void);
69 static void target_command (char *, int);
71 static struct target_ops
*find_default_run_target (char *);
73 static void update_current_target (void);
75 static void nosupport_runtime (void);
77 static void normal_target_post_startup_inferior (ptid_t ptid
);
79 /* Transfer LEN bytes between target address MEMADDR and GDB address
80 MYADDR. Returns 0 for success, errno code for failure (which
81 includes partial transfers -- if you want a more useful response to
82 partial transfers, try either target_read_memory_partial or
83 target_write_memory_partial). */
85 static int target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
,
88 static void init_dummy_target (void);
90 static void debug_to_open (char *, int);
92 static void debug_to_close (int);
94 static void debug_to_attach (char *, int);
96 static void debug_to_detach (char *, int);
98 static void debug_to_disconnect (char *, int);
100 static void debug_to_resume (ptid_t
, int, enum target_signal
);
102 static ptid_t
debug_to_wait (ptid_t
, struct target_waitstatus
*);
104 static void debug_to_fetch_registers (int);
106 static void debug_to_store_registers (int);
108 static void debug_to_prepare_to_store (void);
110 static int debug_to_xfer_memory (CORE_ADDR
, char *, int, int,
111 struct mem_attrib
*, struct target_ops
*);
113 static void debug_to_files_info (struct target_ops
*);
115 static int debug_to_insert_breakpoint (CORE_ADDR
, char *);
117 static int debug_to_remove_breakpoint (CORE_ADDR
, char *);
119 static int debug_to_can_use_hw_breakpoint (int, int, int);
121 static int debug_to_insert_hw_breakpoint (CORE_ADDR
, char *);
123 static int debug_to_remove_hw_breakpoint (CORE_ADDR
, char *);
125 static int debug_to_insert_watchpoint (CORE_ADDR
, int, int);
127 static int debug_to_remove_watchpoint (CORE_ADDR
, int, int);
129 static int debug_to_stopped_by_watchpoint (void);
131 static CORE_ADDR
debug_to_stopped_data_address (void);
133 static int debug_to_region_size_ok_for_hw_watchpoint (int);
135 static void debug_to_terminal_init (void);
137 static void debug_to_terminal_inferior (void);
139 static void debug_to_terminal_ours_for_output (void);
141 static void debug_to_terminal_save_ours (void);
143 static void debug_to_terminal_ours (void);
145 static void debug_to_terminal_info (char *, int);
147 static void debug_to_kill (void);
149 static void debug_to_load (char *, int);
151 static int debug_to_lookup_symbol (char *, CORE_ADDR
*);
153 static void debug_to_create_inferior (char *, char *, char **);
155 static void debug_to_mourn_inferior (void);
157 static int debug_to_can_run (void);
159 static void debug_to_notice_signals (ptid_t
);
161 static int debug_to_thread_alive (ptid_t
);
163 static void debug_to_stop (void);
165 static int debug_to_query (int /*char */ , char *, char *, int *);
167 /* Pointer to array of target architecture structures; the size of the
168 array; the current index into the array; the allocated size of the
170 struct target_ops
**target_structs
;
171 unsigned target_struct_size
;
172 unsigned target_struct_index
;
173 unsigned target_struct_allocsize
;
174 #define DEFAULT_ALLOCSIZE 10
176 /* The initial current target, so that there is always a semi-valid
179 static struct target_ops dummy_target
;
181 /* Top of target stack. */
183 struct target_stack_item
*target_stack
;
185 /* The target structure we are currently using to talk to a process
186 or file or whatever "inferior" we have. */
188 struct target_ops current_target
;
190 /* Command list for target. */
192 static struct cmd_list_element
*targetlist
= NULL
;
194 /* Nonzero if we are debugging an attached outside process
195 rather than an inferior. */
199 /* Non-zero if we want to see trace of target level stuff. */
201 static int targetdebug
= 0;
203 static void setup_target_debug (void);
205 DCACHE
*target_dcache
;
207 /* The user just typed 'target' without the name of a target. */
211 target_command (char *arg
, int from_tty
)
213 fputs_filtered ("Argument required (target name). Try `help target'\n",
217 /* Add a possible target architecture to the list. */
220 add_target (struct target_ops
*t
)
224 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
225 target_structs
= (struct target_ops
**) xmalloc
226 (target_struct_allocsize
* sizeof (*target_structs
));
228 if (target_struct_size
>= target_struct_allocsize
)
230 target_struct_allocsize
*= 2;
231 target_structs
= (struct target_ops
**)
232 xrealloc ((char *) target_structs
,
233 target_struct_allocsize
* sizeof (*target_structs
));
235 target_structs
[target_struct_size
++] = t
;
236 /* cleanup_target (t); */
238 if (targetlist
== NULL
)
239 add_prefix_cmd ("target", class_run
, target_command
,
240 "Connect to a target machine or process.\n\
241 The first argument is the type or protocol of the target machine.\n\
242 Remaining arguments are interpreted by the target protocol. For more\n\
243 information on the arguments for a particular protocol, type\n\
244 `help target ' followed by the protocol name.",
245 &targetlist
, "target ", 0, &cmdlist
);
246 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
257 target_load (char *arg
, int from_tty
)
259 dcache_invalidate (target_dcache
);
260 (*current_target
.to_load
) (arg
, from_tty
);
265 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
266 struct target_ops
*t
)
268 errno
= EIO
; /* Can't read/write this location */
269 return 0; /* No bytes handled */
275 error ("You can't do that when your target is `%s'",
276 current_target
.to_shortname
);
282 error ("You can't do that without a process to debug.");
287 nosymbol (char *name
, CORE_ADDR
*addrp
)
289 return 1; /* Symbol does not exist in target env */
294 nosupport_runtime (void)
296 if (ptid_equal (inferior_ptid
, null_ptid
))
299 error ("No run-time support for this");
305 default_terminal_info (char *args
, int from_tty
)
307 printf_unfiltered ("No saved terminal information.\n");
310 /* This is the default target_create_inferior and target_attach function.
311 If the current target is executing, it asks whether to kill it off.
312 If this function returns without calling error(), it has killed off
313 the target, and the operation should be attempted. */
316 kill_or_be_killed (int from_tty
)
318 if (target_has_execution
)
320 printf_unfiltered ("You are already running a program:\n");
321 target_files_info ();
322 if (query ("Kill it? "))
325 if (target_has_execution
)
326 error ("Killing the program did not help.");
331 error ("Program not killed.");
338 maybe_kill_then_attach (char *args
, int from_tty
)
340 kill_or_be_killed (from_tty
);
341 target_attach (args
, from_tty
);
345 maybe_kill_then_create_inferior (char *exec
, char *args
, char **env
)
347 kill_or_be_killed (0);
348 target_create_inferior (exec
, args
, env
);
351 /* Clean up a target struct so it no longer has any zero pointers in it.
352 We default entries, at least to stubs that print error messages. */
355 cleanup_target (struct target_ops
*t
)
358 #define de_fault(field, value) \
363 (void (*) (char *, int))
369 maybe_kill_then_attach
);
370 de_fault (to_post_attach
,
374 (void (*) (char *, int))
376 de_fault (to_disconnect
,
377 (void (*) (char *, int))
380 (void (*) (ptid_t
, int, enum target_signal
))
383 (ptid_t (*) (ptid_t
, struct target_waitstatus
*))
385 de_fault (to_post_wait
,
386 (void (*) (ptid_t
, int))
388 de_fault (to_fetch_registers
,
391 de_fault (to_store_registers
,
394 de_fault (to_prepare_to_store
,
397 de_fault (to_xfer_memory
,
398 (int (*) (CORE_ADDR
, char *, int, int, struct mem_attrib
*, struct target_ops
*))
400 de_fault (to_files_info
,
401 (void (*) (struct target_ops
*))
403 de_fault (to_insert_breakpoint
,
404 memory_insert_breakpoint
);
405 de_fault (to_remove_breakpoint
,
406 memory_remove_breakpoint
);
407 de_fault (to_can_use_hw_breakpoint
,
408 (int (*) (int, int, int))
410 de_fault (to_insert_hw_breakpoint
,
411 (int (*) (CORE_ADDR
, char *))
413 de_fault (to_remove_hw_breakpoint
,
414 (int (*) (CORE_ADDR
, char *))
416 de_fault (to_insert_watchpoint
,
417 (int (*) (CORE_ADDR
, int, int))
419 de_fault (to_remove_watchpoint
,
420 (int (*) (CORE_ADDR
, int, int))
422 de_fault (to_stopped_by_watchpoint
,
425 de_fault (to_stopped_data_address
,
426 (CORE_ADDR (*) (void))
428 de_fault (to_region_size_ok_for_hw_watchpoint
,
429 default_region_size_ok_for_hw_watchpoint
);
430 de_fault (to_terminal_init
,
433 de_fault (to_terminal_inferior
,
436 de_fault (to_terminal_ours_for_output
,
439 de_fault (to_terminal_ours
,
442 de_fault (to_terminal_save_ours
,
445 de_fault (to_terminal_info
,
446 default_terminal_info
);
451 (void (*) (char *, int))
453 de_fault (to_lookup_symbol
,
454 (int (*) (char *, CORE_ADDR
*))
456 de_fault (to_create_inferior
,
457 maybe_kill_then_create_inferior
);
458 de_fault (to_post_startup_inferior
,
461 de_fault (to_acknowledge_created_inferior
,
464 de_fault (to_insert_fork_catchpoint
,
467 de_fault (to_remove_fork_catchpoint
,
470 de_fault (to_insert_vfork_catchpoint
,
473 de_fault (to_remove_vfork_catchpoint
,
476 de_fault (to_follow_fork
,
479 de_fault (to_insert_exec_catchpoint
,
482 de_fault (to_remove_exec_catchpoint
,
485 de_fault (to_reported_exec_events_per_exec_call
,
488 de_fault (to_has_exited
,
489 (int (*) (int, int, int *))
491 de_fault (to_mourn_inferior
,
494 de_fault (to_can_run
,
496 de_fault (to_notice_signals
,
499 de_fault (to_thread_alive
,
502 de_fault (to_find_new_threads
,
505 de_fault (to_extra_thread_info
,
506 (char *(*) (struct thread_info
*))
512 (void (*) (char *, struct ui_file
*))
514 de_fault (to_enable_exception_callback
,
515 (struct symtab_and_line
* (*) (enum exception_event_kind
, int))
517 de_fault (to_get_current_exception_event
,
518 (struct exception_event_record
* (*) (void))
520 de_fault (to_pid_to_exec_file
,
523 de_fault (to_can_async_p
,
526 de_fault (to_is_async_p
,
530 (void (*) (void (*) (enum inferior_event_type
, void*), void*))
535 /* Go through the target stack from top to bottom, copying over zero entries in
536 current_target. In effect, we are doing class inheritance through the
537 pushed target vectors. */
540 update_current_target (void)
542 struct target_stack_item
*item
;
543 struct target_ops
*t
;
545 /* First, reset current_target */
546 memset (¤t_target
, 0, sizeof current_target
);
548 for (item
= target_stack
; item
; item
= item
->next
)
550 t
= item
->target_ops
;
552 #define INHERIT(FIELD, TARGET) \
553 if (!current_target.FIELD) \
554 current_target.FIELD = TARGET->FIELD
556 INHERIT (to_shortname
, t
);
557 INHERIT (to_longname
, t
);
559 INHERIT (to_open
, t
);
560 INHERIT (to_close
, t
);
561 INHERIT (to_attach
, t
);
562 INHERIT (to_post_attach
, t
);
563 INHERIT (to_detach
, t
);
564 INHERIT (to_disconnect
, t
);
565 INHERIT (to_resume
, t
);
566 INHERIT (to_wait
, t
);
567 INHERIT (to_post_wait
, t
);
568 INHERIT (to_fetch_registers
, t
);
569 INHERIT (to_store_registers
, t
);
570 INHERIT (to_prepare_to_store
, t
);
571 INHERIT (to_xfer_memory
, t
);
572 INHERIT (to_files_info
, t
);
573 INHERIT (to_insert_breakpoint
, t
);
574 INHERIT (to_remove_breakpoint
, t
);
575 INHERIT (to_can_use_hw_breakpoint
, t
);
576 INHERIT (to_insert_hw_breakpoint
, t
);
577 INHERIT (to_remove_hw_breakpoint
, t
);
578 INHERIT (to_insert_watchpoint
, t
);
579 INHERIT (to_remove_watchpoint
, t
);
580 INHERIT (to_stopped_data_address
, t
);
581 INHERIT (to_stopped_by_watchpoint
, t
);
582 INHERIT (to_have_continuable_watchpoint
, t
);
583 INHERIT (to_region_size_ok_for_hw_watchpoint
, t
);
584 INHERIT (to_terminal_init
, t
);
585 INHERIT (to_terminal_inferior
, t
);
586 INHERIT (to_terminal_ours_for_output
, t
);
587 INHERIT (to_terminal_ours
, t
);
588 INHERIT (to_terminal_save_ours
, t
);
589 INHERIT (to_terminal_info
, t
);
590 INHERIT (to_kill
, t
);
591 INHERIT (to_load
, t
);
592 INHERIT (to_lookup_symbol
, t
);
593 INHERIT (to_create_inferior
, t
);
594 INHERIT (to_post_startup_inferior
, t
);
595 INHERIT (to_acknowledge_created_inferior
, t
);
596 INHERIT (to_insert_fork_catchpoint
, t
);
597 INHERIT (to_remove_fork_catchpoint
, t
);
598 INHERIT (to_insert_vfork_catchpoint
, t
);
599 INHERIT (to_remove_vfork_catchpoint
, t
);
600 INHERIT (to_follow_fork
, t
);
601 INHERIT (to_insert_exec_catchpoint
, t
);
602 INHERIT (to_remove_exec_catchpoint
, t
);
603 INHERIT (to_reported_exec_events_per_exec_call
, t
);
604 INHERIT (to_has_exited
, t
);
605 INHERIT (to_mourn_inferior
, t
);
606 INHERIT (to_can_run
, t
);
607 INHERIT (to_notice_signals
, t
);
608 INHERIT (to_thread_alive
, t
);
609 INHERIT (to_find_new_threads
, t
);
610 INHERIT (to_pid_to_str
, t
);
611 INHERIT (to_extra_thread_info
, t
);
612 INHERIT (to_stop
, t
);
613 INHERIT (to_query
, t
);
614 INHERIT (to_rcmd
, t
);
615 INHERIT (to_enable_exception_callback
, t
);
616 INHERIT (to_get_current_exception_event
, t
);
617 INHERIT (to_pid_to_exec_file
, t
);
618 INHERIT (to_stratum
, t
);
619 INHERIT (to_has_all_memory
, t
);
620 INHERIT (to_has_memory
, t
);
621 INHERIT (to_has_stack
, t
);
622 INHERIT (to_has_registers
, t
);
623 INHERIT (to_has_execution
, t
);
624 INHERIT (to_has_thread_control
, t
);
625 INHERIT (to_sections
, t
);
626 INHERIT (to_sections_end
, t
);
627 INHERIT (to_can_async_p
, t
);
628 INHERIT (to_is_async_p
, t
);
629 INHERIT (to_async
, t
);
630 INHERIT (to_async_mask_value
, t
);
631 INHERIT (to_find_memory_regions
, t
);
632 INHERIT (to_make_corefile_notes
, t
);
633 INHERIT (to_get_thread_local_address
, t
);
634 INHERIT (to_magic
, t
);
640 /* Push a new target type into the stack of the existing target accessors,
641 possibly superseding some of the existing accessors.
643 Result is zero if the pushed target ended up on top of the stack,
644 nonzero if at least one target is on top of it.
646 Rather than allow an empty stack, we always have the dummy target at
647 the bottom stratum, so we can call the function vectors without
651 push_target (struct target_ops
*t
)
653 struct target_stack_item
*cur
, *prev
, *tmp
;
655 /* Check magic number. If wrong, it probably means someone changed
656 the struct definition, but not all the places that initialize one. */
657 if (t
->to_magic
!= OPS_MAGIC
)
659 fprintf_unfiltered (gdb_stderr
,
660 "Magic number of %s target struct wrong\n",
662 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
665 /* Find the proper stratum to install this target in. */
667 for (prev
= NULL
, cur
= target_stack
; cur
; prev
= cur
, cur
= cur
->next
)
669 if ((int) (t
->to_stratum
) >= (int) (cur
->target_ops
->to_stratum
))
673 /* If there's already targets at this stratum, remove them. */
676 while (t
->to_stratum
== cur
->target_ops
->to_stratum
)
678 /* There's already something on this stratum. Close it off. */
679 if (cur
->target_ops
->to_close
)
680 (cur
->target_ops
->to_close
) (0);
682 prev
->next
= cur
->next
; /* Unchain old target_ops */
684 target_stack
= cur
->next
; /* Unchain first on list */
690 /* We have removed all targets in our stratum, now add the new one. */
692 tmp
= (struct target_stack_item
*)
693 xmalloc (sizeof (struct target_stack_item
));
702 update_current_target ();
704 cleanup_target (¤t_target
); /* Fill in the gaps */
707 setup_target_debug ();
712 /* Remove a target_ops vector from the stack, wherever it may be.
713 Return how many times it was removed (0 or 1). */
716 unpush_target (struct target_ops
*t
)
718 struct target_stack_item
*cur
, *prev
;
721 t
->to_close (0); /* Let it clean up */
723 /* Look for the specified target. Note that we assume that a target
724 can only occur once in the target stack. */
726 for (cur
= target_stack
, prev
= NULL
; cur
; prev
= cur
, cur
= cur
->next
)
727 if (cur
->target_ops
== t
)
731 return 0; /* Didn't find target_ops, quit now */
733 /* Unchain the target */
736 target_stack
= cur
->next
;
738 prev
->next
= cur
->next
;
740 xfree (cur
); /* Release the target_stack_item */
742 update_current_target ();
743 cleanup_target (¤t_target
);
751 (current_target
.to_close
) (0); /* Let it clean up */
752 if (unpush_target (target_stack
->target_ops
) == 1)
755 fprintf_unfiltered (gdb_stderr
,
756 "pop_target couldn't find target %s\n",
757 current_target
.to_shortname
);
758 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
762 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
764 /* target_read_string -- read a null terminated string, up to LEN bytes,
765 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
766 Set *STRING to a pointer to malloc'd memory containing the data; the caller
767 is responsible for freeing it. Return the number of bytes successfully
771 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
773 int tlen
, origlen
, offset
, i
;
777 int buffer_allocated
;
779 unsigned int nbytes_read
= 0;
781 /* Small for testing. */
782 buffer_allocated
= 4;
783 buffer
= xmalloc (buffer_allocated
);
790 tlen
= MIN (len
, 4 - (memaddr
& 3));
791 offset
= memaddr
& 3;
793 errcode
= target_xfer_memory (memaddr
& ~3, buf
, 4, 0);
796 /* The transfer request might have crossed the boundary to an
797 unallocated region of memory. Retry the transfer, requesting
801 errcode
= target_xfer_memory (memaddr
, buf
, 1, 0);
806 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
809 bytes
= bufptr
- buffer
;
810 buffer_allocated
*= 2;
811 buffer
= xrealloc (buffer
, buffer_allocated
);
812 bufptr
= buffer
+ bytes
;
815 for (i
= 0; i
< tlen
; i
++)
817 *bufptr
++ = buf
[i
+ offset
];
818 if (buf
[i
+ offset
] == '\000')
820 nbytes_read
+= i
+ 1;
837 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
838 GDB's memory at MYADDR. Returns either 0 for success or an errno value
841 If an error occurs, no guarantee is made about the contents of the data at
842 MYADDR. In particular, the caller should not depend upon partial reads
843 filling the buffer with good data. There is no way for the caller to know
844 how much good data might have been transfered anyway. Callers that can
845 deal with partial reads should call target_read_memory_partial. */
848 target_read_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
850 return target_xfer_memory (memaddr
, myaddr
, len
, 0);
854 target_write_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
856 return target_xfer_memory (memaddr
, myaddr
, len
, 1);
859 static int trust_readonly
= 0;
861 /* Move memory to or from the targets. The top target gets priority;
862 if it cannot handle it, it is offered to the next one down, etc.
864 Result is -1 on error, or the number of bytes transfered. */
867 do_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
868 struct mem_attrib
*attrib
)
872 struct target_ops
*t
;
873 struct target_stack_item
*item
;
875 /* Zero length requests are ok and require no work. */
879 /* to_xfer_memory is not guaranteed to set errno, even when it returns
883 if (!write
&& trust_readonly
)
885 /* User-settable option, "trust-readonly-sections". If true,
886 then memory from any SEC_READONLY bfd section may be read
887 directly from the bfd file. */
889 struct section_table
*secp
;
891 for (secp
= current_target
.to_sections
;
892 secp
< current_target
.to_sections_end
;
895 if (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
897 if (memaddr
>= secp
->addr
&& memaddr
< secp
->endaddr
)
898 return xfer_memory (memaddr
, myaddr
, len
, 0,
899 attrib
, ¤t_target
);
903 /* The quick case is that the top target can handle the transfer. */
904 res
= current_target
.to_xfer_memory
905 (memaddr
, myaddr
, len
, write
, attrib
, ¤t_target
);
907 /* If res <= 0 then we call it again in the loop. Ah well. */
910 for (item
= target_stack
; item
; item
= item
->next
)
912 t
= item
->target_ops
;
913 if (!t
->to_has_memory
)
916 res
= t
->to_xfer_memory (memaddr
, myaddr
, len
, write
, attrib
, t
);
918 break; /* Handled all or part of xfer */
919 if (t
->to_has_all_memory
)
931 /* Perform a memory transfer. Iterate until the entire region has
934 Result is 0 or errno value. */
937 target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
)
941 struct mem_region
*region
;
943 /* Zero length requests are ok and require no work. */
951 region
= lookup_mem_region(memaddr
);
952 if (memaddr
+ len
< region
->hi
)
955 reg_len
= region
->hi
- memaddr
;
957 switch (region
->attrib
.mode
)
972 if (region
->attrib
.cache
)
973 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
,
976 res
= do_xfer_memory (memaddr
, myaddr
, reg_len
, write
,
981 /* If this address is for nonexistent memory, read zeros
982 if reading, or do nothing if writing. Return
985 memset (myaddr
, 0, len
);
999 return 0; /* We managed to cover it all somehow. */
1003 /* Perform a partial memory transfer.
1005 Result is -1 on error, or the number of bytes transfered. */
1008 target_xfer_memory_partial (CORE_ADDR memaddr
, char *myaddr
, int len
,
1009 int write_p
, int *err
)
1013 struct mem_region
*region
;
1015 /* Zero length requests are ok and require no work. */
1022 region
= lookup_mem_region(memaddr
);
1023 if (memaddr
+ len
< region
->hi
)
1026 reg_len
= region
->hi
- memaddr
;
1028 switch (region
->attrib
.mode
)
1047 if (region
->attrib
.cache
)
1048 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
,
1051 res
= do_xfer_memory (memaddr
, myaddr
, reg_len
, write_p
,
1069 target_read_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1071 return target_xfer_memory_partial (memaddr
, buf
, len
, 0, err
);
1075 target_write_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1077 return target_xfer_memory_partial (memaddr
, buf
, len
, 1, err
);
1082 target_info (char *args
, int from_tty
)
1084 struct target_ops
*t
;
1085 struct target_stack_item
*item
;
1086 int has_all_mem
= 0;
1088 if (symfile_objfile
!= NULL
)
1089 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
1091 #ifdef FILES_INFO_HOOK
1092 if (FILES_INFO_HOOK ())
1096 for (item
= target_stack
; item
; item
= item
->next
)
1098 t
= item
->target_ops
;
1100 if (!t
->to_has_memory
)
1103 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
1106 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1107 printf_unfiltered ("%s:\n", t
->to_longname
);
1108 (t
->to_files_info
) (t
);
1109 has_all_mem
= t
->to_has_all_memory
;
1113 /* This is to be called by the open routine before it does
1117 target_preopen (int from_tty
)
1121 if (target_has_execution
)
1124 || query ("A program is being debugged already. Kill it? "))
1127 error ("Program not killed.");
1130 /* Calling target_kill may remove the target from the stack. But if
1131 it doesn't (which seems like a win for UDI), remove it now. */
1133 if (target_has_execution
)
1137 /* Detach a target after doing deferred register stores. */
1140 target_detach (char *args
, int from_tty
)
1142 /* Handle any optimized stores to the inferior. */
1143 #ifdef DO_DEFERRED_STORES
1146 (current_target
.to_detach
) (args
, from_tty
);
1150 target_disconnect (char *args
, int from_tty
)
1152 /* Handle any optimized stores to the inferior. */
1153 #ifdef DO_DEFERRED_STORES
1156 (current_target
.to_disconnect
) (args
, from_tty
);
1160 target_link (char *modname
, CORE_ADDR
*t_reloc
)
1162 if (STREQ (current_target
.to_shortname
, "rombug"))
1164 (current_target
.to_lookup_symbol
) (modname
, t_reloc
);
1166 error ("Unable to link to %s and get relocation in rombug", modname
);
1169 *t_reloc
= (CORE_ADDR
) -1;
1173 target_async_mask (int mask
)
1175 int saved_async_masked_status
= target_async_mask_value
;
1176 target_async_mask_value
= mask
;
1177 return saved_async_masked_status
;
1180 /* Look through the list of possible targets for a target that can
1181 execute a run or attach command without any other data. This is
1182 used to locate the default process stratum.
1184 Result is always valid (error() is called for errors). */
1186 static struct target_ops
*
1187 find_default_run_target (char *do_mesg
)
1189 struct target_ops
**t
;
1190 struct target_ops
*runable
= NULL
;
1195 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1198 if ((*t
)->to_can_run
&& target_can_run (*t
))
1206 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
1212 find_default_attach (char *args
, int from_tty
)
1214 struct target_ops
*t
;
1216 t
= find_default_run_target ("attach");
1217 (t
->to_attach
) (args
, from_tty
);
1222 find_default_create_inferior (char *exec_file
, char *allargs
, char **env
)
1224 struct target_ops
*t
;
1226 t
= find_default_run_target ("run");
1227 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
1232 default_region_size_ok_for_hw_watchpoint (int byte_count
)
1234 return (byte_count
<= DEPRECATED_REGISTER_SIZE
);
1250 return_minus_one (void)
1256 * Resize the to_sections pointer. Also make sure that anyone that
1257 * was holding on to an old value of it gets updated.
1258 * Returns the old size.
1262 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1264 struct target_ops
**t
;
1265 struct section_table
*old_value
;
1268 old_value
= target
->to_sections
;
1270 if (target
->to_sections
)
1272 old_count
= target
->to_sections_end
- target
->to_sections
;
1273 target
->to_sections
= (struct section_table
*)
1274 xrealloc ((char *) target
->to_sections
,
1275 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1280 target
->to_sections
= (struct section_table
*)
1281 xmalloc ((sizeof (struct section_table
)) * num_added
);
1283 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1285 /* Check to see if anyone else was pointing to this structure.
1286 If old_value was null, then no one was. */
1290 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1293 if ((*t
)->to_sections
== old_value
)
1295 (*t
)->to_sections
= target
->to_sections
;
1296 (*t
)->to_sections_end
= target
->to_sections_end
;
1305 /* Remove all target sections taken from ABFD.
1307 Scan the current target stack for targets whose section tables
1308 refer to sections from BFD, and remove those sections. We use this
1309 when we notice that the inferior has unloaded a shared object, for
1312 remove_target_sections (bfd
*abfd
)
1314 struct target_ops
**t
;
1316 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; t
++)
1318 struct section_table
*src
, *dest
;
1320 dest
= (*t
)->to_sections
;
1321 for (src
= (*t
)->to_sections
; src
< (*t
)->to_sections_end
; src
++)
1322 if (src
->bfd
!= abfd
)
1324 /* Keep this section. */
1325 if (dest
< src
) *dest
= *src
;
1329 /* If we've dropped any sections, resize the section table. */
1331 target_resize_to_sections (*t
, dest
- src
);
1338 /* Find a single runnable target in the stack and return it. If for
1339 some reason there is more than one, return NULL. */
1342 find_run_target (void)
1344 struct target_ops
**t
;
1345 struct target_ops
*runable
= NULL
;
1350 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1352 if ((*t
)->to_can_run
&& target_can_run (*t
))
1359 return (count
== 1 ? runable
: NULL
);
1362 /* Find a single core_stratum target in the list of targets and return it.
1363 If for some reason there is more than one, return NULL. */
1366 find_core_target (void)
1368 struct target_ops
**t
;
1369 struct target_ops
*runable
= NULL
;
1374 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1377 if ((*t
)->to_stratum
== core_stratum
)
1384 return (count
== 1 ? runable
: NULL
);
1388 * Find the next target down the stack from the specified target.
1392 find_target_beneath (struct target_ops
*t
)
1394 struct target_stack_item
*cur
;
1396 for (cur
= target_stack
; cur
; cur
= cur
->next
)
1397 if (cur
->target_ops
== t
)
1400 if (cur
== NULL
|| cur
->next
== NULL
)
1403 return cur
->next
->target_ops
;
1407 /* The inferior process has died. Long live the inferior! */
1410 generic_mourn_inferior (void)
1412 extern int show_breakpoint_hit_counts
;
1414 inferior_ptid
= null_ptid
;
1416 breakpoint_init_inferior (inf_exited
);
1417 registers_changed ();
1419 #ifdef CLEAR_DEFERRED_STORES
1420 /* Delete any pending stores to the inferior... */
1421 CLEAR_DEFERRED_STORES
;
1424 reopen_exec_file ();
1425 reinit_frame_cache ();
1427 /* It is confusing to the user for ignore counts to stick around
1428 from previous runs of the inferior. So clear them. */
1429 /* However, it is more confusing for the ignore counts to disappear when
1430 using hit counts. So don't clear them if we're counting hits. */
1431 if (!show_breakpoint_hit_counts
)
1432 breakpoint_clear_ignore_counts ();
1438 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1439 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1440 translation of that in OURSTATUS. */
1442 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
1444 #ifdef CHILD_SPECIAL_WAITSTATUS
1445 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1446 if it wants to deal with hoststatus. */
1447 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
1451 if (WIFEXITED (hoststatus
))
1453 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1454 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
1456 else if (!WIFSTOPPED (hoststatus
))
1458 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1459 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
1463 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
1464 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
1468 /* Returns zero to leave the inferior alone, one to interrupt it. */
1469 int (*target_activity_function
) (void);
1470 int target_activity_fd
;
1472 /* Convert a normal process ID to a string. Returns the string in a static
1476 normal_pid_to_str (ptid_t ptid
)
1478 static char buf
[30];
1480 sprintf (buf
, "process %d", PIDGET (ptid
));
1484 /* Some targets (such as ttrace-based HPUX) don't allow us to request
1485 notification of inferior events such as fork and vork immediately
1486 after the inferior is created. (This because of how gdb gets an
1487 inferior created via invoking a shell to do it. In such a scenario,
1488 if the shell init file has commands in it, the shell will fork and
1489 exec for each of those commands, and we will see each such fork
1492 This function is used by all targets that allow us to request
1493 notification of forks, etc at inferior creation time; e.g., in
1494 target_acknowledge_forked_child.
1497 normal_target_post_startup_inferior (ptid_t ptid
)
1499 /* This space intentionally left blank. */
1502 /* Error-catcher for target_find_memory_regions */
1504 static int dummy_find_memory_regions (int (*ignore1
) (), void *ignore2
)
1506 error ("No target.");
1510 /* Error-catcher for target_make_corefile_notes */
1512 static char * dummy_make_corefile_notes (bfd
*ignore1
, int *ignore2
)
1514 error ("No target.");
1518 /* Set up the handful of non-empty slots needed by the dummy target
1522 init_dummy_target (void)
1524 dummy_target
.to_shortname
= "None";
1525 dummy_target
.to_longname
= "None";
1526 dummy_target
.to_doc
= "";
1527 dummy_target
.to_attach
= find_default_attach
;
1528 dummy_target
.to_create_inferior
= find_default_create_inferior
;
1529 dummy_target
.to_pid_to_str
= normal_pid_to_str
;
1530 dummy_target
.to_stratum
= dummy_stratum
;
1531 dummy_target
.to_find_memory_regions
= dummy_find_memory_regions
;
1532 dummy_target
.to_make_corefile_notes
= dummy_make_corefile_notes
;
1533 dummy_target
.to_magic
= OPS_MAGIC
;
1537 static struct target_ops debug_target
;
1540 debug_to_open (char *args
, int from_tty
)
1542 debug_target
.to_open (args
, from_tty
);
1544 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
1548 debug_to_close (int quitting
)
1550 debug_target
.to_close (quitting
);
1552 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
1556 debug_to_attach (char *args
, int from_tty
)
1558 debug_target
.to_attach (args
, from_tty
);
1560 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
1565 debug_to_post_attach (int pid
)
1567 debug_target
.to_post_attach (pid
);
1569 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
1573 debug_to_detach (char *args
, int from_tty
)
1575 debug_target
.to_detach (args
, from_tty
);
1577 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
1581 debug_to_disconnect (char *args
, int from_tty
)
1583 debug_target
.to_disconnect (args
, from_tty
);
1585 fprintf_unfiltered (gdb_stdlog
, "target_disconnect (%s, %d)\n",
1590 debug_to_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
1592 debug_target
.to_resume (ptid
, step
, siggnal
);
1594 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", PIDGET (ptid
),
1595 step
? "step" : "continue",
1596 target_signal_to_name (siggnal
));
1600 debug_to_wait (ptid_t ptid
, struct target_waitstatus
*status
)
1604 retval
= debug_target
.to_wait (ptid
, status
);
1606 fprintf_unfiltered (gdb_stdlog
,
1607 "target_wait (%d, status) = %d, ", PIDGET (ptid
),
1609 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
1610 switch (status
->kind
)
1612 case TARGET_WAITKIND_EXITED
:
1613 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
1614 status
->value
.integer
);
1616 case TARGET_WAITKIND_STOPPED
:
1617 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
1618 target_signal_to_name (status
->value
.sig
));
1620 case TARGET_WAITKIND_SIGNALLED
:
1621 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
1622 target_signal_to_name (status
->value
.sig
));
1624 case TARGET_WAITKIND_LOADED
:
1625 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
1627 case TARGET_WAITKIND_FORKED
:
1628 fprintf_unfiltered (gdb_stdlog
, "forked\n");
1630 case TARGET_WAITKIND_VFORKED
:
1631 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
1633 case TARGET_WAITKIND_EXECD
:
1634 fprintf_unfiltered (gdb_stdlog
, "execd\n");
1636 case TARGET_WAITKIND_SPURIOUS
:
1637 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
1640 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
1648 debug_to_post_wait (ptid_t ptid
, int status
)
1650 debug_target
.to_post_wait (ptid
, status
);
1652 fprintf_unfiltered (gdb_stdlog
, "target_post_wait (%d, %d)\n",
1653 PIDGET (ptid
), status
);
1657 debug_print_register (const char * func
, int regno
)
1659 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
1660 if (regno
>= 0 && regno
< NUM_REGS
+ NUM_PSEUDO_REGS
1661 && REGISTER_NAME (regno
) != NULL
&& REGISTER_NAME (regno
)[0] != '\0')
1662 fprintf_unfiltered (gdb_stdlog
, "(%s)", REGISTER_NAME (regno
));
1664 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
1668 unsigned char buf
[MAX_REGISTER_SIZE
];
1669 deprecated_read_register_gen (regno
, buf
);
1670 fprintf_unfiltered (gdb_stdlog
, " = ");
1671 for (i
= 0; i
< REGISTER_RAW_SIZE (regno
); i
++)
1673 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
1675 if (REGISTER_RAW_SIZE (regno
) <= sizeof (LONGEST
))
1677 fprintf_unfiltered (gdb_stdlog
, " 0x%s %s",
1678 paddr_nz (read_register (regno
)),
1679 paddr_d (read_register (regno
)));
1682 fprintf_unfiltered (gdb_stdlog
, "\n");
1686 debug_to_fetch_registers (int regno
)
1688 debug_target
.to_fetch_registers (regno
);
1689 debug_print_register ("target_fetch_registers", regno
);
1693 debug_to_store_registers (int regno
)
1695 debug_target
.to_store_registers (regno
);
1696 debug_print_register ("target_store_registers", regno
);
1697 fprintf_unfiltered (gdb_stdlog
, "\n");
1701 debug_to_prepare_to_store (void)
1703 debug_target
.to_prepare_to_store ();
1705 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
1709 debug_to_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
1710 struct mem_attrib
*attrib
,
1711 struct target_ops
*target
)
1715 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
,
1718 fprintf_unfiltered (gdb_stdlog
,
1719 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
1720 (unsigned int) memaddr
, /* possable truncate long long */
1721 len
, write
? "write" : "read", retval
);
1729 fputs_unfiltered (", bytes =", gdb_stdlog
);
1730 for (i
= 0; i
< retval
; i
++)
1732 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
1733 fprintf_unfiltered (gdb_stdlog
, "\n");
1734 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1738 fputc_unfiltered ('\n', gdb_stdlog
);
1744 debug_to_files_info (struct target_ops
*target
)
1746 debug_target
.to_files_info (target
);
1748 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
1752 debug_to_insert_breakpoint (CORE_ADDR addr
, char *save
)
1756 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
1758 fprintf_unfiltered (gdb_stdlog
,
1759 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
1760 (unsigned long) addr
,
1761 (unsigned long) retval
);
1766 debug_to_remove_breakpoint (CORE_ADDR addr
, char *save
)
1770 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
1772 fprintf_unfiltered (gdb_stdlog
,
1773 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
1774 (unsigned long) addr
,
1775 (unsigned long) retval
);
1780 debug_to_can_use_hw_breakpoint (int type
, int cnt
, int from_tty
)
1784 retval
= debug_target
.to_can_use_hw_breakpoint (type
, cnt
, from_tty
);
1786 fprintf_unfiltered (gdb_stdlog
,
1787 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
1788 (unsigned long) type
,
1789 (unsigned long) cnt
,
1790 (unsigned long) from_tty
,
1791 (unsigned long) retval
);
1796 debug_to_region_size_ok_for_hw_watchpoint (int byte_count
)
1800 retval
= debug_target
.to_region_size_ok_for_hw_watchpoint (byte_count
);
1802 fprintf_unfiltered (gdb_stdlog
,
1803 "TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT (%ld) = 0x%lx\n",
1804 (unsigned long) byte_count
,
1805 (unsigned long) retval
);
1810 debug_to_stopped_by_watchpoint (void)
1814 retval
= debug_target
.to_stopped_by_watchpoint ();
1816 fprintf_unfiltered (gdb_stdlog
,
1817 "STOPPED_BY_WATCHPOINT () = %ld\n",
1818 (unsigned long) retval
);
1823 debug_to_stopped_data_address (void)
1827 retval
= debug_target
.to_stopped_data_address ();
1829 fprintf_unfiltered (gdb_stdlog
,
1830 "target_stopped_data_address () = 0x%lx\n",
1831 (unsigned long) retval
);
1836 debug_to_insert_hw_breakpoint (CORE_ADDR addr
, char *save
)
1840 retval
= debug_target
.to_insert_hw_breakpoint (addr
, save
);
1842 fprintf_unfiltered (gdb_stdlog
,
1843 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
1844 (unsigned long) addr
,
1845 (unsigned long) retval
);
1850 debug_to_remove_hw_breakpoint (CORE_ADDR addr
, char *save
)
1854 retval
= debug_target
.to_remove_hw_breakpoint (addr
, save
);
1856 fprintf_unfiltered (gdb_stdlog
,
1857 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
1858 (unsigned long) addr
,
1859 (unsigned long) retval
);
1864 debug_to_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
1868 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
1870 fprintf_unfiltered (gdb_stdlog
,
1871 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1872 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
1877 debug_to_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
1881 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
1883 fprintf_unfiltered (gdb_stdlog
,
1884 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1885 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
1890 debug_to_terminal_init (void)
1892 debug_target
.to_terminal_init ();
1894 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
1898 debug_to_terminal_inferior (void)
1900 debug_target
.to_terminal_inferior ();
1902 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
1906 debug_to_terminal_ours_for_output (void)
1908 debug_target
.to_terminal_ours_for_output ();
1910 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
1914 debug_to_terminal_ours (void)
1916 debug_target
.to_terminal_ours ();
1918 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
1922 debug_to_terminal_save_ours (void)
1924 debug_target
.to_terminal_save_ours ();
1926 fprintf_unfiltered (gdb_stdlog
, "target_terminal_save_ours ()\n");
1930 debug_to_terminal_info (char *arg
, int from_tty
)
1932 debug_target
.to_terminal_info (arg
, from_tty
);
1934 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
1939 debug_to_kill (void)
1941 debug_target
.to_kill ();
1943 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
1947 debug_to_load (char *args
, int from_tty
)
1949 debug_target
.to_load (args
, from_tty
);
1951 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
1955 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
1959 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
1961 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
1967 debug_to_create_inferior (char *exec_file
, char *args
, char **env
)
1969 debug_target
.to_create_inferior (exec_file
, args
, env
);
1971 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx)\n",
1976 debug_to_post_startup_inferior (ptid_t ptid
)
1978 debug_target
.to_post_startup_inferior (ptid
);
1980 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
1985 debug_to_acknowledge_created_inferior (int pid
)
1987 debug_target
.to_acknowledge_created_inferior (pid
);
1989 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
1994 debug_to_insert_fork_catchpoint (int pid
)
1998 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
2000 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
2007 debug_to_remove_fork_catchpoint (int pid
)
2011 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
2013 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
2020 debug_to_insert_vfork_catchpoint (int pid
)
2024 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
2026 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)= %d\n",
2033 debug_to_remove_vfork_catchpoint (int pid
)
2037 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
2039 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
2046 debug_to_follow_fork (int follow_child
)
2048 int retval
= debug_target
.to_follow_fork (follow_child
);
2050 fprintf_unfiltered (gdb_stdlog
, "target_follow_fork (%d) = %d\n",
2051 follow_child
, retval
);
2057 debug_to_insert_exec_catchpoint (int pid
)
2061 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
2063 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
2070 debug_to_remove_exec_catchpoint (int pid
)
2074 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
2076 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2083 debug_to_reported_exec_events_per_exec_call (void)
2085 int reported_exec_events
;
2087 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2089 fprintf_unfiltered (gdb_stdlog
,
2090 "target_reported_exec_events_per_exec_call () = %d\n",
2091 reported_exec_events
);
2093 return reported_exec_events
;
2097 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
2101 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2103 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2104 pid
, wait_status
, *exit_status
, has_exited
);
2110 debug_to_mourn_inferior (void)
2112 debug_target
.to_mourn_inferior ();
2114 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2118 debug_to_can_run (void)
2122 retval
= debug_target
.to_can_run ();
2124 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2130 debug_to_notice_signals (ptid_t ptid
)
2132 debug_target
.to_notice_signals (ptid
);
2134 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n",
2139 debug_to_thread_alive (ptid_t ptid
)
2143 retval
= debug_target
.to_thread_alive (ptid
);
2145 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2146 PIDGET (ptid
), retval
);
2152 debug_to_find_new_threads (void)
2154 debug_target
.to_find_new_threads ();
2156 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog
);
2160 debug_to_stop (void)
2162 debug_target
.to_stop ();
2164 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2168 debug_to_query (int type
, char *req
, char *resp
, int *siz
)
2172 retval
= debug_target
.to_query (type
, req
, resp
, siz
);
2174 fprintf_unfiltered (gdb_stdlog
, "target_query (%c, %s, %s, %d) = %d\n", type
, req
, resp
, *siz
, retval
);
2180 debug_to_rcmd (char *command
,
2181 struct ui_file
*outbuf
)
2183 debug_target
.to_rcmd (command
, outbuf
);
2184 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2187 static struct symtab_and_line
*
2188 debug_to_enable_exception_callback (enum exception_event_kind kind
, int enable
)
2190 struct symtab_and_line
*result
;
2191 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2192 fprintf_unfiltered (gdb_stdlog
,
2193 "target get_exception_callback_sal (%d, %d)\n",
2198 static struct exception_event_record
*
2199 debug_to_get_current_exception_event (void)
2201 struct exception_event_record
*result
;
2202 result
= debug_target
.to_get_current_exception_event ();
2203 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2208 debug_to_pid_to_exec_file (int pid
)
2212 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2214 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2221 setup_target_debug (void)
2223 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2225 current_target
.to_open
= debug_to_open
;
2226 current_target
.to_close
= debug_to_close
;
2227 current_target
.to_attach
= debug_to_attach
;
2228 current_target
.to_post_attach
= debug_to_post_attach
;
2229 current_target
.to_detach
= debug_to_detach
;
2230 current_target
.to_disconnect
= debug_to_disconnect
;
2231 current_target
.to_resume
= debug_to_resume
;
2232 current_target
.to_wait
= debug_to_wait
;
2233 current_target
.to_post_wait
= debug_to_post_wait
;
2234 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2235 current_target
.to_store_registers
= debug_to_store_registers
;
2236 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2237 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2238 current_target
.to_files_info
= debug_to_files_info
;
2239 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2240 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2241 current_target
.to_can_use_hw_breakpoint
= debug_to_can_use_hw_breakpoint
;
2242 current_target
.to_insert_hw_breakpoint
= debug_to_insert_hw_breakpoint
;
2243 current_target
.to_remove_hw_breakpoint
= debug_to_remove_hw_breakpoint
;
2244 current_target
.to_insert_watchpoint
= debug_to_insert_watchpoint
;
2245 current_target
.to_remove_watchpoint
= debug_to_remove_watchpoint
;
2246 current_target
.to_stopped_by_watchpoint
= debug_to_stopped_by_watchpoint
;
2247 current_target
.to_stopped_data_address
= debug_to_stopped_data_address
;
2248 current_target
.to_region_size_ok_for_hw_watchpoint
= debug_to_region_size_ok_for_hw_watchpoint
;
2249 current_target
.to_terminal_init
= debug_to_terminal_init
;
2250 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2251 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2252 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2253 current_target
.to_terminal_save_ours
= debug_to_terminal_save_ours
;
2254 current_target
.to_terminal_info
= debug_to_terminal_info
;
2255 current_target
.to_kill
= debug_to_kill
;
2256 current_target
.to_load
= debug_to_load
;
2257 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2258 current_target
.to_create_inferior
= debug_to_create_inferior
;
2259 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2260 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2261 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2262 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2263 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2264 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2265 current_target
.to_follow_fork
= debug_to_follow_fork
;
2266 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2267 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2268 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2269 current_target
.to_has_exited
= debug_to_has_exited
;
2270 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2271 current_target
.to_can_run
= debug_to_can_run
;
2272 current_target
.to_notice_signals
= debug_to_notice_signals
;
2273 current_target
.to_thread_alive
= debug_to_thread_alive
;
2274 current_target
.to_find_new_threads
= debug_to_find_new_threads
;
2275 current_target
.to_stop
= debug_to_stop
;
2276 current_target
.to_query
= debug_to_query
;
2277 current_target
.to_rcmd
= debug_to_rcmd
;
2278 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
2279 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
2280 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2285 static char targ_desc
[] =
2286 "Names of targets and files being debugged.\n\
2287 Shows the entire stack of targets currently in use (including the exec-file,\n\
2288 core-file, and process, if any), as well as the symbol file name.";
2291 do_monitor_command (char *cmd
,
2294 if ((current_target
.to_rcmd
2295 == (void (*) (char *, struct ui_file
*)) tcomplain
)
2296 || (current_target
.to_rcmd
== debug_to_rcmd
2297 && (debug_target
.to_rcmd
2298 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
2300 error ("\"monitor\" command not supported by this target.\n");
2302 target_rcmd (cmd
, gdb_stdtarg
);
2306 initialize_targets (void)
2308 init_dummy_target ();
2309 push_target (&dummy_target
);
2311 add_info ("target", target_info
, targ_desc
);
2312 add_info ("files", target_info
, targ_desc
);
2315 (add_set_cmd ("target", class_maintenance
, var_zinteger
,
2316 (char *) &targetdebug
,
2317 "Set target debugging.\n\
2318 When non-zero, target debugging is enabled.", &setdebuglist
),
2321 add_setshow_boolean_cmd ("trust-readonly-sections", class_support
,
2323 Set mode for reading from readonly sections.\n\
2324 When this mode is on, memory reads from readonly sections (such as .text)\n\
2325 will be read from the object file instead of from the target. This will\n\
2326 result in significant performance improvement for remote targets.", "\
2327 Show mode for reading from readonly sections.\n",
2329 &setlist
, &showlist
);
2331 add_com ("monitor", class_obscure
, do_monitor_command
,
2332 "Send a command to the remote monitor (remote targets only).");
2334 target_dcache
= dcache_init ();