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