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