]> https://gitweb.dealii.org/ - dealii.git/commitdiff
try to break in gdb when Assert fails 4497/head
authorTimo Heister <timo.heister@gmail.com>
Wed, 7 Jun 2017 17:26:07 +0000 (19:26 +0200)
committerTimo Heister <timo.heister@gmail.com>
Wed, 7 Jun 2017 17:36:20 +0000 (19:36 +0200)
addresses #4490 (as good as we can do it), improves #4413

source/base/exceptions.cc

index 6f7c217dd08fbbf113fa7f2672f7c45bebfff31d..90c8962e8b300fda42677ef97bedc6fe06140fc5 100644 (file)
@@ -421,14 +421,30 @@ namespace deal_II_exceptions
           // if the others don't recognize this, or at the very least
           // delay their termination until they realize that their
           // communication with the job that died times out.
+          //
+          // Unlike std::abort(), MPI_Abort() unfortunately doesn't break when
+          // running inside a debugger like GDB, so only use this strategy if
+          // absolutely necessary and inform the user how to use a debugger.
 #ifdef DEAL_II_WITH_MPI
           int is_initialized;
           MPI_Initialized(&is_initialized);
           if (is_initialized)
-            MPI_Abort (MPI_COMM_WORLD,
-                       /* return code = */ 255);
-          else
-            std::abort ();
+            {
+              const unsigned int n_proc = Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD);
+              if (n_proc>1)
+                {
+                  std::cerr << "Calling MPI_Abort now.\n"
+                            << "To break execution in a GDB session, execute 'break MPI_Abort' before "
+                            << "running. You can also put the following into your ~/.gdbinit:\n"
+                            << "  set breakpoint pending on\n"
+                            << "  break MPI_Abort\n"
+                            << "  set breakpoint pending auto" << std::endl;
+
+                  MPI_Abort (MPI_COMM_WORLD,
+                             /* return code = */ 255);
+                }
+            }
+          std::abort ();
 #else
           std::abort();
 #endif

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.