Commit 49f8351a authored by Kitware Robot's avatar Kitware Robot Committed by Brad King
Browse files

KWSys 2019-05-15 (dea11658)

Code extracted from:

    https://gitlab.kitware.com/utils/kwsys.git

at commit dea11658266eaca24c017670b1b6c6e817afe5be (master).

Upstream Shortlog
-----------------

Fan Jinke (1):
      93352b24 SystemInformation: Add Hygon Dhyana Support

Ken Martin (1):
      43c6e2fd SystemInformation: Implement backtrace support on Windows
parent 0225b05a
...@@ -894,6 +894,11 @@ IF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS) ...@@ -894,6 +894,11 @@ IF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS)
IF(KWSYS_USE_SystemInformation) IF(KWSYS_USE_SystemInformation)
IF(WIN32) IF(WIN32)
TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} ws2_32) TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} ws2_32)
# link in dbghelp.dll for symbol lookup if MSVC 1800 or later
# Note that the dbghelp runtime is part of MS Windows OS
IF(MSVC_VERSION AND NOT MSVC_VERSION VERSION_LESS 1800)
TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} dbghelp)
ENDIF()
IF(KWSYS_SYS_HAS_PSAPI) IF(KWSYS_SYS_HAS_PSAPI)
TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY} TARGET_LINK_LIBRARIES(${KWSYS_TARGET_INTERFACE} ${KWSYS_LINK_DEPENDENCY}
Psapi) Psapi)
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ file Copyright.txt or https://cmake.org/licensing#kwsys for details. */
#if defined(_WIN32) #if defined(_WIN32)
# define NOMINMAX // use our min,max # define NOMINMAX // use our min,max
# if !defined(_WIN32_WINNT) && defined(_MSC_VER) && _MSC_VER >= 1800
# define _WIN32_WINNT 0x0600 // vista
# endif
# if !defined(_WIN32_WINNT) && !(defined(_MSC_VER) && _MSC_VER < 1300) # if !defined(_WIN32_WINNT) && !(defined(_MSC_VER) && _MSC_VER < 1300)
# define _WIN32_WINNT 0x0501 # define _WIN32_WINNT 0x0501
# endif # endif
...@@ -444,6 +447,7 @@ public: ...@@ -444,6 +447,7 @@ public:
IBM, IBM,
Motorola, Motorola,
HP, HP,
Hygon,
UnknownManufacturer UnknownManufacturer
}; };
...@@ -1766,6 +1770,8 @@ const char* SystemInformationImplementation::GetVendorID() ...@@ -1766,6 +1770,8 @@ const char* SystemInformationImplementation::GetVendorID()
return "Motorola"; return "Motorola";
case HP: case HP:
return "Hewlett-Packard"; return "Hewlett-Packard";
case Hygon:
return "Chengdu Haiguang IC Design Co., Ltd.";
case UnknownManufacturer: case UnknownManufacturer:
default: default:
return "Unknown Manufacturer"; return "Unknown Manufacturer";
...@@ -2117,6 +2123,8 @@ void SystemInformationImplementation::FindManufacturer( ...@@ -2117,6 +2123,8 @@ void SystemInformationImplementation::FindManufacturer(
this->ChipManufacturer = AMD; // Advanced Micro Devices this->ChipManufacturer = AMD; // Advanced Micro Devices
else if (this->ChipID.Vendor == "AMD ISBETTER") else if (this->ChipID.Vendor == "AMD ISBETTER")
this->ChipManufacturer = AMD; // Advanced Micro Devices (1994) this->ChipManufacturer = AMD; // Advanced Micro Devices (1994)
else if (this->ChipID.Vendor == "HygonGenuine")
this->ChipManufacturer = Hygon; // Chengdu Haiguang IC Design Co., Ltd.
else if (this->ChipID.Vendor == "CyrixInstead") else if (this->ChipID.Vendor == "CyrixInstead")
this->ChipManufacturer = Cyrix; // Cyrix Corp., VIA Inc. this->ChipManufacturer = Cyrix; // Cyrix Corp., VIA Inc.
else if (this->ChipID.Vendor == "NexGenDriven") else if (this->ChipID.Vendor == "NexGenDriven")
...@@ -2751,7 +2759,7 @@ bool SystemInformationImplementation::RetrieveExtendedCPUFeatures() ...@@ -2751,7 +2759,7 @@ bool SystemInformationImplementation::RetrieveExtendedCPUFeatures()
0); // MP Capable -- > Bit 19. 0); // MP Capable -- > Bit 19.
// Retrieve AMD specific extended features. // Retrieve AMD specific extended features.
if (this->ChipManufacturer == AMD) { if (this->ChipManufacturer == AMD || this->ChipManufacturer == Hygon) {
this->Features.ExtendedFeatures.HasMMXPlus = this->Features.ExtendedFeatures.HasMMXPlus =
((localCPUExtendedFeatures[3] & 0x00400000) != ((localCPUExtendedFeatures[3] & 0x00400000) !=
0); // AMD specific: MMX-SSE --> Bit 22 0); // AMD specific: MMX-SSE --> Bit 22
...@@ -3158,6 +3166,10 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() ...@@ -3158,6 +3166,10 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity()
} }
break; break;
case Hygon:
this->ChipID.ProcessorName = "Unknown Hygon family";
return false;
case Transmeta: case Transmeta:
switch (this->ChipID.Family) { switch (this->ChipID.Family) {
case 5: case 5:
...@@ -3879,6 +3891,20 @@ SystemInformation::LongLong SystemInformationImplementation::GetProcessId() ...@@ -3879,6 +3891,20 @@ SystemInformation::LongLong SystemInformationImplementation::GetProcessId()
#endif #endif
} }
/**
* Used in GetProgramStack(...) below
*/
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600 && defined(_MSC_VER) && \
_MSC_VER >= 1800
# define KWSYS_SYSTEMINFORMATION_HAS_DBGHELP
# define TRACE_MAX_STACK_FRAMES 1024
# define TRACE_MAX_FUNCTION_NAME_LENGTH 1024
# pragma warning(push)
# pragma warning(disable : 4091) /* 'typedef ': ignored on left of '' */
# include "dbghelp.h"
# pragma warning(pop)
#endif
/** /**
return current program stack in a string return current program stack in a string
demangle cxx symbols if possible. demangle cxx symbols if possible.
...@@ -3886,28 +3912,58 @@ demangle cxx symbols if possible. ...@@ -3886,28 +3912,58 @@ demangle cxx symbols if possible.
std::string SystemInformationImplementation::GetProgramStack(int firstFrame, std::string SystemInformationImplementation::GetProgramStack(int firstFrame,
int wholePath) int wholePath)
{ {
std::string programStack = "" std::ostringstream oss;
#if !defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE) std::string programStack = "";
"WARNING: The stack could not be examined "
"because backtrace is not supported.\n" #ifdef KWSYS_SYSTEMINFORMATION_HAS_DBGHELP
#elif !defined(KWSYS_SYSTEMINFORMATION_HAS_DEBUG_BUILD) (void)wholePath;
"WARNING: The stack trace will not use advanced "
"capabilities because this is a release build.\n" void* stack[TRACE_MAX_STACK_FRAMES];
HANDLE process = GetCurrentProcess();
SymInitialize(process, NULL, TRUE);
WORD numberOfFrames =
CaptureStackBackTrace(firstFrame, TRACE_MAX_STACK_FRAMES, stack, NULL);
SYMBOL_INFO* symbol = static_cast<SYMBOL_INFO*>(
malloc(sizeof(SYMBOL_INFO) +
(TRACE_MAX_FUNCTION_NAME_LENGTH - 1) * sizeof(TCHAR)));
symbol->MaxNameLen = TRACE_MAX_FUNCTION_NAME_LENGTH;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
DWORD displacement;
IMAGEHLP_LINE64 line;
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
for (int i = 0; i < numberOfFrames; i++) {
DWORD64 address = reinterpret_cast<DWORD64>(stack[i]);
SymFromAddr(process, address, NULL, symbol);
if (SymGetLineFromAddr64(process, address, &displacement, &line)) {
oss << " at " << symbol->Name << " in " << line.FileName << " line "
<< line.LineNumber << std::endl;
} else {
oss << " at " << symbol->Name << std::endl;
}
}
free(symbol);
#else #else
# if !defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP) programStack += ""
"WARNING: Function names will not be demangled " # if !defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
"because " "WARNING: The stack could not be examined "
"dladdr is not available.\n" "because backtrace is not supported.\n"
# endif # elif !defined(KWSYS_SYSTEMINFORMATION_HAS_DEBUG_BUILD)
# if !defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE) "WARNING: The stack trace will not use advanced "
"WARNING: Function names will not be demangled " "capabilities because this is a release build.\n"
"because cxxabi is not available.\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 # endif
#endif
; ;
std::ostringstream oss; # if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
#if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE)
void* stackSymbols[256]; void* stackSymbols[256];
int nFrames = backtrace(stackSymbols, 256); int nFrames = backtrace(stackSymbols, 256);
for (int i = firstFrame; i < nFrames; ++i) { for (int i = firstFrame; i < nFrames; ++i) {
...@@ -3916,10 +3972,12 @@ std::string SystemInformationImplementation::GetProgramStack(int firstFrame, ...@@ -3916,10 +3972,12 @@ std::string SystemInformationImplementation::GetProgramStack(int firstFrame,
symProps.Initialize(stackSymbols[i]); symProps.Initialize(stackSymbols[i]);
oss << symProps << std::endl; oss << symProps << std::endl;
} }
#else # else
(void)firstFrame; (void)firstFrame;
(void)wholePath; (void)wholePath;
# endif
#endif #endif
programStack += oss.str(); programStack += oss.str();
return programStack; return programStack;
......
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