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