3

For a demonstrating, take a look at the following section of this video.

Basically, I know this is possible in Visual Studio Community Edition 2015. I was wondering:

a) Is this related to Intellitrace and "Historic debugging"? b) Will there be any side-effect when I do this? Or is this just moving the instructions backwards and that's it?

anemaria20
  • 1,646
  • 2
  • 17
  • 36
  • It simply moves the instruction pointer. There certainly can be side-effects, you might accidentally skip required code that isn't visible in your source. A good example is [available here](http://stackoverflow.com/questions/28896531/clr-system-nullreferenceexception-when-forcing-set-next-statement-into-if-bl). – Hans Passant Jun 20 '16 at 11:24

2 Answers2

2

It is just moving the instruction pointer backwards and that's it, to use your own words.

This means that:

  • Any side-effects already incurred between where you drag it to and where you dragged it from has already incurred and won't be reversed.
  • Any variables changed in the same section of instructions will still be changed, they are not reversed to whatever values they had at the point you you drag the instruction pointer to

So you can use this debugging aid to either force the program to take a path it didn't (for instance by dragging the instruction pointer inside an if-statement it skipped), to skip (by dragging the instruction pointer past some code you don't want to execute), or to rerun some code.

But you must be aware of the above limitations. If the code is not safe to be executed again, then doing so will likely not help you debug.

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
  • Thanks! Is this a recommended practice? I haven't been able to find anything about this functionality, including when/when not to use it. – anemaria20 Jun 20 '16 at 10:46
  • 1
    "recommended practice" sounds like something I would recommend you do all the time, and this is not one of those functions. However, you should definitely learn how to use this function, what it can and cannot do, as sometimes you have no option other than to rerun or skip some code. If, for instance, it would take 2-3 minutes to rerun the entire program to get back to the point where your breakpoint hit, and then you step one step too far before you start "stepping into" code, then I would easily just drag the pointer back up and hit F11 to step into whatever. – Lasse V. Karlsen Jun 20 '16 at 10:48
  • Thanks! What about moving it forward? I saw this is possible too. If it works the same way forwards as it does backwards, I can imagine this is like a goto statement.. – anemaria20 Jun 20 '16 at 10:57
0

It's been doable for a long while now. Everything that happened to the point from where you are dragging the cursor already happened, so you will essentially be re-doing that bit.

There are no REAL consequences, unless you are processing something or saving to database etc., as writing the same existing data might throw an exception or mess with processing of some data.

All of the variables that have been set (even if you drag the cursor higher than they initialize) will retain the value they had from the spot you've dragged the cursor upward.

Jurijs Kastanovs
  • 685
  • 1
  • 15
  • 35