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