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

move enhance_call_tree_pattern to gcc_tools, and teach gcc_tools how to pick up call trees for RISC-V #102

Merged
merged 1 commit into from
Aug 12, 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
9 changes: 1 addition & 8 deletions puncover/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,11 @@ def add_function_call(self, caller, callee):
if callee_file and caller_file and callee_file != caller_file:
callee["called_from_other_file"] = True

# 934: f7ff bba8 b.w 88 <jump_to_pbl_function>
# 8e4: f000 f824 bl 930 <app_log>
#
# but not:
# 805bbac: 2471 0805 b64b 0804 b3c9 0804 b459 0804 q$..K.......Y...
enhance_call_tree_pattern = re.compile(r"^\s*[\da-f]+:\s+[\d\sa-f]{9}\s+BL?(EQ|NE|CS|HS|CC|LO|MI|PL|VS|VC|HI|LS|GE|LT|GT|LE|AL)?(\.W|\.N)?\s+([\d\sa-f]+)", re.IGNORECASE)

def enhance_call_tree_from_assembly_line(self, function, line):
if "<" not in line:
return False

match = self.enhance_call_tree_pattern.match(line)
match = self.gcc_tools.enhance_call_tree_pattern.match(line)

if match:
callee = self.symbol_by_addr(match.group(3))
Expand Down
11 changes: 11 additions & 0 deletions puncover/gcc_tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import subprocess
import re

import itertools

Expand All @@ -12,6 +13,16 @@ def __init__(self, gcc_base_filename):

self.gcc_base_filename = gcc_base_filename

if 'riscv' in gcc_base_filename:
self.enhance_call_tree_pattern = re.compile(r"^\s*[\da-f]+:\s+[\d\sa-f]{9}\s+(J|JAL|JR|JALR|BEQZ|BNEZ|BEQ|BNE|NLT|BGE|BLTU|BGEU)()\s+([\d\sa-f]+)", re.IGNORECASE)
else: # ARM
# 934: f7ff bba8 b.w 88 <jump_to_pbl_function>
# 8e4: f000 f824 bl 930 <app_log>
#
# but not:
# 805bbac: 2471 0805 b64b 0804 b3c9 0804 b459 0804 q$..K.......Y...
self.enhance_call_tree_pattern = re.compile(r"^\s*[\da-f]+:\s+[\d\sa-f]{9}\s+BL?(EQ|NE|CS|HS|CC|LO|MI|PL|VS|VC|HI|LS|GE|LT|GT|LE|AL)?(\.W|\.N)?\s+([\d\sa-f]+)", re.IGNORECASE)

def gcc_tool_path(self, name):
path = self.gcc_base_filename + name
if os.name == 'nt':
Expand Down