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

on terminating, Pdb debugs itself #58948

Open
xdegaye mannequin opened this issue May 7, 2012 · 5 comments
Open

on terminating, Pdb debugs itself #58948

xdegaye mannequin opened this issue May 7, 2012 · 5 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@xdegaye
Copy link
Mannequin

xdegaye mannequin commented May 7, 2012

BPO 14743
Nosy @birkenfeld, @asvetlov, @xdegaye
Files
  • pdb_botframe_default.patch
  • pdb_botframe_default_2.patch
  • pdb_botframe_default_3.patch
  • 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 2012-05-07.19:48:30.866>
    labels = ['type-bug', 'library']
    title = 'on terminating, Pdb debugs itself'
    updated_at = <Date 2019-03-16.00:13:59.628>
    user = 'https://github.com/xdegaye'

    bugs.python.org fields:

    activity = <Date 2019-03-16.00:13:59.628>
    actor = 'BreamoreBoy'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2012-05-07.19:48:30.866>
    creator = 'xdegaye'
    dependencies = []
    files = ['25489', '25493', '25535']
    hgrepos = []
    issue_num = 14743
    keywords = ['patch', 'needs review']
    message_count = 5.0
    messages = ['160166', '160197', '160403', '176276', '222268']
    nosy_count = 3.0
    nosy_names = ['georg.brandl', 'asvetlov', 'xdegaye']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'test needed'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue14743'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented May 7, 2012

    All the problems raised in this issue are caused by self.botframe
    being set in a Pdb frame.

    In the following pdb session run with python 3.2.2, the first two
    frames in the printed stack are Pdb frames, this is wrong. And the
    second step command steps incorrectly into the exec() frame that is
    called by the Bdb run() method. What prevents the third step command
    to step into the run() frame, is that this frame does not have a trace
    function setup initially.
    === foo.py =================================

    i = 1

    =================================================

    $ python3 -m pdb foo.py
    > path_to/foo.py(1)<module>()
    -> i = 1
    (Pdb) import sys; print(sys.version)
    3.2.2 (default, Dec 27 2011, 17:35:55) 
    [GCC 4.3.2]
    (Pdb) where
      /usr/local/lib/python3.2/bdb.py(392)run()
    -> exec(cmd, globals, locals)
      <string>(1)<module>()
    > path_to/foo.py(1)<module>()
    -> i = 1
    (Pdb) step
    --Return--
    > path_to/foo.py(1)<module>()->None
    -> i = 1
    (Pdb) step
    --Return--
    > <string>(1)<module>()->None
    (Pdb) step
    The program finished and will be restarted
    > path_to/foo.py(1)<module>()
    -> i = 1
    (Pdb) quit

    =================================================

    In the following pdb session run with python built from the default
    branch (i.e. after bpo-13183 has been fixed) the third step command
    steps into the run() method of Bdb and the backtrace printed after the
    quit command shows duplicate entries. Pdb is trying to debug itself !
    Pdb steps in the run() method because after the fix in bpo-13183,
    Pdb knows now how to step when returning into the caller frame with no
    trace function.
    === foo.py =================================

    i = 1

    =================================================

    $ python -m pdb foo.py 
    > path_to/foo.py(1)<module>()
    -> i = 1
    (Pdb) step
    --Return--
    > path_to/foo.py(1)<module>()->None
    -> i = 1
    (Pdb) step
    --Return--
    > <string>(1)<module>()->None
    (Pdb) step
    > path_to/cpython/Lib/bdb.py(409)run()
    -> self.quitting = True
    (Pdb) quit
    Traceback (most recent call last):
      File "path_to/cpython/Lib/pdb.py", line 1651, in main
        pdb._runscript(mainpyfile)
      File "path_to/cpython/Lib/pdb.py", line 1532, in _runscript
        self.run(statement)
      File "path_to/cpython/Lib/bdb.py", line 409, in run
        self.quitting = True
      File "path_to/cpython/Lib/bdb.py", line 409, in run
        self.quitting = True
      File "path_to/cpython/Lib/bdb.py", line 47, in trace_dispatch
        return self.dispatch_line(frame)
      File "path_to/cpython/Lib/bdb.py", line 66, in dispatch_line
        if self.quitting: raise BdbQuit
    bdb.BdbQuit
    Uncaught exception. Entering post mortem debugging
    Running 'cont' or 'step' will restart the program
    > path_to/cpython/Lib/bdb.py(66)dispatch_line()
    -> if self.quitting: raise BdbQuit
    (Pdb) quit
    Post mortem debugger finished. The foo.py will be restarted
    > path_to/foo.py(1)<module>()
    -> i = 1
    (Pdb) quit

    =================================================

    In the following pdb session run with python 3.2.2, the session is
    interrupted with <Ctl-C>. The same problems occur as in the previous
    case.
    =================================================

    import time
    i = 1
    while i:
        time.sleep(.100)
    i = 0

    =================================================

    $ python3 -m pdb foo.py
    > path_to/foo.py(1)<module>()
    -> import time
    (Pdb) import sys; print(sys.version)
    3.2.2 (default, Dec 27 2011, 17:35:55) 
    [GCC 4.3.2]
    (Pdb) continue
    ^C
    Program interrupted. (Use 'cont' to resume).
    > path_to/foo.py(3)<module>()
    -> while i:
    (Pdb) !i=0
    (Pdb) step
    > path_to/foo.py(5)<module>()
    -> i = 0
    (Pdb) step
    --Return--
    > path_to/foo.py(5)<module>()->None
    -> i = 0
    (Pdb) step
    --Return--
    > <string>(1)<module>()->None
    (Pdb) step
    > /usr/local/lib/python3.2/bdb.py(396)run()
    -> self.quitting = True
    (Pdb) quit
    Traceback (most recent call last):
      File "/usr/local/lib/python3.2/pdb.py", line 1556, in main
        pdb._runscript(mainpyfile)
      File "/usr/local/lib/python3.2/pdb.py", line 1437, in _runscript
        self.run(statement)
      File "/usr/local/lib/python3.2/bdb.py", line 396, in run
        self.quitting = True
      File "/usr/local/lib/python3.2/bdb.py", line 396, in run
        self.quitting = True
      File "/usr/local/lib/python3.2/bdb.py", line 46, in trace_dispatch
        return self.dispatch_line(frame)
      File "/usr/local/lib/python3.2/bdb.py", line 65, in dispatch_line
        if self.quitting: raise BdbQuit
    bdb.BdbQuit
    Uncaught exception. Entering post mortem debugging
    Running 'cont' or 'step' will restart the program
    > /usr/local/lib/python3.2/bdb.py(65)dispatch_line()
    -> if self.quitting: raise BdbQuit
    (Pdb) quit
    Post mortem debugger finished. The foo.py will be restarted
    > path_to/foo.py(1)<module>()
    -> import time
    (Pdb) quit

    =================================================

    The attached patch fixes all those problems. The patch applies to the
    default branch.

    @xdegaye xdegaye mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels May 7, 2012
    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented May 8, 2012

    Uploaded a new patch, pdb_botframe_default_2.patch (that applies to
    the current tip of the default branch) with:

    * a correction to the initial change made to fix sigint_handler()
    
    * the two test cases
    

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented May 11, 2012

    The previous patch only fixed the problem when the debugger is started
    from its main function. Uploaded new patch
    pdb_botframe_default_3.patch that fixes pdb.main and the pdb.run*
    function.

    This patch also corrects pdb.runcall(): in the following session, the
    3.1 debugger starts the debugging session at the second line of foo()
    and not at the --Call-- event. A test case for this problem is also
    included in the patch.

    === main.py =================================

    import pdb, sys
    print(sys.version)
    
    def foo():
        pass
    
    pdb.runcall(foo)

    =================================================

    $ python3.1 main.py
    3.1.2 (r312:79147, Apr  4 2010, 17:46:48) 
    [GCC 4.3.2]
    > /path_to/main.py(5)foo()
    -> pass
    (Pdb) quit

    =================================================

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Nov 24, 2012

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 4, 2014

    Can we have a formal patch review please, but note the similar patch on bpo-14788.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    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

    0 participants