Skip to content

Commit

Permalink
Adjust comparison for new yaml format
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonievonMann committed Feb 8, 2024
1 parent 1326c39 commit 59625d3
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 130 deletions.
228 changes: 118 additions & 110 deletions tests/data/test_ast_blame_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,120 +21,128 @@
"""

YAML_DOC_BA_LINE = """---
annotations:
0=bitcasti32*resulttoi8*,!dbg!23,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
1=loadi32,i32*x.addr,align4,!dbg!25,!tbaa!18,!BlameRegion!26:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
2=loadi32,i32*result,align4,!dbg!31,!tbaa!18,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
3=bitcasti32*resulttoi8*,!dbg!32,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
add=addnswi321,42,!dbg!28,!BlameRegion!26:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
call1=calli32(i8*,...)@printf(i8*noundefgetelementptrinbounds([3xi8],[3xi8]*@.str,i640,i640),i32noundefcall),!dbg!17,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
call=callnoundefi32@_Z19calculate_somethingi(i32noundef4),!dbg!16,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
[email protected](metadatai32*result,metadata!17,metadata!DIExpression()),!dbg!24:
dbghash: ''
varahash: ''
[email protected](metadatai32*x.addr,metadata!16,metadata!DIExpression()),!dbg!22:
dbghash: ''
varahash: ''
[email protected](i644,i8*3)#5,!dbg!32,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
[email protected](i644,i8*0)#5,!dbg!23,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
result=allocai32,align4,!BlameRegion!0:
dbghash: ''
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
reti320,!dbg!18,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
reti322,!dbg!33,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
storei32sub,i32*result,align4,!dbg!30,!tbaa!18,!BlameRegion!26:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
storei32x,i32*x.addr,align4,!tbaa!18,!BlameRegion!0:
dbghash: ''
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
sub=subnswi32add,1,!dbg!29,!BlameRegion!26:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
x.addr=allocai32,align4,!BlameRegion!0:
dbghash: ''
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
functions:
_Z19calculate_somethingi:
annotations:
0=bitcasti32*resulttoi8*:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
1=loadi32,i32*x.addr,align4:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
2=loadi32,i32*result,align4:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
3=bitcasti32*resulttoi8*:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
add=addnswi321,42:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
[email protected](metadatai32*result,metadata!17,metadata!DIExpression()):
dbghash: ''
varahash: ''
[email protected](metadatai32*x.addr,metadata!16,metadata!DIExpression()):
dbghash: ''
varahash: ''
[email protected](i644,i8*3)#5:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
[email protected](i644,i8*0)#5:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
result=allocai32,align4:
dbghash: ''
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
reti322:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
storei32sub,i32*result,align4:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
storei32x,i32*x.addr,align4:
dbghash: ''
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
sub=subnswi32add,1:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
x.addr=allocai32,align4:
dbghash: ''
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
main:
annotations:
call1=calli32(i8*,...)@printf(i8*noundefgetelementptrinbounds([3xi8],[3xi8]*@.str,i640,i640),i32noundefcall):
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
call=callnoundefi32@_Z19calculate_somethingi(i32noundef4):
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
reti320:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
...
"""

YAML_DOC_BA_AST = """---
annotations:
0=bitcasti32*resulttoi8*,!dbg!23,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
1=loadi32,i32*x.addr,align4,!dbg!25,!tbaa!18,!BlameRegion!0:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
2=loadi32,i32*result,align4,!dbg!31,!tbaa!18,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
3=bitcasti32*resulttoi8*,!dbg!32,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
add=addnswi321,42,!dbg!26,!BlameRegion!0:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
call1=calli32(i8*,...)@printf(i8*noundefgetelementptrinbounds([3xi8],[3xi8]*@.str,i640,i640),i32noundefcall),!dbg!17,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
call=callnoundefi32@_Z19calculate_somethingi(i32noundef4),!dbg!16,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
[email protected](metadatai32*result,metadata!17,metadata!DIExpression()),!dbg!24:
dbghash: ''
varahash: ''
[email protected](metadatai32*x.addr,metadata!16,metadata!DIExpression()),!dbg!22:
dbghash: ''
varahash: ''
[email protected](i644,i8*3)#5,!dbg!32,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
[email protected](i644,i8*0)#5,!dbg!23,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
result=allocai32,align4,!BlameRegion!0:
dbghash: ''
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
reti320,!dbg!18,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
reti322,!dbg!33,!BlameRegion!0:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
storei32sub,i32*result,align4,!dbg!30,!tbaa!18,!BlameRegion!0:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
storei32x,i32*x.addr,align4,!tbaa!18,!BlameRegion!0:
dbghash: ''
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
sub=subnswi32add,1,!dbg!27,!BlameRegion!28:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
x.addr=allocai32,align4,!BlameRegion!0:
dbghash: ''
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
functions:
_Z19calculate_somethingi:
annotations:
0=bitcasti32*resulttoi8*:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
1=loadi32,i32*x.addr,align4:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
2=loadi32,i32*result,align4:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
3=bitcasti32*resulttoi8*:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
add=addnswi321,42:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
[email protected](metadatai32*result,metadata!17,metadata!DIExpression()):
dbghash: ''
varahash: ''
[email protected](metadatai32*x.addr,metadata!16,metadata!DIExpression()):
dbghash: ''
varahash: ''
[email protected](i644,i8*3)#5:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
[email protected](i644,i8*0)#5:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
result=allocai32,align4:
dbghash: ''
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
reti322:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
storei32sub,i32*result,align4:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
storei32x,i32*x.addr,align4:
dbghash: ''
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
sub=subnswi32add,1:
dbghash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
varahash: 2b9a08d1adb63d2db9283811f79ac66e373ccfe9
x.addr=allocai32,align4:
dbghash: ''
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
main:
annotations:
call1=calli32(i8*,...)@printf(i8*noundefgetelementptrinbounds([3xi8],[3xi8]*@.str,i640,i640),i32noundefcall):
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
call=callnoundefi32@_Z19calculate_somethingi(i32noundef4):
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
reti320:
dbghash: 2553b819d9434f3396727617438dc0d6ae39b056
varahash: 2553b819d9434f3396727617438dc0d6ae39b056
...
"""

Expand Down
63 changes: 43 additions & 20 deletions varats/varats/data/reports/blame_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,27 @@ def varahash(self) -> str:
return self.__varahash


class BlameFunctionAnnotations():
"""Contains all instruction annotations for one function."""

def __init__(self) -> None:
self.__blame_annotations = {}

Check failure on line 43 in varats/varats/data/reports/blame_annotations.py

View workflow job for this annotation

GitHub Actions / mypy

[mypy] varats/varats/data/reports/blame_annotations.py#L43

error: Need type annotation for "__blame_annotations" (hint: "__blame_annotations: Dict[<type>, <type>] = ...") [var-annotated]
Raw output
varats/varats/data/reports/blame_annotations.py:43:9: error: Need type annotation for "__blame_annotations" (hint: "__blame_annotations: Dict[<type>, <type>] = ...")  [var-annotated]

def add_annotation(self, name: str, inst: BlameInstruction) -> None:
self.__blame_annotations[name] = inst

@property
def blame_annotations(self) -> tp.Dict[str, BlameInstruction]:
"""Iterate over all blame annotations."""
return self.__blame_annotations


class BlameAnnotations(BaseReport, shorthand="BA", file_type="yaml"):
"""Report containing debug blame and blame annotations."""

def __init__(self, path: Path) -> None:
super().__init__(path)
self.__blame_annotations = {}
self.__functions = {}

with open(path, 'r') as stream:
documents = yaml.load_all(stream, Loader=yaml.CLoader)
Expand All @@ -50,18 +65,22 @@ def __init__(self, path: Path) -> None:

raw_blame_report = next(documents)

for raw_entry in raw_blame_report['annotations']:
new_entry = (
BlameInstruction.create_blame_instruction(
raw_blame_report['annotations'][raw_entry]
for func in raw_blame_report['functions']:
new_func = BlameFunctionAnnotations()
func_entry = raw_blame_report['functions'][func]
for raw_entry in func_entry['annotations']:
new_entry = (
BlameInstruction.create_blame_instruction(
func_entry['annotations'][raw_entry]
)
)
)
self.__blame_annotations[raw_entry] = new_entry
new_func.add_annotation(raw_entry, new_entry)
self.__functions[func] = new_func

@property
def blame_annotations(self) -> tp.ValuesView[BlameInstruction]:
def functions(self) -> tp.ValuesView[BlameFunctionAnnotations]:
"""Iterate over all blame annotations."""
return self.__blame_annotations.values()
return self.__functions.values()


class ASTBlameReport(BaseReport, shorthand="BAST", file_type="yaml"):
Expand Down Expand Up @@ -133,16 +152,20 @@ def compare_blame_annotations(
based to the AST based blame."""
ast_report = ASTBlameReport(path)

for entry in ast_ba.blame_annotations:
if entry.dbghash and entry.varahash:
ast_report.update_dbg_ast(entry.dbghash != entry.varahash)

for line_entry, ast_entry in zip(
line_ba.blame_annotations, ast_ba.blame_annotations
):
if line_entry.varahash and ast_entry.varahash:
ast_report.update_line_ast(
line_entry.varahash != ast_entry.varahash
)
for func in ast_ba.functions:
for entry in func.blame_annotations.values():
if entry.dbghash and entry.varahash:
ast_report.update_dbg_ast(entry.dbghash != entry.varahash)

for line_func, ast_func in zip(line_ba.functions, ast_ba.functions):
line_annotations = line_func.blame_annotations
ast_annotations = ast_func.blame_annotations
for inst in ast_annotations:
if line_annotations[inst].varahash and ast_annotations[inst
].varahash:
ast_report.update_line_ast(
line_annotations[inst].varahash !=
ast_annotations[inst].varahash
)

return ast_report

0 comments on commit 59625d3

Please sign in to comment.