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