summaryrefslogtreecommitdiff
path: root/src/python/m5
diff options
context:
space:
mode:
authorSteve Reinhardt <steve.reinhardt@amd.com>2014-01-03 17:08:43 -0800
committerSteve Reinhardt <steve.reinhardt@amd.com>2014-01-03 17:08:43 -0800
commitd8c9b5431b05550ee3a232e95af50a5e3d9ce4b5 (patch)
tree19c011c33deb91c72f32b8feb3c502628efedb45 /src/python/m5
parentba9ec669bcf68e4d4e3322f07e5f51af19f05b4a (diff)
downloadgem5-d8c9b5431b05550ee3a232e95af50a5e3d9ce4b5.tar.xz
python: provide better error message for wrapped C++ methods
If you successfully export a C++ SimObject method, but try to invoke it from Python before the C++ object is created, you get a confusing error that says the attribute does not exist, making you question whether you successfully exported the method at all. In reality, your only problem is that you're calling the method too soon. This patch enhances the error message to give you a better clue.
Diffstat (limited to 'src/python/m5')
-rw-r--r--src/python/m5/SimObject.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py
index 013f609d6..fc5416cbf 100644
--- a/src/python/m5/SimObject.py
+++ b/src/python/m5/SimObject.py
@@ -724,9 +724,15 @@ class SimObject(object):
if self._ccObject and hasattr(self._ccObject, attr):
return getattr(self._ccObject, attr)
- raise AttributeError, "object '%s' has no attribute '%s'" \
+ err_string = "object '%s' has no attribute '%s'" \
% (self.__class__.__name__, attr)
+ if not self._ccObject:
+ err_string += "\n (C++ object is not yet constructed," \
+ " so wrapped C++ methods are unavailable.)"
+
+ raise AttributeError, err_string
+
# Set attribute (called on foo.attr = value when foo is an
# instance of class cls).
def __setattr__(self, attr, value):