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