* config/m68k/monitor.mt (TDEPFILE): Add remote-es.o.
[deliverable/binutils-gdb.git] / gdb / target.c
CommitLineData
bd5635a1 1/* Select target systems and architectures at runtime for GDB.
49781499 2 Copyright 1990, 1992, 1993 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
JG
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
bd5635a1 20
80d68b1d 21#include "defs.h"
bd5635a1
RP
22#include <errno.h>
23#include <ctype.h>
bd5635a1
RP
24#include "target.h"
25#include "gdbcmd.h"
26#include "symtab.h"
27#include "inferior.h"
28#include "bfd.h"
29#include "symfile.h"
51b57ded 30#include "objfiles.h"
bd5635a1 31
e17960fb
JG
32extern int errno;
33
7919c3ed
JG
34static void
35target_info PARAMS ((char *, int));
36
37static void
38cleanup_target PARAMS ((struct target_ops *));
39
40static void
41maybe_kill_then_create_inferior PARAMS ((char *, char *, char **));
42
43static void
44maybe_kill_then_attach PARAMS ((char *, int));
45
46static void
47kill_or_be_killed PARAMS ((int));
48
49static void
50default_terminal_info PARAMS ((char *, int));
51
52static int
53nosymbol PARAMS ((char *, CORE_ADDR *));
54
7919c3ed
JG
55static void
56tcomplain PARAMS ((void));
57
58static int
59nomemory PARAMS ((CORE_ADDR, char *, int, int));
60
597dc86b
SG
61static int
62return_zero PARAMS ((void));
63
7919c3ed
JG
64static void
65ignore PARAMS ((void));
597dc86b 66
7919c3ed
JG
67static void
68target_command PARAMS ((char *, int));
bd5635a1 69
597dc86b
SG
70static struct target_ops *
71find_default_run_target PARAMS ((char *));
72
bd5635a1
RP
73/* Pointer to array of target architecture structures; the size of the
74 array; the current index into the array; the allocated size of the
75 array. */
76struct target_ops **target_structs;
77unsigned target_struct_size;
78unsigned target_struct_index;
79unsigned target_struct_allocsize;
80#define DEFAULT_ALLOCSIZE 10
81
82/* The initial current target, so that there is always a semi-valid
83 current target. */
84
f2fc6e7a 85struct target_ops dummy_target = {"None", "None", "",
597dc86b
SG
86 0, 0, /* open, close */
87 find_default_attach, 0, /* attach, detach */
bd5635a1 88 0, 0, /* resume, wait */
dcc8abce 89 0, 0, 0, /* registers */
bd5635a1
RP
90 0, 0, /* memory */
91 0, 0, /* bkpts */
92 0, 0, 0, 0, 0, /* terminal */
fc47a10d 93 0, 0, /* kill, load */
e17960fb 94 0, /* lookup_symbol */
597dc86b
SG
95 find_default_create_inferior, /* create_inferior */
96 0, /* mourn_inferior */
97 0, /* can_run */
49781499 98 0, /* notice_signals */
bd5635a1
RP
99 dummy_stratum, 0, /* stratum, next */
100 0, 0, 0, 0, 0, /* all mem, mem, stack, regs, exec */
e17960fb 101 0, 0, /* section pointers */
bd5635a1
RP
102 OPS_MAGIC,
103};
104
105/* The target structure we are currently using to talk to a process
106 or file or whatever "inferior" we have. */
107
108struct target_ops *current_target;
109
110/* The stack of target structures that have been pushed. */
111
112struct target_ops **current_target_stack;
113
f2fc6e7a
JK
114/* Command list for target. */
115
116static struct cmd_list_element *targetlist = NULL;
117
f2fc6e7a
JK
118/* The user just typed 'target' without the name of a target. */
119
e1ce8aa5 120/* ARGSUSED */
f2fc6e7a
JK
121static void
122target_command (arg, from_tty)
123 char *arg;
124 int from_tty;
125{
597dc86b 126 fputs_filtered ("Argument required (target name). Try `help target'\n",
67ac9759 127 gdb_stdout);
f2fc6e7a 128}
bd5635a1
RP
129
130/* Add a possible target architecture to the list. */
131
132void
133add_target (t)
134 struct target_ops *t;
135{
136 if (t->to_magic != OPS_MAGIC)
137 {
67ac9759 138 fprintf_unfiltered(gdb_stderr, "Magic number of %s target struct wrong\n",
bd5635a1
RP
139 t->to_shortname);
140 abort();
141 }
142
143 if (!target_structs)
144 {
145 target_struct_allocsize = DEFAULT_ALLOCSIZE;
146 target_structs = (struct target_ops **) xmalloc
147 (target_struct_allocsize * sizeof (*target_structs));
148 }
149 if (target_struct_size >= target_struct_allocsize)
150 {
151 target_struct_allocsize *= 2;
7919c3ed
JG
152 target_structs = (struct target_ops **)
153 xrealloc ((char *) target_structs,
154 target_struct_allocsize * sizeof (*target_structs));
bd5635a1
RP
155 }
156 target_structs[target_struct_size++] = t;
157 cleanup_target (t);
f2fc6e7a
JK
158
159 if (targetlist == NULL)
160 add_prefix_cmd ("target", class_run, target_command,
161 "Connect to a target machine or process.\n\
162The first argument is the type or protocol of the target machine.\n\
163Remaining arguments are interpreted by the target protocol. For more\n\
164information on the arguments for a particular protocol, type\n\
165`help target ' followed by the protocol name.",
166 &targetlist, "target ", 0, &cmdlist);
167 add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist);
bd5635a1
RP
168}
169
170/* Stub functions */
171
172static void
173ignore ()
174{
175}
176
177/* ARGSUSED */
178static int
179nomemory (memaddr, myaddr, len, write)
180 CORE_ADDR memaddr;
181 char *myaddr;
182 int len;
183 int write;
184{
51b57ded 185 errno = EIO; /* Can't read/write this location */
bd5635a1
RP
186 return 0; /* No bytes handled */
187}
188
189static void
190tcomplain ()
191{
192 error ("You can't do that when your target is `%s'",
193 current_target->to_shortname);
194}
195
80d68b1d 196void
bd5635a1
RP
197noprocess ()
198{
199 error ("You can't do that without a process to debug");
200}
201
e1ce8aa5 202/* ARGSUSED */
bd5635a1
RP
203static int
204nosymbol (name, addrp)
205 char *name;
206 CORE_ADDR *addrp;
207{
208 return 1; /* Symbol does not exist in target env */
209}
210
e1ce8aa5 211/* ARGSUSED */
bd5635a1
RP
212static void
213default_terminal_info (args, from_tty)
214 char *args;
215 int from_tty;
216{
67ac9759 217 printf_unfiltered("No saved terminal information.\n");
bd5635a1
RP
218}
219
220#if 0
221/* With strata, this function is no longer needed. FIXME. */
222/* This is the default target_create_inferior function. It looks up
223 the stack for some target that cares to create inferiors, then
224 calls it -- or complains if not found. */
225
226static void
227upstack_create_inferior (exec, args, env)
228 char *exec;
229 char *args;
230 char **env;
231{
232 struct target_ops *t;
233
234 for (t = current_target;
235 t;
236 t = t->to_next)
237 {
238 if (t->to_create_inferior != upstack_create_inferior)
239 {
240 t->to_create_inferior (exec, args, env);
241 return;
242 }
243
244 }
245 tcomplain();
246}
247#endif
248
249/* This is the default target_create_inferior and target_attach function.
250 If the current target is executing, it asks whether to kill it off.
251 If this function returns without calling error(), it has killed off
252 the target, and the operation should be attempted. */
253
254static void
255kill_or_be_killed (from_tty)
256 int from_tty;
257{
bd5635a1
RP
258 if (target_has_execution)
259 {
67ac9759 260 printf_unfiltered ("You are already running a program:\n");
bd5635a1
RP
261 target_files_info ();
262 if (query ("Kill it? ")) {
e17960fb 263 target_kill ();
bd5635a1
RP
264 if (target_has_execution)
265 error ("Killing the program did not help.");
266 return;
267 } else {
268 error ("Program not killed.");
269 }
270 }
271 tcomplain();
272}
273
274static void
275maybe_kill_then_attach (args, from_tty)
276 char *args;
277 int from_tty;
278{
279 kill_or_be_killed (from_tty);
280 target_attach (args, from_tty);
281}
282
283static void
284maybe_kill_then_create_inferior (exec, args, env)
285 char *exec;
286 char *args;
287 char **env;
288{
289 kill_or_be_killed (0);
290 target_create_inferior (exec, args, env);
291}
292
293/* Clean up a target struct so it no longer has any zero pointers in it.
294 We default entries, at least to stubs that print error messages. */
295
296static void
297cleanup_target (t)
298 struct target_ops *t;
299{
300
301 /* Check magic number. If wrong, it probably means someone changed
302 the struct definition, but not all the places that initialize one. */
303 if (t->to_magic != OPS_MAGIC)
304 {
67ac9759 305 fprintf_unfiltered(gdb_stderr, "Magic number of %s target struct wrong\n",
bd5635a1
RP
306 t->to_shortname);
307 abort();
308 }
309
310#define de_fault(field, value) \
311 if (!t->field) t->field = value
312
313 /* FIELD DEFAULT VALUE */
314
7919c3ed 315 de_fault (to_open, (void (*)())tcomplain);
bd5635a1
RP
316 de_fault (to_close, (void (*)())ignore);
317 de_fault (to_attach, maybe_kill_then_attach);
318 de_fault (to_detach, (void (*)())ignore);
319 de_fault (to_resume, (void (*)())noprocess);
7919c3ed
JG
320 de_fault (to_wait, (int (*)())noprocess);
321 de_fault (to_fetch_registers, (void (*)())ignore);
e17960fb 322 de_fault (to_store_registers, (void (*)())noprocess);
bd5635a1 323 de_fault (to_prepare_to_store, (void (*)())noprocess);
7919c3ed
JG
324 de_fault (to_xfer_memory, (int (*)())nomemory);
325 de_fault (to_files_info, (void (*)())ignore);
bd5635a1
RP
326 de_fault (to_insert_breakpoint, memory_insert_breakpoint);
327 de_fault (to_remove_breakpoint, memory_remove_breakpoint);
328 de_fault (to_terminal_init, ignore);
329 de_fault (to_terminal_inferior, ignore);
330 de_fault (to_terminal_ours_for_output,ignore);
331 de_fault (to_terminal_ours, ignore);
332 de_fault (to_terminal_info, default_terminal_info);
333 de_fault (to_kill, (void (*)())noprocess);
7919c3ed 334 de_fault (to_load, (void (*)())tcomplain);
bd5635a1
RP
335 de_fault (to_lookup_symbol, nosymbol);
336 de_fault (to_create_inferior, maybe_kill_then_create_inferior);
337 de_fault (to_mourn_inferior, (void (*)())noprocess);
597dc86b 338 de_fault (to_can_run, return_zero);
49781499 339 de_fault (to_notice_signals, (void (*)())ignore);
bd5635a1
RP
340 de_fault (to_next, 0);
341 de_fault (to_has_all_memory, 0);
342 de_fault (to_has_memory, 0);
343 de_fault (to_has_stack, 0);
344 de_fault (to_has_registers, 0);
345 de_fault (to_has_execution, 0);
346
347#undef de_fault
348}
349
350/* Push a new target type into the stack of the existing target accessors,
351 possibly superseding some of the existing accessors.
352
353 Result is zero if the pushed target ended up on top of the stack,
354 nonzero if at least one target is on top of it.
355
356 Rather than allow an empty stack, we always have the dummy target at
357 the bottom stratum, so we can call the function vectors without
358 checking them. */
359
360int
361push_target (t)
362 struct target_ops *t;
363{
364 struct target_ops *st, *prev;
365
366 for (prev = 0, st = current_target;
367 st;
368 prev = st, st = st->to_next) {
369 if ((int)(t->to_stratum) >= (int)(st->to_stratum))
370 break;
371 }
372
373 while (t->to_stratum == st->to_stratum) {
374 /* There's already something on this stratum. Close it off. */
375 (st->to_close) (0);
376 if (prev)
377 prev->to_next = st->to_next; /* Unchain old target_ops */
378 else
379 current_target = st->to_next; /* Unchain first on list */
380 st = st->to_next;
381 }
382
383 /* We have removed all targets in our stratum, now add ourself. */
384 t->to_next = st;
385 if (prev)
386 prev->to_next = t;
387 else
388 current_target = t;
389
390 cleanup_target (current_target);
391 return prev != 0;
392}
393
394/* Remove a target_ops vector from the stack, wherever it may be.
395 Return how many times it was removed (0 or 1 unless bug). */
396
397int
398unpush_target (t)
399 struct target_ops *t;
400{
401 struct target_ops *u, *v;
402 int result = 0;
403
404 for (u = current_target, v = 0;
405 u;
406 v = u, u = u->to_next)
407 if (u == t)
408 {
409 if (v == 0)
410 pop_target(); /* unchain top copy */
411 else {
412 (t->to_close)(0); /* Let it clean up */
413 v->to_next = t->to_next; /* unchain middle copy */
414 }
415 result++;
416 }
417 return result;
418}
419
420void
421pop_target ()
422{
423 (current_target->to_close)(0); /* Let it clean up */
424 current_target = current_target->to_next;
49781499
JK
425#if 0
426 /* This will dump core if ever called--push_target expects current_target
427 to be non-NULL. But I don't think it's needed; I don't see how the
428 dummy_target could ever be removed from the stack. */
bd5635a1
RP
429 if (!current_target) /* At bottom, push dummy. */
430 push_target (&dummy_target);
49781499 431#endif
bd5635a1
RP
432}
433
49781499 434#undef MIN
e17960fb
JG
435#define MIN(A, B) (((A) <= (B)) ? (A) : (B))
436
437/* target_read_string -- read a null terminated string from MEMADDR in target.
438 The read may also be terminated early by getting an error from target_xfer_
439 memory.
440 LEN is the size of the buffer pointed to by MYADDR. Note that a terminating
441 null will only be written if there is sufficient room. The return value is
442 is the number of bytes (including the null) actually transferred.
443*/
444
445int
446target_read_string (memaddr, myaddr, len)
447 CORE_ADDR memaddr;
448 char *myaddr;
449 int len;
450{
451 int tlen, origlen, offset, i;
452 char buf[4];
453
454 origlen = len;
455
456 while (len > 0)
457 {
458 tlen = MIN (len, 4 - (memaddr & 3));
459 offset = memaddr & 3;
460
461 if (target_xfer_memory (memaddr & ~3, buf, 4, 0))
462 return origlen - len;
463
464 for (i = 0; i < tlen; i++)
465 {
466 *myaddr++ = buf[i + offset];
467 if (buf[i + offset] == '\000')
468 return (origlen - len) + i + 1;
469 }
470
471 memaddr += tlen;
472 len -= tlen;
473 }
474 return origlen;
475}
476
49781499
JK
477/* Read LEN bytes of target memory at address MEMADDR, placing the results in
478 GDB's memory at MYADDR. Returns either 0 for success or an errno value
479 if any error occurs.
bd5635a1 480
49781499
JK
481 If an error occurs, no guarantee is made about the contents of the data at
482 MYADDR. In particular, the caller should not depend upon partial reads
483 filling the buffer with good data. There is no way for the caller to know
484 how much good data might have been transfered anyway. Callers that can
485 deal with partial reads should call target_read_memory_partial. */
bd5635a1
RP
486
487int
488target_read_memory (memaddr, myaddr, len)
489 CORE_ADDR memaddr;
490 char *myaddr;
491 int len;
492{
493 return target_xfer_memory (memaddr, myaddr, len, 0);
494}
495
49781499
JK
496/* Read LEN bytes of target memory at address MEMADDR, placing the results
497 in GDB's memory at MYADDR. Returns a count of the bytes actually read,
498 and optionally an errno value in the location pointed to by ERRNOPTR
499 if ERRNOPTR is non-null. */
500
501int
502target_read_memory_partial (memaddr, myaddr, len, errnoptr)
503 CORE_ADDR memaddr;
504 char *myaddr;
505 int len;
506 int *errnoptr;
507{
508 int nread; /* Number of bytes actually read. */
509 int errcode; /* Error from last read. */
510
511 /* First try a complete read. */
512 errcode = target_xfer_memory (memaddr, myaddr, len, 0);
513 if (errcode == 0)
514 {
515 /* Got it all. */
516 nread = len;
517 }
518 else
519 {
520 /* Loop, reading one byte at a time until we get as much as we can. */
521 for (errcode = 0, nread = 0; len > 0 && errcode == 0; nread++, len--)
522 {
523 errcode = target_xfer_memory (memaddr++, myaddr++, 1, 0);
524 }
525 /* If an error, the last read was unsuccessful, so adjust count. */
526 if (errcode != 0)
527 {
528 nread--;
529 }
530 }
531 if (errnoptr != NULL)
532 {
533 *errnoptr = errcode;
534 }
535 return (nread);
536}
537
bd5635a1
RP
538int
539target_write_memory (memaddr, myaddr, len)
540 CORE_ADDR memaddr;
541 char *myaddr;
542 int len;
543{
544 return target_xfer_memory (memaddr, myaddr, len, 1);
545}
546
49781499
JK
547/* Move memory to or from the targets. Iterate until all of it has
548 been moved, if necessary. The top target gets priority; anything
549 it doesn't want, is offered to the next one down, etc. Note the
550 business with curlen: if an early target says "no, but I have a
551 boundary overlapping this xfer" then we shorten what we offer to
552 the subsequent targets so the early guy will get a chance at the
553 tail before the subsequent ones do.
554
555 Result is 0 or errno value. */
556
bd5635a1
RP
557int
558target_xfer_memory (memaddr, myaddr, len, write)
559 CORE_ADDR memaddr;
560 char *myaddr;
561 int len;
562 int write;
563{
564 int curlen;
565 int res;
566 struct target_ops *t;
49781499
JK
567
568 /* to_xfer_memory is not guaranteed to set errno, even when it returns
569 0. */
570 errno = 0;
571
bd5635a1 572 /* The quick case is that the top target does it all. */
e17960fb
JG
573 res = current_target->to_xfer_memory
574 (memaddr, myaddr, len, write, current_target);
bd5635a1
RP
575 if (res == len)
576 return 0;
577
578 if (res > 0)
579 goto bump;
580 /* If res <= 0 then we call it again in the loop. Ah well. */
581
582 for (; len > 0;)
583 {
584 curlen = len; /* Want to do it all */
585 for (t = current_target;
586 t;
587 t = t->to_has_all_memory? 0: t->to_next)
588 {
e17960fb 589 res = t->to_xfer_memory(memaddr, myaddr, curlen, write, t);
bd5635a1
RP
590 if (res > 0) break; /* Handled all or part of xfer */
591 if (res == 0) continue; /* Handled none */
592 curlen = -res; /* Could handle once we get past res bytes */
593 }
594 if (res <= 0)
595 {
596 /* If this address is for nonexistent memory,
597 read zeros if reading, or do nothing if writing. Return error. */
598 if (!write)
a8e033f2 599 memset (myaddr, 0, len);
e17960fb
JG
600 if (errno == 0)
601 return EIO;
602 else
603 return errno;
bd5635a1
RP
604 }
605bump:
606 memaddr += res;
607 myaddr += res;
608 len -= res;
609 }
610 return 0; /* We managed to cover it all somehow. */
611}
612
613
e1ce8aa5 614/* ARGSUSED */
bd5635a1
RP
615static void
616target_info (args, from_tty)
617 char *args;
618 int from_tty;
619{
620 struct target_ops *t;
621 int has_all_mem = 0;
622
80d68b1d 623 if (symfile_objfile != NULL)
67ac9759 624 printf_unfiltered ("Symbols from \"%s\".\n", symfile_objfile->name);
bd5635a1
RP
625
626#ifdef FILES_INFO_HOOK
627 if (FILES_INFO_HOOK ())
628 return;
629#endif
630
631 for (t = current_target;
632 t;
633 t = t->to_next)
634 {
635 if ((int)(t->to_stratum) <= (int)dummy_stratum)
636 continue;
637 if (has_all_mem)
67ac9759
JK
638 printf_unfiltered("\tWhile running this, gdb does not access memory from...\n");
639 printf_unfiltered("%s:\n", t->to_longname);
e17960fb 640 (t->to_files_info)(t);
bd5635a1
RP
641 has_all_mem = t->to_has_all_memory;
642 }
643}
644
f2fc6e7a
JK
645/* This is to be called by the open routine before it does
646 anything. */
bd5635a1 647
f2fc6e7a
JK
648void
649target_preopen (from_tty)
bd5635a1
RP
650 int from_tty;
651{
bd5635a1
RP
652 dont_repeat();
653
bd5635a1
RP
654 if (target_has_execution)
655 {
656 if (query ("A program is being debugged already. Kill it? "))
e17960fb 657 target_kill ();
bd5635a1
RP
658 else
659 error ("Program not killed.");
660 }
bd5635a1
RP
661}
662
49781499
JK
663/* Detach a target after doing deferred register stores. */
664
665void
666target_detach (args, from_tty)
667 char *args;
668 int from_tty;
669{
670 /* Handle any optimized stores to the inferior. */
671#ifdef DO_DEFERRED_STORES
672 DO_DEFERRED_STORES;
673#endif
674 (current_target->to_detach) (args, from_tty);
49781499
JK
675}
676
597dc86b
SG
677/* Look through the list of possible targets for a target that can
678 execute a run or attach command without any other data. This is
679 used to locate the default process stratum.
680
681 Result is always valid (error() is called for errors). */
682
683static struct target_ops *
684find_default_run_target (do_mesg)
685 char *do_mesg;
686{
687 struct target_ops **t;
49781499 688 struct target_ops *runable = NULL;
597dc86b
SG
689 int count;
690
691 count = 0;
692
693 for (t = target_structs; t < target_structs + target_struct_size;
694 ++t)
695 {
696 if (target_can_run(*t))
697 {
698 runable = *t;
699 ++count;
700 }
701 }
702
703 if (count != 1)
704 error ("Don't know how to %s. Try \"help target\".", do_mesg);
705
706 return runable;
707}
708
709void
710find_default_attach (args, from_tty)
711 char *args;
712 int from_tty;
713{
714 struct target_ops *t;
715
716 t = find_default_run_target("attach");
717 (t->to_attach) (args, from_tty);
718 return;
719}
720
721void
722find_default_create_inferior (exec_file, allargs, env)
723 char *exec_file;
724 char *allargs;
725 char **env;
726{
727 struct target_ops *t;
728
729 t = find_default_run_target("run");
730 (t->to_create_inferior) (exec_file, allargs, env);
731 return;
732}
733
734static int
735return_zero ()
736{
737 return 0;
738}
739
49781499
JK
740struct target_ops *
741find_core_target ()
742{
743 struct target_ops **t;
744 struct target_ops *runable = NULL;
745 int count;
746
747 count = 0;
748
749 for (t = target_structs; t < target_structs + target_struct_size;
750 ++t)
751 {
752 if ((*t)->to_stratum == core_stratum)
753 {
754 runable = *t;
755 ++count;
756 }
757 }
758
759 return(count == 1 ? runable : NULL);
760}
67ac9759
JK
761\f
762/* This table must match in order and size the signals in enum target_signal
763 in target.h. */
764static struct {
765 char *name;
766 char *string;
767 } signals [] =
768{
769 {"0", "Signal 0"},
770 {"SIGHUP", "Hangup"},
771 {"SIGINT", "Interrupt"},
772 {"SIGQUIT", "Quit"},
773 {"SIGILL", "Illegal instruction"},
774 {"SIGTRAP", "Trace/breakpoint trap"},
775 {"SIGABRT", "Aborted"},
776 {"SIGEMT", "Emulation trap"},
777 {"SIGFPE", "Arithmetic exception"},
778 {"SIGKILL", "Killed"},
779 {"SIGBUS", "Bus error"},
780 {"SIGSEGV", "Segmentation fault"},
781 {"SIGSYS", "Bad system call"},
782 {"SIGPIPE", "Broken pipe"},
783 {"SIGALRM", "Alarm clock"},
784 {"SIGTERM", "Terminated"},
785 {"SIGURG", "Urgent I/O condition"},
786 {"SIGSTOP", "Stopped (signal)"},
787 {"SIGTSTP", "Stopped (user)"},
788 {"SIGCONT", "Continued"},
789 {"SIGCHLD", "Child status changed"},
790 {"SIGTTIN", "Stopped (tty input)"},
791 {"SIGTTOU", "Stopped (tty output)"},
792 {"SIGIO", "I/O possible"},
793 {"SIGXCPU", "CPU time limit exceeded"},
794 {"SIGXFSZ", "File size limit exceeded"},
795 {"SIGVTALRM", "Virtual timer expired"},
796 {"SIGPROF", "Profiling timer expired"},
797 {"SIGWINCH", "Window size changed"},
798 {"SIGLOST", "Resource lost"},
799 {"SIGUSR1", "User defined signal 1"},
800 {"SIGUSR2", "User defined signal 2"},
801 {"SIGPWR", "Power fail/restart"},
802 {"SIGPOLL", "Pollable event occurred"},
803 {"SIGWIND", "SIGWIND"},
804 {"SIGPHONE", "SIGPHONE"},
805 {"SIGWAITING", "Process's LWPs are blocked"},
806 {"SIGLWP", "Signal LWP"},
807 {"SIGDANGER", "Swap space dangerously low"},
808 {"SIGGRANT", "Monitor mode granted"},
809 {"SIGRETRACT", "Need to relinguish monitor mode"},
810 {"SIGMSG", "Monitor mode data available"},
811 {"SIGSOUND", "Sound completed"},
812 {"SIGSAK", "Secure attention"},
813 {NULL, "Unknown signal"},
814 /* Last entry, used to check whether the table is the right size. */
815 {NULL, "TARGET_SIGNAL_MAGIC"}
816};
817
818/* Return the string for a signal. */
819char *
820target_signal_to_string (sig)
821 enum target_signal sig;
822{
823 return signals[sig].string;
824}
825
826/* Return the name for a signal. */
827char *
828target_signal_to_name (sig)
829 enum target_signal sig;
830{
831 if (sig == TARGET_SIGNAL_UNKNOWN)
832 /* I think the code which prints this will always print it along with
833 the string, so no need to be verbose. */
834 return "?";
835 return signals[sig].name;
836}
837
838/* Given a name, return its signal. */
839enum target_signal
840target_signal_from_name (name)
841 char *name;
842{
843 enum target_signal sig;
844
845 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD"
846 for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more
847 questionable; seems like by now people should call it SIGABRT
848 instead. */
849
850 for (sig = TARGET_SIGNAL_HUP; signals[sig].name != NULL; ++sig)
851 if (STREQ (name, signals[sig].name))
852 return sig;
853 return TARGET_SIGNAL_UNKNOWN;
854}
855\f
49781499
JK
856/* Convert a normal process ID to a string. Returns the string in a static
857 buffer. */
858
859char *
860normal_pid_to_str (pid)
861 int pid;
862{
863 static char buf[30];
864
865 sprintf (buf, "process %d", pid);
866
867 return buf;
868}
67ac9759 869\f
bd5635a1
RP
870static char targ_desc[] =
871 "Names of targets and files being debugged.\n\
872Shows the entire stack of targets currently in use (including the exec-file,\n\
873core-file, and process, if any), as well as the symbol file name.";
874
875void
876_initialize_targets ()
877{
878 current_target = &dummy_target;
879 cleanup_target (current_target);
880
bd5635a1
RP
881 add_info ("target", target_info, targ_desc);
882 add_info ("files", target_info, targ_desc);
67ac9759
JK
883
884 if (!STREQ (signals[TARGET_SIGNAL_LAST].string, "TARGET_SIGNAL_MAGIC"))
885 abort ();
bd5635a1 886}
This page took 0.315755 seconds and 4 git commands to generate.