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
);
277 nomemory (memaddr
, myaddr
, len
, write
, t
)
282 struct target_ops
*t
;
284 errno
= EIO
; /* Can't read/write this location */
285 return 0; /* No bytes handled */
291 error ("You can't do that when your target is `%s'",
292 current_target
.to_shortname
);
298 error ("You can't do that without a process to debug.");
303 nosymbol (name
, addrp
)
307 return 1; /* Symbol does not exist in target env */
317 error ("No run-time support for this");
323 default_terminal_info (args
, from_tty
)
327 printf_unfiltered ("No saved terminal information.\n");
330 /* This is the default target_create_inferior and target_attach function.
331 If the current target is executing, it asks whether to kill it off.
332 If this function returns without calling error(), it has killed off
333 the target, and the operation should be attempted. */
336 kill_or_be_killed (from_tty
)
339 if (target_has_execution
)
341 printf_unfiltered ("You are already running a program:\n");
342 target_files_info ();
343 if (query ("Kill it? "))
346 if (target_has_execution
)
347 error ("Killing the program did not help.");
352 error ("Program not killed.");
359 maybe_kill_then_attach (args
, from_tty
)
363 kill_or_be_killed (from_tty
);
364 target_attach (args
, from_tty
);
368 maybe_kill_then_create_inferior (exec
, args
, env
)
373 kill_or_be_killed (0);
374 target_create_inferior (exec
, args
, env
);
378 default_clone_and_follow_inferior (child_pid
, followed_child
)
382 target_clone_and_follow_inferior (child_pid
, followed_child
);
385 /* Clean up a target struct so it no longer has any zero pointers in it.
386 We default entries, at least to stubs that print error messages. */
390 struct target_ops
*t
;
393 #define de_fault(field, value) \
394 if (!t->field) t->field = value
396 /* FIELD DEFAULT VALUE */
398 de_fault (to_open
, (void (*)PARAMS ((char *, int))) tcomplain
);
399 de_fault (to_close
, (void (*)PARAMS ((int))) target_ignore
);
400 de_fault (to_attach
, maybe_kill_then_attach
);
401 de_fault (to_post_attach
, (void (*)PARAMS ((int))) target_ignore
);
402 de_fault (to_require_attach
, maybe_kill_then_attach
);
403 de_fault (to_detach
, (void (*)PARAMS ((char *, int))) target_ignore
);
404 de_fault (to_require_detach
, (void (*)PARAMS ((int, char *, int))) target_ignore
);
405 de_fault (to_resume
, (void (*)PARAMS ((int, int, enum target_signal
))) noprocess
);
406 de_fault (to_wait
, (int (*)PARAMS ((int, struct target_waitstatus
*))) noprocess
);
407 de_fault (to_post_wait
, (void (*)PARAMS ((int, int))) target_ignore
);
408 de_fault (to_fetch_registers
, (void (*)PARAMS ((int))) target_ignore
);
409 de_fault (to_store_registers
, (void (*)PARAMS ((int))) noprocess
);
410 de_fault (to_prepare_to_store
, (void (*)PARAMS ((void))) noprocess
);
411 de_fault (to_xfer_memory
, (int (*)PARAMS ((CORE_ADDR
, char *, int, int, struct target_ops
*))) nomemory
);
412 de_fault (to_files_info
, (void (*)PARAMS ((struct target_ops
*))) target_ignore
);
413 de_fault (to_insert_breakpoint
, memory_insert_breakpoint
);
414 de_fault (to_remove_breakpoint
, memory_remove_breakpoint
);
415 de_fault (to_terminal_init
, (void (*)PARAMS ((void))) target_ignore
);
416 de_fault (to_terminal_inferior
, (void (*)PARAMS ((void))) target_ignore
);
417 de_fault (to_terminal_ours_for_output
, (void (*)PARAMS ((void))) target_ignore
);
418 de_fault (to_terminal_ours
, (void (*)PARAMS ((void))) target_ignore
);
419 de_fault (to_terminal_info
, default_terminal_info
);
420 de_fault (to_kill
, (void (*)PARAMS ((void))) noprocess
);
421 de_fault (to_load
, (void (*)PARAMS ((char *, int))) tcomplain
);
422 de_fault (to_lookup_symbol
, (int (*)PARAMS ((char *, CORE_ADDR
*))) nosymbol
);
423 de_fault (to_create_inferior
, maybe_kill_then_create_inferior
);
424 de_fault (to_post_startup_inferior
, (void (*)PARAMS ((int))) target_ignore
);
425 de_fault (to_acknowledge_created_inferior
, (void (*)PARAMS ((int))) target_ignore
);
426 de_fault (to_clone_and_follow_inferior
, default_clone_and_follow_inferior
);
427 de_fault (to_post_follow_inferior_by_clone
, (void (*)PARAMS ((void))) target_ignore
);
428 de_fault (to_insert_fork_catchpoint
, (int (*)PARAMS ((int))) tcomplain
);
429 de_fault (to_remove_fork_catchpoint
, (int (*)PARAMS ((int))) tcomplain
);
430 de_fault (to_insert_vfork_catchpoint
, (int (*)PARAMS ((int))) tcomplain
);
431 de_fault (to_remove_vfork_catchpoint
, (int (*)PARAMS ((int))) tcomplain
);
432 de_fault (to_has_forked
, (int (*)PARAMS ((int, int *))) return_zero
);
433 de_fault (to_has_vforked
, (int (*)PARAMS ((int, int *))) return_zero
);
434 de_fault (to_can_follow_vfork_prior_to_exec
, (int (*)PARAMS ((void))) return_zero
);
435 de_fault (to_post_follow_vfork
, (void (*)PARAMS ((int, int, int, int))) target_ignore
);
436 de_fault (to_insert_exec_catchpoint
, (int (*)PARAMS ((int))) tcomplain
);
437 de_fault (to_remove_exec_catchpoint
, (int (*)PARAMS ((int))) tcomplain
);
438 de_fault (to_has_execd
, (int (*)PARAMS ((int, char **))) return_zero
);
439 de_fault (to_reported_exec_events_per_exec_call
, (int (*)PARAMS ((void))) return_one
);
440 de_fault (to_has_syscall_event
, (int (*)PARAMS ((int, enum target_waitkind
*, int *))) return_zero
);
441 de_fault (to_has_exited
, (int (*)PARAMS ((int, int, int *))) return_zero
);
442 de_fault (to_mourn_inferior
, (void (*)PARAMS ((void))) noprocess
);
443 de_fault (to_can_run
, return_zero
);
444 de_fault (to_notice_signals
, (void (*)PARAMS ((int))) target_ignore
);
445 de_fault (to_thread_alive
, (int (*)PARAMS ((int))) target_ignore
);
446 de_fault (to_stop
, (void (*)PARAMS ((void))) target_ignore
);
447 de_fault (to_query
, (int (*)PARAMS ((int /*char */ , char *, char *, int *))) target_ignore
);
448 de_fault (to_rcmd
, (void (*) (char *, struct gdb_file
*)) tcomplain
);
449 de_fault (to_enable_exception_callback
, (struct symtab_and_line
* (*)PARAMS ((enum exception_event_kind
, int))) nosupport_runtime
);
450 de_fault (to_get_current_exception_event
, (struct exception_event_record
* (*)PARAMS ((void))) nosupport_runtime
);
452 de_fault (to_pid_to_exec_file
, (char *(*)PARAMS ((int))) return_zero
);
453 de_fault (to_core_file_to_sym_file
, (char *(*)PARAMS ((char *))) return_zero
);
454 de_fault (to_can_async_p
, (int (*) (void)) return_zero
);
455 de_fault (to_is_async_p
, (int (*) (void)) return_zero
);
456 de_fault (to_async
, (void (*) (void (*) (enum inferior_event_type
, void*), void*)) tcomplain
);
460 /* Go through the target stack from top to bottom, copying over zero entries in
461 current_target. In effect, we are doing class inheritance through the
462 pushed target vectors. */
465 update_current_target ()
467 struct target_stack_item
*item
;
468 struct target_ops
*t
;
470 /* First, reset current_target */
471 memset (¤t_target
, 0, sizeof current_target
);
473 for (item
= target_stack
; item
; item
= item
->next
)
475 t
= item
->target_ops
;
477 #define INHERIT(FIELD, TARGET) \
478 if (!current_target.FIELD) \
479 current_target.FIELD = TARGET->FIELD
481 INHERIT (to_shortname
, t
);
482 INHERIT (to_longname
, t
);
484 INHERIT (to_open
, t
);
485 INHERIT (to_close
, t
);
486 INHERIT (to_attach
, t
);
487 INHERIT (to_post_attach
, t
);
488 INHERIT (to_require_attach
, t
);
489 INHERIT (to_detach
, t
);
490 INHERIT (to_require_detach
, t
);
491 INHERIT (to_resume
, t
);
492 INHERIT (to_wait
, t
);
493 INHERIT (to_post_wait
, t
);
494 INHERIT (to_fetch_registers
, t
);
495 INHERIT (to_store_registers
, t
);
496 INHERIT (to_prepare_to_store
, t
);
497 INHERIT (to_xfer_memory
, t
);
498 INHERIT (to_files_info
, t
);
499 INHERIT (to_insert_breakpoint
, t
);
500 INHERIT (to_remove_breakpoint
, t
);
501 INHERIT (to_terminal_init
, t
);
502 INHERIT (to_terminal_inferior
, t
);
503 INHERIT (to_terminal_ours_for_output
, t
);
504 INHERIT (to_terminal_ours
, t
);
505 INHERIT (to_terminal_info
, t
);
506 INHERIT (to_kill
, t
);
507 INHERIT (to_load
, t
);
508 INHERIT (to_lookup_symbol
, t
);
509 INHERIT (to_create_inferior
, t
);
510 INHERIT (to_post_startup_inferior
, t
);
511 INHERIT (to_acknowledge_created_inferior
, t
);
512 INHERIT (to_clone_and_follow_inferior
, t
);
513 INHERIT (to_post_follow_inferior_by_clone
, t
);
514 INHERIT (to_insert_fork_catchpoint
, t
);
515 INHERIT (to_remove_fork_catchpoint
, t
);
516 INHERIT (to_insert_vfork_catchpoint
, t
);
517 INHERIT (to_remove_vfork_catchpoint
, t
);
518 INHERIT (to_has_forked
, t
);
519 INHERIT (to_has_vforked
, t
);
520 INHERIT (to_can_follow_vfork_prior_to_exec
, t
);
521 INHERIT (to_post_follow_vfork
, t
);
522 INHERIT (to_insert_exec_catchpoint
, t
);
523 INHERIT (to_remove_exec_catchpoint
, t
);
524 INHERIT (to_has_execd
, t
);
525 INHERIT (to_reported_exec_events_per_exec_call
, t
);
526 INHERIT (to_has_syscall_event
, t
);
527 INHERIT (to_has_exited
, t
);
528 INHERIT (to_mourn_inferior
, t
);
529 INHERIT (to_can_run
, t
);
530 INHERIT (to_notice_signals
, t
);
531 INHERIT (to_thread_alive
, t
);
532 INHERIT (to_find_new_threads
, t
);
533 INHERIT (to_stop
, t
);
534 INHERIT (to_query
, t
);
535 INHERIT (to_rcmd
, t
);
536 INHERIT (to_enable_exception_callback
, t
);
537 INHERIT (to_get_current_exception_event
, t
);
538 INHERIT (to_pid_to_exec_file
, t
);
539 INHERIT (to_core_file_to_sym_file
, t
);
540 INHERIT (to_stratum
, t
);
541 INHERIT (DONT_USE
, t
);
542 INHERIT (to_has_all_memory
, t
);
543 INHERIT (to_has_memory
, t
);
544 INHERIT (to_has_stack
, t
);
545 INHERIT (to_has_registers
, t
);
546 INHERIT (to_has_execution
, t
);
547 INHERIT (to_has_thread_control
, t
);
548 INHERIT (to_sections
, t
);
549 INHERIT (to_sections_end
, t
);
550 INHERIT (to_can_async_p
, t
);
551 INHERIT (to_is_async_p
, t
);
552 INHERIT (to_async
, t
);
553 INHERIT (to_magic
, t
);
559 /* Push a new target type into the stack of the existing target accessors,
560 possibly superseding some of the existing accessors.
562 Result is zero if the pushed target ended up on top of the stack,
563 nonzero if at least one target is on top of it.
565 Rather than allow an empty stack, we always have the dummy target at
566 the bottom stratum, so we can call the function vectors without
571 struct target_ops
*t
;
573 struct target_stack_item
*cur
, *prev
, *tmp
;
575 /* Check magic number. If wrong, it probably means someone changed
576 the struct definition, but not all the places that initialize one. */
577 if (t
->to_magic
!= OPS_MAGIC
)
579 fprintf_unfiltered (gdb_stderr
,
580 "Magic number of %s target struct wrong\n",
585 /* Find the proper stratum to install this target in. */
587 for (prev
= NULL
, cur
= target_stack
; cur
; prev
= cur
, cur
= cur
->next
)
589 if ((int) (t
->to_stratum
) >= (int) (cur
->target_ops
->to_stratum
))
593 /* If there's already targets at this stratum, remove them. */
596 while (t
->to_stratum
== cur
->target_ops
->to_stratum
)
598 /* There's already something on this stratum. Close it off. */
599 if (cur
->target_ops
->to_close
)
600 (cur
->target_ops
->to_close
) (0);
602 prev
->next
= cur
->next
; /* Unchain old target_ops */
604 target_stack
= cur
->next
; /* Unchain first on list */
610 /* We have removed all targets in our stratum, now add the new one. */
612 tmp
= (struct target_stack_item
*)
613 xmalloc (sizeof (struct target_stack_item
));
622 update_current_target ();
624 cleanup_target (¤t_target
); /* Fill in the gaps */
627 setup_target_debug ();
632 /* Remove a target_ops vector from the stack, wherever it may be.
633 Return how many times it was removed (0 or 1). */
637 struct target_ops
*t
;
639 struct target_stack_item
*cur
, *prev
;
642 t
->to_close (0); /* Let it clean up */
644 /* Look for the specified target. Note that we assume that a target
645 can only occur once in the target stack. */
647 for (cur
= target_stack
, prev
= NULL
; cur
; prev
= cur
, cur
= cur
->next
)
648 if (cur
->target_ops
== t
)
652 return 0; /* Didn't find target_ops, quit now */
654 /* Unchain the target */
657 target_stack
= cur
->next
;
659 prev
->next
= cur
->next
;
661 free (cur
); /* Release the target_stack_item */
663 update_current_target ();
664 cleanup_target (¤t_target
);
672 (current_target
.to_close
) (0); /* Let it clean up */
673 if (unpush_target (target_stack
->target_ops
) == 1)
676 fprintf_unfiltered (gdb_stderr
,
677 "pop_target couldn't find target %s\n",
678 current_target
.to_shortname
);
683 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
685 /* target_read_string -- read a null terminated string, up to LEN bytes,
686 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
687 Set *STRING to a pointer to malloc'd memory containing the data; the caller
688 is responsible for freeing it. Return the number of bytes successfully
692 target_read_string (memaddr
, string
, len
, errnop
)
698 int tlen
, origlen
, offset
, i
;
702 int buffer_allocated
;
704 unsigned int nbytes_read
= 0;
706 /* Small for testing. */
707 buffer_allocated
= 4;
708 buffer
= xmalloc (buffer_allocated
);
715 tlen
= MIN (len
, 4 - (memaddr
& 3));
716 offset
= memaddr
& 3;
718 errcode
= target_xfer_memory (memaddr
& ~3, buf
, 4, 0, NULL
);
721 /* The transfer request might have crossed the boundary to an
722 unallocated region of memory. Retry the transfer, requesting
726 errcode
= target_xfer_memory (memaddr
, buf
, 1, 0, NULL
);
731 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
734 bytes
= bufptr
- buffer
;
735 buffer_allocated
*= 2;
736 buffer
= xrealloc (buffer
, buffer_allocated
);
737 bufptr
= buffer
+ bytes
;
740 for (i
= 0; i
< tlen
; i
++)
742 *bufptr
++ = buf
[i
+ offset
];
743 if (buf
[i
+ offset
] == '\000')
745 nbytes_read
+= i
+ 1;
762 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
763 GDB's memory at MYADDR. Returns either 0 for success or an errno value
766 If an error occurs, no guarantee is made about the contents of the data at
767 MYADDR. In particular, the caller should not depend upon partial reads
768 filling the buffer with good data. There is no way for the caller to know
769 how much good data might have been transfered anyway. Callers that can
770 deal with partial reads should call target_read_memory_partial. */
773 target_read_memory (memaddr
, myaddr
, len
)
778 return target_xfer_memory (memaddr
, myaddr
, len
, 0, NULL
);
782 target_read_memory_section (memaddr
, myaddr
, len
, bfd_section
)
786 asection
*bfd_section
;
788 return target_xfer_memory (memaddr
, myaddr
, len
, 0, bfd_section
);
792 target_write_memory (memaddr
, myaddr
, len
)
797 return target_xfer_memory (memaddr
, myaddr
, len
, 1, NULL
);
800 /* This variable is used to pass section information down to targets. This
801 *should* be done by adding an argument to the target_xfer_memory function
802 of all the targets, but I didn't feel like changing 50+ files. */
804 asection
*target_memory_bfd_section
= NULL
;
806 /* Move memory to or from the targets. Iterate until all of it has
807 been moved, if necessary. The top target gets priority; anything
808 it doesn't want, is offered to the next one down, etc. Note the
809 business with curlen: if an early target says "no, but I have a
810 boundary overlapping this xfer" then we shorten what we offer to
811 the subsequent targets so the early guy will get a chance at the
812 tail before the subsequent ones do.
814 Result is 0 or errno value. */
817 target_xfer_memory (memaddr
, myaddr
, len
, write
, bfd_section
)
822 asection
*bfd_section
;
826 struct target_ops
*t
;
827 struct target_stack_item
*item
;
829 /* Zero length requests are ok and require no work. */
833 target_memory_bfd_section
= bfd_section
;
835 /* to_xfer_memory is not guaranteed to set errno, even when it returns
839 /* The quick case is that the top target does it all. */
840 res
= current_target
.to_xfer_memory
841 (memaddr
, myaddr
, len
, write
, ¤t_target
);
847 /* If res <= 0 then we call it again in the loop. Ah well. */
851 curlen
= len
; /* Want to do it all */
852 for (item
= target_stack
; item
; item
= item
->next
)
854 t
= item
->target_ops
;
855 if (!t
->to_has_memory
)
858 res
= t
->to_xfer_memory (memaddr
, myaddr
, curlen
, write
, t
);
860 break; /* Handled all or part of xfer */
861 if (t
->to_has_all_memory
)
867 /* If this address is for nonexistent memory,
868 read zeros if reading, or do nothing if writing. Return error. */
870 memset (myaddr
, 0, len
);
881 return 0; /* We managed to cover it all somehow. */
885 /* Perform a partial memory transfer. */
888 target_xfer_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
,
889 int write_p
, int *err
)
894 struct target_ops
*t
;
895 struct target_stack_item
*item
;
897 /* Zero length requests are ok and require no work. */
904 /* The quick case is that the top target does it all. */
905 res
= current_target
.to_xfer_memory (memaddr
, buf
, len
, write_p
, ¤t_target
);
912 /* xfer memory doesn't always reliably set errno. */
915 /* Try all levels of the target stack to see one can handle it. */
916 for (item
= target_stack
; item
; item
= item
->next
)
918 t
= item
->target_ops
;
919 if (!t
->to_has_memory
)
921 res
= t
->to_xfer_memory (memaddr
, buf
, len
, write_p
, t
);
924 /* Handled all or part of xfer */
928 if (t
->to_has_all_memory
)
932 /* Total failure. Return error. */
943 target_read_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
945 return target_xfer_memory_partial (memaddr
, buf
, len
, 0, err
);
949 target_write_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
951 return target_xfer_memory_partial (memaddr
, buf
, len
, 1, err
);
956 target_info (args
, from_tty
)
960 struct target_ops
*t
;
961 struct target_stack_item
*item
;
964 if (symfile_objfile
!= NULL
)
965 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
967 #ifdef FILES_INFO_HOOK
968 if (FILES_INFO_HOOK ())
972 for (item
= target_stack
; item
; item
= item
->next
)
974 t
= item
->target_ops
;
976 if (!t
->to_has_memory
)
979 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
982 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
983 printf_unfiltered ("%s:\n", t
->to_longname
);
984 (t
->to_files_info
) (t
);
985 has_all_mem
= t
->to_has_all_memory
;
989 /* This is to be called by the open routine before it does
993 target_preopen (from_tty
)
998 if (target_has_execution
)
1001 || query ("A program is being debugged already. Kill it? "))
1004 error ("Program not killed.");
1007 /* Calling target_kill may remove the target from the stack. But if
1008 it doesn't (which seems like a win for UDI), remove it now. */
1010 if (target_has_execution
)
1014 /* Detach a target after doing deferred register stores. */
1017 target_detach (args
, from_tty
)
1021 /* Handle any optimized stores to the inferior. */
1022 #ifdef DO_DEFERRED_STORES
1025 (current_target
.to_detach
) (args
, from_tty
);
1029 target_link (modname
, t_reloc
)
1033 if (STREQ (current_target
.to_shortname
, "rombug"))
1035 (current_target
.to_lookup_symbol
) (modname
, t_reloc
);
1037 error ("Unable to link to %s and get relocation in rombug", modname
);
1040 *t_reloc
= (CORE_ADDR
) -1;
1043 /* Look through the list of possible targets for a target that can
1044 execute a run or attach command without any other data. This is
1045 used to locate the default process stratum.
1047 Result is always valid (error() is called for errors). */
1049 static struct target_ops
*
1050 find_default_run_target (do_mesg
)
1053 struct target_ops
**t
;
1054 struct target_ops
*runable
= NULL
;
1059 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1062 if ((*t
)->to_can_run
&& target_can_run (*t
))
1070 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
1076 find_default_attach (args
, from_tty
)
1080 struct target_ops
*t
;
1082 t
= find_default_run_target ("attach");
1083 (t
->to_attach
) (args
, from_tty
);
1088 find_default_require_attach (args
, from_tty
)
1092 struct target_ops
*t
;
1094 t
= find_default_run_target ("require_attach");
1095 (t
->to_require_attach
) (args
, from_tty
);
1100 find_default_require_detach (pid
, args
, from_tty
)
1105 struct target_ops
*t
;
1107 t
= find_default_run_target ("require_detach");
1108 (t
->to_require_detach
) (pid
, args
, from_tty
);
1113 find_default_create_inferior (exec_file
, allargs
, env
)
1118 struct target_ops
*t
;
1120 t
= find_default_run_target ("run");
1121 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
1126 find_default_clone_and_follow_inferior (child_pid
, followed_child
)
1128 int *followed_child
;
1130 struct target_ops
*t
;
1132 t
= find_default_run_target ("run");
1133 (t
->to_clone_and_follow_inferior
) (child_pid
, followed_child
);
1150 * Resize the to_sections pointer. Also make sure that anyone that
1151 * was holding on to an old value of it gets updated.
1152 * Returns the old size.
1156 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1158 struct target_ops
**t
;
1159 struct section_table
*old_value
;
1162 old_value
= target
->to_sections
;
1164 if (target
->to_sections
)
1166 old_count
= target
->to_sections_end
- target
->to_sections
;
1167 target
->to_sections
= (struct section_table
*)
1168 xrealloc ((char *) target
->to_sections
,
1169 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1174 target
->to_sections
= (struct section_table
*)
1175 xmalloc ((sizeof (struct section_table
)) * num_added
);
1177 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1179 /* Check to see if anyone else was pointing to this structure.
1180 If old_value was null, then no one was. */
1184 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1187 if ((*t
)->to_sections
== old_value
)
1189 (*t
)->to_sections
= target
->to_sections
;
1190 (*t
)->to_sections_end
= target
->to_sections_end
;
1199 /* Find a single runnable target in the stack and return it. If for
1200 some reason there is more than one, return NULL. */
1205 struct target_ops
**t
;
1206 struct target_ops
*runable
= NULL
;
1211 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1213 if ((*t
)->to_can_run
&& target_can_run (*t
))
1220 return (count
== 1 ? runable
: NULL
);
1226 struct target_ops
**t
;
1227 struct target_ops
*runable
= NULL
;
1232 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1235 if ((*t
)->to_stratum
== core_stratum
)
1242 return (count
== 1 ? runable
: NULL
);
1245 /* The inferior process has died. Long live the inferior! */
1248 generic_mourn_inferior ()
1250 extern int show_breakpoint_hit_counts
;
1254 breakpoint_init_inferior (inf_exited
);
1255 registers_changed ();
1257 #ifdef CLEAR_DEFERRED_STORES
1258 /* Delete any pending stores to the inferior... */
1259 CLEAR_DEFERRED_STORES
;
1262 reopen_exec_file ();
1263 reinit_frame_cache ();
1265 /* It is confusing to the user for ignore counts to stick around
1266 from previous runs of the inferior. So clear them. */
1267 /* However, it is more confusing for the ignore counts to disappear when
1268 using hit counts. So don't clear them if we're counting hits. */
1269 if (!show_breakpoint_hit_counts
)
1270 breakpoint_clear_ignore_counts ();
1273 /* This table must match in order and size the signals in enum target_signal
1282 {"SIGHUP", "Hangup"},
1283 {"SIGINT", "Interrupt"},
1284 {"SIGQUIT", "Quit"},
1285 {"SIGILL", "Illegal instruction"},
1286 {"SIGTRAP", "Trace/breakpoint trap"},
1287 {"SIGABRT", "Aborted"},
1288 {"SIGEMT", "Emulation trap"},
1289 {"SIGFPE", "Arithmetic exception"},
1290 {"SIGKILL", "Killed"},
1291 {"SIGBUS", "Bus error"},
1292 {"SIGSEGV", "Segmentation fault"},
1293 {"SIGSYS", "Bad system call"},
1294 {"SIGPIPE", "Broken pipe"},
1295 {"SIGALRM", "Alarm clock"},
1296 {"SIGTERM", "Terminated"},
1297 {"SIGURG", "Urgent I/O condition"},
1298 {"SIGSTOP", "Stopped (signal)"},
1299 {"SIGTSTP", "Stopped (user)"},
1300 {"SIGCONT", "Continued"},
1301 {"SIGCHLD", "Child status changed"},
1302 {"SIGTTIN", "Stopped (tty input)"},
1303 {"SIGTTOU", "Stopped (tty output)"},
1304 {"SIGIO", "I/O possible"},
1305 {"SIGXCPU", "CPU time limit exceeded"},
1306 {"SIGXFSZ", "File size limit exceeded"},
1307 {"SIGVTALRM", "Virtual timer expired"},
1308 {"SIGPROF", "Profiling timer expired"},
1309 {"SIGWINCH", "Window size changed"},
1310 {"SIGLOST", "Resource lost"},
1311 {"SIGUSR1", "User defined signal 1"},
1312 {"SIGUSR2", "User defined signal 2"},
1313 {"SIGPWR", "Power fail/restart"},
1314 {"SIGPOLL", "Pollable event occurred"},
1315 {"SIGWIND", "SIGWIND"},
1316 {"SIGPHONE", "SIGPHONE"},
1317 {"SIGWAITING", "Process's LWPs are blocked"},
1318 {"SIGLWP", "Signal LWP"},
1319 {"SIGDANGER", "Swap space dangerously low"},
1320 {"SIGGRANT", "Monitor mode granted"},
1321 {"SIGRETRACT", "Need to relinquish monitor mode"},
1322 {"SIGMSG", "Monitor mode data available"},
1323 {"SIGSOUND", "Sound completed"},
1324 {"SIGSAK", "Secure attention"},
1325 {"SIGPRIO", "SIGPRIO"},
1326 {"SIG33", "Real-time event 33"},
1327 {"SIG34", "Real-time event 34"},
1328 {"SIG35", "Real-time event 35"},
1329 {"SIG36", "Real-time event 36"},
1330 {"SIG37", "Real-time event 37"},
1331 {"SIG38", "Real-time event 38"},
1332 {"SIG39", "Real-time event 39"},
1333 {"SIG40", "Real-time event 40"},
1334 {"SIG41", "Real-time event 41"},
1335 {"SIG42", "Real-time event 42"},
1336 {"SIG43", "Real-time event 43"},
1337 {"SIG44", "Real-time event 44"},
1338 {"SIG45", "Real-time event 45"},
1339 {"SIG46", "Real-time event 46"},
1340 {"SIG47", "Real-time event 47"},
1341 {"SIG48", "Real-time event 48"},
1342 {"SIG49", "Real-time event 49"},
1343 {"SIG50", "Real-time event 50"},
1344 {"SIG51", "Real-time event 51"},
1345 {"SIG52", "Real-time event 52"},
1346 {"SIG53", "Real-time event 53"},
1347 {"SIG54", "Real-time event 54"},
1348 {"SIG55", "Real-time event 55"},
1349 {"SIG56", "Real-time event 56"},
1350 {"SIG57", "Real-time event 57"},
1351 {"SIG58", "Real-time event 58"},
1352 {"SIG59", "Real-time event 59"},
1353 {"SIG60", "Real-time event 60"},
1354 {"SIG61", "Real-time event 61"},
1355 {"SIG62", "Real-time event 62"},
1356 {"SIG63", "Real-time event 63"},
1357 {"SIGCANCEL", "LWP internal signal"},
1358 {"SIG32", "Real-time event 32"},
1360 #if defined(MACH) || defined(__MACH__)
1361 /* Mach exceptions */
1362 {"EXC_BAD_ACCESS", "Could not access memory"},
1363 {"EXC_BAD_INSTRUCTION", "Illegal instruction/operand"},
1364 {"EXC_ARITHMETIC", "Arithmetic exception"},
1365 {"EXC_EMULATION", "Emulation instruction"},
1366 {"EXC_SOFTWARE", "Software generated exception"},
1367 {"EXC_BREAKPOINT", "Breakpoint"},
1369 {"SIGINFO", "Information request"},
1371 {NULL
, "Unknown signal"},
1372 {NULL
, "Internal error: printing TARGET_SIGNAL_DEFAULT"},
1374 /* Last entry, used to check whether the table is the right size. */
1375 {NULL
, "TARGET_SIGNAL_MAGIC"}
1381 /* Return the string for a signal. */
1383 target_signal_to_string (sig
)
1384 enum target_signal sig
;
1386 if ((sig
>= TARGET_SIGNAL_FIRST
) && (sig
<= TARGET_SIGNAL_LAST
))
1387 return signals
[sig
].string
;
1389 return signals
[TARGET_SIGNAL_UNKNOWN
].string
;
1392 /* Return the name for a signal. */
1394 target_signal_to_name (sig
)
1395 enum target_signal sig
;
1397 if (sig
== TARGET_SIGNAL_UNKNOWN
)
1398 /* I think the code which prints this will always print it along with
1399 the string, so no need to be verbose. */
1401 return signals
[sig
].name
;
1404 /* Given a name, return its signal. */
1406 target_signal_from_name (name
)
1409 enum target_signal sig
;
1411 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
1412 for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
1413 questionable; seems like by now people should call it SIGABRT
1416 /* This ugly cast brought to you by the native VAX compiler. */
1417 for (sig
= TARGET_SIGNAL_HUP
;
1418 signals
[sig
].name
!= NULL
;
1419 sig
= (enum target_signal
) ((int) sig
+ 1))
1420 if (STREQ (name
, signals
[sig
].name
))
1422 return TARGET_SIGNAL_UNKNOWN
;
1425 /* The following functions are to help certain targets deal
1426 with the signal/waitstatus stuff. They could just as well be in
1427 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
1429 /* Convert host signal to our signals. */
1431 target_signal_from_host (hostsig
)
1434 /* A switch statement would make sense but would require special kludges
1435 to deal with the cases where more than one signal has the same number. */
1438 return TARGET_SIGNAL_0
;
1440 #if defined (SIGHUP)
1441 if (hostsig
== SIGHUP
)
1442 return TARGET_SIGNAL_HUP
;
1444 #if defined (SIGINT)
1445 if (hostsig
== SIGINT
)
1446 return TARGET_SIGNAL_INT
;
1448 #if defined (SIGQUIT)
1449 if (hostsig
== SIGQUIT
)
1450 return TARGET_SIGNAL_QUIT
;
1452 #if defined (SIGILL)
1453 if (hostsig
== SIGILL
)
1454 return TARGET_SIGNAL_ILL
;
1456 #if defined (SIGTRAP)
1457 if (hostsig
== SIGTRAP
)
1458 return TARGET_SIGNAL_TRAP
;
1460 #if defined (SIGABRT)
1461 if (hostsig
== SIGABRT
)
1462 return TARGET_SIGNAL_ABRT
;
1464 #if defined (SIGEMT)
1465 if (hostsig
== SIGEMT
)
1466 return TARGET_SIGNAL_EMT
;
1468 #if defined (SIGFPE)
1469 if (hostsig
== SIGFPE
)
1470 return TARGET_SIGNAL_FPE
;
1472 #if defined (SIGKILL)
1473 if (hostsig
== SIGKILL
)
1474 return TARGET_SIGNAL_KILL
;
1476 #if defined (SIGBUS)
1477 if (hostsig
== SIGBUS
)
1478 return TARGET_SIGNAL_BUS
;
1480 #if defined (SIGSEGV)
1481 if (hostsig
== SIGSEGV
)
1482 return TARGET_SIGNAL_SEGV
;
1484 #if defined (SIGSYS)
1485 if (hostsig
== SIGSYS
)
1486 return TARGET_SIGNAL_SYS
;
1488 #if defined (SIGPIPE)
1489 if (hostsig
== SIGPIPE
)
1490 return TARGET_SIGNAL_PIPE
;
1492 #if defined (SIGALRM)
1493 if (hostsig
== SIGALRM
)
1494 return TARGET_SIGNAL_ALRM
;
1496 #if defined (SIGTERM)
1497 if (hostsig
== SIGTERM
)
1498 return TARGET_SIGNAL_TERM
;
1500 #if defined (SIGUSR1)
1501 if (hostsig
== SIGUSR1
)
1502 return TARGET_SIGNAL_USR1
;
1504 #if defined (SIGUSR2)
1505 if (hostsig
== SIGUSR2
)
1506 return TARGET_SIGNAL_USR2
;
1508 #if defined (SIGCLD)
1509 if (hostsig
== SIGCLD
)
1510 return TARGET_SIGNAL_CHLD
;
1512 #if defined (SIGCHLD)
1513 if (hostsig
== SIGCHLD
)
1514 return TARGET_SIGNAL_CHLD
;
1516 #if defined (SIGPWR)
1517 if (hostsig
== SIGPWR
)
1518 return TARGET_SIGNAL_PWR
;
1520 #if defined (SIGWINCH)
1521 if (hostsig
== SIGWINCH
)
1522 return TARGET_SIGNAL_WINCH
;
1524 #if defined (SIGURG)
1525 if (hostsig
== SIGURG
)
1526 return TARGET_SIGNAL_URG
;
1529 if (hostsig
== SIGIO
)
1530 return TARGET_SIGNAL_IO
;
1532 #if defined (SIGPOLL)
1533 if (hostsig
== SIGPOLL
)
1534 return TARGET_SIGNAL_POLL
;
1536 #if defined (SIGSTOP)
1537 if (hostsig
== SIGSTOP
)
1538 return TARGET_SIGNAL_STOP
;
1540 #if defined (SIGTSTP)
1541 if (hostsig
== SIGTSTP
)
1542 return TARGET_SIGNAL_TSTP
;
1544 #if defined (SIGCONT)
1545 if (hostsig
== SIGCONT
)
1546 return TARGET_SIGNAL_CONT
;
1548 #if defined (SIGTTIN)
1549 if (hostsig
== SIGTTIN
)
1550 return TARGET_SIGNAL_TTIN
;
1552 #if defined (SIGTTOU)
1553 if (hostsig
== SIGTTOU
)
1554 return TARGET_SIGNAL_TTOU
;
1556 #if defined (SIGVTALRM)
1557 if (hostsig
== SIGVTALRM
)
1558 return TARGET_SIGNAL_VTALRM
;
1560 #if defined (SIGPROF)
1561 if (hostsig
== SIGPROF
)
1562 return TARGET_SIGNAL_PROF
;
1564 #if defined (SIGXCPU)
1565 if (hostsig
== SIGXCPU
)
1566 return TARGET_SIGNAL_XCPU
;
1568 #if defined (SIGXFSZ)
1569 if (hostsig
== SIGXFSZ
)
1570 return TARGET_SIGNAL_XFSZ
;
1572 #if defined (SIGWIND)
1573 if (hostsig
== SIGWIND
)
1574 return TARGET_SIGNAL_WIND
;
1576 #if defined (SIGPHONE)
1577 if (hostsig
== SIGPHONE
)
1578 return TARGET_SIGNAL_PHONE
;
1580 #if defined (SIGLOST)
1581 if (hostsig
== SIGLOST
)
1582 return TARGET_SIGNAL_LOST
;
1584 #if defined (SIGWAITING)
1585 if (hostsig
== SIGWAITING
)
1586 return TARGET_SIGNAL_WAITING
;
1588 #if defined (SIGCANCEL)
1589 if (hostsig
== SIGCANCEL
)
1590 return TARGET_SIGNAL_CANCEL
;
1592 #if defined (SIGLWP)
1593 if (hostsig
== SIGLWP
)
1594 return TARGET_SIGNAL_LWP
;
1596 #if defined (SIGDANGER)
1597 if (hostsig
== SIGDANGER
)
1598 return TARGET_SIGNAL_DANGER
;
1600 #if defined (SIGGRANT)
1601 if (hostsig
== SIGGRANT
)
1602 return TARGET_SIGNAL_GRANT
;
1604 #if defined (SIGRETRACT)
1605 if (hostsig
== SIGRETRACT
)
1606 return TARGET_SIGNAL_RETRACT
;
1608 #if defined (SIGMSG)
1609 if (hostsig
== SIGMSG
)
1610 return TARGET_SIGNAL_MSG
;
1612 #if defined (SIGSOUND)
1613 if (hostsig
== SIGSOUND
)
1614 return TARGET_SIGNAL_SOUND
;
1616 #if defined (SIGSAK)
1617 if (hostsig
== SIGSAK
)
1618 return TARGET_SIGNAL_SAK
;
1620 #if defined (SIGPRIO)
1621 if (hostsig
== SIGPRIO
)
1622 return TARGET_SIGNAL_PRIO
;
1625 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1626 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1627 if (hostsig
== _NSIG
+ EXC_BAD_ACCESS
)
1628 return TARGET_EXC_BAD_ACCESS
;
1630 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1631 if (hostsig
== _NSIG
+ EXC_BAD_INSTRUCTION
)
1632 return TARGET_EXC_BAD_INSTRUCTION
;
1634 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1635 if (hostsig
== _NSIG
+ EXC_ARITHMETIC
)
1636 return TARGET_EXC_ARITHMETIC
;
1638 #if defined (EXC_EMULATION) && defined (_NSIG)
1639 if (hostsig
== _NSIG
+ EXC_EMULATION
)
1640 return TARGET_EXC_EMULATION
;
1642 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1643 if (hostsig
== _NSIG
+ EXC_SOFTWARE
)
1644 return TARGET_EXC_SOFTWARE
;
1646 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1647 if (hostsig
== _NSIG
+ EXC_BREAKPOINT
)
1648 return TARGET_EXC_BREAKPOINT
;
1651 #if defined (SIGINFO)
1652 if (hostsig
== SIGINFO
)
1653 return TARGET_SIGNAL_INFO
;
1656 #if defined (REALTIME_LO)
1657 if (hostsig
>= REALTIME_LO
&& hostsig
< REALTIME_HI
)
1659 /* This block of TARGET_SIGNAL_REALTIME value is in order. */
1660 if (33 <= hostsig
&& hostsig
<= 63)
1661 return (enum target_signal
)
1662 (hostsig
- 33 + (int) TARGET_SIGNAL_REALTIME_33
);
1663 else if (hostsig
== 32)
1664 return TARGET_SIGNAL_REALTIME_32
;
1666 error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
1669 return TARGET_SIGNAL_UNKNOWN
;
1673 target_signal_to_host (oursig
)
1674 enum target_signal oursig
;
1678 case TARGET_SIGNAL_0
:
1681 #if defined (SIGHUP)
1682 case TARGET_SIGNAL_HUP
:
1685 #if defined (SIGINT)
1686 case TARGET_SIGNAL_INT
:
1689 #if defined (SIGQUIT)
1690 case TARGET_SIGNAL_QUIT
:
1693 #if defined (SIGILL)
1694 case TARGET_SIGNAL_ILL
:
1697 #if defined (SIGTRAP)
1698 case TARGET_SIGNAL_TRAP
:
1701 #if defined (SIGABRT)
1702 case TARGET_SIGNAL_ABRT
:
1705 #if defined (SIGEMT)
1706 case TARGET_SIGNAL_EMT
:
1709 #if defined (SIGFPE)
1710 case TARGET_SIGNAL_FPE
:
1713 #if defined (SIGKILL)
1714 case TARGET_SIGNAL_KILL
:
1717 #if defined (SIGBUS)
1718 case TARGET_SIGNAL_BUS
:
1721 #if defined (SIGSEGV)
1722 case TARGET_SIGNAL_SEGV
:
1725 #if defined (SIGSYS)
1726 case TARGET_SIGNAL_SYS
:
1729 #if defined (SIGPIPE)
1730 case TARGET_SIGNAL_PIPE
:
1733 #if defined (SIGALRM)
1734 case TARGET_SIGNAL_ALRM
:
1737 #if defined (SIGTERM)
1738 case TARGET_SIGNAL_TERM
:
1741 #if defined (SIGUSR1)
1742 case TARGET_SIGNAL_USR1
:
1745 #if defined (SIGUSR2)
1746 case TARGET_SIGNAL_USR2
:
1749 #if defined (SIGCHLD) || defined (SIGCLD)
1750 case TARGET_SIGNAL_CHLD
:
1751 #if defined (SIGCHLD)
1756 #endif /* SIGCLD or SIGCHLD */
1757 #if defined (SIGPWR)
1758 case TARGET_SIGNAL_PWR
:
1761 #if defined (SIGWINCH)
1762 case TARGET_SIGNAL_WINCH
:
1765 #if defined (SIGURG)
1766 case TARGET_SIGNAL_URG
:
1770 case TARGET_SIGNAL_IO
:
1773 #if defined (SIGPOLL)
1774 case TARGET_SIGNAL_POLL
:
1777 #if defined (SIGSTOP)
1778 case TARGET_SIGNAL_STOP
:
1781 #if defined (SIGTSTP)
1782 case TARGET_SIGNAL_TSTP
:
1785 #if defined (SIGCONT)
1786 case TARGET_SIGNAL_CONT
:
1789 #if defined (SIGTTIN)
1790 case TARGET_SIGNAL_TTIN
:
1793 #if defined (SIGTTOU)
1794 case TARGET_SIGNAL_TTOU
:
1797 #if defined (SIGVTALRM)
1798 case TARGET_SIGNAL_VTALRM
:
1801 #if defined (SIGPROF)
1802 case TARGET_SIGNAL_PROF
:
1805 #if defined (SIGXCPU)
1806 case TARGET_SIGNAL_XCPU
:
1809 #if defined (SIGXFSZ)
1810 case TARGET_SIGNAL_XFSZ
:
1813 #if defined (SIGWIND)
1814 case TARGET_SIGNAL_WIND
:
1817 #if defined (SIGPHONE)
1818 case TARGET_SIGNAL_PHONE
:
1821 #if defined (SIGLOST)
1822 case TARGET_SIGNAL_LOST
:
1825 #if defined (SIGWAITING)
1826 case TARGET_SIGNAL_WAITING
:
1829 #if defined (SIGCANCEL)
1830 case TARGET_SIGNAL_CANCEL
:
1833 #if defined (SIGLWP)
1834 case TARGET_SIGNAL_LWP
:
1837 #if defined (SIGDANGER)
1838 case TARGET_SIGNAL_DANGER
:
1841 #if defined (SIGGRANT)
1842 case TARGET_SIGNAL_GRANT
:
1845 #if defined (SIGRETRACT)
1846 case TARGET_SIGNAL_RETRACT
:
1849 #if defined (SIGMSG)
1850 case TARGET_SIGNAL_MSG
:
1853 #if defined (SIGSOUND)
1854 case TARGET_SIGNAL_SOUND
:
1857 #if defined (SIGSAK)
1858 case TARGET_SIGNAL_SAK
:
1861 #if defined (SIGPRIO)
1862 case TARGET_SIGNAL_PRIO
:
1866 case TARGET_SIGNAL_REALTIME_32
: return 32; /* by definition */
1868 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1869 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1870 case TARGET_EXC_BAD_ACCESS
:
1871 return _NSIG
+ EXC_BAD_ACCESS
;
1873 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1874 case TARGET_EXC_BAD_INSTRUCTION
:
1875 return _NSIG
+ EXC_BAD_INSTRUCTION
;
1877 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1878 case TARGET_EXC_ARITHMETIC
:
1879 return _NSIG
+ EXC_ARITHMETIC
;
1881 #if defined (EXC_EMULATION) && defined (_NSIG)
1882 case TARGET_EXC_EMULATION
:
1883 return _NSIG
+ EXC_EMULATION
;
1885 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1886 case TARGET_EXC_SOFTWARE
:
1887 return _NSIG
+ EXC_SOFTWARE
;
1889 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1890 case TARGET_EXC_BREAKPOINT
:
1891 return _NSIG
+ EXC_BREAKPOINT
;
1894 #if defined (SIGINFO)
1895 case TARGET_SIGNAL_INFO
:
1900 #if defined (REALTIME_LO)
1901 if (oursig
>= TARGET_SIGNAL_REALTIME_33
1902 && oursig
<= TARGET_SIGNAL_REALTIME_63
)
1905 (int) oursig
- (int) TARGET_SIGNAL_REALTIME_33
+ REALTIME_LO
;
1906 if (retsig
< REALTIME_HI
)
1910 /* The user might be trying to do "signal SIGSAK" where this system
1911 doesn't have SIGSAK. */
1912 warning ("Signal %s does not exist on this system.\n",
1913 target_signal_to_name (oursig
));
1918 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1919 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1920 translation of that in OURSTATUS. */
1922 store_waitstatus (ourstatus
, hoststatus
)
1923 struct target_waitstatus
*ourstatus
;
1926 #ifdef CHILD_SPECIAL_WAITSTATUS
1927 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1928 if it wants to deal with hoststatus. */
1929 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
1933 if (WIFEXITED (hoststatus
))
1935 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1936 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
1938 else if (!WIFSTOPPED (hoststatus
))
1940 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1941 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
1945 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
1946 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
1950 /* In some circumstances we allow a command to specify a numeric
1951 signal. The idea is to keep these circumstances limited so that
1952 users (and scripts) develop portable habits. For comparison,
1953 POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
1954 numeric signal at all is obscelescent. We are slightly more
1955 lenient and allow 1-15 which should match host signal numbers on
1956 most systems. Use of symbolic signal names is strongly encouraged. */
1959 target_signal_from_command (num
)
1962 if (num
>= 1 && num
<= 15)
1963 return (enum target_signal
) num
;
1964 error ("Only signals 1-15 are valid as numeric signals.\n\
1965 Use \"info signals\" for a list of symbolic signals.");
1968 /* Returns zero to leave the inferior alone, one to interrupt it. */
1969 int (*target_activity_function
) PARAMS ((void));
1970 int target_activity_fd
;
1972 /* Convert a normal process ID to a string. Returns the string in a static
1976 normal_pid_to_str (pid
)
1979 static char buf
[30];
1981 if (STREQ (current_target
.to_shortname
, "remote"))
1982 sprintf (buf
, "thread %d", pid
);
1984 sprintf (buf
, "process %d", pid
);
1989 /* Some targets (such as ttrace-based HPUX) don't allow us to request
1990 notification of inferior events such as fork and vork immediately
1991 after the inferior is created. (This because of how gdb gets an
1992 inferior created via invoking a shell to do it. In such a scenario,
1993 if the shell init file has commands in it, the shell will fork and
1994 exec for each of those commands, and we will see each such fork
1997 This function is used by all targets that allow us to request
1998 notification of forks, etc at inferior creation time; e.g., in
1999 target_acknowledge_forked_child.
2002 normal_target_post_startup_inferior (pid
)
2005 /* This space intentionally left blank. */
2008 /* Set up the handful of non-empty slots needed by the dummy target
2012 init_dummy_target ()
2014 dummy_target
.to_shortname
= "None";
2015 dummy_target
.to_longname
= "None";
2016 dummy_target
.to_doc
= "";
2017 dummy_target
.to_attach
= find_default_attach
;
2018 dummy_target
.to_require_attach
= find_default_require_attach
;
2019 dummy_target
.to_require_detach
= find_default_require_detach
;
2020 dummy_target
.to_create_inferior
= find_default_create_inferior
;
2021 dummy_target
.to_clone_and_follow_inferior
= find_default_clone_and_follow_inferior
;
2022 dummy_target
.to_stratum
= dummy_stratum
;
2023 dummy_target
.to_magic
= OPS_MAGIC
;
2027 static struct target_ops debug_target
;
2030 debug_to_open (args
, from_tty
)
2034 debug_target
.to_open (args
, from_tty
);
2036 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
2040 debug_to_close (quitting
)
2043 debug_target
.to_close (quitting
);
2045 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
2049 debug_to_attach (args
, from_tty
)
2053 debug_target
.to_attach (args
, from_tty
);
2055 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
2060 debug_to_post_attach (pid
)
2063 debug_target
.to_post_attach (pid
);
2065 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
2069 debug_to_require_attach (args
, from_tty
)
2073 debug_target
.to_require_attach (args
, from_tty
);
2075 fprintf_unfiltered (gdb_stdlog
,
2076 "target_require_attach (%s, %d)\n", args
, from_tty
);
2080 debug_to_detach (args
, from_tty
)
2084 debug_target
.to_detach (args
, from_tty
);
2086 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
2090 debug_to_require_detach (pid
, args
, from_tty
)
2095 debug_target
.to_require_detach (pid
, args
, from_tty
);
2097 fprintf_unfiltered (gdb_stdlog
,
2098 "target_require_detach (%d, %s, %d)\n", pid
, args
, from_tty
);
2102 debug_to_resume (pid
, step
, siggnal
)
2105 enum target_signal siggnal
;
2107 debug_target
.to_resume (pid
, step
, siggnal
);
2109 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", pid
,
2110 step
? "step" : "continue",
2111 target_signal_to_name (siggnal
));
2115 debug_to_wait (pid
, status
)
2117 struct target_waitstatus
*status
;
2121 retval
= debug_target
.to_wait (pid
, status
);
2123 fprintf_unfiltered (gdb_stdlog
,
2124 "target_wait (%d, status) = %d, ", pid
, retval
);
2125 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
2126 switch (status
->kind
)
2128 case TARGET_WAITKIND_EXITED
:
2129 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
2130 status
->value
.integer
);
2132 case TARGET_WAITKIND_STOPPED
:
2133 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
2134 target_signal_to_name (status
->value
.sig
));
2136 case TARGET_WAITKIND_SIGNALLED
:
2137 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
2138 target_signal_to_name (status
->value
.sig
));
2140 case TARGET_WAITKIND_LOADED
:
2141 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
2143 case TARGET_WAITKIND_FORKED
:
2144 fprintf_unfiltered (gdb_stdlog
, "forked\n");
2146 case TARGET_WAITKIND_VFORKED
:
2147 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
2149 case TARGET_WAITKIND_EXECD
:
2150 fprintf_unfiltered (gdb_stdlog
, "execd\n");
2152 case TARGET_WAITKIND_SPURIOUS
:
2153 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
2156 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
2164 debug_to_post_wait (pid
, status
)
2168 debug_target
.to_post_wait (pid
, status
);
2170 fprintf_unfiltered (gdb_stdlog
, "target_post_wait (%d, %d)\n",
2175 debug_to_fetch_registers (regno
)
2178 debug_target
.to_fetch_registers (regno
);
2180 fprintf_unfiltered (gdb_stdlog
, "target_fetch_registers (%s)",
2181 regno
!= -1 ? REGISTER_NAME (regno
) : "-1");
2183 fprintf_unfiltered (gdb_stdlog
, " = 0x%lx %ld",
2184 (unsigned long) read_register (regno
),
2185 (unsigned long) read_register (regno
));
2186 fprintf_unfiltered (gdb_stdlog
, "\n");
2190 debug_to_store_registers (regno
)
2193 debug_target
.to_store_registers (regno
);
2195 if (regno
>= 0 && regno
< NUM_REGS
)
2196 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%s) = 0x%lx %ld\n",
2197 REGISTER_NAME (regno
),
2198 (unsigned long) read_register (regno
),
2199 (unsigned long) read_register (regno
));
2201 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%d)\n", regno
);
2205 debug_to_prepare_to_store ()
2207 debug_target
.to_prepare_to_store ();
2209 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
2213 debug_to_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
2218 struct target_ops
*target
;
2222 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
, target
);
2224 fprintf_unfiltered (gdb_stdlog
,
2225 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
2226 (unsigned int) memaddr
, /* possable truncate long long */
2227 len
, write
? "write" : "read", retval
);
2235 fputs_unfiltered (", bytes =", gdb_stdlog
);
2236 for (i
= 0; i
< retval
; i
++)
2238 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
2239 fprintf_unfiltered (gdb_stdlog
, "\n");
2240 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
2244 fputc_unfiltered ('\n', gdb_stdlog
);
2250 debug_to_files_info (target
)
2251 struct target_ops
*target
;
2253 debug_target
.to_files_info (target
);
2255 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
2259 debug_to_insert_breakpoint (addr
, save
)
2265 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
2267 fprintf_unfiltered (gdb_stdlog
,
2268 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
2269 (unsigned long) addr
,
2270 (unsigned long) retval
);
2275 debug_to_remove_breakpoint (addr
, save
)
2281 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
2283 fprintf_unfiltered (gdb_stdlog
,
2284 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
2285 (unsigned long) addr
,
2286 (unsigned long) retval
);
2291 debug_to_terminal_init ()
2293 debug_target
.to_terminal_init ();
2295 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
2299 debug_to_terminal_inferior ()
2301 debug_target
.to_terminal_inferior ();
2303 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
2307 debug_to_terminal_ours_for_output ()
2309 debug_target
.to_terminal_ours_for_output ();
2311 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
2315 debug_to_terminal_ours ()
2317 debug_target
.to_terminal_ours ();
2319 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
2323 debug_to_terminal_info (arg
, from_tty
)
2327 debug_target
.to_terminal_info (arg
, from_tty
);
2329 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
2336 debug_target
.to_kill ();
2338 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
2342 debug_to_load (args
, from_tty
)
2346 debug_target
.to_load (args
, from_tty
);
2348 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
2352 debug_to_lookup_symbol (name
, addrp
)
2358 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
2360 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
2366 debug_to_create_inferior (exec_file
, args
, env
)
2371 debug_target
.to_create_inferior (exec_file
, args
, env
);
2373 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx)\n",
2378 debug_to_post_startup_inferior (pid
)
2381 debug_target
.to_post_startup_inferior (pid
);
2383 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
2388 debug_to_acknowledge_created_inferior (pid
)
2391 debug_target
.to_acknowledge_created_inferior (pid
);
2393 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
2398 debug_to_clone_and_follow_inferior (child_pid
, followed_child
)
2400 int *followed_child
;
2402 debug_target
.to_clone_and_follow_inferior (child_pid
, followed_child
);
2404 fprintf_unfiltered (gdb_stdlog
,
2405 "target_clone_and_follow_inferior (%d, %d)\n",
2406 child_pid
, *followed_child
);
2410 debug_to_post_follow_inferior_by_clone ()
2412 debug_target
.to_post_follow_inferior_by_clone ();
2414 fprintf_unfiltered (gdb_stdlog
, "target_post_follow_inferior_by_clone ()\n");
2418 debug_to_insert_fork_catchpoint (pid
)
2423 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
2425 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
2432 debug_to_remove_fork_catchpoint (pid
)
2437 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
2439 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
2446 debug_to_insert_vfork_catchpoint (pid
)
2451 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
2453 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)= %d\n",
2460 debug_to_remove_vfork_catchpoint (pid
)
2465 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
2467 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
2474 debug_to_has_forked (pid
, child_pid
)
2480 has_forked
= debug_target
.to_has_forked (pid
, child_pid
);
2482 fprintf_unfiltered (gdb_stdlog
, "target_has_forked (%d, %d) = %d\n",
2483 pid
, *child_pid
, has_forked
);
2489 debug_to_has_vforked (pid
, child_pid
)
2495 has_vforked
= debug_target
.to_has_vforked (pid
, child_pid
);
2497 fprintf_unfiltered (gdb_stdlog
, "target_has_vforked (%d, %d) = %d\n",
2498 pid
, *child_pid
, has_vforked
);
2504 debug_to_can_follow_vfork_prior_to_exec ()
2506 int can_immediately_follow_vfork
;
2508 can_immediately_follow_vfork
= debug_target
.to_can_follow_vfork_prior_to_exec ();
2510 fprintf_unfiltered (gdb_stdlog
, "target_can_follow_vfork_prior_to_exec () = %d\n",
2511 can_immediately_follow_vfork
);
2513 return can_immediately_follow_vfork
;
2517 debug_to_post_follow_vfork (parent_pid
, followed_parent
, child_pid
, followed_child
)
2519 int followed_parent
;
2523 debug_target
.to_post_follow_vfork (parent_pid
, followed_parent
, child_pid
, followed_child
);
2525 fprintf_unfiltered (gdb_stdlog
,
2526 "target_post_follow_vfork (%d, %d, %d, %d)\n",
2527 parent_pid
, followed_parent
, child_pid
, followed_child
);
2531 debug_to_insert_exec_catchpoint (pid
)
2536 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
2538 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
2545 debug_to_remove_exec_catchpoint (pid
)
2550 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
2552 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2559 debug_to_has_execd (pid
, execd_pathname
)
2561 char **execd_pathname
;
2565 has_execd
= debug_target
.to_has_execd (pid
, execd_pathname
);
2567 fprintf_unfiltered (gdb_stdlog
, "target_has_execd (%d, %s) = %d\n",
2568 pid
, (*execd_pathname
? *execd_pathname
: "<NULL>"),
2575 debug_to_reported_exec_events_per_exec_call ()
2577 int reported_exec_events
;
2579 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2581 fprintf_unfiltered (gdb_stdlog
,
2582 "target_reported_exec_events_per_exec_call () = %d\n",
2583 reported_exec_events
);
2585 return reported_exec_events
;
2589 debug_to_has_syscall_event (pid
, kind
, syscall_id
)
2591 enum target_waitkind
*kind
;
2594 int has_syscall_event
;
2595 char *kind_spelling
= "??";
2597 has_syscall_event
= debug_target
.to_has_syscall_event (pid
, kind
, syscall_id
);
2598 if (has_syscall_event
)
2602 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2603 kind_spelling
= "SYSCALL_ENTRY";
2605 case TARGET_WAITKIND_SYSCALL_RETURN
:
2606 kind_spelling
= "SYSCALL_RETURN";
2613 fprintf_unfiltered (gdb_stdlog
,
2614 "target_has_syscall_event (%d, %s, %d) = %d\n",
2615 pid
, kind_spelling
, *syscall_id
, has_syscall_event
);
2617 return has_syscall_event
;
2621 debug_to_has_exited (pid
, wait_status
, exit_status
)
2628 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2630 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2631 pid
, wait_status
, *exit_status
, has_exited
);
2637 debug_to_mourn_inferior ()
2639 debug_target
.to_mourn_inferior ();
2641 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2649 retval
= debug_target
.to_can_run ();
2651 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2657 debug_to_notice_signals (pid
)
2660 debug_target
.to_notice_signals (pid
);
2662 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n", pid
);
2666 debug_to_thread_alive (pid
)
2671 retval
= debug_target
.to_thread_alive (pid
);
2673 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2682 debug_target
.to_stop ();
2684 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2688 debug_to_query (type
, req
, resp
, siz
)
2696 retval
= debug_target
.to_query (type
, req
, resp
, siz
);
2698 fprintf_unfiltered (gdb_stdlog
, "target_query (%c, %s, %s, %d) = %d\n", type
, req
, resp
, *siz
, retval
);
2704 debug_to_rcmd (char *command
,
2705 struct gdb_file
*outbuf
)
2707 debug_target
.to_rcmd (command
, outbuf
);
2708 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2711 static struct symtab_and_line
*
2712 debug_to_enable_exception_callback (kind
, enable
)
2713 enum exception_event_kind kind
;
2716 struct symtab_and_line
*result
;
2717 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2718 fprintf_unfiltered (gdb_stdlog
,
2719 "target get_exception_callback_sal (%d, %d)\n",
2724 static struct exception_event_record
*
2725 debug_to_get_current_exception_event ()
2727 struct exception_event_record
*result
;
2728 result
= debug_target
.to_get_current_exception_event ();
2729 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2734 debug_to_pid_to_exec_file (pid
)
2739 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2741 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2748 debug_to_core_file_to_sym_file (core
)
2753 sym_file
= debug_target
.to_core_file_to_sym_file (core
);
2755 fprintf_unfiltered (gdb_stdlog
, "target_core_file_to_sym_file (%s) = %s\n",
2762 setup_target_debug ()
2764 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2766 current_target
.to_open
= debug_to_open
;
2767 current_target
.to_close
= debug_to_close
;
2768 current_target
.to_attach
= debug_to_attach
;
2769 current_target
.to_post_attach
= debug_to_post_attach
;
2770 current_target
.to_require_attach
= debug_to_require_attach
;
2771 current_target
.to_detach
= debug_to_detach
;
2772 current_target
.to_require_detach
= debug_to_require_detach
;
2773 current_target
.to_resume
= debug_to_resume
;
2774 current_target
.to_wait
= debug_to_wait
;
2775 current_target
.to_post_wait
= debug_to_post_wait
;
2776 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2777 current_target
.to_store_registers
= debug_to_store_registers
;
2778 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2779 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2780 current_target
.to_files_info
= debug_to_files_info
;
2781 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2782 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2783 current_target
.to_terminal_init
= debug_to_terminal_init
;
2784 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2785 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2786 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2787 current_target
.to_terminal_info
= debug_to_terminal_info
;
2788 current_target
.to_kill
= debug_to_kill
;
2789 current_target
.to_load
= debug_to_load
;
2790 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2791 current_target
.to_create_inferior
= debug_to_create_inferior
;
2792 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2793 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2794 current_target
.to_clone_and_follow_inferior
= debug_to_clone_and_follow_inferior
;
2795 current_target
.to_post_follow_inferior_by_clone
= debug_to_post_follow_inferior_by_clone
;
2796 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2797 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2798 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2799 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2800 current_target
.to_has_forked
= debug_to_has_forked
;
2801 current_target
.to_has_vforked
= debug_to_has_vforked
;
2802 current_target
.to_can_follow_vfork_prior_to_exec
= debug_to_can_follow_vfork_prior_to_exec
;
2803 current_target
.to_post_follow_vfork
= debug_to_post_follow_vfork
;
2804 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2805 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2806 current_target
.to_has_execd
= debug_to_has_execd
;
2807 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2808 current_target
.to_has_syscall_event
= debug_to_has_syscall_event
;
2809 current_target
.to_has_exited
= debug_to_has_exited
;
2810 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2811 current_target
.to_can_run
= debug_to_can_run
;
2812 current_target
.to_notice_signals
= debug_to_notice_signals
;
2813 current_target
.to_thread_alive
= debug_to_thread_alive
;
2814 current_target
.to_stop
= debug_to_stop
;
2815 current_target
.to_query
= debug_to_query
;
2816 current_target
.to_rcmd
= debug_to_rcmd
;
2817 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
2818 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
2819 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2820 current_target
.to_core_file_to_sym_file
= debug_to_core_file_to_sym_file
;
2825 static char targ_desc
[] =
2826 "Names of targets and files being debugged.\n\
2827 Shows the entire stack of targets currently in use (including the exec-file,\n\
2828 core-file, and process, if any), as well as the symbol file name.";
2831 do_monitor_command (char *cmd
,
2834 if ((current_target
.to_rcmd
== (void*) tcomplain
)
2835 || (current_target
.to_rcmd
== debug_to_rcmd
2836 && (debug_target
.to_rcmd
== (void*) tcomplain
)))
2838 error ("\"monitor\" command not supported by this target.\n");
2840 target_rcmd (cmd
, gdb_stdtarg
);
2844 initialize_targets ()
2846 init_dummy_target ();
2847 push_target (&dummy_target
);
2849 add_info ("target", target_info
, targ_desc
);
2850 add_info ("files", target_info
, targ_desc
);
2853 add_set_cmd ("targetdebug", class_maintenance
, var_zinteger
,
2854 (char *) &targetdebug
,
2855 "Set target debugging.\n\
2856 When non-zero, target debugging is enabled.", &setlist
),
2860 add_com ("monitor", class_obscure
, do_monitor_command
,
2861 "Send a command to the remote monitor (remote targets only).");
2863 if (!STREQ (signals
[TARGET_SIGNAL_LAST
].string
, "TARGET_SIGNAL_MAGIC"))