| 1 | /* General utility routines for the remote server for GDB. |
| 2 | Copyright (C) 1986, 1989, 1993, 1995, 1996, 1997, 1999, 2000, 2002, 2003, |
| 3 | 2007 Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 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. |
| 11 | |
| 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. |
| 16 | |
| 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., 51 Franklin Street, Fifth Floor, |
| 20 | Boston, MA 02110-1301, USA. */ |
| 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 |
| 33 | perror_with_name (char *string) |
| 34 | { |
| 35 | #ifndef STDC_HEADERS |
| 36 | extern int errno; |
| 37 | #endif |
| 38 | const char *err; |
| 39 | char *combined; |
| 40 | |
| 41 | err = strerror (errno); |
| 42 | if (err == NULL) |
| 43 | err = "unknown error"; |
| 44 | |
| 45 | combined = (char *) alloca (strlen (err) + strlen (string) + 3); |
| 46 | strcpy (combined, string); |
| 47 | strcat (combined, ": "); |
| 48 | strcat (combined, err); |
| 49 | |
| 50 | error ("%s.", combined); |
| 51 | } |
| 52 | |
| 53 | /* Print an error message and return to command level. |
| 54 | STRING is the error message, used as a fprintf string, |
| 55 | and ARG is passed as an argument to it. */ |
| 56 | |
| 57 | void |
| 58 | error (const char *string,...) |
| 59 | { |
| 60 | extern jmp_buf toplevel; |
| 61 | va_list args; |
| 62 | va_start (args, string); |
| 63 | fflush (stdout); |
| 64 | vfprintf (stderr, string, args); |
| 65 | fprintf (stderr, "\n"); |
| 66 | longjmp (toplevel, 1); |
| 67 | } |
| 68 | |
| 69 | /* Print an error message and exit reporting failure. |
| 70 | This is for a error that we cannot continue from. |
| 71 | STRING and ARG are passed to fprintf. */ |
| 72 | |
| 73 | /* VARARGS */ |
| 74 | void |
| 75 | fatal (const char *string,...) |
| 76 | { |
| 77 | va_list args; |
| 78 | va_start (args, string); |
| 79 | fprintf (stderr, "gdb: "); |
| 80 | vfprintf (stderr, string, args); |
| 81 | fprintf (stderr, "\n"); |
| 82 | va_end (args); |
| 83 | exit (1); |
| 84 | } |
| 85 | |
| 86 | /* VARARGS */ |
| 87 | void |
| 88 | warning (const char *string,...) |
| 89 | { |
| 90 | va_list args; |
| 91 | va_start (args, string); |
| 92 | fprintf (stderr, "gdb: "); |
| 93 | vfprintf (stderr, string, args); |
| 94 | fprintf (stderr, "\n"); |
| 95 | va_end (args); |
| 96 | } |