From 0f481ad9f139d36e1e9b5b078994396493233aba Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Thu, 24 May 2018 18:02:59 +1200 Subject: rtemstoolkit: Add an output routine for a std::exception. The output routine is used by a number of tools. --- rtemstoolkit/rld.cpp | 15 +++++++++++++++ rtemstoolkit/rld.h | 5 +++++ 2 files changed, 20 insertions(+) (limited to 'rtemstoolkit') 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 +#include #include #include @@ -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 @@ -104,6 +104,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. */ -- cgit v1.2.3