mirror of
https://github.com/python/cpython.git
synced 2025-11-17 09:30:10 +00:00
Better debugger support (show stack etc).
This commit is contained in:
parent
92a67d7847
commit
80d132deda
2 changed files with 88 additions and 11 deletions
|
|
@ -43,27 +43,50 @@ class Debugger(bdb.Bdb):
|
||||||
self.root = root = pyshell.root
|
self.root = root = pyshell.root
|
||||||
self.top = top = Toplevel(root)
|
self.top = top = Toplevel(root)
|
||||||
top.wm_protocol("WM_DELETE_WINDOW", self.close)
|
top.wm_protocol("WM_DELETE_WINDOW", self.close)
|
||||||
|
#
|
||||||
self.bframe = bframe = Frame(top)
|
self.bframe = bframe = Frame(top)
|
||||||
self.bframe.pack(anchor="w")
|
self.bframe.pack(anchor="w")
|
||||||
self.buttons = bl = []
|
self.buttons = bl = []
|
||||||
|
#
|
||||||
self.bcont = b = Button(bframe, text="Go", command=self.cont)
|
self.bcont = b = Button(bframe, text="Go", command=self.cont)
|
||||||
bl.append(b)
|
bl.append(b)
|
||||||
self.bstep = b = Button(bframe, text="Step into", command=self.step)
|
self.bstep = b = Button(bframe, text="Into", command=self.step)
|
||||||
bl.append(b)
|
bl.append(b)
|
||||||
self.bnext = b = Button(bframe, text="Step over", command=self.next)
|
self.bnext = b = Button(bframe, text="Over", command=self.next)
|
||||||
bl.append(b)
|
bl.append(b)
|
||||||
self.bret = b = Button(bframe, text="Step out", command=self.ret)
|
self.bret = b = Button(bframe, text="Out", command=self.ret)
|
||||||
bl.append(b)
|
bl.append(b)
|
||||||
|
#
|
||||||
for b in bl:
|
for b in bl:
|
||||||
b.configure(state="disabled")
|
b.configure(state="disabled")
|
||||||
b.pack(side="left")
|
b.pack(side="left")
|
||||||
|
#
|
||||||
|
self.cframe = cframe = Frame(bframe)
|
||||||
|
self.cframe.pack(side="left")
|
||||||
|
#
|
||||||
|
self.vstack = BooleanVar(top)
|
||||||
|
self.bstack = Checkbutton(cframe,
|
||||||
|
text="Stack", command=self.show_stack, variable=self.vstack)
|
||||||
|
self.bstack.grid(row=0, column=0)
|
||||||
|
self.vsource = BooleanVar(top)
|
||||||
|
self.bsource = Checkbutton(cframe,
|
||||||
|
text="Source", command=self.show_source, variable=self.vsource)
|
||||||
|
self.bsource.grid(row=0, column=0)
|
||||||
|
self.vlocals = BooleanVar(top)
|
||||||
|
self.blocals = Checkbutton(cframe,
|
||||||
|
text="Locals", command=self.show_locals, variable=self.vlocals)
|
||||||
|
self.blocals.grid(row=1, column=0)
|
||||||
|
self.vglobals = BooleanVar(top)
|
||||||
|
self.bglobals = Checkbutton(cframe,
|
||||||
|
text="Globals", command=self.show_globals, variable=self.vglobals)
|
||||||
|
self.bglobals.grid(row=1, column=1)
|
||||||
|
#
|
||||||
self.status = Label(top, anchor="w")
|
self.status = Label(top, anchor="w")
|
||||||
self.status.pack(anchor="w")
|
self.status.pack(anchor="w")
|
||||||
self.error = Label(top, anchor="w")
|
self.error = Label(top, anchor="w")
|
||||||
self.error.pack(anchor="w")
|
self.error.pack(anchor="w")
|
||||||
|
|
||||||
def interaction(self, frame, info=None):
|
def interaction(self, frame, info=None):
|
||||||
self.top.pack_propagate(0)
|
|
||||||
self.frame = frame
|
self.frame = frame
|
||||||
code = frame.f_code
|
code = frame.f_code
|
||||||
file = code.co_filename
|
file = code.co_filename
|
||||||
|
|
@ -86,11 +109,14 @@ class Debugger(bdb.Bdb):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
m1 = ""
|
m1 = ""
|
||||||
|
tb = None
|
||||||
self.error.configure(text=m1)
|
self.error.configure(text=m1)
|
||||||
if file[:1] + file[-1:] != "<>" and os.path.exists(file):
|
sv = self.stackviewer
|
||||||
edit = self.flist.open(file)
|
if sv:
|
||||||
if edit:
|
stack, i = self.get_stack(self.frame, tb)
|
||||||
edit.gotoline(lineno)
|
sv.load_stack(stack, i)
|
||||||
|
if self.vsource.get():
|
||||||
|
self.sync_source_line()
|
||||||
for b in self.buttons:
|
for b in self.buttons:
|
||||||
b.configure(state="normal")
|
b.configure(state="normal")
|
||||||
self.top.tkraise()
|
self.top.tkraise()
|
||||||
|
|
@ -101,6 +127,18 @@ class Debugger(bdb.Bdb):
|
||||||
self.error.configure(text="")
|
self.error.configure(text="")
|
||||||
self.frame = None
|
self.frame = None
|
||||||
|
|
||||||
|
def sync_source_line(self):
|
||||||
|
frame = self.frame
|
||||||
|
if not frame:
|
||||||
|
return
|
||||||
|
code = frame.f_code
|
||||||
|
file = code.co_filename
|
||||||
|
lineno = frame.f_lineno
|
||||||
|
if file[:1] + file[-1:] != "<>" and os.path.exists(file):
|
||||||
|
edit = self.flist.open(file)
|
||||||
|
if edit:
|
||||||
|
edit.gotoline(lineno)
|
||||||
|
|
||||||
def cont(self):
|
def cont(self):
|
||||||
self.set_continue()
|
self.set_continue()
|
||||||
self.root.quit()
|
self.root.quit()
|
||||||
|
|
@ -116,3 +154,30 @@ class Debugger(bdb.Bdb):
|
||||||
def ret(self):
|
def ret(self):
|
||||||
self.set_return(self.frame)
|
self.set_return(self.frame)
|
||||||
self.root.quit()
|
self.root.quit()
|
||||||
|
|
||||||
|
stackviewer = None
|
||||||
|
|
||||||
|
def show_stack(self):
|
||||||
|
if not self.stackviewer and self.vstack.get():
|
||||||
|
import StackViewer
|
||||||
|
self.stackviewer = sv = StackViewer.StackViewer(
|
||||||
|
self.top, self.flist, self)
|
||||||
|
if self.frame:
|
||||||
|
else:
|
||||||
|
sv = self.stackviewer
|
||||||
|
if sv and not self.vstack.get():
|
||||||
|
self.stackviewer = None
|
||||||
|
sv.close()
|
||||||
|
|
||||||
|
def show_source(self):
|
||||||
|
if self.vsource.get():
|
||||||
|
self.sync_source_line()
|
||||||
|
|
||||||
|
def show_frame(self, (frame, lineno)):
|
||||||
|
print frame, lineno
|
||||||
|
|
||||||
|
def show_locals(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def show_globals(self):
|
||||||
|
pass
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import string
|
import string
|
||||||
|
import getopt
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import linecache
|
import linecache
|
||||||
|
|
@ -552,8 +553,8 @@ class PyShell(PyShellEditorWindow):
|
||||||
"(sys.last_traceback is not defined)",
|
"(sys.last_traceback is not defined)",
|
||||||
master=self.text)
|
master=self.text)
|
||||||
return
|
return
|
||||||
from StackViewer import StackViewer
|
from StackViewer import StackBrowser
|
||||||
sv = StackViewer(self.root, self.flist)
|
sv = StackBrowser(self.root, self.flist)
|
||||||
|
|
||||||
def showprompt(self):
|
def showprompt(self):
|
||||||
self.resetoutput()
|
self.resetoutput()
|
||||||
|
|
@ -599,17 +600,28 @@ class PseudoFile:
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
debug = 0
|
||||||
|
try:
|
||||||
|
opts, args = getopt.getopt(sys.argv[1:], "d")
|
||||||
|
except getopt.error, msg:
|
||||||
|
sys.stderr.write("Error: %s\n" % str(msg))
|
||||||
|
sys.exit(2)
|
||||||
|
for o, a in opts:
|
||||||
|
if o == "-d":
|
||||||
|
debug = 1
|
||||||
global flist, root
|
global flist, root
|
||||||
root = Tk()
|
root = Tk()
|
||||||
fixwordbreaks(root)
|
fixwordbreaks(root)
|
||||||
root.withdraw()
|
root.withdraw()
|
||||||
flist = PyShellFileList(root)
|
flist = PyShellFileList(root)
|
||||||
if sys.argv[1:]:
|
if args:
|
||||||
for filename in sys.argv[1:]:
|
for filename in sys.argv[1:]:
|
||||||
flist.open(filename)
|
flist.open(filename)
|
||||||
t = PyShell(flist)
|
t = PyShell(flist)
|
||||||
flist.pyshell = t
|
flist.pyshell = t
|
||||||
t.begin()
|
t.begin()
|
||||||
|
if debug:
|
||||||
|
t.open_debugger()
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue