diff --git a/python/deps/pytrace-generator/main.py b/python/deps/pytrace-generator/main.py index 9a784fd..b9f34c1 100644 --- a/python/deps/pytrace-generator/main.py +++ b/python/deps/pytrace-generator/main.py @@ -155,7 +155,8 @@ def format(self): return [frame.format() for frame in self.frames] class Heap: - def __init__(self): + def __init__(self, script_path): + self.script_path = script_path self.memory = {} def store(self, address, value): @@ -202,7 +203,7 @@ def store(self, address, value): except: # Just ignore it in case getattr fails continue - if should_ignore_on_heap(field, v): + if should_ignore_on_heap(field, v, self.script_path): continue prim_value = PrimitiveValue(v) @@ -234,7 +235,7 @@ def format(self): } -def should_ignore(variable_name, value, ignore_list = []): +def should_ignore(variable_name, value, script_path, ignore_list = []): if variable_name in ignore_list or variable_name.startswith("__"): return True if inspect.isfunction(value) or inspect.ismethod(value) or inspect.isbuiltin(value): @@ -245,24 +246,27 @@ def should_ignore(variable_name, value, ignore_list = []): return True if inspect.isframe(value): return True + if hasattr(value, "__module__"): + if not sys.modules[value.__module__].__file__.startswith(script_path): + return True return False -def should_ignore_on_stack(variable_name, value, ignore_list = []): - if should_ignore(variable_name, value, ignore_list): +def should_ignore_on_stack(variable_name, value, script_path, ignore_list = []): + if should_ignore(variable_name, value, script_path, ignore_list): return True return False -def should_ignore_on_heap(variable_name, value, ignore_list = []): - if should_ignore(variable_name, value, ignore_list): +def should_ignore_on_heap(variable_name, value, script_path, ignore_list = []): + if should_ignore(variable_name, value, script_path, ignore_list): return True return False -def generate_heap(frame, ignore): - heap = Heap() +def generate_heap(frame, script_path, ignore): + heap = Heap(script_path) while True: for variable_name in frame.f_locals: - if should_ignore_on_stack(variable_name, frame.f_locals[variable_name], ignore): + if should_ignore_on_stack(variable_name, frame.f_locals[variable_name], script_path, ignore): continue if primitive_type(type(frame.f_locals[variable_name])) != "ref": continue @@ -313,10 +317,10 @@ def trace_dispatch(self, frame, event, arg): self.stack.pop_frame() elif event == "line": for variable_name in frame.f_locals: - if should_ignore_on_stack(variable_name, frame.f_locals[variable_name],self.stack_ignore): + if should_ignore_on_stack(variable_name, frame.f_locals[variable_name], self.filename, self.stack_ignore): continue self.stack.push(variable_name, frame.f_locals[variable_name]) - heap = generate_heap(frame, self.stack_ignore) + heap = generate_heap(frame, self.filename, self.stack_ignore) step = TraceStep(line, filename, copy.deepcopy(self.stack), copy.deepcopy(heap)) diff --git a/python/deps/pytrace-generator/test/test-cases/importWypp.py b/python/deps/pytrace-generator/test/test-cases/importWypp.py new file mode 100644 index 0000000..b095763 --- /dev/null +++ b/python/deps/pytrace-generator/test/test-cases/importWypp.py @@ -0,0 +1 @@ +from wypp import * \ No newline at end of file diff --git a/python/deps/pytrace-generator/test/test-cases/importWypp.py.json b/python/deps/pytrace-generator/test/test-cases/importWypp.py.json new file mode 100644 index 0000000..69f974f --- /dev/null +++ b/python/deps/pytrace-generator/test/test-cases/importWypp.py.json @@ -0,0 +1,24 @@ +[ + { + "line": 1, + "filePath": "importWypp.py", + "stack": [ + { + "frameName": "", + "locals": [] + } + ], + "heap": {} + }, + { + "line": 2, + "filePath": "importWypp.py", + "stack": [ + { + "frameName": "", + "locals": [] + } + ], + "heap": {} + } +] \ No newline at end of file diff --git a/python/deps/pytrace-generator/test/test-cases/module1.py b/python/deps/pytrace-generator/test/test-cases/module1.py new file mode 100644 index 0000000..6acd97b --- /dev/null +++ b/python/deps/pytrace-generator/test/test-cases/module1.py @@ -0,0 +1,3 @@ +# This test ensures that module2 can be imported and used +import module2 +b = module2.myfun(1) diff --git a/python/deps/pytrace-generator/test/test-cases/module2.py b/python/deps/pytrace-generator/test/test-cases/module2.py new file mode 100644 index 0000000..67670c9 --- /dev/null +++ b/python/deps/pytrace-generator/test/test-cases/module2.py @@ -0,0 +1,5 @@ +def myfun(i): + i += 1 + i += 1 + i += 1 + return i