daily update
[deliverable/binutils-gdb.git] / gdb / target.c
CommitLineData
c906108c 1/* Select target systems and architectures at runtime for GDB.
b6ba6518 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
be4d1333
MS
3 2000, 2001, 2002
4 Free Software Foundation, Inc.
c906108c
SS
5 Contributed by Cygnus Support.
6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
c906108c 13
c5aa993b
JM
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
c906108c 18
c5aa993b
JM
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
c906108c
SS
23
24#include "defs.h"
25#include <errno.h>
c906108c
SS
26#include "gdb_string.h"
27#include "target.h"
28#include "gdbcmd.h"
29#include "symtab.h"
30#include "inferior.h"
31#include "bfd.h"
32#include "symfile.h"
33#include "objfiles.h"
03f2053f 34#include "gdb_wait.h"
4930751a 35#include "dcache.h"
c906108c 36#include <signal.h>
4e052eda 37#include "regcache.h"
c906108c
SS
38
39extern int errno;
40
a14ed312 41static void target_info (char *, int);
c906108c 42
a14ed312 43static void cleanup_target (struct target_ops *);
c906108c 44
a14ed312 45static void maybe_kill_then_create_inferior (char *, char *, char **);
c906108c 46
a14ed312 47static void default_clone_and_follow_inferior (int, int *);
c906108c 48
a14ed312 49static void maybe_kill_then_attach (char *, int);
c906108c 50
a14ed312 51static void kill_or_be_killed (int);
c906108c 52
a14ed312 53static void default_terminal_info (char *, int);
c906108c 54
a14ed312 55static int nosymbol (char *, CORE_ADDR *);
c906108c 56
a14ed312 57static void tcomplain (void);
c906108c 58
a14ed312 59static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *);
c906108c 60
a14ed312 61static int return_zero (void);
c906108c 62
a14ed312 63static int return_one (void);
c906108c 64
a14ed312 65void target_ignore (void);
c906108c 66
a14ed312 67static void target_command (char *, int);
c906108c 68
a14ed312 69static struct target_ops *find_default_run_target (char *);
c906108c 70
a14ed312 71static void update_current_target (void);
c906108c 72
a14ed312 73static void nosupport_runtime (void);
392a587b 74
39f77062 75static void normal_target_post_startup_inferior (ptid_t ptid);
392a587b 76
917317f4
JM
77/* Transfer LEN bytes between target address MEMADDR and GDB address
78 MYADDR. Returns 0 for success, errno code for failure (which
79 includes partial transfers -- if you want a more useful response to
80 partial transfers, try either target_read_memory_partial or
81 target_write_memory_partial). */
c906108c
SS
82
83static int
a14ed312 84target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write);
c906108c 85
a14ed312 86static void init_dummy_target (void);
c906108c 87
a14ed312 88static void debug_to_open (char *, int);
c906108c 89
a14ed312 90static void debug_to_close (int);
c906108c 91
a14ed312 92static void debug_to_attach (char *, int);
c906108c 93
a14ed312 94static void debug_to_detach (char *, int);
c906108c 95
39f77062 96static void debug_to_resume (ptid_t, int, enum target_signal);
c906108c 97
39f77062 98static ptid_t debug_to_wait (ptid_t, struct target_waitstatus *);
c906108c 99
a14ed312 100static void debug_to_fetch_registers (int);
c906108c 101
a14ed312 102static void debug_to_store_registers (int);
c906108c 103
a14ed312 104static void debug_to_prepare_to_store (void);
c906108c
SS
105
106static int
29e57380
C
107debug_to_xfer_memory (CORE_ADDR, char *, int, int, struct mem_attrib *,
108 struct target_ops *);
c906108c 109
a14ed312 110static void debug_to_files_info (struct target_ops *);
c906108c 111
a14ed312 112static int debug_to_insert_breakpoint (CORE_ADDR, char *);
c906108c 113
a14ed312 114static int debug_to_remove_breakpoint (CORE_ADDR, char *);
c906108c 115
a14ed312 116static void debug_to_terminal_init (void);
c906108c 117
a14ed312 118static void debug_to_terminal_inferior (void);
c906108c 119
a14ed312 120static void debug_to_terminal_ours_for_output (void);
c906108c 121
a14ed312 122static void debug_to_terminal_ours (void);
c906108c 123
a14ed312 124static void debug_to_terminal_info (char *, int);
c906108c 125
a14ed312 126static void debug_to_kill (void);
c906108c 127
a14ed312 128static void debug_to_load (char *, int);
c906108c 129
a14ed312 130static int debug_to_lookup_symbol (char *, CORE_ADDR *);
c906108c 131
a14ed312 132static void debug_to_create_inferior (char *, char *, char **);
c906108c 133
a14ed312 134static void debug_to_mourn_inferior (void);
c906108c 135
a14ed312 136static int debug_to_can_run (void);
c906108c 137
39f77062 138static void debug_to_notice_signals (ptid_t);
c906108c 139
39f77062 140static int debug_to_thread_alive (ptid_t);
c906108c 141
a14ed312 142static void debug_to_stop (void);
c906108c 143
a14ed312 144static int debug_to_query (int /*char */ , char *, char *, int *);
c906108c
SS
145
146/* Pointer to array of target architecture structures; the size of the
147 array; the current index into the array; the allocated size of the
148 array. */
149struct target_ops **target_structs;
150unsigned target_struct_size;
151unsigned target_struct_index;
152unsigned target_struct_allocsize;
153#define DEFAULT_ALLOCSIZE 10
154
155/* The initial current target, so that there is always a semi-valid
156 current target. */
157
158static struct target_ops dummy_target;
159
160/* Top of target stack. */
161
162struct target_stack_item *target_stack;
163
164/* The target structure we are currently using to talk to a process
165 or file or whatever "inferior" we have. */
166
167struct target_ops current_target;
168
169/* Command list for target. */
170
171static struct cmd_list_element *targetlist = NULL;
172
173/* Nonzero if we are debugging an attached outside process
174 rather than an inferior. */
175
176int attach_flag;
177
c906108c
SS
178/* Non-zero if we want to see trace of target level stuff. */
179
180static int targetdebug = 0;
181
a14ed312 182static void setup_target_debug (void);
c906108c 183
4930751a
C
184DCACHE *target_dcache;
185
c906108c
SS
186/* The user just typed 'target' without the name of a target. */
187
188/* ARGSUSED */
189static void
fba45db2 190target_command (char *arg, int from_tty)
c906108c
SS
191{
192 fputs_filtered ("Argument required (target name). Try `help target'\n",
193 gdb_stdout);
194}
195
196/* Add a possible target architecture to the list. */
197
198void
fba45db2 199add_target (struct target_ops *t)
c906108c
SS
200{
201 if (!target_structs)
202 {
203 target_struct_allocsize = DEFAULT_ALLOCSIZE;
204 target_structs = (struct target_ops **) xmalloc
205 (target_struct_allocsize * sizeof (*target_structs));
206 }
207 if (target_struct_size >= target_struct_allocsize)
208 {
209 target_struct_allocsize *= 2;
210 target_structs = (struct target_ops **)
c5aa993b
JM
211 xrealloc ((char *) target_structs,
212 target_struct_allocsize * sizeof (*target_structs));
c906108c
SS
213 }
214 target_structs[target_struct_size++] = t;
c5aa993b 215/* cleanup_target (t); */
c906108c
SS
216
217 if (targetlist == NULL)
218 add_prefix_cmd ("target", class_run, target_command,
219 "Connect to a target machine or process.\n\
220The first argument is the type or protocol of the target machine.\n\
221Remaining arguments are interpreted by the target protocol. For more\n\
222information on the arguments for a particular protocol, type\n\
223`help target ' followed by the protocol name.",
224 &targetlist, "target ", 0, &cmdlist);
225 add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist);
226}
227
228/* Stub functions */
229
230void
fba45db2 231target_ignore (void)
c906108c
SS
232{
233}
234
11cf8741
JM
235void
236target_load (char *arg, int from_tty)
237{
4930751a 238 dcache_invalidate (target_dcache);
11cf8741
JM
239 (*current_target.to_load) (arg, from_tty);
240}
241
c906108c
SS
242/* ARGSUSED */
243static int
fba45db2
KB
244nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write,
245 struct target_ops *t)
c906108c 246{
c5aa993b
JM
247 errno = EIO; /* Can't read/write this location */
248 return 0; /* No bytes handled */
c906108c
SS
249}
250
251static void
fba45db2 252tcomplain (void)
c906108c
SS
253{
254 error ("You can't do that when your target is `%s'",
255 current_target.to_shortname);
256}
257
258void
fba45db2 259noprocess (void)
c906108c
SS
260{
261 error ("You can't do that without a process to debug.");
262}
263
264/* ARGSUSED */
265static int
fba45db2 266nosymbol (char *name, CORE_ADDR *addrp)
c906108c 267{
c5aa993b 268 return 1; /* Symbol does not exist in target env */
c906108c
SS
269}
270
271/* ARGSUSED */
392a587b 272static void
fba45db2 273nosupport_runtime (void)
c906108c 274{
39f77062 275 if (ptid_equal (inferior_ptid, null_ptid))
c906108c
SS
276 noprocess ();
277 else
278 error ("No run-time support for this");
279}
280
281
282/* ARGSUSED */
283static void
fba45db2 284default_terminal_info (char *args, int from_tty)
c906108c 285{
c5aa993b 286 printf_unfiltered ("No saved terminal information.\n");
c906108c
SS
287}
288
289/* This is the default target_create_inferior and target_attach function.
290 If the current target is executing, it asks whether to kill it off.
291 If this function returns without calling error(), it has killed off
292 the target, and the operation should be attempted. */
293
294static void
fba45db2 295kill_or_be_killed (int from_tty)
c906108c
SS
296{
297 if (target_has_execution)
298 {
299 printf_unfiltered ("You are already running a program:\n");
300 target_files_info ();
c5aa993b
JM
301 if (query ("Kill it? "))
302 {
303 target_kill ();
304 if (target_has_execution)
305 error ("Killing the program did not help.");
306 return;
307 }
308 else
309 {
310 error ("Program not killed.");
311 }
c906108c 312 }
c5aa993b 313 tcomplain ();
c906108c
SS
314}
315
316static void
fba45db2 317maybe_kill_then_attach (char *args, int from_tty)
c906108c
SS
318{
319 kill_or_be_killed (from_tty);
320 target_attach (args, from_tty);
321}
322
323static void
fba45db2 324maybe_kill_then_create_inferior (char *exec, char *args, char **env)
c906108c
SS
325{
326 kill_or_be_killed (0);
327 target_create_inferior (exec, args, env);
328}
329
330static void
fba45db2 331default_clone_and_follow_inferior (int child_pid, int *followed_child)
c906108c
SS
332{
333 target_clone_and_follow_inferior (child_pid, followed_child);
334}
335
336/* Clean up a target struct so it no longer has any zero pointers in it.
337 We default entries, at least to stubs that print error messages. */
338
339static void
fba45db2 340cleanup_target (struct target_ops *t)
c906108c
SS
341{
342
343#define de_fault(field, value) \
0d06e24b
JM
344 if (!t->field) \
345 t->field = value
346
347 de_fault (to_open,
348 (void (*) (char *, int))
349 tcomplain);
350 de_fault (to_close,
351 (void (*) (int))
352 target_ignore);
353 de_fault (to_attach,
354 maybe_kill_then_attach);
355 de_fault (to_post_attach,
356 (void (*) (int))
357 target_ignore);
358 de_fault (to_require_attach,
359 maybe_kill_then_attach);
360 de_fault (to_detach,
361 (void (*) (char *, int))
362 target_ignore);
363 de_fault (to_require_detach,
364 (void (*) (int, char *, int))
365 target_ignore);
366 de_fault (to_resume,
39f77062 367 (void (*) (ptid_t, int, enum target_signal))
0d06e24b
JM
368 noprocess);
369 de_fault (to_wait,
39f77062 370 (ptid_t (*) (ptid_t, struct target_waitstatus *))
0d06e24b
JM
371 noprocess);
372 de_fault (to_post_wait,
39f77062 373 (void (*) (ptid_t, int))
0d06e24b
JM
374 target_ignore);
375 de_fault (to_fetch_registers,
376 (void (*) (int))
377 target_ignore);
378 de_fault (to_store_registers,
379 (void (*) (int))
380 noprocess);
381 de_fault (to_prepare_to_store,
382 (void (*) (void))
383 noprocess);
384 de_fault (to_xfer_memory,
29e57380 385 (int (*) (CORE_ADDR, char *, int, int, struct mem_attrib *, struct target_ops *))
0d06e24b
JM
386 nomemory);
387 de_fault (to_files_info,
388 (void (*) (struct target_ops *))
389 target_ignore);
390 de_fault (to_insert_breakpoint,
391 memory_insert_breakpoint);
392 de_fault (to_remove_breakpoint,
393 memory_remove_breakpoint);
394 de_fault (to_terminal_init,
395 (void (*) (void))
396 target_ignore);
397 de_fault (to_terminal_inferior,
398 (void (*) (void))
399 target_ignore);
400 de_fault (to_terminal_ours_for_output,
401 (void (*) (void))
402 target_ignore);
403 de_fault (to_terminal_ours,
404 (void (*) (void))
405 target_ignore);
406 de_fault (to_terminal_info,
407 default_terminal_info);
408 de_fault (to_kill,
409 (void (*) (void))
410 noprocess);
411 de_fault (to_load,
412 (void (*) (char *, int))
413 tcomplain);
414 de_fault (to_lookup_symbol,
415 (int (*) (char *, CORE_ADDR *))
416 nosymbol);
417 de_fault (to_create_inferior,
418 maybe_kill_then_create_inferior);
419 de_fault (to_post_startup_inferior,
39f77062 420 (void (*) (ptid_t))
0d06e24b
JM
421 target_ignore);
422 de_fault (to_acknowledge_created_inferior,
423 (void (*) (int))
424 target_ignore);
425 de_fault (to_clone_and_follow_inferior,
426 default_clone_and_follow_inferior);
427 de_fault (to_post_follow_inferior_by_clone,
428 (void (*) (void))
429 target_ignore);
430 de_fault (to_insert_fork_catchpoint,
431 (int (*) (int))
432 tcomplain);
433 de_fault (to_remove_fork_catchpoint,
434 (int (*) (int))
435 tcomplain);
436 de_fault (to_insert_vfork_catchpoint,
437 (int (*) (int))
438 tcomplain);
439 de_fault (to_remove_vfork_catchpoint,
440 (int (*) (int))
441 tcomplain);
442 de_fault (to_has_forked,
443 (int (*) (int, int *))
444 return_zero);
445 de_fault (to_has_vforked,
446 (int (*) (int, int *))
447 return_zero);
448 de_fault (to_can_follow_vfork_prior_to_exec,
449 (int (*) (void))
450 return_zero);
451 de_fault (to_post_follow_vfork,
452 (void (*) (int, int, int, int))
453 target_ignore);
454 de_fault (to_insert_exec_catchpoint,
455 (int (*) (int))
456 tcomplain);
457 de_fault (to_remove_exec_catchpoint,
458 (int (*) (int))
459 tcomplain);
460 de_fault (to_has_execd,
461 (int (*) (int, char **))
462 return_zero);
463 de_fault (to_reported_exec_events_per_exec_call,
464 (int (*) (void))
465 return_one);
466 de_fault (to_has_syscall_event,
467 (int (*) (int, enum target_waitkind *, int *))
468 return_zero);
469 de_fault (to_has_exited,
470 (int (*) (int, int, int *))
471 return_zero);
472 de_fault (to_mourn_inferior,
473 (void (*) (void))
474 noprocess);
475 de_fault (to_can_run,
476 return_zero);
477 de_fault (to_notice_signals,
39f77062 478 (void (*) (ptid_t))
0d06e24b
JM
479 target_ignore);
480 de_fault (to_thread_alive,
39f77062 481 (int (*) (ptid_t))
0d06e24b
JM
482 return_zero);
483 de_fault (to_find_new_threads,
484 (void (*) (void))
485 target_ignore);
486 de_fault (to_extra_thread_info,
487 (char *(*) (struct thread_info *))
488 return_zero);
489 de_fault (to_stop,
490 (void (*) (void))
491 target_ignore);
0d06e24b 492 de_fault (to_rcmd,
d9fcf2fb 493 (void (*) (char *, struct ui_file *))
0d06e24b
JM
494 tcomplain);
495 de_fault (to_enable_exception_callback,
496 (struct symtab_and_line * (*) (enum exception_event_kind, int))
497 nosupport_runtime);
498 de_fault (to_get_current_exception_event,
499 (struct exception_event_record * (*) (void))
500 nosupport_runtime);
501 de_fault (to_pid_to_exec_file,
502 (char *(*) (int))
503 return_zero);
0d06e24b
JM
504 de_fault (to_can_async_p,
505 (int (*) (void))
506 return_zero);
507 de_fault (to_is_async_p,
508 (int (*) (void))
509 return_zero);
510 de_fault (to_async,
511 (void (*) (void (*) (enum inferior_event_type, void*), void*))
512 tcomplain);
c906108c
SS
513#undef de_fault
514}
515
516/* Go through the target stack from top to bottom, copying over zero entries in
517 current_target. In effect, we are doing class inheritance through the
518 pushed target vectors. */
519
520static void
fba45db2 521update_current_target (void)
c906108c
SS
522{
523 struct target_stack_item *item;
524 struct target_ops *t;
525
526 /* First, reset current_target */
527 memset (&current_target, 0, sizeof current_target);
528
529 for (item = target_stack; item; item = item->next)
530 {
531 t = item->target_ops;
532
533#define INHERIT(FIELD, TARGET) \
534 if (!current_target.FIELD) \
535 current_target.FIELD = TARGET->FIELD
536
537 INHERIT (to_shortname, t);
538 INHERIT (to_longname, t);
539 INHERIT (to_doc, t);
540 INHERIT (to_open, t);
541 INHERIT (to_close, t);
542 INHERIT (to_attach, t);
543 INHERIT (to_post_attach, t);
544 INHERIT (to_require_attach, t);
545 INHERIT (to_detach, t);
546 INHERIT (to_require_detach, t);
547 INHERIT (to_resume, t);
548 INHERIT (to_wait, t);
549 INHERIT (to_post_wait, t);
550 INHERIT (to_fetch_registers, t);
551 INHERIT (to_store_registers, t);
552 INHERIT (to_prepare_to_store, t);
553 INHERIT (to_xfer_memory, t);
554 INHERIT (to_files_info, t);
555 INHERIT (to_insert_breakpoint, t);
556 INHERIT (to_remove_breakpoint, t);
557 INHERIT (to_terminal_init, t);
558 INHERIT (to_terminal_inferior, t);
559 INHERIT (to_terminal_ours_for_output, t);
560 INHERIT (to_terminal_ours, t);
561 INHERIT (to_terminal_info, t);
562 INHERIT (to_kill, t);
563 INHERIT (to_load, t);
564 INHERIT (to_lookup_symbol, t);
565 INHERIT (to_create_inferior, t);
566 INHERIT (to_post_startup_inferior, t);
567 INHERIT (to_acknowledge_created_inferior, t);
568 INHERIT (to_clone_and_follow_inferior, t);
569 INHERIT (to_post_follow_inferior_by_clone, t);
570 INHERIT (to_insert_fork_catchpoint, t);
571 INHERIT (to_remove_fork_catchpoint, t);
572 INHERIT (to_insert_vfork_catchpoint, t);
573 INHERIT (to_remove_vfork_catchpoint, t);
574 INHERIT (to_has_forked, t);
575 INHERIT (to_has_vforked, t);
576 INHERIT (to_can_follow_vfork_prior_to_exec, t);
577 INHERIT (to_post_follow_vfork, t);
578 INHERIT (to_insert_exec_catchpoint, t);
579 INHERIT (to_remove_exec_catchpoint, t);
580 INHERIT (to_has_execd, t);
581 INHERIT (to_reported_exec_events_per_exec_call, t);
582 INHERIT (to_has_syscall_event, t);
583 INHERIT (to_has_exited, t);
584 INHERIT (to_mourn_inferior, t);
585 INHERIT (to_can_run, t);
586 INHERIT (to_notice_signals, t);
587 INHERIT (to_thread_alive, t);
b83266a0 588 INHERIT (to_find_new_threads, t);
ed9a39eb 589 INHERIT (to_pid_to_str, t);
0d06e24b 590 INHERIT (to_extra_thread_info, t);
c906108c
SS
591 INHERIT (to_stop, t);
592 INHERIT (to_query, t);
96baa820 593 INHERIT (to_rcmd, t);
c906108c
SS
594 INHERIT (to_enable_exception_callback, t);
595 INHERIT (to_get_current_exception_event, t);
596 INHERIT (to_pid_to_exec_file, t);
c906108c
SS
597 INHERIT (to_stratum, t);
598 INHERIT (DONT_USE, t);
599 INHERIT (to_has_all_memory, t);
600 INHERIT (to_has_memory, t);
601 INHERIT (to_has_stack, t);
602 INHERIT (to_has_registers, t);
603 INHERIT (to_has_execution, t);
604 INHERIT (to_has_thread_control, t);
605 INHERIT (to_sections, t);
606 INHERIT (to_sections_end, t);
6426a772
JM
607 INHERIT (to_can_async_p, t);
608 INHERIT (to_is_async_p, t);
609 INHERIT (to_async, t);
ed9a39eb 610 INHERIT (to_async_mask_value, t);
be4d1333
MS
611 INHERIT (to_find_memory_regions, t);
612 INHERIT (to_make_corefile_notes, t);
c906108c
SS
613 INHERIT (to_magic, t);
614
615#undef INHERIT
616 }
617}
618
619/* Push a new target type into the stack of the existing target accessors,
620 possibly superseding some of the existing accessors.
621
622 Result is zero if the pushed target ended up on top of the stack,
623 nonzero if at least one target is on top of it.
624
625 Rather than allow an empty stack, we always have the dummy target at
626 the bottom stratum, so we can call the function vectors without
627 checking them. */
628
629int
fba45db2 630push_target (struct target_ops *t)
c906108c
SS
631{
632 struct target_stack_item *cur, *prev, *tmp;
633
634 /* Check magic number. If wrong, it probably means someone changed
635 the struct definition, but not all the places that initialize one. */
636 if (t->to_magic != OPS_MAGIC)
637 {
c5aa993b
JM
638 fprintf_unfiltered (gdb_stderr,
639 "Magic number of %s target struct wrong\n",
640 t->to_shortname);
e1e9e218 641 internal_error (__FILE__, __LINE__, "failed internal consistency check");
c906108c
SS
642 }
643
644 /* Find the proper stratum to install this target in. */
645
646 for (prev = NULL, cur = target_stack; cur; prev = cur, cur = cur->next)
647 {
c5aa993b 648 if ((int) (t->to_stratum) >= (int) (cur->target_ops->to_stratum))
c906108c
SS
649 break;
650 }
651
652 /* If there's already targets at this stratum, remove them. */
653
654 if (cur)
655 while (t->to_stratum == cur->target_ops->to_stratum)
656 {
657 /* There's already something on this stratum. Close it off. */
658 if (cur->target_ops->to_close)
659 (cur->target_ops->to_close) (0);
660 if (prev)
c5aa993b 661 prev->next = cur->next; /* Unchain old target_ops */
c906108c 662 else
c5aa993b 663 target_stack = cur->next; /* Unchain first on list */
c906108c 664 tmp = cur->next;
b8c9b27d 665 xfree (cur);
c906108c
SS
666 cur = tmp;
667 }
668
669 /* We have removed all targets in our stratum, now add the new one. */
670
671 tmp = (struct target_stack_item *)
672 xmalloc (sizeof (struct target_stack_item));
673 tmp->next = cur;
674 tmp->target_ops = t;
675
676 if (prev)
677 prev->next = tmp;
678 else
679 target_stack = tmp;
680
681 update_current_target ();
682
c5aa993b 683 cleanup_target (&current_target); /* Fill in the gaps */
c906108c 684
c906108c
SS
685 if (targetdebug)
686 setup_target_debug ();
c906108c
SS
687
688 return prev != 0;
689}
690
691/* Remove a target_ops vector from the stack, wherever it may be.
692 Return how many times it was removed (0 or 1). */
693
694int
fba45db2 695unpush_target (struct target_ops *t)
c906108c
SS
696{
697 struct target_stack_item *cur, *prev;
698
699 if (t->to_close)
700 t->to_close (0); /* Let it clean up */
701
702 /* Look for the specified target. Note that we assume that a target
703 can only occur once in the target stack. */
704
705 for (cur = target_stack, prev = NULL; cur; prev = cur, cur = cur->next)
706 if (cur->target_ops == t)
707 break;
708
709 if (!cur)
710 return 0; /* Didn't find target_ops, quit now */
711
712 /* Unchain the target */
713
714 if (!prev)
715 target_stack = cur->next;
716 else
717 prev->next = cur->next;
718
b8c9b27d 719 xfree (cur); /* Release the target_stack_item */
c906108c
SS
720
721 update_current_target ();
722 cleanup_target (&current_target);
723
724 return 1;
725}
726
727void
fba45db2 728pop_target (void)
c906108c 729{
c5aa993b 730 (current_target.to_close) (0); /* Let it clean up */
c906108c
SS
731 if (unpush_target (target_stack->target_ops) == 1)
732 return;
733
c5aa993b
JM
734 fprintf_unfiltered (gdb_stderr,
735 "pop_target couldn't find target %s\n",
736 current_target.to_shortname);
e1e9e218 737 internal_error (__FILE__, __LINE__, "failed internal consistency check");
c906108c
SS
738}
739
740#undef MIN
741#define MIN(A, B) (((A) <= (B)) ? (A) : (B))
742
743/* target_read_string -- read a null terminated string, up to LEN bytes,
744 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
745 Set *STRING to a pointer to malloc'd memory containing the data; the caller
746 is responsible for freeing it. Return the number of bytes successfully
747 read. */
748
749int
fba45db2 750target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop)
c906108c
SS
751{
752 int tlen, origlen, offset, i;
753 char buf[4];
754 int errcode = 0;
755 char *buffer;
756 int buffer_allocated;
757 char *bufptr;
758 unsigned int nbytes_read = 0;
759
760 /* Small for testing. */
761 buffer_allocated = 4;
762 buffer = xmalloc (buffer_allocated);
763 bufptr = buffer;
764
765 origlen = len;
766
767 while (len > 0)
768 {
769 tlen = MIN (len, 4 - (memaddr & 3));
770 offset = memaddr & 3;
771
d4b2399a 772 errcode = target_xfer_memory (memaddr & ~3, buf, 4, 0);
c906108c
SS
773 if (errcode != 0)
774 {
775 /* The transfer request might have crossed the boundary to an
776 unallocated region of memory. Retry the transfer, requesting
777 a single byte. */
778 tlen = 1;
779 offset = 0;
d4b2399a 780 errcode = target_xfer_memory (memaddr, buf, 1, 0);
c906108c
SS
781 if (errcode != 0)
782 goto done;
783 }
784
785 if (bufptr - buffer + tlen > buffer_allocated)
786 {
787 unsigned int bytes;
788 bytes = bufptr - buffer;
789 buffer_allocated *= 2;
790 buffer = xrealloc (buffer, buffer_allocated);
791 bufptr = buffer + bytes;
792 }
793
794 for (i = 0; i < tlen; i++)
795 {
796 *bufptr++ = buf[i + offset];
797 if (buf[i + offset] == '\000')
798 {
799 nbytes_read += i + 1;
800 goto done;
801 }
802 }
803
804 memaddr += tlen;
805 len -= tlen;
806 nbytes_read += tlen;
807 }
c5aa993b 808done:
c906108c
SS
809 if (errnop != NULL)
810 *errnop = errcode;
811 if (string != NULL)
812 *string = buffer;
813 return nbytes_read;
814}
815
816/* Read LEN bytes of target memory at address MEMADDR, placing the results in
817 GDB's memory at MYADDR. Returns either 0 for success or an errno value
818 if any error occurs.
819
820 If an error occurs, no guarantee is made about the contents of the data at
821 MYADDR. In particular, the caller should not depend upon partial reads
822 filling the buffer with good data. There is no way for the caller to know
823 how much good data might have been transfered anyway. Callers that can
824 deal with partial reads should call target_read_memory_partial. */
825
826int
fba45db2 827target_read_memory (CORE_ADDR memaddr, char *myaddr, int len)
c906108c 828{
d4b2399a 829 return target_xfer_memory (memaddr, myaddr, len, 0);
c906108c
SS
830}
831
c906108c 832int
fba45db2 833target_write_memory (CORE_ADDR memaddr, char *myaddr, int len)
c906108c 834{
d4b2399a 835 return target_xfer_memory (memaddr, myaddr, len, 1);
c906108c 836}
c5aa993b 837
67e0617e
C
838/* Move memory to or from the targets. The top target gets priority;
839 if it cannot handle it, it is offered to the next one down, etc.
c906108c 840
67e0617e 841 Result is -1 on error, or the number of bytes transfered. */
c906108c 842
4930751a 843int
29e57380
C
844do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
845 struct mem_attrib *attrib)
c906108c 846{
c906108c 847 int res;
4930751a 848 int done = 0;
c906108c
SS
849 struct target_ops *t;
850 struct target_stack_item *item;
851
852 /* Zero length requests are ok and require no work. */
853 if (len == 0)
854 return 0;
855
c906108c
SS
856 /* to_xfer_memory is not guaranteed to set errno, even when it returns
857 0. */
858 errno = 0;
859
67e0617e 860 /* The quick case is that the top target can handle the transfer. */
c906108c 861 res = current_target.to_xfer_memory
29e57380 862 (memaddr, myaddr, len, write, attrib, &current_target);
c906108c 863
67e0617e
C
864 /* If res <= 0 then we call it again in the loop. Ah well. */
865 if (res <= 0)
c906108c 866 {
c906108c
SS
867 for (item = target_stack; item; item = item->next)
868 {
869 t = item->target_ops;
870 if (!t->to_has_memory)
871 continue;
872
29e57380 873 res = t->to_xfer_memory (memaddr, myaddr, len, write, attrib, t);
c906108c
SS
874 if (res > 0)
875 break; /* Handled all or part of xfer */
876 if (t->to_has_all_memory)
877 break;
878 }
879
4930751a 880 if (res <= 0)
67e0617e 881 return -1;
4930751a 882 }
67e0617e
C
883
884 return res;
4930751a
C
885}
886
67e0617e
C
887
888/* Perform a memory transfer. Iterate until the entire region has
889 been transfered.
890
891 Result is 0 or errno value. */
892
4930751a
C
893static int
894target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write)
895{
896 int res;
29e57380
C
897 int reg_len;
898 struct mem_region *region;
4930751a
C
899
900 /* Zero length requests are ok and require no work. */
901 if (len == 0)
902 {
903 return 0;
904 }
905
906 while (len > 0)
907 {
29e57380
C
908 region = lookup_mem_region(memaddr);
909 if (memaddr + len < region->hi)
910 reg_len = len;
911 else
912 reg_len = region->hi - memaddr;
913
914 switch (region->attrib.mode)
c906108c 915 {
29e57380
C
916 case MEM_RO:
917 if (write)
918 return EIO;
919 break;
920
921 case MEM_WO:
c906108c 922 if (!write)
c906108c 923 return EIO;
29e57380 924 break;
c906108c 925 }
4930751a 926
29e57380
C
927 while (reg_len > 0)
928 {
929 if (region->attrib.cache)
930 res = dcache_xfer_memory(target_dcache, memaddr, myaddr,
931 reg_len, write);
932 else
933 res = do_xfer_memory(memaddr, myaddr, reg_len, write,
934 &region->attrib);
935
936 if (res <= 0)
937 {
938 /* If this address is for nonexistent memory, read zeros
939 if reading, or do nothing if writing. Return
940 error. */
941 if (!write)
942 memset (myaddr, 0, len);
943 if (errno == 0)
944 return EIO;
945 else
946 return errno;
947 }
948
949 memaddr += res;
950 myaddr += res;
951 len -= res;
952 reg_len -= res;
953 }
c906108c 954 }
4930751a 955
c906108c
SS
956 return 0; /* We managed to cover it all somehow. */
957}
958
959
67e0617e
C
960/* Perform a partial memory transfer.
961
962 Result is -1 on error, or the number of bytes transfered. */
917317f4
JM
963
964static int
4930751a 965target_xfer_memory_partial (CORE_ADDR memaddr, char *myaddr, int len,
917317f4
JM
966 int write_p, int *err)
967{
968 int res;
29e57380
C
969 int reg_len;
970 struct mem_region *region;
917317f4
JM
971
972 /* Zero length requests are ok and require no work. */
973 if (len == 0)
974 {
975 *err = 0;
976 return 0;
977 }
978
29e57380
C
979 region = lookup_mem_region(memaddr);
980 if (memaddr + len < region->hi)
981 reg_len = len;
982 else
983 reg_len = region->hi - memaddr;
984
985 switch (region->attrib.mode)
986 {
987 case MEM_RO:
988 if (write_p)
989 {
990 *err = EIO;
873406a6 991 return -1;
29e57380
C
992 }
993 break;
994
995 case MEM_WO:
996 if (write_p)
997 {
998 *err = EIO;
873406a6 999 return -1;
29e57380
C
1000 }
1001 break;
1002 }
1003
1004 if (region->attrib.cache)
1005 res = dcache_xfer_memory (target_dcache, memaddr, myaddr,
1006 reg_len, write_p);
1007 else
1008 res = do_xfer_memory (memaddr, myaddr, reg_len, write_p,
1009 &region->attrib);
1010
4930751a 1011 if (res <= 0)
917317f4 1012 {
4930751a
C
1013 if (errno != 0)
1014 *err = errno;
1015 else
1016 *err = EIO;
917317f4 1017
4930751a 1018 return -1;
917317f4
JM
1019 }
1020
4930751a 1021 *err = 0;
67e0617e 1022 return res;
917317f4
JM
1023}
1024
1025int
1026target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1027{
1028 return target_xfer_memory_partial (memaddr, buf, len, 0, err);
1029}
1030
1031int
1032target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1033{
1034 return target_xfer_memory_partial (memaddr, buf, len, 1, err);
1035}
1036
c906108c
SS
1037/* ARGSUSED */
1038static void
fba45db2 1039target_info (char *args, int from_tty)
c906108c
SS
1040{
1041 struct target_ops *t;
1042 struct target_stack_item *item;
1043 int has_all_mem = 0;
c5aa993b 1044
c906108c
SS
1045 if (symfile_objfile != NULL)
1046 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile->name);
1047
1048#ifdef FILES_INFO_HOOK
1049 if (FILES_INFO_HOOK ())
1050 return;
1051#endif
1052
1053 for (item = target_stack; item; item = item->next)
1054 {
1055 t = item->target_ops;
1056
1057 if (!t->to_has_memory)
1058 continue;
1059
c5aa993b 1060 if ((int) (t->to_stratum) <= (int) dummy_stratum)
c906108c
SS
1061 continue;
1062 if (has_all_mem)
c5aa993b
JM
1063 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1064 printf_unfiltered ("%s:\n", t->to_longname);
1065 (t->to_files_info) (t);
c906108c
SS
1066 has_all_mem = t->to_has_all_memory;
1067 }
1068}
1069
1070/* This is to be called by the open routine before it does
1071 anything. */
1072
1073void
fba45db2 1074target_preopen (int from_tty)
c906108c 1075{
c5aa993b 1076 dont_repeat ();
c906108c
SS
1077
1078 if (target_has_execution)
c5aa993b 1079 {
adf40b2e
JM
1080 if (!from_tty
1081 || query ("A program is being debugged already. Kill it? "))
c5aa993b 1082 target_kill ();
c906108c 1083 else
c5aa993b 1084 error ("Program not killed.");
c906108c
SS
1085 }
1086
1087 /* Calling target_kill may remove the target from the stack. But if
1088 it doesn't (which seems like a win for UDI), remove it now. */
1089
1090 if (target_has_execution)
1091 pop_target ();
1092}
1093
1094/* Detach a target after doing deferred register stores. */
1095
1096void
fba45db2 1097target_detach (char *args, int from_tty)
c906108c
SS
1098{
1099 /* Handle any optimized stores to the inferior. */
1100#ifdef DO_DEFERRED_STORES
1101 DO_DEFERRED_STORES;
1102#endif
1103 (current_target.to_detach) (args, from_tty);
1104}
1105
1106void
fba45db2 1107target_link (char *modname, CORE_ADDR *t_reloc)
c906108c 1108{
c5aa993b 1109 if (STREQ (current_target.to_shortname, "rombug"))
c906108c
SS
1110 {
1111 (current_target.to_lookup_symbol) (modname, t_reloc);
1112 if (*t_reloc == 0)
c5aa993b 1113 error ("Unable to link to %s and get relocation in rombug", modname);
c906108c
SS
1114 }
1115 else
2acceee2 1116 *t_reloc = (CORE_ADDR) -1;
c906108c
SS
1117}
1118
ed9a39eb
JM
1119int
1120target_async_mask (int mask)
1121{
1122 int saved_async_masked_status = target_async_mask_value;
1123 target_async_mask_value = mask;
1124 return saved_async_masked_status;
1125}
1126
c906108c
SS
1127/* Look through the list of possible targets for a target that can
1128 execute a run or attach command without any other data. This is
1129 used to locate the default process stratum.
1130
1131 Result is always valid (error() is called for errors). */
1132
1133static struct target_ops *
fba45db2 1134find_default_run_target (char *do_mesg)
c906108c
SS
1135{
1136 struct target_ops **t;
1137 struct target_ops *runable = NULL;
1138 int count;
1139
1140 count = 0;
1141
1142 for (t = target_structs; t < target_structs + target_struct_size;
1143 ++t)
1144 {
c5aa993b 1145 if ((*t)->to_can_run && target_can_run (*t))
c906108c
SS
1146 {
1147 runable = *t;
1148 ++count;
1149 }
1150 }
1151
1152 if (count != 1)
1153 error ("Don't know how to %s. Try \"help target\".", do_mesg);
1154
1155 return runable;
1156}
1157
1158void
fba45db2 1159find_default_attach (char *args, int from_tty)
c906108c
SS
1160{
1161 struct target_ops *t;
1162
c5aa993b 1163 t = find_default_run_target ("attach");
c906108c
SS
1164 (t->to_attach) (args, from_tty);
1165 return;
1166}
1167
1168void
fba45db2 1169find_default_require_attach (char *args, int from_tty)
c906108c
SS
1170{
1171 struct target_ops *t;
1172
c5aa993b 1173 t = find_default_run_target ("require_attach");
c906108c
SS
1174 (t->to_require_attach) (args, from_tty);
1175 return;
1176}
1177
1178void
fba45db2 1179find_default_require_detach (int pid, char *args, int from_tty)
c906108c
SS
1180{
1181 struct target_ops *t;
1182
c5aa993b 1183 t = find_default_run_target ("require_detach");
c906108c
SS
1184 (t->to_require_detach) (pid, args, from_tty);
1185 return;
1186}
1187
1188void
fba45db2 1189find_default_create_inferior (char *exec_file, char *allargs, char **env)
c906108c
SS
1190{
1191 struct target_ops *t;
1192
c5aa993b 1193 t = find_default_run_target ("run");
c906108c
SS
1194 (t->to_create_inferior) (exec_file, allargs, env);
1195 return;
1196}
1197
1198void
fba45db2 1199find_default_clone_and_follow_inferior (int child_pid, int *followed_child)
c906108c
SS
1200{
1201 struct target_ops *t;
1202
c5aa993b 1203 t = find_default_run_target ("run");
c906108c
SS
1204 (t->to_clone_and_follow_inferior) (child_pid, followed_child);
1205 return;
1206}
1207
1208static int
fba45db2 1209return_zero (void)
c906108c
SS
1210{
1211 return 0;
1212}
1213
1214static int
fba45db2 1215return_one (void)
c906108c
SS
1216{
1217 return 1;
1218}
1219
6426a772
JM
1220/*
1221 * Resize the to_sections pointer. Also make sure that anyone that
1222 * was holding on to an old value of it gets updated.
1223 * Returns the old size.
1224 */
1225
1226int
1227target_resize_to_sections (struct target_ops *target, int num_added)
1228{
1229 struct target_ops **t;
1230 struct section_table *old_value;
1231 int old_count;
1232
1233 old_value = target->to_sections;
1234
1235 if (target->to_sections)
1236 {
1237 old_count = target->to_sections_end - target->to_sections;
1238 target->to_sections = (struct section_table *)
1239 xrealloc ((char *) target->to_sections,
1240 (sizeof (struct section_table)) * (num_added + old_count));
1241 }
1242 else
1243 {
1244 old_count = 0;
1245 target->to_sections = (struct section_table *)
1246 xmalloc ((sizeof (struct section_table)) * num_added);
1247 }
1248 target->to_sections_end = target->to_sections + (num_added + old_count);
1249
1250 /* Check to see if anyone else was pointing to this structure.
1251 If old_value was null, then no one was. */
1252
1253 if (old_value)
1254 {
1255 for (t = target_structs; t < target_structs + target_struct_size;
1256 ++t)
1257 {
1258 if ((*t)->to_sections == old_value)
1259 {
1260 (*t)->to_sections = target->to_sections;
1261 (*t)->to_sections_end = target->to_sections_end;
1262 }
1263 }
1264 }
1265
1266 return old_count;
1267
1268}
1269
07cd4b97
JB
1270/* Remove all target sections taken from ABFD.
1271
1272 Scan the current target stack for targets whose section tables
1273 refer to sections from BFD, and remove those sections. We use this
1274 when we notice that the inferior has unloaded a shared object, for
1275 example. */
1276void
1277remove_target_sections (bfd *abfd)
1278{
1279 struct target_ops **t;
1280
1281 for (t = target_structs; t < target_structs + target_struct_size; t++)
1282 {
1283 struct section_table *src, *dest;
1284
1285 dest = (*t)->to_sections;
1286 for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++)
1287 if (src->bfd != abfd)
1288 {
1289 /* Keep this section. */
1290 if (dest < src) *dest = *src;
1291 dest++;
1292 }
1293
1294 /* If we've dropped any sections, resize the section table. */
1295 if (dest < src)
1296 target_resize_to_sections (*t, dest - src);
1297 }
1298}
1299
1300
1301
1302
7a292a7a
SS
1303/* Find a single runnable target in the stack and return it. If for
1304 some reason there is more than one, return NULL. */
1305
1306struct target_ops *
fba45db2 1307find_run_target (void)
7a292a7a
SS
1308{
1309 struct target_ops **t;
1310 struct target_ops *runable = NULL;
1311 int count;
c5aa993b 1312
7a292a7a 1313 count = 0;
c5aa993b 1314
7a292a7a
SS
1315 for (t = target_structs; t < target_structs + target_struct_size; ++t)
1316 {
c5aa993b 1317 if ((*t)->to_can_run && target_can_run (*t))
7a292a7a
SS
1318 {
1319 runable = *t;
1320 ++count;
1321 }
1322 }
c5aa993b 1323
7a292a7a
SS
1324 return (count == 1 ? runable : NULL);
1325}
1326
ed9a39eb
JM
1327/* Find a single core_stratum target in the list of targets and return it.
1328 If for some reason there is more than one, return NULL. */
1329
c906108c 1330struct target_ops *
fba45db2 1331find_core_target (void)
c906108c
SS
1332{
1333 struct target_ops **t;
1334 struct target_ops *runable = NULL;
1335 int count;
c5aa993b 1336
c906108c 1337 count = 0;
c5aa993b 1338
c906108c
SS
1339 for (t = target_structs; t < target_structs + target_struct_size;
1340 ++t)
1341 {
1342 if ((*t)->to_stratum == core_stratum)
1343 {
1344 runable = *t;
1345 ++count;
1346 }
1347 }
c5aa993b
JM
1348
1349 return (count == 1 ? runable : NULL);
c906108c 1350}
ed9a39eb
JM
1351
1352/*
1353 * Find the next target down the stack from the specified target.
1354 */
1355
1356struct target_ops *
fba45db2 1357find_target_beneath (struct target_ops *t)
ed9a39eb
JM
1358{
1359 struct target_stack_item *cur;
1360
1361 for (cur = target_stack; cur; cur = cur->next)
1362 if (cur->target_ops == t)
1363 break;
1364
1365 if (cur == NULL || cur->next == NULL)
1366 return NULL;
1367 else
1368 return cur->next->target_ops;
1369}
1370
c906108c
SS
1371\f
1372/* The inferior process has died. Long live the inferior! */
1373
1374void
fba45db2 1375generic_mourn_inferior (void)
c906108c
SS
1376{
1377 extern int show_breakpoint_hit_counts;
1378
39f77062 1379 inferior_ptid = null_ptid;
c906108c
SS
1380 attach_flag = 0;
1381 breakpoint_init_inferior (inf_exited);
1382 registers_changed ();
1383
1384#ifdef CLEAR_DEFERRED_STORES
1385 /* Delete any pending stores to the inferior... */
1386 CLEAR_DEFERRED_STORES;
1387#endif
1388
1389 reopen_exec_file ();
1390 reinit_frame_cache ();
1391
1392 /* It is confusing to the user for ignore counts to stick around
1393 from previous runs of the inferior. So clear them. */
1394 /* However, it is more confusing for the ignore counts to disappear when
1395 using hit counts. So don't clear them if we're counting hits. */
1396 if (!show_breakpoint_hit_counts)
1397 breakpoint_clear_ignore_counts ();
c5b739b5
FN
1398
1399 if (detach_hook)
1400 detach_hook ();
c906108c
SS
1401}
1402\f
c906108c
SS
1403/* Helper function for child_wait and the Lynx derivatives of child_wait.
1404 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1405 translation of that in OURSTATUS. */
1406void
fba45db2 1407store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus)
c906108c
SS
1408{
1409#ifdef CHILD_SPECIAL_WAITSTATUS
1410 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1411 if it wants to deal with hoststatus. */
1412 if (CHILD_SPECIAL_WAITSTATUS (ourstatus, hoststatus))
1413 return;
1414#endif
1415
1416 if (WIFEXITED (hoststatus))
1417 {
1418 ourstatus->kind = TARGET_WAITKIND_EXITED;
1419 ourstatus->value.integer = WEXITSTATUS (hoststatus);
1420 }
1421 else if (!WIFSTOPPED (hoststatus))
1422 {
1423 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
1424 ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus));
1425 }
1426 else
1427 {
1428 ourstatus->kind = TARGET_WAITKIND_STOPPED;
1429 ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus));
1430 }
1431}
1432\f
c906108c 1433/* Returns zero to leave the inferior alone, one to interrupt it. */
507f3c78 1434int (*target_activity_function) (void);
c906108c
SS
1435int target_activity_fd;
1436\f
1437/* Convert a normal process ID to a string. Returns the string in a static
1438 buffer. */
1439
1440char *
39f77062 1441normal_pid_to_str (ptid_t ptid)
c906108c
SS
1442{
1443 static char buf[30];
1444
39f77062 1445 sprintf (buf, "process %d", PIDGET (ptid));
c906108c
SS
1446 return buf;
1447}
1448
1449/* Some targets (such as ttrace-based HPUX) don't allow us to request
1450 notification of inferior events such as fork and vork immediately
1451 after the inferior is created. (This because of how gdb gets an
1452 inferior created via invoking a shell to do it. In such a scenario,
1453 if the shell init file has commands in it, the shell will fork and
1454 exec for each of those commands, and we will see each such fork
1455 event. Very bad.)
c5aa993b 1456
c906108c
SS
1457 This function is used by all targets that allow us to request
1458 notification of forks, etc at inferior creation time; e.g., in
1459 target_acknowledge_forked_child.
c5aa993b 1460 */
392a587b 1461static void
39f77062 1462normal_target_post_startup_inferior (ptid_t ptid)
c906108c
SS
1463{
1464 /* This space intentionally left blank. */
1465}
1466
be4d1333
MS
1467/* Error-catcher for target_find_memory_regions */
1468/* ARGSUSED */
1469static int dummy_find_memory_regions (int (*ignore1) (), void *ignore2)
1470{
1471 error ("No target.");
1472 return 0;
1473}
1474
1475/* Error-catcher for target_make_corefile_notes */
1476/* ARGSUSED */
1477static char * dummy_make_corefile_notes (bfd *ignore1, int *ignore2)
1478{
1479 error ("No target.");
1480 return NULL;
1481}
1482
c906108c
SS
1483/* Set up the handful of non-empty slots needed by the dummy target
1484 vector. */
1485
1486static void
fba45db2 1487init_dummy_target (void)
c906108c
SS
1488{
1489 dummy_target.to_shortname = "None";
1490 dummy_target.to_longname = "None";
1491 dummy_target.to_doc = "";
1492 dummy_target.to_attach = find_default_attach;
1493 dummy_target.to_require_attach = find_default_require_attach;
1494 dummy_target.to_require_detach = find_default_require_detach;
1495 dummy_target.to_create_inferior = find_default_create_inferior;
1496 dummy_target.to_clone_and_follow_inferior = find_default_clone_and_follow_inferior;
ed9a39eb 1497 dummy_target.to_pid_to_str = normal_pid_to_str;
c906108c 1498 dummy_target.to_stratum = dummy_stratum;
be4d1333
MS
1499 dummy_target.to_find_memory_regions = dummy_find_memory_regions;
1500 dummy_target.to_make_corefile_notes = dummy_make_corefile_notes;
c906108c
SS
1501 dummy_target.to_magic = OPS_MAGIC;
1502}
c906108c 1503\f
c5aa993b 1504
c906108c
SS
1505static struct target_ops debug_target;
1506
1507static void
fba45db2 1508debug_to_open (char *args, int from_tty)
c906108c
SS
1509{
1510 debug_target.to_open (args, from_tty);
1511
96baa820 1512 fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty);
c906108c
SS
1513}
1514
1515static void
fba45db2 1516debug_to_close (int quitting)
c906108c
SS
1517{
1518 debug_target.to_close (quitting);
1519
96baa820 1520 fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting);
c906108c
SS
1521}
1522
1523static void
fba45db2 1524debug_to_attach (char *args, int from_tty)
c906108c
SS
1525{
1526 debug_target.to_attach (args, from_tty);
1527
96baa820 1528 fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty);
c906108c
SS
1529}
1530
1531
1532static void
fba45db2 1533debug_to_post_attach (int pid)
c906108c
SS
1534{
1535 debug_target.to_post_attach (pid);
1536
96baa820 1537 fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid);
c906108c
SS
1538}
1539
1540static void
fba45db2 1541debug_to_require_attach (char *args, int from_tty)
c906108c
SS
1542{
1543 debug_target.to_require_attach (args, from_tty);
1544
96baa820 1545 fprintf_unfiltered (gdb_stdlog,
c906108c
SS
1546 "target_require_attach (%s, %d)\n", args, from_tty);
1547}
1548
1549static void
fba45db2 1550debug_to_detach (char *args, int from_tty)
c906108c
SS
1551{
1552 debug_target.to_detach (args, from_tty);
1553
96baa820 1554 fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty);
c906108c
SS
1555}
1556
1557static void
fba45db2 1558debug_to_require_detach (int pid, char *args, int from_tty)
c906108c
SS
1559{
1560 debug_target.to_require_detach (pid, args, from_tty);
1561
96baa820 1562 fprintf_unfiltered (gdb_stdlog,
c5aa993b 1563 "target_require_detach (%d, %s, %d)\n", pid, args, from_tty);
c906108c
SS
1564}
1565
1566static void
39f77062 1567debug_to_resume (ptid_t ptid, int step, enum target_signal siggnal)
c906108c 1568{
39f77062 1569 debug_target.to_resume (ptid, step, siggnal);
c906108c 1570
39f77062 1571 fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", PIDGET (ptid),
c906108c
SS
1572 step ? "step" : "continue",
1573 target_signal_to_name (siggnal));
1574}
1575
39f77062
KB
1576static ptid_t
1577debug_to_wait (ptid_t ptid, struct target_waitstatus *status)
c906108c 1578{
39f77062 1579 ptid_t retval;
c906108c 1580
39f77062 1581 retval = debug_target.to_wait (ptid, status);
c906108c 1582
96baa820 1583 fprintf_unfiltered (gdb_stdlog,
39f77062
KB
1584 "target_wait (%d, status) = %d, ", PIDGET (ptid),
1585 PIDGET (retval));
96baa820 1586 fprintf_unfiltered (gdb_stdlog, "status->kind = ");
c906108c
SS
1587 switch (status->kind)
1588 {
1589 case TARGET_WAITKIND_EXITED:
96baa820 1590 fprintf_unfiltered (gdb_stdlog, "exited, status = %d\n",
c906108c
SS
1591 status->value.integer);
1592 break;
1593 case TARGET_WAITKIND_STOPPED:
96baa820 1594 fprintf_unfiltered (gdb_stdlog, "stopped, signal = %s\n",
c906108c
SS
1595 target_signal_to_name (status->value.sig));
1596 break;
1597 case TARGET_WAITKIND_SIGNALLED:
96baa820 1598 fprintf_unfiltered (gdb_stdlog, "signalled, signal = %s\n",
c906108c
SS
1599 target_signal_to_name (status->value.sig));
1600 break;
1601 case TARGET_WAITKIND_LOADED:
96baa820 1602 fprintf_unfiltered (gdb_stdlog, "loaded\n");
c906108c
SS
1603 break;
1604 case TARGET_WAITKIND_FORKED:
96baa820 1605 fprintf_unfiltered (gdb_stdlog, "forked\n");
c906108c
SS
1606 break;
1607 case TARGET_WAITKIND_VFORKED:
96baa820 1608 fprintf_unfiltered (gdb_stdlog, "vforked\n");
c906108c
SS
1609 break;
1610 case TARGET_WAITKIND_EXECD:
96baa820 1611 fprintf_unfiltered (gdb_stdlog, "execd\n");
c906108c
SS
1612 break;
1613 case TARGET_WAITKIND_SPURIOUS:
96baa820 1614 fprintf_unfiltered (gdb_stdlog, "spurious\n");
c906108c
SS
1615 break;
1616 default:
96baa820 1617 fprintf_unfiltered (gdb_stdlog, "unknown???\n");
c906108c
SS
1618 break;
1619 }
1620
1621 return retval;
1622}
1623
1624static void
39f77062 1625debug_to_post_wait (ptid_t ptid, int status)
c906108c 1626{
39f77062 1627 debug_target.to_post_wait (ptid, status);
c906108c 1628
96baa820 1629 fprintf_unfiltered (gdb_stdlog, "target_post_wait (%d, %d)\n",
39f77062 1630 PIDGET (ptid), status);
c906108c
SS
1631}
1632
1633static void
fba45db2 1634debug_to_fetch_registers (int regno)
c906108c
SS
1635{
1636 debug_target.to_fetch_registers (regno);
1637
96baa820 1638 fprintf_unfiltered (gdb_stdlog, "target_fetch_registers (%s)",
c906108c
SS
1639 regno != -1 ? REGISTER_NAME (regno) : "-1");
1640 if (regno != -1)
104c1213 1641 fprintf_unfiltered (gdb_stdlog, " = 0x%lx %ld",
c906108c 1642 (unsigned long) read_register (regno),
104c1213 1643 (unsigned long) read_register (regno));
96baa820 1644 fprintf_unfiltered (gdb_stdlog, "\n");
c906108c
SS
1645}
1646
1647static void
fba45db2 1648debug_to_store_registers (int regno)
c906108c
SS
1649{
1650 debug_target.to_store_registers (regno);
1651
1652 if (regno >= 0 && regno < NUM_REGS)
104c1213 1653 fprintf_unfiltered (gdb_stdlog, "target_store_registers (%s) = 0x%lx %ld\n",
c906108c
SS
1654 REGISTER_NAME (regno),
1655 (unsigned long) read_register (regno),
1656 (unsigned long) read_register (regno));
1657 else
96baa820 1658 fprintf_unfiltered (gdb_stdlog, "target_store_registers (%d)\n", regno);
c906108c
SS
1659}
1660
1661static void
fba45db2 1662debug_to_prepare_to_store (void)
c906108c
SS
1663{
1664 debug_target.to_prepare_to_store ();
1665
96baa820 1666 fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n");
c906108c
SS
1667}
1668
1669static int
fba45db2 1670debug_to_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
29e57380 1671 struct mem_attrib *attrib,
fba45db2 1672 struct target_ops *target)
c906108c
SS
1673{
1674 int retval;
1675
29e57380
C
1676 retval = debug_target.to_xfer_memory (memaddr, myaddr, len, write,
1677 attrib, target);
c906108c 1678
96baa820 1679 fprintf_unfiltered (gdb_stdlog,
c906108c 1680 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
c5aa993b 1681 (unsigned int) memaddr, /* possable truncate long long */
c906108c
SS
1682 len, write ? "write" : "read", retval);
1683
c5aa993b 1684
c906108c
SS
1685
1686 if (retval > 0)
1687 {
1688 int i;
1689
96baa820 1690 fputs_unfiltered (", bytes =", gdb_stdlog);
c906108c
SS
1691 for (i = 0; i < retval; i++)
1692 {
1693 if ((((long) &(myaddr[i])) & 0xf) == 0)
96baa820
JM
1694 fprintf_unfiltered (gdb_stdlog, "\n");
1695 fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff);
c906108c
SS
1696 }
1697 }
1698
96baa820 1699 fputc_unfiltered ('\n', gdb_stdlog);
c906108c
SS
1700
1701 return retval;
1702}
1703
1704static void
fba45db2 1705debug_to_files_info (struct target_ops *target)
c906108c
SS
1706{
1707 debug_target.to_files_info (target);
1708
96baa820 1709 fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n");
c906108c
SS
1710}
1711
1712static int
fba45db2 1713debug_to_insert_breakpoint (CORE_ADDR addr, char *save)
c906108c
SS
1714{
1715 int retval;
1716
1717 retval = debug_target.to_insert_breakpoint (addr, save);
1718
96baa820 1719 fprintf_unfiltered (gdb_stdlog,
104c1213
JM
1720 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
1721 (unsigned long) addr,
1722 (unsigned long) retval);
c906108c
SS
1723 return retval;
1724}
1725
1726static int
fba45db2 1727debug_to_remove_breakpoint (CORE_ADDR addr, char *save)
c906108c
SS
1728{
1729 int retval;
1730
1731 retval = debug_target.to_remove_breakpoint (addr, save);
1732
96baa820 1733 fprintf_unfiltered (gdb_stdlog,
104c1213
JM
1734 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
1735 (unsigned long) addr,
1736 (unsigned long) retval);
c906108c
SS
1737 return retval;
1738}
1739
1740static void
fba45db2 1741debug_to_terminal_init (void)
c906108c
SS
1742{
1743 debug_target.to_terminal_init ();
1744
96baa820 1745 fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n");
c906108c
SS
1746}
1747
1748static void
fba45db2 1749debug_to_terminal_inferior (void)
c906108c
SS
1750{
1751 debug_target.to_terminal_inferior ();
1752
96baa820 1753 fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n");
c906108c
SS
1754}
1755
1756static void
fba45db2 1757debug_to_terminal_ours_for_output (void)
c906108c
SS
1758{
1759 debug_target.to_terminal_ours_for_output ();
1760
96baa820 1761 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n");
c906108c
SS
1762}
1763
1764static void
fba45db2 1765debug_to_terminal_ours (void)
c906108c
SS
1766{
1767 debug_target.to_terminal_ours ();
1768
96baa820 1769 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n");
c906108c
SS
1770}
1771
1772static void
fba45db2 1773debug_to_terminal_info (char *arg, int from_tty)
c906108c
SS
1774{
1775 debug_target.to_terminal_info (arg, from_tty);
1776
96baa820 1777 fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg,
c906108c
SS
1778 from_tty);
1779}
1780
1781static void
fba45db2 1782debug_to_kill (void)
c906108c
SS
1783{
1784 debug_target.to_kill ();
1785
96baa820 1786 fprintf_unfiltered (gdb_stdlog, "target_kill ()\n");
c906108c
SS
1787}
1788
1789static void
fba45db2 1790debug_to_load (char *args, int from_tty)
c906108c
SS
1791{
1792 debug_target.to_load (args, from_tty);
1793
96baa820 1794 fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty);
c906108c
SS
1795}
1796
1797static int
fba45db2 1798debug_to_lookup_symbol (char *name, CORE_ADDR *addrp)
c906108c
SS
1799{
1800 int retval;
1801
1802 retval = debug_target.to_lookup_symbol (name, addrp);
1803
96baa820 1804 fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name);
c906108c
SS
1805
1806 return retval;
1807}
1808
1809static void
fba45db2 1810debug_to_create_inferior (char *exec_file, char *args, char **env)
c906108c
SS
1811{
1812 debug_target.to_create_inferior (exec_file, args, env);
1813
96baa820 1814 fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx)\n",
c906108c
SS
1815 exec_file, args);
1816}
1817
1818static void
39f77062 1819debug_to_post_startup_inferior (ptid_t ptid)
c906108c 1820{
39f77062 1821 debug_target.to_post_startup_inferior (ptid);
c906108c 1822
96baa820 1823 fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n",
39f77062 1824 PIDGET (ptid));
c906108c
SS
1825}
1826
1827static void
fba45db2 1828debug_to_acknowledge_created_inferior (int pid)
c906108c
SS
1829{
1830 debug_target.to_acknowledge_created_inferior (pid);
1831
96baa820 1832 fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n",
c906108c
SS
1833 pid);
1834}
1835
1836static void
fba45db2 1837debug_to_clone_and_follow_inferior (int child_pid, int *followed_child)
c906108c
SS
1838{
1839 debug_target.to_clone_and_follow_inferior (child_pid, followed_child);
1840
96baa820 1841 fprintf_unfiltered (gdb_stdlog,
c906108c
SS
1842 "target_clone_and_follow_inferior (%d, %d)\n",
1843 child_pid, *followed_child);
1844}
1845
1846static void
fba45db2 1847debug_to_post_follow_inferior_by_clone (void)
c906108c
SS
1848{
1849 debug_target.to_post_follow_inferior_by_clone ();
1850
96baa820 1851 fprintf_unfiltered (gdb_stdlog, "target_post_follow_inferior_by_clone ()\n");
c906108c
SS
1852}
1853
1854static int
fba45db2 1855debug_to_insert_fork_catchpoint (int pid)
c906108c 1856{
c5aa993b 1857 int retval;
c906108c
SS
1858
1859 retval = debug_target.to_insert_fork_catchpoint (pid);
1860
96baa820 1861 fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d) = %d\n",
c5aa993b 1862 pid, retval);
c906108c
SS
1863
1864 return retval;
1865}
1866
1867static int
fba45db2 1868debug_to_remove_fork_catchpoint (int pid)
c906108c 1869{
c5aa993b 1870 int retval;
c906108c
SS
1871
1872 retval = debug_target.to_remove_fork_catchpoint (pid);
1873
96baa820 1874 fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n",
c5aa993b 1875 pid, retval);
c906108c
SS
1876
1877 return retval;
1878}
1879
1880static int
fba45db2 1881debug_to_insert_vfork_catchpoint (int pid)
c906108c 1882{
c5aa993b 1883 int retval;
c906108c
SS
1884
1885 retval = debug_target.to_insert_vfork_catchpoint (pid);
1886
96baa820 1887 fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)= %d\n",
c5aa993b 1888 pid, retval);
c906108c
SS
1889
1890 return retval;
1891}
1892
1893static int
fba45db2 1894debug_to_remove_vfork_catchpoint (int pid)
c906108c 1895{
c5aa993b 1896 int retval;
c906108c
SS
1897
1898 retval = debug_target.to_remove_vfork_catchpoint (pid);
1899
96baa820 1900 fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n",
c5aa993b 1901 pid, retval);
c906108c
SS
1902
1903 return retval;
1904}
1905
1906static int
fba45db2 1907debug_to_has_forked (int pid, int *child_pid)
c906108c 1908{
c5aa993b 1909 int has_forked;
c906108c
SS
1910
1911 has_forked = debug_target.to_has_forked (pid, child_pid);
1912
96baa820 1913 fprintf_unfiltered (gdb_stdlog, "target_has_forked (%d, %d) = %d\n",
c5aa993b 1914 pid, *child_pid, has_forked);
c906108c
SS
1915
1916 return has_forked;
1917}
1918
1919static int
fba45db2 1920debug_to_has_vforked (int pid, int *child_pid)
c906108c 1921{
c5aa993b 1922 int has_vforked;
c906108c
SS
1923
1924 has_vforked = debug_target.to_has_vforked (pid, child_pid);
1925
96baa820 1926 fprintf_unfiltered (gdb_stdlog, "target_has_vforked (%d, %d) = %d\n",
c5aa993b 1927 pid, *child_pid, has_vforked);
c906108c
SS
1928
1929 return has_vforked;
1930}
1931
1932static int
fba45db2 1933debug_to_can_follow_vfork_prior_to_exec (void)
c906108c 1934{
c5aa993b 1935 int can_immediately_follow_vfork;
c906108c
SS
1936
1937 can_immediately_follow_vfork = debug_target.to_can_follow_vfork_prior_to_exec ();
1938
96baa820 1939 fprintf_unfiltered (gdb_stdlog, "target_can_follow_vfork_prior_to_exec () = %d\n",
c5aa993b 1940 can_immediately_follow_vfork);
c906108c
SS
1941
1942 return can_immediately_follow_vfork;
1943}
1944
1945static void
fba45db2
KB
1946debug_to_post_follow_vfork (int parent_pid, int followed_parent, int child_pid,
1947 int followed_child)
c906108c
SS
1948{
1949 debug_target.to_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child);
1950
96baa820 1951 fprintf_unfiltered (gdb_stdlog,
c906108c 1952 "target_post_follow_vfork (%d, %d, %d, %d)\n",
c5aa993b 1953 parent_pid, followed_parent, child_pid, followed_child);
c906108c
SS
1954}
1955
1956static int
fba45db2 1957debug_to_insert_exec_catchpoint (int pid)
c906108c 1958{
c5aa993b 1959 int retval;
c906108c
SS
1960
1961 retval = debug_target.to_insert_exec_catchpoint (pid);
1962
96baa820 1963 fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d) = %d\n",
c5aa993b 1964 pid, retval);
c906108c
SS
1965
1966 return retval;
1967}
1968
1969static int
fba45db2 1970debug_to_remove_exec_catchpoint (int pid)
c906108c 1971{
c5aa993b 1972 int retval;
c906108c
SS
1973
1974 retval = debug_target.to_remove_exec_catchpoint (pid);
1975
96baa820 1976 fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n",
c5aa993b 1977 pid, retval);
c906108c
SS
1978
1979 return retval;
1980}
1981
1982static int
fba45db2 1983debug_to_has_execd (int pid, char **execd_pathname)
c906108c 1984{
c5aa993b 1985 int has_execd;
c906108c
SS
1986
1987 has_execd = debug_target.to_has_execd (pid, execd_pathname);
1988
96baa820 1989 fprintf_unfiltered (gdb_stdlog, "target_has_execd (%d, %s) = %d\n",
c5aa993b 1990 pid, (*execd_pathname ? *execd_pathname : "<NULL>"),
7a292a7a 1991 has_execd);
c906108c
SS
1992
1993 return has_execd;
1994}
1995
1996static int
fba45db2 1997debug_to_reported_exec_events_per_exec_call (void)
c906108c 1998{
c5aa993b 1999 int reported_exec_events;
c906108c
SS
2000
2001 reported_exec_events = debug_target.to_reported_exec_events_per_exec_call ();
2002
96baa820 2003 fprintf_unfiltered (gdb_stdlog,
c906108c 2004 "target_reported_exec_events_per_exec_call () = %d\n",
c5aa993b 2005 reported_exec_events);
c906108c
SS
2006
2007 return reported_exec_events;
2008}
2009
2010static int
fba45db2
KB
2011debug_to_has_syscall_event (int pid, enum target_waitkind *kind,
2012 int *syscall_id)
c906108c 2013{
c5aa993b
JM
2014 int has_syscall_event;
2015 char *kind_spelling = "??";
c906108c
SS
2016
2017 has_syscall_event = debug_target.to_has_syscall_event (pid, kind, syscall_id);
2018 if (has_syscall_event)
2019 {
2020 switch (*kind)
c5aa993b
JM
2021 {
2022 case TARGET_WAITKIND_SYSCALL_ENTRY:
2023 kind_spelling = "SYSCALL_ENTRY";
2024 break;
2025 case TARGET_WAITKIND_SYSCALL_RETURN:
2026 kind_spelling = "SYSCALL_RETURN";
2027 break;
2028 default:
2029 break;
2030 }
c906108c
SS
2031 }
2032
96baa820 2033 fprintf_unfiltered (gdb_stdlog,
c906108c 2034 "target_has_syscall_event (%d, %s, %d) = %d\n",
c5aa993b 2035 pid, kind_spelling, *syscall_id, has_syscall_event);
c906108c
SS
2036
2037 return has_syscall_event;
2038}
2039
2040static int
fba45db2 2041debug_to_has_exited (int pid, int wait_status, int *exit_status)
c906108c 2042{
c5aa993b 2043 int has_exited;
c906108c
SS
2044
2045 has_exited = debug_target.to_has_exited (pid, wait_status, exit_status);
2046
96baa820 2047 fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n",
c5aa993b 2048 pid, wait_status, *exit_status, has_exited);
c906108c
SS
2049
2050 return has_exited;
2051}
2052
2053static void
fba45db2 2054debug_to_mourn_inferior (void)
c906108c
SS
2055{
2056 debug_target.to_mourn_inferior ();
2057
96baa820 2058 fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n");
c906108c
SS
2059}
2060
2061static int
fba45db2 2062debug_to_can_run (void)
c906108c
SS
2063{
2064 int retval;
2065
2066 retval = debug_target.to_can_run ();
2067
96baa820 2068 fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval);
c906108c
SS
2069
2070 return retval;
2071}
2072
2073static void
39f77062 2074debug_to_notice_signals (ptid_t ptid)
c906108c 2075{
39f77062 2076 debug_target.to_notice_signals (ptid);
c906108c 2077
39f77062
KB
2078 fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n",
2079 PIDGET (ptid));
c906108c
SS
2080}
2081
2082static int
39f77062 2083debug_to_thread_alive (ptid_t ptid)
c906108c
SS
2084{
2085 int retval;
2086
39f77062 2087 retval = debug_target.to_thread_alive (ptid);
c906108c 2088
96baa820 2089 fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n",
39f77062 2090 PIDGET (ptid), retval);
c906108c
SS
2091
2092 return retval;
2093}
2094
0d06e24b 2095static void
fba45db2 2096debug_to_find_new_threads (void)
0d06e24b
JM
2097{
2098 debug_target.to_find_new_threads ();
2099
2100 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog);
2101}
2102
c906108c 2103static void
fba45db2 2104debug_to_stop (void)
c906108c
SS
2105{
2106 debug_target.to_stop ();
2107
96baa820 2108 fprintf_unfiltered (gdb_stdlog, "target_stop ()\n");
c906108c
SS
2109}
2110
2111static int
fba45db2 2112debug_to_query (int type, char *req, char *resp, int *siz)
c906108c
SS
2113{
2114 int retval;
2115
2116 retval = debug_target.to_query (type, req, resp, siz);
2117
96baa820 2118 fprintf_unfiltered (gdb_stdlog, "target_query (%c, %s, %s, %d) = %d\n", type, req, resp, *siz, retval);
c906108c
SS
2119
2120 return retval;
2121}
2122
96baa820
JM
2123static void
2124debug_to_rcmd (char *command,
d9fcf2fb 2125 struct ui_file *outbuf)
96baa820
JM
2126{
2127 debug_target.to_rcmd (command, outbuf);
2128 fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command);
2129}
2130
c906108c 2131static struct symtab_and_line *
fba45db2 2132debug_to_enable_exception_callback (enum exception_event_kind kind, int enable)
c906108c 2133{
7a292a7a
SS
2134 struct symtab_and_line *result;
2135 result = debug_target.to_enable_exception_callback (kind, enable);
96baa820 2136 fprintf_unfiltered (gdb_stdlog,
c906108c
SS
2137 "target get_exception_callback_sal (%d, %d)\n",
2138 kind, enable);
7a292a7a 2139 return result;
c906108c
SS
2140}
2141
2142static struct exception_event_record *
fba45db2 2143debug_to_get_current_exception_event (void)
c906108c 2144{
7a292a7a 2145 struct exception_event_record *result;
c5aa993b 2146 result = debug_target.to_get_current_exception_event ();
96baa820 2147 fprintf_unfiltered (gdb_stdlog, "target get_current_exception_event ()\n");
7a292a7a 2148 return result;
c906108c
SS
2149}
2150
2151static char *
fba45db2 2152debug_to_pid_to_exec_file (int pid)
c906108c 2153{
c5aa993b 2154 char *exec_file;
c906108c
SS
2155
2156 exec_file = debug_target.to_pid_to_exec_file (pid);
2157
96baa820 2158 fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n",
c5aa993b 2159 pid, exec_file);
c906108c
SS
2160
2161 return exec_file;
2162}
2163
c906108c 2164static void
fba45db2 2165setup_target_debug (void)
c906108c
SS
2166{
2167 memcpy (&debug_target, &current_target, sizeof debug_target);
2168
2169 current_target.to_open = debug_to_open;
2170 current_target.to_close = debug_to_close;
2171 current_target.to_attach = debug_to_attach;
2172 current_target.to_post_attach = debug_to_post_attach;
2173 current_target.to_require_attach = debug_to_require_attach;
2174 current_target.to_detach = debug_to_detach;
2175 current_target.to_require_detach = debug_to_require_detach;
2176 current_target.to_resume = debug_to_resume;
2177 current_target.to_wait = debug_to_wait;
2178 current_target.to_post_wait = debug_to_post_wait;
2179 current_target.to_fetch_registers = debug_to_fetch_registers;
2180 current_target.to_store_registers = debug_to_store_registers;
2181 current_target.to_prepare_to_store = debug_to_prepare_to_store;
2182 current_target.to_xfer_memory = debug_to_xfer_memory;
2183 current_target.to_files_info = debug_to_files_info;
2184 current_target.to_insert_breakpoint = debug_to_insert_breakpoint;
2185 current_target.to_remove_breakpoint = debug_to_remove_breakpoint;
2186 current_target.to_terminal_init = debug_to_terminal_init;
2187 current_target.to_terminal_inferior = debug_to_terminal_inferior;
2188 current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output;
2189 current_target.to_terminal_ours = debug_to_terminal_ours;
2190 current_target.to_terminal_info = debug_to_terminal_info;
2191 current_target.to_kill = debug_to_kill;
2192 current_target.to_load = debug_to_load;
2193 current_target.to_lookup_symbol = debug_to_lookup_symbol;
2194 current_target.to_create_inferior = debug_to_create_inferior;
2195 current_target.to_post_startup_inferior = debug_to_post_startup_inferior;
2196 current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior;
2197 current_target.to_clone_and_follow_inferior = debug_to_clone_and_follow_inferior;
2198 current_target.to_post_follow_inferior_by_clone = debug_to_post_follow_inferior_by_clone;
2199 current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint;
2200 current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
2201 current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
2202 current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint;
2203 current_target.to_has_forked = debug_to_has_forked;
2204 current_target.to_has_vforked = debug_to_has_vforked;
2205 current_target.to_can_follow_vfork_prior_to_exec = debug_to_can_follow_vfork_prior_to_exec;
2206 current_target.to_post_follow_vfork = debug_to_post_follow_vfork;
2207 current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint;
2208 current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
2209 current_target.to_has_execd = debug_to_has_execd;
2210 current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call;
2211 current_target.to_has_syscall_event = debug_to_has_syscall_event;
2212 current_target.to_has_exited = debug_to_has_exited;
2213 current_target.to_mourn_inferior = debug_to_mourn_inferior;
2214 current_target.to_can_run = debug_to_can_run;
2215 current_target.to_notice_signals = debug_to_notice_signals;
2216 current_target.to_thread_alive = debug_to_thread_alive;
0d06e24b 2217 current_target.to_find_new_threads = debug_to_find_new_threads;
c906108c
SS
2218 current_target.to_stop = debug_to_stop;
2219 current_target.to_query = debug_to_query;
96baa820 2220 current_target.to_rcmd = debug_to_rcmd;
c906108c
SS
2221 current_target.to_enable_exception_callback = debug_to_enable_exception_callback;
2222 current_target.to_get_current_exception_event = debug_to_get_current_exception_event;
2223 current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
c906108c
SS
2224
2225}
c906108c 2226\f
c5aa993b
JM
2227
2228static char targ_desc[] =
2229"Names of targets and files being debugged.\n\
c906108c
SS
2230Shows the entire stack of targets currently in use (including the exec-file,\n\
2231core-file, and process, if any), as well as the symbol file name.";
2232
96baa820
JM
2233static void
2234do_monitor_command (char *cmd,
2235 int from_tty)
2236{
2b5fe715
AC
2237 if ((current_target.to_rcmd
2238 == (void (*) (char *, struct ui_file *)) tcomplain)
96baa820 2239 || (current_target.to_rcmd == debug_to_rcmd
2b5fe715
AC
2240 && (debug_target.to_rcmd
2241 == (void (*) (char *, struct ui_file *)) tcomplain)))
96baa820
JM
2242 {
2243 error ("\"monitor\" command not supported by this target.\n");
2244 }
2245 target_rcmd (cmd, gdb_stdtarg);
2246}
2247
c906108c 2248void
fba45db2 2249initialize_targets (void)
c906108c
SS
2250{
2251 init_dummy_target ();
2252 push_target (&dummy_target);
2253
2254 add_info ("target", target_info, targ_desc);
2255 add_info ("files", target_info, targ_desc);
2256
c906108c 2257 add_show_from_set (
5d161b24 2258 add_set_cmd ("target", class_maintenance, var_zinteger,
c5aa993b
JM
2259 (char *) &targetdebug,
2260 "Set target debugging.\n\
5d161b24
DB
2261When non-zero, target debugging is enabled.", &setdebuglist),
2262 &showdebuglist);
c906108c 2263
96baa820
JM
2264
2265 add_com ("monitor", class_obscure, do_monitor_command,
2266 "Send a command to the remote monitor (remote targets only).");
2267
4930751a 2268 target_dcache = dcache_init();
c906108c 2269}
This page took 0.317212 seconds and 4 git commands to generate.