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\li b\site-packages\sm\scr iptutils.py", line 52, in run
sdb.run('exec codeObject in mainDict', locals(), mainDict)
File "C:\Python23\li b\site-packages\sm\spe db.py", line 29, in run
Sdb().run(state ment, globals, locals)
File "C:\Python23\li b\site-packages\sm\spe db.py", line 23, in run
pdb.Pdb.do_brea k(self, str(linenbr))
File "C:\Python23\li b\pdb.py", line 262, in do_break
filename = self.defaultFil e()
File "C:\Python23\li b\pdb.py", line 278, in defaultFile
filename = self.curframe.f _code.co_filena me
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(sel f, statement, globals, locals)
it does not even prompt the usual prompt (not any prompt at all...)!
I got this:[color=blue][color=green][color=darkred]
>>> Running 'C:\Python23\Li b\site-packages\sm\spe db.py' ...[/color][/color][/color]
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_brea k
}
lines=globals['source'].splitlines()
linenbr=0
for line in lines:
linenbr+=1
if line in functions:
pdb.Pdb.do_brea k(self, str(linenbr))
bdb.Bdb.run(sel f, statement, globals, locals)
def run(statement, globals=None, locals=None):
Sdb().run(state ment, globals, locals)
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\li b\site-packages\sm\scr iptutils.py", line 52, in run
sdb.run('exec codeObject in mainDict', locals(), mainDict)
File "C:\Python23\li b\site-packages\sm\spe db.py", line 29, in run
Sdb().run(state ment, globals, locals)
File "C:\Python23\li b\site-packages\sm\spe db.py", line 23, in run
pdb.Pdb.do_brea k(self, str(linenbr))
File "C:\Python23\li b\pdb.py", line 262, in do_break
filename = self.defaultFil e()
File "C:\Python23\li b\pdb.py", line 278, in defaultFile
filename = self.curframe.f _code.co_filena me
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(sel f, statement, globals, locals)
it does not even prompt the usual prompt (not any prompt at all...)!
I got this:[color=blue][color=green][color=darkred]
>>> Running 'C:\Python23\Li b\site-packages\sm\spe db.py' ...[/color][/color][/color]
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_brea k
}
lines=globals['source'].splitlines()
linenbr=0
for line in lines:
linenbr+=1
if line in functions:
pdb.Pdb.do_brea k(self, str(linenbr))
bdb.Bdb.run(sel f, statement, globals, locals)
def run(statement, globals=None, locals=None):
Sdb().run(state ment, globals, locals)