Skip to content

Commit

Permalink
Enable WPP Event Tracing for both the WSK library and the test driver
Browse files Browse the repository at this point in the history
The WPP Event Tracing can be disabled which means return to the good old DbgPrintEx routine. To disable WPP, the following steps need to be done:
- commenting the line `#define EVENT_TRACING` in project's trace.h file,
- setting the "Run Wpp Tracing" option in project settings to No.

Signed-off-by: Martin Drab <[email protected]>
  • Loading branch information
Martin Drab committed Jan 27, 2024
1 parent a030333 commit 819dc29
Show file tree
Hide file tree
Showing 17 changed files with 459 additions and 14 deletions.
8 changes: 8 additions & 0 deletions viosock/inc/debug-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
#define __DEBUG_UTILS_H__


#include <Evntrace.h>
#include "wpp-trace.h"
#include "..\..\virtio\kdebugprint.h"

#ifndef EVENT_TRACING


#if defined(DBG) || defined(_DEBUG)

Expand Down Expand Up @@ -81,3 +87,5 @@


#endif

#endif
3 changes: 3 additions & 0 deletions viosock/viosock-wsk-test/test-messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <bcrypt.h>
#include "..\inc\debug-utils.h"
#include "test-messages.h"
#ifdef EVENT_TRACING
#include "test-messages.tmh"
#endif


static ULONG _randSeed;
Expand Down
123 changes: 120 additions & 3 deletions viosock/viosock-wsk-test/viosock-wsk-test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
<Configuration>Win10 Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Win11 Release|ARM64">
<Configuration>Win11 Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Win11 Release|Win32">
<Configuration>Win11 Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Win11 Release|x64">
<Configuration>Win11 Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{A2A7AFFC-BEFE-4066-A1DD-23242FAFAD70}</ProjectGuid>
Expand All @@ -34,6 +46,14 @@
<DriverType>WDM</DriverType>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win11 Release|Win32'" Label="Configuration">
<TargetVersion>Windows10</TargetVersion>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<ConfigurationType>Driver</ConfigurationType>
<DriverType>WDM</DriverType>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win10 Release|x64'" Label="Configuration">
<TargetVersion>Windows10</TargetVersion>
<UseDebugLibraries>false</UseDebugLibraries>
Expand All @@ -42,6 +62,14 @@
<DriverType>WDM</DriverType>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win11 Release|x64'" Label="Configuration">
<TargetVersion>Windows10</TargetVersion>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<ConfigurationType>Driver</ConfigurationType>
<DriverType>WDM</DriverType>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win10 Release|ARM64'" Label="Configuration">
<TargetVersion>Windows10</TargetVersion>
<UseDebugLibraries>false</UseDebugLibraries>
Expand All @@ -50,6 +78,14 @@
<DriverType>WDM</DriverType>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win11 Release|ARM64'" Label="Configuration">
<TargetVersion>Windows10</TargetVersion>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<ConfigurationType>Driver</ConfigurationType>
<DriverType>WDM</DriverType>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
Expand All @@ -64,31 +100,111 @@
<OutDir>objfre_win10_x86\i386\</OutDir>
<IntDir>objfre_win10_x86\i386\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win11 Release|Win32'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
<EnableInf2cat>false</EnableInf2cat>
<OutDir>objfre_win11_x86\i386\</OutDir>
<IntDir>objfre_win11_x86\i386\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win10 Release|x64'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
<EnableInf2cat>false</EnableInf2cat>
<OutDir>objfre_win10_amd64\amd64\</OutDir>
<IntDir>objfre_win10_amd64\amd64\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win11 Release|x64'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
<EnableInf2cat>false</EnableInf2cat>
<OutDir>objfre_win11_amd64\amd64\</OutDir>
<IntDir>objfre_win11_amd64\amd64\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win10 Release|ARM64'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
<OutDir>objfre_win10_arm64\arm64\</OutDir>
<IntDir>objfre_win10_arm64\arm64\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Win11 Release|ARM64'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
<OutDir>objfre_win11_arm64\arm64\</OutDir>
<IntDir>objfre_win11_arm64\arm64\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Win10 Release|Win32'">
<Link>
<AdditionalDependencies>cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib</AdditionalDependencies>
<AdditionalDependencies>Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib</AdditionalDependencies>
</Link>
<ClCompile>
<WppEnabled>true</WppEnabled>
<WppScanConfigurationData>wpp-trace.h</WppScanConfigurationData>
<PreprocessorDefinitions>TRACE_PROJECT_NAME=VioWskTest;_X86_=1;i386=1;STD_CALL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<DriverSign>
<FileDigestAlgorithm>SHA256</FileDigestAlgorithm>
</DriverSign>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Win11 Release|Win32'">
<Link>
<AdditionalDependencies>Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib</AdditionalDependencies>
</Link>
<ClCompile>
<WppEnabled>true</WppEnabled>
<WppScanConfigurationData>wpp-trace.h</WppScanConfigurationData>
<PreprocessorDefinitions>TRACE_PROJECT_NAME=VioWskTest;_X86_=1;i386=1;STD_CALL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<DriverSign>
<FileDigestAlgorithm>SHA256</FileDigestAlgorithm>
</DriverSign>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Win10 Release|x64'">
<Link>
<AdditionalDependencies>cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib</AdditionalDependencies>
<AdditionalDependencies>Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib</AdditionalDependencies>
</Link>
<ClCompile>
<WppEnabled>true</WppEnabled>
<WppScanConfigurationData>wpp-trace.h</WppScanConfigurationData>
<PreprocessorDefinitions>TRACE_PROJECT_NAME=VioWskTest;_WIN64;_AMD64_;AMD64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<DriverSign>
<FileDigestAlgorithm>SHA256</FileDigestAlgorithm>
</DriverSign>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Win11 Release|x64'">
<Link>
<AdditionalDependencies>Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib</AdditionalDependencies>
</Link>
<ClCompile>
<WppEnabled>true</WppEnabled>
<WppScanConfigurationData>wpp-trace.h</WppScanConfigurationData>
<PreprocessorDefinitions>TRACE_PROJECT_NAME=VioWskTest;_WIN64;_AMD64_;AMD64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<DriverSign>
<FileDigestAlgorithm>SHA256</FileDigestAlgorithm>
</DriverSign>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Win10 Release|ARM64'">
<Link>
<AdditionalDependencies>cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib</AdditionalDependencies>
<AdditionalDependencies>Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib</AdditionalDependencies>
</Link>
<ClCompile>
<WppEnabled>true</WppEnabled>
<WppScanConfigurationData>wpp-trace.h</WppScanConfigurationData>
<PreprocessorDefinitions>TRACE_PROJECT_NAME=VioWskTest;_ARM64_;ARM64;_USE_DECLSPECS_FOR_SAL=1;STD_CALL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<DriverSign>
<FileDigestAlgorithm>SHA256</FileDigestAlgorithm>
</DriverSign>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Win11 Release|ARM64'">
<Link>
<AdditionalDependencies>Ntstrsafe.lib;cng.lib;%(AdditionalDependencies);$(KernelBufferOverflowLib);$(DDK_LIB_PATH)ntoskrnl.lib;$(DDK_LIB_PATH)hal.lib;$(DDK_LIB_PATH)wmilib.lib</AdditionalDependencies>
</Link>
<ClCompile>
<WppEnabled>true</WppEnabled>
<WppScanConfigurationData>wpp-trace.h</WppScanConfigurationData>
<PreprocessorDefinitions>TRACE_PROJECT_NAME=VioWskTest;_ARM64_;ARM64;_USE_DECLSPECS_FOR_SAL=1;STD_CALL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<DriverSign>
<FileDigestAlgorithm>SHA256</FileDigestAlgorithm>
</DriverSign>
</ItemDefinitionGroup>
<ItemGroup>
<FilesToPackage Include="$(TargetPath)" />
Expand All @@ -104,6 +220,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="test-messages.h" />
<ClInclude Include="wpp-trace.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
3 changes: 3 additions & 0 deletions viosock/viosock-wsk-test/viosock-wsk-test.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
<ClInclude Include="test-messages.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="wpp-trace.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
11 changes: 10 additions & 1 deletion viosock/viosock-wsk-test/viosockwsk-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
#include "..\inc\vio_sockets.h"
#include "..\sys\public.h"
#include "test-messages.h"

#ifdef EVENT_TRACING
#include "viosockwsk-test.tmh"
#endif


#define LISTEN_PORT_MIN 1337
Expand Down Expand Up @@ -797,6 +799,7 @@ DriverUnload(
VioWskDeregister(&_vioWskRegistration);
VioWskModuleFinit();
IoDeleteDevice(_shutdownDeviceObject);
WPP_CLEANUP(DriverObject);

DEBUG_EXIT_FUNCTION_VOID();
WPP_CLEANUP(DriverObject);
Expand All @@ -815,6 +818,7 @@ DriverEntry(
WPP_INIT_TRACING(DriverObject, RegistryPath);
DEBUG_ENTER_FUNCTION("DriverObject=0x%p; RegistryPath=\"%wZ\"", DriverObject, RegistryPath);

WPP_INIT_TRACING(DriverObject, RegistryPath);
Status = IoCreateDevice(DriverObject, 0, NULL, FILE_DEVICE_UNKNOWN, 0, FALSE, &Device);
if (!NT_SUCCESS(Status))
goto Exit;
Expand Down Expand Up @@ -867,6 +871,11 @@ DriverEntry(
if (Device)
IoDeleteDevice(Device);
Exit:
if (!NT_SUCCESS(Status))
{
WPP_CLEANUP(DriverObject);
}

DEBUG_EXIT_FUNCTION("0x%x", Status);
return Status;
}
117 changes: 117 additions & 0 deletions viosock/viosock-wsk-test/wpp-trace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2023 Virtuozzo International GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met :
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of their contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/



#define EVENT_TRACING

#if !defined(EVENT_TRACING)

#if !defined(TRACE_LEVEL_NONE)
#define TRACE_LEVEL_NONE 0
#define TRACE_LEVEL_CRITICAL 1
#define TRACE_LEVEL_FATAL 1
#define TRACE_LEVEL_ERROR 2
#define TRACE_LEVEL_WARNING 3
#define TRACE_LEVEL_INFORMATION 4
#define TRACE_LEVEL_VERBOSE 5
#define TRACE_LEVEL_RESERVED6 6
#define TRACE_LEVEL_RESERVED7 7
#define TRACE_LEVEL_RESERVED8 8
#define TRACE_LEVEL_RESERVED9 9
#endif


//
// Define Debug Flags
//
#define DBG_VIOWSK 0x00000001

#define DBG_TEST 0x00000001

#define WPP_INIT_TRACING(a,b)
#define WPP_CLEANUP(DriverObject)

#else
#define WPP_CHECK_FOR_NULL_STRING

//
// Define the tracing flags.
//
// Tracing GUID - C2D7F82F-CE5F-4408-8A37-8B9FE2B3D52E
//

// {13b9cfb4-b962-4b43-b59d-92242fab52e3}
// {46e3298a-70b1-49c6-b9fd-8691980b7adf}
#define WPP_CONTROL_GUIDS \
WPP_DEFINE_CONTROL_GUID(WskTraceGuid,(13b9cfb4,b962,4b43,b59d,92242fab52e3), \
WPP_DEFINE_BIT(DBG_VIOWSK) /* bit 0 = 0x00000001 */ \
) \
WPP_DEFINE_CONTROL_GUID(WskTestTraceGuid,(46e3298a,70b1,49c6,b9fd,8691980b7adf), \
WPP_DEFINE_BIT(DBG_TEST) /* bit 0 = 0x00000001 */ \
)


#define WPP_FLAG_LEVEL_LOGGER(flag, level) \
WPP_LEVEL_LOGGER(flag)

#define WPP_FLAG_LEVEL_ENABLED(flag, level) \
(WPP_LEVEL_ENABLED(flag) && WPP_CONTROL(WPP_BIT_ ## flag).Level >= level)

#define WPP_LEVEL_FLAGS_LOGGER(lvl,flags) \
WPP_LEVEL_LOGGER(flags)

#define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) \
(WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= lvl)

//
// This comment block is scanned by the trace preprocessor to define our
// Trace function.
//
// begin_wpp config
//
// USEPREFIX(DEBUG_ENTER_FUNCTION, "%!STDPREFIX! %!FUNC!(");
// USESUFFIX(DEBUG_ENTER_FUNCTION, ")");
// USEPREFIX(DEBUG_ENTER_FUNCTION_NO_ARGS, "%!STDPREFIX! %!FUNC!()");
// USEPREFIX(DEBUG_EXIT_FUNCTION, "%!STDPREFIX! %!FUNC!(-)");
// USEPREFIX(DEBUG_EXIT_FUNCTION_VOID, "%!STDPREFIX! %!FUNC!");
// USESUFFIX(DEBUG_EXIT_FUNCTION_VOID, "(-)");
//
// FUNC TraceEvents(LEVEL, FLAGS, MSG, ...);
// FUNC DEBUG_ENTER_FUNCTION{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=DBG_TEST}(MSG, ...);
// FUNC DEBUG_ENTER_FUNCTION_NO_ARGS{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=DBG_TEST}();
// FUNC DEBUG_EXIT_FUNCTION{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=DBG_TEST}(MSG, ...);
// FUNC DEBUG_EXIT_FUNCTION_VOID{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=DBG_TEST}();
// FUNC DEBUG_ERROR{LEVEL=TRACE_LEVEL_ERROR, FLAGS=DBG_TEST}(MSG, ...);
// FUNC DEBUG_WARNING{LEVEL=TRACE_LEVEL_WARNING, FLAGS=DBG_TEST}(MSG, ...);
// FUNC DEBUG_TRACE{LEVEL=TRACE_LEVEL_VERBOSE, FLAGS=DBG_TEST}(MSG, ...);
// FUNC DEBUG_INFO{LEVEL=TRACE_LEVEL_INFORMATION, FLAGS=DBG_TEST}(MSG, ...);
//
// end_wpp
//

#endif
Loading

0 comments on commit 819dc29

Please sign in to comment.