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