qira can do multiple runs without a server

This commit is contained in:
George Hotz 2014-07-21 14:37:47 -07:00
parent da79de9bff
commit 42f1c23273
3 changed files with 39 additions and 24 deletions

View File

@ -10,6 +10,8 @@ import fcntl
import signal
import argparse
QIRA_PORT = 3002
from flask import Flask, Response
from flask.ext.socketio import SocketIO, emit
@ -172,7 +174,7 @@ def serve(path):
def run_socketio():
print "starting socketio server..."
socketio.run(app, port=3002)
socketio.run(app, port=QIRA_PORT)
def check_file(logfile, trace):
global program
@ -298,19 +300,31 @@ if __name__ == '__main__':
# creates the file symlink, program is constant through server run
program = qira_trace.Program(args.binary, args.args)
is_qira_running = 1
try:
socket.create_connection(('127.0.0.1', QIRA_PORT))
if args.server:
raise Exception("can't run as server if QIRA is already running")
except:
is_qira_running = 0
print "no qira server found, starting it"
program.clear()
# start the binary runner
if args.server:
init_bindserver()
start_bindserver(ss, -1, 1, True)
else:
print "**** running "+program.program
if os.fork() == 0:
os.execvp(program.qirabinary, [program.qirabinary, "-D", "/dev/null", "-d", "in_asm", "-singlestep", program.program]+program.args)
if is_qira_running or os.fork() == 0: # cute?
os.execvp(program.qirabinary, [program.qirabinary, "-D", "/dev/null", "-d", "in_asm",
"-singlestep", program.program]+program.args)
# start the http server
http = threading.Thread(target=run_socketio)
http.start()
if not is_qira_running:
# start the http server
http = threading.Thread(target=run_socketio)
http.start()
# this reads the files. replace it with c
run_middleware()
# this reads the files. replace it with c
run_middleware()

View File

@ -20,12 +20,6 @@ class Program:
except:
pass
# probably always good to do except in development of middleware
print "*** deleting old runs"
self.delete_old_runs()
# getting asm from qemu
self.create_asm_file()
# pmaps is global, but updated by the traces
self.pmaps = {}
@ -34,17 +28,10 @@ class Program:
self.program = prog
self.args = args
"""
self.basemem = qira_memory.Memory()
print "committing base memory..."
qira_binary.mem_commit_base_binary(prog, self.basemem)
"""
# get file type
#self.fb = qira_binary.file_binary(prog)
self.fb = struct.unpack("H", open(prog).read(0x18)[0x12:0x14])[0]
print "e_machine is",hex(self.fb)
qemu_dir = os.path.dirname(os.path.realpath(__file__))+"/../qemu/"
if self.fb == 0x28:
self.tregs = ARMREGS
@ -56,11 +43,21 @@ class Program:
self.tregs = X86REGS
self.qirabinary = qemu_dir + "qira-i386"
else:
print "BINARY TYPE NOT SUPPORTED"
raise Exception("binary type not supported")
print "**** using",self.qirabinary,"for",hex(self.fb)
# no traces yet
self.traces = {}
def clear(self):
# probably always good to do except in development of middleware
print "*** deleting old runs"
self.delete_old_runs()
# getting asm from qemu
self.create_asm_file()
def create_asm_file(self):
try:
os.unlink("/tmp/qira_asm")
@ -110,7 +107,7 @@ class Trace:
def reset(self):
self.regs = qira_memory.Memory()
self.mem = qira_memory.Memory()
#self.mem = self.program.basemem.copy()
self.minclnum = -1
self.maxclnum = 1

View File

@ -484,7 +484,7 @@ struct logstate *GLOBAL_logstate;
// input args
uint32_t GLOBAL_start_clnum = 1;
int GLOBAL_parent_id = -1, GLOBAL_id = 0;
int GLOBAL_parent_id = -1, GLOBAL_id = -1;
FILE *GLOBAL_asm_file = NULL;
@ -855,6 +855,9 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t *tb_ptr)
//TaskState *ts = (TaskState *)cpu->opaque;
if (unlikely(GLOBAL_QIRA_did_init == 0)) {
// get next id
if (GLOBAL_id == -1) { GLOBAL_id = get_next_id(); }
// do initial core dump
/*struct rlimit core_limit, core_limit_old;
getrlimit(RLIMIT_CORE, &core_limit_old);
@ -873,6 +876,7 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t *tb_ptr)
run_QIRA_log(env, GLOBAL_parent_id, GLOBAL_start_clnum);
}
init_QIRA(env, GLOBAL_id);
return 0;
}