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