Implemented WPP tracing boilerplate

This commit is contained in:
Benjamin Höglinger
2018-05-12 14:31:07 +02:00
parent d2d690467d
commit 42bc54ce13
7 changed files with 145 additions and 4 deletions

8
.gitignore vendored
View File

@@ -18,3 +18,11 @@
/Release (static)
/build/bin/Debug
/build/obj/Debug
/bin
/sys/x64/Debug
/x64/Debug
/x64/Debug (static)
*.user
/.vs/config
/sys/RCa21300
/sys/RCb21300

View File

@@ -25,6 +25,7 @@ SOFTWARE.
#include "busenum.h"
#include <wdmguid.h>
#include "driver.tmh"
#ifdef ALLOC_PRAGMA
#pragma alloc_text (INIT, DriverEntry)
@@ -40,18 +41,31 @@ SOFTWARE.
//
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
{
WDF_DRIVER_CONFIG config;
NTSTATUS status;
WDFDRIVER driver;
WDF_DRIVER_CONFIG config;
NTSTATUS status;
WDFDRIVER driver;
WDF_OBJECT_ATTRIBUTES attributes;
KdPrint((DRIVERNAME "Virtual Gamepad Emulation Bus Driver [built: %s %s]\n", __DATE__, __TIME__));
//
// Initialize WPP Tracing
//
WPP_INIT_TRACING(DriverObject, RegistryPath);
//
// Register cleanup callback
//
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
attributes.EvtCleanupCallback = Bus_EvtDriverContextCleanup;
WDF_DRIVER_CONFIG_INIT(&config, Bus_EvtDeviceAdd);
status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, &driver);
status = WdfDriverCreate(DriverObject, RegistryPath, &attributes, &config, &driver);
if (!NT_SUCCESS(status))
{
WPP_CLEANUP(DriverObject);
KdPrint((DRIVERNAME "WdfDriverCreate failed with status 0x%x\n", status));
}
@@ -382,6 +396,38 @@ Bus_FileClose(
WdfChildListEndIteration(list, &iterator);
}
VOID
Bus_EvtDriverContextCleanup(
_In_ WDFOBJECT DriverObject
)
/*++
Routine Description:
Free all the resources allocated in DriverEntry.
Arguments:
DriverObject - handle to a WDF Driver object.
Return Value:
VOID.
--*/
{
UNREFERENCED_PARAMETER(DriverObject);
PAGED_CODE ();
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, "%!FUNC! Entry");
//
// Stop WPP Tracing
//
WPP_CLEANUP( WdfDriverWdmGetDriverObject( (WDFDRIVER) DriverObject) );
}
//
// Called by PDO when a boot-up stage has been completed
//

View File

@@ -149,6 +149,7 @@
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
<IncludePath>$(SolutionDir)Include;$(IncludePath)</IncludePath>
<Inf2CatUseLocalTime>true</Inf2CatUseLocalTime>
<EnableInf2cat>false</EnableInf2cat>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
@@ -161,6 +162,7 @@
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
<IncludePath>$(SolutionDir)Include;$(IncludePath)</IncludePath>
<Inf2CatUseLocalTime>true</Inf2CatUseLocalTime>
<EnableInf2cat>false</EnableInf2cat>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
@@ -212,6 +214,11 @@
<Link>
<AdditionalDependencies>$(DDK_LIB_PATH)ntstrsafe.lib;$(DDK_LIB_PATH)wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ClCompile>
<WppRecorderEnabled>true</WppRecorderEnabled>
<WppEnabled>true</WppEnabled>
<WppScanConfigurationData>trace.h</WppScanConfigurationData>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Inf>
@@ -225,6 +232,9 @@
</ClCompile>
<ClCompile>
<WholeProgramOptimization>true</WholeProgramOptimization>
<WppRecorderEnabled>true</WppRecorderEnabled>
<WppEnabled>true</WppEnabled>
<WppScanConfigurationData>trace.h</WppScanConfigurationData>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
@@ -250,6 +260,11 @@
<Link>
<AdditionalDependencies>$(DDK_LIB_PATH)ntstrsafe.lib;$(DDK_LIB_PATH)wdmsec.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ClCompile>
<WppRecorderEnabled>true</WppRecorderEnabled>
<WppEnabled>true</WppEnabled>
<WppScanConfigurationData>trace.h</WppScanConfigurationData>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Inf>
@@ -263,6 +278,9 @@
</ClCompile>
<ClCompile>
<WholeProgramOptimization>true</WholeProgramOptimization>
<WppRecorderEnabled>true</WppRecorderEnabled>
<WppEnabled>true</WppEnabled>
<WppScanConfigurationData>trace.h</WppScanConfigurationData>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
@@ -281,6 +299,7 @@
<ClInclude Include="Ds4.h" />
<ClInclude Include="Queue.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="trace.h" />
<ClInclude Include="UsbPdo.h" />
<ClInclude Include="Util.h" />
<ClInclude Include="Xgip.h" />

View File

@@ -66,6 +66,9 @@
<ClInclude Include="$(SolutionDir)\Include\ViGEmCommon.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="trace.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ViGEmBus.rc">

View File

@@ -26,6 +26,7 @@ SOFTWARE.
#include "busenum.h"
#include <wdmguid.h>
#include <usb.h>
#include "busenum.tmh"
#ifdef ALLOC_PRAGMA
#pragma alloc_text (PAGE, Bus_PlugInDevice)

View File

@@ -25,6 +25,7 @@ SOFTWARE.
#pragma once
#include "trace.h"
#include <ntddk.h>
#include <wdf.h>
#define NTSTRSAFE_LIB
@@ -99,6 +100,8 @@ EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL Pdo_EvtIoInternalDeviceControl;
EVT_WDF_TIMER Xgip_SysInitTimerFunc;
EVT_WDF_OBJECT_CONTEXT_CLEANUP Bus_EvtDriverContextCleanup;
#pragma endregion
#pragma region Bus enumeration-specific functions

61
sys/trace.h Normal file
View File

@@ -0,0 +1,61 @@
/*++
Module Name:
Trace.h
Abstract:
Header file for the debug tracing related function defintions and macros.
Environment:
Kernel mode
--*/
//
// Define the tracing flags.
//
// Tracing GUID - c5ce18fe-27bd-4049-b0b4-8a47cab1dcd9
//
#define WPP_CONTROL_GUIDS \
WPP_DEFINE_CONTROL_GUID( \
ViGEmBusTraceGuid, (c5ce18fe,27bd,4049,b0b4,8a47cab1dcd9), \
\
WPP_DEFINE_BIT(MYDRIVER_ALL_INFO) \
WPP_DEFINE_BIT(TRACE_BUSENUM) \
WPP_DEFINE_BIT(TRACE_BUSPDO) \
WPP_DEFINE_BIT(TRACE_BYTEARRAY) \
WPP_DEFINE_BIT(TRACE_DRIVER) \
WPP_DEFINE_BIT(TRACE_DS4) \
WPP_DEFINE_BIT(TRACE_QUEUE) \
WPP_DEFINE_BIT(TRACE_USBPDO) \
WPP_DEFINE_BIT(TRACE_UTIL) \
WPP_DEFINE_BIT(TRACE_XGIP) \
WPP_DEFINE_BIT(TRACE_XUSB) \
)
#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
// FUNC Trace{FLAG=MYDRIVER_ALL_INFO}(LEVEL, MSG, ...);
// FUNC TraceEvents(LEVEL, FLAGS, MSG, ...);
// end_wpp
//