Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* General utility routines for the remote server for GDB. |
2 | Copyright (C) 1986, 1989, 1993 Free Software Foundation, Inc. | |
3 | ||
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
c906108c | 10 | |
c5aa993b JM |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
c906108c | 15 | |
c5aa993b JM |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
20 | |
21 | #include "server.h" | |
22 | #include <stdio.h> | |
23 | #include <string.h> | |
24 | ||
25 | /* Generally useful subroutines used throughout the program. */ | |
26 | ||
27 | /* Print the system error message for errno, and also mention STRING | |
28 | as the file name for which the error was encountered. | |
29 | Then return to command level. */ | |
30 | ||
31 | void | |
fba45db2 | 32 | perror_with_name (char *string) |
c906108c | 33 | { |
5c44784c | 34 | #ifndef STDC_HEADERS |
c906108c SS |
35 | extern int sys_nerr; |
36 | extern char *sys_errlist[]; | |
37 | extern int errno; | |
5c44784c JM |
38 | #endif |
39 | const char *err; | |
c906108c SS |
40 | char *combined; |
41 | ||
42 | if (errno < sys_nerr) | |
43 | err = sys_errlist[errno]; | |
44 | else | |
45 | err = "unknown error"; | |
46 | ||
47 | combined = (char *) alloca (strlen (err) + strlen (string) + 3); | |
48 | strcpy (combined, string); | |
49 | strcat (combined, ": "); | |
50 | strcat (combined, err); | |
51 | ||
52 | error ("%s.", combined); | |
53 | } | |
54 | ||
55 | /* Print an error message and return to command level. | |
56 | STRING is the error message, used as a fprintf string, | |
57 | and ARG is passed as an argument to it. */ | |
58 | ||
c906108c | 59 | NORETURN void |
c5aa993b | 60 | error (const char *string,...) |
c906108c SS |
61 | { |
62 | extern jmp_buf toplevel; | |
63 | va_list args; | |
c906108c | 64 | va_start (args, string); |
c906108c | 65 | fflush (stdout); |
c906108c | 66 | vfprintf (stderr, string, args); |
c906108c | 67 | fprintf (stderr, "\n"); |
c5aa993b | 68 | longjmp (toplevel, 1); |
c906108c SS |
69 | } |
70 | ||
71 | /* Print an error message and exit reporting failure. | |
72 | This is for a error that we cannot continue from. | |
73 | STRING and ARG are passed to fprintf. */ | |
74 | ||
75 | /* VARARGS */ | |
76 | NORETURN void | |
c5aa993b | 77 | fatal (char *string,...) |
c906108c SS |
78 | { |
79 | va_list args; | |
c906108c | 80 | va_start (args, string); |
c906108c SS |
81 | fprintf (stderr, "gdb: "); |
82 | vfprintf (stderr, string, args); | |
83 | fprintf (stderr, "\n"); | |
84 | va_end (args); | |
85 | exit (1); | |
86 | } |