I suggest you ...

New debugging feature: debug shunts

I sometimes find myself running code in a testing configuration where certain parts of the code can't be run, or certain variables need values assigned. Currently, I set a breakpoint at the start of the code that needs to be skipped, or at the point where variables need to be set up, and then I use 'Set Next Statement' and assignments in the Watch pane to set things up.

This works fine, except that if I need to do multiple test runs, I have to repeat these steps *every single time*. For that reason, I'd like to propose a new feature: A new debugger construct that allows execution to be intercepted at one point and redirected to another point, optionally running a short block of user-supplied code in between. In effect, then, this allows a particular block of code to be replaced by another block of code for the duration of a debug session. Until turned off, these "debug shunts" would execute automatically on every run, every time the code hit the designated start point. Would save a lot of time in certain types of debug scenarios that I've found to be fairly common!

28 votes
Vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Jonathan Gilbert shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

2 comments

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...
  • Jonathan Gilbert commented  ·   ·  Flag as inappropriate

    Here's an example: Suppose you have code like this:

    static int Main()
    {
      var globalConfiguration = LoadGlobalConfiguration();
      var localConfigukration = LoadLocalConfiguration();

    var configuration = ApplyConfigurationOverrides(globalConfiguration, localConfiguration);

      RunService(configuration);
    }

    Now, suppose in my debug run I need to completely override the configuration. Currently, I could create an entry in the Watch window like this:

      configuration = new Configuration() { GronkulatorEnabled = true, LogSinks = LogSinks.Console, LogLevel = LogLevel.Diagnostic }

    Then, I put a breakpoint on the LoadGlobalConfiguration line, and on every test run, it stops on that line, and I use "Set Next Statement" to move execution to the RunService line and click the "Refresh" button in the watch window. This, then, overrides the configuration with my debugging configuration each time. This is a lot of work, though, and the more complicated code is, the easier it is to miss a step and invalidate a debug run.

    With my proposed feature, you could select the three "var" lines of the method, right-click and select "Add Debug Shunt". A dialog would pop up, with a code snippet editor, and with a hint stating that variables "globalConfiguration", "localConfiguration" and "configuration" must be assigned by the end of the code block. In that code snippet editor, I could then type:

      globalConfiguration = null;
      localConfiguration = null;
      configuration = new Configuration() { GronkulatorEnabled = true, LogSinks = LogSinks.Console, LogLevel = LogLevel.Diagnostic };

    With this shunt added, simply hitting "Start Debug" would automatically replace the effect of the three "var" lines with the lines in the code snippet. The ultimate effect would be the same as if I had used "Edit and Continue" to replace those lines of code with my shunt code, except without any permanent effect outside of debug sessions.

Feedback and Knowledge Base