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