1 /* General utility routines for the remote server for GDB. 2 Copyright (C) 1986, 1989, 1993 Free Software Foundation, Inc. 3 4 This file is part of GDB. 5 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. 10 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. 15 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, Boston, MA 02111-1307, USA. */ 19 20 #include "server.h" 21 #include <stdio.h> 22 #include <string.h> 23 24 /* Generally useful subroutines used throughout the program. */ 25 26 /* Print the system error message for errno, and also mention STRING 27 as the file name for which the error was encountered. 28 Then return to command level. */ 29 30 void 31 perror_with_name (string) 32 char *string; 33 { 34 extern int sys_nerr; 35 extern char *sys_errlist[]; 36 extern int errno; 37 char *err; 38 char *combined; 39 40 if (errno < sys_nerr) 41 err = sys_errlist[errno]; 42 else 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 #ifdef ANSI_PROTOTYPES 58 NORETURN void 59 error (char *string, ...) 60 #else 61 void 62 error (va_alist) 63 va_dcl 64 #endif 65 { 66 extern jmp_buf toplevel; 67 va_list args; 68 #ifdef ANSI_PROTOTYPES 69 va_start (args, string); 70 #else 71 va_start (args); 72 #endif 73 fflush (stdout); 74 #ifdef ANSI_PROTOTYPES 75 vfprintf (stderr, string, args); 76 #else 77 { 78 char *string1; 79 80 string1 = va_arg (args, char *); 81 vfprintf (stderr, string1, args); 82 } 83 #endif 84 fprintf (stderr, "\n"); 85 longjmp(toplevel, 1); 86 } 87 88 /* Print an error message and exit reporting failure. 89 This is for a error that we cannot continue from. 90 STRING and ARG are passed to fprintf. */ 91 92 /* VARARGS */ 93 NORETURN void 94 #ifdef ANSI_PROTOTYPES 95 fatal (char *string, ...) 96 #else 97 fatal (va_alist) 98 va_dcl 99 #endif 100 { 101 va_list args; 102 #ifdef ANSI_PROTOTYPES 103 va_start (args, string); 104 #else 105 char *string; 106 va_start (args); 107 string = va_arg (args, char *); 108 #endif 109 fprintf (stderr, "gdb: "); 110 vfprintf (stderr, string, args); 111 fprintf (stderr, "\n"); 112 va_end (args); 113 exit (1); 114 } 115