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"
40 static void target_info (char *, int);
42 static void maybe_kill_then_create_inferior (char *, char *, char **);
44 static void maybe_kill_then_attach (char *, int);
46 static void kill_or_be_killed (int);
48 static void default_terminal_info (char *, int);
50 static int default_region_size_ok_for_hw_watchpoint (int);
52 static int nosymbol (char *, CORE_ADDR
*);
54 static void tcomplain (void);
56 static int nomemory (CORE_ADDR
, char *, int, int, struct target_ops
*);
58 static int return_zero (void);
60 static int return_one (void);
62 static int return_minus_one (void);
64 void target_ignore (void);
66 static void target_command (char *, int);
68 static struct target_ops
*find_default_run_target (char *);
70 static void nosupport_runtime (void);
72 static void normal_target_post_startup_inferior (ptid_t ptid
);
74 /* Transfer LEN bytes between target address MEMADDR and GDB address
75 MYADDR. Returns 0 for success, errno code for failure (which
76 includes partial transfers -- if you want a more useful response to
77 partial transfers, try either target_read_memory_partial or
78 target_write_memory_partial). */
80 static int target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
,
83 static void init_dummy_target (void);
85 static void debug_to_open (char *, int);
87 static void debug_to_close (int);
89 static void debug_to_attach (char *, int);
91 static void debug_to_detach (char *, int);
93 static void debug_to_disconnect (char *, int);
95 static void debug_to_resume (ptid_t
, int, enum target_signal
);
97 static ptid_t
debug_to_wait (ptid_t
, struct target_waitstatus
*);
99 static void debug_to_fetch_registers (int);
101 static void debug_to_store_registers (int);
103 static void debug_to_prepare_to_store (void);
105 static int debug_to_xfer_memory (CORE_ADDR
, char *, int, int,
106 struct mem_attrib
*, struct target_ops
*);
108 static void debug_to_files_info (struct target_ops
*);
110 static int debug_to_insert_breakpoint (CORE_ADDR
, char *);
112 static int debug_to_remove_breakpoint (CORE_ADDR
, char *);
114 static int debug_to_can_use_hw_breakpoint (int, int, int);
116 static int debug_to_insert_hw_breakpoint (CORE_ADDR
, char *);
118 static int debug_to_remove_hw_breakpoint (CORE_ADDR
, char *);
120 static int debug_to_insert_watchpoint (CORE_ADDR
, int, int);
122 static int debug_to_remove_watchpoint (CORE_ADDR
, int, int);
124 static int debug_to_stopped_by_watchpoint (void);
126 static CORE_ADDR
debug_to_stopped_data_address (void);
128 static int debug_to_region_size_ok_for_hw_watchpoint (int);
130 static void debug_to_terminal_init (void);
132 static void debug_to_terminal_inferior (void);
134 static void debug_to_terminal_ours_for_output (void);
136 static void debug_to_terminal_save_ours (void);
138 static void debug_to_terminal_ours (void);
140 static void debug_to_terminal_info (char *, int);
142 static void debug_to_kill (void);
144 static void debug_to_load (char *, int);
146 static int debug_to_lookup_symbol (char *, CORE_ADDR
*);
148 static void debug_to_create_inferior (char *, char *, char **);
150 static void debug_to_mourn_inferior (void);
152 static int debug_to_can_run (void);
154 static void debug_to_notice_signals (ptid_t
);
156 static int debug_to_thread_alive (ptid_t
);
158 static void debug_to_stop (void);
160 /* Pointer to array of target architecture structures; the size of the
161 array; the current index into the array; the allocated size of the
163 struct target_ops
**target_structs
;
164 unsigned target_struct_size
;
165 unsigned target_struct_index
;
166 unsigned target_struct_allocsize
;
167 #define DEFAULT_ALLOCSIZE 10
169 /* The initial current target, so that there is always a semi-valid
172 static struct target_ops dummy_target
;
174 /* Top of target stack. */
176 static struct target_ops
*target_stack
;
178 /* The target structure we are currently using to talk to a process
179 or file or whatever "inferior" we have. */
181 struct target_ops current_target
;
183 /* Command list for target. */
185 static struct cmd_list_element
*targetlist
= NULL
;
187 /* Nonzero if we are debugging an attached outside process
188 rather than an inferior. */
192 /* Non-zero if we want to see trace of target level stuff. */
194 static int targetdebug
= 0;
196 static void setup_target_debug (void);
198 DCACHE
*target_dcache
;
200 /* The user just typed 'target' without the name of a target. */
203 target_command (char *arg
, int from_tty
)
205 fputs_filtered ("Argument required (target name). Try `help target'\n",
209 /* Add a possible target architecture to the list. */
212 add_target (struct target_ops
*t
)
216 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
217 target_structs
= (struct target_ops
**) xmalloc
218 (target_struct_allocsize
* sizeof (*target_structs
));
220 if (target_struct_size
>= target_struct_allocsize
)
222 target_struct_allocsize
*= 2;
223 target_structs
= (struct target_ops
**)
224 xrealloc ((char *) target_structs
,
225 target_struct_allocsize
* sizeof (*target_structs
));
227 target_structs
[target_struct_size
++] = t
;
229 if (targetlist
== NULL
)
230 add_prefix_cmd ("target", class_run
, target_command
,
231 "Connect to a target machine or process.\n\
232 The first argument is the type or protocol of the target machine.\n\
233 Remaining arguments are interpreted by the target protocol. For more\n\
234 information on the arguments for a particular protocol, type\n\
235 `help target ' followed by the protocol name.",
236 &targetlist
, "target ", 0, &cmdlist
);
237 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
248 target_load (char *arg
, int from_tty
)
250 dcache_invalidate (target_dcache
);
251 (*current_target
.to_load
) (arg
, from_tty
);
255 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
256 struct target_ops
*t
)
258 errno
= EIO
; /* Can't read/write this location */
259 return 0; /* No bytes handled */
265 error ("You can't do that when your target is `%s'",
266 current_target
.to_shortname
);
272 error ("You can't do that without a process to debug.");
276 nosymbol (char *name
, CORE_ADDR
*addrp
)
278 return 1; /* Symbol does not exist in target env */
282 nosupport_runtime (void)
284 if (ptid_equal (inferior_ptid
, null_ptid
))
287 error ("No run-time support for this");
292 default_terminal_info (char *args
, int from_tty
)
294 printf_unfiltered ("No saved terminal information.\n");
297 /* This is the default target_create_inferior and target_attach function.
298 If the current target is executing, it asks whether to kill it off.
299 If this function returns without calling error(), it has killed off
300 the target, and the operation should be attempted. */
303 kill_or_be_killed (int from_tty
)
305 if (target_has_execution
)
307 printf_unfiltered ("You are already running a program:\n");
308 target_files_info ();
309 if (query ("Kill it? "))
312 if (target_has_execution
)
313 error ("Killing the program did not help.");
318 error ("Program not killed.");
325 maybe_kill_then_attach (char *args
, int from_tty
)
327 kill_or_be_killed (from_tty
);
328 target_attach (args
, from_tty
);
332 maybe_kill_then_create_inferior (char *exec
, char *args
, char **env
)
334 kill_or_be_killed (0);
335 target_create_inferior (exec
, args
, env
);
338 /* Go through the target stack from top to bottom, copying over zero
339 entries in current_target, then filling in still empty entries. In
340 effect, we are doing class inheritance through the pushed target
343 NOTE: cagney/2003-10-17: The problem with this inheritance, as it
344 is currently implemented, is that it discards any knowledge of
345 which target an inherited method originally belonged to.
346 Consequently, new new target methods should instead explicitly and
347 locally search the target stack for the target that can handle the
351 update_current_target (void)
353 struct target_ops
*t
;
355 /* First, reset curren'ts contents. */
356 memset (¤t_target
, 0, sizeof (current_target
));
358 #define INHERIT(FIELD, TARGET) \
359 if (!current_target.FIELD) \
360 current_target.FIELD = (TARGET)->FIELD
362 for (t
= target_stack
; t
; t
= t
->beneath
)
364 INHERIT (to_shortname
, t
);
365 INHERIT (to_longname
, t
);
367 INHERIT (to_open
, t
);
368 INHERIT (to_close
, t
);
369 INHERIT (to_attach
, t
);
370 INHERIT (to_post_attach
, t
);
371 INHERIT (to_detach
, t
);
372 INHERIT (to_disconnect
, t
);
373 INHERIT (to_resume
, t
);
374 INHERIT (to_wait
, t
);
375 INHERIT (to_post_wait
, t
);
376 INHERIT (to_fetch_registers
, t
);
377 INHERIT (to_store_registers
, t
);
378 INHERIT (to_prepare_to_store
, t
);
379 INHERIT (to_xfer_memory
, t
);
380 INHERIT (to_files_info
, t
);
381 INHERIT (to_insert_breakpoint
, t
);
382 INHERIT (to_remove_breakpoint
, t
);
383 INHERIT (to_can_use_hw_breakpoint
, t
);
384 INHERIT (to_insert_hw_breakpoint
, t
);
385 INHERIT (to_remove_hw_breakpoint
, t
);
386 INHERIT (to_insert_watchpoint
, t
);
387 INHERIT (to_remove_watchpoint
, t
);
388 INHERIT (to_stopped_data_address
, t
);
389 INHERIT (to_stopped_by_watchpoint
, t
);
390 INHERIT (to_have_continuable_watchpoint
, t
);
391 INHERIT (to_region_size_ok_for_hw_watchpoint
, t
);
392 INHERIT (to_terminal_init
, t
);
393 INHERIT (to_terminal_inferior
, t
);
394 INHERIT (to_terminal_ours_for_output
, t
);
395 INHERIT (to_terminal_ours
, t
);
396 INHERIT (to_terminal_save_ours
, t
);
397 INHERIT (to_terminal_info
, t
);
398 INHERIT (to_kill
, t
);
399 INHERIT (to_load
, t
);
400 INHERIT (to_lookup_symbol
, t
);
401 INHERIT (to_create_inferior
, t
);
402 INHERIT (to_post_startup_inferior
, t
);
403 INHERIT (to_acknowledge_created_inferior
, t
);
404 INHERIT (to_insert_fork_catchpoint
, t
);
405 INHERIT (to_remove_fork_catchpoint
, t
);
406 INHERIT (to_insert_vfork_catchpoint
, t
);
407 INHERIT (to_remove_vfork_catchpoint
, t
);
408 INHERIT (to_follow_fork
, t
);
409 INHERIT (to_insert_exec_catchpoint
, t
);
410 INHERIT (to_remove_exec_catchpoint
, t
);
411 INHERIT (to_reported_exec_events_per_exec_call
, t
);
412 INHERIT (to_has_exited
, t
);
413 INHERIT (to_mourn_inferior
, t
);
414 INHERIT (to_can_run
, t
);
415 INHERIT (to_notice_signals
, t
);
416 INHERIT (to_thread_alive
, t
);
417 INHERIT (to_find_new_threads
, t
);
418 INHERIT (to_pid_to_str
, t
);
419 INHERIT (to_extra_thread_info
, t
);
420 INHERIT (to_stop
, t
);
421 /* Do not inherit to_read_partial. */
422 /* Do not inherit to_write_partial. */
423 INHERIT (to_rcmd
, t
);
424 INHERIT (to_enable_exception_callback
, t
);
425 INHERIT (to_get_current_exception_event
, t
);
426 INHERIT (to_pid_to_exec_file
, t
);
427 INHERIT (to_stratum
, t
);
428 INHERIT (to_has_all_memory
, t
);
429 INHERIT (to_has_memory
, t
);
430 INHERIT (to_has_stack
, t
);
431 INHERIT (to_has_registers
, t
);
432 INHERIT (to_has_execution
, t
);
433 INHERIT (to_has_thread_control
, t
);
434 INHERIT (to_sections
, t
);
435 INHERIT (to_sections_end
, t
);
436 INHERIT (to_can_async_p
, t
);
437 INHERIT (to_is_async_p
, t
);
438 INHERIT (to_async
, t
);
439 INHERIT (to_async_mask_value
, t
);
440 INHERIT (to_find_memory_regions
, t
);
441 INHERIT (to_make_corefile_notes
, t
);
442 INHERIT (to_get_thread_local_address
, t
);
443 INHERIT (to_magic
, t
);
447 /* Clean up a target struct so it no longer has any zero pointers in
448 it. We default entries, at least to stubs that print error
451 #define de_fault(field, value) \
452 if (!current_target.field) \
453 current_target.field = value
456 (void (*) (char *, int))
462 maybe_kill_then_attach
);
463 de_fault (to_post_attach
,
467 (void (*) (char *, int))
469 de_fault (to_disconnect
,
470 (void (*) (char *, int))
473 (void (*) (ptid_t
, int, enum target_signal
))
476 (ptid_t (*) (ptid_t
, struct target_waitstatus
*))
478 de_fault (to_post_wait
,
479 (void (*) (ptid_t
, int))
481 de_fault (to_fetch_registers
,
484 de_fault (to_store_registers
,
487 de_fault (to_prepare_to_store
,
490 de_fault (to_xfer_memory
,
491 (int (*) (CORE_ADDR
, char *, int, int, struct mem_attrib
*, struct target_ops
*))
493 de_fault (to_files_info
,
494 (void (*) (struct target_ops
*))
496 de_fault (to_insert_breakpoint
,
497 memory_insert_breakpoint
);
498 de_fault (to_remove_breakpoint
,
499 memory_remove_breakpoint
);
500 de_fault (to_can_use_hw_breakpoint
,
501 (int (*) (int, int, int))
503 de_fault (to_insert_hw_breakpoint
,
504 (int (*) (CORE_ADDR
, char *))
506 de_fault (to_remove_hw_breakpoint
,
507 (int (*) (CORE_ADDR
, char *))
509 de_fault (to_insert_watchpoint
,
510 (int (*) (CORE_ADDR
, int, int))
512 de_fault (to_remove_watchpoint
,
513 (int (*) (CORE_ADDR
, int, int))
515 de_fault (to_stopped_by_watchpoint
,
518 de_fault (to_stopped_data_address
,
519 (CORE_ADDR (*) (void))
521 de_fault (to_region_size_ok_for_hw_watchpoint
,
522 default_region_size_ok_for_hw_watchpoint
);
523 de_fault (to_terminal_init
,
526 de_fault (to_terminal_inferior
,
529 de_fault (to_terminal_ours_for_output
,
532 de_fault (to_terminal_ours
,
535 de_fault (to_terminal_save_ours
,
538 de_fault (to_terminal_info
,
539 default_terminal_info
);
544 (void (*) (char *, int))
546 de_fault (to_lookup_symbol
,
547 (int (*) (char *, CORE_ADDR
*))
549 de_fault (to_create_inferior
,
550 maybe_kill_then_create_inferior
);
551 de_fault (to_post_startup_inferior
,
554 de_fault (to_acknowledge_created_inferior
,
557 de_fault (to_insert_fork_catchpoint
,
560 de_fault (to_remove_fork_catchpoint
,
563 de_fault (to_insert_vfork_catchpoint
,
566 de_fault (to_remove_vfork_catchpoint
,
569 de_fault (to_follow_fork
,
572 de_fault (to_insert_exec_catchpoint
,
575 de_fault (to_remove_exec_catchpoint
,
578 de_fault (to_reported_exec_events_per_exec_call
,
581 de_fault (to_has_exited
,
582 (int (*) (int, int, int *))
584 de_fault (to_mourn_inferior
,
587 de_fault (to_can_run
,
589 de_fault (to_notice_signals
,
592 de_fault (to_thread_alive
,
595 de_fault (to_find_new_threads
,
598 de_fault (to_extra_thread_info
,
599 (char *(*) (struct thread_info
*))
605 (void (*) (char *, struct ui_file
*))
607 de_fault (to_enable_exception_callback
,
608 (struct symtab_and_line
* (*) (enum exception_event_kind
, int))
610 de_fault (to_get_current_exception_event
,
611 (struct exception_event_record
* (*) (void))
613 de_fault (to_pid_to_exec_file
,
616 de_fault (to_can_async_p
,
619 de_fault (to_is_async_p
,
623 (void (*) (void (*) (enum inferior_event_type
, void*), void*))
627 /* Finally, position the target-stack beneath the squashed
628 "current_target". That way code looking for a non-inherited
629 target method can quickly and simply find it. */
630 current_target
.beneath
= target_stack
;
633 /* Push a new target type into the stack of the existing target accessors,
634 possibly superseding some of the existing accessors.
636 Result is zero if the pushed target ended up on top of the stack,
637 nonzero if at least one target is on top of it.
639 Rather than allow an empty stack, we always have the dummy target at
640 the bottom stratum, so we can call the function vectors without
644 push_target (struct target_ops
*t
)
646 struct target_ops
**cur
;
648 /* Check magic number. If wrong, it probably means someone changed
649 the struct definition, but not all the places that initialize one. */
650 if (t
->to_magic
!= OPS_MAGIC
)
652 fprintf_unfiltered (gdb_stderr
,
653 "Magic number of %s target struct wrong\n",
655 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
658 /* Find the proper stratum to install this target in. */
659 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
661 if ((int) (t
->to_stratum
) >= (int) (*cur
)->to_stratum
)
665 /* If there's already targets at this stratum, remove them. */
666 /* FIXME: cagney/2003-10-15: I think this should be poping all
667 targets to CUR, and not just those at this stratum level. */
668 while ((*cur
) != NULL
&& t
->to_stratum
== (*cur
)->to_stratum
)
670 /* There's already something at this stratum level. Close it,
671 and un-hook it from the stack. */
672 struct target_ops
*tmp
= (*cur
);
673 (*cur
) = (*cur
)->beneath
;
679 /* We have removed all targets in our stratum, now add the new one. */
683 update_current_target ();
686 setup_target_debug ();
689 return (t
!= target_stack
);
692 /* Remove a target_ops vector from the stack, wherever it may be.
693 Return how many times it was removed (0 or 1). */
696 unpush_target (struct target_ops
*t
)
698 struct target_ops
**cur
;
699 struct target_ops
*tmp
;
702 t
->to_close (0); /* Let it clean up */
704 /* Look for the specified target. Note that we assume that a target
705 can only occur once in the target stack. */
707 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
714 return 0; /* Didn't find target_ops, quit now */
716 /* Unchain the target */
718 (*cur
) = (*cur
)->beneath
;
721 update_current_target ();
729 (current_target
.to_close
) (0); /* Let it clean up */
730 if (unpush_target (target_stack
) == 1)
733 fprintf_unfiltered (gdb_stderr
,
734 "pop_target couldn't find target %s\n",
735 current_target
.to_shortname
);
736 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
740 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
742 /* target_read_string -- read a null terminated string, up to LEN bytes,
743 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
744 Set *STRING to a pointer to malloc'd memory containing the data; the caller
745 is responsible for freeing it. Return the number of bytes successfully
749 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
751 int tlen
, origlen
, offset
, i
;
755 int buffer_allocated
;
757 unsigned int nbytes_read
= 0;
759 /* Small for testing. */
760 buffer_allocated
= 4;
761 buffer
= xmalloc (buffer_allocated
);
768 tlen
= MIN (len
, 4 - (memaddr
& 3));
769 offset
= memaddr
& 3;
771 errcode
= target_xfer_memory (memaddr
& ~3, buf
, 4, 0);
774 /* The transfer request might have crossed the boundary to an
775 unallocated region of memory. Retry the transfer, requesting
779 errcode
= target_xfer_memory (memaddr
, buf
, 1, 0);
784 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
787 bytes
= bufptr
- buffer
;
788 buffer_allocated
*= 2;
789 buffer
= xrealloc (buffer
, buffer_allocated
);
790 bufptr
= buffer
+ bytes
;
793 for (i
= 0; i
< tlen
; i
++)
795 *bufptr
++ = buf
[i
+ offset
];
796 if (buf
[i
+ offset
] == '\000')
798 nbytes_read
+= i
+ 1;
815 /* Find a section containing ADDR. */
816 struct section_table
*
817 target_section_by_addr (struct target_ops
*target
, CORE_ADDR addr
)
819 struct section_table
*secp
;
820 for (secp
= target
->to_sections
;
821 secp
< target
->to_sections_end
;
824 if (addr
>= secp
->addr
&& addr
< secp
->endaddr
)
830 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
831 GDB's memory at MYADDR. Returns either 0 for success or an errno value
834 If an error occurs, no guarantee is made about the contents of the data at
835 MYADDR. In particular, the caller should not depend upon partial reads
836 filling the buffer with good data. There is no way for the caller to know
837 how much good data might have been transfered anyway. Callers that can
838 deal with partial reads should call target_read_memory_partial. */
841 target_read_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
843 return target_xfer_memory (memaddr
, myaddr
, len
, 0);
847 target_write_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
849 return target_xfer_memory (memaddr
, myaddr
, len
, 1);
852 static int trust_readonly
= 0;
854 /* Move memory to or from the targets. The top target gets priority;
855 if it cannot handle it, it is offered to the next one down, etc.
857 Result is -1 on error, or the number of bytes transfered. */
860 do_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
861 struct mem_attrib
*attrib
)
865 struct target_ops
*t
;
867 /* Zero length requests are ok and require no work. */
871 /* to_xfer_memory is not guaranteed to set errno, even when it returns
875 if (!write
&& trust_readonly
)
877 struct section_table
*secp
;
878 /* User-settable option, "trust-readonly-sections". If true,
879 then memory from any SEC_READONLY bfd section may be read
880 directly from the bfd file. */
881 secp
= target_section_by_addr (¤t_target
, memaddr
);
883 && (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
885 return xfer_memory (memaddr
, myaddr
, len
, 0, attrib
, ¤t_target
);
888 /* The quick case is that the top target can handle the transfer. */
889 res
= current_target
.to_xfer_memory
890 (memaddr
, myaddr
, len
, write
, attrib
, ¤t_target
);
892 /* If res <= 0 then we call it again in the loop. Ah well. */
895 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
897 if (!t
->to_has_memory
)
900 res
= t
->to_xfer_memory (memaddr
, myaddr
, len
, write
, attrib
, t
);
902 break; /* Handled all or part of xfer */
903 if (t
->to_has_all_memory
)
915 /* Perform a memory transfer. Iterate until the entire region has
918 Result is 0 or errno value. */
921 target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
)
925 struct mem_region
*region
;
927 /* Zero length requests are ok and require no work. */
935 region
= lookup_mem_region(memaddr
);
936 if (memaddr
+ len
< region
->hi
)
939 reg_len
= region
->hi
- memaddr
;
941 switch (region
->attrib
.mode
)
956 if (region
->attrib
.cache
)
957 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
,
960 res
= do_xfer_memory (memaddr
, myaddr
, reg_len
, write
,
965 /* If this address is for nonexistent memory, read zeros
966 if reading, or do nothing if writing. Return
969 memset (myaddr
, 0, len
);
983 return 0; /* We managed to cover it all somehow. */
987 /* Perform a partial memory transfer.
989 Result is -1 on error, or the number of bytes transfered. */
992 target_xfer_memory_partial (CORE_ADDR memaddr
, char *myaddr
, int len
,
993 int write_p
, int *err
)
997 struct mem_region
*region
;
999 /* Zero length requests are ok and require no work. */
1006 region
= lookup_mem_region(memaddr
);
1007 if (memaddr
+ len
< region
->hi
)
1010 reg_len
= region
->hi
- memaddr
;
1012 switch (region
->attrib
.mode
)
1031 if (region
->attrib
.cache
)
1032 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
,
1035 res
= do_xfer_memory (memaddr
, myaddr
, reg_len
, write_p
,
1053 target_read_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1055 return target_xfer_memory_partial (memaddr
, buf
, len
, 0, err
);
1059 target_write_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1061 return target_xfer_memory_partial (memaddr
, buf
, len
, 1, err
);
1064 /* More generic transfers. */
1067 target_read_partial (struct target_ops
*ops
,
1068 enum target_object object
,
1069 const char *annex
, void *buf
,
1070 ULONGEST offset
, LONGEST len
)
1072 struct target_ops
*op
;
1074 /* Find the first target stratum that can handle the request. */
1076 op
!= NULL
&& op
->to_read_partial
== NULL
;
1082 /* Now apply the operation at that level. */
1083 return op
->to_read_partial (op
, object
, annex
, buf
, offset
, len
);
1087 target_write_partial (struct target_ops
*ops
,
1088 enum target_object object
,
1089 const char *annex
, const void *buf
,
1090 ULONGEST offset
, LONGEST len
)
1092 struct target_ops
*op
;
1094 /* Find the first target stratum that can handle the request. */
1096 op
!= NULL
&& op
->to_write_partial
== NULL
;
1102 return op
->to_write_partial (op
, object
, annex
, buf
, offset
, len
);
1105 /* Wrappers to perform the full transfer. */
1107 target_read (struct target_ops
*ops
,
1108 enum target_object object
,
1109 const char *annex
, void *buf
,
1110 ULONGEST offset
, LONGEST len
)
1113 while (xfered
< len
)
1115 LONGEST xfer
= target_write_partial (ops
, object
, annex
,
1116 (bfd_byte
*) buf
+ xfered
,
1117 offset
+ xfered
, len
- xfered
);
1118 /* Call an observer, notifying them of the xfer progress? */
1128 target_write (struct target_ops
*ops
,
1129 enum target_object object
,
1130 const char *annex
, const void *buf
,
1131 ULONGEST offset
, LONGEST len
)
1134 while (xfered
< len
)
1136 LONGEST xfer
= target_write_partial (ops
, object
, annex
,
1137 (bfd_byte
*) buf
+ xfered
,
1138 offset
+ xfered
, len
- xfered
);
1139 /* Call an observer, notifying them of the xfer progress? */
1149 target_info (char *args
, int from_tty
)
1151 struct target_ops
*t
;
1152 int has_all_mem
= 0;
1154 if (symfile_objfile
!= NULL
)
1155 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
1157 #ifdef FILES_INFO_HOOK
1158 if (FILES_INFO_HOOK ())
1162 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
1164 if (!t
->to_has_memory
)
1167 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
1170 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1171 printf_unfiltered ("%s:\n", t
->to_longname
);
1172 (t
->to_files_info
) (t
);
1173 has_all_mem
= t
->to_has_all_memory
;
1177 /* This is to be called by the open routine before it does
1181 target_preopen (int from_tty
)
1185 if (target_has_execution
)
1188 || query ("A program is being debugged already. Kill it? "))
1191 error ("Program not killed.");
1194 /* Calling target_kill may remove the target from the stack. But if
1195 it doesn't (which seems like a win for UDI), remove it now. */
1197 if (target_has_execution
)
1201 /* Detach a target after doing deferred register stores. */
1204 target_detach (char *args
, int from_tty
)
1206 /* Handle any optimized stores to the inferior. */
1207 #ifdef DO_DEFERRED_STORES
1210 (current_target
.to_detach
) (args
, from_tty
);
1214 target_disconnect (char *args
, int from_tty
)
1216 /* Handle any optimized stores to the inferior. */
1217 #ifdef DO_DEFERRED_STORES
1220 (current_target
.to_disconnect
) (args
, from_tty
);
1224 target_link (char *modname
, CORE_ADDR
*t_reloc
)
1226 if (STREQ (current_target
.to_shortname
, "rombug"))
1228 (current_target
.to_lookup_symbol
) (modname
, t_reloc
);
1230 error ("Unable to link to %s and get relocation in rombug", modname
);
1233 *t_reloc
= (CORE_ADDR
) -1;
1237 target_async_mask (int mask
)
1239 int saved_async_masked_status
= target_async_mask_value
;
1240 target_async_mask_value
= mask
;
1241 return saved_async_masked_status
;
1244 /* Look through the list of possible targets for a target that can
1245 execute a run or attach command without any other data. This is
1246 used to locate the default process stratum.
1248 Result is always valid (error() is called for errors). */
1250 static struct target_ops
*
1251 find_default_run_target (char *do_mesg
)
1253 struct target_ops
**t
;
1254 struct target_ops
*runable
= NULL
;
1259 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1262 if ((*t
)->to_can_run
&& target_can_run (*t
))
1270 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
1276 find_default_attach (char *args
, int from_tty
)
1278 struct target_ops
*t
;
1280 t
= find_default_run_target ("attach");
1281 (t
->to_attach
) (args
, from_tty
);
1286 find_default_create_inferior (char *exec_file
, char *allargs
, char **env
)
1288 struct target_ops
*t
;
1290 t
= find_default_run_target ("run");
1291 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
1296 default_region_size_ok_for_hw_watchpoint (int byte_count
)
1298 return (byte_count
<= DEPRECATED_REGISTER_SIZE
);
1314 return_minus_one (void)
1320 * Resize the to_sections pointer. Also make sure that anyone that
1321 * was holding on to an old value of it gets updated.
1322 * Returns the old size.
1326 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1328 struct target_ops
**t
;
1329 struct section_table
*old_value
;
1332 old_value
= target
->to_sections
;
1334 if (target
->to_sections
)
1336 old_count
= target
->to_sections_end
- target
->to_sections
;
1337 target
->to_sections
= (struct section_table
*)
1338 xrealloc ((char *) target
->to_sections
,
1339 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1344 target
->to_sections
= (struct section_table
*)
1345 xmalloc ((sizeof (struct section_table
)) * num_added
);
1347 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1349 /* Check to see if anyone else was pointing to this structure.
1350 If old_value was null, then no one was. */
1354 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1357 if ((*t
)->to_sections
== old_value
)
1359 (*t
)->to_sections
= target
->to_sections
;
1360 (*t
)->to_sections_end
= target
->to_sections_end
;
1369 /* Remove all target sections taken from ABFD.
1371 Scan the current target stack for targets whose section tables
1372 refer to sections from BFD, and remove those sections. We use this
1373 when we notice that the inferior has unloaded a shared object, for
1376 remove_target_sections (bfd
*abfd
)
1378 struct target_ops
**t
;
1380 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; t
++)
1382 struct section_table
*src
, *dest
;
1384 dest
= (*t
)->to_sections
;
1385 for (src
= (*t
)->to_sections
; src
< (*t
)->to_sections_end
; src
++)
1386 if (src
->bfd
!= abfd
)
1388 /* Keep this section. */
1389 if (dest
< src
) *dest
= *src
;
1393 /* If we've dropped any sections, resize the section table. */
1395 target_resize_to_sections (*t
, dest
- src
);
1402 /* Find a single runnable target in the stack and return it. If for
1403 some reason there is more than one, return NULL. */
1406 find_run_target (void)
1408 struct target_ops
**t
;
1409 struct target_ops
*runable
= NULL
;
1414 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1416 if ((*t
)->to_can_run
&& target_can_run (*t
))
1423 return (count
== 1 ? runable
: NULL
);
1426 /* Find a single core_stratum target in the list of targets and return it.
1427 If for some reason there is more than one, return NULL. */
1430 find_core_target (void)
1432 struct target_ops
**t
;
1433 struct target_ops
*runable
= NULL
;
1438 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1441 if ((*t
)->to_stratum
== core_stratum
)
1448 return (count
== 1 ? runable
: NULL
);
1452 * Find the next target down the stack from the specified target.
1456 find_target_beneath (struct target_ops
*t
)
1462 /* The inferior process has died. Long live the inferior! */
1465 generic_mourn_inferior (void)
1467 extern int show_breakpoint_hit_counts
;
1469 inferior_ptid
= null_ptid
;
1471 breakpoint_init_inferior (inf_exited
);
1472 registers_changed ();
1474 #ifdef CLEAR_DEFERRED_STORES
1475 /* Delete any pending stores to the inferior... */
1476 CLEAR_DEFERRED_STORES
;
1479 reopen_exec_file ();
1480 reinit_frame_cache ();
1482 /* It is confusing to the user for ignore counts to stick around
1483 from previous runs of the inferior. So clear them. */
1484 /* However, it is more confusing for the ignore counts to disappear when
1485 using hit counts. So don't clear them if we're counting hits. */
1486 if (!show_breakpoint_hit_counts
)
1487 breakpoint_clear_ignore_counts ();
1493 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1494 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1495 translation of that in OURSTATUS. */
1497 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
1499 #ifdef CHILD_SPECIAL_WAITSTATUS
1500 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1501 if it wants to deal with hoststatus. */
1502 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
1506 if (WIFEXITED (hoststatus
))
1508 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1509 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
1511 else if (!WIFSTOPPED (hoststatus
))
1513 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1514 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
1518 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
1519 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
1523 /* Returns zero to leave the inferior alone, one to interrupt it. */
1524 int (*target_activity_function
) (void);
1525 int target_activity_fd
;
1527 /* Convert a normal process ID to a string. Returns the string in a static
1531 normal_pid_to_str (ptid_t ptid
)
1533 static char buf
[30];
1535 sprintf (buf
, "process %d", PIDGET (ptid
));
1539 /* Some targets (such as ttrace-based HPUX) don't allow us to request
1540 notification of inferior events such as fork and vork immediately
1541 after the inferior is created. (This because of how gdb gets an
1542 inferior created via invoking a shell to do it. In such a scenario,
1543 if the shell init file has commands in it, the shell will fork and
1544 exec for each of those commands, and we will see each such fork
1547 This function is used by all targets that allow us to request
1548 notification of forks, etc at inferior creation time; e.g., in
1549 target_acknowledge_forked_child.
1552 normal_target_post_startup_inferior (ptid_t ptid
)
1554 /* This space intentionally left blank. */
1557 /* Error-catcher for target_find_memory_regions */
1558 static int dummy_find_memory_regions (int (*ignore1
) (), void *ignore2
)
1560 error ("No target.");
1564 /* Error-catcher for target_make_corefile_notes */
1565 static char * dummy_make_corefile_notes (bfd
*ignore1
, int *ignore2
)
1567 error ("No target.");
1571 /* Set up the handful of non-empty slots needed by the dummy target
1575 init_dummy_target (void)
1577 dummy_target
.to_shortname
= "None";
1578 dummy_target
.to_longname
= "None";
1579 dummy_target
.to_doc
= "";
1580 dummy_target
.to_attach
= find_default_attach
;
1581 dummy_target
.to_create_inferior
= find_default_create_inferior
;
1582 dummy_target
.to_pid_to_str
= normal_pid_to_str
;
1583 dummy_target
.to_stratum
= dummy_stratum
;
1584 dummy_target
.to_find_memory_regions
= dummy_find_memory_regions
;
1585 dummy_target
.to_make_corefile_notes
= dummy_make_corefile_notes
;
1586 dummy_target
.to_magic
= OPS_MAGIC
;
1590 static struct target_ops debug_target
;
1593 debug_to_open (char *args
, int from_tty
)
1595 debug_target
.to_open (args
, from_tty
);
1597 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
1601 debug_to_close (int quitting
)
1603 debug_target
.to_close (quitting
);
1605 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
1609 debug_to_attach (char *args
, int from_tty
)
1611 debug_target
.to_attach (args
, from_tty
);
1613 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
1618 debug_to_post_attach (int pid
)
1620 debug_target
.to_post_attach (pid
);
1622 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
1626 debug_to_detach (char *args
, int from_tty
)
1628 debug_target
.to_detach (args
, from_tty
);
1630 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
1634 debug_to_disconnect (char *args
, int from_tty
)
1636 debug_target
.to_disconnect (args
, from_tty
);
1638 fprintf_unfiltered (gdb_stdlog
, "target_disconnect (%s, %d)\n",
1643 debug_to_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
1645 debug_target
.to_resume (ptid
, step
, siggnal
);
1647 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", PIDGET (ptid
),
1648 step
? "step" : "continue",
1649 target_signal_to_name (siggnal
));
1653 debug_to_wait (ptid_t ptid
, struct target_waitstatus
*status
)
1657 retval
= debug_target
.to_wait (ptid
, status
);
1659 fprintf_unfiltered (gdb_stdlog
,
1660 "target_wait (%d, status) = %d, ", PIDGET (ptid
),
1662 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
1663 switch (status
->kind
)
1665 case TARGET_WAITKIND_EXITED
:
1666 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
1667 status
->value
.integer
);
1669 case TARGET_WAITKIND_STOPPED
:
1670 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
1671 target_signal_to_name (status
->value
.sig
));
1673 case TARGET_WAITKIND_SIGNALLED
:
1674 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
1675 target_signal_to_name (status
->value
.sig
));
1677 case TARGET_WAITKIND_LOADED
:
1678 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
1680 case TARGET_WAITKIND_FORKED
:
1681 fprintf_unfiltered (gdb_stdlog
, "forked\n");
1683 case TARGET_WAITKIND_VFORKED
:
1684 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
1686 case TARGET_WAITKIND_EXECD
:
1687 fprintf_unfiltered (gdb_stdlog
, "execd\n");
1689 case TARGET_WAITKIND_SPURIOUS
:
1690 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
1693 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
1701 debug_to_post_wait (ptid_t ptid
, int status
)
1703 debug_target
.to_post_wait (ptid
, status
);
1705 fprintf_unfiltered (gdb_stdlog
, "target_post_wait (%d, %d)\n",
1706 PIDGET (ptid
), status
);
1710 debug_print_register (const char * func
, int regno
)
1712 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
1713 if (regno
>= 0 && regno
< NUM_REGS
+ NUM_PSEUDO_REGS
1714 && REGISTER_NAME (regno
) != NULL
&& REGISTER_NAME (regno
)[0] != '\0')
1715 fprintf_unfiltered (gdb_stdlog
, "(%s)", REGISTER_NAME (regno
));
1717 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
1721 unsigned char buf
[MAX_REGISTER_SIZE
];
1722 deprecated_read_register_gen (regno
, buf
);
1723 fprintf_unfiltered (gdb_stdlog
, " = ");
1724 for (i
= 0; i
< DEPRECATED_REGISTER_RAW_SIZE (regno
); i
++)
1726 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
1728 if (DEPRECATED_REGISTER_RAW_SIZE (regno
) <= sizeof (LONGEST
))
1730 fprintf_unfiltered (gdb_stdlog
, " 0x%s %s",
1731 paddr_nz (read_register (regno
)),
1732 paddr_d (read_register (regno
)));
1735 fprintf_unfiltered (gdb_stdlog
, "\n");
1739 debug_to_fetch_registers (int regno
)
1741 debug_target
.to_fetch_registers (regno
);
1742 debug_print_register ("target_fetch_registers", regno
);
1746 debug_to_store_registers (int regno
)
1748 debug_target
.to_store_registers (regno
);
1749 debug_print_register ("target_store_registers", regno
);
1750 fprintf_unfiltered (gdb_stdlog
, "\n");
1754 debug_to_prepare_to_store (void)
1756 debug_target
.to_prepare_to_store ();
1758 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
1762 debug_to_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
1763 struct mem_attrib
*attrib
,
1764 struct target_ops
*target
)
1768 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
,
1771 fprintf_unfiltered (gdb_stdlog
,
1772 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
1773 (unsigned int) memaddr
, /* possable truncate long long */
1774 len
, write
? "write" : "read", retval
);
1782 fputs_unfiltered (", bytes =", gdb_stdlog
);
1783 for (i
= 0; i
< retval
; i
++)
1785 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
1786 fprintf_unfiltered (gdb_stdlog
, "\n");
1787 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1791 fputc_unfiltered ('\n', gdb_stdlog
);
1797 debug_to_files_info (struct target_ops
*target
)
1799 debug_target
.to_files_info (target
);
1801 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
1805 debug_to_insert_breakpoint (CORE_ADDR addr
, char *save
)
1809 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
1811 fprintf_unfiltered (gdb_stdlog
,
1812 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
1813 (unsigned long) addr
,
1814 (unsigned long) retval
);
1819 debug_to_remove_breakpoint (CORE_ADDR addr
, char *save
)
1823 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
1825 fprintf_unfiltered (gdb_stdlog
,
1826 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
1827 (unsigned long) addr
,
1828 (unsigned long) retval
);
1833 debug_to_can_use_hw_breakpoint (int type
, int cnt
, int from_tty
)
1837 retval
= debug_target
.to_can_use_hw_breakpoint (type
, cnt
, from_tty
);
1839 fprintf_unfiltered (gdb_stdlog
,
1840 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
1841 (unsigned long) type
,
1842 (unsigned long) cnt
,
1843 (unsigned long) from_tty
,
1844 (unsigned long) retval
);
1849 debug_to_region_size_ok_for_hw_watchpoint (int byte_count
)
1853 retval
= debug_target
.to_region_size_ok_for_hw_watchpoint (byte_count
);
1855 fprintf_unfiltered (gdb_stdlog
,
1856 "TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT (%ld) = 0x%lx\n",
1857 (unsigned long) byte_count
,
1858 (unsigned long) retval
);
1863 debug_to_stopped_by_watchpoint (void)
1867 retval
= debug_target
.to_stopped_by_watchpoint ();
1869 fprintf_unfiltered (gdb_stdlog
,
1870 "STOPPED_BY_WATCHPOINT () = %ld\n",
1871 (unsigned long) retval
);
1876 debug_to_stopped_data_address (void)
1880 retval
= debug_target
.to_stopped_data_address ();
1882 fprintf_unfiltered (gdb_stdlog
,
1883 "target_stopped_data_address () = 0x%lx\n",
1884 (unsigned long) retval
);
1889 debug_to_insert_hw_breakpoint (CORE_ADDR addr
, char *save
)
1893 retval
= debug_target
.to_insert_hw_breakpoint (addr
, save
);
1895 fprintf_unfiltered (gdb_stdlog
,
1896 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
1897 (unsigned long) addr
,
1898 (unsigned long) retval
);
1903 debug_to_remove_hw_breakpoint (CORE_ADDR addr
, char *save
)
1907 retval
= debug_target
.to_remove_hw_breakpoint (addr
, save
);
1909 fprintf_unfiltered (gdb_stdlog
,
1910 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
1911 (unsigned long) addr
,
1912 (unsigned long) retval
);
1917 debug_to_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
1921 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
1923 fprintf_unfiltered (gdb_stdlog
,
1924 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1925 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
1930 debug_to_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
1934 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
1936 fprintf_unfiltered (gdb_stdlog
,
1937 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1938 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
1943 debug_to_terminal_init (void)
1945 debug_target
.to_terminal_init ();
1947 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
1951 debug_to_terminal_inferior (void)
1953 debug_target
.to_terminal_inferior ();
1955 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
1959 debug_to_terminal_ours_for_output (void)
1961 debug_target
.to_terminal_ours_for_output ();
1963 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
1967 debug_to_terminal_ours (void)
1969 debug_target
.to_terminal_ours ();
1971 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
1975 debug_to_terminal_save_ours (void)
1977 debug_target
.to_terminal_save_ours ();
1979 fprintf_unfiltered (gdb_stdlog
, "target_terminal_save_ours ()\n");
1983 debug_to_terminal_info (char *arg
, int from_tty
)
1985 debug_target
.to_terminal_info (arg
, from_tty
);
1987 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
1992 debug_to_kill (void)
1994 debug_target
.to_kill ();
1996 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
2000 debug_to_load (char *args
, int from_tty
)
2002 debug_target
.to_load (args
, from_tty
);
2004 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
2008 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
2012 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
2014 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
2020 debug_to_create_inferior (char *exec_file
, char *args
, char **env
)
2022 debug_target
.to_create_inferior (exec_file
, args
, env
);
2024 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx)\n",
2029 debug_to_post_startup_inferior (ptid_t ptid
)
2031 debug_target
.to_post_startup_inferior (ptid
);
2033 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
2038 debug_to_acknowledge_created_inferior (int pid
)
2040 debug_target
.to_acknowledge_created_inferior (pid
);
2042 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
2047 debug_to_insert_fork_catchpoint (int pid
)
2051 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
2053 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
2060 debug_to_remove_fork_catchpoint (int pid
)
2064 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
2066 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
2073 debug_to_insert_vfork_catchpoint (int pid
)
2077 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
2079 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)= %d\n",
2086 debug_to_remove_vfork_catchpoint (int pid
)
2090 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
2092 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
2099 debug_to_follow_fork (int follow_child
)
2101 int retval
= debug_target
.to_follow_fork (follow_child
);
2103 fprintf_unfiltered (gdb_stdlog
, "target_follow_fork (%d) = %d\n",
2104 follow_child
, retval
);
2110 debug_to_insert_exec_catchpoint (int pid
)
2114 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
2116 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
2123 debug_to_remove_exec_catchpoint (int pid
)
2127 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
2129 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2136 debug_to_reported_exec_events_per_exec_call (void)
2138 int reported_exec_events
;
2140 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2142 fprintf_unfiltered (gdb_stdlog
,
2143 "target_reported_exec_events_per_exec_call () = %d\n",
2144 reported_exec_events
);
2146 return reported_exec_events
;
2150 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
2154 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2156 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2157 pid
, wait_status
, *exit_status
, has_exited
);
2163 debug_to_mourn_inferior (void)
2165 debug_target
.to_mourn_inferior ();
2167 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2171 debug_to_can_run (void)
2175 retval
= debug_target
.to_can_run ();
2177 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2183 debug_to_notice_signals (ptid_t ptid
)
2185 debug_target
.to_notice_signals (ptid
);
2187 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n",
2192 debug_to_thread_alive (ptid_t ptid
)
2196 retval
= debug_target
.to_thread_alive (ptid
);
2198 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2199 PIDGET (ptid
), retval
);
2205 debug_to_find_new_threads (void)
2207 debug_target
.to_find_new_threads ();
2209 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog
);
2213 debug_to_stop (void)
2215 debug_target
.to_stop ();
2217 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2221 debug_to_read_partial (struct target_ops
*ops
,
2222 enum target_object object
,
2223 const char *annex
, void *buf
,
2224 ULONGEST offset
, LONGEST len
)
2228 retval
= target_read_partial (&debug_target
, object
, annex
, buf
, offset
,
2231 fprintf_unfiltered (gdb_stdlog
,
2232 "target_read_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n",
2233 (int) object
, (annex
? annex
: "(null)"),
2234 (long) buf
, paddr_nz (offset
),
2235 paddr_d (len
), paddr_d (retval
));
2241 debug_to_write_partial (struct target_ops
*ops
,
2242 enum target_object object
,
2243 const char *annex
, const void *buf
,
2244 ULONGEST offset
, LONGEST len
)
2248 retval
= target_write_partial (&debug_target
, object
, annex
, buf
, offset
,
2251 fprintf_unfiltered (gdb_stdlog
,
2252 "target_write_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n",
2253 (int) object
, (annex
? annex
: "(null)"),
2254 (long) buf
, paddr_nz (offset
),
2255 paddr_d (len
), paddr_d (retval
));
2261 debug_to_rcmd (char *command
,
2262 struct ui_file
*outbuf
)
2264 debug_target
.to_rcmd (command
, outbuf
);
2265 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2268 static struct symtab_and_line
*
2269 debug_to_enable_exception_callback (enum exception_event_kind kind
, int enable
)
2271 struct symtab_and_line
*result
;
2272 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2273 fprintf_unfiltered (gdb_stdlog
,
2274 "target get_exception_callback_sal (%d, %d)\n",
2279 static struct exception_event_record
*
2280 debug_to_get_current_exception_event (void)
2282 struct exception_event_record
*result
;
2283 result
= debug_target
.to_get_current_exception_event ();
2284 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2289 debug_to_pid_to_exec_file (int pid
)
2293 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2295 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2302 setup_target_debug (void)
2304 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2306 current_target
.to_open
= debug_to_open
;
2307 current_target
.to_close
= debug_to_close
;
2308 current_target
.to_attach
= debug_to_attach
;
2309 current_target
.to_post_attach
= debug_to_post_attach
;
2310 current_target
.to_detach
= debug_to_detach
;
2311 current_target
.to_disconnect
= debug_to_disconnect
;
2312 current_target
.to_resume
= debug_to_resume
;
2313 current_target
.to_wait
= debug_to_wait
;
2314 current_target
.to_post_wait
= debug_to_post_wait
;
2315 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2316 current_target
.to_store_registers
= debug_to_store_registers
;
2317 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2318 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2319 current_target
.to_files_info
= debug_to_files_info
;
2320 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2321 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2322 current_target
.to_can_use_hw_breakpoint
= debug_to_can_use_hw_breakpoint
;
2323 current_target
.to_insert_hw_breakpoint
= debug_to_insert_hw_breakpoint
;
2324 current_target
.to_remove_hw_breakpoint
= debug_to_remove_hw_breakpoint
;
2325 current_target
.to_insert_watchpoint
= debug_to_insert_watchpoint
;
2326 current_target
.to_remove_watchpoint
= debug_to_remove_watchpoint
;
2327 current_target
.to_stopped_by_watchpoint
= debug_to_stopped_by_watchpoint
;
2328 current_target
.to_stopped_data_address
= debug_to_stopped_data_address
;
2329 current_target
.to_region_size_ok_for_hw_watchpoint
= debug_to_region_size_ok_for_hw_watchpoint
;
2330 current_target
.to_terminal_init
= debug_to_terminal_init
;
2331 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2332 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2333 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2334 current_target
.to_terminal_save_ours
= debug_to_terminal_save_ours
;
2335 current_target
.to_terminal_info
= debug_to_terminal_info
;
2336 current_target
.to_kill
= debug_to_kill
;
2337 current_target
.to_load
= debug_to_load
;
2338 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2339 current_target
.to_create_inferior
= debug_to_create_inferior
;
2340 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2341 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2342 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2343 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2344 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2345 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2346 current_target
.to_follow_fork
= debug_to_follow_fork
;
2347 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2348 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2349 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2350 current_target
.to_has_exited
= debug_to_has_exited
;
2351 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2352 current_target
.to_can_run
= debug_to_can_run
;
2353 current_target
.to_notice_signals
= debug_to_notice_signals
;
2354 current_target
.to_thread_alive
= debug_to_thread_alive
;
2355 current_target
.to_find_new_threads
= debug_to_find_new_threads
;
2356 current_target
.to_stop
= debug_to_stop
;
2357 current_target
.to_read_partial
= debug_to_read_partial
;
2358 current_target
.to_write_partial
= debug_to_write_partial
;
2359 current_target
.to_rcmd
= debug_to_rcmd
;
2360 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
2361 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
2362 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2367 static char targ_desc
[] =
2368 "Names of targets and files being debugged.\n\
2369 Shows the entire stack of targets currently in use (including the exec-file,\n\
2370 core-file, and process, if any), as well as the symbol file name.";
2373 do_monitor_command (char *cmd
,
2376 if ((current_target
.to_rcmd
2377 == (void (*) (char *, struct ui_file
*)) tcomplain
)
2378 || (current_target
.to_rcmd
== debug_to_rcmd
2379 && (debug_target
.to_rcmd
2380 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
2382 error ("\"monitor\" command not supported by this target.\n");
2384 target_rcmd (cmd
, gdb_stdtarg
);
2388 initialize_targets (void)
2390 init_dummy_target ();
2391 push_target (&dummy_target
);
2393 add_info ("target", target_info
, targ_desc
);
2394 add_info ("files", target_info
, targ_desc
);
2397 (add_set_cmd ("target", class_maintenance
, var_zinteger
,
2398 (char *) &targetdebug
,
2399 "Set target debugging.\n\
2400 When non-zero, target debugging is enabled.", &setdebuglist
),
2403 add_setshow_boolean_cmd ("trust-readonly-sections", class_support
,
2405 Set mode for reading from readonly sections.\n\
2406 When this mode is on, memory reads from readonly sections (such as .text)\n\
2407 will be read from the object file instead of from the target. This will\n\
2408 result in significant performance improvement for remote targets.", "\
2409 Show mode for reading from readonly sections.\n",
2411 &setlist
, &showlist
);
2413 add_com ("monitor", class_obscure
, do_monitor_command
,
2414 "Send a command to the remote monitor (remote targets only).");
2416 target_dcache
= dcache_init ();