gas/
[deliverable/binutils-gdb.git] / gdb / target.c
1 /* Select target systems and architectures at runtime for GDB.
2
3 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
6
7 Contributed by Cygnus Support.
8
9 This file is part of GDB.
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
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 #include "gdb_assert.h"
39 #include "gdbcore.h"
40 #include "exceptions.h"
41 #include "target-descriptions.h"
42 #include "gdbthread.h"
43 #include "solib.h"
44 #include "exec.h"
45 #include "inline-frame.h"
46
47 static void target_info (char *, int);
48
49 static void default_terminal_info (char *, int);
50
51 static int default_watchpoint_addr_within_range (struct target_ops *,
52 CORE_ADDR, CORE_ADDR, int);
53
54 static int default_region_ok_for_hw_watchpoint (CORE_ADDR, int);
55
56 static int nosymbol (char *, CORE_ADDR *);
57
58 static void tcomplain (void) ATTR_NORETURN;
59
60 static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *);
61
62 static int return_zero (void);
63
64 static int return_one (void);
65
66 static int return_minus_one (void);
67
68 void target_ignore (void);
69
70 static void target_command (char *, int);
71
72 static struct target_ops *find_default_run_target (char *);
73
74 static LONGEST default_xfer_partial (struct target_ops *ops,
75 enum target_object object,
76 const char *annex, gdb_byte *readbuf,
77 const gdb_byte *writebuf,
78 ULONGEST offset, LONGEST len);
79
80 static LONGEST current_xfer_partial (struct target_ops *ops,
81 enum target_object object,
82 const char *annex, gdb_byte *readbuf,
83 const gdb_byte *writebuf,
84 ULONGEST offset, LONGEST len);
85
86 static LONGEST target_xfer_partial (struct target_ops *ops,
87 enum target_object object,
88 const char *annex,
89 void *readbuf, const void *writebuf,
90 ULONGEST offset, LONGEST len);
91
92 static struct gdbarch *default_thread_architecture (struct target_ops *ops,
93 ptid_t ptid);
94
95 static void init_dummy_target (void);
96
97 static struct target_ops debug_target;
98
99 static void debug_to_open (char *, int);
100
101 static void debug_to_prepare_to_store (struct regcache *);
102
103 static void debug_to_files_info (struct target_ops *);
104
105 static int debug_to_insert_breakpoint (struct gdbarch *,
106 struct bp_target_info *);
107
108 static int debug_to_remove_breakpoint (struct gdbarch *,
109 struct bp_target_info *);
110
111 static int debug_to_can_use_hw_breakpoint (int, int, int);
112
113 static int debug_to_insert_hw_breakpoint (struct gdbarch *,
114 struct bp_target_info *);
115
116 static int debug_to_remove_hw_breakpoint (struct gdbarch *,
117 struct bp_target_info *);
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 int debug_to_stopped_data_address (struct target_ops *, CORE_ADDR *);
126
127 static int debug_to_watchpoint_addr_within_range (struct target_ops *,
128 CORE_ADDR, CORE_ADDR, int);
129
130 static int debug_to_region_ok_for_hw_watchpoint (CORE_ADDR, 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_load (char *, int);
145
146 static int debug_to_lookup_symbol (char *, CORE_ADDR *);
147
148 static int debug_to_can_run (void);
149
150 static void debug_to_notice_signals (ptid_t);
151
152 static void debug_to_stop (ptid_t);
153
154 /* NOTE: cagney/2004-09-29: Many targets reference this variable in
155 wierd and mysterious ways. Putting the variable here lets those
156 wierd and mysterious ways keep building while they are being
157 converted to the inferior inheritance structure. */
158 struct target_ops deprecated_child_ops;
159
160 /* Pointer to array of target architecture structures; the size of the
161 array; the current index into the array; the allocated size of the
162 array. */
163 struct target_ops **target_structs;
164 unsigned target_struct_size;
165 unsigned target_struct_index;
166 unsigned target_struct_allocsize;
167 #define DEFAULT_ALLOCSIZE 10
168
169 /* The initial current target, so that there is always a semi-valid
170 current target. */
171
172 static struct target_ops dummy_target;
173
174 /* Top of target stack. */
175
176 static struct target_ops *target_stack;
177
178 /* The target structure we are currently using to talk to a process
179 or file or whatever "inferior" we have. */
180
181 struct target_ops current_target;
182
183 /* Command list for target. */
184
185 static struct cmd_list_element *targetlist = NULL;
186
187 /* Nonzero if we should trust readonly sections from the
188 executable when reading memory. */
189
190 static int trust_readonly = 0;
191
192 /* Nonzero if we should show true memory content including
193 memory breakpoint inserted by gdb. */
194
195 static int show_memory_breakpoints = 0;
196
197 /* Non-zero if we want to see trace of target level stuff. */
198
199 static int targetdebug = 0;
200 static void
201 show_targetdebug (struct ui_file *file, int from_tty,
202 struct cmd_list_element *c, const char *value)
203 {
204 fprintf_filtered (file, _("Target debugging is %s.\n"), value);
205 }
206
207 static void setup_target_debug (void);
208
209 /* The option sets this. */
210 static int stack_cache_enabled_p_1 = 1;
211 /* And set_stack_cache_enabled_p updates this.
212 The reason for the separation is so that we don't flush the cache for
213 on->on transitions. */
214 static int stack_cache_enabled_p = 1;
215
216 /* This is called *after* the stack-cache has been set.
217 Flush the cache for off->on and on->off transitions.
218 There's no real need to flush the cache for on->off transitions,
219 except cleanliness. */
220
221 static void
222 set_stack_cache_enabled_p (char *args, int from_tty,
223 struct cmd_list_element *c)
224 {
225 if (stack_cache_enabled_p != stack_cache_enabled_p_1)
226 target_dcache_invalidate ();
227
228 stack_cache_enabled_p = stack_cache_enabled_p_1;
229 }
230
231 static void
232 show_stack_cache_enabled_p (struct ui_file *file, int from_tty,
233 struct cmd_list_element *c, const char *value)
234 {
235 fprintf_filtered (file, _("Cache use for stack accesses is %s.\n"), value);
236 }
237
238 /* Cache of memory operations, to speed up remote access. */
239 static DCACHE *target_dcache;
240
241 /* Invalidate the target dcache. */
242
243 void
244 target_dcache_invalidate (void)
245 {
246 dcache_invalidate (target_dcache);
247 }
248
249 /* The user just typed 'target' without the name of a target. */
250
251 static void
252 target_command (char *arg, int from_tty)
253 {
254 fputs_filtered ("Argument required (target name). Try `help target'\n",
255 gdb_stdout);
256 }
257
258 /* Default target_has_* methods for process_stratum targets. */
259
260 int
261 default_child_has_all_memory (struct target_ops *ops)
262 {
263 /* If no inferior selected, then we can't read memory here. */
264 if (ptid_equal (inferior_ptid, null_ptid))
265 return 0;
266
267 return 1;
268 }
269
270 int
271 default_child_has_memory (struct target_ops *ops)
272 {
273 /* If no inferior selected, then we can't read memory here. */
274 if (ptid_equal (inferior_ptid, null_ptid))
275 return 0;
276
277 return 1;
278 }
279
280 int
281 default_child_has_stack (struct target_ops *ops)
282 {
283 /* If no inferior selected, there's no stack. */
284 if (ptid_equal (inferior_ptid, null_ptid))
285 return 0;
286
287 return 1;
288 }
289
290 int
291 default_child_has_registers (struct target_ops *ops)
292 {
293 /* Can't read registers from no inferior. */
294 if (ptid_equal (inferior_ptid, null_ptid))
295 return 0;
296
297 return 1;
298 }
299
300 int
301 default_child_has_execution (struct target_ops *ops)
302 {
303 /* If there's no thread selected, then we can't make it run through
304 hoops. */
305 if (ptid_equal (inferior_ptid, null_ptid))
306 return 0;
307
308 return 1;
309 }
310
311
312 int
313 target_has_all_memory_1 (void)
314 {
315 struct target_ops *t;
316
317 for (t = current_target.beneath; t != NULL; t = t->beneath)
318 if (t->to_has_all_memory (t))
319 return 1;
320
321 return 0;
322 }
323
324 int
325 target_has_memory_1 (void)
326 {
327 struct target_ops *t;
328
329 for (t = current_target.beneath; t != NULL; t = t->beneath)
330 if (t->to_has_memory (t))
331 return 1;
332
333 return 0;
334 }
335
336 int
337 target_has_stack_1 (void)
338 {
339 struct target_ops *t;
340
341 for (t = current_target.beneath; t != NULL; t = t->beneath)
342 if (t->to_has_stack (t))
343 return 1;
344
345 return 0;
346 }
347
348 int
349 target_has_registers_1 (void)
350 {
351 struct target_ops *t;
352
353 for (t = current_target.beneath; t != NULL; t = t->beneath)
354 if (t->to_has_registers (t))
355 return 1;
356
357 return 0;
358 }
359
360 int
361 target_has_execution_1 (void)
362 {
363 struct target_ops *t;
364
365 for (t = current_target.beneath; t != NULL; t = t->beneath)
366 if (t->to_has_execution (t))
367 return 1;
368
369 return 0;
370 }
371
372 /* Add a possible target architecture to the list. */
373
374 void
375 add_target (struct target_ops *t)
376 {
377 /* Provide default values for all "must have" methods. */
378 if (t->to_xfer_partial == NULL)
379 t->to_xfer_partial = default_xfer_partial;
380
381 if (t->to_has_all_memory == NULL)
382 t->to_has_all_memory = (int (*) (struct target_ops *)) return_zero;
383
384 if (t->to_has_memory == NULL)
385 t->to_has_memory = (int (*) (struct target_ops *)) return_zero;
386
387 if (t->to_has_stack == NULL)
388 t->to_has_stack = (int (*) (struct target_ops *)) return_zero;
389
390 if (t->to_has_registers == NULL)
391 t->to_has_registers = (int (*) (struct target_ops *)) return_zero;
392
393 if (t->to_has_execution == NULL)
394 t->to_has_execution = (int (*) (struct target_ops *)) return_zero;
395
396 if (!target_structs)
397 {
398 target_struct_allocsize = DEFAULT_ALLOCSIZE;
399 target_structs = (struct target_ops **) xmalloc
400 (target_struct_allocsize * sizeof (*target_structs));
401 }
402 if (target_struct_size >= target_struct_allocsize)
403 {
404 target_struct_allocsize *= 2;
405 target_structs = (struct target_ops **)
406 xrealloc ((char *) target_structs,
407 target_struct_allocsize * sizeof (*target_structs));
408 }
409 target_structs[target_struct_size++] = t;
410
411 if (targetlist == NULL)
412 add_prefix_cmd ("target", class_run, target_command, _("\
413 Connect to a target machine or process.\n\
414 The first argument is the type or protocol of the target machine.\n\
415 Remaining arguments are interpreted by the target protocol. For more\n\
416 information on the arguments for a particular protocol, type\n\
417 `help target ' followed by the protocol name."),
418 &targetlist, "target ", 0, &cmdlist);
419 add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist);
420 }
421
422 /* Stub functions */
423
424 void
425 target_ignore (void)
426 {
427 }
428
429 void
430 target_kill (void)
431 {
432 struct target_ops *t;
433
434 for (t = current_target.beneath; t != NULL; t = t->beneath)
435 if (t->to_kill != NULL)
436 {
437 if (targetdebug)
438 fprintf_unfiltered (gdb_stdlog, "target_kill ()\n");
439
440 t->to_kill (t);
441 return;
442 }
443
444 noprocess ();
445 }
446
447 void
448 target_load (char *arg, int from_tty)
449 {
450 target_dcache_invalidate ();
451 (*current_target.to_load) (arg, from_tty);
452 }
453
454 void
455 target_create_inferior (char *exec_file, char *args,
456 char **env, int from_tty)
457 {
458 struct target_ops *t;
459 for (t = current_target.beneath; t != NULL; t = t->beneath)
460 {
461 if (t->to_create_inferior != NULL)
462 {
463 t->to_create_inferior (t, exec_file, args, env, from_tty);
464 if (targetdebug)
465 fprintf_unfiltered (gdb_stdlog,
466 "target_create_inferior (%s, %s, xxx, %d)\n",
467 exec_file, args, from_tty);
468 return;
469 }
470 }
471
472 internal_error (__FILE__, __LINE__,
473 "could not find a target to create inferior");
474 }
475
476 void
477 target_terminal_inferior (void)
478 {
479 /* A background resume (``run&'') should leave GDB in control of the
480 terminal. Use target_can_async_p, not target_is_async_p, since at
481 this point the target is not async yet. However, if sync_execution
482 is not set, we know it will become async prior to resume. */
483 if (target_can_async_p () && !sync_execution)
484 return;
485
486 /* If GDB is resuming the inferior in the foreground, install
487 inferior's terminal modes. */
488 (*current_target.to_terminal_inferior) ();
489 }
490
491 static int
492 nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write,
493 struct target_ops *t)
494 {
495 errno = EIO; /* Can't read/write this location */
496 return 0; /* No bytes handled */
497 }
498
499 static void
500 tcomplain (void)
501 {
502 error (_("You can't do that when your target is `%s'"),
503 current_target.to_shortname);
504 }
505
506 void
507 noprocess (void)
508 {
509 error (_("You can't do that without a process to debug."));
510 }
511
512 static int
513 nosymbol (char *name, CORE_ADDR *addrp)
514 {
515 return 1; /* Symbol does not exist in target env */
516 }
517
518 static void
519 default_terminal_info (char *args, int from_tty)
520 {
521 printf_unfiltered (_("No saved terminal information.\n"));
522 }
523
524 /* A default implementation for the to_get_ada_task_ptid target method.
525
526 This function builds the PTID by using both LWP and TID as part of
527 the PTID lwp and tid elements. The pid used is the pid of the
528 inferior_ptid. */
529
530 static ptid_t
531 default_get_ada_task_ptid (long lwp, long tid)
532 {
533 return ptid_build (ptid_get_pid (inferior_ptid), lwp, tid);
534 }
535
536 /* Go through the target stack from top to bottom, copying over zero
537 entries in current_target, then filling in still empty entries. In
538 effect, we are doing class inheritance through the pushed target
539 vectors.
540
541 NOTE: cagney/2003-10-17: The problem with this inheritance, as it
542 is currently implemented, is that it discards any knowledge of
543 which target an inherited method originally belonged to.
544 Consequently, new new target methods should instead explicitly and
545 locally search the target stack for the target that can handle the
546 request. */
547
548 static void
549 update_current_target (void)
550 {
551 struct target_ops *t;
552
553 /* First, reset current's contents. */
554 memset (&current_target, 0, sizeof (current_target));
555
556 #define INHERIT(FIELD, TARGET) \
557 if (!current_target.FIELD) \
558 current_target.FIELD = (TARGET)->FIELD
559
560 for (t = target_stack; t; t = t->beneath)
561 {
562 INHERIT (to_shortname, t);
563 INHERIT (to_longname, t);
564 INHERIT (to_doc, t);
565 /* Do not inherit to_open. */
566 /* Do not inherit to_close. */
567 /* Do not inherit to_attach. */
568 INHERIT (to_post_attach, t);
569 INHERIT (to_attach_no_wait, t);
570 /* Do not inherit to_detach. */
571 /* Do not inherit to_disconnect. */
572 /* Do not inherit to_resume. */
573 /* Do not inherit to_wait. */
574 /* Do not inherit to_fetch_registers. */
575 /* Do not inherit to_store_registers. */
576 INHERIT (to_prepare_to_store, t);
577 INHERIT (deprecated_xfer_memory, t);
578 INHERIT (to_files_info, t);
579 INHERIT (to_insert_breakpoint, t);
580 INHERIT (to_remove_breakpoint, t);
581 INHERIT (to_can_use_hw_breakpoint, t);
582 INHERIT (to_insert_hw_breakpoint, t);
583 INHERIT (to_remove_hw_breakpoint, t);
584 INHERIT (to_insert_watchpoint, t);
585 INHERIT (to_remove_watchpoint, t);
586 INHERIT (to_stopped_data_address, t);
587 INHERIT (to_have_steppable_watchpoint, t);
588 INHERIT (to_have_continuable_watchpoint, t);
589 INHERIT (to_stopped_by_watchpoint, t);
590 INHERIT (to_watchpoint_addr_within_range, t);
591 INHERIT (to_region_ok_for_hw_watchpoint, t);
592 INHERIT (to_terminal_init, t);
593 INHERIT (to_terminal_inferior, t);
594 INHERIT (to_terminal_ours_for_output, t);
595 INHERIT (to_terminal_ours, t);
596 INHERIT (to_terminal_save_ours, t);
597 INHERIT (to_terminal_info, t);
598 /* Do not inherit to_kill. */
599 INHERIT (to_load, t);
600 INHERIT (to_lookup_symbol, t);
601 /* Do no inherit to_create_inferior. */
602 INHERIT (to_post_startup_inferior, t);
603 INHERIT (to_acknowledge_created_inferior, t);
604 INHERIT (to_insert_fork_catchpoint, t);
605 INHERIT (to_remove_fork_catchpoint, t);
606 INHERIT (to_insert_vfork_catchpoint, t);
607 INHERIT (to_remove_vfork_catchpoint, t);
608 /* Do not inherit to_follow_fork. */
609 INHERIT (to_insert_exec_catchpoint, t);
610 INHERIT (to_remove_exec_catchpoint, t);
611 INHERIT (to_set_syscall_catchpoint, t);
612 INHERIT (to_has_exited, t);
613 /* Do not inherit to_mourn_inferiour. */
614 INHERIT (to_can_run, t);
615 INHERIT (to_notice_signals, t);
616 /* Do not inherit to_thread_alive. */
617 /* Do not inherit to_find_new_threads. */
618 /* Do not inherit to_pid_to_str. */
619 INHERIT (to_extra_thread_info, t);
620 INHERIT (to_stop, t);
621 /* Do not inherit to_xfer_partial. */
622 INHERIT (to_rcmd, t);
623 INHERIT (to_pid_to_exec_file, t);
624 INHERIT (to_log_command, t);
625 INHERIT (to_stratum, t);
626 /* Do not inherit to_has_all_memory */
627 /* Do not inherit to_has_memory */
628 /* Do not inherit to_has_stack */
629 /* Do not inherit to_has_registers */
630 /* Do not inherit to_has_execution */
631 INHERIT (to_has_thread_control, t);
632 INHERIT (to_can_async_p, t);
633 INHERIT (to_is_async_p, t);
634 INHERIT (to_async, t);
635 INHERIT (to_async_mask, t);
636 INHERIT (to_find_memory_regions, t);
637 INHERIT (to_make_corefile_notes, t);
638 INHERIT (to_get_bookmark, t);
639 INHERIT (to_goto_bookmark, t);
640 /* Do not inherit to_get_thread_local_address. */
641 INHERIT (to_can_execute_reverse, t);
642 INHERIT (to_thread_architecture, t);
643 /* Do not inherit to_read_description. */
644 INHERIT (to_get_ada_task_ptid, t);
645 /* Do not inherit to_search_memory. */
646 INHERIT (to_supports_multi_process, t);
647 INHERIT (to_trace_init, t);
648 INHERIT (to_download_tracepoint, t);
649 INHERIT (to_download_trace_state_variable, t);
650 INHERIT (to_trace_set_readonly_regions, t);
651 INHERIT (to_trace_start, t);
652 INHERIT (to_get_trace_status, t);
653 INHERIT (to_trace_stop, t);
654 INHERIT (to_trace_find, t);
655 INHERIT (to_get_trace_state_variable_value, t);
656 INHERIT (to_save_trace_data, t);
657 INHERIT (to_upload_tracepoints, t);
658 INHERIT (to_upload_trace_state_variables, t);
659 INHERIT (to_get_raw_trace_data, t);
660 INHERIT (to_set_disconnected_tracing, t);
661 INHERIT (to_magic, t);
662 /* Do not inherit to_memory_map. */
663 /* Do not inherit to_flash_erase. */
664 /* Do not inherit to_flash_done. */
665 }
666 #undef INHERIT
667
668 /* Clean up a target struct so it no longer has any zero pointers in
669 it. Some entries are defaulted to a method that print an error,
670 others are hard-wired to a standard recursive default. */
671
672 #define de_fault(field, value) \
673 if (!current_target.field) \
674 current_target.field = value
675
676 de_fault (to_open,
677 (void (*) (char *, int))
678 tcomplain);
679 de_fault (to_close,
680 (void (*) (int))
681 target_ignore);
682 de_fault (to_post_attach,
683 (void (*) (int))
684 target_ignore);
685 de_fault (to_prepare_to_store,
686 (void (*) (struct regcache *))
687 noprocess);
688 de_fault (deprecated_xfer_memory,
689 (int (*) (CORE_ADDR, gdb_byte *, int, int, struct mem_attrib *, struct target_ops *))
690 nomemory);
691 de_fault (to_files_info,
692 (void (*) (struct target_ops *))
693 target_ignore);
694 de_fault (to_insert_breakpoint,
695 memory_insert_breakpoint);
696 de_fault (to_remove_breakpoint,
697 memory_remove_breakpoint);
698 de_fault (to_can_use_hw_breakpoint,
699 (int (*) (int, int, int))
700 return_zero);
701 de_fault (to_insert_hw_breakpoint,
702 (int (*) (struct gdbarch *, struct bp_target_info *))
703 return_minus_one);
704 de_fault (to_remove_hw_breakpoint,
705 (int (*) (struct gdbarch *, struct bp_target_info *))
706 return_minus_one);
707 de_fault (to_insert_watchpoint,
708 (int (*) (CORE_ADDR, int, int))
709 return_minus_one);
710 de_fault (to_remove_watchpoint,
711 (int (*) (CORE_ADDR, int, int))
712 return_minus_one);
713 de_fault (to_stopped_by_watchpoint,
714 (int (*) (void))
715 return_zero);
716 de_fault (to_stopped_data_address,
717 (int (*) (struct target_ops *, CORE_ADDR *))
718 return_zero);
719 de_fault (to_watchpoint_addr_within_range,
720 default_watchpoint_addr_within_range);
721 de_fault (to_region_ok_for_hw_watchpoint,
722 default_region_ok_for_hw_watchpoint);
723 de_fault (to_terminal_init,
724 (void (*) (void))
725 target_ignore);
726 de_fault (to_terminal_inferior,
727 (void (*) (void))
728 target_ignore);
729 de_fault (to_terminal_ours_for_output,
730 (void (*) (void))
731 target_ignore);
732 de_fault (to_terminal_ours,
733 (void (*) (void))
734 target_ignore);
735 de_fault (to_terminal_save_ours,
736 (void (*) (void))
737 target_ignore);
738 de_fault (to_terminal_info,
739 default_terminal_info);
740 de_fault (to_load,
741 (void (*) (char *, int))
742 tcomplain);
743 de_fault (to_lookup_symbol,
744 (int (*) (char *, CORE_ADDR *))
745 nosymbol);
746 de_fault (to_post_startup_inferior,
747 (void (*) (ptid_t))
748 target_ignore);
749 de_fault (to_acknowledge_created_inferior,
750 (void (*) (int))
751 target_ignore);
752 de_fault (to_insert_fork_catchpoint,
753 (void (*) (int))
754 tcomplain);
755 de_fault (to_remove_fork_catchpoint,
756 (int (*) (int))
757 tcomplain);
758 de_fault (to_insert_vfork_catchpoint,
759 (void (*) (int))
760 tcomplain);
761 de_fault (to_remove_vfork_catchpoint,
762 (int (*) (int))
763 tcomplain);
764 de_fault (to_insert_exec_catchpoint,
765 (void (*) (int))
766 tcomplain);
767 de_fault (to_remove_exec_catchpoint,
768 (int (*) (int))
769 tcomplain);
770 de_fault (to_set_syscall_catchpoint,
771 (int (*) (int, int, int, int, int *))
772 tcomplain);
773 de_fault (to_has_exited,
774 (int (*) (int, int, int *))
775 return_zero);
776 de_fault (to_can_run,
777 return_zero);
778 de_fault (to_notice_signals,
779 (void (*) (ptid_t))
780 target_ignore);
781 de_fault (to_extra_thread_info,
782 (char *(*) (struct thread_info *))
783 return_zero);
784 de_fault (to_stop,
785 (void (*) (ptid_t))
786 target_ignore);
787 current_target.to_xfer_partial = current_xfer_partial;
788 de_fault (to_rcmd,
789 (void (*) (char *, struct ui_file *))
790 tcomplain);
791 de_fault (to_pid_to_exec_file,
792 (char *(*) (int))
793 return_zero);
794 de_fault (to_async,
795 (void (*) (void (*) (enum inferior_event_type, void*), void*))
796 tcomplain);
797 de_fault (to_async_mask,
798 (int (*) (int))
799 return_one);
800 de_fault (to_thread_architecture,
801 default_thread_architecture);
802 current_target.to_read_description = NULL;
803 de_fault (to_get_ada_task_ptid,
804 (ptid_t (*) (long, long))
805 default_get_ada_task_ptid);
806 de_fault (to_supports_multi_process,
807 (int (*) (void))
808 return_zero);
809 de_fault (to_trace_init,
810 (void (*) (void))
811 tcomplain);
812 de_fault (to_download_tracepoint,
813 (void (*) (struct breakpoint *))
814 tcomplain);
815 de_fault (to_download_trace_state_variable,
816 (void (*) (struct trace_state_variable *))
817 tcomplain);
818 de_fault (to_trace_set_readonly_regions,
819 (void (*) (void))
820 tcomplain);
821 de_fault (to_trace_start,
822 (void (*) (void))
823 tcomplain);
824 de_fault (to_get_trace_status,
825 (int (*) (struct trace_status *))
826 return_minus_one);
827 de_fault (to_trace_stop,
828 (void (*) (void))
829 tcomplain);
830 de_fault (to_trace_find,
831 (int (*) (enum trace_find_type, int, ULONGEST, ULONGEST, int *))
832 return_zero);
833 de_fault (to_get_trace_state_variable_value,
834 (int (*) (int, LONGEST *))
835 return_zero);
836 de_fault (to_save_trace_data,
837 (int (*) (char *))
838 tcomplain);
839 de_fault (to_upload_tracepoints,
840 (int (*) (struct uploaded_tp **))
841 return_zero);
842 de_fault (to_upload_trace_state_variables,
843 (int (*) (struct uploaded_tsv **))
844 return_zero);
845 de_fault (to_get_raw_trace_data,
846 (LONGEST (*) (gdb_byte *, ULONGEST, LONGEST))
847 tcomplain);
848 de_fault (to_set_disconnected_tracing,
849 (void (*) (int))
850 tcomplain);
851 #undef de_fault
852
853 /* Finally, position the target-stack beneath the squashed
854 "current_target". That way code looking for a non-inherited
855 target method can quickly and simply find it. */
856 current_target.beneath = target_stack;
857
858 if (targetdebug)
859 setup_target_debug ();
860 }
861
862 /* Push a new target type into the stack of the existing target accessors,
863 possibly superseding some of the existing accessors.
864
865 Result is zero if the pushed target ended up on top of the stack,
866 nonzero if at least one target is on top of it.
867
868 Rather than allow an empty stack, we always have the dummy target at
869 the bottom stratum, so we can call the function vectors without
870 checking them. */
871
872 int
873 push_target (struct target_ops *t)
874 {
875 struct target_ops **cur;
876
877 /* Check magic number. If wrong, it probably means someone changed
878 the struct definition, but not all the places that initialize one. */
879 if (t->to_magic != OPS_MAGIC)
880 {
881 fprintf_unfiltered (gdb_stderr,
882 "Magic number of %s target struct wrong\n",
883 t->to_shortname);
884 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
885 }
886
887 /* Find the proper stratum to install this target in. */
888 for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
889 {
890 if ((int) (t->to_stratum) >= (int) (*cur)->to_stratum)
891 break;
892 }
893
894 /* If there's already targets at this stratum, remove them. */
895 /* FIXME: cagney/2003-10-15: I think this should be popping all
896 targets to CUR, and not just those at this stratum level. */
897 while ((*cur) != NULL && t->to_stratum == (*cur)->to_stratum)
898 {
899 /* There's already something at this stratum level. Close it,
900 and un-hook it from the stack. */
901 struct target_ops *tmp = (*cur);
902 (*cur) = (*cur)->beneath;
903 tmp->beneath = NULL;
904 target_close (tmp, 0);
905 }
906
907 /* We have removed all targets in our stratum, now add the new one. */
908 t->beneath = (*cur);
909 (*cur) = t;
910
911 update_current_target ();
912
913 /* Not on top? */
914 return (t != target_stack);
915 }
916
917 /* Remove a target_ops vector from the stack, wherever it may be.
918 Return how many times it was removed (0 or 1). */
919
920 int
921 unpush_target (struct target_ops *t)
922 {
923 struct target_ops **cur;
924 struct target_ops *tmp;
925
926 if (t->to_stratum == dummy_stratum)
927 internal_error (__FILE__, __LINE__,
928 "Attempt to unpush the dummy target");
929
930 /* Look for the specified target. Note that we assume that a target
931 can only occur once in the target stack. */
932
933 for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
934 {
935 if ((*cur) == t)
936 break;
937 }
938
939 if ((*cur) == NULL)
940 return 0; /* Didn't find target_ops, quit now */
941
942 /* NOTE: cagney/2003-12-06: In '94 the close call was made
943 unconditional by moving it to before the above check that the
944 target was in the target stack (something about "Change the way
945 pushing and popping of targets work to support target overlays
946 and inheritance"). This doesn't make much sense - only open
947 targets should be closed. */
948 target_close (t, 0);
949
950 /* Unchain the target */
951 tmp = (*cur);
952 (*cur) = (*cur)->beneath;
953 tmp->beneath = NULL;
954
955 update_current_target ();
956
957 return 1;
958 }
959
960 void
961 pop_target (void)
962 {
963 target_close (target_stack, 0); /* Let it clean up */
964 if (unpush_target (target_stack) == 1)
965 return;
966
967 fprintf_unfiltered (gdb_stderr,
968 "pop_target couldn't find target %s\n",
969 current_target.to_shortname);
970 internal_error (__FILE__, __LINE__, _("failed internal consistency check"));
971 }
972
973 void
974 pop_all_targets_above (enum strata above_stratum, int quitting)
975 {
976 while ((int) (current_target.to_stratum) > (int) above_stratum)
977 {
978 target_close (target_stack, quitting);
979 if (!unpush_target (target_stack))
980 {
981 fprintf_unfiltered (gdb_stderr,
982 "pop_all_targets couldn't find target %s\n",
983 target_stack->to_shortname);
984 internal_error (__FILE__, __LINE__,
985 _("failed internal consistency check"));
986 break;
987 }
988 }
989 }
990
991 void
992 pop_all_targets (int quitting)
993 {
994 pop_all_targets_above (dummy_stratum, quitting);
995 }
996
997 /* Using the objfile specified in OBJFILE, find the address for the
998 current thread's thread-local storage with offset OFFSET. */
999 CORE_ADDR
1000 target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
1001 {
1002 volatile CORE_ADDR addr = 0;
1003 struct target_ops *target;
1004
1005 for (target = current_target.beneath;
1006 target != NULL;
1007 target = target->beneath)
1008 {
1009 if (target->to_get_thread_local_address != NULL)
1010 break;
1011 }
1012
1013 if (target != NULL
1014 && gdbarch_fetch_tls_load_module_address_p (target_gdbarch))
1015 {
1016 ptid_t ptid = inferior_ptid;
1017 volatile struct gdb_exception ex;
1018
1019 TRY_CATCH (ex, RETURN_MASK_ALL)
1020 {
1021 CORE_ADDR lm_addr;
1022
1023 /* Fetch the load module address for this objfile. */
1024 lm_addr = gdbarch_fetch_tls_load_module_address (target_gdbarch,
1025 objfile);
1026 /* If it's 0, throw the appropriate exception. */
1027 if (lm_addr == 0)
1028 throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR,
1029 _("TLS load module not found"));
1030
1031 addr = target->to_get_thread_local_address (target, ptid, lm_addr, offset);
1032 }
1033 /* If an error occurred, print TLS related messages here. Otherwise,
1034 throw the error to some higher catcher. */
1035 if (ex.reason < 0)
1036 {
1037 int objfile_is_library = (objfile->flags & OBJF_SHARED);
1038
1039 switch (ex.error)
1040 {
1041 case TLS_NO_LIBRARY_SUPPORT_ERROR:
1042 error (_("Cannot find thread-local variables in this thread library."));
1043 break;
1044 case TLS_LOAD_MODULE_NOT_FOUND_ERROR:
1045 if (objfile_is_library)
1046 error (_("Cannot find shared library `%s' in dynamic"
1047 " linker's load module list"), objfile->name);
1048 else
1049 error (_("Cannot find executable file `%s' in dynamic"
1050 " linker's load module list"), objfile->name);
1051 break;
1052 case TLS_NOT_ALLOCATED_YET_ERROR:
1053 if (objfile_is_library)
1054 error (_("The inferior has not yet allocated storage for"
1055 " thread-local variables in\n"
1056 "the shared library `%s'\n"
1057 "for %s"),
1058 objfile->name, target_pid_to_str (ptid));
1059 else
1060 error (_("The inferior has not yet allocated storage for"
1061 " thread-local variables in\n"
1062 "the executable `%s'\n"
1063 "for %s"),
1064 objfile->name, target_pid_to_str (ptid));
1065 break;
1066 case TLS_GENERIC_ERROR:
1067 if (objfile_is_library)
1068 error (_("Cannot find thread-local storage for %s, "
1069 "shared library %s:\n%s"),
1070 target_pid_to_str (ptid),
1071 objfile->name, ex.message);
1072 else
1073 error (_("Cannot find thread-local storage for %s, "
1074 "executable file %s:\n%s"),
1075 target_pid_to_str (ptid),
1076 objfile->name, ex.message);
1077 break;
1078 default:
1079 throw_exception (ex);
1080 break;
1081 }
1082 }
1083 }
1084 /* It wouldn't be wrong here to try a gdbarch method, too; finding
1085 TLS is an ABI-specific thing. But we don't do that yet. */
1086 else
1087 error (_("Cannot find thread-local variables on this target"));
1088
1089 return addr;
1090 }
1091
1092 #undef MIN
1093 #define MIN(A, B) (((A) <= (B)) ? (A) : (B))
1094
1095 /* target_read_string -- read a null terminated string, up to LEN bytes,
1096 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
1097 Set *STRING to a pointer to malloc'd memory containing the data; the caller
1098 is responsible for freeing it. Return the number of bytes successfully
1099 read. */
1100
1101 int
1102 target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop)
1103 {
1104 int tlen, origlen, offset, i;
1105 gdb_byte buf[4];
1106 int errcode = 0;
1107 char *buffer;
1108 int buffer_allocated;
1109 char *bufptr;
1110 unsigned int nbytes_read = 0;
1111
1112 gdb_assert (string);
1113
1114 /* Small for testing. */
1115 buffer_allocated = 4;
1116 buffer = xmalloc (buffer_allocated);
1117 bufptr = buffer;
1118
1119 origlen = len;
1120
1121 while (len > 0)
1122 {
1123 tlen = MIN (len, 4 - (memaddr & 3));
1124 offset = memaddr & 3;
1125
1126 errcode = target_read_memory (memaddr & ~3, buf, sizeof buf);
1127 if (errcode != 0)
1128 {
1129 /* The transfer request might have crossed the boundary to an
1130 unallocated region of memory. Retry the transfer, requesting
1131 a single byte. */
1132 tlen = 1;
1133 offset = 0;
1134 errcode = target_read_memory (memaddr, buf, 1);
1135 if (errcode != 0)
1136 goto done;
1137 }
1138
1139 if (bufptr - buffer + tlen > buffer_allocated)
1140 {
1141 unsigned int bytes;
1142 bytes = bufptr - buffer;
1143 buffer_allocated *= 2;
1144 buffer = xrealloc (buffer, buffer_allocated);
1145 bufptr = buffer + bytes;
1146 }
1147
1148 for (i = 0; i < tlen; i++)
1149 {
1150 *bufptr++ = buf[i + offset];
1151 if (buf[i + offset] == '\000')
1152 {
1153 nbytes_read += i + 1;
1154 goto done;
1155 }
1156 }
1157
1158 memaddr += tlen;
1159 len -= tlen;
1160 nbytes_read += tlen;
1161 }
1162 done:
1163 *string = buffer;
1164 if (errnop != NULL)
1165 *errnop = errcode;
1166 return nbytes_read;
1167 }
1168
1169 struct target_section_table *
1170 target_get_section_table (struct target_ops *target)
1171 {
1172 struct target_ops *t;
1173
1174 if (targetdebug)
1175 fprintf_unfiltered (gdb_stdlog, "target_get_section_table ()\n");
1176
1177 for (t = target; t != NULL; t = t->beneath)
1178 if (t->to_get_section_table != NULL)
1179 return (*t->to_get_section_table) (t);
1180
1181 return NULL;
1182 }
1183
1184 /* Find a section containing ADDR. */
1185
1186 struct target_section *
1187 target_section_by_addr (struct target_ops *target, CORE_ADDR addr)
1188 {
1189 struct target_section_table *table = target_get_section_table (target);
1190 struct target_section *secp;
1191
1192 if (table == NULL)
1193 return NULL;
1194
1195 for (secp = table->sections; secp < table->sections_end; secp++)
1196 {
1197 if (addr >= secp->addr && addr < secp->endaddr)
1198 return secp;
1199 }
1200 return NULL;
1201 }
1202
1203 /* Perform a partial memory transfer.
1204 For docs see target.h, to_xfer_partial. */
1205
1206 static LONGEST
1207 memory_xfer_partial (struct target_ops *ops, enum target_object object,
1208 void *readbuf, const void *writebuf, ULONGEST memaddr,
1209 LONGEST len)
1210 {
1211 LONGEST res;
1212 int reg_len;
1213 struct mem_region *region;
1214 struct inferior *inf;
1215
1216 /* Zero length requests are ok and require no work. */
1217 if (len == 0)
1218 return 0;
1219
1220 /* For accesses to unmapped overlay sections, read directly from
1221 files. Must do this first, as MEMADDR may need adjustment. */
1222 if (readbuf != NULL && overlay_debugging)
1223 {
1224 struct obj_section *section = find_pc_overlay (memaddr);
1225 if (pc_in_unmapped_range (memaddr, section))
1226 {
1227 struct target_section_table *table
1228 = target_get_section_table (ops);
1229 const char *section_name = section->the_bfd_section->name;
1230 memaddr = overlay_mapped_address (memaddr, section);
1231 return section_table_xfer_memory_partial (readbuf, writebuf,
1232 memaddr, len,
1233 table->sections,
1234 table->sections_end,
1235 section_name);
1236 }
1237 }
1238
1239 /* Try the executable files, if "trust-readonly-sections" is set. */
1240 if (readbuf != NULL && trust_readonly)
1241 {
1242 struct target_section *secp;
1243 struct target_section_table *table;
1244
1245 secp = target_section_by_addr (ops, memaddr);
1246 if (secp != NULL
1247 && (bfd_get_section_flags (secp->bfd, secp->the_bfd_section)
1248 & SEC_READONLY))
1249 {
1250 table = target_get_section_table (ops);
1251 return section_table_xfer_memory_partial (readbuf, writebuf,
1252 memaddr, len,
1253 table->sections,
1254 table->sections_end,
1255 NULL);
1256 }
1257 }
1258
1259 /* Try GDB's internal data cache. */
1260 region = lookup_mem_region (memaddr);
1261 /* region->hi == 0 means there's no upper bound. */
1262 if (memaddr + len < region->hi || region->hi == 0)
1263 reg_len = len;
1264 else
1265 reg_len = region->hi - memaddr;
1266
1267 switch (region->attrib.mode)
1268 {
1269 case MEM_RO:
1270 if (writebuf != NULL)
1271 return -1;
1272 break;
1273
1274 case MEM_WO:
1275 if (readbuf != NULL)
1276 return -1;
1277 break;
1278
1279 case MEM_FLASH:
1280 /* We only support writing to flash during "load" for now. */
1281 if (writebuf != NULL)
1282 error (_("Writing to flash memory forbidden in this context"));
1283 break;
1284
1285 case MEM_NONE:
1286 return -1;
1287 }
1288
1289 if (!ptid_equal (inferior_ptid, null_ptid))
1290 inf = find_inferior_pid (ptid_get_pid (inferior_ptid));
1291 else
1292 inf = NULL;
1293
1294 if (inf != NULL
1295 && (region->attrib.cache
1296 || (stack_cache_enabled_p && object == TARGET_OBJECT_STACK_MEMORY)))
1297 {
1298 if (readbuf != NULL)
1299 res = dcache_xfer_memory (ops, target_dcache, memaddr, readbuf,
1300 reg_len, 0);
1301 else
1302 /* FIXME drow/2006-08-09: If we're going to preserve const
1303 correctness dcache_xfer_memory should take readbuf and
1304 writebuf. */
1305 res = dcache_xfer_memory (ops, target_dcache, memaddr,
1306 (void *) writebuf,
1307 reg_len, 1);
1308 if (res <= 0)
1309 return -1;
1310 else
1311 {
1312 if (readbuf && !show_memory_breakpoints)
1313 breakpoint_restore_shadows (readbuf, memaddr, reg_len);
1314 return res;
1315 }
1316 }
1317
1318 /* If none of those methods found the memory we wanted, fall back
1319 to a target partial transfer. Normally a single call to
1320 to_xfer_partial is enough; if it doesn't recognize an object
1321 it will call the to_xfer_partial of the next target down.
1322 But for memory this won't do. Memory is the only target
1323 object which can be read from more than one valid target.
1324 A core file, for instance, could have some of memory but
1325 delegate other bits to the target below it. So, we must
1326 manually try all targets. */
1327
1328 do
1329 {
1330 res = ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL,
1331 readbuf, writebuf, memaddr, reg_len);
1332 if (res > 0)
1333 break;
1334
1335 /* We want to continue past core files to executables, but not
1336 past a running target's memory. */
1337 if (ops->to_has_all_memory (ops))
1338 break;
1339
1340 ops = ops->beneath;
1341 }
1342 while (ops != NULL);
1343
1344 if (readbuf && !show_memory_breakpoints)
1345 breakpoint_restore_shadows (readbuf, memaddr, reg_len);
1346
1347 /* Make sure the cache gets updated no matter what - if we are writing
1348 to the stack. Even if this write is not tagged as such, we still need
1349 to update the cache. */
1350
1351 if (res > 0
1352 && inf != NULL
1353 && writebuf != NULL
1354 && !region->attrib.cache
1355 && stack_cache_enabled_p
1356 && object != TARGET_OBJECT_STACK_MEMORY)
1357 {
1358 dcache_update (target_dcache, memaddr, (void *) writebuf, res);
1359 }
1360
1361 /* If we still haven't got anything, return the last error. We
1362 give up. */
1363 return res;
1364 }
1365
1366 static void
1367 restore_show_memory_breakpoints (void *arg)
1368 {
1369 show_memory_breakpoints = (uintptr_t) arg;
1370 }
1371
1372 struct cleanup *
1373 make_show_memory_breakpoints_cleanup (int show)
1374 {
1375 int current = show_memory_breakpoints;
1376 show_memory_breakpoints = show;
1377
1378 return make_cleanup (restore_show_memory_breakpoints,
1379 (void *) (uintptr_t) current);
1380 }
1381
1382 /* For docs see target.h, to_xfer_partial. */
1383
1384 static LONGEST
1385 target_xfer_partial (struct target_ops *ops,
1386 enum target_object object, const char *annex,
1387 void *readbuf, const void *writebuf,
1388 ULONGEST offset, LONGEST len)
1389 {
1390 LONGEST retval;
1391
1392 gdb_assert (ops->to_xfer_partial != NULL);
1393
1394 /* If this is a memory transfer, let the memory-specific code
1395 have a look at it instead. Memory transfers are more
1396 complicated. */
1397 if (object == TARGET_OBJECT_MEMORY || object == TARGET_OBJECT_STACK_MEMORY)
1398 retval = memory_xfer_partial (ops, object, readbuf,
1399 writebuf, offset, len);
1400 else
1401 {
1402 enum target_object raw_object = object;
1403
1404 /* If this is a raw memory transfer, request the normal
1405 memory object from other layers. */
1406 if (raw_object == TARGET_OBJECT_RAW_MEMORY)
1407 raw_object = TARGET_OBJECT_MEMORY;
1408
1409 retval = ops->to_xfer_partial (ops, raw_object, annex, readbuf,
1410 writebuf, offset, len);
1411 }
1412
1413 if (targetdebug)
1414 {
1415 const unsigned char *myaddr = NULL;
1416
1417 fprintf_unfiltered (gdb_stdlog,
1418 "%s:target_xfer_partial (%d, %s, %s, %s, %s, %s) = %s",
1419 ops->to_shortname,
1420 (int) object,
1421 (annex ? annex : "(null)"),
1422 host_address_to_string (readbuf),
1423 host_address_to_string (writebuf),
1424 core_addr_to_string_nz (offset),
1425 plongest (len), plongest (retval));
1426
1427 if (readbuf)
1428 myaddr = readbuf;
1429 if (writebuf)
1430 myaddr = writebuf;
1431 if (retval > 0 && myaddr != NULL)
1432 {
1433 int i;
1434
1435 fputs_unfiltered (", bytes =", gdb_stdlog);
1436 for (i = 0; i < retval; i++)
1437 {
1438 if ((((intptr_t) &(myaddr[i])) & 0xf) == 0)
1439 {
1440 if (targetdebug < 2 && i > 0)
1441 {
1442 fprintf_unfiltered (gdb_stdlog, " ...");
1443 break;
1444 }
1445 fprintf_unfiltered (gdb_stdlog, "\n");
1446 }
1447
1448 fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff);
1449 }
1450 }
1451
1452 fputc_unfiltered ('\n', gdb_stdlog);
1453 }
1454 return retval;
1455 }
1456
1457 /* Read LEN bytes of target memory at address MEMADDR, placing the results in
1458 GDB's memory at MYADDR. Returns either 0 for success or an errno value
1459 if any error occurs.
1460
1461 If an error occurs, no guarantee is made about the contents of the data at
1462 MYADDR. In particular, the caller should not depend upon partial reads
1463 filling the buffer with good data. There is no way for the caller to know
1464 how much good data might have been transfered anyway. Callers that can
1465 deal with partial reads should call target_read (which will retry until
1466 it makes no progress, and then return how much was transferred). */
1467
1468 int
1469 target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
1470 {
1471 /* Dispatch to the topmost target, not the flattened current_target.
1472 Memory accesses check target->to_has_(all_)memory, and the
1473 flattened target doesn't inherit those. */
1474 if (target_read (current_target.beneath, TARGET_OBJECT_MEMORY, NULL,
1475 myaddr, memaddr, len) == len)
1476 return 0;
1477 else
1478 return EIO;
1479 }
1480
1481 /* Like target_read_memory, but specify explicitly that this is a read from
1482 the target's stack. This may trigger different cache behavior. */
1483
1484 int
1485 target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
1486 {
1487 /* Dispatch to the topmost target, not the flattened current_target.
1488 Memory accesses check target->to_has_(all_)memory, and the
1489 flattened target doesn't inherit those. */
1490
1491 if (target_read (current_target.beneath, TARGET_OBJECT_STACK_MEMORY, NULL,
1492 myaddr, memaddr, len) == len)
1493 return 0;
1494 else
1495 return EIO;
1496 }
1497
1498 /* Write LEN bytes from MYADDR to target memory at address MEMADDR.
1499 Returns either 0 for success or an errno value if any error occurs.
1500 If an error occurs, no guarantee is made about how much data got written.
1501 Callers that can deal with partial writes should call target_write. */
1502
1503 int
1504 target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
1505 {
1506 /* Dispatch to the topmost target, not the flattened current_target.
1507 Memory accesses check target->to_has_(all_)memory, and the
1508 flattened target doesn't inherit those. */
1509 if (target_write (current_target.beneath, TARGET_OBJECT_MEMORY, NULL,
1510 myaddr, memaddr, len) == len)
1511 return 0;
1512 else
1513 return EIO;
1514 }
1515
1516 /* Fetch the target's memory map. */
1517
1518 VEC(mem_region_s) *
1519 target_memory_map (void)
1520 {
1521 VEC(mem_region_s) *result;
1522 struct mem_region *last_one, *this_one;
1523 int ix;
1524 struct target_ops *t;
1525
1526 if (targetdebug)
1527 fprintf_unfiltered (gdb_stdlog, "target_memory_map ()\n");
1528
1529 for (t = current_target.beneath; t != NULL; t = t->beneath)
1530 if (t->to_memory_map != NULL)
1531 break;
1532
1533 if (t == NULL)
1534 return NULL;
1535
1536 result = t->to_memory_map (t);
1537 if (result == NULL)
1538 return NULL;
1539
1540 qsort (VEC_address (mem_region_s, result),
1541 VEC_length (mem_region_s, result),
1542 sizeof (struct mem_region), mem_region_cmp);
1543
1544 /* Check that regions do not overlap. Simultaneously assign
1545 a numbering for the "mem" commands to use to refer to
1546 each region. */
1547 last_one = NULL;
1548 for (ix = 0; VEC_iterate (mem_region_s, result, ix, this_one); ix++)
1549 {
1550 this_one->number = ix;
1551
1552 if (last_one && last_one->hi > this_one->lo)
1553 {
1554 warning (_("Overlapping regions in memory map: ignoring"));
1555 VEC_free (mem_region_s, result);
1556 return NULL;
1557 }
1558 last_one = this_one;
1559 }
1560
1561 return result;
1562 }
1563
1564 void
1565 target_flash_erase (ULONGEST address, LONGEST length)
1566 {
1567 struct target_ops *t;
1568
1569 for (t = current_target.beneath; t != NULL; t = t->beneath)
1570 if (t->to_flash_erase != NULL)
1571 {
1572 if (targetdebug)
1573 fprintf_unfiltered (gdb_stdlog, "target_flash_erase (%s, %s)\n",
1574 hex_string (address), phex (length, 0));
1575 t->to_flash_erase (t, address, length);
1576 return;
1577 }
1578
1579 tcomplain ();
1580 }
1581
1582 void
1583 target_flash_done (void)
1584 {
1585 struct target_ops *t;
1586
1587 for (t = current_target.beneath; t != NULL; t = t->beneath)
1588 if (t->to_flash_done != NULL)
1589 {
1590 if (targetdebug)
1591 fprintf_unfiltered (gdb_stdlog, "target_flash_done\n");
1592 t->to_flash_done (t);
1593 return;
1594 }
1595
1596 tcomplain ();
1597 }
1598
1599 static void
1600 show_trust_readonly (struct ui_file *file, int from_tty,
1601 struct cmd_list_element *c, const char *value)
1602 {
1603 fprintf_filtered (file, _("\
1604 Mode for reading from readonly sections is %s.\n"),
1605 value);
1606 }
1607
1608 /* More generic transfers. */
1609
1610 static LONGEST
1611 default_xfer_partial (struct target_ops *ops, enum target_object object,
1612 const char *annex, gdb_byte *readbuf,
1613 const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
1614 {
1615 if (object == TARGET_OBJECT_MEMORY
1616 && ops->deprecated_xfer_memory != NULL)
1617 /* If available, fall back to the target's
1618 "deprecated_xfer_memory" method. */
1619 {
1620 int xfered = -1;
1621 errno = 0;
1622 if (writebuf != NULL)
1623 {
1624 void *buffer = xmalloc (len);
1625 struct cleanup *cleanup = make_cleanup (xfree, buffer);
1626 memcpy (buffer, writebuf, len);
1627 xfered = ops->deprecated_xfer_memory (offset, buffer, len,
1628 1/*write*/, NULL, ops);
1629 do_cleanups (cleanup);
1630 }
1631 if (readbuf != NULL)
1632 xfered = ops->deprecated_xfer_memory (offset, readbuf, len,
1633 0/*read*/, NULL, ops);
1634 if (xfered > 0)
1635 return xfered;
1636 else if (xfered == 0 && errno == 0)
1637 /* "deprecated_xfer_memory" uses 0, cross checked against
1638 ERRNO as one indication of an error. */
1639 return 0;
1640 else
1641 return -1;
1642 }
1643 else if (ops->beneath != NULL)
1644 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
1645 readbuf, writebuf, offset, len);
1646 else
1647 return -1;
1648 }
1649
1650 /* The xfer_partial handler for the topmost target. Unlike the default,
1651 it does not need to handle memory specially; it just passes all
1652 requests down the stack. */
1653
1654 static LONGEST
1655 current_xfer_partial (struct target_ops *ops, enum target_object object,
1656 const char *annex, gdb_byte *readbuf,
1657 const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
1658 {
1659 if (ops->beneath != NULL)
1660 return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
1661 readbuf, writebuf, offset, len);
1662 else
1663 return -1;
1664 }
1665
1666 /* Target vector read/write partial wrapper functions. */
1667
1668 static LONGEST
1669 target_read_partial (struct target_ops *ops,
1670 enum target_object object,
1671 const char *annex, gdb_byte *buf,
1672 ULONGEST offset, LONGEST len)
1673 {
1674 return target_xfer_partial (ops, object, annex, buf, NULL, offset, len);
1675 }
1676
1677 static LONGEST
1678 target_write_partial (struct target_ops *ops,
1679 enum target_object object,
1680 const char *annex, const gdb_byte *buf,
1681 ULONGEST offset, LONGEST len)
1682 {
1683 return target_xfer_partial (ops, object, annex, NULL, buf, offset, len);
1684 }
1685
1686 /* Wrappers to perform the full transfer. */
1687
1688 /* For docs on target_read see target.h. */
1689
1690 LONGEST
1691 target_read (struct target_ops *ops,
1692 enum target_object object,
1693 const char *annex, gdb_byte *buf,
1694 ULONGEST offset, LONGEST len)
1695 {
1696 LONGEST xfered = 0;
1697 while (xfered < len)
1698 {
1699 LONGEST xfer = target_read_partial (ops, object, annex,
1700 (gdb_byte *) buf + xfered,
1701 offset + xfered, len - xfered);
1702 /* Call an observer, notifying them of the xfer progress? */
1703 if (xfer == 0)
1704 return xfered;
1705 if (xfer < 0)
1706 return -1;
1707 xfered += xfer;
1708 QUIT;
1709 }
1710 return len;
1711 }
1712
1713 LONGEST
1714 target_read_until_error (struct target_ops *ops,
1715 enum target_object object,
1716 const char *annex, gdb_byte *buf,
1717 ULONGEST offset, LONGEST len)
1718 {
1719 LONGEST xfered = 0;
1720 while (xfered < len)
1721 {
1722 LONGEST xfer = target_read_partial (ops, object, annex,
1723 (gdb_byte *) buf + xfered,
1724 offset + xfered, len - xfered);
1725 /* Call an observer, notifying them of the xfer progress? */
1726 if (xfer == 0)
1727 return xfered;
1728 if (xfer < 0)
1729 {
1730 /* We've got an error. Try to read in smaller blocks. */
1731 ULONGEST start = offset + xfered;
1732 ULONGEST remaining = len - xfered;
1733 ULONGEST half;
1734
1735 /* If an attempt was made to read a random memory address,
1736 it's likely that the very first byte is not accessible.
1737 Try reading the first byte, to avoid doing log N tries
1738 below. */
1739 xfer = target_read_partial (ops, object, annex,
1740 (gdb_byte *) buf + xfered, start, 1);
1741 if (xfer <= 0)
1742 return xfered;
1743 start += 1;
1744 remaining -= 1;
1745 half = remaining/2;
1746
1747 while (half > 0)
1748 {
1749 xfer = target_read_partial (ops, object, annex,
1750 (gdb_byte *) buf + xfered,
1751 start, half);
1752 if (xfer == 0)
1753 return xfered;
1754 if (xfer < 0)
1755 {
1756 remaining = half;
1757 }
1758 else
1759 {
1760 /* We have successfully read the first half. So, the
1761 error must be in the second half. Adjust start and
1762 remaining to point at the second half. */
1763 xfered += xfer;
1764 start += xfer;
1765 remaining -= xfer;
1766 }
1767 half = remaining/2;
1768 }
1769
1770 return xfered;
1771 }
1772 xfered += xfer;
1773 QUIT;
1774 }
1775 return len;
1776 }
1777
1778 /* An alternative to target_write with progress callbacks. */
1779
1780 LONGEST
1781 target_write_with_progress (struct target_ops *ops,
1782 enum target_object object,
1783 const char *annex, const gdb_byte *buf,
1784 ULONGEST offset, LONGEST len,
1785 void (*progress) (ULONGEST, void *), void *baton)
1786 {
1787 LONGEST xfered = 0;
1788
1789 /* Give the progress callback a chance to set up. */
1790 if (progress)
1791 (*progress) (0, baton);
1792
1793 while (xfered < len)
1794 {
1795 LONGEST xfer = target_write_partial (ops, object, annex,
1796 (gdb_byte *) buf + xfered,
1797 offset + xfered, len - xfered);
1798
1799 if (xfer == 0)
1800 return xfered;
1801 if (xfer < 0)
1802 return -1;
1803
1804 if (progress)
1805 (*progress) (xfer, baton);
1806
1807 xfered += xfer;
1808 QUIT;
1809 }
1810 return len;
1811 }
1812
1813 /* For docs on target_write see target.h. */
1814
1815 LONGEST
1816 target_write (struct target_ops *ops,
1817 enum target_object object,
1818 const char *annex, const gdb_byte *buf,
1819 ULONGEST offset, LONGEST len)
1820 {
1821 return target_write_with_progress (ops, object, annex, buf, offset, len,
1822 NULL, NULL);
1823 }
1824
1825 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1826 the size of the transferred data. PADDING additional bytes are
1827 available in *BUF_P. This is a helper function for
1828 target_read_alloc; see the declaration of that function for more
1829 information. */
1830
1831 static LONGEST
1832 target_read_alloc_1 (struct target_ops *ops, enum target_object object,
1833 const char *annex, gdb_byte **buf_p, int padding)
1834 {
1835 size_t buf_alloc, buf_pos;
1836 gdb_byte *buf;
1837 LONGEST n;
1838
1839 /* This function does not have a length parameter; it reads the
1840 entire OBJECT). Also, it doesn't support objects fetched partly
1841 from one target and partly from another (in a different stratum,
1842 e.g. a core file and an executable). Both reasons make it
1843 unsuitable for reading memory. */
1844 gdb_assert (object != TARGET_OBJECT_MEMORY);
1845
1846 /* Start by reading up to 4K at a time. The target will throttle
1847 this number down if necessary. */
1848 buf_alloc = 4096;
1849 buf = xmalloc (buf_alloc);
1850 buf_pos = 0;
1851 while (1)
1852 {
1853 n = target_read_partial (ops, object, annex, &buf[buf_pos],
1854 buf_pos, buf_alloc - buf_pos - padding);
1855 if (n < 0)
1856 {
1857 /* An error occurred. */
1858 xfree (buf);
1859 return -1;
1860 }
1861 else if (n == 0)
1862 {
1863 /* Read all there was. */
1864 if (buf_pos == 0)
1865 xfree (buf);
1866 else
1867 *buf_p = buf;
1868 return buf_pos;
1869 }
1870
1871 buf_pos += n;
1872
1873 /* If the buffer is filling up, expand it. */
1874 if (buf_alloc < buf_pos * 2)
1875 {
1876 buf_alloc *= 2;
1877 buf = xrealloc (buf, buf_alloc);
1878 }
1879
1880 QUIT;
1881 }
1882 }
1883
1884 /* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1885 the size of the transferred data. See the declaration in "target.h"
1886 function for more information about the return value. */
1887
1888 LONGEST
1889 target_read_alloc (struct target_ops *ops, enum target_object object,
1890 const char *annex, gdb_byte **buf_p)
1891 {
1892 return target_read_alloc_1 (ops, object, annex, buf_p, 0);
1893 }
1894
1895 /* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and
1896 returned as a string, allocated using xmalloc. If an error occurs
1897 or the transfer is unsupported, NULL is returned. Empty objects
1898 are returned as allocated but empty strings. A warning is issued
1899 if the result contains any embedded NUL bytes. */
1900
1901 char *
1902 target_read_stralloc (struct target_ops *ops, enum target_object object,
1903 const char *annex)
1904 {
1905 gdb_byte *buffer;
1906 LONGEST transferred;
1907
1908 transferred = target_read_alloc_1 (ops, object, annex, &buffer, 1);
1909
1910 if (transferred < 0)
1911 return NULL;
1912
1913 if (transferred == 0)
1914 return xstrdup ("");
1915
1916 buffer[transferred] = 0;
1917 if (strlen (buffer) < transferred)
1918 warning (_("target object %d, annex %s, "
1919 "contained unexpected null characters"),
1920 (int) object, annex ? annex : "(none)");
1921
1922 return (char *) buffer;
1923 }
1924
1925 /* Memory transfer methods. */
1926
1927 void
1928 get_target_memory (struct target_ops *ops, CORE_ADDR addr, gdb_byte *buf,
1929 LONGEST len)
1930 {
1931 /* This method is used to read from an alternate, non-current
1932 target. This read must bypass the overlay support (as symbols
1933 don't match this target), and GDB's internal cache (wrong cache
1934 for this target). */
1935 if (target_read (ops, TARGET_OBJECT_RAW_MEMORY, NULL, buf, addr, len)
1936 != len)
1937 memory_error (EIO, addr);
1938 }
1939
1940 ULONGEST
1941 get_target_memory_unsigned (struct target_ops *ops,
1942 CORE_ADDR addr, int len, enum bfd_endian byte_order)
1943 {
1944 gdb_byte buf[sizeof (ULONGEST)];
1945
1946 gdb_assert (len <= sizeof (buf));
1947 get_target_memory (ops, addr, buf, len);
1948 return extract_unsigned_integer (buf, len, byte_order);
1949 }
1950
1951 static void
1952 target_info (char *args, int from_tty)
1953 {
1954 struct target_ops *t;
1955 int has_all_mem = 0;
1956
1957 if (symfile_objfile != NULL)
1958 printf_unfiltered (_("Symbols from \"%s\".\n"), symfile_objfile->name);
1959
1960 for (t = target_stack; t != NULL; t = t->beneath)
1961 {
1962 if (!(*t->to_has_memory) (t))
1963 continue;
1964
1965 if ((int) (t->to_stratum) <= (int) dummy_stratum)
1966 continue;
1967 if (has_all_mem)
1968 printf_unfiltered (_("\tWhile running this, GDB does not access memory from...\n"));
1969 printf_unfiltered ("%s:\n", t->to_longname);
1970 (t->to_files_info) (t);
1971 has_all_mem = (*t->to_has_all_memory) (t);
1972 }
1973 }
1974
1975 /* This function is called before any new inferior is created, e.g.
1976 by running a program, attaching, or connecting to a target.
1977 It cleans up any state from previous invocations which might
1978 change between runs. This is a subset of what target_preopen
1979 resets (things which might change between targets). */
1980
1981 void
1982 target_pre_inferior (int from_tty)
1983 {
1984 /* Clear out solib state. Otherwise the solib state of the previous
1985 inferior might have survived and is entirely wrong for the new
1986 target. This has been observed on GNU/Linux using glibc 2.3. How
1987 to reproduce:
1988
1989 bash$ ./foo&
1990 [1] 4711
1991 bash$ ./foo&
1992 [1] 4712
1993 bash$ gdb ./foo
1994 [...]
1995 (gdb) attach 4711
1996 (gdb) detach
1997 (gdb) attach 4712
1998 Cannot access memory at address 0xdeadbeef
1999 */
2000
2001 /* In some OSs, the shared library list is the same/global/shared
2002 across inferiors. If code is shared between processes, so are
2003 memory regions and features. */
2004 if (!gdbarch_has_global_solist (target_gdbarch))
2005 {
2006 no_shared_libraries (NULL, from_tty);
2007
2008 invalidate_target_mem_regions ();
2009
2010 target_clear_description ();
2011 }
2012 }
2013
2014 /* Callback for iterate_over_inferiors. Gets rid of the given
2015 inferior. */
2016
2017 static int
2018 dispose_inferior (struct inferior *inf, void *args)
2019 {
2020 struct thread_info *thread;
2021
2022 thread = any_thread_of_process (inf->pid);
2023 if (thread)
2024 {
2025 switch_to_thread (thread->ptid);
2026
2027 /* Core inferiors actually should be detached, not killed. */
2028 if (target_has_execution)
2029 target_kill ();
2030 else
2031 target_detach (NULL, 0);
2032 }
2033
2034 return 0;
2035 }
2036
2037 /* This is to be called by the open routine before it does
2038 anything. */
2039
2040 void
2041 target_preopen (int from_tty)
2042 {
2043 dont_repeat ();
2044
2045 if (have_inferiors ())
2046 {
2047 if (!from_tty
2048 || !have_live_inferiors ()
2049 || query (_("A program is being debugged already. Kill it? ")))
2050 iterate_over_inferiors (dispose_inferior, NULL);
2051 else
2052 error (_("Program not killed."));
2053 }
2054
2055 /* Calling target_kill may remove the target from the stack. But if
2056 it doesn't (which seems like a win for UDI), remove it now. */
2057 /* Leave the exec target, though. The user may be switching from a
2058 live process to a core of the same program. */
2059 pop_all_targets_above (file_stratum, 0);
2060
2061 target_pre_inferior (from_tty);
2062 }
2063
2064 /* Detach a target after doing deferred register stores. */
2065
2066 void
2067 target_detach (char *args, int from_tty)
2068 {
2069 struct target_ops* t;
2070
2071 if (gdbarch_has_global_breakpoints (target_gdbarch))
2072 /* Don't remove global breakpoints here. They're removed on
2073 disconnection from the target. */
2074 ;
2075 else
2076 /* If we're in breakpoints-always-inserted mode, have to remove
2077 them before detaching. */
2078 remove_breakpoints_pid (PIDGET (inferior_ptid));
2079
2080 for (t = current_target.beneath; t != NULL; t = t->beneath)
2081 {
2082 if (t->to_detach != NULL)
2083 {
2084 t->to_detach (t, args, from_tty);
2085 if (targetdebug)
2086 fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n",
2087 args, from_tty);
2088 return;
2089 }
2090 }
2091
2092 internal_error (__FILE__, __LINE__, "could not find a target to detach");
2093 }
2094
2095 void
2096 target_disconnect (char *args, int from_tty)
2097 {
2098 struct target_ops *t;
2099
2100 /* If we're in breakpoints-always-inserted mode or if breakpoints
2101 are global across processes, we have to remove them before
2102 disconnecting. */
2103 remove_breakpoints ();
2104
2105 for (t = current_target.beneath; t != NULL; t = t->beneath)
2106 if (t->to_disconnect != NULL)
2107 {
2108 if (targetdebug)
2109 fprintf_unfiltered (gdb_stdlog, "target_disconnect (%s, %d)\n",
2110 args, from_tty);
2111 t->to_disconnect (t, args, from_tty);
2112 return;
2113 }
2114
2115 tcomplain ();
2116 }
2117
2118 ptid_t
2119 target_wait (ptid_t ptid, struct target_waitstatus *status, int options)
2120 {
2121 struct target_ops *t;
2122
2123 for (t = current_target.beneath; t != NULL; t = t->beneath)
2124 {
2125 if (t->to_wait != NULL)
2126 {
2127 ptid_t retval = (*t->to_wait) (t, ptid, status, options);
2128
2129 if (targetdebug)
2130 {
2131 char *status_string;
2132
2133 status_string = target_waitstatus_to_string (status);
2134 fprintf_unfiltered (gdb_stdlog,
2135 "target_wait (%d, status) = %d, %s\n",
2136 PIDGET (ptid), PIDGET (retval),
2137 status_string);
2138 xfree (status_string);
2139 }
2140
2141 return retval;
2142 }
2143 }
2144
2145 noprocess ();
2146 }
2147
2148 char *
2149 target_pid_to_str (ptid_t ptid)
2150 {
2151 struct target_ops *t;
2152
2153 for (t = current_target.beneath; t != NULL; t = t->beneath)
2154 {
2155 if (t->to_pid_to_str != NULL)
2156 return (*t->to_pid_to_str) (t, ptid);
2157 }
2158
2159 return normal_pid_to_str (ptid);
2160 }
2161
2162 void
2163 target_resume (ptid_t ptid, int step, enum target_signal signal)
2164 {
2165 struct target_ops *t;
2166
2167 target_dcache_invalidate ();
2168
2169 for (t = current_target.beneath; t != NULL; t = t->beneath)
2170 {
2171 if (t->to_resume != NULL)
2172 {
2173 t->to_resume (t, ptid, step, signal);
2174 if (targetdebug)
2175 fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n",
2176 PIDGET (ptid),
2177 step ? "step" : "continue",
2178 target_signal_to_name (signal));
2179
2180 set_executing (ptid, 1);
2181 set_running (ptid, 1);
2182 clear_inline_frame_state (ptid);
2183 return;
2184 }
2185 }
2186
2187 noprocess ();
2188 }
2189 /* Look through the list of possible targets for a target that can
2190 follow forks. */
2191
2192 int
2193 target_follow_fork (int follow_child)
2194 {
2195 struct target_ops *t;
2196
2197 for (t = current_target.beneath; t != NULL; t = t->beneath)
2198 {
2199 if (t->to_follow_fork != NULL)
2200 {
2201 int retval = t->to_follow_fork (t, follow_child);
2202 if (targetdebug)
2203 fprintf_unfiltered (gdb_stdlog, "target_follow_fork (%d) = %d\n",
2204 follow_child, retval);
2205 return retval;
2206 }
2207 }
2208
2209 /* Some target returned a fork event, but did not know how to follow it. */
2210 internal_error (__FILE__, __LINE__,
2211 "could not find a target to follow fork");
2212 }
2213
2214 void
2215 target_mourn_inferior (void)
2216 {
2217 struct target_ops *t;
2218 for (t = current_target.beneath; t != NULL; t = t->beneath)
2219 {
2220 if (t->to_mourn_inferior != NULL)
2221 {
2222 t->to_mourn_inferior (t);
2223 if (targetdebug)
2224 fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n");
2225
2226 /* We no longer need to keep handles on any of the object files.
2227 Make sure to release them to avoid unnecessarily locking any
2228 of them while we're not actually debugging. */
2229 bfd_cache_close_all ();
2230
2231 return;
2232 }
2233 }
2234
2235 internal_error (__FILE__, __LINE__,
2236 "could not find a target to follow mourn inferiour");
2237 }
2238
2239 /* Look for a target which can describe architectural features, starting
2240 from TARGET. If we find one, return its description. */
2241
2242 const struct target_desc *
2243 target_read_description (struct target_ops *target)
2244 {
2245 struct target_ops *t;
2246
2247 for (t = target; t != NULL; t = t->beneath)
2248 if (t->to_read_description != NULL)
2249 {
2250 const struct target_desc *tdesc;
2251
2252 tdesc = t->to_read_description (t);
2253 if (tdesc)
2254 return tdesc;
2255 }
2256
2257 return NULL;
2258 }
2259
2260 /* The default implementation of to_search_memory.
2261 This implements a basic search of memory, reading target memory and
2262 performing the search here (as opposed to performing the search in on the
2263 target side with, for example, gdbserver). */
2264
2265 int
2266 simple_search_memory (struct target_ops *ops,
2267 CORE_ADDR start_addr, ULONGEST search_space_len,
2268 const gdb_byte *pattern, ULONGEST pattern_len,
2269 CORE_ADDR *found_addrp)
2270 {
2271 /* NOTE: also defined in find.c testcase. */
2272 #define SEARCH_CHUNK_SIZE 16000
2273 const unsigned chunk_size = SEARCH_CHUNK_SIZE;
2274 /* Buffer to hold memory contents for searching. */
2275 gdb_byte *search_buf;
2276 unsigned search_buf_size;
2277 struct cleanup *old_cleanups;
2278
2279 search_buf_size = chunk_size + pattern_len - 1;
2280
2281 /* No point in trying to allocate a buffer larger than the search space. */
2282 if (search_space_len < search_buf_size)
2283 search_buf_size = search_space_len;
2284
2285 search_buf = malloc (search_buf_size);
2286 if (search_buf == NULL)
2287 error (_("Unable to allocate memory to perform the search."));
2288 old_cleanups = make_cleanup (free_current_contents, &search_buf);
2289
2290 /* Prime the search buffer. */
2291
2292 if (target_read (ops, TARGET_OBJECT_MEMORY, NULL,
2293 search_buf, start_addr, search_buf_size) != search_buf_size)
2294 {
2295 warning (_("Unable to access target memory at %s, halting search."),
2296 hex_string (start_addr));
2297 do_cleanups (old_cleanups);
2298 return -1;
2299 }
2300
2301 /* Perform the search.
2302
2303 The loop is kept simple by allocating [N + pattern-length - 1] bytes.
2304 When we've scanned N bytes we copy the trailing bytes to the start and
2305 read in another N bytes. */
2306
2307 while (search_space_len >= pattern_len)
2308 {
2309 gdb_byte *found_ptr;
2310 unsigned nr_search_bytes = min (search_space_len, search_buf_size);
2311
2312 found_ptr = memmem (search_buf, nr_search_bytes,
2313 pattern, pattern_len);
2314
2315 if (found_ptr != NULL)
2316 {
2317 CORE_ADDR found_addr = start_addr + (found_ptr - search_buf);
2318 *found_addrp = found_addr;
2319 do_cleanups (old_cleanups);
2320 return 1;
2321 }
2322
2323 /* Not found in this chunk, skip to next chunk. */
2324
2325 /* Don't let search_space_len wrap here, it's unsigned. */
2326 if (search_space_len >= chunk_size)
2327 search_space_len -= chunk_size;
2328 else
2329 search_space_len = 0;
2330
2331 if (search_space_len >= pattern_len)
2332 {
2333 unsigned keep_len = search_buf_size - chunk_size;
2334 CORE_ADDR read_addr = start_addr + chunk_size + keep_len;
2335 int nr_to_read;
2336
2337 /* Copy the trailing part of the previous iteration to the front
2338 of the buffer for the next iteration. */
2339 gdb_assert (keep_len == pattern_len - 1);
2340 memcpy (search_buf, search_buf + chunk_size, keep_len);
2341
2342 nr_to_read = min (search_space_len - keep_len, chunk_size);
2343
2344 if (target_read (ops, TARGET_OBJECT_MEMORY, NULL,
2345 search_buf + keep_len, read_addr,
2346 nr_to_read) != nr_to_read)
2347 {
2348 warning (_("Unable to access target memory at %s, halting search."),
2349 hex_string (read_addr));
2350 do_cleanups (old_cleanups);
2351 return -1;
2352 }
2353
2354 start_addr += chunk_size;
2355 }
2356 }
2357
2358 /* Not found. */
2359
2360 do_cleanups (old_cleanups);
2361 return 0;
2362 }
2363
2364 /* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
2365 sequence of bytes in PATTERN with length PATTERN_LEN.
2366
2367 The result is 1 if found, 0 if not found, and -1 if there was an error
2368 requiring halting of the search (e.g. memory read error).
2369 If the pattern is found the address is recorded in FOUND_ADDRP. */
2370
2371 int
2372 target_search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
2373 const gdb_byte *pattern, ULONGEST pattern_len,
2374 CORE_ADDR *found_addrp)
2375 {
2376 struct target_ops *t;
2377 int found;
2378
2379 /* We don't use INHERIT to set current_target.to_search_memory,
2380 so we have to scan the target stack and handle targetdebug
2381 ourselves. */
2382
2383 if (targetdebug)
2384 fprintf_unfiltered (gdb_stdlog, "target_search_memory (%s, ...)\n",
2385 hex_string (start_addr));
2386
2387 for (t = current_target.beneath; t != NULL; t = t->beneath)
2388 if (t->to_search_memory != NULL)
2389 break;
2390
2391 if (t != NULL)
2392 {
2393 found = t->to_search_memory (t, start_addr, search_space_len,
2394 pattern, pattern_len, found_addrp);
2395 }
2396 else
2397 {
2398 /* If a special version of to_search_memory isn't available, use the
2399 simple version. */
2400 found = simple_search_memory (current_target.beneath,
2401 start_addr, search_space_len,
2402 pattern, pattern_len, found_addrp);
2403 }
2404
2405 if (targetdebug)
2406 fprintf_unfiltered (gdb_stdlog, " = %d\n", found);
2407
2408 return found;
2409 }
2410
2411 /* Look through the currently pushed targets. If none of them will
2412 be able to restart the currently running process, issue an error
2413 message. */
2414
2415 void
2416 target_require_runnable (void)
2417 {
2418 struct target_ops *t;
2419
2420 for (t = target_stack; t != NULL; t = t->beneath)
2421 {
2422 /* If this target knows how to create a new program, then
2423 assume we will still be able to after killing the current
2424 one. Either killing and mourning will not pop T, or else
2425 find_default_run_target will find it again. */
2426 if (t->to_create_inferior != NULL)
2427 return;
2428
2429 /* Do not worry about thread_stratum targets that can not
2430 create inferiors. Assume they will be pushed again if
2431 necessary, and continue to the process_stratum. */
2432 if (t->to_stratum == thread_stratum
2433 || t->to_stratum == arch_stratum)
2434 continue;
2435
2436 error (_("\
2437 The \"%s\" target does not support \"run\". Try \"help target\" or \"continue\"."),
2438 t->to_shortname);
2439 }
2440
2441 /* This function is only called if the target is running. In that
2442 case there should have been a process_stratum target and it
2443 should either know how to create inferiors, or not... */
2444 internal_error (__FILE__, __LINE__, "No targets found");
2445 }
2446
2447 /* Look through the list of possible targets for a target that can
2448 execute a run or attach command without any other data. This is
2449 used to locate the default process stratum.
2450
2451 If DO_MESG is not NULL, the result is always valid (error() is
2452 called for errors); else, return NULL on error. */
2453
2454 static struct target_ops *
2455 find_default_run_target (char *do_mesg)
2456 {
2457 struct target_ops **t;
2458 struct target_ops *runable = NULL;
2459 int count;
2460
2461 count = 0;
2462
2463 for (t = target_structs; t < target_structs + target_struct_size;
2464 ++t)
2465 {
2466 if ((*t)->to_can_run && target_can_run (*t))
2467 {
2468 runable = *t;
2469 ++count;
2470 }
2471 }
2472
2473 if (count != 1)
2474 {
2475 if (do_mesg)
2476 error (_("Don't know how to %s. Try \"help target\"."), do_mesg);
2477 else
2478 return NULL;
2479 }
2480
2481 return runable;
2482 }
2483
2484 void
2485 find_default_attach (struct target_ops *ops, char *args, int from_tty)
2486 {
2487 struct target_ops *t;
2488
2489 t = find_default_run_target ("attach");
2490 (t->to_attach) (t, args, from_tty);
2491 return;
2492 }
2493
2494 void
2495 find_default_create_inferior (struct target_ops *ops,
2496 char *exec_file, char *allargs, char **env,
2497 int from_tty)
2498 {
2499 struct target_ops *t;
2500
2501 t = find_default_run_target ("run");
2502 (t->to_create_inferior) (t, exec_file, allargs, env, from_tty);
2503 return;
2504 }
2505
2506 static int
2507 find_default_can_async_p (void)
2508 {
2509 struct target_ops *t;
2510
2511 /* This may be called before the target is pushed on the stack;
2512 look for the default process stratum. If there's none, gdb isn't
2513 configured with a native debugger, and target remote isn't
2514 connected yet. */
2515 t = find_default_run_target (NULL);
2516 if (t && t->to_can_async_p)
2517 return (t->to_can_async_p) ();
2518 return 0;
2519 }
2520
2521 static int
2522 find_default_is_async_p (void)
2523 {
2524 struct target_ops *t;
2525
2526 /* This may be called before the target is pushed on the stack;
2527 look for the default process stratum. If there's none, gdb isn't
2528 configured with a native debugger, and target remote isn't
2529 connected yet. */
2530 t = find_default_run_target (NULL);
2531 if (t && t->to_is_async_p)
2532 return (t->to_is_async_p) ();
2533 return 0;
2534 }
2535
2536 static int
2537 find_default_supports_non_stop (void)
2538 {
2539 struct target_ops *t;
2540
2541 t = find_default_run_target (NULL);
2542 if (t && t->to_supports_non_stop)
2543 return (t->to_supports_non_stop) ();
2544 return 0;
2545 }
2546
2547 int
2548 target_supports_non_stop (void)
2549 {
2550 struct target_ops *t;
2551 for (t = &current_target; t != NULL; t = t->beneath)
2552 if (t->to_supports_non_stop)
2553 return t->to_supports_non_stop ();
2554
2555 return 0;
2556 }
2557
2558
2559 char *
2560 target_get_osdata (const char *type)
2561 {
2562 char *document;
2563 struct target_ops *t;
2564
2565 /* If we're already connected to something that can get us OS
2566 related data, use it. Otherwise, try using the native
2567 target. */
2568 if (current_target.to_stratum >= process_stratum)
2569 t = current_target.beneath;
2570 else
2571 t = find_default_run_target ("get OS data");
2572
2573 if (!t)
2574 return NULL;
2575
2576 return target_read_stralloc (t, TARGET_OBJECT_OSDATA, type);
2577 }
2578
2579 /* Determine the current address space of thread PTID. */
2580
2581 struct address_space *
2582 target_thread_address_space (ptid_t ptid)
2583 {
2584 struct address_space *aspace;
2585 struct inferior *inf;
2586 struct target_ops *t;
2587
2588 for (t = current_target.beneath; t != NULL; t = t->beneath)
2589 {
2590 if (t->to_thread_address_space != NULL)
2591 {
2592 aspace = t->to_thread_address_space (t, ptid);
2593 gdb_assert (aspace);
2594
2595 if (targetdebug)
2596 fprintf_unfiltered (gdb_stdlog,
2597 "target_thread_address_space (%s) = %d\n",
2598 target_pid_to_str (ptid),
2599 address_space_num (aspace));
2600 return aspace;
2601 }
2602 }
2603
2604 /* Fall-back to the "main" address space of the inferior. */
2605 inf = find_inferior_pid (ptid_get_pid (ptid));
2606
2607 if (inf == NULL || inf->aspace == NULL)
2608 internal_error (__FILE__, __LINE__, "\
2609 Can't determine the current address space of thread %s\n",
2610 target_pid_to_str (ptid));
2611
2612 return inf->aspace;
2613 }
2614
2615 static int
2616 default_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
2617 {
2618 return (len <= gdbarch_ptr_bit (target_gdbarch) / TARGET_CHAR_BIT);
2619 }
2620
2621 static int
2622 default_watchpoint_addr_within_range (struct target_ops *target,
2623 CORE_ADDR addr,
2624 CORE_ADDR start, int length)
2625 {
2626 return addr >= start && addr < start + length;
2627 }
2628
2629 static struct gdbarch *
2630 default_thread_architecture (struct target_ops *ops, ptid_t ptid)
2631 {
2632 return target_gdbarch;
2633 }
2634
2635 static int
2636 return_zero (void)
2637 {
2638 return 0;
2639 }
2640
2641 static int
2642 return_one (void)
2643 {
2644 return 1;
2645 }
2646
2647 static int
2648 return_minus_one (void)
2649 {
2650 return -1;
2651 }
2652
2653 /* Find a single runnable target in the stack and return it. If for
2654 some reason there is more than one, return NULL. */
2655
2656 struct target_ops *
2657 find_run_target (void)
2658 {
2659 struct target_ops **t;
2660 struct target_ops *runable = NULL;
2661 int count;
2662
2663 count = 0;
2664
2665 for (t = target_structs; t < target_structs + target_struct_size; ++t)
2666 {
2667 if ((*t)->to_can_run && target_can_run (*t))
2668 {
2669 runable = *t;
2670 ++count;
2671 }
2672 }
2673
2674 return (count == 1 ? runable : NULL);
2675 }
2676
2677 /* Find a single core_stratum target in the list of targets and return it.
2678 If for some reason there is more than one, return NULL. */
2679
2680 struct target_ops *
2681 find_core_target (void)
2682 {
2683 struct target_ops **t;
2684 struct target_ops *runable = NULL;
2685 int count;
2686
2687 count = 0;
2688
2689 for (t = target_structs; t < target_structs + target_struct_size;
2690 ++t)
2691 {
2692 if ((*t)->to_stratum == core_stratum)
2693 {
2694 runable = *t;
2695 ++count;
2696 }
2697 }
2698
2699 return (count == 1 ? runable : NULL);
2700 }
2701
2702 /*
2703 * Find the next target down the stack from the specified target.
2704 */
2705
2706 struct target_ops *
2707 find_target_beneath (struct target_ops *t)
2708 {
2709 return t->beneath;
2710 }
2711
2712 \f
2713 /* The inferior process has died. Long live the inferior! */
2714
2715 void
2716 generic_mourn_inferior (void)
2717 {
2718 ptid_t ptid;
2719
2720 ptid = inferior_ptid;
2721 inferior_ptid = null_ptid;
2722
2723 if (!ptid_equal (ptid, null_ptid))
2724 {
2725 int pid = ptid_get_pid (ptid);
2726 exit_inferior (pid);
2727 }
2728
2729 breakpoint_init_inferior (inf_exited);
2730 registers_changed ();
2731
2732 reopen_exec_file ();
2733 reinit_frame_cache ();
2734
2735 if (deprecated_detach_hook)
2736 deprecated_detach_hook ();
2737 }
2738 \f
2739 /* Helper function for child_wait and the derivatives of child_wait.
2740 HOSTSTATUS is the waitstatus from wait() or the equivalent; store our
2741 translation of that in OURSTATUS. */
2742 void
2743 store_waitstatus (struct target_waitstatus *ourstatus, int hoststatus)
2744 {
2745 if (WIFEXITED (hoststatus))
2746 {
2747 ourstatus->kind = TARGET_WAITKIND_EXITED;
2748 ourstatus->value.integer = WEXITSTATUS (hoststatus);
2749 }
2750 else if (!WIFSTOPPED (hoststatus))
2751 {
2752 ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
2753 ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus));
2754 }
2755 else
2756 {
2757 ourstatus->kind = TARGET_WAITKIND_STOPPED;
2758 ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus));
2759 }
2760 }
2761 \f
2762 /* Convert a normal process ID to a string. Returns the string in a
2763 static buffer. */
2764
2765 char *
2766 normal_pid_to_str (ptid_t ptid)
2767 {
2768 static char buf[32];
2769
2770 xsnprintf (buf, sizeof buf, "process %d", ptid_get_pid (ptid));
2771 return buf;
2772 }
2773
2774 static char *
2775 dummy_pid_to_str (struct target_ops *ops, ptid_t ptid)
2776 {
2777 return normal_pid_to_str (ptid);
2778 }
2779
2780 /* Error-catcher for target_find_memory_regions. */
2781 static int
2782 dummy_find_memory_regions (int (*ignore1) (), void *ignore2)
2783 {
2784 error (_("Command not implemented for this target."));
2785 return 0;
2786 }
2787
2788 /* Error-catcher for target_make_corefile_notes. */
2789 static char *
2790 dummy_make_corefile_notes (bfd *ignore1, int *ignore2)
2791 {
2792 error (_("Command not implemented for this target."));
2793 return NULL;
2794 }
2795
2796 /* Error-catcher for target_get_bookmark. */
2797 static gdb_byte *
2798 dummy_get_bookmark (char *ignore1, int ignore2)
2799 {
2800 tcomplain ();
2801 return NULL;
2802 }
2803
2804 /* Error-catcher for target_goto_bookmark. */
2805 static void
2806 dummy_goto_bookmark (gdb_byte *ignore, int from_tty)
2807 {
2808 tcomplain ();
2809 }
2810
2811 /* Set up the handful of non-empty slots needed by the dummy target
2812 vector. */
2813
2814 static void
2815 init_dummy_target (void)
2816 {
2817 dummy_target.to_shortname = "None";
2818 dummy_target.to_longname = "None";
2819 dummy_target.to_doc = "";
2820 dummy_target.to_attach = find_default_attach;
2821 dummy_target.to_detach =
2822 (void (*)(struct target_ops *, char *, int))target_ignore;
2823 dummy_target.to_create_inferior = find_default_create_inferior;
2824 dummy_target.to_can_async_p = find_default_can_async_p;
2825 dummy_target.to_is_async_p = find_default_is_async_p;
2826 dummy_target.to_supports_non_stop = find_default_supports_non_stop;
2827 dummy_target.to_pid_to_str = dummy_pid_to_str;
2828 dummy_target.to_stratum = dummy_stratum;
2829 dummy_target.to_find_memory_regions = dummy_find_memory_regions;
2830 dummy_target.to_make_corefile_notes = dummy_make_corefile_notes;
2831 dummy_target.to_get_bookmark = dummy_get_bookmark;
2832 dummy_target.to_goto_bookmark = dummy_goto_bookmark;
2833 dummy_target.to_xfer_partial = default_xfer_partial;
2834 dummy_target.to_has_all_memory = (int (*) (struct target_ops *)) return_zero;
2835 dummy_target.to_has_memory = (int (*) (struct target_ops *)) return_zero;
2836 dummy_target.to_has_stack = (int (*) (struct target_ops *)) return_zero;
2837 dummy_target.to_has_registers = (int (*) (struct target_ops *)) return_zero;
2838 dummy_target.to_has_execution = (int (*) (struct target_ops *)) return_zero;
2839 dummy_target.to_magic = OPS_MAGIC;
2840 }
2841 \f
2842 static void
2843 debug_to_open (char *args, int from_tty)
2844 {
2845 debug_target.to_open (args, from_tty);
2846
2847 fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty);
2848 }
2849
2850 void
2851 target_close (struct target_ops *targ, int quitting)
2852 {
2853 if (targ->to_xclose != NULL)
2854 targ->to_xclose (targ, quitting);
2855 else if (targ->to_close != NULL)
2856 targ->to_close (quitting);
2857
2858 if (targetdebug)
2859 fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting);
2860 }
2861
2862 void
2863 target_attach (char *args, int from_tty)
2864 {
2865 struct target_ops *t;
2866 for (t = current_target.beneath; t != NULL; t = t->beneath)
2867 {
2868 if (t->to_attach != NULL)
2869 {
2870 t->to_attach (t, args, from_tty);
2871 if (targetdebug)
2872 fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n",
2873 args, from_tty);
2874 return;
2875 }
2876 }
2877
2878 internal_error (__FILE__, __LINE__,
2879 "could not find a target to attach");
2880 }
2881
2882 int
2883 target_thread_alive (ptid_t ptid)
2884 {
2885 struct target_ops *t;
2886 for (t = current_target.beneath; t != NULL; t = t->beneath)
2887 {
2888 if (t->to_thread_alive != NULL)
2889 {
2890 int retval;
2891
2892 retval = t->to_thread_alive (t, ptid);
2893 if (targetdebug)
2894 fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n",
2895 PIDGET (ptid), retval);
2896
2897 return retval;
2898 }
2899 }
2900
2901 return 0;
2902 }
2903
2904 void
2905 target_find_new_threads (void)
2906 {
2907 struct target_ops *t;
2908 for (t = current_target.beneath; t != NULL; t = t->beneath)
2909 {
2910 if (t->to_find_new_threads != NULL)
2911 {
2912 t->to_find_new_threads (t);
2913 if (targetdebug)
2914 fprintf_unfiltered (gdb_stdlog, "target_find_new_threads ()\n");
2915
2916 return;
2917 }
2918 }
2919 }
2920
2921 static void
2922 debug_to_post_attach (int pid)
2923 {
2924 debug_target.to_post_attach (pid);
2925
2926 fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid);
2927 }
2928
2929 /* Return a pretty printed form of target_waitstatus.
2930 Space for the result is malloc'd, caller must free. */
2931
2932 char *
2933 target_waitstatus_to_string (const struct target_waitstatus *ws)
2934 {
2935 const char *kind_str = "status->kind = ";
2936
2937 switch (ws->kind)
2938 {
2939 case TARGET_WAITKIND_EXITED:
2940 return xstrprintf ("%sexited, status = %d",
2941 kind_str, ws->value.integer);
2942 case TARGET_WAITKIND_STOPPED:
2943 return xstrprintf ("%sstopped, signal = %s",
2944 kind_str, target_signal_to_name (ws->value.sig));
2945 case TARGET_WAITKIND_SIGNALLED:
2946 return xstrprintf ("%ssignalled, signal = %s",
2947 kind_str, target_signal_to_name (ws->value.sig));
2948 case TARGET_WAITKIND_LOADED:
2949 return xstrprintf ("%sloaded", kind_str);
2950 case TARGET_WAITKIND_FORKED:
2951 return xstrprintf ("%sforked", kind_str);
2952 case TARGET_WAITKIND_VFORKED:
2953 return xstrprintf ("%svforked", kind_str);
2954 case TARGET_WAITKIND_EXECD:
2955 return xstrprintf ("%sexecd", kind_str);
2956 case TARGET_WAITKIND_SYSCALL_ENTRY:
2957 return xstrprintf ("%sentered syscall", kind_str);
2958 case TARGET_WAITKIND_SYSCALL_RETURN:
2959 return xstrprintf ("%sexited syscall", kind_str);
2960 case TARGET_WAITKIND_SPURIOUS:
2961 return xstrprintf ("%sspurious", kind_str);
2962 case TARGET_WAITKIND_IGNORE:
2963 return xstrprintf ("%signore", kind_str);
2964 case TARGET_WAITKIND_NO_HISTORY:
2965 return xstrprintf ("%sno-history", kind_str);
2966 default:
2967 return xstrprintf ("%sunknown???", kind_str);
2968 }
2969 }
2970
2971 static void
2972 debug_print_register (const char * func,
2973 struct regcache *regcache, int regno)
2974 {
2975 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2976 fprintf_unfiltered (gdb_stdlog, "%s ", func);
2977 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)
2978 && gdbarch_register_name (gdbarch, regno) != NULL
2979 && gdbarch_register_name (gdbarch, regno)[0] != '\0')
2980 fprintf_unfiltered (gdb_stdlog, "(%s)",
2981 gdbarch_register_name (gdbarch, regno));
2982 else
2983 fprintf_unfiltered (gdb_stdlog, "(%d)", regno);
2984 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch))
2985 {
2986 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2987 int i, size = register_size (gdbarch, regno);
2988 unsigned char buf[MAX_REGISTER_SIZE];
2989 regcache_raw_collect (regcache, regno, buf);
2990 fprintf_unfiltered (gdb_stdlog, " = ");
2991 for (i = 0; i < size; i++)
2992 {
2993 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
2994 }
2995 if (size <= sizeof (LONGEST))
2996 {
2997 ULONGEST val = extract_unsigned_integer (buf, size, byte_order);
2998 fprintf_unfiltered (gdb_stdlog, " %s %s",
2999 core_addr_to_string_nz (val), plongest (val));
3000 }
3001 }
3002 fprintf_unfiltered (gdb_stdlog, "\n");
3003 }
3004
3005 void
3006 target_fetch_registers (struct regcache *regcache, int regno)
3007 {
3008 struct target_ops *t;
3009 for (t = current_target.beneath; t != NULL; t = t->beneath)
3010 {
3011 if (t->to_fetch_registers != NULL)
3012 {
3013 t->to_fetch_registers (t, regcache, regno);
3014 if (targetdebug)
3015 debug_print_register ("target_fetch_registers", regcache, regno);
3016 return;
3017 }
3018 }
3019 }
3020
3021 void
3022 target_store_registers (struct regcache *regcache, int regno)
3023 {
3024
3025 struct target_ops *t;
3026 for (t = current_target.beneath; t != NULL; t = t->beneath)
3027 {
3028 if (t->to_store_registers != NULL)
3029 {
3030 t->to_store_registers (t, regcache, regno);
3031 if (targetdebug)
3032 {
3033 debug_print_register ("target_store_registers", regcache, regno);
3034 }
3035 return;
3036 }
3037 }
3038
3039 noprocess ();
3040 }
3041
3042 int
3043 target_core_of_thread (ptid_t ptid)
3044 {
3045 struct target_ops *t;
3046
3047 for (t = current_target.beneath; t != NULL; t = t->beneath)
3048 {
3049 if (t->to_core_of_thread != NULL)
3050 {
3051 int retval = t->to_core_of_thread (t, ptid);
3052 if (targetdebug)
3053 fprintf_unfiltered (gdb_stdlog, "target_core_of_thread (%d) = %d\n",
3054 PIDGET (ptid), retval);
3055 return retval;
3056 }
3057 }
3058
3059 return -1;
3060 }
3061
3062 static void
3063 debug_to_prepare_to_store (struct regcache *regcache)
3064 {
3065 debug_target.to_prepare_to_store (regcache);
3066
3067 fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n");
3068 }
3069
3070 static int
3071 deprecated_debug_xfer_memory (CORE_ADDR memaddr, bfd_byte *myaddr, int len,
3072 int write, struct mem_attrib *attrib,
3073 struct target_ops *target)
3074 {
3075 int retval;
3076
3077 retval = debug_target.deprecated_xfer_memory (memaddr, myaddr, len, write,
3078 attrib, target);
3079
3080 fprintf_unfiltered (gdb_stdlog,
3081 "target_xfer_memory (%s, xxx, %d, %s, xxx) = %d",
3082 paddress (target_gdbarch, memaddr), len,
3083 write ? "write" : "read", retval);
3084
3085 if (retval > 0)
3086 {
3087 int i;
3088
3089 fputs_unfiltered (", bytes =", gdb_stdlog);
3090 for (i = 0; i < retval; i++)
3091 {
3092 if ((((intptr_t) &(myaddr[i])) & 0xf) == 0)
3093 {
3094 if (targetdebug < 2 && i > 0)
3095 {
3096 fprintf_unfiltered (gdb_stdlog, " ...");
3097 break;
3098 }
3099 fprintf_unfiltered (gdb_stdlog, "\n");
3100 }
3101
3102 fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff);
3103 }
3104 }
3105
3106 fputc_unfiltered ('\n', gdb_stdlog);
3107
3108 return retval;
3109 }
3110
3111 static void
3112 debug_to_files_info (struct target_ops *target)
3113 {
3114 debug_target.to_files_info (target);
3115
3116 fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n");
3117 }
3118
3119 static int
3120 debug_to_insert_breakpoint (struct gdbarch *gdbarch,
3121 struct bp_target_info *bp_tgt)
3122 {
3123 int retval;
3124
3125 retval = debug_target.to_insert_breakpoint (gdbarch, bp_tgt);
3126
3127 fprintf_unfiltered (gdb_stdlog,
3128 "target_insert_breakpoint (0x%lx, xxx) = %ld\n",
3129 (unsigned long) bp_tgt->placed_address,
3130 (unsigned long) retval);
3131 return retval;
3132 }
3133
3134 static int
3135 debug_to_remove_breakpoint (struct gdbarch *gdbarch,
3136 struct bp_target_info *bp_tgt)
3137 {
3138 int retval;
3139
3140 retval = debug_target.to_remove_breakpoint (gdbarch, bp_tgt);
3141
3142 fprintf_unfiltered (gdb_stdlog,
3143 "target_remove_breakpoint (0x%lx, xxx) = %ld\n",
3144 (unsigned long) bp_tgt->placed_address,
3145 (unsigned long) retval);
3146 return retval;
3147 }
3148
3149 static int
3150 debug_to_can_use_hw_breakpoint (int type, int cnt, int from_tty)
3151 {
3152 int retval;
3153
3154 retval = debug_target.to_can_use_hw_breakpoint (type, cnt, from_tty);
3155
3156 fprintf_unfiltered (gdb_stdlog,
3157 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
3158 (unsigned long) type,
3159 (unsigned long) cnt,
3160 (unsigned long) from_tty,
3161 (unsigned long) retval);
3162 return retval;
3163 }
3164
3165 static int
3166 debug_to_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len)
3167 {
3168 CORE_ADDR retval;
3169
3170 retval = debug_target.to_region_ok_for_hw_watchpoint (addr, len);
3171
3172 fprintf_unfiltered (gdb_stdlog,
3173 "target_region_ok_for_hw_watchpoint (%ld, %ld) = 0x%lx\n",
3174 (unsigned long) addr,
3175 (unsigned long) len,
3176 (unsigned long) retval);
3177 return retval;
3178 }
3179
3180 static int
3181 debug_to_stopped_by_watchpoint (void)
3182 {
3183 int retval;
3184
3185 retval = debug_target.to_stopped_by_watchpoint ();
3186
3187 fprintf_unfiltered (gdb_stdlog,
3188 "target_stopped_by_watchpoint () = %ld\n",
3189 (unsigned long) retval);
3190 return retval;
3191 }
3192
3193 static int
3194 debug_to_stopped_data_address (struct target_ops *target, CORE_ADDR *addr)
3195 {
3196 int retval;
3197
3198 retval = debug_target.to_stopped_data_address (target, addr);
3199
3200 fprintf_unfiltered (gdb_stdlog,
3201 "target_stopped_data_address ([0x%lx]) = %ld\n",
3202 (unsigned long)*addr,
3203 (unsigned long)retval);
3204 return retval;
3205 }
3206
3207 static int
3208 debug_to_watchpoint_addr_within_range (struct target_ops *target,
3209 CORE_ADDR addr,
3210 CORE_ADDR start, int length)
3211 {
3212 int retval;
3213
3214 retval = debug_target.to_watchpoint_addr_within_range (target, addr,
3215 start, length);
3216
3217 fprintf_filtered (gdb_stdlog,
3218 "target_watchpoint_addr_within_range (0x%lx, 0x%lx, %d) = %d\n",
3219 (unsigned long) addr, (unsigned long) start, length,
3220 retval);
3221 return retval;
3222 }
3223
3224 static int
3225 debug_to_insert_hw_breakpoint (struct gdbarch *gdbarch,
3226 struct bp_target_info *bp_tgt)
3227 {
3228 int retval;
3229
3230 retval = debug_target.to_insert_hw_breakpoint (gdbarch, bp_tgt);
3231
3232 fprintf_unfiltered (gdb_stdlog,
3233 "target_insert_hw_breakpoint (0x%lx, xxx) = %ld\n",
3234 (unsigned long) bp_tgt->placed_address,
3235 (unsigned long) retval);
3236 return retval;
3237 }
3238
3239 static int
3240 debug_to_remove_hw_breakpoint (struct gdbarch *gdbarch,
3241 struct bp_target_info *bp_tgt)
3242 {
3243 int retval;
3244
3245 retval = debug_target.to_remove_hw_breakpoint (gdbarch, bp_tgt);
3246
3247 fprintf_unfiltered (gdb_stdlog,
3248 "target_remove_hw_breakpoint (0x%lx, xxx) = %ld\n",
3249 (unsigned long) bp_tgt->placed_address,
3250 (unsigned long) retval);
3251 return retval;
3252 }
3253
3254 static int
3255 debug_to_insert_watchpoint (CORE_ADDR addr, int len, int type)
3256 {
3257 int retval;
3258
3259 retval = debug_target.to_insert_watchpoint (addr, len, type);
3260
3261 fprintf_unfiltered (gdb_stdlog,
3262 "target_insert_watchpoint (0x%lx, %d, %d) = %ld\n",
3263 (unsigned long) addr, len, type, (unsigned long) retval);
3264 return retval;
3265 }
3266
3267 static int
3268 debug_to_remove_watchpoint (CORE_ADDR addr, int len, int type)
3269 {
3270 int retval;
3271
3272 retval = debug_target.to_remove_watchpoint (addr, len, type);
3273
3274 fprintf_unfiltered (gdb_stdlog,
3275 "target_remove_watchpoint (0x%lx, %d, %d) = %ld\n",
3276 (unsigned long) addr, len, type, (unsigned long) retval);
3277 return retval;
3278 }
3279
3280 static void
3281 debug_to_terminal_init (void)
3282 {
3283 debug_target.to_terminal_init ();
3284
3285 fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n");
3286 }
3287
3288 static void
3289 debug_to_terminal_inferior (void)
3290 {
3291 debug_target.to_terminal_inferior ();
3292
3293 fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n");
3294 }
3295
3296 static void
3297 debug_to_terminal_ours_for_output (void)
3298 {
3299 debug_target.to_terminal_ours_for_output ();
3300
3301 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n");
3302 }
3303
3304 static void
3305 debug_to_terminal_ours (void)
3306 {
3307 debug_target.to_terminal_ours ();
3308
3309 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n");
3310 }
3311
3312 static void
3313 debug_to_terminal_save_ours (void)
3314 {
3315 debug_target.to_terminal_save_ours ();
3316
3317 fprintf_unfiltered (gdb_stdlog, "target_terminal_save_ours ()\n");
3318 }
3319
3320 static void
3321 debug_to_terminal_info (char *arg, int from_tty)
3322 {
3323 debug_target.to_terminal_info (arg, from_tty);
3324
3325 fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg,
3326 from_tty);
3327 }
3328
3329 static void
3330 debug_to_load (char *args, int from_tty)
3331 {
3332 debug_target.to_load (args, from_tty);
3333
3334 fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty);
3335 }
3336
3337 static int
3338 debug_to_lookup_symbol (char *name, CORE_ADDR *addrp)
3339 {
3340 int retval;
3341
3342 retval = debug_target.to_lookup_symbol (name, addrp);
3343
3344 fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name);
3345
3346 return retval;
3347 }
3348
3349 static void
3350 debug_to_post_startup_inferior (ptid_t ptid)
3351 {
3352 debug_target.to_post_startup_inferior (ptid);
3353
3354 fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n",
3355 PIDGET (ptid));
3356 }
3357
3358 static void
3359 debug_to_acknowledge_created_inferior (int pid)
3360 {
3361 debug_target.to_acknowledge_created_inferior (pid);
3362
3363 fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n",
3364 pid);
3365 }
3366
3367 static void
3368 debug_to_insert_fork_catchpoint (int pid)
3369 {
3370 debug_target.to_insert_fork_catchpoint (pid);
3371
3372 fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d)\n",
3373 pid);
3374 }
3375
3376 static int
3377 debug_to_remove_fork_catchpoint (int pid)
3378 {
3379 int retval;
3380
3381 retval = debug_target.to_remove_fork_catchpoint (pid);
3382
3383 fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n",
3384 pid, retval);
3385
3386 return retval;
3387 }
3388
3389 static void
3390 debug_to_insert_vfork_catchpoint (int pid)
3391 {
3392 debug_target.to_insert_vfork_catchpoint (pid);
3393
3394 fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)\n",
3395 pid);
3396 }
3397
3398 static int
3399 debug_to_remove_vfork_catchpoint (int pid)
3400 {
3401 int retval;
3402
3403 retval = debug_target.to_remove_vfork_catchpoint (pid);
3404
3405 fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n",
3406 pid, retval);
3407
3408 return retval;
3409 }
3410
3411 static void
3412 debug_to_insert_exec_catchpoint (int pid)
3413 {
3414 debug_target.to_insert_exec_catchpoint (pid);
3415
3416 fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d)\n",
3417 pid);
3418 }
3419
3420 static int
3421 debug_to_remove_exec_catchpoint (int pid)
3422 {
3423 int retval;
3424
3425 retval = debug_target.to_remove_exec_catchpoint (pid);
3426
3427 fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n",
3428 pid, retval);
3429
3430 return retval;
3431 }
3432
3433 static int
3434 debug_to_has_exited (int pid, int wait_status, int *exit_status)
3435 {
3436 int has_exited;
3437
3438 has_exited = debug_target.to_has_exited (pid, wait_status, exit_status);
3439
3440 fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n",
3441 pid, wait_status, *exit_status, has_exited);
3442
3443 return has_exited;
3444 }
3445
3446 static int
3447 debug_to_can_run (void)
3448 {
3449 int retval;
3450
3451 retval = debug_target.to_can_run ();
3452
3453 fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval);
3454
3455 return retval;
3456 }
3457
3458 static void
3459 debug_to_notice_signals (ptid_t ptid)
3460 {
3461 debug_target.to_notice_signals (ptid);
3462
3463 fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n",
3464 PIDGET (ptid));
3465 }
3466
3467 static struct gdbarch *
3468 debug_to_thread_architecture (struct target_ops *ops, ptid_t ptid)
3469 {
3470 struct gdbarch *retval;
3471
3472 retval = debug_target.to_thread_architecture (ops, ptid);
3473
3474 fprintf_unfiltered (gdb_stdlog, "target_thread_architecture (%s) = %s [%s]\n",
3475 target_pid_to_str (ptid), host_address_to_string (retval),
3476 gdbarch_bfd_arch_info (retval)->printable_name);
3477 return retval;
3478 }
3479
3480 static void
3481 debug_to_stop (ptid_t ptid)
3482 {
3483 debug_target.to_stop (ptid);
3484
3485 fprintf_unfiltered (gdb_stdlog, "target_stop (%s)\n",
3486 target_pid_to_str (ptid));
3487 }
3488
3489 static void
3490 debug_to_rcmd (char *command,
3491 struct ui_file *outbuf)
3492 {
3493 debug_target.to_rcmd (command, outbuf);
3494 fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command);
3495 }
3496
3497 static char *
3498 debug_to_pid_to_exec_file (int pid)
3499 {
3500 char *exec_file;
3501
3502 exec_file = debug_target.to_pid_to_exec_file (pid);
3503
3504 fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n",
3505 pid, exec_file);
3506
3507 return exec_file;
3508 }
3509
3510 static void
3511 setup_target_debug (void)
3512 {
3513 memcpy (&debug_target, &current_target, sizeof debug_target);
3514
3515 current_target.to_open = debug_to_open;
3516 current_target.to_post_attach = debug_to_post_attach;
3517 current_target.to_prepare_to_store = debug_to_prepare_to_store;
3518 current_target.deprecated_xfer_memory = deprecated_debug_xfer_memory;
3519 current_target.to_files_info = debug_to_files_info;
3520 current_target.to_insert_breakpoint = debug_to_insert_breakpoint;
3521 current_target.to_remove_breakpoint = debug_to_remove_breakpoint;
3522 current_target.to_can_use_hw_breakpoint = debug_to_can_use_hw_breakpoint;
3523 current_target.to_insert_hw_breakpoint = debug_to_insert_hw_breakpoint;
3524 current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint;
3525 current_target.to_insert_watchpoint = debug_to_insert_watchpoint;
3526 current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
3527 current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
3528 current_target.to_stopped_data_address = debug_to_stopped_data_address;
3529 current_target.to_watchpoint_addr_within_range = debug_to_watchpoint_addr_within_range;
3530 current_target.to_region_ok_for_hw_watchpoint = debug_to_region_ok_for_hw_watchpoint;
3531 current_target.to_terminal_init = debug_to_terminal_init;
3532 current_target.to_terminal_inferior = debug_to_terminal_inferior;
3533 current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output;
3534 current_target.to_terminal_ours = debug_to_terminal_ours;
3535 current_target.to_terminal_save_ours = debug_to_terminal_save_ours;
3536 current_target.to_terminal_info = debug_to_terminal_info;
3537 current_target.to_load = debug_to_load;
3538 current_target.to_lookup_symbol = debug_to_lookup_symbol;
3539 current_target.to_post_startup_inferior = debug_to_post_startup_inferior;
3540 current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior;
3541 current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint;
3542 current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
3543 current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
3544 current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint;
3545 current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint;
3546 current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
3547 current_target.to_has_exited = debug_to_has_exited;
3548 current_target.to_can_run = debug_to_can_run;
3549 current_target.to_notice_signals = debug_to_notice_signals;
3550 current_target.to_stop = debug_to_stop;
3551 current_target.to_rcmd = debug_to_rcmd;
3552 current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
3553 current_target.to_thread_architecture = debug_to_thread_architecture;
3554 }
3555 \f
3556
3557 static char targ_desc[] =
3558 "Names of targets and files being debugged.\n\
3559 Shows the entire stack of targets currently in use (including the exec-file,\n\
3560 core-file, and process, if any), as well as the symbol file name.";
3561
3562 static void
3563 do_monitor_command (char *cmd,
3564 int from_tty)
3565 {
3566 if ((current_target.to_rcmd
3567 == (void (*) (char *, struct ui_file *)) tcomplain)
3568 || (current_target.to_rcmd == debug_to_rcmd
3569 && (debug_target.to_rcmd
3570 == (void (*) (char *, struct ui_file *)) tcomplain)))
3571 error (_("\"monitor\" command not supported by this target."));
3572 target_rcmd (cmd, gdb_stdtarg);
3573 }
3574
3575 /* Print the name of each layers of our target stack. */
3576
3577 static void
3578 maintenance_print_target_stack (char *cmd, int from_tty)
3579 {
3580 struct target_ops *t;
3581
3582 printf_filtered (_("The current target stack is:\n"));
3583
3584 for (t = target_stack; t != NULL; t = t->beneath)
3585 {
3586 printf_filtered (" - %s (%s)\n", t->to_shortname, t->to_longname);
3587 }
3588 }
3589
3590 /* Controls if async mode is permitted. */
3591 int target_async_permitted = 0;
3592
3593 /* The set command writes to this variable. If the inferior is
3594 executing, linux_nat_async_permitted is *not* updated. */
3595 static int target_async_permitted_1 = 0;
3596
3597 static void
3598 set_maintenance_target_async_permitted (char *args, int from_tty,
3599 struct cmd_list_element *c)
3600 {
3601 if (have_live_inferiors ())
3602 {
3603 target_async_permitted_1 = target_async_permitted;
3604 error (_("Cannot change this setting while the inferior is running."));
3605 }
3606
3607 target_async_permitted = target_async_permitted_1;
3608 }
3609
3610 static void
3611 show_maintenance_target_async_permitted (struct ui_file *file, int from_tty,
3612 struct cmd_list_element *c,
3613 const char *value)
3614 {
3615 fprintf_filtered (file, _("\
3616 Controlling the inferior in asynchronous mode is %s.\n"), value);
3617 }
3618
3619 void
3620 initialize_targets (void)
3621 {
3622 init_dummy_target ();
3623 push_target (&dummy_target);
3624
3625 add_info ("target", target_info, targ_desc);
3626 add_info ("files", target_info, targ_desc);
3627
3628 add_setshow_zinteger_cmd ("target", class_maintenance, &targetdebug, _("\
3629 Set target debugging."), _("\
3630 Show target debugging."), _("\
3631 When non-zero, target debugging is enabled. Higher numbers are more\n\
3632 verbose. Changes do not take effect until the next \"run\" or \"target\"\n\
3633 command."),
3634 NULL,
3635 show_targetdebug,
3636 &setdebuglist, &showdebuglist);
3637
3638 add_setshow_boolean_cmd ("trust-readonly-sections", class_support,
3639 &trust_readonly, _("\
3640 Set mode for reading from readonly sections."), _("\
3641 Show mode for reading from readonly sections."), _("\
3642 When this mode is on, memory reads from readonly sections (such as .text)\n\
3643 will be read from the object file instead of from the target. This will\n\
3644 result in significant performance improvement for remote targets."),
3645 NULL,
3646 show_trust_readonly,
3647 &setlist, &showlist);
3648
3649 add_com ("monitor", class_obscure, do_monitor_command,
3650 _("Send a command to the remote monitor (remote targets only)."));
3651
3652 add_cmd ("target-stack", class_maintenance, maintenance_print_target_stack,
3653 _("Print the name of each layer of the internal target stack."),
3654 &maintenanceprintlist);
3655
3656 add_setshow_boolean_cmd ("target-async", no_class,
3657 &target_async_permitted_1, _("\
3658 Set whether gdb controls the inferior in asynchronous mode."), _("\
3659 Show whether gdb controls the inferior in asynchronous mode."), _("\
3660 Tells gdb whether to control the inferior in asynchronous mode."),
3661 set_maintenance_target_async_permitted,
3662 show_maintenance_target_async_permitted,
3663 &setlist,
3664 &showlist);
3665
3666 add_setshow_boolean_cmd ("stack-cache", class_support,
3667 &stack_cache_enabled_p_1, _("\
3668 Set cache use for stack access."), _("\
3669 Show cache use for stack access."), _("\
3670 When on, use the data cache for all stack access, regardless of any\n\
3671 configured memory regions. This improves remote performance significantly.\n\
3672 By default, caching for stack access is on."),
3673 set_stack_cache_enabled_p,
3674 show_stack_cache_enabled_p,
3675 &setlist, &showlist);
3676
3677 target_dcache = dcache_init ();
3678 }
This page took 0.158416 seconds and 4 git commands to generate.