Title: can't step through _frozen_importlib/importlib._bootstrap using pdb
Type: behavior Stage: test needed
Components: Interpreter Core, Library (Lib) Versions: Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, brett.cannon, eric.snow, exarkun
Priority: normal Keywords:

Created on 2012-09-10 19:30 by exarkun, last changed 2020-01-29 00:42 by brett.cannon.

Messages (3)
msg170221 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2012-09-10 19:30
Debugging problems involving the frozen importlib._bootstrap is difficult, because the source for importlib._bootstrap is not available to pdb.  The bootstrap code can be stepped through, but with only function names and line numbers available, not source lines.

The value of having importlib written in Python would be greatly enhanced if it were more like a regular Python module that, eg, pdb could display source lines from.
msg170224 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2012-09-10 19:42
This comes back to #14657, which addressed the frozen vs. non-frozen copies of importlib.  It sounds like one useful solution for your situation would be for _frozen_importlib to be used only long enough for bootstrap purposes.  This was discussed in that other issue.
msg170301 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-09-11 13:09
I'm going to guess this is a shortcoming of pdb when it comes to frozen modules as I can get to the source using inspect (which pdb leans on)::

>>> len(inspect.findsource(_frozen_importlib)[0])
>>> len(inspect.findsource(importlib._bootstrap)[0])

Which are accurate line counts::

$ wc Lib/importlib/ 
 1761  6236 62517 Lib/importlib/

So why gdb can't output the source line when it has the line number of the file I don't know when it can already get access to the source without issue.

And yes, debugging imports are hard. =) Still, it's better than before as you can easily toss in a print statement or two and then just regenerate the frozen object. But I do agree it would be nice to get gdb to play along with the whole situation (and thus the title change for this bug).
Date User Action Args
2020-01-29 00:42:31brett.cannonsetversions: + Python 3.9, - Python 3.4
2020-01-29 00:40:10brett.cannonsettitle: can't step through _frozen_importlib/importlib._bootstrap using gdb -> can't step through _frozen_importlib/importlib._bootstrap using pdb
2012-12-18 02:14:29Arfreversetnosy: + Arfrever
2012-09-11 13:09:40brett.cannonsetversions: + Python 3.4, - Python 3.3
type: behavior

nosy: + brett.cannon
title: Debugging import problems is hard -> can't step through _frozen_importlib/importlib._bootstrap using gdb
messages: + msg170301
stage: test needed
2012-09-10 19:42:31eric.snowsetnosy: + eric.snow
messages: + msg170224
2012-09-10 19:30:36exarkuncreate