本文整理汇总了Python中target_objects.trace函数的典型用法代码示例。如果您正苦于以下问题:Python trace函数的具体用法?Python trace怎么用?Python trace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了trace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_split_limit
def find_split_limit (p, n, restrs, hyps, kind, bound = 51, must_find = True,
hints = [], use_rep = None):
tag = p.node_tags[n][0]
trace ('Finding split limit: %d (%s) %s' % (n, tag, restrs))
trace (' (restrs = %s)' % (restrs, ))
trace (' (hyps = %s)' % (hyps, ), push = 1)
if use_rep == None:
rep = mk_graph_slice (p, fast = True)
else:
rep = use_rep
check_order = hints + [i for i in split_sample_set (bound)
if i not in hints]
for i in check_order:
restrs2 = restrs + ((n, VisitCount (kind, i)), )
pc = rep.get_pc ((n, restrs2))
restrs3 = restr_others (p, restrs2, 2)
epc = rep.get_pc (('Err', restrs3), tag = tag)
hyp = mk_implies (mk_not (epc), mk_not (pc))
if rep.test_hyp_whyps (hyp, hyps):
trace ('split limit found: %d' % i, push = -1)
return i
trace ('No split limit found for %d (%s).' % (n, tag), push = -1)
if must_find:
assert not 'split limit found'
return None
示例2: expr_eval_before
def expr_eval_before (n2, expr):
if expr.kind == 'Op':
if expr.vals == []:
return (set(), expr)
vals = [expr_eval_before (n2, v)
for v in expr.vals]
if None in vals:
return None
s = set.union (* [s for (s, v) in vals])
if len(s) > 1:
if diag:
trace ('too many vars for %s @ %d: %s' % (expr, n2, s))
return None
return (s, Expr ('Op', expr.typ,
name = expr.name,
vals = [v for (s, v) in vals]))
elif expr.kind == 'Num':
return (set(), expr)
elif expr.kind == 'Var':
return var_eval_before (n2,
(expr.name, expr.typ))
else:
if diag:
trace ('Unwalkable expr %s' % expr)
return None
示例3: build_rodata
def build_rodata (rodata_stream):
rodata = {}
for line in rodata_stream:
if not is_rodata_line.match (line):
continue
bits = line.split ()
rodata[int (bits[0][:-1], 16)] = int (bits[1], 16)
rodata_min = min (rodata.keys ())
rodata_max = max (rodata.keys ()) + 4
assert rodata_min % 4 == 0
rodata_range = range (rodata_min, rodata_max, 4)
for x in rodata_range:
if x not in rodata:
trace ('.rodata section gap at address %x' % x)
struct_name = fresh_name ('rodata', structs)
struct = Struct (struct_name, rodata_max - rodata_min, 1)
structs[struct_name] = struct
(start, end) = sections['.rodata']
assert start <= rodata_min
assert end + 1 >= rodata_max
return (rodata, mk_word32 (rodata_min), struct.typ)
示例4: do_loop_analysis
def do_loop_analysis(self):
entries = [e for (e, tag, nm, args) in self.entries]
self.loop_data = {}
graph = self.mk_node_graph()
comps = logic.tarjan(graph, entries)
self.tarjan_order = []
for (head, tail) in comps:
self.tarjan_order.append(head)
self.tarjan_order.extend(tail)
if not tail and head not in graph[head]:
continue
trace("Loop (%d, %s)" % (head, tail))
loop_set = set(tail)
loop_set.add(head)
r = self.force_single_loop_return(head, loop_set)
if r != None:
tail.append(r)
loop_set.add(r)
self.tarjan_order.append(r)
self.compute_preds()
self.loop_data[head] = ("Head", loop_set)
for t in tail:
self.loop_data[t] = ("Mem", head)
# put this in first-to-last order.
self.tarjan_order.reverse()
示例5: save_bound
def save_bound(glob, split_bin_addr, call_ctxt, prob_hash, prev_bounds, bound, time=None):
f_names = [trace_refute.get_body_addrs_fun(x) for x in call_ctxt + [split_bin_addr]]
loop_name = "<%s>" % " -> ".join(f_names)
comment = "# bound for loop in %s:" % loop_name
ss = ["LoopBound"] + serialise_bound(split_bin_addr, bound)
if glob:
ss[0] = "GlobalLoopBound"
ss += [str(len(call_ctxt))] + map(hex, call_ctxt)
ss += [str(prob_hash)]
if glob:
assert prev_bounds == None
else:
ss += [str(len(prev_bounds))]
for (split, bound) in prev_bounds:
ss += serialise_bound(split, bound)
s = " ".join(ss)
f = open("%s/LoopBounds.txt" % target_objects.target_dir, "a")
f.write(comment + "\n")
f.write(s + "\n")
if time != None:
ctxt2 = call_ctxt + [split_bin_addr]
ctxt2 = " ".join([str(len(ctxt2))] + map(hex, ctxt2))
f.write("LoopBoundTiming %s %s\n" % (ctxt2, time))
f.close()
trace("Found bound %s for 0x%x in %s." % (bound, split_bin_addr, loop_name))
示例6: v_eqs_to_split
def v_eqs_to_split (p, pair, v_eqs, restrs, hyps, tags = None):
trace ('v_eqs_to_split: (%s, %s)' % pair)
((l_n, l_init, l_step), (r_n, r_init, r_step)) = pair
l_details = (l_n, (l_init, l_step), mk_seq_eqs (p, l_n, l_step, True)
+ [v_i[0] for (v_i, v_j) in v_eqs if v_j == 'Const'])
r_details = (r_n, (r_init, r_step), mk_seq_eqs (p, r_n, r_step, False)
+ c_memory_loop_invariant (p, r_n, l_n))
eqs = [(v_i[0], mk_cast (v_j[0], v_i[0].typ))
for (v_i, v_j) in v_eqs if v_j != 'Const']
n = 2
split = (l_details, r_details, eqs, n, (n * r_step) - 1)
trace ('Split: %s' % (split, ))
if tags == None:
tags = p.pairing.tags
hyps = hyps + check.split_loop_hyps (tags, split, restrs, exit = True)
r_max = find_split_limit (p, r_n, restrs, hyps, 'Offset',
bound = (n + 2) * r_step, must_find = False,
hints = [n * r_step, n * r_step + 1])
if r_max == None:
trace ('v_eqs_to_split: no RHS limit')
return None
if r_max > n * r_step:
trace ('v_eqs_to_split: RHS limit not %d' % (n * r_step))
return None
trace ('v_eqs_to_split: split %s' % (split,))
return split
示例7: build_proof_rec
def build_proof_rec (searcher, p, restrs, hyps):
trace ('doing build proof rec with restrs = %r, hyps = %r' % (restrs, hyps))
(kind, details) = searcher (p, restrs, hyps)
last_searcher_results.append ((p, restrs, hyps, kind, details))
del last_searcher_results[:-10]
trace ('proof searcher found %s, %s' % (kind, details))
if kind == 'Restr':
(restr_kind, restr_points) = details
return build_proof_rec_with_restrs (restr_points, restr_kind,
searcher, p, restrs, hyps)
elif kind == 'Leaf':
return ProofNode ('Leaf', None, ())
assert kind in ['CaseSplit', 'Split']
split = details
[(_, hyps1, _), (_, hyps2, _)] = check.proof_subproblems (p, kind,
split, restrs, hyps, '')
if kind == 'CaseSplit':
return ProofNode ('CaseSplit', split,
[build_proof_rec (searcher, p, restrs, hyps1),
build_proof_rec (searcher, p, restrs, hyps2)])
split_points = check.split_heads (split)
no_loop_proof = build_proof_rec_with_restrs (split_points,
'Number', searcher, p, restrs, hyps1)
loop_proof = build_proof_rec_with_restrs (split_points,
'Offset', searcher, p, restrs, hyps2)
return ProofNode ('Split', split,
[no_loop_proof, loop_proof])
示例8: load_proofs_from_file
def load_proofs_from_file (fname):
f = open (fname)
proofs = {}
lines = None
for line in f:
line = line.strip ()
if line.startswith ('ProblemProof'):
assert line.endswith ('{'), line
name_bit = line[len ('ProblemProof') : -1].strip ()
assert name_bit.startswith ('('), name_bit
assert name_bit.endswith (')'), name_bit
name = name_bit[1:-1]
lines = []
elif line == '}':
assert lines[0] == 'Problem'
assert lines[-2] == 'EndProblem'
import problem
trace ('loading proof from %d lines' % len (lines))
p = problem.deserialise (name, lines[:-1])
proof = deserialise (lines[-1])
proofs.setdefault (name, [])
proofs[name].append ((p, proof))
trace ('loaded proof %s' % name)
lines = None
elif line.startswith ('#'):
pass
elif line:
lines.append (line)
assert not lines
return proofs
示例9: save_compiled_funcs
def save_compiled_funcs (fname):
out = open (fname, 'w')
for (f, func) in functions.iteritems ():
trace ('Saving %s' % f)
for s in func.serialise ():
out.write (s + '\n')
out.close ()
示例10: search_bin_bound
def search_bin_bound (p, restrs, hyps, split):
trace ('Searching for bound for 0x%x in %s.', (split, p.name))
bound = search_bound (p, restrs, hyps, split)
if bound:
return bound
# try to use a bound inferred from C
if avoid_C_information[0]:
# OK told not to
return None
if get_prior_loop_heads (p, split):
# too difficult for now
return None
asm_tag = p.node_tags[split][0]
(_, fname, _) = p.get_entry_details (asm_tag)
funs = [f for pair in target_objects.pairings[fname]
for f in pair.funs.values ()]
c_tags = [tag for tag in p.tags ()
if p.get_entry_details (tag)[1] in funs and tag != asm_tag]
if len (c_tags) != 1:
print 'Surprised to see multiple matching tags %s' % c_tags
return None
[c_tag] = c_tags
return getBinaryBoundFromC (p, c_tag, split, restrs, hyps)
示例11: save_bound
def save_bound (glob, split_bin_addr, call_ctxt, prob_hash, prev_bounds, bound,
time = None):
f_names = [trace_refute.get_body_addrs_fun (x)
for x in call_ctxt + [split_bin_addr]]
loop_name = '<%s>' % ' -> '.join (f_names)
comment = '# bound for loop in %s:' % loop_name
ss = ['LoopBound'] + serialise_bound (split_bin_addr, bound)
if glob:
ss[0] = 'GlobalLoopBound'
ss += [str (len (call_ctxt))] + map (hex, call_ctxt)
ss += [str (prob_hash)]
if glob:
assert prev_bounds == None
else:
ss += [str (len (prev_bounds))]
for (split, bound) in prev_bounds:
ss += serialise_bound (split, bound)
s = ' '.join (ss)
f = open ('%s/LoopBounds.txt' % target_objects.target_dir, 'a')
f.write (comment + '\n')
f.write (s + '\n')
if time != None:
ctxt2 = call_ctxt + [split_bin_addr]
ctxt2 = ' '.join ([str (len (ctxt2))] + map (hex, ctxt2))
f.write ('LoopBoundTiming %s %s\n' % (ctxt2, time))
f.close ()
trace ('Found bound %s for 0x%x in %s.' % (bound, split_bin_addr,
loop_name))
示例12: test_hyp_whyps
def test_hyp_whyps (self, hyp, hyps, cache = None, fast = False,
model = None):
self.avail_hyps = set (hyps)
if not self.used_hyps <= self.avail_hyps:
self.rebuild ()
last_test[0] = (hyp, hyps, list (self.pc_env_requests))
expr = self.interpret_hyp_imps (hyps, hyp)
trace ('Testing hyp whyps', push = 1)
trace ('requests = %s' % self.pc_env_requests)
expr_s = smt_expr (expr, {}, self.solv)
if cache and expr_s in cache:
trace ('Cached: %s' % cache[expr_s])
return cache[expr_s]
if fast:
trace ('(not in cache)')
return None
self.solv.add_pvalid_dom_assertions ()
if model == None:
(result, _) = self.solv.parallel_test_hyps (
[(None, expr)], {})
else:
result = self.solv.test_hyp (expr, {}, model = model)
trace ('Result: %s' % result, push = -1)
if cache != None:
cache[expr_s] = result
if not result:
last_failed_test[0] = last_test[0]
return result
示例13: setup_split_search
def setup_split_search (rep, head, restrs, hyps,
i_opts, j_opts, unfold_limit = None, tags = None):
p = rep.p
if not tags:
tags = p.pairing.tags
if unfold_limit == None:
unfold_limit = max ([start + (2 * step) + 1
for (start, step) in i_opts + j_opts])
trace ('Split search at %d, unfold limit %d.' % (head, unfold_limit))
l_tag, r_tag = tags
loop_elts = [(n, start, step) for n in p.splittable_points (head)
for (start, step) in i_opts]
init_to_split = init_loops_to_split (p, restrs)
r_to_split = [n for n in init_to_split if p.node_tags[n][0] == r_tag]
cand_r_loop_elts = [(n2, start, step) for n in r_to_split
for n2 in p.splittable_points (n)
for (start, step) in j_opts]
err_restrs = restr_others (p, tuple ([(sp, vc_upto (unfold_limit))
for sp in r_to_split]) + restrs, 1)
nrerr_pc = mk_not (rep.get_pc (('Err', err_restrs), tag = r_tag))
def get_pc (n, k):
head = p.loop_id (n)
assert head in init_to_split
if n != head:
k += 1
restrs2 = restrs + ((head, vc_num (k)), )
return rep.get_pc ((n, restrs2))
for n in r_to_split:
get_pc (n, unfold_limit)
get_pc (head, unfold_limit)
premise = foldr1 (mk_and, [nrerr_pc] + map (rep.interpret_hyp, hyps))
premise = logic.weaken_assert (premise)
knowledge = SearchKnowledge (rep,
'search at %d (unfold limit %d)' % (head, unfold_limit),
restrs, hyps, tags, (loop_elts, cand_r_loop_elts))
knowledge.premise = premise
last_knowledge[0] = knowledge
# make sure the representation is in sync
rep.test_hyp_whyps (true_term, hyps)
# make sure all mem eqs are being tracked
mem_vs = [v for v in knowledge.v_ids if v[0].typ == builtinTs['Mem']]
for (i, v) in enumerate (mem_vs):
for v2 in mem_vs[:i]:
for pred in expand_var_eqs (knowledge, (v, v2)):
smt_expr (pred, {}, rep.solv)
for v in knowledge.v_ids:
for pred in expand_var_eqs (knowledge, (v, 'Const')):
smt_expr (pred, {}, rep.solv)
return knowledge
示例14: find_split_loop
def find_split_loop (p, head, restrs, hyps, unfold_limit = 9):
assert p.loop_data[head][0] == 'Head'
assert p.node_tags[head][0] == p.pairing.tags[0]
# the idea is to loop through testable hyps, starting with ones that
# need smaller models (the most unfolded models will time out for
# large problems like finaliseSlot)
rep = mk_graph_slice (p, fast = True)
nec = get_necessary_split_opts (p, head, restrs, hyps)
if nec and nec[0] == 'CaseSplit':
return nec
elif nec:
i_j_opts = nec
else:
i_j_opts = default_i_j_opts (unfold_limit)
ind_fails = []
for (i_opts, j_opts) in i_j_opts:
result = find_split (rep, head, restrs, hyps,
i_opts, j_opts)
if result[0] != None:
return result
ind_fails.extend (result[1])
if ind_fails:
trace ('Warning: inductive failures: %s' % ind_fails)
raise NoSplit ()
示例15: hyps_add_model
def hyps_add_model (self, hyps, assert_progress = True):
if hyps:
test_expr = foldr1 (mk_and, hyps)
else:
# we want to learn something, either a new model, or
# that all hyps are true. if there are no hyps,
# learning they're all true is learning nothing.
# instead force a model
test_expr = false_term
test_expr = mk_implies (self.premise, test_expr)
m = {}
(r, _) = self.rep.solv.parallel_check_hyps ([(1, test_expr)],
{}, model = m)
if r == 'unsat':
if not hyps:
trace ('WARNING: SearchKnowledge: premise unsat.')
trace (" ... learning procedure isn't going to work.")
return
if assert_progress:
assert not (set (hyps) <= self.facts), hyps
for hyp in hyps:
self.facts.add (hyp)
else:
assert r == 'sat', r
self.add_model (m)
if assert_progress:
assert self.model_trace[-2:-1] != [m]