[Libreoffice] LibreOffice / valgrind detection ...
Michael Meeks
michael.meeks at novell.com
Fri Jun 24 03:30:48 PDT 2011
Hi Julian,
On Thu, 2011-06-23 at 11:59 +0200, Julian Seward wrote:
> Oh, I think I missed answering the simple question here. Thusly:
Ah indeed :-) and I missed that in the headers.
> #include "valgrind.h"
>
> bool running_under_valgrind (void)
> {
> return (RUNNING_ON_VALGRIND) ? true : false;
> }
>
> Is that what you want, or did you mean something different?
Yes; that was what I wanted, sorry I couldn't find it in the header
somehow - though it is clearly there ;-)
Reading more carefully, it seems the #undef block at the bottom of a
recent svn's valgrind.h doesn't match the similar undef at the top - is
that intended ? [seems to miss eg. the s390 piece].
I wonder too whether (since the weak symbol thing doesn't seem to work
so well) whether exporting a type-safe function-pointer-table via a
single "get-me-the-fn-table-or-null" type method might be more readable;
though of course you'd still need the trap-doors in stubs behind that I
guess.
> You might want to cache the result of RUNNING_ON_VALGRIND
> so that the common (production) case overhead is reduced to
> a load and conditional branch, rather than the strange sequence
> of stores and rotates generated by the macro.
Yep; we'd do it once just at the beginning.
Caolan - what do you think of doing:
diff --git a/sal/rtl/source/alloc_global.c b/sal/rtl/source/alloc_global.c
index fb95e83..4923428 100644
--- a/sal/rtl/source/alloc_global.c
+++ b/sal/rtl/source/alloc_global.c
@@ -35,6 +35,7 @@
#include <stdio.h>
#if !defined(FORCE_SYSALLOC)
+#include "valgrind.h"
typedef enum { AMode_CUSTOM, AMode_SYSTEM, AMode_UNSET } AllocMode;
@@ -46,7 +47,13 @@ static void determine_alloc_mode(void)
if (alloc_mode != AMode_UNSET)
return;
- if (getenv("G_SLICE") != NULL)
+ if (RUNNING_ON_VALGRIND)
+ {
+ putenv ("G_SLICE=1");
+ fprintf(stderr, "LibreOffice: running under valgrind detected.\n");
+ alloc_mode = AMode_SYSTEM;
+ }
+ else if (getenv("G_SLICE") != NULL)
{
alloc_mode = AMode_SYSTEM;
fprintf(stderr, "LibreOffice: Using system memory allocator.\n");
And dropping the 'memcheck.h' and 'valgrind.h' headers straight into
sal - they are BSD licensed anyway, then we could loose a lot of that
fluff in configure.ac / makefile around valgrind (?) perhaps we'd want a
environment variable for "TRY_TO_VALGRIND_INTERNAL_ALLOCATORS" too ;-)
That might help the QA guys automagically generate better valgrind
traces with less effort ?
ATB,
Michael.
--
michael.meeks at novell.com <><, Pseudo Engineer, itinerant idiot
More information about the LibreOffice
mailing list