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