22

The question says it all. Basically, I am looking for the opposite button to the Step over button in VS code debugger (more precisely, the opposite button to the underlined button).

5
  • 5
    There is NONE of such function Commented May 2, 2021 at 11:27
  • 4
    I wish this was a thing you could do. Commented May 2, 2021 at 13:57
  • 1
    Not even theoretically possible without something like VM snapshot integration. And even then whether it worked would depend on whether all IO stayed inside the VM bounds (code doing networking would get out of sync with services outside the host). Commented May 2, 2021 at 17:18
  • 1
    That would be a really cool feature, but it would require something that cached the program and computer state and let you rollback to it on request. Quite expensive if even possible. However, my approach is to put a break point on that previous line and run from the beginning again. Not the same, I know, but sometimes it lets me figure out what I wanted. Commented May 2, 2021 at 21:14
  • 1
    @joanis, definitely possible; every major virtualization tool out there (qemu, VirtualBox, VMware) supports snapshots/rollback, so it's just a question of debugger integration. But expensive to be sure. (OTOH, if the error being debugged happens hours into runtime, maybe it would be less expensive than starting from the beginning). Commented May 3, 2021 at 14:57

2 Answers 2

31

You can change next executing line with Debug: Jump to Cursor command.

  1. Set breakpoint
  2. Wait for code to stop
  3. Click on desired line
  4. Open command list (default is ctrl + shift + p)
  5. Use Debug: Jump to Cursor
  6. Enjoy enter image description here

Note: you can bind this action to some hotkey like (ctrl + f8) doc

Sign up to request clarification or add additional context in comments.

5 Comments

This does not solve the problem. If you change a variable then step to a line of code before you changed this variable, this variable is still changed and will act this way.
@Evergreen you cannot undo such things because debugger cannot travel in time, but you can change value of variable with watch panel at right side
yes... that is what i mean, if you have a function, and you step over the function and it changes the value of a long list, you have no way to know what the value of the list was before it was changed unless you have superhuman memory. Dont get me wrong, this is a good answer but it does not help in the case where you are debugging complicated code or handling gigantic arrays.
@JL0PD, ...but time travel is what the OP is asking to do here, so the proper answer if "no that's not possible" instead of showing them something that looks similar but doesn't actually do what they want.
It is a decent way and good use of a debugger. You can go back a few lines to reset variable values and re-examine the steps you fast-forwarded. Sometimes re-running the debugger is costly because of huge data loads and other IO tasks.
-2

if it is possible to run you code in a [.ipynb]jupyter notebook file, there is such a functionality in the google colab.

  • use %%debug magic command and command up in the debugger prompt.

1 Comment

up goes to the outer stack frame. It does not go back in time; when that stack frame has references to data mutated by the last operation, the effect of those mutations is not undone.

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.