Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could just call <strong>DebugBreak()</strong> from within your program.</p> <p>According to the <a href="http://msdn.microsoft.com/en-us/library/ms679297(VS.85).aspx" rel="nofollow noreferrer">MSDN page</a>, DebugBreak does the following:</p> <blockquote> <p>Causes a breakpoint exception to occur in the current process. This allows the calling thread to signal the debugger to handle the exception.</p> <p>To cause a breakpoint exception in another process, use the DebugBreakProcess function.</p> </blockquote> <p>You can then attach your debugger at this point, and continue running the program.</p> <p>The only problem with this solution is that you need to make the DebugBreak() in the code conditional, so that it won't break <em>every</em> time the program is run. Maybe you achieve this through an environment variable, registry setting, or a parameter which the scheduler passes in to the program to ensure that it breaks when it starts up.</p> <h3>Example code</h3> <p>Here's some untested example code reading an environment variable:</p> <pre><code>int main() { char *debugBreakChar = getenv("DEBUG_BREAK"); int debugBreak = atoi(debugBreakChar); if (debugBreak) { DebugBreak(); } // Rest of the program follows here } </code></pre> <p>Now all you need to do is set the environment variable as a system variable, and ensure that it's accessible from the same shell context as the scheduler (rebooting will achieve this):</p> <pre><code>set DEBUG_BREAK=1 </code></pre> <p>Now the program will break on startup, allowing you to attach a debugger. Changing the environment variable to 0, or un-setting it, will allow the program to run normally.</p> <p>Environment variables are a bit fiddly in this regard, as they are context-based and you need to know that the scheduler runs from the same environmental context. Registry values are better than this, and you can read a registry value using <a href="http://msdn.microsoft.com/en-us/library/ms724911(VS.85).aspx" rel="nofollow noreferrer">RegQueryValueEx</a> in your code instead (you'll need to include windows.h to use this function).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload