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 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
818 GDB's memory at MYADDR. Returns either 0 for success or an errno value
821 If an error occurs, no guarantee is made about the contents of the data at
822 MYADDR. In particular, the caller should not depend upon partial reads
823 filling the buffer with good data. There is no way for the caller to know
824 how much good data might have been transfered anyway. Callers that can
825 deal with partial reads should call target_read_memory_partial. */
828 target_read_memory (CORE_ADDR memaddr, char *myaddr, int len)
830 return target_xfer_memory (memaddr, myaddr, len, 0);
834 target_write_memory (CORE_ADDR memaddr, char *myaddr, int len)
836 return target_xfer_memory (memaddr, myaddr, len, 1);
839 static int trust_readonly = 0;
841 /* Move memory to or from the targets. The top target gets priority;
842 if it cannot handle it, it is offered to the next one down, etc.
844 Result is -1 on error, or the number of bytes transfered. */
847 do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
848 struct mem_attrib *attrib)
852 struct target_ops *t;
854 /* Zero length requests are ok and require no work. */
858 /* to_xfer_memory is not guaranteed to set errno, even when it returns
862 if (!write && trust_readonly)
864 /* User-settable option, "trust-readonly-sections". If true,
865 then memory from any SEC_READONLY bfd section may be read
866 directly from the bfd file. */
868 struct section_table *secp;
870 for (secp = current_target.to_sections;
871 secp < current_target.to_sections_end;
874 if (bfd_get_section_flags (secp->bfd, secp->the_bfd_section)
876 if (memaddr >= secp->addr && memaddr < secp->endaddr)
877 return xfer_memory (memaddr, myaddr, len, 0,
878 attrib, ¤t_target);
882 /* The quick case is that the top target can handle the transfer. */
883 res = current_target.to_xfer_memory
884 (memaddr, myaddr, len, write, attrib, ¤t_target);
886 /* If res <= 0 then we call it again in the loop. Ah well. */
889 for (t = target_stack; t != NULL; t = t->beneath)
891 if (!t->to_has_memory)
894 res = t->to_xfer_memory (memaddr, myaddr, len, write, attrib, t);
896 break; /* Handled all or part of xfer */
897 if (t->to_has_all_memory)
909 /* Perform a memory transfer. Iterate until the entire region has
912 Result is 0 or errno value. */
915 target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write)
919 struct mem_region *region;
921 /* Zero length requests are ok and require no work. */
929 region = lookup_mem_region(memaddr);
930 if (memaddr + len < region->hi)
933 reg_len = region->hi - memaddr;
935 switch (region->attrib.mode)
950 if (region->attrib.cache)
951 res = dcache_xfer_memory (target_dcache, memaddr, myaddr,
954 res = do_xfer_memory (memaddr, myaddr, reg_len, write,
959 /* If this address is for nonexistent memory, read zeros
960 if reading, or do nothing if writing. Return
963 memset (myaddr, 0, len);
977 return 0; /* We managed to cover it all somehow. */
981 /* Perform a partial memory transfer.
983 Result is -1 on error, or the number of bytes transfered. */
986 target_xfer_memory_partial (CORE_ADDR memaddr, char *myaddr, int len,
987 int write_p, int *err)
991 struct mem_region *region;
993 /* Zero length requests are ok and require no work. */
1000 region = lookup_mem_region(memaddr);
1001 if (memaddr + len < region->hi)
1004 reg_len = region->hi - memaddr;
1006 switch (region->attrib.mode)
1025 if (region->attrib.cache)
1026 res = dcache_xfer_memory (target_dcache, memaddr, myaddr,
1029 res = do_xfer_memory (memaddr, myaddr, reg_len, write_p,
1047 target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1049 return target_xfer_memory_partial (memaddr, buf, len, 0, err);
1053 target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1055 return target_xfer_memory_partial (memaddr, buf, len, 1, err);
1058 /* More generic transfers. */
1061 target_read_partial (struct target_ops *ops,
1062 enum target_object object,
1063 const char *annex, void *buf,
1064 ULONGEST offset, LONGEST len)
1066 struct target_ops *op;
1068 /* Find the first target stratum that can handle the request. */
1070 op != NULL && op->to_read_partial == NULL;
1076 /* Now apply the operation at that level. */
1077 return op->to_read_partial (op, object, annex, buf, offset, len);
1081 target_write_partial (struct target_ops *ops,
1082 enum target_object object,
1083 const char *annex, const void *buf,
1084 ULONGEST offset, LONGEST len)
1086 struct target_ops *op;
1088 /* Find the first target stratum that can handle the request. */
1090 op != NULL && op->to_write_partial == NULL;
1096 return op->to_write_partial (op, object, annex, buf, offset, len);
1099 /* Wrappers to perform the full transfer. */
1101 target_read (struct target_ops *ops,
1102 enum target_object object,
1103 const char *annex, void *buf,
1104 ULONGEST offset, LONGEST len)
1107 while (xfered < len)
1109 LONGEST xfer = target_write_partial (ops, object, annex,
1110 (bfd_byte *) buf + xfered,
1111 offset + xfered, len - xfered);
1112 /* Call an observer, notifying them of the xfer progress? */
1122 target_write (struct target_ops *ops,
1123 enum target_object object,
1124 const char *annex, const void *buf,
1125 ULONGEST offset, LONGEST len)
1128 while (xfered < len)
1130 LONGEST xfer = target_write_partial (ops, object, annex,
1131 (bfd_byte *) buf + xfered,
1132 offset + xfered, len - xfered);
1133 /* Call an observer, notifying them of the xfer progress? */
1143 target_info (char *args, int from_tty)
1145 struct target_ops *t;
1146 int has_all_mem = 0;
1148 if (symfile_objfile != NULL)
1149 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile->name);
1151 #ifdef FILES_INFO_HOOK
1152 if (FILES_INFO_HOOK ())
1156 for (t = target_stack; t != NULL; t = t->beneath)
1158 if (!t->to_has_memory)
1161 if ((int) (t->to_stratum) <= (int) dummy_stratum)
1164 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1165 printf_unfiltered ("%s:\n", t->to_longname);
1166 (t->to_files_info) (t);
1167 has_all_mem = t->to_has_all_memory;
1171 /* This is to be called by the open routine before it does
1175 target_preopen (int from_tty)
1179 if (target_has_execution)
1182 || query ("A program is being debugged already. Kill it? "))
1185 error ("Program not killed.");
1188 /* Calling target_kill may remove the target from the stack. But if
1189 it doesn't (which seems like a win for UDI), remove it now. */
1191 if (target_has_execution)
1195 /* Detach a target after doing deferred register stores. */
1198 target_detach (char *args, int from_tty)
1200 /* Handle any optimized stores to the inferior. */
1201 #ifdef DO_DEFERRED_STORES
1204 (current_target.to_detach) (args, from_tty);
1208 target_disconnect (char *args, int from_tty)
1210 /* Handle any optimized stores to the inferior. */
1211 #ifdef DO_DEFERRED_STORES
1214 (current_target.to_disconnect) (args, from_tty);
1218 target_link (char *modname, CORE_ADDR *t_reloc)
1220 if (STREQ (current_target.to_shortname, "rombug"))
1222 (current_target.to_lookup_symbol) (modname, t_reloc);
1224 error ("Unable to link to %s and get relocation in rombug", modname);
1227 *t_reloc = (CORE_ADDR) -1;
1231 target_async_mask (int mask)
1233 int saved_async_masked_status = target_async_mask_value;
1234 target_async_mask_value = mask;
1235 return saved_async_masked_status;
1238 /* Look through the list of possible targets for a target that can
1239 execute a run or attach command without any other data. This is
1240 used to locate the default process stratum.
1242 Result is always valid (error() is called for errors). */
1244 static struct target_ops *
1245 find_default_run_target (char *do_mesg)
1247 struct target_ops **t;
1248 struct target_ops *runable = NULL;
1253 for (t = target_structs; t < target_structs + target_struct_size;
1256 if ((*t)->to_can_run && target_can_run (*t))
1264 error ("Don't know how to %s. Try \"help target\".", do_mesg);
1270 find_default_attach (char *args, int from_tty)
1272 struct target_ops *t;
1274 t = find_default_run_target ("attach");
1275 (t->to_attach) (args, from_tty);
1280 find_default_create_inferior (char *exec_file, char *allargs, char **env)
1282 struct target_ops *t;
1284 t = find_default_run_target ("run");
1285 (t->to_create_inferior) (exec_file, allargs, env);
1290 default_region_size_ok_for_hw_watchpoint (int byte_count)
1292 return (byte_count <= DEPRECATED_REGISTER_SIZE);
1308 return_minus_one (void)
1314 * Resize the to_sections pointer. Also make sure that anyone that
1315 * was holding on to an old value of it gets updated.
1316 * Returns the old size.
1320 target_resize_to_sections (struct target_ops *target, int num_added)
1322 struct target_ops **t;
1323 struct section_table *old_value;
1326 old_value = target->to_sections;
1328 if (target->to_sections)
1330 old_count = target->to_sections_end - target->to_sections;
1331 target->to_sections = (struct section_table *)
1332 xrealloc ((char *) target->to_sections,
1333 (sizeof (struct section_table)) * (num_added + old_count));
1338 target->to_sections = (struct section_table *)
1339 xmalloc ((sizeof (struct section_table)) * num_added);
1341 target->to_sections_end = target->to_sections + (num_added + old_count);
1343 /* Check to see if anyone else was pointing to this structure.
1344 If old_value was null, then no one was. */
1348 for (t = target_structs; t < target_structs + target_struct_size;
1351 if ((*t)->to_sections == old_value)
1353 (*t)->to_sections = target->to_sections;
1354 (*t)->to_sections_end = target->to_sections_end;
1363 /* Remove all target sections taken from ABFD.
1365 Scan the current target stack for targets whose section tables
1366 refer to sections from BFD, and remove those sections. We use this
1367 when we notice that the inferior has unloaded a shared object, for
1370 remove_target_sections (bfd *abfd)
1372 struct target_ops **t;
1374 for (t = target_structs; t < target_structs + target_struct_size; t++)
1376 struct section_table *src, *dest;
1378 dest = (*t)->to_sections;
1379 for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++)
1380 if (src->bfd != abfd)
1382 /* Keep this section. */
1383 if (dest < src) *dest = *src;
1387 /* If we've dropped any sections, resize the section table. */
1389 target_resize_to_sections (*t, dest - src);
1396 /* Find a single runnable target in the stack and return it. If for
1397 some reason there is more than one, return NULL. */
1400 find_run_target (void)
1402 struct target_ops **t;
1403 struct target_ops *runable = NULL;
1408 for (t = target_structs; t < target_structs + target_struct_size; ++t)
1410 if ((*t)->to_can_run && target_can_run (*t))
1417 return (count == 1 ? runable : NULL);
1420 /* Find a single core_stratum target in the list of targets and return it.
1421 If for some reason there is more than one, return NULL. */
1424 find_core_target (void)
1426 struct target_ops **t;
1427 struct target_ops *runable = NULL;
1432 for (t = target_structs; t < target_structs + target_struct_size;
1435 if ((*t)->to_stratum == core_stratum)
1442 return (count == 1 ? runable : NULL);
1446 * Find the next target down the stack from the specified target.
1450 find_target_beneath (struct target_ops *t)
1456 /* The inferior process has died. Long live the inferior! */
1459 generic_mourn_inferior (void)
1461 extern int show_breakpoint_hit_counts;
1463 inferior_ptid = null_ptid;
1465 breakpoint_init_inferior (inf_exited);
1466 registers_changed ();
1468 #ifdef CLEAR_DEFERRED_STORES
1469 /* Delete any pending stores to the inferior... */
1470 CLEAR_DEFERRED_STORES;
1473 reopen_exec_file ();
1474 reinit_frame_cache ();
1476 /* It is confusing to the user for ignore counts to stick around
1477 from previous runs of the inferior. So clear them. */
1478 /* However, it is more confusing for the ignore counts to disappear when
1479 using hit counts. So don't clear them if we're counting hits. */
1480 if (!show_breakpoint_hit_counts)
1481 breakpoint_clear_ignore_counts ();
1487 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1488 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1489 translation of that in OURSTATUS. */
1491 store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus)
1493 #ifdef CHILD_SPECIAL_WAITSTATUS
1494 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1495 if it wants to deal with hoststatus. */
1496 if (CHILD_SPECIAL_WAITSTATUS (ourstatus, hoststatus))
1500 if (WIFEXITED (hoststatus))
1502 ourstatus->kind = TARGET_WAITKIND_EXITED;
1503 ourstatus->value.integer = WEXITSTATUS (hoststatus);
1505 else if (!WIFSTOPPED (hoststatus))
1507 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
1508 ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus));
1512 ourstatus->kind = TARGET_WAITKIND_STOPPED;
1513 ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus));
1517 /* Returns zero to leave the inferior alone, one to interrupt it. */
1518 int (*target_activity_function) (void);
1519 int target_activity_fd;
1521 /* Convert a normal process ID to a string. Returns the string in a static
1525 normal_pid_to_str (ptid_t ptid)
1527 static char buf[30];
1529 sprintf (buf, "process %d", PIDGET (ptid));
1533 /* Some targets (such as ttrace-based HPUX) don't allow us to request
1534 notification of inferior events such as fork and vork immediately
1535 after the inferior is created. (This because of how gdb gets an
1536 inferior created via invoking a shell to do it. In such a scenario,
1537 if the shell init file has commands in it, the shell will fork and
1538 exec for each of those commands, and we will see each such fork
1541 This function is used by all targets that allow us to request
1542 notification of forks, etc at inferior creation time; e.g., in
1543 target_acknowledge_forked_child.
1546 normal_target_post_startup_inferior (ptid_t ptid)
1548 /* This space intentionally left blank. */
1551 /* Error-catcher for target_find_memory_regions */
1552 static int dummy_find_memory_regions (int (*ignore1) (), void *ignore2)
1554 error ("No target.");
1558 /* Error-catcher for target_make_corefile_notes */
1559 static char * dummy_make_corefile_notes (bfd *ignore1, int *ignore2)
1561 error ("No target.");
1565 /* Set up the handful of non-empty slots needed by the dummy target
1569 init_dummy_target (void)
1571 dummy_target.to_shortname = "None";
1572 dummy_target.to_longname = "None";
1573 dummy_target.to_doc = "";
1574 dummy_target.to_attach = find_default_attach;
1575 dummy_target.to_create_inferior = find_default_create_inferior;
1576 dummy_target.to_pid_to_str = normal_pid_to_str;
1577 dummy_target.to_stratum = dummy_stratum;
1578 dummy_target.to_find_memory_regions = dummy_find_memory_regions;
1579 dummy_target.to_make_corefile_notes = dummy_make_corefile_notes;
1580 dummy_target.to_magic = OPS_MAGIC;
1584 static struct target_ops debug_target;
1587 debug_to_open (char *args, int from_tty)
1589 debug_target.to_open (args, from_tty);
1591 fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty);
1595 debug_to_close (int quitting)
1597 debug_target.to_close (quitting);
1599 fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting);
1603 debug_to_attach (char *args, int from_tty)
1605 debug_target.to_attach (args, from_tty);
1607 fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty);
1612 debug_to_post_attach (int pid)
1614 debug_target.to_post_attach (pid);
1616 fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid);
1620 debug_to_detach (char *args, int from_tty)
1622 debug_target.to_detach (args, from_tty);
1624 fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty);
1628 debug_to_disconnect (char *args, int from_tty)
1630 debug_target.to_disconnect (args, from_tty);
1632 fprintf_unfiltered (gdb_stdlog, "target_disconnect (%s, %d)\n",
1637 debug_to_resume (ptid_t ptid, int step, enum target_signal siggnal)
1639 debug_target.to_resume (ptid, step, siggnal);
1641 fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", PIDGET (ptid),
1642 step ? "step" : "continue",
1643 target_signal_to_name (siggnal));
1647 debug_to_wait (ptid_t ptid, struct target_waitstatus *status)
1651 retval = debug_target.to_wait (ptid, status);
1653 fprintf_unfiltered (gdb_stdlog,
1654 "target_wait (%d, status) = %d, ", PIDGET (ptid),
1656 fprintf_unfiltered (gdb_stdlog, "status->kind = ");
1657 switch (status->kind)
1659 case TARGET_WAITKIND_EXITED:
1660 fprintf_unfiltered (gdb_stdlog, "exited, status = %d\n",
1661 status->value.integer);
1663 case TARGET_WAITKIND_STOPPED:
1664 fprintf_unfiltered (gdb_stdlog, "stopped, signal = %s\n",
1665 target_signal_to_name (status->value.sig));
1667 case TARGET_WAITKIND_SIGNALLED:
1668 fprintf_unfiltered (gdb_stdlog, "signalled, signal = %s\n",
1669 target_signal_to_name (status->value.sig));
1671 case TARGET_WAITKIND_LOADED:
1672 fprintf_unfiltered (gdb_stdlog, "loaded\n");
1674 case TARGET_WAITKIND_FORKED:
1675 fprintf_unfiltered (gdb_stdlog, "forked\n");
1677 case TARGET_WAITKIND_VFORKED:
1678 fprintf_unfiltered (gdb_stdlog, "vforked\n");
1680 case TARGET_WAITKIND_EXECD:
1681 fprintf_unfiltered (gdb_stdlog, "execd\n");
1683 case TARGET_WAITKIND_SPURIOUS:
1684 fprintf_unfiltered (gdb_stdlog, "spurious\n");
1687 fprintf_unfiltered (gdb_stdlog, "unknown???\n");
1695 debug_to_post_wait (ptid_t ptid, int status)
1697 debug_target.to_post_wait (ptid, status);
1699 fprintf_unfiltered (gdb_stdlog, "target_post_wait (%d, %d)\n",
1700 PIDGET (ptid), status);
1704 debug_print_register (const char * func, int regno)
1706 fprintf_unfiltered (gdb_stdlog, "%s ", func);
1707 if (regno >= 0 && regno < NUM_REGS + NUM_PSEUDO_REGS
1708 && REGISTER_NAME (regno) != NULL && REGISTER_NAME (regno)[0] != '\0')
1709 fprintf_unfiltered (gdb_stdlog, "(%s)", REGISTER_NAME (regno));
1711 fprintf_unfiltered (gdb_stdlog, "(%d)", regno);
1715 unsigned char buf[MAX_REGISTER_SIZE];
1716 deprecated_read_register_gen (regno, buf);
1717 fprintf_unfiltered (gdb_stdlog, " = ");
1718 for (i = 0; i < DEPRECATED_REGISTER_RAW_SIZE (regno); i++)
1720 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
1722 if (DEPRECATED_REGISTER_RAW_SIZE (regno) <= sizeof (LONGEST))
1724 fprintf_unfiltered (gdb_stdlog, " 0x%s %s",
1725 paddr_nz (read_register (regno)),
1726 paddr_d (read_register (regno)));
1729 fprintf_unfiltered (gdb_stdlog, "\n");
1733 debug_to_fetch_registers (int regno)
1735 debug_target.to_fetch_registers (regno);
1736 debug_print_register ("target_fetch_registers", regno);
1740 debug_to_store_registers (int regno)
1742 debug_target.to_store_registers (regno);
1743 debug_print_register ("target_store_registers", regno);
1744 fprintf_unfiltered (gdb_stdlog, "\n");
1748 debug_to_prepare_to_store (void)
1750 debug_target.to_prepare_to_store ();
1752 fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n");
1756 debug_to_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
1757 struct mem_attrib *attrib,
1758 struct target_ops *target)
1762 retval = debug_target.to_xfer_memory (memaddr, myaddr, len, write,
1765 fprintf_unfiltered (gdb_stdlog,
1766 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
1767 (unsigned int) memaddr, /* possable truncate long long */
1768 len, write ? "write" : "read", retval);
1776 fputs_unfiltered (", bytes =", gdb_stdlog);
1777 for (i = 0; i < retval; i++)
1779 if ((((long) &(myaddr[i])) & 0xf) == 0)
1780 fprintf_unfiltered (gdb_stdlog, "\n");
1781 fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff);
1785 fputc_unfiltered ('\n', gdb_stdlog);
1791 debug_to_files_info (struct target_ops *target)
1793 debug_target.to_files_info (target);
1795 fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n");
1799 debug_to_insert_breakpoint (CORE_ADDR addr, char *save)
1803 retval = debug_target.to_insert_breakpoint (addr, save);
1805 fprintf_unfiltered (gdb_stdlog,
1806 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
1807 (unsigned long) addr,
1808 (unsigned long) retval);
1813 debug_to_remove_breakpoint (CORE_ADDR addr, char *save)
1817 retval = debug_target.to_remove_breakpoint (addr, save);
1819 fprintf_unfiltered (gdb_stdlog,
1820 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
1821 (unsigned long) addr,
1822 (unsigned long) retval);
1827 debug_to_can_use_hw_breakpoint (int type, int cnt, int from_tty)
1831 retval = debug_target.to_can_use_hw_breakpoint (type, cnt, from_tty);
1833 fprintf_unfiltered (gdb_stdlog,
1834 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
1835 (unsigned long) type,
1836 (unsigned long) cnt,
1837 (unsigned long) from_tty,
1838 (unsigned long) retval);
1843 debug_to_region_size_ok_for_hw_watchpoint (int byte_count)
1847 retval = debug_target.to_region_size_ok_for_hw_watchpoint (byte_count);
1849 fprintf_unfiltered (gdb_stdlog,
1850 "TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT (%ld) = 0x%lx\n",
1851 (unsigned long) byte_count,
1852 (unsigned long) retval);
1857 debug_to_stopped_by_watchpoint (void)
1861 retval = debug_target.to_stopped_by_watchpoint ();
1863 fprintf_unfiltered (gdb_stdlog,
1864 "STOPPED_BY_WATCHPOINT () = %ld\n",
1865 (unsigned long) retval);
1870 debug_to_stopped_data_address (void)
1874 retval = debug_target.to_stopped_data_address ();
1876 fprintf_unfiltered (gdb_stdlog,
1877 "target_stopped_data_address () = 0x%lx\n",
1878 (unsigned long) retval);
1883 debug_to_insert_hw_breakpoint (CORE_ADDR addr, char *save)
1887 retval = debug_target.to_insert_hw_breakpoint (addr, save);
1889 fprintf_unfiltered (gdb_stdlog,
1890 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
1891 (unsigned long) addr,
1892 (unsigned long) retval);
1897 debug_to_remove_hw_breakpoint (CORE_ADDR addr, char *save)
1901 retval = debug_target.to_remove_hw_breakpoint (addr, save);
1903 fprintf_unfiltered (gdb_stdlog,
1904 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
1905 (unsigned long) addr,
1906 (unsigned long) retval);
1911 debug_to_insert_watchpoint (CORE_ADDR addr, int len, int type)
1915 retval = debug_target.to_insert_watchpoint (addr, len, type);
1917 fprintf_unfiltered (gdb_stdlog,
1918 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1919 (unsigned long) addr, len, type, (unsigned long) retval);
1924 debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type)
1928 retval = debug_target.to_insert_watchpoint (addr, len, type);
1930 fprintf_unfiltered (gdb_stdlog,
1931 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1932 (unsigned long) addr, len, type, (unsigned long) retval);
1937 debug_to_terminal_init (void)
1939 debug_target.to_terminal_init ();
1941 fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n");
1945 debug_to_terminal_inferior (void)
1947 debug_target.to_terminal_inferior ();
1949 fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n");
1953 debug_to_terminal_ours_for_output (void)
1955 debug_target.to_terminal_ours_for_output ();
1957 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n");
1961 debug_to_terminal_ours (void)
1963 debug_target.to_terminal_ours ();
1965 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n");
1969 debug_to_terminal_save_ours (void)
1971 debug_target.to_terminal_save_ours ();
1973 fprintf_unfiltered (gdb_stdlog, "target_terminal_save_ours ()\n");
1977 debug_to_terminal_info (char *arg, int from_tty)
1979 debug_target.to_terminal_info (arg, from_tty);
1981 fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg,
1986 debug_to_kill (void)
1988 debug_target.to_kill ();
1990 fprintf_unfiltered (gdb_stdlog, "target_kill ()\n");
1994 debug_to_load (char *args, int from_tty)
1996 debug_target.to_load (args, from_tty);
1998 fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty);
2002 debug_to_lookup_symbol (char *name, CORE_ADDR *addrp)
2006 retval = debug_target.to_lookup_symbol (name, addrp);
2008 fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name);
2014 debug_to_create_inferior (char *exec_file, char *args, char **env)
2016 debug_target.to_create_inferior (exec_file, args, env);
2018 fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx)\n",
2023 debug_to_post_startup_inferior (ptid_t ptid)
2025 debug_target.to_post_startup_inferior (ptid);
2027 fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n",
2032 debug_to_acknowledge_created_inferior (int pid)
2034 debug_target.to_acknowledge_created_inferior (pid);
2036 fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n",
2041 debug_to_insert_fork_catchpoint (int pid)
2045 retval = debug_target.to_insert_fork_catchpoint (pid);
2047 fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d) = %d\n",
2054 debug_to_remove_fork_catchpoint (int pid)
2058 retval = debug_target.to_remove_fork_catchpoint (pid);
2060 fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n",
2067 debug_to_insert_vfork_catchpoint (int pid)
2071 retval = debug_target.to_insert_vfork_catchpoint (pid);
2073 fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)= %d\n",
2080 debug_to_remove_vfork_catchpoint (int pid)
2084 retval = debug_target.to_remove_vfork_catchpoint (pid);
2086 fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n",
2093 debug_to_follow_fork (int follow_child)
2095 int retval = debug_target.to_follow_fork (follow_child);
2097 fprintf_unfiltered (gdb_stdlog, "target_follow_fork (%d) = %d\n",
2098 follow_child, retval);
2104 debug_to_insert_exec_catchpoint (int pid)
2108 retval = debug_target.to_insert_exec_catchpoint (pid);
2110 fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d) = %d\n",
2117 debug_to_remove_exec_catchpoint (int pid)
2121 retval = debug_target.to_remove_exec_catchpoint (pid);
2123 fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n",
2130 debug_to_reported_exec_events_per_exec_call (void)
2132 int reported_exec_events;
2134 reported_exec_events = debug_target.to_reported_exec_events_per_exec_call ();
2136 fprintf_unfiltered (gdb_stdlog,
2137 "target_reported_exec_events_per_exec_call () = %d\n",
2138 reported_exec_events);
2140 return reported_exec_events;
2144 debug_to_has_exited (int pid, int wait_status, int *exit_status)
2148 has_exited = debug_target.to_has_exited (pid, wait_status, exit_status);
2150 fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n",
2151 pid, wait_status, *exit_status, has_exited);
2157 debug_to_mourn_inferior (void)
2159 debug_target.to_mourn_inferior ();
2161 fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n");
2165 debug_to_can_run (void)
2169 retval = debug_target.to_can_run ();
2171 fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval);
2177 debug_to_notice_signals (ptid_t ptid)
2179 debug_target.to_notice_signals (ptid);
2181 fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n",
2186 debug_to_thread_alive (ptid_t ptid)
2190 retval = debug_target.to_thread_alive (ptid);
2192 fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n",
2193 PIDGET (ptid), retval);
2199 debug_to_find_new_threads (void)
2201 debug_target.to_find_new_threads ();
2203 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog);
2207 debug_to_stop (void)
2209 debug_target.to_stop ();
2211 fprintf_unfiltered (gdb_stdlog, "target_stop ()\n");
2215 debug_to_read_partial (struct target_ops *ops,
2216 enum target_object object,
2217 const char *annex, void *buf,
2218 ULONGEST offset, LONGEST len)
2222 retval = target_read_partial (&debug_target, object, annex, buf, offset,
2225 fprintf_unfiltered (gdb_stdlog,
2226 "target_read_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n",
2227 (int) object, (annex ? annex : "(null)"),
2228 (long) buf, paddr_nz (offset),
2229 paddr_d (len), paddr_d (retval));
2235 debug_to_write_partial (struct target_ops *ops,
2236 enum target_object object,
2237 const char *annex, const void *buf,
2238 ULONGEST offset, LONGEST len)
2242 retval = target_write_partial (&debug_target, object, annex, buf, offset,
2245 fprintf_unfiltered (gdb_stdlog,
2246 "target_write_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n",
2247 (int) object, (annex ? annex : "(null)"),
2248 (long) buf, paddr_nz (offset),
2249 paddr_d (len), paddr_d (retval));
2255 debug_to_rcmd (char *command,
2256 struct ui_file *outbuf)
2258 debug_target.to_rcmd (command, outbuf);
2259 fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command);
2262 static struct symtab_and_line *
2263 debug_to_enable_exception_callback (enum exception_event_kind kind, int enable)
2265 struct symtab_and_line *result;
2266 result = debug_target.to_enable_exception_callback (kind, enable);
2267 fprintf_unfiltered (gdb_stdlog,
2268 "target get_exception_callback_sal (%d, %d)\n",
2273 static struct exception_event_record *
2274 debug_to_get_current_exception_event (void)
2276 struct exception_event_record *result;
2277 result = debug_target.to_get_current_exception_event ();
2278 fprintf_unfiltered (gdb_stdlog, "target get_current_exception_event ()\n");
2283 debug_to_pid_to_exec_file (int pid)
2287 exec_file = debug_target.to_pid_to_exec_file (pid);
2289 fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n",
2296 setup_target_debug (void)
2298 memcpy (&debug_target, ¤t_target, sizeof debug_target);
2300 current_target.to_open = debug_to_open;
2301 current_target.to_close = debug_to_close;
2302 current_target.to_attach = debug_to_attach;
2303 current_target.to_post_attach = debug_to_post_attach;
2304 current_target.to_detach = debug_to_detach;
2305 current_target.to_disconnect = debug_to_disconnect;
2306 current_target.to_resume = debug_to_resume;
2307 current_target.to_wait = debug_to_wait;
2308 current_target.to_post_wait = debug_to_post_wait;
2309 current_target.to_fetch_registers = debug_to_fetch_registers;
2310 current_target.to_store_registers = debug_to_store_registers;
2311 current_target.to_prepare_to_store = debug_to_prepare_to_store;
2312 current_target.to_xfer_memory = debug_to_xfer_memory;
2313 current_target.to_files_info = debug_to_files_info;
2314 current_target.to_insert_breakpoint = debug_to_insert_breakpoint;
2315 current_target.to_remove_breakpoint = debug_to_remove_breakpoint;
2316 current_target.to_can_use_hw_breakpoint = debug_to_can_use_hw_breakpoint;
2317 current_target.to_insert_hw_breakpoint = debug_to_insert_hw_breakpoint;
2318 current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint;
2319 current_target.to_insert_watchpoint = debug_to_insert_watchpoint;
2320 current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
2321 current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
2322 current_target.to_stopped_data_address = debug_to_stopped_data_address;
2323 current_target.to_region_size_ok_for_hw_watchpoint = debug_to_region_size_ok_for_hw_watchpoint;
2324 current_target.to_terminal_init = debug_to_terminal_init;
2325 current_target.to_terminal_inferior = debug_to_terminal_inferior;
2326 current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output;
2327 current_target.to_terminal_ours = debug_to_terminal_ours;
2328 current_target.to_terminal_save_ours = debug_to_terminal_save_ours;
2329 current_target.to_terminal_info = debug_to_terminal_info;
2330 current_target.to_kill = debug_to_kill;
2331 current_target.to_load = debug_to_load;
2332 current_target.to_lookup_symbol = debug_to_lookup_symbol;
2333 current_target.to_create_inferior = debug_to_create_inferior;
2334 current_target.to_post_startup_inferior = debug_to_post_startup_inferior;
2335 current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior;
2336 current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint;
2337 current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
2338 current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
2339 current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint;
2340 current_target.to_follow_fork = debug_to_follow_fork;
2341 current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint;
2342 current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
2343 current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call;
2344 current_target.to_has_exited = debug_to_has_exited;
2345 current_target.to_mourn_inferior = debug_to_mourn_inferior;
2346 current_target.to_can_run = debug_to_can_run;
2347 current_target.to_notice_signals = debug_to_notice_signals;
2348 current_target.to_thread_alive = debug_to_thread_alive;
2349 current_target.to_find_new_threads = debug_to_find_new_threads;
2350 current_target.to_stop = debug_to_stop;
2351 current_target.to_read_partial = debug_to_read_partial;
2352 current_target.to_write_partial = debug_to_write_partial;
2353 current_target.to_rcmd = debug_to_rcmd;
2354 current_target.to_enable_exception_callback = debug_to_enable_exception_callback;
2355 current_target.to_get_current_exception_event = debug_to_get_current_exception_event;
2356 current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
2361 static char targ_desc[] =
2362 "Names of targets and files being debugged.\n\
2363 Shows the entire stack of targets currently in use (including the exec-file,\n\
2364 core-file, and process, if any), as well as the symbol file name.";
2367 do_monitor_command (char *cmd,
2370 if ((current_target.to_rcmd
2371 == (void (*) (char *, struct ui_file *)) tcomplain)
2372 || (current_target.to_rcmd == debug_to_rcmd
2373 && (debug_target.to_rcmd
2374 == (void (*) (char *, struct ui_file *)) tcomplain)))
2376 error ("\"monitor\" command not supported by this target.\n");
2378 target_rcmd (cmd, gdb_stdtarg);
2382 initialize_targets (void)
2384 init_dummy_target ();
2385 push_target (&dummy_target);
2387 add_info ("target", target_info, targ_desc);
2388 add_info ("files", target_info, targ_desc);
2391 (add_set_cmd ("target", class_maintenance, var_zinteger,
2392 (char *) &targetdebug,
2393 "Set target debugging.\n\
2394 When non-zero, target debugging is enabled.", &setdebuglist),
2397 add_setshow_boolean_cmd ("trust-readonly-sections", class_support,
2399 Set mode for reading from readonly sections.\n\
2400 When this mode is on, memory reads from readonly sections (such as .text)\n\
2401 will be read from the object file instead of from the target. This will\n\
2402 result in significant performance improvement for remote targets.", "\
2403 Show mode for reading from readonly sections.\n",
2405 &setlist, &showlist);
2407 add_com ("monitor", class_obscure, do_monitor_command,
2408 "Send a command to the remote monitor (remote targets only).");
2410 target_dcache = dcache_init ();