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