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