Home | History | Annotate | Line # | Download | only in gdbsupport
errors.h revision 1.1.1.4
      1 /* Declarations for error-reporting facilities.
      2 
      3    Copyright (C) 1986-2024 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 3 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, see <http://www.gnu.org/licenses/>.  */
     19 
     20 #ifndef GDBSUPPORT_ERRORS_H
     21 #define GDBSUPPORT_ERRORS_H
     22 
     23 /* A problem was detected, but the requested operation can still
     24    proceed.  A warning message is constructed using a printf- or
     25    vprintf-style argument list.  The function "vwarning" must be
     26    provided by the client.  */
     27 
     28 extern void warning (const char *fmt, ...)
     29      ATTRIBUTE_PRINTF (1, 2);
     30 
     31 extern void vwarning (const char *fmt, va_list args)
     32      ATTRIBUTE_PRINTF (1, 0);
     33 
     34 /* A non-predictable, non-fatal error was detected.  The requested
     35    operation cannot proceed.  An error message is constructed using
     36    a printf- or vprintf-style argument list.  These functions do not
     37    return.  The function "verror" must be provided by the client.  */
     38 
     39 [[noreturn]] extern void error (const char *fmt, ...) ATTRIBUTE_PRINTF (1, 2);
     40 
     41 [[noreturn]] extern void verror (const char *fmt, va_list args)
     42   ATTRIBUTE_PRINTF (1, 0);
     43 
     44 /* An internal error was detected.  Internal errors indicate
     45    programming errors such as assertion failures, as opposed to
     46    more general errors beyond the application's control.  These
     47    functions do not return.  An error message is constructed using
     48    a printf- or vprintf-style argument list.  FILE and LINE
     49    indicate the file and line number where the programming error
     50    was detected.  Most client code should call the internal_error
     51    wrapper macro instead, which expands the source location
     52    automatically.  The function "internal_verror" must be provided
     53    by the client.  */
     54 
     55 [[noreturn]] extern void internal_error_loc (const char *file, int line,
     56 					     const char *fmt, ...)
     57   ATTRIBUTE_PRINTF (3, 4);
     58 
     59 #define internal_error(fmt, ...)				\
     60   internal_error_loc (__FILE__, __LINE__, fmt, ##__VA_ARGS__)
     61 
     62 [[noreturn]] extern void internal_verror (const char *file, int line,
     63 					  const char *fmt, va_list args)
     64   ATTRIBUTE_PRINTF (3, 0);
     65 
     66 /* An internal problem was detected, but the requested operation can
     67    still proceed.  Internal warnings indicate programming errors as
     68    opposed to more general issues beyond the application's control.
     69    A warning message is constructed using a printf- or vprintf-style
     70    argument list.  The function "internal_vwarning" must be provided
     71    by the client.  */
     72 
     73 extern void internal_warning_loc (const char *file, int line,
     74 				  const char *fmt, ...)
     75      ATTRIBUTE_PRINTF (3, 4);
     76 
     77 #define internal_warning(fmt, ...)				\
     78   internal_warning_loc (__FILE__, __LINE__, fmt, ##__VA_ARGS__)
     79 
     80 extern void internal_vwarning (const char *file, int line,
     81 			       const char *fmt, va_list args)
     82      ATTRIBUTE_PRINTF (3, 0);
     83 
     84 
     86 /* Return a newly allocated string, containing the PREFIX followed
     87    by the system error message for errno (separated by a colon).
     88    If ERRNUM is given, then use it in place of errno.  */
     89 
     90 extern std::string perror_string (const char *prefix, int errnum = 0);
     91 
     92 /* Like "error", but the error message is constructed by combining
     93    STRING with the system error message for errno.  If ERRNUM is given,
     94    then use it in place of errno.  This function does not return.  */
     95 
     96 [[noreturn]] extern void perror_with_name (const char *string, int errnum = 0);
     97 
     98 /* Call this function to handle memory allocation failures.  This
     99    function does not return.  This function must be provided by the
    100    client.  */
    101 
    102 [[noreturn]] extern void malloc_failure (long size);
    103 
    104 /* Flush stdout and stderr.  Must be provided by the client.  */
    105 
    106 extern void flush_streams ();
    107 
    108 #if defined(USE_WIN32API) || defined(__CYGWIN__)
    109 
    110 /* Map the Windows error number in ERROR to a locale-dependent error
    111    message string and return a pointer to it.  Typically, the values
    112    for ERROR come from GetLastError.
    113 
    114    The string pointed to shall not be modified by the application,
    115    but may be overwritten by a subsequent call to strwinerror
    116 
    117    The strwinerror function does not change the current setting
    118    of GetLastError.  */
    119 
    120 extern const char *strwinerror (ULONGEST error);
    121 
    122 /* Like perror_with_name, but for Windows errors.  Throw an exception
    123    including STRING and the system text for the given error
    124    number.  */
    125 
    126 [[noreturn]] extern void throw_winerror_with_name (const char *string,
    127 						   ULONGEST err);
    128 
    129 #endif /* USE_WIN32API */
    130 
    131 #endif /* GDBSUPPORT_ERRORS_H */
    132