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