1 /* Error reporting facilities.
3 Copyright (C) 1986-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
21 #if defined (USE_WIN32API) || defined(__CYGWIN__)
23 #endif /* USE_WIN32API */
25 /* See gdbsupport/errors.h. */
28 warning (const char *fmt
, ...)
37 /* See gdbsupport/errors.h. */
40 error (const char *fmt
, ...)
49 /* See gdbsupport/errors.h. */
52 internal_error_loc (const char *file
, int line
, const char *fmt
, ...)
57 internal_verror (file
, line
, fmt
, ap
);
61 /* See gdbsupport/errors.h. */
64 internal_warning_loc (const char *file
, int line
, const char *fmt
, ...)
69 internal_vwarning (file
, line
, fmt
, ap
);
76 perror_string (const char *prefix
, int errnum
)
81 err
= safe_strerror (errnum
);
83 err
= safe_strerror (errno
);
84 return std::string (prefix
) + ": " + err
;
90 perror_with_name (const char *string
, int errnum
)
92 std::string combined
= perror_string (string
, errnum
);
94 error (_("%s."), combined
.c_str ());
97 #if defined (USE_WIN32API) || defined(__CYGWIN__)
102 strwinerror (ULONGEST error
)
104 static char buf
[1024];
106 DWORD lasterr
= GetLastError ();
107 DWORD chars
= FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
108 | FORMAT_MESSAGE_ALLOCATE_BUFFER
,
111 0, /* Default language */
117 /* If there is an \r\n appended, zap it. */
119 && msgbuf
[chars
- 2] == '\r'
120 && msgbuf
[chars
- 1] == '\n')
126 if (chars
> ARRAY_SIZE (buf
) - 1)
128 chars
= ARRAY_SIZE (buf
) - 1;
133 wcstombs (buf
, msgbuf
, chars
+ 1);
135 strncpy (buf
, msgbuf
, chars
+ 1);
140 sprintf (buf
, "unknown win32 error (%u)", (unsigned) error
);
142 SetLastError (lasterr
);
149 throw_winerror_with_name (const char *string
, ULONGEST err
)
151 error (_("%s (error %u): %s"), string
, (unsigned) err
, strwinerror (err
));
154 #endif /* USE_WIN32API */