diff options
author | Chris Johns <chrisj@rtems.org> | 2018-05-24 18:02:59 +1200 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2018-05-25 09:27:01 +1200 |
commit | 2b607c2d7e59b2d961eab23d33e0f6e3a5f54067 (patch) | |
tree | a4061e29dc908f8802158abe62410232dcef6959 | |
parent | 7b43281e54ac9900c81d70d2045b27617f0a6433 (diff) |
rtemstoolkit: Add an output routine for a std::exception.
The output routine is used by a number of tools.
-rw-r--r-- | rtemstoolkit/rld.cpp | 15 | ||||
-rw-r--r-- | rtemstoolkit/rld.h | 5 |
2 files changed, 20 insertions, 0 deletions
diff --git a/rtemstoolkit/rld.cpp b/rtemstoolkit/rld.cpp index acce748..90fb39d 100644 --- a/rtemstoolkit/rld.cpp +++ b/rtemstoolkit/rld.cpp @@ -28,6 +28,7 @@ #include <iostream> +#include <cxxabi.h> #include <sys/stat.h> #include <rld.h> @@ -81,6 +82,20 @@ namespace rld */ static uint64_t _version_revision; + void + output_std_exception (std::exception e, std::ostream& out) + { + int status; + char* realname; + realname = abi::__cxa_demangle (e.what(), 0, 0, &status); + out << "error: exception: " << realname << " ["; + ::free (realname); + const std::type_info &ti = typeid (e); + realname = abi::__cxa_demangle (ti.name(), 0, 0, &status); + out << realname << "] " << e.what () << std::endl; + ::free (realname); + } + bool starts_with(const std::string& s1, const std::string& s2) { diff --git a/rtemstoolkit/rld.h b/rtemstoolkit/rld.h index 2b6a40d..1031a54 100644 --- a/rtemstoolkit/rld.h +++ b/rtemstoolkit/rld.h @@ -105,6 +105,11 @@ namespace rld }; /** + * Handle a standard exception. + */ + void output_std_exception (std::exception e, std::ostream& out); + + /** * A convenience macro to make where a file and line number. */ #define rld_error_at(_what) \ |