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