HyperDbg Debugger
Loading...
Searching...
No Matches
Tracing.h File Reference

Headers for the tracing functions. More...

Go to the source code of this file.

Functions

VOID TracingHandleMtf (PROCESSOR_DEBUGGING_STATE *DbgState)
 Callback for handling VM-exits for MTF in the case of tracing instructions.
VOID TracingRestoreSystemState (PROCESSOR_DEBUGGING_STATE *DbgState)
 Restore the system state in the case of tracing instructions.
VOID TracingCheckForContinuingSteps (PROCESSOR_DEBUGGING_STATE *DbgState)
 Change for continuing the stepping state in the case of tracing instructions.
VOID TracingPerformInstrumentationStepIn (PROCESSOR_DEBUGGING_STATE *DbgState)
 Perform tracing of instructions (instrumentation step-in).
VOID TracingRegularStepInInstruction ()
 Regular step-in, step one instruction to the debuggee.
VOID TracingPerformRegularStepInInstruction ()
 Regular step-in, step one instruction to the debuggee.

Detailed Description

Headers for the tracing functions.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.7
Date
2023-11-03

Function Documentation

◆ TracingCheckForContinuingSteps()

VOID TracingCheckForContinuingSteps ( PROCESSOR_DEBUGGING_STATE * DbgState)

Change for continuing the stepping state in the case of tracing instructions.

Parameters
DbgStateThe state of the debugger on the current core
Returns
VOID
95{
96 //
97 // As it's called from a step itself, we need to double
98 // check whether the MTF should be ignored or not
99 //
100 if (DbgState->TracingMode)
101 {
103 }
104}
#define TRUE
Definition BasicTypes.h:114
IMPORT_EXPORT_VMM VOID VmFuncChangeMtfUnsettingState(UINT32 CoreId, BOOLEAN Set)
Suppress unsetting MTF.
Definition Export.c:47
UINT32 CoreId
Definition State.h:168
BOOLEAN TracingMode
Definition State.h:174

◆ TracingHandleMtf()

VOID TracingHandleMtf ( PROCESSOR_DEBUGGING_STATE * DbgState)

Callback for handling VM-exits for MTF in the case of tracing instructions.

Parameters
DbgStateThe state of the debugger on the current core
Returns
VOID
44{
45 //
46 // Handle system-state after handling single instrumentation step-in
47 //
49
50 //
51 // Dispatch and trigger the related events
52 //
54
55 //
56 // Check whether the steps needs to be continued or not
57 //
59}
VOID MetaDispatchEventInstrumentationTrace(PROCESSOR_DEBUGGING_STATE *DbgState)
Handling debugger functions related to instrumentation trace events.
Definition MetaDispatch.c:22
VOID TracingCheckForContinuingSteps(PROCESSOR_DEBUGGING_STATE *DbgState)
Change for continuing the stepping state in the case of tracing instructions.
Definition Tracing.c:94
VOID TracingRestoreSystemState(PROCESSOR_DEBUGGING_STATE *DbgState)
Restore the system state in the case of tracing instructions.
Definition Tracing.c:68

◆ TracingPerformInstrumentationStepIn()

VOID TracingPerformInstrumentationStepIn ( PROCESSOR_DEBUGGING_STATE * DbgState)

Perform tracing of instructions (instrumentation step-in).

Parameters
DbgStateThe state of the debugger on the current core
Returns
VOID
23{
25
26 DbgState->TracingMode = TRUE;
27
28 //
29 // Set instrumentation step-in state
30 //
32
34}
void * PVOID
Definition BasicTypes.h:56
#define FALSE
Definition BasicTypes.h:113
IMPORT_EXPORT_VMM VOID VmFuncEnableMtfAndChangeExternalInterruptState(UINT32 CoreId)
Enables MTF and adjust external interrupt state.
Definition Export.c:1073
IMPORT_EXPORT_VMM UINT32 DisassemblerShowOneInstructionInVmxRootMode(PVOID Address, BOOLEAN Is32Bit)
Shows the disassembly of only one instruction.
Definition Disassembler.c:372
IMPORT_EXPORT_VMM VOID VmFuncSetInstrumentationStepInState(UINT32 CoreId)
Set instrumentation step in MTF (used for single stepping with MTF).
Definition Export.c:73
IMPORT_EXPORT_VMM UINT64 VmFuncGetLastVmexitRip(UINT32 CoreId)
get the last vm-exit RIP
Definition Export.c:363

◆ TracingPerformRegularStepInInstruction()

VOID TracingPerformRegularStepInInstruction ( )

Regular step-in, step one instruction to the debuggee.

Returns
VOID
136{
137 UINT64 Interruptibility;
138 UINT64 InterruptibilityOld = NULL64_ZERO;
139
140 //
141 // Adjust RFLAG's trap-flag
142 //
144
145 //
146 // During testing single-step, we realized that after single-stepping
147 // on 'STI' instruction, after one instruction, the guest (target core)
148 // starts Invalid Guest State (0x21) vm-exits, after some searches we
149 // realized that KVM developer's encountered the same error; so, in order
150 // to solve the problem of stepping on 'STI' and 'MOV SS', we check the
151 // interruptibility state, here is a comment from KVM :
152 //
153 // When single stepping over STI and MOV SS, we must clear the
154 // corresponding interruptibility bits in the guest state
155 // Otherwise vmentry fails as it then expects bit 14 (BS)
156 // in pending debug exceptions being set, but that's not
157 // correct for the guest debugging case
158 //
159 InterruptibilityOld = VmFuncGetInterruptibilityState();
160
161 Interruptibility = InterruptibilityOld;
162
163 Interruptibility = VmFuncClearSteppingBits(Interruptibility);
164
165 if ((Interruptibility != InterruptibilityOld))
166 {
167 VmFuncSetInterruptibilityState(Interruptibility);
168 }
169}
#define NULL64_ZERO
Definition BasicTypes.h:111
IMPORT_EXPORT_VMM VOID VmFuncSetRflagTrapFlag(BOOLEAN Set)
Set Rflag's trap flag.
Definition Export.c:123
IMPORT_EXPORT_VMM VOID VmFuncSetInterruptibilityState(UINT64 InterruptibilityState)
Set guest's interruptibility state.
Definition Export.c:671
IMPORT_EXPORT_VMM UINT64 VmFuncGetInterruptibilityState()
Read guest's interruptibility state.
Definition Export.c:648
IMPORT_EXPORT_VMM UINT64 VmFuncClearSteppingBits(UINT64 Interruptibility)
Clear STI and MOV SS bits.
Definition Export.c:659

◆ TracingRegularStepInInstruction()

VOID TracingRegularStepInInstruction ( )

Regular step-in, step one instruction to the debuggee.

Returns
VOID
113{
114 //
115 // Perform the step-in
116 //
118
119 //
120 // Unset the trap flag on the next VM-exit
121 //
122 if (!BreakpointRestoreTheTrapFlagOnceTriggered(HANDLE_TO_UINT32(PsGetCurrentProcessId()), HANDLE_TO_UINT32(PsGetCurrentThreadId())))
123 {
124 LogWarning("Warning, it is currently not possible to add the current process/thread to the list of processes "
125 "where the trap flag should be masked. Please ensure that you manually unset the trap flag");
126 }
127}
BOOLEAN BreakpointRestoreTheTrapFlagOnceTriggered(UINT32 ProcessId, UINT32 ThreadId)
This function makes sure to unset the RFLAGS.TF on next trigger of DB on the target process/thread.
Definition BreakpointCommands.c:174
#define HANDLE_TO_UINT32(_var)
Definition MetaMacros.h:39
VOID TracingPerformRegularStepInInstruction()
Regular step-in, step one instruction to the debuggee.
Definition Tracing.c:135
#define LogWarning(format,...)
Log in the case of warning.
Definition HyperDbgHyperLogIntrinsics.h:99

◆ TracingRestoreSystemState()

VOID TracingRestoreSystemState ( PROCESSOR_DEBUGGING_STATE * DbgState)

Restore the system state in the case of tracing instructions.

Parameters
DbgStateThe state of the debugger on the current core
Returns
VOID
69{
70 //
71 // Indicate that we're no longer looking for the tracing
72 //
73 DbgState->TracingMode = FALSE;
74
75 //
76 // Uset the instrumentation step-in state
77 //
79
80 //
81 // Check for reenabling external interrupts
82 //
84}
IMPORT_EXPORT_VMM VOID VmFuncEnableAndCheckForPreviousExternalInterrupts(UINT32 CoreId)
Checks to enable and reinject previous interrupts.
Definition Export.c:1086
IMPORT_EXPORT_VMM VOID VmFuncUnsetInstrumentationStepInState(UINT32 CoreId)
Unset instrumentation step in MTF (used for single stepping with MTF).
Definition Export.c:86