[New-bugs-announce] [issue13328] pdb shows code from wrong module
report at bugs.python.org
Thu Nov 3 01:03:17 CET 2011
New submission from Arkadiusz Wahlig <arkadiusz.wahlig at gmail.com>:
If pdb is used to debug code using zipimport, it may end up displaying source code from wrong module. Python will execute the correct code but the source code lines displayed by pdb (including the "list" command) will come from an unrelated module.
The pdb obtains lines of code using the linecache module. When used with zipimported modules, linecache requires the module's globals dict to be passed in along with the filename. The filename is then used as a cache key for future lookups.
A bug in pdb causes it to pass filename and globals from different modules when calling linecache thus polluting the cache with bogus data.
A patch for 2.7.2 is attached that fixes the problem.
The patch also fixes another problem:
When Bdb (Pdb parent class from bdb.py) calls linecache, it calls Bdb.canonic(filename) before passing the filename to it. It doesn't pass the module's globals though. This isn't a problem because the call is always made after Pdb has queried source lines for the same module (and it does pass the globals). However, because Pdb doesn't call Bdb.canonic() on the filename, the cache key is different and Bdb's call fails.
To fix this, the patch adds calls to Bdb.canonic(filename) whenever Pdb passes a filename to linecache.
title: pdb shows code from wrong module
versions: Python 2.7
Added file: http://bugs.python.org/file23601/pdb.diff
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce