1 /* Convert between signal names and numbers.
2 Copyright (C) 1990 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 1, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* GDB-specific, FIXME. (This is for the SYS_SIGLIST_MISSING define). */
32 #if SYS_SIGLIST_MISSING
33 /* There is too much variation in Sys V signal numbers and names, so
34 we must initialize them at runtime. */
36 static CONST
char undoc
[] = "unknown signal";
38 /* We'd like to make this const char*[], but whoever's using it might
39 want to assign from it to a char*. */
40 char *sys_siglist
[NSIG
];
41 #endif /* SYS_SIGLIST_MISSING */
43 /* Table of abbreviations for signals. Note: A given number can
44 appear more than once with different abbreviations. */
50 static num_abbrev sig_table
[NSIG
*2];
51 /* Number of elements of sig_table used. */
52 static int sig_table_nelts
= 0;
54 /* Enter signal number NUMBER into the tables with ABBREV and NAME. */
56 init_sig (number
, abbrev
, name
)
61 #if SYS_SIGLIST_MISSING
62 sys_siglist
[number
] = (char *) name
;
64 sig_table
[sig_table_nelts
].number
= number
;
65 sig_table
[sig_table_nelts
++].abbrev
= abbrev
;
68 static void init_sigs ()
70 #if SYS_SIGLIST_MISSING
73 /* Initialize signal names. */
74 for (i
= 0; i
< NSIG
; i
++)
75 sys_siglist
[i
] = (char *) undoc
;
76 #endif /* SYS_SIGLIST_MISSING */
78 /* Initialize signal names. */
80 init_sig (SIGHUP
, "HUP", "Hangup");
83 init_sig (SIGINT
, "INT", "Interrupt");
86 init_sig (SIGQUIT
, "QUIT", "Quit");
89 init_sig (SIGILL
, "ILL", "Illegal Instruction");
92 init_sig (SIGTRAP
, "TRAP", "Trace/breakpoint trap");
94 /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
95 SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
97 init_sig (SIGABRT
, "ABRT", "Aborted");
100 init_sig (SIGIOT
, "IOT", "IOT trap");
103 init_sig (SIGEMT
, "EMT", "EMT trap");
106 init_sig (SIGFPE
, "FPE", "Floating point exception");
108 #if defined (SIGKILL)
109 init_sig (SIGKILL
, "KILL", "Killed");
112 init_sig (SIGBUS
, "BUS", "Bus error");
114 #if defined (SIGSEGV)
115 init_sig (SIGSEGV
, "SEGV", "Segmentation fault");
118 init_sig (SIGSYS
, "SYS", "Bad system call");
120 #if defined (SIGPIPE)
121 init_sig (SIGPIPE
, "PIPE", "Broken pipe");
123 #if defined (SIGALRM)
124 init_sig (SIGALRM
, "ALRM", "Alarm clock");
126 #if defined (SIGTERM)
127 init_sig (SIGTERM
, "TERM", "Terminated");
129 #if defined (SIGUSR1)
130 init_sig (SIGUSR1
, "USR1", "User defined signal 1");
132 #if defined (SIGUSR2)
133 init_sig (SIGUSR2
, "USR2", "User defined signal 2");
135 /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
136 is what is in POSIX.1. */
137 #if defined (SIGCHLD)
138 init_sig (SIGCHLD
, "CHLD", "Child exited");
141 init_sig (SIGCLD
, "CLD", "Child exited");
144 init_sig (SIGPWR
, "PWR", "Power failure");
146 #if defined (SIGTSTP)
147 init_sig (SIGTSTP
, "TSTP", "Stopped");
149 #if defined (SIGTTIN)
150 init_sig (SIGTTIN
, "TTIN", "Stopped (tty input)");
152 #if defined (SIGTTOU)
153 init_sig (SIGTTOU
, "TTOU", "Stopped (tty output)");
155 #if defined (SIGSTOP)
156 init_sig (SIGSTOP
, "STOP", "Stopped (signal)");
158 #if defined (SIGXCPU)
159 init_sig (SIGXCPU
, "XCPU", "CPU time limit exceeded");
161 #if defined (SIGXFSZ)
162 init_sig (SIGXFSZ
, "XFSZ", "File size limit exceeded");
164 #if defined (SIGVTALRM)
165 init_sig (SIGVTALRM
, "VTALRM", "Virtual timer expired");
167 #if defined (SIGPROF)
168 init_sig (SIGPROF
, "PROF", "Profiling timer expired");
170 #if defined (SIGWINCH)
171 /* "Window size changed" might be more accurate, but even if that
172 is all that it means now, perhaps in the future it will be
173 extended to cover other kinds of window changes. */
174 init_sig (SIGWINCH
, "WINCH", "Window changed");
176 #if defined (SIGCONT)
177 init_sig (SIGCONT
, "CONT", "Continued");
180 init_sig (SIGURG
, "URG", "Urgent I/O condition");
183 /* "I/O pending" has also been suggested. A disadvantage is
184 that signal only happens when the process has
185 asked for it, not everytime I/O is pending. Another disadvantage
186 is the confusion from giving it a different name than under Unix. */
187 init_sig (SIGIO
, "IO", "I/O possible");
189 #if defined (SIGWIND)
190 init_sig (SIGWIND
, "WIND", "SIGWIND");
192 #if defined (SIGPHONE)
193 init_sig (SIGPHONE
, "PHONE", "SIGPHONE");
195 #if defined (SIGPOLL)
196 init_sig (SIGPOLL
, "POLL", "I/O possible");
198 #if defined (SIGLOST)
199 init_sig (SIGLOST
, "LOST", "Resource lost");
203 /* Return the abbreviation for signal NUMBER. */
210 for (i
= 0; i
< sig_table_nelts
; i
++)
211 if (sig_table
[i
].number
== number
)
212 return (char *)sig_table
[i
].abbrev
;
216 /* Return the signal number for an ABBREV, or -1 if there is no
217 signal by that name. */
224 /* Skip over "SIG" if present. */
225 if (abbrev
[0] == 'S' && abbrev
[1] == 'I' && abbrev
[2] == 'G')
228 for (i
= 0; i
< sig_table_nelts
; i
++)
229 if (abbrev
[0] == sig_table
[i
].abbrev
[0]
230 && strcmp (abbrev
, sig_table
[i
].abbrev
) == 0)
231 return sig_table
[i
].number
;
235 #if SYS_SIGLIST_MISSING
236 /* Print to standard error the name of SIGNAL, preceded by MESSAGE and
237 a colon, and followed by a newline. */
239 psignal (signal
, message
)
243 if (signal
<= 0 || signal
>= NSIG
)
244 fprintf (stderr
, "%s: unknown signal", message
);
246 fprintf (stderr
, "%s: %s\n", message
, sys_siglist
[signal
]);
248 #endif /* SYS_SIGLIST_MISSING */
251 _initialize_signame ()