Commit | Line | Data |
---|---|---|
c906108c | 1 | /* General utility routines for the remote server for GDB. |
6aba47ca | 2 | Copyright (C) 1986, 1989, 1993, 1995, 1996, 1997, 1999, 2000, 2002, 2003, |
9b254dd1 | 3 | 2007, 2008 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 | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 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 | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "server.h" | |
21 | #include <stdio.h> | |
22 | #include <string.h> | |
68070c10 PA |
23 | #include <stdlib.h> |
24 | #if HAVE_ERRNO_H | |
25 | #include <errno.h> | |
26 | #endif | |
27 | #if HAVE_MALLOC_H | |
28 | #include <malloc.h> | |
29 | #endif | |
c906108c SS |
30 | |
31 | /* Generally useful subroutines used throughout the program. */ | |
32 | ||
33 | /* Print the system error message for errno, and also mention STRING | |
34 | as the file name for which the error was encountered. | |
35 | Then return to command level. */ | |
36 | ||
37 | void | |
fba45db2 | 38 | perror_with_name (char *string) |
c906108c | 39 | { |
5c44784c | 40 | const char *err; |
c906108c SS |
41 | char *combined; |
42 | ||
43d5792c DJ |
43 | err = strerror (errno); |
44 | if (err == NULL) | |
c906108c SS |
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 | ||
0729219d | 59 | 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 */ | |
0729219d | 76 | void |
0a30fbc4 | 77 | fatal (const char *string,...) |
c906108c SS |
78 | { |
79 | va_list args; | |
c906108c | 80 | va_start (args, string); |
24a09b5f | 81 | fprintf (stderr, "gdbserver: "); |
c906108c SS |
82 | vfprintf (stderr, string, args); |
83 | fprintf (stderr, "\n"); | |
84 | va_end (args); | |
85 | exit (1); | |
86 | } | |
0a30fbc4 DJ |
87 | |
88 | /* VARARGS */ | |
89 | void | |
90 | warning (const char *string,...) | |
91 | { | |
92 | va_list args; | |
93 | va_start (args, string); | |
24a09b5f | 94 | fprintf (stderr, "gdbserver: "); |
0a30fbc4 DJ |
95 | vfprintf (stderr, string, args); |
96 | fprintf (stderr, "\n"); | |
97 | va_end (args); | |
98 | } |