Пример #1
0
def profile():
    maxi = 0 
    for i in path_counts:
      for j in path_counts[i]:
	if path_counts[i][j] > maxi:
          maxi = path_counts[i][j]
	  max_edge = (i,j)           
    i,j = max_edge
    print 'max edge %d -> %d : %d' % (int(i),int(j), maxi)
    i_bb = id_to_bb_addr[i]
    j_bb = id_to_bb_addr[j]
    print '         %x -> %x '% (i_bb,j_bb)
    print '         %s -> %s ' %  (elfFile().addrs_to_f[i_bb],elfFile().addrs_to_f[j_bb]) 
    print '         context:'
    print_context(id_to_context[i])
    maxi=0
    
    for b_id in b_id_counts:
      count = b_id_counts[b_id]
      if count > maxi:
	max_id = b_id
	maxi = count
	print 't: max_id b%d, count %d' % (max_id, maxi)
    print 'max_id b%d, count %d' % (max_id, maxi)
    print 'max_bb_addr: %x' % id_to_bb_addr[str(max_id)]
    print_context(id_to_context[str(max_id)])
Пример #2
0
def profile():
    bb_addr_to_count = {}
    funs_to_bb_addrs = {}
    funs_to_count = {}
    total_inst_ran = 0
    global tcfg_to_bb_map
    maxi = 0
    for i in path_counts:
      for j in path_counts[i]:

        bb_addr = id_to_bb_addr[j]
        inst_count = path_counts[i][j] * tcfg_to_bb_map[j][1]
        total_inst_ran += inst_count
        if inst_count == 0:
            continue
        if (bb_addr not in bb_addr_to_count):
            bb_addr_to_count[bb_addr] = 0
        bb_addr_to_count[bb_addr] += inst_count

        if path_counts[i][j] > maxi:
            maxi = path_counts[i][j]
            max_edge = (i,j)

    for bb_addr in bb_addr_to_count:
        fun = elfFile().addrs_to_f[bb_addr]
        if fun not in funs_to_count:
            funs_to_count[fun] = 0
            funs_to_bb_addrs[fun] = []
        funs_to_bb_addrs[fun].append( bb_addr )
        funs_to_count[fun] += bb_addr_to_count[bb_addr]

    bb_addr_to_size = buildBBAddrToSize()
    for fun in sorted(funs_to_count, key= lambda x: funs_to_count[x], reverse=True):
        count = funs_to_count[fun]
        print "%s: %u insturctions / %.2f %%" % (fun, count, float (count) / total_inst_ran * 100)
        for bb_addr in sorted(funs_to_bb_addrs[fun]):
            print "     %x-%x : %u " % (bb_addr, bb_addr + bb_addr_to_size[bb_addr] -4, bb_addr_to_count[bb_addr])

    print "\n\n Dominating executing path:"
    i,j = max_edge
    print 'max edge %d -> %d : %d' % (int(i),int(j), maxi)
    i_bb = id_to_bb_addr[i]
    j_bb = id_to_bb_addr[j]
    print '         %x -> %x '% (i_bb,j_bb)
    print '         %s -> %s ' %  (elfFile().addrs_to_f[i_bb],elfFile().addrs_to_f[j_bb]) 
    print '         context:'
    print_context(id_to_context[i])
    maxi=0

    for b_id in b_id_counts:
      count = b_id_counts[b_id]
      if count > maxi:
	max_id = b_id
	maxi = count
	print 't: max_id b%d, count %d' % (max_id, maxi)
    print 'max_id b%d, count %d' % (max_id, maxi)
    print 'max_bb_addr: %x' % id_to_bb_addr[str(max_id)]
    
    print_context(id_to_context[str(max_id)])
Пример #3
0
def gFuncsCalled(f,fs,ignore_funs):
    g = fs[elfFile().gFunName(f)]
    call_node_indexes = [x for x in g.nodes if g.nodes[x].kind == 'Call']
    call_targs = [g.nodes[x].get_args()[0] for x in call_node_indexes]
    #rid clone subfixes
    call_targs = [x.split('.')[0] for x in call_targs]
    call_targs = [x for x in call_targs if x not in ignore_funs]

    return list(set(call_targs))
Пример #4
0
def gFuncsCalled(f, fs, ignore_funs):
    g = fs[elfFile().gFunName(f)]
    call_node_indexes = [x for x in g.nodes if g.nodes[x].kind == 'Call']
    call_targs = [g.nodes[x].get_args()[0] for x in call_node_indexes]
    #rid clone subfixes
    call_targs = [x.split('.')[0] for x in call_targs]
    call_targs = [x for x in call_targs if x not in ignore_funs]

    return list(set(call_targs))
Пример #5
0
 def __init__(self, dir_name, function_name, imm_fun, emit_as_dummy=None):
     self.function_name = function_name
     self.imm_fun = imm_fun
     self.imm_file_name = '%s/%s.imm' % (dir_name, function_name)
     self.imm_f = open(self.imm_file_name, 'w')
     self.debug_f = open('%s/d_%s.imm' % (dir_name, function_name),'w')
     self.emitted_loop_counts_file = open('%s/%s_emittedLoopCounts' % (dir_name, function_name),'w')
     self.emit_as_dummy = emit_as_dummy
     self.elf_fun_to_skip = elfFile().funcs['clean_D_PoU']
     self.skip_fun = False
Пример #6
0
def transitivelyCalled(f,cg):
    ret = set()
    vs = list(cg[f]) # copy the list
    #print '     cg[%s] : %s' % (f, cg[f])
    while vs:
       ff = elfFile().gFunName(vs.pop())
       assert '.' not in ff
       if ff not in ret and not isSpecIns(ff):
          ret.add(ff)
          vs += cg[ff]
    return ret
Пример #7
0
def transitivelyCalled(f, cg):
    ret = set()
    vs = list(cg[f])  # copy the list
    #print '     cg[%s] : %s' % (f, cg[f])
    while vs:
        ff = elfFile().gFunName(vs.pop())
        assert '.' not in ff
        if ff not in ret and not isSpecIns(ff):
            ret.add(ff)
            vs += cg[ff]
    return ret
Пример #8
0
 def __init__(self, dir_name, function_name, imm_fun, emit_as_dummy=None):
     self.function_name = function_name
     self.imm_fun = imm_fun
     self.imm_file_name = '%s/%s.imm' % (dir_name, function_name)
     self.imm_f = open(self.imm_file_name, 'w')
     self.debug_f = open('%s/d_%s.imm' % (dir_name, function_name), 'w')
     self.emitted_loop_counts_file = open(
         '%s/%s_emittedLoopCounts' % (dir_name, function_name), 'w')
     self.emit_as_dummy = emit_as_dummy
     self.elf_fun_to_skip = elfFile().funcs['clean_D_PoU']
     self.skip_fun = False
Пример #9
0
 def emitSyms (self):
     ef = elfFile()
     for name in sorted(ef.syms.keys(),key=lambda x: ef.syms[x].addr):
         flag_str = ''
         sym = ef.syms[name]
         #objects(O) in objdump is data
         if 'O' in sym.flags:
            flag_str += 'd'
            #functions are text
         if 'F' in sym.flags:
             flag_str += 't'
             self.imm_f.write('s %s 0x%s %s %s\n' % (name, sym.addr, sym.ali_size, flag_str))
Пример #10
0
 def emitSyms(self):
     ef = elfFile()
     for name in sorted(ef.syms.keys(), key=lambda x: ef.syms[x].addr):
         flag_str = ''
         sym = ef.syms[name]
         #objects(O) in objdump is data
         if 'O' in sym.flags:
             flag_str += 'd'
             #functions are text
         if 'F' in sym.flags:
             flag_str += 't'
             self.imm_f.write('s %s 0x%s %s %s\n' %
                              (name, sym.addr, sym.ali_size, flag_str))
Пример #11
0
def print_context(ctx_list):
    for x in ctx_list[:-1]:
      print '%s' % elfFile().addrs_to_f[x],
    print ''
Пример #12
0
 def emitLiterals(self):
     ef = elfFile()
     for addr in sorted(ef.literals, key=int):
         (size, value) = ef.literals[addr]
         self.imm_f.write('v %s %s %d\n' % (hex(addr), value, size))
Пример #13
0
def dot():
    print 'digraph imm {'
    for i in path_counts:
        for j in path_counts[i]:
            if i != 'Sta' and type(j) != 'Sta':
              print '%s -> %s [label = \"%d %s -> %s\"];' % (i, j, path_counts[i][j], elfFile().addrs_to_f[id_to_bb_addr[i]], elfFile().addrs_to_f[id_to_bb_addr[j]])
            else: 
              print '%s -> %s [label = \"%d\"];' % (i, j, path_counts[i][j])

    print '}'
Пример #14
0
	if argv[1].startswith ('--'):
		opt = argv[1]
		argv = argv[:1] + argv[2:]
	#print 'Reading data'
	dir_name = argv[1]
	sol_file = argv[2]
	tcfg_map_f = argv[3]
	elf_file = argv[4]
	print 'reconstruct: sol_file %s' % sol_file
	read_variables(sol_file)
	#print 'Reading tcfg'
	read_tcfg_map(tcfg_map_f)
	#print ' .. done reading'
	#initialise elfFile and parse the objdump 
	elfFile(dir_name=dir_name,elf_only=True)
	elf_parser.parseTxt()
	#print 'Simplifying'
	#simplify()
	#print ' .. done simplifying'
	if opt == '--follow':
		follow2()
	elif opt == '--dot':
		dot()
	elif opt == '--refutable':
		refutable()
	elif opt == '--profile':
		profile()
	else:
		print 'Unknown reconstruction type: %r' % opt
Пример #15
0
def preemption_limit(fout,fake_preemption_points,preempt_limit):
        #hardcoded preemption point limit
        fout.write('\ === preemption constraints === \n\n')
        preemp_addr = elfFile().funcs['preemptionPoint'].addr
        times_limit(fout,fake_preemption_points+[preemp_addr],preempt_limit)
Пример #16
0
def id_print_context(id1,ctx=None):
        if ctx==None:
                ctx = id_to_context[id1][:-1]
        for bb in ctx:
          print '%s'% elfFile().addrs_to_f[bb]
        return
Пример #17
0
def inFunLoop(addr):
  from addr_utils import gToPAddrP
  f = elfFile().addrs_to_f[addr]
  p = immFunc().f_problems[f]
  p_addr = gToPAddrP(addr,p)
  return p_addr in p.loop_data
Пример #18
0
 def emitLiterals (self):
     ef = elfFile()
     for addr in sorted(ef.literals,key=int):
         (size,value) = ef.literals[addr]
         self.imm_f.write('v %s %s %d\n'% (hex(addr),value,size))
Пример #19
0
def preemption_limit(fout, fake_preemption_points, preempt_limit):
    #hardcoded preemption point limit
    fout.write('\ === preemption constraints === \n\n')
    preemp_addr = elfFile().funcs['preemptionPoint'].addr
    times_limit(fout, fake_preemption_points + [preemp_addr], preempt_limit)
Пример #20
0
def id_print_context(id1, ctx=None):
    if ctx == None:
        ctx = id_to_context[id1][:-1]
    for bb in ctx:
        print '%s' % elfFile().addrs_to_f[bb]
    return
Пример #21
0
def inFunLoop(addr):
    from addr_utils import gToPAddrP
    f = elfFile().addrs_to_f[addr]
    p = immFunc().f_problems[f]
    p_addr = gToPAddrP(addr, p)
    return p_addr in p.loop_data