summaryrefslogtreecommitdiffstats
path: root/Tools/idle/Debugger.py
blob: 3a16a120ee2ab0c3ea7c698b9e0ff3b262d84bc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import bdb
import traceback
from Tkinter import *


class Debugger(bdb.Bdb):
    
    def __init__(self, pyshell):
        bdb.Bdb.__init__(self)
        self.pyshell = pyshell
        self.make_gui()
    
    def close(self):
        self.top.destroy()

    def user_line(self, frame):
        self.interaction(frame)

    def user_return(self, frame, rv):
        # XXX show rv?
        self.interaction(frame)

    def user_exception(self, frame, info):
        self.interaction(frame, info)
    
    def make_gui(self):
        pyshell = self.pyshell
        self.flist = pyshell.flist
        self.root = root = pyshell.root
        self.top = top = Toplevel(root)
        self.bframe = bframe = Frame(top)
        self.bframe.pack()
        self.buttons = bl = []
        self.bcont = b = Button(bframe, text="Go", command=self.cont)
        bl.append(b)
        self.bstep = b = Button(bframe, text="Step into", command=self.step)
        bl.append(b)
        self.bnext = b = Button(bframe, text="Step over", command=self.next)
        bl.append(b)
        self.bret = b = Button(bframe, text="Step out", command=self.ret)
        bl.append(b)
        for b in bl:
            b.configure(state="disabled")
            b.pack(side="left")
        self.status = Label(top)
        self.status.pack()
    
    def interaction(self, frame, info=None):
        self.frame = frame
        code = frame.f_code
        file = code.co_filename
        lineno = frame.f_lineno
        message = "file=%s, name=%s, line=%s" % (file, code.co_name, lineno)
        if info:
            type, value, tb = info
            m1 = "%s" % str(type)
##            if value is not None:
##                try:
##                    m1 = "%s: %s" % (m1, str(value))
##                except:
##                    pass
            message = "%s\n%s" % (message, m1)
        self.status.configure(text=message)
        if file[:1] + file[-1:] != "<>" and os.path.exists(file):
            edit = self.flist.open(file)
            if edit:
                edit.gotoline(lineno)
        for b in self.buttons:
            b.configure(state="normal")
        self.top.tkraise()
        self.root.mainloop()
        for b in self.buttons:
            b.configure(state="disabled")
        self.status.configure(text="")
        self.frame = None
    
    def cont(self):
        self.set_continue()
        self.root.quit()
        
    def step(self):
        self.set_step()
        self.root.quit()
    
    def next(self):
        self.set_next(self.frame)
        self.root.quit()
    
    def ret(self):
        self.set_return(self.frame)
        self.root.quit()