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