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