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

pdb shows code from wrong module #57537

Open
yak mannequin opened this issue Nov 3, 2011 · 2 comments
Open

pdb shows code from wrong module #57537

yak mannequin opened this issue Nov 3, 2011 · 2 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@yak
Copy link
Mannequin

yak mannequin commented Nov 3, 2011

BPO 13328
Nosy @birkenfeld, @ncoghlan, @meadori, @xdegaye, @akheron
Files
  • pdb.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2011-11-03.00:03:17.072>
    labels = ['type-bug']
    title = 'pdb shows code from wrong module'
    updated_at = <Date 2020-01-24.23:30:40.025>
    user = 'https://bugs.python.org/yak'

    bugs.python.org fields:

    activity = <Date 2020-01-24.23:30:40.025>
    actor = 'brett.cannon'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2011-11-03.00:03:17.072>
    creator = 'yak'
    dependencies = []
    files = ['23601']
    hgrepos = []
    issue_num = 13328
    keywords = ['patch']
    message_count = 2.0
    messages = ['146885', '146886']
    nosy_count = 6.0
    nosy_names = ['georg.brandl', 'ncoghlan', 'meador.inge', 'yak', 'xdegaye', 'petri.lehtinen']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue13328'
    versions = ['Python 2.7']

    @yak
    Copy link
    Mannequin Author

    yak mannequin commented Nov 3, 2011

    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.

    Reason:

    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.

    @yak yak mannequin added the type-bug An unexpected behavior, bug, or error label Nov 3, 2011
    @yak
    Copy link
    Mannequin Author

    yak mannequin commented Nov 3, 2011

    How to reproduce:

    Given a module foo.py imported using zipimport with a function bar, if we try to set a breakpoint in bar using:

    break foo.bar

    pdb would take filename and lineno from the function object but would use current frame to get module globals.

    linecache would return a line from current module but also store it in cache under foo's filename.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 22, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant