Going back to previous line while debugging on visual studio

16,580

Solution 1

After pausing on a break point, right click on the line you want to "go back" to. From the menu that pops up, select "set next statement".

This will adjust the instruction pointer to continue from the specified line of code, but it will not roll back any variables or memory addresses to the values they were at before that line of code was originally executed.

Solution 2

It sounds like what you want to do is rewind / replay your code rather than just move to a specific line. You can move to a specific line, you can just right click and choose set next statement. Unfortunately, this won't rewind the state of the program to some past point (beyond setting the stack and doing a bit of unwinding).

To rewind/replay you need to be a bit trickier. Some options are: -

  • VMWare replay which will allow you to record and then go back to a certain point in time.
  • Intellitrace. I haven't tried it, but it allows you to replay to a point.

Which is a bit heavyweight and wont help you right now.

Solution 3

You can use the mouse to drag the yellow arrow pointing to the "next statement to be executed." This actually changes which statement will be executed next. It's not guaranteed to work, but as long as the code is not too complex, it could.

Share:
16,580

Related videos on Youtube

Srujan Barai
Author by

Srujan Barai

Updated on September 15, 2022

Comments

  • Srujan Barai
    Srujan Barai over 1 year

    I am debugging a piece of code on visual studio and I forgot to note down the values I have kept a watch on. Can I go to previous line without rerunning the entire code? There are similar questions asked on SO but in my case i haven't run through any error or exception. The code is running normally.

  • Srujan Barai
    Srujan Barai about 10 years
    Will it roll back the values of my variable and pointers that i have kept a watch on?
  • Angew is no longer proud of SO
    Angew is no longer proud of SO about 10 years
    @SrujanBarai I'm afraid not; but I've never used this feature, so I'm not sure.
  • Srujan Barai
    Srujan Barai about 10 years
    The next answer answers this question anyways. So unfortunately it doesn't!
  • Srujan Barai
    Srujan Barai about 10 years
    I only wish I could set more than one answers as "Accepted" on SO. Well, this did help by the way. Thanks.
  • acarlon
    acarlon about 10 years
    @SrujanBarai - glad to help. Good luck.