python: Updates to improve debugging output

This changeset updates SimObject and Proxy so that certain errors are
easier to diagnose. In SimObject, the warn() statement could cause
another exception, so it's split into two statements. In Proxy, it is
helpful to know which attribute is referenced when there's a mistake.

Change-Id: I3704a247b8b40e18ffc5e4a6241a74829313c07e
Signed-off-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/51787
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Jason Lowe-Power
2021-10-19 10:50:07 -07:00
committed by Jason Lowe-Power
parent 56494ed699
commit 8f33e9e34e
2 changed files with 4 additions and 3 deletions

View File

@@ -1534,9 +1534,9 @@ class SimObject(object, metaclass=MetaSimObject):
def add_child(self, name, child):
child = coerceSimObjectOrVector(child)
if child.has_parent():
warn(f"{self}.{name} already has parent (Previously declared as "
f"{child._parent}.{name}), not resetting parent.\n"
warn(f"{self}.{name} already has parent not resetting parent.\n"
f"\tNote: {name} is not a parameter of {type(self).__name__}")
warn(f"(Previously declared as {child._parent}.{name}")
return
if name in self._children:
# This code path had an undiscovered bug that would make it fail

View File

@@ -172,7 +172,8 @@ class AttrProxy(BaseProxy):
if attr.startswith('_'):
return super(AttrProxy, self).__getattr__(self, attr)
if hasattr(self, '_pdesc'):
raise AttributeError("Attribute reference on bound proxy")
raise AttributeError("Attribute reference on bound proxy "
f"({self}.{attr})")
# Return a copy of self rather than modifying self in place
# since self could be an indirect reference via a variable or
# parameter