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