xref: /netbsd-src/external/gpl3/gdb/dist/gdbsupport/errors.h (revision 5ba1f45f2a09259cc846f20c7c5501604d633c90)
18dffb485Schristos /* Declarations for error-reporting facilities.
28dffb485Schristos 
3*5ba1f45fSchristos    Copyright (C) 1986-2024 Free Software Foundation, Inc.
48dffb485Schristos 
58dffb485Schristos    This file is part of GDB.
68dffb485Schristos 
78dffb485Schristos    This program is free software; you can redistribute it and/or modify
88dffb485Schristos    it under the terms of the GNU General Public License as published by
98dffb485Schristos    the Free Software Foundation; either version 3 of the License, or
108dffb485Schristos    (at your option) any later version.
118dffb485Schristos 
128dffb485Schristos    This program is distributed in the hope that it will be useful,
138dffb485Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
148dffb485Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
158dffb485Schristos    GNU General Public License for more details.
168dffb485Schristos 
178dffb485Schristos    You should have received a copy of the GNU General Public License
188dffb485Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
198dffb485Schristos 
208dffb485Schristos #ifndef COMMON_ERRORS_H
218dffb485Schristos #define COMMON_ERRORS_H
228dffb485Schristos 
238dffb485Schristos /* A problem was detected, but the requested operation can still
248dffb485Schristos    proceed.  A warning message is constructed using a printf- or
258dffb485Schristos    vprintf-style argument list.  The function "vwarning" must be
268dffb485Schristos    provided by the client.  */
278dffb485Schristos 
288dffb485Schristos extern void warning (const char *fmt, ...)
298dffb485Schristos      ATTRIBUTE_PRINTF (1, 2);
308dffb485Schristos 
318dffb485Schristos extern void vwarning (const char *fmt, va_list args)
328dffb485Schristos      ATTRIBUTE_PRINTF (1, 0);
338dffb485Schristos 
348dffb485Schristos /* A non-predictable, non-fatal error was detected.  The requested
358dffb485Schristos    operation cannot proceed.  An error message is constructed using
368dffb485Schristos    a printf- or vprintf-style argument list.  These functions do not
378dffb485Schristos    return.  The function "verror" must be provided by the client.  */
388dffb485Schristos 
398dffb485Schristos extern void error (const char *fmt, ...)
408dffb485Schristos      ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 2);
418dffb485Schristos 
428dffb485Schristos extern void verror (const char *fmt, va_list args)
438dffb485Schristos      ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (1, 0);
448dffb485Schristos 
458dffb485Schristos /* An internal error was detected.  Internal errors indicate
468dffb485Schristos    programming errors such as assertion failures, as opposed to
478dffb485Schristos    more general errors beyond the application's control.  These
488dffb485Schristos    functions do not return.  An error message is constructed using
498dffb485Schristos    a printf- or vprintf-style argument list.  FILE and LINE
508dffb485Schristos    indicate the file and line number where the programming error
514b169a6bSchristos    was detected.  Most client code should call the internal_error
524b169a6bSchristos    wrapper macro instead, which expands the source location
534b169a6bSchristos    automatically.  The function "internal_verror" must be provided
548dffb485Schristos    by the client.  */
558dffb485Schristos 
564b169a6bSchristos extern void internal_error_loc (const char *file, int line,
578dffb485Schristos 				const char *fmt, ...)
588dffb485Schristos      ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 4);
598dffb485Schristos 
604b169a6bSchristos #define internal_error(fmt, ...)				\
614b169a6bSchristos   internal_error_loc (__FILE__, __LINE__, fmt, ##__VA_ARGS__)
624b169a6bSchristos 
638dffb485Schristos extern void internal_verror (const char *file, int line,
648dffb485Schristos 			     const char *fmt, va_list args)
658dffb485Schristos      ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 0);
668dffb485Schristos 
678dffb485Schristos /* An internal problem was detected, but the requested operation can
688dffb485Schristos    still proceed.  Internal warnings indicate programming errors as
698dffb485Schristos    opposed to more general issues beyond the application's control.
708dffb485Schristos    A warning message is constructed using a printf- or vprintf-style
718dffb485Schristos    argument list.  The function "internal_vwarning" must be provided
728dffb485Schristos    by the client.  */
738dffb485Schristos 
744b169a6bSchristos extern void internal_warning_loc (const char *file, int line,
758dffb485Schristos 				  const char *fmt, ...)
768dffb485Schristos      ATTRIBUTE_PRINTF (3, 4);
778dffb485Schristos 
784b169a6bSchristos #define internal_warning(fmt, ...)				\
794b169a6bSchristos   internal_warning_loc (__FILE__, __LINE__, fmt, ##__VA_ARGS__)
804b169a6bSchristos 
818dffb485Schristos extern void internal_vwarning (const char *file, int line,
828dffb485Schristos 			       const char *fmt, va_list args)
838dffb485Schristos      ATTRIBUTE_PRINTF (3, 0);
848dffb485Schristos 
858dffb485Schristos 
86*5ba1f45fSchristos /* Return a newly allocated string, containing the PREFIX followed
87*5ba1f45fSchristos    by the system error message for errno (separated by a colon).
88*5ba1f45fSchristos    If ERRNUM is given, then use it in place of errno.  */
898dffb485Schristos 
90*5ba1f45fSchristos extern std::string perror_string (const char *prefix, int errnum = 0);
91*5ba1f45fSchristos 
92*5ba1f45fSchristos /* Like "error", but the error message is constructed by combining
93*5ba1f45fSchristos    STRING with the system error message for errno.  If ERRNUM is given,
94*5ba1f45fSchristos    then use it in place of errno.  This function does not return.  */
95*5ba1f45fSchristos 
96*5ba1f45fSchristos extern void perror_with_name (const char *string, int errnum = 0)
97*5ba1f45fSchristos     ATTRIBUTE_NORETURN;
988dffb485Schristos 
998dffb485Schristos /* Call this function to handle memory allocation failures.  This
1008dffb485Schristos    function does not return.  This function must be provided by the
1018dffb485Schristos    client.  */
1028dffb485Schristos 
1038dffb485Schristos extern void malloc_failure (long size) ATTRIBUTE_NORETURN;
1048dffb485Schristos 
1058dffb485Schristos /* Flush stdout and stderr.  Must be provided by the client.  */
1068dffb485Schristos 
1078dffb485Schristos extern void flush_streams ();
1088dffb485Schristos 
1094b169a6bSchristos #if defined(USE_WIN32API) || defined(__CYGWIN__)
1104b169a6bSchristos 
1114b169a6bSchristos /* Map the Windows error number in ERROR to a locale-dependent error
1124b169a6bSchristos    message string and return a pointer to it.  Typically, the values
1134b169a6bSchristos    for ERROR come from GetLastError.
1144b169a6bSchristos 
1154b169a6bSchristos    The string pointed to shall not be modified by the application,
1164b169a6bSchristos    but may be overwritten by a subsequent call to strwinerror
1174b169a6bSchristos 
1184b169a6bSchristos    The strwinerror function does not change the current setting
1194b169a6bSchristos    of GetLastError.  */
1204b169a6bSchristos 
1214b169a6bSchristos extern const char *strwinerror (ULONGEST error);
1224b169a6bSchristos 
123*5ba1f45fSchristos /* Like perror_with_name, but for Windows errors.  Throw an exception
124*5ba1f45fSchristos    including STRING and the system text for the given error
125*5ba1f45fSchristos    number.  */
126*5ba1f45fSchristos 
127*5ba1f45fSchristos extern void throw_winerror_with_name (const char *string, ULONGEST err)
128*5ba1f45fSchristos   ATTRIBUTE_NORETURN;
129*5ba1f45fSchristos 
1304b169a6bSchristos #endif /* USE_WIN32API */
1314b169a6bSchristos 
1328dffb485Schristos #endif /* COMMON_ERRORS_H */
133