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