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