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