Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/30295 )

Change subject: sim: Add some helpers to catch and reporting using unbound ports.
......................................................................

sim: Add some helpers to catch and reporting using unbound ports.

If a port is unbound, trying to call its peer will likely cause a
segfault. Rather than check if a port is bound every time you go to use
it, we can instead bind to a default peer which just throws an exception
back to the caller. The caller can catch the exception and report the
error.

This change adds a common new class to throw as the exception, and also
a small utility function which reports the error and dies.

Change-Id: Ia58a2030922c73e2fd7d139822bce38d9b0f2171
---
M src/sim/port.cc
M src/sim/port.hh
2 files changed, 13 insertions(+), 0 deletions(-)



diff --git a/src/sim/port.cc b/src/sim/port.cc
index 7ca8db6..9131f84 100644
--- a/src/sim/port.cc
+++ b/src/sim/port.cc
@@ -45,7 +45,16 @@

 #include "sim/port.hh"

+#include "base/logging.hh"
+
 Port::Port(const std::string& _name, PortID _id) :
     portName(_name), id(_id), _peer(nullptr), _connected(false)
 {}
 Port::~Port() {}
+
+
+void
+Port::reportUnbound() const
+{
+    fatal("%s: Unconnected port!", name());
+}
diff --git a/src/sim/port.hh b/src/sim/port.hh
index 251624c..85472d0 100644
--- a/src/sim/port.hh
+++ b/src/sim/port.hh
@@ -63,6 +63,10 @@

   protected:

+    class UnboundPortException {};
+
+    [[noreturn]] void reportUnbound() const;
+
     /**
      * A numeric identifier to distinguish ports in a vector, and set
      * to InvalidPortID in case this port is not part of a vector.

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/30295
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ia58a2030922c73e2fd7d139822bce38d9b0f2171
Gerrit-Change-Number: 30295
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to