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"
39 #include "gdb_assert.h"
42 static void target_info (char *, int);
44 static void maybe_kill_then_create_inferior (char *, char *, char **);
46 static void maybe_kill_then_attach (char *, int);
48 static void kill_or_be_killed (int);
50 static void default_terminal_info (char *, int);
52 static int default_region_size_ok_for_hw_watchpoint (int);
54 static int nosymbol (char *, CORE_ADDR
*);
56 static void tcomplain (void);
58 static int nomemory (CORE_ADDR
, char *, int, int, struct target_ops
*);
60 static int return_zero (void);
62 static int return_one (void);
64 static int return_minus_one (void);
66 void target_ignore (void);
68 static void target_command (char *, int);
70 static struct target_ops
*find_default_run_target (char *);
72 static void nosupport_runtime (void);
74 static void normal_target_post_startup_inferior (ptid_t ptid
);
76 static LONGEST
default_read_partial (struct target_ops
*ops
,
77 enum target_object object
,
78 const char *annex
, void *buf
,
79 ULONGEST offset
, LONGEST len
);
80 static LONGEST
default_write_partial (struct target_ops
*ops
,
81 enum target_object object
,
82 const char *annex
, const void *buf
,
83 ULONGEST offset
, LONGEST len
);
85 /* Transfer LEN bytes between target address MEMADDR and GDB address
86 MYADDR. Returns 0 for success, errno code for failure (which
87 includes partial transfers -- if you want a more useful response to
88 partial transfers, try either target_read_memory_partial or
89 target_write_memory_partial). */
91 static int target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
,
94 static void init_dummy_target (void);
96 static void debug_to_open (char *, int);
98 static void debug_to_close (int);
100 static void debug_to_attach (char *, int);
102 static void debug_to_detach (char *, int);
104 static void debug_to_disconnect (char *, int);
106 static void debug_to_resume (ptid_t
, int, enum target_signal
);
108 static ptid_t
debug_to_wait (ptid_t
, struct target_waitstatus
*);
110 static void debug_to_fetch_registers (int);
112 static void debug_to_store_registers (int);
114 static void debug_to_prepare_to_store (void);
116 static int debug_to_xfer_memory (CORE_ADDR
, char *, int, int,
117 struct mem_attrib
*, struct target_ops
*);
119 static void debug_to_files_info (struct target_ops
*);
121 static int debug_to_insert_breakpoint (CORE_ADDR
, char *);
123 static int debug_to_remove_breakpoint (CORE_ADDR
, char *);
125 static int debug_to_can_use_hw_breakpoint (int, int, int);
127 static int debug_to_insert_hw_breakpoint (CORE_ADDR
, char *);
129 static int debug_to_remove_hw_breakpoint (CORE_ADDR
, char *);
131 static int debug_to_insert_watchpoint (CORE_ADDR
, int, int);
133 static int debug_to_remove_watchpoint (CORE_ADDR
, int, int);
135 static int debug_to_stopped_by_watchpoint (void);
137 static CORE_ADDR
debug_to_stopped_data_address (void);
139 static int debug_to_region_size_ok_for_hw_watchpoint (int);
141 static void debug_to_terminal_init (void);
143 static void debug_to_terminal_inferior (void);
145 static void debug_to_terminal_ours_for_output (void);
147 static void debug_to_terminal_save_ours (void);
149 static void debug_to_terminal_ours (void);
151 static void debug_to_terminal_info (char *, int);
153 static void debug_to_kill (void);
155 static void debug_to_load (char *, int);
157 static int debug_to_lookup_symbol (char *, CORE_ADDR
*);
159 static void debug_to_create_inferior (char *, char *, char **);
161 static void debug_to_mourn_inferior (void);
163 static int debug_to_can_run (void);
165 static void debug_to_notice_signals (ptid_t
);
167 static int debug_to_thread_alive (ptid_t
);
169 static void debug_to_stop (void);
171 /* Pointer to array of target architecture structures; the size of the
172 array; the current index into the array; the allocated size of the
174 struct target_ops
**target_structs
;
175 unsigned target_struct_size
;
176 unsigned target_struct_index
;
177 unsigned target_struct_allocsize
;
178 #define DEFAULT_ALLOCSIZE 10
180 /* The initial current target, so that there is always a semi-valid
183 static struct target_ops dummy_target
;
185 /* Top of target stack. */
187 static struct target_ops
*target_stack
;
189 /* The target structure we are currently using to talk to a process
190 or file or whatever "inferior" we have. */
192 struct target_ops current_target
;
194 /* Command list for target. */
196 static struct cmd_list_element
*targetlist
= NULL
;
198 /* Nonzero if we are debugging an attached outside process
199 rather than an inferior. */
203 /* Non-zero if we want to see trace of target level stuff. */
205 static int targetdebug
= 0;
207 static void setup_target_debug (void);
209 DCACHE
*target_dcache
;
211 /* The user just typed 'target' without the name of a target. */
214 target_command (char *arg
, int from_tty
)
216 fputs_filtered ("Argument required (target name). Try `help target'\n",
220 /* Add a possible target architecture to the list. */
223 add_target (struct target_ops
*t
)
225 /* Provide default values for all "must have" methods. */
226 t
->to_read_partial
= default_read_partial
;
227 t
->to_write_partial
= default_write_partial
;
231 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
232 target_structs
= (struct target_ops
**) xmalloc
233 (target_struct_allocsize
* sizeof (*target_structs
));
235 if (target_struct_size
>= target_struct_allocsize
)
237 target_struct_allocsize
*= 2;
238 target_structs
= (struct target_ops
**)
239 xrealloc ((char *) target_structs
,
240 target_struct_allocsize
* sizeof (*target_structs
));
242 target_structs
[target_struct_size
++] = t
;
244 if (targetlist
== NULL
)
245 add_prefix_cmd ("target", class_run
, target_command
,
246 "Connect to a target machine or process.\n\
247 The first argument is the type or protocol of the target machine.\n\
248 Remaining arguments are interpreted by the target protocol. For more\n\
249 information on the arguments for a particular protocol, type\n\
250 `help target ' followed by the protocol name.",
251 &targetlist
, "target ", 0, &cmdlist
);
252 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
263 target_load (char *arg
, int from_tty
)
265 dcache_invalidate (target_dcache
);
266 (*current_target
.to_load
) (arg
, from_tty
);
270 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
271 struct target_ops
*t
)
273 errno
= EIO
; /* Can't read/write this location */
274 return 0; /* No bytes handled */
280 error ("You can't do that when your target is `%s'",
281 current_target
.to_shortname
);
287 error ("You can't do that without a process to debug.");
291 nosymbol (char *name
, CORE_ADDR
*addrp
)
293 return 1; /* Symbol does not exist in target env */
297 nosupport_runtime (void)
299 if (ptid_equal (inferior_ptid
, null_ptid
))
302 error ("No run-time support for this");
307 default_terminal_info (char *args
, int from_tty
)
309 printf_unfiltered ("No saved terminal information.\n");
312 /* This is the default target_create_inferior and target_attach function.
313 If the current target is executing, it asks whether to kill it off.
314 If this function returns without calling error(), it has killed off
315 the target, and the operation should be attempted. */
318 kill_or_be_killed (int from_tty
)
320 if (target_has_execution
)
322 printf_unfiltered ("You are already running a program:\n");
323 target_files_info ();
324 if (query ("Kill it? "))
327 if (target_has_execution
)
328 error ("Killing the program did not help.");
333 error ("Program not killed.");
340 maybe_kill_then_attach (char *args
, int from_tty
)
342 kill_or_be_killed (from_tty
);
343 target_attach (args
, from_tty
);
347 maybe_kill_then_create_inferior (char *exec
, char *args
, char **env
)
349 kill_or_be_killed (0);
350 target_create_inferior (exec
, args
, env
);
353 /* Go through the target stack from top to bottom, copying over zero
354 entries in current_target, then filling in still empty entries. In
355 effect, we are doing class inheritance through the pushed target
358 NOTE: cagney/2003-10-17: The problem with this inheritance, as it
359 is currently implemented, is that it discards any knowledge of
360 which target an inherited method originally belonged to.
361 Consequently, new new target methods should instead explicitly and
362 locally search the target stack for the target that can handle the
366 update_current_target (void)
368 struct target_ops
*t
;
370 /* First, reset curren'ts contents. */
371 memset (¤t_target
, 0, sizeof (current_target
));
373 #define INHERIT(FIELD, TARGET) \
374 if (!current_target.FIELD) \
375 current_target.FIELD = (TARGET)->FIELD
377 for (t
= target_stack
; t
; t
= t
->beneath
)
379 INHERIT (to_shortname
, t
);
380 INHERIT (to_longname
, t
);
382 INHERIT (to_open
, t
);
383 INHERIT (to_close
, t
);
384 INHERIT (to_attach
, t
);
385 INHERIT (to_post_attach
, t
);
386 INHERIT (to_detach
, t
);
387 INHERIT (to_disconnect
, t
);
388 INHERIT (to_resume
, t
);
389 INHERIT (to_wait
, t
);
390 INHERIT (to_post_wait
, t
);
391 INHERIT (to_fetch_registers
, t
);
392 INHERIT (to_store_registers
, t
);
393 INHERIT (to_prepare_to_store
, t
);
394 INHERIT (to_xfer_memory
, t
);
395 INHERIT (to_files_info
, t
);
396 INHERIT (to_insert_breakpoint
, t
);
397 INHERIT (to_remove_breakpoint
, t
);
398 INHERIT (to_can_use_hw_breakpoint
, t
);
399 INHERIT (to_insert_hw_breakpoint
, t
);
400 INHERIT (to_remove_hw_breakpoint
, t
);
401 INHERIT (to_insert_watchpoint
, t
);
402 INHERIT (to_remove_watchpoint
, t
);
403 INHERIT (to_stopped_data_address
, t
);
404 INHERIT (to_stopped_by_watchpoint
, t
);
405 INHERIT (to_have_continuable_watchpoint
, t
);
406 INHERIT (to_region_size_ok_for_hw_watchpoint
, t
);
407 INHERIT (to_terminal_init
, t
);
408 INHERIT (to_terminal_inferior
, t
);
409 INHERIT (to_terminal_ours_for_output
, t
);
410 INHERIT (to_terminal_ours
, t
);
411 INHERIT (to_terminal_save_ours
, t
);
412 INHERIT (to_terminal_info
, t
);
413 INHERIT (to_kill
, t
);
414 INHERIT (to_load
, t
);
415 INHERIT (to_lookup_symbol
, t
);
416 INHERIT (to_create_inferior
, t
);
417 INHERIT (to_post_startup_inferior
, t
);
418 INHERIT (to_acknowledge_created_inferior
, t
);
419 INHERIT (to_insert_fork_catchpoint
, t
);
420 INHERIT (to_remove_fork_catchpoint
, t
);
421 INHERIT (to_insert_vfork_catchpoint
, t
);
422 INHERIT (to_remove_vfork_catchpoint
, t
);
423 INHERIT (to_follow_fork
, t
);
424 INHERIT (to_insert_exec_catchpoint
, t
);
425 INHERIT (to_remove_exec_catchpoint
, t
);
426 INHERIT (to_reported_exec_events_per_exec_call
, t
);
427 INHERIT (to_has_exited
, t
);
428 INHERIT (to_mourn_inferior
, t
);
429 INHERIT (to_can_run
, t
);
430 INHERIT (to_notice_signals
, t
);
431 INHERIT (to_thread_alive
, t
);
432 INHERIT (to_find_new_threads
, t
);
433 INHERIT (to_pid_to_str
, t
);
434 INHERIT (to_extra_thread_info
, t
);
435 INHERIT (to_stop
, t
);
436 /* Do not inherit to_read_partial. */
437 /* Do not inherit to_write_partial. */
438 INHERIT (to_rcmd
, t
);
439 INHERIT (to_enable_exception_callback
, t
);
440 INHERIT (to_get_current_exception_event
, t
);
441 INHERIT (to_pid_to_exec_file
, t
);
442 INHERIT (to_stratum
, t
);
443 INHERIT (to_has_all_memory
, t
);
444 INHERIT (to_has_memory
, t
);
445 INHERIT (to_has_stack
, t
);
446 INHERIT (to_has_registers
, t
);
447 INHERIT (to_has_execution
, t
);
448 INHERIT (to_has_thread_control
, t
);
449 INHERIT (to_sections
, t
);
450 INHERIT (to_sections_end
, t
);
451 INHERIT (to_can_async_p
, t
);
452 INHERIT (to_is_async_p
, t
);
453 INHERIT (to_async
, t
);
454 INHERIT (to_async_mask_value
, t
);
455 INHERIT (to_find_memory_regions
, t
);
456 INHERIT (to_make_corefile_notes
, t
);
457 INHERIT (to_get_thread_local_address
, t
);
458 INHERIT (to_magic
, t
);
462 /* Clean up a target struct so it no longer has any zero pointers in
463 it. Some entries are defaulted to a method that print an error,
464 others are hard-wired to a standard recursive default. */
466 #define de_fault(field, value) \
467 if (!current_target.field) \
468 current_target.field = value
471 (void (*) (char *, int))
477 maybe_kill_then_attach
);
478 de_fault (to_post_attach
,
482 (void (*) (char *, int))
484 de_fault (to_disconnect
,
485 (void (*) (char *, int))
488 (void (*) (ptid_t
, int, enum target_signal
))
491 (ptid_t (*) (ptid_t
, struct target_waitstatus
*))
493 de_fault (to_post_wait
,
494 (void (*) (ptid_t
, int))
496 de_fault (to_fetch_registers
,
499 de_fault (to_store_registers
,
502 de_fault (to_prepare_to_store
,
505 de_fault (to_xfer_memory
,
506 (int (*) (CORE_ADDR
, char *, int, int, struct mem_attrib
*, struct target_ops
*))
508 de_fault (to_files_info
,
509 (void (*) (struct target_ops
*))
511 de_fault (to_insert_breakpoint
,
512 memory_insert_breakpoint
);
513 de_fault (to_remove_breakpoint
,
514 memory_remove_breakpoint
);
515 de_fault (to_can_use_hw_breakpoint
,
516 (int (*) (int, int, int))
518 de_fault (to_insert_hw_breakpoint
,
519 (int (*) (CORE_ADDR
, char *))
521 de_fault (to_remove_hw_breakpoint
,
522 (int (*) (CORE_ADDR
, char *))
524 de_fault (to_insert_watchpoint
,
525 (int (*) (CORE_ADDR
, int, int))
527 de_fault (to_remove_watchpoint
,
528 (int (*) (CORE_ADDR
, int, int))
530 de_fault (to_stopped_by_watchpoint
,
533 de_fault (to_stopped_data_address
,
534 (CORE_ADDR (*) (void))
536 de_fault (to_region_size_ok_for_hw_watchpoint
,
537 default_region_size_ok_for_hw_watchpoint
);
538 de_fault (to_terminal_init
,
541 de_fault (to_terminal_inferior
,
544 de_fault (to_terminal_ours_for_output
,
547 de_fault (to_terminal_ours
,
550 de_fault (to_terminal_save_ours
,
553 de_fault (to_terminal_info
,
554 default_terminal_info
);
559 (void (*) (char *, int))
561 de_fault (to_lookup_symbol
,
562 (int (*) (char *, CORE_ADDR
*))
564 de_fault (to_create_inferior
,
565 maybe_kill_then_create_inferior
);
566 de_fault (to_post_startup_inferior
,
569 de_fault (to_acknowledge_created_inferior
,
572 de_fault (to_insert_fork_catchpoint
,
575 de_fault (to_remove_fork_catchpoint
,
578 de_fault (to_insert_vfork_catchpoint
,
581 de_fault (to_remove_vfork_catchpoint
,
584 de_fault (to_follow_fork
,
587 de_fault (to_insert_exec_catchpoint
,
590 de_fault (to_remove_exec_catchpoint
,
593 de_fault (to_reported_exec_events_per_exec_call
,
596 de_fault (to_has_exited
,
597 (int (*) (int, int, int *))
599 de_fault (to_mourn_inferior
,
602 de_fault (to_can_run
,
604 de_fault (to_notice_signals
,
607 de_fault (to_thread_alive
,
610 de_fault (to_find_new_threads
,
613 de_fault (to_extra_thread_info
,
614 (char *(*) (struct thread_info
*))
619 current_target
.to_read_partial
= default_read_partial
;
620 current_target
.to_write_partial
= default_write_partial
;
622 (void (*) (char *, struct ui_file
*))
624 de_fault (to_enable_exception_callback
,
625 (struct symtab_and_line
* (*) (enum exception_event_kind
, int))
627 de_fault (to_get_current_exception_event
,
628 (struct exception_event_record
* (*) (void))
630 de_fault (to_pid_to_exec_file
,
633 de_fault (to_can_async_p
,
636 de_fault (to_is_async_p
,
640 (void (*) (void (*) (enum inferior_event_type
, void*), void*))
644 /* Finally, position the target-stack beneath the squashed
645 "current_target". That way code looking for a non-inherited
646 target method can quickly and simply find it. */
647 current_target
.beneath
= target_stack
;
650 /* Push a new target type into the stack of the existing target accessors,
651 possibly superseding some of the existing accessors.
653 Result is zero if the pushed target ended up on top of the stack,
654 nonzero if at least one target is on top of it.
656 Rather than allow an empty stack, we always have the dummy target at
657 the bottom stratum, so we can call the function vectors without
661 push_target (struct target_ops
*t
)
663 struct target_ops
**cur
;
665 /* Check magic number. If wrong, it probably means someone changed
666 the struct definition, but not all the places that initialize one. */
667 if (t
->to_magic
!= OPS_MAGIC
)
669 fprintf_unfiltered (gdb_stderr
,
670 "Magic number of %s target struct wrong\n",
672 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
675 /* Find the proper stratum to install this target in. */
676 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
678 if ((int) (t
->to_stratum
) >= (int) (*cur
)->to_stratum
)
682 /* If there's already targets at this stratum, remove them. */
683 /* FIXME: cagney/2003-10-15: I think this should be poping all
684 targets to CUR, and not just those at this stratum level. */
685 while ((*cur
) != NULL
&& t
->to_stratum
== (*cur
)->to_stratum
)
687 /* There's already something at this stratum level. Close it,
688 and un-hook it from the stack. */
689 struct target_ops
*tmp
= (*cur
);
690 (*cur
) = (*cur
)->beneath
;
692 target_close (tmp
, 0);
695 /* We have removed all targets in our stratum, now add the new one. */
699 update_current_target ();
702 setup_target_debug ();
705 return (t
!= target_stack
);
708 /* Remove a target_ops vector from the stack, wherever it may be.
709 Return how many times it was removed (0 or 1). */
712 unpush_target (struct target_ops
*t
)
714 struct target_ops
**cur
;
715 struct target_ops
*tmp
;
719 /* Look for the specified target. Note that we assume that a target
720 can only occur once in the target stack. */
722 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
729 return 0; /* Didn't find target_ops, quit now */
731 /* Unchain the target */
733 (*cur
) = (*cur
)->beneath
;
736 update_current_target ();
744 target_close (¤t_target
, 0); /* Let it clean up */
745 if (unpush_target (target_stack
) == 1)
748 fprintf_unfiltered (gdb_stderr
,
749 "pop_target couldn't find target %s\n",
750 current_target
.to_shortname
);
751 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
755 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
757 /* target_read_string -- read a null terminated string, up to LEN bytes,
758 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
759 Set *STRING to a pointer to malloc'd memory containing the data; the caller
760 is responsible for freeing it. Return the number of bytes successfully
764 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
766 int tlen
, origlen
, offset
, i
;
770 int buffer_allocated
;
772 unsigned int nbytes_read
= 0;
774 /* Small for testing. */
775 buffer_allocated
= 4;
776 buffer
= xmalloc (buffer_allocated
);
783 tlen
= MIN (len
, 4 - (memaddr
& 3));
784 offset
= memaddr
& 3;
786 errcode
= target_xfer_memory (memaddr
& ~3, buf
, 4, 0);
789 /* The transfer request might have crossed the boundary to an
790 unallocated region of memory. Retry the transfer, requesting
794 errcode
= target_xfer_memory (memaddr
, buf
, 1, 0);
799 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
802 bytes
= bufptr
- buffer
;
803 buffer_allocated
*= 2;
804 buffer
= xrealloc (buffer
, buffer_allocated
);
805 bufptr
= buffer
+ bytes
;
808 for (i
= 0; i
< tlen
; i
++)
810 *bufptr
++ = buf
[i
+ offset
];
811 if (buf
[i
+ offset
] == '\000')
813 nbytes_read
+= i
+ 1;
830 /* Find a section containing ADDR. */
831 struct section_table
*
832 target_section_by_addr (struct target_ops
*target
, CORE_ADDR addr
)
834 struct section_table
*secp
;
835 for (secp
= target
->to_sections
;
836 secp
< target
->to_sections_end
;
839 if (addr
>= secp
->addr
&& addr
< secp
->endaddr
)
845 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
846 GDB's memory at MYADDR. Returns either 0 for success or an errno value
849 If an error occurs, no guarantee is made about the contents of the data at
850 MYADDR. In particular, the caller should not depend upon partial reads
851 filling the buffer with good data. There is no way for the caller to know
852 how much good data might have been transfered anyway. Callers that can
853 deal with partial reads should call target_read_memory_partial. */
856 target_read_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
858 return target_xfer_memory (memaddr
, myaddr
, len
, 0);
862 target_write_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
864 return target_xfer_memory (memaddr
, myaddr
, len
, 1);
867 static int trust_readonly
= 0;
869 /* Move memory to or from the targets. The top target gets priority;
870 if it cannot handle it, it is offered to the next one down, etc.
872 Result is -1 on error, or the number of bytes transfered. */
875 do_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
876 struct mem_attrib
*attrib
)
880 struct target_ops
*t
;
882 /* Zero length requests are ok and require no work. */
886 /* to_xfer_memory is not guaranteed to set errno, even when it returns
890 if (!write
&& trust_readonly
)
892 struct section_table
*secp
;
893 /* User-settable option, "trust-readonly-sections". If true,
894 then memory from any SEC_READONLY bfd section may be read
895 directly from the bfd file. */
896 secp
= target_section_by_addr (¤t_target
, memaddr
);
898 && (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
900 return xfer_memory (memaddr
, myaddr
, len
, 0, attrib
, ¤t_target
);
903 /* The quick case is that the top target can handle the transfer. */
904 res
= current_target
.to_xfer_memory
905 (memaddr
, myaddr
, len
, write
, attrib
, ¤t_target
);
907 /* If res <= 0 then we call it again in the loop. Ah well. */
910 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
912 if (!t
->to_has_memory
)
915 res
= t
->to_xfer_memory (memaddr
, myaddr
, len
, write
, attrib
, t
);
917 break; /* Handled all or part of xfer */
918 if (t
->to_has_all_memory
)
930 /* Perform a memory transfer. Iterate until the entire region has
933 Result is 0 or errno value. */
936 target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
)
940 struct mem_region
*region
;
942 /* Zero length requests are ok and require no work. */
950 region
= lookup_mem_region(memaddr
);
951 if (memaddr
+ len
< region
->hi
)
954 reg_len
= region
->hi
- memaddr
;
956 switch (region
->attrib
.mode
)
971 if (region
->attrib
.cache
)
972 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
,
975 res
= do_xfer_memory (memaddr
, myaddr
, reg_len
, write
,
980 /* If this address is for nonexistent memory, read zeros
981 if reading, or do nothing if writing. Return
984 memset (myaddr
, 0, len
);
998 return 0; /* We managed to cover it all somehow. */
1002 /* Perform a partial memory transfer.
1004 Result is -1 on error, or the number of bytes transfered. */
1007 target_xfer_memory_partial (CORE_ADDR memaddr
, char *myaddr
, int len
,
1008 int write_p
, int *err
)
1012 struct mem_region
*region
;
1014 /* Zero length requests are ok and require no work. */
1021 region
= lookup_mem_region(memaddr
);
1022 if (memaddr
+ len
< region
->hi
)
1025 reg_len
= region
->hi
- memaddr
;
1027 switch (region
->attrib
.mode
)
1046 if (region
->attrib
.cache
)
1047 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
,
1050 res
= do_xfer_memory (memaddr
, myaddr
, reg_len
, write_p
,
1068 target_read_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1070 return target_xfer_memory_partial (memaddr
, buf
, len
, 0, err
);
1074 target_write_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1076 return target_xfer_memory_partial (memaddr
, buf
, len
, 1, err
);
1079 /* More generic transfers. */
1082 default_read_partial (struct target_ops
*ops
,
1083 enum target_object object
,
1084 const char *annex
, void *buf
,
1085 ULONGEST offset
, LONGEST len
)
1087 if (object
== TARGET_OBJECT_MEMORY
1088 && ops
->to_xfer_memory
!= NULL
)
1089 /* If available, fall back to the target's "to_xfer_memory"
1094 xfered
= ops
->to_xfer_memory (offset
, buf
, len
, 0/*read*/, NULL
, ops
);
1097 else if (xfered
== 0 && errno
== 0)
1098 /* "to_xfer_memory" uses 0, cross checked against ERRNO as one
1099 indication of an error. */
1104 else if (ops
->beneath
!= NULL
)
1105 return target_read_partial (ops
->beneath
, object
, annex
, buf
, offset
, len
);
1111 default_write_partial (struct target_ops
*ops
,
1112 enum target_object object
,
1113 const char *annex
, const void *buf
,
1114 ULONGEST offset
, LONGEST len
)
1116 if (object
== TARGET_OBJECT_MEMORY
1117 && ops
->to_xfer_memory
!= NULL
)
1118 /* If available, fall back to the target's "to_xfer_memory"
1124 void *buffer
= xmalloc (len
);
1125 struct cleanup
*cleanup
= make_cleanup (xfree
, buffer
);
1126 memcpy (buffer
, buf
, len
);
1127 xfered
= ops
->to_xfer_memory (offset
, buffer
, len
, 1/*write*/, NULL
,
1129 do_cleanups (cleanup
);
1133 else if (xfered
== 0 && errno
== 0)
1134 /* "to_xfer_memory" uses 0, cross checked against ERRNO as one
1135 indication of an error. */
1140 else if (ops
->beneath
!= NULL
)
1141 return target_write_partial (ops
->beneath
, object
, annex
, buf
, offset
,
1147 /* Target vector read/write partial wrapper functions.
1149 NOTE: cagney/2003-10-21: I wonder if having "to_xfer_partial
1150 (inbuf, outbuf)", instead of separate read/write methods, make life
1154 target_read_partial (struct target_ops
*ops
,
1155 enum target_object object
,
1156 const char *annex
, void *buf
,
1157 ULONGEST offset
, LONGEST len
)
1159 gdb_assert (ops
->to_read_partial
!= NULL
);
1160 return ops
->to_read_partial (ops
, object
, annex
, buf
, offset
, len
);
1164 target_write_partial (struct target_ops
*ops
,
1165 enum target_object object
,
1166 const char *annex
, const void *buf
,
1167 ULONGEST offset
, LONGEST len
)
1169 gdb_assert (ops
->to_write_partial
!= NULL
);
1170 return ops
->to_write_partial (ops
, object
, annex
, buf
, offset
, len
);
1173 /* Wrappers to perform the full transfer. */
1175 target_read (struct target_ops
*ops
,
1176 enum target_object object
,
1177 const char *annex
, void *buf
,
1178 ULONGEST offset
, LONGEST len
)
1181 while (xfered
< len
)
1183 LONGEST xfer
= target_read_partial (ops
, object
, annex
,
1184 (bfd_byte
*) buf
+ xfered
,
1185 offset
+ xfered
, len
- xfered
);
1186 /* Call an observer, notifying them of the xfer progress? */
1188 /* Call memory_error? */
1197 target_write (struct target_ops
*ops
,
1198 enum target_object object
,
1199 const char *annex
, const void *buf
,
1200 ULONGEST offset
, LONGEST len
)
1203 while (xfered
< len
)
1205 LONGEST xfer
= target_write_partial (ops
, object
, annex
,
1206 (bfd_byte
*) buf
+ xfered
,
1207 offset
+ xfered
, len
- xfered
);
1208 /* Call an observer, notifying them of the xfer progress? */
1210 /* Call memory_error? */
1218 /* Memory transfer methods. */
1221 get_target_memory (struct target_ops
*ops
, CORE_ADDR addr
, void *buf
,
1224 if (target_read (ops
, TARGET_OBJECT_MEMORY
, NULL
, buf
, addr
, len
)
1226 memory_error (EIO
, addr
);
1230 get_target_memory_unsigned (struct target_ops
*ops
,
1231 CORE_ADDR addr
, int len
)
1233 char buf
[sizeof (ULONGEST
)];
1235 gdb_assert (len
<= sizeof (buf
));
1236 get_target_memory (ops
, addr
, buf
, len
);
1237 return extract_unsigned_integer (buf
, len
);
1241 target_info (char *args
, int from_tty
)
1243 struct target_ops
*t
;
1244 int has_all_mem
= 0;
1246 if (symfile_objfile
!= NULL
)
1247 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
1249 #ifdef FILES_INFO_HOOK
1250 if (FILES_INFO_HOOK ())
1254 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
1256 if (!t
->to_has_memory
)
1259 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
1262 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1263 printf_unfiltered ("%s:\n", t
->to_longname
);
1264 (t
->to_files_info
) (t
);
1265 has_all_mem
= t
->to_has_all_memory
;
1269 /* This is to be called by the open routine before it does
1273 target_preopen (int from_tty
)
1277 if (target_has_execution
)
1280 || query ("A program is being debugged already. Kill it? "))
1283 error ("Program not killed.");
1286 /* Calling target_kill may remove the target from the stack. But if
1287 it doesn't (which seems like a win for UDI), remove it now. */
1289 if (target_has_execution
)
1293 /* Detach a target after doing deferred register stores. */
1296 target_detach (char *args
, int from_tty
)
1298 /* Handle any optimized stores to the inferior. */
1299 #ifdef DO_DEFERRED_STORES
1302 (current_target
.to_detach
) (args
, from_tty
);
1306 target_disconnect (char *args
, int from_tty
)
1308 /* Handle any optimized stores to the inferior. */
1309 #ifdef DO_DEFERRED_STORES
1312 (current_target
.to_disconnect
) (args
, from_tty
);
1316 target_link (char *modname
, CORE_ADDR
*t_reloc
)
1318 if (STREQ (current_target
.to_shortname
, "rombug"))
1320 (current_target
.to_lookup_symbol
) (modname
, t_reloc
);
1322 error ("Unable to link to %s and get relocation in rombug", modname
);
1325 *t_reloc
= (CORE_ADDR
) -1;
1329 target_async_mask (int mask
)
1331 int saved_async_masked_status
= target_async_mask_value
;
1332 target_async_mask_value
= mask
;
1333 return saved_async_masked_status
;
1336 /* Look through the list of possible targets for a target that can
1337 execute a run or attach command without any other data. This is
1338 used to locate the default process stratum.
1340 Result is always valid (error() is called for errors). */
1342 static struct target_ops
*
1343 find_default_run_target (char *do_mesg
)
1345 struct target_ops
**t
;
1346 struct target_ops
*runable
= NULL
;
1351 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1354 if ((*t
)->to_can_run
&& target_can_run (*t
))
1362 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
1368 find_default_attach (char *args
, int from_tty
)
1370 struct target_ops
*t
;
1372 t
= find_default_run_target ("attach");
1373 (t
->to_attach
) (args
, from_tty
);
1378 find_default_create_inferior (char *exec_file
, char *allargs
, char **env
)
1380 struct target_ops
*t
;
1382 t
= find_default_run_target ("run");
1383 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
1388 default_region_size_ok_for_hw_watchpoint (int byte_count
)
1390 return (byte_count
<= DEPRECATED_REGISTER_SIZE
);
1406 return_minus_one (void)
1412 * Resize the to_sections pointer. Also make sure that anyone that
1413 * was holding on to an old value of it gets updated.
1414 * Returns the old size.
1418 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1420 struct target_ops
**t
;
1421 struct section_table
*old_value
;
1424 old_value
= target
->to_sections
;
1426 if (target
->to_sections
)
1428 old_count
= target
->to_sections_end
- target
->to_sections
;
1429 target
->to_sections
= (struct section_table
*)
1430 xrealloc ((char *) target
->to_sections
,
1431 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1436 target
->to_sections
= (struct section_table
*)
1437 xmalloc ((sizeof (struct section_table
)) * num_added
);
1439 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1441 /* Check to see if anyone else was pointing to this structure.
1442 If old_value was null, then no one was. */
1446 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1449 if ((*t
)->to_sections
== old_value
)
1451 (*t
)->to_sections
= target
->to_sections
;
1452 (*t
)->to_sections_end
= target
->to_sections_end
;
1461 /* Remove all target sections taken from ABFD.
1463 Scan the current target stack for targets whose section tables
1464 refer to sections from BFD, and remove those sections. We use this
1465 when we notice that the inferior has unloaded a shared object, for
1468 remove_target_sections (bfd
*abfd
)
1470 struct target_ops
**t
;
1472 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; t
++)
1474 struct section_table
*src
, *dest
;
1476 dest
= (*t
)->to_sections
;
1477 for (src
= (*t
)->to_sections
; src
< (*t
)->to_sections_end
; src
++)
1478 if (src
->bfd
!= abfd
)
1480 /* Keep this section. */
1481 if (dest
< src
) *dest
= *src
;
1485 /* If we've dropped any sections, resize the section table. */
1487 target_resize_to_sections (*t
, dest
- src
);
1494 /* Find a single runnable target in the stack and return it. If for
1495 some reason there is more than one, return NULL. */
1498 find_run_target (void)
1500 struct target_ops
**t
;
1501 struct target_ops
*runable
= NULL
;
1506 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1508 if ((*t
)->to_can_run
&& target_can_run (*t
))
1515 return (count
== 1 ? runable
: NULL
);
1518 /* Find a single core_stratum target in the list of targets and return it.
1519 If for some reason there is more than one, return NULL. */
1522 find_core_target (void)
1524 struct target_ops
**t
;
1525 struct target_ops
*runable
= NULL
;
1530 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1533 if ((*t
)->to_stratum
== core_stratum
)
1540 return (count
== 1 ? runable
: NULL
);
1544 * Find the next target down the stack from the specified target.
1548 find_target_beneath (struct target_ops
*t
)
1554 /* The inferior process has died. Long live the inferior! */
1557 generic_mourn_inferior (void)
1559 extern int show_breakpoint_hit_counts
;
1561 inferior_ptid
= null_ptid
;
1563 breakpoint_init_inferior (inf_exited
);
1564 registers_changed ();
1566 #ifdef CLEAR_DEFERRED_STORES
1567 /* Delete any pending stores to the inferior... */
1568 CLEAR_DEFERRED_STORES
;
1571 reopen_exec_file ();
1572 reinit_frame_cache ();
1574 /* It is confusing to the user for ignore counts to stick around
1575 from previous runs of the inferior. So clear them. */
1576 /* However, it is more confusing for the ignore counts to disappear when
1577 using hit counts. So don't clear them if we're counting hits. */
1578 if (!show_breakpoint_hit_counts
)
1579 breakpoint_clear_ignore_counts ();
1585 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1586 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1587 translation of that in OURSTATUS. */
1589 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
1591 #ifdef CHILD_SPECIAL_WAITSTATUS
1592 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1593 if it wants to deal with hoststatus. */
1594 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
1598 if (WIFEXITED (hoststatus
))
1600 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1601 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
1603 else if (!WIFSTOPPED (hoststatus
))
1605 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1606 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
1610 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
1611 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
1615 /* Returns zero to leave the inferior alone, one to interrupt it. */
1616 int (*target_activity_function
) (void);
1617 int target_activity_fd
;
1619 /* Convert a normal process ID to a string. Returns the string in a static
1623 normal_pid_to_str (ptid_t ptid
)
1625 static char buf
[30];
1627 sprintf (buf
, "process %d", PIDGET (ptid
));
1631 /* Some targets (such as ttrace-based HPUX) don't allow us to request
1632 notification of inferior events such as fork and vork immediately
1633 after the inferior is created. (This because of how gdb gets an
1634 inferior created via invoking a shell to do it. In such a scenario,
1635 if the shell init file has commands in it, the shell will fork and
1636 exec for each of those commands, and we will see each such fork
1639 This function is used by all targets that allow us to request
1640 notification of forks, etc at inferior creation time; e.g., in
1641 target_acknowledge_forked_child.
1644 normal_target_post_startup_inferior (ptid_t ptid
)
1646 /* This space intentionally left blank. */
1649 /* Error-catcher for target_find_memory_regions */
1650 static int dummy_find_memory_regions (int (*ignore1
) (), void *ignore2
)
1652 error ("No target.");
1656 /* Error-catcher for target_make_corefile_notes */
1657 static char * dummy_make_corefile_notes (bfd
*ignore1
, int *ignore2
)
1659 error ("No target.");
1663 /* Set up the handful of non-empty slots needed by the dummy target
1667 init_dummy_target (void)
1669 dummy_target
.to_shortname
= "None";
1670 dummy_target
.to_longname
= "None";
1671 dummy_target
.to_doc
= "";
1672 dummy_target
.to_attach
= find_default_attach
;
1673 dummy_target
.to_create_inferior
= find_default_create_inferior
;
1674 dummy_target
.to_pid_to_str
= normal_pid_to_str
;
1675 dummy_target
.to_stratum
= dummy_stratum
;
1676 dummy_target
.to_find_memory_regions
= dummy_find_memory_regions
;
1677 dummy_target
.to_make_corefile_notes
= dummy_make_corefile_notes
;
1678 dummy_target
.to_magic
= OPS_MAGIC
;
1682 static struct target_ops debug_target
;
1685 debug_to_open (char *args
, int from_tty
)
1687 debug_target
.to_open (args
, from_tty
);
1689 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
1693 debug_to_close (int quitting
)
1695 target_close (&debug_target
, quitting
);
1696 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
1700 target_close (struct target_ops
*targ
, int quitting
)
1702 if (targ
->to_xclose
!= NULL
)
1703 targ
->to_xclose (targ
, quitting
);
1704 else if (targ
->to_close
!= NULL
)
1705 targ
->to_close (quitting
);
1709 debug_to_attach (char *args
, int from_tty
)
1711 debug_target
.to_attach (args
, from_tty
);
1713 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
1718 debug_to_post_attach (int pid
)
1720 debug_target
.to_post_attach (pid
);
1722 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
1726 debug_to_detach (char *args
, int from_tty
)
1728 debug_target
.to_detach (args
, from_tty
);
1730 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
1734 debug_to_disconnect (char *args
, int from_tty
)
1736 debug_target
.to_disconnect (args
, from_tty
);
1738 fprintf_unfiltered (gdb_stdlog
, "target_disconnect (%s, %d)\n",
1743 debug_to_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
1745 debug_target
.to_resume (ptid
, step
, siggnal
);
1747 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", PIDGET (ptid
),
1748 step
? "step" : "continue",
1749 target_signal_to_name (siggnal
));
1753 debug_to_wait (ptid_t ptid
, struct target_waitstatus
*status
)
1757 retval
= debug_target
.to_wait (ptid
, status
);
1759 fprintf_unfiltered (gdb_stdlog
,
1760 "target_wait (%d, status) = %d, ", PIDGET (ptid
),
1762 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
1763 switch (status
->kind
)
1765 case TARGET_WAITKIND_EXITED
:
1766 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
1767 status
->value
.integer
);
1769 case TARGET_WAITKIND_STOPPED
:
1770 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
1771 target_signal_to_name (status
->value
.sig
));
1773 case TARGET_WAITKIND_SIGNALLED
:
1774 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
1775 target_signal_to_name (status
->value
.sig
));
1777 case TARGET_WAITKIND_LOADED
:
1778 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
1780 case TARGET_WAITKIND_FORKED
:
1781 fprintf_unfiltered (gdb_stdlog
, "forked\n");
1783 case TARGET_WAITKIND_VFORKED
:
1784 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
1786 case TARGET_WAITKIND_EXECD
:
1787 fprintf_unfiltered (gdb_stdlog
, "execd\n");
1789 case TARGET_WAITKIND_SPURIOUS
:
1790 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
1793 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
1801 debug_to_post_wait (ptid_t ptid
, int status
)
1803 debug_target
.to_post_wait (ptid
, status
);
1805 fprintf_unfiltered (gdb_stdlog
, "target_post_wait (%d, %d)\n",
1806 PIDGET (ptid
), status
);
1810 debug_print_register (const char * func
, int regno
)
1812 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
1813 if (regno
>= 0 && regno
< NUM_REGS
+ NUM_PSEUDO_REGS
1814 && REGISTER_NAME (regno
) != NULL
&& REGISTER_NAME (regno
)[0] != '\0')
1815 fprintf_unfiltered (gdb_stdlog
, "(%s)", REGISTER_NAME (regno
));
1817 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
1821 unsigned char buf
[MAX_REGISTER_SIZE
];
1822 deprecated_read_register_gen (regno
, buf
);
1823 fprintf_unfiltered (gdb_stdlog
, " = ");
1824 for (i
= 0; i
< DEPRECATED_REGISTER_RAW_SIZE (regno
); i
++)
1826 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
1828 if (DEPRECATED_REGISTER_RAW_SIZE (regno
) <= sizeof (LONGEST
))
1830 fprintf_unfiltered (gdb_stdlog
, " 0x%s %s",
1831 paddr_nz (read_register (regno
)),
1832 paddr_d (read_register (regno
)));
1835 fprintf_unfiltered (gdb_stdlog
, "\n");
1839 debug_to_fetch_registers (int regno
)
1841 debug_target
.to_fetch_registers (regno
);
1842 debug_print_register ("target_fetch_registers", regno
);
1846 debug_to_store_registers (int regno
)
1848 debug_target
.to_store_registers (regno
);
1849 debug_print_register ("target_store_registers", regno
);
1850 fprintf_unfiltered (gdb_stdlog
, "\n");
1854 debug_to_prepare_to_store (void)
1856 debug_target
.to_prepare_to_store ();
1858 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
1862 debug_to_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
1863 struct mem_attrib
*attrib
,
1864 struct target_ops
*target
)
1868 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
,
1871 fprintf_unfiltered (gdb_stdlog
,
1872 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
1873 (unsigned int) memaddr
, /* possable truncate long long */
1874 len
, write
? "write" : "read", retval
);
1882 fputs_unfiltered (", bytes =", gdb_stdlog
);
1883 for (i
= 0; i
< retval
; i
++)
1885 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
1886 fprintf_unfiltered (gdb_stdlog
, "\n");
1887 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1891 fputc_unfiltered ('\n', gdb_stdlog
);
1897 debug_to_files_info (struct target_ops
*target
)
1899 debug_target
.to_files_info (target
);
1901 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
1905 debug_to_insert_breakpoint (CORE_ADDR addr
, char *save
)
1909 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
1911 fprintf_unfiltered (gdb_stdlog
,
1912 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
1913 (unsigned long) addr
,
1914 (unsigned long) retval
);
1919 debug_to_remove_breakpoint (CORE_ADDR addr
, char *save
)
1923 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
1925 fprintf_unfiltered (gdb_stdlog
,
1926 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
1927 (unsigned long) addr
,
1928 (unsigned long) retval
);
1933 debug_to_can_use_hw_breakpoint (int type
, int cnt
, int from_tty
)
1937 retval
= debug_target
.to_can_use_hw_breakpoint (type
, cnt
, from_tty
);
1939 fprintf_unfiltered (gdb_stdlog
,
1940 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
1941 (unsigned long) type
,
1942 (unsigned long) cnt
,
1943 (unsigned long) from_tty
,
1944 (unsigned long) retval
);
1949 debug_to_region_size_ok_for_hw_watchpoint (int byte_count
)
1953 retval
= debug_target
.to_region_size_ok_for_hw_watchpoint (byte_count
);
1955 fprintf_unfiltered (gdb_stdlog
,
1956 "TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT (%ld) = 0x%lx\n",
1957 (unsigned long) byte_count
,
1958 (unsigned long) retval
);
1963 debug_to_stopped_by_watchpoint (void)
1967 retval
= debug_target
.to_stopped_by_watchpoint ();
1969 fprintf_unfiltered (gdb_stdlog
,
1970 "STOPPED_BY_WATCHPOINT () = %ld\n",
1971 (unsigned long) retval
);
1976 debug_to_stopped_data_address (void)
1980 retval
= debug_target
.to_stopped_data_address ();
1982 fprintf_unfiltered (gdb_stdlog
,
1983 "target_stopped_data_address () = 0x%lx\n",
1984 (unsigned long) retval
);
1989 debug_to_insert_hw_breakpoint (CORE_ADDR addr
, char *save
)
1993 retval
= debug_target
.to_insert_hw_breakpoint (addr
, save
);
1995 fprintf_unfiltered (gdb_stdlog
,
1996 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
1997 (unsigned long) addr
,
1998 (unsigned long) retval
);
2003 debug_to_remove_hw_breakpoint (CORE_ADDR addr
, char *save
)
2007 retval
= debug_target
.to_remove_hw_breakpoint (addr
, save
);
2009 fprintf_unfiltered (gdb_stdlog
,
2010 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
2011 (unsigned long) addr
,
2012 (unsigned long) retval
);
2017 debug_to_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
2021 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
2023 fprintf_unfiltered (gdb_stdlog
,
2024 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
2025 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
2030 debug_to_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
2034 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
2036 fprintf_unfiltered (gdb_stdlog
,
2037 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
2038 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
2043 debug_to_terminal_init (void)
2045 debug_target
.to_terminal_init ();
2047 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
2051 debug_to_terminal_inferior (void)
2053 debug_target
.to_terminal_inferior ();
2055 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
2059 debug_to_terminal_ours_for_output (void)
2061 debug_target
.to_terminal_ours_for_output ();
2063 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
2067 debug_to_terminal_ours (void)
2069 debug_target
.to_terminal_ours ();
2071 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
2075 debug_to_terminal_save_ours (void)
2077 debug_target
.to_terminal_save_ours ();
2079 fprintf_unfiltered (gdb_stdlog
, "target_terminal_save_ours ()\n");
2083 debug_to_terminal_info (char *arg
, int from_tty
)
2085 debug_target
.to_terminal_info (arg
, from_tty
);
2087 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
2092 debug_to_kill (void)
2094 debug_target
.to_kill ();
2096 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
2100 debug_to_load (char *args
, int from_tty
)
2102 debug_target
.to_load (args
, from_tty
);
2104 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
2108 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
2112 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
2114 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
2120 debug_to_create_inferior (char *exec_file
, char *args
, char **env
)
2122 debug_target
.to_create_inferior (exec_file
, args
, env
);
2124 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx)\n",
2129 debug_to_post_startup_inferior (ptid_t ptid
)
2131 debug_target
.to_post_startup_inferior (ptid
);
2133 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
2138 debug_to_acknowledge_created_inferior (int pid
)
2140 debug_target
.to_acknowledge_created_inferior (pid
);
2142 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
2147 debug_to_insert_fork_catchpoint (int pid
)
2151 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
2153 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
2160 debug_to_remove_fork_catchpoint (int pid
)
2164 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
2166 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
2173 debug_to_insert_vfork_catchpoint (int pid
)
2177 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
2179 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)= %d\n",
2186 debug_to_remove_vfork_catchpoint (int pid
)
2190 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
2192 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
2199 debug_to_follow_fork (int follow_child
)
2201 int retval
= debug_target
.to_follow_fork (follow_child
);
2203 fprintf_unfiltered (gdb_stdlog
, "target_follow_fork (%d) = %d\n",
2204 follow_child
, retval
);
2210 debug_to_insert_exec_catchpoint (int pid
)
2214 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
2216 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
2223 debug_to_remove_exec_catchpoint (int pid
)
2227 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
2229 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2236 debug_to_reported_exec_events_per_exec_call (void)
2238 int reported_exec_events
;
2240 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2242 fprintf_unfiltered (gdb_stdlog
,
2243 "target_reported_exec_events_per_exec_call () = %d\n",
2244 reported_exec_events
);
2246 return reported_exec_events
;
2250 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
2254 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2256 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2257 pid
, wait_status
, *exit_status
, has_exited
);
2263 debug_to_mourn_inferior (void)
2265 debug_target
.to_mourn_inferior ();
2267 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2271 debug_to_can_run (void)
2275 retval
= debug_target
.to_can_run ();
2277 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2283 debug_to_notice_signals (ptid_t ptid
)
2285 debug_target
.to_notice_signals (ptid
);
2287 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n",
2292 debug_to_thread_alive (ptid_t ptid
)
2296 retval
= debug_target
.to_thread_alive (ptid
);
2298 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2299 PIDGET (ptid
), retval
);
2305 debug_to_find_new_threads (void)
2307 debug_target
.to_find_new_threads ();
2309 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog
);
2313 debug_to_stop (void)
2315 debug_target
.to_stop ();
2317 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2321 debug_to_read_partial (struct target_ops
*ops
,
2322 enum target_object object
,
2323 const char *annex
, void *buf
,
2324 ULONGEST offset
, LONGEST len
)
2328 retval
= target_read_partial (&debug_target
, object
, annex
, buf
, offset
,
2331 fprintf_unfiltered (gdb_stdlog
,
2332 "target_read_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n",
2333 (int) object
, (annex
? annex
: "(null)"),
2334 (long) buf
, paddr_nz (offset
),
2335 paddr_d (len
), paddr_d (retval
));
2341 debug_to_write_partial (struct target_ops
*ops
,
2342 enum target_object object
,
2343 const char *annex
, const void *buf
,
2344 ULONGEST offset
, LONGEST len
)
2348 retval
= target_write_partial (&debug_target
, object
, annex
, buf
, offset
,
2351 fprintf_unfiltered (gdb_stdlog
,
2352 "target_write_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n",
2353 (int) object
, (annex
? annex
: "(null)"),
2354 (long) buf
, paddr_nz (offset
),
2355 paddr_d (len
), paddr_d (retval
));
2361 debug_to_rcmd (char *command
,
2362 struct ui_file
*outbuf
)
2364 debug_target
.to_rcmd (command
, outbuf
);
2365 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2368 static struct symtab_and_line
*
2369 debug_to_enable_exception_callback (enum exception_event_kind kind
, int enable
)
2371 struct symtab_and_line
*result
;
2372 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2373 fprintf_unfiltered (gdb_stdlog
,
2374 "target get_exception_callback_sal (%d, %d)\n",
2379 static struct exception_event_record
*
2380 debug_to_get_current_exception_event (void)
2382 struct exception_event_record
*result
;
2383 result
= debug_target
.to_get_current_exception_event ();
2384 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2389 debug_to_pid_to_exec_file (int pid
)
2393 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2395 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2402 setup_target_debug (void)
2404 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2406 current_target
.to_open
= debug_to_open
;
2407 current_target
.to_close
= debug_to_close
;
2408 current_target
.to_attach
= debug_to_attach
;
2409 current_target
.to_post_attach
= debug_to_post_attach
;
2410 current_target
.to_detach
= debug_to_detach
;
2411 current_target
.to_disconnect
= debug_to_disconnect
;
2412 current_target
.to_resume
= debug_to_resume
;
2413 current_target
.to_wait
= debug_to_wait
;
2414 current_target
.to_post_wait
= debug_to_post_wait
;
2415 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2416 current_target
.to_store_registers
= debug_to_store_registers
;
2417 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2418 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2419 current_target
.to_files_info
= debug_to_files_info
;
2420 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2421 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2422 current_target
.to_can_use_hw_breakpoint
= debug_to_can_use_hw_breakpoint
;
2423 current_target
.to_insert_hw_breakpoint
= debug_to_insert_hw_breakpoint
;
2424 current_target
.to_remove_hw_breakpoint
= debug_to_remove_hw_breakpoint
;
2425 current_target
.to_insert_watchpoint
= debug_to_insert_watchpoint
;
2426 current_target
.to_remove_watchpoint
= debug_to_remove_watchpoint
;
2427 current_target
.to_stopped_by_watchpoint
= debug_to_stopped_by_watchpoint
;
2428 current_target
.to_stopped_data_address
= debug_to_stopped_data_address
;
2429 current_target
.to_region_size_ok_for_hw_watchpoint
= debug_to_region_size_ok_for_hw_watchpoint
;
2430 current_target
.to_terminal_init
= debug_to_terminal_init
;
2431 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2432 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2433 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2434 current_target
.to_terminal_save_ours
= debug_to_terminal_save_ours
;
2435 current_target
.to_terminal_info
= debug_to_terminal_info
;
2436 current_target
.to_kill
= debug_to_kill
;
2437 current_target
.to_load
= debug_to_load
;
2438 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2439 current_target
.to_create_inferior
= debug_to_create_inferior
;
2440 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2441 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2442 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2443 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2444 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2445 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2446 current_target
.to_follow_fork
= debug_to_follow_fork
;
2447 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2448 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2449 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2450 current_target
.to_has_exited
= debug_to_has_exited
;
2451 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2452 current_target
.to_can_run
= debug_to_can_run
;
2453 current_target
.to_notice_signals
= debug_to_notice_signals
;
2454 current_target
.to_thread_alive
= debug_to_thread_alive
;
2455 current_target
.to_find_new_threads
= debug_to_find_new_threads
;
2456 current_target
.to_stop
= debug_to_stop
;
2457 current_target
.to_read_partial
= debug_to_read_partial
;
2458 current_target
.to_write_partial
= debug_to_write_partial
;
2459 current_target
.to_rcmd
= debug_to_rcmd
;
2460 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
2461 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
2462 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2467 static char targ_desc
[] =
2468 "Names of targets and files being debugged.\n\
2469 Shows the entire stack of targets currently in use (including the exec-file,\n\
2470 core-file, and process, if any), as well as the symbol file name.";
2473 do_monitor_command (char *cmd
,
2476 if ((current_target
.to_rcmd
2477 == (void (*) (char *, struct ui_file
*)) tcomplain
)
2478 || (current_target
.to_rcmd
== debug_to_rcmd
2479 && (debug_target
.to_rcmd
2480 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
2482 error ("\"monitor\" command not supported by this target.\n");
2484 target_rcmd (cmd
, gdb_stdtarg
);
2488 initialize_targets (void)
2490 init_dummy_target ();
2491 push_target (&dummy_target
);
2493 add_info ("target", target_info
, targ_desc
);
2494 add_info ("files", target_info
, targ_desc
);
2497 (add_set_cmd ("target", class_maintenance
, var_zinteger
,
2498 (char *) &targetdebug
,
2499 "Set target debugging.\n\
2500 When non-zero, target debugging is enabled.", &setdebuglist
),
2503 add_setshow_boolean_cmd ("trust-readonly-sections", class_support
,
2505 Set mode for reading from readonly sections.\n\
2506 When this mode is on, memory reads from readonly sections (such as .text)\n\
2507 will be read from the object file instead of from the target. This will\n\
2508 result in significant performance improvement for remote targets.", "\
2509 Show mode for reading from readonly sections.\n",
2511 &setlist
, &showlist
);
2513 add_com ("monitor", class_obscure
, do_monitor_command
,
2514 "Send a command to the remote monitor (remote targets only).");
2516 target_dcache
= dcache_init ();