Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Select target systems and architectures at runtime for GDB. |
d9fcf2fb | 2 | Copyright 1990, 1992-1995, 1998-2000 Free Software Foundation, Inc. |
c906108c SS |
3 | Contributed by Cygnus Support. |
4 | ||
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b JM |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include <errno.h> | |
24 | #include <ctype.h> | |
25 | #include "gdb_string.h" | |
26 | #include "target.h" | |
27 | #include "gdbcmd.h" | |
28 | #include "symtab.h" | |
29 | #include "inferior.h" | |
30 | #include "bfd.h" | |
31 | #include "symfile.h" | |
32 | #include "objfiles.h" | |
03f2053f | 33 | #include "gdb_wait.h" |
c906108c SS |
34 | #include <signal.h> |
35 | ||
36 | extern int errno; | |
37 | ||
a14ed312 | 38 | static void target_info (char *, int); |
c906108c | 39 | |
a14ed312 | 40 | static void cleanup_target (struct target_ops *); |
c906108c | 41 | |
a14ed312 | 42 | static void maybe_kill_then_create_inferior (char *, char *, char **); |
c906108c | 43 | |
a14ed312 | 44 | static void default_clone_and_follow_inferior (int, int *); |
c906108c | 45 | |
a14ed312 | 46 | static void maybe_kill_then_attach (char *, int); |
c906108c | 47 | |
a14ed312 | 48 | static void kill_or_be_killed (int); |
c906108c | 49 | |
a14ed312 | 50 | static void default_terminal_info (char *, int); |
c906108c | 51 | |
a14ed312 | 52 | static int nosymbol (char *, CORE_ADDR *); |
c906108c | 53 | |
a14ed312 | 54 | static void tcomplain (void); |
c906108c | 55 | |
a14ed312 | 56 | static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *); |
c906108c | 57 | |
a14ed312 | 58 | static int return_zero (void); |
c906108c | 59 | |
a14ed312 | 60 | static int return_one (void); |
c906108c | 61 | |
a14ed312 | 62 | void target_ignore (void); |
c906108c | 63 | |
a14ed312 | 64 | static void target_command (char *, int); |
c906108c | 65 | |
a14ed312 | 66 | static struct target_ops *find_default_run_target (char *); |
c906108c | 67 | |
a14ed312 | 68 | static void update_current_target (void); |
c906108c | 69 | |
a14ed312 | 70 | static void nosupport_runtime (void); |
392a587b | 71 | |
a14ed312 | 72 | static void normal_target_post_startup_inferior (int pid); |
392a587b | 73 | |
917317f4 JM |
74 | /* Transfer LEN bytes between target address MEMADDR and GDB address |
75 | MYADDR. Returns 0 for success, errno code for failure (which | |
76 | includes partial transfers -- if you want a more useful response to | |
77 | partial transfers, try either target_read_memory_partial or | |
78 | target_write_memory_partial). */ | |
c906108c SS |
79 | |
80 | static int | |
a14ed312 | 81 | target_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write); |
c906108c | 82 | |
a14ed312 | 83 | static void init_dummy_target (void); |
c906108c | 84 | |
a14ed312 | 85 | static void debug_to_open (char *, int); |
c906108c | 86 | |
a14ed312 | 87 | static void debug_to_close (int); |
c906108c | 88 | |
a14ed312 | 89 | static void debug_to_attach (char *, int); |
c906108c | 90 | |
a14ed312 | 91 | static void debug_to_detach (char *, int); |
c906108c | 92 | |
a14ed312 | 93 | static void debug_to_resume (int, int, enum target_signal); |
c906108c | 94 | |
a14ed312 | 95 | static int debug_to_wait (int, struct target_waitstatus *); |
c906108c | 96 | |
a14ed312 | 97 | static void debug_to_fetch_registers (int); |
c906108c | 98 | |
a14ed312 | 99 | static void debug_to_store_registers (int); |
c906108c | 100 | |
a14ed312 | 101 | static void debug_to_prepare_to_store (void); |
c906108c SS |
102 | |
103 | static int | |
a14ed312 | 104 | debug_to_xfer_memory (CORE_ADDR, char *, int, int, struct target_ops *); |
c906108c | 105 | |
a14ed312 | 106 | static void debug_to_files_info (struct target_ops *); |
c906108c | 107 | |
a14ed312 | 108 | static int debug_to_insert_breakpoint (CORE_ADDR, char *); |
c906108c | 109 | |
a14ed312 | 110 | static int debug_to_remove_breakpoint (CORE_ADDR, char *); |
c906108c | 111 | |
a14ed312 | 112 | static void debug_to_terminal_init (void); |
c906108c | 113 | |
a14ed312 | 114 | static void debug_to_terminal_inferior (void); |
c906108c | 115 | |
a14ed312 | 116 | static void debug_to_terminal_ours_for_output (void); |
c906108c | 117 | |
a14ed312 | 118 | static void debug_to_terminal_ours (void); |
c906108c | 119 | |
a14ed312 | 120 | static void debug_to_terminal_info (char *, int); |
c906108c | 121 | |
a14ed312 | 122 | static void debug_to_kill (void); |
c906108c | 123 | |
a14ed312 | 124 | static void debug_to_load (char *, int); |
c906108c | 125 | |
a14ed312 | 126 | static int debug_to_lookup_symbol (char *, CORE_ADDR *); |
c906108c | 127 | |
a14ed312 | 128 | static void debug_to_create_inferior (char *, char *, char **); |
c906108c | 129 | |
a14ed312 | 130 | static void debug_to_mourn_inferior (void); |
c906108c | 131 | |
a14ed312 | 132 | static int debug_to_can_run (void); |
c906108c | 133 | |
a14ed312 | 134 | static void debug_to_notice_signals (int); |
c906108c | 135 | |
a14ed312 | 136 | static int debug_to_thread_alive (int); |
c906108c | 137 | |
a14ed312 | 138 | static void debug_to_stop (void); |
c906108c | 139 | |
a14ed312 | 140 | static int debug_to_query (int /*char */ , char *, char *, int *); |
c906108c SS |
141 | |
142 | /* Pointer to array of target architecture structures; the size of the | |
143 | array; the current index into the array; the allocated size of the | |
144 | array. */ | |
145 | struct target_ops **target_structs; | |
146 | unsigned target_struct_size; | |
147 | unsigned target_struct_index; | |
148 | unsigned target_struct_allocsize; | |
149 | #define DEFAULT_ALLOCSIZE 10 | |
150 | ||
151 | /* The initial current target, so that there is always a semi-valid | |
152 | current target. */ | |
153 | ||
154 | static struct target_ops dummy_target; | |
155 | ||
156 | /* Top of target stack. */ | |
157 | ||
158 | struct target_stack_item *target_stack; | |
159 | ||
160 | /* The target structure we are currently using to talk to a process | |
161 | or file or whatever "inferior" we have. */ | |
162 | ||
163 | struct target_ops current_target; | |
164 | ||
165 | /* Command list for target. */ | |
166 | ||
167 | static struct cmd_list_element *targetlist = NULL; | |
168 | ||
169 | /* Nonzero if we are debugging an attached outside process | |
170 | rather than an inferior. */ | |
171 | ||
172 | int attach_flag; | |
173 | ||
c906108c SS |
174 | /* Non-zero if we want to see trace of target level stuff. */ |
175 | ||
176 | static int targetdebug = 0; | |
177 | ||
a14ed312 | 178 | static void setup_target_debug (void); |
c906108c | 179 | |
c906108c SS |
180 | /* The user just typed 'target' without the name of a target. */ |
181 | ||
182 | /* ARGSUSED */ | |
183 | static void | |
184 | target_command (arg, from_tty) | |
185 | char *arg; | |
186 | int from_tty; | |
187 | { | |
188 | fputs_filtered ("Argument required (target name). Try `help target'\n", | |
189 | gdb_stdout); | |
190 | } | |
191 | ||
192 | /* Add a possible target architecture to the list. */ | |
193 | ||
194 | void | |
195 | add_target (t) | |
196 | struct target_ops *t; | |
197 | { | |
198 | if (!target_structs) | |
199 | { | |
200 | target_struct_allocsize = DEFAULT_ALLOCSIZE; | |
201 | target_structs = (struct target_ops **) xmalloc | |
202 | (target_struct_allocsize * sizeof (*target_structs)); | |
203 | } | |
204 | if (target_struct_size >= target_struct_allocsize) | |
205 | { | |
206 | target_struct_allocsize *= 2; | |
207 | target_structs = (struct target_ops **) | |
c5aa993b JM |
208 | xrealloc ((char *) target_structs, |
209 | target_struct_allocsize * sizeof (*target_structs)); | |
c906108c SS |
210 | } |
211 | target_structs[target_struct_size++] = t; | |
c5aa993b | 212 | /* cleanup_target (t); */ |
c906108c SS |
213 | |
214 | if (targetlist == NULL) | |
215 | add_prefix_cmd ("target", class_run, target_command, | |
216 | "Connect to a target machine or process.\n\ | |
217 | The first argument is the type or protocol of the target machine.\n\ | |
218 | Remaining arguments are interpreted by the target protocol. For more\n\ | |
219 | information on the arguments for a particular protocol, type\n\ | |
220 | `help target ' followed by the protocol name.", | |
221 | &targetlist, "target ", 0, &cmdlist); | |
222 | add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist); | |
223 | } | |
224 | ||
225 | /* Stub functions */ | |
226 | ||
227 | void | |
228 | target_ignore () | |
229 | { | |
230 | } | |
231 | ||
11cf8741 JM |
232 | void |
233 | target_load (char *arg, int from_tty) | |
234 | { | |
235 | (*current_target.to_load) (arg, from_tty); | |
236 | } | |
237 | ||
c906108c SS |
238 | /* ARGSUSED */ |
239 | static int | |
240 | nomemory (memaddr, myaddr, len, write, t) | |
241 | CORE_ADDR memaddr; | |
242 | char *myaddr; | |
243 | int len; | |
244 | int write; | |
245 | struct target_ops *t; | |
246 | { | |
c5aa993b JM |
247 | errno = EIO; /* Can't read/write this location */ |
248 | return 0; /* No bytes handled */ | |
c906108c SS |
249 | } |
250 | ||
251 | static void | |
252 | tcomplain () | |
253 | { | |
254 | error ("You can't do that when your target is `%s'", | |
255 | current_target.to_shortname); | |
256 | } | |
257 | ||
258 | void | |
259 | noprocess () | |
260 | { | |
261 | error ("You can't do that without a process to debug."); | |
262 | } | |
263 | ||
264 | /* ARGSUSED */ | |
265 | static int | |
266 | nosymbol (name, addrp) | |
267 | char *name; | |
268 | CORE_ADDR *addrp; | |
269 | { | |
c5aa993b | 270 | return 1; /* Symbol does not exist in target env */ |
c906108c SS |
271 | } |
272 | ||
273 | /* ARGSUSED */ | |
392a587b | 274 | static void |
c906108c SS |
275 | nosupport_runtime () |
276 | { | |
277 | if (!inferior_pid) | |
278 | noprocess (); | |
279 | else | |
280 | error ("No run-time support for this"); | |
281 | } | |
282 | ||
283 | ||
284 | /* ARGSUSED */ | |
285 | static void | |
286 | default_terminal_info (args, from_tty) | |
287 | char *args; | |
288 | int from_tty; | |
289 | { | |
c5aa993b | 290 | printf_unfiltered ("No saved terminal information.\n"); |
c906108c SS |
291 | } |
292 | ||
293 | /* This is the default target_create_inferior and target_attach function. | |
294 | If the current target is executing, it asks whether to kill it off. | |
295 | If this function returns without calling error(), it has killed off | |
296 | the target, and the operation should be attempted. */ | |
297 | ||
298 | static void | |
299 | kill_or_be_killed (from_tty) | |
300 | int from_tty; | |
301 | { | |
302 | if (target_has_execution) | |
303 | { | |
304 | printf_unfiltered ("You are already running a program:\n"); | |
305 | target_files_info (); | |
c5aa993b JM |
306 | if (query ("Kill it? ")) |
307 | { | |
308 | target_kill (); | |
309 | if (target_has_execution) | |
310 | error ("Killing the program did not help."); | |
311 | return; | |
312 | } | |
313 | else | |
314 | { | |
315 | error ("Program not killed."); | |
316 | } | |
c906108c | 317 | } |
c5aa993b | 318 | tcomplain (); |
c906108c SS |
319 | } |
320 | ||
321 | static void | |
322 | maybe_kill_then_attach (args, from_tty) | |
323 | char *args; | |
324 | int from_tty; | |
325 | { | |
326 | kill_or_be_killed (from_tty); | |
327 | target_attach (args, from_tty); | |
328 | } | |
329 | ||
330 | static void | |
331 | maybe_kill_then_create_inferior (exec, args, env) | |
332 | char *exec; | |
333 | char *args; | |
334 | char **env; | |
335 | { | |
336 | kill_or_be_killed (0); | |
337 | target_create_inferior (exec, args, env); | |
338 | } | |
339 | ||
340 | static void | |
341 | default_clone_and_follow_inferior (child_pid, followed_child) | |
c5aa993b JM |
342 | int child_pid; |
343 | int *followed_child; | |
c906108c SS |
344 | { |
345 | target_clone_and_follow_inferior (child_pid, followed_child); | |
346 | } | |
347 | ||
348 | /* Clean up a target struct so it no longer has any zero pointers in it. | |
349 | We default entries, at least to stubs that print error messages. */ | |
350 | ||
351 | static void | |
352 | cleanup_target (t) | |
353 | struct target_ops *t; | |
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, | |
380 | (void (*) (int, int, enum target_signal)) | |
381 | noprocess); | |
382 | de_fault (to_wait, | |
383 | (int (*) (int, struct target_waitstatus *)) | |
384 | noprocess); | |
385 | de_fault (to_post_wait, | |
386 | (void (*) (int, int)) | |
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, | |
398 | (int (*) (CORE_ADDR, char *, int, int, struct target_ops *)) | |
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); | |
407 | de_fault (to_terminal_init, | |
408 | (void (*) (void)) | |
409 | target_ignore); | |
410 | de_fault (to_terminal_inferior, | |
411 | (void (*) (void)) | |
412 | target_ignore); | |
413 | de_fault (to_terminal_ours_for_output, | |
414 | (void (*) (void)) | |
415 | target_ignore); | |
416 | de_fault (to_terminal_ours, | |
417 | (void (*) (void)) | |
418 | target_ignore); | |
419 | de_fault (to_terminal_info, | |
420 | default_terminal_info); | |
421 | de_fault (to_kill, | |
422 | (void (*) (void)) | |
423 | noprocess); | |
424 | de_fault (to_load, | |
425 | (void (*) (char *, int)) | |
426 | tcomplain); | |
427 | de_fault (to_lookup_symbol, | |
428 | (int (*) (char *, CORE_ADDR *)) | |
429 | nosymbol); | |
430 | de_fault (to_create_inferior, | |
431 | maybe_kill_then_create_inferior); | |
432 | de_fault (to_post_startup_inferior, | |
433 | (void (*) (int)) | |
434 | target_ignore); | |
435 | de_fault (to_acknowledge_created_inferior, | |
436 | (void (*) (int)) | |
437 | target_ignore); | |
438 | de_fault (to_clone_and_follow_inferior, | |
439 | default_clone_and_follow_inferior); | |
440 | de_fault (to_post_follow_inferior_by_clone, | |
441 | (void (*) (void)) | |
442 | target_ignore); | |
443 | de_fault (to_insert_fork_catchpoint, | |
444 | (int (*) (int)) | |
445 | tcomplain); | |
446 | de_fault (to_remove_fork_catchpoint, | |
447 | (int (*) (int)) | |
448 | tcomplain); | |
449 | de_fault (to_insert_vfork_catchpoint, | |
450 | (int (*) (int)) | |
451 | tcomplain); | |
452 | de_fault (to_remove_vfork_catchpoint, | |
453 | (int (*) (int)) | |
454 | tcomplain); | |
455 | de_fault (to_has_forked, | |
456 | (int (*) (int, int *)) | |
457 | return_zero); | |
458 | de_fault (to_has_vforked, | |
459 | (int (*) (int, int *)) | |
460 | return_zero); | |
461 | de_fault (to_can_follow_vfork_prior_to_exec, | |
462 | (int (*) (void)) | |
463 | return_zero); | |
464 | de_fault (to_post_follow_vfork, | |
465 | (void (*) (int, int, int, int)) | |
466 | target_ignore); | |
467 | de_fault (to_insert_exec_catchpoint, | |
468 | (int (*) (int)) | |
469 | tcomplain); | |
470 | de_fault (to_remove_exec_catchpoint, | |
471 | (int (*) (int)) | |
472 | tcomplain); | |
473 | de_fault (to_has_execd, | |
474 | (int (*) (int, char **)) | |
475 | return_zero); | |
476 | de_fault (to_reported_exec_events_per_exec_call, | |
477 | (int (*) (void)) | |
478 | return_one); | |
479 | de_fault (to_has_syscall_event, | |
480 | (int (*) (int, enum target_waitkind *, int *)) | |
481 | return_zero); | |
482 | de_fault (to_has_exited, | |
483 | (int (*) (int, int, int *)) | |
484 | return_zero); | |
485 | de_fault (to_mourn_inferior, | |
486 | (void (*) (void)) | |
487 | noprocess); | |
488 | de_fault (to_can_run, | |
489 | return_zero); | |
490 | de_fault (to_notice_signals, | |
491 | (void (*) (int)) | |
492 | target_ignore); | |
493 | de_fault (to_thread_alive, | |
494 | (int (*) (int)) | |
495 | return_zero); | |
496 | de_fault (to_find_new_threads, | |
497 | (void (*) (void)) | |
498 | target_ignore); | |
499 | de_fault (to_extra_thread_info, | |
500 | (char *(*) (struct thread_info *)) | |
501 | return_zero); | |
502 | de_fault (to_stop, | |
503 | (void (*) (void)) | |
504 | target_ignore); | |
505 | de_fault (to_query, | |
506 | (int (*) (int, char *, char *, int *)) | |
507 | return_zero); | |
508 | de_fault (to_rcmd, | |
d9fcf2fb | 509 | (void (*) (char *, struct ui_file *)) |
0d06e24b JM |
510 | tcomplain); |
511 | de_fault (to_enable_exception_callback, | |
512 | (struct symtab_and_line * (*) (enum exception_event_kind, int)) | |
513 | nosupport_runtime); | |
514 | de_fault (to_get_current_exception_event, | |
515 | (struct exception_event_record * (*) (void)) | |
516 | nosupport_runtime); | |
517 | de_fault (to_pid_to_exec_file, | |
518 | (char *(*) (int)) | |
519 | return_zero); | |
520 | de_fault (to_core_file_to_sym_file, | |
521 | (char *(*) (char *)) | |
522 | return_zero); | |
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 | |
540 | update_current_target () | |
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); | |
576 | INHERIT (to_terminal_init, t); | |
577 | INHERIT (to_terminal_inferior, t); | |
578 | INHERIT (to_terminal_ours_for_output, t); | |
579 | INHERIT (to_terminal_ours, t); | |
580 | INHERIT (to_terminal_info, t); | |
581 | INHERIT (to_kill, t); | |
582 | INHERIT (to_load, t); | |
583 | INHERIT (to_lookup_symbol, t); | |
584 | INHERIT (to_create_inferior, t); | |
585 | INHERIT (to_post_startup_inferior, t); | |
586 | INHERIT (to_acknowledge_created_inferior, t); | |
587 | INHERIT (to_clone_and_follow_inferior, t); | |
588 | INHERIT (to_post_follow_inferior_by_clone, t); | |
589 | INHERIT (to_insert_fork_catchpoint, t); | |
590 | INHERIT (to_remove_fork_catchpoint, t); | |
591 | INHERIT (to_insert_vfork_catchpoint, t); | |
592 | INHERIT (to_remove_vfork_catchpoint, t); | |
593 | INHERIT (to_has_forked, t); | |
594 | INHERIT (to_has_vforked, t); | |
595 | INHERIT (to_can_follow_vfork_prior_to_exec, t); | |
596 | INHERIT (to_post_follow_vfork, t); | |
597 | INHERIT (to_insert_exec_catchpoint, t); | |
598 | INHERIT (to_remove_exec_catchpoint, t); | |
599 | INHERIT (to_has_execd, t); | |
600 | INHERIT (to_reported_exec_events_per_exec_call, t); | |
601 | INHERIT (to_has_syscall_event, t); | |
602 | INHERIT (to_has_exited, t); | |
603 | INHERIT (to_mourn_inferior, t); | |
604 | INHERIT (to_can_run, t); | |
605 | INHERIT (to_notice_signals, t); | |
606 | INHERIT (to_thread_alive, t); | |
b83266a0 | 607 | INHERIT (to_find_new_threads, t); |
ed9a39eb | 608 | INHERIT (to_pid_to_str, t); |
0d06e24b | 609 | INHERIT (to_extra_thread_info, t); |
c906108c SS |
610 | INHERIT (to_stop, t); |
611 | INHERIT (to_query, t); | |
96baa820 | 612 | INHERIT (to_rcmd, t); |
c906108c SS |
613 | INHERIT (to_enable_exception_callback, t); |
614 | INHERIT (to_get_current_exception_event, t); | |
615 | INHERIT (to_pid_to_exec_file, t); | |
616 | INHERIT (to_core_file_to_sym_file, t); | |
617 | INHERIT (to_stratum, t); | |
618 | INHERIT (DONT_USE, t); | |
619 | INHERIT (to_has_all_memory, t); | |
620 | INHERIT (to_has_memory, t); | |
621 | INHERIT (to_has_stack, t); | |
622 | INHERIT (to_has_registers, t); | |
623 | INHERIT (to_has_execution, t); | |
624 | INHERIT (to_has_thread_control, t); | |
625 | INHERIT (to_sections, t); | |
626 | INHERIT (to_sections_end, t); | |
6426a772 JM |
627 | INHERIT (to_can_async_p, t); |
628 | INHERIT (to_is_async_p, t); | |
629 | INHERIT (to_async, t); | |
ed9a39eb | 630 | INHERIT (to_async_mask_value, t); |
c906108c SS |
631 | INHERIT (to_magic, t); |
632 | ||
633 | #undef INHERIT | |
634 | } | |
635 | } | |
636 | ||
637 | /* Push a new target type into the stack of the existing target accessors, | |
638 | possibly superseding some of the existing accessors. | |
639 | ||
640 | Result is zero if the pushed target ended up on top of the stack, | |
641 | nonzero if at least one target is on top of it. | |
642 | ||
643 | Rather than allow an empty stack, we always have the dummy target at | |
644 | the bottom stratum, so we can call the function vectors without | |
645 | checking them. */ | |
646 | ||
647 | int | |
648 | push_target (t) | |
649 | struct target_ops *t; | |
650 | { | |
651 | struct target_stack_item *cur, *prev, *tmp; | |
652 | ||
653 | /* Check magic number. If wrong, it probably means someone changed | |
654 | the struct definition, but not all the places that initialize one. */ | |
655 | if (t->to_magic != OPS_MAGIC) | |
656 | { | |
c5aa993b JM |
657 | fprintf_unfiltered (gdb_stderr, |
658 | "Magic number of %s target struct wrong\n", | |
659 | t->to_shortname); | |
660 | abort (); | |
c906108c SS |
661 | } |
662 | ||
663 | /* Find the proper stratum to install this target in. */ | |
664 | ||
665 | for (prev = NULL, cur = target_stack; cur; prev = cur, cur = cur->next) | |
666 | { | |
c5aa993b | 667 | if ((int) (t->to_stratum) >= (int) (cur->target_ops->to_stratum)) |
c906108c SS |
668 | break; |
669 | } | |
670 | ||
671 | /* If there's already targets at this stratum, remove them. */ | |
672 | ||
673 | if (cur) | |
674 | while (t->to_stratum == cur->target_ops->to_stratum) | |
675 | { | |
676 | /* There's already something on this stratum. Close it off. */ | |
677 | if (cur->target_ops->to_close) | |
678 | (cur->target_ops->to_close) (0); | |
679 | if (prev) | |
c5aa993b | 680 | prev->next = cur->next; /* Unchain old target_ops */ |
c906108c | 681 | else |
c5aa993b | 682 | target_stack = cur->next; /* Unchain first on list */ |
c906108c SS |
683 | tmp = cur->next; |
684 | free (cur); | |
685 | cur = tmp; | |
686 | } | |
687 | ||
688 | /* We have removed all targets in our stratum, now add the new one. */ | |
689 | ||
690 | tmp = (struct target_stack_item *) | |
691 | xmalloc (sizeof (struct target_stack_item)); | |
692 | tmp->next = cur; | |
693 | tmp->target_ops = t; | |
694 | ||
695 | if (prev) | |
696 | prev->next = tmp; | |
697 | else | |
698 | target_stack = tmp; | |
699 | ||
700 | update_current_target (); | |
701 | ||
c5aa993b | 702 | cleanup_target (¤t_target); /* Fill in the gaps */ |
c906108c | 703 | |
c906108c SS |
704 | if (targetdebug) |
705 | setup_target_debug (); | |
c906108c SS |
706 | |
707 | return prev != 0; | |
708 | } | |
709 | ||
710 | /* Remove a target_ops vector from the stack, wherever it may be. | |
711 | Return how many times it was removed (0 or 1). */ | |
712 | ||
713 | int | |
714 | unpush_target (t) | |
715 | struct target_ops *t; | |
716 | { | |
717 | struct target_stack_item *cur, *prev; | |
718 | ||
719 | if (t->to_close) | |
720 | t->to_close (0); /* Let it clean up */ | |
721 | ||
722 | /* Look for the specified target. Note that we assume that a target | |
723 | can only occur once in the target stack. */ | |
724 | ||
725 | for (cur = target_stack, prev = NULL; cur; prev = cur, cur = cur->next) | |
726 | if (cur->target_ops == t) | |
727 | break; | |
728 | ||
729 | if (!cur) | |
730 | return 0; /* Didn't find target_ops, quit now */ | |
731 | ||
732 | /* Unchain the target */ | |
733 | ||
734 | if (!prev) | |
735 | target_stack = cur->next; | |
736 | else | |
737 | prev->next = cur->next; | |
738 | ||
739 | free (cur); /* Release the target_stack_item */ | |
740 | ||
741 | update_current_target (); | |
742 | cleanup_target (¤t_target); | |
743 | ||
744 | return 1; | |
745 | } | |
746 | ||
747 | void | |
748 | pop_target () | |
749 | { | |
c5aa993b | 750 | (current_target.to_close) (0); /* Let it clean up */ |
c906108c SS |
751 | if (unpush_target (target_stack->target_ops) == 1) |
752 | return; | |
753 | ||
c5aa993b JM |
754 | fprintf_unfiltered (gdb_stderr, |
755 | "pop_target couldn't find target %s\n", | |
756 | current_target.to_shortname); | |
757 | abort (); | |
c906108c SS |
758 | } |
759 | ||
760 | #undef MIN | |
761 | #define MIN(A, B) (((A) <= (B)) ? (A) : (B)) | |
762 | ||
763 | /* target_read_string -- read a null terminated string, up to LEN bytes, | |
764 | from MEMADDR in target. Set *ERRNOP to the errno code, or 0 if successful. | |
765 | Set *STRING to a pointer to malloc'd memory containing the data; the caller | |
766 | is responsible for freeing it. Return the number of bytes successfully | |
767 | read. */ | |
768 | ||
769 | int | |
770 | target_read_string (memaddr, string, len, errnop) | |
771 | CORE_ADDR memaddr; | |
772 | char **string; | |
773 | int len; | |
774 | int *errnop; | |
775 | { | |
776 | int tlen, origlen, offset, i; | |
777 | char buf[4]; | |
778 | int errcode = 0; | |
779 | char *buffer; | |
780 | int buffer_allocated; | |
781 | char *bufptr; | |
782 | unsigned int nbytes_read = 0; | |
783 | ||
784 | /* Small for testing. */ | |
785 | buffer_allocated = 4; | |
786 | buffer = xmalloc (buffer_allocated); | |
787 | bufptr = buffer; | |
788 | ||
789 | origlen = len; | |
790 | ||
791 | while (len > 0) | |
792 | { | |
793 | tlen = MIN (len, 4 - (memaddr & 3)); | |
794 | offset = memaddr & 3; | |
795 | ||
d4b2399a | 796 | errcode = target_xfer_memory (memaddr & ~3, buf, 4, 0); |
c906108c SS |
797 | if (errcode != 0) |
798 | { | |
799 | /* The transfer request might have crossed the boundary to an | |
800 | unallocated region of memory. Retry the transfer, requesting | |
801 | a single byte. */ | |
802 | tlen = 1; | |
803 | offset = 0; | |
d4b2399a | 804 | errcode = target_xfer_memory (memaddr, buf, 1, 0); |
c906108c SS |
805 | if (errcode != 0) |
806 | goto done; | |
807 | } | |
808 | ||
809 | if (bufptr - buffer + tlen > buffer_allocated) | |
810 | { | |
811 | unsigned int bytes; | |
812 | bytes = bufptr - buffer; | |
813 | buffer_allocated *= 2; | |
814 | buffer = xrealloc (buffer, buffer_allocated); | |
815 | bufptr = buffer + bytes; | |
816 | } | |
817 | ||
818 | for (i = 0; i < tlen; i++) | |
819 | { | |
820 | *bufptr++ = buf[i + offset]; | |
821 | if (buf[i + offset] == '\000') | |
822 | { | |
823 | nbytes_read += i + 1; | |
824 | goto done; | |
825 | } | |
826 | } | |
827 | ||
828 | memaddr += tlen; | |
829 | len -= tlen; | |
830 | nbytes_read += tlen; | |
831 | } | |
c5aa993b | 832 | done: |
c906108c SS |
833 | if (errnop != NULL) |
834 | *errnop = errcode; | |
835 | if (string != NULL) | |
836 | *string = buffer; | |
837 | return nbytes_read; | |
838 | } | |
839 | ||
840 | /* Read LEN bytes of target memory at address MEMADDR, placing the results in | |
841 | GDB's memory at MYADDR. Returns either 0 for success or an errno value | |
842 | if any error occurs. | |
843 | ||
844 | If an error occurs, no guarantee is made about the contents of the data at | |
845 | MYADDR. In particular, the caller should not depend upon partial reads | |
846 | filling the buffer with good data. There is no way for the caller to know | |
847 | how much good data might have been transfered anyway. Callers that can | |
848 | deal with partial reads should call target_read_memory_partial. */ | |
849 | ||
850 | int | |
851 | target_read_memory (memaddr, myaddr, len) | |
852 | CORE_ADDR memaddr; | |
853 | char *myaddr; | |
854 | int len; | |
855 | { | |
d4b2399a | 856 | return target_xfer_memory (memaddr, myaddr, len, 0); |
c906108c SS |
857 | } |
858 | ||
c906108c SS |
859 | int |
860 | target_write_memory (memaddr, myaddr, len) | |
861 | CORE_ADDR memaddr; | |
862 | char *myaddr; | |
863 | int len; | |
864 | { | |
d4b2399a | 865 | return target_xfer_memory (memaddr, myaddr, len, 1); |
c906108c | 866 | } |
c5aa993b | 867 | |
c906108c SS |
868 | /* Move memory to or from the targets. Iterate until all of it has |
869 | been moved, if necessary. The top target gets priority; anything | |
870 | it doesn't want, is offered to the next one down, etc. Note the | |
871 | business with curlen: if an early target says "no, but I have a | |
872 | boundary overlapping this xfer" then we shorten what we offer to | |
873 | the subsequent targets so the early guy will get a chance at the | |
874 | tail before the subsequent ones do. | |
875 | ||
876 | Result is 0 or errno value. */ | |
877 | ||
878 | static int | |
d4b2399a | 879 | target_xfer_memory (memaddr, myaddr, len, write) |
c906108c SS |
880 | CORE_ADDR memaddr; |
881 | char *myaddr; | |
882 | int len; | |
883 | int write; | |
c906108c SS |
884 | { |
885 | int curlen; | |
886 | int res; | |
887 | struct target_ops *t; | |
888 | struct target_stack_item *item; | |
889 | ||
890 | /* Zero length requests are ok and require no work. */ | |
891 | if (len == 0) | |
892 | return 0; | |
893 | ||
c906108c SS |
894 | /* to_xfer_memory is not guaranteed to set errno, even when it returns |
895 | 0. */ | |
896 | errno = 0; | |
897 | ||
898 | /* The quick case is that the top target does it all. */ | |
899 | res = current_target.to_xfer_memory | |
c5aa993b | 900 | (memaddr, myaddr, len, write, ¤t_target); |
c906108c SS |
901 | if (res == len) |
902 | return 0; | |
903 | ||
904 | if (res > 0) | |
905 | goto bump; | |
906 | /* If res <= 0 then we call it again in the loop. Ah well. */ | |
907 | ||
908 | for (; len > 0;) | |
909 | { | |
910 | curlen = len; /* Want to do it all */ | |
911 | for (item = target_stack; item; item = item->next) | |
912 | { | |
913 | t = item->target_ops; | |
914 | if (!t->to_has_memory) | |
915 | continue; | |
916 | ||
917 | res = t->to_xfer_memory (memaddr, myaddr, curlen, write, t); | |
918 | if (res > 0) | |
919 | break; /* Handled all or part of xfer */ | |
920 | if (t->to_has_all_memory) | |
921 | break; | |
922 | } | |
923 | ||
924 | if (res <= 0) | |
925 | { | |
926 | /* If this address is for nonexistent memory, | |
927 | read zeros if reading, or do nothing if writing. Return error. */ | |
928 | if (!write) | |
929 | memset (myaddr, 0, len); | |
930 | if (errno == 0) | |
931 | return EIO; | |
932 | else | |
933 | return errno; | |
934 | } | |
c5aa993b | 935 | bump: |
c906108c | 936 | memaddr += res; |
c5aa993b JM |
937 | myaddr += res; |
938 | len -= res; | |
c906108c SS |
939 | } |
940 | return 0; /* We managed to cover it all somehow. */ | |
941 | } | |
942 | ||
943 | ||
917317f4 JM |
944 | /* Perform a partial memory transfer. */ |
945 | ||
946 | static int | |
947 | target_xfer_memory_partial (CORE_ADDR memaddr, char *buf, int len, | |
948 | int write_p, int *err) | |
949 | { | |
950 | int res; | |
951 | int err_res; | |
952 | int len_res; | |
953 | struct target_ops *t; | |
954 | struct target_stack_item *item; | |
955 | ||
956 | /* Zero length requests are ok and require no work. */ | |
957 | if (len == 0) | |
958 | { | |
959 | *err = 0; | |
960 | return 0; | |
961 | } | |
962 | ||
963 | /* The quick case is that the top target does it all. */ | |
964 | res = current_target.to_xfer_memory (memaddr, buf, len, write_p, ¤t_target); | |
965 | if (res > 0) | |
966 | { | |
967 | *err = 0; | |
968 | return res; | |
969 | } | |
970 | ||
971 | /* xfer memory doesn't always reliably set errno. */ | |
972 | errno = 0; | |
973 | ||
974 | /* Try all levels of the target stack to see one can handle it. */ | |
975 | for (item = target_stack; item; item = item->next) | |
976 | { | |
977 | t = item->target_ops; | |
978 | if (!t->to_has_memory) | |
979 | continue; | |
980 | res = t->to_xfer_memory (memaddr, buf, len, write_p, t); | |
981 | if (res > 0) | |
982 | { | |
983 | /* Handled all or part of xfer */ | |
984 | *err = 0; | |
985 | return res; | |
986 | } | |
987 | if (t->to_has_all_memory) | |
988 | break; | |
989 | } | |
990 | ||
991 | /* Total failure. Return error. */ | |
992 | if (errno != 0) | |
993 | { | |
994 | *err = errno; | |
995 | return -1; | |
996 | } | |
997 | *err = EIO; | |
998 | return -1; | |
999 | } | |
1000 | ||
1001 | int | |
1002 | target_read_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err) | |
1003 | { | |
1004 | return target_xfer_memory_partial (memaddr, buf, len, 0, err); | |
1005 | } | |
1006 | ||
1007 | int | |
1008 | target_write_memory_partial (CORE_ADDR memaddr, char *buf, int len, int *err) | |
1009 | { | |
1010 | return target_xfer_memory_partial (memaddr, buf, len, 1, err); | |
1011 | } | |
1012 | ||
c906108c SS |
1013 | /* ARGSUSED */ |
1014 | static void | |
1015 | target_info (args, from_tty) | |
1016 | char *args; | |
1017 | int from_tty; | |
1018 | { | |
1019 | struct target_ops *t; | |
1020 | struct target_stack_item *item; | |
1021 | int has_all_mem = 0; | |
c5aa993b | 1022 | |
c906108c SS |
1023 | if (symfile_objfile != NULL) |
1024 | printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile->name); | |
1025 | ||
1026 | #ifdef FILES_INFO_HOOK | |
1027 | if (FILES_INFO_HOOK ()) | |
1028 | return; | |
1029 | #endif | |
1030 | ||
1031 | for (item = target_stack; item; item = item->next) | |
1032 | { | |
1033 | t = item->target_ops; | |
1034 | ||
1035 | if (!t->to_has_memory) | |
1036 | continue; | |
1037 | ||
c5aa993b | 1038 | if ((int) (t->to_stratum) <= (int) dummy_stratum) |
c906108c SS |
1039 | continue; |
1040 | if (has_all_mem) | |
c5aa993b JM |
1041 | printf_unfiltered ("\tWhile running this, GDB does not access memory from...\n"); |
1042 | printf_unfiltered ("%s:\n", t->to_longname); | |
1043 | (t->to_files_info) (t); | |
c906108c SS |
1044 | has_all_mem = t->to_has_all_memory; |
1045 | } | |
1046 | } | |
1047 | ||
1048 | /* This is to be called by the open routine before it does | |
1049 | anything. */ | |
1050 | ||
1051 | void | |
1052 | target_preopen (from_tty) | |
1053 | int from_tty; | |
1054 | { | |
c5aa993b | 1055 | dont_repeat (); |
c906108c SS |
1056 | |
1057 | if (target_has_execution) | |
c5aa993b | 1058 | { |
adf40b2e JM |
1059 | if (!from_tty |
1060 | || query ("A program is being debugged already. Kill it? ")) | |
c5aa993b | 1061 | target_kill (); |
c906108c | 1062 | else |
c5aa993b | 1063 | error ("Program not killed."); |
c906108c SS |
1064 | } |
1065 | ||
1066 | /* Calling target_kill may remove the target from the stack. But if | |
1067 | it doesn't (which seems like a win for UDI), remove it now. */ | |
1068 | ||
1069 | if (target_has_execution) | |
1070 | pop_target (); | |
1071 | } | |
1072 | ||
1073 | /* Detach a target after doing deferred register stores. */ | |
1074 | ||
1075 | void | |
1076 | target_detach (args, from_tty) | |
1077 | char *args; | |
1078 | int from_tty; | |
1079 | { | |
1080 | /* Handle any optimized stores to the inferior. */ | |
1081 | #ifdef DO_DEFERRED_STORES | |
1082 | DO_DEFERRED_STORES; | |
1083 | #endif | |
1084 | (current_target.to_detach) (args, from_tty); | |
1085 | } | |
1086 | ||
1087 | void | |
1088 | target_link (modname, t_reloc) | |
1089 | char *modname; | |
1090 | CORE_ADDR *t_reloc; | |
1091 | { | |
c5aa993b | 1092 | if (STREQ (current_target.to_shortname, "rombug")) |
c906108c SS |
1093 | { |
1094 | (current_target.to_lookup_symbol) (modname, t_reloc); | |
1095 | if (*t_reloc == 0) | |
c5aa993b | 1096 | error ("Unable to link to %s and get relocation in rombug", modname); |
c906108c SS |
1097 | } |
1098 | else | |
2acceee2 | 1099 | *t_reloc = (CORE_ADDR) -1; |
c906108c SS |
1100 | } |
1101 | ||
ed9a39eb JM |
1102 | int |
1103 | target_async_mask (int mask) | |
1104 | { | |
1105 | int saved_async_masked_status = target_async_mask_value; | |
1106 | target_async_mask_value = mask; | |
1107 | return saved_async_masked_status; | |
1108 | } | |
1109 | ||
c906108c SS |
1110 | /* Look through the list of possible targets for a target that can |
1111 | execute a run or attach command without any other data. This is | |
1112 | used to locate the default process stratum. | |
1113 | ||
1114 | Result is always valid (error() is called for errors). */ | |
1115 | ||
1116 | static struct target_ops * | |
1117 | find_default_run_target (do_mesg) | |
1118 | char *do_mesg; | |
1119 | { | |
1120 | struct target_ops **t; | |
1121 | struct target_ops *runable = NULL; | |
1122 | int count; | |
1123 | ||
1124 | count = 0; | |
1125 | ||
1126 | for (t = target_structs; t < target_structs + target_struct_size; | |
1127 | ++t) | |
1128 | { | |
c5aa993b | 1129 | if ((*t)->to_can_run && target_can_run (*t)) |
c906108c SS |
1130 | { |
1131 | runable = *t; | |
1132 | ++count; | |
1133 | } | |
1134 | } | |
1135 | ||
1136 | if (count != 1) | |
1137 | error ("Don't know how to %s. Try \"help target\".", do_mesg); | |
1138 | ||
1139 | return runable; | |
1140 | } | |
1141 | ||
1142 | void | |
1143 | find_default_attach (args, from_tty) | |
1144 | char *args; | |
1145 | int from_tty; | |
1146 | { | |
1147 | struct target_ops *t; | |
1148 | ||
c5aa993b | 1149 | t = find_default_run_target ("attach"); |
c906108c SS |
1150 | (t->to_attach) (args, from_tty); |
1151 | return; | |
1152 | } | |
1153 | ||
1154 | void | |
1155 | find_default_require_attach (args, from_tty) | |
1156 | char *args; | |
1157 | int from_tty; | |
1158 | { | |
1159 | struct target_ops *t; | |
1160 | ||
c5aa993b | 1161 | t = find_default_run_target ("require_attach"); |
c906108c SS |
1162 | (t->to_require_attach) (args, from_tty); |
1163 | return; | |
1164 | } | |
1165 | ||
1166 | void | |
1167 | find_default_require_detach (pid, args, from_tty) | |
c5aa993b JM |
1168 | int pid; |
1169 | char *args; | |
1170 | int from_tty; | |
c906108c SS |
1171 | { |
1172 | struct target_ops *t; | |
1173 | ||
c5aa993b | 1174 | t = find_default_run_target ("require_detach"); |
c906108c SS |
1175 | (t->to_require_detach) (pid, args, from_tty); |
1176 | return; | |
1177 | } | |
1178 | ||
1179 | void | |
1180 | find_default_create_inferior (exec_file, allargs, env) | |
1181 | char *exec_file; | |
1182 | char *allargs; | |
1183 | char **env; | |
1184 | { | |
1185 | struct target_ops *t; | |
1186 | ||
c5aa993b | 1187 | t = find_default_run_target ("run"); |
c906108c SS |
1188 | (t->to_create_inferior) (exec_file, allargs, env); |
1189 | return; | |
1190 | } | |
1191 | ||
1192 | void | |
1193 | find_default_clone_and_follow_inferior (child_pid, followed_child) | |
c5aa993b JM |
1194 | int child_pid; |
1195 | int *followed_child; | |
c906108c SS |
1196 | { |
1197 | struct target_ops *t; | |
1198 | ||
c5aa993b | 1199 | t = find_default_run_target ("run"); |
c906108c SS |
1200 | (t->to_clone_and_follow_inferior) (child_pid, followed_child); |
1201 | return; | |
1202 | } | |
1203 | ||
1204 | static int | |
1205 | return_zero () | |
1206 | { | |
1207 | return 0; | |
1208 | } | |
1209 | ||
1210 | static int | |
1211 | return_one () | |
1212 | { | |
1213 | return 1; | |
1214 | } | |
1215 | ||
6426a772 JM |
1216 | /* |
1217 | * Resize the to_sections pointer. Also make sure that anyone that | |
1218 | * was holding on to an old value of it gets updated. | |
1219 | * Returns the old size. | |
1220 | */ | |
1221 | ||
1222 | int | |
1223 | target_resize_to_sections (struct target_ops *target, int num_added) | |
1224 | { | |
1225 | struct target_ops **t; | |
1226 | struct section_table *old_value; | |
1227 | int old_count; | |
1228 | ||
1229 | old_value = target->to_sections; | |
1230 | ||
1231 | if (target->to_sections) | |
1232 | { | |
1233 | old_count = target->to_sections_end - target->to_sections; | |
1234 | target->to_sections = (struct section_table *) | |
1235 | xrealloc ((char *) target->to_sections, | |
1236 | (sizeof (struct section_table)) * (num_added + old_count)); | |
1237 | } | |
1238 | else | |
1239 | { | |
1240 | old_count = 0; | |
1241 | target->to_sections = (struct section_table *) | |
1242 | xmalloc ((sizeof (struct section_table)) * num_added); | |
1243 | } | |
1244 | target->to_sections_end = target->to_sections + (num_added + old_count); | |
1245 | ||
1246 | /* Check to see if anyone else was pointing to this structure. | |
1247 | If old_value was null, then no one was. */ | |
1248 | ||
1249 | if (old_value) | |
1250 | { | |
1251 | for (t = target_structs; t < target_structs + target_struct_size; | |
1252 | ++t) | |
1253 | { | |
1254 | if ((*t)->to_sections == old_value) | |
1255 | { | |
1256 | (*t)->to_sections = target->to_sections; | |
1257 | (*t)->to_sections_end = target->to_sections_end; | |
1258 | } | |
1259 | } | |
1260 | } | |
1261 | ||
1262 | return old_count; | |
1263 | ||
1264 | } | |
1265 | ||
07cd4b97 JB |
1266 | /* Remove all target sections taken from ABFD. |
1267 | ||
1268 | Scan the current target stack for targets whose section tables | |
1269 | refer to sections from BFD, and remove those sections. We use this | |
1270 | when we notice that the inferior has unloaded a shared object, for | |
1271 | example. */ | |
1272 | void | |
1273 | remove_target_sections (bfd *abfd) | |
1274 | { | |
1275 | struct target_ops **t; | |
1276 | ||
1277 | for (t = target_structs; t < target_structs + target_struct_size; t++) | |
1278 | { | |
1279 | struct section_table *src, *dest; | |
1280 | ||
1281 | dest = (*t)->to_sections; | |
1282 | for (src = (*t)->to_sections; src < (*t)->to_sections_end; src++) | |
1283 | if (src->bfd != abfd) | |
1284 | { | |
1285 | /* Keep this section. */ | |
1286 | if (dest < src) *dest = *src; | |
1287 | dest++; | |
1288 | } | |
1289 | ||
1290 | /* If we've dropped any sections, resize the section table. */ | |
1291 | if (dest < src) | |
1292 | target_resize_to_sections (*t, dest - src); | |
1293 | } | |
1294 | } | |
1295 | ||
1296 | ||
1297 | ||
1298 | ||
7a292a7a SS |
1299 | /* Find a single runnable target in the stack and return it. If for |
1300 | some reason there is more than one, return NULL. */ | |
1301 | ||
1302 | struct target_ops * | |
1303 | find_run_target () | |
1304 | { | |
1305 | struct target_ops **t; | |
1306 | struct target_ops *runable = NULL; | |
1307 | int count; | |
c5aa993b | 1308 | |
7a292a7a | 1309 | count = 0; |
c5aa993b | 1310 | |
7a292a7a SS |
1311 | for (t = target_structs; t < target_structs + target_struct_size; ++t) |
1312 | { | |
c5aa993b | 1313 | if ((*t)->to_can_run && target_can_run (*t)) |
7a292a7a SS |
1314 | { |
1315 | runable = *t; | |
1316 | ++count; | |
1317 | } | |
1318 | } | |
c5aa993b | 1319 | |
7a292a7a SS |
1320 | return (count == 1 ? runable : NULL); |
1321 | } | |
1322 | ||
ed9a39eb JM |
1323 | /* Find a single core_stratum target in the list of targets and return it. |
1324 | If for some reason there is more than one, return NULL. */ | |
1325 | ||
c906108c SS |
1326 | struct target_ops * |
1327 | find_core_target () | |
1328 | { | |
1329 | struct target_ops **t; | |
1330 | struct target_ops *runable = NULL; | |
1331 | int count; | |
c5aa993b | 1332 | |
c906108c | 1333 | count = 0; |
c5aa993b | 1334 | |
c906108c SS |
1335 | for (t = target_structs; t < target_structs + target_struct_size; |
1336 | ++t) | |
1337 | { | |
1338 | if ((*t)->to_stratum == core_stratum) | |
1339 | { | |
1340 | runable = *t; | |
1341 | ++count; | |
1342 | } | |
1343 | } | |
c5aa993b JM |
1344 | |
1345 | return (count == 1 ? runable : NULL); | |
c906108c | 1346 | } |
ed9a39eb JM |
1347 | |
1348 | /* | |
1349 | * Find the next target down the stack from the specified target. | |
1350 | */ | |
1351 | ||
1352 | struct target_ops * | |
1353 | find_target_beneath (t) | |
1354 | struct target_ops *t; | |
1355 | { | |
1356 | struct target_stack_item *cur; | |
1357 | ||
1358 | for (cur = target_stack; cur; cur = cur->next) | |
1359 | if (cur->target_ops == t) | |
1360 | break; | |
1361 | ||
1362 | if (cur == NULL || cur->next == NULL) | |
1363 | return NULL; | |
1364 | else | |
1365 | return cur->next->target_ops; | |
1366 | } | |
1367 | ||
c906108c SS |
1368 | \f |
1369 | /* The inferior process has died. Long live the inferior! */ | |
1370 | ||
1371 | void | |
1372 | generic_mourn_inferior () | |
1373 | { | |
1374 | extern int show_breakpoint_hit_counts; | |
1375 | ||
1376 | inferior_pid = 0; | |
1377 | attach_flag = 0; | |
1378 | breakpoint_init_inferior (inf_exited); | |
1379 | registers_changed (); | |
1380 | ||
1381 | #ifdef CLEAR_DEFERRED_STORES | |
1382 | /* Delete any pending stores to the inferior... */ | |
1383 | CLEAR_DEFERRED_STORES; | |
1384 | #endif | |
1385 | ||
1386 | reopen_exec_file (); | |
1387 | reinit_frame_cache (); | |
1388 | ||
1389 | /* It is confusing to the user for ignore counts to stick around | |
1390 | from previous runs of the inferior. So clear them. */ | |
1391 | /* However, it is more confusing for the ignore counts to disappear when | |
1392 | using hit counts. So don't clear them if we're counting hits. */ | |
1393 | if (!show_breakpoint_hit_counts) | |
1394 | breakpoint_clear_ignore_counts (); | |
1395 | } | |
1396 | \f | |
1397 | /* This table must match in order and size the signals in enum target_signal | |
1398 | in target.h. */ | |
9846de1b | 1399 | /* *INDENT-OFF* */ |
c906108c SS |
1400 | static struct { |
1401 | char *name; | |
1402 | char *string; | |
1403 | } signals [] = | |
1404 | { | |
1405 | {"0", "Signal 0"}, | |
1406 | {"SIGHUP", "Hangup"}, | |
1407 | {"SIGINT", "Interrupt"}, | |
1408 | {"SIGQUIT", "Quit"}, | |
1409 | {"SIGILL", "Illegal instruction"}, | |
1410 | {"SIGTRAP", "Trace/breakpoint trap"}, | |
1411 | {"SIGABRT", "Aborted"}, | |
1412 | {"SIGEMT", "Emulation trap"}, | |
1413 | {"SIGFPE", "Arithmetic exception"}, | |
1414 | {"SIGKILL", "Killed"}, | |
1415 | {"SIGBUS", "Bus error"}, | |
1416 | {"SIGSEGV", "Segmentation fault"}, | |
1417 | {"SIGSYS", "Bad system call"}, | |
1418 | {"SIGPIPE", "Broken pipe"}, | |
1419 | {"SIGALRM", "Alarm clock"}, | |
1420 | {"SIGTERM", "Terminated"}, | |
1421 | {"SIGURG", "Urgent I/O condition"}, | |
1422 | {"SIGSTOP", "Stopped (signal)"}, | |
1423 | {"SIGTSTP", "Stopped (user)"}, | |
1424 | {"SIGCONT", "Continued"}, | |
1425 | {"SIGCHLD", "Child status changed"}, | |
1426 | {"SIGTTIN", "Stopped (tty input)"}, | |
1427 | {"SIGTTOU", "Stopped (tty output)"}, | |
1428 | {"SIGIO", "I/O possible"}, | |
1429 | {"SIGXCPU", "CPU time limit exceeded"}, | |
1430 | {"SIGXFSZ", "File size limit exceeded"}, | |
1431 | {"SIGVTALRM", "Virtual timer expired"}, | |
1432 | {"SIGPROF", "Profiling timer expired"}, | |
1433 | {"SIGWINCH", "Window size changed"}, | |
1434 | {"SIGLOST", "Resource lost"}, | |
1435 | {"SIGUSR1", "User defined signal 1"}, | |
1436 | {"SIGUSR2", "User defined signal 2"}, | |
1437 | {"SIGPWR", "Power fail/restart"}, | |
1438 | {"SIGPOLL", "Pollable event occurred"}, | |
1439 | {"SIGWIND", "SIGWIND"}, | |
1440 | {"SIGPHONE", "SIGPHONE"}, | |
1441 | {"SIGWAITING", "Process's LWPs are blocked"}, | |
1442 | {"SIGLWP", "Signal LWP"}, | |
1443 | {"SIGDANGER", "Swap space dangerously low"}, | |
1444 | {"SIGGRANT", "Monitor mode granted"}, | |
1445 | {"SIGRETRACT", "Need to relinquish monitor mode"}, | |
1446 | {"SIGMSG", "Monitor mode data available"}, | |
1447 | {"SIGSOUND", "Sound completed"}, | |
1448 | {"SIGSAK", "Secure attention"}, | |
1449 | {"SIGPRIO", "SIGPRIO"}, | |
1450 | {"SIG33", "Real-time event 33"}, | |
1451 | {"SIG34", "Real-time event 34"}, | |
1452 | {"SIG35", "Real-time event 35"}, | |
1453 | {"SIG36", "Real-time event 36"}, | |
1454 | {"SIG37", "Real-time event 37"}, | |
1455 | {"SIG38", "Real-time event 38"}, | |
1456 | {"SIG39", "Real-time event 39"}, | |
1457 | {"SIG40", "Real-time event 40"}, | |
1458 | {"SIG41", "Real-time event 41"}, | |
1459 | {"SIG42", "Real-time event 42"}, | |
1460 | {"SIG43", "Real-time event 43"}, | |
1461 | {"SIG44", "Real-time event 44"}, | |
1462 | {"SIG45", "Real-time event 45"}, | |
1463 | {"SIG46", "Real-time event 46"}, | |
1464 | {"SIG47", "Real-time event 47"}, | |
1465 | {"SIG48", "Real-time event 48"}, | |
1466 | {"SIG49", "Real-time event 49"}, | |
1467 | {"SIG50", "Real-time event 50"}, | |
1468 | {"SIG51", "Real-time event 51"}, | |
1469 | {"SIG52", "Real-time event 52"}, | |
1470 | {"SIG53", "Real-time event 53"}, | |
1471 | {"SIG54", "Real-time event 54"}, | |
1472 | {"SIG55", "Real-time event 55"}, | |
1473 | {"SIG56", "Real-time event 56"}, | |
1474 | {"SIG57", "Real-time event 57"}, | |
1475 | {"SIG58", "Real-time event 58"}, | |
1476 | {"SIG59", "Real-time event 59"}, | |
1477 | {"SIG60", "Real-time event 60"}, | |
1478 | {"SIG61", "Real-time event 61"}, | |
1479 | {"SIG62", "Real-time event 62"}, | |
1480 | {"SIG63", "Real-time event 63"}, | |
cd0fc7c3 | 1481 | {"SIGCANCEL", "LWP internal signal"}, |
d4f3574e | 1482 | {"SIG32", "Real-time event 32"}, |
c906108c SS |
1483 | |
1484 | #if defined(MACH) || defined(__MACH__) | |
1485 | /* Mach exceptions */ | |
1486 | {"EXC_BAD_ACCESS", "Could not access memory"}, | |
1487 | {"EXC_BAD_INSTRUCTION", "Illegal instruction/operand"}, | |
1488 | {"EXC_ARITHMETIC", "Arithmetic exception"}, | |
1489 | {"EXC_EMULATION", "Emulation instruction"}, | |
1490 | {"EXC_SOFTWARE", "Software generated exception"}, | |
1491 | {"EXC_BREAKPOINT", "Breakpoint"}, | |
1492 | #endif | |
7a292a7a SS |
1493 | {"SIGINFO", "Information request"}, |
1494 | ||
c906108c SS |
1495 | {NULL, "Unknown signal"}, |
1496 | {NULL, "Internal error: printing TARGET_SIGNAL_DEFAULT"}, | |
1497 | ||
1498 | /* Last entry, used to check whether the table is the right size. */ | |
1499 | {NULL, "TARGET_SIGNAL_MAGIC"} | |
1500 | }; | |
9846de1b | 1501 | /* *INDENT-ON* */ |
c906108c | 1502 | |
c5aa993b JM |
1503 | |
1504 | ||
c906108c SS |
1505 | /* Return the string for a signal. */ |
1506 | char * | |
1507 | target_signal_to_string (sig) | |
1508 | enum target_signal sig; | |
1509 | { | |
7a292a7a SS |
1510 | if ((sig >= TARGET_SIGNAL_FIRST) && (sig <= TARGET_SIGNAL_LAST)) |
1511 | return signals[sig].string; | |
1512 | else | |
1513 | return signals[TARGET_SIGNAL_UNKNOWN].string; | |
c906108c SS |
1514 | } |
1515 | ||
1516 | /* Return the name for a signal. */ | |
1517 | char * | |
1518 | target_signal_to_name (sig) | |
1519 | enum target_signal sig; | |
1520 | { | |
1521 | if (sig == TARGET_SIGNAL_UNKNOWN) | |
1522 | /* I think the code which prints this will always print it along with | |
1523 | the string, so no need to be verbose. */ | |
1524 | return "?"; | |
1525 | return signals[sig].name; | |
1526 | } | |
1527 | ||
1528 | /* Given a name, return its signal. */ | |
1529 | enum target_signal | |
1530 | target_signal_from_name (name) | |
1531 | char *name; | |
1532 | { | |
1533 | enum target_signal sig; | |
1534 | ||
1535 | /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD" | |
1536 | for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more | |
1537 | questionable; seems like by now people should call it SIGABRT | |
1538 | instead. */ | |
1539 | ||
1540 | /* This ugly cast brought to you by the native VAX compiler. */ | |
1541 | for (sig = TARGET_SIGNAL_HUP; | |
1542 | signals[sig].name != NULL; | |
c5aa993b | 1543 | sig = (enum target_signal) ((int) sig + 1)) |
c906108c SS |
1544 | if (STREQ (name, signals[sig].name)) |
1545 | return sig; | |
1546 | return TARGET_SIGNAL_UNKNOWN; | |
1547 | } | |
1548 | \f | |
1549 | /* The following functions are to help certain targets deal | |
1550 | with the signal/waitstatus stuff. They could just as well be in | |
1551 | a file called native-utils.c or unixwaitstatus-utils.c or whatever. */ | |
1552 | ||
1553 | /* Convert host signal to our signals. */ | |
1554 | enum target_signal | |
1555 | target_signal_from_host (hostsig) | |
1556 | int hostsig; | |
1557 | { | |
1558 | /* A switch statement would make sense but would require special kludges | |
1559 | to deal with the cases where more than one signal has the same number. */ | |
1560 | ||
c5aa993b JM |
1561 | if (hostsig == 0) |
1562 | return TARGET_SIGNAL_0; | |
c906108c SS |
1563 | |
1564 | #if defined (SIGHUP) | |
c5aa993b JM |
1565 | if (hostsig == SIGHUP) |
1566 | return TARGET_SIGNAL_HUP; | |
c906108c SS |
1567 | #endif |
1568 | #if defined (SIGINT) | |
c5aa993b JM |
1569 | if (hostsig == SIGINT) |
1570 | return TARGET_SIGNAL_INT; | |
c906108c SS |
1571 | #endif |
1572 | #if defined (SIGQUIT) | |
c5aa993b JM |
1573 | if (hostsig == SIGQUIT) |
1574 | return TARGET_SIGNAL_QUIT; | |
c906108c SS |
1575 | #endif |
1576 | #if defined (SIGILL) | |
c5aa993b JM |
1577 | if (hostsig == SIGILL) |
1578 | return TARGET_SIGNAL_ILL; | |
c906108c SS |
1579 | #endif |
1580 | #if defined (SIGTRAP) | |
c5aa993b JM |
1581 | if (hostsig == SIGTRAP) |
1582 | return TARGET_SIGNAL_TRAP; | |
c906108c SS |
1583 | #endif |
1584 | #if defined (SIGABRT) | |
c5aa993b JM |
1585 | if (hostsig == SIGABRT) |
1586 | return TARGET_SIGNAL_ABRT; | |
c906108c SS |
1587 | #endif |
1588 | #if defined (SIGEMT) | |
c5aa993b JM |
1589 | if (hostsig == SIGEMT) |
1590 | return TARGET_SIGNAL_EMT; | |
c906108c SS |
1591 | #endif |
1592 | #if defined (SIGFPE) | |
c5aa993b JM |
1593 | if (hostsig == SIGFPE) |
1594 | return TARGET_SIGNAL_FPE; | |
c906108c SS |
1595 | #endif |
1596 | #if defined (SIGKILL) | |
c5aa993b JM |
1597 | if (hostsig == SIGKILL) |
1598 | return TARGET_SIGNAL_KILL; | |
c906108c SS |
1599 | #endif |
1600 | #if defined (SIGBUS) | |
c5aa993b JM |
1601 | if (hostsig == SIGBUS) |
1602 | return TARGET_SIGNAL_BUS; | |
c906108c SS |
1603 | #endif |
1604 | #if defined (SIGSEGV) | |
c5aa993b JM |
1605 | if (hostsig == SIGSEGV) |
1606 | return TARGET_SIGNAL_SEGV; | |
c906108c SS |
1607 | #endif |
1608 | #if defined (SIGSYS) | |
c5aa993b JM |
1609 | if (hostsig == SIGSYS) |
1610 | return TARGET_SIGNAL_SYS; | |
c906108c SS |
1611 | #endif |
1612 | #if defined (SIGPIPE) | |
c5aa993b JM |
1613 | if (hostsig == SIGPIPE) |
1614 | return TARGET_SIGNAL_PIPE; | |
c906108c SS |
1615 | #endif |
1616 | #if defined (SIGALRM) | |
c5aa993b JM |
1617 | if (hostsig == SIGALRM) |
1618 | return TARGET_SIGNAL_ALRM; | |
c906108c SS |
1619 | #endif |
1620 | #if defined (SIGTERM) | |
c5aa993b JM |
1621 | if (hostsig == SIGTERM) |
1622 | return TARGET_SIGNAL_TERM; | |
c906108c SS |
1623 | #endif |
1624 | #if defined (SIGUSR1) | |
c5aa993b JM |
1625 | if (hostsig == SIGUSR1) |
1626 | return TARGET_SIGNAL_USR1; | |
c906108c SS |
1627 | #endif |
1628 | #if defined (SIGUSR2) | |
c5aa993b JM |
1629 | if (hostsig == SIGUSR2) |
1630 | return TARGET_SIGNAL_USR2; | |
c906108c SS |
1631 | #endif |
1632 | #if defined (SIGCLD) | |
c5aa993b JM |
1633 | if (hostsig == SIGCLD) |
1634 | return TARGET_SIGNAL_CHLD; | |
c906108c SS |
1635 | #endif |
1636 | #if defined (SIGCHLD) | |
c5aa993b JM |
1637 | if (hostsig == SIGCHLD) |
1638 | return TARGET_SIGNAL_CHLD; | |
c906108c SS |
1639 | #endif |
1640 | #if defined (SIGPWR) | |
c5aa993b JM |
1641 | if (hostsig == SIGPWR) |
1642 | return TARGET_SIGNAL_PWR; | |
c906108c SS |
1643 | #endif |
1644 | #if defined (SIGWINCH) | |
c5aa993b JM |
1645 | if (hostsig == SIGWINCH) |
1646 | return TARGET_SIGNAL_WINCH; | |
c906108c SS |
1647 | #endif |
1648 | #if defined (SIGURG) | |
c5aa993b JM |
1649 | if (hostsig == SIGURG) |
1650 | return TARGET_SIGNAL_URG; | |
c906108c SS |
1651 | #endif |
1652 | #if defined (SIGIO) | |
c5aa993b JM |
1653 | if (hostsig == SIGIO) |
1654 | return TARGET_SIGNAL_IO; | |
c906108c SS |
1655 | #endif |
1656 | #if defined (SIGPOLL) | |
c5aa993b JM |
1657 | if (hostsig == SIGPOLL) |
1658 | return TARGET_SIGNAL_POLL; | |
c906108c SS |
1659 | #endif |
1660 | #if defined (SIGSTOP) | |
c5aa993b JM |
1661 | if (hostsig == SIGSTOP) |
1662 | return TARGET_SIGNAL_STOP; | |
c906108c SS |
1663 | #endif |
1664 | #if defined (SIGTSTP) | |
c5aa993b JM |
1665 | if (hostsig == SIGTSTP) |
1666 | return TARGET_SIGNAL_TSTP; | |
c906108c SS |
1667 | #endif |
1668 | #if defined (SIGCONT) | |
c5aa993b JM |
1669 | if (hostsig == SIGCONT) |
1670 | return TARGET_SIGNAL_CONT; | |
c906108c SS |
1671 | #endif |
1672 | #if defined (SIGTTIN) | |
c5aa993b JM |
1673 | if (hostsig == SIGTTIN) |
1674 | return TARGET_SIGNAL_TTIN; | |
c906108c SS |
1675 | #endif |
1676 | #if defined (SIGTTOU) | |
c5aa993b JM |
1677 | if (hostsig == SIGTTOU) |
1678 | return TARGET_SIGNAL_TTOU; | |
c906108c SS |
1679 | #endif |
1680 | #if defined (SIGVTALRM) | |
c5aa993b JM |
1681 | if (hostsig == SIGVTALRM) |
1682 | return TARGET_SIGNAL_VTALRM; | |
c906108c SS |
1683 | #endif |
1684 | #if defined (SIGPROF) | |
c5aa993b JM |
1685 | if (hostsig == SIGPROF) |
1686 | return TARGET_SIGNAL_PROF; | |
c906108c SS |
1687 | #endif |
1688 | #if defined (SIGXCPU) | |
c5aa993b JM |
1689 | if (hostsig == SIGXCPU) |
1690 | return TARGET_SIGNAL_XCPU; | |
c906108c SS |
1691 | #endif |
1692 | #if defined (SIGXFSZ) | |
c5aa993b JM |
1693 | if (hostsig == SIGXFSZ) |
1694 | return TARGET_SIGNAL_XFSZ; | |
c906108c SS |
1695 | #endif |
1696 | #if defined (SIGWIND) | |
c5aa993b JM |
1697 | if (hostsig == SIGWIND) |
1698 | return TARGET_SIGNAL_WIND; | |
c906108c SS |
1699 | #endif |
1700 | #if defined (SIGPHONE) | |
c5aa993b JM |
1701 | if (hostsig == SIGPHONE) |
1702 | return TARGET_SIGNAL_PHONE; | |
c906108c SS |
1703 | #endif |
1704 | #if defined (SIGLOST) | |
c5aa993b JM |
1705 | if (hostsig == SIGLOST) |
1706 | return TARGET_SIGNAL_LOST; | |
c906108c SS |
1707 | #endif |
1708 | #if defined (SIGWAITING) | |
c5aa993b JM |
1709 | if (hostsig == SIGWAITING) |
1710 | return TARGET_SIGNAL_WAITING; | |
c906108c | 1711 | #endif |
cd0fc7c3 | 1712 | #if defined (SIGCANCEL) |
c5aa993b JM |
1713 | if (hostsig == SIGCANCEL) |
1714 | return TARGET_SIGNAL_CANCEL; | |
cd0fc7c3 | 1715 | #endif |
c906108c | 1716 | #if defined (SIGLWP) |
c5aa993b JM |
1717 | if (hostsig == SIGLWP) |
1718 | return TARGET_SIGNAL_LWP; | |
c906108c SS |
1719 | #endif |
1720 | #if defined (SIGDANGER) | |
c5aa993b JM |
1721 | if (hostsig == SIGDANGER) |
1722 | return TARGET_SIGNAL_DANGER; | |
c906108c SS |
1723 | #endif |
1724 | #if defined (SIGGRANT) | |
c5aa993b JM |
1725 | if (hostsig == SIGGRANT) |
1726 | return TARGET_SIGNAL_GRANT; | |
c906108c SS |
1727 | #endif |
1728 | #if defined (SIGRETRACT) | |
c5aa993b JM |
1729 | if (hostsig == SIGRETRACT) |
1730 | return TARGET_SIGNAL_RETRACT; | |
c906108c SS |
1731 | #endif |
1732 | #if defined (SIGMSG) | |
c5aa993b JM |
1733 | if (hostsig == SIGMSG) |
1734 | return TARGET_SIGNAL_MSG; | |
c906108c SS |
1735 | #endif |
1736 | #if defined (SIGSOUND) | |
c5aa993b JM |
1737 | if (hostsig == SIGSOUND) |
1738 | return TARGET_SIGNAL_SOUND; | |
c906108c SS |
1739 | #endif |
1740 | #if defined (SIGSAK) | |
c5aa993b JM |
1741 | if (hostsig == SIGSAK) |
1742 | return TARGET_SIGNAL_SAK; | |
c906108c SS |
1743 | #endif |
1744 | #if defined (SIGPRIO) | |
c5aa993b JM |
1745 | if (hostsig == SIGPRIO) |
1746 | return TARGET_SIGNAL_PRIO; | |
c906108c SS |
1747 | #endif |
1748 | ||
1749 | /* Mach exceptions. Assumes that the values for EXC_ are positive! */ | |
1750 | #if defined (EXC_BAD_ACCESS) && defined (_NSIG) | |
c5aa993b JM |
1751 | if (hostsig == _NSIG + EXC_BAD_ACCESS) |
1752 | return TARGET_EXC_BAD_ACCESS; | |
c906108c SS |
1753 | #endif |
1754 | #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG) | |
c5aa993b JM |
1755 | if (hostsig == _NSIG + EXC_BAD_INSTRUCTION) |
1756 | return TARGET_EXC_BAD_INSTRUCTION; | |
c906108c SS |
1757 | #endif |
1758 | #if defined (EXC_ARITHMETIC) && defined (_NSIG) | |
c5aa993b JM |
1759 | if (hostsig == _NSIG + EXC_ARITHMETIC) |
1760 | return TARGET_EXC_ARITHMETIC; | |
c906108c SS |
1761 | #endif |
1762 | #if defined (EXC_EMULATION) && defined (_NSIG) | |
c5aa993b JM |
1763 | if (hostsig == _NSIG + EXC_EMULATION) |
1764 | return TARGET_EXC_EMULATION; | |
c906108c SS |
1765 | #endif |
1766 | #if defined (EXC_SOFTWARE) && defined (_NSIG) | |
c5aa993b JM |
1767 | if (hostsig == _NSIG + EXC_SOFTWARE) |
1768 | return TARGET_EXC_SOFTWARE; | |
c906108c SS |
1769 | #endif |
1770 | #if defined (EXC_BREAKPOINT) && defined (_NSIG) | |
c5aa993b JM |
1771 | if (hostsig == _NSIG + EXC_BREAKPOINT) |
1772 | return TARGET_EXC_BREAKPOINT; | |
c906108c SS |
1773 | #endif |
1774 | ||
7a292a7a | 1775 | #if defined (SIGINFO) |
c5aa993b JM |
1776 | if (hostsig == SIGINFO) |
1777 | return TARGET_SIGNAL_INFO; | |
7a292a7a SS |
1778 | #endif |
1779 | ||
c906108c SS |
1780 | #if defined (REALTIME_LO) |
1781 | if (hostsig >= REALTIME_LO && hostsig < REALTIME_HI) | |
d4f3574e SS |
1782 | { |
1783 | /* This block of TARGET_SIGNAL_REALTIME value is in order. */ | |
1784 | if (33 <= hostsig && hostsig <= 63) | |
1785 | return (enum target_signal) | |
1786 | (hostsig - 33 + (int) TARGET_SIGNAL_REALTIME_33); | |
1787 | else if (hostsig == 32) | |
1788 | return TARGET_SIGNAL_REALTIME_32; | |
1789 | else | |
1790 | error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal"); | |
1791 | } | |
c906108c SS |
1792 | #endif |
1793 | return TARGET_SIGNAL_UNKNOWN; | |
1794 | } | |
1795 | ||
c2d11a7d JM |
1796 | /* Convert a OURSIG (an enum target_signal) to the form used by the |
1797 | target operating system (refered to as the ``host'') or zero if the | |
1798 | equivalent host signal is not available. Set/clear OURSIG_OK | |
1799 | accordingly. */ | |
1800 | ||
1801 | static int | |
1802 | do_target_signal_to_host (enum target_signal oursig, | |
1803 | int *oursig_ok) | |
c906108c | 1804 | { |
c2d11a7d | 1805 | *oursig_ok = 1; |
c906108c SS |
1806 | switch (oursig) |
1807 | { | |
c5aa993b JM |
1808 | case TARGET_SIGNAL_0: |
1809 | return 0; | |
c906108c SS |
1810 | |
1811 | #if defined (SIGHUP) | |
c5aa993b JM |
1812 | case TARGET_SIGNAL_HUP: |
1813 | return SIGHUP; | |
c906108c SS |
1814 | #endif |
1815 | #if defined (SIGINT) | |
c5aa993b JM |
1816 | case TARGET_SIGNAL_INT: |
1817 | return SIGINT; | |
c906108c SS |
1818 | #endif |
1819 | #if defined (SIGQUIT) | |
c5aa993b JM |
1820 | case TARGET_SIGNAL_QUIT: |
1821 | return SIGQUIT; | |
c906108c SS |
1822 | #endif |
1823 | #if defined (SIGILL) | |
c5aa993b JM |
1824 | case TARGET_SIGNAL_ILL: |
1825 | return SIGILL; | |
c906108c SS |
1826 | #endif |
1827 | #if defined (SIGTRAP) | |
c5aa993b JM |
1828 | case TARGET_SIGNAL_TRAP: |
1829 | return SIGTRAP; | |
c906108c SS |
1830 | #endif |
1831 | #if defined (SIGABRT) | |
c5aa993b JM |
1832 | case TARGET_SIGNAL_ABRT: |
1833 | return SIGABRT; | |
c906108c SS |
1834 | #endif |
1835 | #if defined (SIGEMT) | |
c5aa993b JM |
1836 | case TARGET_SIGNAL_EMT: |
1837 | return SIGEMT; | |
c906108c SS |
1838 | #endif |
1839 | #if defined (SIGFPE) | |
c5aa993b JM |
1840 | case TARGET_SIGNAL_FPE: |
1841 | return SIGFPE; | |
c906108c SS |
1842 | #endif |
1843 | #if defined (SIGKILL) | |
c5aa993b JM |
1844 | case TARGET_SIGNAL_KILL: |
1845 | return SIGKILL; | |
c906108c SS |
1846 | #endif |
1847 | #if defined (SIGBUS) | |
c5aa993b JM |
1848 | case TARGET_SIGNAL_BUS: |
1849 | return SIGBUS; | |
c906108c SS |
1850 | #endif |
1851 | #if defined (SIGSEGV) | |
c5aa993b JM |
1852 | case TARGET_SIGNAL_SEGV: |
1853 | return SIGSEGV; | |
c906108c SS |
1854 | #endif |
1855 | #if defined (SIGSYS) | |
c5aa993b JM |
1856 | case TARGET_SIGNAL_SYS: |
1857 | return SIGSYS; | |
c906108c SS |
1858 | #endif |
1859 | #if defined (SIGPIPE) | |
c5aa993b JM |
1860 | case TARGET_SIGNAL_PIPE: |
1861 | return SIGPIPE; | |
c906108c SS |
1862 | #endif |
1863 | #if defined (SIGALRM) | |
c5aa993b JM |
1864 | case TARGET_SIGNAL_ALRM: |
1865 | return SIGALRM; | |
c906108c SS |
1866 | #endif |
1867 | #if defined (SIGTERM) | |
c5aa993b JM |
1868 | case TARGET_SIGNAL_TERM: |
1869 | return SIGTERM; | |
c906108c SS |
1870 | #endif |
1871 | #if defined (SIGUSR1) | |
c5aa993b JM |
1872 | case TARGET_SIGNAL_USR1: |
1873 | return SIGUSR1; | |
c906108c SS |
1874 | #endif |
1875 | #if defined (SIGUSR2) | |
c5aa993b JM |
1876 | case TARGET_SIGNAL_USR2: |
1877 | return SIGUSR2; | |
c906108c SS |
1878 | #endif |
1879 | #if defined (SIGCHLD) || defined (SIGCLD) | |
c5aa993b | 1880 | case TARGET_SIGNAL_CHLD: |
c906108c SS |
1881 | #if defined (SIGCHLD) |
1882 | return SIGCHLD; | |
1883 | #else | |
1884 | return SIGCLD; | |
1885 | #endif | |
1886 | #endif /* SIGCLD or SIGCHLD */ | |
1887 | #if defined (SIGPWR) | |
c5aa993b JM |
1888 | case TARGET_SIGNAL_PWR: |
1889 | return SIGPWR; | |
c906108c SS |
1890 | #endif |
1891 | #if defined (SIGWINCH) | |
c5aa993b JM |
1892 | case TARGET_SIGNAL_WINCH: |
1893 | return SIGWINCH; | |
c906108c SS |
1894 | #endif |
1895 | #if defined (SIGURG) | |
c5aa993b JM |
1896 | case TARGET_SIGNAL_URG: |
1897 | return SIGURG; | |
c906108c SS |
1898 | #endif |
1899 | #if defined (SIGIO) | |
c5aa993b JM |
1900 | case TARGET_SIGNAL_IO: |
1901 | return SIGIO; | |
c906108c SS |
1902 | #endif |
1903 | #if defined (SIGPOLL) | |
c5aa993b JM |
1904 | case TARGET_SIGNAL_POLL: |
1905 | return SIGPOLL; | |
c906108c SS |
1906 | #endif |
1907 | #if defined (SIGSTOP) | |
c5aa993b JM |
1908 | case TARGET_SIGNAL_STOP: |
1909 | return SIGSTOP; | |
c906108c SS |
1910 | #endif |
1911 | #if defined (SIGTSTP) | |
c5aa993b JM |
1912 | case TARGET_SIGNAL_TSTP: |
1913 | return SIGTSTP; | |
c906108c SS |
1914 | #endif |
1915 | #if defined (SIGCONT) | |
c5aa993b JM |
1916 | case TARGET_SIGNAL_CONT: |
1917 | return SIGCONT; | |
c906108c SS |
1918 | #endif |
1919 | #if defined (SIGTTIN) | |
c5aa993b JM |
1920 | case TARGET_SIGNAL_TTIN: |
1921 | return SIGTTIN; | |
c906108c SS |
1922 | #endif |
1923 | #if defined (SIGTTOU) | |
c5aa993b JM |
1924 | case TARGET_SIGNAL_TTOU: |
1925 | return SIGTTOU; | |
c906108c SS |
1926 | #endif |
1927 | #if defined (SIGVTALRM) | |
c5aa993b JM |
1928 | case TARGET_SIGNAL_VTALRM: |
1929 | return SIGVTALRM; | |
c906108c SS |
1930 | #endif |
1931 | #if defined (SIGPROF) | |
c5aa993b JM |
1932 | case TARGET_SIGNAL_PROF: |
1933 | return SIGPROF; | |
c906108c SS |
1934 | #endif |
1935 | #if defined (SIGXCPU) | |
c5aa993b JM |
1936 | case TARGET_SIGNAL_XCPU: |
1937 | return SIGXCPU; | |
c906108c SS |
1938 | #endif |
1939 | #if defined (SIGXFSZ) | |
c5aa993b JM |
1940 | case TARGET_SIGNAL_XFSZ: |
1941 | return SIGXFSZ; | |
c906108c SS |
1942 | #endif |
1943 | #if defined (SIGWIND) | |
c5aa993b JM |
1944 | case TARGET_SIGNAL_WIND: |
1945 | return SIGWIND; | |
c906108c SS |
1946 | #endif |
1947 | #if defined (SIGPHONE) | |
c5aa993b JM |
1948 | case TARGET_SIGNAL_PHONE: |
1949 | return SIGPHONE; | |
c906108c SS |
1950 | #endif |
1951 | #if defined (SIGLOST) | |
c5aa993b JM |
1952 | case TARGET_SIGNAL_LOST: |
1953 | return SIGLOST; | |
c906108c SS |
1954 | #endif |
1955 | #if defined (SIGWAITING) | |
c5aa993b JM |
1956 | case TARGET_SIGNAL_WAITING: |
1957 | return SIGWAITING; | |
c906108c | 1958 | #endif |
cd0fc7c3 | 1959 | #if defined (SIGCANCEL) |
c5aa993b JM |
1960 | case TARGET_SIGNAL_CANCEL: |
1961 | return SIGCANCEL; | |
cd0fc7c3 | 1962 | #endif |
c906108c | 1963 | #if defined (SIGLWP) |
c5aa993b JM |
1964 | case TARGET_SIGNAL_LWP: |
1965 | return SIGLWP; | |
c906108c SS |
1966 | #endif |
1967 | #if defined (SIGDANGER) | |
c5aa993b JM |
1968 | case TARGET_SIGNAL_DANGER: |
1969 | return SIGDANGER; | |
c906108c SS |
1970 | #endif |
1971 | #if defined (SIGGRANT) | |
c5aa993b JM |
1972 | case TARGET_SIGNAL_GRANT: |
1973 | return SIGGRANT; | |
c906108c SS |
1974 | #endif |
1975 | #if defined (SIGRETRACT) | |
c5aa993b JM |
1976 | case TARGET_SIGNAL_RETRACT: |
1977 | return SIGRETRACT; | |
c906108c SS |
1978 | #endif |
1979 | #if defined (SIGMSG) | |
c5aa993b JM |
1980 | case TARGET_SIGNAL_MSG: |
1981 | return SIGMSG; | |
c906108c SS |
1982 | #endif |
1983 | #if defined (SIGSOUND) | |
c5aa993b JM |
1984 | case TARGET_SIGNAL_SOUND: |
1985 | return SIGSOUND; | |
c906108c SS |
1986 | #endif |
1987 | #if defined (SIGSAK) | |
c5aa993b JM |
1988 | case TARGET_SIGNAL_SAK: |
1989 | return SIGSAK; | |
c906108c SS |
1990 | #endif |
1991 | #if defined (SIGPRIO) | |
c5aa993b JM |
1992 | case TARGET_SIGNAL_PRIO: |
1993 | return SIGPRIO; | |
c906108c SS |
1994 | #endif |
1995 | ||
1996 | /* Mach exceptions. Assumes that the values for EXC_ are positive! */ | |
1997 | #if defined (EXC_BAD_ACCESS) && defined (_NSIG) | |
c5aa993b JM |
1998 | case TARGET_EXC_BAD_ACCESS: |
1999 | return _NSIG + EXC_BAD_ACCESS; | |
c906108c SS |
2000 | #endif |
2001 | #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG) | |
c5aa993b JM |
2002 | case TARGET_EXC_BAD_INSTRUCTION: |
2003 | return _NSIG + EXC_BAD_INSTRUCTION; | |
c906108c SS |
2004 | #endif |
2005 | #if defined (EXC_ARITHMETIC) && defined (_NSIG) | |
c5aa993b JM |
2006 | case TARGET_EXC_ARITHMETIC: |
2007 | return _NSIG + EXC_ARITHMETIC; | |
c906108c SS |
2008 | #endif |
2009 | #if defined (EXC_EMULATION) && defined (_NSIG) | |
c5aa993b JM |
2010 | case TARGET_EXC_EMULATION: |
2011 | return _NSIG + EXC_EMULATION; | |
c906108c SS |
2012 | #endif |
2013 | #if defined (EXC_SOFTWARE) && defined (_NSIG) | |
c5aa993b JM |
2014 | case TARGET_EXC_SOFTWARE: |
2015 | return _NSIG + EXC_SOFTWARE; | |
c906108c SS |
2016 | #endif |
2017 | #if defined (EXC_BREAKPOINT) && defined (_NSIG) | |
c5aa993b JM |
2018 | case TARGET_EXC_BREAKPOINT: |
2019 | return _NSIG + EXC_BREAKPOINT; | |
c906108c SS |
2020 | #endif |
2021 | ||
7a292a7a | 2022 | #if defined (SIGINFO) |
c5aa993b JM |
2023 | case TARGET_SIGNAL_INFO: |
2024 | return SIGINFO; | |
7a292a7a SS |
2025 | #endif |
2026 | ||
c906108c SS |
2027 | default: |
2028 | #if defined (REALTIME_LO) | |
2029 | if (oursig >= TARGET_SIGNAL_REALTIME_33 | |
2030 | && oursig <= TARGET_SIGNAL_REALTIME_63) | |
2031 | { | |
e95a43ad MK |
2032 | /* This block of signals is continuous, and |
2033 | TARGET_SIGNAL_REALTIME_33 is 33 by definition. */ | |
c906108c | 2034 | int retsig = |
e95a43ad MK |
2035 | (int) oursig - (int) TARGET_SIGNAL_REALTIME_33 + 33; |
2036 | if (retsig >= REALTIME_LO && retsig < REALTIME_HI) | |
c906108c SS |
2037 | return retsig; |
2038 | } | |
e95a43ad MK |
2039 | #if (REALTIME_LO < 33) |
2040 | else if (oursig == TARGET_SIGNAL_REALTIME_32) | |
2041 | { | |
2042 | /* TARGET_SIGNAL_REALTIME_32 isn't contiguous with | |
2043 | TARGET_SIGNAL_REALTIME_33. It is 32 by definition. */ | |
2044 | return 32; | |
2045 | } | |
2046 | #endif | |
c906108c | 2047 | #endif |
c2d11a7d JM |
2048 | *oursig_ok = 0; |
2049 | return 0; | |
2050 | } | |
2051 | } | |
2052 | ||
2053 | int | |
2054 | target_signal_to_host_p (enum target_signal oursig) | |
2055 | { | |
2056 | int oursig_ok; | |
2057 | do_target_signal_to_host (oursig, &oursig_ok); | |
2058 | return oursig_ok; | |
2059 | } | |
2060 | ||
2061 | int | |
2062 | target_signal_to_host (enum target_signal oursig) | |
2063 | { | |
2064 | int oursig_ok; | |
2065 | int targ_signo = do_target_signal_to_host (oursig, &oursig_ok); | |
2066 | if (!oursig_ok) | |
2067 | { | |
c906108c | 2068 | /* The user might be trying to do "signal SIGSAK" where this system |
c5aa993b | 2069 | doesn't have SIGSAK. */ |
c906108c SS |
2070 | warning ("Signal %s does not exist on this system.\n", |
2071 | target_signal_to_name (oursig)); | |
2072 | return 0; | |
2073 | } | |
c2d11a7d JM |
2074 | else |
2075 | return targ_signo; | |
c906108c SS |
2076 | } |
2077 | ||
2078 | /* Helper function for child_wait and the Lynx derivatives of child_wait. | |
2079 | HOSTSTATUS is the waitstatus from wait() or the equivalent; store our | |
2080 | translation of that in OURSTATUS. */ | |
2081 | void | |
2082 | store_waitstatus (ourstatus, hoststatus) | |
2083 | struct target_waitstatus *ourstatus; | |
2084 | int hoststatus; | |
2085 | { | |
2086 | #ifdef CHILD_SPECIAL_WAITSTATUS | |
2087 | /* CHILD_SPECIAL_WAITSTATUS should return nonzero and set *OURSTATUS | |
2088 | if it wants to deal with hoststatus. */ | |
2089 | if (CHILD_SPECIAL_WAITSTATUS (ourstatus, hoststatus)) | |
2090 | return; | |
2091 | #endif | |
2092 | ||
2093 | if (WIFEXITED (hoststatus)) | |
2094 | { | |
2095 | ourstatus->kind = TARGET_WAITKIND_EXITED; | |
2096 | ourstatus->value.integer = WEXITSTATUS (hoststatus); | |
2097 | } | |
2098 | else if (!WIFSTOPPED (hoststatus)) | |
2099 | { | |
2100 | ourstatus->kind = TARGET_WAITKIND_SIGNALLED; | |
2101 | ourstatus->value.sig = target_signal_from_host (WTERMSIG (hoststatus)); | |
2102 | } | |
2103 | else | |
2104 | { | |
2105 | ourstatus->kind = TARGET_WAITKIND_STOPPED; | |
2106 | ourstatus->value.sig = target_signal_from_host (WSTOPSIG (hoststatus)); | |
2107 | } | |
2108 | } | |
2109 | \f | |
2110 | /* In some circumstances we allow a command to specify a numeric | |
2111 | signal. The idea is to keep these circumstances limited so that | |
2112 | users (and scripts) develop portable habits. For comparison, | |
2113 | POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a | |
2114 | numeric signal at all is obscelescent. We are slightly more | |
2115 | lenient and allow 1-15 which should match host signal numbers on | |
2116 | most systems. Use of symbolic signal names is strongly encouraged. */ | |
2117 | ||
2118 | enum target_signal | |
2119 | target_signal_from_command (num) | |
2120 | int num; | |
2121 | { | |
2122 | if (num >= 1 && num <= 15) | |
c5aa993b | 2123 | return (enum target_signal) num; |
c906108c SS |
2124 | error ("Only signals 1-15 are valid as numeric signals.\n\ |
2125 | Use \"info signals\" for a list of symbolic signals."); | |
2126 | } | |
2127 | \f | |
2128 | /* Returns zero to leave the inferior alone, one to interrupt it. */ | |
2129 | int (*target_activity_function) PARAMS ((void)); | |
2130 | int target_activity_fd; | |
2131 | \f | |
2132 | /* Convert a normal process ID to a string. Returns the string in a static | |
2133 | buffer. */ | |
2134 | ||
2135 | char * | |
2136 | normal_pid_to_str (pid) | |
2137 | int pid; | |
2138 | { | |
2139 | static char buf[30]; | |
2140 | ||
2141 | if (STREQ (current_target.to_shortname, "remote")) | |
104c1213 | 2142 | sprintf (buf, "thread %d", pid); |
c906108c | 2143 | else |
104c1213 | 2144 | sprintf (buf, "process %d", pid); |
c906108c SS |
2145 | |
2146 | return buf; | |
2147 | } | |
2148 | ||
2149 | /* Some targets (such as ttrace-based HPUX) don't allow us to request | |
2150 | notification of inferior events such as fork and vork immediately | |
2151 | after the inferior is created. (This because of how gdb gets an | |
2152 | inferior created via invoking a shell to do it. In such a scenario, | |
2153 | if the shell init file has commands in it, the shell will fork and | |
2154 | exec for each of those commands, and we will see each such fork | |
2155 | event. Very bad.) | |
c5aa993b | 2156 | |
c906108c SS |
2157 | This function is used by all targets that allow us to request |
2158 | notification of forks, etc at inferior creation time; e.g., in | |
2159 | target_acknowledge_forked_child. | |
c5aa993b | 2160 | */ |
392a587b | 2161 | static void |
c906108c | 2162 | normal_target_post_startup_inferior (pid) |
c5aa993b | 2163 | int pid; |
c906108c SS |
2164 | { |
2165 | /* This space intentionally left blank. */ | |
2166 | } | |
2167 | ||
2168 | /* Set up the handful of non-empty slots needed by the dummy target | |
2169 | vector. */ | |
2170 | ||
2171 | static void | |
2172 | init_dummy_target () | |
2173 | { | |
2174 | dummy_target.to_shortname = "None"; | |
2175 | dummy_target.to_longname = "None"; | |
2176 | dummy_target.to_doc = ""; | |
2177 | dummy_target.to_attach = find_default_attach; | |
2178 | dummy_target.to_require_attach = find_default_require_attach; | |
2179 | dummy_target.to_require_detach = find_default_require_detach; | |
2180 | dummy_target.to_create_inferior = find_default_create_inferior; | |
2181 | dummy_target.to_clone_and_follow_inferior = find_default_clone_and_follow_inferior; | |
ed9a39eb | 2182 | dummy_target.to_pid_to_str = normal_pid_to_str; |
c906108c SS |
2183 | dummy_target.to_stratum = dummy_stratum; |
2184 | dummy_target.to_magic = OPS_MAGIC; | |
2185 | } | |
c906108c | 2186 | \f |
c5aa993b | 2187 | |
c906108c SS |
2188 | static struct target_ops debug_target; |
2189 | ||
2190 | static void | |
2191 | debug_to_open (args, from_tty) | |
2192 | char *args; | |
2193 | int from_tty; | |
2194 | { | |
2195 | debug_target.to_open (args, from_tty); | |
2196 | ||
96baa820 | 2197 | fprintf_unfiltered (gdb_stdlog, "target_open (%s, %d)\n", args, from_tty); |
c906108c SS |
2198 | } |
2199 | ||
2200 | static void | |
2201 | debug_to_close (quitting) | |
2202 | int quitting; | |
2203 | { | |
2204 | debug_target.to_close (quitting); | |
2205 | ||
96baa820 | 2206 | fprintf_unfiltered (gdb_stdlog, "target_close (%d)\n", quitting); |
c906108c SS |
2207 | } |
2208 | ||
2209 | static void | |
2210 | debug_to_attach (args, from_tty) | |
2211 | char *args; | |
2212 | int from_tty; | |
2213 | { | |
2214 | debug_target.to_attach (args, from_tty); | |
2215 | ||
96baa820 | 2216 | fprintf_unfiltered (gdb_stdlog, "target_attach (%s, %d)\n", args, from_tty); |
c906108c SS |
2217 | } |
2218 | ||
2219 | ||
2220 | static void | |
2221 | debug_to_post_attach (pid) | |
c5aa993b | 2222 | int pid; |
c906108c SS |
2223 | { |
2224 | debug_target.to_post_attach (pid); | |
2225 | ||
96baa820 | 2226 | fprintf_unfiltered (gdb_stdlog, "target_post_attach (%d)\n", pid); |
c906108c SS |
2227 | } |
2228 | ||
2229 | static void | |
2230 | debug_to_require_attach (args, from_tty) | |
2231 | char *args; | |
2232 | int from_tty; | |
2233 | { | |
2234 | debug_target.to_require_attach (args, from_tty); | |
2235 | ||
96baa820 | 2236 | fprintf_unfiltered (gdb_stdlog, |
c906108c SS |
2237 | "target_require_attach (%s, %d)\n", args, from_tty); |
2238 | } | |
2239 | ||
2240 | static void | |
2241 | debug_to_detach (args, from_tty) | |
2242 | char *args; | |
2243 | int from_tty; | |
2244 | { | |
2245 | debug_target.to_detach (args, from_tty); | |
2246 | ||
96baa820 | 2247 | fprintf_unfiltered (gdb_stdlog, "target_detach (%s, %d)\n", args, from_tty); |
c906108c SS |
2248 | } |
2249 | ||
2250 | static void | |
2251 | debug_to_require_detach (pid, args, from_tty) | |
c5aa993b JM |
2252 | int pid; |
2253 | char *args; | |
2254 | int from_tty; | |
c906108c SS |
2255 | { |
2256 | debug_target.to_require_detach (pid, args, from_tty); | |
2257 | ||
96baa820 | 2258 | fprintf_unfiltered (gdb_stdlog, |
c5aa993b | 2259 | "target_require_detach (%d, %s, %d)\n", pid, args, from_tty); |
c906108c SS |
2260 | } |
2261 | ||
2262 | static void | |
2263 | debug_to_resume (pid, step, siggnal) | |
2264 | int pid; | |
2265 | int step; | |
2266 | enum target_signal siggnal; | |
2267 | { | |
2268 | debug_target.to_resume (pid, step, siggnal); | |
2269 | ||
96baa820 | 2270 | fprintf_unfiltered (gdb_stdlog, "target_resume (%d, %s, %s)\n", pid, |
c906108c SS |
2271 | step ? "step" : "continue", |
2272 | target_signal_to_name (siggnal)); | |
2273 | } | |
2274 | ||
2275 | static int | |
2276 | debug_to_wait (pid, status) | |
2277 | int pid; | |
2278 | struct target_waitstatus *status; | |
2279 | { | |
2280 | int retval; | |
2281 | ||
2282 | retval = debug_target.to_wait (pid, status); | |
2283 | ||
96baa820 | 2284 | fprintf_unfiltered (gdb_stdlog, |
c906108c | 2285 | "target_wait (%d, status) = %d, ", pid, retval); |
96baa820 | 2286 | fprintf_unfiltered (gdb_stdlog, "status->kind = "); |
c906108c SS |
2287 | switch (status->kind) |
2288 | { | |
2289 | case TARGET_WAITKIND_EXITED: | |
96baa820 | 2290 | fprintf_unfiltered (gdb_stdlog, "exited, status = %d\n", |
c906108c SS |
2291 | status->value.integer); |
2292 | break; | |
2293 | case TARGET_WAITKIND_STOPPED: | |
96baa820 | 2294 | fprintf_unfiltered (gdb_stdlog, "stopped, signal = %s\n", |
c906108c SS |
2295 | target_signal_to_name (status->value.sig)); |
2296 | break; | |
2297 | case TARGET_WAITKIND_SIGNALLED: | |
96baa820 | 2298 | fprintf_unfiltered (gdb_stdlog, "signalled, signal = %s\n", |
c906108c SS |
2299 | target_signal_to_name (status->value.sig)); |
2300 | break; | |
2301 | case TARGET_WAITKIND_LOADED: | |
96baa820 | 2302 | fprintf_unfiltered (gdb_stdlog, "loaded\n"); |
c906108c SS |
2303 | break; |
2304 | case TARGET_WAITKIND_FORKED: | |
96baa820 | 2305 | fprintf_unfiltered (gdb_stdlog, "forked\n"); |
c906108c SS |
2306 | break; |
2307 | case TARGET_WAITKIND_VFORKED: | |
96baa820 | 2308 | fprintf_unfiltered (gdb_stdlog, "vforked\n"); |
c906108c SS |
2309 | break; |
2310 | case TARGET_WAITKIND_EXECD: | |
96baa820 | 2311 | fprintf_unfiltered (gdb_stdlog, "execd\n"); |
c906108c SS |
2312 | break; |
2313 | case TARGET_WAITKIND_SPURIOUS: | |
96baa820 | 2314 | fprintf_unfiltered (gdb_stdlog, "spurious\n"); |
c906108c SS |
2315 | break; |
2316 | default: | |
96baa820 | 2317 | fprintf_unfiltered (gdb_stdlog, "unknown???\n"); |
c906108c SS |
2318 | break; |
2319 | } | |
2320 | ||
2321 | return retval; | |
2322 | } | |
2323 | ||
2324 | static void | |
2325 | debug_to_post_wait (pid, status) | |
c5aa993b JM |
2326 | int pid; |
2327 | int status; | |
c906108c SS |
2328 | { |
2329 | debug_target.to_post_wait (pid, status); | |
2330 | ||
96baa820 | 2331 | fprintf_unfiltered (gdb_stdlog, "target_post_wait (%d, %d)\n", |
c906108c SS |
2332 | pid, status); |
2333 | } | |
2334 | ||
2335 | static void | |
2336 | debug_to_fetch_registers (regno) | |
2337 | int regno; | |
2338 | { | |
2339 | debug_target.to_fetch_registers (regno); | |
2340 | ||
96baa820 | 2341 | fprintf_unfiltered (gdb_stdlog, "target_fetch_registers (%s)", |
c906108c SS |
2342 | regno != -1 ? REGISTER_NAME (regno) : "-1"); |
2343 | if (regno != -1) | |
104c1213 | 2344 | fprintf_unfiltered (gdb_stdlog, " = 0x%lx %ld", |
c906108c | 2345 | (unsigned long) read_register (regno), |
104c1213 | 2346 | (unsigned long) read_register (regno)); |
96baa820 | 2347 | fprintf_unfiltered (gdb_stdlog, "\n"); |
c906108c SS |
2348 | } |
2349 | ||
2350 | static void | |
2351 | debug_to_store_registers (regno) | |
2352 | int regno; | |
2353 | { | |
2354 | debug_target.to_store_registers (regno); | |
2355 | ||
2356 | if (regno >= 0 && regno < NUM_REGS) | |
104c1213 | 2357 | fprintf_unfiltered (gdb_stdlog, "target_store_registers (%s) = 0x%lx %ld\n", |
c906108c SS |
2358 | REGISTER_NAME (regno), |
2359 | (unsigned long) read_register (regno), | |
2360 | (unsigned long) read_register (regno)); | |
2361 | else | |
96baa820 | 2362 | fprintf_unfiltered (gdb_stdlog, "target_store_registers (%d)\n", regno); |
c906108c SS |
2363 | } |
2364 | ||
2365 | static void | |
2366 | debug_to_prepare_to_store () | |
2367 | { | |
2368 | debug_target.to_prepare_to_store (); | |
2369 | ||
96baa820 | 2370 | fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n"); |
c906108c SS |
2371 | } |
2372 | ||
2373 | static int | |
2374 | debug_to_xfer_memory (memaddr, myaddr, len, write, target) | |
2375 | CORE_ADDR memaddr; | |
2376 | char *myaddr; | |
2377 | int len; | |
2378 | int write; | |
2379 | struct target_ops *target; | |
2380 | { | |
2381 | int retval; | |
2382 | ||
2383 | retval = debug_target.to_xfer_memory (memaddr, myaddr, len, write, target); | |
2384 | ||
96baa820 | 2385 | fprintf_unfiltered (gdb_stdlog, |
c906108c | 2386 | "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d", |
c5aa993b | 2387 | (unsigned int) memaddr, /* possable truncate long long */ |
c906108c SS |
2388 | len, write ? "write" : "read", retval); |
2389 | ||
c5aa993b | 2390 | |
c906108c SS |
2391 | |
2392 | if (retval > 0) | |
2393 | { | |
2394 | int i; | |
2395 | ||
96baa820 | 2396 | fputs_unfiltered (", bytes =", gdb_stdlog); |
c906108c SS |
2397 | for (i = 0; i < retval; i++) |
2398 | { | |
2399 | if ((((long) &(myaddr[i])) & 0xf) == 0) | |
96baa820 JM |
2400 | fprintf_unfiltered (gdb_stdlog, "\n"); |
2401 | fprintf_unfiltered (gdb_stdlog, " %02x", myaddr[i] & 0xff); | |
c906108c SS |
2402 | } |
2403 | } | |
2404 | ||
96baa820 | 2405 | fputc_unfiltered ('\n', gdb_stdlog); |
c906108c SS |
2406 | |
2407 | return retval; | |
2408 | } | |
2409 | ||
2410 | static void | |
2411 | debug_to_files_info (target) | |
2412 | struct target_ops *target; | |
2413 | { | |
2414 | debug_target.to_files_info (target); | |
2415 | ||
96baa820 | 2416 | fprintf_unfiltered (gdb_stdlog, "target_files_info (xxx)\n"); |
c906108c SS |
2417 | } |
2418 | ||
2419 | static int | |
2420 | debug_to_insert_breakpoint (addr, save) | |
2421 | CORE_ADDR addr; | |
2422 | char *save; | |
2423 | { | |
2424 | int retval; | |
2425 | ||
2426 | retval = debug_target.to_insert_breakpoint (addr, save); | |
2427 | ||
96baa820 | 2428 | fprintf_unfiltered (gdb_stdlog, |
104c1213 JM |
2429 | "target_insert_breakpoint (0x%lx, xxx) = %ld\n", |
2430 | (unsigned long) addr, | |
2431 | (unsigned long) retval); | |
c906108c SS |
2432 | return retval; |
2433 | } | |
2434 | ||
2435 | static int | |
2436 | debug_to_remove_breakpoint (addr, save) | |
2437 | CORE_ADDR addr; | |
2438 | char *save; | |
2439 | { | |
2440 | int retval; | |
2441 | ||
2442 | retval = debug_target.to_remove_breakpoint (addr, save); | |
2443 | ||
96baa820 | 2444 | fprintf_unfiltered (gdb_stdlog, |
104c1213 JM |
2445 | "target_remove_breakpoint (0x%lx, xxx) = %ld\n", |
2446 | (unsigned long) addr, | |
2447 | (unsigned long) retval); | |
c906108c SS |
2448 | return retval; |
2449 | } | |
2450 | ||
2451 | static void | |
2452 | debug_to_terminal_init () | |
2453 | { | |
2454 | debug_target.to_terminal_init (); | |
2455 | ||
96baa820 | 2456 | fprintf_unfiltered (gdb_stdlog, "target_terminal_init ()\n"); |
c906108c SS |
2457 | } |
2458 | ||
2459 | static void | |
2460 | debug_to_terminal_inferior () | |
2461 | { | |
2462 | debug_target.to_terminal_inferior (); | |
2463 | ||
96baa820 | 2464 | fprintf_unfiltered (gdb_stdlog, "target_terminal_inferior ()\n"); |
c906108c SS |
2465 | } |
2466 | ||
2467 | static void | |
2468 | debug_to_terminal_ours_for_output () | |
2469 | { | |
2470 | debug_target.to_terminal_ours_for_output (); | |
2471 | ||
96baa820 | 2472 | fprintf_unfiltered (gdb_stdlog, "target_terminal_ours_for_output ()\n"); |
c906108c SS |
2473 | } |
2474 | ||
2475 | static void | |
2476 | debug_to_terminal_ours () | |
2477 | { | |
2478 | debug_target.to_terminal_ours (); | |
2479 | ||
96baa820 | 2480 | fprintf_unfiltered (gdb_stdlog, "target_terminal_ours ()\n"); |
c906108c SS |
2481 | } |
2482 | ||
2483 | static void | |
2484 | debug_to_terminal_info (arg, from_tty) | |
2485 | char *arg; | |
2486 | int from_tty; | |
2487 | { | |
2488 | debug_target.to_terminal_info (arg, from_tty); | |
2489 | ||
96baa820 | 2490 | fprintf_unfiltered (gdb_stdlog, "target_terminal_info (%s, %d)\n", arg, |
c906108c SS |
2491 | from_tty); |
2492 | } | |
2493 | ||
2494 | static void | |
2495 | debug_to_kill () | |
2496 | { | |
2497 | debug_target.to_kill (); | |
2498 | ||
96baa820 | 2499 | fprintf_unfiltered (gdb_stdlog, "target_kill ()\n"); |
c906108c SS |
2500 | } |
2501 | ||
2502 | static void | |
2503 | debug_to_load (args, from_tty) | |
2504 | char *args; | |
2505 | int from_tty; | |
2506 | { | |
2507 | debug_target.to_load (args, from_tty); | |
2508 | ||
96baa820 | 2509 | fprintf_unfiltered (gdb_stdlog, "target_load (%s, %d)\n", args, from_tty); |
c906108c SS |
2510 | } |
2511 | ||
2512 | static int | |
2513 | debug_to_lookup_symbol (name, addrp) | |
2514 | char *name; | |
2515 | CORE_ADDR *addrp; | |
2516 | { | |
2517 | int retval; | |
2518 | ||
2519 | retval = debug_target.to_lookup_symbol (name, addrp); | |
2520 | ||
96baa820 | 2521 | fprintf_unfiltered (gdb_stdlog, "target_lookup_symbol (%s, xxx)\n", name); |
c906108c SS |
2522 | |
2523 | return retval; | |
2524 | } | |
2525 | ||
2526 | static void | |
2527 | debug_to_create_inferior (exec_file, args, env) | |
2528 | char *exec_file; | |
2529 | char *args; | |
2530 | char **env; | |
2531 | { | |
2532 | debug_target.to_create_inferior (exec_file, args, env); | |
2533 | ||
96baa820 | 2534 | fprintf_unfiltered (gdb_stdlog, "target_create_inferior (%s, %s, xxx)\n", |
c906108c SS |
2535 | exec_file, args); |
2536 | } | |
2537 | ||
2538 | static void | |
2539 | debug_to_post_startup_inferior (pid) | |
c5aa993b | 2540 | int pid; |
c906108c SS |
2541 | { |
2542 | debug_target.to_post_startup_inferior (pid); | |
2543 | ||
96baa820 | 2544 | fprintf_unfiltered (gdb_stdlog, "target_post_startup_inferior (%d)\n", |
c906108c SS |
2545 | pid); |
2546 | } | |
2547 | ||
2548 | static void | |
2549 | debug_to_acknowledge_created_inferior (pid) | |
c5aa993b | 2550 | int pid; |
c906108c SS |
2551 | { |
2552 | debug_target.to_acknowledge_created_inferior (pid); | |
2553 | ||
96baa820 | 2554 | fprintf_unfiltered (gdb_stdlog, "target_acknowledge_created_inferior (%d)\n", |
c906108c SS |
2555 | pid); |
2556 | } | |
2557 | ||
2558 | static void | |
2559 | debug_to_clone_and_follow_inferior (child_pid, followed_child) | |
c5aa993b JM |
2560 | int child_pid; |
2561 | int *followed_child; | |
c906108c SS |
2562 | { |
2563 | debug_target.to_clone_and_follow_inferior (child_pid, followed_child); | |
2564 | ||
96baa820 | 2565 | fprintf_unfiltered (gdb_stdlog, |
c906108c SS |
2566 | "target_clone_and_follow_inferior (%d, %d)\n", |
2567 | child_pid, *followed_child); | |
2568 | } | |
2569 | ||
2570 | static void | |
2571 | debug_to_post_follow_inferior_by_clone () | |
2572 | { | |
2573 | debug_target.to_post_follow_inferior_by_clone (); | |
2574 | ||
96baa820 | 2575 | fprintf_unfiltered (gdb_stdlog, "target_post_follow_inferior_by_clone ()\n"); |
c906108c SS |
2576 | } |
2577 | ||
2578 | static int | |
2579 | debug_to_insert_fork_catchpoint (pid) | |
c5aa993b | 2580 | int pid; |
c906108c | 2581 | { |
c5aa993b | 2582 | int retval; |
c906108c SS |
2583 | |
2584 | retval = debug_target.to_insert_fork_catchpoint (pid); | |
2585 | ||
96baa820 | 2586 | fprintf_unfiltered (gdb_stdlog, "target_insert_fork_catchpoint (%d) = %d\n", |
c5aa993b | 2587 | pid, retval); |
c906108c SS |
2588 | |
2589 | return retval; | |
2590 | } | |
2591 | ||
2592 | static int | |
2593 | debug_to_remove_fork_catchpoint (pid) | |
c5aa993b | 2594 | int pid; |
c906108c | 2595 | { |
c5aa993b | 2596 | int retval; |
c906108c SS |
2597 | |
2598 | retval = debug_target.to_remove_fork_catchpoint (pid); | |
2599 | ||
96baa820 | 2600 | fprintf_unfiltered (gdb_stdlog, "target_remove_fork_catchpoint (%d) = %d\n", |
c5aa993b | 2601 | pid, retval); |
c906108c SS |
2602 | |
2603 | return retval; | |
2604 | } | |
2605 | ||
2606 | static int | |
2607 | debug_to_insert_vfork_catchpoint (pid) | |
c5aa993b | 2608 | int pid; |
c906108c | 2609 | { |
c5aa993b | 2610 | int retval; |
c906108c SS |
2611 | |
2612 | retval = debug_target.to_insert_vfork_catchpoint (pid); | |
2613 | ||
96baa820 | 2614 | fprintf_unfiltered (gdb_stdlog, "target_insert_vfork_catchpoint (%d)= %d\n", |
c5aa993b | 2615 | pid, retval); |
c906108c SS |
2616 | |
2617 | return retval; | |
2618 | } | |
2619 | ||
2620 | static int | |
2621 | debug_to_remove_vfork_catchpoint (pid) | |
c5aa993b | 2622 | int pid; |
c906108c | 2623 | { |
c5aa993b | 2624 | int retval; |
c906108c SS |
2625 | |
2626 | retval = debug_target.to_remove_vfork_catchpoint (pid); | |
2627 | ||
96baa820 | 2628 | fprintf_unfiltered (gdb_stdlog, "target_remove_vfork_catchpoint (%d) = %d\n", |
c5aa993b | 2629 | pid, retval); |
c906108c SS |
2630 | |
2631 | return retval; | |
2632 | } | |
2633 | ||
2634 | static int | |
2635 | debug_to_has_forked (pid, child_pid) | |
c5aa993b JM |
2636 | int pid; |
2637 | int *child_pid; | |
c906108c | 2638 | { |
c5aa993b | 2639 | int has_forked; |
c906108c SS |
2640 | |
2641 | has_forked = debug_target.to_has_forked (pid, child_pid); | |
2642 | ||
96baa820 | 2643 | fprintf_unfiltered (gdb_stdlog, "target_has_forked (%d, %d) = %d\n", |
c5aa993b | 2644 | pid, *child_pid, has_forked); |
c906108c SS |
2645 | |
2646 | return has_forked; | |
2647 | } | |
2648 | ||
2649 | static int | |
2650 | debug_to_has_vforked (pid, child_pid) | |
c5aa993b JM |
2651 | int pid; |
2652 | int *child_pid; | |
c906108c | 2653 | { |
c5aa993b | 2654 | int has_vforked; |
c906108c SS |
2655 | |
2656 | has_vforked = debug_target.to_has_vforked (pid, child_pid); | |
2657 | ||
96baa820 | 2658 | fprintf_unfiltered (gdb_stdlog, "target_has_vforked (%d, %d) = %d\n", |
c5aa993b | 2659 | pid, *child_pid, has_vforked); |
c906108c SS |
2660 | |
2661 | return has_vforked; | |
2662 | } | |
2663 | ||
2664 | static int | |
2665 | debug_to_can_follow_vfork_prior_to_exec () | |
2666 | { | |
c5aa993b | 2667 | int can_immediately_follow_vfork; |
c906108c SS |
2668 | |
2669 | can_immediately_follow_vfork = debug_target.to_can_follow_vfork_prior_to_exec (); | |
2670 | ||
96baa820 | 2671 | fprintf_unfiltered (gdb_stdlog, "target_can_follow_vfork_prior_to_exec () = %d\n", |
c5aa993b | 2672 | can_immediately_follow_vfork); |
c906108c SS |
2673 | |
2674 | return can_immediately_follow_vfork; | |
2675 | } | |
2676 | ||
2677 | static void | |
2678 | debug_to_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child) | |
c5aa993b JM |
2679 | int parent_pid; |
2680 | int followed_parent; | |
2681 | int child_pid; | |
2682 | int followed_child; | |
c906108c SS |
2683 | { |
2684 | debug_target.to_post_follow_vfork (parent_pid, followed_parent, child_pid, followed_child); | |
2685 | ||
96baa820 | 2686 | fprintf_unfiltered (gdb_stdlog, |
c906108c | 2687 | "target_post_follow_vfork (%d, %d, %d, %d)\n", |
c5aa993b | 2688 | parent_pid, followed_parent, child_pid, followed_child); |
c906108c SS |
2689 | } |
2690 | ||
2691 | static int | |
2692 | debug_to_insert_exec_catchpoint (pid) | |
c5aa993b | 2693 | int pid; |
c906108c | 2694 | { |
c5aa993b | 2695 | int retval; |
c906108c SS |
2696 | |
2697 | retval = debug_target.to_insert_exec_catchpoint (pid); | |
2698 | ||
96baa820 | 2699 | fprintf_unfiltered (gdb_stdlog, "target_insert_exec_catchpoint (%d) = %d\n", |
c5aa993b | 2700 | pid, retval); |
c906108c SS |
2701 | |
2702 | return retval; | |
2703 | } | |
2704 | ||
2705 | static int | |
2706 | debug_to_remove_exec_catchpoint (pid) | |
c5aa993b | 2707 | int pid; |
c906108c | 2708 | { |
c5aa993b | 2709 | int retval; |
c906108c SS |
2710 | |
2711 | retval = debug_target.to_remove_exec_catchpoint (pid); | |
2712 | ||
96baa820 | 2713 | fprintf_unfiltered (gdb_stdlog, "target_remove_exec_catchpoint (%d) = %d\n", |
c5aa993b | 2714 | pid, retval); |
c906108c SS |
2715 | |
2716 | return retval; | |
2717 | } | |
2718 | ||
2719 | static int | |
2720 | debug_to_has_execd (pid, execd_pathname) | |
c5aa993b JM |
2721 | int pid; |
2722 | char **execd_pathname; | |
c906108c | 2723 | { |
c5aa993b | 2724 | int has_execd; |
c906108c SS |
2725 | |
2726 | has_execd = debug_target.to_has_execd (pid, execd_pathname); | |
2727 | ||
96baa820 | 2728 | fprintf_unfiltered (gdb_stdlog, "target_has_execd (%d, %s) = %d\n", |
c5aa993b | 2729 | pid, (*execd_pathname ? *execd_pathname : "<NULL>"), |
7a292a7a | 2730 | has_execd); |
c906108c SS |
2731 | |
2732 | return has_execd; | |
2733 | } | |
2734 | ||
2735 | static int | |
2736 | debug_to_reported_exec_events_per_exec_call () | |
2737 | { | |
c5aa993b | 2738 | int reported_exec_events; |
c906108c SS |
2739 | |
2740 | reported_exec_events = debug_target.to_reported_exec_events_per_exec_call (); | |
2741 | ||
96baa820 | 2742 | fprintf_unfiltered (gdb_stdlog, |
c906108c | 2743 | "target_reported_exec_events_per_exec_call () = %d\n", |
c5aa993b | 2744 | reported_exec_events); |
c906108c SS |
2745 | |
2746 | return reported_exec_events; | |
2747 | } | |
2748 | ||
2749 | static int | |
2750 | debug_to_has_syscall_event (pid, kind, syscall_id) | |
c5aa993b JM |
2751 | int pid; |
2752 | enum target_waitkind *kind; | |
2753 | int *syscall_id; | |
c906108c | 2754 | { |
c5aa993b JM |
2755 | int has_syscall_event; |
2756 | char *kind_spelling = "??"; | |
c906108c SS |
2757 | |
2758 | has_syscall_event = debug_target.to_has_syscall_event (pid, kind, syscall_id); | |
2759 | if (has_syscall_event) | |
2760 | { | |
2761 | switch (*kind) | |
c5aa993b JM |
2762 | { |
2763 | case TARGET_WAITKIND_SYSCALL_ENTRY: | |
2764 | kind_spelling = "SYSCALL_ENTRY"; | |
2765 | break; | |
2766 | case TARGET_WAITKIND_SYSCALL_RETURN: | |
2767 | kind_spelling = "SYSCALL_RETURN"; | |
2768 | break; | |
2769 | default: | |
2770 | break; | |
2771 | } | |
c906108c SS |
2772 | } |
2773 | ||
96baa820 | 2774 | fprintf_unfiltered (gdb_stdlog, |
c906108c | 2775 | "target_has_syscall_event (%d, %s, %d) = %d\n", |
c5aa993b | 2776 | pid, kind_spelling, *syscall_id, has_syscall_event); |
c906108c SS |
2777 | |
2778 | return has_syscall_event; | |
2779 | } | |
2780 | ||
2781 | static int | |
2782 | debug_to_has_exited (pid, wait_status, exit_status) | |
c5aa993b JM |
2783 | int pid; |
2784 | int wait_status; | |
2785 | int *exit_status; | |
c906108c | 2786 | { |
c5aa993b | 2787 | int has_exited; |
c906108c SS |
2788 | |
2789 | has_exited = debug_target.to_has_exited (pid, wait_status, exit_status); | |
2790 | ||
96baa820 | 2791 | fprintf_unfiltered (gdb_stdlog, "target_has_exited (%d, %d, %d) = %d\n", |
c5aa993b | 2792 | pid, wait_status, *exit_status, has_exited); |
c906108c SS |
2793 | |
2794 | return has_exited; | |
2795 | } | |
2796 | ||
2797 | static void | |
2798 | debug_to_mourn_inferior () | |
2799 | { | |
2800 | debug_target.to_mourn_inferior (); | |
2801 | ||
96baa820 | 2802 | fprintf_unfiltered (gdb_stdlog, "target_mourn_inferior ()\n"); |
c906108c SS |
2803 | } |
2804 | ||
2805 | static int | |
2806 | debug_to_can_run () | |
2807 | { | |
2808 | int retval; | |
2809 | ||
2810 | retval = debug_target.to_can_run (); | |
2811 | ||
96baa820 | 2812 | fprintf_unfiltered (gdb_stdlog, "target_can_run () = %d\n", retval); |
c906108c SS |
2813 | |
2814 | return retval; | |
2815 | } | |
2816 | ||
2817 | static void | |
2818 | debug_to_notice_signals (pid) | |
2819 | int pid; | |
2820 | { | |
2821 | debug_target.to_notice_signals (pid); | |
2822 | ||
96baa820 | 2823 | fprintf_unfiltered (gdb_stdlog, "target_notice_signals (%d)\n", pid); |
c906108c SS |
2824 | } |
2825 | ||
2826 | static int | |
2827 | debug_to_thread_alive (pid) | |
2828 | int pid; | |
2829 | { | |
2830 | int retval; | |
2831 | ||
2832 | retval = debug_target.to_thread_alive (pid); | |
2833 | ||
96baa820 | 2834 | fprintf_unfiltered (gdb_stdlog, "target_thread_alive (%d) = %d\n", |
c906108c SS |
2835 | pid, retval); |
2836 | ||
2837 | return retval; | |
2838 | } | |
2839 | ||
0d06e24b JM |
2840 | static void |
2841 | debug_to_find_new_threads () | |
2842 | { | |
2843 | debug_target.to_find_new_threads (); | |
2844 | ||
2845 | fputs_unfiltered ("target_find_new_threads ()\n", gdb_stdlog); | |
2846 | } | |
2847 | ||
c906108c SS |
2848 | static void |
2849 | debug_to_stop () | |
2850 | { | |
2851 | debug_target.to_stop (); | |
2852 | ||
96baa820 | 2853 | fprintf_unfiltered (gdb_stdlog, "target_stop ()\n"); |
c906108c SS |
2854 | } |
2855 | ||
2856 | static int | |
2857 | debug_to_query (type, req, resp, siz) | |
c5aa993b JM |
2858 | int type; |
2859 | char *req; | |
2860 | char *resp; | |
2861 | int *siz; | |
c906108c SS |
2862 | { |
2863 | int retval; | |
2864 | ||
2865 | retval = debug_target.to_query (type, req, resp, siz); | |
2866 | ||
96baa820 | 2867 | fprintf_unfiltered (gdb_stdlog, "target_query (%c, %s, %s, %d) = %d\n", type, req, resp, *siz, retval); |
c906108c SS |
2868 | |
2869 | return retval; | |
2870 | } | |
2871 | ||
96baa820 JM |
2872 | static void |
2873 | debug_to_rcmd (char *command, | |
d9fcf2fb | 2874 | struct ui_file *outbuf) |
96baa820 JM |
2875 | { |
2876 | debug_target.to_rcmd (command, outbuf); | |
2877 | fprintf_unfiltered (gdb_stdlog, "target_rcmd (%s, ...)\n", command); | |
2878 | } | |
2879 | ||
c906108c SS |
2880 | static struct symtab_and_line * |
2881 | debug_to_enable_exception_callback (kind, enable) | |
c5aa993b JM |
2882 | enum exception_event_kind kind; |
2883 | int enable; | |
c906108c | 2884 | { |
7a292a7a SS |
2885 | struct symtab_and_line *result; |
2886 | result = debug_target.to_enable_exception_callback (kind, enable); | |
96baa820 | 2887 | fprintf_unfiltered (gdb_stdlog, |
c906108c SS |
2888 | "target get_exception_callback_sal (%d, %d)\n", |
2889 | kind, enable); | |
7a292a7a | 2890 | return result; |
c906108c SS |
2891 | } |
2892 | ||
2893 | static struct exception_event_record * | |
2894 | debug_to_get_current_exception_event () | |
2895 | { | |
7a292a7a | 2896 | struct exception_event_record *result; |
c5aa993b | 2897 | result = debug_target.to_get_current_exception_event (); |
96baa820 | 2898 | fprintf_unfiltered (gdb_stdlog, "target get_current_exception_event ()\n"); |
7a292a7a | 2899 | return result; |
c906108c SS |
2900 | } |
2901 | ||
2902 | static char * | |
2903 | debug_to_pid_to_exec_file (pid) | |
c5aa993b | 2904 | int pid; |
c906108c | 2905 | { |
c5aa993b | 2906 | char *exec_file; |
c906108c SS |
2907 | |
2908 | exec_file = debug_target.to_pid_to_exec_file (pid); | |
2909 | ||
96baa820 | 2910 | fprintf_unfiltered (gdb_stdlog, "target_pid_to_exec_file (%d) = %s\n", |
c5aa993b | 2911 | pid, exec_file); |
c906108c SS |
2912 | |
2913 | return exec_file; | |
2914 | } | |
2915 | ||
2916 | static char * | |
2917 | debug_to_core_file_to_sym_file (core) | |
c5aa993b | 2918 | char *core; |
c906108c | 2919 | { |
c5aa993b | 2920 | char *sym_file; |
c906108c SS |
2921 | |
2922 | sym_file = debug_target.to_core_file_to_sym_file (core); | |
2923 | ||
96baa820 | 2924 | fprintf_unfiltered (gdb_stdlog, "target_core_file_to_sym_file (%s) = %s\n", |
c5aa993b | 2925 | core, sym_file); |
c906108c SS |
2926 | |
2927 | return sym_file; | |
2928 | } | |
2929 | ||
2930 | static void | |
2931 | setup_target_debug () | |
2932 | { | |
2933 | memcpy (&debug_target, ¤t_target, sizeof debug_target); | |
2934 | ||
2935 | current_target.to_open = debug_to_open; | |
2936 | current_target.to_close = debug_to_close; | |
2937 | current_target.to_attach = debug_to_attach; | |
2938 | current_target.to_post_attach = debug_to_post_attach; | |
2939 | current_target.to_require_attach = debug_to_require_attach; | |
2940 | current_target.to_detach = debug_to_detach; | |
2941 | current_target.to_require_detach = debug_to_require_detach; | |
2942 | current_target.to_resume = debug_to_resume; | |
2943 | current_target.to_wait = debug_to_wait; | |
2944 | current_target.to_post_wait = debug_to_post_wait; | |
2945 | current_target.to_fetch_registers = debug_to_fetch_registers; | |
2946 | current_target.to_store_registers = debug_to_store_registers; | |
2947 | current_target.to_prepare_to_store = debug_to_prepare_to_store; | |
2948 | current_target.to_xfer_memory = debug_to_xfer_memory; | |
2949 | current_target.to_files_info = debug_to_files_info; | |
2950 | current_target.to_insert_breakpoint = debug_to_insert_breakpoint; | |
2951 | current_target.to_remove_breakpoint = debug_to_remove_breakpoint; | |
2952 | current_target.to_terminal_init = debug_to_terminal_init; | |
2953 | current_target.to_terminal_inferior = debug_to_terminal_inferior; | |
2954 | current_target.to_terminal_ours_for_output = debug_to_terminal_ours_for_output; | |
2955 | current_target.to_terminal_ours = debug_to_terminal_ours; | |
2956 | current_target.to_terminal_info = debug_to_terminal_info; | |
2957 | current_target.to_kill = debug_to_kill; | |
2958 | current_target.to_load = debug_to_load; | |
2959 | current_target.to_lookup_symbol = debug_to_lookup_symbol; | |
2960 | current_target.to_create_inferior = debug_to_create_inferior; | |
2961 | current_target.to_post_startup_inferior = debug_to_post_startup_inferior; | |
2962 | current_target.to_acknowledge_created_inferior = debug_to_acknowledge_created_inferior; | |
2963 | current_target.to_clone_and_follow_inferior = debug_to_clone_and_follow_inferior; | |
2964 | current_target.to_post_follow_inferior_by_clone = debug_to_post_follow_inferior_by_clone; | |
2965 | current_target.to_insert_fork_catchpoint = debug_to_insert_fork_catchpoint; | |
2966 | current_target.to_remove_fork_catchpoint = debug_to_remove_fork_catchpoint; | |
2967 | current_target.to_insert_vfork_catchpoint = debug_to_insert_vfork_catchpoint; | |
2968 | current_target.to_remove_vfork_catchpoint = debug_to_remove_vfork_catchpoint; | |
2969 | current_target.to_has_forked = debug_to_has_forked; | |
2970 | current_target.to_has_vforked = debug_to_has_vforked; | |
2971 | current_target.to_can_follow_vfork_prior_to_exec = debug_to_can_follow_vfork_prior_to_exec; | |
2972 | current_target.to_post_follow_vfork = debug_to_post_follow_vfork; | |
2973 | current_target.to_insert_exec_catchpoint = debug_to_insert_exec_catchpoint; | |
2974 | current_target.to_remove_exec_catchpoint = debug_to_remove_exec_catchpoint; | |
2975 | current_target.to_has_execd = debug_to_has_execd; | |
2976 | current_target.to_reported_exec_events_per_exec_call = debug_to_reported_exec_events_per_exec_call; | |
2977 | current_target.to_has_syscall_event = debug_to_has_syscall_event; | |
2978 | current_target.to_has_exited = debug_to_has_exited; | |
2979 | current_target.to_mourn_inferior = debug_to_mourn_inferior; | |
2980 | current_target.to_can_run = debug_to_can_run; | |
2981 | current_target.to_notice_signals = debug_to_notice_signals; | |
2982 | current_target.to_thread_alive = debug_to_thread_alive; | |
0d06e24b | 2983 | current_target.to_find_new_threads = debug_to_find_new_threads; |
c906108c SS |
2984 | current_target.to_stop = debug_to_stop; |
2985 | current_target.to_query = debug_to_query; | |
96baa820 | 2986 | current_target.to_rcmd = debug_to_rcmd; |
c906108c SS |
2987 | current_target.to_enable_exception_callback = debug_to_enable_exception_callback; |
2988 | current_target.to_get_current_exception_event = debug_to_get_current_exception_event; | |
2989 | current_target.to_pid_to_exec_file = debug_to_pid_to_exec_file; | |
2990 | current_target.to_core_file_to_sym_file = debug_to_core_file_to_sym_file; | |
2991 | ||
2992 | } | |
c906108c | 2993 | \f |
c5aa993b JM |
2994 | |
2995 | static char targ_desc[] = | |
2996 | "Names of targets and files being debugged.\n\ | |
c906108c SS |
2997 | Shows the entire stack of targets currently in use (including the exec-file,\n\ |
2998 | core-file, and process, if any), as well as the symbol file name."; | |
2999 | ||
96baa820 JM |
3000 | static void |
3001 | do_monitor_command (char *cmd, | |
3002 | int from_tty) | |
3003 | { | |
2b5fe715 AC |
3004 | if ((current_target.to_rcmd |
3005 | == (void (*) (char *, struct ui_file *)) tcomplain) | |
96baa820 | 3006 | || (current_target.to_rcmd == debug_to_rcmd |
2b5fe715 AC |
3007 | && (debug_target.to_rcmd |
3008 | == (void (*) (char *, struct ui_file *)) tcomplain))) | |
96baa820 JM |
3009 | { |
3010 | error ("\"monitor\" command not supported by this target.\n"); | |
3011 | } | |
3012 | target_rcmd (cmd, gdb_stdtarg); | |
3013 | } | |
3014 | ||
c906108c SS |
3015 | void |
3016 | initialize_targets () | |
3017 | { | |
3018 | init_dummy_target (); | |
3019 | push_target (&dummy_target); | |
3020 | ||
3021 | add_info ("target", target_info, targ_desc); | |
3022 | add_info ("files", target_info, targ_desc); | |
3023 | ||
c906108c | 3024 | add_show_from_set ( |
5d161b24 | 3025 | add_set_cmd ("target", class_maintenance, var_zinteger, |
c5aa993b JM |
3026 | (char *) &targetdebug, |
3027 | "Set target debugging.\n\ | |
5d161b24 DB |
3028 | When non-zero, target debugging is enabled.", &setdebuglist), |
3029 | &showdebuglist); | |
c906108c | 3030 | |
96baa820 JM |
3031 | |
3032 | add_com ("monitor", class_obscure, do_monitor_command, | |
3033 | "Send a command to the remote monitor (remote targets only)."); | |
3034 | ||
c906108c SS |
3035 | if (!STREQ (signals[TARGET_SIGNAL_LAST].string, "TARGET_SIGNAL_MAGIC")) |
3036 | abort (); | |
3037 | } |