[Pcre-svn] [1151] code/trunk: valgrind: Add --support-valgri…

Startseite
Nachricht löschen
Autor: Subversion repository
Datum:  
To: pcre-svn
Betreff: [Pcre-svn] [1151] code/trunk: valgrind: Add --support-valgrind configure option
Revision: 1151
          http://vcs.pcre.org/viewvc?view=rev&revision=1151
Author:   chpe
Date:     2012-10-21 17:53:46 +0100 (Sun, 21 Oct 2012)


Log Message:
-----------
valgrind: Add --support-valgrind configure option

When --enable-valgrind is passed, PCRE will annotate some memory regions
as unaddressable, aiding in finding invalid memory accesses when running
under valgrind. This is useful mostly for debugging PCRE itself, and thus
probably should not be enabled in release builds.

Modified Paths:
--------------
    code/trunk/Makefile.am
    code/trunk/configure.ac
    code/trunk/doc/pcrebuild.3
    code/trunk/pcre_internal.h


Modified: code/trunk/Makefile.am
===================================================================
--- code/trunk/Makefile.am    2012-10-21 06:35:52 UTC (rev 1150)
+++ code/trunk/Makefile.am    2012-10-21 16:53:46 UTC (rev 1151)
@@ -212,6 +212,11 @@
   pcre_xclass.c \
   ucp.h


+libpcre_la_CFLAGS = \
+ $(AM_CFLAGS)
+
+libpcre_la_LIBADD =
+
## This file is generated as part of the building process, so don't distribute.
nodist_libpcre_la_SOURCES = \
pcre_chartables.c
@@ -245,6 +250,11 @@
pcre16_version.c \
pcre16_xclass.c

+libpcre16_la_CFLAGS = \
+ $(AM_CFLAGS)
+
+libpcre16_la_LIBADD =
+
## This file is generated as part of the building process, so don't distribute.
nodist_libpcre16_la_SOURCES = \
pcre_chartables.c
@@ -278,6 +288,10 @@
pcre32_version.c \
pcre32_xclass.c

+libpcre32_la_CFLAGS = \
+ $(AM_CFLAGS)
+libpcre32_la_LIBADD =
+
## This file is generated as part of the building process, so don't distribute.
nodist_libpcre32_la_SOURCES = \
pcre_chartables.c
@@ -318,6 +332,18 @@
libpcre32_la_LDFLAGS = $(EXTRA_LIBPCRE32_LDFLAGS)
endif # WITH_PCRE32

+if WITH_VALGRIND
+if WITH_PCRE8
+libpcre_la_CFLAGS += $(VALGRIND_CFLAGS)
+endif # WITH_PCRE8
+if WITH_PCRE16
+libpcre16_la_CFLAGS += $(VALGRIND_CFLAGS)
+endif # WITH_PCRE16
+if WITH_PCRE32
+libpcre32_la_CFLAGS += $(VALGRIND_CFLAGS)
+endif # WITH_PCRE32
+endif # WITH_VALGRIND
+
CLEANFILES += pcre_chartables.c

## If JIT support is enabled, arrange for the JIT test program to run.
@@ -385,6 +411,7 @@
EXTRA_DIST += RunTest.bat
bin_PROGRAMS += pcretest
pcretest_SOURCES = pcretest.c
+pcretest_CFLAGS = $(AM_CFLAGS)
pcretest_LDADD = $(LIBREADLINE)
if WITH_PCRE8
pcretest_SOURCES += pcre_printint.c
@@ -398,6 +425,9 @@
pcretest_SOURCES += pcre32_printint.c
pcretest_LDADD += libpcre32.la
endif # WITH_PCRE32
+if WITH_VALGRIND
+pcretest_CFLAGS += $(VALGRIND_CFLAGS)
+endif # WITH_VALGRIND

if WITH_PCRE8
TESTS += RunGrepTest

Modified: code/trunk/configure.ac
===================================================================
--- code/trunk/configure.ac    2012-10-21 06:35:52 UTC (rev 1150)
+++ code/trunk/configure.ac    2012-10-21 16:53:46 UTC (rev 1151)
@@ -48,6 +48,7 @@


AC_PROG_CC
AC_PROG_CXX
+AM_PROG_CC_C_O

 if test "x$remember_set_CFLAGS" = "x"
 then
@@ -284,6 +285,12 @@
                            [default limit on internal recursion (default=MATCH_LIMIT)]),
             , with_match_limit_recursion=MATCH_LIMIT)


+# Handle --enable-valgrind
+AC_ARG_ENABLE(valgrind,
+              AS_HELP_STRING([--enable-valgrind],
+                             [valgrind support]),
+              , enable_valgrind=no)
+
 # Copy enable_utf8 value to enable_utf for compatibility reasons
 if test "x$enable_utf8" != "xunset"
 then
@@ -525,6 +532,7 @@
 AM_CONDITIONAL(WITH_REBUILD_CHARTABLES, test "x$enable_rebuild_chartables" = "xyes")
 AM_CONDITIONAL(WITH_JIT, test "x$enable_jit" = "xyes")
 AM_CONDITIONAL(WITH_UTF, test "x$enable_utf" = "xyes")
+AM_CONDITIONAL(WITH_VALGRIND, test "x$enable_valgrind" = "xyes")


# Checks for typedefs, structures, and compiler characteristics.

@@ -811,6 +819,11 @@
     set EBCDIC_NL25, the adjustment of NEWLINE is automatic.])
 fi       


+if test "$enable_valgrind" = "yes"; then
+  AC_DEFINE_UNQUOTED([SUPPORT_VALGRIND], [], [
+     Valgrind support to find invalid memory reads.])
+fi
+
 # Platform specific issues
 NO_UNDEFINED=
 EXPORT_ALL_SYMBOLS=
@@ -916,6 +929,14 @@
   fi
 fi


+# Check for valgrind
+
+if test "$enable_valgrind" = "yes"; then
+  m4_ifdef([PKG_CHECK_MODULES],
+           [PKG_CHECK_MODULES([VALGRIND],[valgrind])],
+           [AC_MSG_ERROR([pkg-config not supported])])
+fi
+
 # Produce these files, in addition to config.h.
 AC_CONFIG_FILES(
     Makefile
@@ -990,6 +1011,7 @@
     Link pcregrep with libbz2 ....... : ${enable_pcregrep_libbz2}
     Link pcretest with libedit ...... : ${enable_pcretest_libedit}
     Link pcretest with libreadline .. : ${enable_pcretest_libreadline}
+    Valgrind support ................ : ${enable_valgrind}


EOF


Modified: code/trunk/doc/pcrebuild.3
===================================================================
--- code/trunk/doc/pcrebuild.3    2012-10-21 06:35:52 UTC (rev 1150)
+++ code/trunk/doc/pcrebuild.3    2012-10-21 16:53:46 UTC (rev 1151)
@@ -425,6 +425,18 @@
 immediately before the \fBconfigure\fP command.
 .
 .
+.SH "DEBUGGING WITH VALGRIND SUPPORT"
+.rs
+.sp
+By adding the
+.sp
+  --enable-valgrind
+.sp
+option to to the \fBconfigure\fP command, PCRE will use valgrind annotations
+to mark certain memory regions as unaddressable. This allows to detect invalid
+memory accesses, and is mostly useful for debugging PCRE itself.
+.
+.
 .SH "SEE ALSO"
 .rs
 .sp


Modified: code/trunk/pcre_internal.h
===================================================================
--- code/trunk/pcre_internal.h    2012-10-21 06:35:52 UTC (rev 1150)
+++ code/trunk/pcre_internal.h    2012-10-21 16:53:46 UTC (rev 1151)
@@ -112,6 +112,12 @@
 #include <stdlib.h>
 #include <string.h>


+/* Valgrind (memcheck) support */
+
+#ifdef SUPPORT_VALGRIND
+#include <valgrind/memcheck.h>
+#endif
+
/* When compiling a DLL for Windows, the exported symbols have to be declared
using some MS magic. I found some useful information on this web page:
http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the