diff options
author | Nyx (Neal Orman) <nyx@lindenlab.com> | 2011-02-09 14:01:36 -0500 |
---|---|---|
committer | Nyx (Neal Orman) <nyx@lindenlab.com> | 2011-02-09 14:01:36 -0500 |
commit | 9ef62ba2cecbed3db3eff74a294eb252f018399c (patch) | |
tree | b95f78b1ce2a22ceb473d16c221cf21b11825716 | |
parent | e3816f4577a74bba42ae9091461125ec9698b583 (diff) |
forgot to add runtimediagnostics.h. whoops.
-rw-r--r-- | indra/newview/CMakeLists.txt | 1 | ||||
-rw-r--r-- | indra/newview/runtimediagnostics.h | 256 |
2 files changed, 257 insertions, 0 deletions
diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt index 8ea0dd1089..ca408d032a 100644 --- a/indra/newview/CMakeLists.txt +++ b/indra/newview/CMakeLists.txt @@ -1136,6 +1136,7 @@ set(viewer_HEADER_FILES macmain.h noise.h pipeline.h + runtimediagnostics.h VertexCache.h VorbisFramework.h ) diff --git a/indra/newview/runtimediagnostics.h b/indra/newview/runtimediagnostics.h new file mode 100644 index 0000000000..b1c2662958 --- /dev/null +++ b/indra/newview/runtimediagnostics.h @@ -0,0 +1,256 @@ + once + + + +#include <atlbase.h> + + + +/* static*/ class RuntimeDiagnostics + +{ + +public: + + static void CheckPauseOnStartupOption( + + ) + + { + + DWORD dwPause; + + if (GetExecutionOption(TEXT("PauseOnStartup"), &dwPause) == S_OK && dwPause != 0) + + { + + while (true) + + { + + if (IsDebuggerPresent()) + + { + + __debugbreak(); + + break; + + } + + + + Sleep(1000); + + } + + } + + } + + + +private: + + static HRESULT GetExecutionOption( + + LPCTSTR szOptionName, + + DWORD *pValue + + ) + + { + + HRESULT hr; + + DWORD nChar; + + + + *pValue = 0; + + + + CRegKey rkeyExecutionOptions; + + hr = WIN32_ERROR_CALL( rkeyExecutionOptions.Open( + + HKEY_LOCAL_MACHINE, + + TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options"), + + KEY_READ + + ) ); + + + + if (hr == S_OK) + + { + + TCHAR szModPath[MAX_PATH + 1]; + + nChar = GetModuleFileName(NULL, szModPath, ARRAYSIZE(szModPath)); + + hr = WIN32_BOOL_CALL(nChar > 0 && nChar < ARRAYSIZE(szModPath)); + + + + if (hr == S_OK) + + { + + nChar = GetFileNameCharOffset(szModPath); + + + + if (nChar != MAXDWORD) + + { + + CRegKey rkeyExe; + + hr = WIN32_ERROR_CALL( rkeyExe.Open(rkeyExecutionOptions, szModPath + nChar, KEY_QUERY_VALUE) ); + + if (hr == S_OK) + + { + + hr = WIN32_ERROR_CALL( rkeyExe.QueryDWORDValue(szOptionName, *pValue) ); + + } + + } + + else + + { + + hr = E_FAIL; + + } + + } + + } + + + + return hr; + + } + + + + static DWORD GetFileNameCharOffset(LPCTSTR szPath) + + { + + if (!szPath) + + { + + return MAXDWORD; + + } + + + + // Find the last slash + + DWORD dwReturn = 0; + + for (DWORD c = 0; szPath[c] != 0; c++) + + { + + if (c >= INT_MAX) + + { + + return MAXDWORD; // string did not terminate + + } + + + + if (szPath[c] == '\\' || szPath[c] == '/' || (szPath[c] == ':' && c == 1)) + + { + + dwReturn = c + 1; + + } + + } + + + + // Make sure that the string doesn't end at the slash + + if (szPath[dwReturn] == 0) + + { + + dwReturn = MAXDWORD; + + } + + + + return dwReturn; + + } + + + + static inline HRESULT WIN32_ERROR(LONG lError) + + { + + return HRESULT_FROM_WIN32(lError); + + } + + + + static inline HRESULT WIN32_LAST_ERROR() + + { + + return WIN32_ERROR(GetLastError()); + + } + + + + static inline HRESULT WIN32_BOOL_CALL(BOOL rc) + + { + + if (!rc) + + return WIN32_LAST_ERROR(); + + return S_OK; + + } + + + + static inline HRESULT WIN32_ERROR_CALL(LONG lError) + + { + + if (lError != ERROR_SUCCESS) + + return WIN32_ERROR(lError); + + return S_OK; + + } + +}; + |