Is it possible to free a resource (file lock, timer) when the program is stopped in the debugger?
In general, could I execute the code before MSVC stopped the program for debugging and after resuming execution?
I would like to do the following: - Automatically release file locks for editing during debugging. - Automatically reloads the file after resuming the process - Prevent the start of timers that overflow while debugging is stopped - Subtract the duration of debugging from the timers
Workaround: if I can’t execute the code before the program is stopped by the debugger, then program programming in the program that the debugger stopped the application will already help a lot.
Edit: I looked at the Windows API functions for integrating the debugger, but it seems like functions like ContinueDebugEventthat are intended only for the debugger writer and never for the debugged process.
Edit 2: It seems that the hotpatching function of DbgBreakPoint may be a way to intercept when the debugger wants to break the process.
The main idea of attaching is that the debugger calls the "DebugActiveProcess" function, which ends with a call to "RtlCreateUserThread" to create a new remote thread in the target process, with the "DbgUiRemoteBreakin" function as the new entry point for the stream.
(from http://waleedassar.blogspot.de/2011/12/debuggers-anti-attaching-techniques.html )
DbgUiRemoteBreakin appears to be invoking DbgBreakPoint to actually stop the process.
3:
DbgBreakPoint DebugBreak, , MSVC, . , ! , MSVC int 3 .
4:
DebugBreak : 3 , ( ). , .