1 /* Select target systems and architectures at runtime for GDB.
2 Copyright 1990, 1992, 1993, 1994, 1995, 1998 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, Boston, MA 02111-1307, USA. */
24 #include "gdb_string.h"
38 target_info
PARAMS ((char *, int));
41 cleanup_target
PARAMS ((struct target_ops
*));
44 maybe_kill_then_create_inferior
PARAMS ((char *, char *, char **));
47 maybe_kill_then_attach
PARAMS ((char *, int));
50 kill_or_be_killed
PARAMS ((int));
53 default_terminal_info
PARAMS ((char *, int));
56 nosymbol
PARAMS ((char *, CORE_ADDR
*));
59 tcomplain
PARAMS ((void));
62 nomemory
PARAMS ((CORE_ADDR
, char *, int, int, struct target_ops
*));
65 return_zero
PARAMS ((void));
68 ignore
PARAMS ((void));
71 target_command
PARAMS ((char *, int));
73 static struct target_ops
*
74 find_default_run_target
PARAMS ((char *));
77 update_current_target
PARAMS ((void));
79 /* Transfer LEN bytes between target address MEMADDR and GDB address MYADDR.
80 Returns 0 for success, errno code for failure (which includes partial
81 transfers--if you want a more useful response to partial transfers, try
82 target_read_memory_partial). */
85 target_xfer_memory
PARAMS ((CORE_ADDR memaddr
, char *myaddr
, int len
,
86 int write
, asection
*bfd_section
));
89 debug_to_open
PARAMS ((char *, int));
92 debug_to_close
PARAMS ((int));
95 debug_to_attach
PARAMS ((char *, int));
98 debug_to_detach
PARAMS ((char *, int));
101 debug_to_resume
PARAMS ((int, int, enum target_signal
));
104 debug_to_wait
PARAMS ((int, struct target_waitstatus
*));
107 debug_to_fetch_registers
PARAMS ((int));
110 debug_to_store_registers
PARAMS ((int));
113 debug_to_prepare_to_store
PARAMS ((void));
116 debug_to_xfer_memory
PARAMS ((CORE_ADDR
, char *, int, int, struct target_ops
*));
119 debug_to_files_info
PARAMS ((struct target_ops
*));
122 debug_to_insert_breakpoint
PARAMS ((CORE_ADDR
, char *));
125 debug_to_remove_breakpoint
PARAMS ((CORE_ADDR
, char *));
128 debug_to_terminal_init
PARAMS ((void));
131 debug_to_terminal_inferior
PARAMS ((void));
134 debug_to_terminal_ours_for_output
PARAMS ((void));
137 debug_to_terminal_ours
PARAMS ((void));
140 debug_to_terminal_info
PARAMS ((char *, int));
143 debug_to_kill
PARAMS ((void));
146 debug_to_load
PARAMS ((char *, int));
149 debug_to_lookup_symbol
PARAMS ((char *, CORE_ADDR
*));
152 debug_to_create_inferior
PARAMS ((char *, char *, char **));
155 debug_to_mourn_inferior
PARAMS ((void));
158 debug_to_can_run
PARAMS ((void));
161 debug_to_notice_signals
PARAMS ((int));
164 debug_to_thread_alive
PARAMS ((int));
167 debug_to_stop
PARAMS ((void));
169 /* Pointer to array of target architecture structures; the size of the
170 array; the current index into the array; the allocated size of the
172 struct target_ops
**target_structs
;
173 unsigned target_struct_size
;
174 unsigned target_struct_index
;
175 unsigned target_struct_allocsize
;
176 #define DEFAULT_ALLOCSIZE 10
178 /* The initial current target, so that there is always a semi-valid
181 struct target_ops dummy_target
= {
182 "None", /* to_shortname */
183 "None", /* to_longname */
187 find_default_attach
, /* to_attach */
191 0, /* to_fetch_registers */
192 0, /* to_store_registers */
193 0, /* to_prepare_to_store */
194 0, /* to_xfer_memory */
195 0, /* to_files_info */
196 0, /* to_insert_breakpoint */
197 0, /* to_remove_breakpoint */
198 0, /* to_terminal_init */
199 0, /* to_terminal_inferior */
200 0, /* to_terminal_ours_for_output */
201 0, /* to_terminal_ours */
202 0, /* to_terminal_info */
205 0, /* to_lookup_symbol */
206 find_default_create_inferior
, /* to_create_inferior */
207 0, /* to_mourn_inferior */
209 0, /* to_notice_signals */
210 0, /* to_thread_alive */
212 dummy_stratum
, /* to_stratum */
214 0, /* to_has_all_memory */
215 0, /* to_has_memory */
216 0, /* to_has_stack */
217 0, /* to_has_registers */
218 0, /* to_has_execution */
220 0, /* to_sections_end */
221 OPS_MAGIC
, /* to_magic */
224 /* Top of target stack. */
226 struct target_stack_item
*target_stack
;
228 /* The target structure we are currently using to talk to a process
229 or file or whatever "inferior" we have. */
231 struct target_ops current_target
;
233 /* Command list for target. */
235 static struct cmd_list_element
*targetlist
= NULL
;
237 /* Nonzero if we are debugging an attached outside process
238 rather than an inferior. */
242 #ifdef MAINTENANCE_CMDS
243 /* Non-zero if we want to see trace of target level stuff. */
245 static int targetdebug
= 0;
247 static void setup_target_debug
PARAMS ((void));
251 /* The user just typed 'target' without the name of a target. */
255 target_command (arg
, from_tty
)
259 fputs_filtered ("Argument required (target name). Try `help target'\n",
263 /* Add a possible target architecture to the list. */
267 struct target_ops
*t
;
271 target_struct_allocsize
= DEFAULT_ALLOCSIZE
;
272 target_structs
= (struct target_ops
**) xmalloc
273 (target_struct_allocsize
* sizeof (*target_structs
));
275 if (target_struct_size
>= target_struct_allocsize
)
277 target_struct_allocsize
*= 2;
278 target_structs
= (struct target_ops
**)
279 xrealloc ((char *) target_structs
,
280 target_struct_allocsize
* sizeof (*target_structs
));
282 target_structs
[target_struct_size
++] = t
;
283 /* cleanup_target (t);*/
285 if (targetlist
== NULL
)
286 add_prefix_cmd ("target", class_run
, target_command
,
287 "Connect to a target machine or process.\n\
288 The first argument is the type or protocol of the target machine.\n\
289 Remaining arguments are interpreted by the target protocol. For more\n\
290 information on the arguments for a particular protocol, type\n\
291 `help target ' followed by the protocol name.",
292 &targetlist
, "target ", 0, &cmdlist
);
293 add_cmd (t
->to_shortname
, no_class
, t
->to_open
, t
->to_doc
, &targetlist
);
305 nomemory (memaddr
, myaddr
, len
, write
, t
)
310 struct target_ops
*t
;
312 errno
= EIO
; /* Can't read/write this location */
313 return 0; /* No bytes handled */
319 error ("You can't do that when your target is `%s'",
320 current_target
.to_shortname
);
326 error ("You can't do that without a process to debug");
331 nosymbol (name
, addrp
)
335 return 1; /* Symbol does not exist in target env */
340 default_terminal_info (args
, from_tty
)
344 printf_unfiltered("No saved terminal information.\n");
347 /* This is the default target_create_inferior and target_attach function.
348 If the current target is executing, it asks whether to kill it off.
349 If this function returns without calling error(), it has killed off
350 the target, and the operation should be attempted. */
353 kill_or_be_killed (from_tty
)
356 if (target_has_execution
)
358 printf_unfiltered ("You are already running a program:\n");
359 target_files_info ();
360 if (query ("Kill it? ")) {
362 if (target_has_execution
)
363 error ("Killing the program did not help.");
366 error ("Program not killed.");
373 maybe_kill_then_attach (args
, from_tty
)
377 kill_or_be_killed (from_tty
);
378 target_attach (args
, from_tty
);
382 maybe_kill_then_create_inferior (exec
, args
, env
)
387 kill_or_be_killed (0);
388 target_create_inferior (exec
, args
, env
);
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))) ignore
);
406 de_fault (to_attach
, maybe_kill_then_attach
);
407 de_fault (to_detach
, (void (*) PARAMS((char *, int))) ignore
);
408 de_fault (to_resume
, (void (*) PARAMS((int, int, enum target_signal
))) noprocess
);
409 de_fault (to_wait
, (int (*) PARAMS((int, struct target_waitstatus
*))) noprocess
);
410 de_fault (to_fetch_registers
, (void (*) PARAMS((int))) ignore
);
411 de_fault (to_store_registers
, (void (*) PARAMS((int))) noprocess
);
412 de_fault (to_prepare_to_store
, (void (*) PARAMS((void))) noprocess
);
413 de_fault (to_xfer_memory
, (int (*) PARAMS((CORE_ADDR
, char *, int, int, struct target_ops
*))) nomemory
);
414 de_fault (to_files_info
, (void (*) PARAMS((struct target_ops
*))) ignore
);
415 de_fault (to_insert_breakpoint
, memory_insert_breakpoint
);
416 de_fault (to_remove_breakpoint
, memory_remove_breakpoint
);
417 de_fault (to_terminal_init
, (void (*) PARAMS((void))) ignore
);
418 de_fault (to_terminal_inferior
, (void (*) PARAMS ((void))) ignore
);
419 de_fault (to_terminal_ours_for_output
,(void (*) PARAMS ((void))) ignore
);
420 de_fault (to_terminal_ours
, (void (*) PARAMS ((void))) ignore
);
421 de_fault (to_terminal_info
, default_terminal_info
);
422 de_fault (to_kill
, (void (*) PARAMS((void))) noprocess
);
423 de_fault (to_load
, (void (*) PARAMS((char *, int))) tcomplain
);
424 de_fault (to_lookup_symbol
, (int (*) PARAMS ((char *, CORE_ADDR
*))) nosymbol
);
425 de_fault (to_create_inferior
, maybe_kill_then_create_inferior
);
426 de_fault (to_mourn_inferior
, (void (*) PARAMS((void))) noprocess
);
427 de_fault (to_can_run
, return_zero
);
428 de_fault (to_notice_signals
, (void (*) PARAMS((int))) ignore
);
429 de_fault (to_thread_alive
, (int (*) PARAMS((int))) ignore
);
430 de_fault (to_stop
, (void (*) PARAMS((void))) ignore
);
435 /* Go through the target stack from top to bottom, copying over zero entries in
436 current_target. In effect, we are doing class inheritance through the
437 pushed target vectors. */
440 update_current_target ()
442 struct target_stack_item
*item
;
443 struct target_ops
*t
;
445 /* First, reset current_target */
446 memset (¤t_target
, 0, sizeof current_target
);
448 for (item
= target_stack
; item
; item
= item
->next
)
450 t
= item
->target_ops
;
452 #define INHERIT(FIELD, TARGET) \
453 if (!current_target.FIELD) \
454 current_target.FIELD = TARGET->FIELD
456 INHERIT (to_shortname
, t
);
457 INHERIT (to_longname
, t
);
459 INHERIT (to_open
, t
);
460 INHERIT (to_close
, t
);
461 INHERIT (to_attach
, t
);
462 INHERIT (to_detach
, t
);
463 INHERIT (to_resume
, t
);
464 INHERIT (to_wait
, t
);
465 INHERIT (to_fetch_registers
, t
);
466 INHERIT (to_store_registers
, t
);
467 INHERIT (to_prepare_to_store
, t
);
468 INHERIT (to_xfer_memory
, t
);
469 INHERIT (to_files_info
, t
);
470 INHERIT (to_insert_breakpoint
, t
);
471 INHERIT (to_remove_breakpoint
, t
);
472 INHERIT (to_terminal_init
, t
);
473 INHERIT (to_terminal_inferior
, t
);
474 INHERIT (to_terminal_ours_for_output
, t
);
475 INHERIT (to_terminal_ours
, t
);
476 INHERIT (to_terminal_info
, t
);
477 INHERIT (to_kill
, t
);
478 INHERIT (to_load
, t
);
479 INHERIT (to_lookup_symbol
, t
);
480 INHERIT (to_create_inferior
, t
);
481 INHERIT (to_mourn_inferior
, t
);
482 INHERIT (to_can_run
, t
);
483 INHERIT (to_notice_signals
, t
);
484 INHERIT (to_thread_alive
, t
);
485 INHERIT (to_stop
, t
);
486 INHERIT (to_stratum
, t
);
487 INHERIT (DONT_USE
, t
);
488 INHERIT (to_has_all_memory
, t
);
489 INHERIT (to_has_memory
, t
);
490 INHERIT (to_has_stack
, t
);
491 INHERIT (to_has_registers
, t
);
492 INHERIT (to_has_execution
, t
);
493 INHERIT (to_sections
, t
);
494 INHERIT (to_sections_end
, t
);
495 INHERIT (to_magic
, t
);
501 /* Push a new target type into the stack of the existing target accessors,
502 possibly superseding some of the existing accessors.
504 Result is zero if the pushed target ended up on top of the stack,
505 nonzero if at least one target is on top of it.
507 Rather than allow an empty stack, we always have the dummy target at
508 the bottom stratum, so we can call the function vectors without
513 struct target_ops
*t
;
515 struct target_stack_item
*cur
, *prev
, *tmp
;
517 /* Check magic number. If wrong, it probably means someone changed
518 the struct definition, but not all the places that initialize one. */
519 if (t
->to_magic
!= OPS_MAGIC
)
521 fprintf_unfiltered(gdb_stderr
,
522 "Magic number of %s target struct wrong\n",
527 /* Find the proper stratum to install this target in. */
529 for (prev
= NULL
, cur
= target_stack
; cur
; prev
= cur
, cur
= cur
->next
)
531 if ((int)(t
->to_stratum
) >= (int)(cur
->target_ops
->to_stratum
))
535 /* If there's already targets at this stratum, remove them. */
538 while (t
->to_stratum
== cur
->target_ops
->to_stratum
)
540 /* There's already something on this stratum. Close it off. */
541 if (cur
->target_ops
->to_close
)
542 (cur
->target_ops
->to_close
) (0);
544 prev
->next
= cur
->next
; /* Unchain old target_ops */
546 target_stack
= cur
->next
; /* Unchain first on list */
552 /* We have removed all targets in our stratum, now add the new one. */
554 tmp
= (struct target_stack_item
*)
555 xmalloc (sizeof (struct target_stack_item
));
564 update_current_target ();
566 cleanup_target (¤t_target
); /* Fill in the gaps */
568 #ifdef MAINTENANCE_CMDS
570 setup_target_debug ();
576 /* Remove a target_ops vector from the stack, wherever it may be.
577 Return how many times it was removed (0 or 1). */
581 struct target_ops
*t
;
583 struct target_stack_item
*cur
, *prev
;
586 t
->to_close (0); /* Let it clean up */
588 /* Look for the specified target. Note that we assume that a target
589 can only occur once in the target stack. */
591 for (cur
= target_stack
, prev
= NULL
; cur
; prev
= cur
, cur
= cur
->next
)
592 if (cur
->target_ops
== t
)
596 return 0; /* Didn't find target_ops, quit now */
598 /* Unchain the target */
601 target_stack
= cur
->next
;
603 prev
->next
= cur
->next
;
605 free (cur
); /* Release the target_stack_item */
607 update_current_target ();
608 cleanup_target (¤t_target
);
616 (current_target
.to_close
)(0); /* Let it clean up */
617 if (unpush_target (target_stack
->target_ops
) == 1)
620 fprintf_unfiltered(gdb_stderr
,
621 "pop_target couldn't find target %s\n",
622 current_target
.to_shortname
);
627 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
629 /* target_read_string -- read a null terminated string, up to LEN bytes,
630 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
631 Set *STRING to a pointer to malloc'd memory containing the data; the caller
632 is responsible for freeing it. Return the number of bytes successfully
636 target_read_string (memaddr
, string
, len
, errnop
)
642 int tlen
, origlen
, offset
, i
;
646 int buffer_allocated
;
648 unsigned int nbytes_read
= 0;
650 /* Small for testing. */
651 buffer_allocated
= 4;
652 buffer
= xmalloc (buffer_allocated
);
659 tlen
= MIN (len
, 4 - (memaddr
& 3));
660 offset
= memaddr
& 3;
662 errcode
= target_xfer_memory (memaddr
& ~3, buf
, 4, 0, NULL
);
665 /* The transfer request might have crossed the boundary to an
666 unallocated region of memory. Retry the transfer, requesting
670 errcode
= target_xfer_memory (memaddr
, buf
, 1, 0, NULL
);
675 if (bufptr
- buffer
+ tlen
> buffer_allocated
)
678 bytes
= bufptr
- buffer
;
679 buffer_allocated
*= 2;
680 buffer
= xrealloc (buffer
, buffer_allocated
);
681 bufptr
= buffer
+ bytes
;
684 for (i
= 0; i
< tlen
; i
++)
686 *bufptr
++ = buf
[i
+ offset
];
687 if (buf
[i
+ offset
] == '\000')
689 nbytes_read
+= i
+ 1;
706 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
707 GDB's memory at MYADDR. Returns either 0 for success or an errno value
710 If an error occurs, no guarantee is made about the contents of the data at
711 MYADDR. In particular, the caller should not depend upon partial reads
712 filling the buffer with good data. There is no way for the caller to know
713 how much good data might have been transfered anyway. Callers that can
714 deal with partial reads should call target_read_memory_partial. */
717 target_read_memory (memaddr
, myaddr
, len
)
722 return target_xfer_memory (memaddr
, myaddr
, len
, 0, NULL
);
726 target_read_memory_section (memaddr
, myaddr
, len
, bfd_section
)
730 asection
*bfd_section
;
732 return target_xfer_memory (memaddr
, myaddr
, len
, 0, bfd_section
);
735 /* Read LEN bytes of target memory at address MEMADDR, placing the results
736 in GDB's memory at MYADDR. Returns a count of the bytes actually read,
737 and optionally an errno value in the location pointed to by ERRNOPTR
738 if ERRNOPTR is non-null. */
741 target_read_memory_partial (memaddr
, myaddr
, len
, errnoptr
)
747 int nread
; /* Number of bytes actually read. */
748 int errcode
; /* Error from last read. */
750 /* First try a complete read. */
751 errcode
= target_xfer_memory (memaddr
, myaddr
, len
, 0, NULL
);
759 /* Loop, reading one byte at a time until we get as much as we can. */
760 for (errcode
= 0, nread
= 0; len
> 0 && errcode
== 0; nread
++, len
--)
762 errcode
= target_xfer_memory (memaddr
++, myaddr
++, 1, 0, NULL
);
764 /* If an error, the last read was unsuccessful, so adjust count. */
770 if (errnoptr
!= NULL
)
778 target_write_memory (memaddr
, myaddr
, len
)
783 return target_xfer_memory (memaddr
, myaddr
, len
, 1, NULL
);
786 /* This variable is used to pass section information down to targets. This
787 *should* be done by adding an argument to the target_xfer_memory function
788 of all the targets, but I didn't feel like changing 50+ files. */
790 asection
*target_memory_bfd_section
= NULL
;
792 /* Move memory to or from the targets. Iterate until all of it has
793 been moved, if necessary. The top target gets priority; anything
794 it doesn't want, is offered to the next one down, etc. Note the
795 business with curlen: if an early target says "no, but I have a
796 boundary overlapping this xfer" then we shorten what we offer to
797 the subsequent targets so the early guy will get a chance at the
798 tail before the subsequent ones do.
800 Result is 0 or errno value. */
803 target_xfer_memory (memaddr
, myaddr
, len
, write
, bfd_section
)
808 asection
*bfd_section
;
812 struct target_ops
*t
;
813 struct target_stack_item
*item
;
815 /* Zero length requests are ok and require no work. */
819 target_memory_bfd_section
= bfd_section
;
821 /* to_xfer_memory is not guaranteed to set errno, even when it returns
825 /* The quick case is that the top target does it all. */
826 res
= current_target
.to_xfer_memory
827 (memaddr
, myaddr
, len
, write
, ¤t_target
);
833 /* If res <= 0 then we call it again in the loop. Ah well. */
837 curlen
= len
; /* Want to do it all */
838 for (item
= target_stack
; item
; item
= item
->next
)
840 t
= item
->target_ops
;
841 if (!t
->to_has_memory
)
844 res
= t
->to_xfer_memory (memaddr
, myaddr
, curlen
, write
, t
);
846 break; /* Handled all or part of xfer */
847 if (t
->to_has_all_memory
)
853 /* If this address is for nonexistent memory,
854 read zeros if reading, or do nothing if writing. Return error. */
856 memset (myaddr
, 0, len
);
867 return 0; /* We managed to cover it all somehow. */
873 target_info (args
, from_tty
)
877 struct target_ops
*t
;
878 struct target_stack_item
*item
;
881 if (symfile_objfile
!= NULL
)
882 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile
->name
);
884 #ifdef FILES_INFO_HOOK
885 if (FILES_INFO_HOOK ())
889 for (item
= target_stack
; item
; item
= item
->next
)
891 t
= item
->target_ops
;
893 if (!t
->to_has_memory
)
896 if ((int)(t
->to_stratum
) <= (int)dummy_stratum
)
899 printf_unfiltered("\tWhile running this, GDB does not access memory from...\n");
900 printf_unfiltered("%s:\n", t
->to_longname
);
901 (t
->to_files_info
)(t
);
902 has_all_mem
= t
->to_has_all_memory
;
906 /* This is to be called by the open routine before it does
910 target_preopen (from_tty
)
915 if (target_has_execution
)
917 if (query ("A program is being debugged already. Kill it? "))
920 error ("Program not killed.");
923 /* Calling target_kill may remove the target from the stack. But if
924 it doesn't (which seems like a win for UDI), remove it now. */
926 if (target_has_execution
)
930 /* Detach a target after doing deferred register stores. */
933 target_detach (args
, from_tty
)
937 /* Handle any optimized stores to the inferior. */
938 #ifdef DO_DEFERRED_STORES
941 (current_target
.to_detach
) (args
, from_tty
);
945 target_link (modname
, t_reloc
)
949 if (STREQ(current_target
.to_shortname
, "rombug"))
951 (current_target
.to_lookup_symbol
) (modname
, t_reloc
);
953 error("Unable to link to %s and get relocation in rombug", modname
);
956 *t_reloc
= (CORE_ADDR
)-1;
959 /* Look through the list of possible targets for a target that can
960 execute a run or attach command without any other data. This is
961 used to locate the default process stratum.
963 Result is always valid (error() is called for errors). */
965 static struct target_ops
*
966 find_default_run_target (do_mesg
)
969 struct target_ops
**t
;
970 struct target_ops
*runable
= NULL
;
975 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
978 if ((*t
)->to_can_run
&& target_can_run(*t
))
986 error ("Don't know how to %s. Try \"help target\".", do_mesg
);
992 find_default_attach (args
, from_tty
)
996 struct target_ops
*t
;
998 t
= find_default_run_target("attach");
999 (t
->to_attach
) (args
, from_tty
);
1004 find_default_create_inferior (exec_file
, allargs
, env
)
1009 struct target_ops
*t
;
1011 t
= find_default_run_target("run");
1012 (t
->to_create_inferior
) (exec_file
, allargs
, env
);
1025 struct target_ops
**t
;
1026 struct target_ops
*runable
= NULL
;
1031 for (t
= target_structs
; t
< target_structs
+ target_struct_size
;
1034 if ((*t
)->to_stratum
== core_stratum
)
1041 return(count
== 1 ? runable
: NULL
);
1044 /* The inferior process has died. Long live the inferior! */
1047 generic_mourn_inferior ()
1049 extern int show_breakpoint_hit_counts
;
1053 breakpoint_init_inferior ();
1054 registers_changed ();
1056 #ifdef CLEAR_DEFERRED_STORES
1057 /* Delete any pending stores to the inferior... */
1058 CLEAR_DEFERRED_STORES
;
1061 reopen_exec_file ();
1062 reinit_frame_cache ();
1064 /* It is confusing to the user for ignore counts to stick around
1065 from previous runs of the inferior. So clear them. */
1066 /* However, it is more confusing for the ignore counts to disappear when
1067 using hit counts. So don't clear them if we're counting hits. */
1068 if (!show_breakpoint_hit_counts
)
1069 breakpoint_clear_ignore_counts ();
1072 /* This table must match in order and size the signals in enum target_signal
1080 {"SIGHUP", "Hangup"},
1081 {"SIGINT", "Interrupt"},
1082 {"SIGQUIT", "Quit"},
1083 {"SIGILL", "Illegal instruction"},
1084 {"SIGTRAP", "Trace/breakpoint trap"},
1085 {"SIGABRT", "Aborted"},
1086 {"SIGEMT", "Emulation trap"},
1087 {"SIGFPE", "Arithmetic exception"},
1088 {"SIGKILL", "Killed"},
1089 {"SIGBUS", "Bus error"},
1090 {"SIGSEGV", "Segmentation fault"},
1091 {"SIGSYS", "Bad system call"},
1092 {"SIGPIPE", "Broken pipe"},
1093 {"SIGALRM", "Alarm clock"},
1094 {"SIGTERM", "Terminated"},
1095 {"SIGURG", "Urgent I/O condition"},
1096 {"SIGSTOP", "Stopped (signal)"},
1097 {"SIGTSTP", "Stopped (user)"},
1098 {"SIGCONT", "Continued"},
1099 {"SIGCHLD", "Child status changed"},
1100 {"SIGTTIN", "Stopped (tty input)"},
1101 {"SIGTTOU", "Stopped (tty output)"},
1102 {"SIGIO", "I/O possible"},
1103 {"SIGXCPU", "CPU time limit exceeded"},
1104 {"SIGXFSZ", "File size limit exceeded"},
1105 {"SIGVTALRM", "Virtual timer expired"},
1106 {"SIGPROF", "Profiling timer expired"},
1107 {"SIGWINCH", "Window size changed"},
1108 {"SIGLOST", "Resource lost"},
1109 {"SIGUSR1", "User defined signal 1"},
1110 {"SIGUSR2", "User defined signal 2"},
1111 {"SIGPWR", "Power fail/restart"},
1112 {"SIGPOLL", "Pollable event occurred"},
1113 {"SIGWIND", "SIGWIND"},
1114 {"SIGPHONE", "SIGPHONE"},
1115 {"SIGWAITING", "Process's LWPs are blocked"},
1116 {"SIGLWP", "Signal LWP"},
1117 {"SIGDANGER", "Swap space dangerously low"},
1118 {"SIGGRANT", "Monitor mode granted"},
1119 {"SIGRETRACT", "Need to relinguish monitor mode"},
1120 {"SIGMSG", "Monitor mode data available"},
1121 {"SIGSOUND", "Sound completed"},
1122 {"SIGSAK", "Secure attention"},
1123 {"SIGPRIO", "SIGPRIO"},
1124 {"SIG33", "Real-time event 33"},
1125 {"SIG34", "Real-time event 34"},
1126 {"SIG35", "Real-time event 35"},
1127 {"SIG36", "Real-time event 36"},
1128 {"SIG37", "Real-time event 37"},
1129 {"SIG38", "Real-time event 38"},
1130 {"SIG39", "Real-time event 39"},
1131 {"SIG40", "Real-time event 40"},
1132 {"SIG41", "Real-time event 41"},
1133 {"SIG42", "Real-time event 42"},
1134 {"SIG43", "Real-time event 43"},
1135 {"SIG44", "Real-time event 44"},
1136 {"SIG45", "Real-time event 45"},
1137 {"SIG46", "Real-time event 46"},
1138 {"SIG47", "Real-time event 47"},
1139 {"SIG48", "Real-time event 48"},
1140 {"SIG49", "Real-time event 49"},
1141 {"SIG50", "Real-time event 50"},
1142 {"SIG51", "Real-time event 51"},
1143 {"SIG52", "Real-time event 52"},
1144 {"SIG53", "Real-time event 53"},
1145 {"SIG54", "Real-time event 54"},
1146 {"SIG55", "Real-time event 55"},
1147 {"SIG56", "Real-time event 56"},
1148 {"SIG57", "Real-time event 57"},
1149 {"SIG58", "Real-time event 58"},
1150 {"SIG59", "Real-time event 59"},
1151 {"SIG60", "Real-time event 60"},
1152 {"SIG61", "Real-time event 61"},
1153 {"SIG62", "Real-time event 62"},
1154 {"SIG63", "Real-time event 63"},
1156 #if defined(MACH) || defined(__MACH__)
1157 /* Mach exceptions */
1158 {"EXC_BAD_ACCESS", "Could not access memory"},
1159 {"EXC_BAD_INSTRUCTION", "Illegal instruction/operand"},
1160 {"EXC_ARITHMETIC", "Arithmetic exception"},
1161 {"EXC_EMULATION", "Emulation instruction"},
1162 {"EXC_SOFTWARE", "Software generated exception"},
1163 {"EXC_BREAKPOINT", "Breakpoint"},
1165 {NULL
, "Unknown signal"},
1166 {NULL
, "Internal error: printing TARGET_SIGNAL_DEFAULT"},
1168 /* Last entry, used to check whether the table is the right size. */
1169 {NULL
, "TARGET_SIGNAL_MAGIC"}
1172 /* Return the string for a signal. */
1174 target_signal_to_string (sig
)
1175 enum target_signal sig
;
1177 return signals
[sig
].string
;
1180 /* Return the name for a signal. */
1182 target_signal_to_name (sig
)
1183 enum target_signal sig
;
1185 if (sig
== TARGET_SIGNAL_UNKNOWN
)
1186 /* I think the code which prints this will always print it along with
1187 the string, so no need to be verbose. */
1189 return signals
[sig
].name
;
1192 /* Given a name, return its signal. */
1194 target_signal_from_name (name
)
1197 enum target_signal sig
;
1199 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
1200 for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
1201 questionable; seems like by now people should call it SIGABRT
1204 /* This ugly cast brought to you by the native VAX compiler. */
1205 for (sig
= TARGET_SIGNAL_HUP
;
1206 signals
[sig
].name
!= NULL
;
1207 sig
= (enum target_signal
)((int)sig
+ 1))
1208 if (STREQ (name
, signals
[sig
].name
))
1210 return TARGET_SIGNAL_UNKNOWN
;
1213 /* The following functions are to help certain targets deal
1214 with the signal/waitstatus stuff. They could just as well be in
1215 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
1217 /* Convert host signal to our signals. */
1219 target_signal_from_host (hostsig
)
1222 /* A switch statement would make sense but would require special kludges
1223 to deal with the cases where more than one signal has the same number. */
1225 if (hostsig
== 0) return TARGET_SIGNAL_0
;
1227 #if defined (SIGHUP)
1228 if (hostsig
== SIGHUP
) return TARGET_SIGNAL_HUP
;
1230 #if defined (SIGINT)
1231 if (hostsig
== SIGINT
) return TARGET_SIGNAL_INT
;
1233 #if defined (SIGQUIT)
1234 if (hostsig
== SIGQUIT
) return TARGET_SIGNAL_QUIT
;
1236 #if defined (SIGILL)
1237 if (hostsig
== SIGILL
) return TARGET_SIGNAL_ILL
;
1239 #if defined (SIGTRAP)
1240 if (hostsig
== SIGTRAP
) return TARGET_SIGNAL_TRAP
;
1242 #if defined (SIGABRT)
1243 if (hostsig
== SIGABRT
) return TARGET_SIGNAL_ABRT
;
1245 #if defined (SIGEMT)
1246 if (hostsig
== SIGEMT
) return TARGET_SIGNAL_EMT
;
1248 #if defined (SIGFPE)
1249 if (hostsig
== SIGFPE
) return TARGET_SIGNAL_FPE
;
1251 #if defined (SIGKILL)
1252 if (hostsig
== SIGKILL
) return TARGET_SIGNAL_KILL
;
1254 #if defined (SIGBUS)
1255 if (hostsig
== SIGBUS
) return TARGET_SIGNAL_BUS
;
1257 #if defined (SIGSEGV)
1258 if (hostsig
== SIGSEGV
) return TARGET_SIGNAL_SEGV
;
1260 #if defined (SIGSYS)
1261 if (hostsig
== SIGSYS
) return TARGET_SIGNAL_SYS
;
1263 #if defined (SIGPIPE)
1264 if (hostsig
== SIGPIPE
) return TARGET_SIGNAL_PIPE
;
1266 #if defined (SIGALRM)
1267 if (hostsig
== SIGALRM
) return TARGET_SIGNAL_ALRM
;
1269 #if defined (SIGTERM)
1270 if (hostsig
== SIGTERM
) return TARGET_SIGNAL_TERM
;
1272 #if defined (SIGUSR1)
1273 if (hostsig
== SIGUSR1
) return TARGET_SIGNAL_USR1
;
1275 #if defined (SIGUSR2)
1276 if (hostsig
== SIGUSR2
) return TARGET_SIGNAL_USR2
;
1278 #if defined (SIGCLD)
1279 if (hostsig
== SIGCLD
) return TARGET_SIGNAL_CHLD
;
1281 #if defined (SIGCHLD)
1282 if (hostsig
== SIGCHLD
) return TARGET_SIGNAL_CHLD
;
1284 #if defined (SIGPWR)
1285 if (hostsig
== SIGPWR
) return TARGET_SIGNAL_PWR
;
1287 #if defined (SIGWINCH)
1288 if (hostsig
== SIGWINCH
) return TARGET_SIGNAL_WINCH
;
1290 #if defined (SIGURG)
1291 if (hostsig
== SIGURG
) return TARGET_SIGNAL_URG
;
1294 if (hostsig
== SIGIO
) return TARGET_SIGNAL_IO
;
1296 #if defined (SIGPOLL)
1297 if (hostsig
== SIGPOLL
) return TARGET_SIGNAL_POLL
;
1299 #if defined (SIGSTOP)
1300 if (hostsig
== SIGSTOP
) return TARGET_SIGNAL_STOP
;
1302 #if defined (SIGTSTP)
1303 if (hostsig
== SIGTSTP
) return TARGET_SIGNAL_TSTP
;
1305 #if defined (SIGCONT)
1306 if (hostsig
== SIGCONT
) return TARGET_SIGNAL_CONT
;
1308 #if defined (SIGTTIN)
1309 if (hostsig
== SIGTTIN
) return TARGET_SIGNAL_TTIN
;
1311 #if defined (SIGTTOU)
1312 if (hostsig
== SIGTTOU
) return TARGET_SIGNAL_TTOU
;
1314 #if defined (SIGVTALRM)
1315 if (hostsig
== SIGVTALRM
) return TARGET_SIGNAL_VTALRM
;
1317 #if defined (SIGPROF)
1318 if (hostsig
== SIGPROF
) return TARGET_SIGNAL_PROF
;
1320 #if defined (SIGXCPU)
1321 if (hostsig
== SIGXCPU
) return TARGET_SIGNAL_XCPU
;
1323 #if defined (SIGXFSZ)
1324 if (hostsig
== SIGXFSZ
) return TARGET_SIGNAL_XFSZ
;
1326 #if defined (SIGWIND)
1327 if (hostsig
== SIGWIND
) return TARGET_SIGNAL_WIND
;
1329 #if defined (SIGPHONE)
1330 if (hostsig
== SIGPHONE
) return TARGET_SIGNAL_PHONE
;
1332 #if defined (SIGLOST)
1333 if (hostsig
== SIGLOST
) return TARGET_SIGNAL_LOST
;
1335 #if defined (SIGWAITING)
1336 if (hostsig
== SIGWAITING
) return TARGET_SIGNAL_WAITING
;
1338 #if defined (SIGLWP)
1339 if (hostsig
== SIGLWP
) return TARGET_SIGNAL_LWP
;
1341 #if defined (SIGDANGER)
1342 if (hostsig
== SIGDANGER
) return TARGET_SIGNAL_DANGER
;
1344 #if defined (SIGGRANT)
1345 if (hostsig
== SIGGRANT
) return TARGET_SIGNAL_GRANT
;
1347 #if defined (SIGRETRACT)
1348 if (hostsig
== SIGRETRACT
) return TARGET_SIGNAL_RETRACT
;
1350 #if defined (SIGMSG)
1351 if (hostsig
== SIGMSG
) return TARGET_SIGNAL_MSG
;
1353 #if defined (SIGSOUND)
1354 if (hostsig
== SIGSOUND
) return TARGET_SIGNAL_SOUND
;
1356 #if defined (SIGSAK)
1357 if (hostsig
== SIGSAK
) return TARGET_SIGNAL_SAK
;
1359 #if defined (SIGPRIO)
1360 if (hostsig
== SIGPRIO
) return TARGET_SIGNAL_PRIO
;
1363 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1364 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1365 if (hostsig
== _NSIG
+ EXC_BAD_ACCESS
) return TARGET_EXC_BAD_ACCESS
;
1367 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1368 if (hostsig
== _NSIG
+ EXC_BAD_INSTRUCTION
) return TARGET_EXC_BAD_INSTRUCTION
;
1370 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1371 if (hostsig
== _NSIG
+ EXC_ARITHMETIC
) return TARGET_EXC_ARITHMETIC
;
1373 #if defined (EXC_EMULATION) && defined (_NSIG)
1374 if (hostsig
== _NSIG
+ EXC_EMULATION
) return TARGET_EXC_EMULATION
;
1376 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1377 if (hostsig
== _NSIG
+ EXC_SOFTWARE
) return TARGET_EXC_SOFTWARE
;
1379 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1380 if (hostsig
== _NSIG
+ EXC_BREAKPOINT
) return TARGET_EXC_BREAKPOINT
;
1383 #if defined (REALTIME_LO)
1384 if (hostsig
>= REALTIME_LO
&& hostsig
< REALTIME_HI
)
1385 return (enum target_signal
)
1386 (hostsig
- 33 + (int) TARGET_SIGNAL_REALTIME_33
);
1388 return TARGET_SIGNAL_UNKNOWN
;
1392 target_signal_to_host (oursig
)
1393 enum target_signal oursig
;
1397 case TARGET_SIGNAL_0
: return 0;
1399 #if defined (SIGHUP)
1400 case TARGET_SIGNAL_HUP
: return SIGHUP
;
1402 #if defined (SIGINT)
1403 case TARGET_SIGNAL_INT
: return SIGINT
;
1405 #if defined (SIGQUIT)
1406 case TARGET_SIGNAL_QUIT
: return SIGQUIT
;
1408 #if defined (SIGILL)
1409 case TARGET_SIGNAL_ILL
: return SIGILL
;
1411 #if defined (SIGTRAP)
1412 case TARGET_SIGNAL_TRAP
: return SIGTRAP
;
1414 #if defined (SIGABRT)
1415 case TARGET_SIGNAL_ABRT
: return SIGABRT
;
1417 #if defined (SIGEMT)
1418 case TARGET_SIGNAL_EMT
: return SIGEMT
;
1420 #if defined (SIGFPE)
1421 case TARGET_SIGNAL_FPE
: return SIGFPE
;
1423 #if defined (SIGKILL)
1424 case TARGET_SIGNAL_KILL
: return SIGKILL
;
1426 #if defined (SIGBUS)
1427 case TARGET_SIGNAL_BUS
: return SIGBUS
;
1429 #if defined (SIGSEGV)
1430 case TARGET_SIGNAL_SEGV
: return SIGSEGV
;
1432 #if defined (SIGSYS)
1433 case TARGET_SIGNAL_SYS
: return SIGSYS
;
1435 #if defined (SIGPIPE)
1436 case TARGET_SIGNAL_PIPE
: return SIGPIPE
;
1438 #if defined (SIGALRM)
1439 case TARGET_SIGNAL_ALRM
: return SIGALRM
;
1441 #if defined (SIGTERM)
1442 case TARGET_SIGNAL_TERM
: return SIGTERM
;
1444 #if defined (SIGUSR1)
1445 case TARGET_SIGNAL_USR1
: return SIGUSR1
;
1447 #if defined (SIGUSR2)
1448 case TARGET_SIGNAL_USR2
: return SIGUSR2
;
1450 #if defined (SIGCHLD) || defined (SIGCLD)
1451 case TARGET_SIGNAL_CHLD
:
1452 #if defined (SIGCHLD)
1457 #endif /* SIGCLD or SIGCHLD */
1458 #if defined (SIGPWR)
1459 case TARGET_SIGNAL_PWR
: return SIGPWR
;
1461 #if defined (SIGWINCH)
1462 case TARGET_SIGNAL_WINCH
: return SIGWINCH
;
1464 #if defined (SIGURG)
1465 case TARGET_SIGNAL_URG
: return SIGURG
;
1468 case TARGET_SIGNAL_IO
: return SIGIO
;
1470 #if defined (SIGPOLL)
1471 case TARGET_SIGNAL_POLL
: return SIGPOLL
;
1473 #if defined (SIGSTOP)
1474 case TARGET_SIGNAL_STOP
: return SIGSTOP
;
1476 #if defined (SIGTSTP)
1477 case TARGET_SIGNAL_TSTP
: return SIGTSTP
;
1479 #if defined (SIGCONT)
1480 case TARGET_SIGNAL_CONT
: return SIGCONT
;
1482 #if defined (SIGTTIN)
1483 case TARGET_SIGNAL_TTIN
: return SIGTTIN
;
1485 #if defined (SIGTTOU)
1486 case TARGET_SIGNAL_TTOU
: return SIGTTOU
;
1488 #if defined (SIGVTALRM)
1489 case TARGET_SIGNAL_VTALRM
: return SIGVTALRM
;
1491 #if defined (SIGPROF)
1492 case TARGET_SIGNAL_PROF
: return SIGPROF
;
1494 #if defined (SIGXCPU)
1495 case TARGET_SIGNAL_XCPU
: return SIGXCPU
;
1497 #if defined (SIGXFSZ)
1498 case TARGET_SIGNAL_XFSZ
: return SIGXFSZ
;
1500 #if defined (SIGWIND)
1501 case TARGET_SIGNAL_WIND
: return SIGWIND
;
1503 #if defined (SIGPHONE)
1504 case TARGET_SIGNAL_PHONE
: return SIGPHONE
;
1506 #if defined (SIGLOST)
1507 case TARGET_SIGNAL_LOST
: return SIGLOST
;
1509 #if defined (SIGWAITING)
1510 case TARGET_SIGNAL_WAITING
: return SIGWAITING
;
1512 #if defined (SIGLWP)
1513 case TARGET_SIGNAL_LWP
: return SIGLWP
;
1515 #if defined (SIGDANGER)
1516 case TARGET_SIGNAL_DANGER
: return SIGDANGER
;
1518 #if defined (SIGGRANT)
1519 case TARGET_SIGNAL_GRANT
: return SIGGRANT
;
1521 #if defined (SIGRETRACT)
1522 case TARGET_SIGNAL_RETRACT
: return SIGRETRACT
;
1524 #if defined (SIGMSG)
1525 case TARGET_SIGNAL_MSG
: return SIGMSG
;
1527 #if defined (SIGSOUND)
1528 case TARGET_SIGNAL_SOUND
: return SIGSOUND
;
1530 #if defined (SIGSAK)
1531 case TARGET_SIGNAL_SAK
: return SIGSAK
;
1533 #if defined (SIGPRIO)
1534 case TARGET_SIGNAL_PRIO
: return SIGPRIO
;
1537 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1538 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1539 case TARGET_EXC_BAD_ACCESS
: return _NSIG
+ EXC_BAD_ACCESS
;
1541 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1542 case TARGET_EXC_BAD_INSTRUCTION
: return _NSIG
+ EXC_BAD_INSTRUCTION
;
1544 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1545 case TARGET_EXC_ARITHMETIC
: return _NSIG
+ EXC_ARITHMETIC
;
1547 #if defined (EXC_EMULATION) && defined (_NSIG)
1548 case TARGET_EXC_EMULATION
: return _NSIG
+ EXC_EMULATION
;
1550 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1551 case TARGET_EXC_SOFTWARE
: return _NSIG
+ EXC_SOFTWARE
;
1553 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1554 case TARGET_EXC_BREAKPOINT
: return _NSIG
+ EXC_BREAKPOINT
;
1558 #if defined (REALTIME_LO)
1559 if (oursig
>= TARGET_SIGNAL_REALTIME_33
1560 && oursig
<= TARGET_SIGNAL_REALTIME_63
)
1563 (int)oursig
- (int)TARGET_SIGNAL_REALTIME_33
+ REALTIME_LO
;
1564 if (retsig
< REALTIME_HI
)
1568 /* The user might be trying to do "signal SIGSAK" where this system
1569 doesn't have SIGSAK. */
1570 warning ("Signal %s does not exist on this system.\n",
1571 target_signal_to_name (oursig
));
1576 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1577 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1578 translation of that in OURSTATUS. */
1580 store_waitstatus (ourstatus
, hoststatus
)
1581 struct target_waitstatus
*ourstatus
;
1584 #ifdef CHILD_SPECIAL_WAITSTATUS
1585 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1586 if it wants to deal with hoststatus. */
1587 if (CHILD_SPECIAL_WAITSTATUS (ourstatus
, hoststatus
))
1591 if (WIFEXITED (hoststatus
))
1593 ourstatus
->kind
= TARGET_WAITKIND_EXITED
;
1594 ourstatus
->value
.integer
= WEXITSTATUS (hoststatus
);
1596 else if (!WIFSTOPPED (hoststatus
))
1598 ourstatus
->kind
= TARGET_WAITKIND_SIGNALLED
;
1599 ourstatus
->value
.sig
= target_signal_from_host (WTERMSIG (hoststatus
));
1603 ourstatus
->kind
= TARGET_WAITKIND_STOPPED
;
1604 ourstatus
->value
.sig
= target_signal_from_host (WSTOPSIG (hoststatus
));
1608 /* In some circumstances we allow a command to specify a numeric
1609 signal. The idea is to keep these circumstances limited so that
1610 users (and scripts) develop portable habits. For comparison,
1611 POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
1612 numeric signal at all is obscelescent. We are slightly more
1613 lenient and allow 1-15 which should match host signal numbers on
1614 most systems. Use of symbolic signal names is strongly encouraged. */
1617 target_signal_from_command (num
)
1620 if (num
>= 1 && num
<= 15)
1621 return (enum target_signal
)num
;
1622 error ("Only signals 1-15 are valid as numeric signals.\n\
1623 Use \"info signals\" for a list of symbolic signals.");
1626 /* Returns zero to leave the inferior alone, one to interrupt it. */
1627 int (*target_activity_function
) PARAMS ((void));
1628 int target_activity_fd
;
1630 /* Convert a normal process ID to a string. Returns the string in a static
1634 normal_pid_to_str (pid
)
1637 static char buf
[30];
1639 if (STREQ (current_target
.to_shortname
, "remote"))
1640 sprintf (buf
, "thread %d", pid
);
1642 sprintf (buf
, "process %d", pid
);
1647 #ifdef MAINTENANCE_CMDS
1648 static struct target_ops debug_target
;
1651 debug_to_open (args
, from_tty
)
1655 debug_target
.to_open (args
, from_tty
);
1657 fprintf_unfiltered (stderr
, "target_open (%s, %d)\n", args
, from_tty
);
1661 debug_to_close (quitting
)
1664 debug_target
.to_close (quitting
);
1666 fprintf_unfiltered (stderr
, "target_close (%d)\n", quitting
);
1670 debug_to_attach (args
, from_tty
)
1674 debug_target
.to_attach (args
, from_tty
);
1676 fprintf_unfiltered (stderr
, "target_attach (%s, %d)\n", args
, from_tty
);
1680 debug_to_detach (args
, from_tty
)
1684 debug_target
.to_detach (args
, from_tty
);
1686 fprintf_unfiltered (stderr
, "target_detach (%s, %d)\n", args
, from_tty
);
1690 debug_to_resume (pid
, step
, siggnal
)
1693 enum target_signal siggnal
;
1695 debug_target
.to_resume (pid
, step
, siggnal
);
1697 fprintf_unfiltered (stderr
, "target_resume (%d, %s, %s)\n", pid
,
1698 step
? "step" : "continue",
1699 target_signal_to_name (siggnal
));
1703 debug_to_wait (pid
, status
)
1705 struct target_waitstatus
*status
;
1709 retval
= debug_target
.to_wait (pid
, status
);
1711 fprintf_unfiltered (stderr
, "target_wait (%d, status) = %d, ", pid
, retval
);
1712 fprintf_unfiltered (stderr
, "status->kind = ");
1713 switch (status
->kind
)
1715 case TARGET_WAITKIND_EXITED
:
1716 fprintf_unfiltered (stderr
, "exited, status = %d\n", status
->value
.integer
);
1718 case TARGET_WAITKIND_STOPPED
:
1719 fprintf_unfiltered (stderr
, "stopped, signal = %s\n",
1720 target_signal_to_name (status
->value
.sig
));
1722 case TARGET_WAITKIND_SIGNALLED
:
1723 fprintf_unfiltered (stderr
, "signalled, signal = %s\n",
1724 target_signal_to_name (status
->value
.sig
));
1726 case TARGET_WAITKIND_LOADED
:
1727 fprintf_unfiltered (stderr
, "loaded\n");
1729 case TARGET_WAITKIND_SPURIOUS
:
1730 fprintf_unfiltered (stderr
, "spurious\n");
1733 fprintf_unfiltered (stderr
, "unknown???\n");
1741 debug_to_fetch_registers (regno
)
1744 debug_target
.to_fetch_registers (regno
);
1746 fprintf_unfiltered (stderr
, "target_fetch_registers (%s)",
1747 regno
!= -1 ? reg_names
[regno
] : "-1");
1749 fprintf_unfiltered (stderr
, " = 0x%x %d",
1750 (unsigned long) read_register (regno
),
1751 read_register (regno
));
1752 fprintf_unfiltered (stderr
, "\n");
1756 debug_to_store_registers (regno
)
1759 debug_target
.to_store_registers (regno
);
1761 if (regno
>= 0 && regno
< NUM_REGS
)
1762 fprintf_unfiltered (stderr
, "target_store_registers (%s) = 0x%x %d\n",
1764 (unsigned long) read_register (regno
),
1765 (unsigned long) read_register (regno
));
1767 fprintf_unfiltered (stderr
, "target_store_registers (%d)\n", regno
);
1771 debug_to_prepare_to_store ()
1773 debug_target
.to_prepare_to_store ();
1775 fprintf_unfiltered (stderr
, "target_prepare_to_store ()\n");
1779 debug_to_xfer_memory (memaddr
, myaddr
, len
, write
, target
)
1784 struct target_ops
*target
;
1788 retval
= debug_target
.to_xfer_memory (memaddr
, myaddr
, len
, write
, target
);
1790 fprintf_unfiltered (stderr
,
1791 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
1792 (unsigned int) memaddr
, /* possable truncate long long */
1793 len
, write
? "write" : "read", retval
);
1801 fputs_unfiltered (", bytes =", gdb_stderr
);
1802 for (i
= 0; i
< retval
; i
++)
1804 if ((((long) &(myaddr
[i
])) & 0xf) == 0)
1805 fprintf_unfiltered (stderr
, "\n");
1806 fprintf_unfiltered (stderr
, " %02x", myaddr
[i
] & 0xff);
1810 fputc_unfiltered ('\n', gdb_stderr
);
1816 debug_to_files_info (target
)
1817 struct target_ops
*target
;
1819 debug_target
.to_files_info (target
);
1821 fprintf_unfiltered (stderr
, "target_files_info (xxx)\n");
1825 debug_to_insert_breakpoint (addr
, save
)
1831 retval
= debug_target
.to_insert_breakpoint (addr
, save
);
1833 fprintf_unfiltered (stderr
, "target_insert_breakpoint (0x%x, xxx) = %d\n",
1834 (unsigned long) addr
, retval
);
1839 debug_to_remove_breakpoint (addr
, save
)
1845 retval
= debug_target
.to_remove_breakpoint (addr
, save
);
1847 fprintf_unfiltered (stderr
, "target_remove_breakpoint (0x%x, xxx) = %d\n",
1848 (unsigned long)addr
, retval
);
1853 debug_to_terminal_init ()
1855 debug_target
.to_terminal_init ();
1857 fprintf_unfiltered (stderr
, "target_terminal_init ()\n");
1861 debug_to_terminal_inferior ()
1863 debug_target
.to_terminal_inferior ();
1865 fprintf_unfiltered (stderr
, "target_terminal_inferior ()\n");
1869 debug_to_terminal_ours_for_output ()
1871 debug_target
.to_terminal_ours_for_output ();
1873 fprintf_unfiltered (stderr
, "target_terminal_ours_for_output ()\n");
1877 debug_to_terminal_ours ()
1879 debug_target
.to_terminal_ours ();
1881 fprintf_unfiltered (stderr
, "target_terminal_ours ()\n");
1885 debug_to_terminal_info (arg
, from_tty
)
1889 debug_target
.to_terminal_info (arg
, from_tty
);
1891 fprintf_unfiltered (stderr
, "target_terminal_info (%s, %d)\n", arg
,
1898 debug_target
.to_kill ();
1900 fprintf_unfiltered (stderr
, "target_kill ()\n");
1904 debug_to_load (args
, from_tty
)
1908 debug_target
.to_load (args
, from_tty
);
1910 fprintf_unfiltered (stderr
, "target_load (%s, %d)\n", args
, from_tty
);
1914 debug_to_lookup_symbol (name
, addrp
)
1920 retval
= debug_target
.to_lookup_symbol (name
, addrp
);
1922 fprintf_unfiltered (stderr
, "target_lookup_symbol (%s, xxx)\n", name
);
1928 debug_to_create_inferior (exec_file
, args
, env
)
1933 debug_target
.to_create_inferior (exec_file
, args
, env
);
1935 fprintf_unfiltered (stderr
, "target_create_inferior (%s, %s, xxx)\n",
1940 debug_to_mourn_inferior ()
1942 debug_target
.to_mourn_inferior ();
1944 fprintf_unfiltered (stderr
, "target_mourn_inferior ()\n");
1952 retval
= debug_target
.to_can_run ();
1954 fprintf_unfiltered (stderr
, "target_can_run () = %d\n", retval
);
1960 debug_to_notice_signals (pid
)
1963 debug_target
.to_notice_signals (pid
);
1965 fprintf_unfiltered (stderr
, "target_notice_signals (%d)\n", pid
);
1969 debug_to_thread_alive (pid
)
1974 retval
= debug_target
.to_thread_alive (pid
);
1976 fprintf_unfiltered (stderr
, "target_thread_alive (%d) = %d\n", pid
, retval
);
1984 debug_target
.to_stop ();
1986 fprintf_unfiltered (stderr
, "target_stop ()\n");
1990 setup_target_debug ()
1992 memcpy (&debug_target
, ¤t_target
, sizeof debug_target
);
1994 current_target
.to_open
= debug_to_open
;
1995 current_target
.to_close
= debug_to_close
;
1996 current_target
.to_attach
= debug_to_attach
;
1997 current_target
.to_detach
= debug_to_detach
;
1998 current_target
.to_resume
= debug_to_resume
;
1999 current_target
.to_wait
= debug_to_wait
;
2000 current_target
.to_fetch_registers
= debug_to_fetch_registers
;
2001 current_target
.to_store_registers
= debug_to_store_registers
;
2002 current_target
.to_prepare_to_store
= debug_to_prepare_to_store
;
2003 current_target
.to_xfer_memory
= debug_to_xfer_memory
;
2004 current_target
.to_files_info
= debug_to_files_info
;
2005 current_target
.to_insert_breakpoint
= debug_to_insert_breakpoint
;
2006 current_target
.to_remove_breakpoint
= debug_to_remove_breakpoint
;
2007 current_target
.to_terminal_init
= debug_to_terminal_init
;
2008 current_target
.to_terminal_inferior
= debug_to_terminal_inferior
;
2009 current_target
.to_terminal_ours_for_output
= debug_to_terminal_ours_for_output
;
2010 current_target
.to_terminal_ours
= debug_to_terminal_ours
;
2011 current_target
.to_terminal_info
= debug_to_terminal_info
;
2012 current_target
.to_kill
= debug_to_kill
;
2013 current_target
.to_load
= debug_to_load
;
2014 current_target
.to_lookup_symbol
= debug_to_lookup_symbol
;
2015 current_target
.to_create_inferior
= debug_to_create_inferior
;
2016 current_target
.to_mourn_inferior
= debug_to_mourn_inferior
;
2017 current_target
.to_can_run
= debug_to_can_run
;
2018 current_target
.to_notice_signals
= debug_to_notice_signals
;
2019 current_target
.to_thread_alive
= debug_to_thread_alive
;
2020 current_target
.to_stop
= debug_to_stop
;
2022 #endif /* MAINTENANCE_CMDS */
2024 static char targ_desc
[] =
2025 "Names of targets and files being debugged.\n\
2026 Shows the entire stack of targets currently in use (including the exec-file,\n\
2027 core-file, and process, if any), as well as the symbol file name.";
2030 initialize_targets ()
2032 push_target (&dummy_target
);
2034 add_info ("target", target_info
, targ_desc
);
2035 add_info ("files", target_info
, targ_desc
);
2037 #ifdef MAINTENANCE_CMDS
2039 add_set_cmd ("targetdebug", class_maintenance
, var_zinteger
,
2040 (char *)&targetdebug
,
2041 "Set target debugging.\n\
2042 When non-zero, target debugging is enabled.", &setlist
),
2046 if (!STREQ (signals
[TARGET_SIGNAL_LAST
].string
, "TARGET_SIGNAL_MAGIC"))