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