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