]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make sure that copying exceptions doesn't imply dropping the backtrace.
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 20 Aug 2021 21:57:54 +0000 (15:57 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 20 Aug 2021 21:57:54 +0000 (15:57 -0600)
include/deal.II/base/exceptions.h
source/base/exceptions.cc

index d882028436d445e2c04048a3d27eaf9344c63f92..a30b345155057a3f6732960e5f33a358c1c8c9a5 100644 (file)
@@ -155,7 +155,7 @@ protected:
 
 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
   /**
-   * array of pointers that contains the raw stack trace
+   * Array of pointers that contains the raw stack trace.
    */
   void *raw_stacktrace[25];
 #endif
index f45a6f614f588e0874af6d4b9ba919fd76f11c0c..b04ef3588203b605f841314ddedab102f4f5fcee 100644 (file)
@@ -59,18 +59,24 @@ namespace deal_II_exceptions
     bool allow_abort_on_exception = true;
   } // namespace internals
 
+
+
   void
   set_additional_assert_output(const std::string &p)
   {
     internals::get_additional_assert_output() = p;
   }
 
+
+
   void
   suppress_stacktrace_in_exceptions()
   {
     internals::show_stacktrace = false;
   }
 
+
+
   void
   disable_abort_on_exception()
   {
@@ -104,13 +110,17 @@ ExceptionBase::ExceptionBase(const ExceptionBase &exc)
   , cond(exc.cond)
   , exc(exc.exc)
   , stacktrace(nullptr)
-  , // don't copy stacktrace to avoid double de-allocation problem
-  n_stacktrace_frames(0)
+  , n_stacktrace_frames(exc.n_stacktrace_frames)
   , what_str("") // don't copy the error message, it gets generated dynamically
                  // by what()
 {
 #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE
-  std::fill(std::begin(raw_stacktrace), std::end(raw_stacktrace), nullptr);
+  // Copy the raw_stacktrace pointers. We don't own them, they just point to the
+  // addresses of symbols in the executable's/library's symbol tables -- and as
+  // a consequence, it is safe to copy these pointers
+  std::copy(std::begin(exc.raw_stacktrace),
+            std::end(exc.raw_stacktrace),
+            std::begin(raw_stacktrace));
 #endif
 }
 
@@ -147,6 +157,8 @@ ExceptionBase::set_fields(const char *f,
 #endif
 }
 
+
+
 const char *
 ExceptionBase::what() const noexcept
 {
@@ -170,6 +182,7 @@ ExceptionBase::what() const noexcept
 }
 
 
+
 const char *
 ExceptionBase::get_exc_name() const
 {

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.