Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Env Variable: AMREX_DEBUG #4165

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>`__.

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:

Expand Down
17 changes: 15 additions & 2 deletions Src/Base/AMReX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include <cfenv>
#endif

#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
Expand Down Expand Up @@ -334,18 +335,30 @@ 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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, I cannot track memory violations in gdb:

gdb -ex r -ex bt --args warpx ...

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
Loading