]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Modularised assertions and panics in m_libcassert.
authorNicholas Nethercote <njn@valgrind.org>
Sat, 4 Jun 2005 19:16:06 +0000 (19:16 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Sat, 4 Jun 2005 19:16:06 +0000 (19:16 +0000)
As part of this, killed the VG_STRINGIFY macro, which was used to expand
out names like "VG_(foo)" and "vgPlain_foo" in assertion failure
messages.  This is good since we actually want the "VG_(foo)" form used
in these messages.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3842

50 files changed:
cachegrind/cg_main.c
coregrind/Makefile.am
coregrind/amd64/state.c
coregrind/core.h
coregrind/linux/core_os.c
coregrind/m_aspacemgr/aspacemgr.c
coregrind/m_aspacemgr/read_procselfmaps.c
coregrind/m_debuginfo/dwarf.c
coregrind/m_debuginfo/stabs.c
coregrind/m_debuginfo/symtab.c
coregrind/m_debuginfo/symtypes.c
coregrind/m_demangle/cp-demangle.c
coregrind/m_demangle/cplus-dem.c
coregrind/m_demangle/dyn-string.c
coregrind/m_errormgr.c
coregrind/m_execontext.c
coregrind/m_hashtable.c
coregrind/m_libcassert.c [new file with mode: 0644]
coregrind/m_libcprint.c
coregrind/m_main.c
coregrind/m_mallocfree.c
coregrind/m_profile.c
coregrind/m_redir.c
coregrind/m_scheduler/scheduler.c
coregrind/m_scheduler/sema.c
coregrind/m_sigframe/sigframe-amd64-linux.c
coregrind/m_sigframe/sigframe-x86-linux.c
coregrind/m_signals.c
coregrind/m_skiplist.c
coregrind/m_stacktrace.c
coregrind/m_syscalls/syscalls-amd64-linux.c
coregrind/m_syscalls/syscalls-linux.c
coregrind/m_syscalls/syscalls-x86-linux.c
coregrind/m_syscalls/syscalls.c
coregrind/m_tooliface.c
coregrind/m_translate.c
coregrind/m_transtab.c
coregrind/pub_core_libcassert.h [new file with mode: 0644]
coregrind/vg_mylibc.c
coregrind/x86/state.c
helgrind/hg_main.c
include/Makefile.am
include/pub_tool_libcassert.h [new file with mode: 0644]
include/tool.h
massif/ms_main.c
memcheck/mac_leakcheck.c
memcheck/mac_malloc_wrappers.c
memcheck/mac_shared.c
memcheck/mc_main.c
memcheck/mc_translate.c

index 1c13db3b1b7818c37961267a9b2c8c04c765ecd8..a7bfd6b2d02c9b811e42cb1cf9384b3dca11fde5 100644 (file)
@@ -33,6 +33,7 @@
 #include "pub_tool_debuginfo.h"
 #include "pub_tool_hashtable.h"
 #include "pub_tool_libcbase.h"
+#include "pub_tool_libcassert.h"
 #include "pub_tool_libcprint.h"
 #include "pub_tool_mallocfree.h"
 #include "pub_tool_options.h"
index d5c2ef9010e0af36bae74e8cff4202897c92d71e..1068b7dec6258d71e316bf443e8e13af224055ff 100644 (file)
@@ -47,6 +47,7 @@ noinst_HEADERS = \
        pub_core_execontext.h   \
        pub_core_hashtable.h    \
        pub_core_libcbase.h     \
+       pub_core_libcassert.h   \
        pub_core_libcprint.h    \
        pub_core_main.h         \
        pub_core_mallocfree.h   \
@@ -90,6 +91,7 @@ stage2_SOURCES = \
        m_execontext.c \
        m_hashtable.c \
        m_libcbase.c \
+       m_libcassert.c \
        m_libcprint.c \
        m_main.c \
        m_mallocfree.c \
index f88ca584d03dbf8777a3bf804fe98b6630d216dc..b119873174c2bd506166a73be0b17ab030152782 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "core.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_tooliface.h"
 #include <sys/ptrace.h>
 
index 25c8ee41af1b7527ad0ebf56658fe77b0b4e116e..97ccf8bbb6d4a266fae3427520d5a649ecddcb74 100644 (file)
@@ -96,38 +96,6 @@ extern Int VG_(fd_hard_limit);
    Exports of vg_mylibc.c
    ------------------------------------------------------------------ */
 
-// Useful for making failing stubs, when certain things haven't yet been
-// implemented.
-#define I_die_here                                             \
-   VG_(assert_fail) (/*isCore*//*BOGUS*/True,                  \
-                     "Unimplemented functionality",            \
-                     __FILE__, __LINE__, __PRETTY_FUNCTION__,  \
-                     "valgrind", VG_BUGS_TO, "")
-
-#define vg_assert(expr)                                                 \
-  ((void) ((expr) ? 0 :                                                 \
-           (VG_(assert_fail) (/*isCore*/True, VG_STRINGIFY(expr),       \
-                              __FILE__, __LINE__, __PRETTY_FUNCTION__,  \
-                              ""),                                      \
-                              0)))
-
-#define vg_assert2(expr, format, args...)                               \
-  ((void) ((expr) ? 0 :                                                 \
-           (VG_(assert_fail) (/*isCore*/True, VG_STRINGIFY(expr),       \
-                              __FILE__, __LINE__, __PRETTY_FUNCTION__,  \
-                              format, ##args),                          \
-                              0)))
-
-__attribute__ ((__noreturn__))
-extern void  VG_(core_panic)      ( Char* str );
-__attribute__ ((__noreturn__))
-extern void  VG_(core_panic_at)   ( Char* str, Addr ip, Addr sp, Addr fp );
-
-/* Called when some unhandleable client behaviour is detected.
-   Prints a msg and aborts. */
-extern void VG_(unimplemented) ( Char* msg )
-            __attribute__((__noreturn__));
-
 /* Tools use VG_(strdup)() which doesn't expose ArenaId */
 extern Char* VG_(arena_strdup) ( ArenaId aid, const Char* s);
 
index 77ed8618e81a89387d5a365317b477195a77f104..dc1241033edf15007d971dbdc146679c44c6c92b 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "core.h"
 #include "pub_core_debuglog.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_signals.h"
index ded33e6e0d06b0f2ad5924ae1b4f0f8b8ea3c427..ab18b87407fab11a0664d8cf1f709bd968368fef 100644 (file)
@@ -33,6 +33,7 @@
 #include "core.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_syscalls.h"
index 7e20cc162403927da43e12527b772e4305a057e1..17971710239ca01833410ea71688f19551d86e3d 100644 (file)
@@ -33,6 +33,7 @@
 #include "core.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 
 /* Size of a smallish table used to read /proc/self/map entries. */
index 2cde63765a1ff6bdddcd594389286107ae18a699..a6b4a05f1b288f7f65ff63fccd2806bd1497a17b 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "core.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "priv_symtab.h"
index aa117a359edfe53918d5c17c15beededc103af71..3bc57b2fdffca4290b1b20f481feba16ada70d6f 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "core.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "priv_symtab.h"
 
index 94d2b323bfafeef0e200fcd7fae4065eeb5dfcf3..43f0f4c5d283e2e59109a4044399e011e15ac350 100644 (file)
@@ -33,6 +33,7 @@
 #include "pub_core_aspacemgr.h"
 #include "pub_core_demangle.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_profile.h"
index 4eae1ed5eb8c21000d6d5f84cb99851f53faa2d6..ad6d193af6cef8fb7107543bf3e74c5e155b0c8e 100644 (file)
@@ -32,6 +32,7 @@
 #include "pub_core_debuginfo.h"
 #include "pub_core_debuglog.h"    /* VG_(debugLog_vprintf) */
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_tooliface.h"
 #include "priv_symtypes.h"
index 174961fcc4d8f7cfe20602aba91d35a60c8b44a4..ac147f49d068cb1369004cba8fcc128d22ce367a 100644 (file)
@@ -42,6 +42,7 @@
 
 #include "core.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "ansidecl.h"
 #include "dyn-string.h"
 #include "demangle.h"
index e854c04c8fd94c85ad6e665812dc2fed03f7e54f..ec32a3a728e3aa447d4114a265601b458131fedd 100644 (file)
@@ -39,6 +39,7 @@ Boston, MA 02111-1307, USA.  */
 #include "safe-ctype.h"
 #include "core.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_tool_libcprint.h"
 
 /*#include <sys/types.h>
index c5ef67252facd052e1b0bbcd9f46ef3f00df479c..a51d455985813fdb96daee8f80489dba664877ca 100644 (file)
@@ -33,6 +33,7 @@ Boston, MA 02111-1307, USA.  */
 
 #include "core.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "ansidecl.h"
 #include "dyn-string.h"
 
index fe36d2291ebf654926d4f244b1b5100e97f9f4de..71ae7ceb2bcfd00db534759761c1d917727470cb 100644 (file)
@@ -33,6 +33,7 @@
 #include "pub_core_errormgr.h"
 #include "pub_core_execontext.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_main.h"          // for VG_(start_debugger)()
 #include "pub_core_options.h"
index f53f151d7eb1a031140eb7983807c4be6720ec4d..01270d0ad34bbfc9e8320ceac00b44691fe1c037 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "core.h"
 #include "pub_core_execontext.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_profile.h"
index d9748aab84548505799b2ea7b0e9b79c1b405a72..c3b6e3c4d1448c10bbc72372dcb0ca8aefc81b5f 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "core.h"
 #include "pub_core_hashtable.h"
+#include "pub_core_libcassert.h"
 
 /*--------------------------------------------------------------------*/
 /*--- Declarations                                                 ---*/
diff --git a/coregrind/m_libcassert.c b/coregrind/m_libcassert.c
new file mode 100644 (file)
index 0000000..b5c5373
--- /dev/null
@@ -0,0 +1,194 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Assertions and panics.                        m_libcassert.c ---*/
+/*--------------------------------------------------------------------*/
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2005 Julian Seward 
+      jseward@acm.org
+
+   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.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#include "core.h"
+#include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
+#include "pub_core_libcprint.h"
+#include "pub_core_main.h"
+#include "pub_core_stacktrace.h"
+#include "pub_core_tooliface.h"
+
+/* ---------------------------------------------------------------------
+   Assertery.
+   ------------------------------------------------------------------ */
+
+#if defined(VGP_x86_linux)
+#  define GET_REAL_SP_AND_FP(sp, fp) \
+      asm("movl %%esp, %0;" \
+          "movl %%ebp, %1;" \
+          : "=r" (sp),\
+            "=r" (fp));
+#elif defined(VGP_amd64_linux)
+#  define GET_REAL_SP_AND_FP(sp, fp) \
+      asm("movq %%rsp, %0;" \
+          "movq %%rbp, %1;" \
+          : "=r" (sp),\
+            "=r" (fp));
+#else
+#  error Unknown platform
+#endif
+
+__attribute__ ((noreturn))
+static void report_and_quit ( const Char* report, Addr ip, Addr sp, Addr fp )
+{
+   #define BACKTRACE_DEPTH    100         // nice and deep!
+   Addr stacktop, ips[BACKTRACE_DEPTH];
+   ThreadState *tst;
+
+   tst = VG_(get_ThreadState)( VG_(get_lwp_tid)(VG_(gettid)()) );
+
+   // If necessary, fake up an ExeContext which is of our actual real CPU
+   // state.  Could cause problems if we got the panic/exception within the
+   // execontext/stack dump/symtab code.  But it's better than nothing.
+   if (0 == ip && 0 == sp && 0 == fp) {
+       ip = (Addr)__builtin_return_address(0);
+       GET_REAL_SP_AND_FP(sp, fp);
+   }
+
+   stacktop = tst->os_state.valgrind_stack_base + 
+              tst->os_state.valgrind_stack_szB;
+
+   VG_(get_StackTrace2)(ips, BACKTRACE_DEPTH, ip, sp, fp, sp, stacktop);
+   VG_(pp_StackTrace)  (ips, BACKTRACE_DEPTH);
+
+   VG_(printf)("\nBasic block ctr is approximately %llu\n", VG_(bbs_done) );
+
+   VG_(pp_sched_status)();
+   VG_(printf)("\n");
+   VG_(printf)("Note: see also the FAQ.txt in the source distribution.\n");
+   VG_(printf)("It contains workarounds to several common problems.\n");
+   VG_(printf)("\n");
+   VG_(printf)("If that doesn't help, please report this bug to: %s\n\n", 
+               report);
+   VG_(printf)("In the bug report, send all the above text, the valgrind\n");
+   VG_(printf)("version, and what Linux distro you are using.  Thanks.\n\n");
+   VG_(exit)(1);
+
+   #undef BACKTRACE_DEPTH
+}
+
+void VG_(assert_fail) ( Bool isCore, const Char* expr, const Char* file, 
+                        Int line, const Char* fn, const HChar* format, ... )
+{
+   va_list vargs;
+   Char buf[256];
+   Char* bufptr = buf;
+   Char* component;
+   Char* bugs_to;
+
+   static Bool entered = False;
+   if (entered) 
+     VG_(exit)(2);
+   entered = True;
+
+   va_start(vargs, format);
+   VG_(vsprintf) ( bufptr, format, vargs );
+   va_end(vargs);
+
+   if (isCore) {
+      component = "valgrind";
+      bugs_to   = VG_BUGS_TO;
+   } else { 
+      component = VG_(details).name;
+      bugs_to   = VG_(details).bug_reports_to;
+   }
+
+   // Treat vg_assert2(0, "foo") specially, as a panicky abort
+   if (VG_STREQ(expr, "0")) {
+      VG_(printf)("\n%s: %s:%d (%s): the 'impossible' happened.\n",
+                  component, file, line, fn, expr );
+   } else {
+      VG_(printf)("\n%s: %s:%d (%s): Assertion '%s' failed.\n",
+                  component, file, line, fn, expr );
+   }
+   if (!VG_STREQ(buf, ""))
+      VG_(printf)("%s: %s\n", component, buf );
+
+   report_and_quit(bugs_to, 0,0,0);
+}
+
+__attribute__ ((noreturn))
+static void panic ( Char* name, Char* report, Char* str,
+                    Addr ip, Addr sp, Addr fp )
+{
+   VG_(printf)("\n%s: the 'impossible' happened:\n   %s\n", name, str);
+   report_and_quit(report, ip, sp, fp);
+}
+
+void VG_(core_panic_at) ( Char* str, Addr ip, Addr sp, Addr fp )
+{
+   panic("valgrind", VG_BUGS_TO, str, ip, sp, fp);
+}
+
+void VG_(core_panic) ( Char* str )
+{
+   VG_(core_panic_at)(str, 0,0,0);
+}
+
+void VG_(tool_panic) ( Char* str )
+{
+   panic(VG_(details).name, VG_(details).bug_reports_to, str, 0,0,0);
+}
+
+/* Print some helpful-ish text about unimplemented things, and give
+   up. */
+void VG_(unimplemented) ( Char* msg )
+{
+   VG_(message)(Vg_UserMsg, "");
+   VG_(message)(Vg_UserMsg, 
+      "Valgrind detected that your program requires");
+   VG_(message)(Vg_UserMsg, 
+      "the following unimplemented functionality:");
+   VG_(message)(Vg_UserMsg, "   %s", msg);
+   VG_(message)(Vg_UserMsg,
+      "This may be because the functionality is hard to implement,");
+   VG_(message)(Vg_UserMsg,
+      "or because no reasonable program would behave this way,");
+   VG_(message)(Vg_UserMsg,
+      "or because nobody has yet needed it.  In any case, let us know at");
+   VG_(message)(Vg_UserMsg,
+      "%s and/or try to work around the problem, if you can.", VG_BUGS_TO);
+   VG_(message)(Vg_UserMsg,
+      "");
+   VG_(message)(Vg_UserMsg,
+      "Valgrind has to exit now.  Sorry.  Bye!");
+   VG_(message)(Vg_UserMsg,
+      "");
+   VG_(pp_sched_status)();
+   VG_(exit)(1);
+}
+
+
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
+
index be5701cc6cf242dbdae9efd4fc08e00931a8b6a9..f782c48841a76e73700d15cf6220521e5c8b0d9b 100644 (file)
@@ -31,6 +31,7 @@
 #include "core.h"
 #include "pub_core_debuglog.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "valgrind.h"           // for RUNNING_ON_VALGRIND
index d64272bc0d4b39dc3bef74234f9d7ee366bb22b4..7a2e424ff13199a7e482bd0d0fd65449fa40e3b8 100644 (file)
@@ -37,6 +37,7 @@
 #include "pub_core_errormgr.h"
 #include "pub_core_execontext.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_main.h"
 #include "pub_core_options.h"
index 3c09ef92e8b29131fc68959d4c37fc030e177413..235c923bb15c371b283ae7f779efe30d19d81cb3 100644 (file)
@@ -33,6 +33,7 @@
 #include "core.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_profile.h"
index 2f72aa308d0529bb9490ac728cf880a7142f6860..965503abbbe79c54a161b70008a3a75fd05bbc67 100644 (file)
@@ -29,6 +29,7 @@
 */
 
 #include "core.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_profile.h"
 
index 81afc96c61f544f20ae2a1c4942b1a030698da5f..bfcb1b26f198de8e8ed838f01d184c09110378c8 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_skiplist.h"
 #include "pub_core_options.h"
index 5455ce7e7b6439e692283a081335cbe0ccd389ce..43a537818a34c72a1899110b5d7068851bbe8341 100644 (file)
@@ -64,6 +64,7 @@
 #include "pub_core_dispatch.h"
 #include "pub_core_errormgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_main.h"
 #include "pub_core_options.h"
index 8d06651fb3cdb75f9aef23b8e693d0f2850ae53a..5db9e587911b1a82322f4c67e87a5e7ddb3b3ac0 100644 (file)
@@ -29,6 +29,7 @@
 */
 
 #include "core.h"
+#include "pub_core_libcassert.h"
 #include "priv_sema.h"
 
 /* 
index 33593bc96f7654060b3d1bb2d2da568bb3135bd9..19c859e1b914f3302ba5126bc4a88306416443d6 100644 (file)
@@ -32,6 +32,7 @@
 #include "core.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_sigframe.h"
index f76058693543c692732825ae99a5c02b54cabcd8..e94f888d0fffee299ad08f9dc71022c6ccddef27 100644 (file)
@@ -32,6 +32,7 @@
 #include "core.h"
 #include "pub_core_aspacemgr.h" /* find_segment */
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_sigframe.h"
index 36d57361f61cc530f2ae1e899cae82692cdf88db..cfe0f23c97f1dafe8a1401a184586a659c0bd2c0 100644 (file)
@@ -84,6 +84,7 @@
 #include "pub_core_aspacemgr.h"
 #include "pub_core_errormgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_main.h"
 #include "pub_core_options.h"
index 17ee897c9c52476fbaa0b22022f35c6e3dc1a534..4bbc33aacefc01d446b0a1b0e58da78dfd111a1b 100644 (file)
@@ -88,6 +88,7 @@
 
 #include "core.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_skiplist.h"
 
index d9845cd2bfdeaaca289d14b675f21ebf604a02da..8af639eec5e99356d868a3b48a698bc5d916ac9a 100644 (file)
@@ -31,6 +31,7 @@
 #include "core.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_profile.h"
index e96bb2ea50800c2c6fd2c0c57c751da3ad0fef93..355034b5f695188f28c3acfc0fd029c6c6d63e23 100644 (file)
@@ -32,6 +32,7 @@
 #include "ume.h"                /* for jmp_with_stack */
 #include "pub_core_debuglog.h"
 #include "pub_core_aspacemgr.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_sigframe.h"
 #include "pub_core_syscalls.h"
index 165a97f5aa77ad561cc9b6ca29d1f4187d697842..00f5238e88fe6405068f1384edbf701c23675da8 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "core.h"
 #include "pub_core_aspacemgr.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_tooliface.h"
 #include "priv_syscalls.h"
index e4cd2675c8ec0a0ca1f966ac877ef0a7a78da4c0..691be027804196043a7d790c7abda5b5ef10145e 100644 (file)
@@ -37,6 +37,7 @@
 #include "ume.h"                /* for jmp_with_stack */
 #include "pub_core_debuglog.h"
 #include "pub_core_aspacemgr.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_sigframe.h"
 #include "pub_core_syscalls.h"
index dfc9ff6010559c11d5c30df711b84b194117e79c..0a7cbee7445cf616fd0bf549d0929e6085df7639 100644 (file)
@@ -32,6 +32,7 @@
 #include "pub_core_debuglog.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_main.h"
 #include "pub_core_profile.h"
index b9916af4711417206e88a58a4648239ea8c78001..dc06c8518d1e2688c776615db04c8149c96f2fac 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "core.h"
 #include "pub_core_tooliface.h"
+#include "pub_core_libcbase.h"
 #include "pub_core_libcprint.h"
 
 // The core/tool dictionary of functions (initially zeroed, as we want it)
@@ -100,11 +101,10 @@ VgNeeds VG_(needs) = {
 /* static */
 void VG_(sanity_check_needs) ( void)
 {
-#define CHECK_NOT(var, value)                               \
-   if ((var)==(value)) {                                    \
-      VG_(printf)("\nTool error: '%s' not initialised\n",   \
-                  VG_STRINGIFY(var));                       \
-      VG_(tool_panic)("Uninitialised details field\n");     \
+#define CHECK_NOT(var, value)                                   \
+   if ((var)==(value)) {                                        \
+      VG_(printf)("\nTool error: '%s' not initialised\n", #var);\
+      VG_(tool_panic)("Uninitialised details field\n");         \
    }
    
    /* Ones that must be set */
index 9da8aaeb21a35e348e131f0d1c7df8f92cfac7b0..86b127280a5b8c3211be73f1c7672cc2752c97d4 100644 (file)
@@ -32,6 +32,7 @@
 #include "core.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_main.h"       // for VG_(bbs_done)
 #include "pub_core_options.h"
index 8cc16997d64f0c5c323c03e0f80310fdacef2a30..a3f4dc000a8b7ed0a06e34cda1a7182a6d761e79 100644 (file)
@@ -32,6 +32,7 @@
 #include "core.h"
 #include "pub_core_debuginfo.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_options.h"
 #include "pub_core_tooliface.h"
diff --git a/coregrind/pub_core_libcassert.h b/coregrind/pub_core_libcassert.h
new file mode 100644 (file)
index 0000000..1453669
--- /dev/null
@@ -0,0 +1,77 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Assertions, etc.                       pub_core_libcassert.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2005 Julian Seward
+      jseward@acm.org
+
+   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.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_CORE_LIBCASSERT_H
+#define __PUB_CORE_LIBCASSERT_H
+
+//--------------------------------------------------------------------
+// PURPOSE: This module contains all the libc code related to assertions,
+// panics and aborting.
+//--------------------------------------------------------------------
+
+#include "pub_tool_libcassert.h"
+
+// Useful for making failing stubs, when certain things haven't yet been
+// implemented.
+#define I_die_here                                             \
+   VG_(assert_fail) (/*isCore*//*BOGUS*/True,                  \
+                     "Unimplemented functionality",            \
+                     __FILE__, __LINE__, __PRETTY_FUNCTION__,  \
+                     "valgrind", VG_BUGS_TO, "")
+
+#define vg_assert(expr)                                                 \
+  ((void) ((expr) ? 0 :                                                 \
+           (VG_(assert_fail) (/*isCore*/True, #expr,                    \
+                              __FILE__, __LINE__, __PRETTY_FUNCTION__,  \
+                              ""),                                      \
+                              0)))
+
+#define vg_assert2(expr, format, args...)                               \
+  ((void) ((expr) ? 0 :                                                 \
+           (VG_(assert_fail) (/*isCore*/True, #expr,                    \
+                              __FILE__, __LINE__, __PRETTY_FUNCTION__,  \
+                              format, ##args),                          \
+                              0)))
+
+__attribute__ ((__noreturn__))
+extern void  VG_(core_panic)      ( Char* str );
+__attribute__ ((__noreturn__))
+extern void  VG_(core_panic_at)   ( Char* str, Addr ip, Addr sp, Addr fp );
+
+/* Called when some unhandleable client behaviour is detected.
+   Prints a msg and aborts. */
+extern void VG_(unimplemented) ( Char* msg )
+            __attribute__((__noreturn__));
+
+#endif   // __PUB_CORE_LIBCASSERT_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
index 9486dac0e01d80b3a0a363fe2735f5060ec4b146..bc00797ad0afbb9d751d8cef9c5bd15b87b4cdc4 100644 (file)
@@ -34,6 +34,7 @@
 #include "pub_core_aspacemgr.h"
 #include "pub_core_debuglog.h"    /* VG_(debugLog_vprintf) */
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
 #include "pub_core_main.h"
 #include "pub_core_options.h"
@@ -437,157 +438,6 @@ Char* VG_(strdup) ( const Char* s )
    return VG_(arena_strdup) ( VG_AR_TOOL, s ); 
 }
 
-/* ---------------------------------------------------------------------
-   Assertery.
-   ------------------------------------------------------------------ */
-
-#if defined(VGP_x86_linux)
-#  define GET_REAL_SP_AND_FP(sp, fp) \
-      asm("movl %%esp, %0;" \
-          "movl %%ebp, %1;" \
-          : "=r" (sp),\
-            "=r" (fp));
-#elif defined(VGP_amd64_linux)
-#  define GET_REAL_SP_AND_FP(sp, fp) \
-      asm("movq %%rsp, %0;" \
-          "movq %%rbp, %1;" \
-          : "=r" (sp),\
-            "=r" (fp));
-#else
-#  error Unknown platform
-#endif
-
-__attribute__ ((noreturn))
-static void report_and_quit ( const Char* report, Addr ip, Addr sp, Addr fp )
-{
-   #define BACKTRACE_DEPTH    100         // nice and deep!
-   Addr stacktop, ips[BACKTRACE_DEPTH];
-   ThreadState *tst;
-
-   tst = VG_(get_ThreadState)( VG_(get_lwp_tid)(VG_(gettid)()) );
-
-   // If necessary, fake up an ExeContext which is of our actual real CPU
-   // state.  Could cause problems if we got the panic/exception within the
-   // execontext/stack dump/symtab code.  But it's better than nothing.
-   if (0 == ip && 0 == sp && 0 == fp) {
-       ip = (Addr)__builtin_return_address(0);
-       GET_REAL_SP_AND_FP(sp, fp);
-   }
-
-   stacktop = tst->os_state.valgrind_stack_base + 
-              tst->os_state.valgrind_stack_szB;
-
-   VG_(get_StackTrace2)(ips, BACKTRACE_DEPTH, ip, sp, fp, sp, stacktop);
-   VG_(pp_StackTrace)  (ips, BACKTRACE_DEPTH);
-
-   VG_(printf)("\nBasic block ctr is approximately %llu\n", VG_(bbs_done) );
-
-   VG_(pp_sched_status)();
-   VG_(printf)("\n");
-   VG_(printf)("Note: see also the FAQ.txt in the source distribution.\n");
-   VG_(printf)("It contains workarounds to several common problems.\n");
-   VG_(printf)("\n");
-   VG_(printf)("If that doesn't help, please report this bug to: %s\n\n", 
-               report);
-   VG_(printf)("In the bug report, send all the above text, the valgrind\n");
-   VG_(printf)("version, and what Linux distro you are using.  Thanks.\n\n");
-   VG_(exit)(1);
-
-   #undef BACKTRACE_DEPTH
-}
-
-void VG_(assert_fail) ( Bool isCore, const Char* expr, const Char* file, 
-                        Int line, const Char* fn, const HChar* format, ... )
-{
-   va_list vargs;
-   Char buf[256];
-   Char* bufptr = buf;
-   Char* component;
-   Char* bugs_to;
-
-   static Bool entered = False;
-   if (entered) 
-     VG_(exit)(2);
-   entered = True;
-
-   va_start(vargs, format);
-   VG_(vsprintf) ( bufptr, format, vargs );
-   va_end(vargs);
-
-   if (isCore) {
-      component = "valgrind";
-      bugs_to   = VG_BUGS_TO;
-   } else { 
-      component = VG_(details).name;
-      bugs_to   = VG_(details).bug_reports_to;
-   }
-
-   // Treat vg_assert2(0, "foo") specially, as a panicky abort
-   if (VG_STREQ(expr, "0")) {
-      VG_(printf)("\n%s: %s:%d (%s): the 'impossible' happened.\n",
-                  component, file, line, fn, expr );
-   } else {
-      VG_(printf)("\n%s: %s:%d (%s): Assertion '%s' failed.\n",
-                  component, file, line, fn, expr );
-   }
-   if (!VG_STREQ(buf, ""))
-      VG_(printf)("%s: %s\n", component, buf );
-
-   report_and_quit(bugs_to, 0,0,0);
-}
-
-__attribute__ ((noreturn))
-static void panic ( Char* name, Char* report, Char* str,
-                    Addr ip, Addr sp, Addr fp )
-{
-   VG_(printf)("\n%s: the 'impossible' happened:\n   %s\n", name, str);
-   report_and_quit(report, ip, sp, fp);
-}
-
-void VG_(core_panic_at) ( Char* str, Addr ip, Addr sp, Addr fp )
-{
-   panic("valgrind", VG_BUGS_TO, str, ip, sp, fp);
-}
-
-void VG_(core_panic) ( Char* str )
-{
-   VG_(core_panic_at)(str, 0,0,0);
-}
-
-void VG_(tool_panic) ( Char* str )
-{
-   panic(VG_(details).name, VG_(details).bug_reports_to, str, 0,0,0);
-}
-
-/* Print some helpful-ish text about unimplemented things, and give
-   up. */
-void VG_(unimplemented) ( Char* msg )
-{
-   VG_(message)(Vg_UserMsg, "");
-   VG_(message)(Vg_UserMsg, 
-      "Valgrind detected that your program requires");
-   VG_(message)(Vg_UserMsg, 
-      "the following unimplemented functionality:");
-   VG_(message)(Vg_UserMsg, "   %s", msg);
-   VG_(message)(Vg_UserMsg,
-      "This may be because the functionality is hard to implement,");
-   VG_(message)(Vg_UserMsg,
-      "or because no reasonable program would behave this way,");
-   VG_(message)(Vg_UserMsg,
-      "or because nobody has yet needed it.  In any case, let us know at");
-   VG_(message)(Vg_UserMsg,
-      "%s and/or try to work around the problem, if you can.", VG_BUGS_TO);
-   VG_(message)(Vg_UserMsg,
-      "");
-   VG_(message)(Vg_UserMsg,
-      "Valgrind has to exit now.  Sorry.  Bye!");
-   VG_(message)(Vg_UserMsg,
-      "");
-   VG_(pp_sched_status)();
-   VG_(exit)(1);
-}
-
-
 /* ---------------------------------------------------------------------
    Primitive support for reading files.
    ------------------------------------------------------------------ */
index 0c98d480a79a154d3028efd0d5c30816e2690fe7..476459c9d1727cbf6478a6590d6a425a17bd6602 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "core.h"
 #include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_tooliface.h"
 #include "vki_unistd.h"
 #include <sys/ptrace.h>
index d23fe7a574f359b0e5c3c7f7907645ef9a1cd411..f69311eab66d04de0a7f8561c8fbb6460a1b0a00 100644 (file)
@@ -33,6 +33,7 @@
 #include "pub_tool_debuginfo.h"
 #include "pub_tool_hashtable.h"
 #include "pub_tool_libcbase.h"
+#include "pub_tool_libcassert.h"
 #include "pub_tool_libcprint.h"
 #include "pub_tool_mallocfree.h"
 #include "pub_tool_options.h"
index aac22923e1ae0d0b33fcdb3df0277158b3dd31e7..b087a30c361bb921cc63373821fd1e07c2c5216e 100644 (file)
@@ -9,6 +9,7 @@ incinc_HEADERS = \
        pub_tool_execontext.h           \
        pub_tool_hashtable.h            \
        pub_tool_libcbase.h             \
+       pub_tool_libcassert.h           \
        pub_tool_libcprint.h            \
        pub_tool_mallocfree.h           \
        pub_tool_options.h              \
diff --git a/include/pub_tool_libcassert.h b/include/pub_tool_libcassert.h
new file mode 100644 (file)
index 0000000..22a46e0
--- /dev/null
@@ -0,0 +1,57 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Assertions, etc.                       pub_tool_libcassert.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2005 Julian Seward
+      jseward@acm.org
+
+   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.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_TOOL_LIBCBASSERT_H
+#define __PUB_TOOL_LIBCBASSERT_H
+
+#define tl_assert(expr)                                                 \
+  ((void) ((expr) ? 0 :                                                 \
+           (VG_(assert_fail) (/*isCore?*/False, #expr,                  \
+                              __FILE__, __LINE__, __PRETTY_FUNCTION__,  \
+                              ""),                                      \
+                              0)))
+
+#define tl_assert2(expr, format, args...)                               \
+  ((void) ((expr) ? 0 :                                                 \
+           (VG_(assert_fail) (/*isCore?*/False, #expr,                  \
+                              __FILE__, __LINE__, __PRETTY_FUNCTION__,  \
+                              format, ##args),                          \
+                              0)))
+
+__attribute__ ((__noreturn__))
+extern void VG_(assert_fail) ( Bool isCore, const Char* expr, const Char* file, 
+                               Int line, const Char* fn, 
+                               const HChar* format, ... );
+
+#endif   // __PUB_TOOL_LIBCBASSERT_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
index a781459d5903b47727e0a4d1c59c73691e70ae7d..795a129d85e2e6740a78273b6da68166b2173140 100644 (file)
@@ -171,35 +171,6 @@ extern Char* VG_(getcwd) ( Char* buf, SizeT size );
    Returns False if it fails.  Will fail if the pathname is > 65535 bytes. */
 extern Bool VG_(getcwd_alloc) ( Char** cwd );
 
-/* ------------------------------------------------------------------ */
-/* assert.h */
-/* Asserts permanently enabled -- no turning off with NDEBUG.  Hurrah! */
-
-/* This odd definition lets us stringify VG_(x) function names to
-   "vgPlain_x".  We need to do two macroexpansions to get the VG_ macro
-   expanded before stringifying. */
-#define VG_STRINGIFY_WRK(x)   #x
-#define VG_STRINGIFY(x)       VG_STRINGIFY_WRK(x)
-
-#define tl_assert(expr)                                                 \
-  ((void) ((expr) ? 0 :                                                 \
-           (VG_(assert_fail) (/*isCore?*/False, VG_STRINGIFY(expr),     \
-                              __FILE__, __LINE__, __PRETTY_FUNCTION__,  \
-                              ""),                                      \
-                              0)))
-
-#define tl_assert2(expr, format, args...)                               \
-  ((void) ((expr) ? 0 :                                                 \
-           (VG_(assert_fail) (/*isCore?*/False, VG_STRINGIFY(expr),     \
-                              __FILE__, __LINE__, __PRETTY_FUNCTION__,  \
-                              format, ##args),                          \
-                              0)))
-
-__attribute__ ((__noreturn__))
-extern void VG_(assert_fail) ( Bool isCore, const Char* expr, const Char* file, 
-                               Int line, const Char* fn, 
-                               const HChar* format, ... );
-
 /* ------------------------------------------------------------------ */
 /* Get memory by anonymous mmap. */
 extern void* VG_(get_memory_from_mmap) ( SizeT nBytes, Char* who );
index c25147352e8a2f8d7528012f9cb426996d219c79..aebc27d96245ffeab62a7f17a40ca9f9d23512b2 100644 (file)
@@ -38,6 +38,7 @@
 #include "pub_tool_debuginfo.h"
 #include "pub_tool_hashtable.h"
 #include "pub_tool_libcbase.h"
+#include "pub_tool_libcassert.h"
 #include "pub_tool_libcprint.h"
 #include "pub_tool_mallocfree.h"
 #include "pub_tool_options.h"
index 5341c0d143af6835b3269619c4f9e9ade497cc95..82c18049f2b73eccc826a5bb0240abec31e0875e 100644 (file)
@@ -33,6 +33,7 @@
 #include <setjmp.h>
 #include "mac_shared.h"
 #include "pub_tool_libcbase.h"
+#include "pub_tool_libcassert.h"
 #include "pub_tool_libcprint.h"
 
 /* Define to debug the memory-leak-detector. */
index a888536ec7646e49d98427df58dc0b749d09388a..92489beb0bef6305bf3295e78691ca6a3a29dfc3 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "mac_shared.h"
 #include "pub_tool_libcbase.h"
+#include "pub_tool_libcassert.h"
 #include "pub_tool_libcprint.h"
 
 /*------------------------------------------------------------*/
index 83a8084a8fa1513be58ba5b5457d6228f7d7ce36..8ac8fe9e1e54a46a078f29373d312803263bcc9f 100644 (file)
@@ -31,6 +31,7 @@
 */
 
 #include "mac_shared.h"
+#include "pub_tool_libcassert.h"
 #include "pub_tool_libcbase.h"
 #include "pub_tool_libcprint.h"
 #include "memcheck.h"   /* for VG_USERREQ__* */
index a2e24db51c86f1daf5981efa75521f55db43a618..da32ae2103081ad1ea31f4fe5d27bcc42e57ba46 100644 (file)
@@ -39,6 +39,7 @@
 #include "mc_include.h"
 #include "memcheck.h"   /* for client requests */
 #include "pub_tool_libcbase.h"
+#include "pub_tool_libcassert.h"
 #include "pub_tool_libcprint.h"
 
 
index d4a1327c782212b065d9b3452b53436df4c5be00..0900c7572fd0dd0097beacf4c5e5c1f2e9001afc 100644 (file)
@@ -30,6 +30,7 @@
 */
 
 #include "mc_include.h"
+#include "pub_tool_libcassert.h"
 #include "pub_tool_libcprint.h"