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
;
675 target_close (tmp
, 0);
678 /* We have removed all targets in our stratum, now add the new one. */
682 update_current_target ();
685 setup_target_debug ();
688 return (t
!= target_stack
);
691 /* Remove a target_ops vector from the stack, wherever it may be.
692 Return how many times it was removed (0 or 1). */
695 unpush_target (struct target_ops
*t
)
697 struct target_ops
**cur
;
698 struct target_ops
*tmp
;
702 /* Look for the specified target. Note that we assume that a target
703 can only occur once in the target stack. */
705 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
712 return 0; /* Didn't find target_ops, quit now */
714 /* Unchain the target */
716 (*cur
) = (*cur
)->beneath
;
719 update_current_target ();
727 target_close (¤t_target
, 0); /* Let it clean up */
728 if (unpush_target (target_stack
) == 1)
731 fprintf_unfiltered (gdb_stderr
,
732 "pop_target couldn't find target %s\n",
733 current_target
.to_shortname
);
734 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
738 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
740 /* target_read_string -- read a null terminated string, up to LEN bytes,
741 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
742 Set *STRING to a pointer to malloc'd memory containing the data; the caller
743 is responsible for freeing it. Return the number of bytes successfully
747 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
749 int tlen
, origlen
, offset
, i
;
753 int buffer_allocated
;
755 unsigned int nbytes_read
= 0;
757 /* Small for testing. */
758 buffer_allocated
= 4;
759 buffer
= xmalloc (buffer_allocated
);
766 tlen
= MIN (len
, 4 - (memaddr
& 3));
767 offset
= memaddr
& 3;
769 errcode
= target_xfer_memory (memaddr
& ~3, buf
, 4, 0);
772 /* The transfer request might have crossed the boundary to an
773 unallocated region of memory. Retry the transfer, requesting
777 errcode
= target_xfer_memory (memaddr
, buf
, 1, 0);
782 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
785 bytes
= bufptr
- buffer
;
786 buffer_allocated
*= 2;
787 buffer
= xrealloc (buffer
, buffer_allocated
);
788 bufptr
= buffer
+ bytes
;
791 for (i
= 0; i
< tlen
; i
++)
793 *bufptr
++ = buf
[i
+ offset
];
794 if (buf
[i
+ offset
] == '\000')
796 nbytes_read
+= i
+ 1;
813 /* Find a section containing ADDR. */
814 struct section_table
*
815 target_section_by_addr (struct target_ops
*target
, CORE_ADDR addr
)
817 struct section_table
*secp
;
818 for (secp
= target
->to_sections
;
819 secp
< target
->to_sections_end
;
822 if (addr
>= secp
->addr
&& addr
< secp
->endaddr
)
828 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
829 GDB's memory at MYADDR. Returns either 0 for success or an errno value
832 If an error occurs, no guarantee is made about the contents of the data at
833 MYADDR. In particular, the caller should not depend upon partial reads
834 filling the buffer with good data. There is no way for the caller to know
835 how much good data might have been transfered anyway. Callers that can
836 deal with partial reads should call target_read_memory_partial. */
839 target_read_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
841 return target_xfer_memory (memaddr
, myaddr
, len
, 0);
845 target_write_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
847 return target_xfer_memory (memaddr
, myaddr
, len
, 1);
850 static int trust_readonly
= 0;
852 /* Move memory to or from the targets. The top target gets priority;
853 if it cannot handle it, it is offered to the next one down, etc.
855 Result is -1 on error, or the number of bytes transfered. */
858 do_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
859 struct mem_attrib
*attrib
)
863 struct target_ops
*t
;
865 /* Zero length requests are ok and require no work. */
869 /* to_xfer_memory is not guaranteed to set errno, even when it returns
873 if (!write
&& trust_readonly
)
875 struct section_table
*secp
;
876 /* User-settable option, "trust-readonly-sections". If true,
877 then memory from any SEC_READONLY bfd section may be read
878 directly from the bfd file. */
879 secp
= target_section_by_addr (¤t_target
, memaddr
);
881 && (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
883 return xfer_memory (memaddr
, myaddr
, len
, 0, attrib
, ¤t_target
);
886 /* The quick case is that the top target can handle the transfer. */
887 res
= current_target
.to_xfer_memory
888 (memaddr
, myaddr
, len
, write
, attrib
, ¤t_target
);
890 /* If res <= 0 then we call it again in the loop. Ah well. */
893 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
895 if (!t
->to_has_memory
)
898 res
= t
->to_xfer_memory (memaddr
, myaddr
, len
, write
, attrib
, t
);
900 break; /* Handled all or part of xfer */
901 if (t
->to_has_all_memory
)
913 /* Perform a memory transfer. Iterate until the entire region has
916 Result is 0 or errno value. */
919 target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
)
923 struct mem_region
*region
;
925 /* Zero length requests are ok and require no work. */
933 region
= lookup_mem_region(memaddr
);
934 if (memaddr
+ len
< region
->hi
)
937 reg_len
= region
->hi
- memaddr
;
939 switch (region
->attrib
.mode
)
954 if (region
->attrib
.cache
)
955 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
,
958 res
= do_xfer_memory (memaddr
, myaddr
, reg_len
, write
,
963 /* If this address is for nonexistent memory, read zeros
964 if reading, or do nothing if writing. Return
967 memset (myaddr
, 0, len
);
981 return 0; /* We managed to cover it all somehow. */
985 /* Perform a partial memory transfer.
987 Result is -1 on error, or the number of bytes transfered. */
990 target_xfer_memory_partial (CORE_ADDR memaddr
, char *myaddr
, int len
,
991 int write_p
, int *err
)
995 struct mem_region
*region
;
997 /* Zero length requests are ok and require no work. */
1004 region
= lookup_mem_region(memaddr
);
1005 if (memaddr
+ len
< region
->hi
)
1008 reg_len
= region
->hi
- memaddr
;
1010 switch (region
->attrib
.mode
)
1029 if (region
->attrib
.cache
)
1030 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
,
1033 res
= do_xfer_memory (memaddr
, myaddr
, reg_len
, write_p
,
1051 target_read_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1053 return target_xfer_memory_partial (memaddr
, buf
, len
, 0, err
);
1057 target_write_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1059 return target_xfer_memory_partial (memaddr
, buf
, len
, 1, err
);
1062 /* More generic transfers. */
1065 target_read_partial (struct target_ops
*ops
,
1066 enum target_object object
,
1067 const char *annex
, void *buf
,
1068 ULONGEST offset
, LONGEST len
)
1070 struct target_ops
*op
;
1072 /* Find the first target stratum that can handle the request. */
1074 op
!= NULL
&& op
->to_read_partial
== NULL
;
1080 /* Now apply the operation at that level. */
1081 return op
->to_read_partial (op
, object
, annex
, buf
, offset
, len
);
1085 target_write_partial (struct target_ops
*ops
,
1086 enum target_object object
,
1087 const char *annex
, const void *buf
,
1088 ULONGEST offset
, LONGEST len
)
1090 struct target_ops
*op
;
1092 /* Find the first target stratum that can handle the request. */
1094 op
!= NULL
&& op
->to_write_partial
== NULL
;
1100 return op
->to_write_partial (op
, object
, annex
, buf
, offset
, len
);
1103 /* Wrappers to perform the full transfer. */
1105 target_read (struct target_ops
*ops
,
1106 enum target_object object
,
1107 const char *annex
, void *buf
,
1108 ULONGEST offset
, LONGEST len
)
1111 while (xfered
< len
)
1113 LONGEST xfer
= target_write_partial (ops
, object
, annex
,
1114 (bfd_byte
*) buf
+ xfered
,
1115 offset
+ xfered
, len
- xfered
);
1116 /* Call an observer, notifying them of the xfer progress? */
1126 target_write (struct target_ops
*ops
,
1127 enum target_object object
,
1128 const char *annex
, const void *buf
,
1129 ULONGEST offset
, LONGEST len
)
1132 while (xfered
< len
)
1134 LONGEST xfer
= target_write_partial (ops
, object
, annex
,
1135 (bfd_byte
*) buf
+ xfered
,
1136 offset
+ xfered
, len
- xfered
);
1137 /* Call an observer, notifying them of the xfer progress? */
1147 target_info (char *args
, int from_tty
)
1149 struct target_ops
*t
;
1150 int has_all_mem
= 0;
1152 if (symfile_objfile
!= NULL
)
1153 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
1155 #ifdef FILES_INFO_HOOK
1156 if (FILES_INFO_HOOK ())
1160 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
1162 if (!t
->to_has_memory
)
1165 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
1168 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1169 printf_unfiltered ("%s:\n", t
->to_longname
);
1170 (t
->to_files_info
) (t
);
1171 has_all_mem
= t
->to_has_all_memory
;
1175 /* This is to be called by the open routine before it does
1179 target_preopen (int from_tty
)
1183 if (target_has_execution
)
1186 || query ("A program is being debugged already. Kill it? "))
1189 error ("Program not killed.");
1192 /* Calling target_kill may remove the target from the stack. But if
1193 it doesn't (which seems like a win for UDI), remove it now. */
1195 if (target_has_execution
)
1199 /* Detach a target after doing deferred register stores. */
1202 target_detach (char *args
, int from_tty
)
1204 /* Handle any optimized stores to the inferior. */
1205 #ifdef DO_DEFERRED_STORES
1208 (current_target
.to_detach
) (args
, from_tty
);
1212 target_disconnect (char *args
, int from_tty
)
1214 /* Handle any optimized stores to the inferior. */
1215 #ifdef DO_DEFERRED_STORES
1218 (current_target
.to_disconnect
) (args
, from_tty
);
1222 target_link (char *modname
, CORE_ADDR
*t_reloc
)
1224 if (STREQ (current_target
.to_shortname
, "rombug"))
1226 (current_target
.to_lookup_symbol
) (modname
, t_reloc
);
1228 error ("Unable to link to %s and get relocation in rombug", modname
);
1231 *t_reloc
= (CORE_ADDR
) -1;
1235 target_async_mask (int mask
)
1237 int saved_async_masked_status
= target_async_mask_value
;
1238 target_async_mask_value
= mask
;
1239 return saved_async_masked_status
;
1242 /* Look through the list of possible targets for a target that can
1243 execute a run or attach command without any other data. This is
1244 used to locate the default process stratum.
1246 Result is always valid (error() is called for errors). */
1248 static struct target_ops
*
1249 find_default_run_target (char *do_mesg
)
1251 struct target_ops
**t
;
1252 struct target_ops
*runable
= NULL
;
1257 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1260 if ((*t
)->to_can_run
&& target_can_run (*t
))
1268 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
1274 find_default_attach (char *args
, int from_tty
)
1276 struct target_ops
*t
;
1278 t
= find_default_run_target ("attach");
1279 (t
->to_attach
) (args
, from_tty
);
1284 find_default_create_inferior (char *exec_file
, char *allargs
, char **env
)
1286 struct target_ops
*t
;
1288 t
= find_default_run_target ("run");
1289 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
1294 default_region_size_ok_for_hw_watchpoint (int byte_count
)
1296 return (byte_count
<= DEPRECATED_REGISTER_SIZE
);
1312 return_minus_one (void)
1318 * Resize the to_sections pointer. Also make sure that anyone that
1319 * was holding on to an old value of it gets updated.
1320 * Returns the old size.
1324 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1326 struct target_ops
**t
;
1327 struct section_table
*old_value
;
1330 old_value
= target
->to_sections
;
1332 if (target
->to_sections
)
1334 old_count
= target
->to_sections_end
- target
->to_sections
;
1335 target
->to_sections
= (struct section_table
*)
1336 xrealloc ((char *) target
->to_sections
,
1337 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1342 target
->to_sections
= (struct section_table
*)
1343 xmalloc ((sizeof (struct section_table
)) * num_added
);
1345 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1347 /* Check to see if anyone else was pointing to this structure.
1348 If old_value was null, then no one was. */
1352 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1355 if ((*t
)->to_sections
== old_value
)
1357 (*t
)->to_sections
= target
->to_sections
;
1358 (*t
)->to_sections_end
= target
->to_sections_end
;
1367 /* Remove all target sections taken from ABFD.
1369 Scan the current target stack for targets whose section tables
1370 refer to sections from BFD, and remove those sections. We use this
1371 when we notice that the inferior has unloaded a shared object, for
1374 remove_target_sections (bfd
*abfd
)
1376 struct target_ops
**t
;
1378 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; t
++)
1380 struct section_table
*src
, *dest
;
1382 dest
= (*t
)->to_sections
;
1383 for (src
= (*t
)->to_sections
; src
< (*t
)->to_sections_end
; src
++)
1384 if (src
->bfd
!= abfd
)
1386 /* Keep this section. */
1387 if (dest
< src
) *dest
= *src
;
1391 /* If we've dropped any sections, resize the section table. */
1393 target_resize_to_sections (*t
, dest
- src
);
1400 /* Find a single runnable target in the stack and return it. If for
1401 some reason there is more than one, return NULL. */
1404 find_run_target (void)
1406 struct target_ops
**t
;
1407 struct target_ops
*runable
= NULL
;
1412 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1414 if ((*t
)->to_can_run
&& target_can_run (*t
))
1421 return (count
== 1 ? runable
: NULL
);
1424 /* Find a single core_stratum target in the list of targets and return it.
1425 If for some reason there is more than one, return NULL. */
1428 find_core_target (void)
1430 struct target_ops
**t
;
1431 struct target_ops
*runable
= NULL
;
1436 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1439 if ((*t
)->to_stratum
== core_stratum
)
1446 return (count
== 1 ? runable
: NULL
);
1450 * Find the next target down the stack from the specified target.
1454 find_target_beneath (struct target_ops
*t
)
1460 /* The inferior process has died. Long live the inferior! */
1463 generic_mourn_inferior (void)
1465 extern int show_breakpoint_hit_counts
;
1467 inferior_ptid
= null_ptid
;
1469 breakpoint_init_inferior (inf_exited
);
1470 registers_changed ();
1472 #ifdef CLEAR_DEFERRED_STORES
1473 /* Delete any pending stores to the inferior... */
1474 CLEAR_DEFERRED_STORES
;
1477 reopen_exec_file ();
1478 reinit_frame_cache ();
1480 /* It is confusing to the user for ignore counts to stick around
1481 from previous runs of the inferior. So clear them. */
1482 /* However, it is more confusing for the ignore counts to disappear when
1483 using hit counts. So don't clear them if we're counting hits. */
1484 if (!show_breakpoint_hit_counts
)
1485 breakpoint_clear_ignore_counts ();
1491 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1492 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1493 translation of that in OURSTATUS. */
1495 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
1497 #ifdef CHILD_SPECIAL_WAITSTATUS
1498 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1499 if it wants to deal with hoststatus. */
1500 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
1504 if (WIFEXITED (hoststatus
))
1506 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1507 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
1509 else if (!WIFSTOPPED (hoststatus
))
1511 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1512 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
1516 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
1517 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
1521 /* Returns zero to leave the inferior alone, one to interrupt it. */
1522 int (*target_activity_function
) (void);
1523 int target_activity_fd
;
1525 /* Convert a normal process ID to a string. Returns the string in a static
1529 normal_pid_to_str (ptid_t ptid
)
1531 static char buf
[30];
1533 sprintf (buf
, "process %d", PIDGET (ptid
));
1537 /* Some targets (such as ttrace-based HPUX) don't allow us to request
1538 notification of inferior events such as fork and vork immediately
1539 after the inferior is created. (This because of how gdb gets an
1540 inferior created via invoking a shell to do it. In such a scenario,
1541 if the shell init file has commands in it, the shell will fork and
1542 exec for each of those commands, and we will see each such fork
1545 This function is used by all targets that allow us to request
1546 notification of forks, etc at inferior creation time; e.g., in
1547 target_acknowledge_forked_child.
1550 normal_target_post_startup_inferior (ptid_t ptid
)
1552 /* This space intentionally left blank. */
1555 /* Error-catcher for target_find_memory_regions */
1556 static int dummy_find_memory_regions (int (*ignore1
) (), void *ignore2
)
1558 error ("No target.");
1562 /* Error-catcher for target_make_corefile_notes */
1563 static char * dummy_make_corefile_notes (bfd
*ignore1
, int *ignore2
)
1565 error ("No target.");
1569 /* Set up the handful of non-empty slots needed by the dummy target
1573 init_dummy_target (void)
1575 dummy_target
.to_shortname
= "None";
1576 dummy_target
.to_longname
= "None";
1577 dummy_target
.to_doc
= "";
1578 dummy_target
.to_attach
= find_default_attach
;
1579 dummy_target
.to_create_inferior
= find_default_create_inferior
;
1580 dummy_target
.to_pid_to_str
= normal_pid_to_str
;
1581 dummy_target
.to_stratum
= dummy_stratum
;
1582 dummy_target
.to_find_memory_regions
= dummy_find_memory_regions
;
1583 dummy_target
.to_make_corefile_notes
= dummy_make_corefile_notes
;
1584 dummy_target
.to_magic
= OPS_MAGIC
;
1588 static struct target_ops debug_target
;
1591 debug_to_open (char *args
, int from_tty
)
1593 debug_target
.to_open (args
, from_tty
);
1595 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
1599 debug_to_close (int quitting
)
1601 target_close (&debug_target
, quitting
);
1602 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
1606 target_close (struct target_ops
*targ
, int quitting
)
1608 if (targ
->to_xclose
!= NULL
)
1609 targ
->to_xclose (targ
, quitting
);
1610 else if (targ
->to_close
!= NULL
)
1611 targ
->to_close (quitting
);
1615 debug_to_attach (char *args
, int from_tty
)
1617 debug_target
.to_attach (args
, from_tty
);
1619 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
1624 debug_to_post_attach (int pid
)
1626 debug_target
.to_post_attach (pid
);
1628 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
1632 debug_to_detach (char *args
, int from_tty
)
1634 debug_target
.to_detach (args
, from_tty
);
1636 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
1640 debug_to_disconnect (char *args
, int from_tty
)
1642 debug_target
.to_disconnect (args
, from_tty
);
1644 fprintf_unfiltered (gdb_stdlog
, "target_disconnect (%s, %d)\n",
1649 debug_to_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
1651 debug_target
.to_resume (ptid
, step
, siggnal
);
1653 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", PIDGET (ptid
),
1654 step
? "step" : "continue",
1655 target_signal_to_name (siggnal
));
1659 debug_to_wait (ptid_t ptid
, struct target_waitstatus
*status
)
1663 retval
= debug_target
.to_wait (ptid
, status
);
1665 fprintf_unfiltered (gdb_stdlog
,
1666 "target_wait (%d, status) = %d, ", PIDGET (ptid
),
1668 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
1669 switch (status
->kind
)
1671 case TARGET_WAITKIND_EXITED
:
1672 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
1673 status
->value
.integer
);
1675 case TARGET_WAITKIND_STOPPED
:
1676 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
1677 target_signal_to_name (status
->value
.sig
));
1679 case TARGET_WAITKIND_SIGNALLED
:
1680 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
1681 target_signal_to_name (status
->value
.sig
));
1683 case TARGET_WAITKIND_LOADED
:
1684 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
1686 case TARGET_WAITKIND_FORKED
:
1687 fprintf_unfiltered (gdb_stdlog
, "forked\n");
1689 case TARGET_WAITKIND_VFORKED
:
1690 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
1692 case TARGET_WAITKIND_EXECD
:
1693 fprintf_unfiltered (gdb_stdlog
, "execd\n");
1695 case TARGET_WAITKIND_SPURIOUS
:
1696 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
1699 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
1707 debug_to_post_wait (ptid_t ptid
, int status
)
1709 debug_target
.to_post_wait (ptid
, status
);
1711 fprintf_unfiltered (gdb_stdlog
, "target_post_wait (%d, %d)\n",
1712 PIDGET (ptid
), status
);
1716 debug_print_register (const char * func
, int regno
)
1718 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
1719 if (regno
>= 0 && regno
< NUM_REGS
+ NUM_PSEUDO_REGS
1720 && REGISTER_NAME (regno
) != NULL
&& REGISTER_NAME (regno
)[0] != '\0')
1721 fprintf_unfiltered (gdb_stdlog
, "(%s)", REGISTER_NAME (regno
));
1723 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
1727 unsigned char buf
[MAX_REGISTER_SIZE
];
1728 deprecated_read_register_gen (regno
, buf
);
1729 fprintf_unfiltered (gdb_stdlog
, " = ");
1730 for (i
= 0; i
< DEPRECATED_REGISTER_RAW_SIZE (regno
); i
++)
1732 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
1734 if (DEPRECATED_REGISTER_RAW_SIZE (regno
) <= sizeof (LONGEST
))
1736 fprintf_unfiltered (gdb_stdlog
, " 0x%s %s",
1737 paddr_nz (read_register (regno
)),
1738 paddr_d (read_register (regno
)));
1741 fprintf_unfiltered (gdb_stdlog
, "\n");
1745 debug_to_fetch_registers (int regno
)
1747 debug_target
.to_fetch_registers (regno
);
1748 debug_print_register ("target_fetch_registers", regno
);
1752 debug_to_store_registers (int regno
)
1754 debug_target
.to_store_registers (regno
);
1755 debug_print_register ("target_store_registers", regno
);
1756 fprintf_unfiltered (gdb_stdlog
, "\n");
1760 debug_to_prepare_to_store (void)
1762 debug_target
.to_prepare_to_store ();
1764 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
1768 debug_to_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
1769 struct mem_attrib
*attrib
,
1770 struct target_ops
*target
)
1774 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
,
1777 fprintf_unfiltered (gdb_stdlog
,
1778 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
1779 (unsigned int) memaddr
, /* possable truncate long long */
1780 len
, write
? "write" : "read", retval
);
1788 fputs_unfiltered (", bytes =", gdb_stdlog
);
1789 for (i
= 0; i
< retval
; i
++)
1791 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
1792 fprintf_unfiltered (gdb_stdlog
, "\n");
1793 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1797 fputc_unfiltered ('\n', gdb_stdlog
);
1803 debug_to_files_info (struct target_ops
*target
)
1805 debug_target
.to_files_info (target
);
1807 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
1811 debug_to_insert_breakpoint (CORE_ADDR addr
, char *save
)
1815 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
1817 fprintf_unfiltered (gdb_stdlog
,
1818 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
1819 (unsigned long) addr
,
1820 (unsigned long) retval
);
1825 debug_to_remove_breakpoint (CORE_ADDR addr
, char *save
)
1829 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
1831 fprintf_unfiltered (gdb_stdlog
,
1832 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
1833 (unsigned long) addr
,
1834 (unsigned long) retval
);
1839 debug_to_can_use_hw_breakpoint (int type
, int cnt
, int from_tty
)
1843 retval
= debug_target
.to_can_use_hw_breakpoint (type
, cnt
, from_tty
);
1845 fprintf_unfiltered (gdb_stdlog
,
1846 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
1847 (unsigned long) type
,
1848 (unsigned long) cnt
,
1849 (unsigned long) from_tty
,
1850 (unsigned long) retval
);
1855 debug_to_region_size_ok_for_hw_watchpoint (int byte_count
)
1859 retval
= debug_target
.to_region_size_ok_for_hw_watchpoint (byte_count
);
1861 fprintf_unfiltered (gdb_stdlog
,
1862 "TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT (%ld) = 0x%lx\n",
1863 (unsigned long) byte_count
,
1864 (unsigned long) retval
);
1869 debug_to_stopped_by_watchpoint (void)
1873 retval
= debug_target
.to_stopped_by_watchpoint ();
1875 fprintf_unfiltered (gdb_stdlog
,
1876 "STOPPED_BY_WATCHPOINT () = %ld\n",
1877 (unsigned long) retval
);
1882 debug_to_stopped_data_address (void)
1886 retval
= debug_target
.to_stopped_data_address ();
1888 fprintf_unfiltered (gdb_stdlog
,
1889 "target_stopped_data_address () = 0x%lx\n",
1890 (unsigned long) retval
);
1895 debug_to_insert_hw_breakpoint (CORE_ADDR addr
, char *save
)
1899 retval
= debug_target
.to_insert_hw_breakpoint (addr
, save
);
1901 fprintf_unfiltered (gdb_stdlog
,
1902 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
1903 (unsigned long) addr
,
1904 (unsigned long) retval
);
1909 debug_to_remove_hw_breakpoint (CORE_ADDR addr
, char *save
)
1913 retval
= debug_target
.to_remove_hw_breakpoint (addr
, save
);
1915 fprintf_unfiltered (gdb_stdlog
,
1916 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
1917 (unsigned long) addr
,
1918 (unsigned long) retval
);
1923 debug_to_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
1927 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
1929 fprintf_unfiltered (gdb_stdlog
,
1930 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1931 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
1936 debug_to_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
1940 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
1942 fprintf_unfiltered (gdb_stdlog
,
1943 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1944 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
1949 debug_to_terminal_init (void)
1951 debug_target
.to_terminal_init ();
1953 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
1957 debug_to_terminal_inferior (void)
1959 debug_target
.to_terminal_inferior ();
1961 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
1965 debug_to_terminal_ours_for_output (void)
1967 debug_target
.to_terminal_ours_for_output ();
1969 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
1973 debug_to_terminal_ours (void)
1975 debug_target
.to_terminal_ours ();
1977 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
1981 debug_to_terminal_save_ours (void)
1983 debug_target
.to_terminal_save_ours ();
1985 fprintf_unfiltered (gdb_stdlog
, "target_terminal_save_ours ()\n");
1989 debug_to_terminal_info (char *arg
, int from_tty
)
1991 debug_target
.to_terminal_info (arg
, from_tty
);
1993 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
1998 debug_to_kill (void)
2000 debug_target
.to_kill ();
2002 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
2006 debug_to_load (char *args
, int from_tty
)
2008 debug_target
.to_load (args
, from_tty
);
2010 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
2014 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
2018 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
2020 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
2026 debug_to_create_inferior (char *exec_file
, char *args
, char **env
)
2028 debug_target
.to_create_inferior (exec_file
, args
, env
);
2030 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx)\n",
2035 debug_to_post_startup_inferior (ptid_t ptid
)
2037 debug_target
.to_post_startup_inferior (ptid
);
2039 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
2044 debug_to_acknowledge_created_inferior (int pid
)
2046 debug_target
.to_acknowledge_created_inferior (pid
);
2048 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
2053 debug_to_insert_fork_catchpoint (int pid
)
2057 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
2059 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
2066 debug_to_remove_fork_catchpoint (int pid
)
2070 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
2072 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
2079 debug_to_insert_vfork_catchpoint (int pid
)
2083 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
2085 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)= %d\n",
2092 debug_to_remove_vfork_catchpoint (int pid
)
2096 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
2098 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
2105 debug_to_follow_fork (int follow_child
)
2107 int retval
= debug_target
.to_follow_fork (follow_child
);
2109 fprintf_unfiltered (gdb_stdlog
, "target_follow_fork (%d) = %d\n",
2110 follow_child
, retval
);
2116 debug_to_insert_exec_catchpoint (int pid
)
2120 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
2122 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
2129 debug_to_remove_exec_catchpoint (int pid
)
2133 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
2135 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2142 debug_to_reported_exec_events_per_exec_call (void)
2144 int reported_exec_events
;
2146 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2148 fprintf_unfiltered (gdb_stdlog
,
2149 "target_reported_exec_events_per_exec_call () = %d\n",
2150 reported_exec_events
);
2152 return reported_exec_events
;
2156 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
2160 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2162 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2163 pid
, wait_status
, *exit_status
, has_exited
);
2169 debug_to_mourn_inferior (void)
2171 debug_target
.to_mourn_inferior ();
2173 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2177 debug_to_can_run (void)
2181 retval
= debug_target
.to_can_run ();
2183 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2189 debug_to_notice_signals (ptid_t ptid
)
2191 debug_target
.to_notice_signals (ptid
);
2193 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n",
2198 debug_to_thread_alive (ptid_t ptid
)
2202 retval
= debug_target
.to_thread_alive (ptid
);
2204 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2205 PIDGET (ptid
), retval
);
2211 debug_to_find_new_threads (void)
2213 debug_target
.to_find_new_threads ();
2215 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog
);
2219 debug_to_stop (void)
2221 debug_target
.to_stop ();
2223 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2227 debug_to_read_partial (struct target_ops
*ops
,
2228 enum target_object object
,
2229 const char *annex
, void *buf
,
2230 ULONGEST offset
, LONGEST len
)
2234 retval
= target_read_partial (&debug_target
, object
, annex
, buf
, offset
,
2237 fprintf_unfiltered (gdb_stdlog
,
2238 "target_read_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n",
2239 (int) object
, (annex
? annex
: "(null)"),
2240 (long) buf
, paddr_nz (offset
),
2241 paddr_d (len
), paddr_d (retval
));
2247 debug_to_write_partial (struct target_ops
*ops
,
2248 enum target_object object
,
2249 const char *annex
, const void *buf
,
2250 ULONGEST offset
, LONGEST len
)
2254 retval
= target_write_partial (&debug_target
, object
, annex
, buf
, offset
,
2257 fprintf_unfiltered (gdb_stdlog
,
2258 "target_write_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n",
2259 (int) object
, (annex
? annex
: "(null)"),
2260 (long) buf
, paddr_nz (offset
),
2261 paddr_d (len
), paddr_d (retval
));
2267 debug_to_rcmd (char *command
,
2268 struct ui_file
*outbuf
)
2270 debug_target
.to_rcmd (command
, outbuf
);
2271 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2274 static struct symtab_and_line
*
2275 debug_to_enable_exception_callback (enum exception_event_kind kind
, int enable
)
2277 struct symtab_and_line
*result
;
2278 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2279 fprintf_unfiltered (gdb_stdlog
,
2280 "target get_exception_callback_sal (%d, %d)\n",
2285 static struct exception_event_record
*
2286 debug_to_get_current_exception_event (void)
2288 struct exception_event_record
*result
;
2289 result
= debug_target
.to_get_current_exception_event ();
2290 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2295 debug_to_pid_to_exec_file (int pid
)
2299 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2301 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2308 setup_target_debug (void)
2310 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2312 current_target
.to_open
= debug_to_open
;
2313 current_target
.to_close
= debug_to_close
;
2314 current_target
.to_attach
= debug_to_attach
;
2315 current_target
.to_post_attach
= debug_to_post_attach
;
2316 current_target
.to_detach
= debug_to_detach
;
2317 current_target
.to_disconnect
= debug_to_disconnect
;
2318 current_target
.to_resume
= debug_to_resume
;
2319 current_target
.to_wait
= debug_to_wait
;
2320 current_target
.to_post_wait
= debug_to_post_wait
;
2321 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2322 current_target
.to_store_registers
= debug_to_store_registers
;
2323 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2324 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2325 current_target
.to_files_info
= debug_to_files_info
;
2326 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2327 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2328 current_target
.to_can_use_hw_breakpoint
= debug_to_can_use_hw_breakpoint
;
2329 current_target
.to_insert_hw_breakpoint
= debug_to_insert_hw_breakpoint
;
2330 current_target
.to_remove_hw_breakpoint
= debug_to_remove_hw_breakpoint
;
2331 current_target
.to_insert_watchpoint
= debug_to_insert_watchpoint
;
2332 current_target
.to_remove_watchpoint
= debug_to_remove_watchpoint
;
2333 current_target
.to_stopped_by_watchpoint
= debug_to_stopped_by_watchpoint
;
2334 current_target
.to_stopped_data_address
= debug_to_stopped_data_address
;
2335 current_target
.to_region_size_ok_for_hw_watchpoint
= debug_to_region_size_ok_for_hw_watchpoint
;
2336 current_target
.to_terminal_init
= debug_to_terminal_init
;
2337 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2338 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2339 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2340 current_target
.to_terminal_save_ours
= debug_to_terminal_save_ours
;
2341 current_target
.to_terminal_info
= debug_to_terminal_info
;
2342 current_target
.to_kill
= debug_to_kill
;
2343 current_target
.to_load
= debug_to_load
;
2344 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2345 current_target
.to_create_inferior
= debug_to_create_inferior
;
2346 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2347 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2348 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2349 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2350 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2351 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2352 current_target
.to_follow_fork
= debug_to_follow_fork
;
2353 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2354 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2355 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2356 current_target
.to_has_exited
= debug_to_has_exited
;
2357 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2358 current_target
.to_can_run
= debug_to_can_run
;
2359 current_target
.to_notice_signals
= debug_to_notice_signals
;
2360 current_target
.to_thread_alive
= debug_to_thread_alive
;
2361 current_target
.to_find_new_threads
= debug_to_find_new_threads
;
2362 current_target
.to_stop
= debug_to_stop
;
2363 current_target
.to_read_partial
= debug_to_read_partial
;
2364 current_target
.to_write_partial
= debug_to_write_partial
;
2365 current_target
.to_rcmd
= debug_to_rcmd
;
2366 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
2367 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
2368 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2373 static char targ_desc
[] =
2374 "Names of targets and files being debugged.\n\
2375 Shows the entire stack of targets currently in use (including the exec-file,\n\
2376 core-file, and process, if any), as well as the symbol file name.";
2379 do_monitor_command (char *cmd
,
2382 if ((current_target
.to_rcmd
2383 == (void (*) (char *, struct ui_file
*)) tcomplain
)
2384 || (current_target
.to_rcmd
== debug_to_rcmd
2385 && (debug_target
.to_rcmd
2386 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
2388 error ("\"monitor\" command not supported by this target.\n");
2390 target_rcmd (cmd
, gdb_stdtarg
);
2394 initialize_targets (void)
2396 init_dummy_target ();
2397 push_target (&dummy_target
);
2399 add_info ("target", target_info
, targ_desc
);
2400 add_info ("files", target_info
, targ_desc
);
2403 (add_set_cmd ("target", class_maintenance
, var_zinteger
,
2404 (char *) &targetdebug
,
2405 "Set target debugging.\n\
2406 When non-zero, target debugging is enabled.", &setdebuglist
),
2409 add_setshow_boolean_cmd ("trust-readonly-sections", class_support
,
2411 Set mode for reading from readonly sections.\n\
2412 When this mode is on, memory reads from readonly sections (such as .text)\n\
2413 will be read from the object file instead of from the target. This will\n\
2414 result in significant performance improvement for remote targets.", "\
2415 Show mode for reading from readonly sections.\n",
2417 &setlist
, &showlist
);
2419 add_com ("monitor", class_obscure
, do_monitor_command
,
2420 "Send a command to the remote monitor (remote targets only).");
2422 target_dcache
= dcache_init ();