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