view/disasm.py

Go to the documentation of this file.
00001 #
00002 #Copyright (c) 2006 Cristian L. Vlasceanu
00003 #
00004 # Permission is hereby granted, free of charge, to any person
00005 # obtaining a copy of this software and associated documentation
00006 # files (the "Software"), to deal in the Software without
00007 # restriction, including without limitation the rights to use,
00008 # copy, modify, merge, publish, distribute, sublicense, and/or
00009 # sell copies of the Software, and to permit persons to whom
00010 # the Software is furnished to do so, subject to the following
00011 # conditions:
00012 # 
00013 # The above copyright notice and this permission notice shall be
00014 # included in all copies or substantial portions of the Software.
00015 # 
00016 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
00017 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
00018 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00019 # AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00020 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00021 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00022 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
00023 # OR OTHER DEALINGS IN THE SOFTWARE.
00024 # 
00025 # NOTE: The above applies solely to Python source code provided 
00026 # herein, and it DOES NOT COVER the Zero Debugger Engine and plug-ins.
00027 #
00028 from code import Code
00029 import zero
00030 
00031 
00032 class Disasm(Code):
00033         """
00034         Specialized Code view for showing disassembly
00035         """
00036         def __init__(self, win):
00037                 Code.__init__(self, win)
00038                 self.__line_to_addr = None
00039                 self.__addr_to_line = None
00040 
00041         def read_file(self, thread, addr, sym, brkpoints):
00042                 addr -= 128
00043                 start = thread.symbols().lookup(addr)
00044                 if start:
00045                         start = thread.symbols().lookup(start.addr() - start.offset())
00046                 if not start:
00047                         start = sym
00048                 model = self._Code__model
00049                 model.clear()
00050                 self.__line_to_addr = {}
00051                 self.__addr_to_line = {}
00052                 line_num = 0
00053                 for line in thread.disassemble(start, 256, zero.Disasm.WithSource):
00054                         addr = line[0]
00055                         self.__line_to_addr[line_num] = addr
00056                         self.__addr_to_line[addr] = line_num
00057                         iter = model.append()
00058                         model.set_value(iter, 1, hex(addr))
00059                         try:
00060                                 asm = line[1].split(":")[1].split("\t")
00061                                 model.set_value(iter, 2, asm[1])
00062                                 model.set_value(iter, 3, asm[2])
00063                         except:
00064                                 asm = line[1].split(" ")[-1]
00065                                 model.set_value(iter, 2, asm)
00066                         line_num += 1
00067 
00068 
00069         def set_current_line(self, addr, line):
00070                 try:
00071                         line = self.__addr_to_line[addr]
00072                         super(Disasm, self).set_current_line(addr, line)
00073                 except KeyError:
00074                         pass
00075 
00076         def get_addresses(self, iter):
00077                 a = long(self._Code__model.get_value(iter, 1), 16)
00078                 return [a,]
00079