2003-10-17 Andrew Cagney <cagney@redhat.com>
[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 /* Find a section containing ADDR. */
818 struct section_table *
819 target_section_by_addr (struct target_ops *target, CORE_ADDR addr)
820 {
821 struct section_table *secp;
822 for (secp = target->to_sections;
823 secp < target->to_sections_end;
824 secp++)
825 {
826 if (addr >= secp->addr && addr < secp->endaddr)
827 return secp;
828 }
829 return NULL;
830 }
831
832 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
833 GDB's memory at MYADDR. Returns either 0 for success or an errno value
834 if any error occurs.
835
836 If an error occurs, no guarantee is made about the contents of the data at
837 MYADDR. In particular, the caller should not depend upon partial reads
838 filling the buffer with good data. There is no way for the caller to know
839 how much good data might have been transfered anyway. Callers that can
840 deal with partial reads should call target_read_memory_partial. */
841
842 int
843 target_read_memory (CORE_ADDR memaddr, char *myaddr, int len)
844 {
845 return target_xfer_memory (memaddr, myaddr, len, 0);
846 }
847
848 int
849 target_write_memory (CORE_ADDR memaddr, char *myaddr, int len)
850 {
851 return target_xfer_memory (memaddr, myaddr, len, 1);
852 }
853
854 static int trust_readonly = 0;
855
856 /* Move memory to or from the targets. The top target gets priority;
857 if it cannot handle it, it is offered to the next one down, etc.
858
859 Result is -1 on error, or the number of bytes transfered. */
860
861 int
862 do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
863 struct mem_attrib *attrib)
864 {
865 int res;
866 int done = 0;
867 struct target_ops *t;
868
869 /* Zero length requests are ok and require no work. */
870 if (len == 0)
871 return 0;
872
873 /* to_xfer_memory is not guaranteed to set errno, even when it returns
874 0. */
875 errno = 0;
876
877 if (!write && trust_readonly)
878 {
879 struct section_table *secp;
880 /* User-settable option, "trust-readonly-sections". If true,
881 then memory from any SEC_READONLY bfd section may be read
882 directly from the bfd file. */
883 secp = target_section_by_addr (&current_target, memaddr);
884 if (secp != NULL
885 && (bfd_get_section_flags (secp->bfd, secp->the_bfd_section)
886 & SEC_READONLY))
887 return xfer_memory (memaddr, myaddr, len, 0, attrib, &current_target);
888 }
889
890 /* The quick case is that the top target can handle the transfer. */
891 res = current_target.to_xfer_memory
892 (memaddr, myaddr, len, write, attrib, &current_target);
893
894 /* If res <= 0 then we call it again in the loop. Ah well. */
895 if (res <= 0)
896 {
897 for (t = target_stack; t != NULL; t = t->beneath)
898 {
899 if (!t->to_has_memory)
900 continue;
901
902 res = t->to_xfer_memory (memaddr, myaddr, len, write, attrib, t);
903 if (res > 0)
904 break; /* Handled all or part of xfer */
905 if (t->to_has_all_memory)
906 break;
907 }
908
909 if (res <= 0)
910 return -1;
911 }
912
913 return res;
914 }
915
916
917 /* Perform a memory transfer. Iterate until the entire region has
918 been transfered.
919
920 Result is 0 or errno value. */
921
922 static int
923 target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write)
924 {
925 int res;
926 int reg_len;
927 struct mem_region *region;
928
929 /* Zero length requests are ok and require no work. */
930 if (len == 0)
931 {
932 return 0;
933 }
934
935 while (len > 0)
936 {
937 region = lookup_mem_region(memaddr);
938 if (memaddr + len < region->hi)
939 reg_len = len;
940 else
941 reg_len = region->hi - memaddr;
942
943 switch (region->attrib.mode)
944 {
945 case MEM_RO:
946 if (write)
947 return EIO;
948 break;
949
950 case MEM_WO:
951 if (!write)
952 return EIO;
953 break;
954 }
955
956 while (reg_len > 0)
957 {
958 if (region->attrib.cache)
959 res = dcache_xfer_memory (target_dcache, memaddr, myaddr,
960 reg_len, write);
961 else
962 res = do_xfer_memory (memaddr, myaddr, reg_len, write,
963 &region->attrib);
964
965 if (res <= 0)
966 {
967 /* If this address is for nonexistent memory, read zeros
968 if reading, or do nothing if writing. Return
969 error. */
970 if (!write)
971 memset (myaddr, 0, len);
972 if (errno == 0)
973 return EIO;
974 else
975 return errno;
976 }
977
978 memaddr += res;
979 myaddr += res;
980 len -= res;
981 reg_len -= res;
982 }
983 }
984
985 return 0; /* We managed to cover it all somehow. */
986 }
987
988
989 /* Perform a partial memory transfer.
990
991 Result is -1 on error, or the number of bytes transfered. */
992
993 static int
994 target_xfer_memory_partial (CORE_ADDR memaddr, char *myaddr, int len,
995 int write_p, int *err)
996 {
997 int res;
998 int reg_len;
999 struct mem_region *region;
1000
1001 /* Zero length requests are ok and require no work. */
1002 if (len == 0)
1003 {
1004 *err = 0;
1005 return 0;
1006 }
1007
1008 region = lookup_mem_region(memaddr);
1009 if (memaddr + len < region->hi)
1010 reg_len = len;
1011 else
1012 reg_len = region->hi - memaddr;
1013
1014 switch (region->attrib.mode)
1015 {
1016 case MEM_RO:
1017 if (write_p)
1018 {
1019 *err = EIO;
1020 return -1;
1021 }
1022 break;
1023
1024 case MEM_WO:
1025 if (write_p)
1026 {
1027 *err = EIO;
1028 return -1;
1029 }
1030 break;
1031 }
1032
1033 if (region->attrib.cache)
1034 res = dcache_xfer_memory (target_dcache, memaddr, myaddr,
1035 reg_len, write_p);
1036 else
1037 res = do_xfer_memory (memaddr, myaddr, reg_len, write_p,
1038 &region->attrib);
1039
1040 if (res <= 0)
1041 {
1042 if (errno != 0)
1043 *err = errno;
1044 else
1045 *err = EIO;
1046
1047 return -1;
1048 }
1049
1050 *err = 0;
1051 return res;
1052 }
1053
1054 int
1055 target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1056 {
1057 return target_xfer_memory_partial (memaddr, buf, len, 0, err);
1058 }
1059
1060 int
1061 target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err)
1062 {
1063 return target_xfer_memory_partial (memaddr, buf, len, 1, err);
1064 }
1065
1066 /* More generic transfers. */
1067
1068 LONGEST
1069 target_read_partial (struct target_ops *ops,
1070 enum target_object object,
1071 const char *annex, void *buf,
1072 ULONGEST offset, LONGEST len)
1073 {
1074 struct target_ops *op;
1075
1076 /* Find the first target stratum that can handle the request. */
1077 for (op = ops;
1078 op != NULL && op->to_read_partial == NULL;
1079 op = op->beneath)
1080 ;
1081 if (op == NULL)
1082 return -1;
1083
1084 /* Now apply the operation at that level. */
1085 return op->to_read_partial (op, object, annex, buf, offset, len);
1086 }
1087
1088 LONGEST
1089 target_write_partial (struct target_ops *ops,
1090 enum target_object object,
1091 const char *annex, const void *buf,
1092 ULONGEST offset, LONGEST len)
1093 {
1094 struct target_ops *op;
1095
1096 /* Find the first target stratum that can handle the request. */
1097 for (op = ops;
1098 op != NULL && op->to_write_partial == NULL;
1099 op = op->beneath)
1100 ;
1101 if (op == NULL)
1102 return -1;
1103
1104 return op->to_write_partial (op, object, annex, buf, offset, len);
1105 }
1106
1107 /* Wrappers to perform the full transfer. */
1108 LONGEST
1109 target_read (struct target_ops *ops,
1110 enum target_object object,
1111 const char *annex, void *buf,
1112 ULONGEST offset, LONGEST len)
1113 {
1114 LONGEST xfered = 0;
1115 while (xfered < len)
1116 {
1117 LONGEST xfer = target_write_partial (ops, object, annex,
1118 (bfd_byte *) buf + xfered,
1119 offset + xfered, len - xfered);
1120 /* Call an observer, notifying them of the xfer progress? */
1121 if (xfer < 0)
1122 return xfer;
1123 xfered += xfer;
1124 QUIT;
1125 }
1126 return len;
1127 }
1128
1129 LONGEST
1130 target_write (struct target_ops *ops,
1131 enum target_object object,
1132 const char *annex, const void *buf,
1133 ULONGEST offset, LONGEST len)
1134 {
1135 LONGEST xfered = 0;
1136 while (xfered < len)
1137 {
1138 LONGEST xfer = target_write_partial (ops, object, annex,
1139 (bfd_byte *) buf + xfered,
1140 offset + xfered, len - xfered);
1141 /* Call an observer, notifying them of the xfer progress? */
1142 if (xfer < 0)
1143 return xfer;
1144 xfered += xfer;
1145 QUIT;
1146 }
1147 return len;
1148 }
1149
1150 static void
1151 target_info (char *args, int from_tty)
1152 {
1153 struct target_ops *t;
1154 int has_all_mem = 0;
1155
1156 if (symfile_objfile != NULL)
1157 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile->name);
1158
1159 #ifdef FILES_INFO_HOOK
1160 if (FILES_INFO_HOOK ())
1161 return;
1162 #endif
1163
1164 for (t = target_stack; t != NULL; t = t->beneath)
1165 {
1166 if (!t->to_has_memory)
1167 continue;
1168
1169 if ((int) (t->to_stratum) <= (int) dummy_stratum)
1170 continue;
1171 if (has_all_mem)
1172 printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n");
1173 printf_unfiltered ("%s:\n", t->to_longname);
1174 (t->to_files_info) (t);
1175 has_all_mem = t->to_has_all_memory;
1176 }
1177 }
1178
1179 /* This is to be called by the open routine before it does
1180 anything. */
1181
1182 void
1183 target_preopen (int from_tty)
1184 {
1185 dont_repeat ();
1186
1187 if (target_has_execution)
1188 {
1189 if (!from_tty
1190 || query ("A program is being debugged already. Kill it? "))
1191 target_kill ();
1192 else
1193 error ("Program not killed.");
1194 }
1195
1196 /* Calling target_kill may remove the target from the stack. But if
1197 it doesn't (which seems like a win for UDI), remove it now. */
1198
1199 if (target_has_execution)
1200 pop_target ();
1201 }
1202
1203 /* Detach a target after doing deferred register stores. */
1204
1205 void
1206 target_detach (char *args, int from_tty)
1207 {
1208 /* Handle any optimized stores to the inferior. */
1209 #ifdef DO_DEFERRED_STORES
1210 DO_DEFERRED_STORES;
1211 #endif
1212 (current_target.to_detach) (args, from_tty);
1213 }
1214
1215 void
1216 target_disconnect (char *args, int from_tty)
1217 {
1218 /* Handle any optimized stores to the inferior. */
1219 #ifdef DO_DEFERRED_STORES
1220 DO_DEFERRED_STORES;
1221 #endif
1222 (current_target.to_disconnect) (args, from_tty);
1223 }
1224
1225 void
1226 target_link (char *modname, CORE_ADDR *t_reloc)
1227 {
1228 if (STREQ (current_target.to_shortname, "rombug"))
1229 {
1230 (current_target.to_lookup_symbol) (modname, t_reloc);
1231 if (*t_reloc == 0)
1232 error ("Unable to link to %s and get relocation in rombug", modname);
1233 }
1234 else
1235 *t_reloc = (CORE_ADDR) -1;
1236 }
1237
1238 int
1239 target_async_mask (int mask)
1240 {
1241 int saved_async_masked_status = target_async_mask_value;
1242 target_async_mask_value = mask;
1243 return saved_async_masked_status;
1244 }
1245
1246 /* Look through the list of possible targets for a target that can
1247 execute a run or attach command without any other data. This is
1248 used to locate the default process stratum.
1249
1250 Result is always valid (error() is called for errors). */
1251
1252 static struct target_ops *
1253 find_default_run_target (char *do_mesg)
1254 {
1255 struct target_ops **t;
1256 struct target_ops *runable = NULL;
1257 int count;
1258
1259 count = 0;
1260
1261 for (t = target_structs; t < target_structs + target_struct_size;
1262 ++t)
1263 {
1264 if ((*t)->to_can_run && target_can_run (*t))
1265 {
1266 runable = *t;
1267 ++count;
1268 }
1269 }
1270
1271 if (count != 1)
1272 error ("Don't know how to %s. Try \"help target\".", do_mesg);
1273
1274 return runable;
1275 }
1276
1277 void
1278 find_default_attach (char *args, int from_tty)
1279 {
1280 struct target_ops *t;
1281
1282 t = find_default_run_target ("attach");
1283 (t->to_attach) (args, from_tty);
1284 return;
1285 }
1286
1287 void
1288 find_default_create_inferior (char *exec_file, char *allargs, char **env)
1289 {
1290 struct target_ops *t;
1291
1292 t = find_default_run_target ("run");
1293 (t->to_create_inferior) (exec_file, allargs, env);
1294 return;
1295 }
1296
1297 static int
1298 default_region_size_ok_for_hw_watchpoint (int byte_count)
1299 {
1300 return (byte_count <= DEPRECATED_REGISTER_SIZE);
1301 }
1302
1303 static int
1304 return_zero (void)
1305 {
1306 return 0;
1307 }
1308
1309 static int
1310 return_one (void)
1311 {
1312 return 1;
1313 }
1314
1315 static int
1316 return_minus_one (void)
1317 {
1318 return -1;
1319 }
1320
1321 /*
1322 * Resize the to_sections pointer. Also make sure that anyone that
1323 * was holding on to an old value of it gets updated.
1324 * Returns the old size.
1325 */
1326
1327 int
1328 target_resize_to_sections (struct target_ops *target, int num_added)
1329 {
1330 struct target_ops **t;
1331 struct section_table *old_value;
1332 int old_count;
1333
1334 old_value = target->to_sections;
1335
1336 if (target->to_sections)
1337 {
1338 old_count = target->to_sections_end - target->to_sections;
1339 target->to_sections = (struct section_table *)
1340 xrealloc ((char *) target->to_sections,
1341 (sizeof (struct section_table)) * (num_added + old_count));
1342 }
1343 else
1344 {
1345 old_count = 0;
1346 target->to_sections = (struct section_table *)
1347 xmalloc ((sizeof (struct section_table)) * num_added);
1348 }
1349 target->to_sections_end = target->to_sections + (num_added + old_count);
1350
1351 /* Check to see if anyone else was pointing to this structure.
1352 If old_value was null, then no one was. */
1353
1354 if (old_value)
1355 {
1356 for (t = target_structs; t < target_structs + target_struct_size;
1357 ++t)
1358 {
1359 if ((*t)->to_sections == old_value)
1360 {
1361 (*t)->to_sections = target->to_sections;
1362 (*t)->to_sections_end = target->to_sections_end;
1363 }
1364 }
1365 }
1366
1367 return old_count;
1368
1369 }
1370
1371 /* Remove all target sections taken from ABFD.
1372
1373 Scan the current target stack for targets whose section tables
1374 refer to sections from BFD, and remove those sections. We use this
1375 when we notice that the inferior has unloaded a shared object, for
1376 example. */
1377 void
1378 remove_target_sections (bfd *abfd)
1379 {
1380 struct target_ops **t;
1381
1382 for (t = target_structs; t < target_structs + target_struct_size; t++)
1383 {
1384 struct section_table *src, *dest;
1385
1386 dest = (*t)->to_sections;
1387 for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++)
1388 if (src->bfd != abfd)
1389 {
1390 /* Keep this section. */
1391 if (dest < src) *dest = *src;
1392 dest++;
1393 }
1394
1395 /* If we've dropped any sections, resize the section table. */
1396 if (dest < src)
1397 target_resize_to_sections (*t, dest - src);
1398 }
1399 }
1400
1401
1402
1403
1404 /* Find a single runnable target in the stack and return it. If for
1405 some reason there is more than one, return NULL. */
1406
1407 struct target_ops *
1408 find_run_target (void)
1409 {
1410 struct target_ops **t;
1411 struct target_ops *runable = NULL;
1412 int count;
1413
1414 count = 0;
1415
1416 for (t = target_structs; t < target_structs + target_struct_size; ++t)
1417 {
1418 if ((*t)->to_can_run && target_can_run (*t))
1419 {
1420 runable = *t;
1421 ++count;
1422 }
1423 }
1424
1425 return (count == 1 ? runable : NULL);
1426 }
1427
1428 /* Find a single core_stratum target in the list of targets and return it.
1429 If for some reason there is more than one, return NULL. */
1430
1431 struct target_ops *
1432 find_core_target (void)
1433 {
1434 struct target_ops **t;
1435 struct target_ops *runable = NULL;
1436 int count;
1437
1438 count = 0;
1439
1440 for (t = target_structs; t < target_structs + target_struct_size;
1441 ++t)
1442 {
1443 if ((*t)->to_stratum == core_stratum)
1444 {
1445 runable = *t;
1446 ++count;
1447 }
1448 }
1449
1450 return (count == 1 ? runable : NULL);
1451 }
1452
1453 /*
1454 * Find the next target down the stack from the specified target.
1455 */
1456
1457 struct target_ops *
1458 find_target_beneath (struct target_ops *t)
1459 {
1460 return t->beneath;
1461 }
1462
1463 \f
1464 /* The inferior process has died. Long live the inferior! */
1465
1466 void
1467 generic_mourn_inferior (void)
1468 {
1469 extern int show_breakpoint_hit_counts;
1470
1471 inferior_ptid = null_ptid;
1472 attach_flag = 0;
1473 breakpoint_init_inferior (inf_exited);
1474 registers_changed ();
1475
1476 #ifdef CLEAR_DEFERRED_STORES
1477 /* Delete any pending stores to the inferior... */
1478 CLEAR_DEFERRED_STORES;
1479 #endif
1480
1481 reopen_exec_file ();
1482 reinit_frame_cache ();
1483
1484 /* It is confusing to the user for ignore counts to stick around
1485 from previous runs of the inferior. So clear them. */
1486 /* However, it is more confusing for the ignore counts to disappear when
1487 using hit counts. So don't clear them if we're counting hits. */
1488 if (!show_breakpoint_hit_counts)
1489 breakpoint_clear_ignore_counts ();
1490
1491 if (detach_hook)
1492 detach_hook ();
1493 }
1494 \f
1495 /* Helper function for child_wait and the Lynx derivatives of child_wait.
1496 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
1497 translation of that in OURSTATUS. */
1498 void
1499 store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus)
1500 {
1501 #ifdef CHILD_SPECIAL_WAITSTATUS
1502 /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS
1503 if it wants to deal with hoststatus. */
1504 if (CHILD_SPECIAL_WAITSTATUS (ourstatus, hoststatus))
1505 return;
1506 #endif
1507
1508 if (WIFEXITED (hoststatus))
1509 {
1510 ourstatus->kind = TARGET_WAITKIND_EXITED;
1511 ourstatus->value.integer = WEXITSTATUS (hoststatus);
1512 }
1513 else if (!WIFSTOPPED (hoststatus))
1514 {
1515 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
1516 ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus));
1517 }
1518 else
1519 {
1520 ourstatus->kind = TARGET_WAITKIND_STOPPED;
1521 ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus));
1522 }
1523 }
1524 \f
1525 /* Returns zero to leave the inferior alone, one to interrupt it. */
1526 int (*target_activity_function) (void);
1527 int target_activity_fd;
1528 \f
1529 /* Convert a normal process ID to a string. Returns the string in a static
1530 buffer. */
1531
1532 char *
1533 normal_pid_to_str (ptid_t ptid)
1534 {
1535 static char buf[30];
1536
1537 sprintf (buf, "process %d", PIDGET (ptid));
1538 return buf;
1539 }
1540
1541 /* Some targets (such as ttrace-based HPUX) don't allow us to request
1542 notification of inferior events such as fork and vork immediately
1543 after the inferior is created. (This because of how gdb gets an
1544 inferior created via invoking a shell to do it. In such a scenario,
1545 if the shell init file has commands in it, the shell will fork and
1546 exec for each of those commands, and we will see each such fork
1547 event. Very bad.)
1548
1549 This function is used by all targets that allow us to request
1550 notification of forks, etc at inferior creation time; e.g., in
1551 target_acknowledge_forked_child.
1552 */
1553 static void
1554 normal_target_post_startup_inferior (ptid_t ptid)
1555 {
1556 /* This space intentionally left blank. */
1557 }
1558
1559 /* Error-catcher for target_find_memory_regions */
1560 static int dummy_find_memory_regions (int (*ignore1) (), void *ignore2)
1561 {
1562 error ("No target.");
1563 return 0;
1564 }
1565
1566 /* Error-catcher for target_make_corefile_notes */
1567 static char * dummy_make_corefile_notes (bfd *ignore1, int *ignore2)
1568 {
1569 error ("No target.");
1570 return NULL;
1571 }
1572
1573 /* Set up the handful of non-empty slots needed by the dummy target
1574 vector. */
1575
1576 static void
1577 init_dummy_target (void)
1578 {
1579 dummy_target.to_shortname = "None";
1580 dummy_target.to_longname = "None";
1581 dummy_target.to_doc = "";
1582 dummy_target.to_attach = find_default_attach;
1583 dummy_target.to_create_inferior = find_default_create_inferior;
1584 dummy_target.to_pid_to_str = normal_pid_to_str;
1585 dummy_target.to_stratum = dummy_stratum;
1586 dummy_target.to_find_memory_regions = dummy_find_memory_regions;
1587 dummy_target.to_make_corefile_notes = dummy_make_corefile_notes;
1588 dummy_target.to_magic = OPS_MAGIC;
1589 }
1590 \f
1591
1592 static struct target_ops debug_target;
1593
1594 static void
1595 debug_to_open (char *args, int from_tty)
1596 {
1597 debug_target.to_open (args, from_tty);
1598
1599 fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty);
1600 }
1601
1602 static void
1603 debug_to_close (int quitting)
1604 {
1605 debug_target.to_close (quitting);
1606
1607 fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting);
1608 }
1609
1610 static void
1611 debug_to_attach (char *args, int from_tty)
1612 {
1613 debug_target.to_attach (args, from_tty);
1614
1615 fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty);
1616 }
1617
1618
1619 static void
1620 debug_to_post_attach (int pid)
1621 {
1622 debug_target.to_post_attach (pid);
1623
1624 fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid);
1625 }
1626
1627 static void
1628 debug_to_detach (char *args, int from_tty)
1629 {
1630 debug_target.to_detach (args, from_tty);
1631
1632 fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty);
1633 }
1634
1635 static void
1636 debug_to_disconnect (char *args, int from_tty)
1637 {
1638 debug_target.to_disconnect (args, from_tty);
1639
1640 fprintf_unfiltered (gdb_stdlog, "target_disconnect (%s, %d)\n",
1641 args, from_tty);
1642 }
1643
1644 static void
1645 debug_to_resume (ptid_t ptid, int step, enum target_signal siggnal)
1646 {
1647 debug_target.to_resume (ptid, step, siggnal);
1648
1649 fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", PIDGET (ptid),
1650 step ? "step" : "continue",
1651 target_signal_to_name (siggnal));
1652 }
1653
1654 static ptid_t
1655 debug_to_wait (ptid_t ptid, struct target_waitstatus *status)
1656 {
1657 ptid_t retval;
1658
1659 retval = debug_target.to_wait (ptid, status);
1660
1661 fprintf_unfiltered (gdb_stdlog,
1662 "target_wait (%d, status) = %d, ", PIDGET (ptid),
1663 PIDGET (retval));
1664 fprintf_unfiltered (gdb_stdlog, "status->kind = ");
1665 switch (status->kind)
1666 {
1667 case TARGET_WAITKIND_EXITED:
1668 fprintf_unfiltered (gdb_stdlog, "exited, status = %d\n",
1669 status->value.integer);
1670 break;
1671 case TARGET_WAITKIND_STOPPED:
1672 fprintf_unfiltered (gdb_stdlog, "stopped, signal = %s\n",
1673 target_signal_to_name (status->value.sig));
1674 break;
1675 case TARGET_WAITKIND_SIGNALLED:
1676 fprintf_unfiltered (gdb_stdlog, "signalled, signal = %s\n",
1677 target_signal_to_name (status->value.sig));
1678 break;
1679 case TARGET_WAITKIND_LOADED:
1680 fprintf_unfiltered (gdb_stdlog, "loaded\n");
1681 break;
1682 case TARGET_WAITKIND_FORKED:
1683 fprintf_unfiltered (gdb_stdlog, "forked\n");
1684 break;
1685 case TARGET_WAITKIND_VFORKED:
1686 fprintf_unfiltered (gdb_stdlog, "vforked\n");
1687 break;
1688 case TARGET_WAITKIND_EXECD:
1689 fprintf_unfiltered (gdb_stdlog, "execd\n");
1690 break;
1691 case TARGET_WAITKIND_SPURIOUS:
1692 fprintf_unfiltered (gdb_stdlog, "spurious\n");
1693 break;
1694 default:
1695 fprintf_unfiltered (gdb_stdlog, "unknown???\n");
1696 break;
1697 }
1698
1699 return retval;
1700 }
1701
1702 static void
1703 debug_to_post_wait (ptid_t ptid, int status)
1704 {
1705 debug_target.to_post_wait (ptid, status);
1706
1707 fprintf_unfiltered (gdb_stdlog, "target_post_wait (%d, %d)\n",
1708 PIDGET (ptid), status);
1709 }
1710
1711 static void
1712 debug_print_register (const char * func, int regno)
1713 {
1714 fprintf_unfiltered (gdb_stdlog, "%s ", func);
1715 if (regno >= 0 && regno < NUM_REGS + NUM_PSEUDO_REGS
1716 && REGISTER_NAME (regno) != NULL && REGISTER_NAME (regno)[0] != '\0')
1717 fprintf_unfiltered (gdb_stdlog, "(%s)", REGISTER_NAME (regno));
1718 else
1719 fprintf_unfiltered (gdb_stdlog, "(%d)", regno);
1720 if (regno >= 0)
1721 {
1722 int i;
1723 unsigned char buf[MAX_REGISTER_SIZE];
1724 deprecated_read_register_gen (regno, buf);
1725 fprintf_unfiltered (gdb_stdlog, " = ");
1726 for (i = 0; i < DEPRECATED_REGISTER_RAW_SIZE (regno); i++)
1727 {
1728 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
1729 }
1730 if (DEPRECATED_REGISTER_RAW_SIZE (regno) <= sizeof (LONGEST))
1731 {
1732 fprintf_unfiltered (gdb_stdlog, " 0x%s %s",
1733 paddr_nz (read_register (regno)),
1734 paddr_d (read_register (regno)));
1735 }
1736 }
1737 fprintf_unfiltered (gdb_stdlog, "\n");
1738 }
1739
1740 static void
1741 debug_to_fetch_registers (int regno)
1742 {
1743 debug_target.to_fetch_registers (regno);
1744 debug_print_register ("target_fetch_registers", regno);
1745 }
1746
1747 static void
1748 debug_to_store_registers (int regno)
1749 {
1750 debug_target.to_store_registers (regno);
1751 debug_print_register ("target_store_registers", regno);
1752 fprintf_unfiltered (gdb_stdlog, "\n");
1753 }
1754
1755 static void
1756 debug_to_prepare_to_store (void)
1757 {
1758 debug_target.to_prepare_to_store ();
1759
1760 fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n");
1761 }
1762
1763 static int
1764 debug_to_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write,
1765 struct mem_attrib *attrib,
1766 struct target_ops *target)
1767 {
1768 int retval;
1769
1770 retval = debug_target.to_xfer_memory (memaddr, myaddr, len, write,
1771 attrib, target);
1772
1773 fprintf_unfiltered (gdb_stdlog,
1774 "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
1775 (unsigned int) memaddr, /* possable truncate long long */
1776 len, write ? "write" : "read", retval);
1777
1778
1779
1780 if (retval > 0)
1781 {
1782 int i;
1783
1784 fputs_unfiltered (", bytes =", gdb_stdlog);
1785 for (i = 0; i < retval; i++)
1786 {
1787 if ((((long) &(myaddr[i])) & 0xf) == 0)
1788 fprintf_unfiltered (gdb_stdlog, "\n");
1789 fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff);
1790 }
1791 }
1792
1793 fputc_unfiltered ('\n', gdb_stdlog);
1794
1795 return retval;
1796 }
1797
1798 static void
1799 debug_to_files_info (struct target_ops *target)
1800 {
1801 debug_target.to_files_info (target);
1802
1803 fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n");
1804 }
1805
1806 static int
1807 debug_to_insert_breakpoint (CORE_ADDR addr, char *save)
1808 {
1809 int retval;
1810
1811 retval = debug_target.to_insert_breakpoint (addr, save);
1812
1813 fprintf_unfiltered (gdb_stdlog,
1814 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
1815 (unsigned long) addr,
1816 (unsigned long) retval);
1817 return retval;
1818 }
1819
1820 static int
1821 debug_to_remove_breakpoint (CORE_ADDR addr, char *save)
1822 {
1823 int retval;
1824
1825 retval = debug_target.to_remove_breakpoint (addr, save);
1826
1827 fprintf_unfiltered (gdb_stdlog,
1828 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
1829 (unsigned long) addr,
1830 (unsigned long) retval);
1831 return retval;
1832 }
1833
1834 static int
1835 debug_to_can_use_hw_breakpoint (int type, int cnt, int from_tty)
1836 {
1837 int retval;
1838
1839 retval = debug_target.to_can_use_hw_breakpoint (type, cnt, from_tty);
1840
1841 fprintf_unfiltered (gdb_stdlog,
1842 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
1843 (unsigned long) type,
1844 (unsigned long) cnt,
1845 (unsigned long) from_tty,
1846 (unsigned long) retval);
1847 return retval;
1848 }
1849
1850 static int
1851 debug_to_region_size_ok_for_hw_watchpoint (int byte_count)
1852 {
1853 CORE_ADDR retval;
1854
1855 retval = debug_target.to_region_size_ok_for_hw_watchpoint (byte_count);
1856
1857 fprintf_unfiltered (gdb_stdlog,
1858 "TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT (%ld) = 0x%lx\n",
1859 (unsigned long) byte_count,
1860 (unsigned long) retval);
1861 return retval;
1862 }
1863
1864 static int
1865 debug_to_stopped_by_watchpoint (void)
1866 {
1867 int retval;
1868
1869 retval = debug_target.to_stopped_by_watchpoint ();
1870
1871 fprintf_unfiltered (gdb_stdlog,
1872 "STOPPED_BY_WATCHPOINT () = %ld\n",
1873 (unsigned long) retval);
1874 return retval;
1875 }
1876
1877 static CORE_ADDR
1878 debug_to_stopped_data_address (void)
1879 {
1880 CORE_ADDR retval;
1881
1882 retval = debug_target.to_stopped_data_address ();
1883
1884 fprintf_unfiltered (gdb_stdlog,
1885 "target_stopped_data_address () = 0x%lx\n",
1886 (unsigned long) retval);
1887 return retval;
1888 }
1889
1890 static int
1891 debug_to_insert_hw_breakpoint (CORE_ADDR addr, char *save)
1892 {
1893 int retval;
1894
1895 retval = debug_target.to_insert_hw_breakpoint (addr, save);
1896
1897 fprintf_unfiltered (gdb_stdlog,
1898 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
1899 (unsigned long) addr,
1900 (unsigned long) retval);
1901 return retval;
1902 }
1903
1904 static int
1905 debug_to_remove_hw_breakpoint (CORE_ADDR addr, char *save)
1906 {
1907 int retval;
1908
1909 retval = debug_target.to_remove_hw_breakpoint (addr, save);
1910
1911 fprintf_unfiltered (gdb_stdlog,
1912 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
1913 (unsigned long) addr,
1914 (unsigned long) retval);
1915 return retval;
1916 }
1917
1918 static int
1919 debug_to_insert_watchpoint (CORE_ADDR addr, int len, int type)
1920 {
1921 int retval;
1922
1923 retval = debug_target.to_insert_watchpoint (addr, len, type);
1924
1925 fprintf_unfiltered (gdb_stdlog,
1926 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1927 (unsigned long) addr, len, type, (unsigned long) retval);
1928 return retval;
1929 }
1930
1931 static int
1932 debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type)
1933 {
1934 int retval;
1935
1936 retval = debug_target.to_insert_watchpoint (addr, len, type);
1937
1938 fprintf_unfiltered (gdb_stdlog,
1939 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
1940 (unsigned long) addr, len, type, (unsigned long) retval);
1941 return retval;
1942 }
1943
1944 static void
1945 debug_to_terminal_init (void)
1946 {
1947 debug_target.to_terminal_init ();
1948
1949 fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n");
1950 }
1951
1952 static void
1953 debug_to_terminal_inferior (void)
1954 {
1955 debug_target.to_terminal_inferior ();
1956
1957 fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n");
1958 }
1959
1960 static void
1961 debug_to_terminal_ours_for_output (void)
1962 {
1963 debug_target.to_terminal_ours_for_output ();
1964
1965 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n");
1966 }
1967
1968 static void
1969 debug_to_terminal_ours (void)
1970 {
1971 debug_target.to_terminal_ours ();
1972
1973 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n");
1974 }
1975
1976 static void
1977 debug_to_terminal_save_ours (void)
1978 {
1979 debug_target.to_terminal_save_ours ();
1980
1981 fprintf_unfiltered (gdb_stdlog, "target_terminal_save_ours ()\n");
1982 }
1983
1984 static void
1985 debug_to_terminal_info (char *arg, int from_tty)
1986 {
1987 debug_target.to_terminal_info (arg, from_tty);
1988
1989 fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg,
1990 from_tty);
1991 }
1992
1993 static void
1994 debug_to_kill (void)
1995 {
1996 debug_target.to_kill ();
1997
1998 fprintf_unfiltered (gdb_stdlog, "target_kill ()\n");
1999 }
2000
2001 static void
2002 debug_to_load (char *args, int from_tty)
2003 {
2004 debug_target.to_load (args, from_tty);
2005
2006 fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty);
2007 }
2008
2009 static int
2010 debug_to_lookup_symbol (char *name, CORE_ADDR *addrp)
2011 {
2012 int retval;
2013
2014 retval = debug_target.to_lookup_symbol (name, addrp);
2015
2016 fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name);
2017
2018 return retval;
2019 }
2020
2021 static void
2022 debug_to_create_inferior (char *exec_file, char *args, char **env)
2023 {
2024 debug_target.to_create_inferior (exec_file, args, env);
2025
2026 fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx)\n",
2027 exec_file, args);
2028 }
2029
2030 static void
2031 debug_to_post_startup_inferior (ptid_t ptid)
2032 {
2033 debug_target.to_post_startup_inferior (ptid);
2034
2035 fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n",
2036 PIDGET (ptid));
2037 }
2038
2039 static void
2040 debug_to_acknowledge_created_inferior (int pid)
2041 {
2042 debug_target.to_acknowledge_created_inferior (pid);
2043
2044 fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n",
2045 pid);
2046 }
2047
2048 static int
2049 debug_to_insert_fork_catchpoint (int pid)
2050 {
2051 int retval;
2052
2053 retval = debug_target.to_insert_fork_catchpoint (pid);
2054
2055 fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d) = %d\n",
2056 pid, retval);
2057
2058 return retval;
2059 }
2060
2061 static int
2062 debug_to_remove_fork_catchpoint (int pid)
2063 {
2064 int retval;
2065
2066 retval = debug_target.to_remove_fork_catchpoint (pid);
2067
2068 fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n",
2069 pid, retval);
2070
2071 return retval;
2072 }
2073
2074 static int
2075 debug_to_insert_vfork_catchpoint (int pid)
2076 {
2077 int retval;
2078
2079 retval = debug_target.to_insert_vfork_catchpoint (pid);
2080
2081 fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)= %d\n",
2082 pid, retval);
2083
2084 return retval;
2085 }
2086
2087 static int
2088 debug_to_remove_vfork_catchpoint (int pid)
2089 {
2090 int retval;
2091
2092 retval = debug_target.to_remove_vfork_catchpoint (pid);
2093
2094 fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n",
2095 pid, retval);
2096
2097 return retval;
2098 }
2099
2100 static int
2101 debug_to_follow_fork (int follow_child)
2102 {
2103 int retval = debug_target.to_follow_fork (follow_child);
2104
2105 fprintf_unfiltered (gdb_stdlog, "target_follow_fork (%d) = %d\n",
2106 follow_child, retval);
2107
2108 return retval;
2109 }
2110
2111 static int
2112 debug_to_insert_exec_catchpoint (int pid)
2113 {
2114 int retval;
2115
2116 retval = debug_target.to_insert_exec_catchpoint (pid);
2117
2118 fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d) = %d\n",
2119 pid, retval);
2120
2121 return retval;
2122 }
2123
2124 static int
2125 debug_to_remove_exec_catchpoint (int pid)
2126 {
2127 int retval;
2128
2129 retval = debug_target.to_remove_exec_catchpoint (pid);
2130
2131 fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n",
2132 pid, retval);
2133
2134 return retval;
2135 }
2136
2137 static int
2138 debug_to_reported_exec_events_per_exec_call (void)
2139 {
2140 int reported_exec_events;
2141
2142 reported_exec_events = debug_target.to_reported_exec_events_per_exec_call ();
2143
2144 fprintf_unfiltered (gdb_stdlog,
2145 "target_reported_exec_events_per_exec_call () = %d\n",
2146 reported_exec_events);
2147
2148 return reported_exec_events;
2149 }
2150
2151 static int
2152 debug_to_has_exited (int pid, int wait_status, int *exit_status)
2153 {
2154 int has_exited;
2155
2156 has_exited = debug_target.to_has_exited (pid, wait_status, exit_status);
2157
2158 fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n",
2159 pid, wait_status, *exit_status, has_exited);
2160
2161 return has_exited;
2162 }
2163
2164 static void
2165 debug_to_mourn_inferior (void)
2166 {
2167 debug_target.to_mourn_inferior ();
2168
2169 fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n");
2170 }
2171
2172 static int
2173 debug_to_can_run (void)
2174 {
2175 int retval;
2176
2177 retval = debug_target.to_can_run ();
2178
2179 fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval);
2180
2181 return retval;
2182 }
2183
2184 static void
2185 debug_to_notice_signals (ptid_t ptid)
2186 {
2187 debug_target.to_notice_signals (ptid);
2188
2189 fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n",
2190 PIDGET (ptid));
2191 }
2192
2193 static int
2194 debug_to_thread_alive (ptid_t ptid)
2195 {
2196 int retval;
2197
2198 retval = debug_target.to_thread_alive (ptid);
2199
2200 fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n",
2201 PIDGET (ptid), retval);
2202
2203 return retval;
2204 }
2205
2206 static void
2207 debug_to_find_new_threads (void)
2208 {
2209 debug_target.to_find_new_threads ();
2210
2211 fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog);
2212 }
2213
2214 static void
2215 debug_to_stop (void)
2216 {
2217 debug_target.to_stop ();
2218
2219 fprintf_unfiltered (gdb_stdlog, "target_stop ()\n");
2220 }
2221
2222 static LONGEST
2223 debug_to_read_partial (struct target_ops *ops,
2224 enum target_object object,
2225 const char *annex, void *buf,
2226 ULONGEST offset, LONGEST len)
2227 {
2228 LONGEST retval;
2229
2230 retval = target_read_partial (&debug_target, object, annex, buf, offset,
2231 len);
2232
2233 fprintf_unfiltered (gdb_stdlog,
2234 "target_read_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n",
2235 (int) object, (annex ? annex : "(null)"),
2236 (long) buf, paddr_nz (offset),
2237 paddr_d (len), paddr_d (retval));
2238
2239 return retval;
2240 }
2241
2242 static LONGEST
2243 debug_to_write_partial (struct target_ops *ops,
2244 enum target_object object,
2245 const char *annex, const void *buf,
2246 ULONGEST offset, LONGEST len)
2247 {
2248 LONGEST retval;
2249
2250 retval = target_write_partial (&debug_target, object, annex, buf, offset,
2251 len);
2252
2253 fprintf_unfiltered (gdb_stdlog,
2254 "target_write_partial (%d, %s, 0x%lx, 0x%s, %s) = %s\n",
2255 (int) object, (annex ? annex : "(null)"),
2256 (long) buf, paddr_nz (offset),
2257 paddr_d (len), paddr_d (retval));
2258
2259 return retval;
2260 }
2261
2262 static void
2263 debug_to_rcmd (char *command,
2264 struct ui_file *outbuf)
2265 {
2266 debug_target.to_rcmd (command, outbuf);
2267 fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command);
2268 }
2269
2270 static struct symtab_and_line *
2271 debug_to_enable_exception_callback (enum exception_event_kind kind, int enable)
2272 {
2273 struct symtab_and_line *result;
2274 result = debug_target.to_enable_exception_callback (kind, enable);
2275 fprintf_unfiltered (gdb_stdlog,
2276 "target get_exception_callback_sal (%d, %d)\n",
2277 kind, enable);
2278 return result;
2279 }
2280
2281 static struct exception_event_record *
2282 debug_to_get_current_exception_event (void)
2283 {
2284 struct exception_event_record *result;
2285 result = debug_target.to_get_current_exception_event ();
2286 fprintf_unfiltered (gdb_stdlog, "target get_current_exception_event ()\n");
2287 return result;
2288 }
2289
2290 static char *
2291 debug_to_pid_to_exec_file (int pid)
2292 {
2293 char *exec_file;
2294
2295 exec_file = debug_target.to_pid_to_exec_file (pid);
2296
2297 fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n",
2298 pid, exec_file);
2299
2300 return exec_file;
2301 }
2302
2303 static void
2304 setup_target_debug (void)
2305 {
2306 memcpy (&debug_target, &current_target, sizeof debug_target);
2307
2308 current_target.to_open = debug_to_open;
2309 current_target.to_close = debug_to_close;
2310 current_target.to_attach = debug_to_attach;
2311 current_target.to_post_attach = debug_to_post_attach;
2312 current_target.to_detach = debug_to_detach;
2313 current_target.to_disconnect = debug_to_disconnect;
2314 current_target.to_resume = debug_to_resume;
2315 current_target.to_wait = debug_to_wait;
2316 current_target.to_post_wait = debug_to_post_wait;
2317 current_target.to_fetch_registers = debug_to_fetch_registers;
2318 current_target.to_store_registers = debug_to_store_registers;
2319 current_target.to_prepare_to_store = debug_to_prepare_to_store;
2320 current_target.to_xfer_memory = debug_to_xfer_memory;
2321 current_target.to_files_info = debug_to_files_info;
2322 current_target.to_insert_breakpoint = debug_to_insert_breakpoint;
2323 current_target.to_remove_breakpoint = debug_to_remove_breakpoint;
2324 current_target.to_can_use_hw_breakpoint = debug_to_can_use_hw_breakpoint;
2325 current_target.to_insert_hw_breakpoint = debug_to_insert_hw_breakpoint;
2326 current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint;
2327 current_target.to_insert_watchpoint = debug_to_insert_watchpoint;
2328 current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
2329 current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
2330 current_target.to_stopped_data_address = debug_to_stopped_data_address;
2331 current_target.to_region_size_ok_for_hw_watchpoint = debug_to_region_size_ok_for_hw_watchpoint;
2332 current_target.to_terminal_init = debug_to_terminal_init;
2333 current_target.to_terminal_inferior = debug_to_terminal_inferior;
2334 current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output;
2335 current_target.to_terminal_ours = debug_to_terminal_ours;
2336 current_target.to_terminal_save_ours = debug_to_terminal_save_ours;
2337 current_target.to_terminal_info = debug_to_terminal_info;
2338 current_target.to_kill = debug_to_kill;
2339 current_target.to_load = debug_to_load;
2340 current_target.to_lookup_symbol = debug_to_lookup_symbol;
2341 current_target.to_create_inferior = debug_to_create_inferior;
2342 current_target.to_post_startup_inferior = debug_to_post_startup_inferior;
2343 current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior;
2344 current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint;
2345 current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
2346 current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
2347 current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint;
2348 current_target.to_follow_fork = debug_to_follow_fork;
2349 current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint;
2350 current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
2351 current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call;
2352 current_target.to_has_exited = debug_to_has_exited;
2353 current_target.to_mourn_inferior = debug_to_mourn_inferior;
2354 current_target.to_can_run = debug_to_can_run;
2355 current_target.to_notice_signals = debug_to_notice_signals;
2356 current_target.to_thread_alive = debug_to_thread_alive;
2357 current_target.to_find_new_threads = debug_to_find_new_threads;
2358 current_target.to_stop = debug_to_stop;
2359 current_target.to_read_partial = debug_to_read_partial;
2360 current_target.to_write_partial = debug_to_write_partial;
2361 current_target.to_rcmd = debug_to_rcmd;
2362 current_target.to_enable_exception_callback = debug_to_enable_exception_callback;
2363 current_target.to_get_current_exception_event = debug_to_get_current_exception_event;
2364 current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
2365
2366 }
2367 \f
2368
2369 static char targ_desc[] =
2370 "Names of targets and files being debugged.\n\
2371 Shows the entire stack of targets currently in use (including the exec-file,\n\
2372 core-file, and process, if any), as well as the symbol file name.";
2373
2374 static void
2375 do_monitor_command (char *cmd,
2376 int from_tty)
2377 {
2378 if ((current_target.to_rcmd
2379 == (void (*) (char *, struct ui_file *)) tcomplain)
2380 || (current_target.to_rcmd == debug_to_rcmd
2381 && (debug_target.to_rcmd
2382 == (void (*) (char *, struct ui_file *)) tcomplain)))
2383 {
2384 error ("\"monitor\" command not supported by this target.\n");
2385 }
2386 target_rcmd (cmd, gdb_stdtarg);
2387 }
2388
2389 void
2390 initialize_targets (void)
2391 {
2392 init_dummy_target ();
2393 push_target (&dummy_target);
2394
2395 add_info ("target", target_info, targ_desc);
2396 add_info ("files", target_info, targ_desc);
2397
2398 add_show_from_set
2399 (add_set_cmd ("target", class_maintenance, var_zinteger,
2400 (char *) &targetdebug,
2401 "Set target debugging.\n\
2402 When non-zero, target debugging is enabled.", &setdebuglist),
2403 &showdebuglist);
2404
2405 add_setshow_boolean_cmd ("trust-readonly-sections", class_support,
2406 &trust_readonly, "\
2407 Set mode for reading from readonly sections.\n\
2408 When this mode is on, memory reads from readonly sections (such as .text)\n\
2409 will be read from the object file instead of from the target. This will\n\
2410 result in significant performance improvement for remote targets.", "\
2411 Show mode for reading from readonly sections.\n",
2412 NULL, NULL,
2413 &setlist, &showlist);
2414
2415 add_com ("monitor", class_obscure, do_monitor_command,
2416 "Send a command to the remote monitor (remote targets only).");
2417
2418 target_dcache = dcache_init ();
2419 }
This page took 0.077323 seconds and 5 git commands to generate.