Kaydet (Commit) d2ed905c authored tarafından Caolán McNamara's avatar Caolán McNamara

when run under memcheck allow SIGUSR2 to dump current memory allocations

üst f3876e3f
...@@ -109,6 +109,7 @@ for arg in $@ $VALGRINDOPT ; do ...@@ -109,6 +109,7 @@ for arg in $@ $VALGRINDOPT ; do
fi fi
# finally set the valgrind check # finally set the valgrind check
VALGRINDCHECK="valgrind --tool=$VALGRIND --trace-children=yes $valgrind_skip --num-callers=50 --error-limit=no --error-exitcode=101" VALGRINDCHECK="valgrind --tool=$VALGRIND --trace-children=yes $valgrind_skip --num-callers=50 --error-limit=no --error-exitcode=101"
echo "use kill -SIGUSR2 pid to dump traces of active allocations"
checks="c$checks" checks="c$checks"
if [ "$VALGRIND" = "memcheck" ] ; then if [ "$VALGRIND" = "memcheck" ] ; then
export G_SLICE=always-malloc export G_SLICE=always-malloc
......
...@@ -87,6 +87,10 @@ ...@@ -87,6 +87,10 @@
#define MAX_PATH_LEN 2048 #define MAX_PATH_LEN 2048
#if defined(HAVE_MEMCHECK_H)
#include <memcheck.h>
#endif
typedef struct _oslSignalHandlerImpl typedef struct _oslSignalHandlerImpl
{ {
oslSignalHandlerFunction Handler; oslSignalHandlerFunction Handler;
...@@ -260,8 +264,13 @@ static sal_Bool InitSignal() ...@@ -260,8 +264,13 @@ static sal_Bool InitSignal()
sigfillset(&(act.sa_mask)); sigfillset(&(act.sa_mask));
/* Initialize the rest of the signals */ /* Initialize the rest of the signals */
for (i = 0; i < NoSignals; i++) for (i = 0; i < NoSignals; ++i)
{ {
#if defined(HAVE_MEMCHECK_H)
if (Signals[i].Signal == SIGUSR2 && RUNNING_ON_VALGRIND)
Signals[i].Action = ACT_IGNORE;
#endif
/* hack: stomcatd is attaching JavaVM wich dont work with an sigaction(SEGV) */ /* hack: stomcatd is attaching JavaVM wich dont work with an sigaction(SEGV) */
if ((bSetSEGVHandler || Signals[i].Signal != SIGSEGV) if ((bSetSEGVHandler || Signals[i].Signal != SIGSEGV)
&& (bSetWINCHHandler || Signals[i].Signal != SIGWINCH) && (bSetWINCHHandler || Signals[i].Signal != SIGWINCH)
...@@ -283,10 +292,12 @@ static sal_Bool InitSignal() ...@@ -283,10 +292,12 @@ static sal_Bool InitSignal()
Signals[i].Handler = SIG_DFL; Signals[i].Handler = SIG_DFL;
} }
else else
{
if (sigaction(Signals[i].Signal, &act, &oact) == 0) if (sigaction(Signals[i].Signal, &act, &oact) == 0)
Signals[i].Handler = oact.sa_handler; Signals[i].Handler = oact.sa_handler;
else else
Signals[i].Handler = SIG_DFL; Signals[i].Handler = SIG_DFL;
}
} }
} }
} }
...@@ -908,6 +919,26 @@ void CallSystemHandler(int Signal) ...@@ -908,6 +919,26 @@ void CallSystemHandler(int Signal)
} }
} }
#if defined(HAVE_MEMCHECK_H)
static void DUMPCURRENTALLOCS()
{
fprintf(stderr, "hello world\n");
VALGRIND_PRINTF( "=== start memcheck dump of active allocations ===\n" );
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#endif
VALGRIND_DO_LEAK_CHECK;
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
# pragma GCC diagnostic pop
#endif
VALGRIND_PRINTF( "=== end memcheck dump of active allocations ===\n" );
}
#endif
/*****************************************************************************/ /*****************************************************************************/
/* SignalHandlerFunction */ /* SignalHandlerFunction */
...@@ -942,11 +973,19 @@ void SignalHandlerFunction(int Signal) ...@@ -942,11 +973,19 @@ void SignalHandlerFunction(int Signal)
case SIGINT: case SIGINT:
case SIGTERM: case SIGTERM:
case SIGQUIT: case SIGQUIT:
case SIGHUP: case SIGHUP:
Info.Signal = osl_Signal_Terminate; Info.Signal = osl_Signal_Terminate;
break; break;
#if defined(HAVE_MEMCHECK_H)
case SIGUSR2:
if (RUNNING_ON_VALGRIND)
DUMPCURRENTALLOCS();
Info.Signal = osl_Signal_System;
break;
#endif
default: default:
Info.Signal = osl_Signal_System; Info.Signal = osl_Signal_System;
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment