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