Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if Debugger is Attached *and* stepping through

I am aware of the Debugger class within the System.Diagnostics namespace which has the IsAttached property.

Is there a property, somewhere, that can augment this call and tell me if we're actually stepping through code, rather than simply just being attached? I understand this may be highly unlikely, but it would be useful to know.

EDIT

Perhaps a better question, rather than "stepping" is running some code:

  1. When the debugger "breaks" for the first time (enters debug mode, after being attached)
  2. When it runs again (but is still attached, but not "stepping through").
like image 512
Moo-Juice Avatar asked Jun 10 '13 12:06

Moo-Juice


1 Answers

You can get the debugger state from the Debugger.CurrentMode property. But that's only going to tell you whether it is currently in the break state or if the program is running. There is no "step" mode, that's a fleeting moment which pretty much ensures that, if you could find about it, that acting on it would already be too late. Practically guaranteed to be a threading race.

like image 146
Hans Passant Avatar answered Oct 29 '22 15:10

Hans Passant