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
;
1679 target_signal_to_host (oursig
)
1680 enum target_signal oursig
;
1684 case TARGET_SIGNAL_0
:
1687 #if defined (SIGHUP)
1688 case TARGET_SIGNAL_HUP
:
1691 #if defined (SIGINT)
1692 case TARGET_SIGNAL_INT
:
1695 #if defined (SIGQUIT)
1696 case TARGET_SIGNAL_QUIT
:
1699 #if defined (SIGILL)
1700 case TARGET_SIGNAL_ILL
:
1703 #if defined (SIGTRAP)
1704 case TARGET_SIGNAL_TRAP
:
1707 #if defined (SIGABRT)
1708 case TARGET_SIGNAL_ABRT
:
1711 #if defined (SIGEMT)
1712 case TARGET_SIGNAL_EMT
:
1715 #if defined (SIGFPE)
1716 case TARGET_SIGNAL_FPE
:
1719 #if defined (SIGKILL)
1720 case TARGET_SIGNAL_KILL
:
1723 #if defined (SIGBUS)
1724 case TARGET_SIGNAL_BUS
:
1727 #if defined (SIGSEGV)
1728 case TARGET_SIGNAL_SEGV
:
1731 #if defined (SIGSYS)
1732 case TARGET_SIGNAL_SYS
:
1735 #if defined (SIGPIPE)
1736 case TARGET_SIGNAL_PIPE
:
1739 #if defined (SIGALRM)
1740 case TARGET_SIGNAL_ALRM
:
1743 #if defined (SIGTERM)
1744 case TARGET_SIGNAL_TERM
:
1747 #if defined (SIGUSR1)
1748 case TARGET_SIGNAL_USR1
:
1751 #if defined (SIGUSR2)
1752 case TARGET_SIGNAL_USR2
:
1755 #if defined (SIGCHLD) || defined (SIGCLD)
1756 case TARGET_SIGNAL_CHLD
:
1757 #if defined (SIGCHLD)
1762 #endif /* SIGCLD or SIGCHLD */
1763 #if defined (SIGPWR)
1764 case TARGET_SIGNAL_PWR
:
1767 #if defined (SIGWINCH)
1768 case TARGET_SIGNAL_WINCH
:
1771 #if defined (SIGURG)
1772 case TARGET_SIGNAL_URG
:
1776 case TARGET_SIGNAL_IO
:
1779 #if defined (SIGPOLL)
1780 case TARGET_SIGNAL_POLL
:
1783 #if defined (SIGSTOP)
1784 case TARGET_SIGNAL_STOP
:
1787 #if defined (SIGTSTP)
1788 case TARGET_SIGNAL_TSTP
:
1791 #if defined (SIGCONT)
1792 case TARGET_SIGNAL_CONT
:
1795 #if defined (SIGTTIN)
1796 case TARGET_SIGNAL_TTIN
:
1799 #if defined (SIGTTOU)
1800 case TARGET_SIGNAL_TTOU
:
1803 #if defined (SIGVTALRM)
1804 case TARGET_SIGNAL_VTALRM
:
1807 #if defined (SIGPROF)
1808 case TARGET_SIGNAL_PROF
:
1811 #if defined (SIGXCPU)
1812 case TARGET_SIGNAL_XCPU
:
1815 #if defined (SIGXFSZ)
1816 case TARGET_SIGNAL_XFSZ
:
1819 #if defined (SIGWIND)
1820 case TARGET_SIGNAL_WIND
:
1823 #if defined (SIGPHONE)
1824 case TARGET_SIGNAL_PHONE
:
1827 #if defined (SIGLOST)
1828 case TARGET_SIGNAL_LOST
:
1831 #if defined (SIGWAITING)
1832 case TARGET_SIGNAL_WAITING
:
1835 #if defined (SIGCANCEL)
1836 case TARGET_SIGNAL_CANCEL
:
1839 #if defined (SIGLWP)
1840 case TARGET_SIGNAL_LWP
:
1843 #if defined (SIGDANGER)
1844 case TARGET_SIGNAL_DANGER
:
1847 #if defined (SIGGRANT)
1848 case TARGET_SIGNAL_GRANT
:
1851 #if defined (SIGRETRACT)
1852 case TARGET_SIGNAL_RETRACT
:
1855 #if defined (SIGMSG)
1856 case TARGET_SIGNAL_MSG
:
1859 #if defined (SIGSOUND)
1860 case TARGET_SIGNAL_SOUND
:
1863 #if defined (SIGSAK)
1864 case TARGET_SIGNAL_SAK
:
1867 #if defined (SIGPRIO)
1868 case TARGET_SIGNAL_PRIO
:
1872 case TARGET_SIGNAL_REALTIME_32
: return 32; /* by definition */
1874 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1875 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1876 case TARGET_EXC_BAD_ACCESS
:
1877 return _NSIG
+ EXC_BAD_ACCESS
;
1879 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1880 case TARGET_EXC_BAD_INSTRUCTION
:
1881 return _NSIG
+ EXC_BAD_INSTRUCTION
;
1883 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1884 case TARGET_EXC_ARITHMETIC
:
1885 return _NSIG
+ EXC_ARITHMETIC
;
1887 #if defined (EXC_EMULATION) && defined (_NSIG)
1888 case TARGET_EXC_EMULATION
:
1889 return _NSIG
+ EXC_EMULATION
;
1891 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1892 case TARGET_EXC_SOFTWARE
:
1893 return _NSIG
+ EXC_SOFTWARE
;
1895 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1896 case TARGET_EXC_BREAKPOINT
:
1897 return _NSIG
+ EXC_BREAKPOINT
;
1900 #if defined (SIGINFO)
1901 case TARGET_SIGNAL_INFO
:
1906 #if defined (REALTIME_LO)
1907 if (oursig
>= TARGET_SIGNAL_REALTIME_33
1908 && oursig
<= TARGET_SIGNAL_REALTIME_63
)
1911 (int) oursig
- (int) TARGET_SIGNAL_REALTIME_33
+ REALTIME_LO
;
1912 if (retsig
< REALTIME_HI
)
1916 /* The user might be trying to do "signal SIGSAK" where this system
1917 doesn't have SIGSAK. */
1918 warning ("Signal %s does not exist on this system.\n",
1919 target_signal_to_name (oursig
));
1924 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1925 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1926 translation of that in OURSTATUS. */
1928 store_waitstatus (ourstatus
, hoststatus
)
1929 struct target_waitstatus
*ourstatus
;
1932 #ifdef CHILD_SPECIAL_WAITSTATUS
1933 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1934 if it wants to deal with hoststatus. */
1935 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
1939 if (WIFEXITED (hoststatus
))
1941 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1942 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
1944 else if (!WIFSTOPPED (hoststatus
))
1946 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1947 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
1951 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
1952 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
1956 /* In some circumstances we allow a command to specify a numeric
1957 signal. The idea is to keep these circumstances limited so that
1958 users (and scripts) develop portable habits. For comparison,
1959 POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
1960 numeric signal at all is obscelescent. We are slightly more
1961 lenient and allow 1-15 which should match host signal numbers on
1962 most systems. Use of symbolic signal names is strongly encouraged. */
1965 target_signal_from_command (num
)
1968 if (num
>= 1 && num
<= 15)
1969 return (enum target_signal
) num
;
1970 error ("Only signals 1-15 are valid as numeric signals.\n\
1971 Use \"info signals\" for a list of symbolic signals.");
1974 /* Returns zero to leave the inferior alone, one to interrupt it. */
1975 int (*target_activity_function
) PARAMS ((void));
1976 int target_activity_fd
;
1978 /* Convert a normal process ID to a string. Returns the string in a static
1982 normal_pid_to_str (pid
)
1985 static char buf
[30];
1987 if (STREQ (current_target
.to_shortname
, "remote"))
1988 sprintf (buf
, "thread %d", pid
);
1990 sprintf (buf
, "process %d", pid
);
1995 /* Some targets (such as ttrace-based HPUX) don't allow us to request
1996 notification of inferior events such as fork and vork immediately
1997 after the inferior is created. (This because of how gdb gets an
1998 inferior created via invoking a shell to do it. In such a scenario,
1999 if the shell init file has commands in it, the shell will fork and
2000 exec for each of those commands, and we will see each such fork
2003 This function is used by all targets that allow us to request
2004 notification of forks, etc at inferior creation time; e.g., in
2005 target_acknowledge_forked_child.
2008 normal_target_post_startup_inferior (pid
)
2011 /* This space intentionally left blank. */
2014 /* Set up the handful of non-empty slots needed by the dummy target
2018 init_dummy_target ()
2020 dummy_target
.to_shortname
= "None";
2021 dummy_target
.to_longname
= "None";
2022 dummy_target
.to_doc
= "";
2023 dummy_target
.to_attach
= find_default_attach
;
2024 dummy_target
.to_require_attach
= find_default_require_attach
;
2025 dummy_target
.to_require_detach
= find_default_require_detach
;
2026 dummy_target
.to_create_inferior
= find_default_create_inferior
;
2027 dummy_target
.to_clone_and_follow_inferior
= find_default_clone_and_follow_inferior
;
2028 dummy_target
.to_stratum
= dummy_stratum
;
2029 dummy_target
.to_magic
= OPS_MAGIC
;
2033 static struct target_ops debug_target
;
2036 debug_to_open (args
, from_tty
)
2040 debug_target
.to_open (args
, from_tty
);
2042 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
2046 debug_to_close (quitting
)
2049 debug_target
.to_close (quitting
);
2051 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
2055 debug_to_attach (args
, from_tty
)
2059 debug_target
.to_attach (args
, from_tty
);
2061 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
2066 debug_to_post_attach (pid
)
2069 debug_target
.to_post_attach (pid
);
2071 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
2075 debug_to_require_attach (args
, from_tty
)
2079 debug_target
.to_require_attach (args
, from_tty
);
2081 fprintf_unfiltered (gdb_stdlog
,
2082 "target_require_attach (%s, %d)\n", args
, from_tty
);
2086 debug_to_detach (args
, from_tty
)
2090 debug_target
.to_detach (args
, from_tty
);
2092 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
2096 debug_to_require_detach (pid
, args
, from_tty
)
2101 debug_target
.to_require_detach (pid
, args
, from_tty
);
2103 fprintf_unfiltered (gdb_stdlog
,
2104 "target_require_detach (%d, %s, %d)\n", pid
, args
, from_tty
);
2108 debug_to_resume (pid
, step
, siggnal
)
2111 enum target_signal siggnal
;
2113 debug_target
.to_resume (pid
, step
, siggnal
);
2115 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", pid
,
2116 step
? "step" : "continue",
2117 target_signal_to_name (siggnal
));
2121 debug_to_wait (pid
, status
)
2123 struct target_waitstatus
*status
;
2127 retval
= debug_target
.to_wait (pid
, status
);
2129 fprintf_unfiltered (gdb_stdlog
,
2130 "target_wait (%d, status) = %d, ", pid
, retval
);
2131 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
2132 switch (status
->kind
)
2134 case TARGET_WAITKIND_EXITED
:
2135 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
2136 status
->value
.integer
);
2138 case TARGET_WAITKIND_STOPPED
:
2139 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
2140 target_signal_to_name (status
->value
.sig
));
2142 case TARGET_WAITKIND_SIGNALLED
:
2143 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
2144 target_signal_to_name (status
->value
.sig
));
2146 case TARGET_WAITKIND_LOADED
:
2147 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
2149 case TARGET_WAITKIND_FORKED
:
2150 fprintf_unfiltered (gdb_stdlog
, "forked\n");
2152 case TARGET_WAITKIND_VFORKED
:
2153 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
2155 case TARGET_WAITKIND_EXECD
:
2156 fprintf_unfiltered (gdb_stdlog
, "execd\n");
2158 case TARGET_WAITKIND_SPURIOUS
:
2159 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
2162 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
2170 debug_to_post_wait (pid
, status
)
2174 debug_target
.to_post_wait (pid
, status
);
2176 fprintf_unfiltered (gdb_stdlog
, "target_post_wait (%d, %d)\n",
2181 debug_to_fetch_registers (regno
)
2184 debug_target
.to_fetch_registers (regno
);
2186 fprintf_unfiltered (gdb_stdlog
, "target_fetch_registers (%s)",
2187 regno
!= -1 ? REGISTER_NAME (regno
) : "-1");
2189 fprintf_unfiltered (gdb_stdlog
, " = 0x%lx %ld",
2190 (unsigned long) read_register (regno
),
2191 (unsigned long) read_register (regno
));
2192 fprintf_unfiltered (gdb_stdlog
, "\n");
2196 debug_to_store_registers (regno
)
2199 debug_target
.to_store_registers (regno
);
2201 if (regno
>= 0 && regno
< NUM_REGS
)
2202 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%s) = 0x%lx %ld\n",
2203 REGISTER_NAME (regno
),
2204 (unsigned long) read_register (regno
),
2205 (unsigned long) read_register (regno
));
2207 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%d)\n", regno
);
2211 debug_to_prepare_to_store ()
2213 debug_target
.to_prepare_to_store ();
2215 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
2219 debug_to_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
2224 struct target_ops
*target
;
2228 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
, target
);
2230 fprintf_unfiltered (gdb_stdlog
,
2231 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
2232 (unsigned int) memaddr
, /* possable truncate long long */
2233 len
, write
? "write" : "read", retval
);
2241 fputs_unfiltered (", bytes =", gdb_stdlog
);
2242 for (i
= 0; i
< retval
; i
++)
2244 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
2245 fprintf_unfiltered (gdb_stdlog
, "\n");
2246 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
2250 fputc_unfiltered ('\n', gdb_stdlog
);
2256 debug_to_files_info (target
)
2257 struct target_ops
*target
;
2259 debug_target
.to_files_info (target
);
2261 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
2265 debug_to_insert_breakpoint (addr
, save
)
2271 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
2273 fprintf_unfiltered (gdb_stdlog
,
2274 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
2275 (unsigned long) addr
,
2276 (unsigned long) retval
);
2281 debug_to_remove_breakpoint (addr
, save
)
2287 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
2289 fprintf_unfiltered (gdb_stdlog
,
2290 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
2291 (unsigned long) addr
,
2292 (unsigned long) retval
);
2297 debug_to_terminal_init ()
2299 debug_target
.to_terminal_init ();
2301 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
2305 debug_to_terminal_inferior ()
2307 debug_target
.to_terminal_inferior ();
2309 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
2313 debug_to_terminal_ours_for_output ()
2315 debug_target
.to_terminal_ours_for_output ();
2317 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
2321 debug_to_terminal_ours ()
2323 debug_target
.to_terminal_ours ();
2325 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
2329 debug_to_terminal_info (arg
, from_tty
)
2333 debug_target
.to_terminal_info (arg
, from_tty
);
2335 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
2342 debug_target
.to_kill ();
2344 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
2348 debug_to_load (args
, from_tty
)
2352 debug_target
.to_load (args
, from_tty
);
2354 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
2358 debug_to_lookup_symbol (name
, addrp
)
2364 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
2366 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
2372 debug_to_create_inferior (exec_file
, args
, env
)
2377 debug_target
.to_create_inferior (exec_file
, args
, env
);
2379 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx)\n",
2384 debug_to_post_startup_inferior (pid
)
2387 debug_target
.to_post_startup_inferior (pid
);
2389 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
2394 debug_to_acknowledge_created_inferior (pid
)
2397 debug_target
.to_acknowledge_created_inferior (pid
);
2399 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
2404 debug_to_clone_and_follow_inferior (child_pid
, followed_child
)
2406 int *followed_child
;
2408 debug_target
.to_clone_and_follow_inferior (child_pid
, followed_child
);
2410 fprintf_unfiltered (gdb_stdlog
,
2411 "target_clone_and_follow_inferior (%d, %d)\n",
2412 child_pid
, *followed_child
);
2416 debug_to_post_follow_inferior_by_clone ()
2418 debug_target
.to_post_follow_inferior_by_clone ();
2420 fprintf_unfiltered (gdb_stdlog
, "target_post_follow_inferior_by_clone ()\n");
2424 debug_to_insert_fork_catchpoint (pid
)
2429 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
2431 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
2438 debug_to_remove_fork_catchpoint (pid
)
2443 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
2445 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
2452 debug_to_insert_vfork_catchpoint (pid
)
2457 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
2459 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)= %d\n",
2466 debug_to_remove_vfork_catchpoint (pid
)
2471 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
2473 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
2480 debug_to_has_forked (pid
, child_pid
)
2486 has_forked
= debug_target
.to_has_forked (pid
, child_pid
);
2488 fprintf_unfiltered (gdb_stdlog
, "target_has_forked (%d, %d) = %d\n",
2489 pid
, *child_pid
, has_forked
);
2495 debug_to_has_vforked (pid
, child_pid
)
2501 has_vforked
= debug_target
.to_has_vforked (pid
, child_pid
);
2503 fprintf_unfiltered (gdb_stdlog
, "target_has_vforked (%d, %d) = %d\n",
2504 pid
, *child_pid
, has_vforked
);
2510 debug_to_can_follow_vfork_prior_to_exec ()
2512 int can_immediately_follow_vfork
;
2514 can_immediately_follow_vfork
= debug_target
.to_can_follow_vfork_prior_to_exec ();
2516 fprintf_unfiltered (gdb_stdlog
, "target_can_follow_vfork_prior_to_exec () = %d\n",
2517 can_immediately_follow_vfork
);
2519 return can_immediately_follow_vfork
;
2523 debug_to_post_follow_vfork (parent_pid
, followed_parent
, child_pid
, followed_child
)
2525 int followed_parent
;
2529 debug_target
.to_post_follow_vfork (parent_pid
, followed_parent
, child_pid
, followed_child
);
2531 fprintf_unfiltered (gdb_stdlog
,
2532 "target_post_follow_vfork (%d, %d, %d, %d)\n",
2533 parent_pid
, followed_parent
, child_pid
, followed_child
);
2537 debug_to_insert_exec_catchpoint (pid
)
2542 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
2544 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
2551 debug_to_remove_exec_catchpoint (pid
)
2556 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
2558 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2565 debug_to_has_execd (pid
, execd_pathname
)
2567 char **execd_pathname
;
2571 has_execd
= debug_target
.to_has_execd (pid
, execd_pathname
);
2573 fprintf_unfiltered (gdb_stdlog
, "target_has_execd (%d, %s) = %d\n",
2574 pid
, (*execd_pathname
? *execd_pathname
: "<NULL>"),
2581 debug_to_reported_exec_events_per_exec_call ()
2583 int reported_exec_events
;
2585 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2587 fprintf_unfiltered (gdb_stdlog
,
2588 "target_reported_exec_events_per_exec_call () = %d\n",
2589 reported_exec_events
);
2591 return reported_exec_events
;
2595 debug_to_has_syscall_event (pid
, kind
, syscall_id
)
2597 enum target_waitkind
*kind
;
2600 int has_syscall_event
;
2601 char *kind_spelling
= "??";
2603 has_syscall_event
= debug_target
.to_has_syscall_event (pid
, kind
, syscall_id
);
2604 if (has_syscall_event
)
2608 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2609 kind_spelling
= "SYSCALL_ENTRY";
2611 case TARGET_WAITKIND_SYSCALL_RETURN
:
2612 kind_spelling
= "SYSCALL_RETURN";
2619 fprintf_unfiltered (gdb_stdlog
,
2620 "target_has_syscall_event (%d, %s, %d) = %d\n",
2621 pid
, kind_spelling
, *syscall_id
, has_syscall_event
);
2623 return has_syscall_event
;
2627 debug_to_has_exited (pid
, wait_status
, exit_status
)
2634 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2636 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2637 pid
, wait_status
, *exit_status
, has_exited
);
2643 debug_to_mourn_inferior ()
2645 debug_target
.to_mourn_inferior ();
2647 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2655 retval
= debug_target
.to_can_run ();
2657 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2663 debug_to_notice_signals (pid
)
2666 debug_target
.to_notice_signals (pid
);
2668 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n", pid
);
2672 debug_to_thread_alive (pid
)
2677 retval
= debug_target
.to_thread_alive (pid
);
2679 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2688 debug_target
.to_stop ();
2690 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2694 debug_to_query (type
, req
, resp
, siz
)
2702 retval
= debug_target
.to_query (type
, req
, resp
, siz
);
2704 fprintf_unfiltered (gdb_stdlog
, "target_query (%c, %s, %s, %d) = %d\n", type
, req
, resp
, *siz
, retval
);
2710 debug_to_rcmd (char *command
,
2711 struct gdb_file
*outbuf
)
2713 debug_target
.to_rcmd (command
, outbuf
);
2714 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2717 static struct symtab_and_line
*
2718 debug_to_enable_exception_callback (kind
, enable
)
2719 enum exception_event_kind kind
;
2722 struct symtab_and_line
*result
;
2723 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2724 fprintf_unfiltered (gdb_stdlog
,
2725 "target get_exception_callback_sal (%d, %d)\n",
2730 static struct exception_event_record
*
2731 debug_to_get_current_exception_event ()
2733 struct exception_event_record
*result
;
2734 result
= debug_target
.to_get_current_exception_event ();
2735 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2740 debug_to_pid_to_exec_file (pid
)
2745 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2747 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2754 debug_to_core_file_to_sym_file (core
)
2759 sym_file
= debug_target
.to_core_file_to_sym_file (core
);
2761 fprintf_unfiltered (gdb_stdlog
, "target_core_file_to_sym_file (%s) = %s\n",
2768 setup_target_debug ()
2770 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2772 current_target
.to_open
= debug_to_open
;
2773 current_target
.to_close
= debug_to_close
;
2774 current_target
.to_attach
= debug_to_attach
;
2775 current_target
.to_post_attach
= debug_to_post_attach
;
2776 current_target
.to_require_attach
= debug_to_require_attach
;
2777 current_target
.to_detach
= debug_to_detach
;
2778 current_target
.to_require_detach
= debug_to_require_detach
;
2779 current_target
.to_resume
= debug_to_resume
;
2780 current_target
.to_wait
= debug_to_wait
;
2781 current_target
.to_post_wait
= debug_to_post_wait
;
2782 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2783 current_target
.to_store_registers
= debug_to_store_registers
;
2784 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2785 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2786 current_target
.to_files_info
= debug_to_files_info
;
2787 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2788 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2789 current_target
.to_terminal_init
= debug_to_terminal_init
;
2790 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2791 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2792 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2793 current_target
.to_terminal_info
= debug_to_terminal_info
;
2794 current_target
.to_kill
= debug_to_kill
;
2795 current_target
.to_load
= debug_to_load
;
2796 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2797 current_target
.to_create_inferior
= debug_to_create_inferior
;
2798 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2799 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2800 current_target
.to_clone_and_follow_inferior
= debug_to_clone_and_follow_inferior
;
2801 current_target
.to_post_follow_inferior_by_clone
= debug_to_post_follow_inferior_by_clone
;
2802 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2803 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2804 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2805 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2806 current_target
.to_has_forked
= debug_to_has_forked
;
2807 current_target
.to_has_vforked
= debug_to_has_vforked
;
2808 current_target
.to_can_follow_vfork_prior_to_exec
= debug_to_can_follow_vfork_prior_to_exec
;
2809 current_target
.to_post_follow_vfork
= debug_to_post_follow_vfork
;
2810 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2811 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2812 current_target
.to_has_execd
= debug_to_has_execd
;
2813 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2814 current_target
.to_has_syscall_event
= debug_to_has_syscall_event
;
2815 current_target
.to_has_exited
= debug_to_has_exited
;
2816 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2817 current_target
.to_can_run
= debug_to_can_run
;
2818 current_target
.to_notice_signals
= debug_to_notice_signals
;
2819 current_target
.to_thread_alive
= debug_to_thread_alive
;
2820 current_target
.to_stop
= debug_to_stop
;
2821 current_target
.to_query
= debug_to_query
;
2822 current_target
.to_rcmd
= debug_to_rcmd
;
2823 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
2824 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
2825 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2826 current_target
.to_core_file_to_sym_file
= debug_to_core_file_to_sym_file
;
2831 static char targ_desc
[] =
2832 "Names of targets and files being debugged.\n\
2833 Shows the entire stack of targets currently in use (including the exec-file,\n\
2834 core-file, and process, if any), as well as the symbol file name.";
2837 do_monitor_command (char *cmd
,
2840 if ((current_target
.to_rcmd
== (void*) tcomplain
)
2841 || (current_target
.to_rcmd
== debug_to_rcmd
2842 && (debug_target
.to_rcmd
== (void*) tcomplain
)))
2844 error ("\"monitor\" command not supported by this target.\n");
2846 target_rcmd (cmd
, gdb_stdtarg
);
2850 initialize_targets ()
2852 init_dummy_target ();
2853 push_target (&dummy_target
);
2855 add_info ("target", target_info
, targ_desc
);
2856 add_info ("files", target_info
, targ_desc
);
2859 add_set_cmd ("targetdebug", class_maintenance
, var_zinteger
,
2860 (char *) &targetdebug
,
2861 "Set target debugging.\n\
2862 When non-zero, target debugging is enabled.", &setlist
),
2866 add_com ("monitor", class_obscure
, do_monitor_command
,
2867 "Send a command to the remote monitor (remote targets only).");
2869 if (!STREQ (signals
[TARGET_SIGNAL_LAST
].string
, "TARGET_SIGNAL_MAGIC"))