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