Update copyright years
[deliverable/binutils-gdb.git] / gdb / target.c
CommitLineData
c906108c 1/* Select target systems and architectures at runtime for GDB.
7998dfc3 2
ecd75fc8 3 Copyright (C) 1990-2014 Free Software Foundation, Inc.
7998dfc3 4
c906108c
SS
5 Contributed by Cygnus Support.
6
c5aa993b 7 This file is part of GDB.
c906108c 8
c5aa993b
JM
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
c5aa993b 12 (at your option) any later version.
c906108c 13
c5aa993b
JM
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
c906108c 18
c5aa993b 19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
21
22#include "defs.h"
23#include <errno.h>
0e9f083f 24#include <string.h>
c906108c 25#include "target.h"
68c765e2 26#include "target-dcache.h"
c906108c
SS
27#include "gdbcmd.h"
28#include "symtab.h"
29#include "inferior.h"
30#include "bfd.h"
31#include "symfile.h"
32#include "objfiles.h"
4930751a 33#include "dcache.h"
c906108c 34#include <signal.h>
4e052eda 35#include "regcache.h"
0088c768 36#include "gdb_assert.h"
b6591e8b 37#include "gdbcore.h"
9e35dae4 38#include "exceptions.h"
424163ea 39#include "target-descriptions.h"
e1ac3328 40#include "gdbthread.h"
b9db4ced 41#include "solib.h"
07b82ea5 42#include "exec.h"
edb3359d 43#include "inline-frame.h"
2f4d8875 44#include "tracepoint.h"
7313baad 45#include "gdb/fileio.h"
8ffcbaaf 46#include "agent.h"
8de71aab 47#include "auxv.h"
c906108c 48
a14ed312 49static void target_info (char *, int);
c906108c 50
0a4f40a2 51static void default_terminal_info (struct target_ops *, const char *, int);
c906108c 52
5009afc5
AS
53static int default_watchpoint_addr_within_range (struct target_ops *,
54 CORE_ADDR, CORE_ADDR, int);
55
31568a15
TT
56static int default_region_ok_for_hw_watchpoint (struct target_ops *,
57 CORE_ADDR, int);
e0d24f8d 58
a53f3625
TT
59static void default_rcmd (struct target_ops *, char *, struct ui_file *);
60
4229b31d
TT
61static ptid_t default_get_ada_task_ptid (struct target_ops *self,
62 long lwp, long tid);
63
098dba18
TT
64static int default_follow_fork (struct target_ops *self, int follow_child,
65 int detach_fork);
66
8d657035
TT
67static void default_mourn_inferior (struct target_ops *self);
68
58a5184e
TT
69static int default_search_memory (struct target_ops *ops,
70 CORE_ADDR start_addr,
71 ULONGEST search_space_len,
72 const gdb_byte *pattern,
73 ULONGEST pattern_len,
74 CORE_ADDR *found_addrp);
75
c25c4a8b 76static void tcomplain (void) ATTRIBUTE_NORETURN;
c906108c 77
555bbdeb
TT
78static int return_zero (struct target_ops *);
79
80static int return_zero_has_execution (struct target_ops *, ptid_t);
c906108c 81
a14ed312 82static void target_command (char *, int);
c906108c 83
a14ed312 84static struct target_ops *find_default_run_target (char *);
c906108c 85
c2250ad1
UW
86static struct gdbarch *default_thread_architecture (struct target_ops *ops,
87 ptid_t ptid);
88
0b5a2719
TT
89static int dummy_find_memory_regions (struct target_ops *self,
90 find_memory_region_ftype ignore1,
91 void *ignore2);
92
16f796b1
TT
93static char *dummy_make_corefile_notes (struct target_ops *self,
94 bfd *ignore1, int *ignore2);
95
770234d3
TT
96static char *default_pid_to_str (struct target_ops *ops, ptid_t ptid);
97
6b84065d
TT
98static int find_default_can_async_p (struct target_ops *ignore);
99
100static int find_default_is_async_p (struct target_ops *ignore);
101
fe31bf5b
TT
102static enum exec_direction_kind default_execution_direction
103 (struct target_ops *self);
104
c0eca49f
TT
105static CORE_ADDR default_target_decr_pc_after_break (struct target_ops *ops,
106 struct gdbarch *gdbarch);
107
1101cb7b
TT
108#include "target-delegates.c"
109
a14ed312 110static void init_dummy_target (void);
c906108c 111
aa869812
AC
112static struct target_ops debug_target;
113
a14ed312 114static void debug_to_open (char *, int);
c906108c 115
f32dbf8c
MM
116static void debug_to_prepare_to_store (struct target_ops *self,
117 struct regcache *);
c906108c 118
a14ed312 119static void debug_to_files_info (struct target_ops *);
c906108c 120
3db08215 121static int debug_to_insert_breakpoint (struct target_ops *, struct gdbarch *,
a6d9a66e 122 struct bp_target_info *);
c906108c 123
3db08215 124static int debug_to_remove_breakpoint (struct target_ops *, struct gdbarch *,
a6d9a66e 125 struct bp_target_info *);
c906108c 126
5461485a
TT
127static int debug_to_can_use_hw_breakpoint (struct target_ops *self,
128 int, int, int);
ccaa32c7 129
23a26771
TT
130static int debug_to_insert_hw_breakpoint (struct target_ops *self,
131 struct gdbarch *,
a6d9a66e 132 struct bp_target_info *);
ccaa32c7 133
a64dc96c
TT
134static int debug_to_remove_hw_breakpoint (struct target_ops *self,
135 struct gdbarch *,
a6d9a66e 136 struct bp_target_info *);
ccaa32c7 137
7bb99c53
TT
138static int debug_to_insert_watchpoint (struct target_ops *self,
139 CORE_ADDR, int, int,
0cf6dd15 140 struct expression *);
ccaa32c7 141
11b5219a
TT
142static int debug_to_remove_watchpoint (struct target_ops *self,
143 CORE_ADDR, int, int,
0cf6dd15 144 struct expression *);
ccaa32c7 145
4aa7a7f5 146static int debug_to_stopped_data_address (struct target_ops *, CORE_ADDR *);
ccaa32c7 147
5009afc5
AS
148static int debug_to_watchpoint_addr_within_range (struct target_ops *,
149 CORE_ADDR, CORE_ADDR, int);
150
31568a15
TT
151static int debug_to_region_ok_for_hw_watchpoint (struct target_ops *self,
152 CORE_ADDR, int);
e0d24f8d 153
c3a5ff89
TT
154static int debug_to_can_accel_watchpoint_condition (struct target_ops *self,
155 CORE_ADDR, int, int,
0cf6dd15
TJB
156 struct expression *);
157
c42bf286 158static void debug_to_terminal_init (struct target_ops *self);
c906108c 159
d2f640d4 160static void debug_to_terminal_inferior (struct target_ops *self);
c906108c 161
2e1e1a19 162static void debug_to_terminal_ours_for_output (struct target_ops *self);
c906108c 163
ae3bd431 164static void debug_to_terminal_save_ours (struct target_ops *self);
a790ad35 165
e3594fd1 166static void debug_to_terminal_ours (struct target_ops *self);
c906108c 167
71a9f134 168static void debug_to_load (struct target_ops *self, char *, int);
c906108c 169
da82bd6b 170static int debug_to_can_run (struct target_ops *self);
c906108c 171
1eab8a48 172static void debug_to_stop (struct target_ops *self, ptid_t);
c906108c 173
c906108c 174/* Pointer to array of target architecture structures; the size of the
2bc416ba 175 array; the current index into the array; the allocated size of the
c906108c
SS
176 array. */
177struct target_ops **target_structs;
178unsigned target_struct_size;
c906108c
SS
179unsigned target_struct_allocsize;
180#define DEFAULT_ALLOCSIZE 10
181
182/* The initial current target, so that there is always a semi-valid
183 current target. */
184
185static struct target_ops dummy_target;
186
187/* Top of target stack. */
188
258b763a 189static struct target_ops *target_stack;
c906108c
SS
190
191/* The target structure we are currently using to talk to a process
192 or file or whatever "inferior" we have. */
193
194struct target_ops current_target;
195
196/* Command list for target. */
197
198static struct cmd_list_element *targetlist = NULL;
199
cf7a04e8
DJ
200/* Nonzero if we should trust readonly sections from the
201 executable when reading memory. */
202
203static int trust_readonly = 0;
204
8defab1a
DJ
205/* Nonzero if we should show true memory content including
206 memory breakpoint inserted by gdb. */
207
208static int show_memory_breakpoints = 0;
209
d914c394
SS
210/* These globals control whether GDB attempts to perform these
211 operations; they are useful for targets that need to prevent
212 inadvertant disruption, such as in non-stop mode. */
213
214int may_write_registers = 1;
215
216int may_write_memory = 1;
217
218int may_insert_breakpoints = 1;
219
220int may_insert_tracepoints = 1;
221
222int may_insert_fast_tracepoints = 1;
223
224int may_stop = 1;
225
c906108c
SS
226/* Non-zero if we want to see trace of target level stuff. */
227
ccce17b0 228static unsigned int targetdebug = 0;
920d2a44
AC
229static void
230show_targetdebug (struct ui_file *file, int from_tty,
231 struct cmd_list_element *c, const char *value)
232{
233 fprintf_filtered (file, _("Target debugging is %s.\n"), value);
234}
c906108c 235
a14ed312 236static void setup_target_debug (void);
c906108c 237
c906108c
SS
238/* The user just typed 'target' without the name of a target. */
239
c906108c 240static void
fba45db2 241target_command (char *arg, int from_tty)
c906108c
SS
242{
243 fputs_filtered ("Argument required (target name). Try `help target'\n",
244 gdb_stdout);
245}
246
c35b1492
PA
247/* Default target_has_* methods for process_stratum targets. */
248
249int
250default_child_has_all_memory (struct target_ops *ops)
251{
252 /* If no inferior selected, then we can't read memory here. */
253 if (ptid_equal (inferior_ptid, null_ptid))
254 return 0;
255
256 return 1;
257}
258
259int
260default_child_has_memory (struct target_ops *ops)
261{
262 /* If no inferior selected, then we can't read memory here. */
263 if (ptid_equal (inferior_ptid, null_ptid))
264 return 0;
265
266 return 1;
267}
268
269int
270default_child_has_stack (struct target_ops *ops)
271{
272 /* If no inferior selected, there's no stack. */
273 if (ptid_equal (inferior_ptid, null_ptid))
274 return 0;
275
276 return 1;
277}
278
279int
280default_child_has_registers (struct target_ops *ops)
281{
282 /* Can't read registers from no inferior. */
283 if (ptid_equal (inferior_ptid, null_ptid))
284 return 0;
285
286 return 1;
287}
288
289int
aeaec162 290default_child_has_execution (struct target_ops *ops, ptid_t the_ptid)
c35b1492
PA
291{
292 /* If there's no thread selected, then we can't make it run through
293 hoops. */
aeaec162 294 if (ptid_equal (the_ptid, null_ptid))
c35b1492
PA
295 return 0;
296
297 return 1;
298}
299
300
301int
302target_has_all_memory_1 (void)
303{
304 struct target_ops *t;
305
306 for (t = current_target.beneath; t != NULL; t = t->beneath)
307 if (t->to_has_all_memory (t))
308 return 1;
309
310 return 0;
311}
312
313int
314target_has_memory_1 (void)
315{
316 struct target_ops *t;
317
318 for (t = current_target.beneath; t != NULL; t = t->beneath)
319 if (t->to_has_memory (t))
320 return 1;
321
322 return 0;
323}
324
325int
326target_has_stack_1 (void)
327{
328 struct target_ops *t;
329
330 for (t = current_target.beneath; t != NULL; t = t->beneath)
331 if (t->to_has_stack (t))
332 return 1;
333
334 return 0;
335}
336
337int
338target_has_registers_1 (void)
339{
340 struct target_ops *t;
341
342 for (t = current_target.beneath; t != NULL; t = t->beneath)
343 if (t->to_has_registers (t))
344 return 1;
345
346 return 0;
347}
348
349int
aeaec162 350target_has_execution_1 (ptid_t the_ptid)
c35b1492
PA
351{
352 struct target_ops *t;
353
354 for (t = current_target.beneath; t != NULL; t = t->beneath)
aeaec162 355 if (t->to_has_execution (t, the_ptid))
c35b1492
PA
356 return 1;
357
358 return 0;
359}
360
aeaec162
TT
361int
362target_has_execution_current (void)
363{
364 return target_has_execution_1 (inferior_ptid);
365}
366
c22a2b88
TT
367/* Complete initialization of T. This ensures that various fields in
368 T are set, if needed by the target implementation. */
c906108c
SS
369
370void
c22a2b88 371complete_target_initialization (struct target_ops *t)
c906108c 372{
0088c768 373 /* Provide default values for all "must have" methods. */
0088c768 374
c35b1492 375 if (t->to_has_all_memory == NULL)
555bbdeb 376 t->to_has_all_memory = return_zero;
c35b1492
PA
377
378 if (t->to_has_memory == NULL)
555bbdeb 379 t->to_has_memory = return_zero;
c35b1492
PA
380
381 if (t->to_has_stack == NULL)
555bbdeb 382 t->to_has_stack = return_zero;
c35b1492
PA
383
384 if (t->to_has_registers == NULL)
555bbdeb 385 t->to_has_registers = return_zero;
c35b1492
PA
386
387 if (t->to_has_execution == NULL)
555bbdeb 388 t->to_has_execution = return_zero_has_execution;
1101cb7b
TT
389
390 install_delegators (t);
c22a2b88
TT
391}
392
393/* Add possible target architecture T to the list and add a new
394 command 'target T->to_shortname'. Set COMPLETER as the command's
395 completer if not NULL. */
396
397void
398add_target_with_completer (struct target_ops *t,
399 completer_ftype *completer)
400{
401 struct cmd_list_element *c;
402
403 complete_target_initialization (t);
c35b1492 404
c906108c
SS
405 if (!target_structs)
406 {
407 target_struct_allocsize = DEFAULT_ALLOCSIZE;
408 target_structs = (struct target_ops **) xmalloc
409 (target_struct_allocsize * sizeof (*target_structs));
410 }
411 if (target_struct_size >= target_struct_allocsize)
412 {
413 target_struct_allocsize *= 2;
414 target_structs = (struct target_ops **)
c5aa993b
JM
415 xrealloc ((char *) target_structs,
416 target_struct_allocsize * sizeof (*target_structs));
c906108c
SS
417 }
418 target_structs[target_struct_size++] = t;
c906108c
SS
419
420 if (targetlist == NULL)
1bedd215
AC
421 add_prefix_cmd ("target", class_run, target_command, _("\
422Connect to a target machine or process.\n\
c906108c
SS
423The first argument is the type or protocol of the target machine.\n\
424Remaining arguments are interpreted by the target protocol. For more\n\
425information on the arguments for a particular protocol, type\n\
1bedd215 426`help target ' followed by the protocol name."),
c906108c 427 &targetlist, "target ", 0, &cmdlist);
9852c492
YQ
428 c = add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc,
429 &targetlist);
430 if (completer != NULL)
431 set_cmd_completer (c, completer);
432}
433
434/* Add a possible target architecture to the list. */
435
436void
437add_target (struct target_ops *t)
438{
439 add_target_with_completer (t, NULL);
c906108c
SS
440}
441
b48d48eb
MM
442/* See target.h. */
443
444void
445add_deprecated_target_alias (struct target_ops *t, char *alias)
446{
447 struct cmd_list_element *c;
448 char *alt;
449
450 /* If we use add_alias_cmd, here, we do not get the deprecated warning,
451 see PR cli/15104. */
452 c = add_cmd (alias, no_class, t->to_open, t->to_doc, &targetlist);
453 alt = xstrprintf ("target %s", t->to_shortname);
454 deprecate_cmd (c, alt);
455}
456
c906108c
SS
457/* Stub functions */
458
7d85a9c0
JB
459void
460target_kill (void)
461{
423a4807
TT
462 if (targetdebug)
463 fprintf_unfiltered (gdb_stdlog, "target_kill ()\n");
7d85a9c0 464
423a4807 465 current_target.to_kill (&current_target);
7d85a9c0
JB
466}
467
11cf8741
JM
468void
469target_load (char *arg, int from_tty)
470{
4e5d721f 471 target_dcache_invalidate ();
71a9f134 472 (*current_target.to_load) (&current_target, arg, from_tty);
11cf8741
JM
473}
474
947b8855
PA
475void
476target_create_inferior (char *exec_file, char *args,
477 char **env, int from_tty)
136d6dae
VP
478{
479 struct target_ops *t;
5d502164 480
136d6dae
VP
481 for (t = current_target.beneath; t != NULL; t = t->beneath)
482 {
483 if (t->to_create_inferior != NULL)
484 {
485 t->to_create_inferior (t, exec_file, args, env, from_tty);
947b8855
PA
486 if (targetdebug)
487 fprintf_unfiltered (gdb_stdlog,
488 "target_create_inferior (%s, %s, xxx, %d)\n",
489 exec_file, args, from_tty);
136d6dae
VP
490 return;
491 }
492 }
493
494 internal_error (__FILE__, __LINE__,
9b20d036 495 _("could not find a target to create inferior"));
136d6dae
VP
496}
497
d9d2d8b6
PA
498void
499target_terminal_inferior (void)
500{
501 /* A background resume (``run&'') should leave GDB in control of the
c378eb4e 502 terminal. Use target_can_async_p, not target_is_async_p, since at
ba7f6c64
VP
503 this point the target is not async yet. However, if sync_execution
504 is not set, we know it will become async prior to resume. */
505 if (target_can_async_p () && !sync_execution)
d9d2d8b6
PA
506 return;
507
508 /* If GDB is resuming the inferior in the foreground, install
509 inferior's terminal modes. */
d2f640d4 510 (*current_target.to_terminal_inferior) (&current_target);
d9d2d8b6 511}
136d6dae 512
c906108c 513static void
fba45db2 514tcomplain (void)
c906108c 515{
8a3fe4f8 516 error (_("You can't do that when your target is `%s'"),
c906108c
SS
517 current_target.to_shortname);
518}
519
520void
fba45db2 521noprocess (void)
c906108c 522{
8a3fe4f8 523 error (_("You can't do that without a process to debug."));
c906108c
SS
524}
525
c906108c 526static void
0a4f40a2 527default_terminal_info (struct target_ops *self, const char *args, int from_tty)
c906108c 528{
a3f17187 529 printf_unfiltered (_("No saved terminal information.\n"));
c906108c
SS
530}
531
0ef643c8
JB
532/* A default implementation for the to_get_ada_task_ptid target method.
533
534 This function builds the PTID by using both LWP and TID as part of
535 the PTID lwp and tid elements. The pid used is the pid of the
536 inferior_ptid. */
537
2c0b251b 538static ptid_t
1e6b91a4 539default_get_ada_task_ptid (struct target_ops *self, long lwp, long tid)
0ef643c8
JB
540{
541 return ptid_build (ptid_get_pid (inferior_ptid), lwp, tid);
542}
543
32231432 544static enum exec_direction_kind
4c612759 545default_execution_direction (struct target_ops *self)
32231432
PA
546{
547 if (!target_can_execute_reverse)
548 return EXEC_FORWARD;
549 else if (!target_can_async_p ())
550 return EXEC_FORWARD;
551 else
552 gdb_assert_not_reached ("\
553to_execution_direction must be implemented for reverse async");
554}
555
7998dfc3
AC
556/* Go through the target stack from top to bottom, copying over zero
557 entries in current_target, then filling in still empty entries. In
558 effect, we are doing class inheritance through the pushed target
559 vectors.
560
561 NOTE: cagney/2003-10-17: The problem with this inheritance, as it
562 is currently implemented, is that it discards any knowledge of
563 which target an inherited method originally belonged to.
564 Consequently, new new target methods should instead explicitly and
565 locally search the target stack for the target that can handle the
566 request. */
c906108c
SS
567
568static void
7998dfc3 569update_current_target (void)
c906108c 570{
7998dfc3
AC
571 struct target_ops *t;
572
08d8bcd7 573 /* First, reset current's contents. */
7998dfc3
AC
574 memset (&current_target, 0, sizeof (current_target));
575
1101cb7b
TT
576 /* Install the delegators. */
577 install_delegators (&current_target);
578
be4ddd36
TT
579 current_target.to_stratum = target_stack->to_stratum;
580
7998dfc3
AC
581#define INHERIT(FIELD, TARGET) \
582 if (!current_target.FIELD) \
583 current_target.FIELD = (TARGET)->FIELD
584
be4ddd36
TT
585 /* Do not add any new INHERITs here. Instead, use the delegation
586 mechanism provided by make-target-delegates. */
7998dfc3
AC
587 for (t = target_stack; t; t = t->beneath)
588 {
589 INHERIT (to_shortname, t);
590 INHERIT (to_longname, t);
dc177b7a 591 INHERIT (to_attach_no_wait, t);
74174d2e 592 INHERIT (to_have_steppable_watchpoint, t);
7998dfc3 593 INHERIT (to_have_continuable_watchpoint, t);
7998dfc3 594 INHERIT (to_has_thread_control, t);
7998dfc3
AC
595 }
596#undef INHERIT
597
7998dfc3
AC
598 /* Finally, position the target-stack beneath the squashed
599 "current_target". That way code looking for a non-inherited
600 target method can quickly and simply find it. */
601 current_target.beneath = target_stack;
b4b61fdb
DJ
602
603 if (targetdebug)
604 setup_target_debug ();
c906108c
SS
605}
606
607/* Push a new target type into the stack of the existing target accessors,
608 possibly superseding some of the existing accessors.
609
c906108c
SS
610 Rather than allow an empty stack, we always have the dummy target at
611 the bottom stratum, so we can call the function vectors without
612 checking them. */
613
b26a4dcb 614void
fba45db2 615push_target (struct target_ops *t)
c906108c 616{
258b763a 617 struct target_ops **cur;
c906108c
SS
618
619 /* Check magic number. If wrong, it probably means someone changed
620 the struct definition, but not all the places that initialize one. */
621 if (t->to_magic != OPS_MAGIC)
622 {
c5aa993b
JM
623 fprintf_unfiltered (gdb_stderr,
624 "Magic number of %s target struct wrong\n",
625 t->to_shortname);
3e43a32a
MS
626 internal_error (__FILE__, __LINE__,
627 _("failed internal consistency check"));
c906108c
SS
628 }
629
258b763a
AC
630 /* Find the proper stratum to install this target in. */
631 for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
c906108c 632 {
258b763a 633 if ((int) (t->to_stratum) >= (int) (*cur)->to_stratum)
c906108c
SS
634 break;
635 }
636
258b763a 637 /* If there's already targets at this stratum, remove them. */
88c231eb 638 /* FIXME: cagney/2003-10-15: I think this should be popping all
258b763a
AC
639 targets to CUR, and not just those at this stratum level. */
640 while ((*cur) != NULL && t->to_stratum == (*cur)->to_stratum)
641 {
642 /* There's already something at this stratum level. Close it,
643 and un-hook it from the stack. */
644 struct target_ops *tmp = (*cur);
5d502164 645
258b763a
AC
646 (*cur) = (*cur)->beneath;
647 tmp->beneath = NULL;
460014f5 648 target_close (tmp);
258b763a 649 }
c906108c
SS
650
651 /* We have removed all targets in our stratum, now add the new one. */
258b763a
AC
652 t->beneath = (*cur);
653 (*cur) = t;
c906108c
SS
654
655 update_current_target ();
c906108c
SS
656}
657
2bc416ba 658/* Remove a target_ops vector from the stack, wherever it may be.
c906108c
SS
659 Return how many times it was removed (0 or 1). */
660
661int
fba45db2 662unpush_target (struct target_ops *t)
c906108c 663{
258b763a
AC
664 struct target_ops **cur;
665 struct target_ops *tmp;
c906108c 666
c8d104ad
PA
667 if (t->to_stratum == dummy_stratum)
668 internal_error (__FILE__, __LINE__,
9b20d036 669 _("Attempt to unpush the dummy target"));
c8d104ad 670
c906108c 671 /* Look for the specified target. Note that we assume that a target
c378eb4e 672 can only occur once in the target stack. */
c906108c 673
258b763a
AC
674 for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
675 {
676 if ((*cur) == t)
677 break;
678 }
c906108c 679
305436e0
PA
680 /* If we don't find target_ops, quit. Only open targets should be
681 closed. */
258b763a 682 if ((*cur) == NULL)
305436e0 683 return 0;
5269965e 684
c378eb4e 685 /* Unchain the target. */
258b763a
AC
686 tmp = (*cur);
687 (*cur) = (*cur)->beneath;
688 tmp->beneath = NULL;
c906108c
SS
689
690 update_current_target ();
c906108c 691
305436e0
PA
692 /* Finally close the target. Note we do this after unchaining, so
693 any target method calls from within the target_close
694 implementation don't end up in T anymore. */
460014f5 695 target_close (t);
305436e0 696
c906108c
SS
697 return 1;
698}
699
aa76d38d 700void
460014f5 701pop_all_targets_above (enum strata above_stratum)
aa76d38d 702{
87ab71f0 703 while ((int) (current_target.to_stratum) > (int) above_stratum)
aa76d38d 704 {
aa76d38d
PA
705 if (!unpush_target (target_stack))
706 {
707 fprintf_unfiltered (gdb_stderr,
708 "pop_all_targets couldn't find target %s\n",
b52323fa 709 target_stack->to_shortname);
aa76d38d
PA
710 internal_error (__FILE__, __LINE__,
711 _("failed internal consistency check"));
712 break;
713 }
714 }
715}
716
87ab71f0 717void
460014f5 718pop_all_targets (void)
87ab71f0 719{
460014f5 720 pop_all_targets_above (dummy_stratum);
87ab71f0
PA
721}
722
c0edd9ed
JK
723/* Return 1 if T is now pushed in the target stack. Return 0 otherwise. */
724
725int
726target_is_pushed (struct target_ops *t)
727{
728 struct target_ops **cur;
729
730 /* Check magic number. If wrong, it probably means someone changed
731 the struct definition, but not all the places that initialize one. */
732 if (t->to_magic != OPS_MAGIC)
733 {
734 fprintf_unfiltered (gdb_stderr,
735 "Magic number of %s target struct wrong\n",
736 t->to_shortname);
3e43a32a
MS
737 internal_error (__FILE__, __LINE__,
738 _("failed internal consistency check"));
c0edd9ed
JK
739 }
740
741 for (cur = &target_stack; (*cur) != NULL; cur = &(*cur)->beneath)
742 if (*cur == t)
743 return 1;
744
745 return 0;
746}
747
72f5cf0e 748/* Using the objfile specified in OBJFILE, find the address for the
9e35dae4
DJ
749 current thread's thread-local storage with offset OFFSET. */
750CORE_ADDR
751target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
752{
753 volatile CORE_ADDR addr = 0;
117de6a9
PA
754 struct target_ops *target;
755
756 for (target = current_target.beneath;
757 target != NULL;
758 target = target->beneath)
759 {
760 if (target->to_get_thread_local_address != NULL)
761 break;
762 }
9e35dae4 763
117de6a9 764 if (target != NULL
f5656ead 765 && gdbarch_fetch_tls_load_module_address_p (target_gdbarch ()))
9e35dae4
DJ
766 {
767 ptid_t ptid = inferior_ptid;
768 volatile struct gdb_exception ex;
769
770 TRY_CATCH (ex, RETURN_MASK_ALL)
771 {
772 CORE_ADDR lm_addr;
773
774 /* Fetch the load module address for this objfile. */
f5656ead 775 lm_addr = gdbarch_fetch_tls_load_module_address (target_gdbarch (),
9e35dae4
DJ
776 objfile);
777 /* If it's 0, throw the appropriate exception. */
778 if (lm_addr == 0)
779 throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR,
780 _("TLS load module not found"));
781
3e43a32a
MS
782 addr = target->to_get_thread_local_address (target, ptid,
783 lm_addr, offset);
9e35dae4
DJ
784 }
785 /* If an error occurred, print TLS related messages here. Otherwise,
786 throw the error to some higher catcher. */
787 if (ex.reason < 0)
788 {
789 int objfile_is_library = (objfile->flags & OBJF_SHARED);
790
791 switch (ex.error)
792 {
793 case TLS_NO_LIBRARY_SUPPORT_ERROR:
3e43a32a
MS
794 error (_("Cannot find thread-local variables "
795 "in this thread library."));
9e35dae4
DJ
796 break;
797 case TLS_LOAD_MODULE_NOT_FOUND_ERROR:
798 if (objfile_is_library)
799 error (_("Cannot find shared library `%s' in dynamic"
4262abfb 800 " linker's load module list"), objfile_name (objfile));
9e35dae4
DJ
801 else
802 error (_("Cannot find executable file `%s' in dynamic"
4262abfb 803 " linker's load module list"), objfile_name (objfile));
9e35dae4
DJ
804 break;
805 case TLS_NOT_ALLOCATED_YET_ERROR:
806 if (objfile_is_library)
807 error (_("The inferior has not yet allocated storage for"
808 " thread-local variables in\n"
809 "the shared library `%s'\n"
810 "for %s"),
4262abfb 811 objfile_name (objfile), target_pid_to_str (ptid));
9e35dae4
DJ
812 else
813 error (_("The inferior has not yet allocated storage for"
814 " thread-local variables in\n"
815 "the executable `%s'\n"
816 "for %s"),
4262abfb 817 objfile_name (objfile), target_pid_to_str (ptid));
9e35dae4
DJ
818 break;
819 case TLS_GENERIC_ERROR:
820 if (objfile_is_library)
821 error (_("Cannot find thread-local storage for %s, "
822 "shared library %s:\n%s"),
823 target_pid_to_str (ptid),
4262abfb 824 objfile_name (objfile), ex.message);
9e35dae4
DJ
825 else
826 error (_("Cannot find thread-local storage for %s, "
827 "executable file %s:\n%s"),
828 target_pid_to_str (ptid),
4262abfb 829 objfile_name (objfile), ex.message);
9e35dae4
DJ
830 break;
831 default:
832 throw_exception (ex);
833 break;
834 }
835 }
836 }
837 /* It wouldn't be wrong here to try a gdbarch method, too; finding
838 TLS is an ABI-specific thing. But we don't do that yet. */
839 else
840 error (_("Cannot find thread-local variables on this target"));
841
842 return addr;
843}
844
6be7b56e 845const char *
01cb8804 846target_xfer_status_to_string (enum target_xfer_status status)
6be7b56e
PA
847{
848#define CASE(X) case X: return #X
01cb8804 849 switch (status)
6be7b56e
PA
850 {
851 CASE(TARGET_XFER_E_IO);
bc113b4e 852 CASE(TARGET_XFER_UNAVAILABLE);
6be7b56e
PA
853 default:
854 return "<unknown>";
855 }
856#undef CASE
857};
858
859
c906108c
SS
860#undef MIN
861#define MIN(A, B) (((A) <= (B)) ? (A) : (B))
862
863/* target_read_string -- read a null terminated string, up to LEN bytes,
864 from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful.
865 Set *STRING to a pointer to malloc'd memory containing the data; the caller
866 is responsible for freeing it. Return the number of bytes successfully
867 read. */
868
869int
fba45db2 870target_read_string (CORE_ADDR memaddr, char **string, int len, int *errnop)
c906108c 871{
c2e8b827 872 int tlen, offset, i;
1b0ba102 873 gdb_byte buf[4];
c906108c
SS
874 int errcode = 0;
875 char *buffer;
876 int buffer_allocated;
877 char *bufptr;
878 unsigned int nbytes_read = 0;
879
6217bf3e
MS
880 gdb_assert (string);
881
c906108c
SS
882 /* Small for testing. */
883 buffer_allocated = 4;
884 buffer = xmalloc (buffer_allocated);
885 bufptr = buffer;
886
c906108c
SS
887 while (len > 0)
888 {
889 tlen = MIN (len, 4 - (memaddr & 3));
890 offset = memaddr & 3;
891
1b0ba102 892 errcode = target_read_memory (memaddr & ~3, buf, sizeof buf);
c906108c
SS
893 if (errcode != 0)
894 {
895 /* The transfer request might have crossed the boundary to an
c378eb4e 896 unallocated region of memory. Retry the transfer, requesting
c906108c
SS
897 a single byte. */
898 tlen = 1;
899 offset = 0;
b8eb5af0 900 errcode = target_read_memory (memaddr, buf, 1);
c906108c
SS
901 if (errcode != 0)
902 goto done;
903 }
904
905 if (bufptr - buffer + tlen > buffer_allocated)
906 {
907 unsigned int bytes;
5d502164 908
c906108c
SS
909 bytes = bufptr - buffer;
910 buffer_allocated *= 2;
911 buffer = xrealloc (buffer, buffer_allocated);
912 bufptr = buffer + bytes;
913 }
914
915 for (i = 0; i < tlen; i++)
916 {
917 *bufptr++ = buf[i + offset];
918 if (buf[i + offset] == '\000')
919 {
920 nbytes_read += i + 1;
921 goto done;
922 }
923 }
924
925 memaddr += tlen;
926 len -= tlen;
927 nbytes_read += tlen;
928 }
c5aa993b 929done:
6217bf3e 930 *string = buffer;
c906108c
SS
931 if (errnop != NULL)
932 *errnop = errcode;
c906108c
SS
933 return nbytes_read;
934}
935
07b82ea5
PA
936struct target_section_table *
937target_get_section_table (struct target_ops *target)
938{
07b82ea5
PA
939 if (targetdebug)
940 fprintf_unfiltered (gdb_stdlog, "target_get_section_table ()\n");
941
7e35c012 942 return (*target->to_get_section_table) (target);
07b82ea5
PA
943}
944
8db32d44 945/* Find a section containing ADDR. */
07b82ea5 946
0542c86d 947struct target_section *
8db32d44
AC
948target_section_by_addr (struct target_ops *target, CORE_ADDR addr)
949{
07b82ea5 950 struct target_section_table *table = target_get_section_table (target);
0542c86d 951 struct target_section *secp;
07b82ea5
PA
952
953 if (table == NULL)
954 return NULL;
955
956 for (secp = table->sections; secp < table->sections_end; secp++)
8db32d44
AC
957 {
958 if (addr >= secp->addr && addr < secp->endaddr)
959 return secp;
960 }
961 return NULL;
962}
963
e6e4e701
PA
964/* Read memory from the live target, even if currently inspecting a
965 traceframe. The return is the same as that of target_read. */
966
9b409511 967static enum target_xfer_status
e6e4e701 968target_read_live_memory (enum target_object object,
9b409511
YQ
969 ULONGEST memaddr, gdb_byte *myaddr, ULONGEST len,
970 ULONGEST *xfered_len)
e6e4e701 971{
9b409511 972 enum target_xfer_status ret;
e6e4e701
PA
973 struct cleanup *cleanup;
974
975 /* Switch momentarily out of tfind mode so to access live memory.
976 Note that this must not clear global state, such as the frame
977 cache, which must still remain valid for the previous traceframe.
978 We may be _building_ the frame cache at this point. */
979 cleanup = make_cleanup_restore_traceframe_number ();
980 set_traceframe_number (-1);
981
9b409511
YQ
982 ret = target_xfer_partial (current_target.beneath, object, NULL,
983 myaddr, NULL, memaddr, len, xfered_len);
e6e4e701
PA
984
985 do_cleanups (cleanup);
986 return ret;
987}
988
989/* Using the set of read-only target sections of OPS, read live
990 read-only memory. Note that the actual reads start from the
5657161f
PA
991 top-most target again.
992
993 For interface/parameters/return description see target.h,
994 to_xfer_partial. */
e6e4e701 995
9b409511 996static enum target_xfer_status
e6e4e701
PA
997memory_xfer_live_readonly_partial (struct target_ops *ops,
998 enum target_object object,
999 gdb_byte *readbuf, ULONGEST memaddr,
9b409511 1000 ULONGEST len, ULONGEST *xfered_len)
e6e4e701
PA
1001{
1002 struct target_section *secp;
1003 struct target_section_table *table;
1004
1005 secp = target_section_by_addr (ops, memaddr);
1006 if (secp != NULL
2b2848e2
DE
1007 && (bfd_get_section_flags (secp->the_bfd_section->owner,
1008 secp->the_bfd_section)
e6e4e701
PA
1009 & SEC_READONLY))
1010 {
1011 struct target_section *p;
1012 ULONGEST memend = memaddr + len;
1013
1014 table = target_get_section_table (ops);
1015
1016 for (p = table->sections; p < table->sections_end; p++)
1017 {
1018 if (memaddr >= p->addr)
1019 {
1020 if (memend <= p->endaddr)
1021 {
1022 /* Entire transfer is within this section. */
1023 return target_read_live_memory (object, memaddr,
9b409511 1024 readbuf, len, xfered_len);
e6e4e701
PA
1025 }
1026 else if (memaddr >= p->endaddr)
1027 {
1028 /* This section ends before the transfer starts. */
1029 continue;
1030 }
1031 else
1032 {
1033 /* This section overlaps the transfer. Just do half. */
1034 len = p->endaddr - memaddr;
1035 return target_read_live_memory (object, memaddr,
9b409511 1036 readbuf, len, xfered_len);
e6e4e701
PA
1037 }
1038 }
1039 }
1040 }
1041
9b409511 1042 return TARGET_XFER_EOF;
e6e4e701
PA
1043}
1044
9f713294
YQ
1045/* Read memory from more than one valid target. A core file, for
1046 instance, could have some of memory but delegate other bits to
1047 the target below it. So, we must manually try all targets. */
1048
9b409511 1049static enum target_xfer_status
17fde6d0 1050raw_memory_xfer_partial (struct target_ops *ops, gdb_byte *readbuf,
9b409511
YQ
1051 const gdb_byte *writebuf, ULONGEST memaddr, LONGEST len,
1052 ULONGEST *xfered_len)
9f713294 1053{
9b409511 1054 enum target_xfer_status res;
9f713294
YQ
1055
1056 do
1057 {
1058 res = ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL,
9b409511
YQ
1059 readbuf, writebuf, memaddr, len,
1060 xfered_len);
1061 if (res == TARGET_XFER_OK)
9f713294
YQ
1062 break;
1063
633785ff 1064 /* Stop if the target reports that the memory is not available. */
bc113b4e 1065 if (res == TARGET_XFER_UNAVAILABLE)
633785ff
MM
1066 break;
1067
9f713294
YQ
1068 /* We want to continue past core files to executables, but not
1069 past a running target's memory. */
1070 if (ops->to_has_all_memory (ops))
1071 break;
1072
1073 ops = ops->beneath;
1074 }
1075 while (ops != NULL);
1076
1077 return res;
1078}
1079
7f79c47e
DE
1080/* Perform a partial memory transfer.
1081 For docs see target.h, to_xfer_partial. */
cf7a04e8 1082
9b409511 1083static enum target_xfer_status
f0ba3972 1084memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
17fde6d0 1085 gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST memaddr,
9b409511 1086 ULONGEST len, ULONGEST *xfered_len)
0779438d 1087{
9b409511 1088 enum target_xfer_status res;
cf7a04e8
DJ
1089 int reg_len;
1090 struct mem_region *region;
4e5d721f 1091 struct inferior *inf;
cf7a04e8 1092
07b82ea5
PA
1093 /* For accesses to unmapped overlay sections, read directly from
1094 files. Must do this first, as MEMADDR may need adjustment. */
1095 if (readbuf != NULL && overlay_debugging)
1096 {
1097 struct obj_section *section = find_pc_overlay (memaddr);
5d502164 1098
07b82ea5
PA
1099 if (pc_in_unmapped_range (memaddr, section))
1100 {
1101 struct target_section_table *table
1102 = target_get_section_table (ops);
1103 const char *section_name = section->the_bfd_section->name;
5d502164 1104
07b82ea5
PA
1105 memaddr = overlay_mapped_address (memaddr, section);
1106 return section_table_xfer_memory_partial (readbuf, writebuf,
9b409511 1107 memaddr, len, xfered_len,
07b82ea5
PA
1108 table->sections,
1109 table->sections_end,
1110 section_name);
1111 }
1112 }
1113
1114 /* Try the executable files, if "trust-readonly-sections" is set. */
cf7a04e8
DJ
1115 if (readbuf != NULL && trust_readonly)
1116 {
0542c86d 1117 struct target_section *secp;
07b82ea5 1118 struct target_section_table *table;
cf7a04e8
DJ
1119
1120 secp = target_section_by_addr (ops, memaddr);
1121 if (secp != NULL
2b2848e2
DE
1122 && (bfd_get_section_flags (secp->the_bfd_section->owner,
1123 secp->the_bfd_section)
cf7a04e8 1124 & SEC_READONLY))
07b82ea5
PA
1125 {
1126 table = target_get_section_table (ops);
1127 return section_table_xfer_memory_partial (readbuf, writebuf,
9b409511 1128 memaddr, len, xfered_len,
07b82ea5
PA
1129 table->sections,
1130 table->sections_end,
1131 NULL);
1132 }
98646950
UW
1133 }
1134
e6e4e701
PA
1135 /* If reading unavailable memory in the context of traceframes, and
1136 this address falls within a read-only section, fallback to
1137 reading from live memory. */
1138 if (readbuf != NULL && get_traceframe_number () != -1)
1139 {
1140 VEC(mem_range_s) *available;
1141
1142 /* If we fail to get the set of available memory, then the
1143 target does not support querying traceframe info, and so we
1144 attempt reading from the traceframe anyway (assuming the
1145 target implements the old QTro packet then). */
1146 if (traceframe_available_memory (&available, memaddr, len))
1147 {
1148 struct cleanup *old_chain;
1149
1150 old_chain = make_cleanup (VEC_cleanup(mem_range_s), &available);
1151
1152 if (VEC_empty (mem_range_s, available)
1153 || VEC_index (mem_range_s, available, 0)->start != memaddr)
1154 {
1155 /* Don't read into the traceframe's available
1156 memory. */
1157 if (!VEC_empty (mem_range_s, available))
1158 {
1159 LONGEST oldlen = len;
1160
1161 len = VEC_index (mem_range_s, available, 0)->start - memaddr;
1162 gdb_assert (len <= oldlen);
1163 }
1164
1165 do_cleanups (old_chain);
1166
1167 /* This goes through the topmost target again. */
1168 res = memory_xfer_live_readonly_partial (ops, object,
9b409511
YQ
1169 readbuf, memaddr,
1170 len, xfered_len);
1171 if (res == TARGET_XFER_OK)
1172 return TARGET_XFER_OK;
1173 else
1174 {
1175 /* No use trying further, we know some memory starting
1176 at MEMADDR isn't available. */
1177 *xfered_len = len;
bc113b4e 1178 return TARGET_XFER_UNAVAILABLE;
9b409511 1179 }
e6e4e701
PA
1180 }
1181
1182 /* Don't try to read more than how much is available, in
1183 case the target implements the deprecated QTro packet to
1184 cater for older GDBs (the target's knowledge of read-only
1185 sections may be outdated by now). */
1186 len = VEC_index (mem_range_s, available, 0)->length;
1187
1188 do_cleanups (old_chain);
1189 }
1190 }
1191
cf7a04e8
DJ
1192 /* Try GDB's internal data cache. */
1193 region = lookup_mem_region (memaddr);
4b5752d0
VP
1194 /* region->hi == 0 means there's no upper bound. */
1195 if (memaddr + len < region->hi || region->hi == 0)
cf7a04e8
DJ
1196 reg_len = len;
1197 else
1198 reg_len = region->hi - memaddr;
1199
1200 switch (region->attrib.mode)
1201 {
1202 case MEM_RO:
1203 if (writebuf != NULL)
2ed4b548 1204 return TARGET_XFER_E_IO;
cf7a04e8
DJ
1205 break;
1206
1207 case MEM_WO:
1208 if (readbuf != NULL)
2ed4b548 1209 return TARGET_XFER_E_IO;
cf7a04e8 1210 break;
a76d924d
DJ
1211
1212 case MEM_FLASH:
1213 /* We only support writing to flash during "load" for now. */
1214 if (writebuf != NULL)
1215 error (_("Writing to flash memory forbidden in this context"));
1216 break;
4b5752d0
VP
1217
1218 case MEM_NONE:
2ed4b548 1219 return TARGET_XFER_E_IO;
cf7a04e8
DJ
1220 }
1221
6c95b8df
PA
1222 if (!ptid_equal (inferior_ptid, null_ptid))
1223 inf = find_inferior_pid (ptid_get_pid (inferior_ptid));
1224 else
1225 inf = NULL;
4e5d721f
DE
1226
1227 if (inf != NULL
2f4d8875
PA
1228 /* The dcache reads whole cache lines; that doesn't play well
1229 with reading from a trace buffer, because reading outside of
1230 the collected memory range fails. */
1231 && get_traceframe_number () == -1
4e5d721f 1232 && (region->attrib.cache
29453a14
YQ
1233 || (stack_cache_enabled_p () && object == TARGET_OBJECT_STACK_MEMORY)
1234 || (code_cache_enabled_p () && object == TARGET_OBJECT_CODE_MEMORY)))
cf7a04e8 1235 {
2a2f9fe4 1236 DCACHE *dcache = target_dcache_get_or_init ();
9b409511 1237 int l;
2a2f9fe4 1238
cf7a04e8 1239 if (readbuf != NULL)
9b409511 1240 l = dcache_xfer_memory (ops, dcache, memaddr, readbuf, reg_len, 0);
cf7a04e8
DJ
1241 else
1242 /* FIXME drow/2006-08-09: If we're going to preserve const
1243 correctness dcache_xfer_memory should take readbuf and
1244 writebuf. */
9b409511 1245 l = dcache_xfer_memory (ops, dcache, memaddr, (void *) writebuf,
cf7a04e8 1246 reg_len, 1);
9b409511
YQ
1247 if (l <= 0)
1248 return TARGET_XFER_E_IO;
cf7a04e8 1249 else
9b409511
YQ
1250 {
1251 *xfered_len = (ULONGEST) l;
1252 return TARGET_XFER_OK;
1253 }
cf7a04e8
DJ
1254 }
1255
1256 /* If none of those methods found the memory we wanted, fall back
1257 to a target partial transfer. Normally a single call to
1258 to_xfer_partial is enough; if it doesn't recognize an object
1259 it will call the to_xfer_partial of the next target down.
1260 But for memory this won't do. Memory is the only target
9b409511
YQ
1261 object which can be read from more than one valid target.
1262 A core file, for instance, could have some of memory but
1263 delegate other bits to the target below it. So, we must
1264 manually try all targets. */
1265
1266 res = raw_memory_xfer_partial (ops, readbuf, writebuf, memaddr, reg_len,
1267 xfered_len);
cf7a04e8 1268
41dcd03f
DE
1269 /* Make sure the cache gets updated no matter what - if we are writing
1270 to the stack. Even if this write is not tagged as such, we still need
1271 to update the cache. */
1272
9b409511 1273 if (res == TARGET_XFER_OK
41dcd03f
DE
1274 && inf != NULL
1275 && writebuf != NULL
f2de9785 1276 && target_dcache_init_p ()
41dcd03f 1277 && !region->attrib.cache
29453a14
YQ
1278 && ((stack_cache_enabled_p () && object != TARGET_OBJECT_STACK_MEMORY)
1279 || (code_cache_enabled_p () && object != TARGET_OBJECT_CODE_MEMORY)))
41dcd03f 1280 {
f2de9785 1281 DCACHE *dcache = target_dcache_get ();
2a2f9fe4 1282
9b409511 1283 dcache_update (dcache, memaddr, (void *) writebuf, reg_len);
41dcd03f
DE
1284 }
1285
cf7a04e8
DJ
1286 /* If we still haven't got anything, return the last error. We
1287 give up. */
1288 return res;
0779438d
AC
1289}
1290
f0ba3972
PA
1291/* Perform a partial memory transfer. For docs see target.h,
1292 to_xfer_partial. */
1293
9b409511 1294static enum target_xfer_status
f0ba3972 1295memory_xfer_partial (struct target_ops *ops, enum target_object object,
9b409511
YQ
1296 gdb_byte *readbuf, const gdb_byte *writebuf,
1297 ULONGEST memaddr, ULONGEST len, ULONGEST *xfered_len)
f0ba3972 1298{
9b409511 1299 enum target_xfer_status res;
f0ba3972
PA
1300
1301 /* Zero length requests are ok and require no work. */
1302 if (len == 0)
9b409511 1303 return TARGET_XFER_EOF;
f0ba3972
PA
1304
1305 /* Fill in READBUF with breakpoint shadows, or WRITEBUF with
1306 breakpoint insns, thus hiding out from higher layers whether
1307 there are software breakpoints inserted in the code stream. */
1308 if (readbuf != NULL)
1309 {
9b409511
YQ
1310 res = memory_xfer_partial_1 (ops, object, readbuf, NULL, memaddr, len,
1311 xfered_len);
f0ba3972 1312
9b409511 1313 if (res == TARGET_XFER_OK && !show_memory_breakpoints)
c63528fc 1314 breakpoint_xfer_memory (readbuf, NULL, NULL, memaddr, *xfered_len);
f0ba3972
PA
1315 }
1316 else
1317 {
1318 void *buf;
1319 struct cleanup *old_chain;
1320
67c059c2
AB
1321 /* A large write request is likely to be partially satisfied
1322 by memory_xfer_partial_1. We will continually malloc
1323 and free a copy of the entire write request for breakpoint
1324 shadow handling even though we only end up writing a small
1325 subset of it. Cap writes to 4KB to mitigate this. */
1326 len = min (4096, len);
1327
f0ba3972
PA
1328 buf = xmalloc (len);
1329 old_chain = make_cleanup (xfree, buf);
1330 memcpy (buf, writebuf, len);
1331
1332 breakpoint_xfer_memory (NULL, buf, writebuf, memaddr, len);
9b409511
YQ
1333 res = memory_xfer_partial_1 (ops, object, NULL, buf, memaddr, len,
1334 xfered_len);
f0ba3972
PA
1335
1336 do_cleanups (old_chain);
1337 }
1338
1339 return res;
1340}
1341
8defab1a
DJ
1342static void
1343restore_show_memory_breakpoints (void *arg)
1344{
1345 show_memory_breakpoints = (uintptr_t) arg;
1346}
1347
1348struct cleanup *
1349make_show_memory_breakpoints_cleanup (int show)
1350{
1351 int current = show_memory_breakpoints;
8defab1a 1352
5d502164 1353 show_memory_breakpoints = show;
8defab1a
DJ
1354 return make_cleanup (restore_show_memory_breakpoints,
1355 (void *) (uintptr_t) current);
1356}
1357
7f79c47e
DE
1358/* For docs see target.h, to_xfer_partial. */
1359
9b409511 1360enum target_xfer_status
27394598
AC
1361target_xfer_partial (struct target_ops *ops,
1362 enum target_object object, const char *annex,
4ac248ca 1363 gdb_byte *readbuf, const gdb_byte *writebuf,
9b409511
YQ
1364 ULONGEST offset, ULONGEST len,
1365 ULONGEST *xfered_len)
27394598 1366{
9b409511 1367 enum target_xfer_status retval;
27394598
AC
1368
1369 gdb_assert (ops->to_xfer_partial != NULL);
cf7a04e8 1370
ce6d0892
YQ
1371 /* Transfer is done when LEN is zero. */
1372 if (len == 0)
9b409511 1373 return TARGET_XFER_EOF;
ce6d0892 1374
d914c394
SS
1375 if (writebuf && !may_write_memory)
1376 error (_("Writing to memory is not allowed (addr %s, len %s)"),
1377 core_addr_to_string_nz (offset), plongest (len));
1378
9b409511
YQ
1379 *xfered_len = 0;
1380
cf7a04e8
DJ
1381 /* If this is a memory transfer, let the memory-specific code
1382 have a look at it instead. Memory transfers are more
1383 complicated. */
29453a14
YQ
1384 if (object == TARGET_OBJECT_MEMORY || object == TARGET_OBJECT_STACK_MEMORY
1385 || object == TARGET_OBJECT_CODE_MEMORY)
4e5d721f 1386 retval = memory_xfer_partial (ops, object, readbuf,
9b409511 1387 writebuf, offset, len, xfered_len);
9f713294 1388 else if (object == TARGET_OBJECT_RAW_MEMORY)
cf7a04e8 1389 {
9f713294 1390 /* Request the normal memory object from other layers. */
9b409511
YQ
1391 retval = raw_memory_xfer_partial (ops, readbuf, writebuf, offset, len,
1392 xfered_len);
cf7a04e8 1393 }
9f713294
YQ
1394 else
1395 retval = ops->to_xfer_partial (ops, object, annex, readbuf,
9b409511 1396 writebuf, offset, len, xfered_len);
cf7a04e8 1397
27394598
AC
1398 if (targetdebug)
1399 {
1400 const unsigned char *myaddr = NULL;
1401
1402 fprintf_unfiltered (gdb_stdlog,
3e43a32a 1403 "%s:target_xfer_partial "
9b409511 1404 "(%d, %s, %s, %s, %s, %s) = %d, %s",
27394598
AC
1405 ops->to_shortname,
1406 (int) object,
1407 (annex ? annex : "(null)"),
53b71562
JB
1408 host_address_to_string (readbuf),
1409 host_address_to_string (writebuf),
0b1553bc 1410 core_addr_to_string_nz (offset),
9b409511
YQ
1411 pulongest (len), retval,
1412 pulongest (*xfered_len));
27394598
AC
1413
1414 if (readbuf)
1415 myaddr = readbuf;
1416 if (writebuf)
1417 myaddr = writebuf;
9b409511 1418 if (retval == TARGET_XFER_OK && myaddr != NULL)
27394598
AC
1419 {
1420 int i;
2bc416ba 1421
27394598 1422 fputs_unfiltered (", bytes =", gdb_stdlog);
9b409511 1423 for (i = 0; i < *xfered_len; i++)
27394598 1424 {
53b71562 1425 if ((((intptr_t) &(myaddr[i])) & 0xf) == 0)
27394598
AC
1426 {
1427 if (targetdebug < 2 && i > 0)
1428 {
1429 fprintf_unfiltered (gdb_stdlog, " ...");
1430 break;
1431 }
1432 fprintf_unfiltered (gdb_stdlog, "\n");
1433 }
2bc416ba 1434
27394598
AC
1435 fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff);
1436 }
1437 }
2bc416ba 1438
27394598
AC
1439 fputc_unfiltered ('\n', gdb_stdlog);
1440 }
9b409511
YQ
1441
1442 /* Check implementations of to_xfer_partial update *XFERED_LEN
1443 properly. Do assertion after printing debug messages, so that we
1444 can find more clues on assertion failure from debugging messages. */
bc113b4e 1445 if (retval == TARGET_XFER_OK || retval == TARGET_XFER_UNAVAILABLE)
9b409511
YQ
1446 gdb_assert (*xfered_len > 0);
1447
27394598
AC
1448 return retval;
1449}
1450
578d3588
PA
1451/* Read LEN bytes of target memory at address MEMADDR, placing the
1452 results in GDB's memory at MYADDR. Returns either 0 for success or
9b409511 1453 TARGET_XFER_E_IO if any error occurs.
c906108c
SS
1454
1455 If an error occurs, no guarantee is made about the contents of the data at
1456 MYADDR. In particular, the caller should not depend upon partial reads
1457 filling the buffer with good data. There is no way for the caller to know
1458 how much good data might have been transfered anyway. Callers that can
cf7a04e8 1459 deal with partial reads should call target_read (which will retry until
c378eb4e 1460 it makes no progress, and then return how much was transferred). */
c906108c
SS
1461
1462int
1b162304 1463target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
c906108c 1464{
c35b1492
PA
1465 /* Dispatch to the topmost target, not the flattened current_target.
1466 Memory accesses check target->to_has_(all_)memory, and the
1467 flattened target doesn't inherit those. */
1468 if (target_read (current_target.beneath, TARGET_OBJECT_MEMORY, NULL,
cf7a04e8
DJ
1469 myaddr, memaddr, len) == len)
1470 return 0;
0779438d 1471 else
578d3588 1472 return TARGET_XFER_E_IO;
c906108c
SS
1473}
1474
aee4bf85
PA
1475/* Like target_read_memory, but specify explicitly that this is a read
1476 from the target's raw memory. That is, this read bypasses the
1477 dcache, breakpoint shadowing, etc. */
1478
1479int
1480target_read_raw_memory (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
1481{
1482 /* See comment in target_read_memory about why the request starts at
1483 current_target.beneath. */
1484 if (target_read (current_target.beneath, TARGET_OBJECT_RAW_MEMORY, NULL,
1485 myaddr, memaddr, len) == len)
1486 return 0;
1487 else
1488 return TARGET_XFER_E_IO;
1489}
1490
4e5d721f
DE
1491/* Like target_read_memory, but specify explicitly that this is a read from
1492 the target's stack. This may trigger different cache behavior. */
1493
1494int
45aa4659 1495target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
4e5d721f 1496{
aee4bf85
PA
1497 /* See comment in target_read_memory about why the request starts at
1498 current_target.beneath. */
4e5d721f
DE
1499 if (target_read (current_target.beneath, TARGET_OBJECT_STACK_MEMORY, NULL,
1500 myaddr, memaddr, len) == len)
1501 return 0;
1502 else
578d3588 1503 return TARGET_XFER_E_IO;
4e5d721f
DE
1504}
1505
29453a14
YQ
1506/* Like target_read_memory, but specify explicitly that this is a read from
1507 the target's code. This may trigger different cache behavior. */
1508
1509int
1510target_read_code (CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
1511{
aee4bf85
PA
1512 /* See comment in target_read_memory about why the request starts at
1513 current_target.beneath. */
29453a14
YQ
1514 if (target_read (current_target.beneath, TARGET_OBJECT_CODE_MEMORY, NULL,
1515 myaddr, memaddr, len) == len)
1516 return 0;
1517 else
1518 return TARGET_XFER_E_IO;
1519}
1520
7f79c47e 1521/* Write LEN bytes from MYADDR to target memory at address MEMADDR.
9b409511 1522 Returns either 0 for success or TARGET_XFER_E_IO if any
578d3588
PA
1523 error occurs. If an error occurs, no guarantee is made about how
1524 much data got written. Callers that can deal with partial writes
1525 should call target_write. */
7f79c47e 1526
c906108c 1527int
45aa4659 1528target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
c906108c 1529{
aee4bf85
PA
1530 /* See comment in target_read_memory about why the request starts at
1531 current_target.beneath. */
c35b1492 1532 if (target_write (current_target.beneath, TARGET_OBJECT_MEMORY, NULL,
cf7a04e8
DJ
1533 myaddr, memaddr, len) == len)
1534 return 0;
0779438d 1535 else
578d3588 1536 return TARGET_XFER_E_IO;
c906108c 1537}
c5aa993b 1538
f0ba3972 1539/* Write LEN bytes from MYADDR to target raw memory at address
9b409511 1540 MEMADDR. Returns either 0 for success or TARGET_XFER_E_IO
578d3588
PA
1541 if any error occurs. If an error occurs, no guarantee is made
1542 about how much data got written. Callers that can deal with
1543 partial writes should call target_write. */
f0ba3972
PA
1544
1545int
45aa4659 1546target_write_raw_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
f0ba3972 1547{
aee4bf85
PA
1548 /* See comment in target_read_memory about why the request starts at
1549 current_target.beneath. */
f0ba3972
PA
1550 if (target_write (current_target.beneath, TARGET_OBJECT_RAW_MEMORY, NULL,
1551 myaddr, memaddr, len) == len)
1552 return 0;
1553 else
578d3588 1554 return TARGET_XFER_E_IO;
f0ba3972
PA
1555}
1556
fd79ecee
DJ
1557/* Fetch the target's memory map. */
1558
1559VEC(mem_region_s) *
1560target_memory_map (void)
1561{
1562 VEC(mem_region_s) *result;
1563 struct mem_region *last_one, *this_one;
1564 int ix;
1565 struct target_ops *t;
1566
1567 if (targetdebug)
1568 fprintf_unfiltered (gdb_stdlog, "target_memory_map ()\n");
1569
6b2c5a57 1570 result = current_target.to_memory_map (&current_target);
fd79ecee
DJ
1571 if (result == NULL)
1572 return NULL;
1573
1574 qsort (VEC_address (mem_region_s, result),
1575 VEC_length (mem_region_s, result),
1576 sizeof (struct mem_region), mem_region_cmp);
1577
1578 /* Check that regions do not overlap. Simultaneously assign
1579 a numbering for the "mem" commands to use to refer to
1580 each region. */
1581 last_one = NULL;
1582 for (ix = 0; VEC_iterate (mem_region_s, result, ix, this_one); ix++)
1583 {
1584 this_one->number = ix;
1585
1586 if (last_one && last_one->hi > this_one->lo)
1587 {
1588 warning (_("Overlapping regions in memory map: ignoring"));
1589 VEC_free (mem_region_s, result);
1590 return NULL;
1591 }
1592 last_one = this_one;
1593 }
1594
1595 return result;
1596}
1597
a76d924d
DJ
1598void
1599target_flash_erase (ULONGEST address, LONGEST length)
1600{
e8a6c6ac
TT
1601 if (targetdebug)
1602 fprintf_unfiltered (gdb_stdlog, "target_flash_erase (%s, %s)\n",
1603 hex_string (address), phex (length, 0));
1604 current_target.to_flash_erase (&current_target, address, length);
a76d924d
DJ
1605}
1606
1607void
1608target_flash_done (void)
1609{
f6fb2925
TT
1610 if (targetdebug)
1611 fprintf_unfiltered (gdb_stdlog, "target_flash_done\n");
1612 current_target.to_flash_done (&current_target);
a76d924d
DJ
1613}
1614
920d2a44
AC
1615static void
1616show_trust_readonly (struct ui_file *file, int from_tty,
1617 struct cmd_list_element *c, const char *value)
1618{
3e43a32a
MS
1619 fprintf_filtered (file,
1620 _("Mode for reading from readonly sections is %s.\n"),
920d2a44
AC
1621 value);
1622}
3a11626d 1623
7f79c47e 1624/* Target vector read/write partial wrapper functions. */
0088c768 1625
9b409511 1626static enum target_xfer_status
1e3ff5ad
AC
1627target_read_partial (struct target_ops *ops,
1628 enum target_object object,
1b0ba102 1629 const char *annex, gdb_byte *buf,
9b409511
YQ
1630 ULONGEST offset, ULONGEST len,
1631 ULONGEST *xfered_len)
1e3ff5ad 1632{
9b409511
YQ
1633 return target_xfer_partial (ops, object, annex, buf, NULL, offset, len,
1634 xfered_len);
1e3ff5ad
AC
1635}
1636
8a55ffb0 1637static enum target_xfer_status
1e3ff5ad
AC
1638target_write_partial (struct target_ops *ops,
1639 enum target_object object,
1b0ba102 1640 const char *annex, const gdb_byte *buf,
9b409511 1641 ULONGEST offset, LONGEST len, ULONGEST *xfered_len)
1e3ff5ad 1642{
9b409511
YQ
1643 return target_xfer_partial (ops, object, annex, NULL, buf, offset, len,
1644 xfered_len);
1e3ff5ad
AC
1645}
1646
1647/* Wrappers to perform the full transfer. */
7f79c47e
DE
1648
1649/* For docs on target_read see target.h. */
1650
1e3ff5ad
AC
1651LONGEST
1652target_read (struct target_ops *ops,
1653 enum target_object object,
1b0ba102 1654 const char *annex, gdb_byte *buf,
1e3ff5ad
AC
1655 ULONGEST offset, LONGEST len)
1656{
1657 LONGEST xfered = 0;
5d502164 1658
1e3ff5ad
AC
1659 while (xfered < len)
1660 {
9b409511
YQ
1661 ULONGEST xfered_len;
1662 enum target_xfer_status status;
1663
1664 status = target_read_partial (ops, object, annex,
1665 (gdb_byte *) buf + xfered,
1666 offset + xfered, len - xfered,
1667 &xfered_len);
5d502164 1668
1e3ff5ad 1669 /* Call an observer, notifying them of the xfer progress? */
9b409511 1670 if (status == TARGET_XFER_EOF)
13547ab6 1671 return xfered;
9b409511
YQ
1672 else if (status == TARGET_XFER_OK)
1673 {
1674 xfered += xfered_len;
1675 QUIT;
1676 }
1677 else
0088c768 1678 return -1;
9b409511 1679
1e3ff5ad
AC
1680 }
1681 return len;
1682}
1683
f1a507a1
JB
1684/* Assuming that the entire [begin, end) range of memory cannot be
1685 read, try to read whatever subrange is possible to read.
1686
1687 The function returns, in RESULT, either zero or one memory block.
1688 If there's a readable subrange at the beginning, it is completely
1689 read and returned. Any further readable subrange will not be read.
1690 Otherwise, if there's a readable subrange at the end, it will be
1691 completely read and returned. Any readable subranges before it
1692 (obviously, not starting at the beginning), will be ignored. In
1693 other cases -- either no readable subrange, or readable subrange(s)
1694 that is neither at the beginning, or end, nothing is returned.
1695
1696 The purpose of this function is to handle a read across a boundary
1697 of accessible memory in a case when memory map is not available.
1698 The above restrictions are fine for this case, but will give
1699 incorrect results if the memory is 'patchy'. However, supporting
1700 'patchy' memory would require trying to read every single byte,
1701 and it seems unacceptable solution. Explicit memory map is
1702 recommended for this case -- and target_read_memory_robust will
1703 take care of reading multiple ranges then. */
8dedea02
VP
1704
1705static void
3e43a32a
MS
1706read_whatever_is_readable (struct target_ops *ops,
1707 ULONGEST begin, ULONGEST end,
8dedea02 1708 VEC(memory_read_result_s) **result)
d5086790 1709{
f1a507a1 1710 gdb_byte *buf = xmalloc (end - begin);
8dedea02
VP
1711 ULONGEST current_begin = begin;
1712 ULONGEST current_end = end;
1713 int forward;
1714 memory_read_result_s r;
9b409511 1715 ULONGEST xfered_len;
8dedea02
VP
1716
1717 /* If we previously failed to read 1 byte, nothing can be done here. */
1718 if (end - begin <= 1)
13b3fd9b
MS
1719 {
1720 xfree (buf);
1721 return;
1722 }
8dedea02
VP
1723
1724 /* Check that either first or the last byte is readable, and give up
c378eb4e 1725 if not. This heuristic is meant to permit reading accessible memory
8dedea02
VP
1726 at the boundary of accessible region. */
1727 if (target_read_partial (ops, TARGET_OBJECT_MEMORY, NULL,
9b409511 1728 buf, begin, 1, &xfered_len) == TARGET_XFER_OK)
8dedea02
VP
1729 {
1730 forward = 1;
1731 ++current_begin;
1732 }
1733 else if (target_read_partial (ops, TARGET_OBJECT_MEMORY, NULL,
9b409511
YQ
1734 buf + (end-begin) - 1, end - 1, 1,
1735 &xfered_len) == TARGET_XFER_OK)
8dedea02
VP
1736 {
1737 forward = 0;
1738 --current_end;
1739 }
1740 else
1741 {
13b3fd9b 1742 xfree (buf);
8dedea02
VP
1743 return;
1744 }
1745
1746 /* Loop invariant is that the [current_begin, current_end) was previously
1747 found to be not readable as a whole.
1748
1749 Note loop condition -- if the range has 1 byte, we can't divide the range
1750 so there's no point trying further. */
1751 while (current_end - current_begin > 1)
1752 {
1753 ULONGEST first_half_begin, first_half_end;
1754 ULONGEST second_half_begin, second_half_end;
1755 LONGEST xfer;
8dedea02 1756 ULONGEST middle = current_begin + (current_end - current_begin)/2;
f1a507a1 1757
8dedea02
VP
1758 if (forward)
1759 {
1760 first_half_begin = current_begin;
1761 first_half_end = middle;
1762 second_half_begin = middle;
1763 second_half_end = current_end;
1764 }
1765 else
1766 {
1767 first_half_begin = middle;
1768 first_half_end = current_end;
1769 second_half_begin = current_begin;
1770 second_half_end = middle;
1771 }
1772
1773 xfer = target_read (ops, TARGET_OBJECT_MEMORY, NULL,
1774 buf + (first_half_begin - begin),
1775 first_half_begin,
1776 first_half_end - first_half_begin);
1777
1778 if (xfer == first_half_end - first_half_begin)
1779 {
c378eb4e 1780 /* This half reads up fine. So, the error must be in the
3e43a32a 1781 other half. */
8dedea02
VP
1782 current_begin = second_half_begin;
1783 current_end = second_half_end;
1784 }
1785 else
1786 {
c378eb4e
MS
1787 /* This half is not readable. Because we've tried one byte, we
1788 know some part of this half if actually redable. Go to the next
8dedea02
VP
1789 iteration to divide again and try to read.
1790
1791 We don't handle the other half, because this function only tries
1792 to read a single readable subrange. */
1793 current_begin = first_half_begin;
1794 current_end = first_half_end;
1795 }
1796 }
1797
1798 if (forward)
1799 {
1800 /* The [begin, current_begin) range has been read. */
1801 r.begin = begin;
1802 r.end = current_begin;
1803 r.data = buf;
1804 }
1805 else
1806 {
1807 /* The [current_end, end) range has been read. */
1808 LONGEST rlen = end - current_end;
f1a507a1 1809
8dedea02
VP
1810 r.data = xmalloc (rlen);
1811 memcpy (r.data, buf + current_end - begin, rlen);
1812 r.begin = current_end;
1813 r.end = end;
1814 xfree (buf);
1815 }
1816 VEC_safe_push(memory_read_result_s, (*result), &r);
1817}
1818
1819void
1820free_memory_read_result_vector (void *x)
1821{
1822 VEC(memory_read_result_s) *v = x;
1823 memory_read_result_s *current;
1824 int ix;
1825
1826 for (ix = 0; VEC_iterate (memory_read_result_s, v, ix, current); ++ix)
1827 {
1828 xfree (current->data);
1829 }
1830 VEC_free (memory_read_result_s, v);
1831}
1832
1833VEC(memory_read_result_s) *
1834read_memory_robust (struct target_ops *ops, ULONGEST offset, LONGEST len)
1835{
1836 VEC(memory_read_result_s) *result = 0;
1837
1838 LONGEST xfered = 0;
d5086790
VP
1839 while (xfered < len)
1840 {
8dedea02
VP
1841 struct mem_region *region = lookup_mem_region (offset + xfered);
1842 LONGEST rlen;
5d502164 1843
8dedea02
VP
1844 /* If there is no explicit region, a fake one should be created. */
1845 gdb_assert (region);
1846
1847 if (region->hi == 0)
1848 rlen = len - xfered;
1849 else
1850 rlen = region->hi - offset;
1851
1852 if (region->attrib.mode == MEM_NONE || region->attrib.mode == MEM_WO)
d5086790 1853 {
c378eb4e 1854 /* Cannot read this region. Note that we can end up here only
8dedea02
VP
1855 if the region is explicitly marked inaccessible, or
1856 'inaccessible-by-default' is in effect. */
1857 xfered += rlen;
1858 }
1859 else
1860 {
1861 LONGEST to_read = min (len - xfered, rlen);
1862 gdb_byte *buffer = (gdb_byte *)xmalloc (to_read);
1863
1864 LONGEST xfer = target_read (ops, TARGET_OBJECT_MEMORY, NULL,
1865 (gdb_byte *) buffer,
1866 offset + xfered, to_read);
1867 /* Call an observer, notifying them of the xfer progress? */
d5086790 1868 if (xfer <= 0)
d5086790 1869 {
c378eb4e 1870 /* Got an error reading full chunk. See if maybe we can read
8dedea02
VP
1871 some subrange. */
1872 xfree (buffer);
3e43a32a
MS
1873 read_whatever_is_readable (ops, offset + xfered,
1874 offset + xfered + to_read, &result);
8dedea02 1875 xfered += to_read;
d5086790 1876 }
8dedea02
VP
1877 else
1878 {
1879 struct memory_read_result r;
1880 r.data = buffer;
1881 r.begin = offset + xfered;
1882 r.end = r.begin + xfer;
1883 VEC_safe_push (memory_read_result_s, result, &r);
1884 xfered += xfer;
1885 }
1886 QUIT;
d5086790 1887 }
d5086790 1888 }
8dedea02 1889 return result;
d5086790
VP
1890}
1891
8dedea02 1892
cf7a04e8
DJ
1893/* An alternative to target_write with progress callbacks. */
1894
1e3ff5ad 1895LONGEST
cf7a04e8
DJ
1896target_write_with_progress (struct target_ops *ops,
1897 enum target_object object,
1898 const char *annex, const gdb_byte *buf,
1899 ULONGEST offset, LONGEST len,
1900 void (*progress) (ULONGEST, void *), void *baton)
1e3ff5ad
AC
1901{
1902 LONGEST xfered = 0;
a76d924d
DJ
1903
1904 /* Give the progress callback a chance to set up. */
1905 if (progress)
1906 (*progress) (0, baton);
1907
1e3ff5ad
AC
1908 while (xfered < len)
1909 {
9b409511
YQ
1910 ULONGEST xfered_len;
1911 enum target_xfer_status status;
1912
1913 status = target_write_partial (ops, object, annex,
1914 (gdb_byte *) buf + xfered,
1915 offset + xfered, len - xfered,
1916 &xfered_len);
cf7a04e8 1917
5c328c05
YQ
1918 if (status != TARGET_XFER_OK)
1919 return status == TARGET_XFER_EOF ? xfered : -1;
cf7a04e8
DJ
1920
1921 if (progress)
9b409511 1922 (*progress) (xfered_len, baton);
cf7a04e8 1923
9b409511 1924 xfered += xfered_len;
1e3ff5ad
AC
1925 QUIT;
1926 }
1927 return len;
1928}
1929
7f79c47e
DE
1930/* For docs on target_write see target.h. */
1931
cf7a04e8
DJ
1932LONGEST
1933target_write (struct target_ops *ops,
1934 enum target_object object,
1935 const char *annex, const gdb_byte *buf,
1936 ULONGEST offset, LONGEST len)
1937{
1938 return target_write_with_progress (ops, object, annex, buf, offset, len,
1939 NULL, NULL);
1940}
1941
159f81f3
DJ
1942/* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
1943 the size of the transferred data. PADDING additional bytes are
1944 available in *BUF_P. This is a helper function for
1945 target_read_alloc; see the declaration of that function for more
1946 information. */
13547ab6 1947
159f81f3
DJ
1948static LONGEST
1949target_read_alloc_1 (struct target_ops *ops, enum target_object object,
1950 const char *annex, gdb_byte **buf_p, int padding)
13547ab6
DJ
1951{
1952 size_t buf_alloc, buf_pos;
1953 gdb_byte *buf;
13547ab6
DJ
1954
1955 /* This function does not have a length parameter; it reads the
1956 entire OBJECT). Also, it doesn't support objects fetched partly
1957 from one target and partly from another (in a different stratum,
1958 e.g. a core file and an executable). Both reasons make it
1959 unsuitable for reading memory. */
1960 gdb_assert (object != TARGET_OBJECT_MEMORY);
1961
1962 /* Start by reading up to 4K at a time. The target will throttle
1963 this number down if necessary. */
1964 buf_alloc = 4096;
1965 buf = xmalloc (buf_alloc);
1966 buf_pos = 0;
1967 while (1)
1968 {
9b409511
YQ
1969 ULONGEST xfered_len;
1970 enum target_xfer_status status;
1971
1972 status = target_read_partial (ops, object, annex, &buf[buf_pos],
1973 buf_pos, buf_alloc - buf_pos - padding,
1974 &xfered_len);
1975
1976 if (status == TARGET_XFER_EOF)
13547ab6
DJ
1977 {
1978 /* Read all there was. */
1979 if (buf_pos == 0)
1980 xfree (buf);
1981 else
1982 *buf_p = buf;
1983 return buf_pos;
1984 }
9b409511
YQ
1985 else if (status != TARGET_XFER_OK)
1986 {
1987 /* An error occurred. */
1988 xfree (buf);
1989 return TARGET_XFER_E_IO;
1990 }
13547ab6 1991
9b409511 1992 buf_pos += xfered_len;
13547ab6
DJ
1993
1994 /* If the buffer is filling up, expand it. */
1995 if (buf_alloc < buf_pos * 2)
1996 {
1997 buf_alloc *= 2;
1998 buf = xrealloc (buf, buf_alloc);
1999 }
2000
2001 QUIT;
2002 }
2003}
2004
159f81f3
DJ
2005/* Read OBJECT/ANNEX using OPS. Store the result in *BUF_P and return
2006 the size of the transferred data. See the declaration in "target.h"
2007 function for more information about the return value. */
2008
2009LONGEST
2010target_read_alloc (struct target_ops *ops, enum target_object object,
2011 const char *annex, gdb_byte **buf_p)
2012{
2013 return target_read_alloc_1 (ops, object, annex, buf_p, 0);
2014}
2015
2016/* Read OBJECT/ANNEX using OPS. The result is NUL-terminated and
2017 returned as a string, allocated using xmalloc. If an error occurs
2018 or the transfer is unsupported, NULL is returned. Empty objects
2019 are returned as allocated but empty strings. A warning is issued
2020 if the result contains any embedded NUL bytes. */
2021
2022char *
2023target_read_stralloc (struct target_ops *ops, enum target_object object,
2024 const char *annex)
2025{
39086a0e
PA
2026 gdb_byte *buffer;
2027 char *bufstr;
7313baad 2028 LONGEST i, transferred;
159f81f3 2029
39086a0e
PA
2030 transferred = target_read_alloc_1 (ops, object, annex, &buffer, 1);
2031 bufstr = (char *) buffer;
159f81f3
DJ
2032
2033 if (transferred < 0)
2034 return NULL;
2035
2036 if (transferred == 0)
2037 return xstrdup ("");
2038
39086a0e 2039 bufstr[transferred] = 0;
7313baad
UW
2040
2041 /* Check for embedded NUL bytes; but allow trailing NULs. */
39086a0e
PA
2042 for (i = strlen (bufstr); i < transferred; i++)
2043 if (bufstr[i] != 0)
7313baad
UW
2044 {
2045 warning (_("target object %d, annex %s, "
2046 "contained unexpected null characters"),
2047 (int) object, annex ? annex : "(none)");
2048 break;
2049 }
159f81f3 2050
39086a0e 2051 return bufstr;
159f81f3
DJ
2052}
2053
b6591e8b
AC
2054/* Memory transfer methods. */
2055
2056void
1b0ba102 2057get_target_memory (struct target_ops *ops, CORE_ADDR addr, gdb_byte *buf,
b6591e8b
AC
2058 LONGEST len)
2059{
07b82ea5
PA
2060 /* This method is used to read from an alternate, non-current
2061 target. This read must bypass the overlay support (as symbols
2062 don't match this target), and GDB's internal cache (wrong cache
2063 for this target). */
2064 if (target_read (ops, TARGET_OBJECT_RAW_MEMORY, NULL, buf, addr, len)
b6591e8b 2065 != len)
578d3588 2066 memory_error (TARGET_XFER_E_IO, addr);
b6591e8b
AC
2067}
2068
2069ULONGEST
5d502164
MS
2070get_target_memory_unsigned (struct target_ops *ops, CORE_ADDR addr,
2071 int len, enum bfd_endian byte_order)
b6591e8b 2072{
f6519ebc 2073 gdb_byte buf[sizeof (ULONGEST)];
b6591e8b
AC
2074
2075 gdb_assert (len <= sizeof (buf));
2076 get_target_memory (ops, addr, buf, len);
e17a4113 2077 return extract_unsigned_integer (buf, len, byte_order);
b6591e8b
AC
2078}
2079
3db08215
MM
2080/* See target.h. */
2081
d914c394
SS
2082int
2083target_insert_breakpoint (struct gdbarch *gdbarch,
2084 struct bp_target_info *bp_tgt)
2085{
2086 if (!may_insert_breakpoints)
2087 {
2088 warning (_("May not insert breakpoints"));
2089 return 1;
2090 }
2091
6b84065d
TT
2092 return current_target.to_insert_breakpoint (&current_target,
2093 gdbarch, bp_tgt);
d914c394
SS
2094}
2095
3db08215
MM
2096/* See target.h. */
2097
d914c394 2098int
6b84065d
TT
2099target_remove_breakpoint (struct gdbarch *gdbarch,
2100 struct bp_target_info *bp_tgt)
d914c394
SS
2101{
2102 /* This is kind of a weird case to handle, but the permission might
2103 have been changed after breakpoints were inserted - in which case
2104 we should just take the user literally and assume that any
2105 breakpoints should be left in place. */
2106 if (!may_insert_breakpoints)
2107 {
2108 warning (_("May not remove breakpoints"));
2109 return 1;
2110 }
2111
6b84065d
TT
2112 return current_target.to_remove_breakpoint (&current_target,
2113 gdbarch, bp_tgt);
d914c394
SS
2114}
2115
c906108c 2116static void
fba45db2 2117target_info (char *args, int from_tty)
c906108c
SS
2118{
2119 struct target_ops *t;
c906108c 2120 int has_all_mem = 0;
c5aa993b 2121
c906108c 2122 if (symfile_objfile != NULL)
4262abfb
JK
2123 printf_unfiltered (_("Symbols from \"%s\".\n"),
2124 objfile_name (symfile_objfile));
c906108c 2125
258b763a 2126 for (t = target_stack; t != NULL; t = t->beneath)
c906108c 2127 {
c35b1492 2128 if (!(*t->to_has_memory) (t))
c906108c
SS
2129 continue;
2130
c5aa993b 2131 if ((int) (t->to_stratum) <= (int) dummy_stratum)
c906108c
SS
2132 continue;
2133 if (has_all_mem)
3e43a32a
MS
2134 printf_unfiltered (_("\tWhile running this, "
2135 "GDB does not access memory from...\n"));
c5aa993b
JM
2136 printf_unfiltered ("%s:\n", t->to_longname);
2137 (t->to_files_info) (t);
c35b1492 2138 has_all_mem = (*t->to_has_all_memory) (t);
c906108c
SS
2139 }
2140}
2141
fd79ecee
DJ
2142/* This function is called before any new inferior is created, e.g.
2143 by running a program, attaching, or connecting to a target.
2144 It cleans up any state from previous invocations which might
2145 change between runs. This is a subset of what target_preopen
2146 resets (things which might change between targets). */
2147
2148void
2149target_pre_inferior (int from_tty)
2150{
c378eb4e 2151 /* Clear out solib state. Otherwise the solib state of the previous
b9db4ced 2152 inferior might have survived and is entirely wrong for the new
c378eb4e 2153 target. This has been observed on GNU/Linux using glibc 2.3. How
b9db4ced
UW
2154 to reproduce:
2155
2156 bash$ ./foo&
2157 [1] 4711
2158 bash$ ./foo&
2159 [1] 4712
2160 bash$ gdb ./foo
2161 [...]
2162 (gdb) attach 4711
2163 (gdb) detach
2164 (gdb) attach 4712
2165 Cannot access memory at address 0xdeadbeef
2166 */
b9db4ced 2167
50c71eaf
PA
2168 /* In some OSs, the shared library list is the same/global/shared
2169 across inferiors. If code is shared between processes, so are
2170 memory regions and features. */
f5656ead 2171 if (!gdbarch_has_global_solist (target_gdbarch ()))
50c71eaf
PA
2172 {
2173 no_shared_libraries (NULL, from_tty);
2174
2175 invalidate_target_mem_regions ();
424163ea 2176
50c71eaf
PA
2177 target_clear_description ();
2178 }
8ffcbaaf
YQ
2179
2180 agent_capability_invalidate ();
fd79ecee
DJ
2181}
2182
b8fa0bfa
PA
2183/* Callback for iterate_over_inferiors. Gets rid of the given
2184 inferior. */
2185
2186static int
2187dispose_inferior (struct inferior *inf, void *args)
2188{
2189 struct thread_info *thread;
2190
2191 thread = any_thread_of_process (inf->pid);
2192 if (thread)
2193 {
2194 switch_to_thread (thread->ptid);
2195
2196 /* Core inferiors actually should be detached, not killed. */
2197 if (target_has_execution)
2198 target_kill ();
2199 else
2200 target_detach (NULL, 0);
2201 }
2202
2203 return 0;
2204}
2205
c906108c
SS
2206/* This is to be called by the open routine before it does
2207 anything. */
2208
2209void
fba45db2 2210target_preopen (int from_tty)
c906108c 2211{
c5aa993b 2212 dont_repeat ();
c906108c 2213
b8fa0bfa 2214 if (have_inferiors ())
c5aa993b 2215 {
adf40b2e 2216 if (!from_tty
b8fa0bfa
PA
2217 || !have_live_inferiors ()
2218 || query (_("A program is being debugged already. Kill it? ")))
2219 iterate_over_inferiors (dispose_inferior, NULL);
c906108c 2220 else
8a3fe4f8 2221 error (_("Program not killed."));
c906108c
SS
2222 }
2223
2224 /* Calling target_kill may remove the target from the stack. But if
2225 it doesn't (which seems like a win for UDI), remove it now. */
87ab71f0
PA
2226 /* Leave the exec target, though. The user may be switching from a
2227 live process to a core of the same program. */
460014f5 2228 pop_all_targets_above (file_stratum);
fd79ecee
DJ
2229
2230 target_pre_inferior (from_tty);
c906108c
SS
2231}
2232
2233/* Detach a target after doing deferred register stores. */
2234
2235void
52554a0e 2236target_detach (const char *args, int from_tty)
c906108c 2237{
136d6dae
VP
2238 struct target_ops* t;
2239
f5656ead 2240 if (gdbarch_has_global_breakpoints (target_gdbarch ()))
50c71eaf
PA
2241 /* Don't remove global breakpoints here. They're removed on
2242 disconnection from the target. */
2243 ;
2244 else
2245 /* If we're in breakpoints-always-inserted mode, have to remove
2246 them before detaching. */
dfd4cc63 2247 remove_breakpoints_pid (ptid_get_pid (inferior_ptid));
74960c60 2248
24291992
PA
2249 prepare_for_detach ();
2250
09da0d0a
TT
2251 current_target.to_detach (&current_target, args, from_tty);
2252 if (targetdebug)
2253 fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n",
2254 args, from_tty);
c906108c
SS
2255}
2256
6ad8ae5c
DJ
2257void
2258target_disconnect (char *args, int from_tty)
2259{
50c71eaf
PA
2260 /* If we're in breakpoints-always-inserted mode or if breakpoints
2261 are global across processes, we have to remove them before
2262 disconnecting. */
74960c60
VP
2263 remove_breakpoints ();
2264
86a0854a
TT
2265 if (targetdebug)
2266 fprintf_unfiltered (gdb_stdlog, "target_disconnect (%s, %d)\n",
2267 args, from_tty);
2268 current_target.to_disconnect (&current_target, args, from_tty);
6ad8ae5c
DJ
2269}
2270
117de6a9 2271ptid_t
47608cb1 2272target_wait (ptid_t ptid, struct target_waitstatus *status, int options)
117de6a9
PA
2273{
2274 struct target_ops *t;
6b84065d
TT
2275 ptid_t retval = (current_target.to_wait) (&current_target, ptid,
2276 status, options);
117de6a9 2277
6b84065d 2278 if (targetdebug)
117de6a9 2279 {
6b84065d
TT
2280 char *status_string;
2281 char *options_string;
117de6a9 2282
6b84065d
TT
2283 status_string = target_waitstatus_to_string (status);
2284 options_string = target_options_to_string (options);
2285 fprintf_unfiltered (gdb_stdlog,
2286 "target_wait (%d, status, options={%s})"
2287 " = %d, %s\n",
2288 ptid_get_pid (ptid), options_string,
2289 ptid_get_pid (retval), status_string);
2290 xfree (status_string);
2291 xfree (options_string);
117de6a9
PA
2292 }
2293
6b84065d 2294 return retval;
117de6a9
PA
2295}
2296
2297char *
2298target_pid_to_str (ptid_t ptid)
2299{
770234d3 2300 return (*current_target.to_pid_to_str) (&current_target, ptid);
117de6a9
PA
2301}
2302
4694da01
TT
2303char *
2304target_thread_name (struct thread_info *info)
2305{
825828fc 2306 return current_target.to_thread_name (&current_target, info);
4694da01
TT
2307}
2308
e1ac3328 2309void
2ea28649 2310target_resume (ptid_t ptid, int step, enum gdb_signal signal)
e1ac3328 2311{
28439f5e
PA
2312 struct target_ops *t;
2313
4e5d721f 2314 target_dcache_invalidate ();
28439f5e 2315
6b84065d
TT
2316 current_target.to_resume (&current_target, ptid, step, signal);
2317 if (targetdebug)
2318 fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n",
2319 ptid_get_pid (ptid),
2320 step ? "step" : "continue",
2321 gdb_signal_to_name (signal));
28439f5e 2322
6b84065d
TT
2323 registers_changed_ptid (ptid);
2324 set_executing (ptid, 1);
2325 set_running (ptid, 1);
2326 clear_inline_frame_state (ptid);
e1ac3328 2327}
2455069d
UW
2328
2329void
2330target_pass_signals (int numsigs, unsigned char *pass_signals)
2331{
035cad7f 2332 if (targetdebug)
2455069d 2333 {
035cad7f 2334 int i;
2455069d 2335
035cad7f
TT
2336 fprintf_unfiltered (gdb_stdlog, "target_pass_signals (%d, {",
2337 numsigs);
2455069d 2338
035cad7f
TT
2339 for (i = 0; i < numsigs; i++)
2340 if (pass_signals[i])
2341 fprintf_unfiltered (gdb_stdlog, " %s",
2342 gdb_signal_to_name (i));
2455069d 2343
035cad7f 2344 fprintf_unfiltered (gdb_stdlog, " })\n");
2455069d 2345 }
035cad7f
TT
2346
2347 (*current_target.to_pass_signals) (&current_target, numsigs, pass_signals);
2455069d
UW
2348}
2349
9b224c5e
PA
2350void
2351target_program_signals (int numsigs, unsigned char *program_signals)
2352{
7d4f8efa 2353 if (targetdebug)
9b224c5e 2354 {
7d4f8efa 2355 int i;
9b224c5e 2356
7d4f8efa
TT
2357 fprintf_unfiltered (gdb_stdlog, "target_program_signals (%d, {",
2358 numsigs);
9b224c5e 2359
7d4f8efa
TT
2360 for (i = 0; i < numsigs; i++)
2361 if (program_signals[i])
2362 fprintf_unfiltered (gdb_stdlog, " %s",
2363 gdb_signal_to_name (i));
9b224c5e 2364
7d4f8efa 2365 fprintf_unfiltered (gdb_stdlog, " })\n");
9b224c5e 2366 }
7d4f8efa
TT
2367
2368 (*current_target.to_program_signals) (&current_target,
2369 numsigs, program_signals);
9b224c5e
PA
2370}
2371
098dba18
TT
2372static int
2373default_follow_fork (struct target_ops *self, int follow_child,
2374 int detach_fork)
2375{
2376 /* Some target returned a fork event, but did not know how to follow it. */
2377 internal_error (__FILE__, __LINE__,
2378 _("could not find a target to follow fork"));
2379}
2380
ee057212
DJ
2381/* Look through the list of possible targets for a target that can
2382 follow forks. */
2383
2384int
07107ca6 2385target_follow_fork (int follow_child, int detach_fork)
ee057212 2386{
098dba18
TT
2387 int retval = current_target.to_follow_fork (&current_target,
2388 follow_child, detach_fork);
ee057212 2389
098dba18
TT
2390 if (targetdebug)
2391 fprintf_unfiltered (gdb_stdlog,
2392 "target_follow_fork (%d, %d) = %d\n",
2393 follow_child, detach_fork, retval);
2394 return retval;
ee057212
DJ
2395}
2396
8d657035
TT
2397static void
2398default_mourn_inferior (struct target_ops *self)
2399{
2400 internal_error (__FILE__, __LINE__,
2401 _("could not find a target to follow mourn inferior"));
2402}
2403
136d6dae
VP
2404void
2405target_mourn_inferior (void)
2406{
8d657035
TT
2407 current_target.to_mourn_inferior (&current_target);
2408 if (targetdebug)
2409 fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n");
136d6dae 2410
8d657035
TT
2411 /* We no longer need to keep handles on any of the object files.
2412 Make sure to release them to avoid unnecessarily locking any
2413 of them while we're not actually debugging. */
2414 bfd_cache_close_all ();
136d6dae
VP
2415}
2416
424163ea
DJ
2417/* Look for a target which can describe architectural features, starting
2418 from TARGET. If we find one, return its description. */
2419
2420const struct target_desc *
2421target_read_description (struct target_ops *target)
2422{
2117c711 2423 return target->to_read_description (target);
424163ea
DJ
2424}
2425
58a5184e 2426/* This implements a basic search of memory, reading target memory and
08388c79
DE
2427 performing the search here (as opposed to performing the search in on the
2428 target side with, for example, gdbserver). */
2429
2430int
2431simple_search_memory (struct target_ops *ops,
2432 CORE_ADDR start_addr, ULONGEST search_space_len,
2433 const gdb_byte *pattern, ULONGEST pattern_len,
2434 CORE_ADDR *found_addrp)
2435{
2436 /* NOTE: also defined in find.c testcase. */
2437#define SEARCH_CHUNK_SIZE 16000
2438 const unsigned chunk_size = SEARCH_CHUNK_SIZE;
2439 /* Buffer to hold memory contents for searching. */
2440 gdb_byte *search_buf;
2441 unsigned search_buf_size;
2442 struct cleanup *old_cleanups;
2443
2444 search_buf_size = chunk_size + pattern_len - 1;
2445
2446 /* No point in trying to allocate a buffer larger than the search space. */
2447 if (search_space_len < search_buf_size)
2448 search_buf_size = search_space_len;
2449
2450 search_buf = malloc (search_buf_size);
2451 if (search_buf == NULL)
5e1471f5 2452 error (_("Unable to allocate memory to perform the search."));
08388c79
DE
2453 old_cleanups = make_cleanup (free_current_contents, &search_buf);
2454
2455 /* Prime the search buffer. */
2456
2457 if (target_read (ops, TARGET_OBJECT_MEMORY, NULL,
2458 search_buf, start_addr, search_buf_size) != search_buf_size)
2459 {
b3dc46ff
AB
2460 warning (_("Unable to access %s bytes of target "
2461 "memory at %s, halting search."),
2462 pulongest (search_buf_size), hex_string (start_addr));
08388c79
DE
2463 do_cleanups (old_cleanups);
2464 return -1;
2465 }
2466
2467 /* Perform the search.
2468
2469 The loop is kept simple by allocating [N + pattern-length - 1] bytes.
2470 When we've scanned N bytes we copy the trailing bytes to the start and
2471 read in another N bytes. */
2472
2473 while (search_space_len >= pattern_len)
2474 {
2475 gdb_byte *found_ptr;
2476 unsigned nr_search_bytes = min (search_space_len, search_buf_size);
2477
2478 found_ptr = memmem (search_buf, nr_search_bytes,
2479 pattern, pattern_len);
2480
2481 if (found_ptr != NULL)
2482 {
2483 CORE_ADDR found_addr = start_addr + (found_ptr - search_buf);
5d502164 2484
08388c79
DE
2485 *found_addrp = found_addr;
2486 do_cleanups (old_cleanups);
2487 return 1;
2488 }
2489
2490 /* Not found in this chunk, skip to next chunk. */
2491
2492 /* Don't let search_space_len wrap here, it's unsigned. */
2493 if (search_space_len >= chunk_size)
2494 search_space_len -= chunk_size;
2495 else
2496 search_space_len = 0;
2497
2498 if (search_space_len >= pattern_len)
2499 {
2500 unsigned keep_len = search_buf_size - chunk_size;
8a35fb51 2501 CORE_ADDR read_addr = start_addr + chunk_size + keep_len;
08388c79
DE
2502 int nr_to_read;
2503
2504 /* Copy the trailing part of the previous iteration to the front
2505 of the buffer for the next iteration. */
2506 gdb_assert (keep_len == pattern_len - 1);
2507 memcpy (search_buf, search_buf + chunk_size, keep_len);
2508
2509 nr_to_read = min (search_space_len - keep_len, chunk_size);
2510
2511 if (target_read (ops, TARGET_OBJECT_MEMORY, NULL,
2512 search_buf + keep_len, read_addr,
2513 nr_to_read) != nr_to_read)
2514 {
b3dc46ff 2515 warning (_("Unable to access %s bytes of target "
9b20d036 2516 "memory at %s, halting search."),
b3dc46ff 2517 plongest (nr_to_read),
08388c79
DE
2518 hex_string (read_addr));
2519 do_cleanups (old_cleanups);
2520 return -1;
2521 }
2522
2523 start_addr += chunk_size;
2524 }
2525 }
2526
2527 /* Not found. */
2528
2529 do_cleanups (old_cleanups);
2530 return 0;
2531}
2532
58a5184e
TT
2533/* Default implementation of memory-searching. */
2534
2535static int
2536default_search_memory (struct target_ops *self,
2537 CORE_ADDR start_addr, ULONGEST search_space_len,
2538 const gdb_byte *pattern, ULONGEST pattern_len,
2539 CORE_ADDR *found_addrp)
2540{
2541 /* Start over from the top of the target stack. */
2542 return simple_search_memory (current_target.beneath,
2543 start_addr, search_space_len,
2544 pattern, pattern_len, found_addrp);
2545}
2546
08388c79
DE
2547/* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
2548 sequence of bytes in PATTERN with length PATTERN_LEN.
2549
2550 The result is 1 if found, 0 if not found, and -1 if there was an error
2551 requiring halting of the search (e.g. memory read error).
2552 If the pattern is found the address is recorded in FOUND_ADDRP. */
2553
2554int
2555target_search_memory (CORE_ADDR start_addr, ULONGEST search_space_len,
2556 const gdb_byte *pattern, ULONGEST pattern_len,
2557 CORE_ADDR *found_addrp)
2558{
08388c79
DE
2559 int found;
2560
08388c79
DE
2561 if (targetdebug)
2562 fprintf_unfiltered (gdb_stdlog, "target_search_memory (%s, ...)\n",
2563 hex_string (start_addr));
2564
58a5184e
TT
2565 found = current_target.to_search_memory (&current_target, start_addr,
2566 search_space_len,
2567 pattern, pattern_len, found_addrp);
08388c79
DE
2568
2569 if (targetdebug)
2570 fprintf_unfiltered (gdb_stdlog, " = %d\n", found);
2571
2572 return found;
2573}
2574
8edfe269
DJ
2575/* Look through the currently pushed targets. If none of them will
2576 be able to restart the currently running process, issue an error
2577 message. */
2578
2579void
2580target_require_runnable (void)
2581{
2582 struct target_ops *t;
2583
2584 for (t = target_stack; t != NULL; t = t->beneath)
2585 {
2586 /* If this target knows how to create a new program, then
2587 assume we will still be able to after killing the current
2588 one. Either killing and mourning will not pop T, or else
2589 find_default_run_target will find it again. */
2590 if (t->to_create_inferior != NULL)
2591 return;
2592
2593 /* Do not worry about thread_stratum targets that can not
2594 create inferiors. Assume they will be pushed again if
2595 necessary, and continue to the process_stratum. */
85e747d2
UW
2596 if (t->to_stratum == thread_stratum
2597 || t->to_stratum == arch_stratum)
8edfe269
DJ
2598 continue;
2599
3e43a32a
MS
2600 error (_("The \"%s\" target does not support \"run\". "
2601 "Try \"help target\" or \"continue\"."),
8edfe269
DJ
2602 t->to_shortname);
2603 }
2604
2605 /* This function is only called if the target is running. In that
2606 case there should have been a process_stratum target and it
c378eb4e 2607 should either know how to create inferiors, or not... */
9b20d036 2608 internal_error (__FILE__, __LINE__, _("No targets found"));
8edfe269
DJ
2609}
2610
c906108c
SS
2611/* Look through the list of possible targets for a target that can
2612 execute a run or attach command without any other data. This is
2613 used to locate the default process stratum.
2614
5f667f2d
PA
2615 If DO_MESG is not NULL, the result is always valid (error() is
2616 called for errors); else, return NULL on error. */
c906108c
SS
2617
2618static struct target_ops *
fba45db2 2619find_default_run_target (char *do_mesg)
c906108c
SS
2620{
2621 struct target_ops **t;
2622 struct target_ops *runable = NULL;
2623 int count;
2624
2625 count = 0;
2626
2627 for (t = target_structs; t < target_structs + target_struct_size;
2628 ++t)
2629 {
e88ef65c 2630 if ((*t)->to_can_run != delegate_can_run && target_can_run (*t))
c906108c
SS
2631 {
2632 runable = *t;
2633 ++count;
2634 }
2635 }
2636
2637 if (count != 1)
5f667f2d
PA
2638 {
2639 if (do_mesg)
2640 error (_("Don't know how to %s. Try \"help target\"."), do_mesg);
2641 else
2642 return NULL;
2643 }
c906108c
SS
2644
2645 return runable;
2646}
2647
2648void
136d6dae 2649find_default_attach (struct target_ops *ops, char *args, int from_tty)
c906108c
SS
2650{
2651 struct target_ops *t;
2652
c5aa993b 2653 t = find_default_run_target ("attach");
136d6dae 2654 (t->to_attach) (t, args, from_tty);
c906108c
SS
2655 return;
2656}
2657
c906108c 2658void
136d6dae
VP
2659find_default_create_inferior (struct target_ops *ops,
2660 char *exec_file, char *allargs, char **env,
c27cda74 2661 int from_tty)
c906108c
SS
2662{
2663 struct target_ops *t;
2664
c5aa993b 2665 t = find_default_run_target ("run");
136d6dae 2666 (t->to_create_inferior) (t, exec_file, allargs, env, from_tty);
c906108c
SS
2667 return;
2668}
2669
2c0b251b 2670static int
6a109b6b 2671find_default_can_async_p (struct target_ops *ignore)
b84876c2
PA
2672{
2673 struct target_ops *t;
2674
5f667f2d
PA
2675 /* This may be called before the target is pushed on the stack;
2676 look for the default process stratum. If there's none, gdb isn't
2677 configured with a native debugger, and target remote isn't
2678 connected yet. */
2679 t = find_default_run_target (NULL);
6b84065d 2680 if (t && t->to_can_async_p != delegate_can_async_p)
6a109b6b 2681 return (t->to_can_async_p) (t);
b84876c2
PA
2682 return 0;
2683}
2684
2c0b251b 2685static int
6a109b6b 2686find_default_is_async_p (struct target_ops *ignore)
b84876c2
PA
2687{
2688 struct target_ops *t;
2689
5f667f2d
PA
2690 /* This may be called before the target is pushed on the stack;
2691 look for the default process stratum. If there's none, gdb isn't
2692 configured with a native debugger, and target remote isn't
2693 connected yet. */
2694 t = find_default_run_target (NULL);
6b84065d 2695 if (t && t->to_is_async_p != delegate_is_async_p)
6a109b6b 2696 return (t->to_is_async_p) (t);
b84876c2
PA
2697 return 0;
2698}
2699
2c0b251b 2700static int
2a9a2795 2701find_default_supports_non_stop (struct target_ops *self)
9908b566
VP
2702{
2703 struct target_ops *t;
2704
2705 t = find_default_run_target (NULL);
2706 if (t && t->to_supports_non_stop)
2a9a2795 2707 return (t->to_supports_non_stop) (t);
9908b566
VP
2708 return 0;
2709}
2710
2711int
2c0b251b 2712target_supports_non_stop (void)
9908b566
VP
2713{
2714 struct target_ops *t;
5d502164 2715
9908b566
VP
2716 for (t = &current_target; t != NULL; t = t->beneath)
2717 if (t->to_supports_non_stop)
2a9a2795 2718 return t->to_supports_non_stop (t);
9908b566
VP
2719
2720 return 0;
2721}
2722
145b16a9
UW
2723/* Implement the "info proc" command. */
2724
451b7c33 2725int
145b16a9
UW
2726target_info_proc (char *args, enum info_proc_what what)
2727{
2728 struct target_ops *t;
2729
2730 /* If we're already connected to something that can get us OS
2731 related data, use it. Otherwise, try using the native
2732 target. */
2733 if (current_target.to_stratum >= process_stratum)
2734 t = current_target.beneath;
2735 else
2736 t = find_default_run_target (NULL);
2737
2738 for (; t != NULL; t = t->beneath)
2739 {
2740 if (t->to_info_proc != NULL)
2741 {
2742 t->to_info_proc (t, args, what);
2743
2744 if (targetdebug)
2745 fprintf_unfiltered (gdb_stdlog,
2746 "target_info_proc (\"%s\", %d)\n", args, what);
2747
451b7c33 2748 return 1;
145b16a9
UW
2749 }
2750 }
2751
451b7c33 2752 return 0;
145b16a9
UW
2753}
2754
03583c20 2755static int
2bfc0540 2756find_default_supports_disable_randomization (struct target_ops *self)
03583c20
UW
2757{
2758 struct target_ops *t;
2759
2760 t = find_default_run_target (NULL);
2761 if (t && t->to_supports_disable_randomization)
2bfc0540 2762 return (t->to_supports_disable_randomization) (t);
03583c20
UW
2763 return 0;
2764}
2765
2766int
2767target_supports_disable_randomization (void)
2768{
2769 struct target_ops *t;
2770
2771 for (t = &current_target; t != NULL; t = t->beneath)
2772 if (t->to_supports_disable_randomization)
2bfc0540 2773 return t->to_supports_disable_randomization (t);
03583c20
UW
2774
2775 return 0;
2776}
9908b566 2777
07e059b5
VP
2778char *
2779target_get_osdata (const char *type)
2780{
07e059b5
VP
2781 struct target_ops *t;
2782
739ef7fb
PA
2783 /* If we're already connected to something that can get us OS
2784 related data, use it. Otherwise, try using the native
2785 target. */
2786 if (current_target.to_stratum >= process_stratum)
6d097e65 2787 t = current_target.beneath;
739ef7fb
PA
2788 else
2789 t = find_default_run_target ("get OS data");
07e059b5
VP
2790
2791 if (!t)
2792 return NULL;
2793
6d097e65 2794 return target_read_stralloc (t, TARGET_OBJECT_OSDATA, type);
07e059b5
VP
2795}
2796
6c95b8df
PA
2797/* Determine the current address space of thread PTID. */
2798
2799struct address_space *
2800target_thread_address_space (ptid_t ptid)
2801{
c0694254 2802 struct address_space *aspace;
6c95b8df 2803 struct inferior *inf;
c0694254
PA
2804 struct target_ops *t;
2805
2806 for (t = current_target.beneath; t != NULL; t = t->beneath)
2807 {
2808 if (t->to_thread_address_space != NULL)
2809 {
2810 aspace = t->to_thread_address_space (t, ptid);
2811 gdb_assert (aspace);
6c95b8df 2812
c0694254
PA
2813 if (targetdebug)
2814 fprintf_unfiltered (gdb_stdlog,
2815 "target_thread_address_space (%s) = %d\n",
2816 target_pid_to_str (ptid),
2817 address_space_num (aspace));
2818 return aspace;
2819 }
2820 }
6c95b8df
PA
2821
2822 /* Fall-back to the "main" address space of the inferior. */
2823 inf = find_inferior_pid (ptid_get_pid (ptid));
2824
2825 if (inf == NULL || inf->aspace == NULL)
3e43a32a 2826 internal_error (__FILE__, __LINE__,
9b20d036
MS
2827 _("Can't determine the current "
2828 "address space of thread %s\n"),
6c95b8df
PA
2829 target_pid_to_str (ptid));
2830
2831 return inf->aspace;
2832}
2833
7313baad
UW
2834
2835/* Target file operations. */
2836
2837static struct target_ops *
2838default_fileio_target (void)
2839{
2840 /* If we're already connected to something that can perform
2841 file I/O, use it. Otherwise, try using the native target. */
2842 if (current_target.to_stratum >= process_stratum)
2843 return current_target.beneath;
2844 else
2845 return find_default_run_target ("file I/O");
2846}
2847
2848/* Open FILENAME on the target, using FLAGS and MODE. Return a
2849 target file descriptor, or -1 if an error occurs (and set
2850 *TARGET_ERRNO). */
2851int
2852target_fileio_open (const char *filename, int flags, int mode,
2853 int *target_errno)
2854{
2855 struct target_ops *t;
2856
2857 for (t = default_fileio_target (); t != NULL; t = t->beneath)
2858 {
2859 if (t->to_fileio_open != NULL)
2860 {
cd897586 2861 int fd = t->to_fileio_open (t, filename, flags, mode, target_errno);
7313baad
UW
2862
2863 if (targetdebug)
2864 fprintf_unfiltered (gdb_stdlog,
2865 "target_fileio_open (%s,0x%x,0%o) = %d (%d)\n",
2866 filename, flags, mode,
2867 fd, fd != -1 ? 0 : *target_errno);
2868 return fd;
2869 }
2870 }
2871
2872 *target_errno = FILEIO_ENOSYS;
2873 return -1;
2874}
2875
2876/* Write up to LEN bytes from WRITE_BUF to FD on the target.
2877 Return the number of bytes written, or -1 if an error occurs
2878 (and set *TARGET_ERRNO). */
2879int
2880target_fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
2881 ULONGEST offset, int *target_errno)
2882{
2883 struct target_ops *t;
2884
2885 for (t = default_fileio_target (); t != NULL; t = t->beneath)
2886 {
2887 if (t->to_fileio_pwrite != NULL)
2888 {
0d866f62 2889 int ret = t->to_fileio_pwrite (t, fd, write_buf, len, offset,
7313baad
UW
2890 target_errno);
2891
2892 if (targetdebug)
2893 fprintf_unfiltered (gdb_stdlog,
a71b5a38 2894 "target_fileio_pwrite (%d,...,%d,%s) "
7313baad 2895 "= %d (%d)\n",
a71b5a38 2896 fd, len, pulongest (offset),
7313baad
UW
2897 ret, ret != -1 ? 0 : *target_errno);
2898 return ret;
2899 }
2900 }
2901
2902 *target_errno = FILEIO_ENOSYS;
2903 return -1;
2904}
2905
2906/* Read up to LEN bytes FD on the target into READ_BUF.
2907 Return the number of bytes read, or -1 if an error occurs
2908 (and set *TARGET_ERRNO). */
2909int
2910target_fileio_pread (int fd, gdb_byte *read_buf, int len,
2911 ULONGEST offset, int *target_errno)
2912{
2913 struct target_ops *t;
2914
2915 for (t = default_fileio_target (); t != NULL; t = t->beneath)
2916 {
2917 if (t->to_fileio_pread != NULL)
2918 {
a3be983c 2919 int ret = t->to_fileio_pread (t, fd, read_buf, len, offset,
7313baad
UW
2920 target_errno);
2921
2922 if (targetdebug)
2923 fprintf_unfiltered (gdb_stdlog,
a71b5a38 2924 "target_fileio_pread (%d,...,%d,%s) "
7313baad 2925 "= %d (%d)\n",
a71b5a38 2926 fd, len, pulongest (offset),
7313baad
UW
2927 ret, ret != -1 ? 0 : *target_errno);
2928 return ret;
2929 }
2930 }
2931
2932 *target_errno = FILEIO_ENOSYS;
2933 return -1;
2934}
2935
2936/* Close FD on the target. Return 0, or -1 if an error occurs
2937 (and set *TARGET_ERRNO). */
2938int
2939target_fileio_close (int fd, int *target_errno)
2940{
2941 struct target_ops *t;
2942
2943 for (t = default_fileio_target (); t != NULL; t = t->beneath)
2944 {
2945 if (t->to_fileio_close != NULL)
2946 {
df39ea25 2947 int ret = t->to_fileio_close (t, fd, target_errno);
7313baad
UW
2948
2949 if (targetdebug)
2950 fprintf_unfiltered (gdb_stdlog,
2951 "target_fileio_close (%d) = %d (%d)\n",
2952 fd, ret, ret != -1 ? 0 : *target_errno);
2953 return ret;
2954 }
2955 }
2956
2957 *target_errno = FILEIO_ENOSYS;
2958 return -1;
2959}
2960
2961/* Unlink FILENAME on the target. Return 0, or -1 if an error
2962 occurs (and set *TARGET_ERRNO). */
2963int
2964target_fileio_unlink (const char *filename, int *target_errno)
2965{
2966 struct target_ops *t;
2967
2968 for (t = default_fileio_target (); t != NULL; t = t->beneath)
2969 {
2970 if (t->to_fileio_unlink != NULL)
2971 {
dbbca37d 2972 int ret = t->to_fileio_unlink (t, filename, target_errno);
7313baad
UW
2973
2974 if (targetdebug)
2975 fprintf_unfiltered (gdb_stdlog,
2976 "target_fileio_unlink (%s) = %d (%d)\n",
2977 filename, ret, ret != -1 ? 0 : *target_errno);
2978 return ret;
2979 }
2980 }
2981
2982 *target_errno = FILEIO_ENOSYS;
2983 return -1;
2984}
2985
b9e7b9c3
UW
2986/* Read value of symbolic link FILENAME on the target. Return a
2987 null-terminated string allocated via xmalloc, or NULL if an error
2988 occurs (and set *TARGET_ERRNO). */
2989char *
2990target_fileio_readlink (const char *filename, int *target_errno)
2991{
2992 struct target_ops *t;
2993
2994 for (t = default_fileio_target (); t != NULL; t = t->beneath)
2995 {
2996 if (t->to_fileio_readlink != NULL)
2997 {
fab5aa7c 2998 char *ret = t->to_fileio_readlink (t, filename, target_errno);
b9e7b9c3
UW
2999
3000 if (targetdebug)
3001 fprintf_unfiltered (gdb_stdlog,
3002 "target_fileio_readlink (%s) = %s (%d)\n",
3003 filename, ret? ret : "(nil)",
3004 ret? 0 : *target_errno);
3005 return ret;
3006 }
3007 }
3008
3009 *target_errno = FILEIO_ENOSYS;
3010 return NULL;
3011}
3012
7313baad
UW
3013static void
3014target_fileio_close_cleanup (void *opaque)
3015{
3016 int fd = *(int *) opaque;
3017 int target_errno;
3018
3019 target_fileio_close (fd, &target_errno);
3020}
3021
3022/* Read target file FILENAME. Store the result in *BUF_P and
3023 return the size of the transferred data. PADDING additional bytes are
3024 available in *BUF_P. This is a helper function for
3025 target_fileio_read_alloc; see the declaration of that function for more
3026 information. */
3027
3028static LONGEST
3029target_fileio_read_alloc_1 (const char *filename,
3030 gdb_byte **buf_p, int padding)
3031{
3032 struct cleanup *close_cleanup;
3033 size_t buf_alloc, buf_pos;
3034 gdb_byte *buf;
3035 LONGEST n;
3036 int fd;
3037 int target_errno;
3038
3039 fd = target_fileio_open (filename, FILEIO_O_RDONLY, 0700, &target_errno);
3040 if (fd == -1)
3041 return -1;
3042
3043 close_cleanup = make_cleanup (target_fileio_close_cleanup, &fd);
3044
3045 /* Start by reading up to 4K at a time. The target will throttle
3046 this number down if necessary. */
3047 buf_alloc = 4096;
3048 buf = xmalloc (buf_alloc);
3049 buf_pos = 0;
3050 while (1)
3051 {
3052 n = target_fileio_pread (fd, &buf[buf_pos],
3053 buf_alloc - buf_pos - padding, buf_pos,
3054 &target_errno);
3055 if (n < 0)
3056 {
3057 /* An error occurred. */
3058 do_cleanups (close_cleanup);
3059 xfree (buf);
3060 return -1;
3061 }
3062 else if (n == 0)
3063 {
3064 /* Read all there was. */
3065 do_cleanups (close_cleanup);
3066 if (buf_pos == 0)
3067 xfree (buf);
3068 else
3069 *buf_p = buf;
3070 return buf_pos;
3071 }
3072
3073 buf_pos += n;
3074
3075 /* If the buffer is filling up, expand it. */
3076 if (buf_alloc < buf_pos * 2)
3077 {
3078 buf_alloc *= 2;
3079 buf = xrealloc (buf, buf_alloc);
3080 }
3081
3082 QUIT;
3083 }
3084}
3085
3086/* Read target file FILENAME. Store the result in *BUF_P and return
3087 the size of the transferred data. See the declaration in "target.h"
3088 function for more information about the return value. */
3089
3090LONGEST
3091target_fileio_read_alloc (const char *filename, gdb_byte **buf_p)
3092{
3093 return target_fileio_read_alloc_1 (filename, buf_p, 0);
3094}
3095
3096/* Read target file FILENAME. The result is NUL-terminated and
3097 returned as a string, allocated using xmalloc. If an error occurs
3098 or the transfer is unsupported, NULL is returned. Empty objects
3099 are returned as allocated but empty strings. A warning is issued
3100 if the result contains any embedded NUL bytes. */
3101
3102char *
3103target_fileio_read_stralloc (const char *filename)
3104{
39086a0e
PA
3105 gdb_byte *buffer;
3106 char *bufstr;
7313baad
UW
3107 LONGEST i, transferred;
3108
39086a0e
PA
3109 transferred = target_fileio_read_alloc_1 (filename, &buffer, 1);
3110 bufstr = (char *) buffer;
7313baad
UW
3111
3112 if (transferred < 0)
3113 return NULL;
3114
3115 if (transferred == 0)
3116 return xstrdup ("");
3117
39086a0e 3118 bufstr[transferred] = 0;
7313baad
UW
3119
3120 /* Check for embedded NUL bytes; but allow trailing NULs. */
39086a0e
PA
3121 for (i = strlen (bufstr); i < transferred; i++)
3122 if (bufstr[i] != 0)
7313baad
UW
3123 {
3124 warning (_("target file %s "
3125 "contained unexpected null characters"),
3126 filename);
3127 break;
3128 }
3129
39086a0e 3130 return bufstr;
7313baad
UW
3131}
3132
3133
e0d24f8d 3134static int
31568a15
TT
3135default_region_ok_for_hw_watchpoint (struct target_ops *self,
3136 CORE_ADDR addr, int len)
e0d24f8d 3137{
f5656ead 3138 return (len <= gdbarch_ptr_bit (target_gdbarch ()) / TARGET_CHAR_BIT);
ccaa32c7
GS
3139}
3140
5009afc5
AS
3141static int
3142default_watchpoint_addr_within_range (struct target_ops *target,
3143 CORE_ADDR addr,
3144 CORE_ADDR start, int length)
3145{
3146 return addr >= start && addr < start + length;
3147}
3148
c2250ad1
UW
3149static struct gdbarch *
3150default_thread_architecture (struct target_ops *ops, ptid_t ptid)
3151{
f5656ead 3152 return target_gdbarch ();
c2250ad1
UW
3153}
3154
c906108c 3155static int
555bbdeb
TT
3156return_zero (struct target_ops *ignore)
3157{
3158 return 0;
3159}
3160
3161static int
3162return_zero_has_execution (struct target_ops *ignore, ptid_t ignore2)
c906108c
SS
3163{
3164 return 0;
3165}
3166
ed9a39eb
JM
3167/*
3168 * Find the next target down the stack from the specified target.
3169 */
3170
3171struct target_ops *
fba45db2 3172find_target_beneath (struct target_ops *t)
ed9a39eb 3173{
258b763a 3174 return t->beneath;
ed9a39eb
JM
3175}
3176
8b06beed
TT
3177/* See target.h. */
3178
3179struct target_ops *
3180find_target_at (enum strata stratum)
3181{
3182 struct target_ops *t;
3183
3184 for (t = current_target.beneath; t != NULL; t = t->beneath)
3185 if (t->to_stratum == stratum)
3186 return t;
3187
3188 return NULL;
3189}
3190
c906108c
SS
3191\f
3192/* The inferior process has died. Long live the inferior! */
3193
3194void
fba45db2 3195generic_mourn_inferior (void)
c906108c 3196{
7f9f62ba 3197 ptid_t ptid;
c906108c 3198
7f9f62ba 3199 ptid = inferior_ptid;
39f77062 3200 inferior_ptid = null_ptid;
7f9f62ba 3201
f59f708a
PA
3202 /* Mark breakpoints uninserted in case something tries to delete a
3203 breakpoint while we delete the inferior's threads (which would
3204 fail, since the inferior is long gone). */
3205 mark_breakpoints_out ();
3206
7f9f62ba
PA
3207 if (!ptid_equal (ptid, null_ptid))
3208 {
3209 int pid = ptid_get_pid (ptid);
6c95b8df 3210 exit_inferior (pid);
7f9f62ba
PA
3211 }
3212
f59f708a
PA
3213 /* Note this wipes step-resume breakpoints, so needs to be done
3214 after exit_inferior, which ends up referencing the step-resume
3215 breakpoints through clear_thread_inferior_resources. */
c906108c 3216 breakpoint_init_inferior (inf_exited);
f59f708a 3217
c906108c
SS
3218 registers_changed ();
3219
c906108c
SS
3220 reopen_exec_file ();
3221 reinit_frame_cache ();
3222
9a4105ab
AC
3223 if (deprecated_detach_hook)
3224 deprecated_detach_hook ();
c906108c
SS
3225}
3226\f
fd0a2a6f
MK
3227/* Convert a normal process ID to a string. Returns the string in a
3228 static buffer. */
c906108c
SS
3229
3230char *
39f77062 3231normal_pid_to_str (ptid_t ptid)
c906108c 3232{
fd0a2a6f 3233 static char buf[32];
c906108c 3234
5fff8fc0 3235 xsnprintf (buf, sizeof buf, "process %d", ptid_get_pid (ptid));
c906108c
SS
3236 return buf;
3237}
3238
2c0b251b 3239static char *
770234d3 3240default_pid_to_str (struct target_ops *ops, ptid_t ptid)
117de6a9
PA
3241{
3242 return normal_pid_to_str (ptid);
3243}
3244
9b4eba8e
HZ
3245/* Error-catcher for target_find_memory_regions. */
3246static int
2e73927c
TT
3247dummy_find_memory_regions (struct target_ops *self,
3248 find_memory_region_ftype ignore1, void *ignore2)
be4d1333 3249{
9b4eba8e 3250 error (_("Command not implemented for this target."));
be4d1333
MS
3251 return 0;
3252}
3253
9b4eba8e
HZ
3254/* Error-catcher for target_make_corefile_notes. */
3255static char *
fc6691b2
TT
3256dummy_make_corefile_notes (struct target_ops *self,
3257 bfd *ignore1, int *ignore2)
be4d1333 3258{
9b4eba8e 3259 error (_("Command not implemented for this target."));
be4d1333
MS
3260 return NULL;
3261}
3262
c906108c
SS
3263/* Set up the handful of non-empty slots needed by the dummy target
3264 vector. */
3265
3266static void
fba45db2 3267init_dummy_target (void)
c906108c
SS
3268{
3269 dummy_target.to_shortname = "None";
3270 dummy_target.to_longname = "None";
3271 dummy_target.to_doc = "";
c906108c 3272 dummy_target.to_create_inferior = find_default_create_inferior;
9908b566 3273 dummy_target.to_supports_non_stop = find_default_supports_non_stop;
03583c20
UW
3274 dummy_target.to_supports_disable_randomization
3275 = find_default_supports_disable_randomization;
c906108c 3276 dummy_target.to_stratum = dummy_stratum;
555bbdeb
TT
3277 dummy_target.to_has_all_memory = return_zero;
3278 dummy_target.to_has_memory = return_zero;
3279 dummy_target.to_has_stack = return_zero;
3280 dummy_target.to_has_registers = return_zero;
3281 dummy_target.to_has_execution = return_zero_has_execution;
c906108c 3282 dummy_target.to_magic = OPS_MAGIC;
1101cb7b
TT
3283
3284 install_dummy_methods (&dummy_target);
c906108c 3285}
c906108c 3286\f
c906108c 3287static void
fba45db2 3288debug_to_open (char *args, int from_tty)
c906108c
SS
3289{
3290 debug_target.to_open (args, from_tty);
3291
96baa820 3292 fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty);
c906108c
SS
3293}
3294
f1c07ab0 3295void
460014f5 3296target_close (struct target_ops *targ)
f1c07ab0 3297{
7fdc1521
TT
3298 gdb_assert (!target_is_pushed (targ));
3299
f1c07ab0 3300 if (targ->to_xclose != NULL)
460014f5 3301 targ->to_xclose (targ);
f1c07ab0 3302 else if (targ->to_close != NULL)
de90e03d 3303 targ->to_close (targ);
947b8855
PA
3304
3305 if (targetdebug)
460014f5 3306 fprintf_unfiltered (gdb_stdlog, "target_close ()\n");
f1c07ab0
AC
3307}
3308
136d6dae
VP
3309void
3310target_attach (char *args, int from_tty)
3311{
e9a29200
TT
3312 current_target.to_attach (&current_target, args, from_tty);
3313 if (targetdebug)
3314 fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n",
3315 args, from_tty);
136d6dae
VP
3316}
3317
28439f5e
PA
3318int
3319target_thread_alive (ptid_t ptid)
c906108c 3320{
cbffc065 3321 int retval;
28439f5e 3322
cbffc065
TT
3323 retval = current_target.to_thread_alive (&current_target, ptid);
3324 if (targetdebug)
3325 fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n",
3326 ptid_get_pid (ptid), retval);
28439f5e 3327
cbffc065 3328 return retval;
28439f5e
PA
3329}
3330
3331void
3332target_find_new_threads (void)
3333{
09b0dc2b
TT
3334 current_target.to_find_new_threads (&current_target);
3335 if (targetdebug)
3336 fprintf_unfiltered (gdb_stdlog, "target_find_new_threads ()\n");
c906108c
SS
3337}
3338
d914c394
SS
3339void
3340target_stop (ptid_t ptid)
3341{
3342 if (!may_stop)
3343 {
3344 warning (_("May not interrupt or stop the target, ignoring attempt"));
3345 return;
3346 }
3347
1eab8a48 3348 (*current_target.to_stop) (&current_target, ptid);
d914c394
SS
3349}
3350
c906108c 3351static void
f045800c 3352debug_to_post_attach (struct target_ops *self, int pid)
c906108c 3353{
f045800c 3354 debug_target.to_post_attach (&debug_target, pid);
c906108c 3355
28439f5e 3356 fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid);
c906108c
SS
3357}
3358
09826ec5
PA
3359/* Concatenate ELEM to LIST, a comma separate list, and return the
3360 result. The LIST incoming argument is released. */
3361
3362static char *
3363str_comma_list_concat_elem (char *list, const char *elem)
3364{
3365 if (list == NULL)
3366 return xstrdup (elem);
3367 else
3368 return reconcat (list, list, ", ", elem, (char *) NULL);
3369}
3370
3371/* Helper for target_options_to_string. If OPT is present in
3372 TARGET_OPTIONS, append the OPT_STR (string version of OPT) in RET.
3373 Returns the new resulting string. OPT is removed from
3374 TARGET_OPTIONS. */
3375
3376static char *
3377do_option (int *target_options, char *ret,
3378 int opt, char *opt_str)
3379{
3380 if ((*target_options & opt) != 0)
3381 {
3382 ret = str_comma_list_concat_elem (ret, opt_str);
3383 *target_options &= ~opt;
3384 }
3385
3386 return ret;
3387}
3388
3389char *
3390target_options_to_string (int target_options)
3391{
3392 char *ret = NULL;
3393
3394#define DO_TARG_OPTION(OPT) \
3395 ret = do_option (&target_options, ret, OPT, #OPT)
3396
3397 DO_TARG_OPTION (TARGET_WNOHANG);
3398
3399 if (target_options != 0)
3400 ret = str_comma_list_concat_elem (ret, "unknown???");
3401
3402 if (ret == NULL)
3403 ret = xstrdup ("");
3404 return ret;
3405}
3406
bf0c5130 3407static void
56be3814
UW
3408debug_print_register (const char * func,
3409 struct regcache *regcache, int regno)
bf0c5130 3410{
f8d29908 3411 struct gdbarch *gdbarch = get_regcache_arch (regcache);
5d502164 3412
bf0c5130 3413 fprintf_unfiltered (gdb_stdlog, "%s ", func);
f8d29908 3414 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)
f8d29908
UW
3415 && gdbarch_register_name (gdbarch, regno) != NULL
3416 && gdbarch_register_name (gdbarch, regno)[0] != '\0')
3417 fprintf_unfiltered (gdb_stdlog, "(%s)",
3418 gdbarch_register_name (gdbarch, regno));
bf0c5130
AC
3419 else
3420 fprintf_unfiltered (gdb_stdlog, "(%d)", regno);
0ff58721 3421 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch))
bf0c5130 3422 {
e17a4113 3423 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
f8d29908 3424 int i, size = register_size (gdbarch, regno);
e362b510 3425 gdb_byte buf[MAX_REGISTER_SIZE];
5d502164 3426
0ff58721 3427 regcache_raw_collect (regcache, regno, buf);
bf0c5130 3428 fprintf_unfiltered (gdb_stdlog, " = ");
81c4a259 3429 for (i = 0; i < size; i++)
bf0c5130
AC
3430 {
3431 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
3432 }
81c4a259 3433 if (size <= sizeof (LONGEST))
bf0c5130 3434 {
e17a4113 3435 ULONGEST val = extract_unsigned_integer (buf, size, byte_order);
5d502164 3436
0b1553bc
UW
3437 fprintf_unfiltered (gdb_stdlog, " %s %s",
3438 core_addr_to_string_nz (val), plongest (val));
bf0c5130
AC
3439 }
3440 }
3441 fprintf_unfiltered (gdb_stdlog, "\n");
3442}
3443
28439f5e
PA
3444void
3445target_fetch_registers (struct regcache *regcache, int regno)
c906108c 3446{
ad5989bd
TT
3447 current_target.to_fetch_registers (&current_target, regcache, regno);
3448 if (targetdebug)
3449 debug_print_register ("target_fetch_registers", regcache, regno);
c906108c
SS
3450}
3451
28439f5e
PA
3452void
3453target_store_registers (struct regcache *regcache, int regno)
c906108c 3454{
28439f5e 3455 struct target_ops *t;
5d502164 3456
d914c394
SS
3457 if (!may_write_registers)
3458 error (_("Writing to registers is not allowed (regno %d)"), regno);
3459
6b84065d
TT
3460 current_target.to_store_registers (&current_target, regcache, regno);
3461 if (targetdebug)
28439f5e 3462 {
6b84065d 3463 debug_print_register ("target_store_registers", regcache, regno);
28439f5e 3464 }
c906108c
SS
3465}
3466
dc146f7c
VP
3467int
3468target_core_of_thread (ptid_t ptid)
3469{
9e538d0d 3470 int retval = current_target.to_core_of_thread (&current_target, ptid);
dc146f7c 3471
9e538d0d
TT
3472 if (targetdebug)
3473 fprintf_unfiltered (gdb_stdlog,
3474 "target_core_of_thread (%d) = %d\n",
3475 ptid_get_pid (ptid), retval);
3476 return retval;
dc146f7c
VP
3477}
3478
4a5e7a5b
PA
3479int
3480target_verify_memory (const gdb_byte *data, CORE_ADDR memaddr, ULONGEST size)
3481{
eb276a6b
TT
3482 int retval = current_target.to_verify_memory (&current_target,
3483 data, memaddr, size);
5d502164 3484
eb276a6b
TT
3485 if (targetdebug)
3486 fprintf_unfiltered (gdb_stdlog,
3487 "target_verify_memory (%s, %s) = %d\n",
3488 paddress (target_gdbarch (), memaddr),
3489 pulongest (size),
3490 retval);
3491 return retval;
4a5e7a5b
PA
3492}
3493
9c06b0b4
TJB
3494/* The documentation for this function is in its prototype declaration in
3495 target.h. */
3496
3497int
3498target_insert_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask, int rw)
3499{
cd4ae029 3500 int ret;
9c06b0b4 3501
cd4ae029
TT
3502 ret = current_target.to_insert_mask_watchpoint (&current_target,
3503 addr, mask, rw);
9c06b0b4 3504
cd4ae029
TT
3505 if (targetdebug)
3506 fprintf_unfiltered (gdb_stdlog, "\
9c06b0b4 3507target_insert_mask_watchpoint (%s, %s, %d) = %d\n",
cd4ae029
TT
3508 core_addr_to_string (addr),
3509 core_addr_to_string (mask), rw, ret);
3510
3511 return ret;
9c06b0b4
TJB
3512}
3513
3514/* The documentation for this function is in its prototype declaration in
3515 target.h. */
3516
3517int
3518target_remove_mask_watchpoint (CORE_ADDR addr, CORE_ADDR mask, int rw)
3519{
8b1c364c 3520 int ret;
9c06b0b4 3521
8b1c364c
TT
3522 ret = current_target.to_remove_mask_watchpoint (&current_target,
3523 addr, mask, rw);
9c06b0b4 3524
8b1c364c
TT
3525 if (targetdebug)
3526 fprintf_unfiltered (gdb_stdlog, "\
9c06b0b4 3527target_remove_mask_watchpoint (%s, %s, %d) = %d\n",
8b1c364c
TT
3528 core_addr_to_string (addr),
3529 core_addr_to_string (mask), rw, ret);
9c06b0b4 3530
8b1c364c 3531 return ret;
9c06b0b4
TJB
3532}
3533
3534/* The documentation for this function is in its prototype declaration
3535 in target.h. */
3536
3537int
3538target_masked_watch_num_registers (CORE_ADDR addr, CORE_ADDR mask)
3539{
6c7e5e5c
TT
3540 return current_target.to_masked_watch_num_registers (&current_target,
3541 addr, mask);
9c06b0b4
TJB
3542}
3543
f1310107
TJB
3544/* The documentation for this function is in its prototype declaration
3545 in target.h. */
3546
3547int
3548target_ranged_break_num_registers (void)
3549{
a134316b 3550 return current_target.to_ranged_break_num_registers (&current_target);
f1310107
TJB
3551}
3552
02d27625
MM
3553/* See target.h. */
3554
02d27625
MM
3555struct btrace_target_info *
3556target_enable_btrace (ptid_t ptid)
3557{
6dc7fcf4 3558 return current_target.to_enable_btrace (&current_target, ptid);
02d27625
MM
3559}
3560
3561/* See target.h. */
3562
3563void
3564target_disable_btrace (struct btrace_target_info *btinfo)
3565{
8dc292d3 3566 current_target.to_disable_btrace (&current_target, btinfo);
02d27625
MM
3567}
3568
3569/* See target.h. */
3570
3571void
3572target_teardown_btrace (struct btrace_target_info *btinfo)
3573{
9ace480d 3574 current_target.to_teardown_btrace (&current_target, btinfo);
02d27625
MM
3575}
3576
3577/* See target.h. */
3578
969c39fb
MM
3579enum btrace_error
3580target_read_btrace (VEC (btrace_block_s) **btrace,
3581 struct btrace_target_info *btinfo,
02d27625
MM
3582 enum btrace_read_type type)
3583{
eb5b20d4 3584 return current_target.to_read_btrace (&current_target, btrace, btinfo, type);
02d27625
MM
3585}
3586
d02ed0bb
MM
3587/* See target.h. */
3588
7c1687a9
MM
3589void
3590target_stop_recording (void)
3591{
ee97f592 3592 current_target.to_stop_recording (&current_target);
7c1687a9
MM
3593}
3594
3595/* See target.h. */
3596
d02ed0bb
MM
3597void
3598target_info_record (void)
3599{
3600 struct target_ops *t;
3601
3602 for (t = current_target.beneath; t != NULL; t = t->beneath)
3603 if (t->to_info_record != NULL)
3604 {
630d6a4a 3605 t->to_info_record (t);
d02ed0bb
MM
3606 return;
3607 }
3608
3609 tcomplain ();
3610}
3611
3612/* See target.h. */
3613
3614void
85e1311a 3615target_save_record (const char *filename)
d02ed0bb 3616{
f09e2107 3617 current_target.to_save_record (&current_target, filename);
d02ed0bb
MM
3618}
3619
3620/* See target.h. */
3621
3622int
3623target_supports_delete_record (void)
3624{
3625 struct target_ops *t;
3626
3627 for (t = current_target.beneath; t != NULL; t = t->beneath)
3628 if (t->to_delete_record != NULL)
3629 return 1;
3630
3631 return 0;
3632}
3633
3634/* See target.h. */
3635
3636void
3637target_delete_record (void)
3638{
07366925 3639 current_target.to_delete_record (&current_target);
d02ed0bb
MM
3640}
3641
3642/* See target.h. */
3643
3644int
3645target_record_is_replaying (void)
3646{
dd2e9d25 3647 return current_target.to_record_is_replaying (&current_target);
d02ed0bb
MM
3648}
3649
3650/* See target.h. */
3651
3652void
3653target_goto_record_begin (void)
3654{
671e76cc 3655 current_target.to_goto_record_begin (&current_target);
d02ed0bb
MM
3656}
3657
3658/* See target.h. */
3659
3660void
3661target_goto_record_end (void)
3662{
e9179bb3 3663 current_target.to_goto_record_end (&current_target);
d02ed0bb
MM
3664}
3665
3666/* See target.h. */
3667
3668void
3669target_goto_record (ULONGEST insn)
3670{
05969c84 3671 current_target.to_goto_record (&current_target, insn);
d02ed0bb
MM
3672}
3673
67c86d06
MM
3674/* See target.h. */
3675
3676void
3677target_insn_history (int size, int flags)
3678{
3679abfa 3679 current_target.to_insn_history (&current_target, size, flags);
67c86d06
MM
3680}
3681
3682/* See target.h. */
3683
3684void
3685target_insn_history_from (ULONGEST from, int size, int flags)
3686{
8444ab58 3687 current_target.to_insn_history_from (&current_target, from, size, flags);
67c86d06
MM
3688}
3689
3690/* See target.h. */
3691
3692void
3693target_insn_history_range (ULONGEST begin, ULONGEST end, int flags)
3694{
c29302cc 3695 current_target.to_insn_history_range (&current_target, begin, end, flags);
67c86d06
MM
3696}
3697
15984c13
MM
3698/* See target.h. */
3699
3700void
3701target_call_history (int size, int flags)
3702{
170049d4 3703 current_target.to_call_history (&current_target, size, flags);
15984c13
MM
3704}
3705
3706/* See target.h. */
3707
3708void
3709target_call_history_from (ULONGEST begin, int size, int flags)
3710{
16fc27d6 3711 current_target.to_call_history_from (&current_target, begin, size, flags);
15984c13
MM
3712}
3713
3714/* See target.h. */
3715
3716void
3717target_call_history_range (ULONGEST begin, ULONGEST end, int flags)
3718{
115d9817 3719 current_target.to_call_history_range (&current_target, begin, end, flags);
15984c13
MM
3720}
3721
c906108c 3722static void
f32dbf8c 3723debug_to_prepare_to_store (struct target_ops *self, struct regcache *regcache)
c906108c 3724{
f32dbf8c 3725 debug_target.to_prepare_to_store (&debug_target, regcache);
c906108c 3726
96baa820 3727 fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n");
c906108c
SS
3728}
3729
ea001bdc
MM
3730/* See target.h. */
3731
3732const struct frame_unwind *
3733target_get_unwinder (void)
3734{
ac01945b 3735 return current_target.to_get_unwinder (&current_target);
ea001bdc
MM
3736}
3737
3738/* See target.h. */
3739
3740const struct frame_unwind *
3741target_get_tailcall_unwinder (void)
3742{
ac01945b 3743 return current_target.to_get_tailcall_unwinder (&current_target);
ea001bdc
MM
3744}
3745
c0eca49f 3746/* Default implementation of to_decr_pc_after_break. */
118e6252 3747
c0eca49f
TT
3748static CORE_ADDR
3749default_target_decr_pc_after_break (struct target_ops *ops,
118e6252
MM
3750 struct gdbarch *gdbarch)
3751{
118e6252
MM
3752 return gdbarch_decr_pc_after_break (gdbarch);
3753}
3754
3755/* See target.h. */
3756
3757CORE_ADDR
3758target_decr_pc_after_break (struct gdbarch *gdbarch)
3759{
c0eca49f 3760 return current_target.to_decr_pc_after_break (&current_target, gdbarch);
118e6252
MM
3761}
3762
c906108c 3763static void
fba45db2 3764debug_to_files_info (struct target_ops *target)
c906108c
SS
3765{
3766 debug_target.to_files_info (target);
3767
96baa820 3768 fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n");
c906108c
SS
3769}
3770
3771static int
3db08215 3772debug_to_insert_breakpoint (struct target_ops *ops, struct gdbarch *gdbarch,
a6d9a66e 3773 struct bp_target_info *bp_tgt)
c906108c
SS
3774{
3775 int retval;
3776
6b84065d 3777 retval = debug_target.to_insert_breakpoint (&debug_target, gdbarch, bp_tgt);
c906108c 3778
96baa820 3779 fprintf_unfiltered (gdb_stdlog,
bd91e7ae
OS
3780 "target_insert_breakpoint (%s, xxx) = %ld\n",
3781 core_addr_to_string (bp_tgt->placed_address),
104c1213 3782 (unsigned long) retval);
c906108c
SS
3783 return retval;
3784}
3785
3786static int
3db08215 3787debug_to_remove_breakpoint (struct target_ops *ops, struct gdbarch *gdbarch,
a6d9a66e 3788 struct bp_target_info *bp_tgt)
c906108c
SS
3789{
3790 int retval;
3791
6b84065d 3792 retval = debug_target.to_remove_breakpoint (&debug_target, gdbarch, bp_tgt);
c906108c 3793
96baa820 3794 fprintf_unfiltered (gdb_stdlog,
bd91e7ae
OS
3795 "target_remove_breakpoint (%s, xxx) = %ld\n",
3796 core_addr_to_string (bp_tgt->placed_address),
104c1213 3797 (unsigned long) retval);
c906108c
SS
3798 return retval;
3799}
3800
ccaa32c7 3801static int
5461485a
TT
3802debug_to_can_use_hw_breakpoint (struct target_ops *self,
3803 int type, int cnt, int from_tty)
ccaa32c7
GS
3804{
3805 int retval;
3806
5461485a
TT
3807 retval = debug_target.to_can_use_hw_breakpoint (&debug_target,
3808 type, cnt, from_tty);
ccaa32c7
GS
3809
3810 fprintf_unfiltered (gdb_stdlog,
3811 "target_can_use_hw_breakpoint (%ld, %ld, %ld) = %ld\n",
3812 (unsigned long) type,
3813 (unsigned long) cnt,
3814 (unsigned long) from_tty,
3815 (unsigned long) retval);
3816 return retval;
3817}
3818
e0d24f8d 3819static int
31568a15
TT
3820debug_to_region_ok_for_hw_watchpoint (struct target_ops *self,
3821 CORE_ADDR addr, int len)
e0d24f8d
WZ
3822{
3823 CORE_ADDR retval;
3824
31568a15
TT
3825 retval = debug_target.to_region_ok_for_hw_watchpoint (&debug_target,
3826 addr, len);
e0d24f8d
WZ
3827
3828 fprintf_unfiltered (gdb_stdlog,
bd91e7ae
OS
3829 "target_region_ok_for_hw_watchpoint (%s, %ld) = %s\n",
3830 core_addr_to_string (addr), (unsigned long) len,
3831 core_addr_to_string (retval));
e0d24f8d
WZ
3832 return retval;
3833}
3834
0cf6dd15 3835static int
c3a5ff89
TT
3836debug_to_can_accel_watchpoint_condition (struct target_ops *self,
3837 CORE_ADDR addr, int len, int rw,
0cf6dd15
TJB
3838 struct expression *cond)
3839{
3840 int retval;
3841
c3a5ff89
TT
3842 retval = debug_target.to_can_accel_watchpoint_condition (&debug_target,
3843 addr, len,
3e43a32a 3844 rw, cond);
0cf6dd15
TJB
3845
3846 fprintf_unfiltered (gdb_stdlog,
3e43a32a
MS
3847 "target_can_accel_watchpoint_condition "
3848 "(%s, %d, %d, %s) = %ld\n",
bd91e7ae
OS
3849 core_addr_to_string (addr), len, rw,
3850 host_address_to_string (cond), (unsigned long) retval);
0cf6dd15
TJB
3851 return retval;
3852}
3853
ccaa32c7 3854static int
6a109b6b 3855debug_to_stopped_by_watchpoint (struct target_ops *ops)
ccaa32c7
GS
3856{
3857 int retval;
3858
6a109b6b 3859 retval = debug_target.to_stopped_by_watchpoint (&debug_target);
ccaa32c7
GS
3860
3861 fprintf_unfiltered (gdb_stdlog,
d92524f1 3862 "target_stopped_by_watchpoint () = %ld\n",
ccaa32c7
GS
3863 (unsigned long) retval);
3864 return retval;
3865}
3866
4aa7a7f5
JJ
3867static int
3868debug_to_stopped_data_address (struct target_ops *target, CORE_ADDR *addr)
ccaa32c7 3869{
4aa7a7f5 3870 int retval;
ccaa32c7 3871
4aa7a7f5 3872 retval = debug_target.to_stopped_data_address (target, addr);
ccaa32c7
GS
3873
3874 fprintf_unfiltered (gdb_stdlog,
bd91e7ae
OS
3875 "target_stopped_data_address ([%s]) = %ld\n",
3876 core_addr_to_string (*addr),
4aa7a7f5 3877 (unsigned long)retval);
ccaa32c7
GS
3878 return retval;
3879}
3880
5009afc5
AS
3881static int
3882debug_to_watchpoint_addr_within_range (struct target_ops *target,
3883 CORE_ADDR addr,
3884 CORE_ADDR start, int length)
3885{
3886 int retval;
3887
3888 retval = debug_target.to_watchpoint_addr_within_range (target, addr,
3889 start, length);
3890
3891 fprintf_filtered (gdb_stdlog,
bd91e7ae
OS
3892 "target_watchpoint_addr_within_range (%s, %s, %d) = %d\n",
3893 core_addr_to_string (addr), core_addr_to_string (start),
3894 length, retval);
5009afc5
AS
3895 return retval;
3896}
3897
ccaa32c7 3898static int
23a26771
TT
3899debug_to_insert_hw_breakpoint (struct target_ops *self,
3900 struct gdbarch *gdbarch,
a6d9a66e 3901 struct bp_target_info *bp_tgt)
ccaa32c7
GS
3902{
3903 int retval;
3904
23a26771
TT
3905 retval = debug_target.to_insert_hw_breakpoint (&debug_target,
3906 gdbarch, bp_tgt);
ccaa32c7
GS
3907
3908 fprintf_unfiltered (gdb_stdlog,
bd91e7ae
OS
3909 "target_insert_hw_breakpoint (%s, xxx) = %ld\n",
3910 core_addr_to_string (bp_tgt->placed_address),
ccaa32c7
GS
3911 (unsigned long) retval);
3912 return retval;
3913}
3914
3915static int
a64dc96c
TT
3916debug_to_remove_hw_breakpoint (struct target_ops *self,
3917 struct gdbarch *gdbarch,
a6d9a66e 3918 struct bp_target_info *bp_tgt)
ccaa32c7
GS
3919{
3920 int retval;
3921
a64dc96c
TT
3922 retval = debug_target.to_remove_hw_breakpoint (&debug_target,
3923 gdbarch, bp_tgt);
ccaa32c7
GS
3924
3925 fprintf_unfiltered (gdb_stdlog,
bd91e7ae
OS
3926 "target_remove_hw_breakpoint (%s, xxx) = %ld\n",
3927 core_addr_to_string (bp_tgt->placed_address),
ccaa32c7
GS
3928 (unsigned long) retval);
3929 return retval;
3930}
3931
3932static int
7bb99c53
TT
3933debug_to_insert_watchpoint (struct target_ops *self,
3934 CORE_ADDR addr, int len, int type,
0cf6dd15 3935 struct expression *cond)
ccaa32c7
GS
3936{
3937 int retval;
3938
7bb99c53
TT
3939 retval = debug_target.to_insert_watchpoint (&debug_target,
3940 addr, len, type, cond);
ccaa32c7
GS
3941
3942 fprintf_unfiltered (gdb_stdlog,
bd91e7ae
OS
3943 "target_insert_watchpoint (%s, %d, %d, %s) = %ld\n",
3944 core_addr_to_string (addr), len, type,
3945 host_address_to_string (cond), (unsigned long) retval);
ccaa32c7
GS
3946 return retval;
3947}
3948
3949static int
11b5219a
TT
3950debug_to_remove_watchpoint (struct target_ops *self,
3951 CORE_ADDR addr, int len, int type,
0cf6dd15 3952 struct expression *cond)
ccaa32c7
GS
3953{
3954 int retval;
3955
11b5219a
TT
3956 retval = debug_target.to_remove_watchpoint (&debug_target,
3957 addr, len, type, cond);
ccaa32c7
GS
3958
3959 fprintf_unfiltered (gdb_stdlog,
bd91e7ae
OS
3960 "target_remove_watchpoint (%s, %d, %d, %s) = %ld\n",
3961 core_addr_to_string (addr), len, type,
3962 host_address_to_string (cond), (unsigned long) retval);
ccaa32c7
GS
3963 return retval;
3964}
3965
c906108c 3966static void
c42bf286 3967debug_to_terminal_init (struct target_ops *self)
c906108c 3968{
c42bf286 3969 debug_target.to_terminal_init (&debug_target);
c906108c 3970
96baa820 3971 fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n");
c906108c
SS
3972}
3973
3974static void
d2f640d4 3975debug_to_terminal_inferior (struct target_ops *self)
c906108c 3976{
d2f640d4 3977 debug_target.to_terminal_inferior (&debug_target);
c906108c 3978
96baa820 3979 fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n");
c906108c
SS
3980}
3981
3982static void
2e1e1a19 3983debug_to_terminal_ours_for_output (struct target_ops *self)
c906108c 3984{
2e1e1a19 3985 debug_target.to_terminal_ours_for_output (&debug_target);
c906108c 3986
96baa820 3987 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n");
c906108c
SS
3988}
3989
3990static void
e3594fd1 3991debug_to_terminal_ours (struct target_ops *self)
c906108c 3992{
e3594fd1 3993 debug_target.to_terminal_ours (&debug_target);
c906108c 3994
96baa820 3995 fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n");
c906108c
SS
3996}
3997
a790ad35 3998static void
ae3bd431 3999debug_to_terminal_save_ours (struct target_ops *self)
a790ad35 4000{
ae3bd431 4001 debug_target.to_terminal_save_ours (&debug_target);
a790ad35
SC
4002
4003 fprintf_unfiltered (gdb_stdlog, "target_terminal_save_ours ()\n");
4004}
4005
c906108c 4006static void
0a4f40a2
TT
4007debug_to_terminal_info (struct target_ops *self,
4008 const char *arg, int from_tty)
c906108c 4009{
0a4f40a2 4010 debug_target.to_terminal_info (&debug_target, arg, from_tty);
c906108c 4011
96baa820 4012 fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg,
c906108c
SS
4013 from_tty);
4014}
4015
c906108c 4016static void
71a9f134 4017debug_to_load (struct target_ops *self, char *args, int from_tty)
c906108c 4018{
71a9f134 4019 debug_target.to_load (&debug_target, args, from_tty);
c906108c 4020
96baa820 4021 fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty);
c906108c
SS
4022}
4023
c906108c 4024static void
2e97a79e 4025debug_to_post_startup_inferior (struct target_ops *self, ptid_t ptid)
c906108c 4026{
2e97a79e 4027 debug_target.to_post_startup_inferior (&debug_target, ptid);
c906108c 4028
96baa820 4029 fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n",
dfd4cc63 4030 ptid_get_pid (ptid));
c906108c
SS
4031}
4032
77b06cd7 4033static int
a863b201 4034debug_to_insert_fork_catchpoint (struct target_ops *self, int pid)
c906108c 4035{
77b06cd7
TJB
4036 int retval;
4037
a863b201 4038 retval = debug_target.to_insert_fork_catchpoint (&debug_target, pid);
77b06cd7
TJB
4039
4040 fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d) = %d\n",
4041 pid, retval);
c906108c 4042
77b06cd7 4043 return retval;
c906108c
SS
4044}
4045
4046static int
973fc227 4047debug_to_remove_fork_catchpoint (struct target_ops *self, int pid)
c906108c 4048{
c5aa993b 4049 int retval;
c906108c 4050
973fc227 4051 retval = debug_target.to_remove_fork_catchpoint (&debug_target, pid);
c906108c 4052
96baa820 4053 fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n",
c5aa993b 4054 pid, retval);
c906108c
SS
4055
4056 return retval;
4057}
4058
77b06cd7 4059static int
3ecc7da0 4060debug_to_insert_vfork_catchpoint (struct target_ops *self, int pid)
c906108c 4061{
77b06cd7
TJB
4062 int retval;
4063
3ecc7da0 4064 retval = debug_target.to_insert_vfork_catchpoint (&debug_target, pid);
c906108c 4065
77b06cd7
TJB
4066 fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d) = %d\n",
4067 pid, retval);
4068
4069 return retval;
c906108c
SS
4070}
4071
4072static int
e98cf0cd 4073debug_to_remove_vfork_catchpoint (struct target_ops *self, int pid)
c906108c 4074{
c5aa993b 4075 int retval;
c906108c 4076
e98cf0cd 4077 retval = debug_target.to_remove_vfork_catchpoint (&debug_target, pid);
c906108c 4078
96baa820 4079 fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n",
c5aa993b 4080 pid, retval);
c906108c
SS
4081
4082 return retval;
4083}
4084
77b06cd7 4085static int
ba025e51 4086debug_to_insert_exec_catchpoint (struct target_ops *self, int pid)
c906108c 4087{
77b06cd7
TJB
4088 int retval;
4089
ba025e51 4090 retval = debug_target.to_insert_exec_catchpoint (&debug_target, pid);
c906108c 4091
77b06cd7
TJB
4092 fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d) = %d\n",
4093 pid, retval);
4094
4095 return retval;
c906108c
SS
4096}
4097
4098static int
758e29d2 4099debug_to_remove_exec_catchpoint (struct target_ops *self, int pid)
c906108c 4100{
c5aa993b 4101 int retval;
c906108c 4102
758e29d2 4103 retval = debug_target.to_remove_exec_catchpoint (&debug_target, pid);
c906108c 4104
96baa820 4105 fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n",
c5aa993b 4106 pid, retval);
c906108c
SS
4107
4108 return retval;
4109}
4110
c906108c 4111static int
d796e1d6
TT
4112debug_to_has_exited (struct target_ops *self,
4113 int pid, int wait_status, int *exit_status)
c906108c 4114{
c5aa993b 4115 int has_exited;
c906108c 4116
d796e1d6
TT
4117 has_exited = debug_target.to_has_exited (&debug_target,
4118 pid, wait_status, exit_status);
c906108c 4119
96baa820 4120 fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n",
c5aa993b 4121 pid, wait_status, *exit_status, has_exited);
c906108c
SS
4122
4123 return has_exited;
4124}
4125
c906108c 4126static int
da82bd6b 4127debug_to_can_run (struct target_ops *self)
c906108c
SS
4128{
4129 int retval;
4130
da82bd6b 4131 retval = debug_target.to_can_run (&debug_target);
c906108c 4132
96baa820 4133 fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval);
c906108c
SS
4134
4135 return retval;
4136}
4137
c2250ad1
UW
4138static struct gdbarch *
4139debug_to_thread_architecture (struct target_ops *ops, ptid_t ptid)
4140{
4141 struct gdbarch *retval;
4142
4143 retval = debug_target.to_thread_architecture (ops, ptid);
4144
3e43a32a
MS
4145 fprintf_unfiltered (gdb_stdlog,
4146 "target_thread_architecture (%s) = %s [%s]\n",
4147 target_pid_to_str (ptid),
4148 host_address_to_string (retval),
c2250ad1
UW
4149 gdbarch_bfd_arch_info (retval)->printable_name);
4150 return retval;
4151}
4152
c906108c 4153static void
1eab8a48 4154debug_to_stop (struct target_ops *self, ptid_t ptid)
c906108c 4155{
1eab8a48 4156 debug_target.to_stop (&debug_target, ptid);
c906108c 4157
94cc34af
PA
4158 fprintf_unfiltered (gdb_stdlog, "target_stop (%s)\n",
4159 target_pid_to_str (ptid));
c906108c
SS
4160}
4161
96baa820 4162static void
1aac633b 4163debug_to_rcmd (struct target_ops *self, char *command,
d9fcf2fb 4164 struct ui_file *outbuf)
96baa820 4165{
1aac633b 4166 debug_target.to_rcmd (&debug_target, command, outbuf);
96baa820
JM
4167 fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command);
4168}
4169
c906108c 4170static char *
8dd27370 4171debug_to_pid_to_exec_file (struct target_ops *self, int pid)
c906108c 4172{
c5aa993b 4173 char *exec_file;
c906108c 4174
8dd27370 4175 exec_file = debug_target.to_pid_to_exec_file (&debug_target, pid);
c906108c 4176
96baa820 4177 fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n",
c5aa993b 4178 pid, exec_file);
c906108c
SS
4179
4180 return exec_file;
4181}
4182
c906108c 4183static void
fba45db2 4184setup_target_debug (void)
c906108c
SS
4185{
4186 memcpy (&debug_target, &current_target, sizeof debug_target);
4187
4188 current_target.to_open = debug_to_open;
c906108c 4189 current_target.to_post_attach = debug_to_post_attach;
c906108c 4190 current_target.to_prepare_to_store = debug_to_prepare_to_store;
c906108c
SS
4191 current_target.to_files_info = debug_to_files_info;
4192 current_target.to_insert_breakpoint = debug_to_insert_breakpoint;
4193 current_target.to_remove_breakpoint = debug_to_remove_breakpoint;
ccaa32c7
GS
4194 current_target.to_can_use_hw_breakpoint = debug_to_can_use_hw_breakpoint;
4195 current_target.to_insert_hw_breakpoint = debug_to_insert_hw_breakpoint;
4196 current_target.to_remove_hw_breakpoint = debug_to_remove_hw_breakpoint;
4197 current_target.to_insert_watchpoint = debug_to_insert_watchpoint;
4198 current_target.to_remove_watchpoint = debug_to_remove_watchpoint;
4199 current_target.to_stopped_by_watchpoint = debug_to_stopped_by_watchpoint;
4200 current_target.to_stopped_data_address = debug_to_stopped_data_address;
3e43a32a
MS
4201 current_target.to_watchpoint_addr_within_range
4202 = debug_to_watchpoint_addr_within_range;
4203 current_target.to_region_ok_for_hw_watchpoint
4204 = debug_to_region_ok_for_hw_watchpoint;
4205 current_target.to_can_accel_watchpoint_condition
4206 = debug_to_can_accel_watchpoint_condition;
c906108c
SS
4207 current_target.to_terminal_init = debug_to_terminal_init;
4208 current_target.to_terminal_inferior = debug_to_terminal_inferior;
3e43a32a
MS
4209 current_target.to_terminal_ours_for_output
4210 = debug_to_terminal_ours_for_output;
c906108c 4211 current_target.to_terminal_ours = debug_to_terminal_ours;
a790ad35 4212 current_target.to_terminal_save_ours = debug_to_terminal_save_ours;
c906108c 4213 current_target.to_terminal_info = debug_to_terminal_info;
c906108c 4214 current_target.to_load = debug_to_load;
c906108c 4215 current_target.to_post_startup_inferior = debug_to_post_startup_inferior;
c906108c
SS
4216 current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint;
4217 current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint;
4218 current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint;
4219 current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint;
c906108c
SS
4220 current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint;
4221 current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint;
c906108c 4222 current_target.to_has_exited = debug_to_has_exited;
c906108c 4223 current_target.to_can_run = debug_to_can_run;
c906108c 4224 current_target.to_stop = debug_to_stop;
96baa820 4225 current_target.to_rcmd = debug_to_rcmd;
c906108c 4226 current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file;
c2250ad1 4227 current_target.to_thread_architecture = debug_to_thread_architecture;
c906108c 4228}
c906108c 4229\f
c5aa993b
JM
4230
4231static char targ_desc[] =
3e43a32a
MS
4232"Names of targets and files being debugged.\nShows the entire \
4233stack of targets currently in use (including the exec-file,\n\
c906108c
SS
4234core-file, and process, if any), as well as the symbol file name.";
4235
a53f3625
TT
4236static void
4237default_rcmd (struct target_ops *self, char *command, struct ui_file *output)
4238{
4239 error (_("\"monitor\" command not supported by this target."));
4240}
4241
96baa820
JM
4242static void
4243do_monitor_command (char *cmd,
4244 int from_tty)
4245{
96baa820
JM
4246 target_rcmd (cmd, gdb_stdtarg);
4247}
4248
87680a14
JB
4249/* Print the name of each layers of our target stack. */
4250
4251static void
4252maintenance_print_target_stack (char *cmd, int from_tty)
4253{
4254 struct target_ops *t;
4255
4256 printf_filtered (_("The current target stack is:\n"));
4257
4258 for (t = target_stack; t != NULL; t = t->beneath)
4259 {
4260 printf_filtered (" - %s (%s)\n", t->to_shortname, t->to_longname);
4261 }
4262}
4263
c6ebd6cf
VP
4264/* Controls if async mode is permitted. */
4265int target_async_permitted = 0;
4266
4267/* The set command writes to this variable. If the inferior is
b5419e49 4268 executing, target_async_permitted is *not* updated. */
c6ebd6cf
VP
4269static int target_async_permitted_1 = 0;
4270
4271static void
9401a810
PA
4272set_target_async_command (char *args, int from_tty,
4273 struct cmd_list_element *c)
c6ebd6cf 4274{
c35b1492 4275 if (have_live_inferiors ())
c6ebd6cf
VP
4276 {
4277 target_async_permitted_1 = target_async_permitted;
4278 error (_("Cannot change this setting while the inferior is running."));
4279 }
4280
4281 target_async_permitted = target_async_permitted_1;
4282}
4283
4284static void
9401a810
PA
4285show_target_async_command (struct ui_file *file, int from_tty,
4286 struct cmd_list_element *c,
4287 const char *value)
c6ebd6cf 4288{
3e43a32a
MS
4289 fprintf_filtered (file,
4290 _("Controlling the inferior in "
4291 "asynchronous mode is %s.\n"), value);
c6ebd6cf
VP
4292}
4293
d914c394
SS
4294/* Temporary copies of permission settings. */
4295
4296static int may_write_registers_1 = 1;
4297static int may_write_memory_1 = 1;
4298static int may_insert_breakpoints_1 = 1;
4299static int may_insert_tracepoints_1 = 1;
4300static int may_insert_fast_tracepoints_1 = 1;
4301static int may_stop_1 = 1;
4302
4303/* Make the user-set values match the real values again. */
4304
4305void
4306update_target_permissions (void)
4307{
4308 may_write_registers_1 = may_write_registers;
4309 may_write_memory_1 = may_write_memory;
4310 may_insert_breakpoints_1 = may_insert_breakpoints;
4311 may_insert_tracepoints_1 = may_insert_tracepoints;
4312 may_insert_fast_tracepoints_1 = may_insert_fast_tracepoints;
4313 may_stop_1 = may_stop;
4314}
4315
4316/* The one function handles (most of) the permission flags in the same
4317 way. */
4318
4319static void
4320set_target_permissions (char *args, int from_tty,
4321 struct cmd_list_element *c)
4322{
4323 if (target_has_execution)
4324 {
4325 update_target_permissions ();
4326 error (_("Cannot change this setting while the inferior is running."));
4327 }
4328
4329 /* Make the real values match the user-changed values. */
4330 may_write_registers = may_write_registers_1;
4331 may_insert_breakpoints = may_insert_breakpoints_1;
4332 may_insert_tracepoints = may_insert_tracepoints_1;
4333 may_insert_fast_tracepoints = may_insert_fast_tracepoints_1;
4334 may_stop = may_stop_1;
4335 update_observer_mode ();
4336}
4337
4338/* Set memory write permission independently of observer mode. */
4339
4340static void
4341set_write_memory_permission (char *args, int from_tty,
4342 struct cmd_list_element *c)
4343{
4344 /* Make the real values match the user-changed values. */
4345 may_write_memory = may_write_memory_1;
4346 update_observer_mode ();
4347}
4348
4349
c906108c 4350void
fba45db2 4351initialize_targets (void)
c906108c
SS
4352{
4353 init_dummy_target ();
4354 push_target (&dummy_target);
4355
4356 add_info ("target", target_info, targ_desc);
4357 add_info ("files", target_info, targ_desc);
4358
ccce17b0 4359 add_setshow_zuinteger_cmd ("target", class_maintenance, &targetdebug, _("\
85c07804
AC
4360Set target debugging."), _("\
4361Show target debugging."), _("\
333dabeb
DJ
4362When non-zero, target debugging is enabled. Higher numbers are more\n\
4363verbose. Changes do not take effect until the next \"run\" or \"target\"\n\
85c07804 4364command."),
ccce17b0
YQ
4365 NULL,
4366 show_targetdebug,
4367 &setdebuglist, &showdebuglist);
3a11626d 4368
2bc416ba 4369 add_setshow_boolean_cmd ("trust-readonly-sections", class_support,
7915a72c
AC
4370 &trust_readonly, _("\
4371Set mode for reading from readonly sections."), _("\
4372Show mode for reading from readonly sections."), _("\
3a11626d
MS
4373When this mode is on, memory reads from readonly sections (such as .text)\n\
4374will be read from the object file instead of from the target. This will\n\
7915a72c 4375result in significant performance improvement for remote targets."),
2c5b56ce 4376 NULL,
920d2a44 4377 show_trust_readonly,
e707bbc2 4378 &setlist, &showlist);
96baa820
JM
4379
4380 add_com ("monitor", class_obscure, do_monitor_command,
1bedd215 4381 _("Send a command to the remote monitor (remote targets only)."));
96baa820 4382
87680a14
JB
4383 add_cmd ("target-stack", class_maintenance, maintenance_print_target_stack,
4384 _("Print the name of each layer of the internal target stack."),
4385 &maintenanceprintlist);
4386
c6ebd6cf
VP
4387 add_setshow_boolean_cmd ("target-async", no_class,
4388 &target_async_permitted_1, _("\
4389Set whether gdb controls the inferior in asynchronous mode."), _("\
4390Show whether gdb controls the inferior in asynchronous mode."), _("\
4391Tells gdb whether to control the inferior in asynchronous mode."),
9401a810
PA
4392 set_target_async_command,
4393 show_target_async_command,
c6ebd6cf
VP
4394 &setlist,
4395 &showlist);
4396
d914c394
SS
4397 add_setshow_boolean_cmd ("may-write-registers", class_support,
4398 &may_write_registers_1, _("\
4399Set permission to write into registers."), _("\
4400Show permission to write into registers."), _("\
4401When this permission is on, GDB may write into the target's registers.\n\
4402Otherwise, any sort of write attempt will result in an error."),
4403 set_target_permissions, NULL,
4404 &setlist, &showlist);
4405
4406 add_setshow_boolean_cmd ("may-write-memory", class_support,
4407 &may_write_memory_1, _("\
4408Set permission to write into target memory."), _("\
4409Show permission to write into target memory."), _("\
4410When this permission is on, GDB may write into the target's memory.\n\
4411Otherwise, any sort of write attempt will result in an error."),
4412 set_write_memory_permission, NULL,
4413 &setlist, &showlist);
4414
4415 add_setshow_boolean_cmd ("may-insert-breakpoints", class_support,
4416 &may_insert_breakpoints_1, _("\
4417Set permission to insert breakpoints in the target."), _("\
4418Show permission to insert breakpoints in the target."), _("\
4419When this permission is on, GDB may insert breakpoints in the program.\n\
4420Otherwise, any sort of insertion attempt will result in an error."),
4421 set_target_permissions, NULL,
4422 &setlist, &showlist);
4423
4424 add_setshow_boolean_cmd ("may-insert-tracepoints", class_support,
4425 &may_insert_tracepoints_1, _("\
4426Set permission to insert tracepoints in the target."), _("\
4427Show permission to insert tracepoints in the target."), _("\
4428When this permission is on, GDB may insert tracepoints in the program.\n\
4429Otherwise, any sort of insertion attempt will result in an error."),
4430 set_target_permissions, NULL,
4431 &setlist, &showlist);
4432
4433 add_setshow_boolean_cmd ("may-insert-fast-tracepoints", class_support,
4434 &may_insert_fast_tracepoints_1, _("\
4435Set permission to insert fast tracepoints in the target."), _("\
4436Show permission to insert fast tracepoints in the target."), _("\
4437When this permission is on, GDB may insert fast tracepoints.\n\
4438Otherwise, any sort of insertion attempt will result in an error."),
4439 set_target_permissions, NULL,
4440 &setlist, &showlist);
4441
4442 add_setshow_boolean_cmd ("may-interrupt", class_support,
4443 &may_stop_1, _("\
4444Set permission to interrupt or signal the target."), _("\
4445Show permission to interrupt or signal the target."), _("\
4446When this permission is on, GDB may interrupt/stop the target's execution.\n\
4447Otherwise, any attempt to interrupt or stop will be ignored."),
4448 set_target_permissions, NULL,
4449 &setlist, &showlist);
c906108c 4450}
This page took 1.885733 seconds and 4 git commands to generate.