Package vwidget :: Module vwvtrace
[hide private]
[frames] | no frames]

Source Code for Module vwidget.vwvtrace

  1  import envi.memory as e_mem 
  2  import vtrace 
  3  import gtk 
  4  import vwidget.views as vw_views 
  5   
  6  from envi.threads import firethread 
  7  from vwidget.main import idlethread, idlethreadsync 
8 9 -class VtraceView:
10 - def __init__(self, trace):
11 self.trace = trace
12
13 - def setTrace(self, trace):
14 self.trace = trace
15
16 - def traceIsReady(self):
17 if self.trace.isAttached() and not self.trace.isRunning(): 18 return True 19 return False
20
21 -class ProcessListView(VtraceView, vw_views.VTreeView):
22 __cols__ = ( 23 (None, 0, object), 24 ("Pid", 1, int), 25 ("Name", 2, str), 26 ) 27
28 - def __init__(self, trace):
29 VtraceView.__init__(self, trace) 30 vw_views.VTreeView.__init__(self)
31
32 - def vwLoad(self):
33 self.vwClear() 34 for pid,name in self.trace.ps(): 35 self.model.append((None,pid,name))
36
37 -class SelectProcessDialog(gtk.Dialog):
38 - def __init__(self, trace):
39 buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK) 40 gtk.Dialog.__init__(self, "Select a process...", buttons=buttons) 41 self.proclist = ProcessListView(trace) 42 self.vbox.pack_start(self.proclist, expand=True) 43 self.proclist.treeview.connect("row_activated", self.procListActivated) 44 self.proclist.treeview.connect("cursor_changed", self.procListSelected) 45 self.pid = None 46 self.resize(300, 600)
47
48 - def procListActivated(self, *args):
49 self.response(gtk.RESPONSE_OK)
50
51 - def procListSelected(self, *args):
52 self.pid = self.proclist.vwGetSelected(1)
53
54 - def selectProcess(self):
55 self.show_all() 56 resp = self.run() 57 self.hide() 58 if resp == gtk.RESPONSE_OK: 59 return self.pid 60 return None
61
62 -class TraceToolBar(gtk.Toolbar, vtrace.Notifier):
63 - def __init__(self, trace):
64 gtk.Toolbar.__init__(self) 65 vtrace.Notifier.__init__(self) 66 self.trace = trace 67 self.battach = gtk.ToolButton(gtk.STOCK_ADD) 68 self.bdetach = gtk.ToolButton(gtk.STOCK_REMOVE) 69 self.bcontin = gtk.ToolButton(gtk.STOCK_MEDIA_PLAY) 70 self.bbreak = gtk.ToolButton(gtk.STOCK_MEDIA_PAUSE) 71 self.bstep = gtk.ToolButton(gtk.STOCK_GO_FORWARD) 72 #self.bstepo = gtk.ToolButton(gtk.STOCK_GOTO_LAST) 73 74 self.battach.connect("clicked", self.attach) 75 self.battach.set_property("label", "Attach") 76 self.bdetach.connect("clicked", self.detach) 77 self.bdetach.set_property("label", "Detach") 78 self.bcontin.connect("clicked", self.tcontinue) 79 self.bcontin.set_property("label", "Continue") 80 self.bbreak.connect("clicked", self.tbreak) 81 self.bbreak.set_property("label", "Break") 82 self.bstep.connect("clicked", self.tstep) 83 self.bstep.set_property("label", "Step") 84 #self.bstepo.connect("clicked", self.tstep) 85 #self.bstepo.set_property("label", "Step Over") 86 87 self.insert(self.battach, -1) 88 self.insert(self.bdetach, -1) 89 self.insert(self.bcontin, -1) 90 self.insert(self.bbreak, -1) 91 self.insert(self.bstep, -1) 92 93 self.wantsnotattached = [self.battach,] 94 self.wantsrunning = [self.bbreak,] 95 self.wantsnotrunning = [self.bdetach,self.bcontin, self.bstep] 96 97 trace.registerNotifier(vtrace.NOTIFY_ALL, self) 98 99 self.updateButtons(trace.isAttached(), trace.isRunning()) 100 101 self.activateList(self.wantsrunning, True) 102 self.activateList(self.wantsnotrunning, True) 103 self.activateList(self.wantsnotattached, True)
104 105 @idlethread
106 - def updateButtons(self, attached, running):
107 self.activateList(self.wantsnotattached, not attached) 108 if attached: 109 self.activateList(self.wantsrunning, running) 110 self.activateList(self.wantsnotrunning, not running) 111 else: 112 self.activateList(self.wantsrunning, False) 113 self.activateList(self.wantsnotrunning, False)
114
115 - def activateList(self, objs, sens):
116 for o in objs: 117 o.set_sensitive(sens)
118 119 @firethread
120 - def tstep(self, button):
121 self.trace.stepi()
122 123 @firethread
124 - def tbreak(self, button):
125 if self.trace.getMeta('PendingBreak'): 126 return 127 self.trace.setMeta('PendingBreak', True) 128 self.trace.sendBreak()
129 130 @firethread
131 - def tcontinue(self, button):
132 self.trace.run()
133
134 - def attach(self, button):
135 dia = SelectProcessDialog(self.trace) 136 pid = dia.selectProcess() 137 if pid != None: 138 self._doattach(pid)
139 140 @firethread
141 - def _doattach(self, pid):
142 self.trace.attach(pid)
143 144 @firethread
145 - def detach(self, button):
146 if self.trace.isAttached(): 147 self.trace.detach()
148
149 - def notify(self, event, trace):
150 if event == vtrace.NOTIFY_DETACH: 151 self.updateButtons(False, False) 152 153 elif event == vtrace.NOTIFY_CONTINUE: 154 self.updateButtons(True, True) 155 156 else: 157 self.updateButtons(trace.isAttached(), trace.shouldRunAgain())
158
159 -class MemoryMapView(VtraceView, vw_views.VTreeView):
160 __cols__ = ( 161 (None, 0, int), 162 ("Base", 1, str), 163 ("Size", 2, int), 164 ("Perms", 3, str), 165 ("File", 4, str), 166 ) 167
168 - def __init__(self, trace):
169 VtraceView.__init__(self, trace) 170 vw_views.VTreeView.__init__(self)
171
172 - def vwLoad(self):
173 if self.traceIsReady(): 174 self.vwClear() 175 maps = self.trace.getMemoryMaps() 176 for base,size,perms,fname in maps: 177 pname = e_mem.reprPerms(perms) 178 self.model.append((base, "0x%.8x" % base, size, pname, fname))
179
180 -class FileDescView(VtraceView, vw_views.VTreeView):
181 __cols__ = ( 182 (None, 0, object), 183 ("Fd", 1, str), 184 ("Type", 2, int), 185 ("Name", 3, str), 186 ) 187
188 - def __init__(self, trace):
189 VtraceView.__init__(self, trace) 190 vw_views.VTreeView.__init__(self)
191
192 - def vwLoad(self):
193 if self.traceIsReady(): 194 self.vwClear() 195 for fd,fdtype,bestname in self.trace.getFds(): 196 self.model.append((None, fd, fdtype, bestname))
197