150276Speter/* General utility routines for the remote server for GDB. 2174993Srafan Copyright 1986, 1989, 1993, 1995, 1996, 1997, 1999, 2000, 2002, 2003 350276Speter Free Software Foundation, Inc. 450276Speter 550276Speter This file is part of GDB. 650276Speter 750276Speter This program is free software; you can redistribute it and/or modify 850276Speter it under the terms of the GNU General Public License as published by 950276Speter the Free Software Foundation; either version 2 of the License, or 1050276Speter (at your option) any later version. 1150276Speter 1250276Speter This program is distributed in the hope that it will be useful, 1350276Speter but WITHOUT ANY WARRANTY; without even the implied warranty of 1450276Speter MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1550276Speter GNU General Public License for more details. 1650276Speter 1750276Speter You should have received a copy of the GNU General Public License 1850276Speter along with this program; if not, write to the Free Software 1950276Speter Foundation, Inc., 59 Temple Place - Suite 330, 2050276Speter Boston, MA 02111-1307, USA. */ 2150276Speter 2250276Speter#include "server.h" 2350276Speter#include <stdio.h> 2450276Speter#include <string.h> 2550276Speter 2650276Speter/* Generally useful subroutines used throughout the program. */ 2750276Speter 2850276Speter/* Print the system error message for errno, and also mention STRING 2950276Speter as the file name for which the error was encountered. 30166124Srafan Then return to command level. */ 3150276Speter 3250276Spetervoid 3350276Speterperror_with_name (char *string) 3450276Speter{ 35174993Srafan#ifndef STDC_HEADERS 3650276Speter extern int errno; 3750276Speter#endif 38166124Srafan const char *err; 3950276Speter char *combined; 40166124Srafan 4150276Speter err = strerror (errno); 4250276Speter if (err == NULL) 4350276Speter err = "unknown error"; 44166124Srafan 4550276Speter combined = (char *) alloca (strlen (err) + strlen (string) + 3); 4650276Speter strcpy (combined, string); 4750276Speter strcat (combined, ": "); 4850276Speter strcat (combined, err); 4950276Speter 5076726Speter error ("%s.", combined); 51166124Srafan} 5250276Speter 5350276Speter/* Print an error message and return to command level. 5450276Speter STRING is the error message, used as a fprintf string, 5550276Speter and ARG is passed as an argument to it. */ 56166124Srafan 57166124Srafanvoid 58166124Srafanerror (const char *string,...) 59174993Srafan{ 6050276Speter extern jmp_buf toplevel; 61174993Srafan va_list args; 62166124Srafan va_start (args, string); 63166124Srafan fflush (stdout); 64166124Srafan vfprintf (stderr, string, args); 65166124Srafan fprintf (stderr, "\n"); 66166124Srafan longjmp (toplevel, 1); 67166124Srafan} 68166124Srafan 69166124Srafan/* Print an error message and exit reporting failure. 70166124Srafan This is for a error that we cannot continue from. 7150276Speter STRING and ARG are passed to fprintf. */ 72166124Srafan 73166124Srafan/* VARARGS */ 74166124Srafanvoid 75166124Srafanfatal (const char *string,...) 76166124Srafan{ 77166124Srafan va_list args; 78166124Srafan va_start (args, string); 7950276Speter fprintf (stderr, "gdb: "); 80166124Srafan vfprintf (stderr, string, args); 8150276Speter fprintf (stderr, "\n"); 82166124Srafan va_end (args); 8350276Speter exit (1); 8450276Speter} 85166124Srafan 8650276Speter/* VARARGS */ 87166124Srafanvoid 88166124Srafanwarning (const char *string,...) 89166124Srafan{ 9050276Speter va_list args; 9150276Speter va_start (args, string); 9250276Speter fprintf (stderr, "gdb: "); 9350276Speter vfprintf (stderr, string, args); 94166124Srafan fprintf (stderr, "\n"); 9550276Speter va_end (args); 9650276Speter} 9750276Speter