Skip to content

Commit

Permalink
Merge pull request #102 from acceleratedtech/jwise/riscv
Browse files Browse the repository at this point in the history
move enhance_call_tree_pattern to gcc_tools, and teach gcc_tools how to pick up call trees for RISC-V
  • Loading branch information
noahp authored Aug 12, 2024
2 parents 9e5f178 + 3202c04 commit 48b288e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
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

0 comments on commit 48b288e

Please sign in to comment.