view/stack.py

Go to the documentation of this file.
00001 # Stack View
00002 #
00003 # Copyright (c) 2006 Cristian L. Vlasceanu
00004 #
00005 # Permission is hereby granted, free of charge, to any person
00006 # obtaining a copy of this software and associated documentation
00007 # files (the "Software"), to deal in the Software without
00008 # restriction, including without limitation the rights to use,
00009 # copy, modify, merge, publish, distribute, sublicense, and/or
00010 # sell copies of the Software, and to permit persons to whom
00011 # the Software is furnished to do so, subject to the following
00012 # conditions:
00013 # 
00014 # The above copyright notice and this permission notice shall be
00015 # included in all copies or substantial portions of the Software.
00016 # 
00017 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
00018 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
00019 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00020 # AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00021 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00022 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00023 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
00024 # OR OTHER DEALINGS IN THE SOFTWARE.
00025 # 
00026 # NOTE: The above applies solely to Python source code provided 
00027 # herein, and it DOES NOT COVER the Zero Debugger Engine and plug-ins.
00028 #
00029 import gobject
00030 import gtk
00031 from base import Base
00032 
00033 class Stack(Base):
00034         """
00035         Stack Trace View
00036         """
00037         __gsignals__ = {
00038                 "selection-changed" : ( 
00039                         gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (
00040                                 gobject.TYPE_PYOBJECT, 
00041                                 gobject.TYPE_PYOBJECT,) )
00042         }
00043         def __init__(self, tree):
00044                 Base.__init__(self)
00045                 self.__trace = None
00046                 self.__thread = None
00047 
00048                 #the first column holds the stack frame and it is not shown in the view
00049                 self.__model = gtk.ListStore(
00050                         gobject.TYPE_PYOBJECT,
00051                         gobject.TYPE_STRING, 
00052                         gobject.TYPE_STRING, 
00053                         gobject.TYPE_STRING)
00054 
00055                 if tree:
00056                         tree.set_model(self.__model)
00057                         renderer = gtk.CellRendererText()
00058                         tree.append_column(gtk.TreeViewColumn("Address", renderer, text=1))
00059                         tree.append_column(gtk.TreeViewColumn("Location", renderer, text=2))
00060                         tree.append_column(gtk.TreeViewColumn("Function", renderer, text=3))
00061                         tree.get_column(0).set_resizable(True)
00062                         tree.get_column(1).set_resizable(True)
00063                         tree.get_selection().connect("changed", self.on_selection_changed)
00064                         tree.get_selection().set_mode(gtk.SELECTION_SINGLE)
00065 
00066 
00067         def update(self, event):
00068                 self.__thread = event.thread()
00069                 self.__trace = event.thread().stack_trace()
00070                 model = self.__model
00071                 model.clear()
00072                 for frame in self.__trace.frames():
00073                         iter = model.append()
00074                         model.set_value(iter, 0, frame)
00075                         model.set_value(iter, 1, hex(frame.program_count()))
00076                         sym = frame.function()
00077                         if sym:
00078                                 if sym.line():
00079                                         s = "%s:%d" % (sym.filename(), sym.line())
00080                                 else:
00081                                         s = sym.filename()
00082                                 model.set_value(iter, 2, s)
00083                                 model.set_value(iter, 3, sym.demangle())
00084 
00085 
00086         def clear(self):
00087                 self.__model.clear()
00088 
00089 
00090         def on_selection_changed(self, sel):
00091                 ###get_selected_rows() is not available in Pygtk 2.0
00092                 #model, paths = sel.get_selected_rows()
00093                 #if len(paths):
00094                 #       assert len(paths) == 1
00095                 #       iter = model.get_iter(paths[0])
00096                 model, iter = sel.get_selected()
00097                 if iter:
00098                         frame = model.get_value(iter, 0)
00099                         if frame:
00100                                 self.__trace.select_frame(frame.index())
00101                                 self.emit('selection-changed', self.__thread, frame)
00102 
00103 
00104 gobject.type_register(Stack)