From b24a838301b44ac6e93fc39c6cb3833f4e0ed91e Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 19 Jun 2018 12:13:52 -0700 Subject: [PATCH] Cleanup debug logging (#932) --- build/launchSettings.json | 6 +- .../Properties/launchSettings.json | 6 +- .../AspNetCore/src/applicationinfo.cpp | 5 +- .../AspNetCore/src/dllmain.cpp | 27 +- .../CommonLib/CommonLib.vcxproj | 481 ++++++------ .../CommonLib/debugutil.cpp | 163 ++++ src/AspNetCoreModuleV2/CommonLib/debugutil.h | 85 +- src/AspNetCoreModuleV2/IISLib/IISLib.vcxproj | 1 - src/AspNetCoreModuleV2/IISLib/dbgutil.h | 6 +- src/AspNetCoreModuleV2/IISLib/pudebug.h | 736 ------------------ src/AspNetCoreModuleV2/IISLib/reftrace.c | 1 - src/AspNetCoreModuleV2/IISLib/tracelog.c | 1 - .../InProcessRequestHandler/dllmain.cxx | 31 +- .../inprocessapplication.cpp | 2 +- .../OutOfProcessRequestHandler/dllmain.cxx | 20 +- .../inprocess_application_tests.cpp | 1 - .../OutOfProcess/GlobalVersionTests.cs | 10 +- .../Utilities/FunctionalTestsBase.cs | 7 + .../Properties/launchSettings.json | 6 +- .../Properties/launchSettings.json | 6 +- .../Properties/launchSettings.json | 6 +- .../Properties/launchSettings.json | 6 +- .../Properties/launchSettings.json | 6 +- 23 files changed, 490 insertions(+), 1129 deletions(-) create mode 100644 src/AspNetCoreModuleV2/CommonLib/debugutil.cpp delete mode 100644 src/AspNetCoreModuleV2/IISLib/pudebug.h diff --git a/build/launchSettings.json b/build/launchSettings.json index aa0472a2dd..0ef9e81546 100644 --- a/build/launchSettings.json +++ b/build/launchSettings.json @@ -18,7 +18,8 @@ "ANCM_PATH": "$(TargetDir)$(AncmV2Path)", "LAUNCHER_ARGS": "$(TargetPath)", "ASPNETCORE_ENVIRONMENT": "Development", - "LAUNCHER_PATH": "$(DotNetPath)" + "LAUNCHER_PATH": "$(DotNetPath)", + "ASPNETCORE_MODULE_DEBUG": "4" } }, "ANCM IIS": { @@ -30,7 +31,8 @@ "ANCM_PATH": "$(TargetDir)$(AncmV2Path)", "LAUNCHER_ARGS": "$(TargetPath)", "ASPNETCORE_ENVIRONMENT": "Development", - "LAUNCHER_PATH": "$(DotNetPath)" + "LAUNCHER_PATH": "$(DotNetPath)", + "ASPNETCORE_MODULE_DEBUG": "4" } } } diff --git a/samples/NativeIISSample/Properties/launchSettings.json b/samples/NativeIISSample/Properties/launchSettings.json index aa0472a2dd..0ef9e81546 100644 --- a/samples/NativeIISSample/Properties/launchSettings.json +++ b/samples/NativeIISSample/Properties/launchSettings.json @@ -18,7 +18,8 @@ "ANCM_PATH": "$(TargetDir)$(AncmV2Path)", "LAUNCHER_ARGS": "$(TargetPath)", "ASPNETCORE_ENVIRONMENT": "Development", - "LAUNCHER_PATH": "$(DotNetPath)" + "LAUNCHER_PATH": "$(DotNetPath)", + "ASPNETCORE_MODULE_DEBUG": "4" } }, "ANCM IIS": { @@ -30,7 +31,8 @@ "ANCM_PATH": "$(TargetDir)$(AncmV2Path)", "LAUNCHER_ARGS": "$(TargetPath)", "ASPNETCORE_ENVIRONMENT": "Development", - "LAUNCHER_PATH": "$(DotNetPath)" + "LAUNCHER_PATH": "$(DotNetPath)", + "ASPNETCORE_MODULE_DEBUG": "4" } } } diff --git a/src/AspNetCoreModuleV2/AspNetCore/src/applicationinfo.cpp b/src/AspNetCoreModuleV2/AspNetCore/src/applicationinfo.cpp index 56fcc08f6f..032b61f43e 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/src/applicationinfo.cpp +++ b/src/AspNetCoreModuleV2/AspNetCore/src/applicationinfo.cpp @@ -6,6 +6,7 @@ #include "proxymodule.h" #include "hostfxr_utility.h" #include "utility.h" +#include "debugutil.h" const PCWSTR APPLICATION_INFO::s_pwzAspnetcoreInProcessRequestHandlerName = L"aspnetcorev2_inprocess.dll"; const PCWSTR APPLICATION_INFO::s_pwzAspnetcoreOutOfProcessRequestHandlerName = L"aspnetcorev2_outofprocess.dll"; @@ -332,6 +333,8 @@ APPLICATION_INFO::FindRequestHandlerAssembly(STRU& location) } } + WDebugPrintf(ASPNETCORE_DEBUG_FLAG_INFO, L"Loading request handler: %s", struFileName.QueryStr()); + g_hAspnetCoreRH = LoadLibraryW(struFileName.QueryStr()); if (g_hAspnetCoreRH == NULL) @@ -406,7 +409,7 @@ APPLICATION_INFO::FindNativeAssemblyFromGlobalLocation( ASPNETCORE_EVENT_OUT_OF_PROCESS_RH_MISSING, struEvent.QueryStr()); } - + hr = E_FAIL; } catch (...) diff --git a/src/AspNetCoreModuleV2/AspNetCore/src/dllmain.cpp b/src/AspNetCoreModuleV2/AspNetCore/src/dllmain.cpp index f7b9f8aa81..2b77015e36 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/src/dllmain.cpp +++ b/src/AspNetCoreModuleV2/AspNetCore/src/dllmain.cpp @@ -9,6 +9,9 @@ #include "globalmodule.h" #include "acache.h" #include "utility.h" +#include "debugutil.h" + +DECLARE_DEBUG_PRINT_OBJECT("aspnetcore.dll"); HTTP_MODULE_ID g_pModuleId = NULL; IHttpServer * g_pHttpServer = NULL; @@ -20,11 +23,8 @@ HMODULE g_hAspnetCoreRH = NULL; BOOL g_fAspnetcoreRHAssemblyLoaded = FALSE; BOOL g_fAspnetcoreRHLoadedError = FALSE; BOOL g_fInShutdown = FALSE; -DWORD g_dwAspNetCoreDebugFlags = 0; DWORD g_dwActiveServerProcesses = 0; SRWLOCK g_srwLock; -DWORD g_dwDebugFlags = 0; -PCSTR g_szDebugLabel = "ASPNET_CORE_MODULE"; PFN_ASPNETCORE_CREATE_APPLICATION g_pfnAspNetCoreCreateApplication; VOID @@ -100,13 +100,6 @@ HRESULT UNREFERENCED_PARAMETER(dwServerVersion); -#ifdef DEBUG - CREATE_DEBUG_PRINT_OBJECT("Asp.Net Core Module"); - g_dwDebugFlags = DEBUG_FLAGS_ANY; -#endif // DEBUG - - CREATE_DEBUG_PRINT_OBJECT; - //LoadGlobalConfiguration(); InitializeSRWLock(&g_srwLock); @@ -147,21 +140,11 @@ HRESULT fDisableANCM = (dwData != 0); } - cbData = sizeof(dwData); - if ((RegQueryValueEx(hKey, - L"DebugFlags", - NULL, - &dwType, - (LPBYTE)&dwData, - &cbData) == NO_ERROR) && - (dwType == REG_DWORD)) - { - g_dwAspNetCoreDebugFlags = dwData; - } - RegCloseKey(hKey); } + DebugInitialize(); + if (fDisableANCM) { // Logging diff --git a/src/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj b/src/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj index a8e8a60937..cf8f7a929d 100644 --- a/src/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj +++ b/src/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj @@ -1,241 +1,242 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {55494E58-E061-4C4C-A0A8-837008E72F85} - Win32Proj - NewCommon - 10.0.15063.0 - - - - StaticLibrary - true - v141 - Unicode - - - StaticLibrary - false - v141 - true - Unicode - - - StaticLibrary - true - v141 - Unicode - - - StaticLibrary - false - v141 - false - Unicode - - - - - - - - - - - - - - - - - - - - - true - - - true - - - false - - - false - C:\AspNetCoreModule\src\IISLib;$(IncludePath) - - - - NotUsing - Level4 - true - Disabled - false - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - $(IntDir)$(TargetName).pch - stdafx.h - true - MultiThreadedDebug - false - ProgramDatabase - ..\iislib; - true - stdcpp17 - - - Windows - true - - - - - NotUsing - Level4 - true - Disabled - false - _DEBUG;_LIB;%(PreprocessorDefinitions) - $(IntDir)$(TargetName).pch - stdafx.h - true - ProgramDatabase - false - MultiThreadedDebug - false - ..\iislib; - true - stdcpp17 - - - Windows - true - - - - - NotUsing - Level4 - true - MaxSpeed - true - true - false - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) - $(IntDir)$(TargetName).pch - stdafx.h - true - MultiThreaded - false - ..\iislib; - true - stdcpp17 - - - Windows - true - true - true - - - - - NotUsing - Level4 - true - MaxSpeed - true - true - false - NDEBUG;_LIB;%(PreprocessorDefinitions) - $(IntDir)$(TargetName).pch - stdafx.h - true - ..\iislib; - true - - - MultiThreaded - false - stdcpp17 - - - Windows - true - true - true - - - ..\iislib - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {4787a64f-9a3e-4867-a55a-70cb4b2b2ffe} - - - - - Document - mc %(FullPath) - Compiling Event Messages ... - %(Filename).rc;%(Filename).h;MSG0409.bin - mc %(FullPath) - Compiling Event Messages ... - %(Filename).rc;%(Filename).h;MSG0409.bin - mc %(FullPath) - Compiling Event Messages ... - %(Filename).rc;%(Filename).h;MSG0409.bin - mc %(FullPath) - Compiling Event Messages ... - %(Filename).rc;%(Filename).h;MSG0409.bin - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {55494E58-E061-4C4C-A0A8-837008E72F85} + Win32Proj + NewCommon + 10.0.15063.0 + + + + StaticLibrary + true + v141 + Unicode + + + StaticLibrary + false + v141 + true + Unicode + + + StaticLibrary + true + v141 + Unicode + + + StaticLibrary + false + v141 + false + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + C:\AspNetCoreModule\src\IISLib;$(IncludePath) + + + + NotUsing + Level4 + true + Disabled + false + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + $(IntDir)$(TargetName).pch + stdafx.h + true + MultiThreadedDebug + false + ProgramDatabase + ..\iislib; + true + stdcpp17 + + + Windows + true + + + + + NotUsing + Level4 + true + Disabled + false + _DEBUG;_LIB;%(PreprocessorDefinitions) + $(IntDir)$(TargetName).pch + stdafx.h + true + ProgramDatabase + false + MultiThreadedDebug + false + ..\iislib; + true + stdcpp17 + + + Windows + true + + + + + NotUsing + Level4 + true + MaxSpeed + true + true + false + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + $(IntDir)$(TargetName).pch + stdafx.h + true + MultiThreaded + false + ..\iislib; + true + stdcpp17 + + + Windows + true + true + true + + + + + NotUsing + Level4 + true + MaxSpeed + true + true + false + NDEBUG;_LIB;%(PreprocessorDefinitions) + $(IntDir)$(TargetName).pch + stdafx.h + true + ..\iislib; + true + + + MultiThreaded + false + stdcpp17 + + + Windows + true + true + true + + + ..\iislib + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {4787a64f-9a3e-4867-a55a-70cb4b2b2ffe} + + + + + Document + mc %(FullPath) + Compiling Event Messages ... + %(Filename).rc;%(Filename).h;MSG0409.bin + mc %(FullPath) + Compiling Event Messages ... + %(Filename).rc;%(Filename).h;MSG0409.bin + mc %(FullPath) + Compiling Event Messages ... + %(Filename).rc;%(Filename).h;MSG0409.bin + mc %(FullPath) + Compiling Event Messages ... + %(Filename).rc;%(Filename).h;MSG0409.bin + + + + + \ No newline at end of file diff --git a/src/AspNetCoreModuleV2/CommonLib/debugutil.cpp b/src/AspNetCoreModuleV2/CommonLib/debugutil.cpp new file mode 100644 index 0000000000..023d578387 --- /dev/null +++ b/src/AspNetCoreModuleV2/CommonLib/debugutil.cpp @@ -0,0 +1,163 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +#include "debugutil.h" +#include "dbgutil.h" + +inline HANDLE g_hStandardOutput; + +VOID +DebugInitialize() +{ + g_hStandardOutput = GetStdHandle(STD_OUTPUT_HANDLE); + + HKEY hKey; + + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, + L"SOFTWARE\\Microsoft\\IIS Extensions\\IIS AspNetCore Module\\Parameters", + 0, + KEY_READ, + &hKey) == NO_ERROR) + { + DWORD dwType; + DWORD dwData; + DWORD cbData; + + cbData = sizeof(dwData); + if ((RegQueryValueEx(hKey, + L"DebugFlags", + NULL, + &dwType, + (LPBYTE)&dwData, + &cbData) == NO_ERROR) && + (dwType == REG_DWORD)) + { + DEBUG_FLAGS_VAR = dwData; + } + + RegCloseKey(hKey); + } + + // We expect single digit value and a null char + const size_t environmentVariableValueSize = 2; + std::wstring environmentVariableValue(environmentVariableValueSize, '\0'); + + if (GetEnvironmentVariable(L"ASPNETCORE_MODULE_DEBUG", environmentVariableValue.data(), environmentVariableValueSize) == environmentVariableValueSize - 1) + { + try + { + const auto value = std::stoi(environmentVariableValue); + + if (value >= 1) DEBUG_FLAGS_VAR |= ASPNETCORE_DEBUG_FLAG_ERROR; + if (value >= 2) DEBUG_FLAGS_VAR |= ASPNETCORE_DEBUG_FLAG_WARNING; + if (value >= 3) DEBUG_FLAGS_VAR |= ASPNETCORE_DEBUG_FLAG_INFO; + if (value >= 4) DEBUG_FLAGS_VAR |= ASPNETCORE_DEBUG_FLAG_CONSOLE; + } + catch (...) + { + // ignore + } + } +} + +BOOL +IsEnabled( + DWORD dwFlag + ) +{ + return ( dwFlag & DEBUG_FLAGS_VAR ); +} + +VOID +DebugPrint( + DWORD dwFlag, + const LPCSTR szString + ) +{ + STACK_STRA (strOutput, 256); + HRESULT hr = S_OK; + + if ( IsEnabled( dwFlag ) ) + { + hr = strOutput.SafeSnprintf( + "[%s] %s\r\n", + DEBUG_LABEL_VAR, szString ); + + if (FAILED (hr)) + { + return; + } + + OutputDebugStringA( strOutput.QueryStr() ); + + if (IsEnabled(ASPNETCORE_DEBUG_FLAG_CONSOLE)) + { + DWORD nBytesWritten = 0; + WriteFile(g_hStandardOutput, strOutput.QueryStr(), strOutput.QueryCB(), &nBytesWritten, NULL); + } + } +} + +VOID +DebugPrintf( + DWORD dwFlag, + const LPCSTR szFormat, + ... + ) +{ + STACK_STRA (strCooked,256); + + va_list args; + HRESULT hr = S_OK; + + if ( IsEnabled( dwFlag ) ) + { + va_start( args, szFormat ); + + hr = strCooked.SafeVsnprintf(szFormat, args ); + + va_end( args ); + + if (FAILED (hr)) + { + return; + } + + DebugPrint( dwFlag, strCooked.QueryStr() ); + } +} + +VOID +WDebugPrintf( + DWORD dwFlag, + LPWSTR szFormat, + ... + ) +{ + va_list args; + HRESULT hr = S_OK; + + if ( IsEnabled( dwFlag ) ) + { + STACK_STRU (formatted,256); + + va_start( args, szFormat ); + + hr = formatted.SafeVsnwprintf(szFormat, args ); + + va_end( args ); + + if (FAILED (hr)) + { + return; + } + + STACK_STRA (converted, 256); + if (FAILED ( converted.CopyW(formatted.QueryStr(), formatted.QueryCCH()) )) + { + return; + } + + DebugPrint( dwFlag, converted.QueryStr() ); + } +} diff --git a/src/AspNetCoreModuleV2/CommonLib/debugutil.h b/src/AspNetCoreModuleV2/CommonLib/debugutil.h index 16fce88edd..d2340d6214 100644 --- a/src/AspNetCoreModuleV2/CommonLib/debugutil.h +++ b/src/AspNetCoreModuleV2/CommonLib/debugutil.h @@ -2,80 +2,37 @@ // Licensed under the MIT License. See License.txt in the project root for license information. #pragma once -#define ASPNETCORE_DEBUG_FLAG_INFO 0x00000001 -#define ASPNETCORE_DEBUG_FLAG_WARNING 0x00000002 -#define ASPNETCORE_DEBUG_FLAG_ERROR 0x00000004 +#include "stdafx.h" -extern DWORD g_dwAspNetCoreDebugFlags; +#define ASPNETCORE_DEBUG_FLAG_INFO DEBUG_FLAG_INFO +#define ASPNETCORE_DEBUG_FLAG_WARNING DEBUG_FLAG_WARN +#define ASPNETCORE_DEBUG_FLAG_ERROR DEBUG_FLAG_ERROR +#define ASPNETCORE_DEBUG_FLAG_CONSOLE 0x00000008 + +VOID +DebugInitialize(); -static BOOL -IfDebug( +IsEnabled( DWORD dwFlag - ) -{ - return ( dwFlag & g_dwAspNetCoreDebugFlags ); -} + ); -static VOID DebugPrint( DWORD dwFlag, LPCSTR szString - ) -{ - STACK_STRA (strOutput, 256); - HRESULT hr = S_OK; + ); - if ( IfDebug( dwFlag ) ) - { - hr = strOutput.SafeSnprintf( - "[aspnetcore.dll] %s\r\n", - szString ); - - if (FAILED (hr)) - { - goto Finished; - } - - OutputDebugStringA( strOutput.QueryStr() ); - } - -Finished: - - return; -} - -static VOID DebugPrintf( -DWORD dwFlag, -LPCSTR szFormat, -... -) -{ - STACK_STRA (strCooked,256); - - va_list args; - HRESULT hr = S_OK; - - if ( IfDebug( dwFlag ) ) - { - va_start( args, szFormat ); - - hr = strCooked.SafeVsnprintf(szFormat, args ); - - va_end( args ); - - if (FAILED (hr)) - { - goto Finished; - } - - DebugPrint( dwFlag, strCooked.QueryStr() ); - } - -Finished: - return; -} + DWORD dwFlag, + LPCSTR szFormat, + ... + ); +VOID +WDebugPrintf( + DWORD dwFlag, + LPWSTR szFormat, + ... + ); diff --git a/src/AspNetCoreModuleV2/IISLib/IISLib.vcxproj b/src/AspNetCoreModuleV2/IISLib/IISLib.vcxproj index a13fc774fd..6d947fcb58 100644 --- a/src/AspNetCoreModuleV2/IISLib/IISLib.vcxproj +++ b/src/AspNetCoreModuleV2/IISLib/IISLib.vcxproj @@ -179,7 +179,6 @@ - diff --git a/src/AspNetCoreModuleV2/IISLib/dbgutil.h b/src/AspNetCoreModuleV2/IISLib/dbgutil.h index 45c26777a9..bf745bfcd9 100644 --- a/src/AspNetCoreModuleV2/IISLib/dbgutil.h +++ b/src/AspNetCoreModuleV2/IISLib/dbgutil.h @@ -7,11 +7,11 @@ #include // -// TODO +// TODO // Using _CrtDbg implementation. If hooking is desired // wrappers should be provided here so that we can reimplement // if neecessary. -// +// // IF_DEBUG/DEBUG FLAGS // // registry configuration @@ -56,7 +56,7 @@ extern DWORD DEBUG_FLAGS_VAR; #define DECLARE_DEBUG_PRINT_OBJECT( _pszLabel_ ) \ PCSTR DEBUG_LABEL_VAR = _pszLabel_; \ - DWORD DEBUG_FLAGS_VAR = DEBUG_FLAGS_ANY; \ + DWORD DEBUG_FLAGS_VAR = DEBUG_FLAGS_WARN; \ #define DECLARE_DEBUG_PRINT_OBJECT2( _pszLabel_, _dwLevel_ ) \ PCSTR DEBUG_LABEL_VAR = _pszLabel_; \ diff --git a/src/AspNetCoreModuleV2/IISLib/pudebug.h b/src/AspNetCoreModuleV2/IISLib/pudebug.h deleted file mode 100644 index 7b0e35da0f..0000000000 --- a/src/AspNetCoreModuleV2/IISLib/pudebug.h +++ /dev/null @@ -1,736 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -# ifndef _PUDEBUG_H_ -# define _PUDEBUG_H_ - -#ifndef _NO_TRACING_ -# define _NO_TRACING_ -#endif // _NO_TRACING_ - -/************************************************************ - * Include Headers - ************************************************************/ - -# ifdef __cplusplus -extern "C" { -# endif // __cplusplus - -# include - -# ifndef dllexp -# define dllexp __declspec( dllexport) -# endif // dllexp - -#include - -#ifndef IN_OUT -#define IN_OUT __inout -#endif - -/*********************************************************** - * Macros - ************************************************************/ - -enum PRINT_REASONS { - PrintNone = 0x0, // Nothing to be printed - PrintError = 0x1, // An error message - PrintWarning = 0x2, // A warning message - PrintLog = 0x3, // Just logging. Indicates a trace of where ... - PrintMsg = 0x4, // Echo input message - PrintCritical = 0x5, // Print and Exit - PrintAssertion= 0x6 // Printing for an assertion failure - }; - - -enum DEBUG_OUTPUT_FLAGS { - DbgOutputNone = 0x0, // None - DbgOutputKdb = 0x1, // Output to Kernel Debugger - DbgOutputLogFile = 0x2, // Output to LogFile - DbgOutputTruncate = 0x4, // Truncate Log File if necessary - DbgOutputStderr = 0x8, // Send output to std error - DbgOutputBackup = 0x10, // Make backup of debug file ? - DbgOutputMemory = 0x20, // Dump to memory buffer - DbgOutputAll = 0xFFFFFFFF // All the bits set. - }; - - -# define MAX_LABEL_LENGTH ( 100) - - -// The following flags are used internally to track what level of tracing we -// are currently using. Bitmapped for extensibility. -#define DEBUG_FLAG_ODS 0x00000001 -//#define DEBUG_FLAG_INFO 0x00000002 -//#define DEBUG_FLAG_WARN 0x00000004 -//#define DEBUG_FLAG_ERROR 0x00000008 -// The following are used internally to determine whether to log or not based -// on what the current state is -//#define DEBUG_FLAGS_INFO (DEBUG_FLAG_ODS | DEBUG_FLAG_INFO) -//#define DEBUG_FLAGS_WARN (DEBUG_FLAG_ODS | DEBUG_FLAG_INFO | DEBUG_FLAG_WARN) -//#define DEBUG_FLAGS_ERROR (DEBUG_FLAG_ODS | DEBUG_FLAG_INFO | DEBUG_FLAG_WARN | DEBUG_FLAG_ERROR) - -#define DEBUG_FLAGS_ANY (DEBUG_FLAG_INFO | DEBUG_FLAG_WARN | DEBUG_FLAG_ERROR) - -// -// user of DEBUG infrastructure may choose unique variable name for DEBUG_FLAGS -// that's specially useful for cases where DEBUG infrastructure is used within -// static library (static library may prefer to maintain it's own DebugFlags independent -// on the main program it links to -// -#ifndef DEBUG_FLAGS_VAR -#define DEBUG_FLAGS_VAR g_dwDebugFlags -#endif - -extern -#ifdef __cplusplus -"C" -# endif // _cplusplus - DWORD DEBUG_FLAGS_VAR ; // Debugging Flags - -# define DECLARE_DEBUG_VARIABLE() - -# define SET_DEBUG_FLAGS( dwFlags) DEBUG_FLAGS_VAR = dwFlags -# define GET_DEBUG_FLAGS() ( DEBUG_FLAGS_VAR ) - -# define LOAD_DEBUG_FLAGS_FROM_REG(hkey, dwDefault) \ - DEBUG_FLAGS_VAR = PuLoadDebugFlagsFromReg((hkey), (dwDefault)) - -# define LOAD_DEBUG_FLAGS_FROM_REG_STR(pszRegKey, dwDefault) \ - DEBUG_FLAGS_VAR = PuLoadDebugFlagsFromRegStr((pszRegKey), (dwDefault)) - -# define SAVE_DEBUG_FLAGS_IN_REG(hkey, dwDbg) \ - PuSaveDebugFlagsInReg((hkey), (dwDbg)) - -# define DEBUG_IF( arg, s) if ( DEBUG_ ## arg & GET_DEBUG_FLAGS()) { \ - s \ - } else {} - -# define IF_DEBUG( arg) if ( DEBUG_## arg & GET_DEBUG_FLAGS()) - - -/*++ - class DEBUG_PRINTS - - This class is responsible for printing messages to log file / kernel debugger - - Currently the class supports only member functions for char. - ( not unicode-strings). - ---*/ - - -typedef struct _DEBUG_PRINTS { - - CHAR m_rgchLabel[MAX_LABEL_LENGTH]; - CHAR m_rgchLogFilePath[MAX_PATH]; - CHAR m_rgchLogFileName[MAX_PATH]; - HANDLE m_LogFileHandle; - HANDLE m_StdErrHandle; - BOOL m_fInitialized; - BOOL m_fBreakOnAssert; - DWORD m_dwOutputFlags; - VOID *m_pMemoryLog; -} DEBUG_PRINTS, FAR * LPDEBUG_PRINTS; - - -LPDEBUG_PRINTS -PuCreateDebugPrintsObject( - IN const char * pszPrintLabel, - IN DWORD dwOutputFlags); - -// -// frees the debug prints object and closes any file if necessary. -// Returns NULL on success or returns pDebugPrints on failure. -// -LPDEBUG_PRINTS -PuDeleteDebugPrintsObject( - IN_OUT LPDEBUG_PRINTS pDebugPrints); - - -VOID -PuDbgPrint( - IN_OUT LPDEBUG_PRINTS pDebugPrints, - IN const char * pszFilePath, - IN int nLineNum, - IN const char * pszFunctionName, - IN const char * pszFormat, - ...); - // arglist -VOID -PuDbgPrintW( - IN_OUT LPDEBUG_PRINTS pDebugPrints, - IN const char * pszFilePath, - IN int nLineNum, - IN const char * pszFunctionName, - IN const WCHAR * pszFormat, - ...); // arglist - -// PuDbgPrintError is similar to PuDbgPrint() but allows -// one to print error code in friendly manner -VOID -PuDbgPrintError( - IN_OUT LPDEBUG_PRINTS pDebugPrints, - IN const char * pszFilePath, - IN int nLineNum, - IN const char * pszFunctionName, - IN DWORD dwError, - IN const char * pszFormat, - ...); // arglist - -/*++ - PuDbgDump() does not do any formatting of output. - It just dumps the given message onto the debug destinations. ---*/ -VOID -PuDbgDump( - IN_OUT LPDEBUG_PRINTS pDebugPrints, - IN const char * pszFilePath, - IN int nLineNum, - IN const char * pszFunctionName, - IN const char * pszDump - ); - -// -// PuDbgAssertFailed() *must* be __cdecl to properly capture the -// thread context at the time of the failure. -// - -INT -__cdecl -PuDbgAssertFailed( - IN_OUT LPDEBUG_PRINTS pDebugPrints, - IN const char * pszFilePath, - IN int nLineNum, - IN const char * pszFunctionName, - IN const char * pszExpression, - IN const char * pszMessage); - -INT -WINAPI -PuDbgPrintAssertFailed( - IN_OUT LPDEBUG_PRINTS pDebugPrints, - IN const char * pszFilePath, - IN int nLineNum, - IN const char * pszFunctionName, - IN const char * pszExpression, - IN const char * pszMessage); - -VOID -PuDbgCaptureContext ( - OUT PCONTEXT ContextRecord - ); - -VOID -PuDbgPrintCurrentTime( - IN_OUT LPDEBUG_PRINTS pDebugPrints, - IN const char * pszFilePath, - IN int nLineNum, - IN const char * pszFunctionName - ); - -VOID -PuSetDbgOutputFlags( - IN_OUT LPDEBUG_PRINTS pDebugPrints, - IN DWORD dwFlags); - -DWORD -PuGetDbgOutputFlags( - IN const LPDEBUG_PRINTS pDebugPrints); - - -// -// Following functions return Win32 error codes. -// NO_ERROR if success -// - -DWORD -PuOpenDbgPrintFile( - IN_OUT LPDEBUG_PRINTS pDebugPrints, - IN const char * pszFileName, - IN const char * pszPathForFile); - -DWORD -PuReOpenDbgPrintFile( - IN_OUT LPDEBUG_PRINTS pDebugPrints); - -DWORD -PuCloseDbgPrintFile( - IN_OUT LPDEBUG_PRINTS pDebugPrints); - -DWORD -PuOpenDbgMemoryLog( - IN_OUT LPDEBUG_PRINTS pDebugPrints); - -DWORD -PuCloseDbgMemoryLog( - IN_OUT LPDEBUG_PRINTS pDebugPrints); - -DWORD -PuLoadDebugFlagsFromReg(IN HKEY hkey, IN DWORD dwDefault); - -DWORD -PuLoadDebugFlagsFromRegStr(IN LPCSTR pszRegKey, IN DWORD dwDefault); - -DWORD -PuSaveDebugFlagsInReg(IN HKEY hkey, IN DWORD dwDbg); - - -# define PuPrintToKdb( pszOutput) \ - if ( pszOutput != NULL) { \ - OutputDebugString( pszOutput); \ - } else {} - - - -# ifdef __cplusplus -}; -# endif // __cplusplus - -// begin_user_unmodifiable - - - -/*********************************************************** - * Macros - ************************************************************/ - - -extern -#ifdef __cplusplus -"C" -# endif // _cplusplus -DEBUG_PRINTS * g_pDebug; // define a global debug variable - -# if DBG - -// For the CHK build we want ODS enabled. For an explanation of these flags see -// the comment just after the definition of DBG_CONTEXT -# define DECLARE_DEBUG_PRINTS_OBJECT() \ - DEBUG_PRINTS * g_pDebug = NULL; \ - DWORD DEBUG_FLAGS_VAR = DEBUG_FLAG_ERROR; - -#else // !DBG - -# define DECLARE_DEBUG_PRINTS_OBJECT() \ - DEBUG_PRINTS * g_pDebug = NULL; \ - DWORD DEBUG_FLAGS_VAR = 0; - -#endif // !DBG - - -// -// Call the following macro as part of your initialization for program -// planning to use the debugging class. -// -/** DEBUGDEBUG -# define CREATE_DEBUG_PRINT_OBJECT( pszLabel) \ - g_pDebug = PuCreateDebugPrintsObject( pszLabel, DEFAULT_OUTPUT_FLAGS);\ - if ( g_pDebug == NULL) { \ - OutputDebugStringA( "Unable to Create Debug Print Object \n"); \ - } -*/ - -// -// Call the following macro once as part of the termination of program -// which uses the debugging class. -// -# define DELETE_DEBUG_PRINT_OBJECT( ) \ - g_pDebug = PuDeleteDebugPrintsObject( g_pDebug); - - -# define VALID_DEBUG_PRINT_OBJECT() \ - ( ( g_pDebug != NULL) && g_pDebug->m_fInitialized) - - -// -// Use the DBG_CONTEXT without any surrounding braces. -// This is used to pass the values for global DebugPrintObject -// and File/Line information -// -//# define DBG_CONTEXT g_pDebug, __FILE__, __LINE__, __FUNCTION__ - -// The 3 main tracing macros, each one corresponds to a different level of -// tracing - -// The 3 main tracing macros, each one corresponds to a different level of -// tracing -//# define DBGINFO(args) {if (DEBUG_FLAGS_VAR & DEBUG_FLAGS_INFO) { PuDbgPrint args; }} -//# define DBGWARN(args) {if (DEBUG_FLAGS_VAR & DEBUG_FLAGS_WARN) { PuDbgPrint args; }} -//# define DBGERROR(args) {if (DEBUG_FLAGS_VAR & DEBUG_FLAGS_ERROR) { PuDbgPrint args; }} - -# define DBGINFOW(args) {if (DEBUG_FLAGS_VAR & DEBUG_FLAGS_INFO) { PuDbgPrintW args; }} -# define DBGWARNW(args) {if (DEBUG_FLAGS_VAR & DEBUG_FLAGS_WARN) { PuDbgPrintW args; }} -# define DBGERRORW(args) {if (DEBUG_FLAGS_VAR & DEBUG_FLAGS_ERROR) { PuDbgPrintW args; }} - - -// -// DBGPRINTF() is printing function ( much like printf) but always called -// with the DBG_CONTEXT as follows -// DBGPRINTF( ( DBG_CONTEXT, format-string, arguments for format list)); -// -# define DBGPRINTF DBGINFO - -// -// DPERROR() is printing function ( much like printf) but always called -// with the DBG_CONTEXT as follows -// DPERROR( ( DBG_CONTEXT, error, format-string, -// arguments for format list)); -// -# define DPERROR( args) {if (DEBUG_FLAGS_VAR & DEBUG_FLAGS_ERROR) { PuDbgPrintError args; }} - -# if DBG - -# define DBG_CODE(s) s /* echoes code in debugging mode */ - -// The same 3 main tracing macros however in this case the macros are only compiled -// into the CHK build. This is necessary because some tracing info used functions or -// variables which are not compiled into the FRE build. -# define CHKINFO(args) { PuDbgPrint args; } -# define CHKWARN(args) { PuDbgPrint args; } -# define CHKERROR(args) { PuDbgPrint args; } - -# define CHKINFOW(args) { PuDbgPrintW args; } -# define CHKWARNW(args) { PuDbgPrintW args; } -# define CHKERRORW(args) { PuDbgPrintW args; } - - -#ifndef DBG_ASSERT -# ifdef _PREFAST_ -# define DBG_ASSERT(exp) ((void)0) /* Do Nothing */ -# define DBG_ASSERT_MSG(exp, pszMsg) ((void)0) /* Do Nothing */ -# define DBG_REQUIRE( exp) ((void) (exp)) -# else // !_PREFAST_ -# define DBG_ASSERT( exp ) \ - ( (VOID)( ( exp ) || ( DebugBreak(), \ - PuDbgPrintAssertFailed( DBG_CONTEXT, #exp, "" ) ) ) ) - -# define DBG_ASSERT_MSG( exp, pszMsg) \ - ( (VOID)( ( exp ) || ( DebugBreak(), \ - PuDbgPrintAssertFailed( DBG_CONTEXT, #exp, pszMsg ) ) ) ) - -# define DBG_REQUIRE( exp ) \ - DBG_ASSERT( exp ) -# endif // !_PREFAST_ -#endif - - -# define DBG_LOG() PuDbgPrint( DBG_CONTEXT, "\n" ) - -# define DBG_OPEN_LOG_FILE( pszFile, pszPath ) \ - PuOpenDbgPrintFile( g_pDebug, (pszFile), (pszPath) ) - -# define DBG_CLOSE_LOG_FILE( ) \ - PuCloseDbgPrintFile( g_pDebug ) - -# define DBG_OPEN_MEMORY_LOG( ) \ - PuOpenDbgMemoryLog( g_pDebug ) - - -# define DBGDUMP( args ) PuDbgDump args - -# define DBGPRINT_CURRENT_TIME() PuDbgPrintCurrentTime( DBG_CONTEXT ) - -# else // !DBG - -# define DBG_CODE(s) ((void)0) /* Do Nothing */ - -# define CHKINFO(args) ((void)0) /* Do Nothing */ -# define CHKWARN(args) ((void)0) /* Do Nothing */ -# define CHKERROR(args) ((void)0) /* Do Nothing */ - -# define CHKINFOW(args) ((void)0) /* Do Nothing */ -# define CHKWARNW(args) ((void)0) /* Do Nothing */ -# define CHKERRORW(args) ((void)0) /* Do Nothing */ - -#ifndef DBG_ASSERT -# define DBG_ASSERT(exp) ((void)0) /* Do Nothing */ - -# define DBG_ASSERT_MSG(exp, pszMsg) ((void)0) /* Do Nothing */ - -# define DBG_REQUIRE( exp) ((void) (exp)) -#endif // !DBG_ASSERT - -# define DBGDUMP( args) ((void)0) /* Do nothing */ - -# define DBG_LOG() ((void)0) /* Do Nothing */ - -# define DBG_OPEN_LOG_FILE( pszFile, pszPath) ((void)0) /* Do Nothing */ - -# define DBG_OPEN_MEMORY_LOG() ((void)0) /* Do Nothing */ - -# define DBG_CLOSE_LOG_FILE() ((void)0) /* Do Nothing */ - -# define DBGPRINT_CURRENT_TIME() ((void)0) /* Do Nothing */ - -# endif // !DBG - - -// end_user_unmodifiable - -// begin_user_unmodifiable - - -#ifdef ASSERT -# undef ASSERT -#endif - - -# define ASSERT( exp) DBG_ASSERT( exp) - - -// end_user_unmodifiable - -// begin_user_modifiable - -// -// Debugging constants consist of two pieces. -// All constants in the range 0x0 to 0x8000 are reserved -// User extensions may include additional constants (bit flags) -// - -# define DEBUG_API_ENTRY 0x00000001L -# define DEBUG_API_EXIT 0x00000002L -# define DEBUG_INIT_CLEAN 0x00000004L -# define DEBUG_ERROR 0x00000008L - - // End of Reserved Range -# define DEBUG_RESERVED 0x00000FFFL - -// end_user_modifiable - - - -/*********************************************************** - * Platform Type related variables and macros - ************************************************************/ - -// -// Enum for product types -// - -typedef enum _PLATFORM_TYPE { - - PtInvalid = 0, // Invalid - PtNtWorkstation = 1, // NT Workstation - PtNtServer = 2, // NT Server - -} PLATFORM_TYPE; - -// -// IISGetPlatformType is the function used to the platform type -// - -extern -#ifdef __cplusplus -"C" -# endif // _cplusplus -PLATFORM_TYPE -IISGetPlatformType( - VOID - ); - -// -// External Macros -// - -#define InetIsNtServer( _pt ) ((_pt) == PtNtServer) -#define InetIsNtWksta( _pt ) ((_pt) == PtNtWorkstation) -#define InetIsValidPT(_pt) ((_pt) != PtInvalid) - -extern -#ifdef __cplusplus -"C" -# endif // _cplusplus -PLATFORM_TYPE g_PlatformType; - - -// Use the DECLARE_PLATFORM_TYPE macro to declare the platform type -#define DECLARE_PLATFORM_TYPE() \ - PLATFORM_TYPE g_PlatformType = PtInvalid; - -// Use the INITIALIZE_PLATFORM_TYPE to init the platform type -// This should typically go inside the DLLInit or equivalent place. -#define INITIALIZE_PLATFORM_TYPE() \ - g_PlatformType = IISGetPlatformType(); - -// -// Additional Macros to use the Platform Type -// - -#define TsIsNtServer( ) InetIsNtServer(g_PlatformType) -#define TsIsNtWksta( ) InetIsNtWksta(g_PlatformType) -#define IISIsValidPlatform() InetIsValidPT(g_PlatformType) -#define IISPlatformType() (g_PlatformType) - - -/*********************************************************** - * Some utility functions for Critical Sections - ************************************************************/ - -// -// IISSetCriticalSectionSpinCount() provides a thunk for the -// original NT4.0sp3 API SetCriticalSectionSpinCount() for CS with Spin counts -// Users of this function should definitely dynlink with kernel32.dll, -// Otherwise errors will surface to a large extent -// -extern -# ifdef __cplusplus -"C" -# endif // _cplusplus -DWORD -IISSetCriticalSectionSpinCount( - LPCRITICAL_SECTION lpCriticalSection, - DWORD dwSpinCount -); - - -// -// Macro for the calls to SetCriticalSectionSpinCount() -// -# define SET_CRITICAL_SECTION_SPIN_COUNT( lpCS, dwSpins) \ - IISSetCriticalSectionSpinCount( (lpCS), (dwSpins)) - -// -// IIS_DEFAULT_CS_SPIN_COUNT is the default value of spins used by -// Critical sections defined within IIS. -// NYI: We should have to switch the individual values based on experiments! -// Current value is an arbitrary choice -// -# define IIS_DEFAULT_CS_SPIN_COUNT (1000) - -// -// Initializes a critical section and sets its spin count -// to IIS_DEFAULT_CS_SPIN_COUNT. Equivalent to -// InitializeCriticalSectionAndSpinCount(lpCS, IIS_DEFAULT_CS_SPIN_COUNT), -// but provides a safe thunking layer for older systems that don't provide -// this API. -// -extern -# ifdef __cplusplus -"C" -# endif // _cplusplus -BOOL -IISInitializeCriticalSection( - LPCRITICAL_SECTION lpCriticalSection -); - -// -// Macro for the calls to InitializeCriticalSection() -// -# define INITIALIZE_CRITICAL_SECTION(lpCS) IISInitializeCriticalSection(lpCS) - -# endif /* _DEBUG_HXX_ */ - -// -// The following macros allow the automatic naming of certain Win32 objects. -// See IIS\SVCS\IISRTL\WIN32OBJ.C for details on the naming convention. -// -// Set IIS_NAMED_WIN32_OBJECTS to a non-zero value to enable named events, -// semaphores, and mutexes. -// - -#if DBG -#define IIS_NAMED_WIN32_OBJECTS 1 -#else -#define IIS_NAMED_WIN32_OBJECTS 0 -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -HANDLE -PuDbgCreateEvent( - __in LPSTR FileName, - IN ULONG LineNumber, - __in LPSTR MemberName, - IN PVOID Address, - IN BOOL ManualReset, - IN BOOL InitialState - ); - -HANDLE -PuDbgCreateSemaphore( - __in LPSTR FileName, - IN ULONG LineNumber, - __in LPSTR MemberName, - IN PVOID Address, - IN LONG InitialCount, - IN LONG MaximumCount - ); - -HANDLE -PuDbgCreateMutex( - __in LPSTR FileName, - IN ULONG LineNumber, - __in LPSTR MemberName, - IN PVOID Address, - IN BOOL InitialOwner - ); - -#ifdef __cplusplus -} // extern "C" -#endif - -#if IIS_NAMED_WIN32_OBJECTS - -#define IIS_CREATE_EVENT( membername, address, manual, state ) \ - PuDbgCreateEvent( \ - (LPSTR)__FILE__, \ - (ULONG)__LINE__, \ - (membername), \ - (PVOID)(address), \ - (manual), \ - (state) \ - ) - -#define IIS_CREATE_SEMAPHORE( membername, address, initial, maximum ) \ - PuDbgCreateSemaphore( \ - (LPSTR)__FILE__, \ - (ULONG)__LINE__, \ - (membername), \ - (PVOID)(address), \ - (initial), \ - (maximum) \ - ) - -#define IIS_CREATE_MUTEX( membername, address, initial ) \ - PuDbgCreateMutex( \ - (LPSTR)__FILE__, \ - (ULONG)__LINE__, \ - (membername), \ - (PVOID)(address), \ - (initial) \ - ) - -#else // !IIS_NAMED_WIN32_OBJECTS - -#define IIS_CREATE_EVENT( membername, address, manual, state ) \ - CreateEventA( \ - NULL, \ - (manual), \ - (state), \ - NULL \ - ) - -#define IIS_CREATE_SEMAPHORE( membername, address, initial, maximum ) \ - CreateSemaphoreA( \ - NULL, \ - (initial), \ - (maximum), \ - NULL \ - ) - -#define IIS_CREATE_MUTEX( membername, address, initial ) \ - CreateMutexA( \ - NULL, \ - (initial), \ - NULL \ - ) - -#endif // IIS_NAMED_WIN32_OBJECTS - - -/************************ End of File ***********************/ - diff --git a/src/AspNetCoreModuleV2/IISLib/reftrace.c b/src/AspNetCoreModuleV2/IISLib/reftrace.c index c1b2e13a6e..877d358c76 100644 --- a/src/AspNetCoreModuleV2/IISLib/reftrace.c +++ b/src/AspNetCoreModuleV2/IISLib/reftrace.c @@ -3,7 +3,6 @@ #include #include "dbgutil.h" -#include "pudebug.h" #include "reftrace.h" diff --git a/src/AspNetCoreModuleV2/IISLib/tracelog.c b/src/AspNetCoreModuleV2/IISLib/tracelog.c index f7b2da5e43..6c0d080299 100644 --- a/src/AspNetCoreModuleV2/IISLib/tracelog.c +++ b/src/AspNetCoreModuleV2/IISLib/tracelog.c @@ -2,7 +2,6 @@ // Licensed under the MIT License. See License.txt in the project root for license information. #include -#include "pudebug.h" #include "tracelog.h" #include diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cxx b/src/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cxx index ac020d6369..91d8dab0ef 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cxx +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cxx @@ -10,24 +10,23 @@ #include "inprocessapplication.h" #include "inprocesshandler.h" #include "requesthandler_config.h" +#include "debugutil.h" + +DECLARE_DEBUG_PRINT_OBJECT("aspnetcorev2_inprocess.dll"); BOOL g_fGlobalInitialize = FALSE; BOOL g_fProcessDetach = FALSE; -DWORD g_dwAspNetCoreDebugFlags = 0; -DWORD g_dwDebugFlags = 0; SRWLOCK g_srwLockRH; IHttpServer * g_pHttpServer = NULL; HINSTANCE g_hWinHttpModule; HINSTANCE g_hAspNetCoreModule; HANDLE g_hEventLog = NULL; -PCSTR g_szDebugLabel = "ASPNET_CORE_MODULE_INPROCESS_REQUEST_HANDLER"; VOID InitializeGlobalConfiguration( IHttpServer * pServer ) { - HKEY hKey; BOOL fLocked = FALSE; if (!g_fGlobalInitialize) @@ -51,29 +50,7 @@ InitializeGlobalConfiguration( g_hEventLog = RegisterEventSource(NULL, ASPNETCORE_EVENT_PROVIDER); } - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, - L"SOFTWARE\\Microsoft\\IIS Extensions\\IIS AspNetCore Module\\Parameters", - 0, - KEY_READ, - &hKey) == NO_ERROR) - { - DWORD dwType; - DWORD dwData; - DWORD cbData; - - cbData = sizeof(dwData); - if ((RegQueryValueEx(hKey, - L"DebugFlags", - NULL, - &dwType, - (LPBYTE)&dwData, - &cbData) == NO_ERROR) && - (dwType == REG_DWORD)) - { - g_dwAspNetCoreDebugFlags = dwData; - } - RegCloseKey(hKey); - } + DebugInitialize(); g_fGlobalInitialize = TRUE; } diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp index 566b0e0aca..3f4e40a27e 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp @@ -408,7 +408,7 @@ IN_PROCESS_APPLICATION::LoadManagedApplication goto Finished; } } - + if (m_status != APPLICATION_STATUS::STARTING) { if (m_status == APPLICATION_STATUS::FAIL) diff --git a/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cxx b/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cxx index 23b7816ca6..625e884767 100644 --- a/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cxx +++ b/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cxx @@ -3,6 +3,8 @@ #include #include +DECLARE_DEBUG_PRINT_OBJECT("aspnetcorev2_outofprocess.dll"); + BOOL g_fNsiApiNotSupported = FALSE; BOOL g_fWebSocketStaticInitialize = FALSE; BOOL g_fEnableReferenceCountTracing = FALSE; @@ -12,8 +14,6 @@ BOOL g_fOutOfProcessInitializeError = FALSE; BOOL g_fWinHttpNonBlockingCallbackAvailable = FALSE; BOOL g_fProcessDetach = FALSE; DWORD g_OptionalWinHttpFlags = 0; -DWORD g_dwAspNetCoreDebugFlags = 0; -DWORD g_dwDebugFlags = 0; DWORD g_dwTlsIndex = TLS_OUT_OF_INDEXES; SRWLOCK g_srwLockRH; HINTERNET g_hWinhttpSession = NULL; @@ -21,7 +21,6 @@ IHttpServer * g_pHttpServer = NULL; HINSTANCE g_hWinHttpModule; HINSTANCE g_hAspNetCoreModule; HANDLE g_hEventLog = NULL; -PCSTR g_szDebugLabel = "ASPNET_CORE_MODULE_REQUEST_HANDLER"; VOID InitializeGlobalConfiguration( @@ -87,21 +86,10 @@ InitializeGlobalConfiguration( { g_fEnableReferenceCountTracing = !!dwData; } - - cbData = sizeof(dwData); - if ((RegQueryValueEx(hKey, - L"DebugFlags", - NULL, - &dwType, - (LPBYTE)&dwData, - &cbData) == NO_ERROR) && - (dwType == REG_DWORD)) - { - g_dwAspNetCoreDebugFlags = dwData; - } - RegCloseKey(hKey); } + DebugInitialize(); + dwResult = GetExtendedTcpTable(NULL, &dwSize, FALSE, diff --git a/test/CommonLibTests/inprocess_application_tests.cpp b/test/CommonLibTests/inprocess_application_tests.cpp index da3a2c1271..5a713e901a 100644 --- a/test/CommonLibTests/inprocess_application_tests.cpp +++ b/test/CommonLibTests/inprocess_application_tests.cpp @@ -8,7 +8,6 @@ // Externals defined in inprocess BOOL g_fProcessDetach; HANDLE g_hEventLog; -DWORD g_dwAspNetCoreDebugFlags; PCSTR g_szDebugLabel; DWORD g_dwDebugFlags; diff --git a/test/IISIntegration.FunctionalTests/OutOfProcess/GlobalVersionTests.cs b/test/IISIntegration.FunctionalTests/OutOfProcess/GlobalVersionTests.cs index 6e50228564..dfeefd3d8b 100644 --- a/test/IISIntegration.FunctionalTests/OutOfProcess/GlobalVersionTests.cs +++ b/test/IISIntegration.FunctionalTests/OutOfProcess/GlobalVersionTests.cs @@ -75,6 +75,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var response = await deploymentResult.RetryingHttpClient.GetAsync(_helloWorldRequest); var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(_helloWorldResponse, responseText); + AssertLoadedVersion(version); } [Theory] // Tests need to publish to change folder locations @@ -99,9 +100,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(_helloWorldResponse, responseText); + AssertLoadedVersion(version); } - [Theory] + [Theory] [InlineData("2.1.0")] [InlineData("2.1.0-preview")] public async Task GlobalVersion_MultipleRequestHandlers_UpgradeWorks(string version) @@ -134,6 +136,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests responseText = await response.Content.ReadAsStringAsync(); Assert.Equal(_helloWorldResponse, responseText); + AssertLoadedVersion(version); } private DeploymentParameters GetGlobalVersionBaseDeploymentParameters() @@ -156,5 +159,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests version, _aspNetCoreDll); } + + private void AssertLoadedVersion(string version) + { + Assert.Contains(TestSink.Writes, context => context.Message.Contains(version + @"\aspnetcorev2_outofprocess.dll")); + } } } diff --git a/test/IISIntegration.FunctionalTests/Utilities/FunctionalTestsBase.cs b/test/IISIntegration.FunctionalTests/Utilities/FunctionalTestsBase.cs index 3d2be31553..7817fd661f 100644 --- a/test/IISIntegration.FunctionalTests/Utilities/FunctionalTestsBase.cs +++ b/test/IISIntegration.FunctionalTests/Utilities/FunctionalTestsBase.cs @@ -9,6 +9,8 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting { public class FunctionalTestsBase : LoggedTest { + private const string DebugEnvironmentVariable = "ASPNETCORE_MODULE_DEBUG"; + public FunctionalTestsBase(ITestOutputHelper output = null) : base(output) { } @@ -17,6 +19,11 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting protected virtual async Task DeployAsync(DeploymentParameters parameters) { + if (!parameters.EnvironmentVariables.ContainsKey(DebugEnvironmentVariable)) + { + // enable debug output + parameters.EnvironmentVariables[DebugEnvironmentVariable] = "4"; + } _deployer = ApplicationDeployerFactory.Create(parameters, LoggerFactory); var result = await _deployer.DeployAsync(); diff --git a/test/WebSites/InProcessWebSite/Properties/launchSettings.json b/test/WebSites/InProcessWebSite/Properties/launchSettings.json index aa0472a2dd..0ef9e81546 100644 --- a/test/WebSites/InProcessWebSite/Properties/launchSettings.json +++ b/test/WebSites/InProcessWebSite/Properties/launchSettings.json @@ -18,7 +18,8 @@ "ANCM_PATH": "$(TargetDir)$(AncmV2Path)", "LAUNCHER_ARGS": "$(TargetPath)", "ASPNETCORE_ENVIRONMENT": "Development", - "LAUNCHER_PATH": "$(DotNetPath)" + "LAUNCHER_PATH": "$(DotNetPath)", + "ASPNETCORE_MODULE_DEBUG": "4" } }, "ANCM IIS": { @@ -30,7 +31,8 @@ "ANCM_PATH": "$(TargetDir)$(AncmV2Path)", "LAUNCHER_ARGS": "$(TargetPath)", "ASPNETCORE_ENVIRONMENT": "Development", - "LAUNCHER_PATH": "$(DotNetPath)" + "LAUNCHER_PATH": "$(DotNetPath)", + "ASPNETCORE_MODULE_DEBUG": "4" } } } diff --git a/test/WebSites/OutOfProcessWebSite/Properties/launchSettings.json b/test/WebSites/OutOfProcessWebSite/Properties/launchSettings.json index aa0472a2dd..0ef9e81546 100644 --- a/test/WebSites/OutOfProcessWebSite/Properties/launchSettings.json +++ b/test/WebSites/OutOfProcessWebSite/Properties/launchSettings.json @@ -18,7 +18,8 @@ "ANCM_PATH": "$(TargetDir)$(AncmV2Path)", "LAUNCHER_ARGS": "$(TargetPath)", "ASPNETCORE_ENVIRONMENT": "Development", - "LAUNCHER_PATH": "$(DotNetPath)" + "LAUNCHER_PATH": "$(DotNetPath)", + "ASPNETCORE_MODULE_DEBUG": "4" } }, "ANCM IIS": { @@ -30,7 +31,8 @@ "ANCM_PATH": "$(TargetDir)$(AncmV2Path)", "LAUNCHER_ARGS": "$(TargetPath)", "ASPNETCORE_ENVIRONMENT": "Development", - "LAUNCHER_PATH": "$(DotNetPath)" + "LAUNCHER_PATH": "$(DotNetPath)", + "ASPNETCORE_MODULE_DEBUG": "4" } } } diff --git a/test/WebSites/OverriddenServerWebSite/Properties/launchSettings.json b/test/WebSites/OverriddenServerWebSite/Properties/launchSettings.json index aa0472a2dd..0ef9e81546 100644 --- a/test/WebSites/OverriddenServerWebSite/Properties/launchSettings.json +++ b/test/WebSites/OverriddenServerWebSite/Properties/launchSettings.json @@ -18,7 +18,8 @@ "ANCM_PATH": "$(TargetDir)$(AncmV2Path)", "LAUNCHER_ARGS": "$(TargetPath)", "ASPNETCORE_ENVIRONMENT": "Development", - "LAUNCHER_PATH": "$(DotNetPath)" + "LAUNCHER_PATH": "$(DotNetPath)", + "ASPNETCORE_MODULE_DEBUG": "4" } }, "ANCM IIS": { @@ -30,7 +31,8 @@ "ANCM_PATH": "$(TargetDir)$(AncmV2Path)", "LAUNCHER_ARGS": "$(TargetPath)", "ASPNETCORE_ENVIRONMENT": "Development", - "LAUNCHER_PATH": "$(DotNetPath)" + "LAUNCHER_PATH": "$(DotNetPath)", + "ASPNETCORE_MODULE_DEBUG": "4" } } } diff --git a/test/WebSites/StartupExceptionWebSite/Properties/launchSettings.json b/test/WebSites/StartupExceptionWebSite/Properties/launchSettings.json index aa0472a2dd..0ef9e81546 100644 --- a/test/WebSites/StartupExceptionWebSite/Properties/launchSettings.json +++ b/test/WebSites/StartupExceptionWebSite/Properties/launchSettings.json @@ -18,7 +18,8 @@ "ANCM_PATH": "$(TargetDir)$(AncmV2Path)", "LAUNCHER_ARGS": "$(TargetPath)", "ASPNETCORE_ENVIRONMENT": "Development", - "LAUNCHER_PATH": "$(DotNetPath)" + "LAUNCHER_PATH": "$(DotNetPath)", + "ASPNETCORE_MODULE_DEBUG": "4" } }, "ANCM IIS": { @@ -30,7 +31,8 @@ "ANCM_PATH": "$(TargetDir)$(AncmV2Path)", "LAUNCHER_ARGS": "$(TargetPath)", "ASPNETCORE_ENVIRONMENT": "Development", - "LAUNCHER_PATH": "$(DotNetPath)" + "LAUNCHER_PATH": "$(DotNetPath)", + "ASPNETCORE_MODULE_DEBUG": "4" } } } diff --git a/test/WebSites/StressTestWebSite/Properties/launchSettings.json b/test/WebSites/StressTestWebSite/Properties/launchSettings.json index aa0472a2dd..0ef9e81546 100644 --- a/test/WebSites/StressTestWebSite/Properties/launchSettings.json +++ b/test/WebSites/StressTestWebSite/Properties/launchSettings.json @@ -18,7 +18,8 @@ "ANCM_PATH": "$(TargetDir)$(AncmV2Path)", "LAUNCHER_ARGS": "$(TargetPath)", "ASPNETCORE_ENVIRONMENT": "Development", - "LAUNCHER_PATH": "$(DotNetPath)" + "LAUNCHER_PATH": "$(DotNetPath)", + "ASPNETCORE_MODULE_DEBUG": "4" } }, "ANCM IIS": { @@ -30,7 +31,8 @@ "ANCM_PATH": "$(TargetDir)$(AncmV2Path)", "LAUNCHER_ARGS": "$(TargetPath)", "ASPNETCORE_ENVIRONMENT": "Development", - "LAUNCHER_PATH": "$(DotNetPath)" + "LAUNCHER_PATH": "$(DotNetPath)", + "ASPNETCORE_MODULE_DEBUG": "4" } } }