1 /* Select target systems and architectures at runtime for GDB.
3 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
6 Contributed by Cygnus Support.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
27 #include "gdb_string.h"
42 static void target_info (char *, int);
44 static void maybe_kill_then_create_inferior (char *, char *, char **);
46 static void maybe_kill_then_attach (char *, int);
48 static void kill_or_be_killed (int);
50 static void default_terminal_info (char *, int);
52 static int default_region_size_ok_for_hw_watchpoint (int);
54 static int nosymbol (char *, CORE_ADDR
*);
56 static void tcomplain (void);
58 static int nomemory (CORE_ADDR
, char *, int, int, struct target_ops
*);
60 static int return_zero (void);
62 static int return_one (void);
64 static int return_minus_one (void);
66 void target_ignore (void);
68 static void target_command (char *, int);
70 static struct target_ops
*find_default_run_target (char *);
72 static void nosupport_runtime (void);
74 static void normal_target_post_startup_inferior (ptid_t ptid
);
76 /* Transfer LEN bytes between target address MEMADDR and GDB address
77 MYADDR. Returns 0 for success, errno code for failure (which
78 includes partial transfers -- if you want a more useful response to
79 partial transfers, try either target_read_memory_partial or
80 target_write_memory_partial). */
82 static int target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
,
85 static void init_dummy_target (void);
87 static void debug_to_open (char *, int);
89 static void debug_to_close (int);
91 static void debug_to_attach (char *, int);
93 static void debug_to_detach (char *, int);
95 static void debug_to_disconnect (char *, int);
97 static void debug_to_resume (ptid_t
, int, enum target_signal
);
99 static ptid_t
debug_to_wait (ptid_t
, struct target_waitstatus
*);
101 static void debug_to_fetch_registers (int);
103 static void debug_to_store_registers (int);
105 static void debug_to_prepare_to_store (void);
107 static int debug_to_xfer_memory (CORE_ADDR
, char *, int, int,
108 struct mem_attrib
*, struct target_ops
*);
110 static void debug_to_files_info (struct target_ops
*);
112 static int debug_to_insert_breakpoint (CORE_ADDR
, char *);
114 static int debug_to_remove_breakpoint (CORE_ADDR
, char *);
116 static int debug_to_can_use_hw_breakpoint (int, int, int);
118 static int debug_to_insert_hw_breakpoint (CORE_ADDR
, char *);
120 static int debug_to_remove_hw_breakpoint (CORE_ADDR
, char *);
122 static int debug_to_insert_watchpoint (CORE_ADDR
, int, int);
124 static int debug_to_remove_watchpoint (CORE_ADDR
, int, int);
126 static int debug_to_stopped_by_watchpoint (void);
128 static CORE_ADDR
debug_to_stopped_data_address (void);
130 static int debug_to_region_size_ok_for_hw_watchpoint (int);
132 static void debug_to_terminal_init (void);
134 static void debug_to_terminal_inferior (void);
136 static void debug_to_terminal_ours_for_output (void);
138 static void debug_to_terminal_save_ours (void);
140 static void debug_to_terminal_ours (void);
142 static void debug_to_terminal_info (char *, int);
144 static void debug_to_kill (void);
146 static void debug_to_load (char *, int);
148 static int debug_to_lookup_symbol (char *, CORE_ADDR
*);
150 static void debug_to_create_inferior (char *, char *, char **);
152 static void debug_to_mourn_inferior (void);
154 static int debug_to_can_run (void);
156 static void debug_to_notice_signals (ptid_t
);
158 static int debug_to_thread_alive (ptid_t
);
160 static void debug_to_stop (void);
162 /* Pointer to array of target architecture structures; the size of the
163 array; the current index into the array; the allocated size of the
165 struct target_ops
**target_structs
;
166 unsigned target_struct_size
;
167 unsigned target_struct_index
;
168 unsigned target_struct_allocsize
;
169 #define DEFAULT_ALLOCSIZE 10
171 /* The initial current target, so that there is always a semi-valid
174 static struct target_ops dummy_target
;
176 /* Top of target stack. */
178 static struct target_ops
*target_stack
;
180 /* The target structure we are currently using to talk to a process
181 or file or whatever "inferior" we have. */
183 struct target_ops current_target
;
185 /* Command list for target. */
187 static struct cmd_list_element
*targetlist
= NULL
;
189 /* Nonzero if we are debugging an attached outside process
190 rather than an inferior. */
194 /* Non-zero if we want to see trace of target level stuff. */
196 static int targetdebug
= 0;
198 static void setup_target_debug (void);
200 DCACHE
*target_dcache
;
202 /* The user just typed 'target' without the name of a target. */
205 target_command (char *arg
, int from_tty
)
207 fputs_filtered ("Argument required (target name). Try `help target'\n",
211 /* Add a possible target architecture to the list. */
214 add_target (struct target_ops
*t
)
218 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
219 target_structs
= (struct target_ops
**) xmalloc
220 (target_struct_allocsize
* sizeof (*target_structs
));
222 if (target_struct_size
>= target_struct_allocsize
)
224 target_struct_allocsize
*= 2;
225 target_structs
= (struct target_ops
**)
226 xrealloc ((char *) target_structs
,
227 target_struct_allocsize
* sizeof (*target_structs
));
229 target_structs
[target_struct_size
++] = t
;
231 if (targetlist
== NULL
)
232 add_prefix_cmd ("target", class_run
, target_command
,
233 "Connect to a target machine or process.\n\
234 The first argument is the type or protocol of the target machine.\n\
235 Remaining arguments are interpreted by the target protocol. For more\n\
236 information on the arguments for a particular protocol, type\n\
237 `help target ' followed by the protocol name.",
238 &targetlist
, "target ", 0, &cmdlist
);
239 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
250 target_load (char *arg
, int from_tty
)
252 dcache_invalidate (target_dcache
);
253 (*current_target
.to_load
) (arg
, from_tty
);
257 nomemory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
258 struct target_ops
*t
)
260 errno
= EIO
; /* Can't read/write this location */
261 return 0; /* No bytes handled */
267 error ("You can't do that when your target is `%s'",
268 current_target
.to_shortname
);
274 error ("You can't do that without a process to debug.");
278 nosymbol (char *name
, CORE_ADDR
*addrp
)
280 return 1; /* Symbol does not exist in target env */
284 nosupport_runtime (void)
286 if (ptid_equal (inferior_ptid
, null_ptid
))
289 error ("No run-time support for this");
294 default_terminal_info (char *args
, int from_tty
)
296 printf_unfiltered ("No saved terminal information.\n");
299 /* This is the default target_create_inferior and target_attach function.
300 If the current target is executing, it asks whether to kill it off.
301 If this function returns without calling error(), it has killed off
302 the target, and the operation should be attempted. */
305 kill_or_be_killed (int from_tty
)
307 if (target_has_execution
)
309 printf_unfiltered ("You are already running a program:\n");
310 target_files_info ();
311 if (query ("Kill it? "))
314 if (target_has_execution
)
315 error ("Killing the program did not help.");
320 error ("Program not killed.");
327 maybe_kill_then_attach (char *args
, int from_tty
)
329 kill_or_be_killed (from_tty
);
330 target_attach (args
, from_tty
);
334 maybe_kill_then_create_inferior (char *exec
, char *args
, char **env
)
336 kill_or_be_killed (0);
337 target_create_inferior (exec
, args
, env
);
340 /* Go through the target stack from top to bottom, copying over zero
341 entries in current_target, then filling in still empty entries. In
342 effect, we are doing class inheritance through the pushed target
345 NOTE: cagney/2003-10-17: The problem with this inheritance, as it
346 is currently implemented, is that it discards any knowledge of
347 which target an inherited method originally belonged to.
348 Consequently, new new target methods should instead explicitly and
349 locally search the target stack for the target that can handle the
353 update_current_target (void)
355 struct target_ops
*t
;
357 /* First, reset curren'ts contents. */
358 memset (¤t_target
, 0, sizeof (current_target
));
360 #define INHERIT(FIELD, TARGET) \
361 if (!current_target.FIELD) \
362 current_target.FIELD = (TARGET)->FIELD
364 for (t
= target_stack
; t
; t
= t
->beneath
)
366 INHERIT (to_shortname
, t
);
367 INHERIT (to_longname
, t
);
369 INHERIT (to_open
, t
);
370 INHERIT (to_close
, t
);
371 INHERIT (to_attach
, t
);
372 INHERIT (to_post_attach
, t
);
373 INHERIT (to_detach
, t
);
374 INHERIT (to_disconnect
, t
);
375 INHERIT (to_resume
, t
);
376 INHERIT (to_wait
, t
);
377 INHERIT (to_post_wait
, t
);
378 INHERIT (to_fetch_registers
, t
);
379 INHERIT (to_store_registers
, t
);
380 INHERIT (to_prepare_to_store
, t
);
381 INHERIT (to_xfer_memory
, t
);
382 INHERIT (to_files_info
, t
);
383 INHERIT (to_insert_breakpoint
, t
);
384 INHERIT (to_remove_breakpoint
, t
);
385 INHERIT (to_can_use_hw_breakpoint
, t
);
386 INHERIT (to_insert_hw_breakpoint
, t
);
387 INHERIT (to_remove_hw_breakpoint
, t
);
388 INHERIT (to_insert_watchpoint
, t
);
389 INHERIT (to_remove_watchpoint
, t
);
390 INHERIT (to_stopped_data_address
, t
);
391 INHERIT (to_stopped_by_watchpoint
, t
);
392 INHERIT (to_have_continuable_watchpoint
, t
);
393 INHERIT (to_region_size_ok_for_hw_watchpoint
, t
);
394 INHERIT (to_terminal_init
, t
);
395 INHERIT (to_terminal_inferior
, t
);
396 INHERIT (to_terminal_ours_for_output
, t
);
397 INHERIT (to_terminal_ours
, t
);
398 INHERIT (to_terminal_save_ours
, t
);
399 INHERIT (to_terminal_info
, t
);
400 INHERIT (to_kill
, t
);
401 INHERIT (to_load
, t
);
402 INHERIT (to_lookup_symbol
, t
);
403 INHERIT (to_create_inferior
, t
);
404 INHERIT (to_post_startup_inferior
, t
);
405 INHERIT (to_acknowledge_created_inferior
, t
);
406 INHERIT (to_insert_fork_catchpoint
, t
);
407 INHERIT (to_remove_fork_catchpoint
, t
);
408 INHERIT (to_insert_vfork_catchpoint
, t
);
409 INHERIT (to_remove_vfork_catchpoint
, t
);
410 INHERIT (to_follow_fork
, t
);
411 INHERIT (to_insert_exec_catchpoint
, t
);
412 INHERIT (to_remove_exec_catchpoint
, t
);
413 INHERIT (to_reported_exec_events_per_exec_call
, t
);
414 INHERIT (to_has_exited
, t
);
415 INHERIT (to_mourn_inferior
, t
);
416 INHERIT (to_can_run
, t
);
417 INHERIT (to_notice_signals
, t
);
418 INHERIT (to_thread_alive
, t
);
419 INHERIT (to_find_new_threads
, t
);
420 INHERIT (to_pid_to_str
, t
);
421 INHERIT (to_extra_thread_info
, t
);
422 INHERIT (to_stop
, t
);
423 /* Do not inherit to_read_partial. */
424 /* Do not inherit to_write_partial. */
425 INHERIT (to_rcmd
, t
);
426 INHERIT (to_enable_exception_callback
, t
);
427 INHERIT (to_get_current_exception_event
, t
);
428 INHERIT (to_pid_to_exec_file
, t
);
429 INHERIT (to_stratum
, t
);
430 INHERIT (to_has_all_memory
, t
);
431 INHERIT (to_has_memory
, t
);
432 INHERIT (to_has_stack
, t
);
433 INHERIT (to_has_registers
, t
);
434 INHERIT (to_has_execution
, t
);
435 INHERIT (to_has_thread_control
, t
);
436 INHERIT (to_sections
, t
);
437 INHERIT (to_sections_end
, t
);
438 INHERIT (to_can_async_p
, t
);
439 INHERIT (to_is_async_p
, t
);
440 INHERIT (to_async
, t
);
441 INHERIT (to_async_mask_value
, t
);
442 INHERIT (to_find_memory_regions
, t
);
443 INHERIT (to_make_corefile_notes
, t
);
444 INHERIT (to_get_thread_local_address
, t
);
445 INHERIT (to_magic
, t
);
449 /* Clean up a target struct so it no longer has any zero pointers in
450 it. We default entries, at least to stubs that print error
453 #define de_fault(field, value) \
454 if (!current_target.field) \
455 current_target.field = value
458 (void (*) (char *, int))
464 maybe_kill_then_attach
);
465 de_fault (to_post_attach
,
469 (void (*) (char *, int))
471 de_fault (to_disconnect
,
472 (void (*) (char *, int))
475 (void (*) (ptid_t
, int, enum target_signal
))
478 (ptid_t (*) (ptid_t
, struct target_waitstatus
*))
480 de_fault (to_post_wait
,
481 (void (*) (ptid_t
, int))
483 de_fault (to_fetch_registers
,
486 de_fault (to_store_registers
,
489 de_fault (to_prepare_to_store
,
492 de_fault (to_xfer_memory
,
493 (int (*) (CORE_ADDR
, char *, int, int, struct mem_attrib
*, struct target_ops
*))
495 de_fault (to_files_info
,
496 (void (*) (struct target_ops
*))
498 de_fault (to_insert_breakpoint
,
499 memory_insert_breakpoint
);
500 de_fault (to_remove_breakpoint
,
501 memory_remove_breakpoint
);
502 de_fault (to_can_use_hw_breakpoint
,
503 (int (*) (int, int, int))
505 de_fault (to_insert_hw_breakpoint
,
506 (int (*) (CORE_ADDR
, char *))
508 de_fault (to_remove_hw_breakpoint
,
509 (int (*) (CORE_ADDR
, char *))
511 de_fault (to_insert_watchpoint
,
512 (int (*) (CORE_ADDR
, int, int))
514 de_fault (to_remove_watchpoint
,
515 (int (*) (CORE_ADDR
, int, int))
517 de_fault (to_stopped_by_watchpoint
,
520 de_fault (to_stopped_data_address
,
521 (CORE_ADDR (*) (void))
523 de_fault (to_region_size_ok_for_hw_watchpoint
,
524 default_region_size_ok_for_hw_watchpoint
);
525 de_fault (to_terminal_init
,
528 de_fault (to_terminal_inferior
,
531 de_fault (to_terminal_ours_for_output
,
534 de_fault (to_terminal_ours
,
537 de_fault (to_terminal_save_ours
,
540 de_fault (to_terminal_info
,
541 default_terminal_info
);
546 (void (*) (char *, int))
548 de_fault (to_lookup_symbol
,
549 (int (*) (char *, CORE_ADDR
*))
551 de_fault (to_create_inferior
,
552 maybe_kill_then_create_inferior
);
553 de_fault (to_post_startup_inferior
,
556 de_fault (to_acknowledge_created_inferior
,
559 de_fault (to_insert_fork_catchpoint
,
562 de_fault (to_remove_fork_catchpoint
,
565 de_fault (to_insert_vfork_catchpoint
,
568 de_fault (to_remove_vfork_catchpoint
,
571 de_fault (to_follow_fork
,
574 de_fault (to_insert_exec_catchpoint
,
577 de_fault (to_remove_exec_catchpoint
,
580 de_fault (to_reported_exec_events_per_exec_call
,
583 de_fault (to_has_exited
,
584 (int (*) (int, int, int *))
586 de_fault (to_mourn_inferior
,
589 de_fault (to_can_run
,
591 de_fault (to_notice_signals
,
594 de_fault (to_thread_alive
,
597 de_fault (to_find_new_threads
,
600 de_fault (to_extra_thread_info
,
601 (char *(*) (struct thread_info
*))
607 (void (*) (char *, struct ui_file
*))
609 de_fault (to_enable_exception_callback
,
610 (struct symtab_and_line
* (*) (enum exception_event_kind
, int))
612 de_fault (to_get_current_exception_event
,
613 (struct exception_event_record
* (*) (void))
615 de_fault (to_pid_to_exec_file
,
618 de_fault (to_can_async_p
,
621 de_fault (to_is_async_p
,
625 (void (*) (void (*) (enum inferior_event_type
, void*), void*))
629 /* Finally, position the target-stack beneath the squashed
630 "current_target". That way code looking for a non-inherited
631 target method can quickly and simply find it. */
632 current_target
.beneath
= target_stack
;
635 /* Push a new target type into the stack of the existing target accessors,
636 possibly superseding some of the existing accessors.
638 Result is zero if the pushed target ended up on top of the stack,
639 nonzero if at least one target is on top of it.
641 Rather than allow an empty stack, we always have the dummy target at
642 the bottom stratum, so we can call the function vectors without
646 push_target (struct target_ops
*t
)
648 struct target_ops
**cur
;
650 /* Check magic number. If wrong, it probably means someone changed
651 the struct definition, but not all the places that initialize one. */
652 if (t
->to_magic
!= OPS_MAGIC
)
654 fprintf_unfiltered (gdb_stderr
,
655 "Magic number of %s target struct wrong\n",
657 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
660 /* Find the proper stratum to install this target in. */
661 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
663 if ((int) (t
->to_stratum
) >= (int) (*cur
)->to_stratum
)
667 /* If there's already targets at this stratum, remove them. */
668 /* FIXME: cagney/2003-10-15: I think this should be poping all
669 targets to CUR, and not just those at this stratum level. */
670 while ((*cur
) != NULL
&& t
->to_stratum
== (*cur
)->to_stratum
)
672 /* There's already something at this stratum level. Close it,
673 and un-hook it from the stack. */
674 struct target_ops
*tmp
= (*cur
);
675 (*cur
) = (*cur
)->beneath
;
681 /* We have removed all targets in our stratum, now add the new one. */
685 update_current_target ();
688 setup_target_debug ();
691 return (t
!= target_stack
);
694 /* Remove a target_ops vector from the stack, wherever it may be.
695 Return how many times it was removed (0 or 1). */
698 unpush_target (struct target_ops
*t
)
700 struct target_ops
**cur
;
701 struct target_ops
*tmp
;
704 t
->to_close (0); /* Let it clean up */
706 /* Look for the specified target. Note that we assume that a target
707 can only occur once in the target stack. */
709 for (cur
= &target_stack
; (*cur
) != NULL
; cur
= &(*cur
)->beneath
)
716 return 0; /* Didn't find target_ops, quit now */
718 /* Unchain the target */
720 (*cur
) = (*cur
)->beneath
;
723 update_current_target ();
731 (current_target
.to_close
) (0); /* Let it clean up */
732 if (unpush_target (target_stack
) == 1)
735 fprintf_unfiltered (gdb_stderr
,
736 "pop_target couldn't find target %s\n",
737 current_target
.to_shortname
);
738 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
742 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
744 /* target_read_string -- read a null terminated string, up to LEN bytes,
745 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
746 Set *STRING to a pointer to malloc'd memory containing the data; the caller
747 is responsible for freeing it. Return the number of bytes successfully
751 target_read_string (CORE_ADDR memaddr
, char **string
, int len
, int *errnop
)
753 int tlen
, origlen
, offset
, i
;
757 int buffer_allocated
;
759 unsigned int nbytes_read
= 0;
761 /* Small for testing. */
762 buffer_allocated
= 4;
763 buffer
= xmalloc (buffer_allocated
);
770 tlen
= MIN (len
, 4 - (memaddr
& 3));
771 offset
= memaddr
& 3;
773 errcode
= target_xfer_memory (memaddr
& ~3, buf
, 4, 0);
776 /* The transfer request might have crossed the boundary to an
777 unallocated region of memory. Retry the transfer, requesting
781 errcode
= target_xfer_memory (memaddr
, buf
, 1, 0);
786 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
789 bytes
= bufptr
- buffer
;
790 buffer_allocated
*= 2;
791 buffer
= xrealloc (buffer
, buffer_allocated
);
792 bufptr
= buffer
+ bytes
;
795 for (i
= 0; i
< tlen
; i
++)
797 *bufptr
++ = buf
[i
+ offset
];
798 if (buf
[i
+ offset
] == '\000')
800 nbytes_read
+= i
+ 1;
817 /* Find a section containing ADDR. */
818 struct section_table
*
819 target_section_by_addr (struct target_ops
*target
, CORE_ADDR addr
)
821 struct section_table
*secp
;
822 for (secp
= target
->to_sections
;
823 secp
< target
->to_sections_end
;
826 if (addr
>= secp
->addr
&& addr
< secp
->endaddr
)
832 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
833 GDB's memory at MYADDR. Returns either 0 for success or an errno value
836 If an error occurs, no guarantee is made about the contents of the data at
837 MYADDR. In particular, the caller should not depend upon partial reads
838 filling the buffer with good data. There is no way for the caller to know
839 how much good data might have been transfered anyway. Callers that can
840 deal with partial reads should call target_read_memory_partial. */
843 target_read_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
845 return target_xfer_memory (memaddr
, myaddr
, len
, 0);
849 target_write_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
851 return target_xfer_memory (memaddr
, myaddr
, len
, 1);
854 static int trust_readonly
= 0;
856 /* Move memory to or from the targets. The top target gets priority;
857 if it cannot handle it, it is offered to the next one down, etc.
859 Result is -1 on error, or the number of bytes transfered. */
862 do_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
863 struct mem_attrib
*attrib
)
867 struct target_ops
*t
;
869 /* Zero length requests are ok and require no work. */
873 /* to_xfer_memory is not guaranteed to set errno, even when it returns
877 if (!write
&& trust_readonly
)
879 struct section_table
*secp
;
880 /* User-settable option, "trust-readonly-sections". If true,
881 then memory from any SEC_READONLY bfd section may be read
882 directly from the bfd file. */
883 secp
= target_section_by_addr (¤t_target
, memaddr
);
885 && (bfd_get_section_flags (secp
->bfd
, secp
->the_bfd_section
)
887 return xfer_memory (memaddr
, myaddr
, len
, 0, attrib
, ¤t_target
);
890 /* The quick case is that the top target can handle the transfer. */
891 res
= current_target
.to_xfer_memory
892 (memaddr
, myaddr
, len
, write
, attrib
, ¤t_target
);
894 /* If res <= 0 then we call it again in the loop. Ah well. */
897 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
899 if (!t
->to_has_memory
)
902 res
= t
->to_xfer_memory (memaddr
, myaddr
, len
, write
, attrib
, t
);
904 break; /* Handled all or part of xfer */
905 if (t
->to_has_all_memory
)
917 /* Perform a memory transfer. Iterate until the entire region has
920 Result is 0 or errno value. */
923 target_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
)
927 struct mem_region
*region
;
929 /* Zero length requests are ok and require no work. */
937 region
= lookup_mem_region(memaddr
);
938 if (memaddr
+ len
< region
->hi
)
941 reg_len
= region
->hi
- memaddr
;
943 switch (region
->attrib
.mode
)
958 if (region
->attrib
.cache
)
959 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
,
962 res
= do_xfer_memory (memaddr
, myaddr
, reg_len
, write
,
967 /* If this address is for nonexistent memory, read zeros
968 if reading, or do nothing if writing. Return
971 memset (myaddr
, 0, len
);
985 return 0; /* We managed to cover it all somehow. */
989 /* Perform a partial memory transfer.
991 Result is -1 on error, or the number of bytes transfered. */
994 target_xfer_memory_partial (CORE_ADDR memaddr
, char *myaddr
, int len
,
995 int write_p
, int *err
)
999 struct mem_region
*region
;
1001 /* Zero length requests are ok and require no work. */
1008 region
= lookup_mem_region(memaddr
);
1009 if (memaddr
+ len
< region
->hi
)
1012 reg_len
= region
->hi
- memaddr
;
1014 switch (region
->attrib
.mode
)
1033 if (region
->attrib
.cache
)
1034 res
= dcache_xfer_memory (target_dcache
, memaddr
, myaddr
,
1037 res
= do_xfer_memory (memaddr
, myaddr
, reg_len
, write_p
,
1055 target_read_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1057 return target_xfer_memory_partial (memaddr
, buf
, len
, 0, err
);
1061 target_write_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
1063 return target_xfer_memory_partial (memaddr
, buf
, len
, 1, err
);
1066 /* More generic transfers. */
1069 target_read_partial (struct target_ops
*ops
,
1070 enum target_object object
,
1071 const char *annex
, void *buf
,
1072 ULONGEST offset
, LONGEST len
)
1074 struct target_ops
*op
;
1076 /* Find the first target stratum that can handle the request. */
1078 op
!= NULL
&& op
->to_read_partial
== NULL
;
1084 /* Now apply the operation at that level. */
1085 return op
->to_read_partial (op
, object
, annex
, buf
, offset
, len
);
1089 target_write_partial (struct target_ops
*ops
,
1090 enum target_object object
,
1091 const char *annex
, const void *buf
,
1092 ULONGEST offset
, LONGEST len
)
1094 struct target_ops
*op
;
1096 /* Find the first target stratum that can handle the request. */
1098 op
!= NULL
&& op
->to_write_partial
== NULL
;
1104 return op
->to_write_partial (op
, object
, annex
, buf
, offset
, len
);
1107 /* Wrappers to perform the full transfer. */
1109 target_read (struct target_ops
*ops
,
1110 enum target_object object
,
1111 const char *annex
, void *buf
,
1112 ULONGEST offset
, LONGEST len
)
1115 while (xfered
< len
)
1117 LONGEST xfer
= target_write_partial (ops
, object
, annex
,
1118 (bfd_byte
*) buf
+ xfered
,
1119 offset
+ xfered
, len
- xfered
);
1120 /* Call an observer, notifying them of the xfer progress? */
1130 target_write (struct target_ops
*ops
,
1131 enum target_object object
,
1132 const char *annex
, const void *buf
,
1133 ULONGEST offset
, LONGEST len
)
1136 while (xfered
< len
)
1138 LONGEST xfer
= target_write_partial (ops
, object
, annex
,
1139 (bfd_byte
*) buf
+ xfered
,
1140 offset
+ xfered
, len
- xfered
);
1141 /* Call an observer, notifying them of the xfer progress? */
1151 target_info (char *args
, int from_tty
)
1153 struct target_ops
*t
;
1154 int has_all_mem
= 0;
1156 if (symfile_objfile
!= NULL
)
1157 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
1159 #ifdef FILES_INFO_HOOK
1160 if (FILES_INFO_HOOK ())
1164 for (t
= target_stack
; t
!= NULL
; t
= t
->beneath
)
1166 if (!t
->to_has_memory
)
1169 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
1172 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1173 printf_unfiltered ("%s:\n", t
->to_longname
);
1174 (t
->to_files_info
) (t
);
1175 has_all_mem
= t
->to_has_all_memory
;
1179 /* This is to be called by the open routine before it does
1183 target_preopen (int from_tty
)
1187 if (target_has_execution
)
1190 || query ("A program is being debugged already. Kill it? "))
1193 error ("Program not killed.");
1196 /* Calling target_kill may remove the target from the stack. But if
1197 it doesn't (which seems like a win for UDI), remove it now. */
1199 if (target_has_execution
)
1203 /* Detach a target after doing deferred register stores. */
1206 target_detach (char *args
, int from_tty
)
1208 /* Handle any optimized stores to the inferior. */
1209 #ifdef DO_DEFERRED_STORES
1212 (current_target
.to_detach
) (args
, from_tty
);
1216 target_disconnect (char *args
, int from_tty
)
1218 /* Handle any optimized stores to the inferior. */
1219 #ifdef DO_DEFERRED_STORES
1222 (current_target
.to_disconnect
) (args
, from_tty
);
1226 target_link (char *modname
, CORE_ADDR
*t_reloc
)
1228 if (STREQ (current_target
.to_shortname
, "rombug"))
1230 (current_target
.to_lookup_symbol
) (modname
, t_reloc
);
1232 error ("Unable to link to %s and get relocation in rombug", modname
);
1235 *t_reloc
= (CORE_ADDR
) -1;
1239 target_async_mask (int mask
)
1241 int saved_async_masked_status
= target_async_mask_value
;
1242 target_async_mask_value
= mask
;
1243 return saved_async_masked_status
;
1246 /* Look through the list of possible targets for a target that can
1247 execute a run or attach command without any other data. This is
1248 used to locate the default process stratum.
1250 Result is always valid (error() is called for errors). */
1252 static struct target_ops
*
1253 find_default_run_target (char *do_mesg
)
1255 struct target_ops
**t
;
1256 struct target_ops
*runable
= NULL
;
1261 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1264 if ((*t
)->to_can_run
&& target_can_run (*t
))
1272 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
1278 find_default_attach (char *args
, int from_tty
)
1280 struct target_ops
*t
;
1282 t
= find_default_run_target ("attach");
1283 (t
->to_attach
) (args
, from_tty
);
1288 find_default_create_inferior (char *exec_file
, char *allargs
, char **env
)
1290 struct target_ops
*t
;
1292 t
= find_default_run_target ("run");
1293 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
1298 default_region_size_ok_for_hw_watchpoint (int byte_count
)
1300 return (byte_count
<= DEPRECATED_REGISTER_SIZE
);
1316 return_minus_one (void)
1322 * Resize the to_sections pointer. Also make sure that anyone that
1323 * was holding on to an old value of it gets updated.
1324 * Returns the old size.
1328 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1330 struct target_ops
**t
;
1331 struct section_table
*old_value
;
1334 old_value
= target
->to_sections
;
1336 if (target
->to_sections
)
1338 old_count
= target
->to_sections_end
- target
->to_sections
;
1339 target
->to_sections
= (struct section_table
*)
1340 xrealloc ((char *) target
->to_sections
,
1341 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1346 target
->to_sections
= (struct section_table
*)
1347 xmalloc ((sizeof (struct section_table
)) * num_added
);
1349 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1351 /* Check to see if anyone else was pointing to this structure.
1352 If old_value was null, then no one was. */
1356 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1359 if ((*t
)->to_sections
== old_value
)
1361 (*t
)->to_sections
= target
->to_sections
;
1362 (*t
)->to_sections_end
= target
->to_sections_end
;
1371 /* Remove all target sections taken from ABFD.
1373 Scan the current target stack for targets whose section tables
1374 refer to sections from BFD, and remove those sections. We use this
1375 when we notice that the inferior has unloaded a shared object, for
1378 remove_target_sections (bfd
*abfd
)
1380 struct target_ops
**t
;
1382 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; t
++)
1384 struct section_table
*src
, *dest
;
1386 dest
= (*t
)->to_sections
;
1387 for (src
= (*t
)->to_sections
; src
< (*t
)->to_sections_end
; src
++)
1388 if (src
->bfd
!= abfd
)
1390 /* Keep this section. */
1391 if (dest
< src
) *dest
= *src
;
1395 /* If we've dropped any sections, resize the section table. */
1397 target_resize_to_sections (*t
, dest
- src
);
1404 /* Find a single runnable target in the stack and return it. If for
1405 some reason there is more than one, return NULL. */
1408 find_run_target (void)
1410 struct target_ops
**t
;
1411 struct target_ops
*runable
= NULL
;
1416 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1418 if ((*t
)->to_can_run
&& target_can_run (*t
))
1425 return (count
== 1 ? runable
: NULL
);
1428 /* Find a single core_stratum target in the list of targets and return it.
1429 If for some reason there is more than one, return NULL. */
1432 find_core_target (void)
1434 struct target_ops
**t
;
1435 struct target_ops
*runable
= NULL
;
1440 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1443 if ((*t
)->to_stratum
== core_stratum
)
1450 return (count
== 1 ? runable
: NULL
);
1454 * Find the next target down the stack from the specified target.
1458 find_target_beneath (struct target_ops
*t
)
1464 /* The inferior process has died. Long live the inferior! */
1467 generic_mourn_inferior (void)
1469 extern int show_breakpoint_hit_counts
;
1471 inferior_ptid
= null_ptid
;
1473 breakpoint_init_inferior (inf_exited
);
1474 registers_changed ();
1476 #ifdef CLEAR_DEFERRED_STORES
1477 /* Delete any pending stores to the inferior... */
1478 CLEAR_DEFERRED_STORES
;
1481 reopen_exec_file ();
1482 reinit_frame_cache ();
1484 /* It is confusing to the user for ignore counts to stick around
1485 from previous runs of the inferior. So clear them. */
1486 /* However, it is more confusing for the ignore counts to disappear when
1487 using hit counts. So don't clear them if we're counting hits. */
1488 if (!show_breakpoint_hit_counts
)
1489 breakpoint_clear_ignore_counts ();
1495 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1496 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1497 translation of that in OURSTATUS. */
1499 store_waitstatus (struct target_waitstatus
*ourstatus
, int hoststatus
)
1501 #ifdef CHILD_SPECIAL_WAITSTATUS
1502 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1503 if it wants to deal with hoststatus. */
1504 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
1508 if (WIFEXITED (hoststatus
))
1510 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1511 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
1513 else if (!WIFSTOPPED (hoststatus
))
1515 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1516 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
1520 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
1521 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
1525 /* Returns zero to leave the inferior alone, one to interrupt it. */
1526 int (*target_activity_function
) (void);
1527 int target_activity_fd
;
1529 /* Convert a normal process ID to a string. Returns the string in a static
1533 normal_pid_to_str (ptid_t ptid
)
1535 static char buf
[30];
1537 sprintf (buf
, "process %d", PIDGET (ptid
));
1541 /* Some targets (such as ttrace-based HPUX) don't allow us to request
1542 notification of inferior events such as fork and vork immediately
1543 after the inferior is created. (This because of how gdb gets an
1544 inferior created via invoking a shell to do it. In such a scenario,
1545 if the shell init file has commands in it, the shell will fork and
1546 exec for each of those commands, and we will see each such fork
1549 This function is used by all targets that allow us to request
1550 notification of forks, etc at inferior creation time; e.g., in
1551 target_acknowledge_forked_child.
1554 normal_target_post_startup_inferior (ptid_t ptid
)
1556 /* This space intentionally left blank. */
1559 /* Error-catcher for target_find_memory_regions */
1560 static int dummy_find_memory_regions (int (*ignore1
) (), void *ignore2
)
1562 error ("No target.");
1566 /* Error-catcher for target_make_corefile_notes */
1567 static char * dummy_make_corefile_notes (bfd
*ignore1
, int *ignore2
)
1569 error ("No target.");
1573 /* Set up the handful of non-empty slots needed by the dummy target
1577 init_dummy_target (void)
1579 dummy_target
.to_shortname
= "None";
1580 dummy_target
.to_longname
= "None";
1581 dummy_target
.to_doc
= "";
1582 dummy_target
.to_attach
= find_default_attach
;
1583 dummy_target
.to_create_inferior
= find_default_create_inferior
;
1584 dummy_target
.to_pid_to_str
= normal_pid_to_str
;
1585 dummy_target
.to_stratum
= dummy_stratum
;
1586 dummy_target
.to_find_memory_regions
= dummy_find_memory_regions
;
1587 dummy_target
.to_make_corefile_notes
= dummy_make_corefile_notes
;
1588 dummy_target
.to_magic
= OPS_MAGIC
;
1592 static struct target_ops debug_target
;
1595 debug_to_open (char *args
, int from_tty
)
1597 debug_target
.to_open (args
, from_tty
);
1599 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
1603 debug_to_close (int quitting
)
1605 debug_target
.to_close (quitting
);
1607 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
1611 debug_to_attach (char *args
, int from_tty
)
1613 debug_target
.to_attach (args
, from_tty
);
1615 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
1620 debug_to_post_attach (int pid
)
1622 debug_target
.to_post_attach (pid
);
1624 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
1628 debug_to_detach (char *args
, int from_tty
)
1630 debug_target
.to_detach (args
, from_tty
);
1632 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
1636 debug_to_disconnect (char *args
, int from_tty
)
1638 debug_target
.to_disconnect (args
, from_tty
);
1640 fprintf_unfiltered (gdb_stdlog
, "target_disconnect (%s, %d)\n",
1645 debug_to_resume (ptid_t ptid
, int step
, enum target_signal siggnal
)
1647 debug_target
.to_resume (ptid
, step
, siggnal
);
1649 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", PIDGET (ptid
),
1650 step
? "step" : "continue",
1651 target_signal_to_name (siggnal
));
1655 debug_to_wait (ptid_t ptid
, struct target_waitstatus
*status
)
1659 retval
= debug_target
.to_wait (ptid
, status
);
1661 fprintf_unfiltered (gdb_stdlog
,
1662 "target_wait (%d, status) = %d, ", PIDGET (ptid
),
1664 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
1665 switch (status
->kind
)
1667 case TARGET_WAITKIND_EXITED
:
1668 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
1669 status
->value
.integer
);
1671 case TARGET_WAITKIND_STOPPED
:
1672 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
1673 target_signal_to_name (status
->value
.sig
));
1675 case TARGET_WAITKIND_SIGNALLED
:
1676 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
1677 target_signal_to_name (status
->value
.sig
));
1679 case TARGET_WAITKIND_LOADED
:
1680 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
1682 case TARGET_WAITKIND_FORKED
:
1683 fprintf_unfiltered (gdb_stdlog
, "forked\n");
1685 case TARGET_WAITKIND_VFORKED
:
1686 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
1688 case TARGET_WAITKIND_EXECD
:
1689 fprintf_unfiltered (gdb_stdlog
, "execd\n");
1691 case TARGET_WAITKIND_SPURIOUS
:
1692 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
1695 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
1703 debug_to_post_wait (ptid_t ptid
, int status
)
1705 debug_target
.to_post_wait (ptid
, status
);
1707 fprintf_unfiltered (gdb_stdlog
, "target_post_wait (%d, %d)\n",
1708 PIDGET (ptid
), status
);
1712 debug_print_register (const char * func
, int regno
)
1714 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
1715 if (regno
>= 0 && regno
< NUM_REGS
+ NUM_PSEUDO_REGS
1716 && REGISTER_NAME (regno
) != NULL
&& REGISTER_NAME (regno
)[0] != '\0')
1717 fprintf_unfiltered (gdb_stdlog
, "(%s)", REGISTER_NAME (regno
));
1719 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
1723 unsigned char buf
[MAX_REGISTER_SIZE
];
1724 deprecated_read_register_gen (regno
, buf
);
1725 fprintf_unfiltered (gdb_stdlog
, " = ");
1726 for (i
= 0; i
< DEPRECATED_REGISTER_RAW_SIZE (regno
); i
++)
1728 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
1730 if (DEPRECATED_REGISTER_RAW_SIZE (regno
) <= sizeof (LONGEST
))
1732 fprintf_unfiltered (gdb_stdlog
, " 0x%s %s",
1733 paddr_nz (read_register (regno
)),
1734 paddr_d (read_register (regno
)));
1737 fprintf_unfiltered (gdb_stdlog
, "\n");
1741 debug_to_fetch_registers (int regno
)
1743 debug_target
.to_fetch_registers (regno
);
1744 debug_print_register ("target_fetch_registers", regno
);
1748 debug_to_store_registers (int regno
)
1750 debug_target
.to_store_registers (regno
);
1751 debug_print_register ("target_store_registers", regno
);
1752 fprintf_unfiltered (gdb_stdlog
, "\n");
1756 debug_to_prepare_to_store (void)
1758 debug_target
.to_prepare_to_store ();
1760 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
1764 debug_to_xfer_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
1765 struct mem_attrib
*attrib
,
1766 struct target_ops
*target
)
1770 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
,
1773 fprintf_unfiltered (gdb_stdlog
,
1774 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
1775 (unsigned int) memaddr
, /* possable truncate long long */
1776 len
, write
? "write" : "read", retval
);
1784 fputs_unfiltered (", bytes =", gdb_stdlog
);
1785 for (i
= 0; i
< retval
; i
++)
1787 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
1788 fprintf_unfiltered (gdb_stdlog
, "\n");
1789 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
1793 fputc_unfiltered ('\n', gdb_stdlog
);
1799 debug_to_files_info (struct target_ops
*target
)
1801 debug_target
.to_files_info (target
);
1803 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
1807 debug_to_insert_breakpoint (CORE_ADDR addr
, char *save
)
1811 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
1813 fprintf_unfiltered (gdb_stdlog
,
1814 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
1815 (unsigned long) addr
,
1816 (unsigned long) retval
);
1821 debug_to_remove_breakpoint (CORE_ADDR addr
, char *save
)
1825 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
1827 fprintf_unfiltered (gdb_stdlog
,
1828 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
1829 (unsigned long) addr
,
1830 (unsigned long) retval
);
1835 debug_to_can_use_hw_breakpoint (int type
, int cnt
, int from_tty
)
1839 retval
= debug_target
.to_can_use_hw_breakpoint (type
, cnt
, from_tty
);
1841 fprintf_unfiltered (gdb_stdlog
,
1842 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
1843 (unsigned long) type
,
1844 (unsigned long) cnt
,
1845 (unsigned long) from_tty
,
1846 (unsigned long) retval
);
1851 debug_to_region_size_ok_for_hw_watchpoint (int byte_count
)
1855 retval
= debug_target
.to_region_size_ok_for_hw_watchpoint (byte_count
);
1857 fprintf_unfiltered (gdb_stdlog
,
1858 "TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT (%ld) = 0x%lx\n",
1859 (unsigned long) byte_count
,
1860 (unsigned long) retval
);
1865 debug_to_stopped_by_watchpoint (void)
1869 retval
= debug_target
.to_stopped_by_watchpoint ();
1871 fprintf_unfiltered (gdb_stdlog
,
1872 "STOPPED_BY_WATCHPOINT () = %ld\n",
1873 (unsigned long) retval
);
1878 debug_to_stopped_data_address (void)
1882 retval
= debug_target
.to_stopped_data_address ();
1884 fprintf_unfiltered (gdb_stdlog
,
1885 "target_stopped_data_address () = 0x%lx\n",
1886 (unsigned long) retval
);
1891 debug_to_insert_hw_breakpoint (CORE_ADDR addr
, char *save
)
1895 retval
= debug_target
.to_insert_hw_breakpoint (addr
, save
);
1897 fprintf_unfiltered (gdb_stdlog
,
1898 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
1899 (unsigned long) addr
,
1900 (unsigned long) retval
);
1905 debug_to_remove_hw_breakpoint (CORE_ADDR addr
, char *save
)
1909 retval
= debug_target
.to_remove_hw_breakpoint (addr
, save
);
1911 fprintf_unfiltered (gdb_stdlog
,
1912 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
1913 (unsigned long) addr
,
1914 (unsigned long) retval
);
1919 debug_to_insert_watchpoint (CORE_ADDR addr
, int len
, int type
)
1923 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
1925 fprintf_unfiltered (gdb_stdlog
,
1926 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1927 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
1932 debug_to_remove_watchpoint (CORE_ADDR addr
, int len
, int type
)
1936 retval
= debug_target
.to_insert_watchpoint (addr
, len
, type
);
1938 fprintf_unfiltered (gdb_stdlog
,
1939 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1940 (unsigned long) addr
, len
, type
, (unsigned long) retval
);
1945 debug_to_terminal_init (void)
1947 debug_target
.to_terminal_init ();
1949 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
1953 debug_to_terminal_inferior (void)
1955 debug_target
.to_terminal_inferior ();
1957 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
1961 debug_to_terminal_ours_for_output (void)
1963 debug_target
.to_terminal_ours_for_output ();
1965 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
1969 debug_to_terminal_ours (void)
1971 debug_target
.to_terminal_ours ();
1973 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
1977 debug_to_terminal_save_ours (void)
1979 debug_target
.to_terminal_save_ours ();
1981 fprintf_unfiltered (gdb_stdlog
, "target_terminal_save_ours ()\n");
1985 debug_to_terminal_info (char *arg
, int from_tty
)
1987 debug_target
.to_terminal_info (arg
, from_tty
);
1989 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
1994 debug_to_kill (void)
1996 debug_target
.to_kill ();
1998 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
2002 debug_to_load (char *args
, int from_tty
)
2004 debug_target
.to_load (args
, from_tty
);
2006 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
2010 debug_to_lookup_symbol (char *name
, CORE_ADDR
*addrp
)
2014 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
2016 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
2022 debug_to_create_inferior (char *exec_file
, char *args
, char **env
)
2024 debug_target
.to_create_inferior (exec_file
, args
, env
);
2026 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx)\n",
2031 debug_to_post_startup_inferior (ptid_t ptid
)
2033 debug_target
.to_post_startup_inferior (ptid
);
2035 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
2040 debug_to_acknowledge_created_inferior (int pid
)
2042 debug_target
.to_acknowledge_created_inferior (pid
);
2044 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
2049 debug_to_insert_fork_catchpoint (int pid
)
2053 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
2055 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
2062 debug_to_remove_fork_catchpoint (int pid
)
2066 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
2068 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
2075 debug_to_insert_vfork_catchpoint (int pid
)
2079 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
2081 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)= %d\n",
2088 debug_to_remove_vfork_catchpoint (int pid
)
2092 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
2094 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
2101 debug_to_follow_fork (int follow_child
)
2103 int retval
= debug_target
.to_follow_fork (follow_child
);
2105 fprintf_unfiltered (gdb_stdlog
, "target_follow_fork (%d) = %d\n",
2106 follow_child
, retval
);
2112 debug_to_insert_exec_catchpoint (int pid
)
2116 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
2118 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
2125 debug_to_remove_exec_catchpoint (int pid
)
2129 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
2131 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2138 debug_to_reported_exec_events_per_exec_call (void)
2140 int reported_exec_events
;
2142 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2144 fprintf_unfiltered (gdb_stdlog
,
2145 "target_reported_exec_events_per_exec_call () = %d\n",
2146 reported_exec_events
);
2148 return reported_exec_events
;
2152 debug_to_has_exited (int pid
, int wait_status
, int *exit_status
)
2156 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2158 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2159 pid
, wait_status
, *exit_status
, has_exited
);
2165 debug_to_mourn_inferior (void)
2167 debug_target
.to_mourn_inferior ();
2169 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2173 debug_to_can_run (void)
2177 retval
= debug_target
.to_can_run ();
2179 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2185 debug_to_notice_signals (ptid_t ptid
)
2187 debug_target
.to_notice_signals (ptid
);
2189 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n",
2194 debug_to_thread_alive (ptid_t ptid
)
2198 retval
= debug_target
.to_thread_alive (ptid
);
2200 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2201 PIDGET (ptid
), retval
);
2207 debug_to_find_new_threads (void)
2209 debug_target
.to_find_new_threads ();
2211 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog
);
2215 debug_to_stop (void)
2217 debug_target
.to_stop ();
2219 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2223 debug_to_read_partial (struct target_ops
*ops
,
2224 enum target_object object
,
2225 const char *annex
, void *buf
,
2226 ULONGEST offset
, LONGEST len
)
2230 retval
= target_read_partial (&debug_target
, object
, annex
, buf
, offset
,
2233 fprintf_unfiltered (gdb_stdlog
,
2234 "target_read_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n",
2235 (int) object
, (annex
? annex
: "(null)"),
2236 (long) buf
, paddr_nz (offset
),
2237 paddr_d (len
), paddr_d (retval
));
2243 debug_to_write_partial (struct target_ops
*ops
,
2244 enum target_object object
,
2245 const char *annex
, const void *buf
,
2246 ULONGEST offset
, LONGEST len
)
2250 retval
= target_write_partial (&debug_target
, object
, annex
, buf
, offset
,
2253 fprintf_unfiltered (gdb_stdlog
,
2254 "target_write_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n",
2255 (int) object
, (annex
? annex
: "(null)"),
2256 (long) buf
, paddr_nz (offset
),
2257 paddr_d (len
), paddr_d (retval
));
2263 debug_to_rcmd (char *command
,
2264 struct ui_file
*outbuf
)
2266 debug_target
.to_rcmd (command
, outbuf
);
2267 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2270 static struct symtab_and_line
*
2271 debug_to_enable_exception_callback (enum exception_event_kind kind
, int enable
)
2273 struct symtab_and_line
*result
;
2274 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2275 fprintf_unfiltered (gdb_stdlog
,
2276 "target get_exception_callback_sal (%d, %d)\n",
2281 static struct exception_event_record
*
2282 debug_to_get_current_exception_event (void)
2284 struct exception_event_record
*result
;
2285 result
= debug_target
.to_get_current_exception_event ();
2286 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2291 debug_to_pid_to_exec_file (int pid
)
2295 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2297 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2304 setup_target_debug (void)
2306 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2308 current_target
.to_open
= debug_to_open
;
2309 current_target
.to_close
= debug_to_close
;
2310 current_target
.to_attach
= debug_to_attach
;
2311 current_target
.to_post_attach
= debug_to_post_attach
;
2312 current_target
.to_detach
= debug_to_detach
;
2313 current_target
.to_disconnect
= debug_to_disconnect
;
2314 current_target
.to_resume
= debug_to_resume
;
2315 current_target
.to_wait
= debug_to_wait
;
2316 current_target
.to_post_wait
= debug_to_post_wait
;
2317 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2318 current_target
.to_store_registers
= debug_to_store_registers
;
2319 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2320 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2321 current_target
.to_files_info
= debug_to_files_info
;
2322 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2323 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2324 current_target
.to_can_use_hw_breakpoint
= debug_to_can_use_hw_breakpoint
;
2325 current_target
.to_insert_hw_breakpoint
= debug_to_insert_hw_breakpoint
;
2326 current_target
.to_remove_hw_breakpoint
= debug_to_remove_hw_breakpoint
;
2327 current_target
.to_insert_watchpoint
= debug_to_insert_watchpoint
;
2328 current_target
.to_remove_watchpoint
= debug_to_remove_watchpoint
;
2329 current_target
.to_stopped_by_watchpoint
= debug_to_stopped_by_watchpoint
;
2330 current_target
.to_stopped_data_address
= debug_to_stopped_data_address
;
2331 current_target
.to_region_size_ok_for_hw_watchpoint
= debug_to_region_size_ok_for_hw_watchpoint
;
2332 current_target
.to_terminal_init
= debug_to_terminal_init
;
2333 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2334 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2335 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2336 current_target
.to_terminal_save_ours
= debug_to_terminal_save_ours
;
2337 current_target
.to_terminal_info
= debug_to_terminal_info
;
2338 current_target
.to_kill
= debug_to_kill
;
2339 current_target
.to_load
= debug_to_load
;
2340 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2341 current_target
.to_create_inferior
= debug_to_create_inferior
;
2342 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2343 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2344 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2345 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2346 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2347 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2348 current_target
.to_follow_fork
= debug_to_follow_fork
;
2349 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2350 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2351 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2352 current_target
.to_has_exited
= debug_to_has_exited
;
2353 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2354 current_target
.to_can_run
= debug_to_can_run
;
2355 current_target
.to_notice_signals
= debug_to_notice_signals
;
2356 current_target
.to_thread_alive
= debug_to_thread_alive
;
2357 current_target
.to_find_new_threads
= debug_to_find_new_threads
;
2358 current_target
.to_stop
= debug_to_stop
;
2359 current_target
.to_read_partial
= debug_to_read_partial
;
2360 current_target
.to_write_partial
= debug_to_write_partial
;
2361 current_target
.to_rcmd
= debug_to_rcmd
;
2362 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
2363 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
2364 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2369 static char targ_desc
[] =
2370 "Names of targets and files being debugged.\n\
2371 Shows the entire stack of targets currently in use (including the exec-file,\n\
2372 core-file, and process, if any), as well as the symbol file name.";
2375 do_monitor_command (char *cmd
,
2378 if ((current_target
.to_rcmd
2379 == (void (*) (char *, struct ui_file
*)) tcomplain
)
2380 || (current_target
.to_rcmd
== debug_to_rcmd
2381 && (debug_target
.to_rcmd
2382 == (void (*) (char *, struct ui_file
*)) tcomplain
)))
2384 error ("\"monitor\" command not supported by this target.\n");
2386 target_rcmd (cmd
, gdb_stdtarg
);
2390 initialize_targets (void)
2392 init_dummy_target ();
2393 push_target (&dummy_target
);
2395 add_info ("target", target_info
, targ_desc
);
2396 add_info ("files", target_info
, targ_desc
);
2399 (add_set_cmd ("target", class_maintenance
, var_zinteger
,
2400 (char *) &targetdebug
,
2401 "Set target debugging.\n\
2402 When non-zero, target debugging is enabled.", &setdebuglist
),
2405 add_setshow_boolean_cmd ("trust-readonly-sections", class_support
,
2407 Set mode for reading from readonly sections.\n\
2408 When this mode is on, memory reads from readonly sections (such as .text)\n\
2409 will be read from the object file instead of from the target. This will\n\
2410 result in significant performance improvement for remote targets.", "\
2411 Show mode for reading from readonly sections.\n",
2413 &setlist
, &showlist
);
2415 add_com ("monitor", class_obscure
, do_monitor_command
,
2416 "Send a command to the remote monitor (remote targets only).");
2418 target_dcache
= dcache_init ();