Python debugger

Discussion in 'Python' started by Guillermo Fernandez, Oct 16, 2003.

  1. Hi,

    I'm trying to play with the python debugger. The idea is to put lines in the
    code to automatically define breakpoints at the starting of the debugger.

    (like:

    1 def a():
    2 #--- break
    3 print 'done'

    would automatically insert a break in the line number 2)

    I did the code appended (I'm still quite a beginner...) but it makes me problems.
    Traceback (most recent call last):
    File "C:\Python23\lib\site-packages\sm\scriptutils.py", line 52, in run
    sdb.run('exec codeObject in mainDict', locals(), mainDict)
    File "C:\Python23\lib\site-packages\sm\spedb.py", line 29, in run
    Sdb().run(statement, globals, locals)
    File "C:\Python23\lib\site-packages\sm\spedb.py", line 23, in run
    pdb.Pdb.do_break(self, str(linenbr))
    File "C:\Python23\lib\pdb.py", line 262, in do_break
    filename = self.defaultFile()
    File "C:\Python23\lib\pdb.py", line 278, in defaultFile
    filename = self.curframe.f_code.co_filename
    AttributeError: Sdb instance has no attribute 'curframe'
    Exception raised while running script <source>

    I run the program as:
    import spedb
    mainDict=__main__.__dict__
    # mainDict can also be another argument passed,
    # I think it's also locals() by default
    mainDict['codeObject']=codeObject
    spedb.run('exec codeObject in mainDict', locals(), mainDict)


    I think it's because the breakpoint it's instaured before the run, but I really
    don't know how to put the breakpoint "inside" the run.

    Furthermore, if I define the method run like:
    def run(self, statement, globals, locals):
    bdb.Bdb.run(self, statement, globals, locals)
    it does not even prompt the usual prompt (not any prompt at all...)!
    I got this:
    >>> Running 'C:\Python23\Lib\site-packages\sm\spedb.py' ...

    Script '<source>' returned exit code 0

    Could someone give me a hint about:
    1) Why it does not work?
    2) How to modify it the way I want?

    Thanks a lot.

    G

    import pdb
    import bdb

    class Sdb(bdb.Bdb,pdb.Pdb):
    def __init__(self):
    pdb.Pdb.__init__(self)
    bdb.Bdb.__init__(self)

    def run(self, statement, globals, locals):
    functions={
    '#--- break' : pdb.Pdb.do_break
    }
    lines=globals['source'].splitlines()
    linenbr=0
    for line in lines:
    linenbr+=1
    if line in functions:
    pdb.Pdb.do_break(self, str(linenbr))
    bdb.Bdb.run(self, statement, globals, locals)

    def run(statement, globals=None, locals=None):
    Sdb().run(statement, globals, locals)
    Guillermo Fernandez, Oct 16, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Chalk

    Python debugger

    Andrew Chalk, Jul 30, 2003, in forum: Python
    Replies:
    3
    Views:
    273
    Michele Simionato
    Aug 3, 2003
  2. Lothar Scholz

    Python Debugger

    Lothar Scholz, Aug 18, 2003, in forum: Python
    Replies:
    7
    Views:
    395
    Heikki Orsila
    Aug 23, 2003
  3. Maxime Biais

    Graphic python debugger

    Maxime Biais, Sep 17, 2003, in forum: Python
    Replies:
    5
    Views:
    440
    martin z
    Sep 18, 2003
  4. Robert Oschler
    Replies:
    1
    Views:
    213
    Mcginkel
    Sep 5, 2005
  5. aflat362
    Replies:
    7
    Views:
    212
    naixn
    Dec 7, 2006
Loading...

Share This Page