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