This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 1/6] Move throw_perror_with_name to common/
- From: Pedro Alves <palves at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Fri, 6 Mar 2015 19:58:01 +0000
- Subject: [PATCH 1/6] Move throw_perror_with_name to common/
- Authentication-results: sourceware.org; auth=none
- References: <1425671886-7798-1-git-send-email-palves at redhat dot com>
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(-)
diff --git a/gdb/common/errors.c b/gdb/common/errors.c
index 00b325e..5fd4a80 100644
--- a/gdb/common/errors.c
+++ b/gdb/common/errors.c
@@ -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);
+}
diff --git a/gdb/common/errors.h b/gdb/common/errors.h
index 36e2c49..c7d85f1 100644
--- a/gdb/common/errors.h
+++ b/gdb/common/errors.h
@@ -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;
diff --git a/gdb/gdbserver/utils.c b/gdb/gdbserver/utils.c
index e89a862..cd5734b 100644
--- a/gdb/gdbserver/utils.c
+++ b/gdb/gdbserver/utils.c
@@ -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. */
diff --git a/gdb/utils.c b/gdb/utils.c
index 7172bba..6b1aa89 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -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. */
--
1.9.3