Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions manticore/core/smtlib/visitors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import functools

from ...utils.helpers import CacheDict
from ...exceptions import SmtlibError
from .expression import *
Expand Down Expand Up @@ -53,14 +55,21 @@ def result(self):
return self._stack[-1]

def _method(self, expression, *args):
for cls in expression.__class__.__mro__[:-1]:
for method in self._methods(expression.__class__):
value = method(expression, *args)
if value is not None:
return value
return self._rebuild(expression, args)

@functools.lru_cache(maxsize=256)
def _methods(self, ecls):
methods = []
for cls in ecls.__mro__[:-1]:
sort = cls.__name__
methodname = "visit_%s" % sort
if hasattr(self, methodname):
value = getattr(self, methodname)(expression, *args)
if value is not None:
return value
return self._rebuild(expression, args)
methods.append(getattr(self, methodname))
return tuple(methods)

def visit(self, node, use_fixed_point=False):
"""
Expand Down
26 changes: 24 additions & 2 deletions manticore/ethereum/manticore.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import logging
from multiprocessing import Queue, Process
from queue import Empty as EmptyQueue
from typing import Dict, Optional, Union
import threading
from typing import Callable, Dict, Optional, Tuple, Union
import io
import pyevmasm as EVMAsm
import random
Expand Down Expand Up @@ -1767,13 +1768,34 @@ def worker_finalize(q):
except EmptyQueue:
pass

class ReportWorkerSingle:
"""Run task in the current process and current thread"""

def __init__(self, target: Callable, args: Tuple) -> None:
self.target = target
self.args = args

def start(self) -> None:
self.target(*self.args)

def join(self) -> None:
pass

# Generate testcases for all but killed states
q = Queue()
for state_id in self._all_states:
# we need to remove -1 state before forking because it may be in memory
q.put(state_id)

report_workers = [Process(target=worker_finalize, args=(q,)) for _ in range(procs)]
core_consts = config.get_group("core")
report_workers = [
{
core_consts.mprocessing.single: ReportWorkerSingle,
core_consts.mprocessing.threading: threading.Thread,
core_consts.mprocessing.multiprocessing: Process,
}[core_consts.mprocessing](target=worker_finalize, args=(q,))
for _ in range(procs)
]
for proc in report_workers:
proc.start()

Expand Down
Loading