Package vwidget
[hide private]
[frames] | no frames]

Source Code for Package vwidget

  1  
 
  2  import gtk 
  3  import gobject 
  4  from gtk import gdk 
  5  
 
  6  blue = (0, 0, 0x99) 
  7  green =  (0, 0xff, 0) 
  8  yellow = (0xff, 0xff, 0) 
  9  orange = (0xff, 0x66, 0) 
 10  red = (0xff, 0, 0) 
 11  
 
12 -class VWidget(gtk.Widget):
13 - def __init__(self, dheight=300, dwidth=20):
14 self._dheight = dheight 15 self._dwidth = dwidth 16 gtk.Widget.__init__(self) 17 self._layout = self.create_pango_layout("")
18
19 - def do_realize(self):
20 self.set_flags(self.flags() | gtk.REALIZED) 21 22 self.window = gdk.Window(self.get_parent_window(), 23 width=20, 24 height=self.allocation.height, 25 window_type=gdk.WINDOW_CHILD, 26 wclass=gdk.INPUT_OUTPUT, 27 event_mask=self.get_events() | gdk.EXPOSURE_MASK | gdk.BUTTON_PRESS_MASK 28 ) 29 self.window.set_user_data(self) 30 self.style.attach(self.window) 31 self.style.set_background(self.window, gtk.STATE_NORMAL)
32
33 - def do_unrealize(self):
34 self.window.set_user_data(None)
35
36 - def do_size_request(self, req):
37 req.width = self._dwidth 38 req.height = self._dheight
39
40 - def do_size_allocate(self, alloc):
41 self.allocation = alloc 42 if self.flags() & gtk.REALIZED: 43 self.window.move_resize(*alloc)
44
45 -class RefView(VWidget):
46 """ 47 Render a box which draws arrows for references between 48 "locations" in it's known address space. 49 """
50 - def __init__(self, base, size, refs):
51 VWidget.__init__(self) 52 self.updateRefs(base, size, refs)
53
54 - def inRange(self, addr):
55 if addr < self.base: 56 return False 57 if addr >= self.base + self.size: 58 return False 59 return True
60
61 - def updateRefs(self, base, size, refs):
62 self.base = base 63 self.size = size 64 self.refs = [] 65 self.deps = [] 66 for r in refs: 67 fromus = self.inRange(r[0]) 68 tous = self.inRange(r[1]) 69 if fromus and tous: 70 self.refs.insert(0, r) 71 72 elif not fromus and not tous: 73 continue 74 75 else: 76 self.refs.append(refs) 77 78 for i in range(len(self.refs)): 79 depth = 2 80 r = self.refs[i] 81 for j in range(i, 0, -1): 82 if self.isOverlap(r, self.refs[j]): 83 depth += 2 84 85 if self.flags() & gtk.REALIZED: 86 self.move_resize(*self.allocation)
87
88 - def do_expose_event(self, event):
89 x, y, w, h = self.allocation 90 cr = self.window.cairo_create() 91 # Fill the whole thing in black 92 93 cr.set_source_rgb(0, 0, 0) 94 cr.rectangle(0, 0, h, w) 95 cr.fill() 96 97 for base,size,color,text in self.spaces: 98 start = ((base-self.min) * h) / self.range 99 size = ((size * h) / self.range) + 1 100 cr.rectangle(0, start, w, size) 101 cr.set_source_rgb(*color) 102 cr.fill() 103 104 cr.update_layout(self._layout) 105 cr.show_layout(self._layout)
106
107 -class SpaceView(VWidget):
108 """ 109 Render a potentially sparse space which may be backed by varied 110 types of maps/pages/etc. 111 """
112 - def __init__(self, spaces, dheight=300, dwidth=20):
113 """ 114 Render a list of "spaces". These are a list of tuples 115 with the following contents (<base>,<len>,<color_tuple>,<text>). 116 """ 117 VWidget.__init__(self, dheight=dheight, dwidth=dwidth) 118 self.updateSpaces(spaces)
119
120 - def updateSpaces(self, spaces):
121 self.spaces = spaces 122 123 # Find out the range we're dealing with 124 min = 0xffffffff 125 max = 0 126 for base,size,color,text in self.spaces: 127 if base < min: 128 min = base 129 end = base+size 130 if end > max: 131 max = end 132 133 # Setup our size parameters 134 self.min = min 135 self.max = max 136 self.range = max - min 137 138 if self.flags() & gtk.REALIZED: 139 self.queue_draw()
140
141 - def goto(self, value):
142 # Extend and over-ride this for location callbacks 143 pass
144
145 - def do_button_press_event(self, event):
146 x, y, w, h = self.allocation 147 clickx, clicky = event.get_coords() 148 off = float(clicky * self.range) / float(h) 149 self.goto(self.min + int(off)) 150 return True
151
152 - def do_expose_event(self, event):
153 x, y, w, h = self.allocation 154 cr = self.window.cairo_create() 155 # Fill the whole thing in black 156 157 cr.set_source_rgb(0, 0, 0) 158 cr.rectangle(0, 0, h, w) 159 cr.fill() 160 161 for base,size,color,text in self.spaces: 162 start = ((base-self.min) * h) / self.range 163 size = ((size * h) / self.range) + 1 164 cr.rectangle(0, start, w, size) 165 cr.set_source_rgb(*color) 166 cr.fill() 167 168 cr.update_layout(self._layout) 169 cr.show_layout(self._layout)
170
171 - def shutdown(self, *args):
172 gtk.main_quit()
173 174 gobject.type_register(SpaceView) 175 gobject.type_register(RefView) 176 177 cmap = { 4: red, 178 6: blue, 179 5: orange } 180
181 -def spacesForMaps(mapobj):
182 """ 183 Return a set of "spaces" for each of the maps 184 returned by the getMemoryMaps() api (for emu or trace). 185 """ 186 spaces = [] 187 for base,size,perms,fname in mapobj.getMemoryMaps(): 188 spaces.append((base,size,cmap.get(perms, yellow),fname)) 189 return spaces
190
191 -def spacesForWin32HeapSegment(segment):
192 spaces = [] 193 for chunk in segment.getChunks(): 194 if chunk.isBusy(): 195 color = (0xff, 0, 0) 196 else: 197 color = (0, 0xff, 0) 198 spaces.append((chunk.address, len(chunk), color, "stuff")) 199 200 return spaces
201