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