HyperDbg Debugger
Loading...
Searching...
No Matches
Trace.h
Go to the documentation of this file.
1
13#pragma once
14
16// Constants //
18
19#define WPP_CONTROL_GUIDS \
20 WPP_DEFINE_CONTROL_GUID( \
21 HyperDbgLogger, \
22 (2AE39766, AE4B, 46AB, AFC4, 002DB8109721), \
23 WPP_DEFINE_BIT(HVFS_LOG) /* bit 0 = 0x00000001 */ \
24 WPP_DEFINE_BIT(HVFS_LOG_INFO) /* bit 1 = 0x00000002 */ \
25 WPP_DEFINE_BIT(HVFS_LOG_WARNING) /* bit 2 = 0x00000004 */ \
26 WPP_DEFINE_BIT(HVFS_LOG_ERROR) /* bit 3 = 0x00000008 */ \
27 )
28
29#define TRACE_LEVEL_NONE 0 // Tracing is not on
30#define TRACE_LEVEL_FATAL 1 // Abnormal exit or termination
31#define TRACE_LEVEL_ERROR 2 // Severe errors that need logging
32#define TRACE_LEVEL_WARNING 3 // Warnings such as allocation failure
33#define TRACE_LEVEL_INFORMATION 4 // Includes non-error cases(for example, Entry-Exit)
34#define TRACE_LEVEL_VERBOSE 5 // Detailed traces from intermediate steps
35#define TRACE_LEVEL_RESERVED6 6
36#define TRACE_LEVEL_RESERVED7 7
37#define TRACE_LEVEL_RESERVED8 8
38#define TRACE_LEVEL_RESERVED9 9
39
40//
41// DoTraceLevelMessage is a custom macro that adds support for levels to the
42// default DoTraceMessage, which supports only flags. In this version, both
43// flags and level are conditions for generating the trace message.
44// The preprocessor is told to recognize the function by using the -func argument
45// in the RUN_WPP line on the source file. In the source file you will find
46// -func:DoTraceLevelMessage(LEVEL,FLAGS,MSG,...). The conditions for triggering
47// this event in the macro are the Levels defined in evntrace.h and the flags
48// defined above and are evaluated by the macro WPP_LEVEL_FLAGS_ENABLED below.
49//
50#define WPP_LEVEL_FLAGS_LOGGER(level, flags) WPP_LEVEL_LOGGER(flags)
51#define WPP_LEVEL_FLAGS_ENABLED(level, flags) (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_##flags).Level >= level)
52
53//
54// Configuration block to scan the enumeration definition MachineState. Used when
55// viewing the trace to display names instead of the integer values that users must decode
56//
57// begin_wpp config
58// CUSTOM_TYPE(state, ItemEnum(_MachineState));
59// end_wpp
60
61// MACRO: TRACE_RETURN
62// Configuration block that defines trace macro. It uses the PRE/POST macros to include
63// code as part of the trace macro expansion. TRACE_MACRO is equivalent to the code below:
64//
65// {if (Status != STATUS_SUCCESS){ // This is the code in the PRE macro
66// DoTraceMessage(FLAG_ONE, "Function Return = %!STATUS!", Status)
67// ;}} // This is the code in the POST macro
68//
69//
70// USEPREFIX statement: Defines a format string prefix to be used when logging the event,
71// below the STDPREFIX is used. The first value is the trace function name with out parenthesis
72// and the second value is the format string to be used.
73//
74// USESUFFIX statement: Defines a suffix format string that gets logged with the event.
75//
76// FUNC statement: Defines the name and signature of the trace function. The function defined
77// below takes one argument, no format string, and predefines the flag equal to FLAG_ONE.
78//
79//
80//begin_wpp config
81// USEPREFIX (TRACE_RETURN, "%!STDPREFIX!");
82//FUNC TRACE_RETURN{FLAG=FLAG_ONE}(EXP);
83//USESUFFIX (TRACE_RETURN, "Function Return=%!STATUS!",EXP);
84//end_wpp
85//
86
87//
88// PRE macro: The name of the macro includes the condition arguments FLAGS and EXP
89// define in FUNC above
90//
91#define WPP_FLAG_EXP_PRE(FLAGS, HR) \
92 { \
93 if (HR != STATUS_SUCCESS) \
94 {
95//
96// POST macro
97// The name of the macro includes the condition arguments FLAGS and EXP
98// define in FUNC above
99#define WPP_FLAG_EXP_POST(FLAGS, HR) \
100 ; \
101 } \
102 }
103
104//
105// The two macros below are for checking if the event should be logged and for
106// choosing the logger handle to use when calling the ETW trace API
107//
108#define WPP_FLAG_EXP_ENABLED(FLAGS, HR) WPP_FLAG_ENABLED(FLAGS)
109#define WPP_FLAG_EXP_LOGGER(FLAGS, HR) WPP_FLAG_LOGGER(FLAGS)