Skip to content

Commit

Permalink
Introduce: AMReX_ADDRLINES (Default: ON)
Browse files Browse the repository at this point in the history
This is addign the new CMake option `AMReX_ADDRLINES` and CMake public
interface target `AMReX::Flags_ADDRLINES`. This option adds
*minimal* debug info (`-g1` / `-gline-tables-only`) to executables,
which generates more usable backtraces on crashes.

In symmetry to GNUmake, we turn this now ON. This is a breaking change.

Note that this flag still creates significant binary size overheads,
so package managers might decide to turn if off in deployments. Also,
if the increased binary sizes lead to significant startup overhead
at scale on HPC systems, we might need to reconsider the default
(for CMake and GNUmake) in the future.
  • Loading branch information
ax3l committed Mar 2, 2024
1 parent 9751217 commit 6a43082
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Docs/sphinx_documentation/source/BuildingAMReX.rst
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@ The list of available options is reported in the :ref:`table <tab:cmakevar>` bel
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
| AMReX_FPE | Build with Floating Point Exceptions checks | NO | YES, NO |
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
| AMReX_ADDRLINES | Build with minimal debug info for line numbers | YES | YES, NO |
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
| AMReX_ASSERTIONS | Build with assertions turned on | NO | YES, NO |
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
| AMReX_BOUND_CHECK | Enable bound checking in Array4 class | NO | YES, NO |
Expand Down Expand Up @@ -618,6 +620,8 @@ In the above snippet, ``<amrex-target-name>`` is any of the targets listed in th
+-----------------------+-------------------------------------------------+
| Flags_FPE | Floating Point Exception flags (interface) |
+-----------------------+-------------------------------------------------+
| Flags_ADDRLINES | Minimal debug/line numbers flags (interface) |
+-----------------------+-------------------------------------------------+
.. raw:: latex

\end{center}
Expand Down
3 changes: 3 additions & 0 deletions Docs/sphinx_documentation/source/Debugging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ with ``TEST=TRUE`` or ``DEBUG=TRUE`` in GNU make, or with ``-DCMAKE_BUILD_TYPE=D
One can also control the setting for ``FArrayBox`` using the runtime parameter, ``fab.init_snan``.
Note for Macs, M1 and M2 chips using Arm64 architecture are not able to trap division by zero.

By default, even AMReX release mode builds add minimal address to line debub information.
This can be turned off via ``-DAMReX_ADDRLINES=NO``.

One can get more information than the backtrace of the call stack by
instrumenting the code. Here is an example.
You know the line ``Real rho = state(cell,0);`` is causing a segfault. You
Expand Down
7 changes: 7 additions & 0 deletions Src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ foreach(D IN LISTS AMReX_SPACEDIM)
$<BUILD_INTERFACE:Flags_FPE>
)
endif ()

if (AMReX_ADDRLINES)
target_link_libraries(amrex_${D}d
PUBLIC
$<BUILD_INTERFACE:Flags_ADDRLINES>
)
endif ()
endforeach()

# General configuration
Expand Down
1 change: 1 addition & 0 deletions Tools/CMake/AMReXConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ set(AMReX_HDF5_ZFP_FOUND @AMReX_HDF5_ZFP@)

# Compilation options
set(AMReX_FPE_FOUND @AMReX_FPE@)
set(AMReX_ADDRLINES_FOUND @AMReX_ADDRLINES@)
set(AMReX_PIC_FOUND @AMReX_PIC@)
set(AMReX_ASSERTIONS_FOUND @AMReX_ASSERTIONS@)

Expand Down
19 changes: 19 additions & 0 deletions Tools/CMake/AMReXFlagsTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Flags_CXX --> Optional flags for C++ code
# Flags_Fortran --> Optional flags for Fortran code
# Flags_FPE --> Floating-Point Exception flags for both C++ and Fortran
# Flags_ADDRLINES --> Minimal debug flags that only record address to line number
#
# These INTERFACE targets can be added to the AMReX export set.
#
Expand Down Expand Up @@ -61,6 +62,24 @@ else ()
endif ()


#
# Minimal Debug info for address --> line
#
add_library(Flags_ADDRLINES INTERFACE)
add_library(AMReX::Flags_ADDRLINES ALIAS Flags_ADDRLINES)

target_compile_options( Flags_ADDRLINES
INTERFACE
$<${_cxx_gnu}:-g1>
$<${_cxx_intel}:> # TODO: help wanted
$<${_cxx_pgi}:> # TODO: help wanted
$<${_cxx_cray}:> # TODO: help wanted
$<${_cxx_clang}:-gline-tables-only>
$<${_cxx_appleclang}:-gline-tables-only>
# info for profiling: minimal addition and needed for Intel VTune
$<${_cxx_intelllvm}:-gline-tables-only -fdebug-info-for-profiling>
)

#
# C++ flags
#
Expand Down
5 changes: 4 additions & 1 deletion Tools/CMake/AMReXOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ print_option( AMReX_IPO )
option(AMReX_FPE "Enable Floating Point Exceptions checks" OFF)
print_option( AMReX_FPE )

option(AMReX_ADDRLINES "Add minimal debug info that only records line numbers" ON)
print_option( AMReX_ADDRLINES )

if ( "${CMAKE_BUILD_TYPE}" MATCHES "Debug" )
option( AMReX_ASSERTIONS "Enable assertions" ON)
else ()
Expand All @@ -377,7 +380,7 @@ endif ()

print_option( AMReX_ASSERTIONS )

option(AMReX_BOUND_CHECK "Enable bound checking in Array4 class" OFF)
option(AMReX_BOUND_CHECK "Enable bound checking in Array4 class" OFF)
print_option( AMReX_BOUND_CHECK )

if("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
Expand Down
6 changes: 4 additions & 2 deletions Tools/CMake/AMReX_Config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ function (configure_amrex AMREX_TARGET)
#
# Check that needed options have already been defined
#
if ( ( NOT ( DEFINED AMReX_MPI ) ) OR ( NOT (DEFINED AMReX_OMP) )
OR ( NOT (DEFINED AMReX_PIC) ) OR (NOT (DEFINED AMReX_FPE)))
if ( (NOT (DEFINED AMReX_MPI) ) OR (NOT (DEFINED AMReX_OMP) )
OR (NOT (DEFINED AMReX_PIC) ) OR (NOT (DEFINED AMReX_FPE) )
OR (NOT (DEFINED AMReX_ADDRLINES) )
)
message ( AUTHOR_WARNING "Required options are not defined" )
endif ()

Expand Down

0 comments on commit 6a43082

Please sign in to comment.