microsoft / debugpy

An implementation of the Debug Adapter Protocol for Python
https://pypi.org/project/debugpy/
Other
1.74k stars 128 forks source link

python debugger ignores breakpoints? #1593

Open kaare-mikkelsen opened 1 month ago

kaare-mikkelsen commented 1 month ago

Discussed in https://github.com/microsoft/vscode-python/discussions/23522

I have made a cell and marked some break points:

image

However, when I click 'debug cell', the debugger just executes the cell, ignoring the break points?

The behavior is erratic. This is a few lines earlier in the same file:

image

Here the breakpoint at l. 93 works, but all else is ignored.

My launch.json looks like this:

{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": false, "noDebug": false, } ] }

My python version is 3.11.9.

What am I doing wrong?

rchiodo commented 1 month ago

Thanks for the issue. It looks like all the breakpoints that aren't hitting, the lines they're on don't have any executable code. Only the breakpoint on line 93 does.

Can you try it again and put the breakpoints on lines with actual code on them? I believe debugpy does try to look around the breakpoint for lines with code, but it's not a perfect search. It should work though if you move your breakpoints.

Like this one:

image

Try putting the breapoint on line 103 intead of line 104.

I can reproduce the problem myself:

image

If I debug this with Debug Python File, the first breakpoint is rebound to the line above it. If I debug this with Debug Cell, the first breakpoint is skipped.

So I'm guessing either we don't do the special remapping to near lines in cell debugging or there's a bug in our remapping. But for now you should be able to get those breakpoints to work if you put them on lines with actual code.

kaare-mikkelsen commented 1 month ago

you're right, this fixes it. Thanks a lot :)