Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: fix style issues #1457

Merged
merged 4 commits into from
Mar 4, 2024
Merged
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
50 changes: 42 additions & 8 deletions src/fuzz_introspector/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ def load_debug_report(self):
self.debug_all_functions = debug_info.load_debug_all_yaml_files(
self.debug_function_files)

tmp_debug_functions = dict()
no_path_debug_funcs = list()
for func in self.debug_all_functions:
if func['file_location'].strip() == '':
no_path_debug_funcs.append(func)
else:
tmp_debug_functions[func['file_location']] = func

self.debug_all_functions = no_path_debug_funcs + list(
tmp_debug_functions.values())

# Extract the raw function signature. This propagates types into all of
# the debug functions.
debug_info.clean_extract_raw_all_debugged_function_signatures(
Expand Down Expand Up @@ -696,13 +707,13 @@ def detect_branch_level_blockers(


def extract_namespace(mangled_function_name, return_type=None):
logger.info("Demangling: %s" % (mangled_function_name))
# logger.info("Demangling: %s" % (mangled_function_name))
demangled_func_name = utils.demangle_cpp_func(mangled_function_name)
logger.info("Demangled name: %s" % (demangled_func_name))
# logger.info("Demangled name: %s" % (demangled_func_name))
if return_type is not None and demangled_func_name.startswith(
f"{return_type} "):
demangled_func_name = demangled_func_name[len(return_type) + 1:]
logger.info("Removed function type: %s" % (demangled_func_name))
# logger.info("Removed function type: %s" % (demangled_func_name))
if "::" not in demangled_func_name:
return []

Expand All @@ -719,7 +730,7 @@ def extract_namespace(mangled_function_name, return_type=None):
else:
name_spaces.append(elem)

logger.info("split namespace: %s" % (str(name_spaces)))
# logger.info("split namespace: %s" % (str(name_spaces)))
return name_spaces


Expand Down Expand Up @@ -827,9 +838,12 @@ def convert_param_list_to_str_v2(param_list):


def correlate_introspector_func_to_debug_information_v2(
if_func, all_debug_functions):
if_func, all_debug_functions, debug_dict_by_name,
debug_dict_by_filename):
# Check if name matches. If so, this one is easy.
for debug_function in all_debug_functions:
same_name_dfs = debug_dict_by_name.get(if_func['Func name'], [])

for debug_function in same_name_dfs:
if debug_function.get('name', '') == if_func['Func name']:
func_signature = convert_debug_info_to_signature_v2(
debug_function, if_func)
Expand All @@ -839,7 +853,9 @@ def correlate_introspector_func_to_debug_information_v2(
target_minimum = 999999
tfunc_signature = None
most_likely_func = None
for dfunction in all_debug_functions:

for dfunction in debug_dict_by_filename.get(if_func['Functions filename'],
[]):
try:
dline = int(dfunction['source'].get('source_line', '-1'))
except ValueError:
Expand Down Expand Up @@ -874,9 +890,27 @@ def correlate_introspector_func_to_debug_information_v2(

def correlate_introspection_functions_to_debug_info_v2(
all_functions_json_report, debug_all_functions):

debug_dict_by_name = dict()
debug_dict_by_filename = dict()
for df in debug_all_functions:
entry_list1 = debug_dict_by_name.get(df.get('name', ''), [])
entry_list1.append(df)
debug_dict_by_name[df.get('name', '')] = entry_list1

entry_list2 = debug_dict_by_filename.get(
df['source'].get('source_file', ''), [])
entry_list2.append(df)
debug_dict_by_filename[df['source'].get('source_file',
'')] = entry_list2

for dl3 in debug_dict_by_filename:
print("%s ------- %d" % (dl3, len(debug_dict_by_filename[dl3])))

for if_func in all_functions_json_report:
func_sig, correlated_debug_function = correlate_introspector_func_to_debug_information_v2(
if_func, debug_all_functions)
if_func, debug_all_functions, debug_dict_by_name,
debug_dict_by_filename)

if func_sig is not None:
if_func['function_signature'] = func_sig
Expand Down
31 changes: 17 additions & 14 deletions src/fuzz_introspector/debug_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,8 @@ def load_debug_all_yaml_files(debug_all_types_files):
return elem_list


def find_type_with_addr(target_type, all_debug_types):
for debug_type in all_debug_types:
if int(debug_type['addr']) == int(target_type):
return debug_type
return None


def extract_func_sig_friendly_type_tags(target_type, all_debug_types):
def extract_func_sig_friendly_type_tags(target_type, all_debug_types,
debug_type_dictionary):
if int(target_type) == 0:
return ['void']

Expand All @@ -361,7 +355,7 @@ def extract_func_sig_friendly_type_tags(target_type, all_debug_types):
tags.append("Infinite loop")
break

target_type = find_type_with_addr(type_to_query, all_debug_types)
target_type = debug_type_dictionary.get(int(type_to_query), None)
if target_type is None:
tags.append("N/A")
break
Expand Down Expand Up @@ -389,10 +383,11 @@ def extract_func_sig_friendly_type_tags(target_type, all_debug_types):
return tags


def extract_debugged_function_signature(dfunc, all_debug_types):
def extract_debugged_function_signature(dfunc, all_debug_types,
debug_type_dictionary):
try:
return_type = extract_func_sig_friendly_type_tags(
dfunc['type_arguments'][0], all_debug_types)
dfunc['type_arguments'][0], all_debug_types, debug_type_dictionary)
except IndexError:
return_type = 'N/A'
params = []
Expand All @@ -401,7 +396,8 @@ def extract_debugged_function_signature(dfunc, all_debug_types):
for i in range(1, len(dfunc['type_arguments'])):
params.append(
extract_func_sig_friendly_type_tags(dfunc['type_arguments'][i],
all_debug_types))
all_debug_types,
debug_type_dictionary))

source_file = dfunc['file_location'].split(":")[0]
try:
Expand All @@ -421,10 +417,17 @@ def extract_debugged_function_signature(dfunc, all_debug_types):
def clean_extract_raw_all_debugged_function_signatures(all_debug_types,
all_debug_functions):
print("Correlating")
for dfunc in all_debug_functions:
debug_type_dictionary = dict()
for debug_type in all_debug_types:
debug_type_dictionary[int(debug_type['addr'])] = debug_type

idx = 0
for dfunc in all_debug_functions:
logger.info("idx: %d" % (idx))
idx += 1
func_signature_elems, source_location = extract_debugged_function_signature(
dfunc, all_debug_types)
dfunc, all_debug_types, debug_type_dictionary)

dfunc['func_signature_elems'] = func_signature_elems
dfunc['source'] = source_location

Expand Down
Loading