This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xdegaye
Recipients xdegaye
Date 2012-05-25.11:49:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1337946553.88.0.954704249232.issue14913@psf.upfronthosting.co.za>
In-reply-to
Content
Pdb behavior is not consistent with GNU gdb behavior when setting a
breakpoint on an empty line, a comment or a multi-line statement (the
breakpoint is ignored by pdb on a non-first line of a multi-line
statement and rejected on empty lines or comment lines).  It is also
confusing that, when a breakpoint is set on a function definition, pdb
also stops at the function definition execution when the module is
being loaded.

Pdb performance:
----------------
When a breakpoint is set in a module, pdb sets the trace function on
all the frames whose function is defined in this module (and the trace
function is run for each line in the function), regardless of the fact
that the function may not have any breakpoint.

Pdb breakpoint management problems:
-----------------------------------
See issue 14789, issue 14792, issue 14795, issue 14808 and issue 14912.

Pdb rejects setting a breakpoint in a function or method defined in a
non imported submodule of a package, but accepts to set it when the
non imported module is not in a package.  For example with
'asyncore.close_all' and 'logging.info':

    $ python
    Python 3.2.2 (default, Dec 27 2011, 17:35:55) 
    [GCC 4.3.2] on linux2
    Type "help", "copyright", "credits" or "license" for more
    information.
    >>> import pdb; pdb.run('def foo(): pass')
    > <string>(1)<module>()
    (Pdb) break asyncore.close_all
    Breakpoint 1 at /usr/local/lib/python3.2/asyncore.py:580
    (Pdb) break logging.info
    *** The specified object 'logging.info' is not a function or was
    not found along sys.path.

When a breakpoint is set at the line number of a function definition,
the algorithm used to find the first statement of the function (the
actual breakpoint) is not robust, so that when another breakpoint is
also set at this fuction using the function name instead of the line
number, then this last breakpoint hides the first one.


Use tokenize:
-------------
One solution is to parse the module source to build a description of
each function and method defined in the source:
    The description is the set of line_set of a function.  A line_set
    is either the line(s) of a function definition statement, or a
    group of consecutive statement lines, or a group of the physical
    lines of a logical line.

The attached patch implements this solution with std lib tokenize:

    When a breakpoint is set at an empty line or a comment in a
    function, pdb stops at the next statement. When a breakpoint is
    set at a multi-line statement (but not a function definition
    statement), pdb stops at the first line of the multi-line
    statement.  When a breakpoint is set at a line in a function
    definition or at a function name, pdb stops at the first statement
    in this function.  Attempting to set a breakpoint on a line
    outside a function definition is rejected with an error message.
    Pdb does not stop anymore at the function definition execution
    when the module is loaded.

    The trace function is only set on frames whose function has one
    breakpoint or more.

    The patch fixes issue 14789, issue 14792, issue 14795, issue 14808
    and issue 14912.  The patch fixes the problem of setting a
    breakpoint in a function or method defined in package submodule
    when the submodule is not imported.  The patch fixes the problem
    described above of having a breakpoint set by function name hide a
    breakpoint set by line number.  The patch includes test cases for
    all those issues.

    Parser performance: a file is only parsed when a breakpoint is set
    in this file (and parsed only once of course).  Some performance
    results of the parser on a laptop:

        * rpdb2.py from the rpdb2 project: 14500 lines parsed in 2.0
          seconds
        * a more reasonable (but still large) file size with
          turtle.py from the std library: 4100 lines parsed in 0.6
          second
History
Date User Action Args
2012-05-25 11:49:16xdegayesetrecipients: + xdegaye
2012-05-25 11:49:13xdegayesetmessageid: <1337946553.88.0.954704249232.issue14913@psf.upfronthosting.co.za>
2012-05-25 11:49:13xdegayelinkissue14913 messages
2012-05-25 11:49:13xdegayecreate