[1/6] Move throw_perror_with_name to common/
Commit Message
I have a use for throw_perror_with_name in nat/, but currently, only
perror_with_name is available to common gdb+gdbserver code. This
patch makes throw_perror_with_name the function that client need to
implement (instead of perror_with_name), and adds a common
perror_with_name as a wrapper over throw_perror_with_name, just like
GDB's is currently.
gdb/ChangeLog:
2015-03-06 Pedro Alves <palves@redhat.com>
* utils.c (perror_with_name): Move ...
* common/errors.c (perror_with_name): ... here.
* common/errors.h: Include common-exceptions.h.
(throw_perror_with_name): Declare.
(perror_with_name): Update comment.
gdb/gdbserver/ChangeLog:
2015-03-06 Pedro Alves <palves@redhat.com>
* utils.c (perror_with_name): Rename to ...
(throw_perror_with_name): ... this. Use throw_error in gdbserver.
---
gdb/common/errors.c | 8 ++++++++
gdb/common/errors.h | 13 +++++++++++--
gdb/gdbserver/utils.c | 6 +++++-
gdb/utils.c | 8 --------
4 files changed, 24 insertions(+), 11 deletions(-)
@@ -67,3 +67,11 @@ internal_warning (const char *file, int line, const char *fmt, ...)
internal_vwarning (file, line, fmt, ap);
va_end (ap);
}
+
+/* See common/errors.h. */
+
+void
+perror_with_name (const char *string)
+{
+ throw_perror_with_name (GENERIC_ERROR, string);
+}
@@ -20,6 +20,8 @@
#ifndef COMMON_ERRORS_H
#define COMMON_ERRORS_H
+#include "common-exceptions.h"
+
/* A problem was detected, but the requested operation can still
proceed. A warning message is constructed using a printf- or
vprintf-style argument list. The function "vwarning" must be
@@ -76,8 +78,15 @@ extern void internal_vwarning (const char *file, int line,
/* Like "error", but the error message is constructed by combining
- STRING with the system error message for errno. This function does
- not return. This function must be provided by the client. */
+ STRING with the system error message for errno. Uses ERRCODE for
+ the thrown exception. This function does not return. This
+ function must be provided by the client. */
+
+extern void throw_perror_with_name (enum errors errcode, const char *string)
+ ATTRIBUTE_NORETURN;
+
+/* Convenience wrapper for "throw_perror_with_name" that throws
+ GENERIC_ERROR. */
extern void perror_with_name (const char *string) ATTRIBUTE_NORETURN;
@@ -54,7 +54,7 @@ xstrdup (const char *s)
Then return to command level. */
void
-perror_with_name (const char *string)
+throw_perror_with_name (enum errors errcode, const char *string)
{
const char *err;
char *combined;
@@ -68,7 +68,11 @@ perror_with_name (const char *string)
strcat (combined, ": ");
strcat (combined, err);
+#ifdef IN_PROCESS_AGENT
error ("%s.", combined);
+#else
+ throw_error (errcode, "%s.", combined);
+#endif
}
/* Print an error message and return to top level. */
@@ -990,14 +990,6 @@ throw_perror_with_name (enum errors errcode, const char *string)
throw_error (errcode, _("%s."), combined);
}
-/* See throw_perror_with_name, ERRCODE defaults here to GENERIC_ERROR. */
-
-void
-perror_with_name (const char *string)
-{
- throw_perror_with_name (GENERIC_ERROR, string);
-}
-
/* Same as perror_with_name except that it prints a warning instead
of throwing an error. */