From: <sv...@va...> - 2008-06-10 20:13:28
|
Author: cerion Date: 2008-06-07 21:33:15 +0100 (Sat, 07 Jun 2008) New Revision: 423 Log: Support valgrind >= 3.3.0 (at last!), so now: v3.0.0 to < v3.3.0 => use log parameter "--log-file-exactly" >=v3.3.0 => use log parameter "--log-file" Modified: trunk/valkyrie/core/memcheck_object.cpp trunk/valkyrie/core/valgrind_object.cpp trunk/valkyrie/core/valgrind_object.h trunk/valkyrie/core/valkyrie_object.cpp trunk/valkyrie/options/vk_option.cpp trunk/valkyrie/tool_utils/async_process.cpp trunk/valkyrie/tool_utils/vk_process.h trunk/vk_logmerge/vklm_main.cpp Modified: trunk/valkyrie/core/memcheck_object.cpp =================================================================== --- trunk/valkyrie/core/memcheck_object.cpp 2008-06-07 15:44:20 UTC (rev 422) +++ trunk/valkyrie/core/memcheck_object.cpp 2008-06-07 20:33:15 UTC (rev 423) @@ -329,22 +329,41 @@ { m_saveFname = vk_mkstemp( vkConfig->logsDir() + "mc_log", "xml" ); vk_assert( !m_saveFname.isEmpty() ); + + /* check valgrind version: + - supported version + - version dependent code + */ + int v1=0, v2=0, v3=0; + bool ok = Valgrind::getVersionBinary( vgflags.first(), v1, v2, v3 ); + if ( !ok ) { + vkError( view(), "Valgrind start error", + "Failure running valgrind version test" ); + } else { + // valgrind version dependent code + QString log_param; + + if ( v1 == 3 && v2 < 3 ) { // < 3.3.0 + log_param = "--log-file-exactly="; + } else { // >= 3.3.0 + log_param = "--log-file="; + } + v3=v3; // stop compiler complaining + log_param += m_saveFname; + + printf("param: '%s'\n", log_param.latin1() ); + + vgflags.insert( ++(vgflags.begin()), log_param ); + } + + if ( ok ) { + setRunState( VkRunState::VALGRIND ); + m_fileSaved = false; + statusMsg( "Memcheck", "Running ... " ); + + ok = startProcess( vgflags ); + } - /* fill in filename in flags list */ -#if (QT_VERSION-0 >= 0x030200) - vgflags.gres( "--log-file-exactly", "--log-file-exactly=" + m_saveFname ); -#else // QT_VERSION < 3.2 - QStringList::iterator it_str = vgflags.find("--log-file-exactly"); - if (it_str != vgflags.end()) - (*it_str) += ("=" + m_saveFname); -#endif - - setRunState( VkRunState::VALGRIND ); - m_fileSaved = false; - statusMsg( "Memcheck", "Running ... " ); - - bool ok = startProcess( vgflags ); - if (!ok) { statusMsg( "Memcheck", "Failed" ); m_fileSaved = true; Modified: trunk/valkyrie/core/valgrind_object.cpp =================================================================== --- trunk/valkyrie/core/valgrind_object.cpp 2008-06-07 15:44:20 UTC (rev 422) +++ trunk/valkyrie/core/valgrind_object.cpp 2008-06-07 20:33:15 UTC (rev 423) @@ -358,8 +358,7 @@ break; /* logging options */ - /* for all tools we use --log-file-exactly=xyz. - this is set in Valkyrie::runTool(), and updated by the tool. + /* all tools use an internal logging option, all logging options are therefore ignored */ case LOG_FILE: case LOG_FD: @@ -452,8 +451,7 @@ } break; - /* for all tools we use --log-file-exactly=xyz. - this is set in Valkyrie::runTool(), and updated by the tool. + /* all tools use an internal logging option, all logging options should therefore not be used */ case LOG_FILE: case LOG_FD: @@ -476,7 +474,63 @@ +/* Get valgrind version */ +bool Valgrind::getVersionBinary( QString& vg_bin, int& v1, int& v2, int& v3 ) +{ + bool ok = true; + QString vg_version; + QString exec = vg_bin + " --version | sed 's/^valgrind-//'"; + FILE* fd = popen( exec.latin1(), "r"); + if (!fd) { // start error? + perror("popen"); + ok = false; + vkPrintErr( "Valgrind start error: Failure starting valgrind version test" ); + } else { + char buf[1024]; + fgets(buf, sizeof(buf), fd); + vg_version = buf; + vg_version = vg_version.left( vg_version.length() - 1 ); + + int result = pclose(fd); + if ( !WIFEXITED( result ) ) { // exit error? + ok = false; + vkPrintErr( "Valgrind start error: Failure running valgrind version test" ); + } + } + + if ( ok ) { + // parse valgrind version + QStringList slst_vg_ver = QStringList::split( '.', vg_version ); + if ( slst_vg_ver.count() != 3 ) { + ok = false; + } + if ( ok ) { + v1 = slst_vg_ver[0].toUInt( &ok ); + } + if ( ok ) { + v2 = slst_vg_ver[1].toUInt( &ok ); + } + if ( ok ) { + v3 = slst_vg_ver[2].toUInt( &ok ); + } + if ( !ok ) { + vkPrintErr( "Valgrind start error: Failure reading valgrind version: '%s'", + vg_version.latin1() ); + } else { + // check version supported + if ( v1 < 3 ) { // < 3.0.0: unsupported + ok = false; + vkPrintErr( "Valgrind start error: Unsupported version: %s < 3.0.0", + vg_version.latin1() ); + } + } + } + return ok; +} + + + /* Register tools */ void Valgrind::initToolObjects() { Modified: trunk/valkyrie/core/valgrind_object.h =================================================================== --- trunk/valkyrie/core/valgrind_object.h 2008-06-07 15:44:20 UTC (rev 422) +++ trunk/valkyrie/core/valgrind_object.h 2008-06-07 20:33:15 UTC (rev 423) @@ -85,6 +85,9 @@ ToolObject* toolObj( int tid ); ToolObject* toolObj( const QString& name ); + /* Get valgrind version */ + static bool getVersionBinary( QString& vg_bin, int& v1, int& v2, int& v3 ); + private: /* creates the various VkObjects and initialises their options, ready for cmd-line parsing (if any). */ Modified: trunk/valkyrie/core/valkyrie_object.cpp =================================================================== --- trunk/valkyrie/core/valkyrie_object.cpp 2008-06-07 15:44:20 UTC (rev 422) +++ trunk/valkyrie/core/valkyrie_object.cpp 2008-06-07 20:33:15 UTC (rev 423) @@ -350,12 +350,7 @@ ToolObject* activeTool = valgrind()->toolObj( tId ); vk_assert( activeTool != 0 ); - /* Adding user-invisible flags to capture valgrind output - --log-file-exactly must be given a filename by the tool */ - QStringList vgFlags = m_flags; - vgFlags.insert( ++(vgFlags.begin()), "--log-file-exactly" ); - - return activeTool->start( runState, vgFlags ); + return activeTool->start( runState, m_flags ); } Modified: trunk/valkyrie/options/vk_option.cpp =================================================================== --- trunk/valkyrie/options/vk_option.cpp 2008-06-07 15:44:20 UTC (rev 422) +++ trunk/valkyrie/options/vk_option.cpp 2008-06-07 20:33:15 UTC (rev 423) @@ -13,7 +13,7 @@ #include <ctype.h> #include <math.h> #include <malloc.h> -#include <stdlib.h> /* exit */ +#include <stdlib.h> // getenv #include <qdir.h> Modified: trunk/valkyrie/tool_utils/async_process.cpp =================================================================== --- trunk/valkyrie/tool_utils/async_process.cpp 2008-06-07 15:44:20 UTC (rev 422) +++ trunk/valkyrie/tool_utils/async_process.cpp 2008-06-07 20:33:15 UTC (rev 423) @@ -22,7 +22,7 @@ #include <errno.h> /* Fedora Core needs this */ #include <fcntl.h> /* open(), O_RDONLY, O_WRONLY */ #include <signal.h> -#include <stdlib.h> /* exit */ +#include <stdlib.h> /* getenv */ #include <sys/types.h> /* waitpid() */ #include <sys/wait.h> /* waitpid() */ #include <unistd.h> /* dup2(), _exit(), */ Modified: trunk/valkyrie/tool_utils/vk_process.h =================================================================== --- trunk/valkyrie/tool_utils/vk_process.h 2008-06-07 15:44:20 UTC (rev 422) +++ trunk/valkyrie/tool_utils/vk_process.h 2008-06-07 20:33:15 UTC (rev 423) @@ -28,7 +28,7 @@ #include <qsocketnotifier.h> #include <signal.h> -#include <stdlib.h> // exit +#include <stdlib.h> // ssize_t class VKMembuf Modified: trunk/vk_logmerge/vklm_main.cpp =================================================================== --- trunk/vk_logmerge/vklm_main.cpp 2008-06-07 15:44:20 UTC (rev 422) +++ trunk/vk_logmerge/vklm_main.cpp 2008-06-07 20:33:15 UTC (rev 423) @@ -9,7 +9,7 @@ #include <sys/types.h> // getpid #include <unistd.h> // getpid -#include <stdlib.h> // exit +#include <stdlib.h> // abort #include <qfileinfo.h> #include <qdom.h> |