From 19ec9b83b7184cb634878f1555287524f5c8251e Mon Sep 17 00:00:00 2001 From: zevorn Date: Sun, 3 Apr 2022 17:29:55 +0800 Subject: [PATCH 01/11] [fix](arch/arm): update common --- arch/arm/Makefile.am | 2 +- arch/arm/arm11/arm11_core.c | 6 +----- arch/arm/arm926ejs/arm926ejs_core.c | 9 +++------ arch/arm/common/arminit.c | 8 ++++---- arch/arm/common/armos.c | 8 ++++---- arch/arm/common/vfp/vfpinstr.c | 3 --- 6 files changed, 13 insertions(+), 23 deletions(-) diff --git a/arch/arm/Makefile.am b/arch/arm/Makefile.am index 95e61f92..8bee00e2 100644 --- a/arch/arm/Makefile.am +++ b/arch/arm/Makefile.am @@ -58,7 +58,7 @@ DEFS = -DMODET -g -O3 -D_FILE_OFFSET_BITS=64 -DSTANDALONE -DDEFAULT_INLINE=0 -DN #endif libarm_la_LIBADD = armemu32.lo -INCLUDES = -I$(top_srcdir)/arch/arm/common -I$(top_srcdir)/arch/arm/mach/ -I$(top_srcdir)/arch/arm/dyncom -I$(top_srcdir)/common/dyncom/ @COMMON_INCLUDES@ -I$(top_srcdir)/third-party/include/ +INCLUDES = -I$(top_srcdir)/arch/arm/common -I$(top_srcdir)/arch/arm/mach/ @COMMON_INCLUDES@ -I$(top_srcdir)/third-party/include/ #if LLVM_EXIST #INCLUDES += @LLVM_CFLAGS@ #endif diff --git a/arch/arm/arm11/arm11_core.c b/arch/arm/arm11/arm11_core.c index d2a82511..1999c857 100644 --- a/arch/arm/arm11/arm11_core.c +++ b/arch/arm/arm11/arm11_core.c @@ -79,10 +79,7 @@ uint32_t arm11_run(conf_object_t * conf_obj) uint32_t steps = state->NumInstrs; SKY_pc_hap_occurred(NULL, conf_obj, state->Reg[15]); - if (state->mode == DYNCOM_RUN || state->mode == HYBRID_RUN) - { - // arm_dyncom_step_once(state); - } else if (state->mode == INTERPRET_RUN || state->mode == DYNCOM_RUN_SINGLE_STEP) + if (state->mode == INTERPRET_RUN) { arm_step_once(state); } else @@ -352,7 +349,6 @@ static conf_object_t *new_arm11_core(char *obj_name) #if (FAST_MEMORY || FAST_MEM32) state->is_io_space = arm11_is_io_space; #endif - // arm_dyncom_init(state); VFPInit(core); //register_callback(arm11_stepi_check, Step_callback); //register_callback(arm11_check_breakpoint_callback, Step_callback); diff --git a/arch/arm/arm926ejs/arm926ejs_core.c b/arch/arm/arm926ejs/arm926ejs_core.c index 529d383a..16093349 100644 --- a/arch/arm/arm926ejs/arm926ejs_core.c +++ b/arch/arm/arm926ejs/arm926ejs_core.c @@ -248,10 +248,7 @@ int arm926ejs_run(conf_object_t * conf_obj) uint64_t steps = state->NumInstrs; SKY_pc_hap_occurred(NULL, conf_obj, state->Reg[15]); - if (state->mode == DYNCOM_RUN || state->mode == HYBRID_RUN) - { - // arm_dyncom_step_once(state); - } else if (state->mode == INTERPRET_RUN || state->mode == DYNCOM_RUN_SINGLE_STEP) + if (state->mode == INTERPRET_RUN) { arm_step_once(state); } else @@ -259,10 +256,10 @@ int arm926ejs_run(conf_object_t * conf_obj) /* invalid mode */ return; } - if (state->stop_step == 0 && state->mode == DYNCOM_RUN_SINGLE_STEP) + if (state->stop_step == 0) { /* we reach the stop steps */ - state->mode = DYNCOM_RUN; + //state->mode = DYNCOM_RUN; } generic_address_t pc = state->realPC; diff --git a/arch/arm/common/arminit.c b/arch/arm/common/arminit.c index 8edc2ee4..0a6cd5f7 100644 --- a/arch/arm/common/arminit.c +++ b/arch/arm/common/arminit.c @@ -43,10 +43,10 @@ char ARMul_BitList[256]; /* number of bits in a byte table */ extern int debugmode; extern int remote_interrupt(void); -void arm_dyncom_Abort(ARMul_State * state, ARMword vector) -{ - ARMul_Abort(state, vector); -} +// void arm_dyncom_Abort(ARMul_State * state, ARMword vector) +// { +// ARMul_Abort(state, vector); +// } /* ahe-ykl : the following code to initialize user mode * code is architecture dependent and probably model dependant. */ diff --git a/arch/arm/common/armos.c b/arch/arm/common/armos.c index 4d6bcc23..7840d0a5 100644 --- a/arch/arm/common/armos.c +++ b/arch/arm/common/armos.c @@ -112,10 +112,10 @@ extern unsigned ARMul_OSHandleSWI(ARMul_State * state, ARMword number); * OS private Information * \***************************************************************************/ -unsigned arm_dyncom_SWI(ARMul_State * state, ARMword number) -{ - return ARMul_OSHandleSWI(state, number); -} +// unsigned arm_dyncom_SWI(ARMul_State * state, ARMword number) +// { +// return ARMul_OSHandleSWI(state, number); +// } mmap_area_t *mmap_global = NULL; diff --git a/arch/arm/common/vfp/vfpinstr.c b/arch/arm/common/vfp/vfpinstr.c index b3232d7f..a7c73eee 100644 --- a/arch/arm/common/vfp/vfpinstr.c +++ b/arch/arm/common/vfp/vfpinstr.c @@ -472,9 +472,6 @@ if ((OPC_1 & 0xB) == 2 && (OPC_2 & 0x2) == 2) DBG("VNMUL :\n"); } #endif -#ifdef VFP_DYNCOM_TABLE -DYNCOM_FILL_ACTION(vfpinstr), -#endif #undef vfpinstr -- Gitee From 8ca542cb2ce31d67a8062747ebd5feef178ebc58 Mon Sep 17 00:00:00 2001 From: zevorn Date: Sun, 3 Apr 2022 17:31:49 +0800 Subject: [PATCH 02/11] [fix](utils): update python utils --- utils/pycli/coverage.py | 428 ------------------------ utils/pycli/coverage_addr_info_tools.py | 215 ------------ utils/pycli/coverage_code.py | 203 ----------- 3 files changed, 846 deletions(-) delete mode 100644 utils/pycli/coverage.py delete mode 100644 utils/pycli/coverage_addr_info_tools.py delete mode 100644 utils/pycli/coverage_code.py diff --git a/utils/pycli/coverage.py b/utils/pycli/coverage.py deleted file mode 100644 index 6dbc705e..00000000 --- a/utils/pycli/coverage.py +++ /dev/null @@ -1,428 +0,0 @@ -#coding:utf-8 -import os,re -import time -import conf -import tools -import se_path -import json -from skyeye_common_module import * -import coverage_addr_info_tools as cait -import project_config as pconf -import coverage_code as c_code - -#解析前文件内容 -instr_info = None -objdump_info = {} -objdump_file_dic = {} -objdump_thread_dic = {} - -#解析后文件内容 -uninstr_info = None -unobjdump_info = {} - -#当前CPU名称 -cpu_name = None - -#融合覆盖率信息文件 -fusion_file_name = "" - -#替身二进制文件 -replace_binary = None -binary_offset = 0 - -#用户级函数 -user_func_list = [] - -#coverage_info路径 -coverage_info_path = None - -#是否中断运行 -is_cancel = False - -#融合模式 -fusion_mode = "false" - -def set_is_cancel(flag): - global is_cancel - is_cancel = flag - -def check_cancel_run(func): - def wrapped(*args,**argv): - if is_cancel == False: - return func(*args,**argv) - return wrapped - -def cov_init(cpu,source_dir): - global objdump_info - global cpu_name - global user_func_list - global coverage_info_path - global is_cancel - is_cancel = False - try: - coverage_info_path = mkdir_script_dir("coverage_info") - except Exception as e: - return (False, e) - cpu_name = cpu - objdump_file = write_objdump_file(cpu,source_dir) - instr_file = write_coverage_file(cpu) - objdump_info[cpu_name] = open_file(objdump_file) - if is_cancel == False and len(objdump_info[cpu_name]) == 0: - raise Exception("The objdump cache file is empty") - if unobjdump_info.get(cpu_name) == None: - analytic_objdump(objdump_file) - analytic_instr_process(instr_file) - try: - c_code.get_all_code_branch_info(coverage_info_path, source_dir) - user_func_list = set(c_code.code_func_list) - except Exception as e: - raise Exception("Failed to parse the source file") - return [objdump_file, instr_file] - -def open_file(file_name): - try: - with open(file_name,"r",encoding = "utf-8") as fp: - info=fp.read() - if info == "": - return [] - return info.strip().split("\n") - except: - return [] - -def write_file(file_name ,data): - file_path = os.path.split(file_name)[0] - if not os.path.exists(file_path): - os.makedirs(file_path) - try: - with open(file_name,"w") as fp: - fp.write("\n".join(data)) - except: - print ("%s write failed"%file_name) - -def get_project_info(): - return {"asm_file":conf.binary_l[cpu_name],'fusion_file':fusion_file_name} - -def count_total_cov(): - if len(user_func_list) > 0: - run_addr = [] - for func in unobjdump_info[cpu_name][1].keys(): - if func.split("_*_")[0].strip("_") in user_func_list: - run_addr += unobjdump_info[cpu_name][1][func]["addr"] - all_count = len(run_addr) - run_count = len(set(run_addr) & uninstr_info) - else: - run_count = len(uninstr_info) - all_count = unobjdump_info[cpu_name][0] - return {"code_cov":format(run_count/all_count,'.3%'),"branch_cov":None,"running_count":None, - "instr_sum":all_count,"instr_hit":run_count} - -def count_all_func_cov(): - run_func = [] - for addr in uninstr_info: - addr_info = unobjdump_info[cpu_name][2].get(addr) - if addr_info != None: - func_name = addr_info[0] - if func_name not in run_func: - if len(user_func_list) != 0 and func_name.split("_*_")[0].strip("_") not in user_func_list: - continue - run_func.append(func_name) - run_count = len(run_func) - if len(user_func_list) != 0: - all_count = len(user_func_list) - else: - all_count = len(unobjdump_info[cpu_name][1].keys()) - return {"code_cov":format(run_count/all_count,'.3%'),"branch_cov":None,"running_count":None, - "func_sum":all_count,"func_hit":run_count} - -@check_cancel_run -def get_func_run_lines(instr_list): - lines = [] - for instr in instr_list: - line = unobjdump_info[cpu_name][2].get(instr) - if line != None and line[2] != None: - lines.append(line[2]) - return list(set(lines)) - -def count_single_func_cov(): - cov_dict = {} - for func_name in unobjdump_info[cpu_name][1].keys(): - if len(user_func_list) != 0 and func_name.split("_*_")[0].strip("_") not in user_func_list: - continue - start_line = None - end_line = None - code_branch_sum = None - code_branch_hit = None - code_all_lines_status = None - object_list = unobjdump_info[cpu_name][1][func_name]["addr"] - if len(object_list) == 0: - continue - instr_list = set(object_list) & uninstr_info - func_count = len(instr_list) - obj_count = len(object_list) - all_branch_count = len(unobjdump_info[cpu_name][1][func_name]["branch_addr"]) * 2 - run_branch_count = 0 - if all_branch_count != 0 : - for addr1,addr2,addr3 in unobjdump_info[cpu_name][1][func_name]["branch_addr"]: - if addr1 in uninstr_info: - temp = uninstr_info & {addr2,addr3} - run_branch_count += len(temp) - - def get_file_name(f_addr): - name = unobjdump_info[cpu_name][2].get(f_addr) - if name != None and name[1] != None: - return name[1] - return "Other" - run_lines = get_func_run_lines(instr_list) - all_lines = list(set(filter(None,unobjdump_info[cpu_name][3].get(func_name)))) - for f_addr in object_list[:3]: - file_name = get_file_name(f_addr) - if file_name != "Other": - start_line, end_line, code_branch_hit, code_branch_sum, code_all_lines_status = c_code.get_func_code_info(file_name, func_name.split("_*_")[0].strip("_"), run_lines, all_lines) - break - cov_dict[func_name.split("_*_")[0]] = { - "start_addr": min(object_list), - "end_addr": max(object_list), - "instr_sum": obj_count, - "instr_hit": func_count, - "instr_branch_sum": all_branch_count, - "instr_branch_hit": run_branch_count, - "file_name": file_name, - "start_line": start_line, - "end_line": end_line, - "code_line_sum": len(all_lines), - "code_line_hit": len(run_lines), - "code_branch_hit": code_branch_hit, - "code_branch_sum": code_branch_sum, - "code_all_lines_status":code_all_lines_status} - return cov_dict - -@check_cancel_run -def analytic_objdump(objdump_file): - global unobjdump_info - objdump_file_name = os.path.split(objdump_file)[-1] - un_cache = os.path.join(coverage_info_path, "%s_unobjdump.json"%cpu_name) - if pconf.check_bind(objdump_file,un_cache) == True: - with open(un_cache,"r") as fp: - unobjdump_info = json.loads(fp.read()) - if cpu_name in unobjdump_info: - return - all_addr_count = 0 - func_dict = {} - func_name = None - addr = None - addr_file = [None,None] - addr_to_line = {} - func_line_dic = {} - archname = SkyEyeGetArchitecture(cpu_name) - func_patter = r"^([0-9a-f]{8})\s*<([^$]*)>:\s*$" - insr_patter = r"^( {0,7}[0-9a-f]{1,8}):(.*)\s*$" - file_patter = r'^((?:(?:[a-zA-Z]:)|.)?(?:(?:[/\\]{1,2}[^\\/:*?"<>|\r\n]+)*)):(\d+)$' - for num in range(0,len(objdump_info[cpu_name])): - func_ret = re.match(func_patter, objdump_info[cpu_name][num]) - insr_ret = re.match(insr_patter, objdump_info[cpu_name][num]) - file_ret = re.match(file_patter, objdump_info[cpu_name][num]) - if func_ret != None: - func_addr = hex(int(func_ret.group(1).lstrip(" "), 16)).strip("L")[2:] - func_name = func_ret.group(2) + "_*_" + func_addr - func_dict[func_name] = {} - func_dict[func_name]["addr"] = [] - func_dict[func_name]["branch_addr"] = [] - addr_file = [None,None] - func_line_dic[func_name] = [] - elif insr_ret != None: - all_addr_count += 1 - addr = hex(int(insr_ret.group(1).lstrip(" "), 16)).strip("L")[2:] - func_dict[func_name]["addr"].append(addr) - cait.find_branch_info(archname, objdump_info[cpu_name], num, func_dict[func_name]["branch_addr"], binary_offset) - addr_to_line[addr] = [func_name] + addr_file - func_line_dic[func_name].append(addr_file[1]) - elif file_ret != None: - addr_file = [os.path.normpath(file_ret.group(1)).replace('\\','/'),int(file_ret.group(2))] - else: - pass - unobjdump_info[cpu_name] = [all_addr_count,func_dict,addr_to_line,func_line_dic] - #unobjdump_info[objdump_file_name] = pconf.get_file_md5(objdump_file) - - with open(un_cache,"w") as fp: - fp.write(json.dumps(unobjdump_info)) - pconf.file_bind(objdump_file,un_cache) - -@check_cancel_run -def analytic_instr_process(instr_file): - global instr_info - global uninstr_info - global fusion_file_name - try: - coverage_info_path = mkdir_script_dir("coverage_info") - except Exception as e: - return (False,e) - fusion_file_name = os.path.join(coverage_info_path,"%s_fusion.cache"%(cpu_name)) - - instr_info = set(open_file(instr_file)) - if len(instr_info) == 0: - raise Exception("The instr process cache file is empty") - if fusion_mode == "true": - instr_info = instr_info | set(open_file(fusion_file_name)) - write_file(fusion_file_name, list(instr_info)) - uninstr_info = instr_info - - -def code_running_path(): - instr_list=[] - for addr in instr_info: - addr_info = unobjdump_info[cpu_name][2].get(addr) - #func_name ,addr,file_name ,line_num - info = [None,"0x"+addr,None,None] - if addr_info != None: - info[0] = addr_info[1] - info[2] = addr_info[0].split("_*_")[0] - info[3] = addr_info[2] - instr_list.append(info) - return instr_list - -def code_running_number(): - instr_dict={} - for addr in instr_info: - addr_info = unobjdump_info[cpu_name][2].get(addr) - if addr_info != None: - if addr_info[1] != None: - if addr_info[1] not in instr_dict.keys(): - instr_dict[addr_info[1]]=[] - if addr_info[2] not in instr_dict[addr_info[1]]: - instr_dict[addr_info[1]].append(addr_info[2]) - return instr_dict - -@check_cancel_run -def write_coverage_file(cpu, file_name = None): - instr_process = get_instr_process_by_cpu(cpu) - if instr_process != None: - if(not os.path.exists(se_path.CacheFileDir)): - os.mkdir(se_path.CacheFileDir) - if file_name != None: - cover_file = file_name - else: - cover_file = os.path.join(se_path.CacheFileDir, "%s.cache" % instr_process) - tools.get_executed_pc_file(instr_process, cover_file) - else: - raise Exception("Instr_process file generation failed!\nInstr_process device of %s could not be found" % cpu) - return cover_file - -def addr_str_to_int(stri): - stri = stri.lstrip(" ") - return int(stri, 16) - -@check_cancel_run -def change_addr(objdump_file, offset): - file_info = open_file(objdump_file) - func_patter = r"^\s*([0-9a-f]{8})(\s*<.*>:\s*)$" - insr_patter = r"^\s*([ 0-9a-f]{4,8})(:.*\s*)$" - def add_offset(addr): - new_addr = addr_str_to_int(addr) + offset - return hex(new_addr).strip("L")[2:] - for index in range(0,len(file_info)): - func_ret = re.match(func_patter, file_info[index]) - insr_ret = re.match(insr_patter, file_info[index]) - if func_ret != None: - func_addr = add_offset(func_ret.group(1)) - while len(func_addr) < 8: - func_addr = "0" + func_addr - file_info[index] = func_addr + func_ret.group(2) - elif insr_ret != None: - instr_addr = add_offset(insr_ret.group(1)) - while len(instr_addr) < 8: - instr_addr = " " + instr_addr - file_info[index] = instr_addr + insr_ret.group(2) - else: - pass - write_file(objdump_file,file_info) - -@check_cancel_run -def write_objdump_file(cpu,source_dir): - if cpu in objdump_thread_dic: - while objdump_thread_dic[cpu].poll() == None: - time.sleep(0.5) - if objdump_thread_dic[cpu].poll() == 0: - return objdump_file_dic[cpu] - - if cpu in conf.binary_l: - objdump_file = os.path.join(coverage_info_path, "%s_objdump.cache" % (cpu)) - if cpu in objdump_info and cpu == cpu_name and os.path.exists(objdump_file): - return objdump_file - if replace_binary == None: - binary = conf.binary_l[cpu] - else: - binary = replace_binary - if pconf.check_bind(binary,objdump_file) == True: - return objdump_file - if tools.get_objdump_file(cpu, binary, objdump_file, source_dir) == True: - if binary_offset != 0: - change_addr(objdump_file, binary_offset) - pconf.file_bind(binary,objdump_file) - else: - raise Exception("Objdump file generation failed!\nThe binary file for %s was not found in binary_l" % cpu) - return objdump_file - -def write_mach_all_object_file(mach_name): - global coverage_info_path - try: - coverage_info_path = mkdir_script_dir("coverage_info") - except Exception as e: - return (False,e) - config = conf.GetGlobalConfig() - if(config): - for cpu in config.get_cpuname_list_by_mach(mach_name): - if cpu in conf.binary_l: - objdump_file = os.path.join(coverage_info_path, "%s_objdump.cache" % (cpu)) - if replace_binary == None: - binary = conf.binary_l[cpu] - else: - binary = replace_binary - objdump_thread_dic[cpu] = tools.get_objdump_file(cpu, binary, objdump_file, None, False) - if binary_offset != 0: - change_addr(objdump_file, binary_offset) - objdump_file_dic[cpu] = objdump_file - -@check_cancel_run -def write_objcopy_file(cpu,binary,offset): - binary_sl = os.path.splitext(binary) - new_file_name = binary_sl[0] + "_substitute" + binary_sl[1] - tools.get_objcopy_file(cpu, binary, new_file_name, offset) - return new_file_name - -def check_variable(): - if instr_info == None or objdump_info.get(cpu_name) == None or uninstr_info == None or unobjdump_info.get(cpu_name) == None: - return False - return True - -def get_instr_process_by_cpu(cpu): - config = conf.GetGlobalConfig() - if(config): - mach = config.get_cpu_mach(cpu) - if mach: - try: - ret = SkyEyeGetInstrProcessDevice(mach, cpu) - if ret == "": - ret = None - return ret - except: - return None - return None - -def set_fusion_mode(switch): - global fusion_mode - fusion_mode = switch - -def mkdir_script_dir(path_name): - script_path = conf.GetGlobalScript() - if script_path == None: - raise Exception("The script path was not found") - script_path = os.path.split(script_path)[0] - info_path = os.path.join(script_path,path_name) - if not os.path.exists(info_path): - os.makedirs(info_path) - return info_path - -def kill_objdump_thread(): - for thread in objdump_thread_dic.keys(): - objdump_thread_dic[thread].terminate() - objdump_thread_dic[thread].kill() \ No newline at end of file diff --git a/utils/pycli/coverage_addr_info_tools.py b/utils/pycli/coverage_addr_info_tools.py deleted file mode 100644 index cb235eff..00000000 --- a/utils/pycli/coverage_addr_info_tools.py +++ /dev/null @@ -1,215 +0,0 @@ -#coding:utf-8 -import os -import re -import json - -section_addr_dict = {} - -def sparc_get_branch_addr(instr_info, arch_branch_instr, instr_addr, objdump_data): - #支持处理结构 - # be 40101b9c <_longjmp+0x54> - # be,a 40101ba8 <_longjmp+0x60> - # 跳转指令{2,5}最短,最长 - binsr_ret = re.match(r"(?:([a-z]{2,5})(?:,[a-z]*){0,1})\s+([0-9a-f]{1,8})\s+<.*>$", instr_info) - if binsr_ret != None: - if binsr_ret.group(1) in arch_branch_instr['instr']: - return binsr_ret.group(2) - else: - pass - else: - pass - return None - -def mips_get_branch_addr(instr_info, arch_branch_instr, instr_addr, objdump_data): - #支持处理结构 - # bnez v0,bf001990 - # beq a0,a3,bf0018c8 - # 跳转指令{3,5}最短,最长 - binsr_ret = re.match(r"(?:([a-z]{3,5})(?:,[a-z]*){0,1})\s+(?:[a-z0-9]{2},){1,2}([0-9a-f]{1,8})\s+<.*>$", instr_info) - if binsr_ret != None: - if binsr_ret.group(1) in arch_branch_instr['instr']: - return binsr_ret.group(2) - else: - pass - return None - -def tic6x_get_branch_addr(instr_info, arch_branch_instr, instr_addr, objdump_data): - #支持处理结构 - # [b0] b .S1 10800a28 <$C$L4> - # [!b0] b .S1 10802220 <__c6xabi_llshl> - # || [!b0] b .S1 10802220 <__c6xabi_llshl> - # 跳转指令{1,4}最短,最长 - binsr_ret = re.match(r"(?:(?:\|\|\s){0,1}(?:\[.+\]){1})\s*([a-z]{1,4})\s+(.*)$", instr_info) - if binsr_ret != None: - if binsr_ret.group(1) in arch_branch_instr['instr']: - tm = re.match(r"(\.S\S+)\s([0-9a-f]{1,8})(\s.*){0,1}$",binsr_ret.group(2)) - if tm != None: - return tm.group(2) - return None - -def tic28x_get_branch_addr(instr_info, arch_branch_instr, instr_addr, objdump_data): - #支持处理结构 - # sb 13, geq - # sb fffffff2, neq - # 跳转指令{2,3}最短,最长 - binsr_ret = re.match(r"([a-z]{2,3})\s+([0-9a-f]{1,8})(?:,.*){0,1}$", instr_info) - if binsr_ret != None: - if binsr_ret.group(1) in arch_branch_instr['instr']: - offset = int(binsr_ret.group(2), 16) - width=32 - if offset > 2 ** (width - 1) - 1: - offset = 2 ** width - offset - offset=0 - offset - return hex(int(instr_addr, 16) + offset)[2:].strip("L") - else: - pass - return None - -def powerpc_get_branch_addr(instr_info, arch_branch_instr, instr_addr, objdump_data): - #支持处理结构 - # blt- 10550c - # beq- cr7,1055b0 - # 跳转指令长度{3} - binsr_ret = re.match(r"([a-z]{3})(?:[+-]{0,1})\s+(?:\S+,){0,1}([0-9a-f]{1,8})\s(.*)$", instr_info) - if binsr_ret != None: - if binsr_ret.group(1) in arch_branch_instr['instr']: - return binsr_ret.group(2) - else: - pass - else: - pass - return None - -def arm_get_branch_addr(instr_info, arch_branch_instr, instr_addr, objdump_data): - #支持处理结构 - # beq 12a68 - # bcs 12b64 <__default_signal_handler+0x8c> - # 跳转指令长度{3} - binsr_ret = re.match(r"([a-z]{3})\s+([0-9a-f]{1,8})\s(.*)$", instr_info) - if binsr_ret != None: - if binsr_ret.group(1) in arch_branch_instr['instr']: - return binsr_ret.group(2) - else: - pass - else: - pass - return None - -def tic55x_get_branch_addr(instr_info, arch_branch_instr, instr_addr, objdump_data): - #支持处理结构 - # BCC __cmpd,AC2>=#0 - # BCC #0x0024b0,!TC1 - # 跳转指令长度{3} - #此架构为变长指令架构,跳转下一条地址可能存在问题。 - if len(section_addr_dict) == 0: - get_section_addr(objdump_data) - binsr_ret = re.match(r"([A-Z]{3})\s+(\S+),(.*)$", instr_info) - if binsr_ret != None: - if binsr_ret.group(1) in arch_branch_instr['instr']: - if binsr_ret.group(2)[:3] == '#0x': - return hex(int(binsr_ret.group(2)[3:].lstrip(" "), 16)).strip("L")[2:] - else: - if section_addr_dict.get(binsr_ret.group(2)) != None: - return section_addr_dict.get(binsr_ret.group(2)) - elif section_addr_dict.get(binsr_ret.group(2).lstrip("_")) != None: - return section_addr_dict.get(binsr_ret.group(2).lstrip("_")) - else: - print ("Address not found") - return None - else: - pass - else: - pass - return None - -def x86_get_branch_addr(instr_info, arch_branch_instr, instr_addr, objdump_data): - #支持处理结构 - #lock jo 1934e49b <_end+0x18e7489b> - #jo c04e2d13 <_end+0xc0009113> - # 跳转指令长度{2,5} - binsr_ret = re.match(r"(?:[a-z]+ ){0,1}([a-z]{2,5})\s+([0-9a-f]{1,8})\s(.*)$", instr_info) - if binsr_ret != None: - if binsr_ret.group(1) in arch_branch_instr['instr']: - return binsr_ret.group(2) - else: - pass - else: - pass - return None - -def find_branch_info(archname, objdump_data, num, branch_addr, binary_offset): - arch_branch_instr = branch_instr_info[archname] - if not any(instruct in objdump_data[num] for instruct in arch_branch_instr['instr']): - return - if archname == "x86": - patter = r"^\s*([ 0-9a-f]{4,8}):\s+(?:(?:[0-9a-f]{2} ){0,14}[0-9a-f]{2}){1}\s+(.+)$" - else: - patter = r"^\s*([ 0-9a-f]{4,8}):\s+(?:(?:[0-9a-f]{4,8})|(?:(?:[0-9a-f]{2} ){3}[0-9a-f]{2})|(?:[0-9a-f]{4} [0-9a-f]{4})|(?:[0-9a-f-]{2,13})){1}\s+(.+)$" - ret = re.match(patter,objdump_data[num]) - if ret != None: - instr_addr = hex(int(ret.group(1).lstrip(" "), 16)).strip("L")[2:] - jump_addr = arch_branch_instr['func'](ret.group(2), arch_branch_instr, instr_addr, objdump_data) - if jump_addr != None: - jump_addr = hex(int(jump_addr, 16) + binary_offset).strip("L")[2:] - next_addr = find_next_addr(objdump_data, num, arch_branch_instr['next_addr_step']) - branch_addr.append((instr_addr, jump_addr, next_addr)) - else: - pass - -def find_next_addr(objdump_data, num, stepi): - hit_count = 0 - while hit_count < stepi: - num += 1 - if num >= len(objdump_data): - return None - insr_patter = r"^( {0,7}[0-9a-f]{1,8}):(.*)\s*$" - insr_ret = re.match(insr_patter, objdump_data[num]) - if insr_ret != None: - hit_count = hit_count + 1 - return hex(int(insr_ret.group(1).lstrip(" "), 16)).strip("L")[2:] - -def get_section_addr(objdump_data): - global section_addr_dict - func_patter = r"^\s*([0-9a-f]{8})\s*<(.*)>:\s*$" - for info in objdump_data: - func_ret = re.match(func_patter, info) - if func_ret != None: - section_addr_dict[func_ret.group(2)] = hex(int(func_ret.group(1).lstrip(" "), 16)).strip("L")[2:] - -branch_instr_info = { - "sparc":{"instr":["ba","bcc","bcs","be","bg","bge","bgu","ble","bleu","bn","bne","bneg","bpos","bbc","bvs","fble","fbne","fbule","fbuge"], - "next_addr_step":2, - "func":sparc_get_branch_addr - }, - "mips":{"instr":["bnez", "beq", "bne","beqz", "bteqz", "btnez"], - "next_addr_step":2, - "func":mips_get_branch_addr - }, - "tic6x":{"instr":["bnop", "b"], - "next_addr_step":2, - "func":tic6x_get_branch_addr - }, - "tic28x":{"instr":["sb", "sbf"], - "next_addr_step":1, - "func":tic28x_get_branch_addr - }, - "powerpc":{"instr":["bgt", "bne", "ble", "beq", "bge", "blt"], - "next_addr_step":1, - "func":powerpc_get_branch_addr - }, - "arm":{"instr":["beq", "bgt", "bls", "bhi", "bcc", "bcs","ble", "bne", "bge", "blt"], - "next_addr_step":1, - "func":arm_get_branch_addr - }, - "tic55x":{"instr":["BCC"], - "next_addr_step":1, - "func":tic55x_get_branch_addr - }, - "x86":{"instr":["ja", "jae", "jb", "jbe", "jg", "jge", "jl", "jle", "je", "jne", "jc", "jnc", - "jno", "jnp", "jns", "jo", "jp", "js", "jcxz", "jecxz", "jnbe", "jnb", "jnae", "jna", - "jnle", "jnl", "jnge", "jng", "jz", "jnz", "jpo", "jpe"], - "next_addr_step":1, - "func":x86_get_branch_addr - - } -} \ No newline at end of file diff --git a/utils/pycli/coverage_code.py b/utils/pycli/coverage_code.py deleted file mode 100644 index d1318405..00000000 --- a/utils/pycli/coverage_code.py +++ /dev/null @@ -1,203 +0,0 @@ -import os -import clang.cindex as cc -import more_itertools -import project_config as pconf -import json - -code_file_info = {"file_info":{}, 'code_func_list':[]} -code_func_list = [] - -def get_code_func_list(): - func_list = [] - for key in code_file_info["file_info"]: - func_list += code_file_info["file_info"][key].keys() - return func_list - -def get_all_code_branch_info(coverage_info_path, code_path): - global code_file_info - global code_func_list - change_flag = False - load_flag = False - real_file_list = [] - if code_path == None or\ - code_path == "" or\ - os.path.exists(code_path) == False: - code_file_info = {"file_info":{}, 'code_func_list':[]} - code_func_list = [] - return - code_path = os.path.normpath(code_path) - index = cc.Index.create() - code_info_path = os.path.join(coverage_info_path, "code_info.json") - if pconf.cmp_md5(code_info_path) == True: - with open(code_info_path, "r") as fp: - code_file_info = json.loads(fp.read()) - load_flag = True - if code_file_info.get("file_info") == None: - code_file_info["file_info"] = {} - load_flag = False - if code_file_info.get('code_func_list') == None: - code_file_info['code_func_list'] = [] - load_flag = False - for dirpath,dirnames,filenames in os.walk(code_path): - for filename in filenames: - if filename.endswith(".c") or filename.endswith(".cpp"): - real_file_list.append(filename) - code_file = os.path.join(dirpath,filename) - if load_flag == True and\ - pconf.cmp_md5(code_file) == True and\ - code_file_info["file_info"].get(filename) != None: - continue - tu = index.parse(code_file) - node = tu.cursor - code_file_info["file_info"][filename] = get_info(node) - change_flag = True - pconf.write_file_md5(code_file) - if change_flag == True or len(real_file_list) != len(code_file_info["file_info"].keys()): - for key in [key for key in code_file_info["file_info"] if key not in real_file_list]: - code_file_info["file_info"].pop(key) - code_file_info['code_func_list'] = get_code_func_list() - with open(code_info_path, 'w') as fp: - fp.write(json.dumps(code_file_info)) - pconf.write_file_md5(code_info_path) - code_func_list = code_file_info['code_func_list'] - -def count_if_branch_cov(branch_info, run_lines): - if_true = 1 - if_false = 2 - status_dic = {} - branch_hit = 0 - branch_sum = len(branch_info) * 2 - if len(run_lines) > 0: - for info in branch_info: - if_status = 0 - if info[0] in run_lines: - if info[1] == '0': - branch_hit += 1 - if_status += if_false - if any(info[0] < line <= info[2] for line in run_lines): - branch_hit += 1 - if_status += if_true - else: - if any(info[0] < line < info[1] for line in run_lines): - branch_hit += 1 - if_status += if_true - if any(info[1] <= line <= info[2] for line in run_lines): - branch_hit += 1 - if_status += if_false - status_dic[str(info[0])] = if_status - return (branch_hit, branch_sum, status_dic) - -def count_loop_branch_cov(branch_info, run_lines): - branch_hit = 0 - branch_sum = len(branch_info) * 2 - if len(run_lines) > 0: - for info in branch_info: - if info[0] in run_lines: - branch_hit += 1 - if any(info[0] < line <= info[1] for line in run_lines): - branch_hit += 1 - if info[0] == info[1]: - branch_hit += 1 - return (branch_hit, branch_sum) - -def count_switch_branch_cov(branch_info, run_lines): - branch_hit = 0 - branch_sum = len(branch_info) - if len(run_lines) > 0: - for info in branch_info: - if any(info[0] <= line <= info[1] for line in run_lines): - branch_hit += 1 - return (branch_hit, branch_sum) - -def get_func_code_info(file_name, func_name, run_lines, all_lines): - file_name = os.path.abspath(file_name) - file_name = os.path.split(file_name)[1] - file_code_info = code_file_info["file_info"].get(file_name) - start_line = None - end_line = None - all_hit = 0 - all_sum = 0 - all_status = {} - if len(all_lines) > 0: - all_status = {str(i):3 if i in run_lines else 0 for i in all_lines} - if file_code_info != None: - func_code_info = file_code_info.get(func_name) - if func_code_info != None: - start_line = func_code_info["start_line"] - end_line = func_code_info['end_line'] - if_hit, if_sum, if_status = count_if_branch_cov(func_code_info["branch_info"]["if_branch"], run_lines) - loop_hit, loop_sum = count_loop_branch_cov(func_code_info["branch_info"]["loop_branch"], run_lines) - switch_hit, switch_sum = count_switch_branch_cov(func_code_info["branch_info"]["switch_branch"], run_lines) - all_hit = if_hit + loop_hit + switch_hit - all_sum = if_sum + loop_sum + switch_sum - all_status.update(if_status) - return (start_line, end_line, all_hit, all_sum, all_status) - -def pares_if(node): - else_line = 0 - count = 0 - for chi in node.get_children(): - if chi.kind != cc.CursorKind.UNEXPOSED_EXPR: - if chi.kind == cc.CursorKind.BINARY_OPERATOR and chi.location.line == node.extent.start.line: - continue - count += 1 - if count > 1 and chi.location.line - node.extent.start.line > 1: - else_line = chi.location.line - if else_line == node.extent.end.line: - else_line -= 1 - return [node.extent.start.line, else_line, node.extent.end.line] - -def pares_switch(node): - branch_list = [] - start_line_list = [] - for chi in node.get_children(): - if chi.kind == cc.CursorKind.COMPOUND_STMT: - for chi2 in chi.get_children(): - if chi2.kind in [cc.CursorKind.CASE_STMT, cc.CursorKind.DEFAULT_STMT]: - start_line_list.append(chi2.location.line) - start_line_list.append(node.extent.end.line) - for index in range(0, len(start_line_list)-1): - branch_list.append((start_line_list[index], start_line_list[index + 1] - 1)) - return branch_list - -def get_branch_info(node,branch_info,depth=0): - if node.kind == cc.CursorKind.IF_STMT: - start_line = node.extent.start.line - end_line = node.extent.end.line - if start_line == end_line: - pass - elif end_line - start_line == 1: - branch_info["if_branch"].append([start_line,0,end_line]) - else: - branch_info["if_branch"].append(pares_if(node)) - if node.kind in [cc.CursorKind.FOR_STMT, cc.CursorKind.WHILE_STMT]: - branch_info['loop_branch'].append((node.extent.start.line, node.extent.end.line)) - if node.kind == cc.CursorKind.SWITCH_STMT: - branch_info['switch_branch'].extend(pares_switch(node)) - if more_itertools.ilen(node.get_children()) != 0: - for chi in node.get_children(): - get_branch_info(chi,branch_info, depth+1) - -def get_func_info(node): - func_info = {} - if node.kind == cc.CursorKind.FUNCTION_DECL: - func_info = {} - func_info["start_line"] = node.extent.start.line - func_info["end_line"] = node.extent.end.line - func_info["branch_info"] = { - "loop_branch":[], - "if_branch":[], - "switch_branch":[] - } - for ch in node.get_children(): - get_branch_info(ch,func_info["branch_info"]) - return func_info - - -def get_info(node): - file_info = {} - for ch in node.get_children(): - if not str(ch.extent.start.file).endswith(".h")\ - and ch.kind == cc.CursorKind.FUNCTION_DECL: - file_info[ch.spelling.strip("_")] = get_func_info(ch) - return file_info \ No newline at end of file -- Gitee From 57c27df8261e7e4446e527865ad5d2b940dbf8e0 Mon Sep 17 00:00:00 2001 From: zevorn Date: Tue, 12 Apr 2022 20:43:19 +0800 Subject: [PATCH 03/11] [fix](command/ctrl): add the status check of the run and stop commands --- common/cli/skyeye_command.c | 15 +++++++++++++++ common/cli/skyeye_new_api.c | 9 +++++++-- common/ctrl/sim_ctrl.c | 28 ++++++++++++++++++++++------ common/include/sim_control.h | 4 ++-- common/include/skyeye_command.h | 4 ++++ 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/common/cli/skyeye_command.c b/common/cli/skyeye_command.c index 3c7b8e17..813bfcfb 100644 --- a/common/cli/skyeye_command.c +++ b/common/cli/skyeye_command.c @@ -51,6 +51,10 @@ * #include */ +/* Check if load machine */ +static int is_load_machine = 0; /* 0:Unloaded 1: loaded */ + + /* **************************************************************** */ /* */ /* predefined commands */ @@ -574,6 +578,16 @@ void complete_init() SKY_before_init_hap_occurred(); } +int skyeye_record_machine(void) +{ + is_load_machine = 1; +} + +int skyeye_find_machine(void) +{ + return is_load_machine; +} + /*init-ok command */ int prepare_to_run(void) { @@ -598,6 +612,7 @@ int prepare_to_run(void) pthread_t id; create_thread((void *) complete_init, NULL, &id); + skyeye_record_machine(); return 0; } diff --git a/common/cli/skyeye_new_api.c b/common/cli/skyeye_new_api.c index f4f3008e..2f600e79 100644 --- a/common/cli/skyeye_new_api.c +++ b/common/cli/skyeye_new_api.c @@ -57,8 +57,13 @@ SkyEyeAPIRetST skyeye_run() { SkyEyeAPIRetST ApiRet; memset(&ApiRet, 0, sizeof(SkyEyeAPIRetST)); - SIM_run(); - ApiRet.result = API_OK; + if (!SIM_run()) + { + ApiRet.result = API_OK; + } else + { + ApiRet.result = API_ERROR; + } return ApiRet; } diff --git a/common/ctrl/sim_ctrl.c b/common/ctrl/sim_ctrl.c index 4d026265..d6bcedfb 100644 --- a/common/ctrl/sim_ctrl.c +++ b/common/ctrl/sim_ctrl.c @@ -447,11 +447,19 @@ void SIM_cli() /** * @brief set the running state for the simulator */ -void SIM_run() +int SIM_run() { + if (skyeye_find_machine()) + { + SIM_running = True; + start_all_cell(); + return 0; /* ok */ + } else + { + SIM_running = False; + return 1; /* nok */ + } - SIM_running = True; - start_all_cell(); } /** @@ -471,11 +479,19 @@ void SIM_continue(generic_arch_t * arch_instance) * * @param arch_instance */ -void SIM_stop(generic_arch_t * arch_instance) +int SIM_stop(generic_arch_t * arch_instance) { //skyeye_pause(); - SIM_running = False; - stop_all_cell(); + + if (skyeye_find_machine()) + { + SIM_running = False; + stop_all_cell(); + return 0; /* ok */ + } else + { + return 1; /* nok */ + } } /** diff --git a/common/include/sim_control.h b/common/include/sim_control.h index a129f11a..6730339c 100755 --- a/common/include/sim_control.h +++ b/common/include/sim_control.h @@ -22,7 +22,7 @@ exception_t SIM_start(void); /* * Launch the simulator. */ -void SIM_run(void); +int SIM_run(void); /* @@ -59,7 +59,7 @@ void SIM_continue(generic_arch_t* arch_instance); /* * stop a processor */ -void SIM_stop(generic_arch_t* arch_instance); +int SIM_stop(generic_arch_t* arch_instance); void SIM_restart(void); bool_t SIM_is_running(void); diff --git a/common/include/skyeye_command.h b/common/include/skyeye_command.h index 3205ba2a..91fb1e84 100644 --- a/common/include/skyeye_command.h +++ b/common/include/skyeye_command.h @@ -10,6 +10,10 @@ typedef int (*command_func_t)(char* arg); exception_t add_command(char* command_name, command_func_t func, char* helper); exception_t run_command(char* command_str); +int skyeye_record_machine(void); +int skyeye_find_machine(void); + + #ifdef __cplusplus } #endif -- Gitee From 75bb28c9d23ea1b6671278b66980108b7b1400d9 Mon Sep 17 00:00:00 2001 From: zevorn Date: Tue, 12 Apr 2022 21:05:25 +0800 Subject: [PATCH 04/11] [fix](command/ctrl): add the status check of the run and stop commands --- common/cli/skyeye_command.c | 7 ++++++- common/ctrl/sim_ctrl.c | 3 +++ common/include/skyeye_command.h | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/common/cli/skyeye_command.c b/common/cli/skyeye_command.c index 813bfcfb..6799c29b 100644 --- a/common/cli/skyeye_command.c +++ b/common/cli/skyeye_command.c @@ -578,11 +578,16 @@ void complete_init() SKY_before_init_hap_occurred(); } -int skyeye_record_machine(void) +void skyeye_record_machine(void) { is_load_machine = 1; } +void skyeye_clear_machine(void) +{ + is_load_machine = 0; +} + int skyeye_find_machine(void) { return is_load_machine; diff --git a/common/ctrl/sim_ctrl.c b/common/ctrl/sim_ctrl.c index d6bcedfb..10019a9a 100644 --- a/common/ctrl/sim_ctrl.c +++ b/common/ctrl/sim_ctrl.c @@ -409,6 +409,9 @@ void SIM_reset(void) /*init system struct */ system_init(); + + /*clear load machine info */ + skyeye_clear_machine(); } /** diff --git a/common/include/skyeye_command.h b/common/include/skyeye_command.h index 91fb1e84..f9ba85ef 100644 --- a/common/include/skyeye_command.h +++ b/common/include/skyeye_command.h @@ -10,7 +10,8 @@ typedef int (*command_func_t)(char* arg); exception_t add_command(char* command_name, command_func_t func, char* helper); exception_t run_command(char* command_str); -int skyeye_record_machine(void); +void skyeye_record_machine(void); +void skyeye_clear_machine(void); int skyeye_find_machine(void); -- Gitee From 7df3218dec9ef1a3458ebbe564834208c94a91ca Mon Sep 17 00:00:00 2001 From: zevorn Date: Tue, 12 Apr 2022 21:35:40 +0800 Subject: [PATCH 05/11] [fix](command/ctrl): update the status check of the run and stop commands --- common/cli/skyeye_command.c | 18 ------------------ common/ctrl/sim_ctrl.c | 27 ++++++++++++++++++++++++++- common/include/sim_control.h | 15 +++++++++++++++ common/include/skyeye_command.h | 5 ----- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/common/cli/skyeye_command.c b/common/cli/skyeye_command.c index 6799c29b..58236427 100644 --- a/common/cli/skyeye_command.c +++ b/common/cli/skyeye_command.c @@ -51,10 +51,6 @@ * #include */ -/* Check if load machine */ -static int is_load_machine = 0; /* 0:Unloaded 1: loaded */ - - /* **************************************************************** */ /* */ /* predefined commands */ @@ -578,20 +574,6 @@ void complete_init() SKY_before_init_hap_occurred(); } -void skyeye_record_machine(void) -{ - is_load_machine = 1; -} - -void skyeye_clear_machine(void) -{ - is_load_machine = 0; -} - -int skyeye_find_machine(void) -{ - return is_load_machine; -} /*init-ok command */ int prepare_to_run(void) diff --git a/common/ctrl/sim_ctrl.c b/common/ctrl/sim_ctrl.c index 10019a9a..076085aa 100644 --- a/common/ctrl/sim_ctrl.c +++ b/common/ctrl/sim_ctrl.c @@ -62,6 +62,8 @@ const char *default_lib_dir = "/opt/skyeye/lib/skyeye/"; const char *default_lib_dir = SKYEYE_MODULE_DIR; #endif +static struct skyeye_sim_ctrl sim_ctrl; + #ifdef __MINGW32__ int setenv(const char *name, const char *value, int overwrite) { @@ -288,6 +290,11 @@ void SIM_init() */ init_chp(); + /* + * initialization of load machine info. + */ + skyeye_clear_machine(); + /* * get the current preference for simulator */ @@ -439,6 +446,22 @@ void SIM_quit(void) exit(0); } +void skyeye_record_machine(void) +{ + sim_ctrl.is_load_machine = LOADED_MACH; +} + +void skyeye_clear_machine(void) +{ + sim_ctrl.is_load_machine = UNLOADE_MACH; +} + +int skyeye_find_machine(void) +{ + return sim_ctrl.is_load_machine; +} + + /** * @brief all the cli */ @@ -452,7 +475,7 @@ void SIM_cli() */ int SIM_run() { - if (skyeye_find_machine()) + if (skyeye_find_machine() == LOADED_MACH) { SIM_running = True; start_all_cell(); @@ -587,6 +610,8 @@ void SIM_restart(void) skyeye_erase_map(); /* reset arch */ reset_arch(); + + skyeye_clear_machine(); if (!pref->module_search_dir) #ifndef __MINGW32__ diff --git a/common/include/sim_control.h b/common/include/sim_control.h index 6730339c..a0985338 100755 --- a/common/include/sim_control.h +++ b/common/include/sim_control.h @@ -9,6 +9,21 @@ //void SIM_init_environment(char **argv, bool handle_signals); //void SIM_init_simulators(init_prefs_t *init_prefs); +enum mach_status +{ + LOADED_MACH = 0, + UNLOADE_MACH = 1 +}; + +struct skyeye_sim_ctrl +{ + enum mach_status is_load_machine; +}; + +void skyeye_record_machine(void); +void skyeye_clear_machine(void); +int skyeye_find_machine(void); + /* * initialization of simulator. */ diff --git a/common/include/skyeye_command.h b/common/include/skyeye_command.h index f9ba85ef..3205ba2a 100644 --- a/common/include/skyeye_command.h +++ b/common/include/skyeye_command.h @@ -10,11 +10,6 @@ typedef int (*command_func_t)(char* arg); exception_t add_command(char* command_name, command_func_t func, char* helper); exception_t run_command(char* command_str); -void skyeye_record_machine(void); -void skyeye_clear_machine(void); -int skyeye_find_machine(void); - - #ifdef __cplusplus } #endif -- Gitee From 2fd2d29472b916d8baab7935ccef197893d48749 Mon Sep 17 00:00:00 2001 From: zevorn Date: Wed, 13 Apr 2022 15:14:20 +0800 Subject: [PATCH 06/11] [fix](command/ctrl): add struct of sim ctrl --- common/cli/skyeye_command.c | 2 +- common/ctrl/sim_ctrl.c | 70 +++++++++++++++++++++--------------- common/include/sim_control.h | 11 ++++-- 3 files changed, 50 insertions(+), 33 deletions(-) diff --git a/common/cli/skyeye_command.c b/common/cli/skyeye_command.c index 58236427..b3eac580 100644 --- a/common/cli/skyeye_command.c +++ b/common/cli/skyeye_command.c @@ -599,7 +599,7 @@ int prepare_to_run(void) pthread_t id; create_thread((void *) complete_init, NULL, &id); - skyeye_record_machine(); + sim_record_machine(); return 0; } diff --git a/common/ctrl/sim_ctrl.c b/common/ctrl/sim_ctrl.c index 076085aa..9106f6c8 100644 --- a/common/ctrl/sim_ctrl.c +++ b/common/ctrl/sim_ctrl.c @@ -62,7 +62,7 @@ const char *default_lib_dir = "/opt/skyeye/lib/skyeye/"; const char *default_lib_dir = SKYEYE_MODULE_DIR; #endif -static struct skyeye_sim_ctrl sim_ctrl; +static skyeye_sim_ctrl_t sim_ctrl; #ifdef __MINGW32__ int setenv(const char *name, const char *value, int overwrite) @@ -137,8 +137,7 @@ static skyeye_cell_t *default_cell = NULL; /** * @brief the flag of running or stop */ -static bool_t SIM_running = False; -static bool_t SIM_started = False; + void SIM_init_command_line(void) { } @@ -241,6 +240,11 @@ void SIM_init() sky_pref_t *pref; char *welcome_str = get_front_message(); + /* + * initialization of load machine info. + */ + init_sim_machine(); + #ifdef __WIN32__ SIM_set_python_home(); #endif @@ -290,10 +294,6 @@ void SIM_init() */ init_chp(); - /* - * initialization of load machine info. - */ - skyeye_clear_machine(); /* * get the current preference for simulator @@ -377,12 +377,12 @@ void SIM_init() */ exception_t SIM_start(void) { - if (SIM_started) + if (sim_ctrl->SIM_started) { printf("SkyEye has been started\n"); return Unknown_exp; } - SIM_started = True; + sim_ctrl->SIM_started = True; return No_exp; } @@ -392,7 +392,7 @@ exception_t SIM_start(void) void SIM_reset(void) { /*set skyeye status to stop */ - SIM_running = False; + sim_ctrl->SIM_running = False; free_core_symbol_info_list(); @@ -418,7 +418,7 @@ void SIM_reset(void) system_init(); /*clear load machine info */ - skyeye_clear_machine(); + sim_reset_machine(); } /** @@ -428,7 +428,7 @@ void SIM_quit(void) { /*set skyeye status to stop */ //exit(0); //Fix me gpio stop destroy when add lock - SIM_running = False; + sim_ctrl->SIM_running = False; /*stop all cell */ stop_all_cell(); @@ -446,19 +446,31 @@ void SIM_quit(void) exit(0); } -void skyeye_record_machine(void) +void init_sim_machine(void) { - sim_ctrl.is_load_machine = LOADED_MACH; + sim_ctrl = skyeye_mm_zero(sizeof (struct skyeye_sim_ctrl)); + sim_ctrl->is_load_machine = UNLOADE_MACH; } -void skyeye_clear_machine(void) +void sim_reset_machine(void) { - sim_ctrl.is_load_machine = UNLOADE_MACH; + sim_ctrl->is_load_machine = UNLOADE_MACH; + skyeye_free(sim_ctrl); } -int skyeye_find_machine(void) +void sim_record_machine(void) { - return sim_ctrl.is_load_machine; + sim_ctrl->is_load_machine = LOADED_MACH; +} + +void sim_clear_machine(void) +{ + sim_ctrl->is_load_machine = LOADED_MACH; +} + +int sim_find_machine(void) +{ + return sim_ctrl->is_load_machine; } @@ -475,14 +487,14 @@ void SIM_cli() */ int SIM_run() { - if (skyeye_find_machine() == LOADED_MACH) + if (sim_find_machine() == LOADED_MACH) { - SIM_running = True; + sim_ctrl->SIM_running = True; start_all_cell(); return 0; /* ok */ } else { - SIM_running = False; + sim_ctrl->SIM_running = False; return 1; /* nok */ } @@ -496,7 +508,7 @@ int SIM_run() void SIM_continue(generic_arch_t * arch_instance) { //skyeye_continue(); - SIM_running = True; + sim_ctrl->SIM_running = True; start_all_cell(); } @@ -509,9 +521,9 @@ int SIM_stop(generic_arch_t * arch_instance) { //skyeye_pause(); - if (skyeye_find_machine()) + if (sim_find_machine()) { - SIM_running = False; + sim_ctrl->SIM_running = False; stop_all_cell(); return 0; /* ok */ } else @@ -528,7 +540,7 @@ int SIM_stop(generic_arch_t * arch_instance) bool_t SIM_is_running() { - return SIM_running; + return sim_ctrl->SIM_running; } /** @@ -572,7 +584,7 @@ void del_from_cell(void); */ void SIM_restart(void) { - if (!SIM_started) + if (!sim_ctrl->SIM_started) { printf("SkyEye is very pure, you don't need to restart it!\n"); return; @@ -610,8 +622,8 @@ void SIM_restart(void) skyeye_erase_map(); /* reset arch */ reset_arch(); - - skyeye_clear_machine(); + + sim_reset_machine(); if (!pref->module_search_dir) #ifndef __MINGW32__ @@ -638,7 +650,7 @@ void SIM_restart(void) #else tcsetattr(0, TCSAFLUSH, &pref->saved_term); #endif - SIM_started = False; + sim_ctrl->SIM_started = False; } #if 1 diff --git a/common/include/sim_control.h b/common/include/sim_control.h index a0985338..3b1e381a 100755 --- a/common/include/sim_control.h +++ b/common/include/sim_control.h @@ -18,11 +18,16 @@ enum mach_status struct skyeye_sim_ctrl { enum mach_status is_load_machine; + bool_t SIM_running; + bool_t SIM_started; }; +typedef struct skyeye_sim_ctrl * skyeye_sim_ctrl_t; -void skyeye_record_machine(void); -void skyeye_clear_machine(void); -int skyeye_find_machine(void); +void init_sim_machine(void); +void sim_reset_machine(void); +void sim_record_machine(void); +void sim_clear_machine(void); +int sim_find_machine(void); /* * initialization of simulator. -- Gitee From 9e95dc942559aa98bc43ce943a4e31d29ee390be Mon Sep 17 00:00:00 2001 From: zevorn Date: Wed, 13 Apr 2022 15:19:59 +0800 Subject: [PATCH 07/11] [fix](command/ctrl): add struct of sim ctrl --- common/cli/skyeye_command.c | 2 +- common/ctrl/sim_ctrl.c | 70 +++++++++++++++++++++--------------- common/include/sim_control.h | 11 ++++-- 3 files changed, 50 insertions(+), 33 deletions(-) diff --git a/common/cli/skyeye_command.c b/common/cli/skyeye_command.c index 58236427..b3eac580 100644 --- a/common/cli/skyeye_command.c +++ b/common/cli/skyeye_command.c @@ -599,7 +599,7 @@ int prepare_to_run(void) pthread_t id; create_thread((void *) complete_init, NULL, &id); - skyeye_record_machine(); + sim_record_machine(); return 0; } diff --git a/common/ctrl/sim_ctrl.c b/common/ctrl/sim_ctrl.c index 076085aa..9106f6c8 100644 --- a/common/ctrl/sim_ctrl.c +++ b/common/ctrl/sim_ctrl.c @@ -62,7 +62,7 @@ const char *default_lib_dir = "/opt/skyeye/lib/skyeye/"; const char *default_lib_dir = SKYEYE_MODULE_DIR; #endif -static struct skyeye_sim_ctrl sim_ctrl; +static skyeye_sim_ctrl_t sim_ctrl; #ifdef __MINGW32__ int setenv(const char *name, const char *value, int overwrite) @@ -137,8 +137,7 @@ static skyeye_cell_t *default_cell = NULL; /** * @brief the flag of running or stop */ -static bool_t SIM_running = False; -static bool_t SIM_started = False; + void SIM_init_command_line(void) { } @@ -241,6 +240,11 @@ void SIM_init() sky_pref_t *pref; char *welcome_str = get_front_message(); + /* + * initialization of load machine info. + */ + init_sim_machine(); + #ifdef __WIN32__ SIM_set_python_home(); #endif @@ -290,10 +294,6 @@ void SIM_init() */ init_chp(); - /* - * initialization of load machine info. - */ - skyeye_clear_machine(); /* * get the current preference for simulator @@ -377,12 +377,12 @@ void SIM_init() */ exception_t SIM_start(void) { - if (SIM_started) + if (sim_ctrl->SIM_started) { printf("SkyEye has been started\n"); return Unknown_exp; } - SIM_started = True; + sim_ctrl->SIM_started = True; return No_exp; } @@ -392,7 +392,7 @@ exception_t SIM_start(void) void SIM_reset(void) { /*set skyeye status to stop */ - SIM_running = False; + sim_ctrl->SIM_running = False; free_core_symbol_info_list(); @@ -418,7 +418,7 @@ void SIM_reset(void) system_init(); /*clear load machine info */ - skyeye_clear_machine(); + sim_reset_machine(); } /** @@ -428,7 +428,7 @@ void SIM_quit(void) { /*set skyeye status to stop */ //exit(0); //Fix me gpio stop destroy when add lock - SIM_running = False; + sim_ctrl->SIM_running = False; /*stop all cell */ stop_all_cell(); @@ -446,19 +446,31 @@ void SIM_quit(void) exit(0); } -void skyeye_record_machine(void) +void init_sim_machine(void) { - sim_ctrl.is_load_machine = LOADED_MACH; + sim_ctrl = skyeye_mm_zero(sizeof (struct skyeye_sim_ctrl)); + sim_ctrl->is_load_machine = UNLOADE_MACH; } -void skyeye_clear_machine(void) +void sim_reset_machine(void) { - sim_ctrl.is_load_machine = UNLOADE_MACH; + sim_ctrl->is_load_machine = UNLOADE_MACH; + skyeye_free(sim_ctrl); } -int skyeye_find_machine(void) +void sim_record_machine(void) { - return sim_ctrl.is_load_machine; + sim_ctrl->is_load_machine = LOADED_MACH; +} + +void sim_clear_machine(void) +{ + sim_ctrl->is_load_machine = LOADED_MACH; +} + +int sim_find_machine(void) +{ + return sim_ctrl->is_load_machine; } @@ -475,14 +487,14 @@ void SIM_cli() */ int SIM_run() { - if (skyeye_find_machine() == LOADED_MACH) + if (sim_find_machine() == LOADED_MACH) { - SIM_running = True; + sim_ctrl->SIM_running = True; start_all_cell(); return 0; /* ok */ } else { - SIM_running = False; + sim_ctrl->SIM_running = False; return 1; /* nok */ } @@ -496,7 +508,7 @@ int SIM_run() void SIM_continue(generic_arch_t * arch_instance) { //skyeye_continue(); - SIM_running = True; + sim_ctrl->SIM_running = True; start_all_cell(); } @@ -509,9 +521,9 @@ int SIM_stop(generic_arch_t * arch_instance) { //skyeye_pause(); - if (skyeye_find_machine()) + if (sim_find_machine()) { - SIM_running = False; + sim_ctrl->SIM_running = False; stop_all_cell(); return 0; /* ok */ } else @@ -528,7 +540,7 @@ int SIM_stop(generic_arch_t * arch_instance) bool_t SIM_is_running() { - return SIM_running; + return sim_ctrl->SIM_running; } /** @@ -572,7 +584,7 @@ void del_from_cell(void); */ void SIM_restart(void) { - if (!SIM_started) + if (!sim_ctrl->SIM_started) { printf("SkyEye is very pure, you don't need to restart it!\n"); return; @@ -610,8 +622,8 @@ void SIM_restart(void) skyeye_erase_map(); /* reset arch */ reset_arch(); - - skyeye_clear_machine(); + + sim_reset_machine(); if (!pref->module_search_dir) #ifndef __MINGW32__ @@ -638,7 +650,7 @@ void SIM_restart(void) #else tcsetattr(0, TCSAFLUSH, &pref->saved_term); #endif - SIM_started = False; + sim_ctrl->SIM_started = False; } #if 1 diff --git a/common/include/sim_control.h b/common/include/sim_control.h index a0985338..2248f219 100755 --- a/common/include/sim_control.h +++ b/common/include/sim_control.h @@ -17,12 +17,17 @@ enum mach_status struct skyeye_sim_ctrl { + bool_t SIM_running; + bool_t SIM_started; enum mach_status is_load_machine; }; +typedef struct skyeye_sim_ctrl * skyeye_sim_ctrl_t; -void skyeye_record_machine(void); -void skyeye_clear_machine(void); -int skyeye_find_machine(void); +void init_sim_machine(void); +void sim_reset_machine(void); +void sim_record_machine(void); +void sim_clear_machine(void); +int sim_find_machine(void); /* * initialization of simulator. -- Gitee From 809dc0f4d2783808a21d551e8922bb42dd572470 Mon Sep 17 00:00:00 2001 From: zevorn Date: Wed, 13 Apr 2022 15:20:53 +0800 Subject: [PATCH 08/11] [fix](command/ctrl): add struct of sim ctrl --- common/include/sim_control.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/common/include/sim_control.h b/common/include/sim_control.h index 5e1e9b1e..2248f219 100755 --- a/common/include/sim_control.h +++ b/common/include/sim_control.h @@ -20,8 +20,6 @@ struct skyeye_sim_ctrl bool_t SIM_running; bool_t SIM_started; enum mach_status is_load_machine; - bool_t SIM_running; - bool_t SIM_started; }; typedef struct skyeye_sim_ctrl * skyeye_sim_ctrl_t; -- Gitee From d5256f7e9baea30910bacfcb83fe5d7f0a4bf1a4 Mon Sep 17 00:00:00 2001 From: zevorn Date: Wed, 13 Apr 2022 21:09:33 +0800 Subject: [PATCH 09/11] [fix](command/ctrl): update struct of sim ctrl --- common/ctrl/sim_ctrl.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/common/ctrl/sim_ctrl.c b/common/ctrl/sim_ctrl.c index 9106f6c8..ff732859 100644 --- a/common/ctrl/sim_ctrl.c +++ b/common/ctrl/sim_ctrl.c @@ -62,7 +62,7 @@ const char *default_lib_dir = "/opt/skyeye/lib/skyeye/"; const char *default_lib_dir = SKYEYE_MODULE_DIR; #endif -static skyeye_sim_ctrl_t sim_ctrl; +static struct skyeye_sim_ctrl sim_ctrl; #ifdef __MINGW32__ int setenv(const char *name, const char *value, int overwrite) @@ -377,12 +377,12 @@ void SIM_init() */ exception_t SIM_start(void) { - if (sim_ctrl->SIM_started) + if (sim_ctrl.SIM_started) { printf("SkyEye has been started\n"); return Unknown_exp; } - sim_ctrl->SIM_started = True; + sim_ctrl.SIM_started = True; return No_exp; } @@ -392,7 +392,7 @@ exception_t SIM_start(void) void SIM_reset(void) { /*set skyeye status to stop */ - sim_ctrl->SIM_running = False; + sim_ctrl.SIM_running = False; free_core_symbol_info_list(); @@ -428,7 +428,7 @@ void SIM_quit(void) { /*set skyeye status to stop */ //exit(0); //Fix me gpio stop destroy when add lock - sim_ctrl->SIM_running = False; + sim_ctrl.SIM_running = False; /*stop all cell */ stop_all_cell(); @@ -448,29 +448,29 @@ void SIM_quit(void) void init_sim_machine(void) { - sim_ctrl = skyeye_mm_zero(sizeof (struct skyeye_sim_ctrl)); - sim_ctrl->is_load_machine = UNLOADE_MACH; + sim_ctrl.is_load_machine = UNLOADE_MACH; + sim_ctrl.SIM_running = False; + sim_ctrl.SIM_started = False; } void sim_reset_machine(void) { - sim_ctrl->is_load_machine = UNLOADE_MACH; - skyeye_free(sim_ctrl); + sim_ctrl.is_load_machine = UNLOADE_MACH; } void sim_record_machine(void) { - sim_ctrl->is_load_machine = LOADED_MACH; + sim_ctrl.is_load_machine = LOADED_MACH; } void sim_clear_machine(void) { - sim_ctrl->is_load_machine = LOADED_MACH; + sim_ctrl.is_load_machine = LOADED_MACH; } int sim_find_machine(void) { - return sim_ctrl->is_load_machine; + return sim_ctrl.is_load_machine; } @@ -489,12 +489,12 @@ int SIM_run() { if (sim_find_machine() == LOADED_MACH) { - sim_ctrl->SIM_running = True; + sim_ctrl.SIM_running = True; start_all_cell(); return 0; /* ok */ } else { - sim_ctrl->SIM_running = False; + sim_ctrl.SIM_running = False; return 1; /* nok */ } @@ -508,7 +508,7 @@ int SIM_run() void SIM_continue(generic_arch_t * arch_instance) { //skyeye_continue(); - sim_ctrl->SIM_running = True; + sim_ctrl.SIM_running = True; start_all_cell(); } @@ -523,7 +523,7 @@ int SIM_stop(generic_arch_t * arch_instance) if (sim_find_machine()) { - sim_ctrl->SIM_running = False; + sim_ctrl.SIM_running = False; stop_all_cell(); return 0; /* ok */ } else @@ -540,7 +540,7 @@ int SIM_stop(generic_arch_t * arch_instance) bool_t SIM_is_running() { - return sim_ctrl->SIM_running; + return sim_ctrl.SIM_running; } /** @@ -584,7 +584,7 @@ void del_from_cell(void); */ void SIM_restart(void) { - if (!sim_ctrl->SIM_started) + if (!sim_ctrl.SIM_started) { printf("SkyEye is very pure, you don't need to restart it!\n"); return; @@ -650,7 +650,7 @@ void SIM_restart(void) #else tcsetattr(0, TCSAFLUSH, &pref->saved_term); #endif - sim_ctrl->SIM_started = False; + sim_ctrl.SIM_started = False; } #if 1 -- Gitee From 63874117270982f69dc7445992d8f9fdd3f9fe8e Mon Sep 17 00:00:00 2001 From: zevorn Date: Wed, 13 Apr 2022 21:18:46 +0800 Subject: [PATCH 10/11] [fix](command/ctrl): update struct of sim ctrl --- common/ctrl/sim_ctrl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/common/ctrl/sim_ctrl.c b/common/ctrl/sim_ctrl.c index ff732859..8db4cc04 100644 --- a/common/ctrl/sim_ctrl.c +++ b/common/ctrl/sim_ctrl.c @@ -456,6 +456,8 @@ void init_sim_machine(void) void sim_reset_machine(void) { sim_ctrl.is_load_machine = UNLOADE_MACH; + sim_ctrl.SIM_running = False; + sim_ctrl.SIM_started = False; } void sim_record_machine(void) -- Gitee From ccb74d4f08e7f6398f11bfe7374d40236c84b99d Mon Sep 17 00:00:00 2001 From: zevorn Date: Wed, 13 Apr 2022 21:41:43 +0800 Subject: [PATCH 11/11] [fix](command/ctrl): update struct of sim ctrl --- common/ctrl/sim_ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/ctrl/sim_ctrl.c b/common/ctrl/sim_ctrl.c index 8db4cc04..f9eaa04d 100644 --- a/common/ctrl/sim_ctrl.c +++ b/common/ctrl/sim_ctrl.c @@ -523,7 +523,7 @@ int SIM_stop(generic_arch_t * arch_instance) { //skyeye_pause(); - if (sim_find_machine()) + if (sim_find_machine() == LOADED_MACH) { sim_ctrl.SIM_running = False; stop_all_cell(); -- Gitee