def write_interval_info(self, hwname, pclo=None, pchi=None, substage_names=[], substage_entries={}): wt = self._get_writestable(hwname) if "framac" in hwname: return [(r['destlo'], r['desthi']) for r in pytable_utils.get_rows( '(%d <= writepc) & (writepc < %d)' % (pclo, pchi))] else: fns = substage_entries substages = substage_names num = 0 intervals = {n: intervaltree.IntervalTree() for n in substages} for r in wt.read_sorted('index'): pc = r['pc'] if num < len(fns) - 1: # check if we found the entrypoint to the next stage (lopc, hipc) = substage_entries[num + 1] if (lopc <= pc) and (pc < hipc): num += 1 if num in substages: start = r['dest'] end = start + pytable_utils.get_rows( wt, 'pc == %d' % r['pc'])[0]['writesize'] intervals[num].add(intervaltree.Interval(start, end)) return intervals
def create_longwrites_table(self): self.longwritestable = self.h5file.create_table( self.group, 'longwrites', LongWrites, "long writes to precompute") skips = [] if not self.is_arm(): return r2.run_aab(self.stage.elf) # run basic block analysis for r in self.stage.longwrites: skips.append(LongWriteDescriptorGenerator(r.name, r.inplace, self)) for s in skips: r = self.longwritestable.row sdesc = s.generate_descriptor() if not sdesc: print "We didn't find any longwrite labels for %s" % s.name continue # to prevent duplicate entries query = "(breakaddrlo == 0x%x) & (breakaddrhi == 0x%x)" % \ (utils.addr_lo(sdesc.breakaddr), utils.addr_hi(sdesc.breakaddr)) descs = pytable_utils.get_rows(self.longwritestable, query) if len(descs) > 0: print "found duplicate longwrite at breakpoint 0x%x" % sdesc.breakaddr continue if not sdesc.valid: "longwrite is not value, continuing" continue sdesc.populate_row(r) if self.verbose: print sdesc.get_info() r.append() self.longwritestable.flush() self.longwritestable.cols.breakaddrlo.create_index(kind='full') self.longwritestable.cols.breakaddrhi.create_index(kind='full') self.longwritestable.flush() self.writestable.flush() self.h5file.flush()
def print_dsts_info(self): self.flush_table() num_writes = db_info.get(self.stage).num_writes() num_framac_writes = sum([len(pytable_utils.get_rows(t, "dst_not_in_ram == True")) for t in self.tables.itervalues()]) print "%d of %d writes exclusively write "\ "to register memory" % (num_framac_writes, num_writes) for t in self.tables.itervalues(): for r in t.iterrows(): print "%s (%x) -> (%x,%x). substage: %s" % \ (r['line'], r['writepc'], r['dstlo'], r['dsthi'], r['substage'])
def addr2functionname(self, addr): # print "%x -> %x %x" % (addr, utils.addr_hi(addr), utils.addr_lo(addr)) addr = long(addr) rs = pytable_utils.get_rows(self._sdb.db.funcstable, ( "(startaddrlo <= 0x%x) & (startaddrhi <= 0x%x) & (0x%x < endaddrlo) & (0x%x <= endaddrhi)" % (utils.addr_lo(addr), utils.addr_hi(addr), utils.addr_lo(addr), utils.addr_hi(addr)))) if rs: return rs[0]['fname'] else: return ''
def calculate_framac_intervals(self, substages): intervals = {n: intervaltree.IntervalTree() for n in substages} for num in substages: for r in pytable_utils.get_rows(self.trace_intervals_table, 'substagenum == %s' % num): # lookup writes performed by this function f = r['functionname'] (lopc, hipc) = self.fun_info(f) res = db_info.get(self.stage).write_interval_info( tracename, lopc, hipc) intervals[num] += intervaltree.IntervalTree( [intervaltree.Interval(r[0], r[1]) for r in res]) return intervals
def _get_write_pc_or_zero(self, dstinfo): framac = True startlineaddr = self._get_line_addr(dstinfo.key(), True, framac) endlineaddr = self._get_line_addr(dstinfo.key(), False, framac) if (startlineaddr < 0) or (endlineaddr < 0): return 0 query = "(0x%x <= pclo) & (0x%x <= pchi) & (pclo < 0x%x) & (pchi <= 0x%x)" % \ (utils.addr_lo(startlineaddr), utils.addr_hi(startlineaddr), utils.addr_lo(endlineaddr), utils.addr_hi(endlineaddr)) write = pytable_utils.get_rows(self.writestable, query) if len(write) == 1: return write[0]['pc'] else: print "0 or more than 1 write (%d) in %s" % (len(write), query) #raise Exception('?') # either 0 or more than zero results return 0
def function_locations(self, name): return [(r['startaddr'], r['endaddr']) for r in pytable_utils.get_rows(self._sdb.db.funcstable, 'fname == b"%s"' % name)]
def print_substage_tables(self): self.h5mmap.flush() print '----------regions----------' self.print_regions(self.substage_mmap_info_table, self.substage_mmap_addr_table) print '----------substages----------' substages = self._substage_numbers() for num in substages: for s in pytable_utils.get_rows(self.substage_info_table, 'substagenum == %s' % num): print 'Substage %s (%s) (name=%s) stack=%s type=%s' % \ (s['substagenum'], s['functionname'], s['name'], s['stack'], substage_types(s['substage_type'])) print '----------policies----------' for num in substages: print '-----for substage %s (%s) ----' % ( num, self._substage_names()[num]) new = set() defined = set() undefined = set() writable = set() reclassified = set() allregions = set() for s in self.substage_region_policy_table.iterrows(): name = s['short_name'] allregions.add(name) if s['substagenum'] == num: if s['defined'] and s['do_print']: defined.add(name) if s['new'] and s['do_print']: new.add(name) if s['reclassified'] and s['do_print']: reclassified.add(name) if s['writable'] and s['do_print']: writable.add(name) if s['undefined'] and s['do_print']: undefined.add(name) used = new | defined | writable | reclassified unusedregions = allregions - used print '%s total regions: %s new, %s defined -> %s writable | %s not writable' % \ (len(allregions), len(new), len(defined), len(writable), len(unusedregions)) rowinfo = {} for s in pytable_utils.get_rows(self.substage_region_policy_table, 'substagenum == %s' % (num)): name = s['short_name'] rowinfo[name] = (region_types(s['region_type']), perms(s['default_perms'])) ds = ', '.join([ '(%s, %s, %s)' % (r, rowinfo[r][0], rowinfo[r][1]) for r in defined ]) ns = ', '.join([ '(%s, %s, %s)' % (r, rowinfo[r][0], rowinfo[r][1]) for r in new ]) us = ', '.join([ '(%s, %s, %s)' % (r, rowinfo[r][0], rowinfo[r][1]) for r in undefined ]) ws = ', '.join([ '(%s, %s, %s)' % (r, rowinfo[r][0], rowinfo[r][1]) for r in writable ]) cs = ', '.join([ '(%s, %s, %s)' % (r, rowinfo[r][0], rowinfo[r][1]) for r in reclassified ]) ds = ds if ds else "[]" ns = ns if ns else "[]" us = us if us else "[]" ws = ws if ws else "[]" cs = cs if ds else "[]" if ds: print 'defined regions: %s' % ds if ns: print 'new regions: %s' % ns if us: print 'undefined regions: %s' % us if cs: print 'reclassified regions: %s' % cs if ws: print 'writable regions: %s' % ws