From 59625d334db20a6ab8c81978d701bd7768815f97 Mon Sep 17 00:00:00 2001 From: Leonie von Mann Date: Thu, 8 Feb 2024 08:40:59 +0100 Subject: [PATCH] Adjust comparison for new yaml format --- tests/data/test_ast_blame_report.py | 228 +++++++++--------- .../varats/data/reports/blame_annotations.py | 63 +++-- 2 files changed, 161 insertions(+), 130 deletions(-) diff --git a/tests/data/test_ast_blame_report.py b/tests/data/test_ast_blame_report.py index 068d3a552..ee936c94b 100644 --- a/tests/data/test_ast_blame_report.py +++ b/tests/data/test_ast_blame_report.py @@ -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 - callvoid@llvm.dbg.declare(metadatai32*result,metadata!17,metadata!DIExpression()),!dbg!24: - dbghash: '' - varahash: '' - callvoid@llvm.dbg.declare(metadatai32*x.addr,metadata!16,metadata!DIExpression()),!dbg!22: - dbghash: '' - varahash: '' - callvoid@llvm.lifetime.end.p0i8(i644,i8*3)#5,!dbg!32,!BlameRegion!0: - dbghash: 2553b819d9434f3396727617438dc0d6ae39b056 - varahash: 2553b819d9434f3396727617438dc0d6ae39b056 - callvoid@llvm.lifetime.start.p0i8(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 + callvoid@llvm.dbg.declare(metadatai32*result,metadata!17,metadata!DIExpression()): + dbghash: '' + varahash: '' + callvoid@llvm.dbg.declare(metadatai32*x.addr,metadata!16,metadata!DIExpression()): + dbghash: '' + varahash: '' + callvoid@llvm.lifetime.end.p0i8(i644,i8*3)#5: + dbghash: 2553b819d9434f3396727617438dc0d6ae39b056 + varahash: 2553b819d9434f3396727617438dc0d6ae39b056 + callvoid@llvm.lifetime.start.p0i8(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 - callvoid@llvm.dbg.declare(metadatai32*result,metadata!17,metadata!DIExpression()),!dbg!24: - dbghash: '' - varahash: '' - callvoid@llvm.dbg.declare(metadatai32*x.addr,metadata!16,metadata!DIExpression()),!dbg!22: - dbghash: '' - varahash: '' - callvoid@llvm.lifetime.end.p0i8(i644,i8*3)#5,!dbg!32,!BlameRegion!0: - dbghash: 2553b819d9434f3396727617438dc0d6ae39b056 - varahash: 2553b819d9434f3396727617438dc0d6ae39b056 - callvoid@llvm.lifetime.start.p0i8(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 + callvoid@llvm.dbg.declare(metadatai32*result,metadata!17,metadata!DIExpression()): + dbghash: '' + varahash: '' + callvoid@llvm.dbg.declare(metadatai32*x.addr,metadata!16,metadata!DIExpression()): + dbghash: '' + varahash: '' + callvoid@llvm.lifetime.end.p0i8(i644,i8*3)#5: + dbghash: 2553b819d9434f3396727617438dc0d6ae39b056 + varahash: 2553b819d9434f3396727617438dc0d6ae39b056 + callvoid@llvm.lifetime.start.p0i8(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 ... """ diff --git a/varats/varats/data/reports/blame_annotations.py b/varats/varats/data/reports/blame_annotations.py index b35c4061e..aa2c10408 100644 --- a/varats/varats/data/reports/blame_annotations.py +++ b/varats/varats/data/reports/blame_annotations.py @@ -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 = {} + + 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) @@ -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"): @@ -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