view/source.py

Go to the documentation of this file.
00001 # Copyright (c) 2006 Cristian L. Vlasceanu
00002 #
00003 # Permission is hereby granted, free of charge, to any person
00004 # obtaining a copy of this software and associated documentation
00005 # files (the "Software"), to deal in the Software without
00006 # restriction, including without limitation the rights to use,
00007 # copy, modify, merge, publish, distribute, sublicense, and/or
00008 # sell copies of the Software, and to permit persons to whom
00009 # the Software is furnished to do so, subject to the following
00010 # conditions:
00011 # 
00012 # The above copyright notice and this permission notice shall be
00013 # included in all copies or substantial portions of the Software.
00014 # 
00015 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
00016 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
00017 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00018 # AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00019 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00020 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00021 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
00022 # OR OTHER DEALINGS IN THE SOFTWARE.
00023 # 
00024 # NOTE: The above applies solely to Python source code provided 
00025 # herein, and it DOES NOT COVER the Zero Debugger Engine and plug-ins.
00026 #
00027 from code import Code
00028 import zero
00029 
00030 
00031 class Source(Code):
00032         def __init__(self, win):
00033                 Code.__init__(self, win)
00034 
00035 
00036         def read_file(self, thread, addr, sym, brkpoints):
00037                 assert sym
00038                 filename = sym.filename()
00039                 f = open(filename)
00040                 line = f.readline()
00041                 lineNum = 0
00042                 model = self._Code__model
00043                 model.clear()
00044                 while line:
00045                         lineNum += 1
00046                         iter = model.append()
00047                         for b in brkpoints:
00048                                 sym = b.symbol()
00049                                 if sym.filename() == filename and sym.line() == lineNum:
00050                                         self.__set_visual_breakpoint(model, iter, b)
00051                                         self._Code__breakpoints[b.addr()] = b
00052                         model.set_value(iter, 1, lineNum)
00053                         model.set_value(iter, 2, line.strip("\n"))
00054                         line = f.readline()
00055                 f.close()
00056 
00057 
00058         def __set_visual_breakpoint(self, model, iter, bkpoint):
00059                 model.set_value(iter, 0, self._Code__stop)      
00060 
00061 
00062         def get_addresses(self, iter):
00063                 lineNum = int(self._Code__model.get_value(iter, 1))
00064                 #convert line number to addresses:
00065                 addrs = zero.debugger().line_to_addr(self.filename(), lineNum)
00066                 return addrs
00067