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