Adding breakpoint in pdb results with "End of file"?

19 Views Asked by At

I'm so tired of this ...

Well, pdb: set a breakpoint on file which isn't in sys.path says:

According to this answer you can also set a break point by writing the full path to filename

And I've even tried it once before, and it worked.

And now I'm trying to debug another script:

$ python3 -m pdb freeze.py
> c:/tmp/mytest/freeze.py(9)<module>()
-> import py2exe
(Pdb) n
> c:/tmp/mytest/freeze.py(10)<module>()
-> from py2exe import freeze
(Pdb) b /mingw64/lib/python3.11/site-packages/py2exe/runtime.py:166
End of file
(Pdb) b
(Pdb)

And just to show that file, and line 166, exists:

$ awk 'NR >= 165 && NR <= 167 {printf "%d\t%s\n", NR, $0}' /mingw64/lib/python3.11/site-packages/py2exe/runtime.py
165         def analyze(self):
166             logger.info("Analyzing the code")
167

What is the problem? Why cannot I set a breakpoint and I get "End of file" instead? How do I set the breakpoint properly so it works?

1

There are 1 best solutions below

0
sdbbs On

Right, found that error message here: https://github.com/python/cpython/blob/a50cf6c/Lib/pdb.py#L1084 :

...
        line = linecache.getline(filename, lineno, globs)
        if not line:
            self.message('End of file')
            return 0
...

... so the problem is with linecache.getline.

Now, here I am using the MINGW64 Python3 under Windows 10; MINGW64 bash shell typically accepts linux-style paths - but it turns out, Python3 (or at least linecache) does not - from withn pdb:

(Pdb) import linecache
(Pdb) linecache.getline("/mingw64/lib/python3.11/site-packages/py2exe/runtime.py", 166, None)
''
(Pdb) linecache.getline("C:/msys64/mingw64/lib/python3.11/site-packages/py2exe/runtime.py", 166, None)
'        logger.info("Analyzing the code")\n'

So, apparently I needed to specify the full path with a Windows drive prefix (C:), just the Linux-style full path does not work:

(Pdb) b C:/msys64/mingw64/lib/python3.11/site-packages/py2exe/runtime.py:166
Breakpoint 1 at c:/msys64/mingw64/lib/python3.11/site-packages/py2exe/runtime.py:166

Now, there remains the problem that the breakpoint does not hit even though I see the output of the corresponding line ("Analyzing the code") printed - but that is another issue ...