Example #1
0
__all__ = [
    "C2TConfig", "Run", "get_new_rsp", "DebugClient", "DebugServer",
    "TestBuilder"
]

from collections import (namedtuple)
from common import (pypath)
with pypath("..pyrsp"):
    from pyrsp.rsp import (RSP, archmap)

# CPU Testing Tool configuration components
C2TConfig = namedtuple(
    "C2TConfig", "rsp_target qemu gdbserver target_compiler oracle_compiler")
Run = namedtuple("Run", "executable args")


def get_new_rsp(regs, pc, regsize, little_endian=True):
    class CustomRSP(RSP):
        def __init__(self, *a, **kw):
            self.arch = dict(regs=regs, endian=little_endian, bitsize=regsize)
            self.pc_reg = pc
            super(CustomRSP, self).__init__(*a, **kw)

    return CustomRSP


class DebugClient(object):
    def __init__(self, march, new_rsp=None, sp=None, qemu_reset=False):
        self.march = march
        if march in archmap:
            self.rsp = archmap[march]
Example #2
0
from os.path import (dirname, join, exists, basename)
from os import (makedirs, killpg, setpgrp)
from signal import (SIGTERM, SIGKILL)
from argparse import (Action, ArgumentParser)
from re import (compile)
from multiprocessing import (Value, Queue, Process)
from six.moves.queue import (Empty)
from subprocess import (Popen, PIPE)
from platform import (machine)
from collections import (defaultdict)
from struct import (pack)
from common import (execfile, bstr, filefilter, cli_repr, HelpFormatter,
                    pypath)
from debug import (get_elffile_loading, InMemoryELFFile, DWARFInfoCache,
                   Runtime)
with pypath("pyrsp"):
    from pyrsp.rsp import (archmap)
    from pyrsp.utils import (wait_for_tcp_port, QMP, find_free_port)
from c2t import (DebugComparator, DebugCommandExecutor, C2TConfig, Run,
                 get_new_rsp, DebugClient, DebugServer, TestBuilder)

C2T_ERRMSG_FORMAT = "{prog}:\x1b[31m error:\x1b[0m {msg}\n"


def c2t_exit(msg, prog=__file__):
    print(C2T_ERRMSG_FORMAT.format(prog=basename(prog), msg=msg))
    killpg(0, SIGKILL)


C2T_DIR = dirname(__file__) or '.'
C2T_CONFIGS_DIR = join(C2T_DIR, "c2t", "configs")
Example #3
0
File: c_const.py Project: ufwt/qdt
__all__ = ["CConst", "CINT", "CSTR"]

if __name__ == "__main__":
    from c_str_adapter import str2c
else:
    from .c_str_adapter import str2c

from math import (log)
from string import (digits, ascii_uppercase)
from common import (pypath, def_tokens)
from six import (integer_types)
# PLY is used to parse C constants
with pypath("..ply"):
    from ply.lex import lex
    from ply.yacc import yacc


class CConst(object):
    @staticmethod
    def parse(s):
        try:
            return parser.parse(s, lexer=lexer)
        except (QCParserError, QCLexerError):
            return CSTR(s)

    def gen_c_code(self):
        "Implementation must return string compatible with C generator"
        raise NotImplementedError()

    def __c__(self, writer):
        writer.write(self.gen_c_code())
Example #4
0
from common import (iter_submodules, pypath)

# this module uses custom pyelftools
with pypath("pyelftools"):
    for mod in iter_submodules():
        exec("from ." + mod + " import *")