python: Improve SimObject's warning when parent specified twice
authorHoa Nguyen <hoanguyen@ucdavis.edu>
Tue, 8 Dec 2020 01:45:18 +0000 (17:45 -0800)
committerHoa Nguyen <hoanguyen@ucdavis.edu>
Tue, 22 Dec 2020 09:52:23 +0000 (09:52 +0000)
SimObject outputs a warning when its parent is specified more than
once. The cause is most likely that there is unexpected param
specified in the constructor called in the Python interface.

This commit adds a note about this probable cause of this potential
error to the warning message.

Change-Id: I9b6bf5d5fb0c77bfdad5fde42e88f814e8a4b72b
Signed-off-by: Hoa Nguyen <hoanguyen@ucdavis.edu>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/38359
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/python/m5/SimObject.py

index f8d6c27e6e8e3ec234756ee0979ff4abf72370c6..b47d98d833eb99a06e0362870cd0a2cc7bf02746 100644 (file)
@@ -1484,8 +1484,9 @@ class SimObject(object):
     def add_child(self, name, child):
         child = coerceSimObjectOrVector(child)
         if child.has_parent():
-            warn("add_child('%s'): child '%s' already has parent", name,
-                child.get_name())
+            warn(f"{self}.{name} already has parent (Previously declared as "
+                 f"{child._parent}.{name}).\n"
+                 f"\tNote: {name} is not a parameter of {type(self).__name__}")
         if name in self._children:
             # This code path had an undiscovered bug that would make it fail
             # at runtime. It had been here for a long time and was only