1 /* Select target systems and architectures at runtime for GDB.
2 Copyright 1990, 1992-1995, 1998, 1999 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include "gdb_string.h"
39 target_info
PARAMS ((char *, int));
42 cleanup_target
PARAMS ((struct target_ops
*));
45 maybe_kill_then_create_inferior
PARAMS ((char *, char *, char **));
48 default_clone_and_follow_inferior
PARAMS ((int, int *));
51 maybe_kill_then_attach
PARAMS ((char *, int));
54 kill_or_be_killed
PARAMS ((int));
57 default_terminal_info
PARAMS ((char *, int));
60 nosymbol
PARAMS ((char *, CORE_ADDR
*));
63 tcomplain
PARAMS ((void));
66 nomemory
PARAMS ((CORE_ADDR
, char *, int, int, struct target_ops
*));
69 return_zero
PARAMS ((void));
72 return_one
PARAMS ((void));
75 target_ignore
PARAMS ((void));
78 target_command
PARAMS ((char *, int));
80 static struct target_ops
*
81 find_default_run_target
PARAMS ((char *));
84 update_current_target
PARAMS ((void));
86 static void nosupport_runtime
PARAMS ((void));
88 static void normal_target_post_startup_inferior
PARAMS ((int pid
));
90 /* Transfer LEN bytes between target address MEMADDR and GDB address
91 MYADDR. Returns 0 for success, errno code for failure (which
92 includes partial transfers -- if you want a more useful response to
93 partial transfers, try either target_read_memory_partial or
94 target_write_memory_partial). */
97 target_xfer_memory
PARAMS ((CORE_ADDR memaddr
, char *myaddr
, int len
,
98 int write
, asection
* bfd_section
));
100 static void init_dummy_target
PARAMS ((void));
103 debug_to_open
PARAMS ((char *, int));
106 debug_to_close
PARAMS ((int));
109 debug_to_attach
PARAMS ((char *, int));
112 debug_to_detach
PARAMS ((char *, int));
115 debug_to_resume
PARAMS ((int, int, enum target_signal
));
118 debug_to_wait
PARAMS ((int, struct target_waitstatus
*));
121 debug_to_fetch_registers
PARAMS ((int));
124 debug_to_store_registers
PARAMS ((int));
127 debug_to_prepare_to_store
PARAMS ((void));
130 debug_to_xfer_memory
PARAMS ((CORE_ADDR
, char *, int, int, struct target_ops
*));
133 debug_to_files_info
PARAMS ((struct target_ops
*));
136 debug_to_insert_breakpoint
PARAMS ((CORE_ADDR
, char *));
139 debug_to_remove_breakpoint
PARAMS ((CORE_ADDR
, char *));
142 debug_to_terminal_init
PARAMS ((void));
145 debug_to_terminal_inferior
PARAMS ((void));
148 debug_to_terminal_ours_for_output
PARAMS ((void));
151 debug_to_terminal_ours
PARAMS ((void));
154 debug_to_terminal_info
PARAMS ((char *, int));
157 debug_to_kill
PARAMS ((void));
160 debug_to_load
PARAMS ((char *, int));
163 debug_to_lookup_symbol
PARAMS ((char *, CORE_ADDR
*));
166 debug_to_create_inferior
PARAMS ((char *, char *, char **));
169 debug_to_mourn_inferior
PARAMS ((void));
172 debug_to_can_run
PARAMS ((void));
175 debug_to_notice_signals
PARAMS ((int));
178 debug_to_thread_alive
PARAMS ((int));
181 debug_to_stop
PARAMS ((void));
183 static int debug_to_query
PARAMS ((int /*char */ , char *, char *, int *));
185 /* Pointer to array of target architecture structures; the size of the
186 array; the current index into the array; the allocated size of the
188 struct target_ops
**target_structs
;
189 unsigned target_struct_size
;
190 unsigned target_struct_index
;
191 unsigned target_struct_allocsize
;
192 #define DEFAULT_ALLOCSIZE 10
194 /* The initial current target, so that there is always a semi-valid
197 static struct target_ops dummy_target
;
199 /* Top of target stack. */
201 struct target_stack_item
*target_stack
;
203 /* The target structure we are currently using to talk to a process
204 or file or whatever "inferior" we have. */
206 struct target_ops current_target
;
208 /* Command list for target. */
210 static struct cmd_list_element
*targetlist
= NULL
;
212 /* Nonzero if we are debugging an attached outside process
213 rather than an inferior. */
217 /* Non-zero if we want to see trace of target level stuff. */
219 static int targetdebug
= 0;
221 static void setup_target_debug
PARAMS ((void));
223 /* The user just typed 'target' without the name of a target. */
227 target_command (arg
, from_tty
)
231 fputs_filtered ("Argument required (target name). Try `help target'\n",
235 /* Add a possible target architecture to the list. */
239 struct target_ops
*t
;
243 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
244 target_structs
= (struct target_ops
**) xmalloc
245 (target_struct_allocsize
* sizeof (*target_structs
));
247 if (target_struct_size
>= target_struct_allocsize
)
249 target_struct_allocsize
*= 2;
250 target_structs
= (struct target_ops
**)
251 xrealloc ((char *) target_structs
,
252 target_struct_allocsize
* sizeof (*target_structs
));
254 target_structs
[target_struct_size
++] = t
;
255 /* cleanup_target (t); */
257 if (targetlist
== NULL
)
258 add_prefix_cmd ("target", class_run
, target_command
,
259 "Connect to a target machine or process.\n\
260 The first argument is the type or protocol of the target machine.\n\
261 Remaining arguments are interpreted by the target protocol. For more\n\
262 information on the arguments for a particular protocol, type\n\
263 `help target ' followed by the protocol name.",
264 &targetlist
, "target ", 0, &cmdlist
);
265 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
276 target_load (char *arg
, int from_tty
)
278 (*current_target
.to_load
) (arg
, from_tty
);
283 nomemory (memaddr
, myaddr
, len
, write
, t
)
288 struct target_ops
*t
;
290 errno
= EIO
; /* Can't read/write this location */
291 return 0; /* No bytes handled */
297 error ("You can't do that when your target is `%s'",
298 current_target
.to_shortname
);
304 error ("You can't do that without a process to debug.");
309 nosymbol (name
, addrp
)
313 return 1; /* Symbol does not exist in target env */
323 error ("No run-time support for this");
329 default_terminal_info (args
, from_tty
)
333 printf_unfiltered ("No saved terminal information.\n");
336 /* This is the default target_create_inferior and target_attach function.
337 If the current target is executing, it asks whether to kill it off.
338 If this function returns without calling error(), it has killed off
339 the target, and the operation should be attempted. */
342 kill_or_be_killed (from_tty
)
345 if (target_has_execution
)
347 printf_unfiltered ("You are already running a program:\n");
348 target_files_info ();
349 if (query ("Kill it? "))
352 if (target_has_execution
)
353 error ("Killing the program did not help.");
358 error ("Program not killed.");
365 maybe_kill_then_attach (args
, from_tty
)
369 kill_or_be_killed (from_tty
);
370 target_attach (args
, from_tty
);
374 maybe_kill_then_create_inferior (exec
, args
, env
)
379 kill_or_be_killed (0);
380 target_create_inferior (exec
, args
, env
);
384 default_clone_and_follow_inferior (child_pid
, followed_child
)
388 target_clone_and_follow_inferior (child_pid
, followed_child
);
391 /* Clean up a target struct so it no longer has any zero pointers in it.
392 We default entries, at least to stubs that print error messages. */
396 struct target_ops
*t
;
399 #define de_fault(field, value) \
400 if (!t->field) t->field = value
402 /* FIELD DEFAULT VALUE */
404 de_fault (to_open
, (void (*)PARAMS ((char *, int))) tcomplain
);
405 de_fault (to_close
, (void (*)PARAMS ((int))) target_ignore
);
406 de_fault (to_attach
, maybe_kill_then_attach
);
407 de_fault (to_post_attach
, (void (*)PARAMS ((int))) target_ignore
);
408 de_fault (to_require_attach
, maybe_kill_then_attach
);
409 de_fault (to_detach
, (void (*)PARAMS ((char *, int))) target_ignore
);
410 de_fault (to_require_detach
, (void (*)PARAMS ((int, char *, int))) target_ignore
);
411 de_fault (to_resume
, (void (*)PARAMS ((int, int, enum target_signal
))) noprocess
);
412 de_fault (to_wait
, (int (*)PARAMS ((int, struct target_waitstatus
*))) noprocess
);
413 de_fault (to_post_wait
, (void (*)PARAMS ((int, int))) target_ignore
);
414 de_fault (to_fetch_registers
, (void (*)PARAMS ((int))) target_ignore
);
415 de_fault (to_store_registers
, (void (*)PARAMS ((int))) noprocess
);
416 de_fault (to_prepare_to_store
, (void (*)PARAMS ((void))) noprocess
);
417 de_fault (to_xfer_memory
, (int (*)PARAMS ((CORE_ADDR
, char *, int, int, struct target_ops
*))) nomemory
);
418 de_fault (to_files_info
, (void (*)PARAMS ((struct target_ops
*))) target_ignore
);
419 de_fault (to_insert_breakpoint
, memory_insert_breakpoint
);
420 de_fault (to_remove_breakpoint
, memory_remove_breakpoint
);
421 de_fault (to_terminal_init
, (void (*)PARAMS ((void))) target_ignore
);
422 de_fault (to_terminal_inferior
, (void (*)PARAMS ((void))) target_ignore
);
423 de_fault (to_terminal_ours_for_output
, (void (*)PARAMS ((void))) target_ignore
);
424 de_fault (to_terminal_ours
, (void (*)PARAMS ((void))) target_ignore
);
425 de_fault (to_terminal_info
, default_terminal_info
);
426 de_fault (to_kill
, (void (*)PARAMS ((void))) noprocess
);
427 de_fault (to_load
, (void (*)PARAMS ((char *, int))) tcomplain
);
428 de_fault (to_lookup_symbol
, (int (*)PARAMS ((char *, CORE_ADDR
*))) nosymbol
);
429 de_fault (to_create_inferior
, maybe_kill_then_create_inferior
);
430 de_fault (to_post_startup_inferior
, (void (*)PARAMS ((int))) target_ignore
);
431 de_fault (to_acknowledge_created_inferior
, (void (*)PARAMS ((int))) target_ignore
);
432 de_fault (to_clone_and_follow_inferior
, default_clone_and_follow_inferior
);
433 de_fault (to_post_follow_inferior_by_clone
, (void (*)PARAMS ((void))) target_ignore
);
434 de_fault (to_insert_fork_catchpoint
, (int (*)PARAMS ((int))) tcomplain
);
435 de_fault (to_remove_fork_catchpoint
, (int (*)PARAMS ((int))) tcomplain
);
436 de_fault (to_insert_vfork_catchpoint
, (int (*)PARAMS ((int))) tcomplain
);
437 de_fault (to_remove_vfork_catchpoint
, (int (*)PARAMS ((int))) tcomplain
);
438 de_fault (to_has_forked
, (int (*)PARAMS ((int, int *))) return_zero
);
439 de_fault (to_has_vforked
, (int (*)PARAMS ((int, int *))) return_zero
);
440 de_fault (to_can_follow_vfork_prior_to_exec
, (int (*)PARAMS ((void))) return_zero
);
441 de_fault (to_post_follow_vfork
, (void (*)PARAMS ((int, int, int, int))) target_ignore
);
442 de_fault (to_insert_exec_catchpoint
, (int (*)PARAMS ((int))) tcomplain
);
443 de_fault (to_remove_exec_catchpoint
, (int (*)PARAMS ((int))) tcomplain
);
444 de_fault (to_has_execd
, (int (*)PARAMS ((int, char **))) return_zero
);
445 de_fault (to_reported_exec_events_per_exec_call
, (int (*)PARAMS ((void))) return_one
);
446 de_fault (to_has_syscall_event
, (int (*)PARAMS ((int, enum target_waitkind
*, int *))) return_zero
);
447 de_fault (to_has_exited
, (int (*)PARAMS ((int, int, int *))) return_zero
);
448 de_fault (to_mourn_inferior
, (void (*)PARAMS ((void))) noprocess
);
449 de_fault (to_can_run
, return_zero
);
450 de_fault (to_notice_signals
, (void (*)PARAMS ((int))) target_ignore
);
451 de_fault (to_thread_alive
, (int (*)PARAMS ((int))) target_ignore
);
452 de_fault (to_stop
, (void (*)PARAMS ((void))) target_ignore
);
453 de_fault (to_query
, (int (*)PARAMS ((int /*char */ , char *, char *, int *))) target_ignore
);
454 de_fault (to_rcmd
, (void (*) (char *, struct gdb_file
*)) tcomplain
);
455 de_fault (to_enable_exception_callback
, (struct symtab_and_line
* (*)PARAMS ((enum exception_event_kind
, int))) nosupport_runtime
);
456 de_fault (to_get_current_exception_event
, (struct exception_event_record
* (*)PARAMS ((void))) nosupport_runtime
);
458 de_fault (to_pid_to_exec_file
, (char *(*)PARAMS ((int))) return_zero
);
459 de_fault (to_core_file_to_sym_file
, (char *(*)PARAMS ((char *))) return_zero
);
460 de_fault (to_can_async_p
, (int (*) (void)) return_zero
);
461 de_fault (to_is_async_p
, (int (*) (void)) return_zero
);
462 de_fault (to_async
, (void (*) (void (*) (enum inferior_event_type
, void*), void*)) tcomplain
);
466 /* Go through the target stack from top to bottom, copying over zero entries in
467 current_target. In effect, we are doing class inheritance through the
468 pushed target vectors. */
471 update_current_target ()
473 struct target_stack_item
*item
;
474 struct target_ops
*t
;
476 /* First, reset current_target */
477 memset (¤t_target
, 0, sizeof current_target
);
479 for (item
= target_stack
; item
; item
= item
->next
)
481 t
= item
->target_ops
;
483 #define INHERIT(FIELD, TARGET) \
484 if (!current_target.FIELD) \
485 current_target.FIELD = TARGET->FIELD
487 INHERIT (to_shortname
, t
);
488 INHERIT (to_longname
, t
);
490 INHERIT (to_open
, t
);
491 INHERIT (to_close
, t
);
492 INHERIT (to_attach
, t
);
493 INHERIT (to_post_attach
, t
);
494 INHERIT (to_require_attach
, t
);
495 INHERIT (to_detach
, t
);
496 INHERIT (to_require_detach
, t
);
497 INHERIT (to_resume
, t
);
498 INHERIT (to_wait
, t
);
499 INHERIT (to_post_wait
, t
);
500 INHERIT (to_fetch_registers
, t
);
501 INHERIT (to_store_registers
, t
);
502 INHERIT (to_prepare_to_store
, t
);
503 INHERIT (to_xfer_memory
, t
);
504 INHERIT (to_files_info
, t
);
505 INHERIT (to_insert_breakpoint
, t
);
506 INHERIT (to_remove_breakpoint
, t
);
507 INHERIT (to_terminal_init
, t
);
508 INHERIT (to_terminal_inferior
, t
);
509 INHERIT (to_terminal_ours_for_output
, t
);
510 INHERIT (to_terminal_ours
, t
);
511 INHERIT (to_terminal_info
, t
);
512 INHERIT (to_kill
, t
);
513 INHERIT (to_load
, t
);
514 INHERIT (to_lookup_symbol
, t
);
515 INHERIT (to_create_inferior
, t
);
516 INHERIT (to_post_startup_inferior
, t
);
517 INHERIT (to_acknowledge_created_inferior
, t
);
518 INHERIT (to_clone_and_follow_inferior
, t
);
519 INHERIT (to_post_follow_inferior_by_clone
, t
);
520 INHERIT (to_insert_fork_catchpoint
, t
);
521 INHERIT (to_remove_fork_catchpoint
, t
);
522 INHERIT (to_insert_vfork_catchpoint
, t
);
523 INHERIT (to_remove_vfork_catchpoint
, t
);
524 INHERIT (to_has_forked
, t
);
525 INHERIT (to_has_vforked
, t
);
526 INHERIT (to_can_follow_vfork_prior_to_exec
, t
);
527 INHERIT (to_post_follow_vfork
, t
);
528 INHERIT (to_insert_exec_catchpoint
, t
);
529 INHERIT (to_remove_exec_catchpoint
, t
);
530 INHERIT (to_has_execd
, t
);
531 INHERIT (to_reported_exec_events_per_exec_call
, t
);
532 INHERIT (to_has_syscall_event
, t
);
533 INHERIT (to_has_exited
, t
);
534 INHERIT (to_mourn_inferior
, t
);
535 INHERIT (to_can_run
, t
);
536 INHERIT (to_notice_signals
, t
);
537 INHERIT (to_thread_alive
, t
);
538 INHERIT (to_find_new_threads
, t
);
539 INHERIT (to_stop
, t
);
540 INHERIT (to_query
, t
);
541 INHERIT (to_rcmd
, t
);
542 INHERIT (to_enable_exception_callback
, t
);
543 INHERIT (to_get_current_exception_event
, t
);
544 INHERIT (to_pid_to_exec_file
, t
);
545 INHERIT (to_core_file_to_sym_file
, t
);
546 INHERIT (to_stratum
, t
);
547 INHERIT (DONT_USE
, t
);
548 INHERIT (to_has_all_memory
, t
);
549 INHERIT (to_has_memory
, t
);
550 INHERIT (to_has_stack
, t
);
551 INHERIT (to_has_registers
, t
);
552 INHERIT (to_has_execution
, t
);
553 INHERIT (to_has_thread_control
, t
);
554 INHERIT (to_sections
, t
);
555 INHERIT (to_sections_end
, t
);
556 INHERIT (to_can_async_p
, t
);
557 INHERIT (to_is_async_p
, t
);
558 INHERIT (to_async
, t
);
559 INHERIT (to_magic
, t
);
565 /* Push a new target type into the stack of the existing target accessors,
566 possibly superseding some of the existing accessors.
568 Result is zero if the pushed target ended up on top of the stack,
569 nonzero if at least one target is on top of it.
571 Rather than allow an empty stack, we always have the dummy target at
572 the bottom stratum, so we can call the function vectors without
577 struct target_ops
*t
;
579 struct target_stack_item
*cur
, *prev
, *tmp
;
581 /* Check magic number. If wrong, it probably means someone changed
582 the struct definition, but not all the places that initialize one. */
583 if (t
->to_magic
!= OPS_MAGIC
)
585 fprintf_unfiltered (gdb_stderr
,
586 "Magic number of %s target struct wrong\n",
591 /* Find the proper stratum to install this target in. */
593 for (prev
= NULL
, cur
= target_stack
; cur
; prev
= cur
, cur
= cur
->next
)
595 if ((int) (t
->to_stratum
) >= (int) (cur
->target_ops
->to_stratum
))
599 /* If there's already targets at this stratum, remove them. */
602 while (t
->to_stratum
== cur
->target_ops
->to_stratum
)
604 /* There's already something on this stratum. Close it off. */
605 if (cur
->target_ops
->to_close
)
606 (cur
->target_ops
->to_close
) (0);
608 prev
->next
= cur
->next
; /* Unchain old target_ops */
610 target_stack
= cur
->next
; /* Unchain first on list */
616 /* We have removed all targets in our stratum, now add the new one. */
618 tmp
= (struct target_stack_item
*)
619 xmalloc (sizeof (struct target_stack_item
));
628 update_current_target ();
630 cleanup_target (¤t_target
); /* Fill in the gaps */
633 setup_target_debug ();
638 /* Remove a target_ops vector from the stack, wherever it may be.
639 Return how many times it was removed (0 or 1). */
643 struct target_ops
*t
;
645 struct target_stack_item
*cur
, *prev
;
648 t
->to_close (0); /* Let it clean up */
650 /* Look for the specified target. Note that we assume that a target
651 can only occur once in the target stack. */
653 for (cur
= target_stack
, prev
= NULL
; cur
; prev
= cur
, cur
= cur
->next
)
654 if (cur
->target_ops
== t
)
658 return 0; /* Didn't find target_ops, quit now */
660 /* Unchain the target */
663 target_stack
= cur
->next
;
665 prev
->next
= cur
->next
;
667 free (cur
); /* Release the target_stack_item */
669 update_current_target ();
670 cleanup_target (¤t_target
);
678 (current_target
.to_close
) (0); /* Let it clean up */
679 if (unpush_target (target_stack
->target_ops
) == 1)
682 fprintf_unfiltered (gdb_stderr
,
683 "pop_target couldn't find target %s\n",
684 current_target
.to_shortname
);
689 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
691 /* target_read_string -- read a null terminated string, up to LEN bytes,
692 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
693 Set *STRING to a pointer to malloc'd memory containing the data; the caller
694 is responsible for freeing it. Return the number of bytes successfully
698 target_read_string (memaddr
, string
, len
, errnop
)
704 int tlen
, origlen
, offset
, i
;
708 int buffer_allocated
;
710 unsigned int nbytes_read
= 0;
712 /* Small for testing. */
713 buffer_allocated
= 4;
714 buffer
= xmalloc (buffer_allocated
);
721 tlen
= MIN (len
, 4 - (memaddr
& 3));
722 offset
= memaddr
& 3;
724 errcode
= target_xfer_memory (memaddr
& ~3, buf
, 4, 0, NULL
);
727 /* The transfer request might have crossed the boundary to an
728 unallocated region of memory. Retry the transfer, requesting
732 errcode
= target_xfer_memory (memaddr
, buf
, 1, 0, NULL
);
737 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
740 bytes
= bufptr
- buffer
;
741 buffer_allocated
*= 2;
742 buffer
= xrealloc (buffer
, buffer_allocated
);
743 bufptr
= buffer
+ bytes
;
746 for (i
= 0; i
< tlen
; i
++)
748 *bufptr
++ = buf
[i
+ offset
];
749 if (buf
[i
+ offset
] == '\000')
751 nbytes_read
+= i
+ 1;
768 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
769 GDB's memory at MYADDR. Returns either 0 for success or an errno value
772 If an error occurs, no guarantee is made about the contents of the data at
773 MYADDR. In particular, the caller should not depend upon partial reads
774 filling the buffer with good data. There is no way for the caller to know
775 how much good data might have been transfered anyway. Callers that can
776 deal with partial reads should call target_read_memory_partial. */
779 target_read_memory (memaddr
, myaddr
, len
)
784 return target_xfer_memory (memaddr
, myaddr
, len
, 0, NULL
);
788 target_read_memory_section (memaddr
, myaddr
, len
, bfd_section
)
792 asection
*bfd_section
;
794 return target_xfer_memory (memaddr
, myaddr
, len
, 0, bfd_section
);
798 target_write_memory (memaddr
, myaddr
, len
)
803 return target_xfer_memory (memaddr
, myaddr
, len
, 1, NULL
);
806 /* This variable is used to pass section information down to targets. This
807 *should* be done by adding an argument to the target_xfer_memory function
808 of all the targets, but I didn't feel like changing 50+ files. */
810 asection
*target_memory_bfd_section
= NULL
;
812 /* Move memory to or from the targets. Iterate until all of it has
813 been moved, if necessary. The top target gets priority; anything
814 it doesn't want, is offered to the next one down, etc. Note the
815 business with curlen: if an early target says "no, but I have a
816 boundary overlapping this xfer" then we shorten what we offer to
817 the subsequent targets so the early guy will get a chance at the
818 tail before the subsequent ones do.
820 Result is 0 or errno value. */
823 target_xfer_memory (memaddr
, myaddr
, len
, write
, bfd_section
)
828 asection
*bfd_section
;
832 struct target_ops
*t
;
833 struct target_stack_item
*item
;
835 /* Zero length requests are ok and require no work. */
839 target_memory_bfd_section
= bfd_section
;
841 /* to_xfer_memory is not guaranteed to set errno, even when it returns
845 /* The quick case is that the top target does it all. */
846 res
= current_target
.to_xfer_memory
847 (memaddr
, myaddr
, len
, write
, ¤t_target
);
853 /* If res <= 0 then we call it again in the loop. Ah well. */
857 curlen
= len
; /* Want to do it all */
858 for (item
= target_stack
; item
; item
= item
->next
)
860 t
= item
->target_ops
;
861 if (!t
->to_has_memory
)
864 res
= t
->to_xfer_memory (memaddr
, myaddr
, curlen
, write
, t
);
866 break; /* Handled all or part of xfer */
867 if (t
->to_has_all_memory
)
873 /* If this address is for nonexistent memory,
874 read zeros if reading, or do nothing if writing. Return error. */
876 memset (myaddr
, 0, len
);
887 return 0; /* We managed to cover it all somehow. */
891 /* Perform a partial memory transfer. */
894 target_xfer_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
,
895 int write_p
, int *err
)
900 struct target_ops
*t
;
901 struct target_stack_item
*item
;
903 /* Zero length requests are ok and require no work. */
910 /* The quick case is that the top target does it all. */
911 res
= current_target
.to_xfer_memory (memaddr
, buf
, len
, write_p
, ¤t_target
);
918 /* xfer memory doesn't always reliably set errno. */
921 /* Try all levels of the target stack to see one can handle it. */
922 for (item
= target_stack
; item
; item
= item
->next
)
924 t
= item
->target_ops
;
925 if (!t
->to_has_memory
)
927 res
= t
->to_xfer_memory (memaddr
, buf
, len
, write_p
, t
);
930 /* Handled all or part of xfer */
934 if (t
->to_has_all_memory
)
938 /* Total failure. Return error. */
949 target_read_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
951 return target_xfer_memory_partial (memaddr
, buf
, len
, 0, err
);
955 target_write_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
957 return target_xfer_memory_partial (memaddr
, buf
, len
, 1, err
);
962 target_info (args
, from_tty
)
966 struct target_ops
*t
;
967 struct target_stack_item
*item
;
970 if (symfile_objfile
!= NULL
)
971 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
973 #ifdef FILES_INFO_HOOK
974 if (FILES_INFO_HOOK ())
978 for (item
= target_stack
; item
; item
= item
->next
)
980 t
= item
->target_ops
;
982 if (!t
->to_has_memory
)
985 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
988 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
989 printf_unfiltered ("%s:\n", t
->to_longname
);
990 (t
->to_files_info
) (t
);
991 has_all_mem
= t
->to_has_all_memory
;
995 /* This is to be called by the open routine before it does
999 target_preopen (from_tty
)
1004 if (target_has_execution
)
1007 || query ("A program is being debugged already. Kill it? "))
1010 error ("Program not killed.");
1013 /* Calling target_kill may remove the target from the stack. But if
1014 it doesn't (which seems like a win for UDI), remove it now. */
1016 if (target_has_execution
)
1020 /* Detach a target after doing deferred register stores. */
1023 target_detach (args
, from_tty
)
1027 /* Handle any optimized stores to the inferior. */
1028 #ifdef DO_DEFERRED_STORES
1031 (current_target
.to_detach
) (args
, from_tty
);
1035 target_link (modname
, t_reloc
)
1039 if (STREQ (current_target
.to_shortname
, "rombug"))
1041 (current_target
.to_lookup_symbol
) (modname
, t_reloc
);
1043 error ("Unable to link to %s and get relocation in rombug", modname
);
1046 *t_reloc
= (CORE_ADDR
) -1;
1049 /* Look through the list of possible targets for a target that can
1050 execute a run or attach command without any other data. This is
1051 used to locate the default process stratum.
1053 Result is always valid (error() is called for errors). */
1055 static struct target_ops
*
1056 find_default_run_target (do_mesg
)
1059 struct target_ops
**t
;
1060 struct target_ops
*runable
= NULL
;
1065 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1068 if ((*t
)->to_can_run
&& target_can_run (*t
))
1076 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
1082 find_default_attach (args
, from_tty
)
1086 struct target_ops
*t
;
1088 t
= find_default_run_target ("attach");
1089 (t
->to_attach
) (args
, from_tty
);
1094 find_default_require_attach (args
, from_tty
)
1098 struct target_ops
*t
;
1100 t
= find_default_run_target ("require_attach");
1101 (t
->to_require_attach
) (args
, from_tty
);
1106 find_default_require_detach (pid
, args
, from_tty
)
1111 struct target_ops
*t
;
1113 t
= find_default_run_target ("require_detach");
1114 (t
->to_require_detach
) (pid
, args
, from_tty
);
1119 find_default_create_inferior (exec_file
, allargs
, env
)
1124 struct target_ops
*t
;
1126 t
= find_default_run_target ("run");
1127 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
1132 find_default_clone_and_follow_inferior (child_pid
, followed_child
)
1134 int *followed_child
;
1136 struct target_ops
*t
;
1138 t
= find_default_run_target ("run");
1139 (t
->to_clone_and_follow_inferior
) (child_pid
, followed_child
);
1156 * Resize the to_sections pointer. Also make sure that anyone that
1157 * was holding on to an old value of it gets updated.
1158 * Returns the old size.
1162 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1164 struct target_ops
**t
;
1165 struct section_table
*old_value
;
1168 old_value
= target
->to_sections
;
1170 if (target
->to_sections
)
1172 old_count
= target
->to_sections_end
- target
->to_sections
;
1173 target
->to_sections
= (struct section_table
*)
1174 xrealloc ((char *) target
->to_sections
,
1175 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1180 target
->to_sections
= (struct section_table
*)
1181 xmalloc ((sizeof (struct section_table
)) * num_added
);
1183 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1185 /* Check to see if anyone else was pointing to this structure.
1186 If old_value was null, then no one was. */
1190 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1193 if ((*t
)->to_sections
== old_value
)
1195 (*t
)->to_sections
= target
->to_sections
;
1196 (*t
)->to_sections_end
= target
->to_sections_end
;
1205 /* Find a single runnable target in the stack and return it. If for
1206 some reason there is more than one, return NULL. */
1211 struct target_ops
**t
;
1212 struct target_ops
*runable
= NULL
;
1217 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1219 if ((*t
)->to_can_run
&& target_can_run (*t
))
1226 return (count
== 1 ? runable
: NULL
);
1232 struct target_ops
**t
;
1233 struct target_ops
*runable
= NULL
;
1238 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1241 if ((*t
)->to_stratum
== core_stratum
)
1248 return (count
== 1 ? runable
: NULL
);
1251 /* The inferior process has died. Long live the inferior! */
1254 generic_mourn_inferior ()
1256 extern int show_breakpoint_hit_counts
;
1260 breakpoint_init_inferior (inf_exited
);
1261 registers_changed ();
1263 #ifdef CLEAR_DEFERRED_STORES
1264 /* Delete any pending stores to the inferior... */
1265 CLEAR_DEFERRED_STORES
;
1268 reopen_exec_file ();
1269 reinit_frame_cache ();
1271 /* It is confusing to the user for ignore counts to stick around
1272 from previous runs of the inferior. So clear them. */
1273 /* However, it is more confusing for the ignore counts to disappear when
1274 using hit counts. So don't clear them if we're counting hits. */
1275 if (!show_breakpoint_hit_counts
)
1276 breakpoint_clear_ignore_counts ();
1279 /* This table must match in order and size the signals in enum target_signal
1288 {"SIGHUP", "Hangup"},
1289 {"SIGINT", "Interrupt"},
1290 {"SIGQUIT", "Quit"},
1291 {"SIGILL", "Illegal instruction"},
1292 {"SIGTRAP", "Trace/breakpoint trap"},
1293 {"SIGABRT", "Aborted"},
1294 {"SIGEMT", "Emulation trap"},
1295 {"SIGFPE", "Arithmetic exception"},
1296 {"SIGKILL", "Killed"},
1297 {"SIGBUS", "Bus error"},
1298 {"SIGSEGV", "Segmentation fault"},
1299 {"SIGSYS", "Bad system call"},
1300 {"SIGPIPE", "Broken pipe"},
1301 {"SIGALRM", "Alarm clock"},
1302 {"SIGTERM", "Terminated"},
1303 {"SIGURG", "Urgent I/O condition"},
1304 {"SIGSTOP", "Stopped (signal)"},
1305 {"SIGTSTP", "Stopped (user)"},
1306 {"SIGCONT", "Continued"},
1307 {"SIGCHLD", "Child status changed"},
1308 {"SIGTTIN", "Stopped (tty input)"},
1309 {"SIGTTOU", "Stopped (tty output)"},
1310 {"SIGIO", "I/O possible"},
1311 {"SIGXCPU", "CPU time limit exceeded"},
1312 {"SIGXFSZ", "File size limit exceeded"},
1313 {"SIGVTALRM", "Virtual timer expired"},
1314 {"SIGPROF", "Profiling timer expired"},
1315 {"SIGWINCH", "Window size changed"},
1316 {"SIGLOST", "Resource lost"},
1317 {"SIGUSR1", "User defined signal 1"},
1318 {"SIGUSR2", "User defined signal 2"},
1319 {"SIGPWR", "Power fail/restart"},
1320 {"SIGPOLL", "Pollable event occurred"},
1321 {"SIGWIND", "SIGWIND"},
1322 {"SIGPHONE", "SIGPHONE"},
1323 {"SIGWAITING", "Process's LWPs are blocked"},
1324 {"SIGLWP", "Signal LWP"},
1325 {"SIGDANGER", "Swap space dangerously low"},
1326 {"SIGGRANT", "Monitor mode granted"},
1327 {"SIGRETRACT", "Need to relinquish monitor mode"},
1328 {"SIGMSG", "Monitor mode data available"},
1329 {"SIGSOUND", "Sound completed"},
1330 {"SIGSAK", "Secure attention"},
1331 {"SIGPRIO", "SIGPRIO"},
1332 {"SIG33", "Real-time event 33"},
1333 {"SIG34", "Real-time event 34"},
1334 {"SIG35", "Real-time event 35"},
1335 {"SIG36", "Real-time event 36"},
1336 {"SIG37", "Real-time event 37"},
1337 {"SIG38", "Real-time event 38"},
1338 {"SIG39", "Real-time event 39"},
1339 {"SIG40", "Real-time event 40"},
1340 {"SIG41", "Real-time event 41"},
1341 {"SIG42", "Real-time event 42"},
1342 {"SIG43", "Real-time event 43"},
1343 {"SIG44", "Real-time event 44"},
1344 {"SIG45", "Real-time event 45"},
1345 {"SIG46", "Real-time event 46"},
1346 {"SIG47", "Real-time event 47"},
1347 {"SIG48", "Real-time event 48"},
1348 {"SIG49", "Real-time event 49"},
1349 {"SIG50", "Real-time event 50"},
1350 {"SIG51", "Real-time event 51"},
1351 {"SIG52", "Real-time event 52"},
1352 {"SIG53", "Real-time event 53"},
1353 {"SIG54", "Real-time event 54"},
1354 {"SIG55", "Real-time event 55"},
1355 {"SIG56", "Real-time event 56"},
1356 {"SIG57", "Real-time event 57"},
1357 {"SIG58", "Real-time event 58"},
1358 {"SIG59", "Real-time event 59"},
1359 {"SIG60", "Real-time event 60"},
1360 {"SIG61", "Real-time event 61"},
1361 {"SIG62", "Real-time event 62"},
1362 {"SIG63", "Real-time event 63"},
1363 {"SIGCANCEL", "LWP internal signal"},
1364 {"SIG32", "Real-time event 32"},
1366 #if defined(MACH) || defined(__MACH__)
1367 /* Mach exceptions */
1368 {"EXC_BAD_ACCESS", "Could not access memory"},
1369 {"EXC_BAD_INSTRUCTION", "Illegal instruction/operand"},
1370 {"EXC_ARITHMETIC", "Arithmetic exception"},
1371 {"EXC_EMULATION", "Emulation instruction"},
1372 {"EXC_SOFTWARE", "Software generated exception"},
1373 {"EXC_BREAKPOINT", "Breakpoint"},
1375 {"SIGINFO", "Information request"},
1377 {NULL
, "Unknown signal"},
1378 {NULL
, "Internal error: printing TARGET_SIGNAL_DEFAULT"},
1380 /* Last entry, used to check whether the table is the right size. */
1381 {NULL
, "TARGET_SIGNAL_MAGIC"}
1387 /* Return the string for a signal. */
1389 target_signal_to_string (sig
)
1390 enum target_signal sig
;
1392 if ((sig
>= TARGET_SIGNAL_FIRST
) && (sig
<= TARGET_SIGNAL_LAST
))
1393 return signals
[sig
].string
;
1395 return signals
[TARGET_SIGNAL_UNKNOWN
].string
;
1398 /* Return the name for a signal. */
1400 target_signal_to_name (sig
)
1401 enum target_signal sig
;
1403 if (sig
== TARGET_SIGNAL_UNKNOWN
)
1404 /* I think the code which prints this will always print it along with
1405 the string, so no need to be verbose. */
1407 return signals
[sig
].name
;
1410 /* Given a name, return its signal. */
1412 target_signal_from_name (name
)
1415 enum target_signal sig
;
1417 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
1418 for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
1419 questionable; seems like by now people should call it SIGABRT
1422 /* This ugly cast brought to you by the native VAX compiler. */
1423 for (sig
= TARGET_SIGNAL_HUP
;
1424 signals
[sig
].name
!= NULL
;
1425 sig
= (enum target_signal
) ((int) sig
+ 1))
1426 if (STREQ (name
, signals
[sig
].name
))
1428 return TARGET_SIGNAL_UNKNOWN
;
1431 /* The following functions are to help certain targets deal
1432 with the signal/waitstatus stuff. They could just as well be in
1433 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
1435 /* Convert host signal to our signals. */
1437 target_signal_from_host (hostsig
)
1440 /* A switch statement would make sense but would require special kludges
1441 to deal with the cases where more than one signal has the same number. */
1444 return TARGET_SIGNAL_0
;
1446 #if defined (SIGHUP)
1447 if (hostsig
== SIGHUP
)
1448 return TARGET_SIGNAL_HUP
;
1450 #if defined (SIGINT)
1451 if (hostsig
== SIGINT
)
1452 return TARGET_SIGNAL_INT
;
1454 #if defined (SIGQUIT)
1455 if (hostsig
== SIGQUIT
)
1456 return TARGET_SIGNAL_QUIT
;
1458 #if defined (SIGILL)
1459 if (hostsig
== SIGILL
)
1460 return TARGET_SIGNAL_ILL
;
1462 #if defined (SIGTRAP)
1463 if (hostsig
== SIGTRAP
)
1464 return TARGET_SIGNAL_TRAP
;
1466 #if defined (SIGABRT)
1467 if (hostsig
== SIGABRT
)
1468 return TARGET_SIGNAL_ABRT
;
1470 #if defined (SIGEMT)
1471 if (hostsig
== SIGEMT
)
1472 return TARGET_SIGNAL_EMT
;
1474 #if defined (SIGFPE)
1475 if (hostsig
== SIGFPE
)
1476 return TARGET_SIGNAL_FPE
;
1478 #if defined (SIGKILL)
1479 if (hostsig
== SIGKILL
)
1480 return TARGET_SIGNAL_KILL
;
1482 #if defined (SIGBUS)
1483 if (hostsig
== SIGBUS
)
1484 return TARGET_SIGNAL_BUS
;
1486 #if defined (SIGSEGV)
1487 if (hostsig
== SIGSEGV
)
1488 return TARGET_SIGNAL_SEGV
;
1490 #if defined (SIGSYS)
1491 if (hostsig
== SIGSYS
)
1492 return TARGET_SIGNAL_SYS
;
1494 #if defined (SIGPIPE)
1495 if (hostsig
== SIGPIPE
)
1496 return TARGET_SIGNAL_PIPE
;
1498 #if defined (SIGALRM)
1499 if (hostsig
== SIGALRM
)
1500 return TARGET_SIGNAL_ALRM
;
1502 #if defined (SIGTERM)
1503 if (hostsig
== SIGTERM
)
1504 return TARGET_SIGNAL_TERM
;
1506 #if defined (SIGUSR1)
1507 if (hostsig
== SIGUSR1
)
1508 return TARGET_SIGNAL_USR1
;
1510 #if defined (SIGUSR2)
1511 if (hostsig
== SIGUSR2
)
1512 return TARGET_SIGNAL_USR2
;
1514 #if defined (SIGCLD)
1515 if (hostsig
== SIGCLD
)
1516 return TARGET_SIGNAL_CHLD
;
1518 #if defined (SIGCHLD)
1519 if (hostsig
== SIGCHLD
)
1520 return TARGET_SIGNAL_CHLD
;
1522 #if defined (SIGPWR)
1523 if (hostsig
== SIGPWR
)
1524 return TARGET_SIGNAL_PWR
;
1526 #if defined (SIGWINCH)
1527 if (hostsig
== SIGWINCH
)
1528 return TARGET_SIGNAL_WINCH
;
1530 #if defined (SIGURG)
1531 if (hostsig
== SIGURG
)
1532 return TARGET_SIGNAL_URG
;
1535 if (hostsig
== SIGIO
)
1536 return TARGET_SIGNAL_IO
;
1538 #if defined (SIGPOLL)
1539 if (hostsig
== SIGPOLL
)
1540 return TARGET_SIGNAL_POLL
;
1542 #if defined (SIGSTOP)
1543 if (hostsig
== SIGSTOP
)
1544 return TARGET_SIGNAL_STOP
;
1546 #if defined (SIGTSTP)
1547 if (hostsig
== SIGTSTP
)
1548 return TARGET_SIGNAL_TSTP
;
1550 #if defined (SIGCONT)
1551 if (hostsig
== SIGCONT
)
1552 return TARGET_SIGNAL_CONT
;
1554 #if defined (SIGTTIN)
1555 if (hostsig
== SIGTTIN
)
1556 return TARGET_SIGNAL_TTIN
;
1558 #if defined (SIGTTOU)
1559 if (hostsig
== SIGTTOU
)
1560 return TARGET_SIGNAL_TTOU
;
1562 #if defined (SIGVTALRM)
1563 if (hostsig
== SIGVTALRM
)
1564 return TARGET_SIGNAL_VTALRM
;
1566 #if defined (SIGPROF)
1567 if (hostsig
== SIGPROF
)
1568 return TARGET_SIGNAL_PROF
;
1570 #if defined (SIGXCPU)
1571 if (hostsig
== SIGXCPU
)
1572 return TARGET_SIGNAL_XCPU
;
1574 #if defined (SIGXFSZ)
1575 if (hostsig
== SIGXFSZ
)
1576 return TARGET_SIGNAL_XFSZ
;
1578 #if defined (SIGWIND)
1579 if (hostsig
== SIGWIND
)
1580 return TARGET_SIGNAL_WIND
;
1582 #if defined (SIGPHONE)
1583 if (hostsig
== SIGPHONE
)
1584 return TARGET_SIGNAL_PHONE
;
1586 #if defined (SIGLOST)
1587 if (hostsig
== SIGLOST
)
1588 return TARGET_SIGNAL_LOST
;
1590 #if defined (SIGWAITING)
1591 if (hostsig
== SIGWAITING
)
1592 return TARGET_SIGNAL_WAITING
;
1594 #if defined (SIGCANCEL)
1595 if (hostsig
== SIGCANCEL
)
1596 return TARGET_SIGNAL_CANCEL
;
1598 #if defined (SIGLWP)
1599 if (hostsig
== SIGLWP
)
1600 return TARGET_SIGNAL_LWP
;
1602 #if defined (SIGDANGER)
1603 if (hostsig
== SIGDANGER
)
1604 return TARGET_SIGNAL_DANGER
;
1606 #if defined (SIGGRANT)
1607 if (hostsig
== SIGGRANT
)
1608 return TARGET_SIGNAL_GRANT
;
1610 #if defined (SIGRETRACT)
1611 if (hostsig
== SIGRETRACT
)
1612 return TARGET_SIGNAL_RETRACT
;
1614 #if defined (SIGMSG)
1615 if (hostsig
== SIGMSG
)
1616 return TARGET_SIGNAL_MSG
;
1618 #if defined (SIGSOUND)
1619 if (hostsig
== SIGSOUND
)
1620 return TARGET_SIGNAL_SOUND
;
1622 #if defined (SIGSAK)
1623 if (hostsig
== SIGSAK
)
1624 return TARGET_SIGNAL_SAK
;
1626 #if defined (SIGPRIO)
1627 if (hostsig
== SIGPRIO
)
1628 return TARGET_SIGNAL_PRIO
;
1631 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1632 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1633 if (hostsig
== _NSIG
+ EXC_BAD_ACCESS
)
1634 return TARGET_EXC_BAD_ACCESS
;
1636 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1637 if (hostsig
== _NSIG
+ EXC_BAD_INSTRUCTION
)
1638 return TARGET_EXC_BAD_INSTRUCTION
;
1640 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1641 if (hostsig
== _NSIG
+ EXC_ARITHMETIC
)
1642 return TARGET_EXC_ARITHMETIC
;
1644 #if defined (EXC_EMULATION) && defined (_NSIG)
1645 if (hostsig
== _NSIG
+ EXC_EMULATION
)
1646 return TARGET_EXC_EMULATION
;
1648 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1649 if (hostsig
== _NSIG
+ EXC_SOFTWARE
)
1650 return TARGET_EXC_SOFTWARE
;
1652 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1653 if (hostsig
== _NSIG
+ EXC_BREAKPOINT
)
1654 return TARGET_EXC_BREAKPOINT
;
1657 #if defined (SIGINFO)
1658 if (hostsig
== SIGINFO
)
1659 return TARGET_SIGNAL_INFO
;
1662 #if defined (REALTIME_LO)
1663 if (hostsig
>= REALTIME_LO
&& hostsig
< REALTIME_HI
)
1665 /* This block of TARGET_SIGNAL_REALTIME value is in order. */
1666 if (33 <= hostsig
&& hostsig
<= 63)
1667 return (enum target_signal
)
1668 (hostsig
- 33 + (int) TARGET_SIGNAL_REALTIME_33
);
1669 else if (hostsig
== 32)
1670 return TARGET_SIGNAL_REALTIME_32
;
1672 error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
1675 return TARGET_SIGNAL_UNKNOWN
;
1678 /* Convert a OURSIG (an enum target_signal) to the form used by the
1679 target operating system (refered to as the ``host'') or zero if the
1680 equivalent host signal is not available. Set/clear OURSIG_OK
1684 do_target_signal_to_host (enum target_signal oursig
,
1690 case TARGET_SIGNAL_0
:
1693 #if defined (SIGHUP)
1694 case TARGET_SIGNAL_HUP
:
1697 #if defined (SIGINT)
1698 case TARGET_SIGNAL_INT
:
1701 #if defined (SIGQUIT)
1702 case TARGET_SIGNAL_QUIT
:
1705 #if defined (SIGILL)
1706 case TARGET_SIGNAL_ILL
:
1709 #if defined (SIGTRAP)
1710 case TARGET_SIGNAL_TRAP
:
1713 #if defined (SIGABRT)
1714 case TARGET_SIGNAL_ABRT
:
1717 #if defined (SIGEMT)
1718 case TARGET_SIGNAL_EMT
:
1721 #if defined (SIGFPE)
1722 case TARGET_SIGNAL_FPE
:
1725 #if defined (SIGKILL)
1726 case TARGET_SIGNAL_KILL
:
1729 #if defined (SIGBUS)
1730 case TARGET_SIGNAL_BUS
:
1733 #if defined (SIGSEGV)
1734 case TARGET_SIGNAL_SEGV
:
1737 #if defined (SIGSYS)
1738 case TARGET_SIGNAL_SYS
:
1741 #if defined (SIGPIPE)
1742 case TARGET_SIGNAL_PIPE
:
1745 #if defined (SIGALRM)
1746 case TARGET_SIGNAL_ALRM
:
1749 #if defined (SIGTERM)
1750 case TARGET_SIGNAL_TERM
:
1753 #if defined (SIGUSR1)
1754 case TARGET_SIGNAL_USR1
:
1757 #if defined (SIGUSR2)
1758 case TARGET_SIGNAL_USR2
:
1761 #if defined (SIGCHLD) || defined (SIGCLD)
1762 case TARGET_SIGNAL_CHLD
:
1763 #if defined (SIGCHLD)
1768 #endif /* SIGCLD or SIGCHLD */
1769 #if defined (SIGPWR)
1770 case TARGET_SIGNAL_PWR
:
1773 #if defined (SIGWINCH)
1774 case TARGET_SIGNAL_WINCH
:
1777 #if defined (SIGURG)
1778 case TARGET_SIGNAL_URG
:
1782 case TARGET_SIGNAL_IO
:
1785 #if defined (SIGPOLL)
1786 case TARGET_SIGNAL_POLL
:
1789 #if defined (SIGSTOP)
1790 case TARGET_SIGNAL_STOP
:
1793 #if defined (SIGTSTP)
1794 case TARGET_SIGNAL_TSTP
:
1797 #if defined (SIGCONT)
1798 case TARGET_SIGNAL_CONT
:
1801 #if defined (SIGTTIN)
1802 case TARGET_SIGNAL_TTIN
:
1805 #if defined (SIGTTOU)
1806 case TARGET_SIGNAL_TTOU
:
1809 #if defined (SIGVTALRM)
1810 case TARGET_SIGNAL_VTALRM
:
1813 #if defined (SIGPROF)
1814 case TARGET_SIGNAL_PROF
:
1817 #if defined (SIGXCPU)
1818 case TARGET_SIGNAL_XCPU
:
1821 #if defined (SIGXFSZ)
1822 case TARGET_SIGNAL_XFSZ
:
1825 #if defined (SIGWIND)
1826 case TARGET_SIGNAL_WIND
:
1829 #if defined (SIGPHONE)
1830 case TARGET_SIGNAL_PHONE
:
1833 #if defined (SIGLOST)
1834 case TARGET_SIGNAL_LOST
:
1837 #if defined (SIGWAITING)
1838 case TARGET_SIGNAL_WAITING
:
1841 #if defined (SIGCANCEL)
1842 case TARGET_SIGNAL_CANCEL
:
1845 #if defined (SIGLWP)
1846 case TARGET_SIGNAL_LWP
:
1849 #if defined (SIGDANGER)
1850 case TARGET_SIGNAL_DANGER
:
1853 #if defined (SIGGRANT)
1854 case TARGET_SIGNAL_GRANT
:
1857 #if defined (SIGRETRACT)
1858 case TARGET_SIGNAL_RETRACT
:
1861 #if defined (SIGMSG)
1862 case TARGET_SIGNAL_MSG
:
1865 #if defined (SIGSOUND)
1866 case TARGET_SIGNAL_SOUND
:
1869 #if defined (SIGSAK)
1870 case TARGET_SIGNAL_SAK
:
1873 #if defined (SIGPRIO)
1874 case TARGET_SIGNAL_PRIO
:
1878 case TARGET_SIGNAL_REALTIME_32
: return 32; /* by definition */
1880 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1881 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1882 case TARGET_EXC_BAD_ACCESS
:
1883 return _NSIG
+ EXC_BAD_ACCESS
;
1885 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1886 case TARGET_EXC_BAD_INSTRUCTION
:
1887 return _NSIG
+ EXC_BAD_INSTRUCTION
;
1889 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1890 case TARGET_EXC_ARITHMETIC
:
1891 return _NSIG
+ EXC_ARITHMETIC
;
1893 #if defined (EXC_EMULATION) && defined (_NSIG)
1894 case TARGET_EXC_EMULATION
:
1895 return _NSIG
+ EXC_EMULATION
;
1897 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1898 case TARGET_EXC_SOFTWARE
:
1899 return _NSIG
+ EXC_SOFTWARE
;
1901 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1902 case TARGET_EXC_BREAKPOINT
:
1903 return _NSIG
+ EXC_BREAKPOINT
;
1906 #if defined (SIGINFO)
1907 case TARGET_SIGNAL_INFO
:
1912 #if defined (REALTIME_LO)
1913 if (oursig
>= TARGET_SIGNAL_REALTIME_33
1914 && oursig
<= TARGET_SIGNAL_REALTIME_63
)
1917 (int) oursig
- (int) TARGET_SIGNAL_REALTIME_33
+ REALTIME_LO
;
1918 if (retsig
< REALTIME_HI
)
1928 target_signal_to_host_p (enum target_signal oursig
)
1931 do_target_signal_to_host (oursig
, &oursig_ok
);
1936 target_signal_to_host (enum target_signal oursig
)
1939 int targ_signo
= do_target_signal_to_host (oursig
, &oursig_ok
);
1942 /* The user might be trying to do "signal SIGSAK" where this system
1943 doesn't have SIGSAK. */
1944 warning ("Signal %s does not exist on this system.\n",
1945 target_signal_to_name (oursig
));
1952 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1953 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1954 translation of that in OURSTATUS. */
1956 store_waitstatus (ourstatus
, hoststatus
)
1957 struct target_waitstatus
*ourstatus
;
1960 #ifdef CHILD_SPECIAL_WAITSTATUS
1961 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1962 if it wants to deal with hoststatus. */
1963 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
1967 if (WIFEXITED (hoststatus
))
1969 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1970 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
1972 else if (!WIFSTOPPED (hoststatus
))
1974 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1975 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
1979 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
1980 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
1984 /* In some circumstances we allow a command to specify a numeric
1985 signal. The idea is to keep these circumstances limited so that
1986 users (and scripts) develop portable habits. For comparison,
1987 POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
1988 numeric signal at all is obscelescent. We are slightly more
1989 lenient and allow 1-15 which should match host signal numbers on
1990 most systems. Use of symbolic signal names is strongly encouraged. */
1993 target_signal_from_command (num
)
1996 if (num
>= 1 && num
<= 15)
1997 return (enum target_signal
) num
;
1998 error ("Only signals 1-15 are valid as numeric signals.\n\
1999 Use \"info signals\" for a list of symbolic signals.");
2002 /* Returns zero to leave the inferior alone, one to interrupt it. */
2003 int (*target_activity_function
) PARAMS ((void));
2004 int target_activity_fd
;
2006 /* Convert a normal process ID to a string. Returns the string in a static
2010 normal_pid_to_str (pid
)
2013 static char buf
[30];
2015 if (STREQ (current_target
.to_shortname
, "remote"))
2016 sprintf (buf
, "thread %d", pid
);
2018 sprintf (buf
, "process %d", pid
);
2023 /* Some targets (such as ttrace-based HPUX) don't allow us to request
2024 notification of inferior events such as fork and vork immediately
2025 after the inferior is created. (This because of how gdb gets an
2026 inferior created via invoking a shell to do it. In such a scenario,
2027 if the shell init file has commands in it, the shell will fork and
2028 exec for each of those commands, and we will see each such fork
2031 This function is used by all targets that allow us to request
2032 notification of forks, etc at inferior creation time; e.g., in
2033 target_acknowledge_forked_child.
2036 normal_target_post_startup_inferior (pid
)
2039 /* This space intentionally left blank. */
2042 /* Set up the handful of non-empty slots needed by the dummy target
2046 init_dummy_target ()
2048 dummy_target
.to_shortname
= "None";
2049 dummy_target
.to_longname
= "None";
2050 dummy_target
.to_doc
= "";
2051 dummy_target
.to_attach
= find_default_attach
;
2052 dummy_target
.to_require_attach
= find_default_require_attach
;
2053 dummy_target
.to_require_detach
= find_default_require_detach
;
2054 dummy_target
.to_create_inferior
= find_default_create_inferior
;
2055 dummy_target
.to_clone_and_follow_inferior
= find_default_clone_and_follow_inferior
;
2056 dummy_target
.to_stratum
= dummy_stratum
;
2057 dummy_target
.to_magic
= OPS_MAGIC
;
2061 static struct target_ops debug_target
;
2064 debug_to_open (args
, from_tty
)
2068 debug_target
.to_open (args
, from_tty
);
2070 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
2074 debug_to_close (quitting
)
2077 debug_target
.to_close (quitting
);
2079 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
2083 debug_to_attach (args
, from_tty
)
2087 debug_target
.to_attach (args
, from_tty
);
2089 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
2094 debug_to_post_attach (pid
)
2097 debug_target
.to_post_attach (pid
);
2099 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
2103 debug_to_require_attach (args
, from_tty
)
2107 debug_target
.to_require_attach (args
, from_tty
);
2109 fprintf_unfiltered (gdb_stdlog
,
2110 "target_require_attach (%s, %d)\n", args
, from_tty
);
2114 debug_to_detach (args
, from_tty
)
2118 debug_target
.to_detach (args
, from_tty
);
2120 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
2124 debug_to_require_detach (pid
, args
, from_tty
)
2129 debug_target
.to_require_detach (pid
, args
, from_tty
);
2131 fprintf_unfiltered (gdb_stdlog
,
2132 "target_require_detach (%d, %s, %d)\n", pid
, args
, from_tty
);
2136 debug_to_resume (pid
, step
, siggnal
)
2139 enum target_signal siggnal
;
2141 debug_target
.to_resume (pid
, step
, siggnal
);
2143 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", pid
,
2144 step
? "step" : "continue",
2145 target_signal_to_name (siggnal
));
2149 debug_to_wait (pid
, status
)
2151 struct target_waitstatus
*status
;
2155 retval
= debug_target
.to_wait (pid
, status
);
2157 fprintf_unfiltered (gdb_stdlog
,
2158 "target_wait (%d, status) = %d, ", pid
, retval
);
2159 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
2160 switch (status
->kind
)
2162 case TARGET_WAITKIND_EXITED
:
2163 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
2164 status
->value
.integer
);
2166 case TARGET_WAITKIND_STOPPED
:
2167 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
2168 target_signal_to_name (status
->value
.sig
));
2170 case TARGET_WAITKIND_SIGNALLED
:
2171 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
2172 target_signal_to_name (status
->value
.sig
));
2174 case TARGET_WAITKIND_LOADED
:
2175 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
2177 case TARGET_WAITKIND_FORKED
:
2178 fprintf_unfiltered (gdb_stdlog
, "forked\n");
2180 case TARGET_WAITKIND_VFORKED
:
2181 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
2183 case TARGET_WAITKIND_EXECD
:
2184 fprintf_unfiltered (gdb_stdlog
, "execd\n");
2186 case TARGET_WAITKIND_SPURIOUS
:
2187 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
2190 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
2198 debug_to_post_wait (pid
, status
)
2202 debug_target
.to_post_wait (pid
, status
);
2204 fprintf_unfiltered (gdb_stdlog
, "target_post_wait (%d, %d)\n",
2209 debug_to_fetch_registers (regno
)
2212 debug_target
.to_fetch_registers (regno
);
2214 fprintf_unfiltered (gdb_stdlog
, "target_fetch_registers (%s)",
2215 regno
!= -1 ? REGISTER_NAME (regno
) : "-1");
2217 fprintf_unfiltered (gdb_stdlog
, " = 0x%lx %ld",
2218 (unsigned long) read_register (regno
),
2219 (unsigned long) read_register (regno
));
2220 fprintf_unfiltered (gdb_stdlog
, "\n");
2224 debug_to_store_registers (regno
)
2227 debug_target
.to_store_registers (regno
);
2229 if (regno
>= 0 && regno
< NUM_REGS
)
2230 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%s) = 0x%lx %ld\n",
2231 REGISTER_NAME (regno
),
2232 (unsigned long) read_register (regno
),
2233 (unsigned long) read_register (regno
));
2235 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%d)\n", regno
);
2239 debug_to_prepare_to_store ()
2241 debug_target
.to_prepare_to_store ();
2243 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
2247 debug_to_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
2252 struct target_ops
*target
;
2256 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
, target
);
2258 fprintf_unfiltered (gdb_stdlog
,
2259 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
2260 (unsigned int) memaddr
, /* possable truncate long long */
2261 len
, write
? "write" : "read", retval
);
2269 fputs_unfiltered (", bytes =", gdb_stdlog
);
2270 for (i
= 0; i
< retval
; i
++)
2272 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
2273 fprintf_unfiltered (gdb_stdlog
, "\n");
2274 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
2278 fputc_unfiltered ('\n', gdb_stdlog
);
2284 debug_to_files_info (target
)
2285 struct target_ops
*target
;
2287 debug_target
.to_files_info (target
);
2289 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
2293 debug_to_insert_breakpoint (addr
, save
)
2299 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
2301 fprintf_unfiltered (gdb_stdlog
,
2302 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
2303 (unsigned long) addr
,
2304 (unsigned long) retval
);
2309 debug_to_remove_breakpoint (addr
, save
)
2315 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
2317 fprintf_unfiltered (gdb_stdlog
,
2318 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
2319 (unsigned long) addr
,
2320 (unsigned long) retval
);
2325 debug_to_terminal_init ()
2327 debug_target
.to_terminal_init ();
2329 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
2333 debug_to_terminal_inferior ()
2335 debug_target
.to_terminal_inferior ();
2337 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
2341 debug_to_terminal_ours_for_output ()
2343 debug_target
.to_terminal_ours_for_output ();
2345 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
2349 debug_to_terminal_ours ()
2351 debug_target
.to_terminal_ours ();
2353 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
2357 debug_to_terminal_info (arg
, from_tty
)
2361 debug_target
.to_terminal_info (arg
, from_tty
);
2363 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
2370 debug_target
.to_kill ();
2372 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
2376 debug_to_load (args
, from_tty
)
2380 debug_target
.to_load (args
, from_tty
);
2382 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
2386 debug_to_lookup_symbol (name
, addrp
)
2392 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
2394 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
2400 debug_to_create_inferior (exec_file
, args
, env
)
2405 debug_target
.to_create_inferior (exec_file
, args
, env
);
2407 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx)\n",
2412 debug_to_post_startup_inferior (pid
)
2415 debug_target
.to_post_startup_inferior (pid
);
2417 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
2422 debug_to_acknowledge_created_inferior (pid
)
2425 debug_target
.to_acknowledge_created_inferior (pid
);
2427 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
2432 debug_to_clone_and_follow_inferior (child_pid
, followed_child
)
2434 int *followed_child
;
2436 debug_target
.to_clone_and_follow_inferior (child_pid
, followed_child
);
2438 fprintf_unfiltered (gdb_stdlog
,
2439 "target_clone_and_follow_inferior (%d, %d)\n",
2440 child_pid
, *followed_child
);
2444 debug_to_post_follow_inferior_by_clone ()
2446 debug_target
.to_post_follow_inferior_by_clone ();
2448 fprintf_unfiltered (gdb_stdlog
, "target_post_follow_inferior_by_clone ()\n");
2452 debug_to_insert_fork_catchpoint (pid
)
2457 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
2459 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
2466 debug_to_remove_fork_catchpoint (pid
)
2471 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
2473 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
2480 debug_to_insert_vfork_catchpoint (pid
)
2485 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
2487 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)= %d\n",
2494 debug_to_remove_vfork_catchpoint (pid
)
2499 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
2501 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
2508 debug_to_has_forked (pid
, child_pid
)
2514 has_forked
= debug_target
.to_has_forked (pid
, child_pid
);
2516 fprintf_unfiltered (gdb_stdlog
, "target_has_forked (%d, %d) = %d\n",
2517 pid
, *child_pid
, has_forked
);
2523 debug_to_has_vforked (pid
, child_pid
)
2529 has_vforked
= debug_target
.to_has_vforked (pid
, child_pid
);
2531 fprintf_unfiltered (gdb_stdlog
, "target_has_vforked (%d, %d) = %d\n",
2532 pid
, *child_pid
, has_vforked
);
2538 debug_to_can_follow_vfork_prior_to_exec ()
2540 int can_immediately_follow_vfork
;
2542 can_immediately_follow_vfork
= debug_target
.to_can_follow_vfork_prior_to_exec ();
2544 fprintf_unfiltered (gdb_stdlog
, "target_can_follow_vfork_prior_to_exec () = %d\n",
2545 can_immediately_follow_vfork
);
2547 return can_immediately_follow_vfork
;
2551 debug_to_post_follow_vfork (parent_pid
, followed_parent
, child_pid
, followed_child
)
2553 int followed_parent
;
2557 debug_target
.to_post_follow_vfork (parent_pid
, followed_parent
, child_pid
, followed_child
);
2559 fprintf_unfiltered (gdb_stdlog
,
2560 "target_post_follow_vfork (%d, %d, %d, %d)\n",
2561 parent_pid
, followed_parent
, child_pid
, followed_child
);
2565 debug_to_insert_exec_catchpoint (pid
)
2570 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
2572 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
2579 debug_to_remove_exec_catchpoint (pid
)
2584 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
2586 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2593 debug_to_has_execd (pid
, execd_pathname
)
2595 char **execd_pathname
;
2599 has_execd
= debug_target
.to_has_execd (pid
, execd_pathname
);
2601 fprintf_unfiltered (gdb_stdlog
, "target_has_execd (%d, %s) = %d\n",
2602 pid
, (*execd_pathname
? *execd_pathname
: "<NULL>"),
2609 debug_to_reported_exec_events_per_exec_call ()
2611 int reported_exec_events
;
2613 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2615 fprintf_unfiltered (gdb_stdlog
,
2616 "target_reported_exec_events_per_exec_call () = %d\n",
2617 reported_exec_events
);
2619 return reported_exec_events
;
2623 debug_to_has_syscall_event (pid
, kind
, syscall_id
)
2625 enum target_waitkind
*kind
;
2628 int has_syscall_event
;
2629 char *kind_spelling
= "??";
2631 has_syscall_event
= debug_target
.to_has_syscall_event (pid
, kind
, syscall_id
);
2632 if (has_syscall_event
)
2636 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2637 kind_spelling
= "SYSCALL_ENTRY";
2639 case TARGET_WAITKIND_SYSCALL_RETURN
:
2640 kind_spelling
= "SYSCALL_RETURN";
2647 fprintf_unfiltered (gdb_stdlog
,
2648 "target_has_syscall_event (%d, %s, %d) = %d\n",
2649 pid
, kind_spelling
, *syscall_id
, has_syscall_event
);
2651 return has_syscall_event
;
2655 debug_to_has_exited (pid
, wait_status
, exit_status
)
2662 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2664 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2665 pid
, wait_status
, *exit_status
, has_exited
);
2671 debug_to_mourn_inferior ()
2673 debug_target
.to_mourn_inferior ();
2675 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2683 retval
= debug_target
.to_can_run ();
2685 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2691 debug_to_notice_signals (pid
)
2694 debug_target
.to_notice_signals (pid
);
2696 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n", pid
);
2700 debug_to_thread_alive (pid
)
2705 retval
= debug_target
.to_thread_alive (pid
);
2707 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2716 debug_target
.to_stop ();
2718 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2722 debug_to_query (type
, req
, resp
, siz
)
2730 retval
= debug_target
.to_query (type
, req
, resp
, siz
);
2732 fprintf_unfiltered (gdb_stdlog
, "target_query (%c, %s, %s, %d) = %d\n", type
, req
, resp
, *siz
, retval
);
2738 debug_to_rcmd (char *command
,
2739 struct gdb_file
*outbuf
)
2741 debug_target
.to_rcmd (command
, outbuf
);
2742 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2745 static struct symtab_and_line
*
2746 debug_to_enable_exception_callback (kind
, enable
)
2747 enum exception_event_kind kind
;
2750 struct symtab_and_line
*result
;
2751 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2752 fprintf_unfiltered (gdb_stdlog
,
2753 "target get_exception_callback_sal (%d, %d)\n",
2758 static struct exception_event_record
*
2759 debug_to_get_current_exception_event ()
2761 struct exception_event_record
*result
;
2762 result
= debug_target
.to_get_current_exception_event ();
2763 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2768 debug_to_pid_to_exec_file (pid
)
2773 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2775 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2782 debug_to_core_file_to_sym_file (core
)
2787 sym_file
= debug_target
.to_core_file_to_sym_file (core
);
2789 fprintf_unfiltered (gdb_stdlog
, "target_core_file_to_sym_file (%s) = %s\n",
2796 setup_target_debug ()
2798 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2800 current_target
.to_open
= debug_to_open
;
2801 current_target
.to_close
= debug_to_close
;
2802 current_target
.to_attach
= debug_to_attach
;
2803 current_target
.to_post_attach
= debug_to_post_attach
;
2804 current_target
.to_require_attach
= debug_to_require_attach
;
2805 current_target
.to_detach
= debug_to_detach
;
2806 current_target
.to_require_detach
= debug_to_require_detach
;
2807 current_target
.to_resume
= debug_to_resume
;
2808 current_target
.to_wait
= debug_to_wait
;
2809 current_target
.to_post_wait
= debug_to_post_wait
;
2810 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2811 current_target
.to_store_registers
= debug_to_store_registers
;
2812 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2813 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2814 current_target
.to_files_info
= debug_to_files_info
;
2815 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2816 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2817 current_target
.to_terminal_init
= debug_to_terminal_init
;
2818 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2819 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2820 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2821 current_target
.to_terminal_info
= debug_to_terminal_info
;
2822 current_target
.to_kill
= debug_to_kill
;
2823 current_target
.to_load
= debug_to_load
;
2824 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2825 current_target
.to_create_inferior
= debug_to_create_inferior
;
2826 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2827 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2828 current_target
.to_clone_and_follow_inferior
= debug_to_clone_and_follow_inferior
;
2829 current_target
.to_post_follow_inferior_by_clone
= debug_to_post_follow_inferior_by_clone
;
2830 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2831 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2832 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2833 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2834 current_target
.to_has_forked
= debug_to_has_forked
;
2835 current_target
.to_has_vforked
= debug_to_has_vforked
;
2836 current_target
.to_can_follow_vfork_prior_to_exec
= debug_to_can_follow_vfork_prior_to_exec
;
2837 current_target
.to_post_follow_vfork
= debug_to_post_follow_vfork
;
2838 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2839 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2840 current_target
.to_has_execd
= debug_to_has_execd
;
2841 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2842 current_target
.to_has_syscall_event
= debug_to_has_syscall_event
;
2843 current_target
.to_has_exited
= debug_to_has_exited
;
2844 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2845 current_target
.to_can_run
= debug_to_can_run
;
2846 current_target
.to_notice_signals
= debug_to_notice_signals
;
2847 current_target
.to_thread_alive
= debug_to_thread_alive
;
2848 current_target
.to_stop
= debug_to_stop
;
2849 current_target
.to_query
= debug_to_query
;
2850 current_target
.to_rcmd
= debug_to_rcmd
;
2851 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
2852 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
2853 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2854 current_target
.to_core_file_to_sym_file
= debug_to_core_file_to_sym_file
;
2859 static char targ_desc
[] =
2860 "Names of targets and files being debugged.\n\
2861 Shows the entire stack of targets currently in use (including the exec-file,\n\
2862 core-file, and process, if any), as well as the symbol file name.";
2865 do_monitor_command (char *cmd
,
2868 if ((current_target
.to_rcmd
== (void*) tcomplain
)
2869 || (current_target
.to_rcmd
== debug_to_rcmd
2870 && (debug_target
.to_rcmd
== (void*) tcomplain
)))
2872 error ("\"monitor\" command not supported by this target.\n");
2874 target_rcmd (cmd
, gdb_stdtarg
);
2878 initialize_targets ()
2880 init_dummy_target ();
2881 push_target (&dummy_target
);
2883 add_info ("target", target_info
, targ_desc
);
2884 add_info ("files", target_info
, targ_desc
);
2887 add_set_cmd ("targetdebug", class_maintenance
, var_zinteger
,
2888 (char *) &targetdebug
,
2889 "Set target debugging.\n\
2890 When non-zero, target debugging is enabled.", &setlist
),
2894 add_com ("monitor", class_obscure
, do_monitor_command
,
2895 "Send a command to the remote monitor (remote targets only).");
2897 if (!STREQ (signals
[TARGET_SIGNAL_LAST
].string
, "TARGET_SIGNAL_MAGIC"))