|
From: <sv...@va...> - 2005-04-08 23:28:29
|
Author: njn
Date: 2005-04-09 00:28:23 +0100 (Sat, 09 Apr 2005)
New Revision: 3528
Modified:
trunk/coregrind/core.h
trunk/coregrind/vg_mylibc.c
trunk/coregrind/vg_scheduler.c
trunk/coregrind/vg_signals.c
trunk/include/tool.h.base
Log:
Added new assert macros vg_assert2 and tl_assert2 which allow you to prin=
t a
string explaining more detail if the assertion fails (eg. the value of th=
e
bogus variable) using printf-style format arguments.
One consequence of this is that you can do something like
=20
vg_assert2(0, "bad bad bad");
instead of calling VG_(core_panic). The advantage of the new approach is
that it shows the file/function/line info for the failing code, whereas
VG_(core_panic)() does not.
Modified: trunk/coregrind/core.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/core.h 2005-04-07 17:39:08 UTC (rev 3527)
+++ trunk/coregrind/core.h 2005-04-08 23:28:23 UTC (rev 3528)
@@ -782,19 +782,26 @@
=20
// Useful for making failing stubs, when certain things haven't yet been
// implemented.
-#define I_die_here \
- VG_(core_assert_fail) ("Unimplemented functionality", \
- __FILE__, __LINE__, __PRETTY_FUNCTION__)
+#define I_die_here \
+ VG_(assert_fail) ("Unimplemented functionality", \
+ __FILE__, __LINE__, __PRETTY_FUNCTION__, \
+ "valgrind", VG_BUGS_TO, "")
=20
-#define vg_assert(expr) \
- ((void) ((expr) ? 0 : \
- (VG_(core_assert_fail) (VG_STRINGIFY(expr), \
- __FILE__, __LINE__, \
- __PRETTY_FUNCTION__), 0)))
+#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_assert_fail) ( const Char* expr, const Char* file,=20
- Int line, const Char* fn );
-__attribute__ ((__noreturn__))
extern void VG_(core_panic) ( Char* str );
__attribute__ ((__noreturn__))
extern void VG_(core_panic_at) ( Char* str, StackTrace ips );
Modified: trunk/coregrind/vg_mylibc.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/vg_mylibc.c 2005-04-07 17:39:08 UTC (rev 3527)
+++ trunk/coregrind/vg_mylibc.c 2005-04-08 23:28:23 UTC (rev 3528)
@@ -1169,6 +1169,8 @@
else
VG_(pp_StackTrace)(ips, VG_(clo_backtrace_size));
=20
+ 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=
");
@@ -1181,35 +1183,51 @@
VG_(exit)(1);
}
=20
-__attribute__ ((noreturn))
-static void assert_fail ( const Char* expr, const Char* name, const Char=
* report,
- const Char* file, Int line, const Char* fn )
+void VG_(assert_fail) ( Bool isCore, const Char* expr, const Char* file,=
=20
+ Int line, const Char* fn, const Char* format, ..=
. )
{
+ va_list vargs;
+ Char buf[256];
+ Char* bufptr =3D buf;
+ Char* component;
+ Char* bugs_to;
+
static Bool entered =3D False;
if (entered)=20
VG_(exit)(2);
entered =3D True;
- VG_(printf)("\n%s: %s:%d (%s): Assertion `%s' failed.\n",
- name, file, line, fn, expr );
- report_and_quit(report, NULL);
-}
=20
-void VG_(tool_assert_fail) ( const Char* expr, const Char* file, Int lin=
e, const Char* fn )
-{
- assert_fail(expr, VG_(details).name, VG_(details).bug_reports_to,=20
- file, line, fn);
-}
+ va_start(vargs,format);
+ VG_(vprintf) ( add_to_vg_sprintf_buf, format, vargs, &bufptr );
+ add_to_vg_sprintf_buf('\0', &bufptr);
+ va_end(vargs);
=20
-void VG_(core_assert_fail) ( const Char* expr, const Char* file, Int lin=
e, const Char* fn )
-{
- assert_fail(expr, "valgrind", VG_BUGS_TO, file, line, fn);
+ if (isCore) {
+ component =3D "valgrind";
+ bugs_to =3D VG_BUGS_TO;
+ } else {=20
+ component =3D VG_(details).name;
+ bugs_to =3D 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, NULL);
}
=20
__attribute__ ((noreturn))
static void panic ( Char* name, Char* report, Char* str, StackTrace ips =
)
{
VG_(printf)("\n%s: the `impossible' happened:\n %s\n", name, str);
- VG_(printf)("Basic block ctr is approximately %llu\n", VG_(bbs_done) =
);
report_and_quit(report, ips);
}
=20
Modified: trunk/coregrind/vg_scheduler.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/vg_scheduler.c 2005-04-07 17:39:08 UTC (rev 3527)
+++ trunk/coregrind/vg_scheduler.c 2005-04-08 23:28:23 UTC (rev 3528)
@@ -652,8 +652,8 @@
/* Not found; we need to request a translation. */
if (VG_(translate)( tid, ip, /*debug*/False, 0/*not verbose*/ )) {
found =3D VG_(search_transtab)( NULL, ip, True );=20
- if (!found)
- VG_(core_panic)("VG_TRC_INNER_FASTMISS: missing tt_fast entry");
+ vg_assert2(found, "VG_TRC_INNER_FASTMISS: missing tt_fast entry=
");
+ =20
} else {
// If VG_(translate)() fails, it's because it had to throw a
// signal because the client jumped to a bad address. That
@@ -840,9 +840,8 @@
break;
=20
default:=20
- VG_(printf)("\ntrc =3D %d\n", trc);
- VG_(core_panic)("VG_(scheduler), phase 3: "
- "unexpected thread return code");
+ vg_assert2(0, "VG_(scheduler), phase 3: "
+ "unexpected thread return code (%u)", trc);
/* NOTREACHED */
break;
=20
Modified: trunk/coregrind/vg_signals.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/vg_signals.c 2005-04-07 17:39:08 UTC (rev 3527)
+++ trunk/coregrind/vg_signals.c 2005-04-08 23:28:23 UTC (rev 3528)
@@ -1718,8 +1718,8 @@
=20
void VG_(set_fault_catcher)(void (*catcher)(Int, Addr))
{
- if (catcher !=3D NULL && fault_catcher !=3D NULL)
- VG_(core_panic)("Fault catcher is already registered");
+ vg_assert2(NULL =3D=3D catcher || NULL =3D=3D fault_catcher,
+ "Fault catcher is already registered");
=20
fault_catcher =3D catcher;
}
Modified: trunk/include/tool.h.base
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/include/tool.h.base 2005-04-07 17:39:08 UTC (rev 3527)
+++ trunk/include/tool.h.base 2005-04-08 23:28:23 UTC (rev 3528)
@@ -453,17 +453,25 @@
#define VG_STRINGIFY_WRK(x) #x
#define VG_STRINGIFY(x) VG_STRINGIFY_WRK(x)
=20
-#define tl_assert(expr) \
- ((void) ((expr) ? 0 : \
- (VG_(tool_assert_fail) (VG_STRINGIFY(expr), \
- __FILE__, __LINE__, \
- __PRETTY_FUNCTION__), 0)))
+#define tl_assert(expr) =
\
+ ((void) ((expr) ? 0 : =
\
+ (VG_(assert_fail) (/*isCore?*/False, VG_STRINGIFY(expr), =
\
+ __FILE__, __LINE__, __PRETTY_FUNCTION__, =
\
+ ""), =
\
+ 0)))
=20
+#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_(tool_assert_fail) ( const Char* expr, const Char* file,
- Int line, const Char* fn );
+extern void VG_(assert_fail) ( Bool isCore, const Char* expr, const Char=
* file,=20
+ Int line, const Char* fn,=20
+ const Char* format, ... );
=20
-
/* ------------------------------------------------------------------ */
/* Get memory by anonymous mmap. */
extern void* VG_(get_memory_from_mmap) ( SizeT nBytes, Char* who );
|