5

You know how you can click the yellow arrow on a breakpoint and drag it down to skip execution of lines of code? Well, is it possible to create a "When Hit" macro (or something similar) that skips execution of the line containing the breakpoint?

So instead of writing code like

if(!Debugging)
   Response.Redirect("LoginFail.aspx");

I could sit a breakpoint on the Response.Redirect() line and "When Hit" will skip it.

1

5 Answers 5

6

I don't know of baked in way of doing this. You can however set the "When hit" options of a breakpoint to run a macro. It shouldn't be hard to write a macro that gets the current line, and then sets the next debugger line. You'll probably want to look at the Debugger.SetNextStatement method.

A macro like this should do it:

Public Sub SkipNextLine()
    ActiveDocument().Selection.LineDown()
    DTE.ExecuteCommand("Debug.SetNextStatement")
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

This was great! Unfortunately, Macros where removed from Visual Studio 2012.
1

Yes, you can do this directly using a tracepoint.

  1. Find the address of the return statement or final closing curly brace at the bottom of the function by breaking on it once, and then looking at the EIP register either in the Registers window or add a Watch for "@eip".
  2. Add a tracepoint to the line you want to jump from. Remember that the jump will occur before anything on the line is executed. The content of the tracepoint should be {@eip = address} using the address from step 1.

See also https://stackoverflow.com/a/14695736/301729

Comments

0

There's no way I know of to do this with a breakpoint but you can use compiler directives to skip code

#if (DEBUG)
//this code is skipped in debug mode
#endif

Comments

0

Try:

#if DEBUG
Response.Redirect("LoginFail.aspx");
#endif

Make sure you have the DEBUG constant checked in your build properties.

Comments

0

Agree with the use of compiler directives or any other requiring to add logic in code. However, also understand editing the debugged code is not always an option (e.g. not owning the code might imply not having all resources needed to build it).

If that's your case, I'm afraid that writing your own macro or waiting for VS to have one built-in equivalent are your only options.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.