Skip to content

Commit

Permalink
Env Variable: AMREX_DEBUG
Browse files Browse the repository at this point in the history
Introduce control of backtrace handling and exception throwing via
the environment variable `AMREX_DEBUG`.

This is very handly when running CI/CD and IDE workflows to quickly
debug a failing test without overwriting default init parameters.
  • Loading branch information
ax3l committed Sep 23, 2024
1 parent 467dd68 commit 84c7ade
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Docs/sphinx_documentation/source/Debugging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/Exawind/amr-wind/blob/84f81a990152f4f748c1ab0fa17c8c663e51df86/amr-wind/main.cpp#L21>`__.

The above default can also be achieve by setting the environment variable ``AMREX_DEBUG``:

.. highlight:: console

::

export AMREX_DEBUG=1


.. _sec:gpu:debugging:

Expand Down
18 changes: 16 additions & 2 deletions Src/Base/AMReX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,18 +334,32 @@ 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 : test) { c = 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;
system::handle_sigabrt = true;
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;
Expand Down

0 comments on commit 84c7ade

Please sign in to comment.