Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger out-of-sync with code with blank line #16407

Closed
paul-rogers opened this issue Jan 28, 2025 · 0 comments · Fixed by #16414
Closed

Debugger out-of-sync with code with blank line #16407

paul-rogers opened this issue Jan 28, 2025 · 0 comments · Fixed by #16414
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug notebook-debugging triage-needed Issue needs to be triaged
Milestone

Comments

@paul-rogers
Copy link

Type: Bug

The debugger seems to be thrown off by a blank line at the start of a code cell, resulting in an "off by one" of breakpoints and the yellow "current statement" indicator.

To see this, create a new notebook and choose the Python kernel. Create two cells.

Cell 1. Important: there is a blank line before the def statement.

def fib(n):
    if n < 0:
        raise Exception("Invalid input")
    if n < 2:
        return n
    return fib(n-1) + fib(n-2)

Cell 2:

fib(5)
  • Set breakpoints on the first three lines of fib(.).
  • Choose Debug Cell from the side menu for Cell 2.
  • The debugger stops at the raise statement without stopping at the if statement. Note that the argument is 5, so we're not actually on the raise line, we are actually on the if n < 0 line.
  • Click Step Over (or hit F10 if that is your binding)
  • The debugger is now in the return n line, without hitting the second if statement. However, actually, the intperter is on the if statement: the UI is wrong.
  • Click Step Over again. We again hit the breakpoint on raise. What actually happened is that the debugger is executing the return... line, which calls the method recursively. However, the visual indicator did not show this was happening.

Screen shot when hitting the first breakpoint:

Image

As you can see, when the UI indicator is out of sync with the code, it is very hard to follow what is going on.

The workaround is to remove the blank line:

  • Remove the blank line before def in cell 1 and execute the cell.
  • Again Choose Debug Cell for cell 2.
  • Now the debugger yellow arrow indicator is in sync with the actual code.

A simple explanation is that, in the first case, the code is out of sync with the interpreter: that we forgot to excute the cell to save our changes. This is easy to verify: just add the blank line back and choose Debug Cell. The debugger does not stop because the byte codes are out of sync with the source.

With the blank line added back, save the cell. Debug again. The debugger is again out of sync. This shows that the problem is not user error, but rather an actual repeatable bug.

Finally, note that the problem does not occur if the blank line is replaced by a comment:

# Example
def fib(n):
    ...
  • Make the above edit and execute the function declaration.
  • Ensure that the top three lines within the function have breakpoints as before.
  • Choose Debug Cell from the second cell.
  • Step through the code: the debugger is now in sync with the source.

This problem may be new: I don't recall seeing it in previous versions over the last year, but it could be that I never had a blank line above my code previously.

Extension version: 2024.11.0
VS Code version: Code 1.96.4 (cd4ee3b1c348a13bafd8f9ad8060705f6d4b9cba, 2025-01-16T00:16:19.038Z)
OS version: Linux x64 6.8.0-51-generic
Modes:

System Info
Item Value
CPUs AMD Ryzen 7 9700X 8-Core Processor (16 x 5536)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
webnn: disabled_off
Load (avg) 1, 1, 1
Memory (System) 60.44GB (35.39GB free)
Process Argv --crash-reporter-id 5e232e7b-355a-468c-ac4a-02c300f898bd
Screen Reader no
VM 0%
DESKTOP_SESSION cinnamon
XDG_CURRENT_DESKTOP X-Cinnamon
XDG_SESSION_DESKTOP cinnamon
XDG_SESSION_TYPE x11
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805:30301674
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
pythonnoceb:30805159
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
dvdeprecation:31068756
dwnewjupytercf:31046870
2f103344:31071589
nativerepl1:31139838
pythonrstrctxt:31112756
nativeloc1:31192215
cf971741:31144450
iacca1:31171482
5fd0e150:31155592
dwcopilot:31170013
stablechunks:31184530
6074i472:31201624
dwoutputs:31217127
9064b325:31222308
copilot_t_ci:31222730

@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug notebook-debugging triage-needed Issue needs to be triaged labels Jan 28, 2025
@DonJayamanne DonJayamanne added this to the February 2025 milestone Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug notebook-debugging triage-needed Issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants