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