This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: RFC: internal_error() change + abort()


   Date: Mon, 24 Jul 2000 20:20:00 +1000
   From: Andrew Cagney <ac131313@cygnus.com>

   Yes, the one remaining abort() call would be in internal_error().

   As a generalization, GDB should never abort.  The last thing you want is
   your complext debug session to be terminated by the debugger dumping
   core :-(

Somewhat related to this subject, here's a replacement for assert() I
hacked up a few weaks ago.  It's modelled after the assert() in the
GNU C Library, and very useful since I cannot quit the habit of
littering my code with assertions :-)

Any chance of adding this to GDB?

Mark


--- /dev/null	Thu Feb 19 16:30:24 1998
+++ gdb_assert.h	Thu Jul  6 22:45:36 2000
@@ -0,0 +1,58 @@
+/* GDB-friendly replacement for <assert.h>.
+   Copyright (C) 2000 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#if !defined (GDB_ASSERT_H)
+#define GDB_ASSERT_H
+
+#undef assert
+#undef assert_perror
+
+#define assert(expr)                                                          \
+  ((void) ((expr) ? 0 :                                                       \
+	   (assert_fail (#expr, __FILE__, __LINE__, ASSERT_FUNCTION), 0)))
+
+#define assert_perror(errnum)                                                 \
+  ((void) (!(errnum) ? 0 : (assert_perror_fail ((errnum),                     \
+						__FILE__, __LINE__,           \
+						ASSERT_FUNCTION), 0)))
+
+#if (GCC_VERSION >= 2004)
+#define ASSERT_FUNCTION		__PRETTY_FUNCTION__
+#else
+#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
+#define ASSERT_FUNCTION		__func__
+#else
+#define ASSERT_FUNCTION		((const char *) 0)
+#endif
+#endif
+
+#define assert_fail(assertion, file, line, function)                          \
+  internal_error ("%s:%u: %s%sAssertion `%s' failed.",                        \
+		  file, line,                                                 \
+		  function ? function : "", function ? ": " : "",             \
+		  assertion)
+
+#define assert_perror_fail(errnum, file, line, function)                      \
+  internal_error ("%s:%u: %s%sUnexpected error: %s.",                         \
+                  file, line,                                                 \
+                  function ? function : "", function ? ": " : "",             \
+                  strerror (errnum))
+
+#endif /* !defined (GDB_ASSERT_H) */


	   Andrew


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]