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_pid_to_str
, t
);
540 INHERIT (to_stop
, t
);
541 INHERIT (to_query
, t
);
542 INHERIT (to_rcmd
, t
);
543 INHERIT (to_enable_exception_callback
, t
);
544 INHERIT (to_get_current_exception_event
, t
);
545 INHERIT (to_pid_to_exec_file
, t
);
546 INHERIT (to_core_file_to_sym_file
, t
);
547 INHERIT (to_stratum
, t
);
548 INHERIT (DONT_USE
, t
);
549 INHERIT (to_has_all_memory
, t
);
550 INHERIT (to_has_memory
, t
);
551 INHERIT (to_has_stack
, t
);
552 INHERIT (to_has_registers
, t
);
553 INHERIT (to_has_execution
, t
);
554 INHERIT (to_has_thread_control
, t
);
555 INHERIT (to_sections
, t
);
556 INHERIT (to_sections_end
, t
);
557 INHERIT (to_can_async_p
, t
);
558 INHERIT (to_is_async_p
, t
);
559 INHERIT (to_async
, t
);
560 INHERIT (to_async_mask_value
, t
);
561 INHERIT (to_magic
, t
);
567 /* Push a new target type into the stack of the existing target accessors,
568 possibly superseding some of the existing accessors.
570 Result is zero if the pushed target ended up on top of the stack,
571 nonzero if at least one target is on top of it.
573 Rather than allow an empty stack, we always have the dummy target at
574 the bottom stratum, so we can call the function vectors without
579 struct target_ops
*t
;
581 struct target_stack_item
*cur
, *prev
, *tmp
;
583 /* Check magic number. If wrong, it probably means someone changed
584 the struct definition, but not all the places that initialize one. */
585 if (t
->to_magic
!= OPS_MAGIC
)
587 fprintf_unfiltered (gdb_stderr
,
588 "Magic number of %s target struct wrong\n",
593 /* Find the proper stratum to install this target in. */
595 for (prev
= NULL
, cur
= target_stack
; cur
; prev
= cur
, cur
= cur
->next
)
597 if ((int) (t
->to_stratum
) >= (int) (cur
->target_ops
->to_stratum
))
601 /* If there's already targets at this stratum, remove them. */
604 while (t
->to_stratum
== cur
->target_ops
->to_stratum
)
606 /* There's already something on this stratum. Close it off. */
607 if (cur
->target_ops
->to_close
)
608 (cur
->target_ops
->to_close
) (0);
610 prev
->next
= cur
->next
; /* Unchain old target_ops */
612 target_stack
= cur
->next
; /* Unchain first on list */
618 /* We have removed all targets in our stratum, now add the new one. */
620 tmp
= (struct target_stack_item
*)
621 xmalloc (sizeof (struct target_stack_item
));
630 update_current_target ();
632 cleanup_target (¤t_target
); /* Fill in the gaps */
635 setup_target_debug ();
640 /* Remove a target_ops vector from the stack, wherever it may be.
641 Return how many times it was removed (0 or 1). */
645 struct target_ops
*t
;
647 struct target_stack_item
*cur
, *prev
;
650 t
->to_close (0); /* Let it clean up */
652 /* Look for the specified target. Note that we assume that a target
653 can only occur once in the target stack. */
655 for (cur
= target_stack
, prev
= NULL
; cur
; prev
= cur
, cur
= cur
->next
)
656 if (cur
->target_ops
== t
)
660 return 0; /* Didn't find target_ops, quit now */
662 /* Unchain the target */
665 target_stack
= cur
->next
;
667 prev
->next
= cur
->next
;
669 free (cur
); /* Release the target_stack_item */
671 update_current_target ();
672 cleanup_target (¤t_target
);
680 (current_target
.to_close
) (0); /* Let it clean up */
681 if (unpush_target (target_stack
->target_ops
) == 1)
684 fprintf_unfiltered (gdb_stderr
,
685 "pop_target couldn't find target %s\n",
686 current_target
.to_shortname
);
691 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
693 /* target_read_string -- read a null terminated string, up to LEN bytes,
694 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
695 Set *STRING to a pointer to malloc'd memory containing the data; the caller
696 is responsible for freeing it. Return the number of bytes successfully
700 target_read_string (memaddr
, string
, len
, errnop
)
706 int tlen
, origlen
, offset
, i
;
710 int buffer_allocated
;
712 unsigned int nbytes_read
= 0;
714 /* Small for testing. */
715 buffer_allocated
= 4;
716 buffer
= xmalloc (buffer_allocated
);
723 tlen
= MIN (len
, 4 - (memaddr
& 3));
724 offset
= memaddr
& 3;
726 errcode
= target_xfer_memory (memaddr
& ~3, buf
, 4, 0, NULL
);
729 /* The transfer request might have crossed the boundary to an
730 unallocated region of memory. Retry the transfer, requesting
734 errcode
= target_xfer_memory (memaddr
, buf
, 1, 0, NULL
);
739 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
742 bytes
= bufptr
- buffer
;
743 buffer_allocated
*= 2;
744 buffer
= xrealloc (buffer
, buffer_allocated
);
745 bufptr
= buffer
+ bytes
;
748 for (i
= 0; i
< tlen
; i
++)
750 *bufptr
++ = buf
[i
+ offset
];
751 if (buf
[i
+ offset
] == '\000')
753 nbytes_read
+= i
+ 1;
770 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
771 GDB's memory at MYADDR. Returns either 0 for success or an errno value
774 If an error occurs, no guarantee is made about the contents of the data at
775 MYADDR. In particular, the caller should not depend upon partial reads
776 filling the buffer with good data. There is no way for the caller to know
777 how much good data might have been transfered anyway. Callers that can
778 deal with partial reads should call target_read_memory_partial. */
781 target_read_memory (memaddr
, myaddr
, len
)
786 return target_xfer_memory (memaddr
, myaddr
, len
, 0, NULL
);
790 target_read_memory_section (memaddr
, myaddr
, len
, bfd_section
)
794 asection
*bfd_section
;
796 return target_xfer_memory (memaddr
, myaddr
, len
, 0, bfd_section
);
800 target_write_memory (memaddr
, myaddr
, len
)
805 return target_xfer_memory (memaddr
, myaddr
, len
, 1, NULL
);
808 /* This variable is used to pass section information down to targets. This
809 *should* be done by adding an argument to the target_xfer_memory function
810 of all the targets, but I didn't feel like changing 50+ files. */
812 asection
*target_memory_bfd_section
= NULL
;
814 /* Move memory to or from the targets. Iterate until all of it has
815 been moved, if necessary. The top target gets priority; anything
816 it doesn't want, is offered to the next one down, etc. Note the
817 business with curlen: if an early target says "no, but I have a
818 boundary overlapping this xfer" then we shorten what we offer to
819 the subsequent targets so the early guy will get a chance at the
820 tail before the subsequent ones do.
822 Result is 0 or errno value. */
825 target_xfer_memory (memaddr
, myaddr
, len
, write
, bfd_section
)
830 asection
*bfd_section
;
834 struct target_ops
*t
;
835 struct target_stack_item
*item
;
837 /* Zero length requests are ok and require no work. */
841 target_memory_bfd_section
= bfd_section
;
843 /* to_xfer_memory is not guaranteed to set errno, even when it returns
847 /* The quick case is that the top target does it all. */
848 res
= current_target
.to_xfer_memory
849 (memaddr
, myaddr
, len
, write
, ¤t_target
);
855 /* If res <= 0 then we call it again in the loop. Ah well. */
859 curlen
= len
; /* Want to do it all */
860 for (item
= target_stack
; item
; item
= item
->next
)
862 t
= item
->target_ops
;
863 if (!t
->to_has_memory
)
866 res
= t
->to_xfer_memory (memaddr
, myaddr
, curlen
, write
, t
);
868 break; /* Handled all or part of xfer */
869 if (t
->to_has_all_memory
)
875 /* If this address is for nonexistent memory,
876 read zeros if reading, or do nothing if writing. Return error. */
878 memset (myaddr
, 0, len
);
889 return 0; /* We managed to cover it all somehow. */
893 /* Perform a partial memory transfer. */
896 target_xfer_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
,
897 int write_p
, int *err
)
902 struct target_ops
*t
;
903 struct target_stack_item
*item
;
905 /* Zero length requests are ok and require no work. */
912 /* The quick case is that the top target does it all. */
913 res
= current_target
.to_xfer_memory (memaddr
, buf
, len
, write_p
, ¤t_target
);
920 /* xfer memory doesn't always reliably set errno. */
923 /* Try all levels of the target stack to see one can handle it. */
924 for (item
= target_stack
; item
; item
= item
->next
)
926 t
= item
->target_ops
;
927 if (!t
->to_has_memory
)
929 res
= t
->to_xfer_memory (memaddr
, buf
, len
, write_p
, t
);
932 /* Handled all or part of xfer */
936 if (t
->to_has_all_memory
)
940 /* Total failure. Return error. */
951 target_read_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
953 return target_xfer_memory_partial (memaddr
, buf
, len
, 0, err
);
957 target_write_memory_partial (CORE_ADDR memaddr
, char *buf
, int len
, int *err
)
959 return target_xfer_memory_partial (memaddr
, buf
, len
, 1, err
);
964 target_info (args
, from_tty
)
968 struct target_ops
*t
;
969 struct target_stack_item
*item
;
972 if (symfile_objfile
!= NULL
)
973 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
975 #ifdef FILES_INFO_HOOK
976 if (FILES_INFO_HOOK ())
980 for (item
= target_stack
; item
; item
= item
->next
)
982 t
= item
->target_ops
;
984 if (!t
->to_has_memory
)
987 if ((int) (t
->to_stratum
) <= (int) dummy_stratum
)
990 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
991 printf_unfiltered ("%s:\n", t
->to_longname
);
992 (t
->to_files_info
) (t
);
993 has_all_mem
= t
->to_has_all_memory
;
997 /* This is to be called by the open routine before it does
1001 target_preopen (from_tty
)
1006 if (target_has_execution
)
1009 || query ("A program is being debugged already. Kill it? "))
1012 error ("Program not killed.");
1015 /* Calling target_kill may remove the target from the stack. But if
1016 it doesn't (which seems like a win for UDI), remove it now. */
1018 if (target_has_execution
)
1022 /* Detach a target after doing deferred register stores. */
1025 target_detach (args
, from_tty
)
1029 /* Handle any optimized stores to the inferior. */
1030 #ifdef DO_DEFERRED_STORES
1033 (current_target
.to_detach
) (args
, from_tty
);
1037 target_link (modname
, t_reloc
)
1041 if (STREQ (current_target
.to_shortname
, "rombug"))
1043 (current_target
.to_lookup_symbol
) (modname
, t_reloc
);
1045 error ("Unable to link to %s and get relocation in rombug", modname
);
1048 *t_reloc
= (CORE_ADDR
) -1;
1052 target_async_mask (int mask
)
1054 int saved_async_masked_status
= target_async_mask_value
;
1055 target_async_mask_value
= mask
;
1056 return saved_async_masked_status
;
1059 /* Look through the list of possible targets for a target that can
1060 execute a run or attach command without any other data. This is
1061 used to locate the default process stratum.
1063 Result is always valid (error() is called for errors). */
1065 static struct target_ops
*
1066 find_default_run_target (do_mesg
)
1069 struct target_ops
**t
;
1070 struct target_ops
*runable
= NULL
;
1075 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1078 if ((*t
)->to_can_run
&& target_can_run (*t
))
1086 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
1092 find_default_attach (args
, from_tty
)
1096 struct target_ops
*t
;
1098 t
= find_default_run_target ("attach");
1099 (t
->to_attach
) (args
, from_tty
);
1104 find_default_require_attach (args
, from_tty
)
1108 struct target_ops
*t
;
1110 t
= find_default_run_target ("require_attach");
1111 (t
->to_require_attach
) (args
, from_tty
);
1116 find_default_require_detach (pid
, args
, from_tty
)
1121 struct target_ops
*t
;
1123 t
= find_default_run_target ("require_detach");
1124 (t
->to_require_detach
) (pid
, args
, from_tty
);
1129 find_default_create_inferior (exec_file
, allargs
, env
)
1134 struct target_ops
*t
;
1136 t
= find_default_run_target ("run");
1137 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
1142 find_default_clone_and_follow_inferior (child_pid
, followed_child
)
1144 int *followed_child
;
1146 struct target_ops
*t
;
1148 t
= find_default_run_target ("run");
1149 (t
->to_clone_and_follow_inferior
) (child_pid
, followed_child
);
1166 * Resize the to_sections pointer. Also make sure that anyone that
1167 * was holding on to an old value of it gets updated.
1168 * Returns the old size.
1172 target_resize_to_sections (struct target_ops
*target
, int num_added
)
1174 struct target_ops
**t
;
1175 struct section_table
*old_value
;
1178 old_value
= target
->to_sections
;
1180 if (target
->to_sections
)
1182 old_count
= target
->to_sections_end
- target
->to_sections
;
1183 target
->to_sections
= (struct section_table
*)
1184 xrealloc ((char *) target
->to_sections
,
1185 (sizeof (struct section_table
)) * (num_added
+ old_count
));
1190 target
->to_sections
= (struct section_table
*)
1191 xmalloc ((sizeof (struct section_table
)) * num_added
);
1193 target
->to_sections_end
= target
->to_sections
+ (num_added
+ old_count
);
1195 /* Check to see if anyone else was pointing to this structure.
1196 If old_value was null, then no one was. */
1200 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1203 if ((*t
)->to_sections
== old_value
)
1205 (*t
)->to_sections
= target
->to_sections
;
1206 (*t
)->to_sections_end
= target
->to_sections_end
;
1215 /* Find a single runnable target in the stack and return it. If for
1216 some reason there is more than one, return NULL. */
1221 struct target_ops
**t
;
1222 struct target_ops
*runable
= NULL
;
1227 for (t
= target_structs
; t
< target_structs
+ target_struct_size
; ++t
)
1229 if ((*t
)->to_can_run
&& target_can_run (*t
))
1236 return (count
== 1 ? runable
: NULL
);
1239 /* Find a single core_stratum target in the list of targets and return it.
1240 If for some reason there is more than one, return NULL. */
1245 struct target_ops
**t
;
1246 struct target_ops
*runable
= NULL
;
1251 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1254 if ((*t
)->to_stratum
== core_stratum
)
1261 return (count
== 1 ? runable
: NULL
);
1265 * Find the next target down the stack from the specified target.
1269 find_target_beneath (t
)
1270 struct target_ops
*t
;
1272 struct target_stack_item
*cur
;
1274 for (cur
= target_stack
; cur
; cur
= cur
->next
)
1275 if (cur
->target_ops
== t
)
1278 if (cur
== NULL
|| cur
->next
== NULL
)
1281 return cur
->next
->target_ops
;
1285 /* The inferior process has died. Long live the inferior! */
1288 generic_mourn_inferior ()
1290 extern int show_breakpoint_hit_counts
;
1294 breakpoint_init_inferior (inf_exited
);
1295 registers_changed ();
1297 #ifdef CLEAR_DEFERRED_STORES
1298 /* Delete any pending stores to the inferior... */
1299 CLEAR_DEFERRED_STORES
;
1302 reopen_exec_file ();
1303 reinit_frame_cache ();
1305 /* It is confusing to the user for ignore counts to stick around
1306 from previous runs of the inferior. So clear them. */
1307 /* However, it is more confusing for the ignore counts to disappear when
1308 using hit counts. So don't clear them if we're counting hits. */
1309 if (!show_breakpoint_hit_counts
)
1310 breakpoint_clear_ignore_counts ();
1313 /* This table must match in order and size the signals in enum target_signal
1322 {"SIGHUP", "Hangup"},
1323 {"SIGINT", "Interrupt"},
1324 {"SIGQUIT", "Quit"},
1325 {"SIGILL", "Illegal instruction"},
1326 {"SIGTRAP", "Trace/breakpoint trap"},
1327 {"SIGABRT", "Aborted"},
1328 {"SIGEMT", "Emulation trap"},
1329 {"SIGFPE", "Arithmetic exception"},
1330 {"SIGKILL", "Killed"},
1331 {"SIGBUS", "Bus error"},
1332 {"SIGSEGV", "Segmentation fault"},
1333 {"SIGSYS", "Bad system call"},
1334 {"SIGPIPE", "Broken pipe"},
1335 {"SIGALRM", "Alarm clock"},
1336 {"SIGTERM", "Terminated"},
1337 {"SIGURG", "Urgent I/O condition"},
1338 {"SIGSTOP", "Stopped (signal)"},
1339 {"SIGTSTP", "Stopped (user)"},
1340 {"SIGCONT", "Continued"},
1341 {"SIGCHLD", "Child status changed"},
1342 {"SIGTTIN", "Stopped (tty input)"},
1343 {"SIGTTOU", "Stopped (tty output)"},
1344 {"SIGIO", "I/O possible"},
1345 {"SIGXCPU", "CPU time limit exceeded"},
1346 {"SIGXFSZ", "File size limit exceeded"},
1347 {"SIGVTALRM", "Virtual timer expired"},
1348 {"SIGPROF", "Profiling timer expired"},
1349 {"SIGWINCH", "Window size changed"},
1350 {"SIGLOST", "Resource lost"},
1351 {"SIGUSR1", "User defined signal 1"},
1352 {"SIGUSR2", "User defined signal 2"},
1353 {"SIGPWR", "Power fail/restart"},
1354 {"SIGPOLL", "Pollable event occurred"},
1355 {"SIGWIND", "SIGWIND"},
1356 {"SIGPHONE", "SIGPHONE"},
1357 {"SIGWAITING", "Process's LWPs are blocked"},
1358 {"SIGLWP", "Signal LWP"},
1359 {"SIGDANGER", "Swap space dangerously low"},
1360 {"SIGGRANT", "Monitor mode granted"},
1361 {"SIGRETRACT", "Need to relinquish monitor mode"},
1362 {"SIGMSG", "Monitor mode data available"},
1363 {"SIGSOUND", "Sound completed"},
1364 {"SIGSAK", "Secure attention"},
1365 {"SIGPRIO", "SIGPRIO"},
1366 {"SIG33", "Real-time event 33"},
1367 {"SIG34", "Real-time event 34"},
1368 {"SIG35", "Real-time event 35"},
1369 {"SIG36", "Real-time event 36"},
1370 {"SIG37", "Real-time event 37"},
1371 {"SIG38", "Real-time event 38"},
1372 {"SIG39", "Real-time event 39"},
1373 {"SIG40", "Real-time event 40"},
1374 {"SIG41", "Real-time event 41"},
1375 {"SIG42", "Real-time event 42"},
1376 {"SIG43", "Real-time event 43"},
1377 {"SIG44", "Real-time event 44"},
1378 {"SIG45", "Real-time event 45"},
1379 {"SIG46", "Real-time event 46"},
1380 {"SIG47", "Real-time event 47"},
1381 {"SIG48", "Real-time event 48"},
1382 {"SIG49", "Real-time event 49"},
1383 {"SIG50", "Real-time event 50"},
1384 {"SIG51", "Real-time event 51"},
1385 {"SIG52", "Real-time event 52"},
1386 {"SIG53", "Real-time event 53"},
1387 {"SIG54", "Real-time event 54"},
1388 {"SIG55", "Real-time event 55"},
1389 {"SIG56", "Real-time event 56"},
1390 {"SIG57", "Real-time event 57"},
1391 {"SIG58", "Real-time event 58"},
1392 {"SIG59", "Real-time event 59"},
1393 {"SIG60", "Real-time event 60"},
1394 {"SIG61", "Real-time event 61"},
1395 {"SIG62", "Real-time event 62"},
1396 {"SIG63", "Real-time event 63"},
1397 {"SIGCANCEL", "LWP internal signal"},
1398 {"SIG32", "Real-time event 32"},
1400 #if defined(MACH) || defined(__MACH__)
1401 /* Mach exceptions */
1402 {"EXC_BAD_ACCESS", "Could not access memory"},
1403 {"EXC_BAD_INSTRUCTION", "Illegal instruction/operand"},
1404 {"EXC_ARITHMETIC", "Arithmetic exception"},
1405 {"EXC_EMULATION", "Emulation instruction"},
1406 {"EXC_SOFTWARE", "Software generated exception"},
1407 {"EXC_BREAKPOINT", "Breakpoint"},
1409 {"SIGINFO", "Information request"},
1411 {NULL
, "Unknown signal"},
1412 {NULL
, "Internal error: printing TARGET_SIGNAL_DEFAULT"},
1414 /* Last entry, used to check whether the table is the right size. */
1415 {NULL
, "TARGET_SIGNAL_MAGIC"}
1421 /* Return the string for a signal. */
1423 target_signal_to_string (sig
)
1424 enum target_signal sig
;
1426 if ((sig
>= TARGET_SIGNAL_FIRST
) && (sig
<= TARGET_SIGNAL_LAST
))
1427 return signals
[sig
].string
;
1429 return signals
[TARGET_SIGNAL_UNKNOWN
].string
;
1432 /* Return the name for a signal. */
1434 target_signal_to_name (sig
)
1435 enum target_signal sig
;
1437 if (sig
== TARGET_SIGNAL_UNKNOWN
)
1438 /* I think the code which prints this will always print it along with
1439 the string, so no need to be verbose. */
1441 return signals
[sig
].name
;
1444 /* Given a name, return its signal. */
1446 target_signal_from_name (name
)
1449 enum target_signal sig
;
1451 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
1452 for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
1453 questionable; seems like by now people should call it SIGABRT
1456 /* This ugly cast brought to you by the native VAX compiler. */
1457 for (sig
= TARGET_SIGNAL_HUP
;
1458 signals
[sig
].name
!= NULL
;
1459 sig
= (enum target_signal
) ((int) sig
+ 1))
1460 if (STREQ (name
, signals
[sig
].name
))
1462 return TARGET_SIGNAL_UNKNOWN
;
1465 /* The following functions are to help certain targets deal
1466 with the signal/waitstatus stuff. They could just as well be in
1467 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
1469 /* Convert host signal to our signals. */
1471 target_signal_from_host (hostsig
)
1474 /* A switch statement would make sense but would require special kludges
1475 to deal with the cases where more than one signal has the same number. */
1478 return TARGET_SIGNAL_0
;
1480 #if defined (SIGHUP)
1481 if (hostsig
== SIGHUP
)
1482 return TARGET_SIGNAL_HUP
;
1484 #if defined (SIGINT)
1485 if (hostsig
== SIGINT
)
1486 return TARGET_SIGNAL_INT
;
1488 #if defined (SIGQUIT)
1489 if (hostsig
== SIGQUIT
)
1490 return TARGET_SIGNAL_QUIT
;
1492 #if defined (SIGILL)
1493 if (hostsig
== SIGILL
)
1494 return TARGET_SIGNAL_ILL
;
1496 #if defined (SIGTRAP)
1497 if (hostsig
== SIGTRAP
)
1498 return TARGET_SIGNAL_TRAP
;
1500 #if defined (SIGABRT)
1501 if (hostsig
== SIGABRT
)
1502 return TARGET_SIGNAL_ABRT
;
1504 #if defined (SIGEMT)
1505 if (hostsig
== SIGEMT
)
1506 return TARGET_SIGNAL_EMT
;
1508 #if defined (SIGFPE)
1509 if (hostsig
== SIGFPE
)
1510 return TARGET_SIGNAL_FPE
;
1512 #if defined (SIGKILL)
1513 if (hostsig
== SIGKILL
)
1514 return TARGET_SIGNAL_KILL
;
1516 #if defined (SIGBUS)
1517 if (hostsig
== SIGBUS
)
1518 return TARGET_SIGNAL_BUS
;
1520 #if defined (SIGSEGV)
1521 if (hostsig
== SIGSEGV
)
1522 return TARGET_SIGNAL_SEGV
;
1524 #if defined (SIGSYS)
1525 if (hostsig
== SIGSYS
)
1526 return TARGET_SIGNAL_SYS
;
1528 #if defined (SIGPIPE)
1529 if (hostsig
== SIGPIPE
)
1530 return TARGET_SIGNAL_PIPE
;
1532 #if defined (SIGALRM)
1533 if (hostsig
== SIGALRM
)
1534 return TARGET_SIGNAL_ALRM
;
1536 #if defined (SIGTERM)
1537 if (hostsig
== SIGTERM
)
1538 return TARGET_SIGNAL_TERM
;
1540 #if defined (SIGUSR1)
1541 if (hostsig
== SIGUSR1
)
1542 return TARGET_SIGNAL_USR1
;
1544 #if defined (SIGUSR2)
1545 if (hostsig
== SIGUSR2
)
1546 return TARGET_SIGNAL_USR2
;
1548 #if defined (SIGCLD)
1549 if (hostsig
== SIGCLD
)
1550 return TARGET_SIGNAL_CHLD
;
1552 #if defined (SIGCHLD)
1553 if (hostsig
== SIGCHLD
)
1554 return TARGET_SIGNAL_CHLD
;
1556 #if defined (SIGPWR)
1557 if (hostsig
== SIGPWR
)
1558 return TARGET_SIGNAL_PWR
;
1560 #if defined (SIGWINCH)
1561 if (hostsig
== SIGWINCH
)
1562 return TARGET_SIGNAL_WINCH
;
1564 #if defined (SIGURG)
1565 if (hostsig
== SIGURG
)
1566 return TARGET_SIGNAL_URG
;
1569 if (hostsig
== SIGIO
)
1570 return TARGET_SIGNAL_IO
;
1572 #if defined (SIGPOLL)
1573 if (hostsig
== SIGPOLL
)
1574 return TARGET_SIGNAL_POLL
;
1576 #if defined (SIGSTOP)
1577 if (hostsig
== SIGSTOP
)
1578 return TARGET_SIGNAL_STOP
;
1580 #if defined (SIGTSTP)
1581 if (hostsig
== SIGTSTP
)
1582 return TARGET_SIGNAL_TSTP
;
1584 #if defined (SIGCONT)
1585 if (hostsig
== SIGCONT
)
1586 return TARGET_SIGNAL_CONT
;
1588 #if defined (SIGTTIN)
1589 if (hostsig
== SIGTTIN
)
1590 return TARGET_SIGNAL_TTIN
;
1592 #if defined (SIGTTOU)
1593 if (hostsig
== SIGTTOU
)
1594 return TARGET_SIGNAL_TTOU
;
1596 #if defined (SIGVTALRM)
1597 if (hostsig
== SIGVTALRM
)
1598 return TARGET_SIGNAL_VTALRM
;
1600 #if defined (SIGPROF)
1601 if (hostsig
== SIGPROF
)
1602 return TARGET_SIGNAL_PROF
;
1604 #if defined (SIGXCPU)
1605 if (hostsig
== SIGXCPU
)
1606 return TARGET_SIGNAL_XCPU
;
1608 #if defined (SIGXFSZ)
1609 if (hostsig
== SIGXFSZ
)
1610 return TARGET_SIGNAL_XFSZ
;
1612 #if defined (SIGWIND)
1613 if (hostsig
== SIGWIND
)
1614 return TARGET_SIGNAL_WIND
;
1616 #if defined (SIGPHONE)
1617 if (hostsig
== SIGPHONE
)
1618 return TARGET_SIGNAL_PHONE
;
1620 #if defined (SIGLOST)
1621 if (hostsig
== SIGLOST
)
1622 return TARGET_SIGNAL_LOST
;
1624 #if defined (SIGWAITING)
1625 if (hostsig
== SIGWAITING
)
1626 return TARGET_SIGNAL_WAITING
;
1628 #if defined (SIGCANCEL)
1629 if (hostsig
== SIGCANCEL
)
1630 return TARGET_SIGNAL_CANCEL
;
1632 #if defined (SIGLWP)
1633 if (hostsig
== SIGLWP
)
1634 return TARGET_SIGNAL_LWP
;
1636 #if defined (SIGDANGER)
1637 if (hostsig
== SIGDANGER
)
1638 return TARGET_SIGNAL_DANGER
;
1640 #if defined (SIGGRANT)
1641 if (hostsig
== SIGGRANT
)
1642 return TARGET_SIGNAL_GRANT
;
1644 #if defined (SIGRETRACT)
1645 if (hostsig
== SIGRETRACT
)
1646 return TARGET_SIGNAL_RETRACT
;
1648 #if defined (SIGMSG)
1649 if (hostsig
== SIGMSG
)
1650 return TARGET_SIGNAL_MSG
;
1652 #if defined (SIGSOUND)
1653 if (hostsig
== SIGSOUND
)
1654 return TARGET_SIGNAL_SOUND
;
1656 #if defined (SIGSAK)
1657 if (hostsig
== SIGSAK
)
1658 return TARGET_SIGNAL_SAK
;
1660 #if defined (SIGPRIO)
1661 if (hostsig
== SIGPRIO
)
1662 return TARGET_SIGNAL_PRIO
;
1665 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1666 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1667 if (hostsig
== _NSIG
+ EXC_BAD_ACCESS
)
1668 return TARGET_EXC_BAD_ACCESS
;
1670 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1671 if (hostsig
== _NSIG
+ EXC_BAD_INSTRUCTION
)
1672 return TARGET_EXC_BAD_INSTRUCTION
;
1674 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1675 if (hostsig
== _NSIG
+ EXC_ARITHMETIC
)
1676 return TARGET_EXC_ARITHMETIC
;
1678 #if defined (EXC_EMULATION) && defined (_NSIG)
1679 if (hostsig
== _NSIG
+ EXC_EMULATION
)
1680 return TARGET_EXC_EMULATION
;
1682 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1683 if (hostsig
== _NSIG
+ EXC_SOFTWARE
)
1684 return TARGET_EXC_SOFTWARE
;
1686 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1687 if (hostsig
== _NSIG
+ EXC_BREAKPOINT
)
1688 return TARGET_EXC_BREAKPOINT
;
1691 #if defined (SIGINFO)
1692 if (hostsig
== SIGINFO
)
1693 return TARGET_SIGNAL_INFO
;
1696 #if defined (REALTIME_LO)
1697 if (hostsig
>= REALTIME_LO
&& hostsig
< REALTIME_HI
)
1699 /* This block of TARGET_SIGNAL_REALTIME value is in order. */
1700 if (33 <= hostsig
&& hostsig
<= 63)
1701 return (enum target_signal
)
1702 (hostsig
- 33 + (int) TARGET_SIGNAL_REALTIME_33
);
1703 else if (hostsig
== 32)
1704 return TARGET_SIGNAL_REALTIME_32
;
1706 error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
1709 return TARGET_SIGNAL_UNKNOWN
;
1712 /* Convert a OURSIG (an enum target_signal) to the form used by the
1713 target operating system (refered to as the ``host'') or zero if the
1714 equivalent host signal is not available. Set/clear OURSIG_OK
1718 do_target_signal_to_host (enum target_signal oursig
,
1724 case TARGET_SIGNAL_0
:
1727 #if defined (SIGHUP)
1728 case TARGET_SIGNAL_HUP
:
1731 #if defined (SIGINT)
1732 case TARGET_SIGNAL_INT
:
1735 #if defined (SIGQUIT)
1736 case TARGET_SIGNAL_QUIT
:
1739 #if defined (SIGILL)
1740 case TARGET_SIGNAL_ILL
:
1743 #if defined (SIGTRAP)
1744 case TARGET_SIGNAL_TRAP
:
1747 #if defined (SIGABRT)
1748 case TARGET_SIGNAL_ABRT
:
1751 #if defined (SIGEMT)
1752 case TARGET_SIGNAL_EMT
:
1755 #if defined (SIGFPE)
1756 case TARGET_SIGNAL_FPE
:
1759 #if defined (SIGKILL)
1760 case TARGET_SIGNAL_KILL
:
1763 #if defined (SIGBUS)
1764 case TARGET_SIGNAL_BUS
:
1767 #if defined (SIGSEGV)
1768 case TARGET_SIGNAL_SEGV
:
1771 #if defined (SIGSYS)
1772 case TARGET_SIGNAL_SYS
:
1775 #if defined (SIGPIPE)
1776 case TARGET_SIGNAL_PIPE
:
1779 #if defined (SIGALRM)
1780 case TARGET_SIGNAL_ALRM
:
1783 #if defined (SIGTERM)
1784 case TARGET_SIGNAL_TERM
:
1787 #if defined (SIGUSR1)
1788 case TARGET_SIGNAL_USR1
:
1791 #if defined (SIGUSR2)
1792 case TARGET_SIGNAL_USR2
:
1795 #if defined (SIGCHLD) || defined (SIGCLD)
1796 case TARGET_SIGNAL_CHLD
:
1797 #if defined (SIGCHLD)
1802 #endif /* SIGCLD or SIGCHLD */
1803 #if defined (SIGPWR)
1804 case TARGET_SIGNAL_PWR
:
1807 #if defined (SIGWINCH)
1808 case TARGET_SIGNAL_WINCH
:
1811 #if defined (SIGURG)
1812 case TARGET_SIGNAL_URG
:
1816 case TARGET_SIGNAL_IO
:
1819 #if defined (SIGPOLL)
1820 case TARGET_SIGNAL_POLL
:
1823 #if defined (SIGSTOP)
1824 case TARGET_SIGNAL_STOP
:
1827 #if defined (SIGTSTP)
1828 case TARGET_SIGNAL_TSTP
:
1831 #if defined (SIGCONT)
1832 case TARGET_SIGNAL_CONT
:
1835 #if defined (SIGTTIN)
1836 case TARGET_SIGNAL_TTIN
:
1839 #if defined (SIGTTOU)
1840 case TARGET_SIGNAL_TTOU
:
1843 #if defined (SIGVTALRM)
1844 case TARGET_SIGNAL_VTALRM
:
1847 #if defined (SIGPROF)
1848 case TARGET_SIGNAL_PROF
:
1851 #if defined (SIGXCPU)
1852 case TARGET_SIGNAL_XCPU
:
1855 #if defined (SIGXFSZ)
1856 case TARGET_SIGNAL_XFSZ
:
1859 #if defined (SIGWIND)
1860 case TARGET_SIGNAL_WIND
:
1863 #if defined (SIGPHONE)
1864 case TARGET_SIGNAL_PHONE
:
1867 #if defined (SIGLOST)
1868 case TARGET_SIGNAL_LOST
:
1871 #if defined (SIGWAITING)
1872 case TARGET_SIGNAL_WAITING
:
1875 #if defined (SIGCANCEL)
1876 case TARGET_SIGNAL_CANCEL
:
1879 #if defined (SIGLWP)
1880 case TARGET_SIGNAL_LWP
:
1883 #if defined (SIGDANGER)
1884 case TARGET_SIGNAL_DANGER
:
1887 #if defined (SIGGRANT)
1888 case TARGET_SIGNAL_GRANT
:
1891 #if defined (SIGRETRACT)
1892 case TARGET_SIGNAL_RETRACT
:
1895 #if defined (SIGMSG)
1896 case TARGET_SIGNAL_MSG
:
1899 #if defined (SIGSOUND)
1900 case TARGET_SIGNAL_SOUND
:
1903 #if defined (SIGSAK)
1904 case TARGET_SIGNAL_SAK
:
1907 #if defined (SIGPRIO)
1908 case TARGET_SIGNAL_PRIO
:
1912 case TARGET_SIGNAL_REALTIME_32
: return 32; /* by definition */
1914 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1915 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1916 case TARGET_EXC_BAD_ACCESS
:
1917 return _NSIG
+ EXC_BAD_ACCESS
;
1919 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1920 case TARGET_EXC_BAD_INSTRUCTION
:
1921 return _NSIG
+ EXC_BAD_INSTRUCTION
;
1923 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1924 case TARGET_EXC_ARITHMETIC
:
1925 return _NSIG
+ EXC_ARITHMETIC
;
1927 #if defined (EXC_EMULATION) && defined (_NSIG)
1928 case TARGET_EXC_EMULATION
:
1929 return _NSIG
+ EXC_EMULATION
;
1931 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1932 case TARGET_EXC_SOFTWARE
:
1933 return _NSIG
+ EXC_SOFTWARE
;
1935 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1936 case TARGET_EXC_BREAKPOINT
:
1937 return _NSIG
+ EXC_BREAKPOINT
;
1940 #if defined (SIGINFO)
1941 case TARGET_SIGNAL_INFO
:
1946 #if defined (REALTIME_LO)
1947 if (oursig
>= TARGET_SIGNAL_REALTIME_33
1948 && oursig
<= TARGET_SIGNAL_REALTIME_63
)
1951 (int) oursig
- (int) TARGET_SIGNAL_REALTIME_33
+ REALTIME_LO
;
1952 if (retsig
< REALTIME_HI
)
1962 target_signal_to_host_p (enum target_signal oursig
)
1965 do_target_signal_to_host (oursig
, &oursig_ok
);
1970 target_signal_to_host (enum target_signal oursig
)
1973 int targ_signo
= do_target_signal_to_host (oursig
, &oursig_ok
);
1976 /* The user might be trying to do "signal SIGSAK" where this system
1977 doesn't have SIGSAK. */
1978 warning ("Signal %s does not exist on this system.\n",
1979 target_signal_to_name (oursig
));
1986 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1987 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1988 translation of that in OURSTATUS. */
1990 store_waitstatus (ourstatus
, hoststatus
)
1991 struct target_waitstatus
*ourstatus
;
1994 #ifdef CHILD_SPECIAL_WAITSTATUS
1995 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1996 if it wants to deal with hoststatus. */
1997 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
2001 if (WIFEXITED (hoststatus
))
2003 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
2004 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
2006 else if (!WIFSTOPPED (hoststatus
))
2008 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
2009 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
2013 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
2014 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
2018 /* In some circumstances we allow a command to specify a numeric
2019 signal. The idea is to keep these circumstances limited so that
2020 users (and scripts) develop portable habits. For comparison,
2021 POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
2022 numeric signal at all is obscelescent. We are slightly more
2023 lenient and allow 1-15 which should match host signal numbers on
2024 most systems. Use of symbolic signal names is strongly encouraged. */
2027 target_signal_from_command (num
)
2030 if (num
>= 1 && num
<= 15)
2031 return (enum target_signal
) num
;
2032 error ("Only signals 1-15 are valid as numeric signals.\n\
2033 Use \"info signals\" for a list of symbolic signals.");
2036 /* Returns zero to leave the inferior alone, one to interrupt it. */
2037 int (*target_activity_function
) PARAMS ((void));
2038 int target_activity_fd
;
2040 /* Convert a normal process ID to a string. Returns the string in a static
2044 normal_pid_to_str (pid
)
2047 static char buf
[30];
2049 if (STREQ (current_target
.to_shortname
, "remote"))
2050 sprintf (buf
, "thread %d", pid
);
2052 sprintf (buf
, "process %d", pid
);
2057 /* Some targets (such as ttrace-based HPUX) don't allow us to request
2058 notification of inferior events such as fork and vork immediately
2059 after the inferior is created. (This because of how gdb gets an
2060 inferior created via invoking a shell to do it. In such a scenario,
2061 if the shell init file has commands in it, the shell will fork and
2062 exec for each of those commands, and we will see each such fork
2065 This function is used by all targets that allow us to request
2066 notification of forks, etc at inferior creation time; e.g., in
2067 target_acknowledge_forked_child.
2070 normal_target_post_startup_inferior (pid
)
2073 /* This space intentionally left blank. */
2076 /* Set up the handful of non-empty slots needed by the dummy target
2080 init_dummy_target ()
2082 dummy_target
.to_shortname
= "None";
2083 dummy_target
.to_longname
= "None";
2084 dummy_target
.to_doc
= "";
2085 dummy_target
.to_attach
= find_default_attach
;
2086 dummy_target
.to_require_attach
= find_default_require_attach
;
2087 dummy_target
.to_require_detach
= find_default_require_detach
;
2088 dummy_target
.to_create_inferior
= find_default_create_inferior
;
2089 dummy_target
.to_clone_and_follow_inferior
= find_default_clone_and_follow_inferior
;
2090 dummy_target
.to_pid_to_str
= normal_pid_to_str
;
2091 dummy_target
.to_stratum
= dummy_stratum
;
2092 dummy_target
.to_magic
= OPS_MAGIC
;
2096 static struct target_ops debug_target
;
2099 debug_to_open (args
, from_tty
)
2103 debug_target
.to_open (args
, from_tty
);
2105 fprintf_unfiltered (gdb_stdlog
, "target_open (%s, %d)\n", args
, from_tty
);
2109 debug_to_close (quitting
)
2112 debug_target
.to_close (quitting
);
2114 fprintf_unfiltered (gdb_stdlog
, "target_close (%d)\n", quitting
);
2118 debug_to_attach (args
, from_tty
)
2122 debug_target
.to_attach (args
, from_tty
);
2124 fprintf_unfiltered (gdb_stdlog
, "target_attach (%s, %d)\n", args
, from_tty
);
2129 debug_to_post_attach (pid
)
2132 debug_target
.to_post_attach (pid
);
2134 fprintf_unfiltered (gdb_stdlog
, "target_post_attach (%d)\n", pid
);
2138 debug_to_require_attach (args
, from_tty
)
2142 debug_target
.to_require_attach (args
, from_tty
);
2144 fprintf_unfiltered (gdb_stdlog
,
2145 "target_require_attach (%s, %d)\n", args
, from_tty
);
2149 debug_to_detach (args
, from_tty
)
2153 debug_target
.to_detach (args
, from_tty
);
2155 fprintf_unfiltered (gdb_stdlog
, "target_detach (%s, %d)\n", args
, from_tty
);
2159 debug_to_require_detach (pid
, args
, from_tty
)
2164 debug_target
.to_require_detach (pid
, args
, from_tty
);
2166 fprintf_unfiltered (gdb_stdlog
,
2167 "target_require_detach (%d, %s, %d)\n", pid
, args
, from_tty
);
2171 debug_to_resume (pid
, step
, siggnal
)
2174 enum target_signal siggnal
;
2176 debug_target
.to_resume (pid
, step
, siggnal
);
2178 fprintf_unfiltered (gdb_stdlog
, "target_resume (%d, %s, %s)\n", pid
,
2179 step
? "step" : "continue",
2180 target_signal_to_name (siggnal
));
2184 debug_to_wait (pid
, status
)
2186 struct target_waitstatus
*status
;
2190 retval
= debug_target
.to_wait (pid
, status
);
2192 fprintf_unfiltered (gdb_stdlog
,
2193 "target_wait (%d, status) = %d, ", pid
, retval
);
2194 fprintf_unfiltered (gdb_stdlog
, "status->kind = ");
2195 switch (status
->kind
)
2197 case TARGET_WAITKIND_EXITED
:
2198 fprintf_unfiltered (gdb_stdlog
, "exited, status = %d\n",
2199 status
->value
.integer
);
2201 case TARGET_WAITKIND_STOPPED
:
2202 fprintf_unfiltered (gdb_stdlog
, "stopped, signal = %s\n",
2203 target_signal_to_name (status
->value
.sig
));
2205 case TARGET_WAITKIND_SIGNALLED
:
2206 fprintf_unfiltered (gdb_stdlog
, "signalled, signal = %s\n",
2207 target_signal_to_name (status
->value
.sig
));
2209 case TARGET_WAITKIND_LOADED
:
2210 fprintf_unfiltered (gdb_stdlog
, "loaded\n");
2212 case TARGET_WAITKIND_FORKED
:
2213 fprintf_unfiltered (gdb_stdlog
, "forked\n");
2215 case TARGET_WAITKIND_VFORKED
:
2216 fprintf_unfiltered (gdb_stdlog
, "vforked\n");
2218 case TARGET_WAITKIND_EXECD
:
2219 fprintf_unfiltered (gdb_stdlog
, "execd\n");
2221 case TARGET_WAITKIND_SPURIOUS
:
2222 fprintf_unfiltered (gdb_stdlog
, "spurious\n");
2225 fprintf_unfiltered (gdb_stdlog
, "unknown???\n");
2233 debug_to_post_wait (pid
, status
)
2237 debug_target
.to_post_wait (pid
, status
);
2239 fprintf_unfiltered (gdb_stdlog
, "target_post_wait (%d, %d)\n",
2244 debug_to_fetch_registers (regno
)
2247 debug_target
.to_fetch_registers (regno
);
2249 fprintf_unfiltered (gdb_stdlog
, "target_fetch_registers (%s)",
2250 regno
!= -1 ? REGISTER_NAME (regno
) : "-1");
2252 fprintf_unfiltered (gdb_stdlog
, " = 0x%lx %ld",
2253 (unsigned long) read_register (regno
),
2254 (unsigned long) read_register (regno
));
2255 fprintf_unfiltered (gdb_stdlog
, "\n");
2259 debug_to_store_registers (regno
)
2262 debug_target
.to_store_registers (regno
);
2264 if (regno
>= 0 && regno
< NUM_REGS
)
2265 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%s) = 0x%lx %ld\n",
2266 REGISTER_NAME (regno
),
2267 (unsigned long) read_register (regno
),
2268 (unsigned long) read_register (regno
));
2270 fprintf_unfiltered (gdb_stdlog
, "target_store_registers (%d)\n", regno
);
2274 debug_to_prepare_to_store ()
2276 debug_target
.to_prepare_to_store ();
2278 fprintf_unfiltered (gdb_stdlog
, "target_prepare_to_store ()\n");
2282 debug_to_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
2287 struct target_ops
*target
;
2291 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
, target
);
2293 fprintf_unfiltered (gdb_stdlog
,
2294 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
2295 (unsigned int) memaddr
, /* possable truncate long long */
2296 len
, write
? "write" : "read", retval
);
2304 fputs_unfiltered (", bytes =", gdb_stdlog
);
2305 for (i
= 0; i
< retval
; i
++)
2307 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
2308 fprintf_unfiltered (gdb_stdlog
, "\n");
2309 fprintf_unfiltered (gdb_stdlog
, " %02x", myaddr
[i
] & 0xff);
2313 fputc_unfiltered ('\n', gdb_stdlog
);
2319 debug_to_files_info (target
)
2320 struct target_ops
*target
;
2322 debug_target
.to_files_info (target
);
2324 fprintf_unfiltered (gdb_stdlog
, "target_files_info (xxx)\n");
2328 debug_to_insert_breakpoint (addr
, save
)
2334 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
2336 fprintf_unfiltered (gdb_stdlog
,
2337 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
2338 (unsigned long) addr
,
2339 (unsigned long) retval
);
2344 debug_to_remove_breakpoint (addr
, save
)
2350 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
2352 fprintf_unfiltered (gdb_stdlog
,
2353 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
2354 (unsigned long) addr
,
2355 (unsigned long) retval
);
2360 debug_to_terminal_init ()
2362 debug_target
.to_terminal_init ();
2364 fprintf_unfiltered (gdb_stdlog
, "target_terminal_init ()\n");
2368 debug_to_terminal_inferior ()
2370 debug_target
.to_terminal_inferior ();
2372 fprintf_unfiltered (gdb_stdlog
, "target_terminal_inferior ()\n");
2376 debug_to_terminal_ours_for_output ()
2378 debug_target
.to_terminal_ours_for_output ();
2380 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours_for_output ()\n");
2384 debug_to_terminal_ours ()
2386 debug_target
.to_terminal_ours ();
2388 fprintf_unfiltered (gdb_stdlog
, "target_terminal_ours ()\n");
2392 debug_to_terminal_info (arg
, from_tty
)
2396 debug_target
.to_terminal_info (arg
, from_tty
);
2398 fprintf_unfiltered (gdb_stdlog
, "target_terminal_info (%s, %d)\n", arg
,
2405 debug_target
.to_kill ();
2407 fprintf_unfiltered (gdb_stdlog
, "target_kill ()\n");
2411 debug_to_load (args
, from_tty
)
2415 debug_target
.to_load (args
, from_tty
);
2417 fprintf_unfiltered (gdb_stdlog
, "target_load (%s, %d)\n", args
, from_tty
);
2421 debug_to_lookup_symbol (name
, addrp
)
2427 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
2429 fprintf_unfiltered (gdb_stdlog
, "target_lookup_symbol (%s, xxx)\n", name
);
2435 debug_to_create_inferior (exec_file
, args
, env
)
2440 debug_target
.to_create_inferior (exec_file
, args
, env
);
2442 fprintf_unfiltered (gdb_stdlog
, "target_create_inferior (%s, %s, xxx)\n",
2447 debug_to_post_startup_inferior (pid
)
2450 debug_target
.to_post_startup_inferior (pid
);
2452 fprintf_unfiltered (gdb_stdlog
, "target_post_startup_inferior (%d)\n",
2457 debug_to_acknowledge_created_inferior (pid
)
2460 debug_target
.to_acknowledge_created_inferior (pid
);
2462 fprintf_unfiltered (gdb_stdlog
, "target_acknowledge_created_inferior (%d)\n",
2467 debug_to_clone_and_follow_inferior (child_pid
, followed_child
)
2469 int *followed_child
;
2471 debug_target
.to_clone_and_follow_inferior (child_pid
, followed_child
);
2473 fprintf_unfiltered (gdb_stdlog
,
2474 "target_clone_and_follow_inferior (%d, %d)\n",
2475 child_pid
, *followed_child
);
2479 debug_to_post_follow_inferior_by_clone ()
2481 debug_target
.to_post_follow_inferior_by_clone ();
2483 fprintf_unfiltered (gdb_stdlog
, "target_post_follow_inferior_by_clone ()\n");
2487 debug_to_insert_fork_catchpoint (pid
)
2492 retval
= debug_target
.to_insert_fork_catchpoint (pid
);
2494 fprintf_unfiltered (gdb_stdlog
, "target_insert_fork_catchpoint (%d) = %d\n",
2501 debug_to_remove_fork_catchpoint (pid
)
2506 retval
= debug_target
.to_remove_fork_catchpoint (pid
);
2508 fprintf_unfiltered (gdb_stdlog
, "target_remove_fork_catchpoint (%d) = %d\n",
2515 debug_to_insert_vfork_catchpoint (pid
)
2520 retval
= debug_target
.to_insert_vfork_catchpoint (pid
);
2522 fprintf_unfiltered (gdb_stdlog
, "target_insert_vfork_catchpoint (%d)= %d\n",
2529 debug_to_remove_vfork_catchpoint (pid
)
2534 retval
= debug_target
.to_remove_vfork_catchpoint (pid
);
2536 fprintf_unfiltered (gdb_stdlog
, "target_remove_vfork_catchpoint (%d) = %d\n",
2543 debug_to_has_forked (pid
, child_pid
)
2549 has_forked
= debug_target
.to_has_forked (pid
, child_pid
);
2551 fprintf_unfiltered (gdb_stdlog
, "target_has_forked (%d, %d) = %d\n",
2552 pid
, *child_pid
, has_forked
);
2558 debug_to_has_vforked (pid
, child_pid
)
2564 has_vforked
= debug_target
.to_has_vforked (pid
, child_pid
);
2566 fprintf_unfiltered (gdb_stdlog
, "target_has_vforked (%d, %d) = %d\n",
2567 pid
, *child_pid
, has_vforked
);
2573 debug_to_can_follow_vfork_prior_to_exec ()
2575 int can_immediately_follow_vfork
;
2577 can_immediately_follow_vfork
= debug_target
.to_can_follow_vfork_prior_to_exec ();
2579 fprintf_unfiltered (gdb_stdlog
, "target_can_follow_vfork_prior_to_exec () = %d\n",
2580 can_immediately_follow_vfork
);
2582 return can_immediately_follow_vfork
;
2586 debug_to_post_follow_vfork (parent_pid
, followed_parent
, child_pid
, followed_child
)
2588 int followed_parent
;
2592 debug_target
.to_post_follow_vfork (parent_pid
, followed_parent
, child_pid
, followed_child
);
2594 fprintf_unfiltered (gdb_stdlog
,
2595 "target_post_follow_vfork (%d, %d, %d, %d)\n",
2596 parent_pid
, followed_parent
, child_pid
, followed_child
);
2600 debug_to_insert_exec_catchpoint (pid
)
2605 retval
= debug_target
.to_insert_exec_catchpoint (pid
);
2607 fprintf_unfiltered (gdb_stdlog
, "target_insert_exec_catchpoint (%d) = %d\n",
2614 debug_to_remove_exec_catchpoint (pid
)
2619 retval
= debug_target
.to_remove_exec_catchpoint (pid
);
2621 fprintf_unfiltered (gdb_stdlog
, "target_remove_exec_catchpoint (%d) = %d\n",
2628 debug_to_has_execd (pid
, execd_pathname
)
2630 char **execd_pathname
;
2634 has_execd
= debug_target
.to_has_execd (pid
, execd_pathname
);
2636 fprintf_unfiltered (gdb_stdlog
, "target_has_execd (%d, %s) = %d\n",
2637 pid
, (*execd_pathname
? *execd_pathname
: "<NULL>"),
2644 debug_to_reported_exec_events_per_exec_call ()
2646 int reported_exec_events
;
2648 reported_exec_events
= debug_target
.to_reported_exec_events_per_exec_call ();
2650 fprintf_unfiltered (gdb_stdlog
,
2651 "target_reported_exec_events_per_exec_call () = %d\n",
2652 reported_exec_events
);
2654 return reported_exec_events
;
2658 debug_to_has_syscall_event (pid
, kind
, syscall_id
)
2660 enum target_waitkind
*kind
;
2663 int has_syscall_event
;
2664 char *kind_spelling
= "??";
2666 has_syscall_event
= debug_target
.to_has_syscall_event (pid
, kind
, syscall_id
);
2667 if (has_syscall_event
)
2671 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2672 kind_spelling
= "SYSCALL_ENTRY";
2674 case TARGET_WAITKIND_SYSCALL_RETURN
:
2675 kind_spelling
= "SYSCALL_RETURN";
2682 fprintf_unfiltered (gdb_stdlog
,
2683 "target_has_syscall_event (%d, %s, %d) = %d\n",
2684 pid
, kind_spelling
, *syscall_id
, has_syscall_event
);
2686 return has_syscall_event
;
2690 debug_to_has_exited (pid
, wait_status
, exit_status
)
2697 has_exited
= debug_target
.to_has_exited (pid
, wait_status
, exit_status
);
2699 fprintf_unfiltered (gdb_stdlog
, "target_has_exited (%d, %d, %d) = %d\n",
2700 pid
, wait_status
, *exit_status
, has_exited
);
2706 debug_to_mourn_inferior ()
2708 debug_target
.to_mourn_inferior ();
2710 fprintf_unfiltered (gdb_stdlog
, "target_mourn_inferior ()\n");
2718 retval
= debug_target
.to_can_run ();
2720 fprintf_unfiltered (gdb_stdlog
, "target_can_run () = %d\n", retval
);
2726 debug_to_notice_signals (pid
)
2729 debug_target
.to_notice_signals (pid
);
2731 fprintf_unfiltered (gdb_stdlog
, "target_notice_signals (%d)\n", pid
);
2735 debug_to_thread_alive (pid
)
2740 retval
= debug_target
.to_thread_alive (pid
);
2742 fprintf_unfiltered (gdb_stdlog
, "target_thread_alive (%d) = %d\n",
2751 debug_target
.to_stop ();
2753 fprintf_unfiltered (gdb_stdlog
, "target_stop ()\n");
2757 debug_to_query (type
, req
, resp
, siz
)
2765 retval
= debug_target
.to_query (type
, req
, resp
, siz
);
2767 fprintf_unfiltered (gdb_stdlog
, "target_query (%c, %s, %s, %d) = %d\n", type
, req
, resp
, *siz
, retval
);
2773 debug_to_rcmd (char *command
,
2774 struct gdb_file
*outbuf
)
2776 debug_target
.to_rcmd (command
, outbuf
);
2777 fprintf_unfiltered (gdb_stdlog
, "target_rcmd (%s, ...)\n", command
);
2780 static struct symtab_and_line
*
2781 debug_to_enable_exception_callback (kind
, enable
)
2782 enum exception_event_kind kind
;
2785 struct symtab_and_line
*result
;
2786 result
= debug_target
.to_enable_exception_callback (kind
, enable
);
2787 fprintf_unfiltered (gdb_stdlog
,
2788 "target get_exception_callback_sal (%d, %d)\n",
2793 static struct exception_event_record
*
2794 debug_to_get_current_exception_event ()
2796 struct exception_event_record
*result
;
2797 result
= debug_target
.to_get_current_exception_event ();
2798 fprintf_unfiltered (gdb_stdlog
, "target get_current_exception_event ()\n");
2803 debug_to_pid_to_exec_file (pid
)
2808 exec_file
= debug_target
.to_pid_to_exec_file (pid
);
2810 fprintf_unfiltered (gdb_stdlog
, "target_pid_to_exec_file (%d) = %s\n",
2817 debug_to_core_file_to_sym_file (core
)
2822 sym_file
= debug_target
.to_core_file_to_sym_file (core
);
2824 fprintf_unfiltered (gdb_stdlog
, "target_core_file_to_sym_file (%s) = %s\n",
2831 setup_target_debug ()
2833 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
2835 current_target
.to_open
= debug_to_open
;
2836 current_target
.to_close
= debug_to_close
;
2837 current_target
.to_attach
= debug_to_attach
;
2838 current_target
.to_post_attach
= debug_to_post_attach
;
2839 current_target
.to_require_attach
= debug_to_require_attach
;
2840 current_target
.to_detach
= debug_to_detach
;
2841 current_target
.to_require_detach
= debug_to_require_detach
;
2842 current_target
.to_resume
= debug_to_resume
;
2843 current_target
.to_wait
= debug_to_wait
;
2844 current_target
.to_post_wait
= debug_to_post_wait
;
2845 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2846 current_target
.to_store_registers
= debug_to_store_registers
;
2847 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2848 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2849 current_target
.to_files_info
= debug_to_files_info
;
2850 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2851 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2852 current_target
.to_terminal_init
= debug_to_terminal_init
;
2853 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2854 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2855 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2856 current_target
.to_terminal_info
= debug_to_terminal_info
;
2857 current_target
.to_kill
= debug_to_kill
;
2858 current_target
.to_load
= debug_to_load
;
2859 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2860 current_target
.to_create_inferior
= debug_to_create_inferior
;
2861 current_target
.to_post_startup_inferior
= debug_to_post_startup_inferior
;
2862 current_target
.to_acknowledge_created_inferior
= debug_to_acknowledge_created_inferior
;
2863 current_target
.to_clone_and_follow_inferior
= debug_to_clone_and_follow_inferior
;
2864 current_target
.to_post_follow_inferior_by_clone
= debug_to_post_follow_inferior_by_clone
;
2865 current_target
.to_insert_fork_catchpoint
= debug_to_insert_fork_catchpoint
;
2866 current_target
.to_remove_fork_catchpoint
= debug_to_remove_fork_catchpoint
;
2867 current_target
.to_insert_vfork_catchpoint
= debug_to_insert_vfork_catchpoint
;
2868 current_target
.to_remove_vfork_catchpoint
= debug_to_remove_vfork_catchpoint
;
2869 current_target
.to_has_forked
= debug_to_has_forked
;
2870 current_target
.to_has_vforked
= debug_to_has_vforked
;
2871 current_target
.to_can_follow_vfork_prior_to_exec
= debug_to_can_follow_vfork_prior_to_exec
;
2872 current_target
.to_post_follow_vfork
= debug_to_post_follow_vfork
;
2873 current_target
.to_insert_exec_catchpoint
= debug_to_insert_exec_catchpoint
;
2874 current_target
.to_remove_exec_catchpoint
= debug_to_remove_exec_catchpoint
;
2875 current_target
.to_has_execd
= debug_to_has_execd
;
2876 current_target
.to_reported_exec_events_per_exec_call
= debug_to_reported_exec_events_per_exec_call
;
2877 current_target
.to_has_syscall_event
= debug_to_has_syscall_event
;
2878 current_target
.to_has_exited
= debug_to_has_exited
;
2879 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2880 current_target
.to_can_run
= debug_to_can_run
;
2881 current_target
.to_notice_signals
= debug_to_notice_signals
;
2882 current_target
.to_thread_alive
= debug_to_thread_alive
;
2883 current_target
.to_stop
= debug_to_stop
;
2884 current_target
.to_query
= debug_to_query
;
2885 current_target
.to_rcmd
= debug_to_rcmd
;
2886 current_target
.to_enable_exception_callback
= debug_to_enable_exception_callback
;
2887 current_target
.to_get_current_exception_event
= debug_to_get_current_exception_event
;
2888 current_target
.to_pid_to_exec_file
= debug_to_pid_to_exec_file
;
2889 current_target
.to_core_file_to_sym_file
= debug_to_core_file_to_sym_file
;
2894 static char targ_desc
[] =
2895 "Names of targets and files being debugged.\n\
2896 Shows the entire stack of targets currently in use (including the exec-file,\n\
2897 core-file, and process, if any), as well as the symbol file name.";
2900 do_monitor_command (char *cmd
,
2903 if ((current_target
.to_rcmd
== (void*) tcomplain
)
2904 || (current_target
.to_rcmd
== debug_to_rcmd
2905 && (debug_target
.to_rcmd
== (void*) tcomplain
)))
2907 error ("\"monitor\" command not supported by this target.\n");
2909 target_rcmd (cmd
, gdb_stdtarg
);
2913 initialize_targets ()
2915 init_dummy_target ();
2916 push_target (&dummy_target
);
2918 add_info ("target", target_info
, targ_desc
);
2919 add_info ("files", target_info
, targ_desc
);
2922 add_set_cmd ("targetdebug", class_maintenance
, var_zinteger
,
2923 (char *) &targetdebug
,
2924 "Set target debugging.\n\
2925 When non-zero, target debugging is enabled.", &setlist
),
2929 add_com ("monitor", class_obscure
, do_monitor_command
,
2930 "Send a command to the remote monitor (remote targets only).");
2932 if (!STREQ (signals
[TARGET_SIGNAL_LAST
].string
, "TARGET_SIGNAL_MAGIC"))