gdb/gdbserver/
authorPedro Alves <palves@redhat.com>
Tue, 16 Mar 2010 17:47:52 +0000 (17:47 +0000)
committerPedro Alves <palves@redhat.com>
Tue, 16 Mar 2010 17:47:52 +0000 (17:47 +0000)
* server.h (internal_error): Declare.
(gdb_assert, ASSERT_FUNCTION, gdb_assert_fail): Define.
* utils.c (internal_error): New function.

gdb/gdbserver/ChangeLog
gdb/gdbserver/server.h
gdb/gdbserver/utils.c

index e76390e52b8b8f22481fa24418d5e656d10b1789..29444894ddda38fec2aa5620dde2cec7e2ae177b 100644 (file)
@@ -1,3 +1,9 @@
+2010-03-16  Pedro Alves  <pedro@codesourcery.com>
+
+       * server.h (internal_error): Declare.
+       (gdb_assert, ASSERT_FUNCTION, gdb_assert_fail): Define.
+       * utils.c (internal_error): New function.
+
 2010-03-15  Andreas Schwab  <schwab@redhat.com>
 
        * configure.srv: Fix typo setting srv_regobj.
index f46ee603f9a23c1163a1ab64fc757f653f95ac54..18232956190eaf35bc72a88e0d4455725aecc495 100644 (file)
@@ -407,9 +407,39 @@ void freeargv (char **argv);
 void perror_with_name (const char *string);
 void error (const char *string,...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
 void fatal (const char *string,...) ATTR_NORETURN ATTR_FORMAT (printf, 1, 2);
+void internal_error (const char *file, int line, const char *, ...)
+     ATTR_NORETURN ATTR_FORMAT (printf, 3, 4);
 void warning (const char *string,...) ATTR_FORMAT (printf, 1, 2);
 char *paddress (CORE_ADDR addr);
 
+#define gdb_assert(expr)                                                      \
+  ((void) ((expr) ? 0 :                                                       \
+          (gdb_assert_fail (#expr, __FILE__, __LINE__, ASSERT_FUNCTION), 0)))
+
+/* Version 2.4 and later of GCC define a magical variable `__PRETTY_FUNCTION__'
+   which contains the name of the function currently being defined.
+   This is broken in G++ before version 2.6.
+   C9x has a similar variable called __func__, but prefer the GCC one since
+   it demangles C++ function names.  */
+#if (GCC_VERSION >= 2004)
+#define ASSERT_FUNCTION                __PRETTY_FUNCTION__
+#else
+#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
+#define ASSERT_FUNCTION                __func__
+#endif
+#endif
+
+/* This prints an "Assertion failed" message, and exits.  */
+#if defined (ASSERT_FUNCTION)
+#define gdb_assert_fail(assertion, file, line, function)               \
+  internal_error (file, line, "%s: Assertion `%s' failed.",            \
+                 function, assertion)
+#else
+#define gdb_assert_fail(assertion, file, line, function)               \
+  internal_error (file, line, "Assertion `%s' failed.",                        \
+                 assertion)
+#endif
+
 /* Maximum number of bytes to read/write at once.  The value here
    is chosen to fill up a packet (the headers account for the 32).  */
 #define MAXBUFBYTES(N) (((N)-32)/2)
index 6035f1e08230706b542702824fcdff9cdc959885..78c6f664c40c29173ca130bc2e823a5ded149301 100644 (file)
@@ -171,6 +171,22 @@ warning (const char *string,...)
   va_end (args);
 }
 
+/* Report a problem internal to GDBserver, and exit.  */
+
+void
+internal_error (const char *file, int line, const char *fmt, ...)
+{
+  va_list args;
+  va_start (args, fmt);
+
+  fprintf (stderr,  "\
+%s:%d: A problem internal to GDBserver has been detected.\n", file, line);
+  vfprintf (stderr, fmt, args);
+  fprintf (stderr, "\n");
+  va_end (args);
+  exit (1);
+}
+
 /* Temporary storage using circular buffer.  */
 #define NUMCELLS 4
 #define CELLSIZE 50
This page took 0.029489 seconds and 4 git commands to generate.