1 /*++ 2 3 Copyright (c) Microsoft Corporation 4 5 ModuleName: 6 7 DbgTrace.cpp 8 9 Abstract: 10 11 Temporary file to be used until ETW can be used 12 for UM 13 14 Author: 15 16 17 18 Revision History: 19 20 21 22 --*/ 23 24 #include "fxobjectpch.hpp" 25 26 #if FX_CORE_MODE==FX_CORE_USER_MODE 27 #include "strsafe.h" 28 #endif 29 30 #if !defined(EVENT_TRACING) 31 32 VOID 33 __cdecl 34 DoTraceLevelMessage( 35 __in PVOID FxDriverGlobals, 36 __in ULONG DebugPrintLevel, 37 __in ULONG DebugPrintFlag, 38 __drv_formatString(FormatMessage) 39 __in PCSTR DebugMessage, 40 ... 41 ) 42 43 /*++ 44 45 Routine Description: 46 47 Print the trace message to debugger. 48 49 Arguments: 50 51 TraceEventsLevel - print level between 0 and 3, with 3 the most verbose 52 53 Return Value: 54 55 None. 56 57 --*/ 58 { 59 #if DBG 60 UNREFERENCED_PARAMETER(FxDriverGlobals); 61 62 #define TEMP_BUFFER_SIZE 1024 63 va_list list; 64 CHAR debugMessageBuffer[TEMP_BUFFER_SIZE]; 65 NTSTATUS status; 66 67 va_start(list, DebugMessage); 68 69 if (DebugMessage) { 70 71 // 72 // Using new safe string functions instead of _vsnprintf. 73 // This function takes care of NULL terminating if the message 74 // is longer than the buffer. 75 // 76 #if FX_CORE_MODE==FX_CORE_KERNEL_MODE 77 status = RtlStringCbVPrintfA( debugMessageBuffer, 78 sizeof(debugMessageBuffer), 79 DebugMessage, 80 list ); 81 #else 82 HRESULT hr; 83 hr = StringCbVPrintfA( debugMessageBuffer, 84 sizeof(debugMessageBuffer), 85 DebugMessage, 86 list ); 87 88 89 if (HRESULT_FACILITY(hr) == FACILITY_WIN32) 90 { 91 status = WinErrorToNtStatus(HRESULT_CODE(hr)); 92 } 93 else 94 { 95 status = SUCCEEDED(hr) ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL; 96 } 97 #endif 98 if(!NT_SUCCESS(status)) { 99 100 #if FX_CORE_MODE==FX_CORE_KERNEL_MODE 101 DbgPrint ("WDFTrace: RtlStringCbVPrintfA failed 0x%x\n", status); 102 #else 103 OutputDebugString("WDFTrace: Unable to expand: "); 104 OutputDebugString(DebugMessage); 105 #endif 106 return; 107 } 108 if (DebugPrintLevel <= TRACE_LEVEL_ERROR || 109 (DebugPrintLevel <= DebugLevel && 110 ((DebugPrintFlag & DebugFlag) == DebugPrintFlag))) { 111 #if FX_CORE_MODE==FX_CORE_KERNEL_MODE 112 DbgPrint("WDFTrace: %s\n", debugMessageBuffer); 113 #else 114 OutputDebugString("WDFTrace: "); 115 OutputDebugString(DebugMessage); 116 #endif 117 } 118 } 119 va_end(list); 120 121 return; 122 #else 123 UNREFERENCED_PARAMETER(FxDriverGlobals); 124 UNREFERENCED_PARAMETER(DebugPrintLevel); 125 UNREFERENCED_PARAMETER(DebugPrintFlag); 126 UNREFERENCED_PARAMETER(DebugMessage); 127 #endif 128 } 129 130 #endif 131