def get_src_lines_of_IR_func(file_name, func_name, db_config): host, db_user, db_password, db_name = read_config(db_config) db = MySQLdb.connect(host, db_user, db_password, db_name, charset='utf8', autocommit=True) db_cursor = db.cursor() get_debug_info_sql = "SELECT * FROM bb_range \ WHERE bb_file = '%s' and bb_label like '%s\\%%%%'" % (file_name,func_name) try: db_cursor.execute(get_debug_info_sql) debug_info_list = db_cursor.fetchall() except: print("Error:", get_debug_info_sql) return [] db.close() lines = [] for bb_info in debug_info_list: if(bb_info[0] != bb_info[2]): print("!!! some inst not in raw file ", bb_info[0], ", now in ", bb_info[2]) # FIXIT: whether it is needed to consider these cross-file inline insts else: lines.append(bb_info[3]) # lines_unduplicated = list(set(lines)).sort(key=lines.index) return lines
def get_src_lines_of_IR_bb1(file_name, func_name , label, db_config): # get debug info of this function host, db_user, db_password, db_name = read_config(db_config) db = MySQLdb.connect(host, db_user, db_password, db_name, charset='utf8', autocommit=True) db_cursor = db.cursor() # disallow inline insts in other files here, since their line is the number in another file. get_debug_info_sql = "SELECT * FROM bb_range \ WHERE bb_file = '%s' and bb_label like '%s\\%%%%'" % (file_name,func_name) try: db_cursor.execute(get_debug_info_sql) debug_info_list = db_cursor.fetchall() # print(get_debug_info_sql) except: print("Error:", get_debug_info_sql) return [] db.close() lines = [] for bb_info in debug_info_list: if(bb_info[0] != bb_info[2]): print("!!! some inst of bb not in raw file ", bb_info[0], ", now in ", bb_info[2]) # FIXIT: whether it is needed to consider these cross-file inline insts else: full_label = bb_info[1] label1 = full_label.split('%')[1] if label1 == label: lines.append(bb_info[3]) # lines_unduplicated = list(set(lines)).sort(key=lines.index) return lines
def build_IR_cfg(file_name, func_name, db_config): host, db_user, db_password, db_name = read_config(db_config) db = MySQLdb.connect(host, db_user, db_password, db_name, charset='utf8', autocommit=True) cursor = db.cursor() edges = IR2graph.get_edges_in_file_from_db(cursor, file_name) edges = IR2graph.filter_edges_by_func(edges, func_name) CFG = IR2graph.build_graph_from_edges(edges) db.close() return CFG
def addr2line(addr, db_config, bin_name=None): host, db_user, db_password, db_name = read_config(db_config) db = MySQLdb.connect(host, db_user, db_password, db_name, charset='utf8', autocommit=True) cursor = db.cursor() res = addr2line_with_db_cache(addr, cursor, bin_name) db.close() return res
def line_of_ir_bb(file_name, func_name, db_config): # get debug info of this function host, db_user, db_password, db_name = read_config(db_config) db = MySQLdb.connect(host, db_user, db_password, db_name, charset='utf8', autocommit=True) db_cursor = db.cursor() # disallow inline insts in other files here, since their line is the number in another file. get_debug_info_sql = "SELECT * FROM bb_range \ WHERE bb_file = '%s' and bb_label like '%s\\%%%%'" % (file_name,func_name) try: db_cursor.execute(get_debug_info_sql) debug_info_list = db_cursor.fetchall() # print(get_debug_info_sql) except: print("Error:", get_debug_info_sql) return [] db.close() # get all the BBs a line can be in line_label_map = {} for bb_info in debug_info_list: if(bb_info[0] != bb_info[2]): print("!!! some inst not in raw file ", bb_info[0], ", now in ", bb_info[2]) # FIXIT: whether it is needed to consider these cross-file inline insts else: full_label = bb_info[1] label = full_label.split('%')[1] line = bb_info[3] line_label_map.setdefault(line,[]).append(label) # bb_2_exclusive_lines, the map of some BB and all its exclusive src-lines. bb_2_exclusive_lines = {} for line in line_label_map: if len(line_label_map[line])== 1: distinct_bb = line_label_map[line][0] bb_2_exclusive_lines.setdefault(distinct_bb,[]).append(line) return bb_2_exclusive_lines