diff --git a/Docs/sphinx_documentation/source/Debugging.rst b/Docs/sphinx_documentation/source/Debugging.rst index aa5a9dcc9a..6808bc2715 100644 --- a/Docs/sphinx_documentation/source/Debugging.rst +++ b/Docs/sphinx_documentation/source/Debugging.rst @@ -100,6 +100,14 @@ The following runtime options need to be set in order to prevent AMReX from catc This default behavior can also be modified by applications, see for example `this custom application initializer `__. +Alternatively, set the environment variable ``AMREX_DEBUG`` to change the defaults in the same way: + +.. code-block: console + + export AMREX_DEBUG=1 + +Note that input and command line arguments always have precedence over environment variables. + .. _sec:gpu:debugging: diff --git a/Src/Base/AMReX.cpp b/Src/Base/AMReX.cpp index b4aa8f4490..e30c81220b 100644 --- a/Src/Base/AMReX.cpp +++ b/Src/Base/AMReX.cpp @@ -66,6 +66,7 @@ #include #endif +#include #include #include #include @@ -334,10 +335,22 @@ amrex::Initialize (int& argc, char**& argv, bool build_parm_parse, std::ostream& a_osout, std::ostream& a_oserr, ErrorHandler a_errhandler) { + // trying to use AMReX in a debugger? + char const *env_amrex_debug = std::getenv("AMREX_DEBUG"); + bool amrex_debug = false; + if (env_amrex_debug != nullptr) { + std::string str_amrex_debug{env_amrex_debug}; + for(auto& c : str_amrex_debug) { c = std::tolower(c); } + + if (str_amrex_debug == "1" || str_amrex_debug == "on" || str_amrex_debug == "true") { + amrex_debug = true; + } + } + system::exename.clear(); // system::verbose = 0; system::regtest_reduction = false; - system::signal_handling = true; + system::signal_handling = !amrex_debug; system::handle_sigsegv = true; system::handle_sigterm = false; system::handle_sigint = true; @@ -345,7 +358,7 @@ amrex::Initialize (int& argc, char**& argv, bool build_parm_parse, system::handle_sigfpe = true; system::handle_sigill = true; system::call_addr2line = true; - system::throw_exception = false; + system::throw_exception = amrex_debug; system::osout = &a_osout; system::oserr = &a_oserr; system::error_handler = a_errhandler;