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: frontend: cpp: improve cfg #1987

Merged
merged 4 commits into from
Jan 16, 2025
Merged
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
31 changes: 19 additions & 12 deletions src/fuzz_introspector/frontends/frontend_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,7 @@ def _extract_information(self):

# Handles class or namespace in the function name
if '::' in self.name:
prefix, _ = self.name.rsplit('::', 1)
if self.namespace_or_class and prefix:
self.namespace_or_class += f'::{prefix}'
else:
self.namespace_or_class = prefix
self.namespace_or_class, _ = self.name.rsplit('::', 1)

# Handles return type
type_node = self.root.child_by_field_name('type')
Expand Down Expand Up @@ -361,6 +357,8 @@ def _traverse_node_instr_count(node: Node) -> int:
def _process_invoke(self, expr: Node,
project) -> list[tuple[str, int, int]]:
"""Internal helper for processing the function invocation statement."""
logger.debug('Handling invoke statmenet: %s', expr.text.decode())
logger.debug('Current namespace: %s', self.namespace_or_class)
callsites = []
target_name: str = ''

Expand All @@ -379,10 +377,12 @@ def _process_invoke(self, expr: Node,

# Find the matching function in our project
logger.debug('Matching function %s', target_name)
matched_func = project.find_function_from_approximate_name(
target_name)
matched_func = get_function_node(
target_name,
project.all_functions,
namespace=self.namespace_or_class)
if matched_func:
logger.debug('Matched function')
logger.debug('Matched function: %s', matched_func.name)
target_name = matched_func.name
else:
logger.debug('Did not find matching function')
Expand Down Expand Up @@ -947,10 +947,10 @@ def analyse_source_code(source_content: str) -> SourceCodeFile:
return source_code


def get_function_node(
target_name: str,
function_list: List[FunctionDefinition],
one_layer_only: bool = False) -> Optional[FunctionDefinition]:
def get_function_node(target_name: str,
function_list: List[FunctionDefinition],
one_layer_only: bool = False,
namespace: str = '') -> Optional[FunctionDefinition]:
"""Helper to retrieve the RustFunction object of a function."""

logger.debug('Finding match for %s', target_name)
Expand All @@ -959,6 +959,13 @@ def get_function_node(
logger.debug('Found exact match')
return function

if namespace:
logger.debug('Finding function within namespace %s', namespace)
for function in function_list:
if namespace + '::' + target_name == function.name:
logger.debug('Found namespace match')
return function

# Exact match
# if target_name in function_map:
# return function_map[target_name]
Expand Down
Loading