summaryrefslogtreecommitdiff
path: root/Source/kwsys
diff options
context:
space:
mode:
authorKévin THIERRY <kevin.thierry@open.eurogiciel.org>2014-12-23 09:30:24 +0100
committerKévin THIERRY <kevin.thierry@open.eurogiciel.org>2014-12-23 09:30:24 +0100
commit317dbdb79761ef65e45c7358cfc7571c6afa54ad (patch)
treed6e8d59029aea04ca4a0579fb1c19c3e493af78f /Source/kwsys
parent297c63fa65327491a2b50e521b661c5835a19fe4 (diff)
downloadcmake-317dbdb79761ef65e45c7358cfc7571c6afa54ad.tar.gz
cmake-317dbdb79761ef65e45c7358cfc7571c6afa54ad.tar.bz2
cmake-317dbdb79761ef65e45c7358cfc7571c6afa54ad.zip
Imported Upstream version 2.8.12.2upstream/2.8.12.2sandbox/kevinthierry/upstream
Diffstat (limited to 'Source/kwsys')
-rw-r--r--Source/kwsys/CMakeLists.txt96
-rw-r--r--Source/kwsys/CommandLineArguments.hxx.in10
-rw-r--r--Source/kwsys/RegularExpression.cxx114
-rw-r--r--Source/kwsys/SharedForward.h.in2
-rw-r--r--Source/kwsys/SystemInformation.cxx384
-rw-r--r--Source/kwsys/SystemInformation.hxx.in10
-rw-r--r--Source/kwsys/SystemTools.cxx287
-rw-r--r--Source/kwsys/SystemTools.hxx.in9
-rw-r--r--Source/kwsys/auto_ptr.hxx.in18
-rw-r--r--Source/kwsys/hashtable.hxx.in18
-rw-r--r--Source/kwsys/kwsysPlatformTests.cmake3
-rw-r--r--Source/kwsys/kwsysPlatformTestsCXX.cxx67
-rw-r--r--Source/kwsys/testDynamicLoader.cxx4
-rw-r--r--Source/kwsys/testIOS.cxx2
-rw-r--r--Source/kwsys/testSystemInformation.cxx25
15 files changed, 806 insertions, 243 deletions
diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt
index 124b8aca0..0f2783689 100644
--- a/Source/kwsys/CMakeLists.txt
+++ b/Source/kwsys/CMakeLists.txt
@@ -569,8 +569,17 @@ IF(KWSYS_USE_SystemTools)
"Checking whether CXX compiler has unsetenv" DIRECT)
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H
"Checking whether CXX compiler has environ in stdlib.h" DIRECT)
- SET_SOURCE_FILES_PROPERTIES(SystemTools.cxx PROPERTIES
- COMPILE_FLAGS "-DKWSYS_CXX_HAS_SETENV=${KWSYS_CXX_HAS_SETENV} -DKWSYS_CXX_HAS_UNSETENV=${KWSYS_CXX_HAS_UNSETENV} -DKWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=${KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H}")
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_UTIMES
+ "Checking whether CXX compiler has utimes" DIRECT)
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_UTIMENSAT
+ "Checking whether CXX compiler has utimensat" DIRECT)
+ SET_PROPERTY(SOURCE SystemTools.cxx APPEND PROPERTY COMPILE_DEFINITIONS
+ KWSYS_CXX_HAS_SETENV=${KWSYS_CXX_HAS_SETENV}
+ KWSYS_CXX_HAS_UNSETENV=${KWSYS_CXX_HAS_UNSETENV}
+ KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H=${KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H}
+ KWSYS_CXX_HAS_UTIMES=${KWSYS_CXX_HAS_UTIMES}
+ KWSYS_CXX_HAS_UTIMENSAT=${KWSYS_CXX_HAS_UTIMENSAT}
+ )
ENDIF()
IF(KWSYS_USE_SystemInformation)
@@ -640,6 +649,68 @@ IF(KWSYS_USE_SystemInformation)
SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
COMPILE_DEFINITIONS KWSYS_CXX_HAS__ATOI64=1)
ENDIF()
+ IF(UNIX)
+ INCLUDE(CheckIncludeFileCXX)
+ # check for simple stack trace
+ # usually it's in libc but on FreeBSD
+ # it's in libexecinfo
+ FIND_LIBRARY(EXECINFO_LIB "execinfo")
+ IF (NOT EXECINFO_LIB)
+ SET(EXECINFO_LIB "")
+ ENDIF()
+ CHECK_INCLUDE_FILE_CXX("execinfo.h" KWSYS_CXX_HAS_EXECINFOH)
+ IF (KWSYS_CXX_HAS_EXECINFOH)
+ # we have the backtrace header check if it
+ # can be used with this compiler
+ SET(KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES ${EXECINFO_LIB})
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BACKTRACE
+ "Checking whether backtrace works with this C++ compiler" DIRECT)
+ SET(KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES)
+ IF (KWSYS_CXX_HAS_BACKTRACE)
+ # backtrace is supported by this system and compiler.
+ # now check for the more advanced capabilities.
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE=1)
+ # check for symbol lookup using dladdr
+ CHECK_INCLUDE_FILE_CXX("dlfcn.h" KWSYS_CXX_HAS_DLFCNH)
+ IF (KWSYS_CXX_HAS_DLFCNH)
+ # we have symbol lookup libraries and headers
+ # check if they can be used with this compiler
+ SET(KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES ${CMAKE_DL_LIBS})
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_DLADDR
+ "Checking whether dladdr works with this C++ compiler" DIRECT)
+ SET(KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES)
+ IF (KWSYS_CXX_HAS_DLADDR)
+ # symbol lookup is supported by this system
+ # and compiler.
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP=1)
+ ENDIF()
+ ENDIF()
+ # c++ demangling support
+ # check for cxxabi headers
+ CHECK_INCLUDE_FILE_CXX("cxxabi.h" KWSYS_CXX_HAS_CXXABIH)
+ IF (KWSYS_CXX_HAS_CXXABIH)
+ # check if cxxabi can be used with this
+ # system and compiler.
+ KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_CXXABI
+ "Checking whether cxxabi works with this C++ compiler" DIRECT)
+ IF (KWSYS_CXX_HAS_CXXABI)
+ # c++ demangle using cxxabi is supported with
+ # this system and compiler
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE=1)
+ ENDIF()
+ ENDIF()
+ # basic backtrace works better with release build
+ # don't bother with advanced features for release
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS_DEBUG KWSYS_SYSTEMINFORMATION_HAS_DEBUG_BUILD=1)
+ SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY
+ COMPILE_DEFINITIONS_RELWITHDEBINFO KWSYS_SYSTEMINFORMATION_HAS_DEBUG_BUILD=1)
+ ENDIF()
+ ENDIF()
+ ENDIF()
IF(BORLAND)
KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BORLAND_ASM
"Checking whether Borland CXX compiler supports assembler instructions" DIRECT)
@@ -904,12 +975,23 @@ IF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS)
ENDIF(UNIX)
ENDIF(KWSYS_USE_DynamicLoader)
- IF(KWSYS_USE_SystemInformation AND WIN32)
- TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ws2_32)
- IF(KWSYS_SYS_HAS_PSAPI)
- TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} Psapi)
+ IF(KWSYS_USE_SystemInformation)
+ IF(WIN32)
+ TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ws2_32)
+ IF(KWSYS_SYS_HAS_PSAPI)
+ TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} Psapi)
+ ENDIF()
+ ELSEIF(UNIX)
+ IF (EXECINFO_LIB AND KWSYS_CXX_HAS_BACKTRACE)
+ # backtrace on FreeBSD is not in libc
+ TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${EXECINFO_LIB})
+ ENDIF()
+ IF (KWSYS_CXX_HAS_DLADDR)
+ # for symbol lookup using dladdr
+ TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${CMAKE_DL_LIBS})
+ ENDIF()
ENDIF()
- ENDIF(KWSYS_USE_SystemInformation AND WIN32)
+ ENDIF()
# Apply user-defined target properties to the library.
IF(KWSYS_PROPERTIES_CXX)
diff --git a/Source/kwsys/CommandLineArguments.hxx.in b/Source/kwsys/CommandLineArguments.hxx.in
index 68e9600ef..cbf6ee393 100644
--- a/Source/kwsys/CommandLineArguments.hxx.in
+++ b/Source/kwsys/CommandLineArguments.hxx.in
@@ -44,7 +44,7 @@ struct CommandLineArgumentsCallbackStructure;
*
* For the variable interface you associate variable with each argument. When
* the argument is specified, the variable is set to the specified value casted
- * to the apropriate type. For boolean (NO_ARGUMENT), the value is "1".
+ * to the appropriate type. For boolean (NO_ARGUMENT), the value is "1".
*
* Both interfaces can be used at the same time.
*
@@ -99,7 +99,7 @@ public:
STRING_TYPE, // The variable is string (char*)
STL_STRING_TYPE, // The variable is string (char*)
VECTOR_INT_TYPE, // The variable is integer (int)
- VECTOR_BOOL_TYPE, // The vairable is boolean (bool)
+ VECTOR_BOOL_TYPE, // The variable is boolean (bool)
VECTOR_DOUBLE_TYPE, // The variable is float (double)
VECTOR_STRING_TYPE, // The variable is string (char*)
VECTOR_STL_STRING_TYPE, // The variable is string (char*)
@@ -128,7 +128,7 @@ public:
void ProcessArgument(const char* arg);
/**
- * This method will parse arguments and call apropriate methods.
+ * This method will parse arguments and call appropriate methods.
*/
int Parse();
@@ -144,7 +144,7 @@ public:
/**
* Add handler for argument which is going to set the variable to the
* specified value. If the argument is specified, the option is casted to the
- * apropriate type.
+ * appropriate type.
*/
void AddArgument(const char* argument, ArgumentTypeEnum type,
bool* variable, const char* help);
@@ -160,7 +160,7 @@ public:
/**
* Add handler for argument which is going to set the variable to the
* specified value. If the argument is specified, the option is casted to the
- * apropriate type. This will handle the multi argument values.
+ * appropriate type. This will handle the multi argument values.
*/
void AddArgument(const char* argument, ArgumentTypeEnum type,
kwsys_stl::vector<bool>* variable, const char* help);
diff --git a/Source/kwsys/RegularExpression.cxx b/Source/kwsys/RegularExpression.cxx
index f6eeebae4..c8297873f 100644
--- a/Source/kwsys/RegularExpression.cxx
+++ b/Source/kwsys/RegularExpression.cxx
@@ -312,8 +312,8 @@ static char* regbranch (int*);
static char* regpiece (int*);
static char* regatom (int*);
static char* regnode (char);
-static const char* regnext (register const char*);
-static char* regnext (register char*);
+static const char* regnext (const char*);
+static char* regnext (char*);
static void regc (char);
static void reginsert (char, char*);
static void regtail (char*, const char*);
@@ -344,10 +344,10 @@ static int strcspn ();
// for later pattern matching.
bool RegularExpression::compile (const char* exp) {
- register const char* scan;
- register const char* longest;
- register size_t len;
- int flags;
+ const char* scan;
+ const char* longest;
+ size_t len;
+ int flags;
if (exp == 0) {
//RAISE Error, SYM(RegularExpression), SYM(No_Expr),
@@ -444,11 +444,11 @@ bool RegularExpression::compile (const char* exp) {
* follows makes it hard to avoid.
*/
static char* reg (int paren, int *flagp) {
- register char* ret;
- register char* br;
- register char* ender;
- register int parno =0;
- int flags;
+ char* ret;
+ char* br;
+ char* ender;
+ int parno =0;
+ int flags;
*flagp = HASWIDTH; // Tentatively.
@@ -525,10 +525,10 @@ static char* reg (int paren, int *flagp) {
* Implements the concatenation operator.
*/
static char* regbranch (int *flagp) {
- register char* ret;
- register char* chain;
- register char* latest;
- int flags;
+ char* ret;
+ char* chain;
+ char* latest;
+ int flags;
*flagp = WORST; // Tentatively.
@@ -562,10 +562,10 @@ static char* regbranch (int *flagp) {
* endmarker role is not redundant.
*/
static char* regpiece (int *flagp) {
- register char* ret;
- register char op;
- register char* next;
- int flags;
+ char* ret;
+ char op;
+ char* next;
+ int flags;
ret = regatom(&flags);
if (ret == 0)
@@ -631,8 +631,8 @@ static char* regpiece (int *flagp) {
* separate node; the code is simpler that way and it's not worth fixing.
*/
static char* regatom (int *flagp) {
- register char* ret;
- int flags;
+ char* ret;
+ int flags;
*flagp = WORST; // Tentatively.
@@ -648,8 +648,8 @@ static char* regatom (int *flagp) {
*flagp |= HASWIDTH | SIMPLE;
break;
case '[':{
- register int rxpclass;
- register int rxpclassend;
+ int rxpclass;
+ int rxpclassend;
if (*regparse == '^') { // Complement of range.
ret = regnode(ANYBUT);
@@ -720,8 +720,8 @@ static char* regatom (int *flagp) {
*flagp |= HASWIDTH | SIMPLE;
break;
default:{
- register int len;
- register char ender;
+ int len;
+ char ender;
regparse--;
len = int(strcspn(regparse, META));
@@ -754,8 +754,8 @@ static char* regatom (int *flagp) {
Location.
*/
static char* regnode (char op) {
- register char* ret;
- register char* ptr;
+ char* ret;
+ char* ptr;
ret = regcode;
if (ret == &regdummy) {
@@ -790,9 +790,9 @@ static void regc (char b) {
* Means relocating the operand.
*/
static void reginsert (char op, char* opnd) {
- register char* src;
- register char* dst;
- register char* place;
+ char* src;
+ char* dst;
+ char* place;
if (regcode == &regdummy) {
regsize += 3;
@@ -816,9 +816,9 @@ static void reginsert (char op, char* opnd) {
- regtail - set the next-pointer at the end of a node chain
*/
static void regtail (char* p, const char* val) {
- register char* scan;
- register char* temp;
- register int offset;
+ char* scan;
+ char* temp;
+ int offset;
if (p == &regdummy)
return;
@@ -893,7 +893,7 @@ bool RegularExpression::find (kwsys_stl::string const& s)
// Returns true if found, and sets start and end indexes accordingly.
bool RegularExpression::find (const char* string) {
- register const char* s;
+ const char* s;
this->searchstring = string;
@@ -956,9 +956,9 @@ bool RegularExpression::find (const char* string) {
*/
static int regtry (const char* string, const char* *start,
const char* *end, const char* prog) {
- register int i;
- register const char* *sp1;
- register const char* *ep;
+ int i;
+ const char* *sp1;
+ const char* *ep;
reginput = string;
regstartp = start;
@@ -992,8 +992,8 @@ static int regtry (const char* string, const char* *start,
* 0 failure, 1 success
*/
static int regmatch (const char* prog) {
- register const char* scan; // Current node.
- const char* next; // Next node.
+ const char* scan; // Current node.
+ const char* next; // Next node.
scan = prog;
@@ -1016,8 +1016,8 @@ static int regmatch (const char* prog) {
reginput++;
break;
case EXACTLY:{
- register size_t len;
- register const char* opnd;
+ size_t len;
+ const char* opnd;
opnd = OPERAND(scan);
// Inline the first character, for speed.
@@ -1052,8 +1052,8 @@ static int regmatch (const char* prog) {
case OPEN + 7:
case OPEN + 8:
case OPEN + 9:{
- register int no;
- register const char* save;
+ int no;
+ const char* save;
no = OP(scan) - OPEN;
save = reginput;
@@ -1081,8 +1081,8 @@ static int regmatch (const char* prog) {
case CLOSE + 7:
case CLOSE + 8:
case CLOSE + 9:{
- register int no;
- register const char* save;
+ int no;
+ const char* save;
no = OP(scan) - CLOSE;
save = reginput;
@@ -1103,7 +1103,7 @@ static int regmatch (const char* prog) {
// break;
case BRANCH:{
- register const char* save;
+ const char* save;
if (OP(next) != BRANCH) // No choice.
next = OPERAND(scan); // Avoid recursion.
@@ -1122,10 +1122,10 @@ static int regmatch (const char* prog) {
break;
case STAR:
case PLUS:{
- register char nextch;
- register int no;
- register const char* save;
- register int min_no;
+ char nextch;
+ int no;
+ const char* save;
+ int min_no;
//
// Lookahead to avoid useless match attempts when we know
@@ -1174,9 +1174,9 @@ static int regmatch (const char* prog) {
- regrepeat - repeatedly match something simple, report how many
*/
static int regrepeat (const char* p) {
- register int count = 0;
- register const char* scan;
- register const char* opnd;
+ int count = 0;
+ const char* scan;
+ const char* opnd;
scan = reginput;
opnd = OPERAND(p);
@@ -1216,8 +1216,8 @@ static int regrepeat (const char* p) {
/*
- regnext - dig the "next" pointer out of a node
*/
-static const char* regnext (register const char* p) {
- register int offset;
+static const char* regnext (const char* p) {
+ int offset;
if (p == &regdummy)
return (0);
@@ -1232,8 +1232,8 @@ static const char* regnext (register const char* p) {
return (p + offset);
}
-static char* regnext (register char* p) {
- register int offset;
+static char* regnext (char* p) {
+ int offset;
if (p == &regdummy)
return (0);
diff --git a/Source/kwsys/SharedForward.h.in b/Source/kwsys/SharedForward.h.in
index 8521099ad..8bbc74ac2 100644
--- a/Source/kwsys/SharedForward.h.in
+++ b/Source/kwsys/SharedForward.h.in
@@ -772,7 +772,7 @@ static int kwsys_shared_forward_get_settings(const char* self_path,
const char** dir;
for(dir = search_path; *dir; ++dir)
{
- /* Add seperator between path components. */
+ /* Add separator between path components. */
if(dir != search_path)
{
strcat(ldpath, kwsys_shared_forward_path_sep);
diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx
index 9e2a93d7c..beefd7d73 100644
--- a/Source/kwsys/SystemInformation.cxx
+++ b/Source/kwsys/SystemInformation.cxx
@@ -18,6 +18,10 @@
# include <winsock.h> // WSADATA, include before sys/types.h
#endif
+#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
+#endif
+
// TODO:
// We need an alternative implementation for many functions in this file
// when USE_ASM_INSTRUCTIONS gets defined as 0.
@@ -114,8 +118,15 @@ typedef int siginfo_t;
# define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN
# endif
# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 >= 1050
-# include <execinfo.h>
-# define KWSYS_SYSTEMINFORMATION_HAVE_BACKTRACE
+# if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
+# include <execinfo.h>
+# if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE)
+# include <cxxabi.h>
+# endif
+# if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
+# include <dlfcn.h>
+# endif
+# endif
# endif
#endif
@@ -130,10 +141,13 @@ typedef int siginfo_t;
# define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN
# endif
# endif
-# if defined(__GNUC__)
+# if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
# include <execinfo.h>
-# if !(defined(__LSB_VERSION__) && __LSB_VERSION__ < 41)
-# define KWSYS_SYSTEMINFORMATION_HAVE_BACKTRACE
+# if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE)
+# include <cxxabi.h>
+# endif
+# if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
+# include <dlfcn.h>
# endif
# endif
# if defined(KWSYS_CXX_HAS_RLIMIT64)
@@ -357,6 +371,10 @@ public:
static
void SetStackTraceOnError(int enable);
+ // get current stack
+ static
+ kwsys_stl::string GetProgramStack(int firstFrame, int wholePath);
+
/** Run the different checks */
void RunCPUCheck();
void RunOSCheck();
@@ -812,6 +830,11 @@ void SystemInformation::SetStackTraceOnError(int enable)
SystemInformationImplementation::SetStackTraceOnError(enable);
}
+kwsys_stl::string SystemInformation::GetProgramStack(int firstFrame, int wholePath)
+{
+ return SystemInformationImplementation::GetProgramStack(firstFrame, wholePath);
+}
+
/** Run the different checks */
void SystemInformation::RunCPUCheck()
{
@@ -908,6 +931,12 @@ int LoadLines(
}
continue;
}
+ char *pBuf=buf;
+ while(*pBuf)
+ {
+ if (*pBuf=='\n') *pBuf='\0';
+ pBuf+=1;
+ }
lines.push_back(buf);
++nRead;
}
@@ -1046,12 +1075,29 @@ void StacktraceSignalHandler(
#if defined(__linux) || defined(__APPLE__)
kwsys_ios::ostringstream oss;
oss
+ << kwsys_ios::endl
<< "=========================================================" << kwsys_ios::endl
<< "Process id " << getpid() << " ";
switch (sigNo)
{
+ case SIGINT:
+ oss << "Caught SIGINT";
+ break;
+
+ case SIGTERM:
+ oss << "Caught SIGTERM";
+ break;
+
+ case SIGABRT:
+ oss << "Caught SIGABRT";
+ break;
+
case SIGFPE:
- oss << "Caught SIGFPE ";
+ oss
+ << "Caught SIGFPE at "
+ << (sigInfo->si_addr==0?"0x":"")
+ << sigInfo->si_addr
+ << " ";
switch (sigInfo->si_code)
{
# if defined(FPE_INTDIV)
@@ -1099,7 +1145,11 @@ void StacktraceSignalHandler(
break;
case SIGSEGV:
- oss << "Caught SIGSEGV ";
+ oss
+ << "Caught SIGSEGV at "
+ << (sigInfo->si_addr==0?"0x":"")
+ << sigInfo->si_addr
+ << " ";
switch (sigInfo->si_code)
{
case SEGV_MAPERR:
@@ -1116,16 +1166,12 @@ void StacktraceSignalHandler(
}
break;
- case SIGINT:
- oss << "Caught SIGTERM";
- break;
-
- case SIGTERM:
- oss << "Caught SIGTERM";
- break;
-
case SIGBUS:
- oss << "Caught SIGBUS type ";
+ oss
+ << "Caught SIGBUS at "
+ << (sigInfo->si_addr==0?"0x":"")
+ << sigInfo->si_addr
+ << " ";
switch (sigInfo->si_code)
{
case BUS_ADRALN:
@@ -1134,13 +1180,25 @@ void StacktraceSignalHandler(
# if defined(BUS_ADRERR)
case BUS_ADRERR:
- oss << "non-exestent physical address";
+ oss << "nonexistent physical address";
break;
# endif
# if defined(BUS_OBJERR)
case BUS_OBJERR:
- oss << "object specific hardware error";
+ oss << "object-specific hardware error";
+ break;
+# endif
+
+# if defined(BUS_MCEERR_AR)
+ case BUS_MCEERR_AR:
+ oss << "Hardware memory error consumed on a machine check; action required.";
+ break;
+# endif
+
+# if defined(BUS_MCEERR_AO)
+ case BUS_MCEERR_AO:
+ oss << "Hardware memory error detected in process but not consumed; action optional.";
break;
# endif
@@ -1151,7 +1209,11 @@ void StacktraceSignalHandler(
break;
case SIGILL:
- oss << "Caught SIGILL ";
+ oss
+ << "Caught SIGILL at "
+ << (sigInfo->si_addr==0?"0x":"")
+ << sigInfo->si_addr
+ << " ";
switch (sigInfo->si_code)
{
case ILL_ILLOPC:
@@ -1205,20 +1267,16 @@ void StacktraceSignalHandler(
oss << "Caught " << sigNo << " code " << sigInfo->si_code;
break;
}
- oss << kwsys_ios::endl;
-#if defined(KWSYS_SYSTEMINFORMATION_HAVE_BACKTRACE)
- oss << "Program Stack:" << kwsys_ios::endl;
- void *stackSymbols[128];
- int n=backtrace(stackSymbols,128);
- char **stackText=backtrace_symbols(stackSymbols,n);
- for (int i=0; i<n; ++i)
- {
- oss << " " << stackText[i] << kwsys_ios::endl;
- }
-#endif
oss
- << "=========================================================" << kwsys_ios::endl;
+ << kwsys_ios::endl
+ << "Program Stack:" << kwsys_ios::endl
+ << SystemInformationImplementation::GetProgramStack(2,0)
+ << "=========================================================" << kwsys_ios::endl;
kwsys_ios::cerr << oss.str() << kwsys_ios::endl;
+
+ // restore the previously registered handlers
+ // and abort
+ SystemInformationImplementation::SetStackTraceOnError(0);
abort();
#else
// avoid warning C4100
@@ -1227,8 +1285,213 @@ void StacktraceSignalHandler(
#endif
}
#endif
+
+#if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
+#define safes(_arg)((_arg)?(_arg):"???")
+
+// Description:
+// A container for symbol properties. Each instance
+// must be Initialized.
+class SymbolProperties
+{
+public:
+ SymbolProperties();
+
+ // Description:
+ // The SymbolProperties instance must be initialized by
+ // passing a stack address.
+ void Initialize(void *address);
+
+ // Description:
+ // Get the symbol's stack address.
+ void *GetAddress() const { return this->Address; }
+
+ // Description:
+ // If not set paths will be removed. eg, from a binary
+ // or source file.
+ void SetReportPath(int rp){ this->ReportPath=rp; }
+
+ // Description:
+ // Set/Get the name of the binary file that the symbol
+ // is found in.
+ void SetBinary(const char *binary)
+ { this->Binary=safes(binary); }
+
+ kwsys_stl::string GetBinary() const;
+
+ // Description:
+ // Set the name of the function that the symbol is found in.
+ // If c++ demangling is supported it will be demangled.
+ void SetFunction(const char *function)
+ { this->Function=this->Demangle(function); }
+
+ kwsys_stl::string GetFunction() const
+ { return this->Function; }
+
+ // Description:
+ // Set/Get the name of the source file where the symbol
+ // is defined.
+ void SetSourceFile(const char *sourcefile)
+ { this->SourceFile=safes(sourcefile); }
+
+ kwsys_stl::string GetSourceFile() const
+ { return this->GetFileName(this->SourceFile); }
+
+ // Description:
+ // Set/Get the line number where the symbol is defined
+ void SetLineNumber(long linenumber){ this->LineNumber=linenumber; }
+ long GetLineNumber() const { return this->LineNumber; }
+
+ // Description:
+ // Set the address where the biinary image is mapped
+ // into memory.
+ void SetBinaryBaseAddress(void *address)
+ { this->BinaryBaseAddress=address; }
+
+private:
+ void *GetRealAddress() const
+ { return (void*)((char*)this->Address-(char*)this->BinaryBaseAddress); }
+
+ kwsys_stl::string GetFileName(const kwsys_stl::string &path) const;
+ kwsys_stl::string Demangle(const char *symbol) const;
+
+private:
+ kwsys_stl::string Binary;
+ void *BinaryBaseAddress;
+ void *Address;
+ kwsys_stl::string SourceFile;
+ kwsys_stl::string Function;
+ long LineNumber;
+ int ReportPath;
+};
+
+// --------------------------------------------------------------------------
+kwsys_ios::ostream &operator<<(
+ kwsys_ios::ostream &os,
+ const SymbolProperties &sp)
+{
+#if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
+ os
+ << kwsys_ios::hex << sp.GetAddress() << " : "
+ << sp.GetFunction()
+ << " [(" << sp.GetBinary() << ") "
+ << sp.GetSourceFile() << ":"
+ << kwsys_ios::dec << sp.GetLineNumber() << "]";
+#elif defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
+ void *addr = sp.GetAddress();
+ char **syminfo = backtrace_symbols(&addr,1);
+ os << safes(syminfo[0]);
+ free(syminfo);
+#else
+ (void)os;
+ (void)sp;
+#endif
+ return os;
+}
+
+// --------------------------------------------------------------------------
+SymbolProperties::SymbolProperties()
+{
+ // not using an initializer list
+ // to avoid some PGI compiler warnings
+ this->SetBinary("???");
+ this->SetBinaryBaseAddress(NULL);
+ this->Address = NULL;
+ this->SetSourceFile("???");
+ this->SetFunction("???");
+ this->SetLineNumber(-1);
+ this->SetReportPath(0);
+ // avoid PGI compiler warnings
+ this->GetRealAddress();
+ this->GetFunction();
+ this->GetSourceFile();
+ this->GetLineNumber();
+}
+
+// --------------------------------------------------------------------------
+kwsys_stl::string SymbolProperties::GetFileName(const kwsys_stl::string &path) const
+{
+ kwsys_stl::string file(path);
+ if (!this->ReportPath)
+ {
+ size_t at = file.rfind("/");
+ if (at!=kwsys_stl::string::npos)
+ {
+ file = file.substr(at+1,kwsys_stl::string::npos);
+ }
+ }
+ return file;
+}
+
+// --------------------------------------------------------------------------
+kwsys_stl::string SymbolProperties::GetBinary() const
+{
+// only linux has proc fs
+#if defined(__linux__)
+ if (this->Binary=="/proc/self/exe")
+ {
+ kwsys_stl::string binary;
+ char buf[1024]={'\0'};
+ ssize_t ll=0;
+ if ((ll=readlink("/proc/self/exe",buf,1024))>0)
+ {
+ buf[ll]='\0';
+ binary=buf;
+ }
+ else
+ {
+ binary="/proc/self/exe";
+ }
+ return this->GetFileName(binary);
+ }
+#endif
+ return this->GetFileName(this->Binary);
+}
+
+// --------------------------------------------------------------------------
+kwsys_stl::string SymbolProperties::Demangle(const char *symbol) const
+{
+ kwsys_stl::string result = safes(symbol);
+#if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE)
+ int status = 0;
+ size_t bufferLen = 1024;
+ char *buffer = (char*)malloc(1024);
+ char *demangledSymbol =
+ abi::__cxa_demangle(symbol, buffer, &bufferLen, &status);
+ if (!status)
+ {
+ result = demangledSymbol;
+ }
+ free(buffer);
+#else
+ (void)symbol;
+#endif
+ return result;
+}
+
+// --------------------------------------------------------------------------
+void SymbolProperties::Initialize(void *address)
+{
+ this->Address = address;
+#if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
+ // first fallback option can demangle c++ functions
+ Dl_info info;
+ int ierr=dladdr(this->Address,&info);
+ if (ierr && info.dli_sname && info.dli_saddr)
+ {
+ this->SetBinary(info.dli_fname);
+ this->SetFunction(info.dli_sname);
+ }
+#else
+ // second fallback use builtin backtrace_symbols
+ // to decode the bactrace.
+#endif
+}
+#endif // don't define this class if we're not using it
+
} // anonymous namespace
+
SystemInformationImplementation::SystemInformationImplementation()
{
this->TotalVirtualMemory = 0;
@@ -1471,7 +1734,7 @@ int SystemInformationImplementation::GetFullyQualifiedDomainName(
{
char host[NI_MAXHOST]={'\0'};
- int addrlen
+ socklen_t addrlen
= (fam==AF_INET?sizeof(struct sockaddr_in):sizeof(struct sockaddr_in6));
ierr=getnameinfo(
@@ -3336,12 +3599,61 @@ SystemInformationImplementation::GetProcessId()
}
/**
+return current program stack in a string
+demangle cxx symbols if possible.
+*/
+kwsys_stl::string SystemInformationImplementation::GetProgramStack(
+ int firstFrame,
+ int wholePath)
+{
+ kwsys_stl::string programStack = ""
+#if !defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
+ "WARNING: The stack could not be examined "
+ "because backtrace is not supported.\n"
+#elif !defined(KWSYS_SYSTEMINFORMATION_HAS_DEBUG_BUILD)
+ "WARNING: The stack trace will not use advanced "
+ "capabilities because this is a release build.\n"
+#else
+# if !defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP)
+ "WARNING: Function names will not be demangled because "
+ "dladdr is not available.\n"
+# endif
+# if !defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE)
+ "WARNING: Function names will not be demangled "
+ "because cxxabi is not available.\n"
+# endif
+#endif
+ ;
+
+ kwsys_ios::ostringstream oss;
+#if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
+ void *stackSymbols[256];
+ int nFrames=backtrace(stackSymbols,256);
+ for (int i=firstFrame; i<nFrames; ++i)
+ {
+ SymbolProperties symProps;
+ symProps.SetReportPath(wholePath);
+ symProps.Initialize(stackSymbols[i]);
+ oss << symProps << kwsys_ios::endl;
+ }
+#else
+ (void)firstFrame;
+ (void)wholePath;
+#endif
+ programStack += oss.str();
+
+ return programStack;
+}
+
+
+/**
when set print stack trace in response to common signals.
*/
void SystemInformationImplementation::SetStackTraceOnError(int enable)
{
#if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
static int saOrigValid=0;
+ static struct sigaction saABRTOrig;
static struct sigaction saSEGVOrig;
static struct sigaction saTERMOrig;
static struct sigaction saINTOrig;
@@ -3349,9 +3661,11 @@ void SystemInformationImplementation::SetStackTraceOnError(int enable)
static struct sigaction saBUSOrig;
static struct sigaction saFPEOrig;
+
if (enable && !saOrigValid)
{
// save the current actions
+ sigaction(SIGABRT,0,&saABRTOrig);
sigaction(SIGSEGV,0,&saSEGVOrig);
sigaction(SIGTERM,0,&saTERMOrig);
sigaction(SIGINT,0,&saINTOrig);
@@ -3365,9 +3679,10 @@ void SystemInformationImplementation::SetStackTraceOnError(int enable)
// install ours
struct sigaction sa;
sa.sa_sigaction=(SigAction)StacktraceSignalHandler;
- sa.sa_flags=SA_SIGINFO|SA_RESTART;
+ sa.sa_flags=SA_SIGINFO|SA_RESTART|SA_RESETHAND;
sigemptyset(&sa.sa_mask);
+ sigaction(SIGABRT,&sa,0);
sigaction(SIGSEGV,&sa,0);
sigaction(SIGTERM,&sa,0);
sigaction(SIGINT,&sa,0);
@@ -3379,6 +3694,7 @@ void SystemInformationImplementation::SetStackTraceOnError(int enable)
if (!enable && saOrigValid)
{
// restore previous actions
+ sigaction(SIGABRT,&saABRTOrig,0);
sigaction(SIGSEGV,&saSEGVOrig,0);
sigaction(SIGTERM,&saTERMOrig,0);
sigaction(SIGINT,&saINTOrig,0);
@@ -3487,7 +3803,7 @@ bool SystemInformationImplementation::QueryLinuxMemory()
bool have[6] = { false, false, false, false, false, false };
unsigned long value[6];
int count = 0;
- while(fgets(buffer, sizeof(buffer), fd))
+ while(fgets(buffer, static_cast<int>(sizeof(buffer)), fd))
{
for(int i=0; i < 6; ++i)
{
diff --git a/Source/kwsys/SystemInformation.hxx.in b/Source/kwsys/SystemInformation.hxx.in
index 8f4cb4e5a..a9fd05def 100644
--- a/Source/kwsys/SystemInformation.hxx.in
+++ b/Source/kwsys/SystemInformation.hxx.in
@@ -117,8 +117,8 @@ public:
// Get total system RAM in units of KiB available to this process.
// This may differ from the host available if a per-process resource
// limit is applied. per-process memory limits are applied on unix
- // system via rlimit api. Resource limits that are not imposed via
- // rlimit api may be reported to us via an application specified
+ // system via rlimit API. Resource limits that are not imposed via
+ // rlimit API may be reported to us via an application specified
// environment variable.
LongLong GetProcMemoryAvailable(
const char *hostLimitEnvVarName=NULL,
@@ -136,6 +136,12 @@ public:
static
void SetStackTraceOnError(int enable);
+ // format and return the current program stack in a string. In
+ // order to produce an informative stack trace the application
+ // should be dynamically linked and compiled with debug symbols.
+ static
+ kwsys_stl::string GetProgramStack(int firstFrame, int wholePath);
+
/** Run the different checks */
void RunCPUCheck();
void RunOSCheck();
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 8b25d608d..e9a1fd37d 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -605,7 +605,7 @@ bool SystemTools::MakeDirectory(const char* path)
}
if(SystemTools::FileExists(path))
{
- return true;
+ return SystemTools::FileIsDirectory(path);
}
kwsys_stl::string dir = path;
if(dir.size() == 0)
@@ -695,6 +695,52 @@ void SystemTools::ReplaceString(kwsys_stl::string& source,
#endif
#if defined(_WIN32) && !defined(__CYGWIN__)
+static bool SystemToolsParseRegistryKey(const char* key,
+ HKEY& primaryKey,
+ kwsys_stl::string& second,
+ kwsys_stl::string& valuename)
+{
+ kwsys_stl::string primary = key;
+
+ size_t start = primary.find("\\");
+ if (start == kwsys_stl::string::npos)
+ {
+ return false;
+ }
+
+ size_t valuenamepos = primary.find(";");
+ if (valuenamepos != kwsys_stl::string::npos)
+ {
+ valuename = primary.substr(valuenamepos+1);
+ }
+
+ second = primary.substr(start+1, valuenamepos-start-1);
+ primary = primary.substr(0, start);
+
+ if (primary == "HKEY_CURRENT_USER")
+ {
+ primaryKey = HKEY_CURRENT_USER;
+ }
+ if (primary == "HKEY_CURRENT_CONFIG")
+ {
+ primaryKey = HKEY_CURRENT_CONFIG;
+ }
+ if (primary == "HKEY_CLASSES_ROOT")
+ {
+ primaryKey = HKEY_CLASSES_ROOT;
+ }
+ if (primary == "HKEY_LOCAL_MACHINE")
+ {
+ primaryKey = HKEY_LOCAL_MACHINE;
+ }
+ if (primary == "HKEY_USERS")
+ {
+ primaryKey = HKEY_USERS;
+ }
+
+ return true;
+}
+
static DWORD SystemToolsMakeRegistryMode(DWORD mode,
SystemTools::KeyWOW64 view)
{
@@ -718,6 +764,55 @@ static DWORD SystemToolsMakeRegistryMode(DWORD mode,
}
#endif
+#if defined(_WIN32) && !defined(__CYGWIN__)
+bool
+SystemTools::GetRegistrySubKeys(const char *key,
+ kwsys_stl::vector<kwsys_stl::string>& subkeys,
+ KeyWOW64 view)
+{
+ HKEY primaryKey = HKEY_CURRENT_USER;
+ kwsys_stl::string second;
+ kwsys_stl::string valuename;
+ if (!SystemToolsParseRegistryKey(key, primaryKey, second, valuename))
+ {
+ return false;
+ }
+
+ HKEY hKey;
+ if(RegOpenKeyEx(primaryKey,
+ second.c_str(),
+ 0,
+ SystemToolsMakeRegistryMode(KEY_READ, view),
+ &hKey) != ERROR_SUCCESS)
+ {
+ return false;
+ }
+ else
+ {
+ char name[1024];
+ DWORD dwNameSize = sizeof(name)/sizeof(name[0]);
+
+ DWORD i = 0;
+ while (RegEnumKey(hKey, i, name, dwNameSize) == ERROR_SUCCESS)
+ {
+ subkeys.push_back(name);
+ ++i;
+ }
+
+ RegCloseKey(hKey);
+ }
+
+ return true;
+}
+#else
+bool SystemTools::GetRegistrySubKeys(const char *,
+ kwsys_stl::vector<kwsys_stl::string>&,
+ KeyWOW64)
+{
+ return false;
+}
+#endif
+
// Read a registry value.
// Example :
// HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.1\InstallPath
@@ -730,47 +825,14 @@ bool SystemTools::ReadRegistryValue(const char *key, kwsys_stl::string &value,
KeyWOW64 view)
{
bool valueset = false;
- kwsys_stl::string primary = key;
+ HKEY primaryKey = HKEY_CURRENT_USER;
kwsys_stl::string second;
kwsys_stl::string valuename;
-
- size_t start = primary.find("\\");
- if (start == kwsys_stl::string::npos)
+ if (!SystemToolsParseRegistryKey(key, primaryKey, second, valuename))
{
return false;
}
- size_t valuenamepos = primary.find(";");
- if (valuenamepos != kwsys_stl::string::npos)
- {
- valuename = primary.substr(valuenamepos+1);
- }
-
- second = primary.substr(start+1, valuenamepos-start-1);
- primary = primary.substr(0, start);
-
- HKEY primaryKey = HKEY_CURRENT_USER;
- if (primary == "HKEY_CURRENT_USER")
- {
- primaryKey = HKEY_CURRENT_USER;
- }
- if (primary == "HKEY_CURRENT_CONFIG")
- {
- primaryKey = HKEY_CURRENT_CONFIG;
- }
- if (primary == "HKEY_CLASSES_ROOT")
- {
- primaryKey = HKEY_CLASSES_ROOT;
- }
- if (primary == "HKEY_LOCAL_MACHINE")
- {
- primaryKey = HKEY_LOCAL_MACHINE;
- }
- if (primary == "HKEY_USERS")
- {
- primaryKey = HKEY_USERS;
- }
-
HKEY hKey;
if(RegOpenKeyEx(primaryKey,
second.c_str(),
@@ -834,47 +896,14 @@ bool SystemTools::ReadRegistryValue(const char *, kwsys_stl::string &,
bool SystemTools::WriteRegistryValue(const char *key, const char *value,
KeyWOW64 view)
{
- kwsys_stl::string primary = key;
+ HKEY primaryKey = HKEY_CURRENT_USER;
kwsys_stl::string second;
kwsys_stl::string valuename;
-
- size_t start = primary.find("\\");
- if (start == kwsys_stl::string::npos)
+ if (!SystemToolsParseRegistryKey(key, primaryKey, second, valuename))
{
return false;
}
- size_t valuenamepos = primary.find(";");
- if (valuenamepos != kwsys_stl::string::npos)
- {
- valuename = primary.substr(valuenamepos+1);
- }
-
- second = primary.substr(start+1, valuenamepos-start-1);
- primary = primary.substr(0, start);
-
- HKEY primaryKey = HKEY_CURRENT_USER;
- if (primary == "HKEY_CURRENT_USER")
- {
- primaryKey = HKEY_CURRENT_USER;
- }
- if (primary == "HKEY_CURRENT_CONFIG")
- {
- primaryKey = HKEY_CURRENT_CONFIG;
- }
- if (primary == "HKEY_CLASSES_ROOT")
- {
- primaryKey = HKEY_CLASSES_ROOT;
- }
- if (primary == "HKEY_LOCAL_MACHINE")
- {
- primaryKey = HKEY_LOCAL_MACHINE;
- }
- if (primary == "HKEY_USERS")
- {
- primaryKey = HKEY_USERS;
- }
-
HKEY hKey;
DWORD dwDummy;
char lpClass[] = "";
@@ -919,47 +948,14 @@ bool SystemTools::WriteRegistryValue(const char *, const char *, KeyWOW64)
#if defined(_WIN32) && !defined(__CYGWIN__)
bool SystemTools::DeleteRegistryValue(const char *key, KeyWOW64 view)
{
- kwsys_stl::string primary = key;
+ HKEY primaryKey = HKEY_CURRENT_USER;
kwsys_stl::string second;
kwsys_stl::string valuename;
-
- size_t start = primary.find("\\");
- if (start == kwsys_stl::string::npos)
+ if (!SystemToolsParseRegistryKey(key, primaryKey, second, valuename))
{
return false;
}
- size_t valuenamepos = primary.find(";");
- if (valuenamepos != kwsys_stl::string::npos)
- {
- valuename = primary.substr(valuenamepos+1);
- }
-
- second = primary.substr(start+1, valuenamepos-start-1);
- primary = primary.substr(0, start);
-
- HKEY primaryKey = HKEY_CURRENT_USER;
- if (primary == "HKEY_CURRENT_USER")
- {
- primaryKey = HKEY_CURRENT_USER;
- }
- if (primary == "HKEY_CURRENT_CONFIG")
- {
- primaryKey = HKEY_CURRENT_CONFIG;
- }
- if (primary == "HKEY_CLASSES_ROOT")
- {
- primaryKey = HKEY_CLASSES_ROOT;
- }
- if (primary == "HKEY_LOCAL_MACHINE")
- {
- primaryKey = HKEY_LOCAL_MACHINE;
- }
- if (primary == "HKEY_USERS")
- {
- primaryKey = HKEY_USERS;
- }
-
HKEY hKey;
if(RegOpenKeyEx(primaryKey,
second.c_str(),
@@ -1124,22 +1120,58 @@ bool SystemTools::Touch(const char* filename, bool create)
}
return false;
}
-#ifdef _MSC_VER
-#define utime _utime
-#define utimbuf _utimbuf
-#endif
- struct stat fromStat;
- if(stat(filename, &fromStat) < 0)
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ HANDLE h = CreateFile(filename, FILE_WRITE_ATTRIBUTES,
+ FILE_SHARE_WRITE, 0, OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS, 0);
+ if(!h)
+ {
+ return false;
+ }
+ FILETIME mtime;
+ GetSystemTimeAsFileTime(&mtime);
+ if(!SetFileTime(h, 0, 0, &mtime))
+ {
+ CloseHandle(h);
+ return false;
+ }
+ CloseHandle(h);
+#elif KWSYS_CXX_HAS_UTIMENSAT
+ struct timespec times[2] = {{0,UTIME_OMIT},{0,UTIME_NOW}};
+ if(utimensat(AT_FDCWD, filename, times, 0) < 0)
+ {
+ return false;
+ }
+#else
+ struct stat st;
+ if(stat(filename, &st) < 0)
{
return false;
}
- struct utimbuf buf;
- buf.actime = fromStat.st_atime;
- buf.modtime = static_cast<time_t>(SystemTools::GetTime());
- if(utime(filename, &buf) < 0)
+ struct timeval mtime;
+ gettimeofday(&mtime, 0);
+# if KWSYS_CXX_HAS_UTIMES
+ struct timeval times[2] =
+ {
+# if KWSYS_STAT_HAS_ST_MTIM
+ {st.st_atim.tv_sec, st.st_atim.tv_nsec/1000}, /* tv_sec, tv_usec */
+# else
+ {st.st_atime, 0},
+# endif
+ mtime
+ };
+ if(utimes(filename, times) < 0)
+ {
+ return false;
+ }
+# else
+ struct utimbuf times = {st.st_atime, mtime.tv_sec};
+ if(utime(filename, &times) < 0)
{
return false;
}
+# endif
+#endif
return true;
}
@@ -2741,12 +2773,12 @@ bool SystemTools::FileIsDirectory(const char* name)
return false;
}
- // Remove any trailing slash from the name.
+ // Remove any trailing slash from the name except in a root component.
char local_buffer[KWSYS_SYSTEMTOOLS_MAXPATH];
std::string string_buffer;
size_t last = length-1;
if(last > 0 && (name[last] == '/' || name[last] == '\\')
- && strcmp(name, "/") !=0)
+ && strcmp(name, "/") !=0 && name[last-1] != ':')
{
if(last < sizeof(local_buffer))
{
@@ -3049,7 +3081,7 @@ SystemToolsAppendComponents(
{
if(*i == "..")
{
- if(out_components.begin() != out_components.end())
+ if(out_components.size() > 1)
{
out_components.erase(out_components.end()-1, out_components.end());
}
@@ -4011,7 +4043,7 @@ void SystemTools::SplitProgramFromArgs(const char* path,
args = dir.substr(spacePos, dir.size()-spacePos);
return;
}
- // Now try and find the the program in the path
+ // Now try and find the program in the path
findProg = SystemTools::FindProgram(tryProg.c_str(), e);
if(findProg.size())
{
@@ -4225,17 +4257,13 @@ bool SystemTools::IsSubDirectory(const char* cSubdir, const char* cDir)
}
kwsys_stl::string subdir = cSubdir;
kwsys_stl::string dir = cDir;
+ SystemTools::ConvertToUnixSlashes(subdir);
SystemTools::ConvertToUnixSlashes(dir);
- kwsys_stl::string path = subdir;
- do
+ if(subdir.size() > dir.size() && subdir[dir.size()] == '/')
{
- path = SystemTools::GetParentDirectory(path.c_str());
- if(SystemTools::ComparePath(dir.c_str(), path.c_str()))
- {
- return true;
- }
+ std::string s = subdir.substr(0, dir.size());
+ return SystemTools::ComparePath(s.c_str(), dir.c_str());
}
- while ( path.size() > dir.size() );
return false;
}
@@ -4837,7 +4865,8 @@ static int SystemToolsDebugReport(int, char* message, int*)
void SystemTools::EnableMSVCDebugHook()
{
- if (getenv("DART_TEST_FROM_DART"))
+ if (getenv("DART_TEST_FROM_DART") ||
+ getenv("DASHBOARD_TEST_FROM_CTEST"))
{
_CrtSetReportHook(SystemToolsDebugReport);
}
diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in
index 9c56e96b0..d6dae3986 100644
--- a/Source/kwsys/SystemTools.hxx.in
+++ b/Source/kwsys/SystemTools.hxx.in
@@ -716,6 +716,13 @@ public:
enum KeyWOW64 { KeyWOW64_Default, KeyWOW64_32, KeyWOW64_64 };
/**
+ * Get a list of subkeys.
+ */
+ static bool GetRegistrySubKeys(const char *key,
+ kwsys_stl::vector<kwsys_stl::string>& subkeys,
+ KeyWOW64 view = KeyWOW64_Default);
+
+ /**
* Read a registry value
*/
static bool ReadRegistryValue(const char *key, kwsys_stl::string &value,
@@ -766,7 +773,7 @@ public:
static kwsys_stl::string GetCurrentWorkingDirectory(bool collapse =true);
/**
- * Change directory the the directory specified
+ * Change directory to the directory specified
*/
static int ChangeDirectory(const char* dir);
diff --git a/Source/kwsys/auto_ptr.hxx.in b/Source/kwsys/auto_ptr.hxx.in
index 857b1db3c..ad9654cb4 100644
--- a/Source/kwsys/auto_ptr.hxx.in
+++ b/Source/kwsys/auto_ptr.hxx.in
@@ -31,6 +31,17 @@
# define @KWSYS_NAMESPACE@_AUTO_PTR_CAST(a) a
#endif
+// In C++11, clang will warn about using dynamic exception specifications
+// as they are deprecated. But as this class is trying to faithfully
+// mimic std::auto_ptr, we want to keep the 'throw()' decorations below.
+// So we suppress the warning.
+#if defined(__clang__) && defined(__has_warning)
+# if __has_warning("-Wdeprecated")
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdeprecated"
+# endif
+#endif
+
namespace @KWSYS_NAMESPACE@
{
@@ -198,4 +209,11 @@ public:
} // namespace @KWSYS_NAMESPACE@
+// Undo warning suppression.
+#if defined(__clang__) && defined(__has_warning)
+# if __has_warning("-Wdeprecated")
+# pragma clang diagnostic pop
+# endif
+#endif
+
#endif
diff --git a/Source/kwsys/hashtable.hxx.in b/Source/kwsys/hashtable.hxx.in
index c83550304..651de82bf 100644
--- a/Source/kwsys/hashtable.hxx.in
+++ b/Source/kwsys/hashtable.hxx.in
@@ -62,6 +62,17 @@
# pragma set woff 3970 /* pointer to int conversion */ 3321 3968
#endif
+// In C++11, clang will warn about using dynamic exception specifications
+// as they are deprecated. But as this class is trying to faithfully
+// mimic unordered_set and unordered_map, we want to keep the 'throw()'
+// decorations below. So we suppress the warning.
+#if defined(__clang__) && defined(__has_warning)
+# if __has_warning("-Wdeprecated")
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wdeprecated"
+# endif
+#endif
+
#if @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_TEMPLATE
# define @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(T) @KWSYS_NAMESPACE@_stl::allocator< T >
#elif @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_NONTEMPLATE
@@ -1268,6 +1279,13 @@ using @KWSYS_NAMESPACE@::operator==;
using @KWSYS_NAMESPACE@::operator!=;
#endif
+// Undo warning suppression.
+#if defined(__clang__) && defined(__has_warning)
+# if __has_warning("-Wdeprecated")
+# pragma clang diagnostic pop
+# endif
+#endif
+
#if defined(_MSC_VER)
# pragma warning (pop)
#endif
diff --git a/Source/kwsys/kwsysPlatformTests.cmake b/Source/kwsys/kwsysPlatformTests.cmake
index d042450ee..f9ee254f0 100644
--- a/Source/kwsys/kwsysPlatformTests.cmake
+++ b/Source/kwsys/kwsysPlatformTests.cmake
@@ -19,6 +19,7 @@ MACRO(KWSYS_PLATFORM_TEST lang var description invert)
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/${KWSYS_PLATFORM_TEST_FILE_${lang}}
COMPILE_DEFINITIONS -DTEST_${var} ${KWSYS_PLATFORM_TEST_DEFINES} ${KWSYS_PLATFORM_TEST_EXTRA_FLAGS}
+ CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=${KWSYS_PLATFORM_TEST_LINK_LIBRARIES}"
OUTPUT_VARIABLE OUTPUT)
IF(${var}_COMPILED)
FILE(APPEND
@@ -150,9 +151,11 @@ ENDMACRO(KWSYS_PLATFORM_C_TEST_RUN)
MACRO(KWSYS_PLATFORM_CXX_TEST var description invert)
SET(KWSYS_PLATFORM_TEST_DEFINES ${KWSYS_PLATFORM_CXX_TEST_DEFINES})
SET(KWSYS_PLATFORM_TEST_EXTRA_FLAGS ${KWSYS_PLATFORM_CXX_TEST_EXTRA_FLAGS})
+ SET(KWSYS_PLATFORM_TEST_LINK_LIBRARIES ${KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES})
KWSYS_PLATFORM_TEST(CXX "${var}" "${description}" "${invert}")
SET(KWSYS_PLATFORM_TEST_DEFINES)
SET(KWSYS_PLATFORM_TEST_EXTRA_FLAGS)
+ SET(KWSYS_PLATFORM_TEST_LINK_LIBRARIES)
ENDMACRO(KWSYS_PLATFORM_CXX_TEST)
MACRO(KWSYS_PLATFORM_CXX_TEST_RUN var description invert)
diff --git a/Source/kwsys/kwsysPlatformTestsCXX.cxx b/Source/kwsys/kwsysPlatformTestsCXX.cxx
index 48976c442..be7a09ee2 100644
--- a/Source/kwsys/kwsysPlatformTestsCXX.cxx
+++ b/Source/kwsys/kwsysPlatformTestsCXX.cxx
@@ -494,6 +494,73 @@ int main()
}
#endif
+#ifdef TEST_KWSYS_CXX_HAS_UTIMES
+#include <sys/time.h>
+int main()
+{
+ struct timeval* current_time = 0;
+ return utimes("/example", current_time);
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_UTIMENSAT
+#include <fcntl.h>
+#include <sys/stat.h>
+int main()
+{
+ struct timespec times[2] = {{0,UTIME_OMIT},{0,UTIME_NOW}};
+ return utimensat(AT_FDCWD, "/example", times, AT_SYMLINK_NOFOLLOW);
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_BACKTRACE
+#if defined(__PATHSCALE__) || defined(__PATHCC__) \
+ || (defined(__LSB_VERSION__) && (__LSB_VERSION__ < 41))
+backtrace doesnt work with this compiler or os
+#endif
+#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
+#endif
+#include <execinfo.h>
+int main()
+{
+ void *stackSymbols[256];
+ backtrace(stackSymbols,256);
+ backtrace_symbols(&stackSymbols[0],1);
+ return 0;
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_DLADDR
+#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
+#endif
+#include <dlfcn.h>
+int main()
+{
+ Dl_info info;
+ int ierr=dladdr((void*)main,&info);
+ return 0;
+}
+#endif
+
+#ifdef TEST_KWSYS_CXX_HAS_CXXABI
+#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
+#endif
+#include <cxxabi.h>
+int main()
+{
+ int status = 0;
+ size_t bufferLen = 512;
+ char buffer[512] = {'\0'};
+ const char *function="_ZN5kwsys17SystemInformation15GetProgramStackEii";
+ char *demangledFunction =
+ abi::__cxa_demangle(function, buffer, &bufferLen, &status);
+ return status;
+}
+#endif
+
#ifdef TEST_KWSYS_CXX_TYPE_INFO
/* Collect fundamental type information and save it to a CMake script. */
diff --git a/Source/kwsys/testDynamicLoader.cxx b/Source/kwsys/testDynamicLoader.cxx
index 61c157291..dd6d60390 100644
--- a/Source/kwsys/testDynamicLoader.cxx
+++ b/Source/kwsys/testDynamicLoader.cxx
@@ -109,9 +109,9 @@ int testDynamicLoader(int argc, char *argv[])
// dlopen() on Syllable before 11/22/2007 doesn't return 0 on error
#ifndef __SYLLABLE__
- // Make sure that inexistant lib is giving correct result
+ // Make sure that inexistent lib is giving correct result
res += TestDynamicLoader("azerty_", "foo_bar",0,0,0);
- // Make sure that random binary file cannnot be assimilated as dylib
+ // Make sure that random binary file cannot be assimilated as dylib
res += TestDynamicLoader(TEST_SYSTEMTOOLS_BIN_FILE, "wp",0,0,0);
#endif
diff --git a/Source/kwsys/testIOS.cxx b/Source/kwsys/testIOS.cxx
index 3b971e268..f0c7f1a7b 100644
--- a/Source/kwsys/testIOS.cxx
+++ b/Source/kwsys/testIOS.cxx
@@ -48,7 +48,7 @@ int testIOS(int, char*[])
return 1;
}
static const unsigned char array[] = { 0xff,0x4f,0xff,0x51,0x00,0x29,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x01,0x01,0xff,0x52,0x00,0x0c,0x00,0x00,0x00,0x01,0x00,0x05,0x04,0x04,0x00,0x01,0xff,0x5c,0x00,0x13,0x40,0x40,0x48,0x48,0x50,0x48,0x48,0x50,0x48,0x48,0x50,0x48,0x48,0x50,0x48,0x48,0x50,0xff,0x64,0x00,0x2c,0x00,0x00,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x62,0x79,0x20,0x49,0x54,0x4b,0x2f,0x47,0x44,0x43,0x4d,0x2f,0x4f,0x70,0x65,0x6e,0x4a,0x50,0x45,0x47,0x20,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x31,0x2e,0x30,0xff,0x90,0x00,0x0a,0x00,0x00,0x00,0x00,0x06,0x2c,0x00,0x01,0xff,0x93,0xcf,0xb0,0x18,0x08,0x7f,0xc6,0x99,0xbf,0xff,0xc0,0xf8,0xc1,0xc1,0xf3,0x05,0x81,0xf2,0x83,0x0a,0xa5,0xff,0x10,0x90,0xbf,0x2f,0xff,0x04,0xa8,0x7f,0xc0,0xf8,0xc4,0xc1,0xf3,0x09,0x81,0xf3,0x0c,0x19,0x34 };
- const unsigned int narray = sizeof(array); // 180
+ const size_t narray = sizeof(array); // 180
kwsys_ios::stringstream strstr;
strstr.write( (char*)array, narray );
//strstr.seekp( narray / 2 ); // set position of put pointer in mid string
diff --git a/Source/kwsys/testSystemInformation.cxx b/Source/kwsys/testSystemInformation.cxx
index 49a686c17..53d51ac40 100644
--- a/Source/kwsys/testSystemInformation.cxx
+++ b/Source/kwsys/testSystemInformation.cxx
@@ -88,14 +88,31 @@ int testSystemInformation(int, char*[])
printMethod3(info, GetHostMemoryUsed(), "KiB");
printMethod3(info, GetProcMemoryUsed(), "KiB");
- for (int i = 0; i <= 31; i++)
+ for (long int i = 0; i <= 31; i++)
{
- if (info.DoesCPUSupportFeature(1 << i))
+ if (info.DoesCPUSupportFeature(static_cast<long int>(1) << i))
{
kwsys_ios::cout << "CPU feature " << i << "\n";
}
}
- //int GetProcessorCacheXSize(long int);
-// bool DoesCPUSupportFeature(long int);
+
+ /* test stack trace
+ */
+ kwsys_ios::cout
+ << "Program Stack:" << kwsys_ios::endl
+ << kwsys::SystemInformation::GetProgramStack(0,0) << kwsys_ios::endl
+ << kwsys_ios::endl;
+
+ /* test segv handler
+ info.SetStackTraceOnError(1);
+ double *d = (double*)100;
+ *d=0;
+ */
+
+ /* test abort handler
+ info.SetStackTraceOnError(1);
+ abort();
+ */
+
return 0;
}