Update/correct copyright notices.
[deliverable/binutils-gdb.git] / gdb / target.c
1 /* Select target systems and architectures at runtime for GDB.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001 Free Software Foundation, Inc.
4 Contributed by Cygnus Support.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 #include "defs.h"
24 #include <errno.h>
25 #include <ctype.h>
26 #include "gdb_string.h"
27 #include "target.h"
28 #include "gdbcmd.h"
29 #include "symtab.h"
30 #include "inferior.h"
31 #include "bfd.h"
32 #include "symfile.h"
33 #include "objfiles.h"
34 #include "gdb_wait.h"
35 #include "dcache.h"
36 #include <signal.h>
37 #include "regcache.h"
38
39 extern int errno;
40
41 static void target_info (char *, int);
42
43 static void cleanup_target (struct target_ops *);
44
45 static void maybe_kill_then_create_inferior (char *, char *, char **);
46
47 static void default_clone_and_follow_inferior (int, int *);
48
49 static void maybe_kill_then_attach (char *, int);
50
51 static void kill_or_be_killed (int);
52
53 static void default_terminal_info (char *, int);
54
55 static int nosymbol (char *, CORE_ADDR *);
56
57 static void tcomplain (void);
58
59 static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *);
60
61 static int return_zero (void);
62
63 static int return_one (void);
64
65 void target_ignore (void);
66
67 static void target_command (char *, int);
68
69 static struct target_ops *find_default_run_target (char *);
70
71 static void update_current_target (void);
72
73 static void nosupport_runtime (void);
74
75 static void normal_target_post_startup_inferior (int pid);
76
77 /* Transfer LEN bytes between target address MEMADDR and GDB address
78 MYADDR. Returns 0 for success, errno code for failure (which
79 includes partial transfers -- if you want a more useful response to
80 partial transfers, try either target_read_memory_partial or
81 target_write_memory_partial). */
82
83 static int
84 target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write);
85
86 static void init_dummy_target (void);
87
88 static void debug_to_open (char *, int);
89
90 static void debug_to_close (int);
91
92 static void debug_to_attach (char *, int);
93
94 static void debug_to_detach (char *, int);
95
96 static void debug_to_resume (int, int, enum target_signal);
97
98 static int debug_to_wait (int, struct target_waitstatus *);
99
100 static void debug_to_fetch_registers (int);
101
102 static void debug_to_store_registers (int);
103
104 static void debug_to_prepare_to_store (void);
105
106 static int
107 debug_to_xfer_memory (CORE_ADDR, char *, int, int, struct mem_attrib *,
108 struct target_ops *);
109
110 static void debug_to_files_info (struct target_ops *);
111
112 static int debug_to_insert_breakpoint (CORE_ADDR, char *);
113
114 static int debug_to_remove_breakpoint (CORE_ADDR, char *);
115
116 static void debug_to_terminal_init (void);
117
118 static void debug_to_terminal_inferior (void);
119
120 static void debug_to_terminal_ours_for_output (void);
121
122 static void debug_to_terminal_ours (void);
123
124 static void debug_to_terminal_info (char *, int);
125
126 static void debug_to_kill (void);
127
128 static void debug_to_load (char *, int);
129
130 static int debug_to_lookup_symbol (char *, CORE_ADDR *);
131
132 static void debug_to_create_inferior (char *, char *, char **);
133
134 static void debug_to_mourn_inferior (void);
135
136 static int debug_to_can_run (void);
137
138 static void debug_to_notice_signals (int);
139
140 static int debug_to_thread_alive (int);
141
142 static void debug_to_stop (void);
143
144 static int debug_to_query (int /*char */ , char *, char *, int *);
145
146 /* Pointer to array of target architecture structures; the size of the
147 array; the current index into the array; the allocated size of the
148 array. */
149 struct target_ops **target_structs;
150 unsigned target_struct_size;
151 unsigned target_struct_index;
152 unsigned target_struct_allocsize;
153 #define DEFAULT_ALLOCSIZE 10
154
155 /* The initial current target, so that there is always a semi-valid
156 current target. */
157
158 static struct target_ops dummy_target;
159
160 /* Top of target stack. */
161
162 struct target_stack_item *target_stack;
163
164 /* The target structure we are currently using to talk to a process
165 or file or whatever "inferior" we have. */
166
167 struct target_ops current_target;
168
169 /* Command list for target. */
170
171 static struct cmd_list_element *targetlist = NULL;
172
173 /* Nonzero if we are debugging an attached outside process
174 rather than an inferior. */
175
176 int attach_flag;
177
178 /* Non-zero if we want to see trace of target level stuff. */
179
180 static int targetdebug = 0;
181
182 static void setup_target_debug (void);
183
184 DCACHE *target_dcache;
185
186 /* The user just typed 'target' without the name of a target. */
187
188 /* ARGSUSED */
189 static void
190 target_command (char *arg, int from_tty)
191 {
192 fputs_filtered ("Argument required (target name). Try `help target'\n",
193 gdb_stdout);
194 }
195
196 /* Add a possible target architecture to the list. */
197
198 void
199 add_target (struct target_ops *t)
200 {
201 if (!target_structs)
202 {
203 target_struct_allocsize = DEFAULT_ALLOCSIZE;
204 target_structs = (struct target_ops **) xmalloc
205 (target_struct_allocsize * sizeof (*target_structs));
206 }
207 if (target_struct_size >= target_struct_allocsize)
208 {
209 target_struct_allocsize *= 2;
210 target_structs = (struct target_ops **)
211 xrealloc ((char *) target_structs,
212 target_struct_allocsize * sizeof (*target_structs));
213 }
214 target_structs[target_struct_size++] = t;
215 /* cleanup_target (t); */
216
217 if (targetlist == NULL)
218 add_prefix_cmd ("target", class_run, target_command,
219 "Connect to a target machine or process.\n\
220 The first argument is the type or protocol of the target machine.\n\
221 Remaining arguments are interpreted by the target protocol. For more\n\
222 information on the arguments for a particular protocol, type\n\
223 `help target ' followed by the protocol name.",
224 &targetlist, "target ", 0, &cmdlist);
225 add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist);
226 }
227
228 /* Stub functions */
229
230 void
231 target_ignore (void)
232 {
233 }
234
235 void
236 target_load (char *arg, int from_tty)
237 {
238 dcache_invalidate (target_dcache);
239 (*current_target.to_load) (arg, from_tty);
240 }
241
242 /* ARGSUSED */
243 static int
244 nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write,
245 struct target_ops *t)
246 {
247 errno = EIO; /* Can't read/write this location */
248 return 0; /* No bytes handled */
249 }
250
251 static void
252 tcomplain (void)
253 {
254 error ("You can't do that when your target is `%s'",
255 current_target.to_shortname);
256 }
257
258 void
259 noprocess (void)
260 {
261 error ("You can't do that without a process to debug.");
262 }
263
264 /* ARGSUSED */
265 static int
266 nosymbol (char *name, CORE_ADDR *addrp)
267 {
268 return 1; /* Symbol does not exist in target env */
269 }
270
271 /* ARGSUSED */
272 static void
273 nosupport_runtime (void)
274 {
275 if (!inferior_pid)
276 noprocess ();
277 else
278 error ("No run-time support for this");
279 }
280
281
282 /* ARGSUSED */
283 static void
284 default_terminal_info (char *args, int from_tty)
285 {
286 printf_unfiltered ("No saved terminal information.\n");
287 }
288
289 /* This is the default target_create_inferior and target_attach function.
290 If the current target is executing, it asks whether to kill it off.
291 If this function returns without calling error(), it has killed off
292 the target, and the operation should be attempted. */
293
294 static void
295 kill_or_be_killed (int from_tty)
296 {
297 if (target_has_execution)
298 {
299 printf_unfiltered ("You are already running a program:\n");
300 target_files_info ();
301 if (query ("Kill it? "))
302 {
303 target_kill ();
304 if (target_has_execution)
305 error ("Killing the program did not help.");
306 return;
307 }
308 else
309 {
310 error ("Program not killed.");
311 }
312 }
313 tcomplain ();
314 }
315
316 static void
317 maybe_kill_then_attach (char *args, int from_tty)
318 {
319 kill_or_be_killed (from_tty);
320 target_attach (args, from_tty);
321 }
322
323 static void
324 maybe_kill_then_create_inferior (char *exec, char *args, char **env)
325 {
326 kill_or_be_killed (0);
327 target_create_inferior (exec, args, env);
328 }
329
330 static void
331 default_clone_and_follow_inferior (int child_pid, int *followed_child)
332 {
333 target_clone_and_follow_inferior (child_pid, followed_child);
334 }
335
336 /* Clean up a target struct so it no longer has any zero pointers in it.
337 We default entries, at least to stubs that print error messages. */
338
339 static void
340 cleanup_target (struct target_ops *t)
341 {
342
343 #define de_fault(field, value) \
344 if (!t->field) \
345 t->field = value
346
347 de_fault (to_open,
348 (void (*) (char *, int))
349 tcomplain);
350 de_fault (to_close,
351 (void (*) (int))
352 target_ignore);
353 de_fault (to_attach,
354 maybe_kill_then_attach);
355 de_fault (to_post_attach,
356 (void (*) (int))
357 target_ignore);
358 de_fault (to_require_attach,
359 maybe_kill_then_attach);
360 de_fault (to_detach,
361 (void (*) (char *, int))
362 target_ignore);
363 de_fault (to_require_detach,
364 (void (*) (int, char *, int))
365 target_ignore);
366 de_fault (to_resume,
367 (void (*) (int, int, enum target_signal))
368 noprocess);
369 de_fault (to_wait,
370 (int (*) (int, struct target_waitstatus *))
371 noprocess);
372 de_fault (to_post_wait,
373 (void (*) (int, int))
374 target_ignore);
375 de_fault (to_fetch_registers,
376 (void (*) (int))
377 target_ignore);
378 de_fault (to_store_registers,
379 (void (*) (int))
380 noprocess);
381 de_fault (to_prepare_to_store,
382 (void (*) (void))
383 noprocess);
384 de_fault (to_xfer_memory,
385 (int (*) (CORE_ADDR, char *, int, int, struct mem_attrib *, struct target_ops *))
386 nomemory);
387 de_fault (to_files_info,
388 (void (*) (struct target_ops *))
389 target_ignore);
390 de_fault (to_insert_breakpoint,
391 memory_insert_breakpoint);
392 de_fault (to_remove_breakpoint,
393 memory_remove_breakpoint);
394 de_fault (to_terminal_init,
395 (void (*) (void))
396 target_ignore);
397 de_fault (to_terminal_inferior,
398 (void (*) (void))
399 target_ignore);
400 de_fault (to_terminal_ours_for_output,
401 (void (*) (void))
402 target_ignore);
403 de_fault (to_terminal_ours,
404 (void (*) (void))
405 target_ignore);
406 de_fault (to_terminal_info,
407 default_terminal_info);
408 de_fault (to_kill,
409 (void (*) (void))
410 noprocess);
411 de_fault (to_load,
412 (void (*) (char *, int))
413 tcomplain);
414 de_fault (to_lookup_symbol,
415 (int (*) (char *, CORE_ADDR *))
416 nosymbol);
417 de_fault (to_create_inferior,
418 maybe_kill_then_create_inferior);
419 de_fault (to_post_startup_inferior,
420 (void (*) (int))
421 target_ignore);
422 de_fault (to_acknowledge_created_inferior,
423 (void (*) (int))
424 target_ignore);
425 de_fault (to_clone_and_follow_inferior,
426 default_clone_and_follow_inferior);
427 de_fault (to_post_follow_inferior_by_clone,
428 (void (*) (void))
429 target_ignore);
430 de_fault (to_insert_fork_catchpoint,
431 (int (*) (int))
432 tcomplain);
433 de_fault (to_remove_fork_catchpoint,
434 (int (*) (int))
435 tcomplain);
436 de_fault (to_insert_vfork_catchpoint,
437 (int (*) (int))
438 tcomplain);
439 de_fault (to_remove_vfork_catchpoint,
440 (int (*) (int))
441 tcomplain);
442 de_fault (to_has_forked,
443 (int (*) (int, int *))
444 return_zero);
445 de_fault (to_has_vforked,
446 (int (*) (int, int *))
447 return_zero);
448 de_fault (to_can_follow_vfork_prior_to_exec,
449 (int (*) (void))
450 return_zero);
451 de_fault (to_post_follow_vfork,
452 (void (*) (int, int, int, int))
453 target_ignore);
454 de_fault (to_insert_exec_catchpoint,
455 (int (*) (int))
456 tcomplain);
457 de_fault (to_remove_exec_catchpoint,
458 (int (*) (int))
459 tcomplain);
460 de_fault (to_has_execd,
461 (int (*) (int, char **))
462 return_zero);
463 de_fault (to_reported_exec_events_per_exec_call,
464 (int (*) (void))
465 return_one);
466 de_fault (to_has_syscall_event,
467 (int (*) (int, enum target_waitkind *, int *))
468 return_zero);
469 de_fault (to_has_exited,
470 (int (*) (int, int, int *))
471 return_zero);
472 de_fault (to_mourn_inferior,
473 (void (*) (void))
474 noprocess);
475 de_fault (to_can_run,
476 return_zero);
477 de_fault (to_notice_signals,
478 (void (*) (int))
479 target_ignore);
480 de_fault (to_thread_alive,
481 (int (*) (int))
482 return_zero);
483 de_fault (to_find_new_threads,
484 (void (*) (void))
485 target_ignore);
486 de_fault (to_extra_thread_info,
487 (char *(*) (struct thread_info *))
488 return_zero);
489 de_fault (to_stop,
490 (void (*) (void))
491 target_ignore);
492 de_fault (to_query,
493 (int (*) (int, char *, char *, int *))
494 return_zero);
495 de_fault (to_rcmd,
496 (void (*) (char *, struct ui_file *))
497 tcomplain);
498 de_fault (to_enable_exception_callback,
499 (struct symtab_and_line * (*) (enum exception_event_kind, int))
500 nosupport_runtime);
501 de_fault (to_get_current_exception_event,
502 (struct exception_event_record * (*) (void))
503 nosupport_runtime);
504 de_fault (to_pid_to_exec_file,
505 (char *(*) (int))
506 return_zero);
507 de_fault (to_core_file_to_sym_file,
508 (char *(*) (char *))
509 return_zero);
510 de_fault (to_can_async_p,
511 (int (*) (void))
512 return_zero);
513 de_fault (to_is_async_p,
514 (int (*) (void))
515 return_zero);
516 de_fault (to_async,
517 (void (*) (void (*) (enum inferior_event_type, void*), void*))
518 tcomplain);
519 #undef de_fault
520 }
521
522 /* Go through the target stack from top to bottom, copying over zero entries in
523 current_target. In effect, we are doing class inheritance through the
524 pushed target vectors. */
525
526 static void
527 update_current_target (void)
528 {
529 struct target_stack_item *item;
530 struct target_ops *t;
531
532 /* First, reset current_target */
533 memset (&current_target, 0, sizeof current_target);
534
535 for (item = target_stack; item; item = item->next)
536 {
537 t = item->target_ops;
538
539 #define INHERIT(FIELD, TARGET) \
540 if (!current_target.FIELD) \
541 current_target.FIELD = TARGET->FIELD
542
543 INHERIT (to_shortname, t);
544 INHERIT (to_longname, t);
545 INHERIT (to_doc, t);
546 INHERIT (to_open, t);
547 INHERIT (to_close, t);
548 INHERIT (to_attach, t);
549 INHERIT (to_post_attach, t);
550 INHERIT (to_require_attach, t);
551 INHERIT (to_detach, t);
552 INHERIT (to_require_detach, t);
553 INHERIT (to_resume, t);
554 INHERIT (to_wait, t);
555 INHERIT (to_post_wait, t);
556 INHERIT (to_fetch_registers, t);
557 INHERIT (to_store_registers, t);
558 INHERIT (to_prepare_to_store, t);
559 INHERIT (to_xfer_memory, t);
560 INHERIT (to_files_info, t);
561 INHERIT (to_insert_breakpoint, t);
562 INHERIT (to_remove_breakpoint, t);
563 INHERIT (to_terminal_init, t);
564 INHERIT (to_terminal_inferior, t);
565 INHERIT (to_terminal_ours_for_output, t);
566 INHERIT (to_terminal_ours, t);
567 INHERIT (to_terminal_info, t);
568 INHERIT (to_kill, t);
569 INHERIT (to_load, t);
570 INHERIT (to_lookup_symbol, t);
571 INHERIT (to_create_inferior, t);
572 INHERIT (to_post_startup_inferior, t);
573 INHERIT (to_acknowledge_created_inferior, t);
574 INHERIT (to_clone_and_follow_inferior, t);
575 INHERIT (to_post_follow_inferior_by_clone, t);
576 INHERIT (to_insert_fork_catchpoint, t);
577 INHERIT (to_remove_fork_catchpoint, t);
578 INHERIT (to_insert_vfork_catchpoint, t);
579 INHERIT (to_remove_vfork_catchpoint, t);
580 INHERIT (to_has_forked, t);
581 INHERIT (to_has_vforked, t);
582 INHERIT (to_can_follow_vfork_prior_to_exec, t);
583 INHERIT (to_post_follow_vfork, t);
584 INHERIT (to_insert_exec_catchpoint, t);
585 INHERIT (to_remove_exec_catchpoint, t);
586 INHERIT (to_has_execd, t);
587 INHERIT (to_reported_exec_events_per_exec_call, t);
588 INHERIT (to_has_syscall_event, t);
589 INHERIT (to_has_exited, t);
590 INHERIT (to_mourn_inferior, t);
591 INHERIT (to_can_run, t);
592 INHERIT (to_notice_signals, t);
593 INHERIT (to_thread_alive, t);
594 INHERIT (to_find_new_threads, t);
595 INHERIT (to_pid_to_str, t);
596 INHERIT (to_extra_thread_info, t);
597 INHERIT (to_stop, t);
598 INHERIT (to_query, t);
599 INHERIT (to_rcmd, t);
600 INHERIT (to_enable_exception_callback, t);
601 INHERIT (to_get_current_exception_event, t);
602 INHERIT (to_pid_to_exec_file, t);
603 INHERIT (to_core_file_to_sym_file, t);
604 INHERIT (to_stratum, t);
605 INHERIT (DONT_USE, t);
606 INHERIT (to_has_all_memory, t);
607 INHERIT (to_has_memory, t);
608 INHERIT (to_has_stack, t);
609 INHERIT (to_has_registers, t);
610 INHERIT (to_has_execution, t);
611 INHERIT (to_has_thread_control, t);
612 INHERIT (to_sections, t);
613 INHERIT (to_sections_end, t);
614 INHERIT (to_can_async_p, t);
615 INHERIT (to_is_async_p, t);
616 INHERIT (to_async, t);
617 INHERIT (to_async_mask_value, t);
618 INHERIT (to_magic, t);
619
620 #undef INHERIT
621 }
622 }
623
624 /* Push a new target type into the stack of the existing target accessors,
625 possibly superseding some of the existing accessors.
626
627 Result is zero if the pushed target ended up on top of the stack,
628 nonzero if at least one target is on top of it.
629
630 Rather than allow an empty stack, we always have the dummy target at
631 the bottom stratum, so we can call the function vectors without
632 checking them. */
633
634 int
635 push_target (struct target_ops *t)
636 {
637 struct target_stack_item *cur, *prev, *tmp;
638
639 /* Check magic number. If wrong, it probably means someone changed
640 the struct definition, but not all the places that initialize one. */
641 if (t->to_magic != OPS_MAGIC)
642 {
643 fprintf_unfiltered (gdb_stderr,
644 "Magic number of %s target struct wrong\n",
645 t->to_shortname);
646 internal_error (__FILE__, __LINE__, "failed internal consistency check");
647 }
648
649 /* Find the proper stratum to install this target in. */
650
651 for (prev = NULL, cur = target_stack; cur; prev = cur, cur = cur->next)
652 {
653 if ((int) (t->to_stratum) >= (int) (cur->target_ops->to_stratum))
654 break;
655 }
656
657 /* If there's already targets at this stratum, remove them. */
658
659 if (cur)
660 while (t->to_stratum == cur->target_ops->to_stratum)
661 {
662 /* There's already something on this stratum. Close it off. */
663 if (cur->target_ops->to_close)
664 (cur->target_ops->to_close) (0);
665 if (prev)
666 prev->next = cur->next; /* Unchain old target_ops */
667 else
668 target_stack = cur->next; /* Unchain first on list */
669 tmp = cur->next;
670 xfree (cur);
671 cur = tmp;
672 }
673
674 /* We have removed all targets in our stratum, now add the new one. */
675
676 tmp = (struct target_stack_item *)
677 xmalloc (sizeof (struct target_stack_item));
678 tmp->next = cur;
679 tmp->target_ops = t;
680
681 if (prev)
682 prev->next = tmp;
683 else
684 target_stack = tmp;
685
686 update_current_target ();
687
688 cleanup_target (&current_target); /* Fill in the gaps */
689
690 if (targetdebug)
691 setup_target_debug ();
692
693 return prev != 0;
694 }
695
696 /* Remove a target_ops vector from the stack, wherever it may be.
697 Return how many times it was removed (0 or 1). */
698
699 int
700 unpush_target (struct target_ops *t)
701 {
702 struct target_stack_item *cur, *prev;
703
704 if (t->to_close)
705 t->to_close (0); /* Let it clean up */
706
707 /* Look for the specified target. Note that we assume that a target
708 can only occur once in the target stack. */
709
710 for (cur = target_stack, prev = NULL; cur; prev = cur, cur = cur->next)
711 if (cur->target_ops == t)
712 break;
713
714 if (!cur)
715 return 0; /* Didn't find target_ops, quit now */
716
717 /* Unchain the target */
718
719 if (!prev)
720 target_stack = cur->next;
721 else
722 prev->next = cur->next;
723
724 xfree (cur); /* Release the target_stack_item */
725
726 update_current_target ();
727 cleanup_target (&current_target);
728
729 return 1;
730 }
731
732 void
733 pop_target (void)
734 {
735 (current_target.to_close) (0); /* Let it clean up */
736 if (unpush_target (target_stack->target_ops) == 1)
737 return;
738
739 fprintf_unfiltered (gdb_stderr,
740 "pop_target couldn't find target %s\n",
741 current_target.to_shortname);
742 internal_error (__FILE__, __LINE__, "failed internal consistency check");
743 }
744
745 #undef MIN
746 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
747
748 /* target_read_string -- read a null terminated string, up to LEN bytes,
749 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
750 Set *STRING to a pointer to malloc'd memory containing the data; the caller
751 is responsible for freeing it. Return the number of bytes successfully
752 read. */
753
754 int
755 target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop)
756 {
757 int tlen, origlen, offset, i;
758 char buf[4];
759 int errcode = 0;
760 char *buffer;
761 int buffer_allocated;
762 char *bufptr;
763 unsigned int nbytes_read = 0;
764
765 /* Small for testing. */
766 buffer_allocated = 4;
767 buffer = xmalloc (buffer_allocated);
768 bufptr = buffer;
769
770 origlen = len;
771
772 while (len > 0)
773 {
774 tlen = MIN (len, 4 - (memaddr & 3));
775 offset = memaddr & 3;
776
777 errcode = target_xfer_memory (memaddr & ~3, buf, 4, 0);
778 if (errcode != 0)
779 {
780 /* The transfer request might have crossed the boundary to an
781 unallocated region of memory. Retry the transfer, requesting
782 a single byte. */
783 tlen = 1;
784 offset = 0;
785 errcode = target_xfer_memory (memaddr, buf, 1, 0);
786 if (errcode != 0)
787 goto done;
788 }
789
790 if (bufptr - buffer + tlen > buffer_allocated)
791 {
792 unsigned int bytes;
793 bytes = bufptr - buffer;
794 buffer_allocated *= 2;
795 buffer = xrealloc (buffer, buffer_allocated);
796 bufptr = buffer + bytes;
797 }
798
799 for (i = 0; i < tlen; i++)
800 {
801 *bufptr++ = buf[i + offset];
802 if (buf[i + offset] == '\000')
803 {
804 nbytes_read += i + 1;
805 goto done;
806 }
807 }
808
809 memaddr += tlen;
810 len -= tlen;
811 nbytes_read += tlen;
812 }
813 done:
814 if (errnop != NULL)
815 *errnop = errcode;
816 if (string != NULL)
817 *string = buffer;
818 return nbytes_read;
819 }
820
821 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
822 GDB's memory at MYADDR. Returns either 0 for success or an errno value
823 if any error occurs.
824
825 If an error occurs, no guarantee is made about the contents of the data at
826 MYADDR. In particular, the caller should not depend upon partial reads
827 filling the buffer with good data. There is no way for the caller to know
828 how much good data might have been transfered anyway. Callers that can
829 deal with partial reads should call target_read_memory_partial. */
830
831 int
832 target_read_memory (CORE_ADDR memaddr, char *myaddr, int len)
833 {
834 return target_xfer_memory (memaddr, myaddr, len, 0);
835 }
836
837 int
838 target_write_memory (CORE_ADDR memaddr, char *myaddr, int len)
839 {
840 return target_xfer_memory (memaddr, myaddr, len, 1);
841 }
842
843 /* Move memory to or from the targets. The top target gets priority;
844 if it cannot handle it, it is offered to the next one down, etc.
845
846 Result is -1 on error, or the number of bytes transfered. */
847
848 int
849 do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
850 struct mem_attrib *attrib)
851 {
852 int res;
853 int done = 0;
854 struct target_ops *t;
855 struct target_stack_item *item;
856
857 /* Zero length requests are ok and require no work. */
858 if (len == 0)
859 return 0;
860
861 /* to_xfer_memory is not guaranteed to set errno, even when it returns
862 0. */
863 errno = 0;
864
865 /* The quick case is that the top target can handle the transfer. */
866 res = current_target.to_xfer_memory
867 (memaddr, myaddr, len, write, attrib, &current_target);
868
869 /* If res <= 0 then we call it again in the loop. Ah well. */
870 if (res <= 0)
871 {
872 for (item = target_stack; item; item = item->next)
873 {
874 t = item->target_ops;
875 if (!t->to_has_memory)
876 continue;
877
878 res = t->to_xfer_memory (memaddr, myaddr, len, write, attrib, t);
879 if (res > 0)
880 break; /* Handled all or part of xfer */
881 if (t->to_has_all_memory)
882 break;
883 }
884
885 if (res <= 0)
886 return -1;
887 }
888
889 return res;
890 }
891
892
893 /* Perform a memory transfer. Iterate until the entire region has
894 been transfered.
895
896 Result is 0 or errno value. */
897
898 static int
899 target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write)
900 {
901 int res;
902 int reg_len;
903 struct mem_region *region;
904
905 /* Zero length requests are ok and require no work. */
906 if (len == 0)
907 {
908 return 0;
909 }
910
911 while (len > 0)
912 {
913 region = lookup_mem_region(memaddr);
914 if (memaddr + len < region->hi)
915 reg_len = len;
916 else
917 reg_len = region->hi - memaddr;
918
919 switch (region->attrib.mode)
920 {
921 case MEM_RO:
922 if (write)
923 return EIO;
924 break;
925
926 case MEM_WO:
927 if (!write)
928 return EIO;
929 break;
930 }
931
932 while (reg_len > 0)
933 {
934 if (region->attrib.cache)
935 res = dcache_xfer_memory(target_dcache, memaddr, myaddr,
936 reg_len, write);
937 else
938 res = do_xfer_memory(memaddr, myaddr, reg_len, write,
939 &region->attrib);
940
941 if (res <= 0)
942 {
943 /* If this address is for nonexistent memory, read zeros
944 if reading, or do nothing if writing. Return
945 error. */
946 if (!write)
947 memset (myaddr, 0, len);
948 if (errno == 0)
949 return EIO;
950 else
951 return errno;
952 }
953
954 memaddr += res;
955 myaddr += res;
956 len -= res;
957 reg_len -= res;
958 }
959 }
960
961 return 0; /* We managed to cover it all somehow. */
962 }
963
964
965 /* Perform a partial memory transfer.
966
967 Result is -1 on error, or the number of bytes transfered. */
968
969 static int
970 target_xfer_memory_partial (CORE_ADDR memaddr, char *myaddr, int len,
971 int write_p, int *err)
972 {
973 int res;
974 int reg_len;
975 struct mem_region *region;
976
977 /* Zero length requests are ok and require no work. */
978 if (len == 0)
979 {
980 *err = 0;
981 return 0;
982 }
983
984 region = lookup_mem_region(memaddr);
985 if (memaddr + len < region->hi)
986 reg_len = len;
987 else
988 reg_len = region->hi - memaddr;
989
990 switch (region->attrib.mode)
991 {
992 case MEM_RO:
993 if (write_p)
994 {
995 *err = EIO;
996 return -1;
997 }
998 break;
999
1000 case MEM_WO:
1001 if (write_p)
1002 {
1003 *err = EIO;
1004 return -1;
1005 }
1006 break;
1007 }
1008
1009 if (region->attrib.cache)
1010 res = dcache_xfer_memory (target_dcache, memaddr, myaddr,
1011 reg_len, write_p);
1012 else
1013 res = do_xfer_memory (memaddr, myaddr, reg_len, write_p,
1014 &region->attrib);
1015
1016 if (res <= 0)
1017 {
1018 if (errno != 0)
1019 *err = errno;
1020 else
1021 *err = EIO;
1022
1023 return -1;
1024 }
1025
1026 *err = 0;
1027 return res;
1028 }
1029
1030 int
1031 target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1032 {
1033 return target_xfer_memory_partial (memaddr, buf, len, 0, err);
1034 }
1035
1036 int
1037 target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1038 {
1039 return target_xfer_memory_partial (memaddr, buf, len, 1, err);
1040 }
1041
1042 /* ARGSUSED */
1043 static void
1044 target_info (char *args, int from_tty)
1045 {
1046 struct target_ops *t;
1047 struct target_stack_item *item;
1048 int has_all_mem = 0;
1049
1050 if (symfile_objfile != NULL)
1051 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile->name);
1052
1053 #ifdef FILES_INFO_HOOK
1054 if (FILES_INFO_HOOK ())
1055 return;
1056 #endif
1057
1058 for (item = target_stack; item; item = item->next)
1059 {
1060 t = item->target_ops;
1061
1062 if (!t->to_has_memory)
1063 continue;
1064
1065 if ((int) (t->to_stratum) <= (int) dummy_stratum)
1066 continue;
1067 if (has_all_mem)
1068 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1069 printf_unfiltered ("%s:\n", t->to_longname);
1070 (t->to_files_info) (t);
1071 has_all_mem = t->to_has_all_memory;
1072 }
1073 }
1074
1075 /* This is to be called by the open routine before it does
1076 anything. */
1077
1078 void
1079 target_preopen (int from_tty)
1080 {
1081 dont_repeat ();
1082
1083 if (target_has_execution)
1084 {
1085 if (!from_tty
1086 || query ("A program is being debugged already. Kill it? "))
1087 target_kill ();
1088 else
1089 error ("Program not killed.");
1090 }
1091
1092 /* Calling target_kill may remove the target from the stack. But if
1093 it doesn't (which seems like a win for UDI), remove it now. */
1094
1095 if (target_has_execution)
1096 pop_target ();
1097 }
1098
1099 /* Detach a target after doing deferred register stores. */
1100
1101 void
1102 target_detach (char *args, int from_tty)
1103 {
1104 /* Handle any optimized stores to the inferior. */
1105 #ifdef DO_DEFERRED_STORES
1106 DO_DEFERRED_STORES;
1107 #endif
1108 (current_target.to_detach) (args, from_tty);
1109 }
1110
1111 void
1112 target_link (char *modname, CORE_ADDR *t_reloc)
1113 {
1114 if (STREQ (current_target.to_shortname, "rombug"))
1115 {
1116 (current_target.to_lookup_symbol) (modname, t_reloc);
1117 if (*t_reloc == 0)
1118 error ("Unable to link to %s and get relocation in rombug", modname);
1119 }
1120 else
1121 *t_reloc = (CORE_ADDR) -1;
1122 }
1123
1124 int
1125 target_async_mask (int mask)
1126 {
1127 int saved_async_masked_status = target_async_mask_value;
1128 target_async_mask_value = mask;
1129 return saved_async_masked_status;
1130 }
1131
1132 /* Look through the list of possible targets for a target that can
1133 execute a run or attach command without any other data. This is
1134 used to locate the default process stratum.
1135
1136 Result is always valid (error() is called for errors). */
1137
1138 static struct target_ops *
1139 find_default_run_target (char *do_mesg)
1140 {
1141 struct target_ops **t;
1142 struct target_ops *runable = NULL;
1143 int count;
1144
1145 count = 0;
1146
1147 for (t = target_structs; t < target_structs + target_struct_size;
1148 ++t)
1149 {
1150 if ((*t)->to_can_run && target_can_run (*t))
1151 {
1152 runable = *t;
1153 ++count;
1154 }
1155 }
1156
1157 if (count != 1)
1158 error ("Don't know how to %s. Try \"help target\".", do_mesg);
1159
1160 return runable;
1161 }
1162
1163 void
1164 find_default_attach (char *args, int from_tty)
1165 {
1166 struct target_ops *t;
1167
1168 t = find_default_run_target ("attach");
1169 (t->to_attach) (args, from_tty);
1170 return;
1171 }
1172
1173 void
1174 find_default_require_attach (char *args, int from_tty)
1175 {
1176 struct target_ops *t;
1177
1178 t = find_default_run_target ("require_attach");
1179 (t->to_require_attach) (args, from_tty);
1180 return;
1181 }
1182
1183 void
1184 find_default_require_detach (int pid, char *args, int from_tty)
1185 {
1186 struct target_ops *t;
1187
1188 t = find_default_run_target ("require_detach");
1189 (t->to_require_detach) (pid, args, from_tty);
1190 return;
1191 }
1192
1193 void
1194 find_default_create_inferior (char *exec_file, char *allargs, char **env)
1195 {
1196 struct target_ops *t;
1197
1198 t = find_default_run_target ("run");
1199 (t->to_create_inferior) (exec_file, allargs, env);
1200 return;
1201 }
1202
1203 void
1204 find_default_clone_and_follow_inferior (int child_pid, int *followed_child)
1205 {
1206 struct target_ops *t;
1207
1208 t = find_default_run_target ("run");
1209 (t->to_clone_and_follow_inferior) (child_pid, followed_child);
1210 return;
1211 }
1212
1213 static int
1214 return_zero (void)
1215 {
1216 return 0;
1217 }
1218
1219 static int
1220 return_one (void)
1221 {
1222 return 1;
1223 }
1224
1225 /*
1226 * Resize the to_sections pointer. Also make sure that anyone that
1227 * was holding on to an old value of it gets updated.
1228 * Returns the old size.
1229 */
1230
1231 int
1232 target_resize_to_sections (struct target_ops *target, int num_added)
1233 {
1234 struct target_ops **t;
1235 struct section_table *old_value;
1236 int old_count;
1237
1238 old_value = target->to_sections;
1239
1240 if (target->to_sections)
1241 {
1242 old_count = target->to_sections_end - target->to_sections;
1243 target->to_sections = (struct section_table *)
1244 xrealloc ((char *) target->to_sections,
1245 (sizeof (struct section_table)) * (num_added + old_count));
1246 }
1247 else
1248 {
1249 old_count = 0;
1250 target->to_sections = (struct section_table *)
1251 xmalloc ((sizeof (struct section_table)) * num_added);
1252 }
1253 target->to_sections_end = target->to_sections + (num_added + old_count);
1254
1255 /* Check to see if anyone else was pointing to this structure.
1256 If old_value was null, then no one was. */
1257
1258 if (old_value)
1259 {
1260 for (t = target_structs; t < target_structs + target_struct_size;
1261 ++t)
1262 {
1263 if ((*t)->to_sections == old_value)
1264 {
1265 (*t)->to_sections = target->to_sections;
1266 (*t)->to_sections_end = target->to_sections_end;
1267 }
1268 }
1269 }
1270
1271 return old_count;
1272
1273 }
1274
1275 /* Remove all target sections taken from ABFD.
1276
1277 Scan the current target stack for targets whose section tables
1278 refer to sections from BFD, and remove those sections. We use this
1279 when we notice that the inferior has unloaded a shared object, for
1280 example. */
1281 void
1282 remove_target_sections (bfd *abfd)
1283 {
1284 struct target_ops **t;
1285
1286 for (t = target_structs; t < target_structs + target_struct_size; t++)
1287 {
1288 struct section_table *src, *dest;
1289
1290 dest = (*t)->to_sections;
1291 for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++)
1292 if (src->bfd != abfd)
1293 {
1294 /* Keep this section. */
1295 if (dest < src) *dest = *src;
1296 dest++;
1297 }
1298
1299 /* If we've dropped any sections, resize the section table. */
1300 if (dest < src)
1301 target_resize_to_sections (*t, dest - src);
1302 }
1303 }
1304
1305
1306
1307
1308 /* Find a single runnable target in the stack and return it. If for
1309 some reason there is more than one, return NULL. */
1310
1311 struct target_ops *
1312 find_run_target (void)
1313 {
1314 struct target_ops **t;
1315 struct target_ops *runable = NULL;
1316 int count;
1317
1318 count = 0;
1319
1320 for (t = target_structs; t < target_structs + target_struct_size; ++t)
1321 {
1322 if ((*t)->to_can_run && target_can_run (*t))
1323 {
1324 runable = *t;
1325 ++count;
1326 }
1327 }
1328
1329 return (count == 1 ? runable : NULL);
1330 }
1331
1332 /* Find a single core_stratum target in the list of targets and return it.
1333 If for some reason there is more than one, return NULL. */
1334
1335 struct target_ops *
1336 find_core_target (void)
1337 {
1338 struct target_ops **t;
1339 struct target_ops *runable = NULL;
1340 int count;
1341
1342 count = 0;
1343
1344 for (t = target_structs; t < target_structs + target_struct_size;
1345 ++t)
1346 {
1347 if ((*t)->to_stratum == core_stratum)
1348 {
1349 runable = *t;
1350 ++count;
1351 }
1352 }
1353
1354 return (count == 1 ? runable : NULL);
1355 }
1356
1357 /*
1358 * Find the next target down the stack from the specified target.
1359 */
1360
1361 struct target_ops *
1362 find_target_beneath (struct target_ops *t)
1363 {
1364 struct target_stack_item *cur;
1365
1366 for (cur = target_stack; cur; cur = cur->next)
1367 if (cur->target_ops == t)
1368 break;
1369
1370 if (cur == NULL || cur->next == NULL)
1371 return NULL;
1372 else
1373 return cur->next->target_ops;
1374 }
1375
1376 \f
1377 /* The inferior process has died. Long live the inferior! */
1378
1379 void
1380 generic_mourn_inferior (void)
1381 {
1382 extern int show_breakpoint_hit_counts;
1383
1384 inferior_pid = 0;
1385 attach_flag = 0;
1386 breakpoint_init_inferior (inf_exited);
1387 registers_changed ();
1388
1389 #ifdef CLEAR_DEFERRED_STORES
1390 /* Delete any pending stores to the inferior... */
1391 CLEAR_DEFERRED_STORES;
1392 #endif
1393
1394 reopen_exec_file ();
1395 reinit_frame_cache ();
1396
1397 /* It is confusing to the user for ignore counts to stick around
1398 from previous runs of the inferior. So clear them. */
1399 /* However, it is more confusing for the ignore counts to disappear when
1400 using hit counts. So don't clear them if we're counting hits. */
1401 if (!show_breakpoint_hit_counts)
1402 breakpoint_clear_ignore_counts ();
1403
1404 if (detach_hook)
1405 detach_hook ();
1406 }
1407 \f
1408 /* This table must match in order and size the signals in enum target_signal
1409 in target.h. */
1410 /* *INDENT-OFF* */
1411 static struct {
1412 char *name;
1413 char *string;
1414 } signals [] =
1415 {
1416 {"0", "Signal 0"},
1417 {"SIGHUP", "Hangup"},
1418 {"SIGINT", "Interrupt"},
1419 {"SIGQUIT", "Quit"},
1420 {"SIGILL", "Illegal instruction"},
1421 {"SIGTRAP", "Trace/breakpoint trap"},
1422 {"SIGABRT", "Aborted"},
1423 {"SIGEMT", "Emulation trap"},
1424 {"SIGFPE", "Arithmetic exception"},
1425 {"SIGKILL", "Killed"},
1426 {"SIGBUS", "Bus error"},
1427 {"SIGSEGV", "Segmentation fault"},
1428 {"SIGSYS", "Bad system call"},
1429 {"SIGPIPE", "Broken pipe"},
1430 {"SIGALRM", "Alarm clock"},
1431 {"SIGTERM", "Terminated"},
1432 {"SIGURG", "Urgent I/O condition"},
1433 {"SIGSTOP", "Stopped (signal)"},
1434 {"SIGTSTP", "Stopped (user)"},
1435 {"SIGCONT", "Continued"},
1436 {"SIGCHLD", "Child status changed"},
1437 {"SIGTTIN", "Stopped (tty input)"},
1438 {"SIGTTOU", "Stopped (tty output)"},
1439 {"SIGIO", "I/O possible"},
1440 {"SIGXCPU", "CPU time limit exceeded"},
1441 {"SIGXFSZ", "File size limit exceeded"},
1442 {"SIGVTALRM", "Virtual timer expired"},
1443 {"SIGPROF", "Profiling timer expired"},
1444 {"SIGWINCH", "Window size changed"},
1445 {"SIGLOST", "Resource lost"},
1446 {"SIGUSR1", "User defined signal 1"},
1447 {"SIGUSR2", "User defined signal 2"},
1448 {"SIGPWR", "Power fail/restart"},
1449 {"SIGPOLL", "Pollable event occurred"},
1450 {"SIGWIND", "SIGWIND"},
1451 {"SIGPHONE", "SIGPHONE"},
1452 {"SIGWAITING", "Process's LWPs are blocked"},
1453 {"SIGLWP", "Signal LWP"},
1454 {"SIGDANGER", "Swap space dangerously low"},
1455 {"SIGGRANT", "Monitor mode granted"},
1456 {"SIGRETRACT", "Need to relinquish monitor mode"},
1457 {"SIGMSG", "Monitor mode data available"},
1458 {"SIGSOUND", "Sound completed"},
1459 {"SIGSAK", "Secure attention"},
1460 {"SIGPRIO", "SIGPRIO"},
1461 {"SIG33", "Real-time event 33"},
1462 {"SIG34", "Real-time event 34"},
1463 {"SIG35", "Real-time event 35"},
1464 {"SIG36", "Real-time event 36"},
1465 {"SIG37", "Real-time event 37"},
1466 {"SIG38", "Real-time event 38"},
1467 {"SIG39", "Real-time event 39"},
1468 {"SIG40", "Real-time event 40"},
1469 {"SIG41", "Real-time event 41"},
1470 {"SIG42", "Real-time event 42"},
1471 {"SIG43", "Real-time event 43"},
1472 {"SIG44", "Real-time event 44"},
1473 {"SIG45", "Real-time event 45"},
1474 {"SIG46", "Real-time event 46"},
1475 {"SIG47", "Real-time event 47"},
1476 {"SIG48", "Real-time event 48"},
1477 {"SIG49", "Real-time event 49"},
1478 {"SIG50", "Real-time event 50"},
1479 {"SIG51", "Real-time event 51"},
1480 {"SIG52", "Real-time event 52"},
1481 {"SIG53", "Real-time event 53"},
1482 {"SIG54", "Real-time event 54"},
1483 {"SIG55", "Real-time event 55"},
1484 {"SIG56", "Real-time event 56"},
1485 {"SIG57", "Real-time event 57"},
1486 {"SIG58", "Real-time event 58"},
1487 {"SIG59", "Real-time event 59"},
1488 {"SIG60", "Real-time event 60"},
1489 {"SIG61", "Real-time event 61"},
1490 {"SIG62", "Real-time event 62"},
1491 {"SIG63", "Real-time event 63"},
1492 {"SIGCANCEL", "LWP internal signal"},
1493 {"SIG32", "Real-time event 32"},
1494 {"SIG64", "Real-time event 64"},
1495
1496 #if defined(MACH) || defined(__MACH__)
1497 /* Mach exceptions */
1498 {"EXC_BAD_ACCESS", "Could not access memory"},
1499 {"EXC_BAD_INSTRUCTION", "Illegal instruction/operand"},
1500 {"EXC_ARITHMETIC", "Arithmetic exception"},
1501 {"EXC_EMULATION", "Emulation instruction"},
1502 {"EXC_SOFTWARE", "Software generated exception"},
1503 {"EXC_BREAKPOINT", "Breakpoint"},
1504 #endif
1505 {"SIGINFO", "Information request"},
1506
1507 {NULL, "Unknown signal"},
1508 {NULL, "Internal error: printing TARGET_SIGNAL_DEFAULT"},
1509
1510 /* Last entry, used to check whether the table is the right size. */
1511 {NULL, "TARGET_SIGNAL_MAGIC"}
1512 };
1513 /* *INDENT-ON* */
1514
1515
1516
1517 /* Return the string for a signal. */
1518 char *
1519 target_signal_to_string (enum target_signal sig)
1520 {
1521 if ((sig >= TARGET_SIGNAL_FIRST) && (sig <= TARGET_SIGNAL_LAST))
1522 return signals[sig].string;
1523 else
1524 return signals[TARGET_SIGNAL_UNKNOWN].string;
1525 }
1526
1527 /* Return the name for a signal. */
1528 char *
1529 target_signal_to_name (enum target_signal sig)
1530 {
1531 if (sig == TARGET_SIGNAL_UNKNOWN)
1532 /* I think the code which prints this will always print it along with
1533 the string, so no need to be verbose. */
1534 return "?";
1535 return signals[sig].name;
1536 }
1537
1538 /* Given a name, return its signal. */
1539 enum target_signal
1540 target_signal_from_name (char *name)
1541 {
1542 enum target_signal sig;
1543
1544 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
1545 for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
1546 questionable; seems like by now people should call it SIGABRT
1547 instead. */
1548
1549 /* This ugly cast brought to you by the native VAX compiler. */
1550 for (sig = TARGET_SIGNAL_HUP;
1551 signals[sig].name != NULL;
1552 sig = (enum target_signal) ((int) sig + 1))
1553 if (STREQ (name, signals[sig].name))
1554 return sig;
1555 return TARGET_SIGNAL_UNKNOWN;
1556 }
1557 \f
1558 /* The following functions are to help certain targets deal
1559 with the signal/waitstatus stuff. They could just as well be in
1560 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */
1561
1562 /* Convert host signal to our signals. */
1563 enum target_signal
1564 target_signal_from_host (int hostsig)
1565 {
1566 /* A switch statement would make sense but would require special kludges
1567 to deal with the cases where more than one signal has the same number. */
1568
1569 if (hostsig == 0)
1570 return TARGET_SIGNAL_0;
1571
1572 #if defined (SIGHUP)
1573 if (hostsig == SIGHUP)
1574 return TARGET_SIGNAL_HUP;
1575 #endif
1576 #if defined (SIGINT)
1577 if (hostsig == SIGINT)
1578 return TARGET_SIGNAL_INT;
1579 #endif
1580 #if defined (SIGQUIT)
1581 if (hostsig == SIGQUIT)
1582 return TARGET_SIGNAL_QUIT;
1583 #endif
1584 #if defined (SIGILL)
1585 if (hostsig == SIGILL)
1586 return TARGET_SIGNAL_ILL;
1587 #endif
1588 #if defined (SIGTRAP)
1589 if (hostsig == SIGTRAP)
1590 return TARGET_SIGNAL_TRAP;
1591 #endif
1592 #if defined (SIGABRT)
1593 if (hostsig == SIGABRT)
1594 return TARGET_SIGNAL_ABRT;
1595 #endif
1596 #if defined (SIGEMT)
1597 if (hostsig == SIGEMT)
1598 return TARGET_SIGNAL_EMT;
1599 #endif
1600 #if defined (SIGFPE)
1601 if (hostsig == SIGFPE)
1602 return TARGET_SIGNAL_FPE;
1603 #endif
1604 #if defined (SIGKILL)
1605 if (hostsig == SIGKILL)
1606 return TARGET_SIGNAL_KILL;
1607 #endif
1608 #if defined (SIGBUS)
1609 if (hostsig == SIGBUS)
1610 return TARGET_SIGNAL_BUS;
1611 #endif
1612 #if defined (SIGSEGV)
1613 if (hostsig == SIGSEGV)
1614 return TARGET_SIGNAL_SEGV;
1615 #endif
1616 #if defined (SIGSYS)
1617 if (hostsig == SIGSYS)
1618 return TARGET_SIGNAL_SYS;
1619 #endif
1620 #if defined (SIGPIPE)
1621 if (hostsig == SIGPIPE)
1622 return TARGET_SIGNAL_PIPE;
1623 #endif
1624 #if defined (SIGALRM)
1625 if (hostsig == SIGALRM)
1626 return TARGET_SIGNAL_ALRM;
1627 #endif
1628 #if defined (SIGTERM)
1629 if (hostsig == SIGTERM)
1630 return TARGET_SIGNAL_TERM;
1631 #endif
1632 #if defined (SIGUSR1)
1633 if (hostsig == SIGUSR1)
1634 return TARGET_SIGNAL_USR1;
1635 #endif
1636 #if defined (SIGUSR2)
1637 if (hostsig == SIGUSR2)
1638 return TARGET_SIGNAL_USR2;
1639 #endif
1640 #if defined (SIGCLD)
1641 if (hostsig == SIGCLD)
1642 return TARGET_SIGNAL_CHLD;
1643 #endif
1644 #if defined (SIGCHLD)
1645 if (hostsig == SIGCHLD)
1646 return TARGET_SIGNAL_CHLD;
1647 #endif
1648 #if defined (SIGPWR)
1649 if (hostsig == SIGPWR)
1650 return TARGET_SIGNAL_PWR;
1651 #endif
1652 #if defined (SIGWINCH)
1653 if (hostsig == SIGWINCH)
1654 return TARGET_SIGNAL_WINCH;
1655 #endif
1656 #if defined (SIGURG)
1657 if (hostsig == SIGURG)
1658 return TARGET_SIGNAL_URG;
1659 #endif
1660 #if defined (SIGIO)
1661 if (hostsig == SIGIO)
1662 return TARGET_SIGNAL_IO;
1663 #endif
1664 #if defined (SIGPOLL)
1665 if (hostsig == SIGPOLL)
1666 return TARGET_SIGNAL_POLL;
1667 #endif
1668 #if defined (SIGSTOP)
1669 if (hostsig == SIGSTOP)
1670 return TARGET_SIGNAL_STOP;
1671 #endif
1672 #if defined (SIGTSTP)
1673 if (hostsig == SIGTSTP)
1674 return TARGET_SIGNAL_TSTP;
1675 #endif
1676 #if defined (SIGCONT)
1677 if (hostsig == SIGCONT)
1678 return TARGET_SIGNAL_CONT;
1679 #endif
1680 #if defined (SIGTTIN)
1681 if (hostsig == SIGTTIN)
1682 return TARGET_SIGNAL_TTIN;
1683 #endif
1684 #if defined (SIGTTOU)
1685 if (hostsig == SIGTTOU)
1686 return TARGET_SIGNAL_TTOU;
1687 #endif
1688 #if defined (SIGVTALRM)
1689 if (hostsig == SIGVTALRM)
1690 return TARGET_SIGNAL_VTALRM;
1691 #endif
1692 #if defined (SIGPROF)
1693 if (hostsig == SIGPROF)
1694 return TARGET_SIGNAL_PROF;
1695 #endif
1696 #if defined (SIGXCPU)
1697 if (hostsig == SIGXCPU)
1698 return TARGET_SIGNAL_XCPU;
1699 #endif
1700 #if defined (SIGXFSZ)
1701 if (hostsig == SIGXFSZ)
1702 return TARGET_SIGNAL_XFSZ;
1703 #endif
1704 #if defined (SIGWIND)
1705 if (hostsig == SIGWIND)
1706 return TARGET_SIGNAL_WIND;
1707 #endif
1708 #if defined (SIGPHONE)
1709 if (hostsig == SIGPHONE)
1710 return TARGET_SIGNAL_PHONE;
1711 #endif
1712 #if defined (SIGLOST)
1713 if (hostsig == SIGLOST)
1714 return TARGET_SIGNAL_LOST;
1715 #endif
1716 #if defined (SIGWAITING)
1717 if (hostsig == SIGWAITING)
1718 return TARGET_SIGNAL_WAITING;
1719 #endif
1720 #if defined (SIGCANCEL)
1721 if (hostsig == SIGCANCEL)
1722 return TARGET_SIGNAL_CANCEL;
1723 #endif
1724 #if defined (SIGLWP)
1725 if (hostsig == SIGLWP)
1726 return TARGET_SIGNAL_LWP;
1727 #endif
1728 #if defined (SIGDANGER)
1729 if (hostsig == SIGDANGER)
1730 return TARGET_SIGNAL_DANGER;
1731 #endif
1732 #if defined (SIGGRANT)
1733 if (hostsig == SIGGRANT)
1734 return TARGET_SIGNAL_GRANT;
1735 #endif
1736 #if defined (SIGRETRACT)
1737 if (hostsig == SIGRETRACT)
1738 return TARGET_SIGNAL_RETRACT;
1739 #endif
1740 #if defined (SIGMSG)
1741 if (hostsig == SIGMSG)
1742 return TARGET_SIGNAL_MSG;
1743 #endif
1744 #if defined (SIGSOUND)
1745 if (hostsig == SIGSOUND)
1746 return TARGET_SIGNAL_SOUND;
1747 #endif
1748 #if defined (SIGSAK)
1749 if (hostsig == SIGSAK)
1750 return TARGET_SIGNAL_SAK;
1751 #endif
1752 #if defined (SIGPRIO)
1753 if (hostsig == SIGPRIO)
1754 return TARGET_SIGNAL_PRIO;
1755 #endif
1756
1757 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
1758 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
1759 if (hostsig == _NSIG + EXC_BAD_ACCESS)
1760 return TARGET_EXC_BAD_ACCESS;
1761 #endif
1762 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
1763 if (hostsig == _NSIG + EXC_BAD_INSTRUCTION)
1764 return TARGET_EXC_BAD_INSTRUCTION;
1765 #endif
1766 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
1767 if (hostsig == _NSIG + EXC_ARITHMETIC)
1768 return TARGET_EXC_ARITHMETIC;
1769 #endif
1770 #if defined (EXC_EMULATION) && defined (_NSIG)
1771 if (hostsig == _NSIG + EXC_EMULATION)
1772 return TARGET_EXC_EMULATION;
1773 #endif
1774 #if defined (EXC_SOFTWARE) && defined (_NSIG)
1775 if (hostsig == _NSIG + EXC_SOFTWARE)
1776 return TARGET_EXC_SOFTWARE;
1777 #endif
1778 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
1779 if (hostsig == _NSIG + EXC_BREAKPOINT)
1780 return TARGET_EXC_BREAKPOINT;
1781 #endif
1782
1783 #if defined (SIGINFO)
1784 if (hostsig == SIGINFO)
1785 return TARGET_SIGNAL_INFO;
1786 #endif
1787
1788 #if defined (REALTIME_LO)
1789 if (hostsig >= REALTIME_LO && hostsig < REALTIME_HI)
1790 {
1791 /* This block of TARGET_SIGNAL_REALTIME value is in order. */
1792 if (33 <= hostsig && hostsig <= 63)
1793 return (enum target_signal)
1794 (hostsig - 33 + (int) TARGET_SIGNAL_REALTIME_33);
1795 else if (hostsig == 32)
1796 return TARGET_SIGNAL_REALTIME_32;
1797 else
1798 error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
1799 }
1800 #endif
1801
1802 #if defined (SIGRTMIN)
1803 if (hostsig >= SIGRTMIN && hostsig <= SIGRTMAX)
1804 {
1805 /* This block of TARGET_SIGNAL_REALTIME value is in order. */
1806 if (33 <= hostsig && hostsig <= 63)
1807 return (enum target_signal)
1808 (hostsig - 33 + (int) TARGET_SIGNAL_REALTIME_33);
1809 else if (hostsig == 64)
1810 return TARGET_SIGNAL_REALTIME_64;
1811 else
1812 error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal");
1813 }
1814 #endif
1815 return TARGET_SIGNAL_UNKNOWN;
1816 }
1817
1818 /* Convert a OURSIG (an enum target_signal) to the form used by the
1819 target operating system (refered to as the ``host'') or zero if the
1820 equivalent host signal is not available. Set/clear OURSIG_OK
1821 accordingly. */
1822
1823 static int
1824 do_target_signal_to_host (enum target_signal oursig,
1825 int *oursig_ok)
1826 {
1827 *oursig_ok = 1;
1828 switch (oursig)
1829 {
1830 case TARGET_SIGNAL_0:
1831 return 0;
1832
1833 #if defined (SIGHUP)
1834 case TARGET_SIGNAL_HUP:
1835 return SIGHUP;
1836 #endif
1837 #if defined (SIGINT)
1838 case TARGET_SIGNAL_INT:
1839 return SIGINT;
1840 #endif
1841 #if defined (SIGQUIT)
1842 case TARGET_SIGNAL_QUIT:
1843 return SIGQUIT;
1844 #endif
1845 #if defined (SIGILL)
1846 case TARGET_SIGNAL_ILL:
1847 return SIGILL;
1848 #endif
1849 #if defined (SIGTRAP)
1850 case TARGET_SIGNAL_TRAP:
1851 return SIGTRAP;
1852 #endif
1853 #if defined (SIGABRT)
1854 case TARGET_SIGNAL_ABRT:
1855 return SIGABRT;
1856 #endif
1857 #if defined (SIGEMT)
1858 case TARGET_SIGNAL_EMT:
1859 return SIGEMT;
1860 #endif
1861 #if defined (SIGFPE)
1862 case TARGET_SIGNAL_FPE:
1863 return SIGFPE;
1864 #endif
1865 #if defined (SIGKILL)
1866 case TARGET_SIGNAL_KILL:
1867 return SIGKILL;
1868 #endif
1869 #if defined (SIGBUS)
1870 case TARGET_SIGNAL_BUS:
1871 return SIGBUS;
1872 #endif
1873 #if defined (SIGSEGV)
1874 case TARGET_SIGNAL_SEGV:
1875 return SIGSEGV;
1876 #endif
1877 #if defined (SIGSYS)
1878 case TARGET_SIGNAL_SYS:
1879 return SIGSYS;
1880 #endif
1881 #if defined (SIGPIPE)
1882 case TARGET_SIGNAL_PIPE:
1883 return SIGPIPE;
1884 #endif
1885 #if defined (SIGALRM)
1886 case TARGET_SIGNAL_ALRM:
1887 return SIGALRM;
1888 #endif
1889 #if defined (SIGTERM)
1890 case TARGET_SIGNAL_TERM:
1891 return SIGTERM;
1892 #endif
1893 #if defined (SIGUSR1)
1894 case TARGET_SIGNAL_USR1:
1895 return SIGUSR1;
1896 #endif
1897 #if defined (SIGUSR2)
1898 case TARGET_SIGNAL_USR2:
1899 return SIGUSR2;
1900 #endif
1901 #if defined (SIGCHLD) || defined (SIGCLD)
1902 case TARGET_SIGNAL_CHLD:
1903 #if defined (SIGCHLD)
1904 return SIGCHLD;
1905 #else
1906 return SIGCLD;
1907 #endif
1908 #endif /* SIGCLD or SIGCHLD */
1909 #if defined (SIGPWR)
1910 case TARGET_SIGNAL_PWR:
1911 return SIGPWR;
1912 #endif
1913 #if defined (SIGWINCH)
1914 case TARGET_SIGNAL_WINCH:
1915 return SIGWINCH;
1916 #endif
1917 #if defined (SIGURG)
1918 case TARGET_SIGNAL_URG:
1919 return SIGURG;
1920 #endif
1921 #if defined (SIGIO)
1922 case TARGET_SIGNAL_IO:
1923 return SIGIO;
1924 #endif
1925 #if defined (SIGPOLL)
1926 case TARGET_SIGNAL_POLL:
1927 return SIGPOLL;
1928 #endif
1929 #if defined (SIGSTOP)
1930 case TARGET_SIGNAL_STOP:
1931 return SIGSTOP;
1932 #endif
1933 #if defined (SIGTSTP)
1934 case TARGET_SIGNAL_TSTP:
1935 return SIGTSTP;
1936 #endif
1937 #if defined (SIGCONT)
1938 case TARGET_SIGNAL_CONT:
1939 return SIGCONT;
1940 #endif
1941 #if defined (SIGTTIN)
1942 case TARGET_SIGNAL_TTIN:
1943 return SIGTTIN;
1944 #endif
1945 #if defined (SIGTTOU)
1946 case TARGET_SIGNAL_TTOU:
1947 return SIGTTOU;
1948 #endif
1949 #if defined (SIGVTALRM)
1950 case TARGET_SIGNAL_VTALRM:
1951 return SIGVTALRM;
1952 #endif
1953 #if defined (SIGPROF)
1954 case TARGET_SIGNAL_PROF:
1955 return SIGPROF;
1956 #endif
1957 #if defined (SIGXCPU)
1958 case TARGET_SIGNAL_XCPU:
1959 return SIGXCPU;
1960 #endif
1961 #if defined (SIGXFSZ)
1962 case TARGET_SIGNAL_XFSZ:
1963 return SIGXFSZ;
1964 #endif
1965 #if defined (SIGWIND)
1966 case TARGET_SIGNAL_WIND:
1967 return SIGWIND;
1968 #endif
1969 #if defined (SIGPHONE)
1970 case TARGET_SIGNAL_PHONE:
1971 return SIGPHONE;
1972 #endif
1973 #if defined (SIGLOST)
1974 case TARGET_SIGNAL_LOST:
1975 return SIGLOST;
1976 #endif
1977 #if defined (SIGWAITING)
1978 case TARGET_SIGNAL_WAITING:
1979 return SIGWAITING;
1980 #endif
1981 #if defined (SIGCANCEL)
1982 case TARGET_SIGNAL_CANCEL:
1983 return SIGCANCEL;
1984 #endif
1985 #if defined (SIGLWP)
1986 case TARGET_SIGNAL_LWP:
1987 return SIGLWP;
1988 #endif
1989 #if defined (SIGDANGER)
1990 case TARGET_SIGNAL_DANGER:
1991 return SIGDANGER;
1992 #endif
1993 #if defined (SIGGRANT)
1994 case TARGET_SIGNAL_GRANT:
1995 return SIGGRANT;
1996 #endif
1997 #if defined (SIGRETRACT)
1998 case TARGET_SIGNAL_RETRACT:
1999 return SIGRETRACT;
2000 #endif
2001 #if defined (SIGMSG)
2002 case TARGET_SIGNAL_MSG:
2003 return SIGMSG;
2004 #endif
2005 #if defined (SIGSOUND)
2006 case TARGET_SIGNAL_SOUND:
2007 return SIGSOUND;
2008 #endif
2009 #if defined (SIGSAK)
2010 case TARGET_SIGNAL_SAK:
2011 return SIGSAK;
2012 #endif
2013 #if defined (SIGPRIO)
2014 case TARGET_SIGNAL_PRIO:
2015 return SIGPRIO;
2016 #endif
2017
2018 /* Mach exceptions. Assumes that the values for EXC_ are positive! */
2019 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
2020 case TARGET_EXC_BAD_ACCESS:
2021 return _NSIG + EXC_BAD_ACCESS;
2022 #endif
2023 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
2024 case TARGET_EXC_BAD_INSTRUCTION:
2025 return _NSIG + EXC_BAD_INSTRUCTION;
2026 #endif
2027 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
2028 case TARGET_EXC_ARITHMETIC:
2029 return _NSIG + EXC_ARITHMETIC;
2030 #endif
2031 #if defined (EXC_EMULATION) && defined (_NSIG)
2032 case TARGET_EXC_EMULATION:
2033 return _NSIG + EXC_EMULATION;
2034 #endif
2035 #if defined (EXC_SOFTWARE) && defined (_NSIG)
2036 case TARGET_EXC_SOFTWARE:
2037 return _NSIG + EXC_SOFTWARE;
2038 #endif
2039 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
2040 case TARGET_EXC_BREAKPOINT:
2041 return _NSIG + EXC_BREAKPOINT;
2042 #endif
2043
2044 #if defined (SIGINFO)
2045 case TARGET_SIGNAL_INFO:
2046 return SIGINFO;
2047 #endif
2048
2049 default:
2050 #if defined (REALTIME_LO)
2051 if (oursig >= TARGET_SIGNAL_REALTIME_33
2052 && oursig <= TARGET_SIGNAL_REALTIME_63)
2053 {
2054 /* This block of signals is continuous, and
2055 TARGET_SIGNAL_REALTIME_33 is 33 by definition. */
2056 int retsig =
2057 (int) oursig - (int) TARGET_SIGNAL_REALTIME_33 + 33;
2058 if (retsig >= REALTIME_LO && retsig < REALTIME_HI)
2059 return retsig;
2060 }
2061 #if (REALTIME_LO < 33)
2062 else if (oursig == TARGET_SIGNAL_REALTIME_32)
2063 {
2064 /* TARGET_SIGNAL_REALTIME_32 isn't contiguous with
2065 TARGET_SIGNAL_REALTIME_33. It is 32 by definition. */
2066 return 32;
2067 }
2068 #endif
2069 #endif
2070
2071 #if defined (SIGRTMIN)
2072 if (oursig >= TARGET_SIGNAL_REALTIME_33
2073 && oursig <= TARGET_SIGNAL_REALTIME_63)
2074 {
2075 /* This block of signals is continuous, and
2076 TARGET_SIGNAL_REALTIME_33 is 33 by definition. */
2077 int retsig =
2078 (int) oursig - (int) TARGET_SIGNAL_REALTIME_33 + 33;
2079 if (retsig >= SIGRTMIN && retsig <= SIGRTMAX)
2080 return retsig;
2081 }
2082 else if (oursig == TARGET_SIGNAL_REALTIME_64)
2083 return 64;
2084 #endif
2085 *oursig_ok = 0;
2086 return 0;
2087 }
2088 }
2089
2090 int
2091 target_signal_to_host_p (enum target_signal oursig)
2092 {
2093 int oursig_ok;
2094 do_target_signal_to_host (oursig, &oursig_ok);
2095 return oursig_ok;
2096 }
2097
2098 int
2099 target_signal_to_host (enum target_signal oursig)
2100 {
2101 int oursig_ok;
2102 int targ_signo = do_target_signal_to_host (oursig, &oursig_ok);
2103 if (!oursig_ok)
2104 {
2105 /* The user might be trying to do "signal SIGSAK" where this system
2106 doesn't have SIGSAK. */
2107 warning ("Signal %s does not exist on this system.\n",
2108 target_signal_to_name (oursig));
2109 return 0;
2110 }
2111 else
2112 return targ_signo;
2113 }
2114
2115 /* Helper function for child_wait and the Lynx derivatives of child_wait.
2116 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
2117 translation of that in OURSTATUS. */
2118 void
2119 store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus)
2120 {
2121 #ifdef CHILD_SPECIAL_WAITSTATUS
2122 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
2123 if it wants to deal with hoststatus. */
2124 if (CHILD_SPECIAL_WAITSTATUS (ourstatus, hoststatus))
2125 return;
2126 #endif
2127
2128 if (WIFEXITED (hoststatus))
2129 {
2130 ourstatus->kind = TARGET_WAITKIND_EXITED;
2131 ourstatus->value.integer = WEXITSTATUS (hoststatus);
2132 }
2133 else if (!WIFSTOPPED (hoststatus))
2134 {
2135 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
2136 ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus));
2137 }
2138 else
2139 {
2140 ourstatus->kind = TARGET_WAITKIND_STOPPED;
2141 ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus));
2142 }
2143 }
2144 \f
2145 /* In some circumstances we allow a command to specify a numeric
2146 signal. The idea is to keep these circumstances limited so that
2147 users (and scripts) develop portable habits. For comparison,
2148 POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
2149 numeric signal at all is obsolescent. We are slightly more
2150 lenient and allow 1-15 which should match host signal numbers on
2151 most systems. Use of symbolic signal names is strongly encouraged. */
2152
2153 enum target_signal
2154 target_signal_from_command (int num)
2155 {
2156 if (num >= 1 && num <= 15)
2157 return (enum target_signal) num;
2158 error ("Only signals 1-15 are valid as numeric signals.\n\
2159 Use \"info signals\" for a list of symbolic signals.");
2160 }
2161 \f
2162 /* Returns zero to leave the inferior alone, one to interrupt it. */
2163 int (*target_activity_function) (void);
2164 int target_activity_fd;
2165 \f
2166 /* Convert a normal process ID to a string. Returns the string in a static
2167 buffer. */
2168
2169 char *
2170 normal_pid_to_str (int pid)
2171 {
2172 static char buf[30];
2173
2174 if (STREQ (current_target.to_shortname, "remote"))
2175 sprintf (buf, "thread %d", pid);
2176 else
2177 sprintf (buf, "process %d", pid);
2178
2179 return buf;
2180 }
2181
2182 /* Some targets (such as ttrace-based HPUX) don't allow us to request
2183 notification of inferior events such as fork and vork immediately
2184 after the inferior is created. (This because of how gdb gets an
2185 inferior created via invoking a shell to do it. In such a scenario,
2186 if the shell init file has commands in it, the shell will fork and
2187 exec for each of those commands, and we will see each such fork
2188 event. Very bad.)
2189
2190 This function is used by all targets that allow us to request
2191 notification of forks, etc at inferior creation time; e.g., in
2192 target_acknowledge_forked_child.
2193 */
2194 static void
2195 normal_target_post_startup_inferior (int pid)
2196 {
2197 /* This space intentionally left blank. */
2198 }
2199
2200 /* Set up the handful of non-empty slots needed by the dummy target
2201 vector. */
2202
2203 static void
2204 init_dummy_target (void)
2205 {
2206 dummy_target.to_shortname = "None";
2207 dummy_target.to_longname = "None";
2208 dummy_target.to_doc = "";
2209 dummy_target.to_attach = find_default_attach;
2210 dummy_target.to_require_attach = find_default_require_attach;
2211 dummy_target.to_require_detach = find_default_require_detach;
2212 dummy_target.to_create_inferior = find_default_create_inferior;
2213 dummy_target.to_clone_and_follow_inferior = find_default_clone_and_follow_inferior;
2214 dummy_target.to_pid_to_str = normal_pid_to_str;
2215 dummy_target.to_stratum = dummy_stratum;
2216 dummy_target.to_magic = OPS_MAGIC;
2217 }
2218 \f
2219
2220 static struct target_ops debug_target;
2221
2222 static void
2223 debug_to_open (char *args, int from_tty)
2224 {
2225 debug_target.to_open (args, from_tty);
2226
2227 fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty);
2228 }
2229
2230 static void
2231 debug_to_close (int quitting)
2232 {
2233 debug_target.to_close (quitting);
2234
2235 fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting);
2236 }
2237
2238 static void
2239 debug_to_attach (char *args, int from_tty)
2240 {
2241 debug_target.to_attach (args, from_tty);
2242
2243 fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty);
2244 }
2245
2246
2247 static void
2248 debug_to_post_attach (int pid)
2249 {
2250 debug_target.to_post_attach (pid);
2251
2252 fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid);
2253 }
2254
2255 static void
2256 debug_to_require_attach (char *args, int from_tty)
2257 {
2258 debug_target.to_require_attach (args, from_tty);
2259
2260 fprintf_unfiltered (gdb_stdlog,
2261 "target_require_attach (%s, %d)\n", args, from_tty);
2262 }
2263
2264 static void
2265 debug_to_detach (char *args, int from_tty)
2266 {
2267 debug_target.to_detach (args, from_tty);
2268
2269 fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty);
2270 }
2271
2272 static void
2273 debug_to_require_detach (int pid, char *args, int from_tty)
2274 {
2275 debug_target.to_require_detach (pid, args, from_tty);
2276
2277 fprintf_unfiltered (gdb_stdlog,
2278 "target_require_detach (%d, %s, %d)\n", pid, args, from_tty);
2279 }
2280
2281 static void
2282 debug_to_resume (int pid, int step, enum target_signal siggnal)
2283 {
2284 debug_target.to_resume (pid, step, siggnal);
2285
2286 fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", pid,
2287 step ? "step" : "continue",
2288 target_signal_to_name (siggnal));
2289 }
2290
2291 static int
2292 debug_to_wait (int pid, struct target_waitstatus *status)
2293 {
2294 int retval;
2295
2296 retval = debug_target.to_wait (pid, status);
2297
2298 fprintf_unfiltered (gdb_stdlog,
2299 "target_wait (%d, status) = %d, ", pid, retval);
2300 fprintf_unfiltered (gdb_stdlog, "status->kind = ");
2301 switch (status->kind)
2302 {
2303 case TARGET_WAITKIND_EXITED:
2304 fprintf_unfiltered (gdb_stdlog, "exited, status = %d\n",
2305 status->value.integer);
2306 break;
2307 case TARGET_WAITKIND_STOPPED:
2308 fprintf_unfiltered (gdb_stdlog, "stopped, signal = %s\n",
2309 target_signal_to_name (status->value.sig));
2310 break;
2311 case TARGET_WAITKIND_SIGNALLED:
2312 fprintf_unfiltered (gdb_stdlog, "signalled, signal = %s\n",
2313 target_signal_to_name (status->value.sig));
2314 break;
2315 case TARGET_WAITKIND_LOADED:
2316 fprintf_unfiltered (gdb_stdlog, "loaded\n");
2317 break;
2318 case TARGET_WAITKIND_FORKED:
2319 fprintf_unfiltered (gdb_stdlog, "forked\n");
2320 break;
2321 case TARGET_WAITKIND_VFORKED:
2322 fprintf_unfiltered (gdb_stdlog, "vforked\n");
2323 break;
2324 case TARGET_WAITKIND_EXECD:
2325 fprintf_unfiltered (gdb_stdlog, "execd\n");
2326 break;
2327 case TARGET_WAITKIND_SPURIOUS:
2328 fprintf_unfiltered (gdb_stdlog, "spurious\n");
2329 break;
2330 default:
2331 fprintf_unfiltered (gdb_stdlog, "unknown???\n");
2332 break;
2333 }
2334
2335 return retval;
2336 }
2337
2338 static void
2339 debug_to_post_wait (int pid, int status)
2340 {
2341 debug_target.to_post_wait (pid, status);
2342
2343 fprintf_unfiltered (gdb_stdlog, "target_post_wait (%d, %d)\n",
2344 pid, status);
2345 }
2346
2347 static void
2348 debug_to_fetch_registers (int regno)
2349 {
2350 debug_target.to_fetch_registers (regno);
2351
2352 fprintf_unfiltered (gdb_stdlog, "target_fetch_registers (%s)",
2353 regno != -1 ? REGISTER_NAME (regno) : "-1");
2354 if (regno != -1)
2355 fprintf_unfiltered (gdb_stdlog, " = 0x%lx %ld",
2356 (unsigned long) read_register (regno),
2357 (unsigned long) read_register (regno));
2358 fprintf_unfiltered (gdb_stdlog, "\n");
2359 }
2360
2361 static void
2362 debug_to_store_registers (int regno)
2363 {
2364 debug_target.to_store_registers (regno);
2365
2366 if (regno >= 0 && regno < NUM_REGS)
2367 fprintf_unfiltered (gdb_stdlog, "target_store_registers (%s) = 0x%lx %ld\n",
2368 REGISTER_NAME (regno),
2369 (unsigned long) read_register (regno),
2370 (unsigned long) read_register (regno));
2371 else
2372 fprintf_unfiltered (gdb_stdlog, "target_store_registers (%d)\n", regno);
2373 }
2374
2375 static void
2376 debug_to_prepare_to_store (void)
2377 {
2378 debug_target.to_prepare_to_store ();
2379
2380 fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n");
2381 }
2382
2383 static int
2384 debug_to_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
2385 struct mem_attrib *attrib,
2386 struct target_ops *target)
2387 {
2388 int retval;
2389
2390 retval = debug_target.to_xfer_memory (memaddr, myaddr, len, write,
2391 attrib, target);
2392
2393 fprintf_unfiltered (gdb_stdlog,
2394 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
2395 (unsigned int) memaddr, /* possable truncate long long */
2396 len, write ? "write" : "read", retval);
2397
2398
2399
2400 if (retval > 0)
2401 {
2402 int i;
2403
2404 fputs_unfiltered (", bytes =", gdb_stdlog);
2405 for (i = 0; i < retval; i++)
2406 {
2407 if ((((long) &(myaddr[i])) & 0xf) == 0)
2408 fprintf_unfiltered (gdb_stdlog, "\n");
2409 fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff);
2410 }
2411 }
2412
2413 fputc_unfiltered ('\n', gdb_stdlog);
2414
2415 return retval;
2416 }
2417
2418 static void
2419 debug_to_files_info (struct target_ops *target)
2420 {
2421 debug_target.to_files_info (target);
2422
2423 fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n");
2424 }
2425
2426 static int
2427 debug_to_insert_breakpoint (CORE_ADDR addr, char *save)
2428 {
2429 int retval;
2430
2431 retval = debug_target.to_insert_breakpoint (addr, save);
2432
2433 fprintf_unfiltered (gdb_stdlog,
2434 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
2435 (unsigned long) addr,
2436 (unsigned long) retval);
2437 return retval;
2438 }
2439
2440 static int
2441 debug_to_remove_breakpoint (CORE_ADDR addr, char *save)
2442 {
2443 int retval;
2444
2445 retval = debug_target.to_remove_breakpoint (addr, save);
2446
2447 fprintf_unfiltered (gdb_stdlog,
2448 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
2449 (unsigned long) addr,
2450 (unsigned long) retval);
2451 return retval;
2452 }
2453
2454 static void
2455 debug_to_terminal_init (void)
2456 {
2457 debug_target.to_terminal_init ();
2458
2459 fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n");
2460 }
2461
2462 static void
2463 debug_to_terminal_inferior (void)
2464 {
2465 debug_target.to_terminal_inferior ();
2466
2467 fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n");
2468 }
2469
2470 static void
2471 debug_to_terminal_ours_for_output (void)
2472 {
2473 debug_target.to_terminal_ours_for_output ();
2474
2475 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n");
2476 }
2477
2478 static void
2479 debug_to_terminal_ours (void)
2480 {
2481 debug_target.to_terminal_ours ();
2482
2483 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n");
2484 }
2485
2486 static void
2487 debug_to_terminal_info (char *arg, int from_tty)
2488 {
2489 debug_target.to_terminal_info (arg, from_tty);
2490
2491 fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg,
2492 from_tty);
2493 }
2494
2495 static void
2496 debug_to_kill (void)
2497 {
2498 debug_target.to_kill ();
2499
2500 fprintf_unfiltered (gdb_stdlog, "target_kill ()\n");
2501 }
2502
2503 static void
2504 debug_to_load (char *args, int from_tty)
2505 {
2506 debug_target.to_load (args, from_tty);
2507
2508 fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty);
2509 }
2510
2511 static int
2512 debug_to_lookup_symbol (char *name, CORE_ADDR *addrp)
2513 {
2514 int retval;
2515
2516 retval = debug_target.to_lookup_symbol (name, addrp);
2517
2518 fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name);
2519
2520 return retval;
2521 }
2522
2523 static void
2524 debug_to_create_inferior (char *exec_file, char *args, char **env)
2525 {
2526 debug_target.to_create_inferior (exec_file, args, env);
2527
2528 fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx)\n",
2529 exec_file, args);
2530 }
2531
2532 static void
2533 debug_to_post_startup_inferior (int pid)
2534 {
2535 debug_target.to_post_startup_inferior (pid);
2536
2537 fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n",
2538 pid);
2539 }
2540
2541 static void
2542 debug_to_acknowledge_created_inferior (int pid)
2543 {
2544 debug_target.to_acknowledge_created_inferior (pid);
2545
2546 fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n",
2547 pid);
2548 }
2549
2550 static void
2551 debug_to_clone_and_follow_inferior (int child_pid, int *followed_child)
2552 {
2553 debug_target.to_clone_and_follow_inferior (child_pid, followed_child);
2554
2555 fprintf_unfiltered (gdb_stdlog,
2556 "target_clone_and_follow_inferior (%d, %d)\n",
2557 child_pid, *followed_child);
2558 }
2559
2560 static void
2561 debug_to_post_follow_inferior_by_clone (void)
2562 {
2563 debug_target.to_post_follow_inferior_by_clone ();
2564
2565 fprintf_unfiltered (gdb_stdlog, "target_post_follow_inferior_by_clone ()\n");
2566 }
2567
2568 static int
2569 debug_to_insert_fork_catchpoint (int pid)
2570 {
2571 int retval;
2572
2573 retval = debug_target.to_insert_fork_catchpoint (pid);
2574
2575 fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d) = %d\n",
2576 pid, retval);
2577
2578 return retval;
2579 }
2580
2581 static int
2582 debug_to_remove_fork_catchpoint (int pid)
2583 {
2584 int retval;
2585
2586 retval = debug_target.to_remove_fork_catchpoint (pid);
2587
2588 fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n",
2589 pid, retval);
2590
2591 return retval;
2592 }
2593
2594 static int
2595 debug_to_insert_vfork_catchpoint (int pid)
2596 {
2597 int retval;
2598
2599 retval = debug_target.to_insert_vfork_catchpoint (pid);
2600
2601 fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)= %d\n",
2602 pid, retval);
2603
2604 return retval;
2605 }
2606
2607 static int
2608 debug_to_remove_vfork_catchpoint (int pid)
2609 {
2610 int retval;
2611
2612 retval = debug_target.to_remove_vfork_catchpoint (pid);
2613
2614 fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n",
2615 pid, retval);
2616
2617 return retval;
2618 }
2619
2620 static int
2621 debug_to_has_forked (int pid, int *child_pid)
2622 {
2623 int has_forked;
2624
2625 has_forked = debug_target.to_has_forked (pid, child_pid);
2626
2627 fprintf_unfiltered (gdb_stdlog, "target_has_forked (%d, %d) = %d\n",
2628 pid, *child_pid, has_forked);
2629
2630 return has_forked;
2631 }
2632
2633 static int
2634 debug_to_has_vforked (int pid, int *child_pid)
2635 {
2636 int has_vforked;
2637
2638 has_vforked = debug_target.to_has_vforked (pid, child_pid);
2639
2640 fprintf_unfiltered (gdb_stdlog, "target_has_vforked (%d, %d) = %d\n",
2641 pid, *child_pid, has_vforked);
2642
2643 return has_vforked;
2644 }
2645
2646 static int
2647 debug_to_can_follow_vfork_prior_to_exec (void)
2648 {
2649 int can_immediately_follow_vfork;
2650
2651 can_immediately_follow_vfork = debug_target.to_can_follow_vfork_prior_to_exec ();
2652
2653 fprintf_unfiltered (gdb_stdlog, "target_can_follow_vfork_prior_to_exec () = %d\n",
2654 can_immediately_follow_vfork);
2655
2656 return can_immediately_follow_vfork;
2657 }
2658
2659 static void
2660 debug_to_post_follow_vfork (int parent_pid, int followed_parent, int child_pid,
2661 int followed_child)
2662 {
2663 debug_target.to_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child);
2664
2665 fprintf_unfiltered (gdb_stdlog,
2666 "target_post_follow_vfork (%d, %d, %d, %d)\n",
2667 parent_pid, followed_parent, child_pid, followed_child);
2668 }
2669
2670 static int
2671 debug_to_insert_exec_catchpoint (int pid)
2672 {
2673 int retval;
2674
2675 retval = debug_target.to_insert_exec_catchpoint (pid);
2676
2677 fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d) = %d\n",
2678 pid, retval);
2679
2680 return retval;
2681 }
2682
2683 static int
2684 debug_to_remove_exec_catchpoint (int pid)
2685 {
2686 int retval;
2687
2688 retval = debug_target.to_remove_exec_catchpoint (pid);
2689
2690 fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n",
2691 pid, retval);
2692
2693 return retval;
2694 }
2695
2696 static int
2697 debug_to_has_execd (int pid, char **execd_pathname)
2698 {
2699 int has_execd;
2700
2701 has_execd = debug_target.to_has_execd (pid, execd_pathname);
2702
2703 fprintf_unfiltered (gdb_stdlog, "target_has_execd (%d, %s) = %d\n",
2704 pid, (*execd_pathname ? *execd_pathname : "<NULL>"),
2705 has_execd);
2706
2707 return has_execd;
2708 }
2709
2710 static int
2711 debug_to_reported_exec_events_per_exec_call (void)
2712 {
2713 int reported_exec_events;
2714
2715 reported_exec_events = debug_target.to_reported_exec_events_per_exec_call ();
2716
2717 fprintf_unfiltered (gdb_stdlog,
2718 "target_reported_exec_events_per_exec_call () = %d\n",
2719 reported_exec_events);
2720
2721 return reported_exec_events;
2722 }
2723
2724 static int
2725 debug_to_has_syscall_event (int pid, enum target_waitkind *kind,
2726 int *syscall_id)
2727 {
2728 int has_syscall_event;
2729 char *kind_spelling = "??";
2730
2731 has_syscall_event = debug_target.to_has_syscall_event (pid, kind, syscall_id);
2732 if (has_syscall_event)
2733 {
2734 switch (*kind)
2735 {
2736 case TARGET_WAITKIND_SYSCALL_ENTRY:
2737 kind_spelling = "SYSCALL_ENTRY";
2738 break;
2739 case TARGET_WAITKIND_SYSCALL_RETURN:
2740 kind_spelling = "SYSCALL_RETURN";
2741 break;
2742 default:
2743 break;
2744 }
2745 }
2746
2747 fprintf_unfiltered (gdb_stdlog,
2748 "target_has_syscall_event (%d, %s, %d) = %d\n",
2749 pid, kind_spelling, *syscall_id, has_syscall_event);
2750
2751 return has_syscall_event;
2752 }
2753
2754 static int
2755 debug_to_has_exited (int pid, int wait_status, int *exit_status)
2756 {
2757 int has_exited;
2758
2759 has_exited = debug_target.to_has_exited (pid, wait_status, exit_status);
2760
2761 fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n",
2762 pid, wait_status, *exit_status, has_exited);
2763
2764 return has_exited;
2765 }
2766
2767 static void
2768 debug_to_mourn_inferior (void)
2769 {
2770 debug_target.to_mourn_inferior ();
2771
2772 fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n");
2773 }
2774
2775 static int
2776 debug_to_can_run (void)
2777 {
2778 int retval;
2779
2780 retval = debug_target.to_can_run ();
2781
2782 fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval);
2783
2784 return retval;
2785 }
2786
2787 static void
2788 debug_to_notice_signals (int pid)
2789 {
2790 debug_target.to_notice_signals (pid);
2791
2792 fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n", pid);
2793 }
2794
2795 static int
2796 debug_to_thread_alive (int pid)
2797 {
2798 int retval;
2799
2800 retval = debug_target.to_thread_alive (pid);
2801
2802 fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n",
2803 pid, retval);
2804
2805 return retval;
2806 }
2807
2808 static void
2809 debug_to_find_new_threads (void)
2810 {
2811 debug_target.to_find_new_threads ();
2812
2813 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog);
2814 }
2815
2816 static void
2817 debug_to_stop (void)
2818 {
2819 debug_target.to_stop ();
2820
2821 fprintf_unfiltered (gdb_stdlog, "target_stop ()\n");
2822 }
2823
2824 static int
2825 debug_to_query (int type, char *req, char *resp, int *siz)
2826 {
2827 int retval;
2828
2829 retval = debug_target.to_query (type, req, resp, siz);
2830
2831 fprintf_unfiltered (gdb_stdlog, "target_query (%c, %s, %s, %d) = %d\n", type, req, resp, *siz, retval);
2832
2833 return retval;
2834 }
2835
2836 static void
2837 debug_to_rcmd (char *command,
2838 struct ui_file *outbuf)
2839 {
2840 debug_target.to_rcmd (command, outbuf);
2841 fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command);
2842 }
2843
2844 static struct symtab_and_line *
2845 debug_to_enable_exception_callback (enum exception_event_kind kind, int enable)
2846 {
2847 struct symtab_and_line *result;
2848 result = debug_target.to_enable_exception_callback (kind, enable);
2849 fprintf_unfiltered (gdb_stdlog,
2850 "target get_exception_callback_sal (%d, %d)\n",
2851 kind, enable);
2852 return result;
2853 }
2854
2855 static struct exception_event_record *
2856 debug_to_get_current_exception_event (void)
2857 {
2858 struct exception_event_record *result;
2859 result = debug_target.to_get_current_exception_event ();
2860 fprintf_unfiltered (gdb_stdlog, "target get_current_exception_event ()\n");
2861 return result;
2862 }
2863
2864 static char *
2865 debug_to_pid_to_exec_file (int pid)
2866 {
2867 char *exec_file;
2868
2869 exec_file = debug_target.to_pid_to_exec_file (pid);
2870
2871 fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n",
2872 pid, exec_file);
2873
2874 return exec_file;
2875 }
2876
2877 static char *
2878 debug_to_core_file_to_sym_file (char *core)
2879 {
2880 char *sym_file;
2881
2882 sym_file = debug_target.to_core_file_to_sym_file (core);
2883
2884 fprintf_unfiltered (gdb_stdlog, "target_core_file_to_sym_file (%s) = %s\n",
2885 core, sym_file);
2886
2887 return sym_file;
2888 }
2889
2890 static void
2891 setup_target_debug (void)
2892 {
2893 memcpy (&debug_target, &current_target, sizeof debug_target);
2894
2895 current_target.to_open = debug_to_open;
2896 current_target.to_close = debug_to_close;
2897 current_target.to_attach = debug_to_attach;
2898 current_target.to_post_attach = debug_to_post_attach;
2899 current_target.to_require_attach = debug_to_require_attach;
2900 current_target.to_detach = debug_to_detach;
2901 current_target.to_require_detach = debug_to_require_detach;
2902 current_target.to_resume = debug_to_resume;
2903 current_target.to_wait = debug_to_wait;
2904 current_target.to_post_wait = debug_to_post_wait;
2905 current_target.to_fetch_registers = debug_to_fetch_registers;
2906 current_target.to_store_registers = debug_to_store_registers;
2907 current_target.to_prepare_to_store = debug_to_prepare_to_store;
2908 current_target.to_xfer_memory = debug_to_xfer_memory;
2909 current_target.to_files_info = debug_to_files_info;
2910 current_target.to_insert_breakpoint = debug_to_insert_breakpoint;
2911 current_target.to_remove_breakpoint = debug_to_remove_breakpoint;
2912 current_target.to_terminal_init = debug_to_terminal_init;
2913 current_target.to_terminal_inferior = debug_to_terminal_inferior;
2914 current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output;
2915 current_target.to_terminal_ours = debug_to_terminal_ours;
2916 current_target.to_terminal_info = debug_to_terminal_info;
2917 current_target.to_kill = debug_to_kill;
2918 current_target.to_load = debug_to_load;
2919 current_target.to_lookup_symbol = debug_to_lookup_symbol;
2920 current_target.to_create_inferior = debug_to_create_inferior;
2921 current_target.to_post_startup_inferior = debug_to_post_startup_inferior;
2922 current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior;
2923 current_target.to_clone_and_follow_inferior = debug_to_clone_and_follow_inferior;
2924 current_target.to_post_follow_inferior_by_clone = debug_to_post_follow_inferior_by_clone;
2925 current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint;
2926 current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
2927 current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
2928 current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint;
2929 current_target.to_has_forked = debug_to_has_forked;
2930 current_target.to_has_vforked = debug_to_has_vforked;
2931 current_target.to_can_follow_vfork_prior_to_exec = debug_to_can_follow_vfork_prior_to_exec;
2932 current_target.to_post_follow_vfork = debug_to_post_follow_vfork;
2933 current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint;
2934 current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
2935 current_target.to_has_execd = debug_to_has_execd;
2936 current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call;
2937 current_target.to_has_syscall_event = debug_to_has_syscall_event;
2938 current_target.to_has_exited = debug_to_has_exited;
2939 current_target.to_mourn_inferior = debug_to_mourn_inferior;
2940 current_target.to_can_run = debug_to_can_run;
2941 current_target.to_notice_signals = debug_to_notice_signals;
2942 current_target.to_thread_alive = debug_to_thread_alive;
2943 current_target.to_find_new_threads = debug_to_find_new_threads;
2944 current_target.to_stop = debug_to_stop;
2945 current_target.to_query = debug_to_query;
2946 current_target.to_rcmd = debug_to_rcmd;
2947 current_target.to_enable_exception_callback = debug_to_enable_exception_callback;
2948 current_target.to_get_current_exception_event = debug_to_get_current_exception_event;
2949 current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
2950 current_target.to_core_file_to_sym_file = debug_to_core_file_to_sym_file;
2951
2952 }
2953 \f
2954
2955 static char targ_desc[] =
2956 "Names of targets and files being debugged.\n\
2957 Shows the entire stack of targets currently in use (including the exec-file,\n\
2958 core-file, and process, if any), as well as the symbol file name.";
2959
2960 static void
2961 do_monitor_command (char *cmd,
2962 int from_tty)
2963 {
2964 if ((current_target.to_rcmd
2965 == (void (*) (char *, struct ui_file *)) tcomplain)
2966 || (current_target.to_rcmd == debug_to_rcmd
2967 && (debug_target.to_rcmd
2968 == (void (*) (char *, struct ui_file *)) tcomplain)))
2969 {
2970 error ("\"monitor\" command not supported by this target.\n");
2971 }
2972 target_rcmd (cmd, gdb_stdtarg);
2973 }
2974
2975 void
2976 initialize_targets (void)
2977 {
2978 init_dummy_target ();
2979 push_target (&dummy_target);
2980
2981 add_info ("target", target_info, targ_desc);
2982 add_info ("files", target_info, targ_desc);
2983
2984 add_show_from_set (
2985 add_set_cmd ("target", class_maintenance, var_zinteger,
2986 (char *) &targetdebug,
2987 "Set target debugging.\n\
2988 When non-zero, target debugging is enabled.", &setdebuglist),
2989 &showdebuglist);
2990
2991
2992 add_com ("monitor", class_obscure, do_monitor_command,
2993 "Send a command to the remote monitor (remote targets only).");
2994
2995 target_dcache = dcache_init();
2996
2997 if (!STREQ (signals[TARGET_SIGNAL_LAST].string, "TARGET_SIGNAL_MAGIC"))
2998 internal_error (__FILE__, __LINE__, "failed internal consistency check");
2999 }
This page took 0.112149 seconds and 4 git commands to generate.